diff options
Diffstat (limited to 'server/config.c')
-rw-r--r-- | server/config.c | 263 |
1 files changed, 41 insertions, 222 deletions
diff --git a/server/config.c b/server/config.c index f815b22..3d11ff5 100644 --- a/server/config.c +++ b/server/config.c @@ -59,7 +59,6 @@ AP_DECLARE_DATA const char *ap_server_argv0 = NULL; AP_DECLARE_DATA const char *ap_server_root = NULL; -AP_DECLARE_DATA const char *ap_runtime_dir = NULL; AP_DECLARE_DATA server_rec *ap_server_conf = NULL; AP_DECLARE_DATA apr_pool_t *ap_pglobal = NULL; @@ -1038,11 +1037,11 @@ static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms, */ w = ap_getword_conf(parms->temp_pool, &args); - if (*w == '\0' || (strcasecmp(w, "on") && strcasecmp(w, "off"))) + if (*w == '\0' || (ap_cstr_casecmp(w, "on") && ap_cstr_casecmp(w, "off"))) return apr_pstrcat(parms->pool, cmd->name, " must be On or Off", NULL); - return cmd->AP_FLAG(parms, mconfig, strcasecmp(w, "off") != 0); + return cmd->AP_FLAG(parms, mconfig, ap_cstr_casecmp(w, "off") != 0); default: return apr_pstrcat(parms->pool, cmd->name, @@ -1055,7 +1054,7 @@ AP_CORE_DECLARE(const command_rec *) ap_find_command(const char *name, const command_rec *cmds) { while (cmds->name) { - if (!strcasecmp(name, cmds->name)) + if (!ap_cstr_casecmp(name, cmds->name)) return cmds; ++cmds; @@ -1118,8 +1117,9 @@ static const char *ap_build_config_sub(apr_pool_t *p, apr_pool_t *temp_pool, const char *args; char *cmd_name; ap_directive_t *newdir; - module *mod = ap_top_module; const command_rec *cmd; + ap_mod_list *ml; + char *lname; if (*l == '#' || *l == '\0') return NULL; @@ -1157,9 +1157,12 @@ static const char *ap_build_config_sub(apr_pool_t *p, apr_pool_t *temp_pool, newdir->line_num = parms->config_file->line_number; newdir->args = apr_pstrdup(p, args); - if ((cmd = ap_find_command_in_modules(cmd_name, &mod)) != NULL) { + lname = apr_pstrdup(temp_pool, cmd_name); + ap_str_tolower(lname); + ml = apr_hash_get(ap_config_hash, lname, APR_HASH_KEY_STRING); + + if (ml && (cmd = ml->cmd) != NULL) { newdir->directive = cmd->name; - if (cmd->req_override & EXEC_ON_READ) { ap_directive_t *sub_tree = NULL; @@ -1220,7 +1223,7 @@ static const char *ap_build_config_sub(apr_pool_t *p, apr_pool_t *temp_pool, *bracket = '\0'; - if (strcasecmp(cmd_name + 2, + if (ap_cstr_casecmp(cmd_name + 2, (*curr_parent)->directive + 1) != 0) { parms->err_directive = newdir; return apr_pstrcat(p, "Expected </", @@ -1267,7 +1270,7 @@ AP_DECLARE(const char *) ap_build_cont_config(apr_pool_t *p, while ((rc = ap_varbuf_cfg_getline(&vb, parms->config_file, max_len)) == APR_SUCCESS) { if (!memcmp(vb.buf, "</", 2) - && (strcasecmp(vb.buf + 2, bracket) == 0) + && (ap_cstr_casecmp(vb.buf + 2, bracket) == 0) && (*curr_parent == NULL)) { break; } @@ -1542,8 +1545,8 @@ AP_DECLARE_NONSTD(const char *) ap_set_file_slot(cmd_parms *cmd, void *struct_pt path = ap_server_root_relative(cmd->pool, arg); if (!path) { - return apr_pstrcat(cmd->pool, "Invalid file path ", - arg, NULL); + return apr_pstrcat(cmd->pool, cmd->cmd->name, ": Invalid file path '", + arg, "'", NULL); } *(const char **) ((char*)struct_ptr + offset) = path; @@ -1644,7 +1647,7 @@ AP_DECLARE(const char *) ap_soak_end_container(cmd_parms *cmd, char *directive) if (cmd_name[1] == '/') { cmd_name[strlen(cmd_name) - 1] = '\0'; - if (strcasecmp(cmd_name + 2, directive + 1) != 0) { + if (ap_cstr_casecmp(cmd_name + 2, directive + 1) != 0) { return apr_pstrcat(cmd->pool, "Expected </", directive + 1, "> but saw ", cmd_name, ">", NULL); @@ -1793,18 +1796,6 @@ static const char *process_command_config(server_rec *s, return NULL; } -typedef struct { - const char *fname; -} fnames; - -static int fname_alphasort(const void *fn1, const void *fn2) -{ - const fnames *f1 = fn1; - const fnames *f2 = fn2; - - return strcmp(f1->fname,f2->fname); -} - /** * Used by -D DUMP_INCLUDES to output the config file "tree". */ @@ -1897,200 +1888,15 @@ AP_DECLARE(const char *) ap_process_resource_config(server_rec *s, return NULL; } -static const char *process_resource_config_nofnmatch(server_rec *s, - const char *fname, - ap_directive_t **conftree, - apr_pool_t *p, - apr_pool_t *ptemp, - unsigned depth, - int optional) -{ - const char *error; - apr_status_t rv; - - if (ap_is_directory(ptemp, fname)) { - apr_dir_t *dirp; - apr_finfo_t dirent; - int current; - apr_array_header_t *candidates = NULL; - fnames *fnew; - char *path = apr_pstrdup(ptemp, fname); - - if (++depth > AP_MAX_INCLUDE_DIR_DEPTH) { - return apr_psprintf(p, "Directory %s exceeds the maximum include " - "directory nesting level of %u. You have " - "probably a recursion somewhere.", path, - AP_MAX_INCLUDE_DIR_DEPTH); - } - - /* - * first course of business is to grok all the directory - * entries here and store 'em away. Recall we need full pathnames - * for this. - */ - rv = apr_dir_open(&dirp, path, ptemp); - if (rv != APR_SUCCESS) { - return apr_psprintf(p, "Could not open config directory %s: %pm", - path, &rv); - } - - candidates = apr_array_make(ptemp, 1, sizeof(fnames)); - while (apr_dir_read(&dirent, APR_FINFO_DIRENT, dirp) == APR_SUCCESS) { - /* strip out '.' and '..' */ - if (strcmp(dirent.name, ".") - && strcmp(dirent.name, "..")) { - fnew = (fnames *) apr_array_push(candidates); - fnew->fname = ap_make_full_path(ptemp, path, dirent.name); - } - } - - apr_dir_close(dirp); - if (candidates->nelts != 0) { - qsort((void *) candidates->elts, candidates->nelts, - sizeof(fnames), fname_alphasort); - - /* - * Now recurse these... we handle errors and subdirectories - * via the recursion, which is nice - */ - for (current = 0; current < candidates->nelts; ++current) { - fnew = &((fnames *) candidates->elts)[current]; - error = process_resource_config_nofnmatch(s, fnew->fname, - conftree, p, ptemp, - depth, optional); - if (error) { - return error; - } - } - } - - return NULL; - } - else if (optional) { - /* If the optinal flag is set (like for IncludeOptional) we can - * tolerate that no file or directory is present and bail out. - */ - apr_finfo_t finfo; - if (apr_stat(&finfo, fname, APR_FINFO_TYPE, ptemp) != APR_SUCCESS - || finfo.filetype == APR_NOFILE) - return NULL; - } - - return ap_process_resource_config(s, fname, conftree, p, ptemp); -} +typedef struct { + server_rec *s; + ap_directive_t **conftree; +} configs; -static const char *process_resource_config_fnmatch(server_rec *s, - const char *path, - const char *fname, - ap_directive_t **conftree, - apr_pool_t *p, - apr_pool_t *ptemp, - unsigned depth, - int optional) +static const char *process_resource_config_cb(ap_dir_match_t *w, const char *fname) { - const char *rest; - apr_status_t rv; - apr_dir_t *dirp; - apr_finfo_t dirent; - apr_array_header_t *candidates = NULL; - fnames *fnew; - int current; - - /* find the first part of the filename */ - rest = ap_strchr_c(fname, '/'); - if (rest) { - fname = apr_pstrmemdup(ptemp, fname, rest - fname); - rest++; - } - - /* optimisation - if the filename isn't a wildcard, process it directly */ - if (!apr_fnmatch_test(fname)) { - path = ap_make_full_path(ptemp, path, fname); - if (!rest) { - return process_resource_config_nofnmatch(s, path, - conftree, p, - ptemp, 0, optional); - } - else { - return process_resource_config_fnmatch(s, path, rest, - conftree, p, - ptemp, 0, optional); - } - } - - /* - * first course of business is to grok all the directory - * entries here and store 'em away. Recall we need full pathnames - * for this. - */ - rv = apr_dir_open(&dirp, path, ptemp); - if (rv != APR_SUCCESS) { - /* If the directory doesn't exist and the optional flag is set - * there is no need to return an error. - */ - if (rv == APR_ENOENT && optional) { - return NULL; - } - return apr_psprintf(p, "Could not open config directory %s: %pm", - path, &rv); - } - - candidates = apr_array_make(ptemp, 1, sizeof(fnames)); - while (apr_dir_read(&dirent, APR_FINFO_DIRENT | APR_FINFO_TYPE, dirp) == APR_SUCCESS) { - /* strip out '.' and '..' */ - if (strcmp(dirent.name, ".") - && strcmp(dirent.name, "..") - && (apr_fnmatch(fname, dirent.name, - APR_FNM_PERIOD) == APR_SUCCESS)) { - const char *full_path = ap_make_full_path(ptemp, path, dirent.name); - /* If matching internal to path, and we happen to match something - * other than a directory, skip it - */ - if (rest && (dirent.filetype != APR_DIR)) { - continue; - } - fnew = (fnames *) apr_array_push(candidates); - fnew->fname = full_path; - } - } - - apr_dir_close(dirp); - if (candidates->nelts != 0) { - const char *error; - - qsort((void *) candidates->elts, candidates->nelts, - sizeof(fnames), fname_alphasort); - - /* - * Now recurse these... we handle errors and subdirectories - * via the recursion, which is nice - */ - for (current = 0; current < candidates->nelts; ++current) { - fnew = &((fnames *) candidates->elts)[current]; - if (!rest) { - error = process_resource_config_nofnmatch(s, fnew->fname, - conftree, p, - ptemp, 0, optional); - } - else { - error = process_resource_config_fnmatch(s, fnew->fname, rest, - conftree, p, - ptemp, 0, optional); - } - if (error) { - return error; - } - } - } - else { - - if (!optional) { - return apr_psprintf(p, "No matches for the wildcard '%s' in '%s', failing " - "(use IncludeOptional if required)", fname, path); - } - } - - return NULL; + configs *cfgs = w->ctx; + return ap_process_resource_config(cfgs->s, fname, cfgs->conftree, w->p, w->ptemp); } AP_DECLARE(const char *) ap_process_fnmatch_configs(server_rec *s, @@ -2100,8 +1906,19 @@ AP_DECLARE(const char *) ap_process_fnmatch_configs(server_rec *s, apr_pool_t *ptemp, int optional) { - /* XXX: lstat() won't work on the wildcard pattern... - */ + configs cfgs; + ap_dir_match_t w; + + cfgs.s = s; + cfgs.conftree = conftree; + + w.prefix = "Include/IncludeOptional: "; + w.p = p; + w.ptemp = ptemp; + w.flags = (optional ? AP_DIR_FLAG_OPTIONAL : AP_DIR_FLAG_NONE) | AP_DIR_FLAG_RECURSIVE; + w.cb = process_resource_config_cb; + w.ctx = &cfgs; + w.depth = 0; /* don't require conf/httpd.conf if we have a -C or -c switch */ if ((ap_server_pre_read_config->nelts @@ -2114,7 +1931,7 @@ AP_DECLARE(const char *) ap_process_fnmatch_configs(server_rec *s, } if (!apr_fnmatch_test(fname)) { - return process_resource_config_nofnmatch(s, fname, conftree, p, ptemp, 0, optional); + return ap_dir_nofnmatch(&w, fname); } else { apr_status_t status; @@ -2132,8 +1949,7 @@ AP_DECLARE(const char *) ap_process_fnmatch_configs(server_rec *s, } /* walk the filepath */ - return process_resource_config_fnmatch(s, rootpath, filepath, conftree, p, ptemp, - 0, optional); + return ap_dir_fnmatch(&w, rootpath, filepath); } } @@ -2485,6 +2301,9 @@ AP_DECLARE(server_rec*) ap_read_config(process_rec *process, apr_pool_t *ptemp, if (s == NULL) { return s; } + if (ap_server_conf == NULL) { + ap_server_conf = s; + } init_config_globals(p); @@ -2720,7 +2539,7 @@ static int count_directives_sub(const char *directive, ap_directive_t *current) while (current != NULL) { if (current->first_child != NULL) count += count_directives_sub(directive, current->first_child); - if (strcasecmp(current->directive, directive) == 0) + if (ap_cstr_casecmp(current->directive, directive) == 0) count++; current = current->next; } |