From: Dirk-Willem van Gulik Date: Wed, 25 Sep 2002 22:52:45 +0000 (+0000) Subject: Scratched a major itch - got bitten by config directory globbing sucking X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6fcc67fae97902b4be11cfd9fae2a36681768d2d;p=thirdparty%2Fapache%2Fhttpd.git Scratched a major itch - got bitten by config directory globbing sucking in an editor backup file once too many. Applied the patch as submitted by Sander van Zoest (Bug id 12712) whichs makes it possible to limit the scope with simple but effective wild cards. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/1.3.x@96979 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/main/http_config.c b/src/main/http_config.c index 02c3abcdae4..b6bbda456b6 100644 --- a/src/main/http_config.c +++ b/src/main/http_config.c @@ -81,6 +81,7 @@ #include "http_conf_globals.h" /* Sigh... */ #include "http_vhost.h" #include "explain.h" +#include "fnmatch.h" DEF_Explain @@ -1211,7 +1212,7 @@ CORE_EXPORT(void) ap_process_resource_config(server_rec *s, char *fname, pool *p const char *errmsg; cmd_parms parms; struct stat finfo; - + int ispatt; fname = ap_server_root_relative(p, fname); if (!(strcmp(fname, ap_server_root_relative(p, RESOURCE_CONFIG_FILE))) || @@ -1233,12 +1234,38 @@ CORE_EXPORT(void) ap_process_resource_config(server_rec *s, char *fname, pool *p * horrible loops). If so, let's recurse and toss it back into * the function. */ - if (ap_is_rdirectory(fname)) { + ispatt = ap_is_fnmatch(fname); + if (ispatt || ap_is_rdirectory(fname)) { DIR *dirp; struct DIR_TYPE *dir_entry; int current; array_header *candidates = NULL; fnames *fnew; + char *path = ap_pstrdup(p,fname); + char *pattern = NULL; + + if(ispatt) { + pattern = strrchr(path, '/'); + *pattern++ = '\0'; + if (ap_is_fnmatch(path)) { + fprintf(stderr, "%s: wildcard patterns not allowed in Include " + "%s\n", ap_server_argv0, fname); + exit(1); + } + + if (!ap_is_rdirectory(path)){ + fprintf(stderr, "%s: Include directory '%s' not found", + ap_server_argv0, path); + exit(1); + } + if (!ap_is_fnmatch(pattern)) { + fprintf(stderr, "%s: must include a wildcard pattern " + "for Include %s\n", ap_server_argv0, fname); + exit(1); + } + + } + /* * first course of business is to grok all the directory @@ -1246,11 +1273,11 @@ CORE_EXPORT(void) ap_process_resource_config(server_rec *s, char *fname, pool *p * for this. */ fprintf(stderr, "Processing config directory: %s\n", fname); - dirp = ap_popendir(p, fname); + dirp = ap_popendir(p, path); if (dirp == NULL) { perror("fopen"); fprintf(stderr, "%s: could not open config directory %s\n", - ap_server_argv0, fname); + ap_server_argv0, path); #ifdef NETWARE clean_parent_exit(1); #else @@ -1261,9 +1288,11 @@ CORE_EXPORT(void) ap_process_resource_config(server_rec *s, char *fname, pool *p while ((dir_entry = readdir(dirp)) != NULL) { /* strip out '.' and '..' */ if (strcmp(dir_entry->d_name, ".") && - strcmp(dir_entry->d_name, "..")) { + strcmp(dir_entry->d_name, "..") && + (!ispatt || + !ap_fnmatch(pattern,dir_entry->d_name, FNM_PERIOD)) ) { fnew = (fnames *) ap_push_array(candidates); - fnew->fname = ap_make_full_path(p, fname, dir_entry->d_name); + fnew->fname = ap_make_full_path(p, path, dir_entry->d_name); } } ap_pclosedir(p, dirp);