1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "apr_strings.h"
20 #include "apr_fnmatch.h"
22 #include "apr_thread_proc.h" /* for RLIMIT stuff */
23 #include "apr_hooks.h"
25 #define APR_WANT_IOVEC
26 #define APR_WANT_STRFUNC
27 #define APR_WANT_MEMFUNC
30 #include "ap_config.h"
32 #include "http_config.h"
33 #include "http_core.h"
34 #include "http_protocol.h" /* For index_of_response(). Grump. */
35 #include "http_request.h"
36 #include "http_vhost.h"
37 #include "http_main.h" /* For the default_handler below... */
40 #include "http_connection.h"
41 #include "apr_buckets.h"
42 #include "util_filter.h"
43 #include "util_ebcdic.h"
44 #include "util_mutex.h"
46 #include "mpm_common.h"
47 #include "scoreboard.h"
49 #include "mod_proxy.h"
50 #include "ap_listen.h"
52 #include "mod_so.h" /* for ap_find_loaded_module_symbol */
54 #if defined(RLIMIT_CPU) || defined (RLIMIT_DATA) || defined (RLIMIT_VMEM) || defined(RLIMIT_AS) || defined (RLIMIT_NPROC)
58 /* LimitRequestBody handling */
59 #define AP_LIMIT_REQ_BODY_UNSET ((apr_off_t) -1)
60 #define AP_DEFAULT_LIMIT_REQ_BODY ((apr_off_t) 0)
62 /* LimitXMLRequestBody handling */
63 #define AP_LIMIT_UNSET ((long) -1)
64 #define AP_DEFAULT_LIMIT_XML_BODY ((size_t)1000000)
66 #define AP_MIN_SENDFILE_BYTES (256)
68 /* maximum include nesting level */
69 #ifndef AP_MAX_INCLUDE_DEPTH
70 #define AP_MAX_INCLUDE_DEPTH (128)
74 APR_HOOK_LINK(get_mgmt_items
)
77 AP_IMPLEMENT_HOOK_RUN_ALL(int, get_mgmt_items
,
78 (apr_pool_t
*p
, const char *val
, apr_hash_t
*ht
),
79 (p
, val
, ht
), OK
, DECLINED
)
81 /* Server core module... This module provides support for really basic
82 * server operations, including options and commands which control the
83 * operation of other modules. Consider this the bureaucracy module.
85 * The core module also defines handlers, etc., to handle just enough
86 * to allow a server with the core module ONLY to actually serve documents.
88 * This file could almost be mod_core.c, except for the stuff which affects
89 * the http_conf_globals.
92 /* Handles for core filters */
93 AP_DECLARE_DATA ap_filter_rec_t
*ap_subreq_core_filter_handle
;
94 AP_DECLARE_DATA ap_filter_rec_t
*ap_core_output_filter_handle
;
95 AP_DECLARE_DATA ap_filter_rec_t
*ap_content_length_filter_handle
;
96 AP_DECLARE_DATA ap_filter_rec_t
*ap_core_input_filter_handle
;
98 /* magic pointer for ErrorDocument xxx "default" */
99 static char errordocument_default
;
101 static void *create_core_dir_config(apr_pool_t
*a
, char *dir
)
103 core_dir_config
*conf
;
105 conf
= (core_dir_config
*)apr_pcalloc(a
, sizeof(core_dir_config
));
107 /* conf->r and conf->d[_*] are initialized by dirsection() or left NULL */
109 conf
->opts
= dir
? OPT_UNSET
: OPT_UNSET
|OPT_ALL
;
110 conf
->opts_add
= conf
->opts_remove
= OPT_NONE
;
111 conf
->override
= dir
? OR_UNSET
: OR_UNSET
|OR_ALL
;
112 conf
->override_opts
= OPT_UNSET
| OPT_ALL
| OPT_INCNOEXEC
| OPT_SYM_OWNER
115 conf
->content_md5
= 2;
116 conf
->accept_path_info
= 3;
118 conf
->use_canonical_name
= USE_CANONICAL_NAME_UNSET
;
119 conf
->use_canonical_phys_port
= USE_CANONICAL_PHYS_PORT_UNSET
;
121 conf
->hostname_lookups
= HOSTNAME_LOOKUP_UNSET
;
124 conf
->limit_cpu
= NULL
;
126 #if defined(RLIMIT_DATA) || defined(RLIMIT_VMEM) || defined(RLIMIT_AS)
127 conf
->limit_mem
= NULL
;
130 conf
->limit_nproc
= NULL
;
133 conf
->limit_req_body
= AP_LIMIT_REQ_BODY_UNSET
;
134 conf
->limit_xml_body
= AP_LIMIT_UNSET
;
135 conf
->sec_file
= apr_array_make(a
, 2, sizeof(ap_conf_vector_t
*));
137 conf
->server_signature
= srv_sig_unset
;
139 conf
->add_default_charset
= ADD_DEFAULT_CHARSET_UNSET
;
140 conf
->add_default_charset_name
= DEFAULT_ADD_DEFAULT_CHARSET_NAME
;
142 /* Overriding all negotiation
144 conf
->mime_type
= NULL
;
145 conf
->handler
= NULL
;
146 conf
->output_filters
= NULL
;
147 conf
->input_filters
= NULL
;
150 * Flag for use of inodes in ETags.
152 conf
->etag_bits
= ETAG_UNSET
;
153 conf
->etag_add
= ETAG_UNSET
;
154 conf
->etag_remove
= ETAG_UNSET
;
156 conf
->enable_mmap
= ENABLE_MMAP_UNSET
;
157 conf
->enable_sendfile
= ENABLE_SENDFILE_UNSET
;
158 conf
->allow_encoded_slashes
= 0;
164 * Overlay one hash table of ct_output_filters onto another
166 static void *merge_ct_filters(apr_pool_t
*p
,
169 const void *overlay_val
,
170 const void *base_val
,
173 ap_filter_rec_t
*cur
;
174 const ap_filter_rec_t
*overlay_info
= (const ap_filter_rec_t
*)overlay_val
;
175 const ap_filter_rec_t
*base_info
= (const ap_filter_rec_t
*)base_val
;
179 while (overlay_info
) {
180 ap_filter_rec_t
*new;
182 new = apr_pcalloc(p
, sizeof(ap_filter_rec_t
));
183 new->name
= apr_pstrdup(p
, overlay_info
->name
);
186 overlay_info
= overlay_info
->next
;
193 /* We can't have dups. */
196 if (!strcasecmp(base_info
->name
, f
->name
)) {
205 f
= apr_pcalloc(p
, sizeof(ap_filter_rec_t
));
206 f
->name
= apr_pstrdup(p
, base_info
->name
);
211 base_info
= base_info
->next
;
217 static void *merge_core_dir_configs(apr_pool_t
*a
, void *basev
, void *newv
)
219 core_dir_config
*base
= (core_dir_config
*)basev
;
220 core_dir_config
*new = (core_dir_config
*)newv
;
221 core_dir_config
*conf
;
224 /* Create this conf by duplicating the base, replacing elements
225 * (or creating copies for merging) where new-> values exist.
227 conf
= (core_dir_config
*)apr_pmemdup(a
, base
, sizeof(core_dir_config
));
230 conf
->d_is_fnmatch
= new->d_is_fnmatch
;
231 conf
->d_components
= new->d_components
;
233 conf
->condition
= new->condition
;
235 if (new->opts
& OPT_UNSET
) {
236 /* there was no explicit setting of new->opts, so we merge
237 * preserve the invariant (opts_add & opts_remove) == 0
239 conf
->opts_add
= (conf
->opts_add
& ~new->opts_remove
) | new->opts_add
;
240 conf
->opts_remove
= (conf
->opts_remove
& ~new->opts_add
)
242 conf
->opts
= (conf
->opts
& ~conf
->opts_remove
) | conf
->opts_add
;
243 if ((base
->opts
& OPT_INCNOEXEC
) && (new->opts
& OPT_INCLUDES
)) {
244 conf
->opts
= (conf
->opts
& ~OPT_INCNOEXEC
) | OPT_INCLUDES
;
248 /* otherwise we just copy, because an explicit opts setting
249 * overrides all earlier +/- modifiers
251 conf
->opts
= new->opts
;
252 conf
->opts_add
= new->opts_add
;
253 conf
->opts_remove
= new->opts_remove
;
256 if (!(new->override
& OR_UNSET
)) {
257 conf
->override
= new->override
;
260 if (!(new->override_opts
& OPT_UNSET
)) {
261 conf
->override_opts
= new->override_opts
;
264 if (conf
->response_code_strings
== NULL
) {
265 conf
->response_code_strings
= new->response_code_strings
;
267 else if (new->response_code_strings
!= NULL
) {
268 /* If we merge, the merge-result must have it's own array
270 conf
->response_code_strings
= apr_pmemdup(a
,
271 base
->response_code_strings
,
272 sizeof(*conf
->response_code_strings
) * RESPONSE_CODES
);
274 for (i
= 0; i
< RESPONSE_CODES
; ++i
) {
275 if (new->response_code_strings
[i
] != NULL
) {
276 conf
->response_code_strings
[i
] = new->response_code_strings
[i
];
280 /* Otherwise we simply use the base->response_code_strings array
283 if (new->hostname_lookups
!= HOSTNAME_LOOKUP_UNSET
) {
284 conf
->hostname_lookups
= new->hostname_lookups
;
287 if ((new->content_md5
& 2) == 0) {
288 conf
->content_md5
= new->content_md5
;
291 if (new->accept_path_info
!= 3) {
292 conf
->accept_path_info
= new->accept_path_info
;
295 if (new->use_canonical_name
!= USE_CANONICAL_NAME_UNSET
) {
296 conf
->use_canonical_name
= new->use_canonical_name
;
299 if (new->use_canonical_phys_port
!= USE_CANONICAL_PHYS_PORT_UNSET
) {
300 conf
->use_canonical_phys_port
= new->use_canonical_phys_port
;
304 if (new->limit_cpu
) {
305 conf
->limit_cpu
= new->limit_cpu
;
309 #if defined(RLIMIT_DATA) || defined(RLIMIT_VMEM) || defined(RLIMIT_AS)
310 if (new->limit_mem
) {
311 conf
->limit_mem
= new->limit_mem
;
316 if (new->limit_nproc
) {
317 conf
->limit_nproc
= new->limit_nproc
;
321 if (new->limit_req_body
!= AP_LIMIT_REQ_BODY_UNSET
) {
322 conf
->limit_req_body
= new->limit_req_body
;
325 if (new->limit_xml_body
!= AP_LIMIT_UNSET
)
326 conf
->limit_xml_body
= new->limit_xml_body
;
328 conf
->limit_xml_body
= base
->limit_xml_body
;
330 if (!conf
->sec_file
) {
331 conf
->sec_file
= new->sec_file
;
333 else if (new->sec_file
) {
334 /* If we merge, the merge-result must have it's own array
336 conf
->sec_file
= apr_array_append(a
, base
->sec_file
, new->sec_file
);
338 /* Otherwise we simply use the base->sec_file array
341 if (new->server_signature
!= srv_sig_unset
) {
342 conf
->server_signature
= new->server_signature
;
345 if (new->add_default_charset
!= ADD_DEFAULT_CHARSET_UNSET
) {
346 conf
->add_default_charset
= new->add_default_charset
;
347 conf
->add_default_charset_name
= new->add_default_charset_name
;
350 /* Overriding all negotiation
352 if (new->mime_type
) {
353 conf
->mime_type
= new->mime_type
;
357 conf
->handler
= new->handler
;
360 if (new->output_filters
) {
361 conf
->output_filters
= new->output_filters
;
364 if (new->input_filters
) {
365 conf
->input_filters
= new->input_filters
;
368 if (conf
->ct_output_filters
&& new->ct_output_filters
) {
369 conf
->ct_output_filters
= apr_hash_merge(a
,
370 new->ct_output_filters
,
371 conf
->ct_output_filters
,
375 else if (new->ct_output_filters
) {
376 conf
->ct_output_filters
= apr_hash_copy(a
, new->ct_output_filters
);
378 else if (conf
->ct_output_filters
) {
379 /* That memcpy above isn't enough. */
380 conf
->ct_output_filters
= apr_hash_copy(a
, base
->ct_output_filters
);
384 * Now merge the setting of the FileETag directive.
386 if (new->etag_bits
== ETAG_UNSET
) {
388 (conf
->etag_add
& (~ new->etag_remove
)) | new->etag_add
;
390 (conf
->etag_remove
& (~ new->etag_add
)) | new->etag_remove
;
392 (conf
->etag_bits
& (~ conf
->etag_remove
)) | conf
->etag_add
;
395 conf
->etag_bits
= new->etag_bits
;
396 conf
->etag_add
= new->etag_add
;
397 conf
->etag_remove
= new->etag_remove
;
400 if (conf
->etag_bits
!= ETAG_NONE
) {
401 conf
->etag_bits
&= (~ ETAG_NONE
);
404 if (new->enable_mmap
!= ENABLE_MMAP_UNSET
) {
405 conf
->enable_mmap
= new->enable_mmap
;
408 if (new->enable_sendfile
!= ENABLE_SENDFILE_UNSET
) {
409 conf
->enable_sendfile
= new->enable_sendfile
;
412 conf
->allow_encoded_slashes
= new->allow_encoded_slashes
;
417 #if APR_HAS_SO_ACCEPTFILTER
418 #ifndef ACCEPT_FILTER_NAME
419 #define ACCEPT_FILTER_NAME "httpready"
420 #ifdef __FreeBSD_version
421 #if __FreeBSD_version < 411000 /* httpready broken before 4.1.1 */
422 #undef ACCEPT_FILTER_NAME
423 #define ACCEPT_FILTER_NAME "dataready"
429 static void *create_core_server_config(apr_pool_t
*a
, server_rec
*s
)
431 core_server_config
*conf
;
432 int is_virtual
= s
->is_virtual
;
434 conf
= (core_server_config
*)apr_pcalloc(a
, sizeof(core_server_config
));
436 /* global-default / global-only settings */
439 conf
->ap_document_root
= DOCUMENT_LOCATION
;
440 conf
->access_name
= DEFAULT_ACCESS_FNAME
;
442 /* A mapping only makes sense in the global context */
443 conf
->accf_map
= apr_table_make(a
, 5);
444 #if APR_HAS_SO_ACCEPTFILTER
445 apr_table_setn(conf
->accf_map
, "http", ACCEPT_FILTER_NAME
);
446 apr_table_setn(conf
->accf_map
, "https", "dataready");
448 apr_table_setn(conf
->accf_map
, "http", "data");
449 apr_table_setn(conf
->accf_map
, "https", "data");
452 /* pcalloc'ed - we have NULL's/0's
453 else ** is_virtual ** {
454 conf->ap_document_root = NULL;
455 conf->access_name = NULL;
456 conf->accf_map = NULL;
460 /* initialization, no special case for global context */
462 conf
->sec_dir
= apr_array_make(a
, 40, sizeof(ap_conf_vector_t
*));
463 conf
->sec_url
= apr_array_make(a
, 40, sizeof(ap_conf_vector_t
*));
465 /* pcalloc'ed - we have NULL's/0's
466 conf->gprof_dir = NULL;
468 ** recursion stopper; 0 == unset
469 conf->redirect_limit = 0;
470 conf->subreq_limit = 0;
472 conf->protocol = NULL;
475 conf
->trace_enable
= AP_TRACE_UNSET
;
480 static void *merge_core_server_configs(apr_pool_t
*p
, void *basev
, void *virtv
)
482 core_server_config
*base
= (core_server_config
*)basev
;
483 core_server_config
*virt
= (core_server_config
*)virtv
;
484 core_server_config
*conf
= (core_server_config
*)
485 apr_pmemdup(p
, base
, sizeof(core_server_config
));
487 if (virt
->ap_document_root
)
488 conf
->ap_document_root
= virt
->ap_document_root
;
490 if (virt
->access_name
)
491 conf
->access_name
= virt
->access_name
;
493 /* XXX optimize to keep base->sec_ pointers if virt->sec_ array is empty */
494 conf
->sec_dir
= apr_array_append(p
, base
->sec_dir
, virt
->sec_dir
);
495 conf
->sec_url
= apr_array_append(p
, base
->sec_url
, virt
->sec_url
);
497 if (virt
->redirect_limit
)
498 conf
->redirect_limit
= virt
->redirect_limit
;
500 if (virt
->subreq_limit
)
501 conf
->subreq_limit
= virt
->subreq_limit
;
503 if (virt
->trace_enable
!= AP_TRACE_UNSET
)
504 conf
->trace_enable
= virt
->trace_enable
;
506 /* no action for virt->accf_map, not allowed per-vhost */
509 conf
->protocol
= virt
->protocol
;
512 conf
->gprof_dir
= virt
->gprof_dir
;
517 /* Add per-directory configuration entry (for <directory> section);
518 * these are part of the core server config.
521 AP_CORE_DECLARE(void) ap_add_per_dir_conf(server_rec
*s
, void *dir_config
)
523 core_server_config
*sconf
= ap_get_module_config(s
->module_config
,
525 void **new_space
= (void **)apr_array_push(sconf
->sec_dir
);
527 *new_space
= dir_config
;
530 AP_CORE_DECLARE(void) ap_add_per_url_conf(server_rec
*s
, void *url_config
)
532 core_server_config
*sconf
= ap_get_module_config(s
->module_config
,
534 void **new_space
= (void **)apr_array_push(sconf
->sec_url
);
536 *new_space
= url_config
;
539 AP_CORE_DECLARE(void) ap_add_file_conf(core_dir_config
*conf
, void *url_config
)
541 void **new_space
= (void **)apr_array_push(conf
->sec_file
);
543 *new_space
= url_config
;
546 /* We need to do a stable sort, qsort isn't stable. So to make it stable
547 * we'll be maintaining the original index into the list, and using it
548 * as the minor key during sorting. The major key is the number of
549 * components (where the root component is zero).
551 struct reorder_sort_rec
{
552 ap_conf_vector_t
*elt
;
556 static int reorder_sorter(const void *va
, const void *vb
)
558 const struct reorder_sort_rec
*a
= va
;
559 const struct reorder_sort_rec
*b
= vb
;
560 core_dir_config
*core_a
;
561 core_dir_config
*core_b
;
563 core_a
= ap_get_module_config(a
->elt
, &core_module
);
564 core_b
= ap_get_module_config(b
->elt
, &core_module
);
566 /* a regex always sorts after a non-regex
568 if (!core_a
->r
&& core_b
->r
) {
571 else if (core_a
->r
&& !core_b
->r
) {
575 /* we always sort next by the number of components
577 if (core_a
->d_components
< core_b
->d_components
) {
580 else if (core_a
->d_components
> core_b
->d_components
) {
584 /* They have the same number of components, we now have to compare
585 * the minor key to maintain the original order (from the config.)
587 return a
->orig_index
- b
->orig_index
;
590 void ap_core_reorder_directories(apr_pool_t
*p
, server_rec
*s
)
592 core_server_config
*sconf
;
593 apr_array_header_t
*sec_dir
;
594 struct reorder_sort_rec
*sortbin
;
596 ap_conf_vector_t
**elts
;
600 sconf
= ap_get_module_config(s
->module_config
, &core_module
);
601 sec_dir
= sconf
->sec_dir
;
602 nelts
= sec_dir
->nelts
;
603 elts
= (ap_conf_vector_t
**)sec_dir
->elts
;
606 /* simple case of already being sorted... */
607 /* We're not checking this condition to be fast... we're checking
608 * it to avoid trying to palloc zero bytes, which can trigger some
609 * memory debuggers to barf
614 /* we have to allocate tmp space to do a stable sort */
615 apr_pool_create(&tmp
, p
);
616 sortbin
= apr_palloc(tmp
, sec_dir
->nelts
* sizeof(*sortbin
));
617 for (i
= 0; i
< nelts
; ++i
) {
618 sortbin
[i
].orig_index
= i
;
619 sortbin
[i
].elt
= elts
[i
];
622 qsort(sortbin
, nelts
, sizeof(*sortbin
), reorder_sorter
);
624 /* and now copy back to the original array */
625 for (i
= 0; i
< nelts
; ++i
) {
626 elts
[i
] = sortbin
[i
].elt
;
629 apr_pool_destroy(tmp
);
632 /*****************************************************************
634 * There are some elements of the core config structures in which
635 * other modules have a legitimate interest (this is ugly, but necessary
636 * to preserve NCSA back-compatibility). So, we have a bunch of accessors
640 AP_DECLARE(int) ap_allow_options(request_rec
*r
)
642 core_dir_config
*conf
=
643 (core_dir_config
*)ap_get_module_config(r
->per_dir_config
, &core_module
);
648 AP_DECLARE(int) ap_allow_overrides(request_rec
*r
)
650 core_dir_config
*conf
;
651 conf
= (core_dir_config
*)ap_get_module_config(r
->per_dir_config
,
654 return conf
->override
;
658 * Optional function coming from mod_authn_core, used for
659 * retrieving the type of autorization
661 static APR_OPTIONAL_FN_TYPE(authn_ap_auth_type
) *authn_ap_auth_type
;
663 AP_DECLARE(const char *) ap_auth_type(request_rec
*r
)
665 if (authn_ap_auth_type
) {
666 return authn_ap_auth_type(r
);
672 * Optional function coming from mod_authn_core, used for
673 * retrieving the authorization realm
675 static APR_OPTIONAL_FN_TYPE(authn_ap_auth_name
) *authn_ap_auth_name
;
677 AP_DECLARE(const char *) ap_auth_name(request_rec
*r
)
679 if (authn_ap_auth_name
) {
680 return authn_ap_auth_name(r
);
686 * Optional function coming from mod_access_compat, used to determine how
687 access control interacts with authentication/authorization
689 static APR_OPTIONAL_FN_TYPE(access_compat_ap_satisfies
) *access_compat_ap_satisfies
;
691 AP_DECLARE(int) ap_satisfies(request_rec
*r
)
693 if (access_compat_ap_satisfies
) {
694 return access_compat_ap_satisfies(r
);
696 return SATISFY_NOSPEC
;
699 AP_DECLARE(const char *) ap_document_root(request_rec
*r
) /* Don't use this! */
701 core_server_config
*conf
;
703 conf
= (core_server_config
*)ap_get_module_config(r
->server
->module_config
,
706 return conf
->ap_document_root
;
709 /* Should probably just get rid of this... the only code that cares is
710 * part of the core anyway (and in fact, it isn't publicised to other
714 char *ap_response_code_string(request_rec
*r
, int error_index
)
716 core_dir_config
*dirconf
;
717 core_request_config
*reqconf
;
719 /* check for string registered via ap_custom_response() first */
720 reqconf
= (core_request_config
*)ap_get_module_config(r
->request_config
,
722 if (reqconf
->response_code_strings
!= NULL
&&
723 reqconf
->response_code_strings
[error_index
] != NULL
) {
724 return reqconf
->response_code_strings
[error_index
];
727 /* check for string specified via ErrorDocument */
728 dirconf
= (core_dir_config
*)ap_get_module_config(r
->per_dir_config
,
731 if (dirconf
->response_code_strings
== NULL
) {
735 if (dirconf
->response_code_strings
[error_index
] == &errordocument_default
) {
739 return dirconf
->response_code_strings
[error_index
];
743 /* Code from Harald Hanche-Olsen <hanche@imf.unit.no> */
744 static APR_INLINE
void do_double_reverse (conn_rec
*conn
)
749 if (conn
->double_reverse
) {
754 if (conn
->remote_host
== NULL
|| conn
->remote_host
[0] == '\0') {
755 /* single reverse failed, so don't bother */
756 conn
->double_reverse
= -1;
760 rv
= apr_sockaddr_info_get(&sa
, conn
->remote_host
, APR_UNSPEC
, 0, 0, conn
->pool
);
761 if (rv
== APR_SUCCESS
) {
763 if (apr_sockaddr_equal(sa
, conn
->remote_addr
)) {
764 conn
->double_reverse
= 1;
772 conn
->double_reverse
= -1;
775 AP_DECLARE(const char *) ap_get_remote_host(conn_rec
*conn
, void *dir_config
,
776 int type
, int *str_is_ip
)
778 int hostname_lookups
;
779 int ignored_str_is_ip
;
781 if (!str_is_ip
) { /* caller doesn't want to know */
782 str_is_ip
= &ignored_str_is_ip
;
786 /* If we haven't checked the host name, and we want to */
789 ((core_dir_config
*)ap_get_module_config(dir_config
, &core_module
))
792 if (hostname_lookups
== HOSTNAME_LOOKUP_UNSET
) {
793 hostname_lookups
= HOSTNAME_LOOKUP_OFF
;
798 hostname_lookups
= HOSTNAME_LOOKUP_OFF
;
801 if (type
!= REMOTE_NOLOOKUP
802 && conn
->remote_host
== NULL
803 && (type
== REMOTE_DOUBLE_REV
804 || hostname_lookups
!= HOSTNAME_LOOKUP_OFF
)) {
806 if (apr_getnameinfo(&conn
->remote_host
, conn
->remote_addr
, 0)
808 ap_str_tolower(conn
->remote_host
);
810 if (hostname_lookups
== HOSTNAME_LOOKUP_DOUBLE
) {
811 do_double_reverse(conn
);
812 if (conn
->double_reverse
!= 1) {
813 conn
->remote_host
= NULL
;
818 /* if failed, set it to the NULL string to indicate error */
819 if (conn
->remote_host
== NULL
) {
820 conn
->remote_host
= "";
824 if (type
== REMOTE_DOUBLE_REV
) {
825 do_double_reverse(conn
);
826 if (conn
->double_reverse
== -1) {
832 * Return the desired information; either the remote DNS name, if found,
833 * or either NULL (if the hostname was requested) or the IP address
834 * (if any identifier was requested).
836 if (conn
->remote_host
!= NULL
&& conn
->remote_host
[0] != '\0') {
837 return conn
->remote_host
;
840 if (type
== REMOTE_HOST
|| type
== REMOTE_DOUBLE_REV
) {
845 return conn
->remote_ip
;
851 * Optional function coming from mod_ident, used for looking up ident user
853 static APR_OPTIONAL_FN_TYPE(ap_ident_lookup
) *ident_lookup
;
855 AP_DECLARE(const char *) ap_get_remote_logname(request_rec
*r
)
857 if (r
->connection
->remote_logname
!= NULL
) {
858 return r
->connection
->remote_logname
;
862 return ident_lookup(r
);
868 /* There are two options regarding what the "name" of a server is. The
869 * "canonical" name as defined by ServerName and Port, or the "client's
870 * name" as supplied by a possible Host: header or full URI.
872 * The DNS option to UseCanonicalName causes this routine to do a
873 * reverse lookup on the local IP address of the connection and use
874 * that for the ServerName. This makes its value more reliable while
875 * at the same time allowing Demon's magic virtual hosting to work.
876 * The assumption is that DNS lookups are sufficiently quick...
879 AP_DECLARE(const char *) ap_get_server_name(request_rec
*r
)
881 conn_rec
*conn
= r
->connection
;
885 d
= (core_dir_config
*)ap_get_module_config(r
->per_dir_config
,
888 switch (d
->use_canonical_name
) {
889 case USE_CANONICAL_NAME_ON
:
890 retval
= r
->server
->server_hostname
;
892 case USE_CANONICAL_NAME_DNS
:
893 if (conn
->local_host
== NULL
) {
894 if (apr_getnameinfo(&conn
->local_host
,
895 conn
->local_addr
, 0) != APR_SUCCESS
)
896 conn
->local_host
= apr_pstrdup(conn
->pool
,
897 r
->server
->server_hostname
);
899 ap_str_tolower(conn
->local_host
);
902 retval
= conn
->local_host
;
904 case USE_CANONICAL_NAME_OFF
:
905 case USE_CANONICAL_NAME_UNSET
:
906 retval
= r
->hostname
? r
->hostname
: r
->server
->server_hostname
;
909 ap_log_rerror(APLOG_MARK
, APLOG_ERR
, 0, r
,
910 "ap_get_server_name: Invalid UCN Option somehow");
911 retval
= "localhost";
918 * Get the current server name from the request for the purposes
919 * of using in a URL. If the server name is an IPv6 literal
920 * address, it will be returned in URL format (e.g., "[fe80::1]").
922 static const char *get_server_name_for_url(request_rec
*r
)
924 const char *plain_server_name
= ap_get_server_name(r
);
927 if (ap_strchr_c(plain_server_name
, ':')) { /* IPv6 literal? */
928 return apr_psprintf(r
->pool
, "[%s]", plain_server_name
);
931 return plain_server_name
;
934 AP_DECLARE(apr_port_t
) ap_get_server_port(const request_rec
*r
)
938 (core_dir_config
*)ap_get_module_config(r
->per_dir_config
, &core_module
);
940 switch (d
->use_canonical_name
) {
941 case USE_CANONICAL_NAME_OFF
:
942 case USE_CANONICAL_NAME_DNS
:
943 case USE_CANONICAL_NAME_UNSET
:
944 if (d
->use_canonical_phys_port
== USE_CANONICAL_PHYS_PORT_ON
)
945 port
= r
->parsed_uri
.port_str
? r
->parsed_uri
.port
:
946 r
->connection
->local_addr
->port
? r
->connection
->local_addr
->port
:
947 r
->server
->port
? r
->server
->port
:
949 else /* USE_CANONICAL_PHYS_PORT_OFF or USE_CANONICAL_PHYS_PORT_UNSET */
950 port
= r
->parsed_uri
.port_str
? r
->parsed_uri
.port
:
951 r
->server
->port
? r
->server
->port
:
954 case USE_CANONICAL_NAME_ON
:
955 /* With UseCanonicalName on (and in all versions prior to 1.3)
956 * Apache will use the hostname and port specified in the
957 * ServerName directive to construct a canonical name for the
958 * server. (If no port was specified in the ServerName
959 * directive, Apache uses the port supplied by the client if
960 * any is supplied, and finally the default port for the protocol
963 if (d
->use_canonical_phys_port
== USE_CANONICAL_PHYS_PORT_ON
)
964 port
= r
->server
->port
? r
->server
->port
:
965 r
->connection
->local_addr
->port
? r
->connection
->local_addr
->port
:
967 else /* USE_CANONICAL_PHYS_PORT_OFF or USE_CANONICAL_PHYS_PORT_UNSET */
968 port
= r
->server
->port
? r
->server
->port
:
972 ap_log_rerror(APLOG_MARK
, APLOG_ERR
, 0, r
,
973 "ap_get_server_port: Invalid UCN Option somehow");
974 port
= ap_default_port(r
);
981 AP_DECLARE(char *) ap_construct_url(apr_pool_t
*p
, const char *uri
,
984 unsigned port
= ap_get_server_port(r
);
985 const char *host
= get_server_name_for_url(r
);
987 if (ap_is_default_port(port
, r
)) {
988 return apr_pstrcat(p
, ap_http_scheme(r
), "://", host
, uri
, NULL
);
991 return apr_psprintf(p
, "%s://%s:%u%s", ap_http_scheme(r
), host
, port
, uri
);
994 AP_DECLARE(apr_off_t
) ap_get_limit_req_body(const request_rec
*r
)
997 (core_dir_config
*)ap_get_module_config(r
->per_dir_config
, &core_module
);
999 if (d
->limit_req_body
== AP_LIMIT_REQ_BODY_UNSET
) {
1000 return AP_DEFAULT_LIMIT_REQ_BODY
;
1003 return d
->limit_req_body
;
1007 /*****************************************************************
1009 * Commands... this module handles almost all of the NCSA httpd.conf
1010 * commands, but most of the old srm.conf is in the the modules.
1014 /* returns a parent if it matches the given directive */
1015 static const ap_directive_t
* find_parent(const ap_directive_t
*dirp
,
1018 while (dirp
->parent
!= NULL
) {
1019 dirp
= dirp
->parent
;
1021 /* ### it would be nice to have atom-ized directives */
1022 if (strcasecmp(dirp
->directive
, what
) == 0)
1029 AP_DECLARE(const char *) ap_check_cmd_context(cmd_parms
*cmd
,
1032 const char *gt
= (cmd
->cmd
->name
[0] == '<'
1033 && cmd
->cmd
->name
[strlen(cmd
->cmd
->name
)-1] != '>')
1035 const ap_directive_t
*found
;
1037 if ((forbidden
& NOT_IN_VIRTUALHOST
) && cmd
->server
->is_virtual
) {
1038 return apr_pstrcat(cmd
->pool
, cmd
->cmd
->name
, gt
,
1039 " cannot occur within <VirtualHost> section", NULL
);
1042 if ((forbidden
& (NOT_IN_LIMIT
| NOT_IN_DIR_LOC_FILE
))
1043 && cmd
->limited
!= -1) {
1044 return apr_pstrcat(cmd
->pool
, cmd
->cmd
->name
, gt
,
1045 " cannot occur within <Limit> or <LimitExcept> "
1049 if ((forbidden
& NOT_IN_DIR_LOC_FILE
) == NOT_IN_DIR_LOC_FILE
) {
1050 if (cmd
->path
!= NULL
) {
1051 return apr_pstrcat(cmd
->pool
, cmd
->cmd
->name
, gt
,
1052 " cannot occur within <Directory/Location/Files> "
1055 if (cmd
->cmd
->req_override
& EXEC_ON_READ
) {
1056 /* EXEC_ON_READ must be NOT_IN_DIR_LOC_FILE, if not, it will
1057 * (deliberately) segfault below in the individual tests...
1063 if (((forbidden
& NOT_IN_DIRECTORY
)
1064 && ((found
= find_parent(cmd
->directive
, "<Directory"))
1065 || (found
= find_parent(cmd
->directive
, "<DirectoryMatch"))))
1066 || ((forbidden
& NOT_IN_LOCATION
)
1067 && ((found
= find_parent(cmd
->directive
, "<Location"))
1068 || (found
= find_parent(cmd
->directive
, "<LocationMatch"))))
1069 || ((forbidden
& NOT_IN_FILES
)
1070 && ((found
= find_parent(cmd
->directive
, "<Files"))
1071 || (found
= find_parent(cmd
->directive
, "<FilesMatch"))))) {
1072 return apr_pstrcat(cmd
->pool
, cmd
->cmd
->name
, gt
,
1073 " cannot occur within ", found
->directive
,
1080 static const char *set_access_name(cmd_parms
*cmd
, void *dummy
,
1083 void *sconf
= cmd
->server
->module_config
;
1084 core_server_config
*conf
= ap_get_module_config(sconf
, &core_module
);
1086 const char *err
= ap_check_cmd_context(cmd
, NOT_IN_DIR_LOC_FILE
);
1091 conf
->access_name
= apr_pstrdup(cmd
->pool
, arg
);
1096 static const char *set_define(cmd_parms
*cmd
, void *dummy
,
1101 const char *err
= ap_check_cmd_context(cmd
,
1107 newv
= (char **)apr_array_push(ap_server_config_defines
);
1108 *newv
= apr_pstrdup(cmd
->pool
, optarg
);
1114 static const char *set_gprof_dir(cmd_parms
*cmd
, void *dummy
, const char *arg
)
1116 void *sconf
= cmd
->server
->module_config
;
1117 core_server_config
*conf
= ap_get_module_config(sconf
, &core_module
);
1119 const char *err
= ap_check_cmd_context(cmd
, NOT_IN_DIR_LOC_FILE
);
1124 conf
->gprof_dir
= apr_pstrdup(cmd
->pool
, arg
);
1129 static const char *set_add_default_charset(cmd_parms
*cmd
,
1130 void *d_
, const char *arg
)
1132 core_dir_config
*d
= d_
;
1134 if (!strcasecmp(arg
, "Off")) {
1135 d
->add_default_charset
= ADD_DEFAULT_CHARSET_OFF
;
1137 else if (!strcasecmp(arg
, "On")) {
1138 d
->add_default_charset
= ADD_DEFAULT_CHARSET_ON
;
1139 d
->add_default_charset_name
= DEFAULT_ADD_DEFAULT_CHARSET_NAME
;
1142 d
->add_default_charset
= ADD_DEFAULT_CHARSET_ON
;
1143 d
->add_default_charset_name
= arg
;
1149 static const char *set_document_root(cmd_parms
*cmd
, void *dummy
,
1152 void *sconf
= cmd
->server
->module_config
;
1153 core_server_config
*conf
= ap_get_module_config(sconf
, &core_module
);
1155 const char *err
= ap_check_cmd_context(cmd
, NOT_IN_DIR_LOC_FILE
);
1160 /* Make it absolute, relative to ServerRoot */
1161 arg
= ap_server_root_relative(cmd
->pool
, arg
);
1163 return "DocumentRoot must be a directory";
1166 /* TODO: ap_configtestonly && ap_docrootcheck && */
1167 if (apr_filepath_merge((char**)&conf
->ap_document_root
, NULL
, arg
,
1168 APR_FILEPATH_TRUENAME
, cmd
->pool
) != APR_SUCCESS
1169 || !ap_is_directory(cmd
->pool
, arg
)) {
1170 if (cmd
->server
->is_virtual
) {
1171 ap_log_perror(APLOG_MARK
, APLOG_STARTUP
, 0,
1173 "Warning: DocumentRoot [%s] does not exist",
1175 conf
->ap_document_root
= arg
;
1178 return "DocumentRoot must be a directory";
1184 AP_DECLARE(void) ap_custom_response(request_rec
*r
, int status
,
1187 core_request_config
*conf
=
1188 ap_get_module_config(r
->request_config
, &core_module
);
1191 if (conf
->response_code_strings
== NULL
) {
1192 conf
->response_code_strings
=
1193 apr_pcalloc(r
->pool
,
1194 sizeof(*conf
->response_code_strings
) * RESPONSE_CODES
);
1197 idx
= ap_index_of_response(status
);
1199 conf
->response_code_strings
[idx
] =
1200 ((ap_is_url(string
) || (*string
== '/')) && (*string
!= '"')) ?
1201 apr_pstrdup(r
->pool
, string
) : apr_pstrcat(r
->pool
, "\"", string
, NULL
);
1204 static const char *set_error_document(cmd_parms
*cmd
, void *conf_
,
1205 const char *errno_str
, const char *msg
)
1207 core_dir_config
*conf
= conf_
;
1208 int error_number
, index_number
, idx500
;
1209 enum { MSG
, LOCAL_PATH
, REMOTE_PATH
} what
= MSG
;
1211 /* 1st parameter should be a 3 digit number, which we recognize;
1212 * convert it into an array index
1214 error_number
= atoi(errno_str
);
1215 idx500
= ap_index_of_response(HTTP_INTERNAL_SERVER_ERROR
);
1217 if (error_number
== HTTP_INTERNAL_SERVER_ERROR
) {
1218 index_number
= idx500
;
1220 else if ((index_number
= ap_index_of_response(error_number
)) == idx500
) {
1221 return apr_pstrcat(cmd
->pool
, "Unsupported HTTP response code ",
1225 /* Heuristic to determine second argument. */
1226 if (ap_strchr_c(msg
,' '))
1228 else if (msg
[0] == '/')
1230 else if (ap_is_url(msg
))
1235 /* The entry should be ignored if it is a full URL for a 401 error */
1237 if (error_number
== 401 && what
== REMOTE_PATH
) {
1238 ap_log_error(APLOG_MARK
, APLOG_NOTICE
, 0, cmd
->server
,
1239 "cannot use a full URL in a 401 ErrorDocument "
1240 "directive --- ignoring!");
1242 else { /* Store it... */
1243 if (conf
->response_code_strings
== NULL
) {
1244 conf
->response_code_strings
=
1245 apr_pcalloc(cmd
->pool
,
1246 sizeof(*conf
->response_code_strings
) *
1250 if (strcmp(msg
, "default") == 0) {
1251 /* special case: ErrorDocument 404 default restores the
1252 * canned server error response
1254 conf
->response_code_strings
[index_number
] = &errordocument_default
;
1257 /* hack. Prefix a " if it is a msg; as that is what
1258 * http_protocol.c relies on to distinguish between
1259 * a msg and a (local) path.
1261 conf
->response_code_strings
[index_number
] = (what
== MSG
) ?
1262 apr_pstrcat(cmd
->pool
, "\"",msg
,NULL
) :
1263 apr_pstrdup(cmd
->pool
, msg
);
1270 static const char *set_allow_opts(cmd_parms
*cmd
, allow_options_t
*opts
,
1273 allow_options_t opt
;
1276 char *w
, *p
= (char *) l
;
1279 while ((w
= apr_strtok(p
, ",", &tok_state
)) != NULL
) {
1287 if (!strcasecmp(w
, "Indexes")) {
1290 else if (!strcasecmp(w
, "Includes")) {
1293 else if (!strcasecmp(w
, "IncludesNOEXEC")) {
1294 opt
= (OPT_INCLUDES
| OPT_INCNOEXEC
);
1296 else if (!strcasecmp(w
, "FollowSymLinks")) {
1297 opt
= OPT_SYM_LINKS
;
1299 else if (!strcasecmp(w
, "SymLinksIfOwnerMatch")) {
1300 opt
= OPT_SYM_OWNER
;
1302 else if (!strcasecmp(w
, "ExecCGI")) {
1305 else if (!strcasecmp(w
, "MultiViews")) {
1308 else if (!strcasecmp(w
, "RunScripts")) { /* AI backcompat. Yuck */
1309 opt
= OPT_MULTI
|OPT_EXECCGI
;
1311 else if (!strcasecmp(w
, "None")) {
1314 else if (!strcasecmp(w
, "All")) {
1318 return apr_pstrcat(cmd
->pool
, "Illegal option ", w
, NULL
);
1324 (*opts
) &= (~OPT_UNSET
);
1329 static const char *set_override(cmd_parms
*cmd
, void *d_
, const char *l
)
1331 core_dir_config
*d
= d_
;
1335 /* Throw a warning if we're in <Location> or <Files> */
1336 if (ap_check_cmd_context(cmd
, NOT_IN_LOCATION
| NOT_IN_FILES
)) {
1337 ap_log_error(APLOG_MARK
, APLOG_WARNING
, 0, cmd
->server
,
1338 "Useless use of AllowOverride in line %d of %s.",
1339 cmd
->directive
->line_num
, cmd
->directive
->filename
);
1342 d
->override
= OR_NONE
;
1344 w
= ap_getword_conf(cmd
->pool
, &l
);
1352 if (!strcasecmp(w
, "Limit")) {
1353 d
->override
|= OR_LIMIT
;
1355 else if (!strcasecmp(k
, "Options")) {
1356 d
->override
|= OR_OPTIONS
;
1358 set_allow_opts(cmd
, &(d
->override_opts
), v
);
1360 d
->override_opts
= OPT_ALL
;
1362 else if (!strcasecmp(w
, "FileInfo")) {
1363 d
->override
|= OR_FILEINFO
;
1365 else if (!strcasecmp(w
, "AuthConfig")) {
1366 d
->override
|= OR_AUTHCFG
;
1368 else if (!strcasecmp(w
, "Indexes")) {
1369 d
->override
|= OR_INDEXES
;
1371 else if (!strcasecmp(w
, "None")) {
1372 d
->override
= OR_NONE
;
1374 else if (!strcasecmp(w
, "All")) {
1375 d
->override
= OR_ALL
;
1378 return apr_pstrcat(cmd
->pool
, "Illegal override option ", w
, NULL
);
1381 d
->override
&= ~OR_UNSET
;
1387 static const char *set_options(cmd_parms
*cmd
, void *d_
, const char *l
)
1389 core_dir_config
*d
= d_
;
1390 allow_options_t opt
;
1395 char *w
= ap_getword_conf(cmd
->pool
, &l
);
1398 if (*w
== '+' || *w
== '-') {
1406 if (!strcasecmp(w
, "Indexes")) {
1409 else if (!strcasecmp(w
, "Includes")) {
1412 else if (!strcasecmp(w
, "IncludesNOEXEC")) {
1413 opt
= (OPT_INCLUDES
| OPT_INCNOEXEC
);
1415 else if (!strcasecmp(w
, "FollowSymLinks")) {
1416 opt
= OPT_SYM_LINKS
;
1418 else if (!strcasecmp(w
, "SymLinksIfOwnerMatch")) {
1419 opt
= OPT_SYM_OWNER
;
1421 else if (!strcasecmp(w
, "ExecCGI")) {
1424 else if (!strcasecmp(w
, "MultiViews")) {
1427 else if (!strcasecmp(w
, "RunScripts")) { /* AI backcompat. Yuck */
1428 opt
= OPT_MULTI
|OPT_EXECCGI
;
1430 else if (!strcasecmp(w
, "None")) {
1433 else if (!strcasecmp(w
, "All")) {
1437 return apr_pstrcat(cmd
->pool
, "Illegal option ", w
, NULL
);
1440 if ( (cmd
->override_opts
& opt
) != opt
) {
1441 return apr_pstrcat(cmd
->pool
, "Option ", w
, " not allowed here", NULL
);
1443 else if (action
== '-') {
1444 /* we ensure the invariant (d->opts_add & d->opts_remove) == 0 */
1445 d
->opts_remove
|= opt
;
1446 d
->opts_add
&= ~opt
;
1449 else if (action
== '+') {
1451 d
->opts_remove
&= ~opt
;
1462 static const char *set_default_type(cmd_parms
*cmd
, void *d_
,
1465 if ((strcasecmp(arg
, "off") != 0) && (strcasecmp(arg
, "none") != 0)) {
1466 ap_log_error(APLOG_MARK
, APLOG_WARNING
, 0, cmd
->server
,
1467 "Ignoring deprecated use of DefaultType in line %d of %s.",
1468 cmd
->directive
->line_num
, cmd
->directive
->filename
);
1475 * Note what data should be used when forming file ETag values.
1476 * It would be nicer to do this as an ITERATE, but then we couldn't
1477 * remember the +/- state properly.
1479 static const char *set_etag_bits(cmd_parms
*cmd
, void *mconfig
,
1482 core_dir_config
*cfg
;
1483 etag_components_t bit
;
1491 cfg
= (core_dir_config
*)mconfig
;
1496 while (args
[0] != '\0') {
1500 token
= ap_getword_conf(cmd
->pool
, &args
);
1501 if ((*token
== '+') || (*token
== '-')) {
1507 * The occurrence of an absolute setting wipes
1508 * out any previous relative ones. The first such
1509 * occurrence forgets any inherited ones, too.
1512 cfg
->etag_bits
= ETAG_UNSET
;
1513 cfg
->etag_add
= ETAG_UNSET
;
1514 cfg
->etag_remove
= ETAG_UNSET
;
1519 if (strcasecmp(token
, "None") == 0) {
1520 if (action
!= '*') {
1524 cfg
->etag_bits
= bit
= ETAG_NONE
;
1528 else if (strcasecmp(token
, "All") == 0) {
1529 if (action
!= '*') {
1534 cfg
->etag_bits
= bit
= ETAG_ALL
;
1537 else if (strcasecmp(token
, "Size") == 0) {
1540 else if ((strcasecmp(token
, "LMTime") == 0)
1541 || (strcasecmp(token
, "MTime") == 0)
1542 || (strcasecmp(token
, "LastModified") == 0)) {
1545 else if (strcasecmp(token
, "INode") == 0) {
1549 return apr_pstrcat(cmd
->pool
, "Unknown keyword '",
1550 token
, "' for ", cmd
->cmd
->name
,
1551 " directive", NULL
);
1555 return apr_pstrcat(cmd
->pool
, cmd
->cmd
->name
, " keyword '",
1556 token
, "' cannot be used with '+' or '-'",
1560 if (action
== '+') {
1562 * Make sure it's in the 'add' list and absent from the
1565 cfg
->etag_add
|= bit
;
1566 cfg
->etag_remove
&= (~ bit
);
1568 else if (action
== '-') {
1569 cfg
->etag_remove
|= bit
;
1570 cfg
->etag_add
&= (~ bit
);
1574 * Non-relative values wipe out any + or - values
1575 * accumulated so far.
1577 cfg
->etag_bits
|= bit
;
1578 cfg
->etag_add
= ETAG_UNSET
;
1579 cfg
->etag_remove
= ETAG_UNSET
;
1585 * Any setting at all will clear the 'None' and 'Unset' bits.
1588 if (cfg
->etag_add
!= ETAG_UNSET
) {
1589 cfg
->etag_add
&= (~ ETAG_UNSET
);
1592 if (cfg
->etag_remove
!= ETAG_UNSET
) {
1593 cfg
->etag_remove
&= (~ ETAG_UNSET
);
1597 cfg
->etag_bits
&= (~ ETAG_UNSET
);
1599 if ((cfg
->etag_bits
& ETAG_NONE
) != ETAG_NONE
) {
1600 cfg
->etag_bits
&= (~ ETAG_NONE
);
1607 static const char *set_enable_mmap(cmd_parms
*cmd
, void *d_
,
1610 core_dir_config
*d
= d_
;
1612 if (strcasecmp(arg
, "on") == 0) {
1613 d
->enable_mmap
= ENABLE_MMAP_ON
;
1615 else if (strcasecmp(arg
, "off") == 0) {
1616 d
->enable_mmap
= ENABLE_MMAP_OFF
;
1619 return "parameter must be 'on' or 'off'";
1625 static const char *set_enable_sendfile(cmd_parms
*cmd
, void *d_
,
1628 core_dir_config
*d
= d_
;
1630 if (strcasecmp(arg
, "on") == 0) {
1631 d
->enable_sendfile
= ENABLE_SENDFILE_ON
;
1633 else if (strcasecmp(arg
, "off") == 0) {
1634 d
->enable_sendfile
= ENABLE_SENDFILE_OFF
;
1637 return "parameter must be 'on' or 'off'";
1645 * Report a missing-'>' syntax error.
1647 static char *unclosed_directive(cmd_parms
*cmd
)
1649 return apr_pstrcat(cmd
->pool
, cmd
->cmd
->name
,
1650 "> directive missing closing '>'", NULL
);
1654 * Report a missing args in '<Foo >' syntax error.
1656 static char *missing_container_arg(cmd_parms
*cmd
)
1658 return apr_pstrcat(cmd
->pool
, cmd
->cmd
->name
,
1659 "> directive requires additional arguments", NULL
);
1662 AP_CORE_DECLARE_NONSTD(const char *) ap_limit_section(cmd_parms
*cmd
,
1666 const char *endp
= ap_strrchr_c(arg
, '>');
1667 const char *limited_methods
;
1668 void *tog
= cmd
->cmd
->cmd_data
;
1669 apr_int64_t limited
= 0;
1670 apr_int64_t old_limited
= cmd
->limited
;
1674 return unclosed_directive(cmd
);
1677 limited_methods
= apr_pstrndup(cmd
->pool
, arg
, endp
- arg
);
1679 if (!limited_methods
[0]) {
1680 return missing_container_arg(cmd
);
1683 while (limited_methods
[0]) {
1684 char *method
= ap_getword_conf(cmd
->pool
, &limited_methods
);
1687 /* check for builtin or module registered method number */
1688 methnum
= ap_method_number_of(method
);
1690 if (methnum
== M_TRACE
&& !tog
) {
1691 return "TRACE cannot be controlled by <Limit>, see TraceEnable";
1693 else if (methnum
== M_INVALID
) {
1694 /* method has not been registered yet, but resorce restriction
1695 * is always checked before method handling, so register it.
1697 methnum
= ap_method_register(cmd
->pool
, method
);
1700 limited
|= (AP_METHOD_BIT
<< methnum
);
1703 /* Killing two features with one function,
1704 * if (tog == NULL) <Limit>, else <LimitExcept>
1706 limited
= tog
? ~limited
: limited
;
1708 if (!(old_limited
& limited
)) {
1709 return apr_pstrcat(cmd
->pool
, cmd
->cmd
->name
,
1710 "> directive excludes all methods", NULL
);
1712 else if ((old_limited
& limited
) == old_limited
) {
1713 return apr_pstrcat(cmd
->pool
, cmd
->cmd
->name
,
1714 "> directive specifies methods already excluded",
1718 cmd
->limited
&= limited
;
1720 errmsg
= ap_walk_config(cmd
->directive
->first_child
, cmd
, cmd
->context
);
1722 cmd
->limited
= old_limited
;
1727 /* XXX: Bogus - need to do this differently (at least OS2/Netware suffer
1728 * the same problem!!!
1729 * We use this in <DirectoryMatch> and <FilesMatch>, to ensure that
1730 * people don't get bitten by wrong-cased regex matches
1734 #define USE_ICASE AP_REG_ICASE
1739 static const char *dirsection(cmd_parms
*cmd
, void *mconfig
, const char *arg
)
1742 const char *endp
= ap_strrchr_c(arg
, '>');
1743 int old_overrides
= cmd
->override
;
1744 char *old_path
= cmd
->path
;
1745 core_dir_config
*conf
;
1746 ap_conf_vector_t
*new_dir_conf
= ap_create_per_dir_config(cmd
->pool
);
1747 ap_regex_t
*r
= NULL
;
1748 const command_rec
*thiscmd
= cmd
->cmd
;
1750 const char *err
= ap_check_cmd_context(cmd
, NOT_IN_DIR_LOC_FILE
);
1756 return unclosed_directive(cmd
);
1759 arg
= apr_pstrndup(cmd
->pool
, arg
, endp
- arg
);
1762 return missing_container_arg(cmd
);
1766 if (thiscmd
->cmd_data
)
1767 return "<DirectoryMatch > block must specify a path";
1769 return "<Directory > block must specify a path";
1772 cmd
->path
= ap_getword_conf(cmd
->pool
, &arg
);
1773 cmd
->override
= OR_ALL
|ACCESS_CONF
;
1775 if (!strcmp(cmd
->path
, "~")) {
1776 cmd
->path
= ap_getword_conf(cmd
->pool
, &arg
);
1778 return "<Directory ~ > block must specify a path";
1779 r
= ap_pregcomp(cmd
->pool
, cmd
->path
, AP_REG_EXTENDED
|USE_ICASE
);
1781 return "Regex could not be compiled";
1784 else if (thiscmd
->cmd_data
) { /* <DirectoryMatch> */
1785 r
= ap_pregcomp(cmd
->pool
, cmd
->path
, AP_REG_EXTENDED
|USE_ICASE
);
1787 return "Regex could not be compiled";
1790 else if (!strcmp(cmd
->path
, "/") == 0)
1795 * Ensure that the pathname is canonical, and append the trailing /
1797 apr_status_t rv
= apr_filepath_merge(&newpath
, NULL
, cmd
->path
,
1798 APR_FILEPATH_TRUENAME
, cmd
->pool
);
1799 if (rv
!= APR_SUCCESS
&& rv
!= APR_EPATHWILD
) {
1800 return apr_pstrcat(cmd
->pool
, "<Directory \"", cmd
->path
,
1801 "\"> path is invalid.", NULL
);
1804 cmd
->path
= newpath
;
1805 if (cmd
->path
[strlen(cmd
->path
) - 1] != '/')
1806 cmd
->path
= apr_pstrcat(cmd
->pool
, cmd
->path
, "/", NULL
);
1809 /* initialize our config and fetch it */
1810 conf
= ap_set_config_vectors(cmd
->server
, new_dir_conf
, cmd
->path
,
1811 &core_module
, cmd
->pool
);
1813 errmsg
= ap_walk_config(cmd
->directive
->first_child
, cmd
, new_dir_conf
);
1818 conf
->d
= cmd
->path
;
1819 conf
->d_is_fnmatch
= (apr_fnmatch_test(conf
->d
) != 0);
1821 /* Make this explicit - the "/" root has 0 elements, that is, we
1822 * will always merge it, and it will always sort and merge first.
1823 * All others are sorted and tested by the number of slashes.
1825 if (strcmp(conf
->d
, "/") == 0)
1826 conf
->d_components
= 0;
1828 conf
->d_components
= ap_count_dirs(conf
->d
);
1830 ap_add_per_dir_conf(cmd
->server
, new_dir_conf
);
1833 return apr_pstrcat(cmd
->pool
, "Multiple ", thiscmd
->name
,
1834 "> arguments not (yet) supported.", NULL
);
1837 cmd
->path
= old_path
;
1838 cmd
->override
= old_overrides
;
1843 static const char *urlsection(cmd_parms
*cmd
, void *mconfig
, const char *arg
)
1846 const char *endp
= ap_strrchr_c(arg
, '>');
1847 int old_overrides
= cmd
->override
;
1848 char *old_path
= cmd
->path
;
1849 core_dir_config
*conf
;
1850 ap_regex_t
*r
= NULL
;
1851 const command_rec
*thiscmd
= cmd
->cmd
;
1852 ap_conf_vector_t
*new_url_conf
= ap_create_per_dir_config(cmd
->pool
);
1853 const char *err
= ap_check_cmd_context(cmd
, NOT_IN_DIR_LOC_FILE
);
1859 return unclosed_directive(cmd
);
1862 arg
= apr_pstrndup(cmd
->pool
, arg
, endp
- arg
);
1865 return missing_container_arg(cmd
);
1868 cmd
->path
= ap_getword_conf(cmd
->pool
, &arg
);
1869 cmd
->override
= OR_ALL
|ACCESS_CONF
;
1871 if (thiscmd
->cmd_data
) { /* <LocationMatch> */
1872 r
= ap_pregcomp(cmd
->pool
, cmd
->path
, AP_REG_EXTENDED
);
1874 return "Regex could not be compiled";
1877 else if (!strcmp(cmd
->path
, "~")) {
1878 cmd
->path
= ap_getword_conf(cmd
->pool
, &arg
);
1879 r
= ap_pregcomp(cmd
->pool
, cmd
->path
, AP_REG_EXTENDED
);
1881 return "Regex could not be compiled";
1885 /* initialize our config and fetch it */
1886 conf
= ap_set_config_vectors(cmd
->server
, new_url_conf
, cmd
->path
,
1887 &core_module
, cmd
->pool
);
1889 errmsg
= ap_walk_config(cmd
->directive
->first_child
, cmd
, new_url_conf
);
1893 conf
->d
= apr_pstrdup(cmd
->pool
, cmd
->path
); /* No mangling, please */
1894 conf
->d_is_fnmatch
= apr_fnmatch_test(conf
->d
) != 0;
1897 ap_add_per_url_conf(cmd
->server
, new_url_conf
);
1900 return apr_pstrcat(cmd
->pool
, "Multiple ", thiscmd
->name
,
1901 "> arguments not (yet) supported.", NULL
);
1904 cmd
->path
= old_path
;
1905 cmd
->override
= old_overrides
;
1910 static const char *filesection(cmd_parms
*cmd
, void *mconfig
, const char *arg
)
1913 const char *endp
= ap_strrchr_c(arg
, '>');
1914 int old_overrides
= cmd
->override
;
1915 char *old_path
= cmd
->path
;
1916 core_dir_config
*conf
;
1917 ap_regex_t
*r
= NULL
;
1918 const command_rec
*thiscmd
= cmd
->cmd
;
1919 core_dir_config
*c
= mconfig
;
1920 ap_conf_vector_t
*new_file_conf
= ap_create_per_dir_config(cmd
->pool
);
1921 const char *err
= ap_check_cmd_context(cmd
,
1922 NOT_IN_LOCATION
| NOT_IN_LIMIT
);
1929 return unclosed_directive(cmd
);
1932 arg
= apr_pstrndup(cmd
->pool
, arg
, endp
- arg
);
1935 return missing_container_arg(cmd
);
1938 cmd
->path
= ap_getword_conf(cmd
->pool
, &arg
);
1939 /* Only if not an .htaccess file */
1941 cmd
->override
= OR_ALL
|ACCESS_CONF
;
1944 if (thiscmd
->cmd_data
) { /* <FilesMatch> */
1945 r
= ap_pregcomp(cmd
->pool
, cmd
->path
, AP_REG_EXTENDED
|USE_ICASE
);
1947 return "Regex could not be compiled";
1950 else if (!strcmp(cmd
->path
, "~")) {
1951 cmd
->path
= ap_getword_conf(cmd
->pool
, &arg
);
1952 r
= ap_pregcomp(cmd
->pool
, cmd
->path
, AP_REG_EXTENDED
|USE_ICASE
);
1954 return "Regex could not be compiled";
1959 /* Ensure that the pathname is canonical, but we
1960 * can't test the case/aliases without a fixed path */
1961 if (apr_filepath_merge(&newpath
, "", cmd
->path
,
1962 0, cmd
->pool
) != APR_SUCCESS
)
1963 return apr_pstrcat(cmd
->pool
, "<Files \"", cmd
->path
,
1964 "\"> is invalid.", NULL
);
1965 cmd
->path
= newpath
;
1968 /* initialize our config and fetch it */
1969 conf
= ap_set_config_vectors(cmd
->server
, new_file_conf
, cmd
->path
,
1970 &core_module
, cmd
->pool
);
1972 errmsg
= ap_walk_config(cmd
->directive
->first_child
, cmd
, new_file_conf
);
1976 conf
->d
= cmd
->path
;
1977 conf
->d_is_fnmatch
= apr_fnmatch_test(conf
->d
) != 0;
1980 ap_add_file_conf(c
, new_file_conf
);
1983 return apr_pstrcat(cmd
->pool
, "Multiple ", thiscmd
->name
,
1984 "> arguments not (yet) supported.", NULL
);
1987 cmd
->path
= old_path
;
1988 cmd
->override
= old_overrides
;
1992 static const char *ifsection(cmd_parms
*cmd
, void *mconfig
, const char *arg
)
1995 const char *endp
= ap_strrchr_c(arg
, '>');
1996 int old_overrides
= cmd
->override
;
1997 char *old_path
= cmd
->path
;
1998 core_dir_config
*conf
;
1999 const command_rec
*thiscmd
= cmd
->cmd
;
2000 core_dir_config
*c
= mconfig
;
2001 ap_conf_vector_t
*new_file_conf
= ap_create_per_dir_config(cmd
->pool
);
2002 const char *err
= ap_check_cmd_context(cmd
,
2003 NOT_IN_LOCATION
| NOT_IN_LIMIT
);
2004 const char *condition
;
2012 return unclosed_directive(cmd
);
2015 arg
= apr_pstrndup(cmd
->pool
, arg
, endp
- arg
);
2018 return missing_container_arg(cmd
);
2021 condition
= ap_getword_conf(cmd
->pool
, &arg
);
2022 /* Only if not an .htaccess file */
2024 cmd
->override
= OR_ALL
|ACCESS_CONF
;
2027 /* initialize our config and fetch it */
2028 conf
= ap_set_config_vectors(cmd
->server
, new_file_conf
, cmd
->path
,
2029 &core_module
, cmd
->pool
);
2031 conf
->condition
= ap_expr_parse(cmd
->pool
, condition
, &expr_err
);
2033 return "Cannot parse condition clause";
2036 errmsg
= ap_walk_config(cmd
->directive
->first_child
, cmd
, new_file_conf
);
2040 conf
->d
= cmd
->path
;
2041 conf
->d_is_fnmatch
= 0;
2044 ap_add_file_conf(c
, new_file_conf
);
2047 return apr_pstrcat(cmd
->pool
, "Multiple ", thiscmd
->name
,
2048 "> arguments not supported.", NULL
);
2051 cmd
->path
= old_path
;
2052 cmd
->override
= old_overrides
;
2057 static const char *start_ifmod(cmd_parms
*cmd
, void *mconfig
, const char *arg
)
2059 const char *endp
= ap_strrchr_c(arg
, '>');
2060 int not = (arg
[0] == '!');
2064 return unclosed_directive(cmd
);
2067 arg
= apr_pstrndup(cmd
->pool
, arg
, endp
- arg
);
2074 return missing_container_arg(cmd
);
2077 found
= ap_find_linked_module(arg
);
2079 /* search prelinked stuff */
2081 ap_module_symbol_t
*current
= ap_prelinked_module_symbols
;
2083 for (; current
->name
; ++current
) {
2084 if (!strcmp(current
->name
, arg
)) {
2085 found
= current
->modp
;
2091 /* search dynamic stuff */
2093 APR_OPTIONAL_FN_TYPE(ap_find_loaded_module_symbol
) *check_symbol
=
2094 APR_RETRIEVE_OPTIONAL_FN(ap_find_loaded_module_symbol
);
2097 found
= check_symbol(cmd
->server
, arg
);
2101 if ((!not && found
) || (not && !found
)) {
2102 ap_directive_t
*parent
= NULL
;
2103 ap_directive_t
*current
= NULL
;
2106 retval
= ap_build_cont_config(cmd
->pool
, cmd
->temp_pool
, cmd
,
2107 ¤t
, &parent
, "<IfModule");
2108 *(ap_directive_t
**)mconfig
= current
;
2112 *(ap_directive_t
**)mconfig
= NULL
;
2113 return ap_soak_end_container(cmd
, "<IfModule");
2117 AP_DECLARE(int) ap_exists_config_define(const char *name
)
2122 defines
= (char **)ap_server_config_defines
->elts
;
2123 for (i
= 0; i
< ap_server_config_defines
->nelts
; i
++) {
2124 if (strcmp(defines
[i
], name
) == 0) {
2132 static const char *start_ifdefine(cmd_parms
*cmd
, void *dummy
, const char *arg
)
2138 endp
= ap_strrchr_c(arg
, '>');
2140 return unclosed_directive(cmd
);
2143 arg
= apr_pstrndup(cmd
->pool
, arg
, endp
- arg
);
2145 if (arg
[0] == '!') {
2151 return missing_container_arg(cmd
);
2154 defined
= ap_exists_config_define(arg
);
2155 if ((!not && defined
) || (not && !defined
)) {
2156 ap_directive_t
*parent
= NULL
;
2157 ap_directive_t
*current
= NULL
;
2160 retval
= ap_build_cont_config(cmd
->pool
, cmd
->temp_pool
, cmd
,
2161 ¤t
, &parent
, "<IfDefine");
2162 *(ap_directive_t
**)dummy
= current
;
2166 *(ap_directive_t
**)dummy
= NULL
;
2167 return ap_soak_end_container(cmd
, "<IfDefine");
2171 /* httpd.conf commands... beginning with the <VirtualHost> business */
2173 static const char *virtualhost_section(cmd_parms
*cmd
, void *dummy
,
2176 server_rec
*main_server
= cmd
->server
, *s
;
2178 const char *endp
= ap_strrchr_c(arg
, '>');
2179 apr_pool_t
*p
= cmd
->pool
;
2181 const char *err
= ap_check_cmd_context(cmd
, GLOBAL_ONLY
);
2187 return unclosed_directive(cmd
);
2190 arg
= apr_pstrndup(cmd
->pool
, arg
, endp
- arg
);
2193 return missing_container_arg(cmd
);
2196 /* FIXME: There's another feature waiting to happen here -- since you
2197 can now put multiple addresses/names on a single <VirtualHost>
2198 you might want to use it to group common definitions and then
2199 define other "subhosts" with their individual differences. But
2200 personally I'd rather just do it with a macro preprocessor. -djg */
2201 if (main_server
->is_virtual
) {
2202 return "<VirtualHost> doesn't nest!";
2205 errmsg
= ap_init_virtual_host(p
, arg
, main_server
, &s
);
2210 s
->next
= main_server
->next
;
2211 main_server
->next
= s
;
2213 s
->defn_name
= cmd
->directive
->filename
;
2214 s
->defn_line_number
= cmd
->directive
->line_num
;
2218 errmsg
= ap_walk_config(cmd
->directive
->first_child
, cmd
,
2219 s
->lookup_defaults
);
2221 cmd
->server
= main_server
;
2226 static const char *set_server_alias(cmd_parms
*cmd
, void *dummy
,
2229 if (!cmd
->server
->names
) {
2230 return "ServerAlias only used in <VirtualHost>";
2234 char **item
, *name
= ap_getword_conf(cmd
->pool
, &arg
);
2236 if (ap_is_matchexp(name
)) {
2237 item
= (char **)apr_array_push(cmd
->server
->wild_names
);
2240 item
= (char **)apr_array_push(cmd
->server
->names
);
2249 static const char *set_accf_map(cmd_parms
*cmd
, void *dummy
,
2250 const char *iproto
, const char* iaccf
)
2252 const char *err
= ap_check_cmd_context(cmd
, GLOBAL_ONLY
);
2253 core_server_config
*conf
= ap_get_module_config(cmd
->server
->module_config
,
2261 proto
= apr_pstrdup(cmd
->pool
, iproto
);
2262 ap_str_tolower(proto
);
2263 accf
= apr_pstrdup(cmd
->pool
, iaccf
);
2264 ap_str_tolower(accf
);
2265 apr_table_setn(conf
->accf_map
, proto
, accf
);
2270 AP_DECLARE(const char*) ap_get_server_protocol(server_rec
* s
)
2272 core_server_config
*conf
= ap_get_module_config(s
->module_config
,
2274 return conf
->protocol
;
2277 AP_DECLARE(void) ap_set_server_protocol(server_rec
* s
, const char* proto
)
2279 core_server_config
*conf
= ap_get_module_config(s
->module_config
,
2281 conf
->protocol
= proto
;
2284 static const char *set_protocol(cmd_parms
*cmd
, void *dummy
,
2287 const char *err
= ap_check_cmd_context(cmd
, NOT_IN_DIR_LOC_FILE
);
2288 core_server_config
*conf
= ap_get_module_config(cmd
->server
->module_config
,
2296 proto
= apr_pstrdup(cmd
->pool
, arg
);
2297 ap_str_tolower(proto
);
2298 conf
->protocol
= proto
;
2303 static const char *set_server_string_slot(cmd_parms
*cmd
, void *dummy
,
2306 /* This one's pretty generic... */
2308 int offset
= (int)(long)cmd
->info
;
2309 char *struct_ptr
= (char *)cmd
->server
;
2311 const char *err
= ap_check_cmd_context(cmd
,
2312 NOT_IN_DIR_LOC_FILE
);
2317 *(const char **)(struct_ptr
+ offset
) = arg
;
2322 * The ServerName directive takes one argument with format
2323 * [scheme://]fully-qualified-domain-name[:port], for instance
2324 * ServerName www.example.com
2325 * ServerName www.example.com:80
2326 * ServerName https://www.example.com:443
2329 static const char *server_hostname_port(cmd_parms
*cmd
, void *dummy
, const char *arg
)
2331 const char *err
= ap_check_cmd_context(cmd
, NOT_IN_DIR_LOC_FILE
);
2332 const char *portstr
, *part
;
2340 part
= ap_strstr_c(arg
, "://");
2343 scheme
= apr_pstrndup(cmd
->pool
, arg
, part
- arg
);
2344 ap_str_tolower(scheme
);
2345 cmd
->server
->server_scheme
= (const char *)scheme
;
2351 portstr
= ap_strchr_c(part
, ':');
2353 cmd
->server
->server_hostname
= apr_pstrndup(cmd
->pool
, part
,
2356 port
= atoi(portstr
);
2357 if (port
<= 0 || port
>= 65536) { /* 65536 == 1<<16 */
2358 return apr_pstrcat(cmd
->temp_pool
, "The port number \"", arg
,
2359 "\" is outside the appropriate range "
2360 "(i.e., 1..65535).", NULL
);
2364 cmd
->server
->server_hostname
= apr_pstrdup(cmd
->pool
, part
);
2368 cmd
->server
->port
= port
;
2372 static const char *set_signature_flag(cmd_parms
*cmd
, void *d_
,
2375 core_dir_config
*d
= d_
;
2377 if (strcasecmp(arg
, "On") == 0) {
2378 d
->server_signature
= srv_sig_on
;
2380 else if (strcasecmp(arg
, "Off") == 0) {
2381 d
->server_signature
= srv_sig_off
;
2383 else if (strcasecmp(arg
, "EMail") == 0) {
2384 d
->server_signature
= srv_sig_withmail
;
2387 return "ServerSignature: use one of: off | on | email";
2393 static const char *set_server_root(cmd_parms
*cmd
, void *dummy
,
2396 const char *err
= ap_check_cmd_context(cmd
, GLOBAL_ONLY
);
2402 if ((apr_filepath_merge((char**)&ap_server_root
, NULL
, arg
,
2403 APR_FILEPATH_TRUENAME
, cmd
->pool
) != APR_SUCCESS
)
2404 || !ap_is_directory(cmd
->pool
, ap_server_root
)) {
2405 return "ServerRoot must be a valid directory";
2411 static const char *set_timeout(cmd_parms
*cmd
, void *dummy
, const char *arg
)
2413 const char *err
= ap_check_cmd_context(cmd
, NOT_IN_DIR_LOC_FILE
);
2419 cmd
->server
->timeout
= apr_time_from_sec(atoi(arg
));
2423 static const char *set_allow2f(cmd_parms
*cmd
, void *d_
, int arg
)
2425 core_dir_config
*d
= d_
;
2427 d
->allow_encoded_slashes
= arg
!= 0;
2431 static const char *set_hostname_lookups(cmd_parms
*cmd
, void *d_
,
2434 core_dir_config
*d
= d_
;
2436 if (!strcasecmp(arg
, "on")) {
2437 d
->hostname_lookups
= HOSTNAME_LOOKUP_ON
;
2439 else if (!strcasecmp(arg
, "off")) {
2440 d
->hostname_lookups
= HOSTNAME_LOOKUP_OFF
;
2442 else if (!strcasecmp(arg
, "double")) {
2443 d
->hostname_lookups
= HOSTNAME_LOOKUP_DOUBLE
;
2446 return "parameter must be 'on', 'off', or 'double'";
2452 static const char *set_serverpath(cmd_parms
*cmd
, void *dummy
,
2455 const char *err
= ap_check_cmd_context(cmd
, NOT_IN_DIR_LOC_FILE
);
2461 cmd
->server
->path
= arg
;
2462 cmd
->server
->pathlen
= (int)strlen(arg
);
2466 static const char *set_content_md5(cmd_parms
*cmd
, void *d_
, int arg
)
2468 core_dir_config
*d
= d_
;
2470 d
->content_md5
= arg
!= 0;
2474 static const char *set_accept_path_info(cmd_parms
*cmd
, void *d_
, const char *arg
)
2476 core_dir_config
*d
= d_
;
2478 if (strcasecmp(arg
, "on") == 0) {
2479 d
->accept_path_info
= AP_REQ_ACCEPT_PATH_INFO
;
2481 else if (strcasecmp(arg
, "off") == 0) {
2482 d
->accept_path_info
= AP_REQ_REJECT_PATH_INFO
;
2484 else if (strcasecmp(arg
, "default") == 0) {
2485 d
->accept_path_info
= AP_REQ_DEFAULT_PATH_INFO
;
2488 return "AcceptPathInfo must be set to on, off or default";
2494 static const char *set_use_canonical_name(cmd_parms
*cmd
, void *d_
,
2497 core_dir_config
*d
= d_
;
2499 if (strcasecmp(arg
, "on") == 0) {
2500 d
->use_canonical_name
= USE_CANONICAL_NAME_ON
;
2502 else if (strcasecmp(arg
, "off") == 0) {
2503 d
->use_canonical_name
= USE_CANONICAL_NAME_OFF
;
2505 else if (strcasecmp(arg
, "dns") == 0) {
2506 d
->use_canonical_name
= USE_CANONICAL_NAME_DNS
;
2509 return "parameter must be 'on', 'off', or 'dns'";
2515 static const char *set_use_canonical_phys_port(cmd_parms
*cmd
, void *d_
,
2518 core_dir_config
*d
= d_
;
2520 if (strcasecmp(arg
, "on") == 0) {
2521 d
->use_canonical_phys_port
= USE_CANONICAL_PHYS_PORT_ON
;
2523 else if (strcasecmp(arg
, "off") == 0) {
2524 d
->use_canonical_phys_port
= USE_CANONICAL_PHYS_PORT_OFF
;
2527 return "parameter must be 'on' or 'off'";
2534 static const char *include_config (cmd_parms
*cmd
, void *dummy
,
2537 ap_directive_t
*conftree
= NULL
;
2538 const char* conffile
, *error
;
2539 unsigned *recursion
;
2542 apr_pool_userdata_get(&data
, "ap_include_sentinel", cmd
->pool
);
2547 data
= recursion
= apr_palloc(cmd
->pool
, sizeof(*recursion
));
2549 apr_pool_userdata_setn(data
, "ap_include_sentinel", NULL
, cmd
->pool
);
2552 if (++*recursion
> AP_MAX_INCLUDE_DEPTH
) {
2554 return apr_psprintf(cmd
->pool
, "Exceeded maximum include depth of %u. "
2555 "You have probably a recursion somewhere.",
2556 AP_MAX_INCLUDE_DEPTH
);
2559 conffile
= ap_server_root_relative(cmd
->pool
, name
);
2562 return apr_pstrcat(cmd
->pool
, "Invalid Include path ",
2566 error
= ap_process_resource_config(cmd
->server
, conffile
,
2567 &conftree
, cmd
->pool
, cmd
->temp_pool
);
2573 *(ap_directive_t
**)dummy
= conftree
;
2575 /* recursion level done */
2583 static const char *set_loglevel(cmd_parms
*cmd
, void *dummy
, const char *arg
)
2587 const char *err
= ap_check_cmd_context(cmd
, NOT_IN_DIR_LOC_FILE
);
2592 if ((str
= ap_getword_conf(cmd
->pool
, &arg
))) {
2593 if (!strcasecmp(str
, "emerg")) {
2594 cmd
->server
->loglevel
= APLOG_EMERG
;
2596 else if (!strcasecmp(str
, "alert")) {
2597 cmd
->server
->loglevel
= APLOG_ALERT
;
2599 else if (!strcasecmp(str
, "crit")) {
2600 cmd
->server
->loglevel
= APLOG_CRIT
;
2602 else if (!strcasecmp(str
, "error")) {
2603 cmd
->server
->loglevel
= APLOG_ERR
;
2605 else if (!strcasecmp(str
, "warn")) {
2606 cmd
->server
->loglevel
= APLOG_WARNING
;
2608 else if (!strcasecmp(str
, "notice")) {
2609 cmd
->server
->loglevel
= APLOG_NOTICE
;
2611 else if (!strcasecmp(str
, "info")) {
2612 cmd
->server
->loglevel
= APLOG_INFO
;
2614 else if (!strcasecmp(str
, "debug")) {
2615 cmd
->server
->loglevel
= APLOG_DEBUG
;
2618 return "LogLevel requires level keyword: one of "
2619 "emerg/alert/crit/error/warn/notice/info/debug";
2623 return "LogLevel requires level keyword";
2629 AP_DECLARE(const char *) ap_psignature(const char *prefix
, request_rec
*r
)
2632 core_dir_config
*conf
;
2634 conf
= (core_dir_config
*)ap_get_module_config(r
->per_dir_config
,
2636 if ((conf
->server_signature
== srv_sig_off
)
2637 || (conf
->server_signature
== srv_sig_unset
)) {
2641 apr_snprintf(sport
, sizeof sport
, "%u", (unsigned) ap_get_server_port(r
));
2643 if (conf
->server_signature
== srv_sig_withmail
) {
2644 return apr_pstrcat(r
->pool
, prefix
, "<address>",
2645 ap_get_server_banner(),
2646 " Server at <a href=\"",
2647 ap_is_url(r
->server
->server_admin
) ? "" : "mailto:",
2648 ap_escape_html(r
->pool
, r
->server
->server_admin
),
2650 ap_escape_html(r
->pool
, ap_get_server_name(r
)),
2651 "</a> Port ", sport
,
2652 "</address>\n", NULL
);
2655 return apr_pstrcat(r
->pool
, prefix
, "<address>", ap_get_server_banner(),
2657 ap_escape_html(r
->pool
, ap_get_server_name(r
)),
2659 "</address>\n", NULL
);
2663 * Handle a request to include the server's OS platform in the Server
2664 * response header field (the ServerTokens directive). Unfortunately
2665 * this requires a new global in order to communicate the setting back to
2666 * http_main so it can insert the information in the right place in the
2670 static char *server_banner
= NULL
;
2671 static int banner_locked
= 0;
2672 static char *server_description
= NULL
;
2674 enum server_token_type
{
2675 SrvTk_MAJOR
, /* eg: Apache/2 */
2676 SrvTk_MINOR
, /* eg. Apache/2.0 */
2677 SrvTk_MINIMAL
, /* eg: Apache/2.0.41 */
2678 SrvTk_OS
, /* eg: Apache/2.0.41 (UNIX) */
2679 SrvTk_FULL
, /* eg: Apache/2.0.41 (UNIX) PHP/4.2.2 FooBar/1.2b */
2680 SrvTk_PRODUCT_ONLY
/* eg: Apache */
2682 static enum server_token_type ap_server_tokens
= SrvTk_FULL
;
2684 static apr_status_t
reset_banner(void *dummy
)
2687 ap_server_tokens
= SrvTk_FULL
;
2688 server_banner
= NULL
;
2689 server_description
= NULL
;
2693 AP_DECLARE(void) ap_get_server_revision(ap_version_t
*version
)
2695 version
->major
= AP_SERVER_MAJORVERSION_NUMBER
;
2696 version
->minor
= AP_SERVER_MINORVERSION_NUMBER
;
2697 version
->patch
= AP_SERVER_PATCHLEVEL_NUMBER
;
2698 version
->add_string
= AP_SERVER_ADD_STRING
;
2701 AP_DECLARE(const char *) ap_get_server_description(void)
2703 return server_description
? server_description
:
2704 AP_SERVER_BASEVERSION
" (" PLATFORM
")";
2707 AP_DECLARE(const char *) ap_get_server_banner(void)
2709 return server_banner
? server_banner
: AP_SERVER_BASEVERSION
;
2712 AP_DECLARE(void) ap_add_version_component(apr_pool_t
*pconf
, const char *component
)
2714 if (! banner_locked
) {
2716 * If the version string is null, register our cleanup to reset the
2717 * pointer on pool destruction. We also know that, if NULL,
2718 * we are adding the original SERVER_BASEVERSION string.
2720 if (server_banner
== NULL
) {
2721 apr_pool_cleanup_register(pconf
, NULL
, reset_banner
,
2722 apr_pool_cleanup_null
);
2723 server_banner
= apr_pstrdup(pconf
, component
);
2727 * Tack the given component identifier to the end of
2728 * the existing string.
2730 server_banner
= apr_pstrcat(pconf
, server_banner
, " ",
2734 server_description
= apr_pstrcat(pconf
, server_description
, " ",
2739 * This routine adds the real server base identity to the banner string,
2740 * and then locks out changes until the next reconfig.
2742 static void set_banner(apr_pool_t
*pconf
)
2744 if (ap_server_tokens
== SrvTk_PRODUCT_ONLY
) {
2745 ap_add_version_component(pconf
, AP_SERVER_BASEPRODUCT
);
2747 else if (ap_server_tokens
== SrvTk_MINIMAL
) {
2748 ap_add_version_component(pconf
, AP_SERVER_BASEVERSION
);
2750 else if (ap_server_tokens
== SrvTk_MINOR
) {
2751 ap_add_version_component(pconf
, AP_SERVER_BASEPRODUCT
"/" AP_SERVER_MINORREVISION
);
2753 else if (ap_server_tokens
== SrvTk_MAJOR
) {
2754 ap_add_version_component(pconf
, AP_SERVER_BASEPRODUCT
"/" AP_SERVER_MAJORVERSION
);
2757 ap_add_version_component(pconf
, AP_SERVER_BASEVERSION
" (" PLATFORM
")");
2761 * Lock the server_banner string if we're not displaying
2762 * the full set of tokens
2764 if (ap_server_tokens
!= SrvTk_FULL
) {
2767 server_description
= AP_SERVER_BASEVERSION
" (" PLATFORM
")";
2770 static const char *set_serv_tokens(cmd_parms
*cmd
, void *dummy
,
2773 const char *err
= ap_check_cmd_context(cmd
, GLOBAL_ONLY
);
2779 if (!strcasecmp(arg
, "OS")) {
2780 ap_server_tokens
= SrvTk_OS
;
2782 else if (!strcasecmp(arg
, "Min") || !strcasecmp(arg
, "Minimal")) {
2783 ap_server_tokens
= SrvTk_MINIMAL
;
2785 else if (!strcasecmp(arg
, "Major")) {
2786 ap_server_tokens
= SrvTk_MAJOR
;
2788 else if (!strcasecmp(arg
, "Minor") ) {
2789 ap_server_tokens
= SrvTk_MINOR
;
2791 else if (!strcasecmp(arg
, "Prod") || !strcasecmp(arg
, "ProductOnly")) {
2792 ap_server_tokens
= SrvTk_PRODUCT_ONLY
;
2795 ap_server_tokens
= SrvTk_FULL
;
2801 static const char *set_limit_req_line(cmd_parms
*cmd
, void *dummy
,
2804 const char *err
= ap_check_cmd_context(cmd
, NOT_IN_DIR_LOC_FILE
);
2813 return apr_pstrcat(cmd
->temp_pool
, "LimitRequestLine \"", arg
,
2814 "\" must be a non-negative integer", NULL
);
2817 cmd
->server
->limit_req_line
= lim
;
2821 static const char *set_limit_req_fieldsize(cmd_parms
*cmd
, void *dummy
,
2824 const char *err
= ap_check_cmd_context(cmd
, NOT_IN_DIR_LOC_FILE
);
2833 return apr_pstrcat(cmd
->temp_pool
, "LimitRequestFieldsize \"", arg
,
2834 "\" must be a non-negative integer",
2838 cmd
->server
->limit_req_fieldsize
= lim
;
2842 static const char *set_limit_req_fields(cmd_parms
*cmd
, void *dummy
,
2845 const char *err
= ap_check_cmd_context(cmd
, NOT_IN_DIR_LOC_FILE
);
2854 return apr_pstrcat(cmd
->temp_pool
, "LimitRequestFields \"", arg
,
2855 "\" must be a non-negative integer (0 = no limit)",
2859 cmd
->server
->limit_req_fields
= lim
;
2863 static const char *set_limit_req_body(cmd_parms
*cmd
, void *conf_
,
2866 core_dir_config
*conf
= conf_
;
2869 if (APR_SUCCESS
!= apr_strtoff(&conf
->limit_req_body
, arg
, &errp
, 10)) {
2870 return "LimitRequestBody argument is not parsable.";
2872 if (*errp
|| conf
->limit_req_body
< 0) {
2873 return "LimitRequestBody requires a non-negative integer.";
2879 static const char *set_limit_xml_req_body(cmd_parms
*cmd
, void *conf_
,
2882 core_dir_config
*conf
= conf_
;
2884 conf
->limit_xml_body
= atol(arg
);
2885 if (conf
->limit_xml_body
< 0)
2886 return "LimitXMLRequestBody requires a non-negative integer.";
2891 AP_DECLARE(size_t) ap_get_limit_xml_body(const request_rec
*r
)
2893 core_dir_config
*conf
;
2895 conf
= ap_get_module_config(r
->per_dir_config
, &core_module
);
2896 if (conf
->limit_xml_body
== AP_LIMIT_UNSET
)
2897 return AP_DEFAULT_LIMIT_XML_BODY
;
2899 return (size_t)conf
->limit_xml_body
;
2902 #if !defined (RLIMIT_CPU) || !(defined (RLIMIT_DATA) || defined (RLIMIT_VMEM) || defined(RLIMIT_AS)) || !defined (RLIMIT_NPROC)
2903 static const char *no_set_limit(cmd_parms
*cmd
, void *conf_
,
2904 const char *arg
, const char *arg2
)
2906 ap_log_error(APLOG_MARK
, APLOG_ERR
, 0, cmd
->server
,
2907 "%s not supported on this platform", cmd
->cmd
->name
);
2914 static const char *set_limit_cpu(cmd_parms
*cmd
, void *conf_
,
2915 const char *arg
, const char *arg2
)
2917 core_dir_config
*conf
= conf_
;
2919 ap_unixd_set_rlimit(cmd
, &conf
->limit_cpu
, arg
, arg2
, RLIMIT_CPU
);
2924 #if defined (RLIMIT_DATA) || defined (RLIMIT_VMEM) || defined(RLIMIT_AS)
2925 static const char *set_limit_mem(cmd_parms
*cmd
, void *conf_
,
2926 const char *arg
, const char * arg2
)
2928 core_dir_config
*conf
= conf_
;
2930 #if defined(RLIMIT_AS)
2931 ap_unixd_set_rlimit(cmd
, &conf
->limit_mem
, arg
, arg2
,RLIMIT_AS
);
2932 #elif defined(RLIMIT_DATA)
2933 ap_unixd_set_rlimit(cmd
, &conf
->limit_mem
, arg
, arg2
, RLIMIT_DATA
);
2934 #elif defined(RLIMIT_VMEM)
2935 ap_unixd_set_rlimit(cmd
, &conf
->limit_mem
, arg
, arg2
, RLIMIT_VMEM
);
2943 static const char *set_limit_nproc(cmd_parms
*cmd
, void *conf_
,
2944 const char *arg
, const char * arg2
)
2946 core_dir_config
*conf
= conf_
;
2948 ap_unixd_set_rlimit(cmd
, &conf
->limit_nproc
, arg
, arg2
, RLIMIT_NPROC
);
2953 static const char *set_recursion_limit(cmd_parms
*cmd
, void *dummy
,
2954 const char *arg1
, const char *arg2
)
2956 core_server_config
*conf
= ap_get_module_config(cmd
->server
->module_config
,
2958 int limit
= atoi(arg1
);
2961 return "The recursion limit must be greater than zero.";
2964 ap_log_error(APLOG_MARK
, APLOG_WARNING
, 0, cmd
->server
,
2965 "Limiting internal redirects to very low numbers may "
2966 "cause normal requests to fail.");
2969 conf
->redirect_limit
= limit
;
2975 return "The recursion limit must be greater than zero.";
2978 ap_log_error(APLOG_MARK
, APLOG_WARNING
, 0, cmd
->server
,
2979 "Limiting the subrequest depth to a very low level may"
2980 " cause normal requests to fail.");
2984 conf
->subreq_limit
= limit
;
2989 static void log_backtrace(const request_rec
*r
)
2991 const request_rec
*top
= r
;
2993 ap_log_rerror(APLOG_MARK
, APLOG_DEBUG
, 0, r
,
2994 "r->uri = %s", r
->uri
? r
->uri
: "(unexpectedly NULL)");
2996 while (top
&& (top
->prev
|| top
->main
)) {
2999 ap_log_rerror(APLOG_MARK
, APLOG_DEBUG
, 0, r
,
3000 "redirected from r->uri = %s",
3001 top
->uri
? top
->uri
: "(unexpectedly NULL)");
3004 if (!top
->prev
&& top
->main
) {
3006 ap_log_rerror(APLOG_MARK
, APLOG_DEBUG
, 0, r
,
3007 "subrequested from r->uri = %s",
3008 top
->uri
? top
->uri
: "(unexpectedly NULL)");
3014 * check whether redirect limit is reached
3016 AP_DECLARE(int) ap_is_recursion_limit_exceeded(const request_rec
*r
)
3018 core_server_config
*conf
= ap_get_module_config(r
->server
->module_config
,
3020 const request_rec
*top
= r
;
3021 int redirects
= 0, subreqs
= 0;
3022 int rlimit
= conf
->redirect_limit
3023 ? conf
->redirect_limit
3024 : AP_DEFAULT_MAX_INTERNAL_REDIRECTS
;
3025 int slimit
= conf
->subreq_limit
3026 ? conf
->subreq_limit
3027 : AP_DEFAULT_MAX_SUBREQ_DEPTH
;
3030 while (top
->prev
|| top
->main
) {
3032 if (++redirects
>= rlimit
) {
3033 /* uuh, too much. */
3034 ap_log_rerror(APLOG_MARK
, APLOG_ERR
, 0, r
,
3035 "Request exceeded the limit of %d internal "
3036 "redirects due to probable configuration error. "
3037 "Use 'LimitInternalRecursion' to increase the "
3038 "limit if necessary. Use 'LogLevel debug' to get "
3039 "a backtrace.", rlimit
);
3041 /* post backtrace */
3044 /* return failure */
3051 if (!top
->prev
&& top
->main
) {
3052 if (++subreqs
>= slimit
) {
3053 /* uuh, too much. */
3054 ap_log_rerror(APLOG_MARK
, APLOG_ERR
, 0, r
,
3055 "Request exceeded the limit of %d subrequest "
3056 "nesting levels due to probable configuration "
3057 "error. Use 'LimitInternalRecursion' to increase "
3058 "the limit if necessary. Use 'LogLevel debug' to "
3059 "get a backtrace.", slimit
);
3061 /* post backtrace */
3064 /* return failure */
3072 /* recursion state: ok */
3076 static const char *add_ct_output_filters(cmd_parms
*cmd
, void *conf_
,
3077 const char *arg
, const char *arg2
)
3079 core_dir_config
*conf
= conf_
;
3080 ap_filter_rec_t
*old
, *new = NULL
;
3081 const char *filter_name
;
3083 if (!conf
->ct_output_filters
) {
3084 conf
->ct_output_filters
= apr_hash_make(cmd
->pool
);
3088 old
= (ap_filter_rec_t
*) apr_hash_get(conf
->ct_output_filters
, arg2
,
3089 APR_HASH_KEY_STRING
);
3090 /* find last entry */
3099 (filter_name
= ap_getword(cmd
->pool
, &arg
, ';')) &&
3100 strcmp(filter_name
, "")) {
3101 new = apr_pcalloc(cmd
->pool
, sizeof(ap_filter_rec_t
));
3102 new->name
= filter_name
;
3104 /* We found something, so let's append it. */
3109 apr_hash_set(conf
->ct_output_filters
, arg2
,
3110 APR_HASH_KEY_STRING
, new);
3116 return "invalid filter name";
3122 * Insert filters requested by the AddOutputFilterByType
3123 * configuration directive. We cannot add filters based
3124 * on content-type until after the handler has started
3125 * to run. Only then do we reliably know the content-type.
3127 void ap_add_output_filters_by_type(request_rec
*r
)
3129 core_dir_config
*conf
;
3132 conf
= (core_dir_config
*)ap_get_module_config(r
->per_dir_config
,
3135 /* We can't do anything with no content-type or if we don't have a
3136 * filter configured.
3138 if (!r
->content_type
|| !conf
->ct_output_filters
) {
3142 /* remove c-t decoration */
3143 ctype
= ap_field_noparam(r
->pool
, r
->content_type
);
3145 ap_filter_rec_t
*ct_filter
;
3146 ct_filter
= apr_hash_get(conf
->ct_output_filters
, ctype
,
3147 APR_HASH_KEY_STRING
);
3149 ap_add_output_filter(ct_filter
->name
, NULL
, r
, r
->connection
);
3150 ct_filter
= ct_filter
->next
;
3157 static const char *set_trace_enable(cmd_parms
*cmd
, void *dummy
,
3160 core_server_config
*conf
= ap_get_module_config(cmd
->server
->module_config
,
3163 if (strcasecmp(arg1
, "on") == 0) {
3164 conf
->trace_enable
= AP_TRACE_ENABLE
;
3166 else if (strcasecmp(arg1
, "off") == 0) {
3167 conf
->trace_enable
= AP_TRACE_DISABLE
;
3169 else if (strcasecmp(arg1
, "extended") == 0) {
3170 conf
->trace_enable
= AP_TRACE_EXTENDED
;
3173 return "TraceEnable must be one of 'on', 'off', or 'extended'";
3179 /* Note --- ErrorDocument will now work from .htaccess files.
3180 * The AllowOverride of Fileinfo allows webmasters to turn it off
3183 static const command_rec core_cmds
[] = {
3185 /* Old access config file commands */
3187 AP_INIT_RAW_ARGS("<Directory", dirsection
, NULL
, RSRC_CONF
,
3188 "Container for directives affecting resources located in the specified "
3190 AP_INIT_RAW_ARGS("<Location", urlsection
, NULL
, RSRC_CONF
,
3191 "Container for directives affecting resources accessed through the "
3192 "specified URL paths"),
3193 AP_INIT_RAW_ARGS("<VirtualHost", virtualhost_section
, NULL
, RSRC_CONF
,
3194 "Container to map directives to a particular virtual host, takes one or "
3195 "more host addresses"),
3196 AP_INIT_RAW_ARGS("<Files", filesection
, NULL
, OR_ALL
,
3197 "Container for directives affecting files matching specified patterns"),
3198 AP_INIT_RAW_ARGS("<Limit", ap_limit_section
, NULL
, OR_LIMIT
| OR_AUTHCFG
,
3199 "Container for authentication directives when accessed using specified HTTP "
3201 AP_INIT_RAW_ARGS("<LimitExcept", ap_limit_section
, (void*)1,
3202 OR_LIMIT
| OR_AUTHCFG
,
3203 "Container for authentication directives to be applied when any HTTP "
3204 "method other than those specified is used to access the resource"),
3205 AP_INIT_TAKE1("<IfModule", start_ifmod
, NULL
, EXEC_ON_READ
| OR_ALL
,
3206 "Container for directives based on existance of specified modules"),
3207 AP_INIT_TAKE1("<IfDefine", start_ifdefine
, NULL
, EXEC_ON_READ
| OR_ALL
,
3208 "Container for directives based on existance of command line defines"),
3209 AP_INIT_RAW_ARGS("<DirectoryMatch", dirsection
, (void*)1, RSRC_CONF
,
3210 "Container for directives affecting resources located in the "
3211 "specified directories"),
3212 AP_INIT_RAW_ARGS("<LocationMatch", urlsection
, (void*)1, RSRC_CONF
,
3213 "Container for directives affecting resources accessed through the "
3214 "specified URL paths"),
3215 AP_INIT_RAW_ARGS("<FilesMatch", filesection
, (void*)1, OR_ALL
,
3216 "Container for directives affecting files matching specified patterns"),
3218 AP_INIT_TAKE1("GprofDir", set_gprof_dir
, NULL
, RSRC_CONF
,
3219 "Directory to plop gmon.out files"),
3221 AP_INIT_TAKE1("AddDefaultCharset", set_add_default_charset
, NULL
, OR_FILEINFO
,
3222 "The name of the default charset to add to any Content-Type without one or 'Off' to disable"),
3223 AP_INIT_TAKE1("AcceptPathInfo", set_accept_path_info
, NULL
, OR_FILEINFO
,
3224 "Set to on or off for PATH_INFO to be accepted by handlers, or default for the per-handler preference"),
3225 AP_INIT_TAKE1("Define", set_define
, NULL
, RSRC_CONF
,
3226 "Define the existance of a variable. Same as passing -D to the command line."),
3227 AP_INIT_RAW_ARGS("<If", ifsection
, NULL
, OR_ALL
,
3228 "Container for directives to be conditionally applied"),
3230 /* Old resource config file commands */
3232 AP_INIT_RAW_ARGS("AccessFileName", set_access_name
, NULL
, RSRC_CONF
,
3233 "Name(s) of per-directory config files (default: .htaccess)"),
3234 AP_INIT_TAKE1("DocumentRoot", set_document_root
, NULL
, RSRC_CONF
,
3235 "Root directory of the document tree"),
3236 AP_INIT_TAKE2("ErrorDocument", set_error_document
, NULL
, OR_FILEINFO
,
3237 "Change responses for HTTP errors"),
3238 AP_INIT_RAW_ARGS("AllowOverride", set_override
, NULL
, ACCESS_CONF
,
3239 "Controls what groups of directives can be configured by per-directory "
3241 AP_INIT_RAW_ARGS("Options", set_options
, NULL
, OR_OPTIONS
,
3242 "Set a number of attributes for a given directory"),
3243 AP_INIT_TAKE1("DefaultType", set_default_type
, NULL
, OR_FILEINFO
,
3244 "the default media type for otherwise untyped files (DEPRECATED)"),
3245 AP_INIT_RAW_ARGS("FileETag", set_etag_bits
, NULL
, OR_FILEINFO
,
3246 "Specify components used to construct a file's ETag"),
3247 AP_INIT_TAKE1("EnableMMAP", set_enable_mmap
, NULL
, OR_FILEINFO
,
3248 "Controls whether memory-mapping may be used to read files"),
3249 AP_INIT_TAKE1("EnableSendfile", set_enable_sendfile
, NULL
, OR_FILEINFO
,
3250 "Controls whether sendfile may be used to transmit files"),
3252 /* Old server config file commands */
3254 AP_INIT_TAKE1("Protocol", set_protocol
, NULL
, RSRC_CONF
,
3255 "Set the Protocol for httpd to use."),
3256 AP_INIT_TAKE2("AcceptFilter", set_accf_map
, NULL
, RSRC_CONF
,
3257 "Set the Accept Filter to use for a protocol"),
3258 AP_INIT_TAKE1("Port", ap_set_deprecated
, NULL
, RSRC_CONF
,
3259 "Port was replaced with Listen in Apache 2.0"),
3260 AP_INIT_TAKE1("HostnameLookups", set_hostname_lookups
, NULL
,
3261 ACCESS_CONF
|RSRC_CONF
,
3262 "\"on\" to enable, \"off\" to disable reverse DNS lookups, or \"double\" to "
3263 "enable double-reverse DNS lookups"),
3264 AP_INIT_TAKE1("ServerAdmin", set_server_string_slot
,
3265 (void *)APR_OFFSETOF(server_rec
, server_admin
), RSRC_CONF
,
3266 "The email address of the server administrator"),
3267 AP_INIT_TAKE1("ServerName", server_hostname_port
, NULL
, RSRC_CONF
,
3268 "The hostname and port of the server"),
3269 AP_INIT_TAKE1("ServerSignature", set_signature_flag
, NULL
, OR_ALL
,
3270 "En-/disable server signature (on|off|email)"),
3271 AP_INIT_TAKE1("ServerRoot", set_server_root
, NULL
, RSRC_CONF
| EXEC_ON_READ
,
3272 "Common directory of server-related files (logs, confs, etc.)"),
3273 AP_INIT_TAKE1("ErrorLog", set_server_string_slot
,
3274 (void *)APR_OFFSETOF(server_rec
, error_fname
), RSRC_CONF
,
3275 "The filename of the error log"),
3276 AP_INIT_RAW_ARGS("ServerAlias", set_server_alias
, NULL
, RSRC_CONF
,
3277 "A name or names alternately used to access the server"),
3278 AP_INIT_TAKE1("ServerPath", set_serverpath
, NULL
, RSRC_CONF
,
3279 "The pathname the server can be reached at"),
3280 AP_INIT_TAKE1("Timeout", set_timeout
, NULL
, RSRC_CONF
,
3281 "Timeout duration (sec)"),
3282 AP_INIT_FLAG("ContentDigest", set_content_md5
, NULL
, OR_OPTIONS
,
3283 "whether or not to send a Content-MD5 header with each request"),
3284 AP_INIT_TAKE1("UseCanonicalName", set_use_canonical_name
, NULL
,
3285 RSRC_CONF
|ACCESS_CONF
,
3286 "How to work out the ServerName : Port when constructing URLs"),
3287 AP_INIT_TAKE1("UseCanonicalPhysicalPort", set_use_canonical_phys_port
, NULL
,
3288 RSRC_CONF
|ACCESS_CONF
,
3289 "Whether to use the physical Port when constructing URLs"),
3290 /* TODO: RlimitFoo should all be part of mod_cgi, not in the core */
3291 /* TODO: ListenBacklog in MPM */
3292 AP_INIT_TAKE1("Include", include_config
, NULL
,
3293 (RSRC_CONF
| ACCESS_CONF
| EXEC_ON_READ
),
3294 "Name of the config file to be included"),
3295 AP_INIT_TAKE1("LogLevel", set_loglevel
, NULL
, RSRC_CONF
,
3296 "Level of verbosity in error logging"),
3297 AP_INIT_TAKE1("NameVirtualHost", ap_set_name_virtual_host
, NULL
, RSRC_CONF
,
3298 "A numeric IP address:port, or the name of a host"),
3299 AP_INIT_TAKE1("ServerTokens", set_serv_tokens
, NULL
, RSRC_CONF
,
3300 "Determine tokens displayed in the Server: header - Min(imal), OS or Full"),
3301 AP_INIT_TAKE1("LimitRequestLine", set_limit_req_line
, NULL
, RSRC_CONF
,
3302 "Limit on maximum size of an HTTP request line"),
3303 AP_INIT_TAKE1("LimitRequestFieldsize", set_limit_req_fieldsize
, NULL
,
3305 "Limit on maximum size of an HTTP request header field"),
3306 AP_INIT_TAKE1("LimitRequestFields", set_limit_req_fields
, NULL
, RSRC_CONF
,
3307 "Limit (0 = unlimited) on max number of header fields in a request message"),
3308 AP_INIT_TAKE1("LimitRequestBody", set_limit_req_body
,
3309 (void*)APR_OFFSETOF(core_dir_config
, limit_req_body
), OR_ALL
,
3310 "Limit (in bytes) on maximum size of request message body"),
3311 AP_INIT_TAKE1("LimitXMLRequestBody", set_limit_xml_req_body
, NULL
, OR_ALL
,
3312 "Limit (in bytes) on maximum size of an XML-based request "
3315 /* System Resource Controls */
3317 AP_INIT_TAKE12("RLimitCPU", set_limit_cpu
,
3318 (void*)APR_OFFSETOF(core_dir_config
, limit_cpu
),
3319 OR_ALL
, "Soft/hard limits for max CPU usage in seconds"),
3321 AP_INIT_TAKE12("RLimitCPU", no_set_limit
, NULL
,
3322 OR_ALL
, "Soft/hard limits for max CPU usage in seconds"),
3324 #if defined (RLIMIT_DATA) || defined (RLIMIT_VMEM) || defined (RLIMIT_AS)
3325 AP_INIT_TAKE12("RLimitMEM", set_limit_mem
,
3326 (void*)APR_OFFSETOF(core_dir_config
, limit_mem
),
3327 OR_ALL
, "Soft/hard limits for max memory usage per process"),
3329 AP_INIT_TAKE12("RLimitMEM", no_set_limit
, NULL
,
3330 OR_ALL
, "Soft/hard limits for max memory usage per process"),
3333 AP_INIT_TAKE12("RLimitNPROC", set_limit_nproc
,
3334 (void*)APR_OFFSETOF(core_dir_config
, limit_nproc
),
3335 OR_ALL
, "soft/hard limits for max number of processes per uid"),
3337 AP_INIT_TAKE12("RLimitNPROC", no_set_limit
, NULL
,
3338 OR_ALL
, "soft/hard limits for max number of processes per uid"),
3341 /* internal recursion stopper */
3342 AP_INIT_TAKE12("LimitInternalRecursion", set_recursion_limit
, NULL
, RSRC_CONF
,
3343 "maximum recursion depth of internal redirects and subrequests"),
3345 AP_INIT_TAKE1("ForceType", ap_set_string_slot_lower
,
3346 (void *)APR_OFFSETOF(core_dir_config
, mime_type
), OR_FILEINFO
,
3347 "a mime type that overrides other configured type"),
3348 AP_INIT_TAKE1("SetHandler", ap_set_string_slot_lower
,
3349 (void *)APR_OFFSETOF(core_dir_config
, handler
), OR_FILEINFO
,
3350 "a handler name that overrides any other configured handler"),
3351 AP_INIT_TAKE1("SetOutputFilter", ap_set_string_slot
,
3352 (void *)APR_OFFSETOF(core_dir_config
, output_filters
), OR_FILEINFO
,
3353 "filter (or ; delimited list of filters) to be run on the request content"),
3354 AP_INIT_TAKE1("SetInputFilter", ap_set_string_slot
,
3355 (void *)APR_OFFSETOF(core_dir_config
, input_filters
), OR_FILEINFO
,
3356 "filter (or ; delimited list of filters) to be run on the request body"),
3357 AP_INIT_ITERATE2("AddOutputFilterByType", add_ct_output_filters
,
3358 (void *)APR_OFFSETOF(core_dir_config
, ct_output_filters
), OR_FILEINFO
,
3359 "output filter name followed by one or more content-types"),
3360 AP_INIT_FLAG("AllowEncodedSlashes", set_allow2f
, NULL
, RSRC_CONF
,
3361 "Allow URLs containing '/' encoded as '%2F'"),
3364 * These are default configuration directives that mpms can/should
3365 * pay attention to. If an mpm wishes to use these, they should
3366 * #defined them in mpm.h.
3368 #ifdef AP_MPM_WANT_SET_PIDFILE
3369 AP_INIT_TAKE1("PidFile", ap_mpm_set_pidfile
, NULL
, RSRC_CONF
,
3370 "A file for logging the server process ID"),
3372 #ifdef AP_MPM_WANT_SET_SCOREBOARD
3373 AP_INIT_TAKE1("ScoreBoardFile", ap_mpm_set_scoreboard
, NULL
, RSRC_CONF
,
3374 "A file for Apache to maintain runtime process management information"),
3376 #ifdef AP_MPM_WANT_SET_LOCKFILE
3377 AP_INIT_TAKE1("LockFile", ap_mpm_set_lockfile
, NULL
, RSRC_CONF
,
3378 "The lockfile used when Apache needs to lock the accept() call (deprecated)"),
3380 #ifdef AP_MPM_WANT_SET_MAX_REQUESTS
3381 AP_INIT_TAKE1("MaxRequestsPerChild", ap_mpm_set_max_requests
, NULL
, RSRC_CONF
,
3382 "Maximum number of requests a particular child serves before dying."),
3384 #ifdef AP_MPM_WANT_SET_COREDUMPDIR
3385 AP_INIT_TAKE1("CoreDumpDirectory", ap_mpm_set_coredumpdir
, NULL
, RSRC_CONF
,
3386 "The location of the directory Apache changes to before dumping core"),
3388 #ifdef AP_MPM_WANT_SET_ACCEPT_LOCK_MECH
3389 AP_INIT_TAKE1("AcceptMutex", ap_mpm_set_accept_lock_mech
, NULL
, RSRC_CONF
,
3390 AP_AVAILABLE_MUTEXES_STRING
),
3392 #ifdef AP_MPM_WANT_SET_MAX_MEM_FREE
3393 AP_INIT_TAKE1("MaxMemFree", ap_mpm_set_max_mem_free
, NULL
, RSRC_CONF
,
3394 "Maximum number of 1k blocks a particular childs allocator may hold."),
3396 #ifdef AP_MPM_WANT_SET_STACKSIZE
3397 AP_INIT_TAKE1("ThreadStackSize", ap_mpm_set_thread_stacksize
, NULL
, RSRC_CONF
,
3398 "Size in bytes of stack used by threads handling client connections"),
3400 #if AP_ENABLE_EXCEPTION_HOOK
3401 AP_INIT_TAKE1("EnableExceptionHook", ap_mpm_set_exception_hook
, NULL
, RSRC_CONF
,
3402 "Controls whether exception hook may be called after a crash"),
3404 AP_INIT_TAKE1("TraceEnable", set_trace_enable
, NULL
, RSRC_CONF
,
3405 "'on' (default), 'off' or 'extended' to trace request body content"),
3409 /*****************************************************************
3411 * Core handlers for various phases of server operation...
3414 AP_DECLARE_NONSTD(int) ap_core_translate(request_rec
*r
)
3416 void *sconf
= r
->server
->module_config
;
3417 core_server_config
*conf
= ap_get_module_config(sconf
, &core_module
);
3420 /* XXX this seems too specific, this should probably become
3421 * some general-case test
3424 return HTTP_FORBIDDEN
;
3426 if (!r
->uri
|| ((r
->uri
[0] != '/') && strcmp(r
->uri
, "*"))) {
3427 ap_log_rerror(APLOG_MARK
, APLOG_ERR
, 0, r
,
3428 "Invalid URI in request %s", r
->the_request
);
3429 return HTTP_BAD_REQUEST
;
3433 && !strncmp(r
->uri
, r
->server
->path
, r
->server
->pathlen
)
3434 && (r
->server
->path
[r
->server
->pathlen
- 1] == '/'
3435 || r
->uri
[r
->server
->pathlen
] == '/'
3436 || r
->uri
[r
->server
->pathlen
] == '\0'))
3438 /* skip all leading /'s (e.g. http://localhost///foo)
3439 * so we are looking at only the relative path.
3441 char *path
= r
->uri
+ r
->server
->pathlen
;
3442 while (*path
== '/') {
3445 if ((rv
= apr_filepath_merge(&r
->filename
, conf
->ap_document_root
, path
,
3446 APR_FILEPATH_TRUENAME
3447 | APR_FILEPATH_SECUREROOT
, r
->pool
))
3449 ap_log_rerror(APLOG_MARK
, APLOG_ERR
, rv
, r
,
3450 "Cannot map %s to file", r
->the_request
);
3451 return HTTP_FORBIDDEN
;
3453 r
->canonical_filename
= r
->filename
;
3457 * Make sure that we do not mess up the translation by adding two
3458 * /'s in a row. This happens under windows when the document
3459 * root ends with a /
3461 /* skip all leading /'s (e.g. http://localhost///foo)
3462 * so we are looking at only the relative path.
3464 char *path
= r
->uri
;
3465 while (*path
== '/') {
3468 if ((rv
= apr_filepath_merge(&r
->filename
, conf
->ap_document_root
, path
,
3469 APR_FILEPATH_TRUENAME
3470 | APR_FILEPATH_SECUREROOT
, r
->pool
))
3472 ap_log_rerror(APLOG_MARK
, APLOG_ERR
, rv
, r
,
3473 "Cannot map %s to file", r
->the_request
);
3474 return HTTP_FORBIDDEN
;
3476 r
->canonical_filename
= r
->filename
;
3482 /*****************************************************************
3484 * Test the filesystem name through directory_walk and file_walk
3486 static int core_map_to_storage(request_rec
*r
)
3490 if ((access_status
= ap_directory_walk(r
))) {
3491 return access_status
;
3494 if ((access_status
= ap_file_walk(r
))) {
3495 return access_status
;
3502 static int do_nothing(request_rec
*r
) { return OK
; }
3505 static int core_override_type(request_rec
*r
)
3507 core_dir_config
*conf
=
3508 (core_dir_config
*)ap_get_module_config(r
->per_dir_config
,
3511 /* Check for overrides with ForceType / SetHandler
3513 if (conf
->mime_type
&& strcmp(conf
->mime_type
, "none"))
3514 ap_set_content_type(r
, (char*) conf
->mime_type
);
3516 if (conf
->handler
&& strcmp(conf
->handler
, "none"))
3517 r
->handler
= conf
->handler
;
3519 /* Deal with the poor soul who is trying to force path_info to be
3520 * accepted within the core_handler, where they will let the subreq
3521 * address its contents. This is toggled by the user in the very
3522 * beginning of the fixup phase, so modules should override the user's
3523 * discretion in their own module fixup phase. It is tristate, if
3524 * the user doesn't specify, the result is 2 (which the module may
3525 * interpret to its own customary behavior.) It won't be touched
3526 * if the value is no longer undefined (2), so any module changing
3527 * the value prior to the fixup phase OVERRIDES the user's choice.
3529 if ((r
->used_path_info
== AP_REQ_DEFAULT_PATH_INFO
)
3530 && (conf
->accept_path_info
!= 3)) {
3531 r
->used_path_info
= conf
->accept_path_info
;
3537 static int default_handler(request_rec
*r
)
3539 conn_rec
*c
= r
->connection
;
3540 apr_bucket_brigade
*bb
;
3544 apr_file_t
*fd
= NULL
;
3545 apr_status_t status
;
3546 /* XXX if/when somebody writes a content-md5 filter we either need to
3547 * remove this support or coordinate when to use the filter vs.
3548 * when to use this code
3549 * The current choice of when to compute the md5 here matches the 1.3
3550 * support fairly closely (unlike 1.3, we don't handle computing md5
3551 * when the charset is translated).
3553 int bld_content_md5
;
3555 d
= (core_dir_config
*)ap_get_module_config(r
->per_dir_config
,
3557 bld_content_md5
= (d
->content_md5
& 1)
3558 && r
->output_filters
->frec
->ftype
!= AP_FTYPE_RESOURCE
;
3560 ap_allow_standard_methods(r
, MERGE_ALLOW
, M_GET
, M_OPTIONS
, M_POST
, -1);
3562 /* If filters intend to consume the request body, they must
3563 * register an InputFilter to slurp the contents of the POST
3564 * data from the POST input stream. It no longer exists when
3565 * the output filters are invoked by the default handler.
3567 if ((errstatus
= ap_discard_request_body(r
)) != OK
) {
3571 if (r
->method_number
== M_GET
|| r
->method_number
== M_POST
) {
3572 if (r
->finfo
.filetype
== 0) {
3573 ap_log_rerror(APLOG_MARK
, APLOG_ERR
, 0, r
,
3574 "File does not exist: %s", r
->filename
);
3575 return HTTP_NOT_FOUND
;
3578 /* Don't try to serve a dir. Some OSs do weird things with
3581 if (r
->finfo
.filetype
== APR_DIR
) {
3582 ap_log_rerror(APLOG_MARK
, APLOG_ERR
, 0, r
,
3583 "Attempt to serve directory: %s", r
->filename
);
3584 return HTTP_NOT_FOUND
;
3587 if ((r
->used_path_info
!= AP_REQ_ACCEPT_PATH_INFO
) &&
3588 r
->path_info
&& *r
->path_info
)
3590 /* default to reject */
3591 ap_log_rerror(APLOG_MARK
, APLOG_ERR
, 0, r
,
3592 "File does not exist: %s",
3593 apr_pstrcat(r
->pool
, r
->filename
, r
->path_info
, NULL
));
3594 return HTTP_NOT_FOUND
;
3597 /* We understood the (non-GET) method, but it might not be legal for
3598 this particular resource. Check to see if the 'deliver_script'
3599 flag is set. If so, then we go ahead and deliver the file since
3600 it isn't really content (only GET normally returns content).
3602 Note: based on logic further above, the only possible non-GET
3603 method at this point is POST. In the future, we should enable
3604 script delivery for all methods. */
3605 if (r
->method_number
!= M_GET
) {
3606 core_request_config
*req_cfg
;
3608 req_cfg
= ap_get_module_config(r
->request_config
, &core_module
);
3609 if (!req_cfg
->deliver_script
) {
3610 /* The flag hasn't been set for this request. Punt. */
3611 ap_log_rerror(APLOG_MARK
, APLOG_ERR
, 0, r
,
3612 "This resource does not accept the %s method.",
3614 return HTTP_METHOD_NOT_ALLOWED
;
3619 if ((status
= apr_file_open(&fd
, r
->filename
, APR_READ
| APR_BINARY
3620 #if APR_HAS_SENDFILE
3621 | ((d
->enable_sendfile
== ENABLE_SENDFILE_OFF
)
3622 ? 0 : APR_SENDFILE_ENABLED
)
3624 , 0, r
->pool
)) != APR_SUCCESS
) {
3625 ap_log_rerror(APLOG_MARK
, APLOG_ERR
, status
, r
,
3626 "file permissions deny server access: %s", r
->filename
);
3627 return HTTP_FORBIDDEN
;
3630 ap_update_mtime(r
, r
->finfo
.mtime
);
3631 ap_set_last_modified(r
);
3633 apr_table_setn(r
->headers_out
, "Accept-Ranges", "bytes");
3634 ap_set_content_length(r
, r
->finfo
.size
);
3635 if (bld_content_md5
) {
3636 apr_table_setn(r
->headers_out
, "Content-MD5",
3637 ap_md5digest(r
->pool
, fd
));
3640 bb
= apr_brigade_create(r
->pool
, c
->bucket_alloc
);
3642 if ((errstatus
= ap_meets_conditions(r
)) != OK
) {
3644 r
->status
= errstatus
;
3647 e
= apr_brigade_insert_file(bb
, fd
, 0, r
->finfo
.size
, r
->pool
);
3650 if (d
->enable_mmap
== ENABLE_MMAP_OFF
) {
3651 (void)apr_bucket_file_enable_mmap(e
, 0);
3656 e
= apr_bucket_eos_create(c
->bucket_alloc
);
3657 APR_BRIGADE_INSERT_TAIL(bb
, e
);
3659 status
= ap_pass_brigade(r
->output_filters
, bb
);
3660 if (status
== APR_SUCCESS
3661 || r
->status
!= HTTP_OK
3666 /* no way to know what type of error occurred */
3667 ap_log_rerror(APLOG_MARK
, APLOG_DEBUG
, status
, r
,
3668 "default_handler: ap_pass_brigade returned %i",
3670 return HTTP_INTERNAL_SERVER_ERROR
;
3673 else { /* unusual method (not GET or POST) */
3674 if (r
->method_number
== M_INVALID
) {
3675 /* See if this looks like an undecrypted SSL handshake attempt.
3676 * It's safe to look a couple bytes into the_request if it exists, as it's
3677 * always allocated at least MIN_LINE_ALLOC (80) bytes.
3680 && r
->the_request
[0] == 0x16
3681 && (r
->the_request
[1] == 0x2 || r
->the_request
[1] == 0x3)) {
3682 ap_log_rerror(APLOG_MARK
, APLOG_ERR
, 0, r
,
3683 "Invalid method in request %s - possible attempt to establish SSL connection on non-SSL port", r
->the_request
);
3685 ap_log_rerror(APLOG_MARK
, APLOG_ERR
, 0, r
,
3686 "Invalid method in request %s", r
->the_request
);
3688 return HTTP_NOT_IMPLEMENTED
;
3691 if (r
->method_number
== M_OPTIONS
) {
3692 return ap_send_http_options(r
);
3694 return HTTP_METHOD_NOT_ALLOWED
;
3698 /* Optional function coming from mod_logio, used for logging of output
3701 APR_OPTIONAL_FN_TYPE(ap_logio_add_bytes_out
) *ap__logio_add_bytes_out
;
3702 APR_OPTIONAL_FN_TYPE(authz_some_auth_required
) *ap__authz_ap_some_auth_required
;
3704 /* Insist that at least one module will undertake to provide system
3705 * security by dropping startup privileges.
3707 static int sys_privileges
= 0;
3708 AP_DECLARE(int) ap_sys_privileges_handlers(int inc
)
3710 sys_privileges
+= inc
;
3711 return sys_privileges
;
3713 static int core_post_config(apr_pool_t
*pconf
, apr_pool_t
*plog
, apr_pool_t
*ptemp
, server_rec
*s
)
3715 ap__logio_add_bytes_out
= APR_RETRIEVE_OPTIONAL_FN(ap_logio_add_bytes_out
);
3716 ident_lookup
= APR_RETRIEVE_OPTIONAL_FN(ap_ident_lookup
);
3717 ap__authz_ap_some_auth_required
= APR_RETRIEVE_OPTIONAL_FN(authz_some_auth_required
);
3718 authn_ap_auth_type
= APR_RETRIEVE_OPTIONAL_FN(authn_ap_auth_type
);
3719 authn_ap_auth_name
= APR_RETRIEVE_OPTIONAL_FN(authn_ap_auth_name
);
3720 access_compat_ap_satisfies
= APR_RETRIEVE_OPTIONAL_FN(access_compat_ap_satisfies
);
3723 ap_setup_make_content_type(pconf
);
3724 ap_setup_auth_internal(ptemp
);
3725 if (!sys_privileges
) {
3726 ap_log_error(APLOG_MARK
, APLOG_CRIT
, 0, NULL
,
3727 "Server MUST relinquish startup privileges before "
3728 "accepting connections. Please ensure mod_unixd "
3729 "or other system security module is loaded.");
3735 static void core_insert_filter(request_rec
*r
)
3737 core_dir_config
*conf
= (core_dir_config
*)
3738 ap_get_module_config(r
->per_dir_config
,
3740 const char *filter
, *filters
= conf
->output_filters
;
3743 while (*filters
&& (filter
= ap_getword(r
->pool
, &filters
, ';'))) {
3744 ap_add_output_filter(filter
, NULL
, r
, r
->connection
);
3748 filters
= conf
->input_filters
;
3750 while (*filters
&& (filter
= ap_getword(r
->pool
, &filters
, ';'))) {
3751 ap_add_input_filter(filter
, NULL
, r
, r
->connection
);
3756 static apr_size_t num_request_notes
= AP_NUM_STD_NOTES
;
3758 static apr_status_t
reset_request_notes(void *dummy
)
3760 num_request_notes
= AP_NUM_STD_NOTES
;
3764 AP_DECLARE(apr_size_t
) ap_register_request_note(void)
3766 apr_pool_cleanup_register(apr_hook_global_pool
, NULL
, reset_request_notes
,
3767 apr_pool_cleanup_null
);
3768 return num_request_notes
++;
3771 AP_DECLARE(void **) ap_get_request_note(request_rec
*r
, apr_size_t note_num
)
3773 core_request_config
*req_cfg
;
3775 if (note_num
>= num_request_notes
) {
3779 req_cfg
= (core_request_config
*)
3780 ap_get_module_config(r
->request_config
, &core_module
);
3786 return &(req_cfg
->notes
[note_num
]);
3789 static int core_create_req(request_rec
*r
)
3791 /* Alloc the config struct and the array of request notes in
3792 * a single block for efficiency
3794 core_request_config
*req_cfg
;
3796 req_cfg
= apr_pcalloc(r
->pool
, sizeof(core_request_config
) +
3797 sizeof(void *) * num_request_notes
);
3798 req_cfg
->notes
= (void **)((char *)req_cfg
+ sizeof(core_request_config
));
3800 /* ### temporarily enable script delivery as the default */
3801 req_cfg
->deliver_script
= 1;
3804 core_request_config
*main_req_cfg
= (core_request_config
*)
3805 ap_get_module_config(r
->main
->request_config
, &core_module
);
3806 req_cfg
->bb
= main_req_cfg
->bb
;
3809 req_cfg
->bb
= apr_brigade_create(r
->pool
, r
->connection
->bucket_alloc
);
3812 ap_set_module_config(r
->request_config
, &core_module
, req_cfg
);
3817 static int core_create_proxy_req(request_rec
*r
, request_rec
*pr
)
3819 return core_create_req(pr
);
3822 static conn_rec
*core_create_conn(apr_pool_t
*ptrans
, server_rec
*server
,
3823 apr_socket_t
*csd
, long id
, void *sbh
,
3824 apr_bucket_alloc_t
*alloc
)
3827 conn_rec
*c
= (conn_rec
*) apr_pcalloc(ptrans
, sizeof(conn_rec
));
3830 (void)ap_update_child_status(c
->sbh
, SERVER_BUSY_READ
, (request_rec
*)NULL
);
3832 /* Got a connection structure, so initialize what fields we can
3833 * (the rest are zeroed out by pcalloc).
3835 c
->conn_config
= ap_create_conn_config(ptrans
);
3836 c
->notes
= apr_table_make(ptrans
, 5);
3839 if ((rv
= apr_socket_addr_get(&c
->local_addr
, APR_LOCAL
, csd
))
3841 ap_log_error(APLOG_MARK
, APLOG_INFO
, rv
, server
,
3842 "apr_socket_addr_get(APR_LOCAL)");
3843 apr_socket_close(csd
);
3847 apr_sockaddr_ip_get(&c
->local_ip
, c
->local_addr
);
3848 if ((rv
= apr_socket_addr_get(&c
->remote_addr
, APR_REMOTE
, csd
))
3850 ap_log_error(APLOG_MARK
, APLOG_INFO
, rv
, server
,
3851 "apr_socket_addr_get(APR_REMOTE)");
3852 apr_socket_close(csd
);
3856 apr_sockaddr_ip_get(&c
->remote_ip
, c
->remote_addr
);
3857 c
->base_server
= server
;
3860 c
->bucket_alloc
= alloc
;
3862 c
->cs
= (conn_state_t
*)apr_pcalloc(ptrans
, sizeof(conn_state_t
));
3863 APR_RING_INIT(&(c
->cs
->timeout_list
), conn_state_t
, timeout_list
);
3864 c
->cs
->expiration_time
= 0;
3865 c
->cs
->state
= CONN_STATE_CHECK_REQUEST_LINE_READABLE
;
3868 c
->cs
->bucket_alloc
= alloc
;
3869 c
->clogging_input_filters
= 0;
3874 static int core_pre_connection(conn_rec
*c
, void *csd
)
3876 core_net_rec
*net
= apr_palloc(c
->pool
, sizeof(*net
));
3879 #ifdef AP_MPM_DISABLE_NAGLE_ACCEPTED_SOCK
3880 /* The Nagle algorithm says that we should delay sending partial
3881 * packets in hopes of getting more data. We don't want to do
3882 * this; we are not telnet. There are bad interactions between
3883 * persistent connections and Nagle's algorithm that have very severe
3884 * performance penalties. (Failing to disable Nagle is not much of a
3885 * problem with simple HTTP.)
3887 rv
= apr_socket_opt_set(csd
, APR_TCP_NODELAY
, 1);
3888 if (rv
!= APR_SUCCESS
&& rv
!= APR_ENOTIMPL
) {
3889 /* expected cause is that the client disconnected already,
3890 * hence the debug level
3892 ap_log_cerror(APLOG_MARK
, APLOG_DEBUG
, rv
, c
,
3893 "apr_socket_opt_set(APR_TCP_NODELAY)");
3897 /* The core filter requires the timeout mode to be set, which
3898 * incidentally sets the socket to be nonblocking. If this
3899 * is not initialized correctly, Linux - for example - will
3900 * be initially blocking, while Solaris will be non blocking
3901 * and any initial read will fail.
3903 rv
= apr_socket_timeout_set(csd
, c
->base_server
->timeout
);
3904 if (rv
!= APR_SUCCESS
) {
3905 /* expected cause is that the client disconnected already */
3906 ap_log_cerror(APLOG_MARK
, APLOG_DEBUG
, rv
, c
,
3907 "apr_socket_timeout_set");
3912 net
->out_ctx
= NULL
;
3913 net
->client_socket
= csd
;
3915 ap_set_module_config(net
->c
->conn_config
, &core_module
, csd
);
3916 ap_add_input_filter_handle(ap_core_input_filter_handle
, net
, NULL
, net
->c
);
3917 ap_add_output_filter_handle(ap_core_output_filter_handle
, net
, NULL
, net
->c
);
3921 static void register_hooks(apr_pool_t
*p
)
3923 /* create_connection and install_transport_filters are
3924 * hooks that should always be APR_HOOK_REALLY_LAST to give other
3925 * modules the opportunity to install alternate network transports
3926 * and stop other functions from being run.
3928 ap_hook_create_connection(core_create_conn
, NULL
, NULL
,
3929 APR_HOOK_REALLY_LAST
);
3930 ap_hook_pre_connection(core_pre_connection
, NULL
, NULL
,
3931 APR_HOOK_REALLY_LAST
);
3933 ap_hook_post_config(core_post_config
,NULL
,NULL
,APR_HOOK_REALLY_FIRST
);
3934 ap_hook_translate_name(ap_core_translate
,NULL
,NULL
,APR_HOOK_REALLY_LAST
);
3935 ap_hook_map_to_storage(core_map_to_storage
,NULL
,NULL
,APR_HOOK_REALLY_LAST
);
3936 ap_hook_open_logs(ap_open_logs
,NULL
,NULL
,APR_HOOK_REALLY_FIRST
);
3937 ap_hook_child_init(ap_logs_child_init
,NULL
,NULL
,APR_HOOK_MIDDLE
);
3938 ap_hook_handler(default_handler
,NULL
,NULL
,APR_HOOK_REALLY_LAST
);
3939 /* FIXME: I suspect we can eliminate the need for these do_nothings - Ben */
3940 ap_hook_type_checker(do_nothing
,NULL
,NULL
,APR_HOOK_REALLY_LAST
);
3941 ap_hook_fixups(core_override_type
,NULL
,NULL
,APR_HOOK_REALLY_FIRST
);
3942 ap_hook_create_request(core_create_req
, NULL
, NULL
, APR_HOOK_MIDDLE
);
3943 APR_OPTIONAL_HOOK(proxy
, create_req
, core_create_proxy_req
, NULL
, NULL
,
3945 ap_hook_pre_mpm(ap_create_scoreboard
, NULL
, NULL
, APR_HOOK_MIDDLE
);
3947 /* register the core's insert_filter hook and register core-provided
3950 ap_hook_insert_filter(core_insert_filter
, NULL
, NULL
, APR_HOOK_MIDDLE
);
3952 ap_core_input_filter_handle
=
3953 ap_register_input_filter("CORE_IN", ap_core_input_filter
,
3954 NULL
, AP_FTYPE_NETWORK
);
3955 ap_content_length_filter_handle
=
3956 ap_register_output_filter("CONTENT_LENGTH", ap_content_length_filter
,
3957 NULL
, AP_FTYPE_PROTOCOL
);
3958 ap_core_output_filter_handle
=
3959 ap_register_output_filter("CORE", ap_core_output_filter
,
3960 NULL
, AP_FTYPE_NETWORK
);
3961 ap_subreq_core_filter_handle
=
3962 ap_register_output_filter("SUBREQ_CORE", ap_sub_req_output_filter
,
3963 NULL
, AP_FTYPE_CONTENT_SET
);
3965 ap_register_output_filter("OLD_WRITE", ap_old_write_filter
,
3966 NULL
, AP_FTYPE_RESOURCE
- 10);
3969 AP_DECLARE_DATA module core_module
= {
3970 STANDARD20_MODULE_STUFF
,
3971 create_core_dir_config
, /* create per-directory config structure */
3972 merge_core_dir_configs
, /* merge per-directory config structures */
3973 create_core_server_config
, /* create per-server config structure */
3974 merge_core_server_configs
, /* merge per-server config structures */
3975 core_cmds
, /* command apr_table_t */
3976 register_hooks
/* register hooks */