From 95c2ba2dd52fc2c90f68c471509f0851193aba0a Mon Sep 17 00:00:00 2001 From: Ian Holsman Date: Thu, 12 Sep 2002 20:04:07 +0000 Subject: [PATCH] Add support for using fnmatch patterns in the final path segment of an Include statement (eg.. include /foo/bar/*.conf). and remove the noise on stderr during config dir processing. Submitted by: Joe Orton Reviewed by: Ian Holsman, Brian Pane git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@96776 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 6 ++++++ server/config.c | 53 ++++++++++++++++++++++++++++++++++++------------- 2 files changed, 45 insertions(+), 14 deletions(-) diff --git a/CHANGES b/CHANGES index 987944065b..15d07aede8 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,10 @@ Changes with Apache 2.0.41 + + *) Add support for using fnmatch patterns in the final path + segment of an Include statement (eg.. include /foo/bar/*.conf). + and remove the noise on stderr during config dir processing. + [Joe Orton ] + *) mod_cache: cache_storage.c. Add the hostname and any request args to the key generated for caching. This provides a unique key for each virtual host and for each request with unique diff --git a/server/config.c b/server/config.c index 1ca924eea8..0fcbef6b0e 100644 --- a/server/config.c +++ b/server/config.c @@ -75,6 +75,7 @@ #include "apr_strings.h" #include "apr_portable.h" #include "apr_file_io.h" +#include "apr_fnmatch.h" #define APR_WANT_STDIO #define APR_WANT_STRFUNC @@ -1442,6 +1443,7 @@ AP_DECLARE(void) ap_process_resource_config(server_rec *s, const char *fname, apr_finfo_t finfo; const char *errmsg; ap_configfile_t *cfp; + int ispatt; /* don't require conf/httpd.conf if we have a -C or -c switch */ if ((ap_server_pre_read_config->nelts @@ -1451,31 +1453,52 @@ AP_DECLARE(void) ap_process_resource_config(server_rec *s, const char *fname, return; } - /* - * 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(ptemp, fname)) { + ispatt = apr_fnmatch_test(fname); + if (ispatt || ap_is_rdirectory(p, fname)) { apr_dir_t *dirp; apr_finfo_t dirent; int current; apr_array_header_t *candidates = NULL; fnames *fnew; apr_status_t rv; - char errmsg[120]; + char errmsg[120], *path = apr_pstrdup(p, fname), *pattern = NULL; + + if (ispatt) { + pattern = ap_strrchr(path, '/'); + + AP_DEBUG_ASSERT(pattern != NULL); /* path must be absolute. */ + + *pattern++ = '\0'; + + if (apr_fnmatch_test(path)) { + fprintf(stderr, "%s: wildcard patterns not allowed in Include " + "%s\n", ap_server_argv0, fname); + exit(1); + } + + if (!ap_is_rdirectory(p, path)){ + fprintf(stderr, "%s: Include directory '%s' not found", + ap_server_argv0, path); + exit(1); + } + + if (!apr_fnmatch_test(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 * entries here and store 'em away. Recall we need full pathnames * for this. */ - fprintf(stderr, "Processing config directory: %s\n", fname); - rv = apr_dir_open(&dirp, fname, p); + rv = apr_dir_open(&dirp, path, p); if (rv != APR_SUCCESS) { fprintf(stderr, "%s: could not open config directory %s: %s\n", - ap_server_argv0, fname, + ap_server_argv0, path, apr_strerror(rv, errmsg, sizeof errmsg)); exit(1); } @@ -1484,9 +1507,12 @@ AP_DECLARE(void) ap_process_resource_config(server_rec *s, const char *fname, while (apr_dir_read(&dirent, APR_FINFO_DIRENT, dirp) == APR_SUCCESS) { /* strip out '.' and '..' */ if (strcmp(dirent.name, ".") - && strcmp(dirent.name, "..")) { + && strcmp(dirent.name, "..") + && (!ispatt || + apr_fnmatch(pattern, dirent.name, + FNM_PERIOD) == APR_SUCCESS)) { fnew = (fnames *) apr_array_push(candidates); - fnew->fname = ap_make_full_path(p, fname, dirent.name); + fnew->fname = ap_make_full_path(p, path, dirent.name); } } @@ -1501,7 +1527,6 @@ AP_DECLARE(void) ap_process_resource_config(server_rec *s, const char *fname, */ for (current = 0; current < candidates->nelts; ++current) { fnew = &((fnames *) candidates->elts)[current]; - fprintf(stderr, " Processing config file: %s\n", fnew->fname); ap_process_resource_config(s, fnew->fname, conftree, p, ptemp); } } -- 2.40.0