httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jim Jagielski <...@jaguNET.com>
Subject [PATCH] ap_pcfg_openfile knows about device files
Date Fri, 08 May 1998 16:28:54 GMT
This patch removes the unvoted_DISALLOW_DEVICE_ACCESS wrapper so
now ap_pcfg_openfile can stop opening of non-/dev/null devices.
Also, as per Dean's suggestion, it now uses ap_pfopen instead of
fopen. However, this required some API changes... PLEASE review
and comment.

 
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 16:22:53
@@ -902,14 +902,16 @@
 API_EXPORT(char *) ap_escape_quotes (pool *p, const char *instring);
 
 /* Common structure for reading of config files / passwd files etc. */
-typedef struct {
+typedef struct configfile_t configfile_t;
+struct configfile_t {
     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) (configfile_t *cfile);	/* a close hander function */
+    void *param;		/* the argument passed to getc()/gets() */
     const char *name;		/* the filename / description */
     unsigned line_number;	/* current line number, starting at 1 */
-} configfile_t;
+    struct pool *cpool;		/* it's assigned pool */
+} ;
 
 /* 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 +921,7 @@
     void *param,
     int(*getc_func)(void*),
     void *(*gets_func) (void *buf, size_t bufsiz, void *param),
-    int(*close_func)(void*));
+    int(*close_func)(configfile_t*));
 
 /* 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 +930,10 @@
 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);
+
+/* Close handler for ap_pcfg_openfile */
+API_EXPORT(int) ap_cfg_fclose(configfile_t *cfp);
 
 #ifdef NEED_STRERROR
 char *strerror(int err);
Index: src/main/http_config.c
===================================================================
RCS file: /export/home/cvs/apache-1.3/src/main/http_config.c,v
retrieving revision 1.116
diff -u -r1.116 http_config.c
--- http_config.c	1998/05/06 15:18:01	1.116
+++ http_config.c	1998/05/08 16:22:57
@@ -1109,9 +1109,9 @@
 
 
 /* arr_elts_close(): dummy close routine (makes sure no more lines can be read) */
-static int arr_elts_close(void *param)
+static int arr_elts_close(configfile_t *cfile)
 {
-    arr_elts_param_t *arr_param = (arr_elts_param_t *) param;
+    arr_elts_param_t *arr_param = (arr_elts_param_t *) cfile->param;
     arr_param->curr_idx = arr_param->array->nelts;
     return 0;
 }
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 16:23:01
@@ -698,15 +698,25 @@
     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);
+}
 
+API_EXPORT(int) ap_cfg_fclose(configfile_t *cfp)
+{
+    return (ap_pfclose(cfp->cpool, cfp->param));
+}
+
 /* 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;
     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 +724,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,25 +733,24 @@
     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_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->close = ap_cfg_fclose;
     new_cfg->line_number = 0;
+    new_cfg->cpool = p;
     return new_cfg;
 }
 
@@ -751,7 +760,7 @@
     void *param,
     int(*getch)(void *),
     void *(*getstr) (void *buf, size_t bufsiz, void *param),
-    int(*close_func)(void *))
+    int(*close_func)(configfile_t *))
 {
     configfile_t *new_cfg = ap_palloc(p, sizeof(*new_cfg));
 #ifdef DEBUG
@@ -763,6 +772,7 @@
     new_cfg->getstr = getstr;
     new_cfg->close = close_func;
     new_cfg->line_number = 0;
+    new_cfg->cpool = p;
     return new_cfg;
 }
 
@@ -920,15 +930,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 +1322,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"

Mime
View raw message