You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Brian Behlendorf <br...@hyperreal.org> on 1998/05/09 03:12:41 UTC

Re: [PATCH] /dev/zero symlinks and ap_pfopen in ap_pcfg_openfile

+1, appears to work based on light testing.  In eyeballing the patch it
would have been nicer if the renaming of variables and moving of code from
one place to another was kept to a minimum, but that's just me mr. cranky
RM talking.

	Brian

At 05:50 PM 5/8/98 -0400, you wrote:
>Let's try this one... Required some wrappers and another struct,
>but maintains flexibility.
>
>Index: src/include/httpd.h
>===================================================================
>RCS file: /export/home/cvs/apache-1.3/src/include/httpd.h,v
>retrieving revision 1.210
>diff -u -r1.210 httpd.h
>--- httpd.h	1998/05/07 12:24:24	1.210
>+++ httpd.h	1998/05/08 21:46:08
>@@ -905,12 +905,18 @@
> typedef struct {
>     int (*getch) (void *param);	/* a getc()-like function */
>     void *(*getstr) (void *buf, size_t bufsiz, void *param); /* a
fgets()-like function */
>-    int (*close) (void *param);	/* a fclose()-like function */
>-    void *param;		/* the argument passed to getc()/close()/gets() */
>+    int (*close) (void *param);	/* a close hander function */
>+    void *param;		/* the argument passed to getch/getstr/close */
>     const char *name;		/* the filename / description */
>     unsigned line_number;	/* current line number, starting at 1 */
> } configfile_t;
> 
>+/* Common structure that holds the file and pool for ap_pcfg_openfile */
>+typedef struct {
>+    struct pool *pool;
>+    FILE *file;
>+} poolfile_t;
>+
> /* Open a configfile_t as FILE, return open configfile_t struct pointer */
> API_EXPORT(configfile_t *) ap_pcfg_openfile(pool *p, const char *name);
> 
>@@ -919,7 +925,7 @@
>     void *param,
>     int(*getc_func)(void*),
>     void *(*gets_func) (void *buf, size_t bufsiz, void *param),
>-    int(*close_func)(void*));
>+    int(*close_func)(void *param));
> 
> /* Read one line from open configfile_t, strip LF, increase line number */
> API_EXPORT(int) ap_cfg_getline(char *buf, size_t bufsize, configfile_t
*cfp);
>@@ -928,7 +934,7 @@
> API_EXPORT(int) ap_cfg_getc(configfile_t *cfp);
> 
> /* Detach from open configfile_t, calling the close handler */
>-API_EXPORT(int) ap_cfg_closefile(configfile_t *fp);
>+API_EXPORT(int) ap_cfg_closefile(configfile_t *cfp);
> 
> #ifdef NEED_STRERROR
> char *strerror(int err);
>Index: src/main/util.c
>===================================================================
>RCS file: /export/home/cvs/apache-1.3/src/main/util.c,v
>retrieving revision 1.114
>diff -u -r1.114 util.c
>--- util.c	1998/05/06 19:47:08	1.114
>+++ util.c	1998/05/08 21:46:14
>@@ -698,15 +698,39 @@
>     return res;
> }
> 
>+API_EXPORT(int) ap_cfg_closefile(configfile_t *cfp)
>+{
>+#ifdef DEBUG
>+    ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, NULL, "Done with
config file %s", fp->name);
>+#endif
>+    return (cfp->close == NULL) ? 0 : cfp->close(cfp->param);
>+}
>+
>+static int cfg_close(void *param)
>+{
>+    poolfile_t *cfp = (poolfile_t *) param;
>+    return (ap_pfclose(cfp->pool, cfp->file));
>+}
>+
>+static int cfg_getch(void *param)
>+{
>+    poolfile_t *cfp = (poolfile_t *) param;
>+    return (fgetc(cfp->file));
>+}
> 
>+static void *cfg_getstr(void *buf, size_t bufsiz, void *param)
>+{
>+    poolfile_t *cfp = (poolfile_t *) param;
>+    return (fgets(buf, bufsiz, cfp->file));
>+}
>+
> /* Open a configfile_t as FILE, return open configfile_t struct pointer */
> API_EXPORT(configfile_t *) ap_pcfg_openfile(pool *p, const char *name)
> {
>     configfile_t *new_cfg;
>+    poolfile_t *new_pfile;
>     FILE *file;
>-#ifdef unvoted_DISALLOW_DEVICE_ACCESS
>     struct stat stbuf;
>-#endif
> 
>     if (name == NULL) {
>         ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, NULL,
>@@ -714,7 +738,7 @@
>         return NULL;
>     }
> 
>-    file = fopen(name, "r");
>+    file = ap_pfopen(p, name, "r");
> #ifdef DEBUG
>     ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, NULL,
>                 "Opening config file %s (%s)",
>@@ -723,24 +747,25 @@
>     if (file == NULL)
>         return NULL;
> 
>-#ifdef unvoted_DISALLOW_DEVICE_ACCESS
>     if (strcmp(name, "/dev/null") != 0 &&
>         fstat(fileno(file), &stbuf) == 0 &&
>         !S_ISREG(stbuf.st_mode)) {
>         ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, NULL,
>                     "Access to file %s denied by server: not a regular
file",
>                     name);
>-        fclose(file);
>+        ap_pfclose(p, file);
>         return NULL;
>     }
>-#endif
> 
>     new_cfg = ap_palloc(p, sizeof(*new_cfg));
>-    new_cfg->param = file;
>+    new_pfile = ap_palloc(p, sizeof(*new_pfile));
>+    new_pfile->file = file;
>+    new_pfile->pool = p;
>+    new_cfg->param = new_pfile;
>     new_cfg->name = ap_pstrdup(p, name);
>-    new_cfg->getch = (int (*)(void *)) fgetc;
>-    new_cfg->getstr = (void *(*)(void *, size_t, void *)) fgets;
>-    new_cfg->close = (int (*)(void *)) fclose;
>+    new_cfg->getch = (int (*)(void *)) cfg_getch;
>+    new_cfg->getstr = (void *(*)(void *, size_t, void *)) cfg_getstr;
>+    new_cfg->close = (int (*)(void *)) cfg_close;
>     new_cfg->line_number = 0;
>     return new_cfg;
> }
>@@ -749,9 +774,9 @@
> /* Allocate a configfile_t handle with user defined functions and params */
> API_EXPORT(configfile_t *) ap_pcfg_open_custom(pool *p, const char *descr,
>     void *param,
>-    int(*getch)(void *),
>+    int(*getch)(void *param),
>     void *(*getstr) (void *buf, size_t bufsiz, void *param),
>-    int(*close_func)(void *))
>+    int(*close_func)(void *param))
> {
>     configfile_t *new_cfg = ap_palloc(p, sizeof(*new_cfg));
> #ifdef DEBUG
>@@ -920,15 +945,6 @@
>     }
> }
> 
>-API_EXPORT(int) ap_cfg_closefile(configfile_t *fp)
>-{
>-#ifdef DEBUG
>-    ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, NULL, "Done with
config file %s", fp->name);
>-#endif
>-    return (fp->close == NULL) ? 0 : fp->close(fp->param);
>-}
>-
>-
> /* Retrieve a token, spacing over it and returning a pointer to
>  * the first non-white byte afterwards.  Note that these tokens
>  * are delimited by semis and commas; and can also be delimited
>@@ -1321,13 +1337,13 @@
> #ifdef NEED_STRDUP
> char *strdup(const char *str)
> {
>-    char *dup;
>+    char *sdup;
> 
>-    if (!(dup = (char *) malloc(strlen(str) + 1)))
>+    if (!(sdup = (char *) malloc(strlen(str) + 1)))
> 	return NULL;
>-    dup = strcpy(dup, str);
>+    sdup = strcpy(sdup, str);
> 
>-    return dup;
>+    return sdup;
> }
> #endif
> 
>-- 
>===========================================================================
>   Jim Jagielski   |||   jim@jaguNET.com   |||   http://www.jaguNET.com/
>            "That's no ordinary rabbit... that's the most foul,
>            cruel and bad-tempered rodent you ever laid eyes on"
>
>
--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--
pure chewing satisfaction                                  brian@apache.org
                                                        brian@hyperreal.org