#include "http_main.h"
#include "http_vhost.h"
#include "util_cfgtree.h"
+#include "util_varbuf.h"
#include "mpm_common.h"
#define APLOG_UNSET (APLOG_NO_MODULE - 1)
-APLOG_USE_MODULE(core);
+/* we know core's module_index is 0 */
+#undef APLOG_MODULE_INDEX
+#define APLOG_MODULE_INDEX AP_CORE_MODULE_INDEX
AP_DECLARE_DATA const char *ap_server_argv0 = NULL;
AP_DECLARE_DATA const char *ap_server_root = NULL;
AP_IMPLEMENT_HOOK_RUN_FIRST(int, quick_handler, (request_rec *r, int lookup),
(r, lookup), DECLINED)
+/* hooks with no args are implemented last, after disabling APR hook probes */
+#if defined(APR_HOOK_PROBES_ENABLED)
+#undef APR_HOOK_PROBES_ENABLED
+#undef APR_HOOK_PROBE_ENTRY
+#define APR_HOOK_PROBE_ENTRY(ud,ns,name,args)
+#undef APR_HOOK_PROBE_RETURN
+#define APR_HOOK_PROBE_RETURN(ud,ns,name,rv,args)
+#undef APR_HOOK_PROBE_INVOKE
+#define APR_HOOK_PROBE_INVOKE(ud,ns,name,src,args)
+#undef APR_HOOK_PROBE_COMPLETE
+#define APR_HOOK_PROBE_COMPLETE(ud,ns,name,src,rv,args)
+#undef APR_HOOK_INT_DCL_UD
+#define APR_HOOK_INT_DCL_UD
+#endif
AP_IMPLEMENT_HOOK_VOID(optional_fn_retrieve, (void), ())
/****************************************************************
*/
static int conf_vector_length = 0;
+static int reserved_module_slots = 0;
+
AP_DECLARE_DATA module *ap_top_module = NULL;
AP_DECLARE_DATA module **ap_loaded_modules=NULL;
r->handler = old_handler;
if (result == DECLINED && r->handler && r->filename) {
- ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r,
+ ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, APLOGNO(00523)
"handler \"%s\" not found for: %s", r->handler, r->filename);
}
if ((result != OK) && (result != DONE) && (result != DECLINED) && (result != SUSPENDED)
*/
ignore = apr_table_get(r->notes, "HTTP_IGNORE_RANGE");
if (!ignore) {
- ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
+ ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00524)
"Handler for %s returned invalid result code %d",
r->handler, result);
result = HTTP_INTERNAL_SERVER_ERROR;
"reached. Please increase "
"DYNAMIC_MODULE_LIMIT and recompile.", m->name);
}
+ /*
+ * If this fails some module forgot to call ap_reserve_module_slots*.
+ */
+ ap_assert(total_modules < conf_vector_length);
m->module_index = total_modules++;
dynamic_modules++;
if (!modp) {
/* Uh-oh, this module doesn't exist */
- ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL, APLOGNO(00525)
"Cannot remove module %s: not found in module list",
m->name);
return;
ap_loaded_modules = (module **)apr_palloc(process->pool,
sizeof(module *) * conf_vector_length);
if (!ap_module_short_names)
- ap_module_short_names = calloc(sizeof(char *), conf_vector_length);
+ ap_module_short_names = ap_calloc(sizeof(char *), conf_vector_length);
if (!merger_func_cache)
- merger_func_cache = calloc(sizeof(merger_func), conf_vector_length);
+ merger_func_cache = ap_calloc(sizeof(merger_func), conf_vector_length);
if (ap_loaded_modules == NULL || ap_module_short_names == NULL
|| merger_func_cache == NULL)
static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms,
void *mconfig, const char *args)
{
+ int override_list_ok = 0;
char *w, *w2, *w3;
const char *errmsg = NULL;
- if ((parms->override & cmd->req_override) == 0)
+ /** Have we been provided a list of acceptable directives? */
+ if(parms->override_list != NULL)
+ if(apr_table_get(parms->override_list, cmd->name) != NULL)
+ override_list_ok = 1;
+
+ if ((parms->override & cmd->req_override) == 0 && !override_list_ok)
return apr_pstrcat(parms->pool, cmd->name, " not allowed here", NULL);
parms->info = cmd->cmd_data;
return retval;
}
+#define VARBUF_INIT_LEN 200
+#define VARBUF_MAX_LEN (16*1024*1024)
+
AP_DECLARE(const char *) ap_build_cont_config(apr_pool_t *p,
apr_pool_t *temp_pool,
cmd_parms *parms,
ap_directive_t **curr_parent,
char *orig_directive)
{
- char *l;
char *bracket;
const char *retval;
ap_directive_t *sub_tree = NULL;
apr_status_t rc;
-
- /* Since this function can be called recursively, allocate
- * the temporary 8k string buffer from the temp_pool rather
- * than the stack to avoid over-running a fixed length stack.
- */
- l = apr_palloc(temp_pool, MAX_STRING_LEN);
+ struct ap_varbuf vb;
bracket = apr_pstrcat(temp_pool, orig_directive + 1, ">", NULL);
- while ((rc = ap_cfg_getline(l, MAX_STRING_LEN, parms->config_file))
+ ap_varbuf_init(temp_pool, &vb, VARBUF_INIT_LEN);
+
+ while ((rc = ap_varbuf_cfg_getline(&vb, parms->config_file, VARBUF_MAX_LEN))
== APR_SUCCESS) {
- if (!memcmp(l, "</", 2)
- && (strcasecmp(l + 2, bracket) == 0)
+ if (!memcmp(vb.buf, "</", 2)
+ && (strcasecmp(vb.buf + 2, bracket) == 0)
&& (*curr_parent == NULL)) {
break;
}
- retval = ap_build_config_sub(p, temp_pool, l, parms, current,
+ retval = ap_build_config_sub(p, temp_pool, vb.buf, parms, current,
curr_parent, &sub_tree);
if (retval != NULL)
return retval;
sub_tree = *current;
}
}
+ ap_varbuf_free(&vb);
if (rc != APR_EOF && rc != APR_SUCCESS)
return ap_pcfg_strerror(temp_pool, parms->config_file, rc);
{
const command_rec *cmd;
ap_mod_list *ml;
- char *dir = apr_pstrdup(parms->pool, current->directive);
+ char *dir = apr_pstrdup(parms->temp_pool, current->directive);
ap_str_tolower(dir);
{
ap_directive_t *current = *conftree;
ap_directive_t *curr_parent = NULL;
- char *l = apr_palloc (temp_pool, MAX_STRING_LEN);
const char *errmsg;
ap_directive_t **last_ptr = NULL;
apr_status_t rc;
+ struct ap_varbuf vb;
+
+ ap_varbuf_init(temp_pool, &vb, VARBUF_INIT_LEN);
if (current != NULL) {
/* If we have to traverse the whole tree again for every included
}
}
- while ((rc = ap_cfg_getline(l, MAX_STRING_LEN, parms->config_file))
+ while ((rc = ap_varbuf_cfg_getline(&vb, parms->config_file, VARBUF_MAX_LEN))
== APR_SUCCESS) {
- errmsg = ap_build_config_sub(p, temp_pool, l, parms,
+ errmsg = ap_build_config_sub(p, temp_pool, vb.buf, parms,
¤t, &curr_parent, conftree);
if (errmsg != NULL)
return errmsg;
*conftree = current;
}
}
+ ap_varbuf_free(&vb);
if (rc != APR_EOF && rc != APR_SUCCESS)
return ap_pcfg_strerror(temp_pool, parms->config_file, rc);
*/
static cmd_parms default_parms =
-{NULL, 0, 0, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
+{NULL, 0, 0, NULL, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
AP_DECLARE(char *) ap_server_root_relative(apr_pool_t *p, const char *file)
{
AP_DECLARE(const char *) ap_soak_end_container(cmd_parms *cmd, char *directive)
{
- char l[MAX_STRING_LEN];
+ struct ap_varbuf vb;
const char *args;
char *cmd_name;
apr_status_t rc;
- while((rc = ap_cfg_getline(l, MAX_STRING_LEN, cmd->config_file))
+ ap_varbuf_init(cmd->temp_pool, &vb, VARBUF_INIT_LEN);
+
+ while((rc = ap_varbuf_cfg_getline(&vb, cmd->config_file, VARBUF_MAX_LEN))
== APR_SUCCESS) {
#if RESOLVE_ENV_PER_TOKEN
- args = l;
+ args = vb.buf;
#else
- args = ap_resolve_env(cmd->temp_pool, l);
+ args = ap_resolve_env(cmd->temp_pool, vb.buf);
#endif
cmd_name = ap_getword_conf(cmd->temp_pool, &args);
cmd_name, ">", NULL);
}
+ ap_varbuf_free(&vb);
return NULL; /* found end of container */
}
else {
/* walk the filepath */
return process_resource_config_fnmatch(s, rootpath, filepath, conftree, p, ptemp,
0, optional);
-
}
-
- return NULL;
}
AP_DECLARE(int) ap_process_config_tree(server_rec *s,
errmsg = ap_walk_config(conftree, &parms, s->lookup_defaults);
if (errmsg) {
if (parms.err_directive)
- ap_log_perror(APLOG_MARK, APLOG_STARTUP, 0, p,
+ ap_log_perror(APLOG_MARK, APLOG_STARTUP, 0, p, APLOGNO(00526)
"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,
+ ap_log_perror(APLOG_MARK, APLOG_STARTUP, 0, p, APLOGNO(00527)
"%s", errmsg);
return HTTP_INTERNAL_SERVER_ERROR;
}
AP_CORE_DECLARE(int) ap_parse_htaccess(ap_conf_vector_t **result,
request_rec *r, int override,
- int override_opts,
+ int override_opts, apr_table_t *override_list,
const char *d, const char *access_name)
{
ap_configfile_t *f = NULL;
parms = default_parms;
parms.override = override;
parms.override_opts = override_opts;
+ parms.override_list = override_list;
parms.pool = r->pool;
parms.temp_pool = r->pool;
parms.server = r->server;
ap_cfg_closefile(f);
if (errmsg) {
- ap_log_rerror(APLOG_MARK, APLOG_ALERT, 0, r,
+ ap_log_rerror(APLOG_MARK, APLOG_ALERT, 0, r, APLOGNO(00528)
"%s: %s", filename, errmsg);
return HTTP_INTERNAL_SERVER_ERROR;
}
else {
if (!APR_STATUS_IS_ENOENT(status)
&& !APR_STATUS_IS_ENOTDIR(status)) {
- ap_log_rerror(APLOG_MARK, APLOG_CRIT, status, r,
+ ap_log_rerror(APLOG_MARK, APLOG_CRIT, status, r, APLOGNO(00529)
"%s pcfg_openfile: unable to check htaccess file, "
- "ensure it is readable and that '%s' "
+ "ensure it is readable and that '%s' "
"is executable",
filename, d);
apr_table_setn(r->notes, "error-notes",
AP_DECLARE(void) ap_fixup_virtual_hosts(apr_pool_t *p, server_rec *main_server)
{
server_rec *virt;
- core_dir_config *dconf = ap_get_module_config(main_server->lookup_defaults,
- &core_module);
+ core_dir_config *dconf =
+ ap_get_core_module_config(main_server->lookup_defaults);
dconf->log = &main_server->log;
for (virt = main_server->next; virt; virt = virt->next) {
ap_merge_log_config(&main_server->log, &virt->log);
- dconf = ap_get_module_config(virt->lookup_defaults, &core_module);
+ dconf = ap_get_core_module_config(virt->lookup_defaults);
dconf->log = &virt->log;
/* XXX: this is really something that should be dealt with by a
/* 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);
+ NULL, APR_UNSPEC, 0, 0, p);
if (rv != APR_SUCCESS) {
/* should we test here for rv being an EAIERR? */
- ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, rv, NULL,
+ ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, rv, NULL, APLOGNO(00530)
"initialisation: bug or getaddrinfo fail");
return NULL;
}
static apr_status_t reset_conf_vector_length(void *dummy)
{
+ reserved_module_slots = 0;
conf_vector_length = max_modules;
return APR_SUCCESS;
}
+static int conf_vector_length_pre_config(apr_pool_t *pconf, apr_pool_t *plog,
+ apr_pool_t *ptemp)
+{
+ /*
+ * We have loaded all modules that are loaded by EXEC_ON_READ directives.
+ * From now on we reduce the size of the config vectors to what we need,
+ * plus what has been reserved (e.g. by mod_perl) for additional modules
+ * loaded later on.
+ * If max_modules is too small, ap_add_module() will abort.
+ */
+ if (total_modules + reserved_module_slots < max_modules) {
+ conf_vector_length = total_modules + reserved_module_slots;
+ }
+ apr_pool_cleanup_register(pconf, NULL, reset_conf_vector_length,
+ apr_pool_cleanup_null);
+ return OK;
+}
+
+
+AP_CORE_DECLARE(void) ap_register_config_hooks(apr_pool_t *p)
+{
+ ap_hook_pre_config(conf_vector_length_pre_config, NULL, NULL,
+ APR_HOOK_REALLY_LAST);
+}
+
AP_DECLARE(server_rec*) ap_read_config(process_rec *process, apr_pool_t *ptemp,
const char *filename,
ap_directive_t **conftree)
error = process_command_config(s, ap_server_pre_read_config, conftree,
p, ptemp);
if (error) {
- ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, 0, NULL, "%s: %s",
+ ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, 0, NULL, APLOGNO(00531) "%s: %s",
ap_server_argv0, error);
return NULL;
}
if (!confname) {
ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT,
- APR_EBADPATH, NULL, "Invalid config file path %s",
+ APR_EBADPATH, NULL, APLOGNO(00532) "Invalid config file path %s",
filename);
return NULL;
}
error = ap_process_resource_config(s, confname, conftree, p, ptemp);
if (error) {
- ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, 0, NULL,
+ ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, 0, NULL, APLOGNO(00533)
"%s: %s", ap_server_argv0, error);
return NULL;
}
error = ap_check_mpm();
if (error) {
- ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, 0, NULL,
+ ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, 0, NULL, APLOGNO(00534)
"%s: Configuration error: %s", ap_server_argv0, error);
return NULL;
}
- /*
- * We have loaded the dynamic modules. From now on we know exactly how
- * long the config vectors need to be.
- */
- conf_vector_length = total_modules;
- apr_pool_cleanup_register(p, NULL, reset_conf_vector_length,
- apr_pool_cleanup_null);
-
error = process_command_config(s, ap_server_post_read_config, conftree,
p, ptemp);
if (error) {
- ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, 0, NULL, "%s: %s",
+ ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, 0, NULL, APLOGNO(00535) "%s: %s",
ap_server_argv0, error);
return NULL;
}
printf("anywhere");
}
else if (pc->req_override & RSRC_CONF) {
- printf("only outside <Directory>, <Files> or <Location>");
+ printf("only outside <Directory>, <Files>, <Location>, or <If>");
}
else {
- printf("only inside <Directory>, <Files> or <Location>");
+ printf("only inside <Directory>, <Files>, <Location>, or <If>");
}
/* Warn if the directive is allowed inside <Directory> or .htaccess
apr_pool_userdata_set((const void *)retained, key, apr_pool_cleanup_null, ap_pglobal);
return retained;
}
+
+static int count_directives_sub(const char *directive, ap_directive_t *current)
+{
+ int count = 0;
+ while (current != NULL) {
+ if (current->first_child != NULL)
+ count += count_directives_sub(directive, current->first_child);
+ if (strcasecmp(current->directive, directive) == 0)
+ count++;
+ current = current->next;
+ }
+ return count;
+}
+
+AP_DECLARE(void) ap_reserve_module_slots(int count)
+{
+ reserved_module_slots += count;
+}
+
+AP_DECLARE(void) ap_reserve_module_slots_directive(const char *directive)
+{
+ ap_reserve_module_slots(count_directives_sub(directive, ap_conftree));
+}