You are viewing a plain text version of this content. The canonical link for it is here.
Posted to apache-bugdb@apache.org by Stephan Seyboth <sp...@caldera.de> on 2000/11/16 12:23:13 UTC

general/6854: Provide means to exclude editor backups etc when processing conf directories

>Number:         6854
>Category:       general
>Synopsis:       Provide means to exclude editor backups etc when processing conf directories
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    apache
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   apache
>Arrival-Date:   Thu Nov 16 03:30:01 PST 2000
>Closed-Date:
>Last-Modified:
>Originator:     sps@caldera.de
>Release:        1.3.14
>Organization:
apache
>Environment:
Linux miller.caldera.de 2.4.0 #1 SMP Mon Aug 7 21:03:07 CEST 2000 i686 unknown
>Description:
Currently, the conf directory feature will process every file
in a given directory. Imho this is half-way-there in many cases
since there will often be various junk in these directories
like editor backups, package manager residue, etc. that should
normally not be processed.

Since Apache runs on a multitude of platforms in many different
configurations, hard coding an exclusion pattern does not seem
acceptable. Also, I think it is more robust to state what should
be processed than using exculsion. Therefore I came up with the
following solution:

The last part of the path can be a glob, so you can specify
exactly which files in a directory you want to process. Plain
directories are treated as globbing all their contents, retaining
current behaviour. The included patch tries to implement this
with minimal impact.

>How-To-Repeat:
n/a
>Fix:
RCS file: /cvs/apache/apache-1.3/src/main/http_config.c,v
retrieving revision 1.157
diff -u -r1.157 http_config.c
--- http_config.c       2000/11/14 09:57:08     1.157
+++ http_config.c       2000/11/16 10:12:50
@@ -1207,6 +1207,8 @@
 
 void ap_process_resource_config(server_rec *s, char *fname, pool *p, pool *ptemp)
 {
+    char *fparent;
+    char *fglob;
     const char *errmsg;
     cmd_parms parms;
     struct stat finfo;
@@ -1226,13 +1228,27 @@
            return;
     }
 
-    /*
+    /*
+     * The last component of the path may be a glob.
+     * Treat plain directories as globbing all their contents.
+     *
      * here we want to check if the candidate file is really a
      * directory, and most definitely NOT a symlink (to prevent
      * horrible loops).  If so, let's recurse and toss it back into
      * the function.
      */
     if (ap_is_rdirectory(fname)) {
+        fparent = fname;
+        fglob = "*";
+    }
+    else {
+        fparent = ap_make_dirstr_parent(p, fname);
+        fglob = fname + strlen(fparent);
+        if (!(ap_is_rdirectory(fparent) && ap_is_fnmatch(fglob)))
+            fglob = NULL;
+    }
+
+    if (fglob) {
        DIR *dirp;
        struct DIR_TYPE *dir_entry;
        int current;
@@ -1245,11 +1261,11 @@
         * for this.
         */
        fprintf(stderr, "Processing config directory: %s\n", fname);
-       dirp = ap_popendir(p, fname);
+       dirp = ap_popendir(p, fparent);
        if (dirp == NULL) {
            perror("fopen");
            fprintf(stderr, "%s: could not open config directory %s\n",
-               ap_server_argv0, fname);
+               ap_server_argv0, fparent);
 #ifdef NETWARE
            clean_parent_exit(1);
 #else
@@ -1259,10 +1275,16 @@
        candidates = ap_make_array(p, 1, sizeof(fnames));
        while ((dir_entry = readdir(dirp)) != NULL) {
            /* strip out '.' and '..' */
-           if (strcmp(dir_entry->d_name, ".") &&
-               strcmp(dir_entry->d_name, "..")) {
-               fnew = (fnames *) ap_push_array(candidates);
-               fnew->fname = ap_make_full_path(p, fname, dir_entry->d_name);
+           if (!strcmp(dir_entry->d_name, ".")  ||
+               !strcmp(dir_entry->d_name, ".."))
+               continue;
+           /* only process files matching the glob */
+           if (ap_fnmatch(fglob, dir_entry->d_name, 0) == 0) {
+             fnew = (fnames *) ap_push_array(candidates);
+             fnew->fname = ap_make_full_path(p, fparent, dir_entry->d_name);
+           }
+           else {
+             fprintf(stderr, " Excluding config: %s\n", dir_entry->d_name);
            }
        }
        ap_pclosedir(p, dirp);
>Release-Note:
>Audit-Trail:
>Unformatted:
 [In order for any reply to be added to the PR database, you need]
 [to include <ap...@Apache.Org> in the Cc line and make sure the]
 [subject line starts with the report component and number, with ]
 [or without any 'Re:' prefixes (such as "general/1098:" or      ]
 ["Re: general/1098:").  If the subject doesn't match this       ]
 [pattern, your message will be misfiled and ignored.  The       ]
 ["apbugs" address is not added to the Cc line of messages from  ]
 [the database automatically because of the potential for mail   ]
 [loops.  If you do not include this Cc, your reply may be ig-   ]
 [nored unless you are responding to an explicit request from a  ]
 [developer.  Reply only with text; DO NOT SEND ATTACHMENTS!     ]