📄 config.c
字号:
parms.temp_pool = ptemp; parms.server = s; parms.override = (RSRC_CONF | OR_ALL) & ~(OR_AUTHCFG | OR_LIMIT); parms.limited = -1; errmsg = ap_walk_config(conftree, &parms, s->lookup_defaults); if (errmsg) { ap_log_perror(APLOG_MARK, APLOG_STARTUP, 0, p, "Syntax error on line %d of %s:", parms.err_directive->line_num, parms.err_directive->filename); ap_log_perror(APLOG_MARK, APLOG_STARTUP, 0, p, "%s", errmsg); exit(1); }}AP_CORE_DECLARE(int) ap_parse_htaccess(ap_conf_vector_t **result, request_rec *r, int override, const char *d, const char *access_name){ ap_configfile_t *f = NULL; cmd_parms parms; char *filename = NULL; const struct htaccess_result *cache; struct htaccess_result *new; ap_conf_vector_t *dc = NULL; apr_status_t status; /* firstly, search cache */ for (cache = r->htaccess; cache != NULL; cache = cache->next) { if (cache->override == override && strcmp(cache->dir, d) == 0) { *result = cache->htaccess; return OK; } } parms = default_parms; parms.override = override; parms.pool = r->pool; parms.temp_pool = r->pool; parms.server = r->server; parms.path = apr_pstrdup(r->pool, d); /* loop through the access names and find the first one */ while (access_name[0]) { /* AFAICT; there is no use of the actual 'filename' against * any canonicalization, so we will simply take the given * name, ignoring case sensitivity and aliases */ filename = ap_make_full_path(r->pool, d, ap_getword_conf(r->pool, &access_name)); status = ap_pcfg_openfile(&f, r->pool, filename); if (status == APR_SUCCESS) { const char *errmsg; ap_directive_t *temptree = NULL; dc = ap_create_per_dir_config(r->pool); parms.config_file = f; errmsg = ap_build_config(&parms, r->pool, r->pool, &temptree); if (errmsg == NULL) errmsg = ap_walk_config(temptree, &parms, dc); ap_cfg_closefile(f); if (errmsg) { ap_log_rerror(APLOG_MARK, APLOG_ALERT, 0, r, "%s: %s", filename, errmsg); return HTTP_INTERNAL_SERVER_ERROR; } *result = dc; break; } else { if (!APR_STATUS_IS_ENOENT(status) && !APR_STATUS_IS_ENOTDIR(status)) { ap_log_rerror(APLOG_MARK, APLOG_CRIT, status, r, "%s pcfg_openfile: unable to check htaccess file, " "ensure it is readable", filename); apr_table_setn(r->notes, "error-notes", "Server unable to read htaccess file, denying " "access to be safe"); return HTTP_FORBIDDEN; } } } /* cache it */ new = apr_palloc(r->pool, sizeof(struct htaccess_result)); new->dir = parms.path; new->override = override; new->htaccess = dc; /* add to head of list */ new->next = r->htaccess; r->htaccess = new; return OK;}AP_CORE_DECLARE(const char *) ap_init_virtual_host(apr_pool_t *p, const char *hostname, server_rec *main_server, server_rec **ps){ server_rec *s = (server_rec *) apr_pcalloc(p, sizeof(server_rec)); /* TODO: this crap belongs in http_core */ s->process = main_server->process; s->server_admin = NULL; s->server_hostname = NULL; s->error_fname = NULL; s->timeout = 0; s->keep_alive_timeout = 0; s->keep_alive = -1; s->keep_alive_max = -1; s->error_log = main_server->error_log; s->loglevel = main_server->loglevel; /* useful default, otherwise we get a port of 0 on redirects */ s->port = main_server->port; s->next = NULL; s->is_virtual = 1; s->names = apr_array_make(p, 4, sizeof(char **)); s->wild_names = apr_array_make(p, 4, sizeof(char **)); s->module_config = create_empty_config(p); s->lookup_defaults = ap_create_per_dir_config(p); s->limit_req_line = main_server->limit_req_line; s->limit_req_fieldsize = main_server->limit_req_fieldsize; s->limit_req_fields = main_server->limit_req_fields; *ps = s; return ap_parse_vhost_addrs(p, hostname, s);}AP_DECLARE(void) ap_fixup_virtual_hosts(apr_pool_t *p, server_rec *main_server){ server_rec *virt; for (virt = main_server->next; virt; virt = virt->next) { merge_server_configs(p, main_server->module_config, virt->module_config); virt->lookup_defaults = ap_merge_per_dir_configs(p, main_server->lookup_defaults, virt->lookup_defaults); if (virt->server_admin == NULL) virt->server_admin = main_server->server_admin; if (virt->timeout == 0) virt->timeout = main_server->timeout; if (virt->keep_alive_timeout == 0) virt->keep_alive_timeout = main_server->keep_alive_timeout; if (virt->keep_alive == -1) virt->keep_alive = main_server->keep_alive; if (virt->keep_alive_max == -1) virt->keep_alive_max = main_server->keep_alive_max; /* XXX: this is really something that should be dealt with by a * post-config api phase */ ap_core_reorder_directories(p, virt); } ap_core_reorder_directories(p, main_server);}/***************************************************************** * * Getting *everything* configured... */static void init_config_globals(apr_pool_t *p){ /* Global virtual host hash bucket pointers. Init to null. */ ap_init_vhost_config(p);}static server_rec *init_server_config(process_rec *process, apr_pool_t *p){ apr_status_t rv; server_rec *s = (server_rec *) apr_pcalloc(p, sizeof(server_rec)); apr_file_open_stderr(&s->error_log, p); s->process = process; s->port = 0; s->server_admin = DEFAULT_ADMIN; s->server_hostname = NULL; s->error_fname = DEFAULT_ERRORLOG; s->loglevel = DEFAULT_LOGLEVEL; s->limit_req_line = DEFAULT_LIMIT_REQUEST_LINE; s->limit_req_fieldsize = DEFAULT_LIMIT_REQUEST_FIELDSIZE; s->limit_req_fields = DEFAULT_LIMIT_REQUEST_FIELDS; s->timeout = apr_time_from_sec(DEFAULT_TIMEOUT); s->keep_alive_timeout = apr_time_from_sec(DEFAULT_KEEPALIVE_TIMEOUT); s->keep_alive_max = DEFAULT_KEEPALIVE; s->keep_alive = 1; s->next = NULL; s->addrs = apr_pcalloc(p, sizeof(server_addr_rec)); /* NOT virtual host; don't match any real network interface */ rv = apr_sockaddr_info_get(&s->addrs->host_addr, NULL, APR_INET, 0, 0, p); ap_assert(rv == APR_SUCCESS); /* otherwise: bug or no storage */ s->addrs->host_port = 0; /* matches any port */ s->addrs->virthost = ""; /* must be non-NULL */ s->names = s->wild_names = NULL; s->module_config = create_server_config(p, s); s->lookup_defaults = create_default_per_dir_config(p); return s;}AP_DECLARE(server_rec*) ap_read_config(process_rec *process, apr_pool_t *ptemp, const char *filename, ap_directive_t **conftree){ const char *confname; apr_pool_t *p = process->pconf; server_rec *s = init_server_config(process, p); init_config_globals(p); /* All server-wide config files now have the SAME syntax... */ process_command_config(s, ap_server_pre_read_config, conftree, p, ptemp); /* process_command_config may change the ServerRoot so * compute this config file name afterwards. */ confname = ap_server_root_relative(p, filename); if (!confname) { ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, APR_EBADPATH, NULL, "Invalid config file path %s", filename); exit(1); } ap_process_resource_config(s, confname, conftree, p, ptemp); process_command_config(s, ap_server_post_read_config, conftree, p, ptemp); return s;}AP_DECLARE(void) ap_single_module_configure(apr_pool_t *p, server_rec *s, module *m){ if (m->create_server_config) ap_set_module_config(s->module_config, m, (*m->create_server_config)(p, s)); if (m->create_dir_config) ap_set_module_config(s->lookup_defaults, m, (*m->create_dir_config)(p, NULL));}AP_DECLARE(void) ap_run_rewrite_args(process_rec *process){ module *m; for (m = ap_top_module; m; m = m->next) { if (m->rewrite_args) { (*m->rewrite_args)(process); } }}/******************************************************************** * Configuration directives are restricted in terms of where they may * appear in the main configuration files and/or .htaccess files according * to the bitmask req_override in the command_rec structure. * If any of the overrides set in req_override are also allowed in the * context in which the command is read, then the command is allowed. * The context is determined as follows: * * inside *.conf --> override = (RSRC_CONF|OR_ALL)&~(OR_AUTHCFG|OR_LIMIT); * within <Directory> or <Location> --> override = OR_ALL|ACCESS_CONF; * within .htaccess --> override = AllowOverride for current directory; * * the result is, well, a rather confusing set of possibilities for when * a particular directive is allowed to be used. This procedure prints * in English where the given (pc) directive can be used. */static void show_overrides(const command_rec *pc, module *pm){ int n = 0; printf("\tAllowed in *.conf "); if ((pc->req_override & (OR_OPTIONS | OR_FILEINFO | OR_INDEXES)) || ((pc->req_override & RSRC_CONF) && ((pc->req_override & (ACCESS_CONF | OR_AUTHCFG | OR_LIMIT))))) { printf("anywhere"); } else if (pc->req_override & RSRC_CONF) { printf("only outside <Directory>, <Files> or <Location>"); } else { printf("only inside <Directory>, <Files> or <Location>"); } /* Warn if the directive is allowed inside <Directory> or .htaccess * but module doesn't support per-dir configuration */ if ((pc->req_override & (OR_ALL | ACCESS_CONF)) && !pm->create_dir_config) printf(" [no per-dir config]"); if (pc->req_override & OR_ALL) { printf(" and in .htaccess\n\twhen AllowOverride"); if ((pc->req_override & OR_ALL) == OR_ALL) { printf(" isn't None"); } else { printf(" includes "); if (pc->req_override & OR_AUTHCFG) { if (n++) printf(" or "); printf("AuthConfig"); } if (pc->req_override & OR_LIMIT) { if (n++) printf(" or "); printf("Limit"); } if (pc->req_override & OR_OPTIONS) { if (n++) printf(" or "); printf("Options"); } if (pc->req_override & OR_FILEINFO) { if (n++) printf(" or "); printf("FileInfo"); } if (pc->req_override & OR_INDEXES) { if (n++) printf(" or "); printf("Indexes"); } } } printf("\n");}/* Show the preloaded configuration directives, the help string explaining * the directive arguments, in what module they are handled, and in * what parts of the configuration they are allowed. Used for httpd -L. */AP_DECLARE(void) ap_show_directives(void){ const command_rec *pc; int n; for (n = 0; ap_loaded_modules[n]; ++n) { for (pc = ap_loaded_modules[n]->cmds; pc && pc->name; ++pc) { printf("%s (%s)\n", pc->name, ap_loaded_modules[n]->name); if (pc->errmsg) printf("\t%s\n", pc->errmsg); show_overrides(pc, ap_loaded_modules[n]); } }}/* Show the preloaded module names. Used for httpd -l. */AP_DECLARE(void) ap_show_modules(void){ int n; printf("Compiled in modules:\n"); for (n = 0; ap_loaded_modules[n]; ++n) printf(" %s\n", ap_loaded_modules[n]->name);}AP_DECLARE(const char *) ap_show_mpm(void){ return MPM_NAME;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -