Line | Count | Source (jump to first uncovered line) |
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 |
7 | | * |
8 | | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | | * |
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. |
15 | | */ |
16 | | |
17 | | #include "apr.h" |
18 | | #include "apr_strings.h" |
19 | | #include "apr_lib.h" |
20 | | #include "apr_fnmatch.h" |
21 | | #include "apr_hash.h" |
22 | | #include "apr_thread_proc.h" /* for RLIMIT stuff */ |
23 | | #include "apr_random.h" |
24 | | |
25 | | #include "apr_version.h" |
26 | | #if APR_MAJOR_VERSION < 2 |
27 | | #include "apu_version.h" |
28 | | #endif |
29 | | |
30 | | #define APR_WANT_IOVEC |
31 | | #define APR_WANT_STRFUNC |
32 | | #define APR_WANT_MEMFUNC |
33 | | #include "apr_want.h" |
34 | | |
35 | | #include "ap_config.h" |
36 | | #include "httpd.h" |
37 | | #include "http_config.h" |
38 | | #include "http_core.h" |
39 | | #include "http_protocol.h" /* For index_of_response(). Grump. */ |
40 | | #include "http_request.h" |
41 | | #include "http_ssl.h" |
42 | | #include "http_vhost.h" |
43 | | #include "http_main.h" /* For the default_handler below... */ |
44 | | #include "http_log.h" |
45 | | #include "http_connection.h" |
46 | | #include "apr_buckets.h" |
47 | | #include "util_filter.h" |
48 | | #include "util_ebcdic.h" |
49 | | #include "util_mutex.h" |
50 | | #include "util_time.h" |
51 | | #include "mpm_common.h" |
52 | | #include "scoreboard.h" |
53 | | #include "mod_core.h" |
54 | | #include "mod_proxy.h" |
55 | | #include "ap_listen.h" |
56 | | #include "ap_provider.h" |
57 | | #include "ap_regex.h" |
58 | | #include "core.h" |
59 | | |
60 | | #include "mod_so.h" /* for ap_find_loaded_module_symbol */ |
61 | | |
62 | | #if defined(RLIMIT_CPU) || defined (RLIMIT_DATA) || defined (RLIMIT_VMEM) || defined(RLIMIT_AS) || defined (RLIMIT_NPROC) |
63 | | #include "unixd.h" |
64 | | #endif |
65 | | #if APR_HAVE_UNISTD_H |
66 | | #include <unistd.h> |
67 | | #endif |
68 | | |
69 | | /* LimitRequestBody handling */ |
70 | 0 | #define AP_LIMIT_REQ_BODY_UNSET ((apr_off_t) -1) |
71 | 0 | #define AP_DEFAULT_LIMIT_REQ_BODY ((apr_off_t) 1<<30) /* 1GB */ |
72 | | |
73 | | /* LimitXMLRequestBody handling */ |
74 | 0 | #define AP_LIMIT_UNSET ((long) -1) |
75 | 0 | #define AP_DEFAULT_LIMIT_XML_BODY ((apr_size_t)1000000) |
76 | | /* Hard limit for ap_escape_html2() */ |
77 | 0 | #define AP_MAX_LIMIT_XML_BODY ((apr_size_t)(APR_SIZE_MAX / 6 - 1)) |
78 | | |
79 | | #define AP_MIN_SENDFILE_BYTES (256) |
80 | | |
81 | | /* maximum include nesting level */ |
82 | | #ifndef AP_MAX_INCLUDE_DEPTH |
83 | 0 | #define AP_MAX_INCLUDE_DEPTH (128) |
84 | | #endif |
85 | | |
86 | | /* valid in core-conf, but not in runtime r->used_path_info */ |
87 | 0 | #define AP_ACCEPT_PATHINFO_UNSET 3 |
88 | | |
89 | 0 | #define AP_FLUSH_MAX_THRESHOLD 65535 |
90 | 0 | #define AP_FLUSH_MAX_PIPELINED 4 |
91 | | |
92 | | APR_HOOK_STRUCT( |
93 | | APR_HOOK_LINK(get_mgmt_items) |
94 | | APR_HOOK_LINK(insert_network_bucket) |
95 | | ) |
96 | | |
97 | | AP_IMPLEMENT_HOOK_RUN_ALL(int, get_mgmt_items, |
98 | | (apr_pool_t *p, const char *val, apr_hash_t *ht), |
99 | | (p, val, ht), OK, DECLINED) |
100 | | |
101 | | AP_IMPLEMENT_HOOK_RUN_FIRST(apr_status_t, insert_network_bucket, |
102 | | (conn_rec *c, apr_bucket_brigade *bb, |
103 | | apr_socket_t *socket), |
104 | | (c, bb, socket), AP_DECLINED) |
105 | | |
106 | | /* Server core module... This module provides support for really basic |
107 | | * server operations, including options and commands which control the |
108 | | * operation of other modules. Consider this the bureaucracy module. |
109 | | * |
110 | | * The core module also defines handlers, etc., to handle just enough |
111 | | * to allow a server with the core module ONLY to actually serve documents. |
112 | | * |
113 | | * This file could almost be mod_core.c, except for the stuff which affects |
114 | | * the http_conf_globals. |
115 | | */ |
116 | | |
117 | | /* we know core's module_index is 0 */ |
118 | | #undef APLOG_MODULE_INDEX |
119 | 0 | #define APLOG_MODULE_INDEX AP_CORE_MODULE_INDEX |
120 | | |
121 | | /* Handles for core filters */ |
122 | | AP_DECLARE_DATA ap_filter_rec_t *ap_subreq_core_filter_handle; |
123 | | AP_DECLARE_DATA ap_filter_rec_t *ap_core_output_filter_handle; |
124 | | AP_DECLARE_DATA ap_filter_rec_t *ap_content_length_filter_handle; |
125 | | AP_DECLARE_DATA ap_filter_rec_t *ap_core_input_filter_handle; |
126 | | |
127 | | /* Provide ap_document_root_check storage and default value = true */ |
128 | | AP_DECLARE_DATA int ap_document_root_check = 1; |
129 | | |
130 | | /* magic pointer for ErrorDocument xxx "default" */ |
131 | | static char errordocument_default; |
132 | | |
133 | | /* Global state allocated out of pconf: variables here MUST be |
134 | | * cleared/reset in reset_config(), a pconf cleanup, to avoid the |
135 | | * variable getting reused after the pool is cleared. */ |
136 | | static apr_array_header_t *saved_server_config_defines = NULL; |
137 | | static apr_table_t *server_config_defined_vars = NULL; |
138 | | AP_DECLARE_DATA const char *ap_runtime_dir = NULL; |
139 | | static const char *core_state_dir; |
140 | | |
141 | | AP_DECLARE_DATA int ap_main_state = AP_SQ_MS_INITIAL_STARTUP; |
142 | | AP_DECLARE_DATA int ap_run_mode = AP_SQ_RM_UNKNOWN; |
143 | | AP_DECLARE_DATA int ap_config_generation = 0; |
144 | | |
145 | | typedef struct { |
146 | | apr_ipsubnet_t *subnet; |
147 | | struct ap_logconf log; |
148 | | } conn_log_config; |
149 | | |
150 | | static apr_socket_t *dummy_socket; |
151 | | |
152 | | static void *create_core_dir_config(apr_pool_t *a, char *dir) |
153 | 0 | { |
154 | 0 | core_dir_config *conf; |
155 | |
|
156 | 0 | conf = (core_dir_config *)apr_pcalloc(a, sizeof(core_dir_config)); |
157 | | |
158 | | /* conf->r and conf->d[_*] are initialized by dirsection() or left NULL */ |
159 | |
|
160 | 0 | conf->opts = dir ? OPT_UNSET : OPT_UNSET|OPT_SYM_LINKS; |
161 | 0 | conf->opts_add = conf->opts_remove = OPT_NONE; |
162 | 0 | conf->override = OR_UNSET|OR_NONE; |
163 | 0 | conf->override_opts = OPT_UNSET | OPT_ALL | OPT_SYM_OWNER | OPT_MULTI; |
164 | |
|
165 | 0 | conf->accept_path_info = AP_ACCEPT_PATHINFO_UNSET; |
166 | |
|
167 | 0 | conf->use_canonical_name = USE_CANONICAL_NAME_UNSET; |
168 | 0 | conf->use_canonical_phys_port = USE_CANONICAL_PHYS_PORT_UNSET; |
169 | |
|
170 | 0 | conf->hostname_lookups = HOSTNAME_LOOKUP_UNSET; |
171 | | |
172 | | /* |
173 | | * left as NULL (we use apr_pcalloc): |
174 | | * conf->limit_cpu = NULL; |
175 | | * conf->limit_mem = NULL; |
176 | | * conf->limit_nproc = NULL; |
177 | | * conf->sec_file = NULL; |
178 | | * conf->sec_if = NULL; |
179 | | */ |
180 | |
|
181 | 0 | conf->limit_req_body = AP_LIMIT_REQ_BODY_UNSET; |
182 | 0 | conf->limit_xml_body = AP_LIMIT_UNSET; |
183 | |
|
184 | 0 | conf->server_signature = srv_sig_unset; |
185 | |
|
186 | 0 | conf->add_default_charset = ADD_DEFAULT_CHARSET_UNSET; |
187 | 0 | conf->add_default_charset_name = DEFAULT_ADD_DEFAULT_CHARSET_NAME; |
188 | | |
189 | | /* Overriding all negotiation |
190 | | * Set NULL by apr_pcalloc: |
191 | | * conf->mime_type = NULL; |
192 | | * conf->handler = NULL; |
193 | | * conf->output_filters = NULL; |
194 | | * conf->input_filters = NULL; |
195 | | */ |
196 | | |
197 | | /* |
198 | | * Flag for use of inodes in ETags. |
199 | | */ |
200 | 0 | conf->etag_bits = ETAG_UNSET; |
201 | 0 | conf->etag_add = ETAG_UNSET; |
202 | 0 | conf->etag_remove = ETAG_UNSET; |
203 | |
|
204 | 0 | conf->enable_mmap = ENABLE_MMAP_UNSET; |
205 | 0 | conf->enable_sendfile = ENABLE_SENDFILE_UNSET; |
206 | 0 | conf->allow_encoded_slashes = 0; |
207 | 0 | conf->decode_encoded_slashes = 0; |
208 | |
|
209 | 0 | conf->max_ranges = AP_MAXRANGES_UNSET; |
210 | 0 | conf->max_overlaps = AP_MAXRANGES_UNSET; |
211 | 0 | conf->max_reversals = AP_MAXRANGES_UNSET; |
212 | |
|
213 | 0 | conf->cgi_pass_auth = AP_CGI_PASS_AUTH_UNSET; |
214 | 0 | conf->qualify_redirect_url = AP_CORE_CONFIG_UNSET; |
215 | |
|
216 | 0 | return (void *)conf; |
217 | 0 | } |
218 | | |
219 | | static void *merge_core_dir_configs(apr_pool_t *a, void *basev, void *newv) |
220 | 0 | { |
221 | 0 | core_dir_config *base = (core_dir_config *)basev; |
222 | 0 | core_dir_config *new = (core_dir_config *)newv; |
223 | 0 | core_dir_config *conf; |
224 | | |
225 | | /* Create this conf by duplicating the base, replacing elements |
226 | | * (or creating copies for merging) where new-> values exist. |
227 | | */ |
228 | 0 | conf = (core_dir_config *)apr_pmemdup(a, base, sizeof(core_dir_config)); |
229 | |
|
230 | 0 | conf->d = new->d; |
231 | 0 | conf->d_is_fnmatch = new->d_is_fnmatch; |
232 | 0 | conf->d_components = new->d_components; |
233 | 0 | conf->r = new->r; |
234 | 0 | conf->refs = new->refs; |
235 | 0 | conf->condition = new->condition; |
236 | |
|
237 | 0 | if (new->opts & OPT_UNSET) { |
238 | | /* there was no explicit setting of new->opts, so we merge |
239 | | * preserve the invariant (opts_add & opts_remove) == 0 |
240 | | */ |
241 | 0 | conf->opts_add = (conf->opts_add & ~new->opts_remove) | new->opts_add; |
242 | 0 | conf->opts_remove = (conf->opts_remove & ~new->opts_add) |
243 | 0 | | new->opts_remove; |
244 | 0 | conf->opts = (conf->opts & ~conf->opts_remove) | conf->opts_add; |
245 | | |
246 | | /* If Includes was enabled with exec in the base config, but |
247 | | * was enabled without exec in the new config, then disable |
248 | | * exec in the merged set. */ |
249 | 0 | if (((base->opts & (OPT_INCLUDES|OPT_INC_WITH_EXEC)) |
250 | 0 | == (OPT_INCLUDES|OPT_INC_WITH_EXEC)) |
251 | 0 | && ((new->opts & (OPT_INCLUDES|OPT_INC_WITH_EXEC)) |
252 | 0 | == OPT_INCLUDES)) { |
253 | 0 | conf->opts &= ~OPT_INC_WITH_EXEC; |
254 | 0 | } |
255 | 0 | } |
256 | 0 | else { |
257 | | /* otherwise we just copy, because an explicit opts setting |
258 | | * overrides all earlier +/- modifiers |
259 | | */ |
260 | 0 | conf->opts = new->opts; |
261 | 0 | conf->opts_add = new->opts_add; |
262 | 0 | conf->opts_remove = new->opts_remove; |
263 | 0 | } |
264 | |
|
265 | 0 | if (!(new->override & OR_UNSET)) { |
266 | 0 | conf->override = new->override; |
267 | 0 | } |
268 | |
|
269 | 0 | if (!(new->override_opts & OPT_UNSET)) { |
270 | 0 | conf->override_opts = new->override_opts; |
271 | 0 | } |
272 | |
|
273 | 0 | if (new->override_list != NULL) { |
274 | 0 | conf->override_list = new->override_list; |
275 | 0 | } |
276 | |
|
277 | 0 | if (conf->response_code_exprs == NULL) { |
278 | 0 | conf->response_code_exprs = new->response_code_exprs; |
279 | 0 | } |
280 | 0 | else if (new->response_code_exprs != NULL) { |
281 | 0 | conf->response_code_exprs = apr_hash_overlay(a, |
282 | 0 | new->response_code_exprs, conf->response_code_exprs); |
283 | 0 | } |
284 | | /* Otherwise we simply use the base->response_code_exprs array |
285 | | */ |
286 | |
|
287 | 0 | if (new->hostname_lookups != HOSTNAME_LOOKUP_UNSET) { |
288 | 0 | conf->hostname_lookups = new->hostname_lookups; |
289 | 0 | } |
290 | |
|
291 | 0 | if (new->accept_path_info != AP_ACCEPT_PATHINFO_UNSET) { |
292 | 0 | conf->accept_path_info = new->accept_path_info; |
293 | 0 | } |
294 | |
|
295 | 0 | if (new->use_canonical_name != USE_CANONICAL_NAME_UNSET) { |
296 | 0 | conf->use_canonical_name = new->use_canonical_name; |
297 | 0 | } |
298 | |
|
299 | 0 | if (new->use_canonical_phys_port != USE_CANONICAL_PHYS_PORT_UNSET) { |
300 | 0 | conf->use_canonical_phys_port = new->use_canonical_phys_port; |
301 | 0 | } |
302 | |
|
303 | 0 | #ifdef RLIMIT_CPU |
304 | 0 | if (new->limit_cpu) { |
305 | 0 | conf->limit_cpu = new->limit_cpu; |
306 | 0 | } |
307 | 0 | #endif |
308 | |
|
309 | 0 | #if defined(RLIMIT_DATA) || defined(RLIMIT_VMEM) || defined(RLIMIT_AS) |
310 | 0 | if (new->limit_mem) { |
311 | 0 | conf->limit_mem = new->limit_mem; |
312 | 0 | } |
313 | 0 | #endif |
314 | |
|
315 | 0 | #ifdef RLIMIT_NPROC |
316 | 0 | if (new->limit_nproc) { |
317 | 0 | conf->limit_nproc = new->limit_nproc; |
318 | 0 | } |
319 | 0 | #endif |
320 | |
|
321 | 0 | if (new->limit_req_body != AP_LIMIT_REQ_BODY_UNSET) { |
322 | 0 | conf->limit_req_body = new->limit_req_body; |
323 | 0 | } |
324 | |
|
325 | 0 | if (new->limit_xml_body != AP_LIMIT_UNSET) |
326 | 0 | conf->limit_xml_body = new->limit_xml_body; |
327 | |
|
328 | 0 | if (!conf->sec_file) { |
329 | 0 | conf->sec_file = new->sec_file; |
330 | 0 | } |
331 | 0 | else if (new->sec_file) { |
332 | | /* If we merge, the merge-result must have its own array |
333 | | */ |
334 | 0 | conf->sec_file = apr_array_append(a, base->sec_file, new->sec_file); |
335 | 0 | } |
336 | | /* Otherwise we simply use the base->sec_file array |
337 | | */ |
338 | |
|
339 | 0 | if (!conf->sec_if) { |
340 | 0 | conf->sec_if = new->sec_if; |
341 | 0 | } |
342 | 0 | else if (new->sec_if) { |
343 | | /* If we merge, the merge-result must have its own array |
344 | | */ |
345 | 0 | conf->sec_if = apr_array_append(a, base->sec_if, new->sec_if); |
346 | 0 | } |
347 | | /* Otherwise we simply use the base->sec_if array |
348 | | */ |
349 | |
|
350 | 0 | if (new->server_signature != srv_sig_unset) { |
351 | 0 | conf->server_signature = new->server_signature; |
352 | 0 | } |
353 | |
|
354 | 0 | if (new->add_default_charset != ADD_DEFAULT_CHARSET_UNSET) { |
355 | 0 | conf->add_default_charset = new->add_default_charset; |
356 | 0 | conf->add_default_charset_name = new->add_default_charset_name; |
357 | 0 | } |
358 | | |
359 | | /* Overriding all negotiation |
360 | | */ |
361 | 0 | if (new->mime_type) { |
362 | 0 | conf->mime_type = new->mime_type; |
363 | 0 | } |
364 | |
|
365 | 0 | if (new->handler) { |
366 | 0 | conf->handler = new->handler; |
367 | 0 | } |
368 | 0 | if (new->expr_handler) { |
369 | 0 | conf->expr_handler = new->expr_handler; |
370 | 0 | } |
371 | |
|
372 | 0 | if (new->output_filters) { |
373 | 0 | conf->output_filters = new->output_filters; |
374 | 0 | } |
375 | |
|
376 | 0 | if (new->input_filters) { |
377 | 0 | conf->input_filters = new->input_filters; |
378 | 0 | } |
379 | | |
380 | | /* |
381 | | * Now merge the setting of the FileETag directive. |
382 | | */ |
383 | 0 | if (new->etag_bits == ETAG_UNSET) { |
384 | 0 | conf->etag_add = |
385 | 0 | (conf->etag_add & (~ new->etag_remove)) | new->etag_add; |
386 | 0 | conf->etag_remove = |
387 | 0 | (conf->etag_remove & (~ new->etag_add)) | new->etag_remove; |
388 | 0 | conf->etag_bits = |
389 | 0 | (conf->etag_bits & (~ conf->etag_remove)) | conf->etag_add; |
390 | 0 | } |
391 | 0 | else { |
392 | 0 | conf->etag_bits = new->etag_bits; |
393 | 0 | conf->etag_add = new->etag_add; |
394 | 0 | conf->etag_remove = new->etag_remove; |
395 | 0 | } |
396 | |
|
397 | 0 | if (conf->etag_bits != ETAG_NONE) { |
398 | 0 | conf->etag_bits &= (~ ETAG_NONE); |
399 | 0 | } |
400 | |
|
401 | 0 | if (new->enable_mmap != ENABLE_MMAP_UNSET) { |
402 | 0 | conf->enable_mmap = new->enable_mmap; |
403 | 0 | } |
404 | |
|
405 | 0 | if (new->enable_sendfile != ENABLE_SENDFILE_UNSET) { |
406 | 0 | conf->enable_sendfile = new->enable_sendfile; |
407 | 0 | } |
408 | | |
409 | 0 | if (new->read_buf_size) { |
410 | 0 | conf->read_buf_size = new->read_buf_size; |
411 | 0 | } |
412 | 0 | else { |
413 | 0 | conf->read_buf_size = base->read_buf_size; |
414 | 0 | } |
415 | |
|
416 | 0 | if (new->allow_encoded_slashes_set) { |
417 | 0 | conf->allow_encoded_slashes = new->allow_encoded_slashes; |
418 | 0 | } |
419 | 0 | if (new->decode_encoded_slashes_set) { |
420 | 0 | conf->decode_encoded_slashes = new->decode_encoded_slashes; |
421 | 0 | } |
422 | |
|
423 | 0 | if (new->log) { |
424 | 0 | if (!conf->log) { |
425 | 0 | conf->log = new->log; |
426 | 0 | } |
427 | 0 | else { |
428 | 0 | conf->log = ap_new_log_config(a, new->log); |
429 | 0 | ap_merge_log_config(base->log, conf->log); |
430 | 0 | } |
431 | 0 | } |
432 | |
|
433 | 0 | conf->max_ranges = new->max_ranges != AP_MAXRANGES_UNSET ? new->max_ranges : base->max_ranges; |
434 | 0 | conf->max_overlaps = new->max_overlaps != AP_MAXRANGES_UNSET ? new->max_overlaps : base->max_overlaps; |
435 | 0 | conf->max_reversals = new->max_reversals != AP_MAXRANGES_UNSET ? new->max_reversals : base->max_reversals; |
436 | |
|
437 | 0 | conf->cgi_pass_auth = new->cgi_pass_auth != AP_CGI_PASS_AUTH_UNSET ? new->cgi_pass_auth : base->cgi_pass_auth; |
438 | |
|
439 | 0 | if (new->cgi_var_rules) { |
440 | 0 | if (!conf->cgi_var_rules) { |
441 | 0 | conf->cgi_var_rules = new->cgi_var_rules; |
442 | 0 | } |
443 | 0 | else { |
444 | 0 | conf->cgi_var_rules = apr_hash_overlay(a, new->cgi_var_rules, conf->cgi_var_rules); |
445 | 0 | } |
446 | 0 | } |
447 | |
|
448 | 0 | AP_CORE_MERGE_FLAG(qualify_redirect_url, conf, base, new); |
449 | |
|
450 | 0 | return (void*)conf; |
451 | 0 | } |
452 | | |
453 | | #if APR_HAS_SO_ACCEPTFILTER |
454 | | #ifndef ACCEPT_FILTER_NAME |
455 | | #define ACCEPT_FILTER_NAME "httpready" |
456 | | #ifdef __FreeBSD_version |
457 | | #if __FreeBSD_version < 411000 /* httpready broken before 4.1.1 */ |
458 | | #undef ACCEPT_FILTER_NAME |
459 | | #define ACCEPT_FILTER_NAME "dataready" |
460 | | #endif |
461 | | #endif |
462 | | #endif |
463 | | #endif |
464 | | |
465 | | static void *create_core_server_config(apr_pool_t *a, server_rec *s) |
466 | 0 | { |
467 | 0 | core_server_config *conf; |
468 | 0 | int is_virtual = s->is_virtual; |
469 | |
|
470 | 0 | conf = (core_server_config *)apr_pcalloc(a, sizeof(core_server_config)); |
471 | | |
472 | | /* global-default / global-only settings */ |
473 | |
|
474 | 0 | if (!is_virtual) { |
475 | 0 | conf->ap_document_root = DOCUMENT_LOCATION; |
476 | 0 | conf->access_name = DEFAULT_ACCESS_FNAME; |
477 | | |
478 | | /* A mapping only makes sense in the global context */ |
479 | 0 | conf->accf_map = apr_table_make(a, 5); |
480 | | #if APR_HAS_SO_ACCEPTFILTER |
481 | | apr_table_setn(conf->accf_map, "http", ACCEPT_FILTER_NAME); |
482 | | apr_table_setn(conf->accf_map, "https", "dataready"); |
483 | | #elif defined(WIN32) |
484 | | /* 'data' is disabled on Windows due to a DoS vuln (PR 59970) */ |
485 | | apr_table_setn(conf->accf_map, "http", "connect"); |
486 | | apr_table_setn(conf->accf_map, "https", "connect"); |
487 | | #else |
488 | 0 | apr_table_setn(conf->accf_map, "http", "data"); |
489 | 0 | apr_table_setn(conf->accf_map, "https", "data"); |
490 | 0 | #endif |
491 | |
|
492 | 0 | conf->flush_max_threshold = AP_FLUSH_MAX_THRESHOLD; |
493 | 0 | conf->flush_max_pipelined = AP_FLUSH_MAX_PIPELINED; |
494 | 0 | } |
495 | 0 | else { |
496 | | /* Use main ErrorLogFormat while the vhost is loading */ |
497 | 0 | core_server_config *main_conf = |
498 | 0 | ap_get_core_module_config(ap_server_conf->module_config); |
499 | 0 | conf->error_log_format = main_conf->error_log_format; |
500 | |
|
501 | 0 | conf->flush_max_pipelined = -1; |
502 | 0 | } |
503 | | |
504 | | /* initialization, no special case for global context */ |
505 | |
|
506 | 0 | conf->sec_dir = apr_array_make(a, 40, sizeof(ap_conf_vector_t *)); |
507 | 0 | conf->sec_url = apr_array_make(a, 40, sizeof(ap_conf_vector_t *)); |
508 | | |
509 | | /* pcalloc'ed - we have NULL's/0's |
510 | | conf->gprof_dir = NULL; |
511 | | |
512 | | ** recursion stopper; 0 == unset |
513 | | conf->redirect_limit = 0; |
514 | | conf->subreq_limit = 0; |
515 | | |
516 | | conf->protocol = NULL; |
517 | | */ |
518 | |
|
519 | 0 | conf->trace_enable = AP_TRACE_UNSET; |
520 | |
|
521 | 0 | conf->protocols = apr_array_make(a, 5, sizeof(const char *)); |
522 | 0 | conf->protocols_honor_order = -1; |
523 | 0 | conf->async_filter = 0; |
524 | 0 | conf->strict_host_check= AP_CORE_CONFIG_UNSET; |
525 | 0 | conf->merge_slashes = AP_CORE_CONFIG_UNSET; |
526 | |
|
527 | 0 | return (void *)conf; |
528 | 0 | } |
529 | | |
530 | | static void *merge_core_server_configs(apr_pool_t *p, void *basev, void *virtv) |
531 | 0 | { |
532 | 0 | core_server_config *base = (core_server_config *)basev; |
533 | 0 | core_server_config *virt = (core_server_config *)virtv; |
534 | 0 | core_server_config *conf = (core_server_config *) |
535 | 0 | apr_pmemdup(p, base, sizeof(core_server_config)); |
536 | |
|
537 | 0 | if (virt->ap_document_root) |
538 | 0 | conf->ap_document_root = virt->ap_document_root; |
539 | |
|
540 | 0 | if (virt->access_name) |
541 | 0 | conf->access_name = virt->access_name; |
542 | | |
543 | | /* XXX optimize to keep base->sec_ pointers if virt->sec_ array is empty */ |
544 | 0 | conf->sec_dir = apr_array_append(p, base->sec_dir, virt->sec_dir); |
545 | 0 | conf->sec_url = apr_array_append(p, base->sec_url, virt->sec_url); |
546 | |
|
547 | 0 | if (virt->redirect_limit) |
548 | 0 | conf->redirect_limit = virt->redirect_limit; |
549 | |
|
550 | 0 | if (virt->subreq_limit) |
551 | 0 | conf->subreq_limit = virt->subreq_limit; |
552 | |
|
553 | 0 | if (virt->trace_enable != AP_TRACE_UNSET) |
554 | 0 | conf->trace_enable = virt->trace_enable; |
555 | |
|
556 | 0 | if (virt->http09_enable != AP_HTTP09_UNSET) |
557 | 0 | conf->http09_enable = virt->http09_enable; |
558 | |
|
559 | 0 | if (virt->http_conformance != AP_HTTP_CONFORMANCE_UNSET) |
560 | 0 | conf->http_conformance = virt->http_conformance; |
561 | |
|
562 | 0 | if (virt->http_methods != AP_HTTP_METHODS_UNSET) |
563 | 0 | conf->http_methods = virt->http_methods; |
564 | |
|
565 | 0 | if (virt->http_cl_head_zero != AP_HTTP_CL_HEAD_ZERO_UNSET) |
566 | 0 | conf->http_cl_head_zero = virt->http_cl_head_zero; |
567 | |
|
568 | 0 | if (virt->http_expect_strict != AP_HTTP_EXPECT_STRICT_UNSET) |
569 | 0 | conf->http_expect_strict = virt->http_expect_strict; |
570 | | |
571 | | /* no action for virt->accf_map, not allowed per-vhost */ |
572 | |
|
573 | 0 | if (virt->protocol) |
574 | 0 | conf->protocol = virt->protocol; |
575 | |
|
576 | 0 | if (virt->gprof_dir) |
577 | 0 | conf->gprof_dir = virt->gprof_dir; |
578 | |
|
579 | 0 | if (virt->error_log_format) |
580 | 0 | conf->error_log_format = virt->error_log_format; |
581 | |
|
582 | 0 | if (virt->error_log_conn) |
583 | 0 | conf->error_log_conn = virt->error_log_conn; |
584 | |
|
585 | 0 | if (virt->error_log_req) |
586 | 0 | conf->error_log_req = virt->error_log_req; |
587 | |
|
588 | 0 | if (virt->conn_log_level) { |
589 | 0 | if (!conf->conn_log_level) { |
590 | 0 | conf->conn_log_level = virt->conn_log_level; |
591 | 0 | } |
592 | 0 | else { |
593 | | /* apr_array_append actually creates a new array */ |
594 | 0 | conf->conn_log_level = apr_array_append(p, conf->conn_log_level, |
595 | 0 | virt->conn_log_level); |
596 | 0 | } |
597 | 0 | } |
598 | |
|
599 | 0 | conf->merge_trailers = (virt->merge_trailers != AP_MERGE_TRAILERS_UNSET) |
600 | 0 | ? virt->merge_trailers |
601 | 0 | : base->merge_trailers; |
602 | |
|
603 | 0 | conf->protocols = ((virt->protocols->nelts > 0) ? |
604 | 0 | virt->protocols : base->protocols); |
605 | 0 | conf->protocols_honor_order = ((virt->protocols_honor_order < 0) ? |
606 | 0 | base->protocols_honor_order : |
607 | 0 | virt->protocols_honor_order); |
608 | |
|
609 | 0 | conf->async_filter = ((virt->async_filter_set) ? |
610 | 0 | virt->async_filter : |
611 | 0 | base->async_filter); |
612 | 0 | conf->async_filter_set = base->async_filter_set || virt->async_filter_set; |
613 | |
|
614 | 0 | conf->flush_max_threshold = (virt->flush_max_threshold) |
615 | 0 | ? virt->flush_max_threshold |
616 | 0 | : base->flush_max_threshold; |
617 | 0 | conf->flush_max_pipelined = (virt->flush_max_pipelined >= 0) |
618 | 0 | ? virt->flush_max_pipelined |
619 | 0 | : base->flush_max_pipelined; |
620 | |
|
621 | 0 | conf->strict_host_check = (virt->strict_host_check != AP_CORE_CONFIG_UNSET) |
622 | 0 | ? virt->strict_host_check |
623 | 0 | : base->strict_host_check; |
624 | |
|
625 | 0 | AP_CORE_MERGE_FLAG(strict_host_check, conf, base, virt); |
626 | 0 | AP_CORE_MERGE_FLAG(merge_slashes, conf, base, virt); |
627 | |
|
628 | 0 | return conf; |
629 | 0 | } |
630 | | |
631 | | /* Add per-directory configuration entry (for <directory> section); |
632 | | * these are part of the core server config. |
633 | | */ |
634 | | |
635 | | AP_CORE_DECLARE(void) ap_add_per_dir_conf(server_rec *s, void *dir_config) |
636 | 0 | { |
637 | 0 | core_server_config *sconf = ap_get_core_module_config(s->module_config); |
638 | 0 | void **new_space = (void **)apr_array_push(sconf->sec_dir); |
639 | |
|
640 | 0 | *new_space = dir_config; |
641 | 0 | } |
642 | | |
643 | | AP_CORE_DECLARE(void) ap_add_per_url_conf(server_rec *s, void *url_config) |
644 | 0 | { |
645 | 0 | core_server_config *sconf = ap_get_core_module_config(s->module_config); |
646 | 0 | void **new_space = (void **)apr_array_push(sconf->sec_url); |
647 | |
|
648 | 0 | *new_space = url_config; |
649 | 0 | } |
650 | | |
651 | | AP_CORE_DECLARE(void) ap_add_file_conf(apr_pool_t *p, core_dir_config *conf, |
652 | | void *url_config) |
653 | 0 | { |
654 | 0 | void **new_space; |
655 | |
|
656 | 0 | if (!conf->sec_file) |
657 | 0 | conf->sec_file = apr_array_make(p, 2, sizeof(ap_conf_vector_t *)); |
658 | |
|
659 | 0 | new_space = (void **)apr_array_push(conf->sec_file); |
660 | 0 | *new_space = url_config; |
661 | 0 | } |
662 | | |
663 | | AP_CORE_DECLARE(const char *) ap_add_if_conf(apr_pool_t *p, |
664 | | core_dir_config *conf, |
665 | | void *if_config) |
666 | 0 | { |
667 | 0 | void **new_space; |
668 | 0 | core_dir_config *new = ap_get_module_config(if_config, &core_module); |
669 | |
|
670 | 0 | if (!conf->sec_if) { |
671 | 0 | conf->sec_if = apr_array_make(p, 2, sizeof(ap_conf_vector_t *)); |
672 | 0 | } |
673 | 0 | if (new->condition_ifelse & AP_CONDITION_ELSE) { |
674 | 0 | int have_if = 0; |
675 | 0 | if (conf->sec_if->nelts > 0) { |
676 | 0 | core_dir_config *last; |
677 | 0 | ap_conf_vector_t *lastelt = APR_ARRAY_IDX(conf->sec_if, |
678 | 0 | conf->sec_if->nelts - 1, |
679 | 0 | ap_conf_vector_t *); |
680 | 0 | last = ap_get_module_config(lastelt, &core_module); |
681 | 0 | if (last->condition_ifelse & AP_CONDITION_IF) |
682 | 0 | have_if = 1; |
683 | 0 | } |
684 | 0 | if (!have_if) |
685 | 0 | return "<Else> or <ElseIf> section without previous <If> or " |
686 | 0 | "<ElseIf> section in same scope"; |
687 | 0 | } |
688 | | |
689 | 0 | new_space = (void **)apr_array_push(conf->sec_if); |
690 | 0 | *new_space = if_config; |
691 | 0 | return NULL; |
692 | 0 | } |
693 | | |
694 | | |
695 | | /* We need to do a stable sort, qsort isn't stable. So to make it stable |
696 | | * we'll be maintaining the original index into the list, and using it |
697 | | * as the minor key during sorting. The major key is the number of |
698 | | * components (where the root component is zero). |
699 | | */ |
700 | | struct reorder_sort_rec { |
701 | | ap_conf_vector_t *elt; |
702 | | int orig_index; |
703 | | }; |
704 | | |
705 | | static int reorder_sorter(const void *va, const void *vb) |
706 | 0 | { |
707 | 0 | const struct reorder_sort_rec *a = va; |
708 | 0 | const struct reorder_sort_rec *b = vb; |
709 | 0 | core_dir_config *core_a; |
710 | 0 | core_dir_config *core_b; |
711 | |
|
712 | 0 | core_a = ap_get_core_module_config(a->elt); |
713 | 0 | core_b = ap_get_core_module_config(b->elt); |
714 | | |
715 | | /* a regex always sorts after a non-regex |
716 | | */ |
717 | 0 | if (!core_a->r && core_b->r) { |
718 | 0 | return -1; |
719 | 0 | } |
720 | 0 | else if (core_a->r && !core_b->r) { |
721 | 0 | return 1; |
722 | 0 | } |
723 | | |
724 | | /* we always sort next by the number of components |
725 | | */ |
726 | 0 | if (core_a->d_components < core_b->d_components) { |
727 | 0 | return -1; |
728 | 0 | } |
729 | 0 | else if (core_a->d_components > core_b->d_components) { |
730 | 0 | return 1; |
731 | 0 | } |
732 | | |
733 | | /* They have the same number of components, we now have to compare |
734 | | * the minor key to maintain the original order (from the config.) |
735 | | */ |
736 | 0 | return a->orig_index - b->orig_index; |
737 | 0 | } |
738 | | |
739 | | void ap_core_reorder_directories(apr_pool_t *p, server_rec *s) |
740 | 0 | { |
741 | 0 | core_server_config *sconf; |
742 | 0 | apr_array_header_t *sec_dir; |
743 | 0 | struct reorder_sort_rec *sortbin; |
744 | 0 | int nelts; |
745 | 0 | ap_conf_vector_t **elts; |
746 | 0 | int i; |
747 | 0 | apr_pool_t *tmp; |
748 | |
|
749 | 0 | sconf = ap_get_core_module_config(s->module_config); |
750 | 0 | sec_dir = sconf->sec_dir; |
751 | 0 | nelts = sec_dir->nelts; |
752 | 0 | elts = (ap_conf_vector_t **)sec_dir->elts; |
753 | |
|
754 | 0 | if (!nelts) { |
755 | | /* simple case of already being sorted... */ |
756 | | /* We're not checking this condition to be fast... we're checking |
757 | | * it to avoid trying to palloc zero bytes, which can trigger some |
758 | | * memory debuggers to barf |
759 | | */ |
760 | 0 | return; |
761 | 0 | } |
762 | | |
763 | | /* we have to allocate tmp space to do a stable sort */ |
764 | 0 | apr_pool_create(&tmp, p); |
765 | 0 | apr_pool_tag(tmp, "core_reorder_directories"); |
766 | 0 | sortbin = apr_palloc(tmp, sec_dir->nelts * sizeof(*sortbin)); |
767 | 0 | for (i = 0; i < nelts; ++i) { |
768 | 0 | sortbin[i].orig_index = i; |
769 | 0 | sortbin[i].elt = elts[i]; |
770 | 0 | } |
771 | |
|
772 | 0 | qsort(sortbin, nelts, sizeof(*sortbin), reorder_sorter); |
773 | | |
774 | | /* and now copy back to the original array */ |
775 | 0 | for (i = 0; i < nelts; ++i) { |
776 | 0 | elts[i] = sortbin[i].elt; |
777 | 0 | } |
778 | |
|
779 | 0 | apr_pool_destroy(tmp); |
780 | 0 | } |
781 | | |
782 | | /***************************************************************** |
783 | | * |
784 | | * There are some elements of the core config structures in which |
785 | | * other modules have a legitimate interest (this is ugly, but necessary |
786 | | * to preserve NCSA back-compatibility). So, we have a bunch of accessors |
787 | | * here... |
788 | | */ |
789 | | |
790 | | AP_DECLARE(int) ap_allow_options(request_rec *r) |
791 | 0 | { |
792 | 0 | core_dir_config *conf = |
793 | 0 | (core_dir_config *)ap_get_core_module_config(r->per_dir_config); |
794 | |
|
795 | 0 | return conf->opts; |
796 | 0 | } |
797 | | |
798 | | AP_DECLARE(int) ap_allow_overrides(request_rec *r) |
799 | 0 | { |
800 | 0 | core_dir_config *conf; |
801 | 0 | conf = (core_dir_config *)ap_get_core_module_config(r->per_dir_config); |
802 | |
|
803 | 0 | return conf->override; |
804 | 0 | } |
805 | | |
806 | | /* |
807 | | * Optional function coming from mod_authn_core, used for |
808 | | * retrieving the type of authorization |
809 | | */ |
810 | | static APR_OPTIONAL_FN_TYPE(authn_ap_auth_type) *authn_ap_auth_type; |
811 | | |
812 | | AP_DECLARE(const char *) ap_auth_type(request_rec *r) |
813 | 0 | { |
814 | 0 | if (authn_ap_auth_type) { |
815 | 0 | return authn_ap_auth_type(r); |
816 | 0 | } |
817 | 0 | return NULL; |
818 | 0 | } |
819 | | |
820 | | /* |
821 | | * Optional function coming from mod_authn_core, used for |
822 | | * retrieving the authorization realm |
823 | | */ |
824 | | static APR_OPTIONAL_FN_TYPE(authn_ap_auth_name) *authn_ap_auth_name; |
825 | | |
826 | | AP_DECLARE(const char *) ap_auth_name(request_rec *r) |
827 | 0 | { |
828 | 0 | if (authn_ap_auth_name) { |
829 | 0 | return authn_ap_auth_name(r); |
830 | 0 | } |
831 | 0 | return NULL; |
832 | 0 | } |
833 | | |
834 | | /* |
835 | | * Optional function coming from mod_access_compat, used to determine how |
836 | | access control interacts with authentication/authorization |
837 | | */ |
838 | | static APR_OPTIONAL_FN_TYPE(access_compat_ap_satisfies) *access_compat_ap_satisfies; |
839 | | |
840 | | AP_DECLARE(int) ap_satisfies(request_rec *r) |
841 | 0 | { |
842 | 0 | if (access_compat_ap_satisfies) { |
843 | 0 | return access_compat_ap_satisfies(r); |
844 | 0 | } |
845 | 0 | return SATISFY_NOSPEC; |
846 | 0 | } |
847 | | |
848 | | AP_DECLARE(const char *) ap_document_root(request_rec *r) /* Don't use this! */ |
849 | 0 | { |
850 | 0 | core_server_config *sconf; |
851 | 0 | core_request_config *rconf = ap_get_core_module_config(r->request_config); |
852 | 0 | if (rconf->document_root) |
853 | 0 | return rconf->document_root; |
854 | 0 | sconf = ap_get_core_module_config(r->server->module_config); |
855 | 0 | return sconf->ap_document_root; |
856 | 0 | } |
857 | | |
858 | | AP_DECLARE(const char *) ap_context_prefix(request_rec *r) |
859 | 0 | { |
860 | 0 | core_request_config *conf = ap_get_core_module_config(r->request_config); |
861 | 0 | if (conf->context_prefix) |
862 | 0 | return conf->context_prefix; |
863 | 0 | else |
864 | 0 | return ""; |
865 | 0 | } |
866 | | |
867 | | AP_DECLARE(const char *) ap_context_document_root(request_rec *r) |
868 | 0 | { |
869 | 0 | core_request_config *conf = ap_get_core_module_config(r->request_config); |
870 | 0 | if (conf->context_document_root) |
871 | 0 | return conf->context_document_root; |
872 | 0 | else |
873 | 0 | return ap_document_root(r); |
874 | 0 | } |
875 | | |
876 | | AP_DECLARE(void) ap_set_document_root(request_rec *r, const char *document_root) |
877 | 0 | { |
878 | 0 | core_request_config *conf = ap_get_core_module_config(r->request_config); |
879 | 0 | conf->document_root = document_root; |
880 | 0 | } |
881 | | |
882 | | AP_DECLARE(void) ap_set_context_info(request_rec *r, const char *context_prefix, |
883 | | const char *context_document_root) |
884 | 0 | { |
885 | 0 | core_request_config *conf = ap_get_core_module_config(r->request_config); |
886 | 0 | if (context_prefix) |
887 | 0 | conf->context_prefix = context_prefix; |
888 | 0 | if (context_document_root) |
889 | 0 | conf->context_document_root = context_document_root; |
890 | 0 | } |
891 | | |
892 | | /* Should probably just get rid of this... the only code that cares is |
893 | | * part of the core anyway (and in fact, it isn't publicised to other |
894 | | * modules). |
895 | | */ |
896 | | |
897 | | char *ap_response_code_string(request_rec *r, int error_index) |
898 | 0 | { |
899 | 0 | core_dir_config *dirconf; |
900 | 0 | core_request_config *reqconf = ap_get_core_module_config(r->request_config); |
901 | 0 | const char *err; |
902 | 0 | const char *response; |
903 | 0 | ap_expr_info_t *expr; |
904 | | |
905 | | /* check for string registered via ap_custom_response() first */ |
906 | 0 | if (reqconf->response_code_strings != NULL |
907 | 0 | && reqconf->response_code_strings[error_index] != NULL) { |
908 | 0 | return reqconf->response_code_strings[error_index]; |
909 | 0 | } |
910 | | |
911 | | /* check for string specified via ErrorDocument */ |
912 | 0 | dirconf = ap_get_core_module_config(r->per_dir_config); |
913 | |
|
914 | 0 | if (!dirconf->response_code_exprs) { |
915 | 0 | return NULL; |
916 | 0 | } |
917 | | |
918 | 0 | expr = apr_hash_get(dirconf->response_code_exprs, &error_index, |
919 | 0 | sizeof(error_index)); |
920 | 0 | if (!expr) { |
921 | 0 | return NULL; |
922 | 0 | } |
923 | | |
924 | | /* special token to indicate revert back to default */ |
925 | 0 | if ((char *) expr == &errordocument_default) { |
926 | 0 | return NULL; |
927 | 0 | } |
928 | | |
929 | 0 | err = NULL; |
930 | 0 | response = ap_expr_str_exec(r, expr, &err); |
931 | 0 | if (err) { |
932 | 0 | ap_log_rerror( |
933 | 0 | APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(02841) "core: ErrorDocument: can't " |
934 | 0 | "evaluate require expression: %s", err); |
935 | 0 | return NULL; |
936 | 0 | } |
937 | | |
938 | | /* alas, duplication required as we return not-const */ |
939 | 0 | return apr_pstrdup(r->pool, response); |
940 | 0 | } |
941 | | |
942 | | |
943 | | /* Code from Harald Hanche-Olsen <hanche@imf.unit.no> */ |
944 | | static APR_INLINE int do_double_reverse (int double_reverse, |
945 | | const char *remote_host, |
946 | | apr_sockaddr_t *client_addr, |
947 | | apr_pool_t *pool) |
948 | 0 | { |
949 | 0 | apr_sockaddr_t *sa; |
950 | 0 | apr_status_t rv; |
951 | |
|
952 | 0 | if (double_reverse) { |
953 | | /* already done */ |
954 | 0 | return double_reverse; |
955 | 0 | } |
956 | | |
957 | 0 | if (remote_host == NULL || remote_host[0] == '\0') { |
958 | | /* single reverse failed, so don't bother */ |
959 | 0 | return -1; |
960 | 0 | } |
961 | | |
962 | 0 | rv = apr_sockaddr_info_get(&sa, remote_host, APR_UNSPEC, 0, 0, pool); |
963 | 0 | if (rv == APR_SUCCESS) { |
964 | 0 | while (sa) { |
965 | 0 | if (apr_sockaddr_equal(sa, client_addr)) { |
966 | 0 | return 1; |
967 | 0 | } |
968 | | |
969 | 0 | sa = sa->next; |
970 | 0 | } |
971 | 0 | } |
972 | | |
973 | 0 | return -1; |
974 | 0 | } |
975 | | |
976 | | AP_DECLARE(const char *) ap_get_remote_host(conn_rec *conn, void *dir_config, |
977 | | int type, int *str_is_ip) |
978 | 0 | { |
979 | 0 | int hostname_lookups; |
980 | 0 | int ignored_str_is_ip; |
981 | |
|
982 | 0 | if (!str_is_ip) { /* caller doesn't want to know */ |
983 | 0 | str_is_ip = &ignored_str_is_ip; |
984 | 0 | } |
985 | 0 | *str_is_ip = 0; |
986 | | |
987 | | /* If we haven't checked the host name, and we want to */ |
988 | 0 | if (dir_config) { |
989 | 0 | hostname_lookups = ((core_dir_config *)ap_get_core_module_config(dir_config)) |
990 | 0 | ->hostname_lookups; |
991 | |
|
992 | 0 | if (hostname_lookups == HOSTNAME_LOOKUP_UNSET) { |
993 | 0 | hostname_lookups = HOSTNAME_LOOKUP_OFF; |
994 | 0 | } |
995 | 0 | } |
996 | 0 | else { |
997 | | /* the default */ |
998 | 0 | hostname_lookups = HOSTNAME_LOOKUP_OFF; |
999 | 0 | } |
1000 | |
|
1001 | 0 | if (type != REMOTE_NOLOOKUP |
1002 | 0 | && conn->remote_host == NULL |
1003 | 0 | && (type == REMOTE_DOUBLE_REV |
1004 | 0 | || hostname_lookups != HOSTNAME_LOOKUP_OFF)) { |
1005 | |
|
1006 | 0 | if (apr_getnameinfo(&conn->remote_host, conn->client_addr, 0) |
1007 | 0 | == APR_SUCCESS) { |
1008 | 0 | ap_str_tolower(conn->remote_host); |
1009 | |
|
1010 | 0 | if (hostname_lookups == HOSTNAME_LOOKUP_DOUBLE) { |
1011 | 0 | conn->double_reverse = do_double_reverse(conn->double_reverse, |
1012 | 0 | conn->remote_host, |
1013 | 0 | conn->client_addr, |
1014 | 0 | conn->pool); |
1015 | 0 | if (conn->double_reverse != 1) { |
1016 | 0 | conn->remote_host = NULL; |
1017 | 0 | } |
1018 | 0 | } |
1019 | 0 | } |
1020 | | |
1021 | | /* if failed, set it to the NULL string to indicate error */ |
1022 | 0 | if (conn->remote_host == NULL) { |
1023 | 0 | conn->remote_host = ""; |
1024 | 0 | } |
1025 | 0 | } |
1026 | |
|
1027 | 0 | if (type == REMOTE_DOUBLE_REV) { |
1028 | 0 | conn->double_reverse = do_double_reverse(conn->double_reverse, |
1029 | 0 | conn->remote_host, |
1030 | 0 | conn->client_addr, conn->pool); |
1031 | 0 | if (conn->double_reverse == -1) { |
1032 | 0 | return NULL; |
1033 | 0 | } |
1034 | 0 | } |
1035 | | |
1036 | | /* |
1037 | | * Return the desired information; either the remote DNS name, if found, |
1038 | | * or either NULL (if the hostname was requested) or the IP address |
1039 | | * (if any identifier was requested). |
1040 | | */ |
1041 | 0 | if (conn->remote_host != NULL && conn->remote_host[0] != '\0') { |
1042 | 0 | return conn->remote_host; |
1043 | 0 | } |
1044 | 0 | else { |
1045 | 0 | if (type == REMOTE_HOST || type == REMOTE_DOUBLE_REV) { |
1046 | 0 | return NULL; |
1047 | 0 | } |
1048 | 0 | else { |
1049 | 0 | *str_is_ip = 1; |
1050 | 0 | return conn->client_ip; |
1051 | 0 | } |
1052 | 0 | } |
1053 | 0 | } |
1054 | | |
1055 | | AP_DECLARE(const char *) ap_get_useragent_host(request_rec *r, |
1056 | | int type, int *str_is_ip) |
1057 | 0 | { |
1058 | 0 | conn_rec *conn = r->connection; |
1059 | 0 | int hostname_lookups; |
1060 | 0 | int ignored_str_is_ip; |
1061 | | |
1062 | | /* Guard here when examining the host before the read_request hook |
1063 | | * has populated an r->useragent_addr |
1064 | | */ |
1065 | 0 | if (!r->useragent_addr || (r->useragent_addr == conn->client_addr)) { |
1066 | 0 | return ap_get_remote_host(conn, r->per_dir_config, type, str_is_ip); |
1067 | 0 | } |
1068 | | |
1069 | 0 | if (!str_is_ip) { /* caller doesn't want to know */ |
1070 | 0 | str_is_ip = &ignored_str_is_ip; |
1071 | 0 | } |
1072 | 0 | *str_is_ip = 0; |
1073 | |
|
1074 | 0 | hostname_lookups = ((core_dir_config *) |
1075 | 0 | ap_get_core_module_config(r->per_dir_config)) |
1076 | 0 | ->hostname_lookups; |
1077 | 0 | if (hostname_lookups == HOSTNAME_LOOKUP_UNSET) { |
1078 | 0 | hostname_lookups = HOSTNAME_LOOKUP_OFF; |
1079 | 0 | } |
1080 | |
|
1081 | 0 | if (type != REMOTE_NOLOOKUP |
1082 | 0 | && r->useragent_host == NULL |
1083 | 0 | && (type == REMOTE_DOUBLE_REV |
1084 | 0 | || hostname_lookups != HOSTNAME_LOOKUP_OFF)) { |
1085 | |
|
1086 | 0 | if (apr_getnameinfo(&r->useragent_host, r->useragent_addr, 0) |
1087 | 0 | == APR_SUCCESS) { |
1088 | 0 | ap_str_tolower(r->useragent_host); |
1089 | |
|
1090 | 0 | if (hostname_lookups == HOSTNAME_LOOKUP_DOUBLE) { |
1091 | 0 | r->double_reverse = do_double_reverse(r->double_reverse, |
1092 | 0 | r->useragent_host, |
1093 | 0 | r->useragent_addr, |
1094 | 0 | r->pool); |
1095 | 0 | if (r->double_reverse != 1) { |
1096 | 0 | r->useragent_host = NULL; |
1097 | 0 | } |
1098 | 0 | } |
1099 | 0 | } |
1100 | | |
1101 | | /* if failed, set it to the NULL string to indicate error */ |
1102 | 0 | if (r->useragent_host == NULL) { |
1103 | 0 | r->useragent_host = ""; |
1104 | 0 | } |
1105 | 0 | } |
1106 | |
|
1107 | 0 | if (type == REMOTE_DOUBLE_REV) { |
1108 | 0 | r->double_reverse = do_double_reverse(r->double_reverse, |
1109 | 0 | r->useragent_host, |
1110 | 0 | r->useragent_addr, r->pool); |
1111 | 0 | if (r->double_reverse == -1) { |
1112 | 0 | return NULL; |
1113 | 0 | } |
1114 | 0 | } |
1115 | | |
1116 | | /* |
1117 | | * Return the desired information; either the remote DNS name, if found, |
1118 | | * or either NULL (if the hostname was requested) or the IP address |
1119 | | * (if any identifier was requested). |
1120 | | */ |
1121 | 0 | if (r->useragent_host != NULL && r->useragent_host[0] != '\0') { |
1122 | 0 | return r->useragent_host; |
1123 | 0 | } |
1124 | 0 | else { |
1125 | 0 | if (type == REMOTE_HOST || type == REMOTE_DOUBLE_REV) { |
1126 | 0 | return NULL; |
1127 | 0 | } |
1128 | 0 | else { |
1129 | 0 | *str_is_ip = 1; |
1130 | 0 | return r->useragent_ip; |
1131 | 0 | } |
1132 | 0 | } |
1133 | 0 | } |
1134 | | |
1135 | | /* |
1136 | | * Optional function coming from mod_ident, used for looking up ident user |
1137 | | */ |
1138 | | static APR_OPTIONAL_FN_TYPE(ap_ident_lookup) *ident_lookup; |
1139 | | |
1140 | | AP_DECLARE(const char *) ap_get_remote_logname(request_rec *r) |
1141 | 0 | { |
1142 | 0 | if (r->connection->remote_logname != NULL) { |
1143 | 0 | return r->connection->remote_logname; |
1144 | 0 | } |
1145 | | |
1146 | 0 | if (ident_lookup) { |
1147 | 0 | return ident_lookup(r); |
1148 | 0 | } |
1149 | | |
1150 | 0 | return NULL; |
1151 | 0 | } |
1152 | | |
1153 | | /* There are two options regarding what the "name" of a server is. The |
1154 | | * "canonical" name as defined by ServerName and Port, or the "client's |
1155 | | * name" as supplied by a possible Host: header or full URI. |
1156 | | * |
1157 | | * The DNS option to UseCanonicalName causes this routine to do a |
1158 | | * reverse lookup on the local IP address of the connection and use |
1159 | | * that for the ServerName. This makes its value more reliable while |
1160 | | * at the same time allowing Demon's magic virtual hosting to work. |
1161 | | * The assumption is that DNS lookups are sufficiently quick... |
1162 | | * -- fanf 1998-10-03 |
1163 | | */ |
1164 | | AP_DECLARE(const char *) ap_get_server_name(request_rec *r) |
1165 | 0 | { |
1166 | 0 | conn_rec *conn = r->connection; |
1167 | 0 | core_dir_config *d; |
1168 | 0 | const char *retval; |
1169 | |
|
1170 | 0 | d = (core_dir_config *)ap_get_core_module_config(r->per_dir_config); |
1171 | |
|
1172 | 0 | switch (d->use_canonical_name) { |
1173 | 0 | case USE_CANONICAL_NAME_ON: |
1174 | 0 | retval = r->server->server_hostname; |
1175 | 0 | break; |
1176 | 0 | case USE_CANONICAL_NAME_DNS: |
1177 | 0 | if (conn->local_host == NULL) { |
1178 | 0 | if (apr_getnameinfo(&conn->local_host, |
1179 | 0 | conn->local_addr, 0) != APR_SUCCESS) |
1180 | 0 | conn->local_host = apr_pstrdup(conn->pool, |
1181 | 0 | r->server->server_hostname); |
1182 | 0 | else { |
1183 | 0 | ap_str_tolower(conn->local_host); |
1184 | 0 | } |
1185 | 0 | } |
1186 | 0 | retval = conn->local_host; |
1187 | 0 | break; |
1188 | 0 | case USE_CANONICAL_NAME_OFF: |
1189 | 0 | case USE_CANONICAL_NAME_UNSET: |
1190 | 0 | retval = r->hostname ? r->hostname : r->server->server_hostname; |
1191 | 0 | break; |
1192 | 0 | default: |
1193 | 0 | ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00109) |
1194 | 0 | "ap_get_server_name: Invalid UCN Option somehow"); |
1195 | 0 | retval = "localhost"; |
1196 | 0 | break; |
1197 | 0 | } |
1198 | 0 | return retval; |
1199 | 0 | } |
1200 | | |
1201 | | /* |
1202 | | * Get the current server name from the request for the purposes |
1203 | | * of using in a URL. If the server name is an IPv6 literal |
1204 | | * address, it will be returned in URL format (e.g., "[fe80::1]"). |
1205 | | */ |
1206 | | AP_DECLARE(const char *) ap_get_server_name_for_url(request_rec *r) |
1207 | 0 | { |
1208 | 0 | const char *plain_server_name = ap_get_server_name(r); |
1209 | |
|
1210 | 0 | #if APR_HAVE_IPV6 |
1211 | 0 | if (ap_strchr_c(plain_server_name, ':')) { /* IPv6 literal? */ |
1212 | 0 | return apr_pstrcat(r->pool, "[", plain_server_name, "]", NULL); |
1213 | 0 | } |
1214 | 0 | #endif |
1215 | 0 | return plain_server_name; |
1216 | 0 | } |
1217 | | |
1218 | | AP_DECLARE(apr_port_t) ap_get_server_port(const request_rec *r) |
1219 | 0 | { |
1220 | 0 | apr_port_t port; |
1221 | 0 | core_dir_config *d = |
1222 | 0 | (core_dir_config *)ap_get_core_module_config(r->per_dir_config); |
1223 | |
|
1224 | 0 | switch (d->use_canonical_name) { |
1225 | 0 | case USE_CANONICAL_NAME_OFF: |
1226 | 0 | case USE_CANONICAL_NAME_DNS: |
1227 | 0 | case USE_CANONICAL_NAME_UNSET: |
1228 | 0 | if (d->use_canonical_phys_port == USE_CANONICAL_PHYS_PORT_ON) |
1229 | 0 | port = r->parsed_uri.port_str ? r->parsed_uri.port : |
1230 | 0 | r->connection->local_addr->port ? r->connection->local_addr->port : |
1231 | 0 | r->server->port ? r->server->port : |
1232 | 0 | ap_default_port(r); |
1233 | 0 | else /* USE_CANONICAL_PHYS_PORT_OFF or USE_CANONICAL_PHYS_PORT_UNSET */ |
1234 | 0 | port = r->parsed_uri.port_str ? r->parsed_uri.port : |
1235 | 0 | r->server->port ? r->server->port : |
1236 | 0 | ap_default_port(r); |
1237 | 0 | break; |
1238 | 0 | case USE_CANONICAL_NAME_ON: |
1239 | | /* With UseCanonicalName on (and in all versions prior to 1.3) |
1240 | | * Apache will use the hostname and port specified in the |
1241 | | * ServerName directive to construct a canonical name for the |
1242 | | * server. (If no port was specified in the ServerName |
1243 | | * directive, Apache uses the port supplied by the client if |
1244 | | * any is supplied, and finally the default port for the protocol |
1245 | | * used. |
1246 | | */ |
1247 | 0 | if (d->use_canonical_phys_port == USE_CANONICAL_PHYS_PORT_ON) |
1248 | 0 | port = r->server->port ? r->server->port : |
1249 | 0 | r->connection->local_addr->port ? r->connection->local_addr->port : |
1250 | 0 | ap_default_port(r); |
1251 | 0 | else /* USE_CANONICAL_PHYS_PORT_OFF or USE_CANONICAL_PHYS_PORT_UNSET */ |
1252 | 0 | port = r->server->port ? r->server->port : |
1253 | 0 | ap_default_port(r); |
1254 | 0 | break; |
1255 | 0 | default: |
1256 | 0 | ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00110) |
1257 | 0 | "ap_get_server_port: Invalid UCN Option somehow"); |
1258 | 0 | port = ap_default_port(r); |
1259 | 0 | break; |
1260 | 0 | } |
1261 | | |
1262 | 0 | return port; |
1263 | 0 | } |
1264 | | |
1265 | | AP_DECLARE(char *) ap_construct_url(apr_pool_t *p, const char *uri, |
1266 | | request_rec *r) |
1267 | 0 | { |
1268 | 0 | unsigned port = ap_get_server_port(r); |
1269 | 0 | const char *host = ap_get_server_name_for_url(r); |
1270 | |
|
1271 | 0 | if (ap_is_default_port(port, r)) { |
1272 | 0 | return apr_pstrcat(p, ap_http_scheme(r), "://", host, uri, NULL); |
1273 | 0 | } |
1274 | | |
1275 | 0 | return apr_psprintf(p, "%s://%s:%u%s", ap_http_scheme(r), host, port, uri); |
1276 | 0 | } |
1277 | | |
1278 | | AP_DECLARE(apr_off_t) ap_get_limit_req_body(const request_rec *r) |
1279 | 0 | { |
1280 | 0 | core_dir_config *d = |
1281 | 0 | (core_dir_config *)ap_get_core_module_config(r->per_dir_config); |
1282 | |
|
1283 | 0 | if (d->limit_req_body == AP_LIMIT_REQ_BODY_UNSET) { |
1284 | 0 | return AP_DEFAULT_LIMIT_REQ_BODY; |
1285 | 0 | } |
1286 | | |
1287 | 0 | return d->limit_req_body; |
1288 | 0 | } |
1289 | | |
1290 | | AP_DECLARE(apr_size_t) ap_get_read_buf_size(const request_rec *r) |
1291 | 0 | { |
1292 | 0 | core_dir_config *d = ap_get_core_module_config(r->per_dir_config); |
1293 | |
|
1294 | 0 | return d->read_buf_size ? d->read_buf_size : AP_IOBUFSIZE; |
1295 | 0 | } |
1296 | | |
1297 | | |
1298 | | /***************************************************************** |
1299 | | * |
1300 | | * Commands... this module handles almost all of the NCSA httpd.conf |
1301 | | * commands, but most of the old srm.conf is in the modules. |
1302 | | */ |
1303 | | |
1304 | | |
1305 | | /* returns a parent if it matches the given directive */ |
1306 | | static const ap_directive_t * find_parent(const ap_directive_t *dirp, |
1307 | | const char *what) |
1308 | 0 | { |
1309 | 0 | while (dirp->parent != NULL) { |
1310 | 0 | dirp = dirp->parent; |
1311 | | |
1312 | | /* ### it would be nice to have atom-ized directives */ |
1313 | 0 | if (ap_cstr_casecmp(dirp->directive, what) == 0) |
1314 | 0 | return dirp; |
1315 | 0 | } |
1316 | | |
1317 | 0 | return NULL; |
1318 | 0 | } |
1319 | | |
1320 | | AP_DECLARE(const char *) ap_check_cmd_context(cmd_parms *cmd, |
1321 | | unsigned forbidden) |
1322 | 0 | { |
1323 | 0 | const char *gt = (cmd->cmd->name[0] == '<' |
1324 | 0 | && cmd->cmd->name[strlen(cmd->cmd->name)-1] != '>') |
1325 | 0 | ? ">" : ""; |
1326 | 0 | const ap_directive_t *found; |
1327 | |
|
1328 | 0 | if ((forbidden & NOT_IN_VIRTUALHOST) && cmd->server->is_virtual) { |
1329 | 0 | return apr_pstrcat(cmd->pool, cmd->cmd->name, gt, |
1330 | 0 | " cannot occur within <VirtualHost> section", NULL); |
1331 | 0 | } |
1332 | | |
1333 | 0 | if ((forbidden & NOT_IN_DIR_CONTEXT) && cmd->limited != -1) { |
1334 | 0 | return apr_pstrcat(cmd->pool, cmd->cmd->name, gt, |
1335 | 0 | " cannot occur within <Limit> or <LimitExcept> " |
1336 | 0 | "section", NULL); |
1337 | 0 | } |
1338 | | |
1339 | 0 | if ((forbidden & NOT_IN_HTACCESS) && (cmd->pool == cmd->temp_pool)) { |
1340 | 0 | return apr_pstrcat(cmd->pool, cmd->cmd->name, gt, |
1341 | 0 | " cannot occur within htaccess files", NULL); |
1342 | 0 | } |
1343 | | |
1344 | 0 | if ((forbidden & NOT_IN_DIR_CONTEXT) == NOT_IN_DIR_CONTEXT) { |
1345 | 0 | if (cmd->path != NULL) { |
1346 | 0 | return apr_pstrcat(cmd->pool, cmd->cmd->name, gt, |
1347 | 0 | " cannot occur within directory context", NULL); |
1348 | 0 | } |
1349 | 0 | if (cmd->cmd->req_override & EXEC_ON_READ) { |
1350 | | /* EXEC_ON_READ must be NOT_IN_DIR_CONTEXT, if not, it will |
1351 | | * (deliberately) segfault below in the individual tests... |
1352 | | */ |
1353 | 0 | return NULL; |
1354 | 0 | } |
1355 | 0 | } |
1356 | | |
1357 | 0 | if (((forbidden & NOT_IN_DIRECTORY) |
1358 | 0 | && ((found = find_parent(cmd->directive, "<Directory")) |
1359 | 0 | || (found = find_parent(cmd->directive, "<DirectoryMatch")))) |
1360 | 0 | || ((forbidden & NOT_IN_LOCATION) |
1361 | 0 | && ((found = find_parent(cmd->directive, "<Location")) |
1362 | 0 | || (found = find_parent(cmd->directive, "<LocationMatch")))) |
1363 | 0 | || ((forbidden & NOT_IN_FILES) |
1364 | 0 | && ((found = find_parent(cmd->directive, "<Files")) |
1365 | 0 | || (found = find_parent(cmd->directive, "<FilesMatch")) |
1366 | 0 | || (found = find_parent(cmd->directive, "<If")) |
1367 | 0 | || (found = find_parent(cmd->directive, "<ElseIf")) |
1368 | 0 | || (found = find_parent(cmd->directive, "<Else")))) |
1369 | 0 | || ((forbidden & NOT_IN_PROXY) |
1370 | 0 | && ((found = find_parent(cmd->directive, "<Proxy")) |
1371 | 0 | || (found = find_parent(cmd->directive, "<ProxyMatch"))))) { |
1372 | 0 | return apr_pstrcat(cmd->pool, cmd->cmd->name, gt, |
1373 | 0 | " cannot occur within ", found->directive, |
1374 | 0 | "> section", NULL); |
1375 | 0 | } |
1376 | | |
1377 | 0 | return NULL; |
1378 | 0 | } |
1379 | | |
1380 | | static const char *set_access_name(cmd_parms *cmd, void *dummy, |
1381 | | const char *arg) |
1382 | 0 | { |
1383 | 0 | void *sconf = cmd->server->module_config; |
1384 | 0 | core_server_config *conf = ap_get_core_module_config(sconf); |
1385 | |
|
1386 | 0 | const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); |
1387 | 0 | if (err != NULL) { |
1388 | 0 | return err; |
1389 | 0 | } |
1390 | | |
1391 | 0 | conf->access_name = apr_pstrdup(cmd->pool, arg); |
1392 | 0 | return NULL; |
1393 | 0 | } |
1394 | | |
1395 | | AP_DECLARE(const char *) ap_resolve_env(apr_pool_t *p, const char * word) |
1396 | 0 | { |
1397 | 0 | # define SMALL_EXPANSION 5 |
1398 | 0 | struct sll { |
1399 | 0 | struct sll *next; |
1400 | 0 | const char *string; |
1401 | 0 | apr_size_t len; |
1402 | 0 | } *result, *current, sresult[SMALL_EXPANSION]; |
1403 | 0 | char *res_buf, *cp; |
1404 | 0 | const char *s, *e, *ep; |
1405 | 0 | unsigned spc; |
1406 | 0 | apr_size_t outlen; |
1407 | |
|
1408 | 0 | s = ap_strchr_c(word, '$'); |
1409 | 0 | if (!s) { |
1410 | 0 | return word; |
1411 | 0 | } |
1412 | | |
1413 | | /* well, actually something to do */ |
1414 | 0 | ep = word + strlen(word); |
1415 | 0 | spc = 0; |
1416 | 0 | result = current = &(sresult[spc++]); |
1417 | 0 | current->next = NULL; |
1418 | 0 | current->string = word; |
1419 | 0 | current->len = s - word; |
1420 | 0 | outlen = current->len; |
1421 | |
|
1422 | 0 | do { |
1423 | | /* prepare next entry */ |
1424 | 0 | if (current->len) { |
1425 | 0 | current->next = (spc < SMALL_EXPANSION) |
1426 | 0 | ? &(sresult[spc++]) |
1427 | 0 | : (struct sll *)apr_palloc(p, |
1428 | 0 | sizeof(*current->next)); |
1429 | 0 | current = current->next; |
1430 | 0 | current->next = NULL; |
1431 | 0 | current->len = 0; |
1432 | 0 | } |
1433 | |
|
1434 | 0 | if (*s == '$') { |
1435 | 0 | if (s[1] == '{' && (e = ap_strchr_c(s+2, '}'))) { |
1436 | 0 | char *name = apr_pstrmemdup(p, s+2, e-s-2); |
1437 | 0 | char *dflt = ap_strstr(name, "?="); |
1438 | 0 | if (dflt) { |
1439 | | /* Default value for when var is not defined */ |
1440 | 0 | *dflt = '\0'; |
1441 | 0 | dflt += 2; |
1442 | 0 | } |
1443 | 0 | word = NULL; |
1444 | 0 | if (server_config_defined_vars) |
1445 | 0 | word = apr_table_get(server_config_defined_vars, name); |
1446 | 0 | if (!word) |
1447 | 0 | word = apr_pstrdup(p, getenv(name)); |
1448 | 0 | if (word) { |
1449 | 0 | current->string = word; |
1450 | 0 | current->len = strlen(word); |
1451 | 0 | outlen += current->len; |
1452 | 0 | } |
1453 | 0 | else if (dflt) { |
1454 | 0 | current->string = dflt; |
1455 | 0 | current->len = strlen(dflt); |
1456 | 0 | outlen += current->len; |
1457 | 0 | } |
1458 | 0 | else { |
1459 | 0 | if (ap_strchr(name, ':') == 0) |
1460 | 0 | ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL, APLOGNO(00111) |
1461 | 0 | "Config variable ${%s} is not defined", |
1462 | 0 | name); |
1463 | 0 | current->string = s; |
1464 | 0 | current->len = e - s + 1; |
1465 | 0 | outlen += current->len; |
1466 | 0 | } |
1467 | 0 | s = e + 1; |
1468 | 0 | } |
1469 | 0 | else { |
1470 | 0 | current->string = s++; |
1471 | 0 | current->len = 1; |
1472 | 0 | ++outlen; |
1473 | 0 | } |
1474 | 0 | } |
1475 | 0 | else { |
1476 | 0 | word = s; |
1477 | 0 | s = ap_strchr_c(s, '$'); |
1478 | 0 | current->string = word; |
1479 | 0 | current->len = s ? s - word : ep - word; |
1480 | 0 | outlen += current->len; |
1481 | 0 | } |
1482 | 0 | } while (s && *s); |
1483 | | |
1484 | | /* assemble result */ |
1485 | 0 | res_buf = cp = apr_palloc(p, outlen + 1); |
1486 | 0 | do { |
1487 | 0 | if (result->len) { |
1488 | 0 | memcpy(cp, result->string, result->len); |
1489 | 0 | cp += result->len; |
1490 | 0 | } |
1491 | 0 | result = result->next; |
1492 | 0 | } while (result); |
1493 | 0 | res_buf[outlen] = '\0'; |
1494 | |
|
1495 | 0 | return res_buf; |
1496 | 0 | } |
1497 | | |
1498 | | /* pconf cleanup - clear global variables set from config here. */ |
1499 | | static apr_status_t reset_config(void *dummy) |
1500 | 0 | { |
1501 | 0 | ap_server_config_defines = saved_server_config_defines; |
1502 | 0 | saved_server_config_defines = NULL; |
1503 | 0 | server_config_defined_vars = NULL; |
1504 | 0 | core_state_dir = NULL; |
1505 | 0 | ap_runtime_dir = NULL; |
1506 | |
|
1507 | 0 | return APR_SUCCESS; |
1508 | 0 | } |
1509 | | |
1510 | | /* |
1511 | | * Make sure we can revert the effects of Define/UnDefine when restarting. |
1512 | | * This function must be called once per loading of the config, before |
1513 | | * ap_server_config_defines is changed. This may be during reading of the |
1514 | | * config, which is even before the pre_config hook is run (due to |
1515 | | * EXEC_ON_READ for Define/UnDefine). |
1516 | | */ |
1517 | | static void init_config_defines(apr_pool_t *pconf) |
1518 | 0 | { |
1519 | 0 | saved_server_config_defines = ap_server_config_defines; |
1520 | | /* Use apr_array_copy instead of apr_array_copy_hdr because it does not |
1521 | | * protect from the way unset_define removes entries. |
1522 | | */ |
1523 | 0 | ap_server_config_defines = apr_array_copy(pconf, ap_server_config_defines); |
1524 | 0 | } |
1525 | | |
1526 | | static const char *set_define(cmd_parms *cmd, void *dummy, |
1527 | | const char *name, const char *value) |
1528 | 0 | { |
1529 | 0 | if (cmd->parent && ap_cstr_casecmp(cmd->parent->directive, "<VirtualHost")) { |
1530 | 0 | return apr_pstrcat(cmd->pool, cmd->cmd->name, " is not valid in ", |
1531 | 0 | cmd->parent->directive, " context", NULL); |
1532 | 0 | } |
1533 | | |
1534 | 0 | if (ap_strchr_c(name, ':') != NULL) { |
1535 | 0 | return "Variable name must not contain ':'"; |
1536 | 0 | } |
1537 | | |
1538 | 0 | if (!saved_server_config_defines) { |
1539 | 0 | init_config_defines(cmd->pool); |
1540 | 0 | } |
1541 | 0 | if (!ap_exists_config_define(name)) { |
1542 | 0 | *(const char **)apr_array_push(ap_server_config_defines) = name; |
1543 | 0 | } |
1544 | 0 | if (value) { |
1545 | 0 | if (!server_config_defined_vars) { |
1546 | 0 | server_config_defined_vars = apr_table_make(cmd->pool, 5); |
1547 | 0 | } |
1548 | 0 | apr_table_setn(server_config_defined_vars, name, value); |
1549 | 0 | } |
1550 | |
|
1551 | 0 | return NULL; |
1552 | 0 | } |
1553 | | |
1554 | | static const char *unset_define(cmd_parms *cmd, void *dummy, |
1555 | | const char *name) |
1556 | 0 | { |
1557 | 0 | int i; |
1558 | 0 | const char **defines; |
1559 | 0 | if (cmd->parent && ap_cstr_casecmp(cmd->parent->directive, "<VirtualHost")) { |
1560 | 0 | return apr_pstrcat(cmd->pool, cmd->cmd->name, " is not valid in ", |
1561 | 0 | cmd->parent->directive, " context", NULL); |
1562 | 0 | } |
1563 | | |
1564 | 0 | if (ap_strchr_c(name, ':') != NULL) { |
1565 | 0 | return "Variable name must not contain ':'"; |
1566 | 0 | } |
1567 | | |
1568 | 0 | if (!saved_server_config_defines) { |
1569 | 0 | init_config_defines(cmd->pool); |
1570 | 0 | } |
1571 | |
|
1572 | 0 | defines = (const char **)ap_server_config_defines->elts; |
1573 | 0 | for (i = 0; i < ap_server_config_defines->nelts; i++) { |
1574 | 0 | if (strcmp(defines[i], name) == 0) { |
1575 | 0 | defines[i] = *(const char **)apr_array_pop(ap_server_config_defines); |
1576 | 0 | break; |
1577 | 0 | } |
1578 | 0 | } |
1579 | |
|
1580 | 0 | if (server_config_defined_vars) { |
1581 | 0 | apr_table_unset(server_config_defined_vars, name); |
1582 | 0 | } |
1583 | |
|
1584 | 0 | return NULL; |
1585 | 0 | } |
1586 | | |
1587 | | static const char *generate_message(cmd_parms *cmd, void *dummy, |
1588 | | const char *arg) |
1589 | 0 | { |
1590 | | /* cast with 64-bit warning avoidance */ |
1591 | 0 | int level = (cmd->info==(void*)APLOG_ERR)? APLOG_ERR: APLOG_WARNING; |
1592 | 0 | char * msg; |
1593 | | |
1594 | | /* get position information from wherever we can? */ |
1595 | 0 | ap_configfile_t * cf = cmd->config_file; |
1596 | 0 | ap_directive_t const * ed1 = cmd->directive; |
1597 | 0 | ap_directive_t const * ed2 = cmd->err_directive; |
1598 | | |
1599 | | /* expect an argument */ |
1600 | 0 | if (!arg || !*arg) { |
1601 | 0 | return "The Error or Warning directive was used with no message."; |
1602 | 0 | } |
1603 | | |
1604 | | /* set message, strip off quotes if necessary */ |
1605 | 0 | msg = (char *)arg; |
1606 | 0 | if (*arg == '"' || *arg == '\'') { |
1607 | 0 | apr_size_t len = strlen(arg); |
1608 | 0 | char last = *(arg + len - 1); |
1609 | |
|
1610 | 0 | if (*arg == last) { |
1611 | 0 | msg = apr_pstrndup(cmd->pool, arg + 1, len - 2); |
1612 | 0 | } |
1613 | 0 | } |
1614 | | |
1615 | | /* generate error or warning with a configuration file position. |
1616 | | * the log is displayed on the terminal as no log file is opened yet. |
1617 | | */ |
1618 | 0 | ap_log_error(APLOG_MARK, level, 0, NULL, |
1619 | 0 | "%s on line %d of %s", msg, |
1620 | 0 | cf? cf->line_number: |
1621 | 0 | ed1? ed1->line_num: |
1622 | 0 | ed2? ed2->line_num: -1, |
1623 | 0 | cf? cf->name: |
1624 | 0 | ed1? ed1->filename: |
1625 | 0 | ed2? ed2->filename: "<UNKNOWN>"); |
1626 | | |
1627 | | /* message displayed above, return will stop configuration processing */ |
1628 | 0 | return level==APLOG_ERR? |
1629 | 0 | "Configuration processing stopped by Error directive": NULL; |
1630 | 0 | } |
1631 | | |
1632 | | #ifdef GPROF |
1633 | | static const char *set_gprof_dir(cmd_parms *cmd, void *dummy, const char *arg) |
1634 | | { |
1635 | | void *sconf = cmd->server->module_config; |
1636 | | core_server_config *conf = ap_get_core_module_config(sconf); |
1637 | | |
1638 | | const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); |
1639 | | if (err != NULL) { |
1640 | | return err; |
1641 | | } |
1642 | | |
1643 | | conf->gprof_dir = apr_pstrdup(cmd->pool, arg); |
1644 | | return NULL; |
1645 | | } |
1646 | | #endif /*GPROF*/ |
1647 | | |
1648 | | static const char *set_add_default_charset(cmd_parms *cmd, |
1649 | | void *d_, const char *arg) |
1650 | 0 | { |
1651 | 0 | core_dir_config *d = d_; |
1652 | |
|
1653 | 0 | if (!ap_cstr_casecmp(arg, "Off")) { |
1654 | 0 | d->add_default_charset = ADD_DEFAULT_CHARSET_OFF; |
1655 | 0 | } |
1656 | 0 | else if (!ap_cstr_casecmp(arg, "On")) { |
1657 | 0 | d->add_default_charset = ADD_DEFAULT_CHARSET_ON; |
1658 | 0 | d->add_default_charset_name = DEFAULT_ADD_DEFAULT_CHARSET_NAME; |
1659 | 0 | } |
1660 | 0 | else { |
1661 | 0 | d->add_default_charset = ADD_DEFAULT_CHARSET_ON; |
1662 | 0 | d->add_default_charset_name = arg; |
1663 | 0 | } |
1664 | |
|
1665 | 0 | return NULL; |
1666 | 0 | } |
1667 | | |
1668 | | static const char *set_document_root(cmd_parms *cmd, void *dummy, |
1669 | | const char *arg) |
1670 | 0 | { |
1671 | 0 | void *sconf = cmd->server->module_config; |
1672 | 0 | core_server_config *conf = ap_get_core_module_config(sconf); |
1673 | |
|
1674 | 0 | const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); |
1675 | 0 | if (err != NULL) { |
1676 | 0 | return err; |
1677 | 0 | } |
1678 | | |
1679 | | /* When ap_document_root_check is false; skip all the stuff below */ |
1680 | 0 | if (!ap_document_root_check) { |
1681 | 0 | conf->ap_document_root = arg; |
1682 | 0 | return NULL; |
1683 | 0 | } |
1684 | | |
1685 | | /* Make it absolute, relative to ServerRoot */ |
1686 | 0 | arg = ap_server_root_relative(cmd->pool, arg); |
1687 | 0 | if (arg == NULL) { |
1688 | 0 | return "DocumentRoot must be a directory"; |
1689 | 0 | } |
1690 | | |
1691 | 0 | if (apr_filepath_merge((char**)&conf->ap_document_root, NULL, arg, |
1692 | 0 | APR_FILEPATH_TRUENAME, cmd->pool) != APR_SUCCESS |
1693 | 0 | || !ap_is_directory(cmd->temp_pool, arg)) { |
1694 | 0 | if (cmd->server->is_virtual) { |
1695 | 0 | ap_log_perror(APLOG_MARK, APLOG_STARTUP, 0, |
1696 | 0 | cmd->pool, APLOGNO(00112) |
1697 | 0 | "Warning: DocumentRoot [%s] does not exist", |
1698 | 0 | arg); |
1699 | 0 | conf->ap_document_root = arg; |
1700 | 0 | } |
1701 | 0 | else { |
1702 | 0 | return apr_psprintf(cmd->pool, |
1703 | 0 | "DocumentRoot '%s' is not a directory, or is not readable", |
1704 | 0 | arg); |
1705 | 0 | } |
1706 | 0 | } |
1707 | 0 | return NULL; |
1708 | 0 | } |
1709 | | |
1710 | | AP_DECLARE(void) ap_custom_response(request_rec *r, int status, |
1711 | | const char *string) |
1712 | 0 | { |
1713 | 0 | core_request_config *conf = ap_get_core_module_config(r->request_config); |
1714 | 0 | int idx; |
1715 | |
|
1716 | 0 | if (conf->response_code_strings == NULL) { |
1717 | 0 | conf->response_code_strings = |
1718 | 0 | apr_pcalloc(r->pool, |
1719 | 0 | sizeof(*conf->response_code_strings) * RESPONSE_CODES); |
1720 | 0 | } |
1721 | |
|
1722 | 0 | idx = ap_index_of_response(status); |
1723 | |
|
1724 | 0 | conf->response_code_strings[idx] = |
1725 | 0 | ((ap_is_url(string) || (*string == '/')) && (*string != '"')) ? |
1726 | 0 | apr_pstrdup(r->pool, string) : apr_pstrcat(r->pool, "\"", string, NULL); |
1727 | 0 | } |
1728 | | |
1729 | | static const char *set_error_document(cmd_parms *cmd, void *conf_, |
1730 | | const char *errno_str, const char *msg) |
1731 | 0 | { |
1732 | 0 | core_dir_config *conf = conf_; |
1733 | 0 | int error_number, index_number, idx500; |
1734 | 0 | enum { MSG, LOCAL_PATH, REMOTE_PATH } what = MSG; |
1735 | | |
1736 | | /* 1st parameter should be a 3 digit number, which we recognize; |
1737 | | * convert it into an array index |
1738 | | */ |
1739 | 0 | error_number = atoi(errno_str); |
1740 | 0 | idx500 = ap_index_of_response(HTTP_INTERNAL_SERVER_ERROR); |
1741 | |
|
1742 | 0 | if (error_number == HTTP_INTERNAL_SERVER_ERROR) { |
1743 | 0 | index_number = idx500; |
1744 | 0 | } |
1745 | 0 | else if ((index_number = ap_index_of_response(error_number)) == idx500) { |
1746 | 0 | return apr_pstrcat(cmd->pool, "Unsupported HTTP response code ", |
1747 | 0 | errno_str, NULL); |
1748 | 0 | } |
1749 | | |
1750 | | /* Heuristic to determine second argument. */ |
1751 | 0 | if (ap_strchr_c(msg,' ')) |
1752 | 0 | what = MSG; |
1753 | 0 | else if (msg[0] == '/') |
1754 | 0 | what = LOCAL_PATH; |
1755 | 0 | else if (ap_is_url(msg)) |
1756 | 0 | what = REMOTE_PATH; |
1757 | 0 | else |
1758 | 0 | what = MSG; |
1759 | | |
1760 | | /* The entry should be ignored if it is a full URL for a 401 error */ |
1761 | |
|
1762 | 0 | if (error_number == 401 && what == REMOTE_PATH) { |
1763 | 0 | ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, cmd->server, APLOGNO(00113) |
1764 | 0 | "%s:%d cannot use a full URL in a 401 ErrorDocument " |
1765 | 0 | "directive --- ignoring!", cmd->directive->filename, cmd->directive->line_num); |
1766 | 0 | } |
1767 | 0 | else { /* Store it... */ |
1768 | 0 | if (conf->response_code_exprs == NULL) { |
1769 | 0 | conf->response_code_exprs = apr_hash_make(cmd->pool); |
1770 | 0 | } |
1771 | |
|
1772 | 0 | if (ap_cstr_casecmp(msg, "default") == 0) { |
1773 | | /* special case: ErrorDocument 404 default restores the |
1774 | | * canned server error response |
1775 | | */ |
1776 | 0 | apr_hash_set(conf->response_code_exprs, |
1777 | 0 | apr_pmemdup(cmd->pool, &index_number, sizeof(index_number)), |
1778 | 0 | sizeof(index_number), &errordocument_default); |
1779 | 0 | } |
1780 | 0 | else { |
1781 | 0 | ap_expr_info_t *expr; |
1782 | 0 | const char *expr_err = NULL; |
1783 | | |
1784 | | /* hack. Prefix a " if it is a msg; as that is what |
1785 | | * http_protocol.c relies on to distinguish between |
1786 | | * a msg and a (local) path. |
1787 | | */ |
1788 | 0 | const char *response = |
1789 | 0 | (what == MSG) ? apr_pstrcat(cmd->pool, "\"", msg, NULL) : |
1790 | 0 | apr_pstrdup(cmd->pool, msg); |
1791 | |
|
1792 | 0 | expr = ap_expr_parse_cmd(cmd, response, AP_EXPR_FLAG_STRING_RESULT, |
1793 | 0 | &expr_err, NULL); |
1794 | |
|
1795 | 0 | if (expr_err) { |
1796 | 0 | return apr_pstrcat(cmd->temp_pool, |
1797 | 0 | "Cannot parse expression in ErrorDocument: ", |
1798 | 0 | expr_err, NULL); |
1799 | 0 | } |
1800 | | |
1801 | 0 | apr_hash_set(conf->response_code_exprs, |
1802 | 0 | apr_pmemdup(cmd->pool, &index_number, sizeof(index_number)), |
1803 | 0 | sizeof(index_number), expr); |
1804 | |
|
1805 | 0 | } |
1806 | 0 | } |
1807 | | |
1808 | 0 | return NULL; |
1809 | 0 | } |
1810 | | |
1811 | | static const char *set_allow_opts(cmd_parms *cmd, allow_options_t *opts, |
1812 | | const char *l) |
1813 | 0 | { |
1814 | 0 | allow_options_t opt; |
1815 | 0 | int first = 1; |
1816 | |
|
1817 | 0 | char *w, *p = (char *) l; |
1818 | 0 | char *tok_state; |
1819 | |
|
1820 | 0 | while ((w = apr_strtok(p, ",", &tok_state)) != NULL) { |
1821 | |
|
1822 | 0 | if (first) { |
1823 | 0 | p = NULL; |
1824 | 0 | *opts = OPT_NONE; |
1825 | 0 | first = 0; |
1826 | 0 | } |
1827 | |
|
1828 | 0 | if (!ap_cstr_casecmp(w, "Indexes")) { |
1829 | 0 | opt = OPT_INDEXES; |
1830 | 0 | } |
1831 | 0 | else if (!ap_cstr_casecmp(w, "Includes")) { |
1832 | | /* If Includes is permitted, both Includes and |
1833 | | * IncludesNOEXEC may be changed. */ |
1834 | 0 | opt = (OPT_INCLUDES | OPT_INC_WITH_EXEC); |
1835 | 0 | } |
1836 | 0 | else if (!ap_cstr_casecmp(w, "IncludesNOEXEC")) { |
1837 | 0 | opt = OPT_INCLUDES; |
1838 | 0 | } |
1839 | 0 | else if (!ap_cstr_casecmp(w, "FollowSymLinks")) { |
1840 | 0 | opt = OPT_SYM_LINKS; |
1841 | 0 | } |
1842 | 0 | else if (!ap_cstr_casecmp(w, "SymLinksIfOwnerMatch")) { |
1843 | 0 | opt = OPT_SYM_OWNER; |
1844 | 0 | } |
1845 | 0 | else if (!ap_cstr_casecmp(w, "ExecCGI")) { |
1846 | 0 | opt = OPT_EXECCGI; |
1847 | 0 | } |
1848 | 0 | else if (!ap_cstr_casecmp(w, "MultiViews")) { |
1849 | 0 | opt = OPT_MULTI; |
1850 | 0 | } |
1851 | 0 | else if (!ap_cstr_casecmp(w, "RunScripts")) { /* AI backcompat. Yuck */ |
1852 | 0 | opt = OPT_MULTI|OPT_EXECCGI; |
1853 | 0 | } |
1854 | 0 | else if (!ap_cstr_casecmp(w, "None")) { |
1855 | 0 | opt = OPT_NONE; |
1856 | 0 | } |
1857 | 0 | else if (!ap_cstr_casecmp(w, "All")) { |
1858 | 0 | opt = OPT_ALL; |
1859 | 0 | } |
1860 | 0 | else { |
1861 | 0 | return apr_pstrcat(cmd->pool, "Illegal option ", w, NULL); |
1862 | 0 | } |
1863 | | |
1864 | 0 | *opts |= opt; |
1865 | 0 | } |
1866 | | |
1867 | 0 | (*opts) &= (~OPT_UNSET); |
1868 | |
|
1869 | 0 | return NULL; |
1870 | 0 | } |
1871 | | |
1872 | | static const char *set_override(cmd_parms *cmd, void *d_, const char *l) |
1873 | 0 | { |
1874 | 0 | core_dir_config *d = d_; |
1875 | 0 | char *w; |
1876 | 0 | char *k, *v; |
1877 | 0 | const char *err; |
1878 | | |
1879 | | /* Throw a warning if we're in <Location> or <Files> */ |
1880 | 0 | if (ap_check_cmd_context(cmd, NOT_IN_LOCATION | NOT_IN_FILES)) { |
1881 | 0 | ap_log_error(APLOG_MARK, APLOG_WARNING, 0, cmd->server, APLOGNO(00114) |
1882 | 0 | "Useless use of AllowOverride in line %d of %s.", |
1883 | 0 | cmd->directive->line_num, cmd->directive->filename); |
1884 | 0 | } |
1885 | 0 | if ((err = ap_check_cmd_context(cmd, NOT_IN_HTACCESS)) != NULL) |
1886 | 0 | return err; |
1887 | | |
1888 | 0 | d->override = OR_NONE; |
1889 | 0 | while (l[0]) { |
1890 | 0 | w = ap_getword_conf(cmd->temp_pool, &l); |
1891 | |
|
1892 | 0 | k = w; |
1893 | 0 | v = strchr(k, '='); |
1894 | 0 | if (v) { |
1895 | 0 | *v++ = '\0'; |
1896 | 0 | } |
1897 | |
|
1898 | 0 | if (!ap_cstr_casecmp(w, "Limit")) { |
1899 | 0 | d->override |= OR_LIMIT; |
1900 | 0 | } |
1901 | 0 | else if (!ap_cstr_casecmp(k, "Options")) { |
1902 | 0 | d->override |= OR_OPTIONS; |
1903 | 0 | if (v) |
1904 | 0 | set_allow_opts(cmd, &(d->override_opts), v); |
1905 | 0 | else |
1906 | 0 | d->override_opts = OPT_ALL; |
1907 | 0 | } |
1908 | 0 | else if (!ap_cstr_casecmp(w, "FileInfo")) { |
1909 | 0 | d->override |= OR_FILEINFO; |
1910 | 0 | } |
1911 | 0 | else if (!ap_cstr_casecmp(w, "AuthConfig")) { |
1912 | 0 | d->override |= OR_AUTHCFG; |
1913 | 0 | } |
1914 | 0 | else if (!ap_cstr_casecmp(w, "Indexes")) { |
1915 | 0 | d->override |= OR_INDEXES; |
1916 | 0 | } |
1917 | 0 | else if (!ap_cstr_casecmp(w, "Nonfatal")) { |
1918 | 0 | if (!v) { |
1919 | 0 | return apr_pstrcat(cmd->pool, "=Override, =Unknown or =All expected after ", w, NULL); |
1920 | 0 | } |
1921 | 0 | else if (!ap_cstr_casecmp(v, "Override")) { |
1922 | 0 | d->override |= NONFATAL_OVERRIDE; |
1923 | 0 | } |
1924 | 0 | else if (!ap_cstr_casecmp(v, "Unknown")) { |
1925 | 0 | d->override |= NONFATAL_UNKNOWN; |
1926 | 0 | } |
1927 | 0 | else if (!ap_cstr_casecmp(v, "All")) { |
1928 | 0 | d->override |= NONFATAL_ALL; |
1929 | 0 | } |
1930 | 0 | } |
1931 | 0 | else if (!ap_cstr_casecmp(w, "None")) { |
1932 | 0 | d->override = OR_NONE; |
1933 | 0 | } |
1934 | 0 | else if (!ap_cstr_casecmp(w, "All")) { |
1935 | 0 | d->override = OR_ALL; |
1936 | 0 | } |
1937 | 0 | else { |
1938 | 0 | return apr_pstrcat(cmd->pool, "Illegal override option ", w, NULL); |
1939 | 0 | } |
1940 | | |
1941 | 0 | d->override &= ~OR_UNSET; |
1942 | 0 | } |
1943 | | |
1944 | 0 | return NULL; |
1945 | 0 | } |
1946 | | |
1947 | | static const char *set_cgi_pass_auth(cmd_parms *cmd, void *d_, int flag) |
1948 | 0 | { |
1949 | 0 | core_dir_config *d = d_; |
1950 | |
|
1951 | 0 | d->cgi_pass_auth = flag ? AP_CGI_PASS_AUTH_ON : AP_CGI_PASS_AUTH_OFF; |
1952 | |
|
1953 | 0 | return NULL; |
1954 | 0 | } |
1955 | | |
1956 | | static const char *set_cgi_var(cmd_parms *cmd, void *d_, |
1957 | | const char *var, const char *rule_) |
1958 | 0 | { |
1959 | 0 | core_dir_config *d = d_; |
1960 | 0 | char *rule = apr_pstrdup(cmd->pool, rule_); |
1961 | |
|
1962 | 0 | ap_str_tolower(rule); |
1963 | |
|
1964 | 0 | if (!strcmp(var, "REQUEST_URI")) { |
1965 | 0 | if (strcmp(rule, "current-uri") && strcmp(rule, "original-uri")) { |
1966 | 0 | return "Valid rules for REQUEST_URI are 'current-uri' and 'original-uri'"; |
1967 | 0 | } |
1968 | 0 | } |
1969 | 0 | else { |
1970 | 0 | return apr_pstrcat(cmd->pool, "Unrecognized CGI variable: \"", |
1971 | 0 | var, "\"", NULL); |
1972 | 0 | } |
1973 | | |
1974 | 0 | if (!d->cgi_var_rules) { |
1975 | 0 | d->cgi_var_rules = apr_hash_make(cmd->pool); |
1976 | 0 | } |
1977 | 0 | apr_hash_set(d->cgi_var_rules, var, APR_HASH_KEY_STRING, rule); |
1978 | 0 | return NULL; |
1979 | 0 | } |
1980 | | |
1981 | | static const char *set_qualify_redirect_url(cmd_parms *cmd, void *d_, int flag) |
1982 | 0 | { |
1983 | 0 | core_dir_config *d = d_; |
1984 | |
|
1985 | 0 | d->qualify_redirect_url = flag ? AP_CORE_CONFIG_ON : AP_CORE_CONFIG_OFF; |
1986 | |
|
1987 | 0 | return NULL; |
1988 | 0 | } |
1989 | | static const char *set_core_server_flag(cmd_parms *cmd, void *s_, int flag) |
1990 | 0 | { |
1991 | 0 | core_server_config *conf = |
1992 | 0 | ap_get_core_module_config(cmd->server->module_config); |
1993 | 0 | return ap_set_flag_slot(cmd, conf, flag); |
1994 | 0 | } |
1995 | | static const char *set_override_list(cmd_parms *cmd, void *d_, int argc, char *const argv[]) |
1996 | 0 | { |
1997 | 0 | core_dir_config *d = d_; |
1998 | 0 | int i; |
1999 | 0 | const char *err; |
2000 | | |
2001 | | /* Throw a warning if we're in <Location> or <Files> */ |
2002 | 0 | if (ap_check_cmd_context(cmd, NOT_IN_LOCATION | NOT_IN_FILES)) { |
2003 | 0 | ap_log_error(APLOG_MARK, APLOG_WARNING, 0, cmd->server, APLOGNO(00115) |
2004 | 0 | "Useless use of AllowOverrideList at %s:%d", |
2005 | 0 | cmd->directive->filename, cmd->directive->line_num); |
2006 | 0 | } |
2007 | 0 | if ((err = ap_check_cmd_context(cmd, NOT_IN_HTACCESS)) != NULL) |
2008 | 0 | return err; |
2009 | | |
2010 | 0 | d->override_list = apr_table_make(cmd->pool, argc); |
2011 | |
|
2012 | 0 | for (i = 0; i < argc; i++) { |
2013 | 0 | if (!ap_cstr_casecmp(argv[i], "None")) { |
2014 | 0 | if (argc != 1) { |
2015 | 0 | return "'None' not allowed with other directives in " |
2016 | 0 | "AllowOverrideList"; |
2017 | 0 | } |
2018 | 0 | return NULL; |
2019 | 0 | } |
2020 | 0 | else { |
2021 | 0 | const command_rec *result = NULL; |
2022 | 0 | module *mod = ap_top_module; |
2023 | |
|
2024 | 0 | result = ap_find_command_in_modules(argv[i], &mod); |
2025 | 0 | if (result == NULL) { |
2026 | 0 | ap_log_error(APLOG_MARK, APLOG_WARNING, 0, cmd->server, |
2027 | 0 | APLOGNO(00116) "Discarding unrecognized " |
2028 | 0 | "directive `%s' in AllowOverrideList at %s:%d", |
2029 | 0 | argv[i], cmd->directive->filename, |
2030 | 0 | cmd->directive->line_num); |
2031 | 0 | continue; |
2032 | 0 | } |
2033 | 0 | else if ((result->req_override & (OR_ALL|ACCESS_CONF)) == 0) { |
2034 | 0 | ap_log_error(APLOG_MARK, APLOG_WARNING, 0, cmd->server, |
2035 | 0 | APLOGNO(02304) "Discarding directive `%s' not " |
2036 | 0 | "allowed in AllowOverrideList at %s:%d", |
2037 | 0 | argv[i], cmd->directive->filename, |
2038 | 0 | cmd->directive->line_num); |
2039 | 0 | continue; |
2040 | 0 | } |
2041 | 0 | else { |
2042 | 0 | apr_table_setn(d->override_list, argv[i], "1"); |
2043 | 0 | } |
2044 | 0 | } |
2045 | 0 | } |
2046 | | |
2047 | 0 | return NULL; |
2048 | 0 | } |
2049 | | |
2050 | | static const char *set_options(cmd_parms *cmd, void *d_, const char *l) |
2051 | 0 | { |
2052 | 0 | core_dir_config *d = d_; |
2053 | 0 | allow_options_t opt; |
2054 | 0 | int first = 1; |
2055 | 0 | int merge = 0; |
2056 | 0 | int all_none = 0; |
2057 | 0 | char action; |
2058 | |
|
2059 | 0 | while (l[0]) { |
2060 | 0 | char *w = ap_getword_conf(cmd->temp_pool, &l); |
2061 | 0 | action = '\0'; |
2062 | |
|
2063 | 0 | if (*w == '+' || *w == '-') { |
2064 | 0 | action = *(w++); |
2065 | 0 | if (!merge && !first && !all_none) { |
2066 | 0 | return "Either all Options must start with + or -, or no Option may."; |
2067 | 0 | } |
2068 | 0 | merge = 1; |
2069 | 0 | } |
2070 | 0 | else if (first) { |
2071 | 0 | d->opts = OPT_NONE; |
2072 | 0 | } |
2073 | 0 | else if (merge) { |
2074 | 0 | return "Either all Options must start with + or -, or no Option may."; |
2075 | 0 | } |
2076 | | |
2077 | 0 | if (!ap_cstr_casecmp(w, "Indexes")) { |
2078 | 0 | opt = OPT_INDEXES; |
2079 | 0 | } |
2080 | 0 | else if (!ap_cstr_casecmp(w, "Includes")) { |
2081 | 0 | opt = (OPT_INCLUDES | OPT_INC_WITH_EXEC); |
2082 | 0 | } |
2083 | 0 | else if (!ap_cstr_casecmp(w, "IncludesNOEXEC")) { |
2084 | 0 | opt = OPT_INCLUDES; |
2085 | 0 | } |
2086 | 0 | else if (!ap_cstr_casecmp(w, "FollowSymLinks")) { |
2087 | 0 | opt = OPT_SYM_LINKS; |
2088 | 0 | } |
2089 | 0 | else if (!ap_cstr_casecmp(w, "SymLinksIfOwnerMatch")) { |
2090 | 0 | opt = OPT_SYM_OWNER; |
2091 | 0 | } |
2092 | 0 | else if (!ap_cstr_casecmp(w, "ExecCGI")) { |
2093 | 0 | opt = OPT_EXECCGI; |
2094 | 0 | } |
2095 | 0 | else if (!ap_cstr_casecmp(w, "MultiViews")) { |
2096 | 0 | opt = OPT_MULTI; |
2097 | 0 | } |
2098 | 0 | else if (!ap_cstr_casecmp(w, "RunScripts")) { /* AI backcompat. Yuck */ |
2099 | 0 | opt = OPT_MULTI|OPT_EXECCGI; |
2100 | 0 | } |
2101 | 0 | else if (!ap_cstr_casecmp(w, "None")) { |
2102 | 0 | if (!first) { |
2103 | 0 | return "'Options None' must be the first Option given."; |
2104 | 0 | } |
2105 | 0 | else if (merge) { /* Only works since None may not follow any other option. */ |
2106 | 0 | return "You may not use 'Options +None' or 'Options -None'."; |
2107 | 0 | } |
2108 | 0 | opt = OPT_NONE; |
2109 | 0 | all_none = 1; |
2110 | 0 | } |
2111 | 0 | else if (!ap_cstr_casecmp(w, "All")) { |
2112 | 0 | if (!first) { |
2113 | 0 | return "'Options All' must be the first option given."; |
2114 | 0 | } |
2115 | 0 | else if (merge) { /* Only works since All may not follow any other option. */ |
2116 | 0 | return "You may not use 'Options +All' or 'Options -All'."; |
2117 | 0 | } |
2118 | 0 | opt = OPT_ALL; |
2119 | 0 | all_none = 1; |
2120 | 0 | } |
2121 | 0 | else { |
2122 | 0 | return apr_pstrcat(cmd->pool, "Illegal option ", w, NULL); |
2123 | 0 | } |
2124 | | |
2125 | 0 | if ( (cmd->override_opts & opt) != opt ) { |
2126 | 0 | return apr_pstrcat(cmd->pool, "Option ", w, " not allowed here", NULL); |
2127 | 0 | } |
2128 | 0 | else if (action == '-') { |
2129 | | /* we ensure the invariant (d->opts_add & d->opts_remove) == 0 */ |
2130 | 0 | d->opts_remove |= opt; |
2131 | 0 | d->opts_add &= ~opt; |
2132 | 0 | d->opts &= ~opt; |
2133 | 0 | } |
2134 | 0 | else if (action == '+') { |
2135 | 0 | d->opts_add |= opt; |
2136 | 0 | d->opts_remove &= ~opt; |
2137 | 0 | d->opts |= opt; |
2138 | 0 | } |
2139 | 0 | else { |
2140 | 0 | d->opts |= opt; |
2141 | 0 | } |
2142 | | |
2143 | 0 | first = 0; |
2144 | 0 | } |
2145 | | |
2146 | 0 | return NULL; |
2147 | 0 | } |
2148 | | |
2149 | | static const char *set_default_type(cmd_parms *cmd, void *d_, |
2150 | | const char *arg) |
2151 | 0 | { |
2152 | 0 | if (ap_cstr_casecmp(arg, "off") != 0 && ap_cstr_casecmp(arg, "none") != 0) { |
2153 | 0 | ap_log_error(APLOG_MARK, APLOG_WARNING, 0, cmd->server, APLOGNO(00117) |
2154 | 0 | "Ignoring deprecated use of DefaultType in line %d of %s.", |
2155 | 0 | cmd->directive->line_num, cmd->directive->filename); |
2156 | 0 | } |
2157 | |
|
2158 | 0 | return NULL; |
2159 | 0 | } |
2160 | | |
2161 | | static const char *set_sethandler(cmd_parms *cmd, |
2162 | | void *d_, |
2163 | | const char *arg_) |
2164 | 0 | { |
2165 | 0 | core_dir_config *dirconf = d_; |
2166 | 0 | const char *err; |
2167 | 0 | dirconf->expr_handler = ap_expr_parse_cmd(cmd, arg_, |
2168 | 0 | AP_EXPR_FLAG_STRING_RESULT, |
2169 | 0 | &err, NULL); |
2170 | 0 | if (err) { |
2171 | 0 | return apr_pstrcat(cmd->pool, |
2172 | 0 | "Can't parse expression : ", err, NULL); |
2173 | 0 | } |
2174 | 0 | return NULL; |
2175 | 0 | } |
2176 | | |
2177 | | /* |
2178 | | * Note what data should be used when forming file ETag values. |
2179 | | * It would be nicer to do this as an ITERATE, but then we couldn't |
2180 | | * remember the +/- state properly. |
2181 | | */ |
2182 | | static const char *set_etag_bits(cmd_parms *cmd, void *mconfig, |
2183 | | const char *args_p) |
2184 | 0 | { |
2185 | 0 | core_dir_config *cfg; |
2186 | 0 | etag_components_t bit; |
2187 | 0 | char action; |
2188 | 0 | char *token; |
2189 | 0 | const char *args; |
2190 | 0 | int valid; |
2191 | 0 | int first; |
2192 | 0 | int explicit; |
2193 | |
|
2194 | 0 | cfg = (core_dir_config *)mconfig; |
2195 | |
|
2196 | 0 | args = args_p; |
2197 | 0 | first = 1; |
2198 | 0 | explicit = 0; |
2199 | 0 | while (args[0] != '\0') { |
2200 | 0 | action = '*'; |
2201 | 0 | bit = ETAG_UNSET; |
2202 | 0 | valid = 1; |
2203 | 0 | token = ap_getword_conf(cmd->temp_pool, &args); |
2204 | 0 | if ((*token == '+') || (*token == '-')) { |
2205 | 0 | action = *token; |
2206 | 0 | token++; |
2207 | 0 | } |
2208 | 0 | else { |
2209 | | /* |
2210 | | * The occurrence of an absolute setting wipes |
2211 | | * out any previous relative ones. The first such |
2212 | | * occurrence forgets any inherited ones, too. |
2213 | | */ |
2214 | 0 | if (first) { |
2215 | 0 | cfg->etag_bits = ETAG_UNSET; |
2216 | 0 | cfg->etag_add = ETAG_UNSET; |
2217 | 0 | cfg->etag_remove = ETAG_UNSET; |
2218 | 0 | first = 0; |
2219 | 0 | } |
2220 | 0 | } |
2221 | |
|
2222 | 0 | if (ap_cstr_casecmp(token, "None") == 0) { |
2223 | 0 | if (action != '*') { |
2224 | 0 | valid = 0; |
2225 | 0 | } |
2226 | 0 | else { |
2227 | 0 | cfg->etag_bits = bit = ETAG_NONE; |
2228 | 0 | explicit = 1; |
2229 | 0 | } |
2230 | 0 | } |
2231 | 0 | else if (ap_cstr_casecmp(token, "All") == 0) { |
2232 | 0 | if (action != '*') { |
2233 | 0 | valid = 0; |
2234 | 0 | } |
2235 | 0 | else { |
2236 | 0 | explicit = 1; |
2237 | 0 | cfg->etag_bits = bit = ETAG_ALL; |
2238 | 0 | } |
2239 | 0 | } |
2240 | 0 | else if (ap_cstr_casecmp(token, "Size") == 0) { |
2241 | 0 | bit = ETAG_SIZE; |
2242 | 0 | } |
2243 | 0 | else if ((ap_cstr_casecmp(token, "LMTime") == 0) |
2244 | 0 | || (ap_cstr_casecmp(token, "MTime") == 0) |
2245 | 0 | || (ap_cstr_casecmp(token, "LastModified") == 0)) { |
2246 | 0 | bit = ETAG_MTIME; |
2247 | 0 | } |
2248 | 0 | else if (ap_cstr_casecmp(token, "INode") == 0) { |
2249 | 0 | bit = ETAG_INODE; |
2250 | 0 | } |
2251 | 0 | else if (ap_cstr_casecmp(token, "Digest") == 0) { |
2252 | 0 | bit = ETAG_DIGEST; |
2253 | 0 | } |
2254 | 0 | else { |
2255 | 0 | return apr_pstrcat(cmd->pool, "Unknown keyword '", |
2256 | 0 | token, "' for ", cmd->cmd->name, |
2257 | 0 | " directive", NULL); |
2258 | 0 | } |
2259 | | |
2260 | 0 | if (! valid) { |
2261 | 0 | return apr_pstrcat(cmd->pool, cmd->cmd->name, " keyword '", |
2262 | 0 | token, "' cannot be used with '+' or '-'", |
2263 | 0 | NULL); |
2264 | 0 | } |
2265 | | |
2266 | 0 | if (action == '+') { |
2267 | | /* |
2268 | | * Make sure it's in the 'add' list and absent from the |
2269 | | * 'subtract' list. |
2270 | | */ |
2271 | 0 | cfg->etag_add |= bit; |
2272 | 0 | cfg->etag_remove &= (~ bit); |
2273 | 0 | } |
2274 | 0 | else if (action == '-') { |
2275 | 0 | cfg->etag_remove |= bit; |
2276 | 0 | cfg->etag_add &= (~ bit); |
2277 | 0 | } |
2278 | 0 | else { |
2279 | | /* |
2280 | | * Non-relative values wipe out any + or - values |
2281 | | * accumulated so far. |
2282 | | */ |
2283 | 0 | cfg->etag_bits |= bit; |
2284 | 0 | cfg->etag_add = ETAG_UNSET; |
2285 | 0 | cfg->etag_remove = ETAG_UNSET; |
2286 | 0 | explicit = 1; |
2287 | 0 | } |
2288 | 0 | } |
2289 | | |
2290 | | /* |
2291 | | * Any setting at all will clear the 'None' and 'Unset' bits. |
2292 | | */ |
2293 | | |
2294 | 0 | if (cfg->etag_add != ETAG_UNSET) { |
2295 | 0 | cfg->etag_add &= (~ ETAG_UNSET); |
2296 | 0 | } |
2297 | |
|
2298 | 0 | if (cfg->etag_remove != ETAG_UNSET) { |
2299 | 0 | cfg->etag_remove &= (~ ETAG_UNSET); |
2300 | 0 | } |
2301 | |
|
2302 | 0 | if (explicit) { |
2303 | 0 | cfg->etag_bits &= (~ ETAG_UNSET); |
2304 | |
|
2305 | 0 | if ((cfg->etag_bits & ETAG_NONE) != ETAG_NONE) { |
2306 | 0 | cfg->etag_bits &= (~ ETAG_NONE); |
2307 | 0 | } |
2308 | 0 | } |
2309 | |
|
2310 | 0 | return NULL; |
2311 | 0 | } |
2312 | | |
2313 | | static const char *set_enable_mmap(cmd_parms *cmd, void *d_, |
2314 | | const char *arg) |
2315 | 0 | { |
2316 | 0 | core_dir_config *d = d_; |
2317 | |
|
2318 | 0 | if (ap_cstr_casecmp(arg, "on") == 0) { |
2319 | 0 | d->enable_mmap = ENABLE_MMAP_ON; |
2320 | 0 | } |
2321 | 0 | else if (ap_cstr_casecmp(arg, "off") == 0) { |
2322 | 0 | d->enable_mmap = ENABLE_MMAP_OFF; |
2323 | 0 | } |
2324 | 0 | else { |
2325 | 0 | return "parameter must be 'on' or 'off'"; |
2326 | 0 | } |
2327 | | |
2328 | 0 | return NULL; |
2329 | 0 | } |
2330 | | |
2331 | | static const char *set_enable_sendfile(cmd_parms *cmd, void *d_, |
2332 | | const char *arg) |
2333 | 0 | { |
2334 | 0 | core_dir_config *d = d_; |
2335 | |
|
2336 | 0 | if (ap_cstr_casecmp(arg, "on") == 0) { |
2337 | 0 | d->enable_sendfile = ENABLE_SENDFILE_ON; |
2338 | 0 | } |
2339 | 0 | else if (ap_cstr_casecmp(arg, "off") == 0) { |
2340 | 0 | d->enable_sendfile = ENABLE_SENDFILE_OFF; |
2341 | 0 | } |
2342 | 0 | else { |
2343 | 0 | return "parameter must be 'on' or 'off'"; |
2344 | 0 | } |
2345 | | |
2346 | 0 | return NULL; |
2347 | 0 | } |
2348 | | |
2349 | | static const char *set_read_buf_size(cmd_parms *cmd, void *d_, |
2350 | | const char *arg) |
2351 | 0 | { |
2352 | 0 | core_dir_config *d = d_; |
2353 | 0 | apr_off_t size; |
2354 | 0 | char *end; |
2355 | |
|
2356 | 0 | if (apr_strtoff(&size, arg, &end, 10) |
2357 | 0 | || *end || size < 0 || size > APR_UINT32_MAX) |
2358 | 0 | return apr_pstrcat(cmd->pool, |
2359 | 0 | "parameter must be a number between 0 and " |
2360 | 0 | APR_STRINGIFY(APR_UINT32_MAX) "): ", |
2361 | 0 | arg, NULL); |
2362 | | |
2363 | 0 | d->read_buf_size = (apr_size_t)size; |
2364 | |
|
2365 | 0 | return NULL; |
2366 | 0 | } |
2367 | | |
2368 | | static const char *set_flush_max_threshold(cmd_parms *cmd, void *d_, |
2369 | | const char *arg) |
2370 | 0 | { |
2371 | 0 | core_server_config *conf = |
2372 | 0 | ap_get_core_module_config(cmd->server->module_config); |
2373 | 0 | apr_off_t size; |
2374 | 0 | char *end; |
2375 | |
|
2376 | 0 | if (apr_strtoff(&size, arg, &end, 10) |
2377 | 0 | || *end || size < 0 || size > APR_UINT32_MAX) |
2378 | 0 | return apr_pstrcat(cmd->pool, |
2379 | 0 | "parameter must be a number between 0 and " |
2380 | 0 | APR_STRINGIFY(APR_UINT32_MAX) "): ", |
2381 | 0 | arg, NULL); |
2382 | | |
2383 | 0 | conf->flush_max_threshold = (apr_size_t)size; |
2384 | |
|
2385 | 0 | return NULL; |
2386 | 0 | } |
2387 | | |
2388 | | static const char *set_flush_max_pipelined(cmd_parms *cmd, void *d_, |
2389 | | const char *arg) |
2390 | 0 | { |
2391 | 0 | core_server_config *conf = |
2392 | 0 | ap_get_core_module_config(cmd->server->module_config); |
2393 | 0 | apr_off_t num; |
2394 | 0 | char *end; |
2395 | |
|
2396 | 0 | if (apr_strtoff(&num, arg, &end, 10) |
2397 | 0 | || *end || num < -1 || num > APR_INT32_MAX) |
2398 | 0 | return apr_pstrcat(cmd->pool, |
2399 | 0 | "parameter must be a number between -1 and " |
2400 | 0 | APR_STRINGIFY(APR_INT32_MAX) ": ", |
2401 | 0 | arg, NULL); |
2402 | | |
2403 | 0 | conf->flush_max_pipelined = (apr_int32_t)num; |
2404 | |
|
2405 | 0 | return NULL; |
2406 | 0 | } |
2407 | | |
2408 | | /* |
2409 | | * Report a missing-'>' syntax error. |
2410 | | */ |
2411 | | static char *unclosed_directive(cmd_parms *cmd) |
2412 | 0 | { |
2413 | 0 | return apr_pstrcat(cmd->pool, cmd->cmd->name, |
2414 | 0 | "> directive missing closing '>'", NULL); |
2415 | 0 | } |
2416 | | |
2417 | | /* |
2418 | | * Report a missing args in '<Foo >' syntax error. |
2419 | | */ |
2420 | | static char *missing_container_arg(cmd_parms *cmd) |
2421 | 0 | { |
2422 | 0 | return apr_pstrcat(cmd->pool, cmd->cmd->name, |
2423 | 0 | "> directive requires additional arguments", NULL); |
2424 | 0 | } |
2425 | | |
2426 | | AP_CORE_DECLARE_NONSTD(const char *) ap_limit_section(cmd_parms *cmd, |
2427 | | void *dummy, |
2428 | | const char *arg) |
2429 | 0 | { |
2430 | 0 | const char *endp = ap_strrchr_c(arg, '>'); |
2431 | 0 | const char *limited_methods; |
2432 | 0 | void *tog = cmd->cmd->cmd_data; |
2433 | 0 | apr_int64_t limited = 0; |
2434 | 0 | apr_int64_t old_limited = cmd->limited; |
2435 | 0 | const char *errmsg; |
2436 | |
|
2437 | 0 | if (endp == NULL) { |
2438 | 0 | return unclosed_directive(cmd); |
2439 | 0 | } |
2440 | | |
2441 | 0 | limited_methods = apr_pstrmemdup(cmd->temp_pool, arg, endp - arg); |
2442 | |
|
2443 | 0 | if (!limited_methods[0]) { |
2444 | 0 | return missing_container_arg(cmd); |
2445 | 0 | } |
2446 | | |
2447 | 0 | while (limited_methods[0]) { |
2448 | 0 | char *method = ap_getword_conf(cmd->temp_pool, &limited_methods); |
2449 | 0 | int methnum; |
2450 | | |
2451 | | /* check for builtin or module registered method number */ |
2452 | 0 | methnum = ap_method_number_of(method); |
2453 | |
|
2454 | 0 | if (methnum == M_TRACE && !tog) { |
2455 | 0 | return "TRACE cannot be controlled by <Limit>, see TraceEnable"; |
2456 | 0 | } |
2457 | 0 | else if (methnum == M_INVALID) { |
2458 | | /* method has not been registered yet, but resource restriction |
2459 | | * is always checked before method handling, so register it. |
2460 | | */ |
2461 | 0 | if (cmd->pool == cmd->temp_pool) { |
2462 | | /* In .htaccess, we can't globally register new methods. */ |
2463 | 0 | return apr_psprintf(cmd->pool, "Could not register method '%s' " |
2464 | 0 | "for %s from .htaccess configuration", |
2465 | 0 | method, cmd->cmd->name); |
2466 | 0 | } |
2467 | 0 | methnum = ap_method_register(cmd->pool, |
2468 | 0 | apr_pstrdup(cmd->pool, method)); |
2469 | 0 | } |
2470 | | |
2471 | 0 | limited |= (AP_METHOD_BIT << methnum); |
2472 | 0 | } |
2473 | | |
2474 | | /* Killing two features with one function, |
2475 | | * if (tog == NULL) <Limit>, else <LimitExcept> |
2476 | | */ |
2477 | 0 | limited = tog ? ~limited : limited; |
2478 | |
|
2479 | 0 | if (!(old_limited & limited)) { |
2480 | 0 | return apr_pstrcat(cmd->pool, cmd->cmd->name, |
2481 | 0 | "> directive excludes all methods", NULL); |
2482 | 0 | } |
2483 | 0 | else if ((old_limited & limited) == old_limited) { |
2484 | 0 | return apr_pstrcat(cmd->pool, cmd->cmd->name, |
2485 | 0 | "> directive specifies methods already excluded", |
2486 | 0 | NULL); |
2487 | 0 | } |
2488 | | |
2489 | 0 | cmd->limited &= limited; |
2490 | |
|
2491 | 0 | errmsg = ap_walk_config(cmd->directive->first_child, cmd, cmd->context); |
2492 | |
|
2493 | 0 | cmd->limited = old_limited; |
2494 | |
|
2495 | 0 | return errmsg; |
2496 | 0 | } |
2497 | | |
2498 | | /* XXX: Bogus - need to do this differently (at least OS2/Netware suffer |
2499 | | * the same problem!!! |
2500 | | * We use this in <DirectoryMatch> and <FilesMatch>, to ensure that |
2501 | | * people don't get bitten by wrong-cased regex matches |
2502 | | */ |
2503 | | |
2504 | | #ifdef WIN32 |
2505 | | #define USE_ICASE AP_REG_ICASE |
2506 | | #else |
2507 | 0 | #define USE_ICASE 0 |
2508 | | #endif |
2509 | | |
2510 | | static const char *dirsection(cmd_parms *cmd, void *mconfig, const char *arg) |
2511 | 0 | { |
2512 | 0 | const char *errmsg; |
2513 | 0 | const char *endp = ap_strrchr_c(arg, '>'); |
2514 | 0 | int old_overrides = cmd->override; |
2515 | 0 | char *old_path = cmd->path; |
2516 | 0 | core_dir_config *conf; |
2517 | 0 | ap_conf_vector_t *new_dir_conf = ap_create_per_dir_config(cmd->pool); |
2518 | 0 | ap_regex_t *r = NULL; |
2519 | 0 | const command_rec *thiscmd = cmd->cmd; |
2520 | |
|
2521 | 0 | const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); |
2522 | 0 | if (err != NULL) { |
2523 | 0 | return err; |
2524 | 0 | } |
2525 | | |
2526 | 0 | if (endp == NULL) { |
2527 | 0 | return unclosed_directive(cmd); |
2528 | 0 | } |
2529 | | |
2530 | 0 | arg = apr_pstrndup(cmd->temp_pool, arg, endp - arg); |
2531 | |
|
2532 | 0 | if (!arg[0]) { |
2533 | 0 | return missing_container_arg(cmd); |
2534 | 0 | } |
2535 | | |
2536 | 0 | cmd->path = ap_getword_conf(cmd->pool, &arg); |
2537 | 0 | cmd->override = OR_ALL|ACCESS_CONF; |
2538 | |
|
2539 | 0 | if (!strcmp(cmd->path, "~")) { |
2540 | 0 | cmd->path = ap_getword_conf(cmd->pool, &arg); |
2541 | 0 | if (!cmd->path) |
2542 | 0 | return "<Directory ~ > block must specify a path"; |
2543 | 0 | r = ap_pregcomp(cmd->pool, cmd->path, AP_REG_EXTENDED|USE_ICASE); |
2544 | 0 | if (!r) { |
2545 | 0 | return "Regex could not be compiled"; |
2546 | 0 | } |
2547 | 0 | } |
2548 | 0 | else if (thiscmd->cmd_data) { /* <DirectoryMatch> */ |
2549 | 0 | r = ap_pregcomp(cmd->pool, cmd->path, AP_REG_EXTENDED|USE_ICASE); |
2550 | 0 | if (!r) { |
2551 | 0 | return "Regex could not be compiled"; |
2552 | 0 | } |
2553 | 0 | } |
2554 | 0 | else if (strcmp(cmd->path, "/") != 0) |
2555 | 0 | { |
2556 | 0 | int run_mode = ap_state_query(AP_SQ_RUN_MODE); |
2557 | 0 | char *newpath; |
2558 | | |
2559 | | /* |
2560 | | * Ensure that the pathname is canonical, and append the trailing / |
2561 | | */ |
2562 | 0 | apr_status_t rv = apr_filepath_merge(&newpath, NULL, cmd->path, |
2563 | 0 | APR_FILEPATH_TRUENAME, cmd->pool); |
2564 | 0 | if (rv != APR_SUCCESS && rv != APR_EPATHWILD) { |
2565 | 0 | return apr_pstrcat(cmd->pool, "<Directory \"", cmd->path, |
2566 | 0 | "\"> path is invalid.", NULL); |
2567 | 0 | } |
2568 | | |
2569 | 0 | if (run_mode == AP_SQ_RM_CONFIG_TEST && |
2570 | 0 | !ap_is_directory(cmd->temp_pool, cmd->path)) { |
2571 | 0 | ap_log_perror(APLOG_MARK, APLOG_STARTUP, 0, |
2572 | 0 | cmd->temp_pool, APLOGNO(10234) |
2573 | 0 | "Warning: <Directory \"%s\"> does not exist or is not a directory", |
2574 | 0 | cmd->path); |
2575 | 0 | } |
2576 | |
|
2577 | 0 | cmd->path = newpath; |
2578 | 0 | if (cmd->path[strlen(cmd->path) - 1] != '/') |
2579 | 0 | cmd->path = apr_pstrcat(cmd->pool, cmd->path, "/", NULL); |
2580 | 0 | } |
2581 | | |
2582 | | /* initialize our config and fetch it */ |
2583 | 0 | conf = ap_set_config_vectors(cmd->server, new_dir_conf, cmd->path, |
2584 | 0 | &core_module, cmd->pool); |
2585 | |
|
2586 | 0 | errmsg = ap_walk_config(cmd->directive->first_child, cmd, new_dir_conf); |
2587 | 0 | if (errmsg != NULL) |
2588 | 0 | return errmsg; |
2589 | | |
2590 | 0 | conf->r = r; |
2591 | 0 | conf->d = cmd->path; |
2592 | 0 | conf->d_is_fnmatch = (apr_fnmatch_test(conf->d) != 0); |
2593 | |
|
2594 | 0 | if (r) { |
2595 | 0 | conf->refs = apr_array_make(cmd->pool, 8, sizeof(char *)); |
2596 | 0 | ap_regname(r, conf->refs, AP_REG_MATCH, 1); |
2597 | 0 | } |
2598 | | |
2599 | | /* Make this explicit - the "/" root has 0 elements, that is, we |
2600 | | * will always merge it, and it will always sort and merge first. |
2601 | | * All others are sorted and tested by the number of slashes. |
2602 | | */ |
2603 | 0 | if (strcmp(conf->d, "/") == 0) |
2604 | 0 | conf->d_components = 0; |
2605 | 0 | else |
2606 | 0 | conf->d_components = ap_count_dirs(conf->d); |
2607 | |
|
2608 | 0 | ap_add_per_dir_conf(cmd->server, new_dir_conf); |
2609 | |
|
2610 | 0 | if (*arg != '\0') { |
2611 | 0 | return apr_pstrcat(cmd->pool, "Multiple ", thiscmd->name, |
2612 | 0 | "> arguments not (yet) supported.", NULL); |
2613 | 0 | } |
2614 | | |
2615 | 0 | cmd->path = old_path; |
2616 | 0 | cmd->override = old_overrides; |
2617 | |
|
2618 | 0 | return NULL; |
2619 | 0 | } |
2620 | | |
2621 | | static const char *urlsection(cmd_parms *cmd, void *mconfig, const char *arg) |
2622 | 0 | { |
2623 | 0 | const char *errmsg; |
2624 | 0 | const char *endp = ap_strrchr_c(arg, '>'); |
2625 | 0 | int old_overrides = cmd->override; |
2626 | 0 | char *old_path = cmd->path; |
2627 | 0 | core_dir_config *conf; |
2628 | 0 | ap_regex_t *r = NULL; |
2629 | 0 | const command_rec *thiscmd = cmd->cmd; |
2630 | 0 | ap_conf_vector_t *new_url_conf = ap_create_per_dir_config(cmd->pool); |
2631 | 0 | const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); |
2632 | 0 | if (err != NULL) { |
2633 | 0 | return err; |
2634 | 0 | } |
2635 | | |
2636 | 0 | if (endp == NULL) { |
2637 | 0 | return unclosed_directive(cmd); |
2638 | 0 | } |
2639 | | |
2640 | 0 | arg = apr_pstrndup(cmd->temp_pool, arg, endp - arg); |
2641 | |
|
2642 | 0 | if (!arg[0]) { |
2643 | 0 | return missing_container_arg(cmd); |
2644 | 0 | } |
2645 | | |
2646 | 0 | cmd->path = ap_getword_conf(cmd->pool, &arg); |
2647 | 0 | cmd->override = OR_ALL|ACCESS_CONF; |
2648 | |
|
2649 | 0 | if (thiscmd->cmd_data) { /* <LocationMatch> */ |
2650 | 0 | r = ap_pregcomp(cmd->pool, cmd->path, AP_REG_EXTENDED); |
2651 | 0 | if (!r) { |
2652 | 0 | return "Regex could not be compiled"; |
2653 | 0 | } |
2654 | 0 | } |
2655 | 0 | else if (!strcmp(cmd->path, "~")) { |
2656 | 0 | cmd->path = ap_getword_conf(cmd->pool, &arg); |
2657 | 0 | r = ap_pregcomp(cmd->pool, cmd->path, AP_REG_EXTENDED); |
2658 | 0 | if (!r) { |
2659 | 0 | return "Regex could not be compiled"; |
2660 | 0 | } |
2661 | 0 | } |
2662 | | |
2663 | | /* initialize our config and fetch it */ |
2664 | 0 | conf = ap_set_config_vectors(cmd->server, new_url_conf, cmd->path, |
2665 | 0 | &core_module, cmd->pool); |
2666 | |
|
2667 | 0 | errmsg = ap_walk_config(cmd->directive->first_child, cmd, new_url_conf); |
2668 | 0 | if (errmsg != NULL) |
2669 | 0 | return errmsg; |
2670 | | |
2671 | 0 | conf->d = apr_pstrdup(cmd->pool, cmd->path); /* No mangling, please */ |
2672 | 0 | conf->d_is_fnmatch = apr_fnmatch_test(conf->d) != 0; |
2673 | 0 | conf->r = r; |
2674 | |
|
2675 | 0 | if (r) { |
2676 | 0 | conf->refs = apr_array_make(cmd->pool, 8, sizeof(char *)); |
2677 | 0 | ap_regname(r, conf->refs, AP_REG_MATCH, 1); |
2678 | 0 | } |
2679 | |
|
2680 | 0 | ap_add_per_url_conf(cmd->server, new_url_conf); |
2681 | |
|
2682 | 0 | if (*arg != '\0') { |
2683 | 0 | return apr_pstrcat(cmd->pool, "Multiple ", thiscmd->name, |
2684 | 0 | "> arguments not (yet) supported.", NULL); |
2685 | 0 | } |
2686 | | |
2687 | 0 | cmd->path = old_path; |
2688 | 0 | cmd->override = old_overrides; |
2689 | |
|
2690 | 0 | return NULL; |
2691 | 0 | } |
2692 | | |
2693 | | static const char *filesection(cmd_parms *cmd, void *mconfig, const char *arg) |
2694 | 0 | { |
2695 | 0 | const char *errmsg; |
2696 | 0 | const char *endp = ap_strrchr_c(arg, '>'); |
2697 | 0 | int old_overrides = cmd->override; |
2698 | 0 | char *old_path = cmd->path; |
2699 | 0 | core_dir_config *conf; |
2700 | 0 | ap_regex_t *r = NULL; |
2701 | 0 | const command_rec *thiscmd = cmd->cmd; |
2702 | 0 | ap_conf_vector_t *new_file_conf = ap_create_per_dir_config(cmd->pool); |
2703 | 0 | const char *err = ap_check_cmd_context(cmd, |
2704 | 0 | NOT_IN_LOCATION | NOT_IN_LIMIT); |
2705 | |
|
2706 | 0 | if (err != NULL) { |
2707 | 0 | return err; |
2708 | 0 | } |
2709 | | |
2710 | 0 | if (endp == NULL) { |
2711 | 0 | return unclosed_directive(cmd); |
2712 | 0 | } |
2713 | | |
2714 | 0 | arg = apr_pstrndup(cmd->temp_pool, arg, endp - arg); |
2715 | |
|
2716 | 0 | if (!arg[0]) { |
2717 | 0 | return missing_container_arg(cmd); |
2718 | 0 | } |
2719 | | |
2720 | 0 | cmd->path = ap_getword_conf(cmd->pool, &arg); |
2721 | | /* Only if not an .htaccess file */ |
2722 | 0 | if (!old_path) { |
2723 | 0 | cmd->override = OR_ALL|ACCESS_CONF; |
2724 | 0 | } |
2725 | |
|
2726 | 0 | if (thiscmd->cmd_data) { /* <FilesMatch> */ |
2727 | 0 | r = ap_pregcomp(cmd->pool, cmd->path, AP_REG_EXTENDED|USE_ICASE); |
2728 | 0 | if (!r) { |
2729 | 0 | return "Regex could not be compiled"; |
2730 | 0 | } |
2731 | 0 | } |
2732 | 0 | else if (!strcmp(cmd->path, "~")) { |
2733 | 0 | cmd->path = ap_getword_conf(cmd->pool, &arg); |
2734 | 0 | r = ap_pregcomp(cmd->pool, cmd->path, AP_REG_EXTENDED|USE_ICASE); |
2735 | 0 | if (!r) { |
2736 | 0 | return "Regex could not be compiled"; |
2737 | 0 | } |
2738 | 0 | } |
2739 | 0 | else { |
2740 | 0 | char *newpath; |
2741 | | /* Ensure that the pathname is canonical, but we |
2742 | | * can't test the case/aliases without a fixed path */ |
2743 | 0 | if (apr_filepath_merge(&newpath, "", cmd->path, |
2744 | 0 | 0, cmd->pool) != APR_SUCCESS) |
2745 | 0 | return apr_pstrcat(cmd->pool, "<Files \"", cmd->path, |
2746 | 0 | "\"> is invalid.", NULL); |
2747 | 0 | cmd->path = newpath; |
2748 | 0 | } |
2749 | | |
2750 | | /* initialize our config and fetch it */ |
2751 | 0 | conf = ap_set_config_vectors(cmd->server, new_file_conf, cmd->path, |
2752 | 0 | &core_module, cmd->pool); |
2753 | |
|
2754 | 0 | errmsg = ap_walk_config(cmd->directive->first_child, cmd, new_file_conf); |
2755 | 0 | if (errmsg != NULL) |
2756 | 0 | return errmsg; |
2757 | | |
2758 | 0 | conf->d = cmd->path; |
2759 | 0 | conf->d_is_fnmatch = apr_fnmatch_test(conf->d) != 0; |
2760 | 0 | conf->r = r; |
2761 | |
|
2762 | 0 | if (r) { |
2763 | 0 | conf->refs = apr_array_make(cmd->pool, 8, sizeof(char *)); |
2764 | 0 | ap_regname(r, conf->refs, AP_REG_MATCH, 1); |
2765 | 0 | } |
2766 | |
|
2767 | 0 | ap_add_file_conf(cmd->pool, (core_dir_config *)mconfig, new_file_conf); |
2768 | |
|
2769 | 0 | if (*arg != '\0') { |
2770 | 0 | return apr_pstrcat(cmd->pool, "Multiple ", thiscmd->name, |
2771 | 0 | "> arguments not (yet) supported.", NULL); |
2772 | 0 | } |
2773 | | |
2774 | 0 | cmd->path = old_path; |
2775 | 0 | cmd->override = old_overrides; |
2776 | |
|
2777 | 0 | return NULL; |
2778 | 0 | } |
2779 | | |
2780 | 0 | #define COND_IF ((void *)1) |
2781 | 0 | #define COND_ELSE ((void *)2) |
2782 | 0 | #define COND_ELSEIF ((void *)3) |
2783 | | |
2784 | | static const char *ifsection(cmd_parms *cmd, void *mconfig, const char *arg) |
2785 | 0 | { |
2786 | 0 | const char *errmsg; |
2787 | 0 | const char *endp = ap_strrchr_c(arg, '>'); |
2788 | 0 | int old_overrides = cmd->override; |
2789 | 0 | char *old_path = cmd->path; |
2790 | 0 | core_dir_config *conf; |
2791 | 0 | const command_rec *thiscmd = cmd->cmd; |
2792 | 0 | ap_conf_vector_t *new_if_conf = ap_create_per_dir_config(cmd->pool); |
2793 | 0 | const char *err = ap_check_cmd_context(cmd, NOT_IN_LIMIT); |
2794 | 0 | const char *condition; |
2795 | 0 | const char *expr_err; |
2796 | |
|
2797 | 0 | if (err != NULL) { |
2798 | 0 | return err; |
2799 | 0 | } |
2800 | | |
2801 | 0 | if (endp == NULL) { |
2802 | 0 | return unclosed_directive(cmd); |
2803 | 0 | } |
2804 | | |
2805 | 0 | arg = apr_pstrndup(cmd->temp_pool, arg, endp - arg); |
2806 | | |
2807 | | /* |
2808 | | * Set a dummy value so that other directives notice that they are inside |
2809 | | * a config section. |
2810 | | */ |
2811 | 0 | cmd->path = "*If"; |
2812 | | /* Only if not an .htaccess file */ |
2813 | 0 | if (!old_path) { |
2814 | 0 | cmd->override = OR_ALL|ACCESS_CONF; |
2815 | 0 | } |
2816 | | |
2817 | | /* initialize our config and fetch it */ |
2818 | 0 | conf = ap_set_config_vectors(cmd->server, new_if_conf, cmd->path, |
2819 | 0 | &core_module, cmd->pool); |
2820 | |
|
2821 | 0 | if (cmd->cmd->cmd_data == COND_IF) |
2822 | 0 | conf->condition_ifelse = AP_CONDITION_IF; |
2823 | 0 | else if (cmd->cmd->cmd_data == COND_ELSEIF) |
2824 | 0 | conf->condition_ifelse = AP_CONDITION_ELSEIF; |
2825 | 0 | else if (cmd->cmd->cmd_data == COND_ELSE) |
2826 | 0 | conf->condition_ifelse = AP_CONDITION_ELSE; |
2827 | 0 | else |
2828 | 0 | ap_assert(0); |
2829 | | |
2830 | 0 | if (conf->condition_ifelse == AP_CONDITION_ELSE) { |
2831 | 0 | if (arg[0]) |
2832 | 0 | return "<Else> does not take an argument"; |
2833 | 0 | } |
2834 | 0 | else { |
2835 | 0 | if (!arg[0]) |
2836 | 0 | return missing_container_arg(cmd); |
2837 | 0 | condition = ap_getword_conf(cmd->pool, &arg); |
2838 | 0 | conf->condition = ap_expr_parse_cmd(cmd, condition, 0, &expr_err, NULL); |
2839 | 0 | if (expr_err) |
2840 | 0 | return apr_psprintf(cmd->pool, "Cannot parse condition clause: %s", |
2841 | 0 | expr_err); |
2842 | 0 | } |
2843 | | |
2844 | 0 | errmsg = ap_walk_config(cmd->directive->first_child, cmd, new_if_conf); |
2845 | 0 | if (errmsg != NULL) |
2846 | 0 | return errmsg; |
2847 | | |
2848 | 0 | conf->d = cmd->path; |
2849 | 0 | conf->d_is_fnmatch = 0; |
2850 | 0 | conf->r = NULL; |
2851 | |
|
2852 | 0 | errmsg = ap_add_if_conf(cmd->pool, (core_dir_config *)mconfig, new_if_conf); |
2853 | 0 | if (errmsg != NULL) |
2854 | 0 | return errmsg; |
2855 | | |
2856 | 0 | if (*arg != '\0') { |
2857 | 0 | return apr_pstrcat(cmd->pool, "Multiple ", thiscmd->name, |
2858 | 0 | "> arguments not supported.", NULL); |
2859 | 0 | } |
2860 | | |
2861 | 0 | cmd->path = old_path; |
2862 | 0 | cmd->override = old_overrides; |
2863 | |
|
2864 | 0 | return NULL; |
2865 | 0 | } |
2866 | | |
2867 | | static module *find_module(server_rec *s, const char *name) |
2868 | 0 | { |
2869 | 0 | module *found = ap_find_linked_module(name); |
2870 | | |
2871 | | /* search prelinked stuff */ |
2872 | 0 | if (!found) { |
2873 | 0 | ap_module_symbol_t *current = ap_prelinked_module_symbols; |
2874 | |
|
2875 | 0 | for (; current->name; ++current) { |
2876 | 0 | if (!strcmp(current->name, name)) { |
2877 | 0 | found = current->modp; |
2878 | 0 | break; |
2879 | 0 | } |
2880 | 0 | } |
2881 | 0 | } |
2882 | | |
2883 | | /* search dynamic stuff */ |
2884 | 0 | if (!found) { |
2885 | 0 | APR_OPTIONAL_FN_TYPE(ap_find_loaded_module_symbol) *check_symbol = |
2886 | 0 | APR_RETRIEVE_OPTIONAL_FN(ap_find_loaded_module_symbol); |
2887 | |
|
2888 | 0 | if (check_symbol) { |
2889 | | /* |
2890 | | * There are two phases where calling ap_find_loaded_module_symbol |
2891 | | * is problematic: |
2892 | | * |
2893 | | * During reading of the config, ap_server_conf is invalid but s |
2894 | | * points to the main server config, if passed from cmd->server |
2895 | | * of an EXEC_ON_READ directive. |
2896 | | * |
2897 | | * During config parsing, s may be a virtual host that would cause |
2898 | | * a segfault in mod_so if passed to ap_find_loaded_module_symbol, |
2899 | | * because mod_so's server config for vhosts is initialized later. |
2900 | | * But ap_server_conf is already set at this time. |
2901 | | * |
2902 | | * Therefore we use s if it is not virtual and ap_server_conf if |
2903 | | * s is virtual. |
2904 | | */ |
2905 | 0 | found = check_symbol(s->is_virtual ? ap_server_conf : s, name); |
2906 | 0 | } |
2907 | 0 | } |
2908 | |
|
2909 | 0 | return found; |
2910 | 0 | } |
2911 | | |
2912 | | /* Callback function type used by start_cond_section. */ |
2913 | | typedef int (*test_cond_section_fn)(cmd_parms *cmd, const char *arg); |
2914 | | |
2915 | | /* Implementation of <IfXXXXX>-style conditional sections. Callback |
2916 | | * to test condition must be in cmd->info, matching function type |
2917 | | * test_cond_section_fn. */ |
2918 | | static const char *start_cond_section(cmd_parms *cmd, void *mconfig, const char *arg) |
2919 | 0 | { |
2920 | 0 | const char *endp = ap_strrchr_c(arg, '>'); |
2921 | 0 | int result, not = (arg[0] == '!'); |
2922 | 0 | test_cond_section_fn testfn = (test_cond_section_fn)cmd->info; |
2923 | 0 | const char *arg1; |
2924 | |
|
2925 | 0 | if (endp == NULL) { |
2926 | 0 | return unclosed_directive(cmd); |
2927 | 0 | } |
2928 | | |
2929 | 0 | arg = apr_pstrmemdup(cmd->temp_pool, arg, endp - arg); |
2930 | |
|
2931 | 0 | if (not) { |
2932 | 0 | arg++; |
2933 | 0 | } |
2934 | |
|
2935 | 0 | arg1 = ap_getword_conf(cmd->temp_pool, &arg); |
2936 | |
|
2937 | 0 | if (!arg1[0]) { |
2938 | 0 | return missing_container_arg(cmd); |
2939 | 0 | } |
2940 | | |
2941 | 0 | result = testfn(cmd, arg1); |
2942 | |
|
2943 | 0 | if ((!not && result) || (not && !result)) { |
2944 | 0 | ap_directive_t *parent = NULL; |
2945 | 0 | ap_directive_t *current = NULL; |
2946 | 0 | const char *retval; |
2947 | |
|
2948 | 0 | retval = ap_build_cont_config(cmd->pool, cmd->temp_pool, cmd, |
2949 | 0 | ¤t, &parent, cmd->cmd->name); |
2950 | 0 | *(ap_directive_t **)mconfig = current; |
2951 | 0 | return retval; |
2952 | 0 | } |
2953 | 0 | else { |
2954 | 0 | *(ap_directive_t **)mconfig = NULL; |
2955 | 0 | return ap_soak_end_container(cmd, cmd->cmd->name); |
2956 | 0 | } |
2957 | 0 | } |
2958 | | |
2959 | | /* Callback to implement <IfModule> test for start_cond_section. */ |
2960 | | static int test_ifmod_section(cmd_parms *cmd, const char *arg) |
2961 | 0 | { |
2962 | 0 | return find_module(cmd->server, arg) != NULL; |
2963 | 0 | } |
2964 | | |
2965 | | AP_DECLARE(int) ap_exists_config_define(const char *name) |
2966 | 0 | { |
2967 | 0 | return ap_array_str_contains(ap_server_config_defines, name); |
2968 | 0 | } |
2969 | | |
2970 | | static int test_ifdefine_section(cmd_parms *cmd, const char *arg) |
2971 | 0 | { |
2972 | 0 | return ap_exists_config_define(arg); |
2973 | 0 | } |
2974 | | |
2975 | | static int test_iffile_section(cmd_parms *cmd, const char *arg) |
2976 | 0 | { |
2977 | 0 | const char *relative; |
2978 | 0 | apr_finfo_t sb; |
2979 | | |
2980 | | /* |
2981 | | * At least on Windows, if the path we are testing is not valid (for example |
2982 | | * a path on a USB key that is not plugged), 'ap_server_root_relative()' will |
2983 | | * return NULL. In such a case, consider that the file is not there and that |
2984 | | * the section should be skipped. |
2985 | | */ |
2986 | 0 | relative = ap_server_root_relative(cmd->temp_pool, arg); |
2987 | 0 | return (relative && |
2988 | 0 | (apr_stat(&sb, relative, APR_FINFO_TYPE, cmd->temp_pool) == APR_SUCCESS)); |
2989 | 0 | } |
2990 | | |
2991 | | static int test_ifdirective_section(cmd_parms *cmd, const char *arg) |
2992 | 0 | { |
2993 | 0 | return ap_exists_directive(cmd->temp_pool, arg); |
2994 | 0 | } |
2995 | | |
2996 | | static int test_ifsection_section(cmd_parms *cmd, const char *arg) |
2997 | 0 | { |
2998 | 0 | const char *name = apr_pstrcat(cmd->temp_pool, "<", arg, NULL); |
2999 | 0 | return ap_exists_directive(cmd->temp_pool, name); |
3000 | 0 | } |
3001 | | |
3002 | | /* httpd.conf commands... beginning with the <VirtualHost> business */ |
3003 | | |
3004 | | static const char *virtualhost_section(cmd_parms *cmd, void *dummy, |
3005 | | const char *arg) |
3006 | 0 | { |
3007 | 0 | server_rec *main_server = cmd->server, *s; |
3008 | 0 | const char *errmsg; |
3009 | 0 | const char *endp = ap_strrchr_c(arg, '>'); |
3010 | 0 | apr_pool_t *p = cmd->pool; |
3011 | |
|
3012 | 0 | const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); |
3013 | 0 | if (err != NULL) { |
3014 | 0 | return err; |
3015 | 0 | } |
3016 | | |
3017 | 0 | if (endp == NULL) { |
3018 | 0 | return unclosed_directive(cmd); |
3019 | 0 | } |
3020 | | |
3021 | 0 | arg = apr_pstrndup(cmd->temp_pool, arg, endp - arg); |
3022 | |
|
3023 | 0 | if (!arg[0]) { |
3024 | 0 | return missing_container_arg(cmd); |
3025 | 0 | } |
3026 | | |
3027 | | /* FIXME: There's another feature waiting to happen here -- since you |
3028 | | can now put multiple addresses/names on a single <VirtualHost> |
3029 | | you might want to use it to group common definitions and then |
3030 | | define other "subhosts" with their individual differences. But |
3031 | | personally I'd rather just do it with a macro preprocessor. -djg */ |
3032 | 0 | if (main_server->is_virtual) { |
3033 | 0 | return "<VirtualHost> doesn't nest!"; |
3034 | 0 | } |
3035 | | |
3036 | 0 | errmsg = ap_init_virtual_host(p, arg, main_server, &s); |
3037 | 0 | if (errmsg) { |
3038 | 0 | return errmsg; |
3039 | 0 | } |
3040 | | |
3041 | 0 | s->next = main_server->next; |
3042 | 0 | main_server->next = s; |
3043 | |
|
3044 | 0 | s->defn_name = cmd->directive->filename; |
3045 | 0 | s->defn_line_number = cmd->directive->line_num; |
3046 | |
|
3047 | 0 | cmd->server = s; |
3048 | |
|
3049 | 0 | errmsg = ap_walk_config(cmd->directive->first_child, cmd, |
3050 | 0 | s->lookup_defaults); |
3051 | |
|
3052 | 0 | cmd->server = main_server; |
3053 | |
|
3054 | 0 | return errmsg; |
3055 | 0 | } |
3056 | | |
3057 | | static const char *set_regex_default_options(cmd_parms *cmd, |
3058 | | void *dummy, |
3059 | | const char *arg) |
3060 | 0 | { |
3061 | 0 | const command_rec *thiscmd = cmd->cmd; |
3062 | 0 | int cflags, cflag; |
3063 | |
|
3064 | 0 | const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); |
3065 | 0 | if (err != NULL) { |
3066 | 0 | return err; |
3067 | 0 | } |
3068 | | |
3069 | 0 | cflags = ap_regcomp_get_default_cflags(); |
3070 | 0 | while (*arg) { |
3071 | 0 | const char *name = ap_getword_conf(cmd->pool, &arg); |
3072 | 0 | int how = 0; |
3073 | |
|
3074 | 0 | if (strcasecmp(name, "none") == 0) { |
3075 | 0 | cflags = 0; |
3076 | 0 | continue; |
3077 | 0 | } |
3078 | | |
3079 | 0 | if (*name == '+') { |
3080 | 0 | name++; |
3081 | 0 | how = +1; |
3082 | 0 | } |
3083 | 0 | else if (*name == '-') { |
3084 | 0 | name++; |
3085 | 0 | how = -1; |
3086 | 0 | } |
3087 | |
|
3088 | 0 | cflag = ap_regcomp_default_cflag_by_name(name); |
3089 | 0 | if (!cflag) { |
3090 | 0 | return apr_psprintf(cmd->pool, "%s: option '%s' unknown", |
3091 | 0 | thiscmd->name, name); |
3092 | 0 | } |
3093 | | |
3094 | 0 | if (how > 0) { |
3095 | 0 | cflags |= cflag; |
3096 | 0 | } |
3097 | 0 | else if (how < 0) { |
3098 | 0 | cflags &= ~cflag; |
3099 | 0 | } |
3100 | 0 | else { |
3101 | 0 | cflags = cflag; |
3102 | 0 | } |
3103 | 0 | } |
3104 | 0 | ap_regcomp_set_default_cflags(cflags); |
3105 | |
|
3106 | 0 | return NULL; |
3107 | 0 | } |
3108 | | |
3109 | | static const char *set_server_alias(cmd_parms *cmd, void *dummy, |
3110 | | const char *arg) |
3111 | 0 | { |
3112 | 0 | if (!cmd->server->names) { |
3113 | 0 | return "ServerAlias only used in <VirtualHost>"; |
3114 | 0 | } |
3115 | | |
3116 | 0 | while (*arg) { |
3117 | 0 | char **item, *name = ap_getword_conf(cmd->pool, &arg); |
3118 | |
|
3119 | 0 | if (ap_is_matchexp(name)) { |
3120 | 0 | item = (char **)apr_array_push(cmd->server->wild_names); |
3121 | 0 | } |
3122 | 0 | else { |
3123 | 0 | item = (char **)apr_array_push(cmd->server->names); |
3124 | 0 | } |
3125 | |
|
3126 | 0 | *item = name; |
3127 | 0 | } |
3128 | |
|
3129 | 0 | return NULL; |
3130 | 0 | } |
3131 | | |
3132 | | static const char *set_accf_map(cmd_parms *cmd, void *dummy, |
3133 | | const char *iproto, const char* iaccf) |
3134 | 0 | { |
3135 | 0 | const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); |
3136 | 0 | core_server_config *conf = |
3137 | 0 | ap_get_core_module_config(cmd->server->module_config); |
3138 | 0 | char* proto; |
3139 | 0 | char* accf; |
3140 | 0 | if (err != NULL) { |
3141 | 0 | return err; |
3142 | 0 | } |
3143 | | |
3144 | 0 | proto = apr_pstrdup(cmd->pool, iproto); |
3145 | 0 | ap_str_tolower(proto); |
3146 | 0 | accf = apr_pstrdup(cmd->pool, iaccf); |
3147 | 0 | ap_str_tolower(accf); |
3148 | 0 | apr_table_setn(conf->accf_map, proto, accf); |
3149 | |
|
3150 | 0 | return NULL; |
3151 | 0 | } |
3152 | | |
3153 | | AP_DECLARE(const char*) ap_get_server_protocol(server_rec* s) |
3154 | 0 | { |
3155 | 0 | core_server_config *conf = ap_get_core_module_config(s->module_config); |
3156 | 0 | return conf->protocol; |
3157 | 0 | } |
3158 | | |
3159 | | AP_DECLARE(void) ap_set_server_protocol(server_rec* s, const char* proto) |
3160 | 0 | { |
3161 | 0 | core_server_config *conf = ap_get_core_module_config(s->module_config); |
3162 | 0 | conf->protocol = proto; |
3163 | 0 | } |
3164 | | |
3165 | | static const char *set_protocol(cmd_parms *cmd, void *dummy, |
3166 | | const char *arg) |
3167 | 0 | { |
3168 | 0 | const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); |
3169 | 0 | core_server_config *conf = |
3170 | 0 | ap_get_core_module_config(cmd->server->module_config); |
3171 | 0 | char* proto; |
3172 | |
|
3173 | 0 | if (err != NULL) { |
3174 | 0 | return err; |
3175 | 0 | } |
3176 | | |
3177 | 0 | proto = apr_pstrdup(cmd->pool, arg); |
3178 | 0 | ap_str_tolower(proto); |
3179 | 0 | conf->protocol = proto; |
3180 | |
|
3181 | 0 | return NULL; |
3182 | 0 | } |
3183 | | |
3184 | | static const char *set_server_string_slot(cmd_parms *cmd, void *dummy, |
3185 | | const char *arg) |
3186 | 0 | { |
3187 | | /* This one's pretty generic... */ |
3188 | |
|
3189 | 0 | int offset = (int)(long)cmd->info; |
3190 | 0 | char *struct_ptr = (char *)cmd->server; |
3191 | |
|
3192 | 0 | const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); |
3193 | 0 | if (err != NULL) { |
3194 | 0 | return err; |
3195 | 0 | } |
3196 | | |
3197 | 0 | *(const char **)(struct_ptr + offset) = arg; |
3198 | 0 | return NULL; |
3199 | 0 | } |
3200 | | |
3201 | | /* |
3202 | | * The ServerName directive takes one argument with format |
3203 | | * [scheme://]fully-qualified-domain-name[:port], for instance |
3204 | | * ServerName www.example.com |
3205 | | * ServerName www.example.com:80 |
3206 | | * ServerName https://www.example.com:443 |
3207 | | */ |
3208 | | |
3209 | | static const char *server_hostname_port(cmd_parms *cmd, void *dummy, const char *arg) |
3210 | 0 | { |
3211 | 0 | const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); |
3212 | 0 | const char *portstr, *part; |
3213 | 0 | char *scheme; |
3214 | 0 | int port; |
3215 | |
|
3216 | 0 | if (err != NULL) { |
3217 | 0 | return err; |
3218 | 0 | } |
3219 | | |
3220 | 0 | if (apr_fnmatch_test(arg)) |
3221 | 0 | return apr_pstrcat(cmd->temp_pool, "Invalid ServerName \"", arg, |
3222 | 0 | "\" use ServerAlias to set multiple server names.", NULL); |
3223 | | |
3224 | 0 | part = ap_strstr_c(arg, "://"); |
3225 | |
|
3226 | 0 | if (part) { |
3227 | 0 | scheme = apr_pstrndup(cmd->pool, arg, part - arg); |
3228 | 0 | ap_str_tolower(scheme); |
3229 | 0 | cmd->server->server_scheme = (const char *)scheme; |
3230 | 0 | part += 3; |
3231 | 0 | } else { |
3232 | 0 | part = arg; |
3233 | 0 | } |
3234 | |
|
3235 | 0 | portstr = ap_strchr_c(part, ':'); |
3236 | 0 | if (portstr) { |
3237 | 0 | cmd->server->server_hostname = apr_pstrndup(cmd->pool, part, |
3238 | 0 | portstr - part); |
3239 | 0 | portstr++; |
3240 | 0 | port = atoi(portstr); |
3241 | 0 | if (port <= 0 || port >= 65536) { /* 65536 == 1<<16 */ |
3242 | 0 | return apr_pstrcat(cmd->temp_pool, "The port number \"", arg, |
3243 | 0 | "\" is outside the appropriate range " |
3244 | 0 | "(i.e., 1..65535).", NULL); |
3245 | 0 | } |
3246 | 0 | } |
3247 | 0 | else { |
3248 | 0 | cmd->server->server_hostname = apr_pstrdup(cmd->pool, part); |
3249 | 0 | port = 0; |
3250 | 0 | } |
3251 | | |
3252 | 0 | cmd->server->port = port; |
3253 | 0 | return NULL; |
3254 | 0 | } |
3255 | | |
3256 | | static const char *set_signature_flag(cmd_parms *cmd, void *d_, |
3257 | | const char *arg) |
3258 | 0 | { |
3259 | 0 | core_dir_config *d = d_; |
3260 | |
|
3261 | 0 | if (ap_cstr_casecmp(arg, "On") == 0) { |
3262 | 0 | d->server_signature = srv_sig_on; |
3263 | 0 | } |
3264 | 0 | else if (ap_cstr_casecmp(arg, "Off") == 0) { |
3265 | 0 | d->server_signature = srv_sig_off; |
3266 | 0 | } |
3267 | 0 | else if (ap_cstr_casecmp(arg, "EMail") == 0) { |
3268 | 0 | d->server_signature = srv_sig_withmail; |
3269 | 0 | } |
3270 | 0 | else { |
3271 | 0 | return "ServerSignature: use one of: off | on | email"; |
3272 | 0 | } |
3273 | | |
3274 | 0 | return NULL; |
3275 | 0 | } |
3276 | | |
3277 | | static const char *set_server_root(cmd_parms *cmd, void *dummy, |
3278 | | const char *arg) |
3279 | 0 | { |
3280 | 0 | const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); |
3281 | |
|
3282 | 0 | if (err != NULL) { |
3283 | 0 | return err; |
3284 | 0 | } |
3285 | | |
3286 | 0 | if ((apr_filepath_merge((char**)&ap_server_root, NULL, arg, |
3287 | 0 | APR_FILEPATH_TRUENAME, cmd->pool) != APR_SUCCESS) |
3288 | 0 | || !ap_is_directory(cmd->temp_pool, ap_server_root)) { |
3289 | 0 | return "ServerRoot must be a valid directory"; |
3290 | 0 | } |
3291 | | |
3292 | 0 | return NULL; |
3293 | 0 | } |
3294 | | |
3295 | | static const char *set_runtime_dir(cmd_parms *cmd, void *dummy, const char *arg) |
3296 | 0 | { |
3297 | 0 | const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); |
3298 | |
|
3299 | 0 | if (err != NULL) { |
3300 | 0 | return err; |
3301 | 0 | } |
3302 | | |
3303 | 0 | if ((apr_filepath_merge((char**)&ap_runtime_dir, NULL, |
3304 | 0 | ap_server_root_relative(cmd->temp_pool, arg), |
3305 | 0 | APR_FILEPATH_TRUENAME, cmd->pool) != APR_SUCCESS) |
3306 | 0 | || !ap_is_directory(cmd->temp_pool, ap_runtime_dir)) { |
3307 | 0 | return "DefaultRuntimeDir must be a valid directory, absolute or relative to ServerRoot"; |
3308 | 0 | } |
3309 | | |
3310 | 0 | return NULL; |
3311 | 0 | } |
3312 | | |
3313 | | static const char *set_state_dir(cmd_parms *cmd, void *dummy, const char *arg) |
3314 | 0 | { |
3315 | 0 | const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); |
3316 | |
|
3317 | 0 | if (err != NULL) { |
3318 | 0 | return err; |
3319 | 0 | } |
3320 | | |
3321 | 0 | if ((apr_filepath_merge((char**)&core_state_dir, NULL, |
3322 | 0 | ap_server_root_relative(cmd->temp_pool, arg), |
3323 | 0 | APR_FILEPATH_TRUENAME, cmd->pool) != APR_SUCCESS) |
3324 | 0 | || !ap_is_directory(cmd->temp_pool, core_state_dir)) { |
3325 | 0 | return "DefaultStateDir must be a valid directory, absolute or relative to ServerRoot"; |
3326 | 0 | } |
3327 | | |
3328 | 0 | return NULL; |
3329 | 0 | } |
3330 | | |
3331 | | static const char *set_timeout(cmd_parms *cmd, void *dummy, const char *arg) |
3332 | 0 | { |
3333 | 0 | const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); |
3334 | |
|
3335 | 0 | if (err != NULL) { |
3336 | 0 | return err; |
3337 | 0 | } |
3338 | | |
3339 | 0 | cmd->server->timeout = apr_time_from_sec(atoi(arg)); |
3340 | 0 | return NULL; |
3341 | 0 | } |
3342 | | |
3343 | | static const char *set_allow2f(cmd_parms *cmd, void *d_, const char *arg) |
3344 | 0 | { |
3345 | 0 | core_dir_config *d = d_; |
3346 | |
|
3347 | 0 | if (0 == ap_cstr_casecmp(arg, "on")) { |
3348 | 0 | d->allow_encoded_slashes = 1; |
3349 | 0 | d->decode_encoded_slashes = 1; /* for compatibility with 2.0 & 2.2 */ |
3350 | 0 | } else if (0 == ap_cstr_casecmp(arg, "off")) { |
3351 | 0 | d->allow_encoded_slashes = 0; |
3352 | 0 | d->decode_encoded_slashes = 0; |
3353 | 0 | } else if (0 == ap_cstr_casecmp(arg, "nodecode")) { |
3354 | 0 | d->allow_encoded_slashes = 1; |
3355 | 0 | d->decode_encoded_slashes = 0; |
3356 | 0 | } else { |
3357 | 0 | return apr_pstrcat(cmd->pool, |
3358 | 0 | cmd->cmd->name, " must be On, Off, or NoDecode", |
3359 | 0 | NULL); |
3360 | 0 | } |
3361 | | |
3362 | 0 | d->allow_encoded_slashes_set = 1; |
3363 | 0 | d->decode_encoded_slashes_set = 1; |
3364 | |
|
3365 | 0 | return NULL; |
3366 | 0 | } |
3367 | | |
3368 | | static const char *set_hostname_lookups(cmd_parms *cmd, void *d_, |
3369 | | const char *arg) |
3370 | 0 | { |
3371 | 0 | core_dir_config *d = d_; |
3372 | |
|
3373 | 0 | if (!ap_cstr_casecmp(arg, "on")) { |
3374 | 0 | d->hostname_lookups = HOSTNAME_LOOKUP_ON; |
3375 | 0 | } |
3376 | 0 | else if (!ap_cstr_casecmp(arg, "off")) { |
3377 | 0 | d->hostname_lookups = HOSTNAME_LOOKUP_OFF; |
3378 | 0 | } |
3379 | 0 | else if (!ap_cstr_casecmp(arg, "double")) { |
3380 | 0 | d->hostname_lookups = HOSTNAME_LOOKUP_DOUBLE; |
3381 | 0 | } |
3382 | 0 | else { |
3383 | 0 | return "parameter must be 'on', 'off', or 'double'"; |
3384 | 0 | } |
3385 | | |
3386 | 0 | return NULL; |
3387 | 0 | } |
3388 | | |
3389 | | static const char *set_serverpath(cmd_parms *cmd, void *dummy, |
3390 | | const char *arg) |
3391 | 0 | { |
3392 | 0 | const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); |
3393 | |
|
3394 | 0 | if (err != NULL) { |
3395 | 0 | return err; |
3396 | 0 | } |
3397 | | |
3398 | 0 | cmd->server->path = arg; |
3399 | 0 | cmd->server->pathlen = (int)strlen(arg); |
3400 | 0 | return NULL; |
3401 | 0 | } |
3402 | | |
3403 | | static const char *set_accept_path_info(cmd_parms *cmd, void *d_, const char *arg) |
3404 | 0 | { |
3405 | 0 | core_dir_config *d = d_; |
3406 | |
|
3407 | 0 | if (ap_cstr_casecmp(arg, "on") == 0) { |
3408 | 0 | d->accept_path_info = AP_REQ_ACCEPT_PATH_INFO; |
3409 | 0 | } |
3410 | 0 | else if (ap_cstr_casecmp(arg, "off") == 0) { |
3411 | 0 | d->accept_path_info = AP_REQ_REJECT_PATH_INFO; |
3412 | 0 | } |
3413 | 0 | else if (ap_cstr_casecmp(arg, "default") == 0) { |
3414 | 0 | d->accept_path_info = AP_REQ_DEFAULT_PATH_INFO; |
3415 | 0 | } |
3416 | 0 | else { |
3417 | 0 | return "AcceptPathInfo must be set to on, off or default"; |
3418 | 0 | } |
3419 | | |
3420 | 0 | return NULL; |
3421 | 0 | } |
3422 | | |
3423 | | static const char *set_use_canonical_name(cmd_parms *cmd, void *d_, |
3424 | | const char *arg) |
3425 | 0 | { |
3426 | 0 | core_dir_config *d = d_; |
3427 | |
|
3428 | 0 | if (ap_cstr_casecmp(arg, "on") == 0) { |
3429 | 0 | d->use_canonical_name = USE_CANONICAL_NAME_ON; |
3430 | 0 | } |
3431 | 0 | else if (ap_cstr_casecmp(arg, "off") == 0) { |
3432 | 0 | d->use_canonical_name = USE_CANONICAL_NAME_OFF; |
3433 | 0 | } |
3434 | 0 | else if (ap_cstr_casecmp(arg, "dns") == 0) { |
3435 | 0 | d->use_canonical_name = USE_CANONICAL_NAME_DNS; |
3436 | 0 | } |
3437 | 0 | else { |
3438 | 0 | return "parameter must be 'on', 'off', or 'dns'"; |
3439 | 0 | } |
3440 | | |
3441 | 0 | return NULL; |
3442 | 0 | } |
3443 | | |
3444 | | static const char *set_use_canonical_phys_port(cmd_parms *cmd, void *d_, |
3445 | | const char *arg) |
3446 | 0 | { |
3447 | 0 | core_dir_config *d = d_; |
3448 | |
|
3449 | 0 | if (ap_cstr_casecmp(arg, "on") == 0) { |
3450 | 0 | d->use_canonical_phys_port = USE_CANONICAL_PHYS_PORT_ON; |
3451 | 0 | } |
3452 | 0 | else if (ap_cstr_casecmp(arg, "off") == 0) { |
3453 | 0 | d->use_canonical_phys_port = USE_CANONICAL_PHYS_PORT_OFF; |
3454 | 0 | } |
3455 | 0 | else { |
3456 | 0 | return "parameter must be 'on' or 'off'"; |
3457 | 0 | } |
3458 | | |
3459 | 0 | return NULL; |
3460 | 0 | } |
3461 | | |
3462 | | static const char *include_config (cmd_parms *cmd, void *dummy, |
3463 | | const char *name) |
3464 | 0 | { |
3465 | 0 | ap_directive_t *conftree = NULL; |
3466 | 0 | const char *conffile, *error; |
3467 | 0 | unsigned *recursion; |
3468 | 0 | int optional = cmd->cmd->cmd_data ? 1 : 0; |
3469 | 0 | void *data; |
3470 | | |
3471 | | /* NOTE: ap_include_sentinel is also used by ap_process_resource_config() |
3472 | | * during DUMP_INCLUDES; don't change its type or remove it without updating |
3473 | | * the other. |
3474 | | */ |
3475 | 0 | apr_pool_userdata_get(&data, "ap_include_sentinel", cmd->pool); |
3476 | 0 | if (data) { |
3477 | 0 | recursion = data; |
3478 | 0 | } |
3479 | 0 | else { |
3480 | 0 | data = recursion = apr_palloc(cmd->pool, sizeof(*recursion)); |
3481 | 0 | *recursion = 0; |
3482 | 0 | apr_pool_userdata_setn(data, "ap_include_sentinel", NULL, cmd->pool); |
3483 | 0 | } |
3484 | |
|
3485 | 0 | if (++*recursion > AP_MAX_INCLUDE_DEPTH) { |
3486 | 0 | *recursion = 0; |
3487 | 0 | return apr_psprintf(cmd->pool, "Exceeded maximum include depth of %u, " |
3488 | 0 | "There appears to be a recursion.", |
3489 | 0 | AP_MAX_INCLUDE_DEPTH); |
3490 | 0 | } |
3491 | | |
3492 | 0 | conffile = ap_server_root_relative(cmd->pool, name); |
3493 | 0 | if (!conffile) { |
3494 | 0 | *recursion = 0; |
3495 | 0 | return apr_pstrcat(cmd->pool, "Invalid Include path ", |
3496 | 0 | name, NULL); |
3497 | 0 | } |
3498 | | |
3499 | 0 | if (ap_exists_config_define("DUMP_INCLUDES")) { |
3500 | 0 | unsigned *line_number; |
3501 | | |
3502 | | /* NOTE: ap_include_lineno is used by ap_process_resource_config() |
3503 | | * during DUMP_INCLUDES; don't change its type or remove it without |
3504 | | * updating the other. |
3505 | | */ |
3506 | 0 | apr_pool_userdata_get(&data, "ap_include_lineno", cmd->pool); |
3507 | 0 | if (data) { |
3508 | 0 | line_number = data; |
3509 | 0 | } else { |
3510 | 0 | data = line_number = apr_palloc(cmd->pool, sizeof(*line_number)); |
3511 | 0 | apr_pool_userdata_setn(data, "ap_include_lineno", NULL, cmd->pool); |
3512 | 0 | } |
3513 | |
|
3514 | 0 | *line_number = cmd->config_file->line_number; |
3515 | 0 | } |
3516 | |
|
3517 | 0 | error = ap_process_fnmatch_configs(cmd->server, conffile, &conftree, |
3518 | 0 | cmd->pool, cmd->temp_pool, |
3519 | 0 | optional); |
3520 | 0 | if (error) { |
3521 | 0 | *recursion = 0; |
3522 | 0 | return error; |
3523 | 0 | } |
3524 | | |
3525 | 0 | *(ap_directive_t **)dummy = conftree; |
3526 | | |
3527 | | /* recursion level done */ |
3528 | 0 | if (*recursion) { |
3529 | 0 | --*recursion; |
3530 | 0 | } |
3531 | |
|
3532 | 0 | return NULL; |
3533 | 0 | } |
3534 | | |
3535 | | static const char *update_loglevel(cmd_parms *cmd, struct ap_logconf *log, |
3536 | | const char *arg) |
3537 | 0 | { |
3538 | 0 | const char *level_str, *err; |
3539 | 0 | module *module; |
3540 | 0 | int level; |
3541 | |
|
3542 | 0 | level_str = ap_strrchr_c(arg, ':'); |
3543 | |
|
3544 | 0 | if (level_str == NULL) { |
3545 | 0 | err = ap_parse_log_level(arg, &log->level); |
3546 | 0 | if (err != NULL) |
3547 | 0 | return err; |
3548 | 0 | ap_reset_module_loglevels(log, APLOG_NO_MODULE); |
3549 | 0 | ap_log_error(APLOG_MARK, APLOG_TRACE3, 0, cmd->server, |
3550 | 0 | "Setting %s for all modules to %s", cmd->cmd->name, arg); |
3551 | 0 | return NULL; |
3552 | 0 | } |
3553 | | |
3554 | 0 | arg = apr_pstrmemdup(cmd->temp_pool, arg, level_str - arg); |
3555 | 0 | level_str++; |
3556 | 0 | if (!*level_str) { |
3557 | 0 | return apr_psprintf(cmd->temp_pool, "Module specifier '%s' must be " |
3558 | 0 | "followed by a log level keyword", arg); |
3559 | 0 | } |
3560 | | |
3561 | 0 | err = ap_parse_log_level(level_str, &level); |
3562 | 0 | if (err != NULL) |
3563 | 0 | return apr_psprintf(cmd->temp_pool, "%s:%s: %s", arg, level_str, err); |
3564 | | |
3565 | 0 | if ((module = find_module(cmd->server, arg)) == NULL) { |
3566 | 0 | char *name = apr_psprintf(cmd->temp_pool, "%s_module", arg); |
3567 | 0 | ap_log_error(APLOG_MARK, APLOG_TRACE6, 0, cmd->server, |
3568 | 0 | "Cannot find module '%s', trying '%s'", arg, name); |
3569 | 0 | module = find_module(cmd->server, name); |
3570 | 0 | } |
3571 | |
|
3572 | 0 | if (module == NULL) { |
3573 | 0 | return apr_psprintf(cmd->temp_pool, "Cannot find module %s", arg); |
3574 | 0 | } |
3575 | | |
3576 | 0 | ap_set_module_loglevel(cmd->pool, log, module->module_index, level); |
3577 | 0 | ap_log_error(APLOG_MARK, APLOG_TRACE3, 0, cmd->server, |
3578 | 0 | "Setting %s for module %s to %s", cmd->cmd->name, |
3579 | 0 | module->name, level_str); |
3580 | |
|
3581 | 0 | return NULL; |
3582 | 0 | } |
3583 | | |
3584 | | static const char *set_loglevel(cmd_parms *cmd, void *config_, const char *arg) |
3585 | 0 | { |
3586 | 0 | struct ap_logconf *log; |
3587 | |
|
3588 | 0 | if (cmd->path) { |
3589 | 0 | core_dir_config *dconf = config_; |
3590 | 0 | if (!dconf->log) { |
3591 | 0 | dconf->log = ap_new_log_config(cmd->pool, NULL); |
3592 | 0 | } |
3593 | 0 | log = dconf->log; |
3594 | 0 | } |
3595 | 0 | else { |
3596 | 0 | log = &cmd->server->log; |
3597 | 0 | } |
3598 | |
|
3599 | 0 | if (arg == NULL) |
3600 | 0 | return "LogLevel requires level keyword or module loglevel specifier"; |
3601 | | |
3602 | 0 | return update_loglevel(cmd, log, arg); |
3603 | 0 | } |
3604 | | |
3605 | | static const char *set_loglevel_override(cmd_parms *cmd, void *d_, int argc, |
3606 | | char *const argv[]) |
3607 | 0 | { |
3608 | 0 | core_server_config *sconf; |
3609 | 0 | conn_log_config *entry; |
3610 | 0 | int ret, i; |
3611 | 0 | const char *addr, *mask, *err; |
3612 | |
|
3613 | 0 | if (argc < 2) |
3614 | 0 | return "LogLevelOverride requires at least two arguments"; |
3615 | | |
3616 | 0 | entry = apr_pcalloc(cmd->pool, sizeof(conn_log_config)); |
3617 | 0 | sconf = ap_get_core_module_config(cmd->server->module_config); |
3618 | 0 | if (!sconf->conn_log_level) |
3619 | 0 | sconf->conn_log_level = apr_array_make(cmd->pool, 4, sizeof(entry)); |
3620 | 0 | APR_ARRAY_PUSH(sconf->conn_log_level, conn_log_config *) = entry; |
3621 | |
|
3622 | 0 | addr = argv[0]; |
3623 | 0 | mask = ap_strchr_c(addr, '/'); |
3624 | 0 | if (mask) { |
3625 | 0 | addr = apr_pstrmemdup(cmd->temp_pool, addr, mask - addr); |
3626 | 0 | mask++; |
3627 | 0 | } |
3628 | 0 | ret = apr_ipsubnet_create(&entry->subnet, addr, mask, cmd->pool); |
3629 | 0 | if (ret != APR_SUCCESS) |
3630 | 0 | return "parsing of subnet/netmask failed"; |
3631 | | |
3632 | 0 | for (i = 1; i < argc; i++) { |
3633 | 0 | if ((err = update_loglevel(cmd, &entry->log, argv[i])) != NULL) |
3634 | 0 | return err; |
3635 | 0 | } |
3636 | 0 | return NULL; |
3637 | 0 | } |
3638 | | |
3639 | | AP_DECLARE(const char *) ap_psignature(const char *prefix, request_rec *r) |
3640 | 0 | { |
3641 | 0 | char sport[20]; |
3642 | 0 | core_dir_config *conf; |
3643 | |
|
3644 | 0 | conf = (core_dir_config *)ap_get_core_module_config(r->per_dir_config); |
3645 | 0 | if ((conf->server_signature == srv_sig_off) |
3646 | 0 | || (conf->server_signature == srv_sig_unset)) { |
3647 | 0 | return ""; |
3648 | 0 | } |
3649 | | |
3650 | 0 | apr_snprintf(sport, sizeof sport, "%u", (unsigned) ap_get_server_port(r)); |
3651 | |
|
3652 | 0 | if (conf->server_signature == srv_sig_withmail) { |
3653 | 0 | return apr_pstrcat(r->pool, prefix, "<address>", |
3654 | 0 | ap_get_server_banner(), |
3655 | 0 | " Server at <a href=\"", |
3656 | 0 | ap_is_url(r->server->server_admin) ? "" : "mailto:", |
3657 | 0 | ap_escape_html(r->pool, r->server->server_admin), |
3658 | 0 | "\">", |
3659 | 0 | ap_escape_html(r->pool, ap_get_server_name(r)), |
3660 | 0 | "</a> Port ", sport, |
3661 | 0 | "</address>\n", NULL); |
3662 | 0 | } |
3663 | | |
3664 | 0 | return apr_pstrcat(r->pool, prefix, "<address>", ap_get_server_banner(), |
3665 | 0 | " Server at ", |
3666 | 0 | ap_escape_html(r->pool, ap_get_server_name(r)), |
3667 | 0 | " Port ", sport, |
3668 | 0 | "</address>\n", NULL); |
3669 | 0 | } |
3670 | | |
3671 | | /* |
3672 | | * Handle a request to include the server's OS platform in the Server |
3673 | | * response header field (the ServerTokens directive). Unfortunately |
3674 | | * this requires a new global in order to communicate the setting back to |
3675 | | * http_main so it can insert the information in the right place in the |
3676 | | * string. |
3677 | | */ |
3678 | | |
3679 | | static char *server_banner = NULL; |
3680 | | static int banner_locked = 0; |
3681 | | static const char *server_description = NULL; |
3682 | | |
3683 | | enum server_token_type { |
3684 | | SrvTk_MAJOR, /* eg: Apache/2 */ |
3685 | | SrvTk_MINOR, /* eg. Apache/2.0 */ |
3686 | | SrvTk_MINIMAL, /* eg: Apache/2.0.41 */ |
3687 | | SrvTk_OS, /* eg: Apache/2.0.41 (UNIX) */ |
3688 | | SrvTk_FULL, /* eg: Apache/2.0.41 (UNIX) PHP/4.2.2 FooBar/1.2b */ |
3689 | | SrvTk_PRODUCT_ONLY /* eg: Apache */ |
3690 | | }; |
3691 | | static enum server_token_type ap_server_tokens = SrvTk_FULL; |
3692 | | |
3693 | | static apr_status_t reset_banner(void *dummy) |
3694 | 0 | { |
3695 | 0 | banner_locked = 0; |
3696 | 0 | ap_server_tokens = SrvTk_FULL; |
3697 | 0 | server_banner = NULL; |
3698 | 0 | server_description = NULL; |
3699 | 0 | return APR_SUCCESS; |
3700 | 0 | } |
3701 | | |
3702 | | AP_DECLARE(void) ap_get_server_revision(ap_version_t *version) |
3703 | 0 | { |
3704 | 0 | version->major = AP_SERVER_MAJORVERSION_NUMBER; |
3705 | 0 | version->minor = AP_SERVER_MINORVERSION_NUMBER; |
3706 | 0 | version->patch = AP_SERVER_PATCHLEVEL_NUMBER; |
3707 | 0 | version->add_string = AP_SERVER_ADD_STRING; |
3708 | 0 | } |
3709 | | |
3710 | | AP_DECLARE(const char *) ap_get_server_description(void) |
3711 | 0 | { |
3712 | 0 | return server_description ? server_description : |
3713 | 0 | AP_SERVER_BASEVERSION " (" PLATFORM ")"; |
3714 | 0 | } |
3715 | | |
3716 | | AP_DECLARE(const char *) ap_get_server_banner(void) |
3717 | 0 | { |
3718 | 0 | return server_banner ? server_banner : AP_SERVER_BASEVERSION; |
3719 | 0 | } |
3720 | | |
3721 | | AP_DECLARE(void) ap_add_version_component(apr_pool_t *pconf, const char *component) |
3722 | 0 | { |
3723 | 0 | if (! banner_locked) { |
3724 | | /* |
3725 | | * If the version string is null, register our cleanup to reset the |
3726 | | * pointer on pool destruction. We also know that, if NULL, |
3727 | | * we are adding the original SERVER_BASEVERSION string. |
3728 | | */ |
3729 | 0 | if (server_banner == NULL) { |
3730 | 0 | apr_pool_cleanup_register(pconf, NULL, reset_banner, |
3731 | 0 | apr_pool_cleanup_null); |
3732 | 0 | server_banner = apr_pstrdup(pconf, component); |
3733 | 0 | } |
3734 | 0 | else { |
3735 | | /* |
3736 | | * Tack the given component identifier to the end of |
3737 | | * the existing string. |
3738 | | */ |
3739 | 0 | server_banner = apr_pstrcat(pconf, server_banner, " ", |
3740 | 0 | component, NULL); |
3741 | 0 | } |
3742 | 0 | } |
3743 | 0 | server_description = apr_pstrcat(pconf, server_description, " ", |
3744 | 0 | component, NULL); |
3745 | 0 | } |
3746 | | |
3747 | | /* |
3748 | | * This routine adds the real server base identity to the banner string, |
3749 | | * and then locks out changes until the next reconfig. |
3750 | | */ |
3751 | | static void set_banner(apr_pool_t *pconf) |
3752 | 0 | { |
3753 | 0 | if (ap_server_tokens == SrvTk_PRODUCT_ONLY) { |
3754 | 0 | ap_add_version_component(pconf, AP_SERVER_BASEPRODUCT); |
3755 | 0 | } |
3756 | 0 | else if (ap_server_tokens == SrvTk_MINIMAL) { |
3757 | 0 | ap_add_version_component(pconf, AP_SERVER_BASEVERSION); |
3758 | 0 | } |
3759 | 0 | else if (ap_server_tokens == SrvTk_MINOR) { |
3760 | 0 | ap_add_version_component(pconf, AP_SERVER_BASEPRODUCT "/" AP_SERVER_MINORREVISION); |
3761 | 0 | } |
3762 | 0 | else if (ap_server_tokens == SrvTk_MAJOR) { |
3763 | 0 | ap_add_version_component(pconf, AP_SERVER_BASEPRODUCT "/" AP_SERVER_MAJORVERSION); |
3764 | 0 | } |
3765 | 0 | else { |
3766 | 0 | ap_add_version_component(pconf, AP_SERVER_BASEVERSION " (" PLATFORM ")"); |
3767 | 0 | } |
3768 | | |
3769 | | /* |
3770 | | * Lock the server_banner string if we're not displaying |
3771 | | * the full set of tokens |
3772 | | */ |
3773 | 0 | if (ap_server_tokens != SrvTk_FULL) { |
3774 | 0 | banner_locked++; |
3775 | 0 | } |
3776 | 0 | server_description = AP_SERVER_BASEVERSION " (" PLATFORM ")"; |
3777 | 0 | } |
3778 | | |
3779 | | static const char *set_serv_tokens(cmd_parms *cmd, void *dummy, |
3780 | | const char *arg) |
3781 | 0 | { |
3782 | 0 | const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); |
3783 | |
|
3784 | 0 | if (err != NULL) { |
3785 | 0 | return err; |
3786 | 0 | } |
3787 | | |
3788 | 0 | if (!ap_cstr_casecmp(arg, "OS")) { |
3789 | 0 | ap_server_tokens = SrvTk_OS; |
3790 | 0 | } |
3791 | 0 | else if (!ap_cstr_casecmp(arg, "Min") || !ap_cstr_casecmp(arg, "Minimal")) { |
3792 | 0 | ap_server_tokens = SrvTk_MINIMAL; |
3793 | 0 | } |
3794 | 0 | else if (!ap_cstr_casecmp(arg, "Major")) { |
3795 | 0 | ap_server_tokens = SrvTk_MAJOR; |
3796 | 0 | } |
3797 | 0 | else if (!ap_cstr_casecmp(arg, "Minor") ) { |
3798 | 0 | ap_server_tokens = SrvTk_MINOR; |
3799 | 0 | } |
3800 | 0 | else if (!ap_cstr_casecmp(arg, "Prod") || !ap_cstr_casecmp(arg, "ProductOnly")) { |
3801 | 0 | ap_server_tokens = SrvTk_PRODUCT_ONLY; |
3802 | 0 | } |
3803 | 0 | else if (!ap_cstr_casecmp(arg, "Full")) { |
3804 | 0 | ap_server_tokens = SrvTk_FULL; |
3805 | 0 | } |
3806 | 0 | else { |
3807 | 0 | return "ServerTokens takes 1 argument: 'Prod(uctOnly)', 'Major', 'Minor', 'Min(imal)', 'OS', or 'Full'"; |
3808 | 0 | } |
3809 | | |
3810 | 0 | return NULL; |
3811 | 0 | } |
3812 | | |
3813 | | static const char *set_limit_req_line(cmd_parms *cmd, void *dummy, |
3814 | | const char *arg) |
3815 | 0 | { |
3816 | 0 | const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); |
3817 | 0 | int lim; |
3818 | |
|
3819 | 0 | if (err != NULL) { |
3820 | 0 | return err; |
3821 | 0 | } |
3822 | | |
3823 | 0 | lim = atoi(arg); |
3824 | 0 | if (lim < 0) { |
3825 | 0 | return apr_pstrcat(cmd->temp_pool, "LimitRequestLine \"", arg, |
3826 | 0 | "\" must be a non-negative integer", NULL); |
3827 | 0 | } |
3828 | | |
3829 | 0 | cmd->server->limit_req_line = lim; |
3830 | 0 | return NULL; |
3831 | 0 | } |
3832 | | |
3833 | | static const char *set_limit_req_fieldsize(cmd_parms *cmd, void *dummy, |
3834 | | const char *arg) |
3835 | 0 | { |
3836 | 0 | const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); |
3837 | 0 | int lim; |
3838 | |
|
3839 | 0 | if (err != NULL) { |
3840 | 0 | return err; |
3841 | 0 | } |
3842 | | |
3843 | 0 | lim = atoi(arg); |
3844 | 0 | if (lim < 0) { |
3845 | 0 | return apr_pstrcat(cmd->temp_pool, "LimitRequestFieldsize \"", arg, |
3846 | 0 | "\" must be a non-negative integer", |
3847 | 0 | NULL); |
3848 | 0 | } |
3849 | | |
3850 | 0 | cmd->server->limit_req_fieldsize = lim; |
3851 | 0 | return NULL; |
3852 | 0 | } |
3853 | | |
3854 | | static const char *set_limit_req_fields(cmd_parms *cmd, void *dummy, |
3855 | | const char *arg) |
3856 | 0 | { |
3857 | 0 | const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); |
3858 | 0 | int lim; |
3859 | |
|
3860 | 0 | if (err != NULL) { |
3861 | 0 | return err; |
3862 | 0 | } |
3863 | | |
3864 | 0 | lim = atoi(arg); |
3865 | 0 | if (lim < 0) { |
3866 | 0 | return apr_pstrcat(cmd->temp_pool, "LimitRequestFields \"", arg, |
3867 | 0 | "\" must be a non-negative integer (0 = no limit)", |
3868 | 0 | NULL); |
3869 | 0 | } |
3870 | | |
3871 | 0 | cmd->server->limit_req_fields = lim; |
3872 | 0 | return NULL; |
3873 | 0 | } |
3874 | | |
3875 | | static const char *set_limit_req_body(cmd_parms *cmd, void *conf_, |
3876 | | const char *arg) |
3877 | 0 | { |
3878 | 0 | core_dir_config *conf = conf_; |
3879 | 0 | char *errp; |
3880 | |
|
3881 | 0 | if (APR_SUCCESS != apr_strtoff(&conf->limit_req_body, arg, &errp, 10)) { |
3882 | 0 | return "LimitRequestBody argument is not parsable."; |
3883 | 0 | } |
3884 | 0 | if (*errp || conf->limit_req_body < 0) { |
3885 | 0 | return "LimitRequestBody requires a non-negative integer."; |
3886 | 0 | } |
3887 | | |
3888 | 0 | return NULL; |
3889 | 0 | } |
3890 | | |
3891 | | static const char *set_limit_xml_req_body(cmd_parms *cmd, void *conf_, |
3892 | | const char *arg) |
3893 | 0 | { |
3894 | 0 | core_dir_config *conf = conf_; |
3895 | |
|
3896 | 0 | conf->limit_xml_body = atol(arg); |
3897 | 0 | if (conf->limit_xml_body < 0) |
3898 | 0 | return "LimitXMLRequestBody requires a non-negative integer."; |
3899 | | |
3900 | | /* zero is AP_MAX_LIMIT_XML_BODY (implicitly) */ |
3901 | 0 | if ((apr_size_t)conf->limit_xml_body > AP_MAX_LIMIT_XML_BODY) |
3902 | 0 | return apr_psprintf(cmd->pool, "LimitXMLRequestBody must not exceed " |
3903 | 0 | "%" APR_SIZE_T_FMT, AP_MAX_LIMIT_XML_BODY); |
3904 | | |
3905 | 0 | return NULL; |
3906 | 0 | } |
3907 | | |
3908 | | static const char *set_max_ranges(cmd_parms *cmd, void *conf_, const char *arg) |
3909 | 0 | { |
3910 | 0 | core_dir_config *conf = conf_; |
3911 | 0 | int val = 0; |
3912 | |
|
3913 | 0 | if (!ap_cstr_casecmp(arg, "none")) { |
3914 | 0 | val = AP_MAXRANGES_NORANGES; |
3915 | 0 | } |
3916 | 0 | else if (!ap_cstr_casecmp(arg, "default")) { |
3917 | 0 | val = AP_MAXRANGES_DEFAULT; |
3918 | 0 | } |
3919 | 0 | else if (!ap_cstr_casecmp(arg, "unlimited")) { |
3920 | 0 | val = AP_MAXRANGES_UNLIMITED; |
3921 | 0 | } |
3922 | 0 | else { |
3923 | 0 | val = atoi(arg); |
3924 | 0 | if (val <= 0) |
3925 | 0 | return "MaxRanges requires 'none', 'default', 'unlimited' or " |
3926 | 0 | "a positive integer"; |
3927 | 0 | } |
3928 | | |
3929 | 0 | conf->max_ranges = val; |
3930 | |
|
3931 | 0 | return NULL; |
3932 | 0 | } |
3933 | | |
3934 | | static const char *set_max_overlaps(cmd_parms *cmd, void *conf_, const char *arg) |
3935 | 0 | { |
3936 | 0 | core_dir_config *conf = conf_; |
3937 | 0 | int val = 0; |
3938 | |
|
3939 | 0 | if (!ap_cstr_casecmp(arg, "none")) { |
3940 | 0 | val = AP_MAXRANGES_NORANGES; |
3941 | 0 | } |
3942 | 0 | else if (!ap_cstr_casecmp(arg, "default")) { |
3943 | 0 | val = AP_MAXRANGES_DEFAULT; |
3944 | 0 | } |
3945 | 0 | else if (!ap_cstr_casecmp(arg, "unlimited")) { |
3946 | 0 | val = AP_MAXRANGES_UNLIMITED; |
3947 | 0 | } |
3948 | 0 | else { |
3949 | 0 | val = atoi(arg); |
3950 | 0 | if (val <= 0) |
3951 | 0 | return "MaxRangeOverlaps requires 'none', 'default', 'unlimited' or " |
3952 | 0 | "a positive integer"; |
3953 | 0 | } |
3954 | | |
3955 | 0 | conf->max_overlaps = val; |
3956 | |
|
3957 | 0 | return NULL; |
3958 | 0 | } |
3959 | | |
3960 | | static const char *set_max_reversals(cmd_parms *cmd, void *conf_, const char *arg) |
3961 | 0 | { |
3962 | 0 | core_dir_config *conf = conf_; |
3963 | 0 | int val = 0; |
3964 | |
|
3965 | 0 | if (!ap_cstr_casecmp(arg, "none")) { |
3966 | 0 | val = AP_MAXRANGES_NORANGES; |
3967 | 0 | } |
3968 | 0 | else if (!ap_cstr_casecmp(arg, "default")) { |
3969 | 0 | val = AP_MAXRANGES_DEFAULT; |
3970 | 0 | } |
3971 | 0 | else if (!ap_cstr_casecmp(arg, "unlimited")) { |
3972 | 0 | val = AP_MAXRANGES_UNLIMITED; |
3973 | 0 | } |
3974 | 0 | else { |
3975 | 0 | val = atoi(arg); |
3976 | 0 | if (val <= 0) |
3977 | 0 | return "MaxRangeReversals requires 'none', 'default', 'unlimited' or " |
3978 | 0 | "a positive integer"; |
3979 | 0 | } |
3980 | | |
3981 | 0 | conf->max_reversals = val; |
3982 | |
|
3983 | 0 | return NULL; |
3984 | 0 | } |
3985 | | |
3986 | | AP_DECLARE(apr_size_t) ap_get_limit_xml_body(const request_rec *r) |
3987 | 0 | { |
3988 | 0 | core_dir_config *conf; |
3989 | |
|
3990 | 0 | conf = ap_get_core_module_config(r->per_dir_config); |
3991 | 0 | if (conf->limit_xml_body == AP_LIMIT_UNSET) |
3992 | 0 | return AP_DEFAULT_LIMIT_XML_BODY; |
3993 | 0 | if (conf->limit_xml_body == 0) |
3994 | 0 | return AP_MAX_LIMIT_XML_BODY; |
3995 | | |
3996 | 0 | return (apr_size_t)conf->limit_xml_body; |
3997 | 0 | } |
3998 | | |
3999 | | #if !defined (RLIMIT_CPU) || !(defined (RLIMIT_DATA) || defined (RLIMIT_VMEM) || defined(RLIMIT_AS)) || !defined (RLIMIT_NPROC) |
4000 | | static const char *no_set_limit(cmd_parms *cmd, void *conf_, |
4001 | | const char *arg, const char *arg2) |
4002 | | { |
4003 | | ap_log_error(APLOG_MARK, APLOG_ERR, 0, cmd->server, APLOGNO(00118) |
4004 | | "%s not supported on this platform", cmd->cmd->name); |
4005 | | |
4006 | | return NULL; |
4007 | | } |
4008 | | #endif |
4009 | | |
4010 | | #ifdef RLIMIT_CPU |
4011 | | static const char *set_limit_cpu(cmd_parms *cmd, void *conf_, |
4012 | | const char *arg, const char *arg2) |
4013 | 0 | { |
4014 | 0 | core_dir_config *conf = conf_; |
4015 | |
|
4016 | 0 | ap_unixd_set_rlimit(cmd, &conf->limit_cpu, arg, arg2, RLIMIT_CPU); |
4017 | 0 | return NULL; |
4018 | 0 | } |
4019 | | #endif |
4020 | | |
4021 | | #if defined (RLIMIT_DATA) || defined (RLIMIT_VMEM) || defined(RLIMIT_AS) |
4022 | | static const char *set_limit_mem(cmd_parms *cmd, void *conf_, |
4023 | | const char *arg, const char * arg2) |
4024 | 0 | { |
4025 | 0 | core_dir_config *conf = conf_; |
4026 | |
|
4027 | 0 | #if defined(RLIMIT_AS) |
4028 | 0 | ap_unixd_set_rlimit(cmd, &conf->limit_mem, arg, arg2 ,RLIMIT_AS); |
4029 | | #elif defined(RLIMIT_DATA) |
4030 | | ap_unixd_set_rlimit(cmd, &conf->limit_mem, arg, arg2, RLIMIT_DATA); |
4031 | | #elif defined(RLIMIT_VMEM) |
4032 | | ap_unixd_set_rlimit(cmd, &conf->limit_mem, arg, arg2, RLIMIT_VMEM); |
4033 | | #endif |
4034 | |
|
4035 | 0 | return NULL; |
4036 | 0 | } |
4037 | | #endif |
4038 | | |
4039 | | #ifdef RLIMIT_NPROC |
4040 | | static const char *set_limit_nproc(cmd_parms *cmd, void *conf_, |
4041 | | const char *arg, const char * arg2) |
4042 | 0 | { |
4043 | 0 | core_dir_config *conf = conf_; |
4044 | |
|
4045 | 0 | ap_unixd_set_rlimit(cmd, &conf->limit_nproc, arg, arg2, RLIMIT_NPROC); |
4046 | 0 | return NULL; |
4047 | 0 | } |
4048 | | #endif |
4049 | | |
4050 | | static const char *set_recursion_limit(cmd_parms *cmd, void *dummy, |
4051 | | const char *arg1, const char *arg2) |
4052 | 0 | { |
4053 | 0 | core_server_config *conf = |
4054 | 0 | ap_get_core_module_config(cmd->server->module_config); |
4055 | 0 | int limit = atoi(arg1); |
4056 | |
|
4057 | 0 | if (limit <= 0) { |
4058 | 0 | return "The recursion limit must be greater than zero."; |
4059 | 0 | } |
4060 | 0 | if (limit < 4) { |
4061 | 0 | ap_log_error(APLOG_MARK, APLOG_WARNING, 0, cmd->server, APLOGNO(00119) |
4062 | 0 | "Limiting internal redirects to very low numbers may " |
4063 | 0 | "cause normal requests to fail."); |
4064 | 0 | } |
4065 | |
|
4066 | 0 | conf->redirect_limit = limit; |
4067 | |
|
4068 | 0 | if (arg2) { |
4069 | 0 | limit = atoi(arg2); |
4070 | |
|
4071 | 0 | if (limit <= 0) { |
4072 | 0 | return "The recursion limit must be greater than zero."; |
4073 | 0 | } |
4074 | 0 | if (limit < 4) { |
4075 | 0 | ap_log_error(APLOG_MARK, APLOG_WARNING, 0, cmd->server, APLOGNO(00120) |
4076 | 0 | "Limiting the subrequest depth to a very low level may" |
4077 | 0 | " cause normal requests to fail."); |
4078 | 0 | } |
4079 | 0 | } |
4080 | | |
4081 | 0 | conf->subreq_limit = limit; |
4082 | |
|
4083 | 0 | return NULL; |
4084 | 0 | } |
4085 | | |
4086 | | static void log_backtrace(const request_rec *r) |
4087 | 0 | { |
4088 | 0 | if (APLOGrdebug(r)) { |
4089 | 0 | const request_rec *top = r; |
4090 | |
|
4091 | 0 | ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00121) |
4092 | 0 | "r->uri = %s", r->uri ? r->uri : "(unexpectedly NULL)"); |
4093 | |
|
4094 | 0 | while (top && (top->prev || top->main)) { |
4095 | 0 | if (top->prev) { |
4096 | 0 | top = top->prev; |
4097 | 0 | ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00122) |
4098 | 0 | "redirected from r->uri = %s", |
4099 | 0 | top->uri ? top->uri : "(unexpectedly NULL)"); |
4100 | 0 | } |
4101 | |
|
4102 | 0 | if (!top->prev && top->main) { |
4103 | 0 | top = top->main; |
4104 | 0 | ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00123) |
4105 | 0 | "subrequested from r->uri = %s", |
4106 | 0 | top->uri ? top->uri : "(unexpectedly NULL)"); |
4107 | 0 | } |
4108 | 0 | } |
4109 | 0 | } |
4110 | 0 | } |
4111 | | |
4112 | | /* |
4113 | | * check whether redirect limit is reached |
4114 | | */ |
4115 | | AP_DECLARE(int) ap_is_recursion_limit_exceeded(const request_rec *r) |
4116 | 0 | { |
4117 | 0 | core_server_config *conf = |
4118 | 0 | ap_get_core_module_config(r->server->module_config); |
4119 | 0 | const request_rec *top = r; |
4120 | 0 | int redirects = 0, subreqs = 0; |
4121 | 0 | int rlimit = conf->redirect_limit |
4122 | 0 | ? conf->redirect_limit |
4123 | 0 | : AP_DEFAULT_MAX_INTERNAL_REDIRECTS; |
4124 | 0 | int slimit = conf->subreq_limit |
4125 | 0 | ? conf->subreq_limit |
4126 | 0 | : AP_DEFAULT_MAX_SUBREQ_DEPTH; |
4127 | | |
4128 | |
|
4129 | 0 | while (top->prev || top->main) { |
4130 | 0 | if (top->prev) { |
4131 | 0 | if (++redirects >= rlimit) { |
4132 | | /* uuh, too much. */ |
4133 | | /* As we check before a new internal redirect, top->prev->uri |
4134 | | * should be the original request causing this. |
4135 | | */ |
4136 | 0 | ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00124) |
4137 | 0 | "Request (%s) exceeded the limit of %d internal " |
4138 | 0 | "redirects due to probable configuration error. " |
4139 | 0 | "Use 'LimitInternalRecursion' to increase the " |
4140 | 0 | "limit if necessary. Use 'LogLevel debug' to get " |
4141 | 0 | "a backtrace.", top->prev->uri, rlimit); |
4142 | | |
4143 | | /* post backtrace */ |
4144 | 0 | log_backtrace(r); |
4145 | | |
4146 | | /* return failure */ |
4147 | 0 | return 1; |
4148 | 0 | } |
4149 | | |
4150 | 0 | top = top->prev; |
4151 | 0 | } |
4152 | | |
4153 | 0 | if (!top->prev && top->main) { |
4154 | 0 | if (++subreqs >= slimit) { |
4155 | | /* uuh, too much. */ |
4156 | | /* As we check before a new subrequest, top->main->uri should |
4157 | | * be the original request causing this. |
4158 | | */ |
4159 | 0 | ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00125) |
4160 | 0 | "Request (%s) exceeded the limit of %d subrequest " |
4161 | 0 | "nesting levels due to probable configuration " |
4162 | 0 | "error. Use 'LimitInternalRecursion' to increase " |
4163 | 0 | "the limit if necessary. Use 'LogLevel debug' to " |
4164 | 0 | "get a backtrace.", top->main->uri, slimit); |
4165 | | |
4166 | | /* post backtrace */ |
4167 | 0 | log_backtrace(r); |
4168 | | |
4169 | | /* return failure */ |
4170 | 0 | return 1; |
4171 | 0 | } |
4172 | | |
4173 | 0 | top = top->main; |
4174 | 0 | } |
4175 | 0 | } |
4176 | | |
4177 | | /* recursion state: ok */ |
4178 | 0 | return 0; |
4179 | 0 | } |
4180 | | |
4181 | | static const char *set_trace_enable(cmd_parms *cmd, void *dummy, |
4182 | | const char *arg1) |
4183 | 0 | { |
4184 | 0 | core_server_config *conf = |
4185 | 0 | ap_get_core_module_config(cmd->server->module_config); |
4186 | |
|
4187 | 0 | if (ap_cstr_casecmp(arg1, "on") == 0) { |
4188 | 0 | conf->trace_enable = AP_TRACE_ENABLE; |
4189 | 0 | } |
4190 | 0 | else if (ap_cstr_casecmp(arg1, "off") == 0) { |
4191 | 0 | conf->trace_enable = AP_TRACE_DISABLE; |
4192 | 0 | } |
4193 | 0 | else if (ap_cstr_casecmp(arg1, "extended") == 0) { |
4194 | 0 | conf->trace_enable = AP_TRACE_EXTENDED; |
4195 | 0 | } |
4196 | 0 | else { |
4197 | 0 | return "TraceEnable must be one of 'on', 'off', or 'extended'"; |
4198 | 0 | } |
4199 | | |
4200 | 0 | return NULL; |
4201 | 0 | } |
4202 | | |
4203 | | static const char *set_protocols(cmd_parms *cmd, void *dummy, |
4204 | | const char *arg) |
4205 | 0 | { |
4206 | 0 | core_server_config *conf = |
4207 | 0 | ap_get_core_module_config(cmd->server->module_config); |
4208 | 0 | const char **np; |
4209 | 0 | const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); |
4210 | |
|
4211 | 0 | if (err) { |
4212 | 0 | return err; |
4213 | 0 | } |
4214 | | |
4215 | 0 | np = (const char **)apr_array_push(conf->protocols); |
4216 | 0 | *np = arg; |
4217 | |
|
4218 | 0 | return NULL; |
4219 | 0 | } |
4220 | | |
4221 | | static const char *set_protocols_honor_order(cmd_parms *cmd, void *dummy, |
4222 | | const char *arg) |
4223 | 0 | { |
4224 | 0 | core_server_config *conf = |
4225 | 0 | ap_get_core_module_config(cmd->server->module_config); |
4226 | 0 | const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); |
4227 | | |
4228 | 0 | if (err) { |
4229 | 0 | return err; |
4230 | 0 | } |
4231 | | |
4232 | 0 | if (ap_cstr_casecmp(arg, "on") == 0) { |
4233 | 0 | conf->protocols_honor_order = 1; |
4234 | 0 | } |
4235 | 0 | else if (ap_cstr_casecmp(arg, "off") == 0) { |
4236 | 0 | conf->protocols_honor_order = 0; |
4237 | 0 | } |
4238 | 0 | else { |
4239 | 0 | return "ProtocolsHonorOrder must be 'on' or 'off'"; |
4240 | 0 | } |
4241 | | |
4242 | 0 | return NULL; |
4243 | 0 | } |
4244 | | |
4245 | | static const char *set_http_protocol_options(cmd_parms *cmd, void *dummy, |
4246 | | const char *arg) |
4247 | 0 | { |
4248 | 0 | core_server_config *conf = |
4249 | 0 | ap_get_core_module_config(cmd->server->module_config); |
4250 | |
|
4251 | 0 | if (strcasecmp(arg, "allow0.9") == 0) |
4252 | 0 | conf->http09_enable |= AP_HTTP09_ENABLE; |
4253 | 0 | else if (strcasecmp(arg, "require1.0") == 0) |
4254 | 0 | conf->http09_enable |= AP_HTTP09_DISABLE; |
4255 | 0 | else if (strcasecmp(arg, "strict") == 0) |
4256 | 0 | conf->http_conformance |= AP_HTTP_CONFORMANCE_STRICT; |
4257 | 0 | else if (strcasecmp(arg, "unsafe") == 0) |
4258 | 0 | conf->http_conformance |= AP_HTTP_CONFORMANCE_UNSAFE; |
4259 | 0 | else if (strcasecmp(arg, "registeredmethods") == 0) |
4260 | 0 | conf->http_methods |= AP_HTTP_METHODS_REGISTERED; |
4261 | 0 | else if (strcasecmp(arg, "lenientmethods") == 0) |
4262 | 0 | conf->http_methods |= AP_HTTP_METHODS_LENIENT; |
4263 | 0 | else |
4264 | 0 | return "HttpProtocolOptions accepts " |
4265 | 0 | "'Unsafe' or 'Strict' (default), " |
4266 | 0 | "'RegisteredMethods' or 'LenientMethods' (default), and " |
4267 | 0 | "'Require1.0' or 'Allow0.9' (default)"; |
4268 | | |
4269 | 0 | if ((conf->http09_enable & AP_HTTP09_ENABLE) |
4270 | 0 | && (conf->http09_enable & AP_HTTP09_DISABLE)) |
4271 | 0 | return "HttpProtocolOptions 'Allow0.9' and 'Require1.0'" |
4272 | 0 | " are mutually exclusive"; |
4273 | | |
4274 | 0 | if ((conf->http_conformance & AP_HTTP_CONFORMANCE_STRICT) |
4275 | 0 | && (conf->http_conformance & AP_HTTP_CONFORMANCE_UNSAFE)) |
4276 | 0 | return "HttpProtocolOptions 'Strict' and 'Unsafe'" |
4277 | 0 | " are mutually exclusive"; |
4278 | | |
4279 | 0 | if ((conf->http_methods & AP_HTTP_METHODS_REGISTERED) |
4280 | 0 | && (conf->http_methods & AP_HTTP_METHODS_LENIENT)) |
4281 | 0 | return "HttpProtocolOptions 'RegisteredMethods' and 'LenientMethods'" |
4282 | 0 | " are mutually exclusive"; |
4283 | | |
4284 | 0 | return NULL; |
4285 | 0 | } |
4286 | | |
4287 | | static const char *set_async_filter(cmd_parms *cmd, void *dummy, |
4288 | | const char *arg) |
4289 | 0 | { |
4290 | 0 | core_server_config *conf = |
4291 | 0 | ap_get_core_module_config(cmd->server->module_config); |
4292 | 0 | const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); |
4293 | |
|
4294 | 0 | if (err) { |
4295 | 0 | return err; |
4296 | 0 | } |
4297 | | |
4298 | 0 | if (ap_cstr_casecmp(arg, "network") == 0) { |
4299 | 0 | conf->async_filter = AP_FTYPE_NETWORK; |
4300 | 0 | } |
4301 | 0 | else if (ap_cstr_casecmp(arg, "connection") == 0) { |
4302 | 0 | conf->async_filter = AP_FTYPE_CONNECTION; |
4303 | 0 | } |
4304 | 0 | else if (ap_cstr_casecmp(arg, "request") == 0) { |
4305 | 0 | conf->async_filter = 0; |
4306 | 0 | } |
4307 | 0 | else { |
4308 | 0 | return "AsyncFilter must be 'network', 'connection' or 'request'"; |
4309 | 0 | } |
4310 | 0 | conf->async_filter_set = 1; |
4311 | |
|
4312 | 0 | return NULL; |
4313 | 0 | } |
4314 | | |
4315 | | static const char *set_http_method(cmd_parms *cmd, void *conf, const char *arg) |
4316 | 0 | { |
4317 | 0 | const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); |
4318 | 0 | if (err != NULL) |
4319 | 0 | return err; |
4320 | 0 | ap_method_register(cmd->pool, arg); |
4321 | 0 | return NULL; |
4322 | 0 | } |
4323 | | |
4324 | | static const char *set_cl_head_zero(cmd_parms *cmd, void *dummy, int arg) |
4325 | 0 | { |
4326 | 0 | core_server_config *conf = |
4327 | 0 | ap_get_core_module_config(cmd->server->module_config); |
4328 | |
|
4329 | 0 | if (arg) { |
4330 | 0 | conf->http_cl_head_zero = AP_HTTP_CL_HEAD_ZERO_ENABLE; |
4331 | 0 | } else { |
4332 | 0 | conf->http_cl_head_zero = AP_HTTP_CL_HEAD_ZERO_DISABLE; |
4333 | 0 | } |
4334 | 0 | return NULL; |
4335 | 0 | } |
4336 | | |
4337 | | static const char *set_expect_strict(cmd_parms *cmd, void *dummy, int arg) |
4338 | 0 | { |
4339 | 0 | core_server_config *conf = |
4340 | 0 | ap_get_core_module_config(cmd->server->module_config); |
4341 | |
|
4342 | 0 | if (arg) { |
4343 | 0 | conf->http_expect_strict = AP_HTTP_EXPECT_STRICT_ENABLE; |
4344 | 0 | } else { |
4345 | 0 | conf->http_expect_strict = AP_HTTP_EXPECT_STRICT_DISABLE; |
4346 | 0 | } |
4347 | 0 | return NULL; |
4348 | 0 | } |
4349 | | |
4350 | | static apr_hash_t *errorlog_hash; |
4351 | | |
4352 | | static int log_constant_item(const ap_errorlog_info *info, const char *arg, |
4353 | | char *buf, int buflen) |
4354 | 0 | { |
4355 | 0 | char *end = apr_cpystrn(buf, arg, buflen); |
4356 | 0 | return end - buf; |
4357 | 0 | } |
4358 | | |
4359 | | static char *parse_errorlog_misc_string(apr_pool_t *p, |
4360 | | ap_errorlog_format_item *it, |
4361 | | const char **sa) |
4362 | 0 | { |
4363 | 0 | const char *s; |
4364 | 0 | char scratch[MAX_STRING_LEN]; |
4365 | 0 | char *d = scratch; |
4366 | | /* |
4367 | | * non-leading white space terminates this string to allow the next field |
4368 | | * separator to be inserted |
4369 | | */ |
4370 | 0 | int at_start = 1; |
4371 | |
|
4372 | 0 | it->func = log_constant_item; |
4373 | 0 | s = *sa; |
4374 | |
|
4375 | 0 | while (*s && *s != '%' && (*s != ' ' || at_start) && d < scratch + MAX_STRING_LEN) { |
4376 | 0 | if (*s != '\\') { |
4377 | 0 | if (*s != ' ') { |
4378 | 0 | at_start = 0; |
4379 | 0 | } |
4380 | 0 | *d++ = *s++; |
4381 | 0 | } |
4382 | 0 | else { |
4383 | 0 | s++; |
4384 | 0 | switch (*s) { |
4385 | 0 | case 'r': |
4386 | 0 | *d++ = '\r'; |
4387 | 0 | s++; |
4388 | 0 | break; |
4389 | 0 | case 'n': |
4390 | 0 | *d++ = '\n'; |
4391 | 0 | s++; |
4392 | 0 | break; |
4393 | 0 | case 't': |
4394 | 0 | *d++ = '\t'; |
4395 | 0 | s++; |
4396 | 0 | break; |
4397 | 0 | case '\0': |
4398 | | /* handle end of string */ |
4399 | 0 | *d++ = '\\'; |
4400 | 0 | break; |
4401 | 0 | default: |
4402 | | /* copy next char verbatim */ |
4403 | 0 | *d++ = *s++; |
4404 | 0 | break; |
4405 | 0 | } |
4406 | 0 | } |
4407 | 0 | } |
4408 | 0 | *d = '\0'; |
4409 | 0 | it->arg = apr_pstrdup(p, scratch); |
4410 | |
|
4411 | 0 | *sa = s; |
4412 | 0 | return NULL; |
4413 | 0 | } |
4414 | | |
4415 | | static char *parse_errorlog_item(apr_pool_t *p, ap_errorlog_format_item *it, |
4416 | | const char **sa) |
4417 | 0 | { |
4418 | 0 | const char *s = *sa; |
4419 | 0 | ap_errorlog_handler *handler; |
4420 | 0 | int i; |
4421 | |
|
4422 | 0 | if (*s != '%') { |
4423 | 0 | if (*s == ' ') { |
4424 | 0 | it->flags |= AP_ERRORLOG_FLAG_FIELD_SEP; |
4425 | 0 | } |
4426 | 0 | return parse_errorlog_misc_string(p, it, sa); |
4427 | 0 | } |
4428 | | |
4429 | 0 | ++s; |
4430 | |
|
4431 | 0 | if (*s == ' ') { |
4432 | | /* percent-space (% ) is a field separator */ |
4433 | 0 | it->flags |= AP_ERRORLOG_FLAG_FIELD_SEP; |
4434 | 0 | *sa = ++s; |
4435 | | /* recurse */ |
4436 | 0 | return parse_errorlog_item(p, it, sa); |
4437 | 0 | } |
4438 | 0 | else if (*s == '%') { |
4439 | 0 | it->arg = "%"; |
4440 | 0 | it->func = log_constant_item; |
4441 | 0 | *sa = ++s; |
4442 | 0 | return NULL; |
4443 | 0 | } |
4444 | | |
4445 | 0 | while (*s) { |
4446 | 0 | switch (*s) { |
4447 | 0 | case '{': |
4448 | 0 | ++s; |
4449 | 0 | it->arg = ap_getword(p, &s, '}'); |
4450 | 0 | break; |
4451 | 0 | case '+': |
4452 | 0 | ++s; |
4453 | 0 | it->flags |= AP_ERRORLOG_FLAG_REQUIRED; |
4454 | 0 | break; |
4455 | 0 | case '-': |
4456 | 0 | ++s; |
4457 | 0 | it->flags |= AP_ERRORLOG_FLAG_NULL_AS_HYPHEN; |
4458 | 0 | break; |
4459 | 0 | case '0': |
4460 | 0 | case '1': |
4461 | 0 | case '2': |
4462 | 0 | case '3': |
4463 | 0 | case '4': |
4464 | 0 | case '5': |
4465 | 0 | case '6': |
4466 | 0 | case '7': |
4467 | 0 | case '8': |
4468 | 0 | case '9': |
4469 | 0 | i = *s - '0'; |
4470 | 0 | while (apr_isdigit(*++s)) |
4471 | 0 | i = i * 10 + (*s) - '0'; |
4472 | 0 | it->min_loglevel = i; |
4473 | 0 | break; |
4474 | 0 | case 'M': |
4475 | 0 | it->func = NULL; |
4476 | 0 | it->flags |= AP_ERRORLOG_FLAG_MESSAGE; |
4477 | 0 | *sa = ++s; |
4478 | 0 | return NULL; |
4479 | 0 | default: |
4480 | 0 | handler = (ap_errorlog_handler *)apr_hash_get(errorlog_hash, s, 1); |
4481 | 0 | if (!handler) { |
4482 | 0 | char dummy[2]; |
4483 | |
|
4484 | 0 | dummy[0] = *s; |
4485 | 0 | dummy[1] = '\0'; |
4486 | 0 | return apr_pstrcat(p, "Unrecognized error log format directive %", |
4487 | 0 | dummy, NULL); |
4488 | 0 | } |
4489 | 0 | it->func = handler->func; |
4490 | 0 | *sa = ++s; |
4491 | 0 | return NULL; |
4492 | 0 | } |
4493 | 0 | } |
4494 | | |
4495 | 0 | return "Ran off end of error log format parsing args to some directive"; |
4496 | 0 | } |
4497 | | |
4498 | | static apr_array_header_t *parse_errorlog_string(apr_pool_t *p, |
4499 | | const char *s, |
4500 | | const char **err, |
4501 | | int is_main_fmt) |
4502 | 0 | { |
4503 | 0 | apr_array_header_t *a = apr_array_make(p, 30, |
4504 | 0 | sizeof(ap_errorlog_format_item)); |
4505 | 0 | char *res; |
4506 | 0 | int seen_msg_fmt = 0; |
4507 | |
|
4508 | 0 | while (s && *s) { |
4509 | 0 | ap_errorlog_format_item *item = |
4510 | 0 | (ap_errorlog_format_item *)apr_array_push(a); |
4511 | 0 | memset(item, 0, sizeof(*item)); |
4512 | 0 | res = parse_errorlog_item(p, item, &s); |
4513 | 0 | if (res) { |
4514 | 0 | *err = res; |
4515 | 0 | return NULL; |
4516 | 0 | } |
4517 | 0 | if (item->flags & AP_ERRORLOG_FLAG_MESSAGE) { |
4518 | 0 | if (!is_main_fmt) { |
4519 | 0 | *err = "%M cannot be used in once-per-request or " |
4520 | 0 | "once-per-connection formats"; |
4521 | 0 | return NULL; |
4522 | 0 | } |
4523 | 0 | seen_msg_fmt = 1; |
4524 | 0 | } |
4525 | 0 | if (is_main_fmt && item->flags & AP_ERRORLOG_FLAG_REQUIRED) { |
4526 | 0 | *err = "The '+' flag cannot be used in the main error log format"; |
4527 | 0 | return NULL; |
4528 | 0 | } |
4529 | 0 | if (!is_main_fmt && item->min_loglevel) { |
4530 | 0 | *err = "The loglevel cannot be used as a condition in " |
4531 | 0 | "once-per-request or once-per-connection formats"; |
4532 | 0 | return NULL; |
4533 | 0 | } |
4534 | 0 | if (item->min_loglevel > APLOG_TRACE8) { |
4535 | 0 | *err = "The specified loglevel modifier is out of range"; |
4536 | 0 | return NULL; |
4537 | 0 | } |
4538 | 0 | } |
4539 | | |
4540 | 0 | if (is_main_fmt && !seen_msg_fmt) { |
4541 | 0 | *err = "main ErrorLogFormat must contain message format string '%M'"; |
4542 | 0 | return NULL; |
4543 | 0 | } |
4544 | | |
4545 | 0 | return a; |
4546 | 0 | } |
4547 | | |
4548 | | static const char *set_errorlog(cmd_parms *cmd, void *dummy, const char *arg1, |
4549 | | const char *arg2) |
4550 | 0 | { |
4551 | 0 | ap_errorlog_provider *provider; |
4552 | 0 | const char *err; |
4553 | 0 | cmd->server->errorlog_provider = NULL; |
4554 | |
|
4555 | 0 | if (!arg2) { |
4556 | | /* Stay backward compatible and check for "syslog" */ |
4557 | 0 | if (strncmp("syslog", arg1, 6) == 0) { |
4558 | 0 | arg2 = arg1 + 7; /* skip the ':' if any */ |
4559 | 0 | arg1 = "syslog"; |
4560 | 0 | } |
4561 | 0 | else { |
4562 | | /* Admin can define only "ErrorLog provider" and we should |
4563 | | * still handle that using the defined provider, but with empty |
4564 | | * error_fname. */ |
4565 | 0 | provider = ap_lookup_provider(AP_ERRORLOG_PROVIDER_GROUP, arg1, |
4566 | 0 | AP_ERRORLOG_PROVIDER_VERSION); |
4567 | 0 | if (provider) { |
4568 | 0 | arg2 = ""; |
4569 | 0 | } |
4570 | 0 | else { |
4571 | 0 | return set_server_string_slot(cmd, dummy, arg1); |
4572 | 0 | } |
4573 | 0 | } |
4574 | 0 | } |
4575 | | |
4576 | 0 | if (strcmp("file", arg1) == 0) { |
4577 | 0 | return set_server_string_slot(cmd, dummy, arg2); |
4578 | 0 | } |
4579 | | |
4580 | 0 | provider = ap_lookup_provider(AP_ERRORLOG_PROVIDER_GROUP, arg1, |
4581 | 0 | AP_ERRORLOG_PROVIDER_VERSION); |
4582 | 0 | if (!provider) { |
4583 | 0 | return apr_psprintf(cmd->pool, |
4584 | 0 | "Unknown ErrorLog provider: %s", |
4585 | 0 | arg1); |
4586 | 0 | } |
4587 | | |
4588 | 0 | err = provider->parse_errorlog_arg(cmd, arg2); |
4589 | 0 | if (err) { |
4590 | 0 | return err; |
4591 | 0 | } |
4592 | | |
4593 | 0 | cmd->server->errorlog_provider = provider; |
4594 | 0 | return set_server_string_slot(cmd, dummy, arg2); |
4595 | 0 | } |
4596 | | |
4597 | | static const char *set_errorlog_format(cmd_parms *cmd, void *dummy, |
4598 | | const char *arg1, const char *arg2) |
4599 | 0 | { |
4600 | 0 | const char *err_string = NULL; |
4601 | 0 | core_server_config *conf = |
4602 | 0 | ap_get_core_module_config(cmd->server->module_config); |
4603 | |
|
4604 | 0 | if (!arg2) { |
4605 | 0 | conf->error_log_format = parse_errorlog_string(cmd->pool, arg1, |
4606 | 0 | &err_string, 1); |
4607 | 0 | } |
4608 | 0 | else if (!ap_cstr_casecmp(arg1, "connection")) { |
4609 | 0 | if (!conf->error_log_conn) { |
4610 | 0 | conf->error_log_conn = apr_array_make(cmd->pool, 5, |
4611 | 0 | sizeof(apr_array_header_t *)); |
4612 | 0 | } |
4613 | |
|
4614 | 0 | if (*arg2) { |
4615 | 0 | apr_array_header_t **e; |
4616 | 0 | e = (apr_array_header_t **) apr_array_push(conf->error_log_conn); |
4617 | 0 | *e = parse_errorlog_string(cmd->pool, arg2, &err_string, 0); |
4618 | 0 | } |
4619 | 0 | } |
4620 | 0 | else if (!ap_cstr_casecmp(arg1, "request")) { |
4621 | 0 | if (!conf->error_log_req) { |
4622 | 0 | conf->error_log_req = apr_array_make(cmd->pool, 5, |
4623 | 0 | sizeof(apr_array_header_t *)); |
4624 | 0 | } |
4625 | |
|
4626 | 0 | if (*arg2) { |
4627 | 0 | apr_array_header_t **e; |
4628 | 0 | e = (apr_array_header_t **) apr_array_push(conf->error_log_req); |
4629 | 0 | *e = parse_errorlog_string(cmd->pool, arg2, &err_string, 0); |
4630 | 0 | } |
4631 | 0 | } |
4632 | 0 | else { |
4633 | 0 | err_string = "ErrorLogFormat type must be one of request, connection"; |
4634 | 0 | } |
4635 | |
|
4636 | 0 | return err_string; |
4637 | 0 | } |
4638 | | |
4639 | | AP_DECLARE(void) ap_register_errorlog_handler(apr_pool_t *p, char *tag, |
4640 | | ap_errorlog_handler_fn_t *handler, |
4641 | | int flags) |
4642 | 0 | { |
4643 | 0 | ap_errorlog_handler *log_struct = apr_palloc(p, sizeof(*log_struct)); |
4644 | 0 | log_struct->func = handler; |
4645 | 0 | log_struct->flags = flags; |
4646 | |
|
4647 | 0 | apr_hash_set(errorlog_hash, tag, 1, (const void *)log_struct); |
4648 | 0 | } |
4649 | | |
4650 | | |
4651 | | static const char *set_merge_trailers(cmd_parms *cmd, void *dummy, int arg) |
4652 | 0 | { |
4653 | 0 | core_server_config *conf = ap_get_module_config(cmd->server->module_config, |
4654 | 0 | &core_module); |
4655 | 0 | conf->merge_trailers = (arg ? AP_MERGE_TRAILERS_ENABLE : |
4656 | 0 | AP_MERGE_TRAILERS_DISABLE); |
4657 | |
|
4658 | 0 | return NULL; |
4659 | 0 | } |
4660 | | |
4661 | | /* Note --- ErrorDocument will now work from .htaccess files. |
4662 | | * The AllowOverride of Fileinfo allows webmasters to turn it off |
4663 | | */ |
4664 | | |
4665 | | static const command_rec core_cmds[] = { |
4666 | | |
4667 | | /* Old access config file commands */ |
4668 | | |
4669 | | AP_INIT_RAW_ARGS("<Directory", dirsection, NULL, RSRC_CONF, |
4670 | | "Container for directives affecting resources located in the specified " |
4671 | | "directories"), |
4672 | | AP_INIT_RAW_ARGS("<Location", urlsection, NULL, RSRC_CONF, |
4673 | | "Container for directives affecting resources accessed through the " |
4674 | | "specified URL paths"), |
4675 | | AP_INIT_RAW_ARGS("<VirtualHost", virtualhost_section, NULL, RSRC_CONF, |
4676 | | "Container to map directives to a particular virtual host, takes one or " |
4677 | | "more host addresses"), |
4678 | | AP_INIT_RAW_ARGS("<Files", filesection, NULL, OR_ALL, |
4679 | | "Container for directives affecting files matching specified patterns"), |
4680 | | AP_INIT_RAW_ARGS("<Limit", ap_limit_section, NULL, OR_LIMIT | OR_AUTHCFG, |
4681 | | "Container for authentication directives when accessed using specified HTTP " |
4682 | | "methods"), |
4683 | | AP_INIT_RAW_ARGS("<LimitExcept", ap_limit_section, (void*)1, |
4684 | | OR_LIMIT | OR_AUTHCFG, |
4685 | | "Container for authentication directives to be applied when any HTTP " |
4686 | | "method other than those specified is used to access the resource"), |
4687 | | AP_INIT_RAW_ARGS("<IfModule", start_cond_section, (void *)test_ifmod_section, |
4688 | | EXEC_ON_READ | OR_ALL, |
4689 | | "Container for directives based on existence of specified modules"), |
4690 | | AP_INIT_RAW_ARGS("<IfDefine", start_cond_section, (void *)test_ifdefine_section, |
4691 | | EXEC_ON_READ | OR_ALL, |
4692 | | "Container for directives based on existence of command line defines"), |
4693 | | AP_INIT_RAW_ARGS("<IfFile", start_cond_section, (void *)test_iffile_section, |
4694 | | EXEC_ON_READ | OR_ALL, |
4695 | | "Container for directives based on existence of files on disk"), |
4696 | | AP_INIT_RAW_ARGS("<IfDirective", start_cond_section, (void *)test_ifdirective_section, |
4697 | | EXEC_ON_READ | OR_ALL, |
4698 | | "Container for directives based on existence of named directive"), |
4699 | | AP_INIT_RAW_ARGS("<IfSection", start_cond_section, (void *)test_ifsection_section, |
4700 | | EXEC_ON_READ | OR_ALL, |
4701 | | "Container for directives based on existence of named section"), |
4702 | | AP_INIT_RAW_ARGS("<DirectoryMatch", dirsection, (void*)1, RSRC_CONF, |
4703 | | "Container for directives affecting resources located in the " |
4704 | | "specified directories"), |
4705 | | AP_INIT_RAW_ARGS("<LocationMatch", urlsection, (void*)1, RSRC_CONF, |
4706 | | "Container for directives affecting resources accessed through the " |
4707 | | "specified URL paths"), |
4708 | | AP_INIT_RAW_ARGS("<FilesMatch", filesection, (void*)1, OR_ALL, |
4709 | | "Container for directives affecting files matching specified patterns"), |
4710 | | #ifdef GPROF |
4711 | | AP_INIT_TAKE1("GprofDir", set_gprof_dir, NULL, RSRC_CONF, |
4712 | | "Directory to plop gmon.out files"), |
4713 | | #endif |
4714 | | AP_INIT_TAKE1("AddDefaultCharset", set_add_default_charset, NULL, OR_FILEINFO, |
4715 | | "The name of the default charset to add to any Content-Type without one or 'Off' to disable"), |
4716 | | AP_INIT_TAKE1("AcceptPathInfo", set_accept_path_info, NULL, OR_FILEINFO, |
4717 | | "Set to on or off for PATH_INFO to be accepted by handlers, or default for the per-handler preference"), |
4718 | | AP_INIT_TAKE12("Define", set_define, NULL, EXEC_ON_READ|RSRC_CONF, |
4719 | | "Define a variable, optionally to a value. Same as passing -D to the command line."), |
4720 | | AP_INIT_TAKE1("UnDefine", unset_define, NULL, EXEC_ON_READ|RSRC_CONF, |
4721 | | "Undefine the existence of a variable. Undo a Define."), |
4722 | | AP_INIT_RAW_ARGS("Error", generate_message, (void*) APLOG_ERR, OR_ALL, |
4723 | | "Generate error message from within configuration."), |
4724 | | AP_INIT_RAW_ARGS("Warning", generate_message, (void*) APLOG_WARNING, OR_ALL, |
4725 | | "Generate warning message from within configuration."), |
4726 | | AP_INIT_RAW_ARGS("<If", ifsection, COND_IF, OR_ALL, |
4727 | | "Container for directives to be conditionally applied"), |
4728 | | AP_INIT_RAW_ARGS("<ElseIf", ifsection, COND_ELSEIF, OR_ALL, |
4729 | | "Container for directives to be conditionally applied"), |
4730 | | AP_INIT_RAW_ARGS("<Else", ifsection, COND_ELSE, OR_ALL, |
4731 | | "Container for directives to be conditionally applied"), |
4732 | | |
4733 | | /* Old resource config file commands */ |
4734 | | |
4735 | | AP_INIT_RAW_ARGS("AccessFileName", set_access_name, NULL, RSRC_CONF, |
4736 | | "Name(s) of per-directory config files (default: .htaccess)"), |
4737 | | AP_INIT_TAKE1("DocumentRoot", set_document_root, NULL, RSRC_CONF, |
4738 | | "Root directory of the document tree"), |
4739 | | AP_INIT_TAKE2("ErrorDocument", set_error_document, NULL, OR_FILEINFO, |
4740 | | "Change responses for HTTP errors"), |
4741 | | AP_INIT_RAW_ARGS("AllowOverride", set_override, NULL, ACCESS_CONF, |
4742 | | "Controls what groups of directives can be configured by per-directory " |
4743 | | "config files"), |
4744 | | AP_INIT_TAKE_ARGV("AllowOverrideList", set_override_list, NULL, ACCESS_CONF, |
4745 | | "Controls what individual directives can be configured by per-directory " |
4746 | | "config files"), |
4747 | | AP_INIT_RAW_ARGS("Options", set_options, NULL, OR_OPTIONS, |
4748 | | "Set a number of attributes for a given directory"), |
4749 | | AP_INIT_TAKE1("DefaultType", set_default_type, NULL, OR_FILEINFO, |
4750 | | "the default media type for otherwise untyped files (DEPRECATED)"), |
4751 | | AP_INIT_RAW_ARGS("FileETag", set_etag_bits, NULL, OR_FILEINFO, |
4752 | | "Specify components used to construct a file's ETag"), |
4753 | | AP_INIT_TAKE1("EnableMMAP", set_enable_mmap, NULL, OR_FILEINFO, |
4754 | | "Controls whether memory-mapping may be used to read files"), |
4755 | | AP_INIT_TAKE1("EnableSendfile", set_enable_sendfile, NULL, OR_FILEINFO, |
4756 | | "Controls whether sendfile may be used to transmit files"), |
4757 | | AP_INIT_TAKE1("ReadBufferSize", set_read_buf_size, NULL, ACCESS_CONF|RSRC_CONF, |
4758 | | "Size (in bytes) of the memory buffers used to read data"), |
4759 | | AP_INIT_TAKE1("FlushMaxThreshold", set_flush_max_threshold, NULL, RSRC_CONF, |
4760 | | "Maximum threshold above which pending data are flushed to the network"), |
4761 | | AP_INIT_TAKE1("FlushMaxPipelined", set_flush_max_pipelined, NULL, RSRC_CONF, |
4762 | | "Maximum number of pipelined responses (pending) above which they are " |
4763 | | "flushed to the network"), |
4764 | | |
4765 | | /* Old server config file commands */ |
4766 | | |
4767 | | AP_INIT_TAKE1("Protocol", set_protocol, NULL, RSRC_CONF, |
4768 | | "Set the Protocol for httpd to use."), |
4769 | | AP_INIT_TAKE2("AcceptFilter", set_accf_map, NULL, RSRC_CONF, |
4770 | | "Set the Accept Filter to use for a protocol"), |
4771 | | AP_INIT_TAKE1("Port", ap_set_deprecated, NULL, RSRC_CONF, |
4772 | | "Port was replaced with Listen in Apache 2.0"), |
4773 | | AP_INIT_TAKE1("HostnameLookups", set_hostname_lookups, NULL, |
4774 | | ACCESS_CONF|RSRC_CONF, |
4775 | | "\"on\" to enable, \"off\" to disable reverse DNS lookups, or \"double\" to " |
4776 | | "enable double-reverse DNS lookups"), |
4777 | | AP_INIT_TAKE1("ServerAdmin", set_server_string_slot, |
4778 | | (void *)APR_OFFSETOF(server_rec, server_admin), RSRC_CONF, |
4779 | | "The email address of the server administrator"), |
4780 | | AP_INIT_TAKE1("ServerName", server_hostname_port, NULL, RSRC_CONF, |
4781 | | "The hostname and port of the server"), |
4782 | | AP_INIT_TAKE1("ServerSignature", set_signature_flag, NULL, OR_ALL, |
4783 | | "En-/disable server signature (on|off|email)"), |
4784 | | AP_INIT_TAKE1("ServerRoot", set_server_root, NULL, RSRC_CONF | EXEC_ON_READ, |
4785 | | "Common directory of server-related files (logs, confs, etc.)"), |
4786 | | AP_INIT_TAKE1("DefaultRuntimeDir", set_runtime_dir, NULL, RSRC_CONF | EXEC_ON_READ, |
4787 | | "Common directory for run-time files (shared memory, locks, etc.)"), |
4788 | | AP_INIT_TAKE1("DefaultStateDir", set_state_dir, NULL, RSRC_CONF | EXEC_ON_READ, |
4789 | | "Common directory for persistent state (databases, long-lived caches, etc.)"), |
4790 | | AP_INIT_TAKE12("ErrorLog", set_errorlog, |
4791 | | (void *)APR_OFFSETOF(server_rec, error_fname), RSRC_CONF, |
4792 | | "The filename of the error log"), |
4793 | | AP_INIT_TAKE12("ErrorLogFormat", set_errorlog_format, NULL, RSRC_CONF, |
4794 | | "Format string for the ErrorLog"), |
4795 | | AP_INIT_RAW_ARGS("ServerAlias", set_server_alias, NULL, RSRC_CONF, |
4796 | | "A name or names alternately used to access the server"), |
4797 | | AP_INIT_TAKE1("ServerPath", set_serverpath, NULL, RSRC_CONF, |
4798 | | "The pathname the server can be reached at"), |
4799 | | AP_INIT_TAKE1("Timeout", set_timeout, NULL, RSRC_CONF, |
4800 | | "Timeout duration (sec)"), |
4801 | | AP_INIT_TAKE1("UseCanonicalName", set_use_canonical_name, NULL, |
4802 | | RSRC_CONF|ACCESS_CONF, |
4803 | | "How to work out the ServerName : Port when constructing URLs"), |
4804 | | AP_INIT_TAKE1("UseCanonicalPhysicalPort", set_use_canonical_phys_port, NULL, |
4805 | | RSRC_CONF|ACCESS_CONF, |
4806 | | "Whether to use the physical Port when constructing URLs"), |
4807 | | /* TODO: RlimitFoo should all be part of mod_cgi, not in the core */ |
4808 | | /* TODO: ListenBacklog in MPM */ |
4809 | | AP_INIT_TAKE1("Include", include_config, NULL, |
4810 | | (RSRC_CONF | ACCESS_CONF | EXEC_ON_READ), |
4811 | | "Name(s) of the config file(s) to be included; fails if the wildcard does " |
4812 | | "not match at least one file"), |
4813 | | AP_INIT_TAKE1("IncludeOptional", include_config, (void*)1, |
4814 | | (RSRC_CONF | ACCESS_CONF | EXEC_ON_READ), |
4815 | | "Name or pattern of the config file(s) to be included; ignored if the file " |
4816 | | "does not exist or the pattern does not match any files"), |
4817 | | AP_INIT_ITERATE("LogLevel", set_loglevel, NULL, RSRC_CONF|ACCESS_CONF, |
4818 | | "Level of verbosity in error logging"), |
4819 | | AP_INIT_TAKE_ARGV("LogLevelOverride", set_loglevel_override, NULL, RSRC_CONF, |
4820 | | "Override LogLevel for clients with certain IPs"), |
4821 | | AP_INIT_TAKE1("NameVirtualHost", ap_set_name_virtual_host, NULL, RSRC_CONF, |
4822 | | "A numeric IP address:port, or the name of a host"), |
4823 | | AP_INIT_TAKE1("ServerTokens", set_serv_tokens, NULL, RSRC_CONF, |
4824 | | "Determine tokens displayed in the Server: header - Min(imal), " |
4825 | | "Major, Minor, Prod(uctOnly), OS, or Full"), |
4826 | | AP_INIT_TAKE1("LimitRequestLine", set_limit_req_line, NULL, RSRC_CONF, |
4827 | | "Limit on maximum size of an HTTP request line"), |
4828 | | AP_INIT_TAKE1("LimitRequestFieldsize", set_limit_req_fieldsize, NULL, |
4829 | | RSRC_CONF, |
4830 | | "Limit on maximum size of an HTTP request header field"), |
4831 | | AP_INIT_TAKE1("LimitRequestFields", set_limit_req_fields, NULL, RSRC_CONF, |
4832 | | "Limit (0 = unlimited) on max number of header fields in a request message"), |
4833 | | AP_INIT_TAKE1("LimitRequestBody", set_limit_req_body, |
4834 | | (void*)APR_OFFSETOF(core_dir_config, limit_req_body), OR_ALL, |
4835 | | "Limit (in bytes) on maximum size of request message body"), |
4836 | | AP_INIT_TAKE1("LimitXMLRequestBody", set_limit_xml_req_body, NULL, OR_ALL, |
4837 | | "Limit (in bytes) on maximum size of an XML-based request " |
4838 | | "body"), |
4839 | | AP_INIT_RAW_ARGS("Mutex", ap_set_mutex, NULL, RSRC_CONF, |
4840 | | "mutex (or \"default\") and mechanism"), |
4841 | | |
4842 | | AP_INIT_TAKE1("MaxRanges", set_max_ranges, NULL, RSRC_CONF|ACCESS_CONF, |
4843 | | "Maximum number of Ranges in a request before returning the entire " |
4844 | | "resource, or 0 for unlimited"), |
4845 | | AP_INIT_TAKE1("MaxRangeOverlaps", set_max_overlaps, NULL, RSRC_CONF|ACCESS_CONF, |
4846 | | "Maximum number of overlaps in Ranges in a request before returning the entire " |
4847 | | "resource, or 0 for unlimited"), |
4848 | | AP_INIT_TAKE1("MaxRangeReversals", set_max_reversals, NULL, RSRC_CONF|ACCESS_CONF, |
4849 | | "Maximum number of reversals in Ranges in a request before returning the entire " |
4850 | | "resource, or 0 for unlimited"), |
4851 | | /* System Resource Controls */ |
4852 | | #ifdef RLIMIT_CPU |
4853 | | AP_INIT_TAKE12("RLimitCPU", set_limit_cpu, |
4854 | | (void*)APR_OFFSETOF(core_dir_config, limit_cpu), |
4855 | | OR_ALL, "Soft/hard limits for max CPU usage in seconds"), |
4856 | | #else |
4857 | | AP_INIT_TAKE12("RLimitCPU", no_set_limit, NULL, |
4858 | | OR_ALL, "Soft/hard limits for max CPU usage in seconds"), |
4859 | | #endif |
4860 | | #if defined (RLIMIT_DATA) || defined (RLIMIT_VMEM) || defined (RLIMIT_AS) |
4861 | | AP_INIT_TAKE12("RLimitMEM", set_limit_mem, |
4862 | | (void*)APR_OFFSETOF(core_dir_config, limit_mem), |
4863 | | OR_ALL, "Soft/hard limits for max memory usage per process"), |
4864 | | #else |
4865 | | AP_INIT_TAKE12("RLimitMEM", no_set_limit, NULL, |
4866 | | OR_ALL, "Soft/hard limits for max memory usage per process"), |
4867 | | #endif |
4868 | | #ifdef RLIMIT_NPROC |
4869 | | AP_INIT_TAKE12("RLimitNPROC", set_limit_nproc, |
4870 | | (void*)APR_OFFSETOF(core_dir_config, limit_nproc), |
4871 | | OR_ALL, "soft/hard limits for max number of processes per uid"), |
4872 | | #else |
4873 | | AP_INIT_TAKE12("RLimitNPROC", no_set_limit, NULL, |
4874 | | OR_ALL, "soft/hard limits for max number of processes per uid"), |
4875 | | #endif |
4876 | | |
4877 | | AP_INIT_RAW_ARGS("RegexDefaultOptions", set_regex_default_options, NULL, RSRC_CONF, |
4878 | | "default options for regexes (prefixed by '+' to add, '-' to del)"), |
4879 | | |
4880 | | /* internal recursion stopper */ |
4881 | | AP_INIT_TAKE12("LimitInternalRecursion", set_recursion_limit, NULL, RSRC_CONF, |
4882 | | "maximum recursion depth of internal redirects and subrequests"), |
4883 | | |
4884 | | AP_INIT_FLAG("CGIPassAuth", set_cgi_pass_auth, NULL, OR_AUTHCFG, |
4885 | | "Controls whether HTTP authorization headers, normally hidden, will " |
4886 | | "be passed to scripts"), |
4887 | | AP_INIT_TAKE2("CGIVar", set_cgi_var, NULL, OR_FILEINFO, |
4888 | | "Controls how some CGI variables are set"), |
4889 | | AP_INIT_FLAG("QualifyRedirectURL", set_qualify_redirect_url, NULL, OR_FILEINFO, |
4890 | | "Controls whether the REDIRECT_URL environment variable is fully " |
4891 | | "qualified"), |
4892 | | AP_INIT_FLAG("StrictHostCheck", set_core_server_flag, |
4893 | | (void *)APR_OFFSETOF(core_server_config, strict_host_check), |
4894 | | RSRC_CONF, |
4895 | | "Controls whether a hostname match is required"), |
4896 | | AP_INIT_TAKE1("ForceType", ap_set_string_slot_lower, |
4897 | | (void *)APR_OFFSETOF(core_dir_config, mime_type), OR_FILEINFO, |
4898 | | "a mime type that overrides other configured type"), |
4899 | | AP_INIT_TAKE1("SetHandler", set_sethandler, NULL, OR_FILEINFO, |
4900 | | "a handler name that overrides any other configured handler"), |
4901 | | AP_INIT_TAKE1("SetOutputFilter", ap_set_string_slot, |
4902 | | (void *)APR_OFFSETOF(core_dir_config, output_filters), OR_FILEINFO, |
4903 | | "filter (or ; delimited list of filters) to be run on the request content"), |
4904 | | AP_INIT_TAKE1("SetInputFilter", ap_set_string_slot, |
4905 | | (void *)APR_OFFSETOF(core_dir_config, input_filters), OR_FILEINFO, |
4906 | | "filter (or ; delimited list of filters) to be run on the request body"), |
4907 | | AP_INIT_TAKE1("AllowEncodedSlashes", set_allow2f, NULL, RSRC_CONF, |
4908 | | "Allow URLs containing '/' encoded as '%2F'"), |
4909 | | |
4910 | | /* scoreboard.c directives */ |
4911 | | AP_INIT_TAKE1("ScoreBoardFile", ap_set_scoreboard, NULL, RSRC_CONF, |
4912 | | "A file for Apache to maintain runtime process management information"), |
4913 | | AP_INIT_FLAG("ExtendedStatus", ap_set_extended_status, NULL, RSRC_CONF, |
4914 | | "\"On\" to track extended status information, \"Off\" to disable"), |
4915 | | AP_INIT_FLAG("SeeRequestTail", ap_set_reqtail, NULL, RSRC_CONF, |
4916 | | "For extended status, \"On\" to see the last 63 chars of " |
4917 | | "the request line, \"Off\" (default) to see the first 63"), |
4918 | | |
4919 | | /* |
4920 | | * These are default configuration directives that mpms can/should |
4921 | | * pay attention to. |
4922 | | * XXX These are not for all platforms, and even some Unix MPMs might not want |
4923 | | * some directives. |
4924 | | */ |
4925 | | AP_INIT_TAKE1("PidFile", ap_mpm_set_pidfile, NULL, RSRC_CONF, |
4926 | | "A file for logging the server process ID"), |
4927 | | AP_INIT_TAKE1("MaxRequestsPerChild", ap_mpm_set_max_requests, NULL, RSRC_CONF, |
4928 | | "Maximum number of connections a particular child serves before " |
4929 | | "dying. (DEPRECATED, use MaxConnectionsPerChild)"), |
4930 | | AP_INIT_TAKE1("MaxConnectionsPerChild", ap_mpm_set_max_requests, NULL, RSRC_CONF, |
4931 | | "Maximum number of connections a particular child serves before dying."), |
4932 | | AP_INIT_TAKE1("CoreDumpDirectory", ap_mpm_set_coredumpdir, NULL, RSRC_CONF, |
4933 | | "The location of the directory Apache changes to before dumping core"), |
4934 | | AP_INIT_TAKE1("MaxMemFree", ap_mpm_set_max_mem_free, NULL, RSRC_CONF, |
4935 | | "Maximum number of 1k blocks a particular child's allocator may hold."), |
4936 | | AP_INIT_TAKE1("ThreadStackSize", ap_mpm_set_thread_stacksize, NULL, RSRC_CONF, |
4937 | | "Size in bytes of stack used by threads handling client connections"), |
4938 | | #if AP_ENABLE_EXCEPTION_HOOK |
4939 | | AP_INIT_TAKE1("EnableExceptionHook", ap_mpm_set_exception_hook, NULL, RSRC_CONF, |
4940 | | "Controls whether exception hook may be called after a crash"), |
4941 | | #endif |
4942 | | AP_INIT_TAKE1("TraceEnable", set_trace_enable, NULL, RSRC_CONF, |
4943 | | "'on' (default), 'off' or 'extended' to trace request body content"), |
4944 | | AP_INIT_FLAG("MergeTrailers", set_merge_trailers, NULL, RSRC_CONF, |
4945 | | "merge request trailers into request headers or not"), |
4946 | | AP_INIT_ITERATE("HttpProtocolOptions", set_http_protocol_options, NULL, RSRC_CONF, |
4947 | | "'Allow0.9' or 'Require1.0' (default); " |
4948 | | "'RegisteredMethods' or 'LenientMethods' (default); " |
4949 | | "'Unsafe' or 'Strict' (default). Sets HTTP acceptance rules"), |
4950 | | AP_INIT_ITERATE("RegisterHttpMethod", set_http_method, NULL, RSRC_CONF, |
4951 | | "Registers non-standard HTTP methods"), |
4952 | | AP_INIT_FLAG("HttpContentLengthHeadZero", set_cl_head_zero, NULL, OR_OPTIONS, |
4953 | | "whether to permit Content-Length of 0 responses to HEAD requests"), |
4954 | | AP_INIT_FLAG("HttpExpectStrict", set_expect_strict, NULL, OR_OPTIONS, |
4955 | | "whether to return a 417 if a client doesn't send 100-Continue"), |
4956 | | AP_INIT_ITERATE("Protocols", set_protocols, NULL, RSRC_CONF, |
4957 | | "Controls which protocols are allowed"), |
4958 | | AP_INIT_TAKE1("ProtocolsHonorOrder", set_protocols_honor_order, NULL, RSRC_CONF, |
4959 | | "'off' (default) or 'on' to respect given order of protocols, " |
4960 | | "by default the client specified order determines selection"), |
4961 | | AP_INIT_TAKE1("AsyncFilter", set_async_filter, NULL, RSRC_CONF, |
4962 | | "'network', 'connection' (default) or 'request' to limit the " |
4963 | | "types of filters that support asynchronous handling"), |
4964 | | AP_INIT_FLAG("MergeSlashes", set_core_server_flag, |
4965 | | (void *)APR_OFFSETOF(core_server_config, merge_slashes), |
4966 | | RSRC_CONF, |
4967 | | "Controls whether consecutive slashes in the URI path are merged"), |
4968 | | { NULL } |
4969 | | }; |
4970 | | |
4971 | | /***************************************************************** |
4972 | | * |
4973 | | * Core handlers for various phases of server operation... |
4974 | | */ |
4975 | | |
4976 | | AP_DECLARE_NONSTD(int) ap_core_translate(request_rec *r) |
4977 | 0 | { |
4978 | 0 | apr_status_t rv; |
4979 | 0 | char *path; |
4980 | | |
4981 | | /* XXX this seems too specific, this should probably become |
4982 | | * some general-case test |
4983 | | */ |
4984 | 0 | if (r->proxyreq) { |
4985 | 0 | return HTTP_FORBIDDEN; |
4986 | 0 | } |
4987 | 0 | if (!r->uri || ((r->uri[0] != '/') && strcmp(r->uri, "*"))) { |
4988 | 0 | ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00126) |
4989 | 0 | "Invalid URI in request '%s' '%s'", r->uri, r->the_request); |
4990 | 0 | return HTTP_BAD_REQUEST; |
4991 | 0 | } |
4992 | | |
4993 | 0 | if (r->server->path |
4994 | 0 | && !strncmp(r->uri, r->server->path, r->server->pathlen) |
4995 | 0 | && (r->server->path[r->server->pathlen - 1] == '/' |
4996 | 0 | || r->uri[r->server->pathlen] == '/' |
4997 | 0 | || r->uri[r->server->pathlen] == '\0')) |
4998 | 0 | { |
4999 | 0 | path = r->uri + r->server->pathlen; |
5000 | 0 | } |
5001 | 0 | else { |
5002 | 0 | path = r->uri; |
5003 | 0 | } |
5004 | | /* |
5005 | | * Make sure that we do not mess up the translation by adding two |
5006 | | * /'s in a row. This happens under windows when the document |
5007 | | * root ends with a / |
5008 | | */ |
5009 | | /* skip all leading /'s (e.g. http://localhost///foo) |
5010 | | * so we are looking at only the relative path. |
5011 | | */ |
5012 | 0 | while (*path == '/') { |
5013 | 0 | ++path; |
5014 | 0 | } |
5015 | 0 | if ((rv = apr_filepath_merge(&r->filename, ap_document_root(r), path, |
5016 | 0 | APR_FILEPATH_TRUENAME |
5017 | 0 | | APR_FILEPATH_SECUREROOT, r->pool)) |
5018 | 0 | != APR_SUCCESS) { |
5019 | 0 | ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(00127) |
5020 | 0 | "Cannot map %s to file", r->the_request); |
5021 | 0 | return HTTP_FORBIDDEN; |
5022 | 0 | } |
5023 | 0 | r->canonical_filename = r->filename; |
5024 | |
|
5025 | 0 | return OK; |
5026 | 0 | } |
5027 | | |
5028 | | /***************************************************************** |
5029 | | * |
5030 | | * Test the filesystem name through directory_walk and file_walk |
5031 | | */ |
5032 | | static int core_map_to_storage(request_rec *r) |
5033 | 0 | { |
5034 | 0 | int access_status; |
5035 | |
|
5036 | 0 | if ((access_status = ap_directory_walk(r))) { |
5037 | 0 | return access_status; |
5038 | 0 | } |
5039 | | |
5040 | 0 | if ((access_status = ap_file_walk(r))) { |
5041 | 0 | return access_status; |
5042 | 0 | } |
5043 | | |
5044 | 0 | return OK; |
5045 | 0 | } |
5046 | | |
5047 | | |
5048 | 0 | static int do_nothing(request_rec *r) { return OK; } |
5049 | | |
5050 | | static int core_override_type(request_rec *r) |
5051 | 0 | { |
5052 | 0 | core_dir_config *conf = |
5053 | 0 | (core_dir_config *)ap_get_core_module_config(r->per_dir_config); |
5054 | | |
5055 | | /* Check for overrides with ForceType / SetHandler |
5056 | | */ |
5057 | 0 | if (conf->mime_type && strcmp(conf->mime_type, "none")) |
5058 | 0 | ap_set_content_type(r, (char*) conf->mime_type); |
5059 | |
|
5060 | 0 | if (conf->expr_handler) { |
5061 | 0 | const char *err; |
5062 | 0 | const char *val; |
5063 | 0 | val = ap_expr_str_exec(r, conf->expr_handler, &err); |
5064 | 0 | if (err) { |
5065 | 0 | ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(03154) |
5066 | 0 | "Can't evaluate handler expression: %s", err); |
5067 | 0 | return HTTP_INTERNAL_SERVER_ERROR; |
5068 | 0 | } |
5069 | | |
5070 | 0 | if (val != ap_strstr_c(val, "proxy:unix")) { |
5071 | | /* Retained for compatibility -- but not for UDS */ |
5072 | 0 | char *tmp = apr_pstrdup(r->pool, val); |
5073 | 0 | ap_str_tolower(tmp); |
5074 | 0 | val = tmp; |
5075 | 0 | } |
5076 | |
|
5077 | 0 | if (strcmp(val, "none")) { |
5078 | 0 | r->handler = val; |
5079 | 0 | } |
5080 | 0 | } |
5081 | 0 | else if (conf->handler && strcmp(conf->handler, "none")) { |
5082 | 0 | r->handler = conf->handler; |
5083 | 0 | } |
5084 | | |
5085 | | /* Deal with the poor soul who is trying to force path_info to be |
5086 | | * accepted within the core_handler, where they will let the subreq |
5087 | | * address its contents. This is toggled by the user in the very |
5088 | | * beginning of the fixup phase (here!), so modules should override the user's |
5089 | | * discretion in their own module fixup phase. It is tristate, if |
5090 | | * the user doesn't specify, the result is AP_REQ_DEFAULT_PATH_INFO. |
5091 | | * (which the module may interpret to its own customary behavior.) |
5092 | | * It won't be touched if the value is no longer AP_ACCEPT_PATHINFO_UNSET, |
5093 | | * so any module changing the value prior to the fixup phase |
5094 | | * OVERRIDES the user's choice. |
5095 | | */ |
5096 | 0 | if ((r->used_path_info == AP_REQ_DEFAULT_PATH_INFO) |
5097 | 0 | && (conf->accept_path_info != AP_ACCEPT_PATHINFO_UNSET)) { |
5098 | | /* No module knew better, and the user coded AcceptPathInfo */ |
5099 | 0 | r->used_path_info = conf->accept_path_info; |
5100 | 0 | } |
5101 | |
|
5102 | 0 | return OK; |
5103 | 0 | } |
5104 | | |
5105 | | static int default_handler(request_rec *r) |
5106 | 0 | { |
5107 | 0 | conn_rec *c = r->connection; |
5108 | 0 | apr_bucket_brigade *bb; |
5109 | 0 | apr_bucket *e; |
5110 | 0 | core_dir_config *d; |
5111 | 0 | int errstatus; |
5112 | 0 | apr_file_t *fd = NULL; |
5113 | 0 | apr_status_t status; |
5114 | |
|
5115 | 0 | d = (core_dir_config *)ap_get_core_module_config(r->per_dir_config); |
5116 | |
|
5117 | 0 | ap_allow_standard_methods(r, MERGE_ALLOW, M_GET, M_OPTIONS, M_POST, -1); |
5118 | | |
5119 | | /* If filters intend to consume the request body, they must |
5120 | | * register an InputFilter to slurp the contents of the POST |
5121 | | * data from the POST input stream. It no longer exists when |
5122 | | * the output filters are invoked by the default handler. |
5123 | | */ |
5124 | 0 | if ((errstatus = ap_discard_request_body(r)) != OK) { |
5125 | 0 | return errstatus; |
5126 | 0 | } |
5127 | | |
5128 | 0 | if (r->method_number == M_GET || r->method_number == M_POST) { |
5129 | 0 | if (r->finfo.filetype == APR_NOFILE) { |
5130 | 0 | ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(00128) |
5131 | 0 | "File does not exist: %s", |
5132 | 0 | apr_pstrcat(r->pool, r->filename, r->path_info, NULL)); |
5133 | 0 | return HTTP_NOT_FOUND; |
5134 | 0 | } |
5135 | | |
5136 | | /* Don't try to serve a dir. Some OSs do weird things with |
5137 | | * raw I/O on a dir. |
5138 | | */ |
5139 | 0 | if (r->finfo.filetype == APR_DIR) { |
5140 | 0 | ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(00129) |
5141 | 0 | "Attempt to serve directory: %s", r->filename); |
5142 | 0 | return HTTP_NOT_FOUND; |
5143 | 0 | } |
5144 | | |
5145 | 0 | if ((r->used_path_info != AP_REQ_ACCEPT_PATH_INFO) && |
5146 | 0 | r->path_info && *r->path_info) |
5147 | 0 | { |
5148 | | /* default to reject */ |
5149 | 0 | ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(00130) |
5150 | 0 | "File does not exist: %s", |
5151 | 0 | apr_pstrcat(r->pool, r->filename, r->path_info, NULL)); |
5152 | 0 | return HTTP_NOT_FOUND; |
5153 | 0 | } |
5154 | | |
5155 | | /* We understood the (non-GET) method, but it might not be legal for |
5156 | | this particular resource. Check to see if the 'deliver_script' |
5157 | | flag is set. If so, then we go ahead and deliver the file since |
5158 | | it isn't really content (only GET normally returns content). |
5159 | | |
5160 | | Note: based on logic further above, the only possible non-GET |
5161 | | method at this point is POST. In the future, we should enable |
5162 | | script delivery for all methods. */ |
5163 | 0 | if (r->method_number != M_GET) { |
5164 | 0 | core_request_config *req_cfg; |
5165 | |
|
5166 | 0 | req_cfg = ap_get_core_module_config(r->request_config); |
5167 | 0 | if (!req_cfg->deliver_script) { |
5168 | | /* The flag hasn't been set for this request. Punt. */ |
5169 | 0 | ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00131) |
5170 | 0 | "This resource does not accept the %s method.", |
5171 | 0 | r->method); |
5172 | 0 | return HTTP_METHOD_NOT_ALLOWED; |
5173 | 0 | } |
5174 | 0 | } |
5175 | | |
5176 | | |
5177 | 0 | if ((status = apr_file_open(&fd, r->filename, APR_READ | APR_BINARY |
5178 | 0 | #if APR_HAS_SENDFILE |
5179 | 0 | | AP_SENDFILE_ENABLED(d->enable_sendfile) |
5180 | 0 | #endif |
5181 | 0 | , 0, r->pool)) != APR_SUCCESS) { |
5182 | 0 | ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00132) |
5183 | 0 | "file permissions deny server access: %s", r->filename); |
5184 | 0 | return HTTP_FORBIDDEN; |
5185 | 0 | } |
5186 | | |
5187 | 0 | ap_update_mtime(r, r->finfo.mtime); |
5188 | 0 | ap_set_last_modified(r); |
5189 | 0 | ap_set_etag_fd(r, fd); |
5190 | 0 | ap_set_accept_ranges(r); |
5191 | 0 | ap_set_content_length(r, r->finfo.size); |
5192 | |
|
5193 | 0 | bb = apr_brigade_create(r->pool, c->bucket_alloc); |
5194 | |
|
5195 | 0 | if ((errstatus = ap_meets_conditions(r)) != OK) { |
5196 | 0 | apr_file_close(fd); |
5197 | 0 | r->status = errstatus; |
5198 | 0 | } |
5199 | 0 | else { |
5200 | 0 | e = apr_brigade_insert_file(bb, fd, 0, r->finfo.size, r->pool); |
5201 | |
|
5202 | 0 | #if APR_HAS_MMAP |
5203 | 0 | if (d->enable_mmap == ENABLE_MMAP_OFF) { |
5204 | 0 | (void)apr_bucket_file_enable_mmap(e, 0); |
5205 | 0 | } |
5206 | 0 | #endif |
5207 | 0 | #if APR_MAJOR_VERSION > 1 || (APU_MAJOR_VERSION == 1 && APU_MINOR_VERSION >= 6) |
5208 | 0 | if (d->read_buf_size) { |
5209 | 0 | apr_bucket_file_set_buf_size(e, d->read_buf_size); |
5210 | 0 | } |
5211 | 0 | #endif |
5212 | 0 | } |
5213 | |
|
5214 | 0 | e = apr_bucket_eos_create(c->bucket_alloc); |
5215 | 0 | APR_BRIGADE_INSERT_TAIL(bb, e); |
5216 | |
|
5217 | 0 | status = ap_pass_brigade(r->output_filters, bb); |
5218 | 0 | apr_brigade_cleanup(bb); |
5219 | |
|
5220 | 0 | if (status == APR_SUCCESS |
5221 | 0 | || r->status != HTTP_OK |
5222 | 0 | || c->aborted) { |
5223 | 0 | return OK; |
5224 | 0 | } |
5225 | 0 | else { |
5226 | | /* no way to know what type of error occurred */ |
5227 | 0 | ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, APLOGNO(00133) |
5228 | 0 | "default_handler: ap_pass_brigade returned %i", |
5229 | 0 | status); |
5230 | 0 | return AP_FILTER_ERROR; |
5231 | 0 | } |
5232 | 0 | } |
5233 | 0 | else { /* unusual method (not GET or POST) */ |
5234 | 0 | if (r->method_number == M_INVALID) { |
5235 | | /* See if this looks like an undecrypted SSL handshake attempt. |
5236 | | * It's safe to look a couple bytes into the_request if it exists, as it's |
5237 | | * always allocated at least MIN_LINE_ALLOC (80) bytes. |
5238 | | */ |
5239 | 0 | if (r->the_request |
5240 | 0 | && r->the_request[0] == 0x16 |
5241 | 0 | && (r->the_request[1] == 0x2 || r->the_request[1] == 0x3)) { |
5242 | 0 | ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00134) |
5243 | 0 | "Invalid method in request %s - possible attempt to establish SSL connection on non-SSL port", r->the_request); |
5244 | 0 | } else { |
5245 | 0 | ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00135) |
5246 | 0 | "Invalid method in request %s", r->the_request); |
5247 | 0 | } |
5248 | 0 | return HTTP_NOT_IMPLEMENTED; |
5249 | 0 | } |
5250 | | |
5251 | 0 | if (r->method_number == M_OPTIONS) { |
5252 | 0 | return ap_send_http_options(r); |
5253 | 0 | } |
5254 | 0 | return HTTP_METHOD_NOT_ALLOWED; |
5255 | 0 | } |
5256 | 0 | } |
5257 | | |
5258 | | /* Optional function coming from mod_logio, used for logging of output |
5259 | | * traffic |
5260 | | */ |
5261 | | APR_OPTIONAL_FN_TYPE(ap_logio_add_bytes_out) *ap__logio_add_bytes_out; |
5262 | | APR_OPTIONAL_FN_TYPE(authz_some_auth_required) *ap__authz_ap_some_auth_required; |
5263 | | |
5264 | | /* Insist that at least one module will undertake to provide system |
5265 | | * security by dropping startup privileges. |
5266 | | */ |
5267 | | static int sys_privileges = 0; |
5268 | | AP_DECLARE(int) ap_sys_privileges_handlers(int inc) |
5269 | 0 | { |
5270 | 0 | sys_privileges += inc; |
5271 | 0 | return sys_privileges; |
5272 | 0 | } |
5273 | | |
5274 | | static int check_errorlog_dir(apr_pool_t *p, server_rec *s) |
5275 | 0 | { |
5276 | 0 | if (!s->error_fname || s->error_fname[0] == '|' |
5277 | 0 | || s->errorlog_provider != NULL) { |
5278 | 0 | return APR_SUCCESS; |
5279 | 0 | } |
5280 | 0 | else { |
5281 | 0 | char *abs = ap_server_root_relative(p, s->error_fname); |
5282 | 0 | char *dir = ap_make_dirstr_parent(p, abs); |
5283 | 0 | apr_finfo_t finfo; |
5284 | 0 | apr_status_t rv = apr_stat(&finfo, dir, APR_FINFO_TYPE, p); |
5285 | 0 | if (rv == APR_SUCCESS && finfo.filetype != APR_DIR) |
5286 | 0 | rv = APR_ENOTDIR; |
5287 | 0 | if (rv != APR_SUCCESS) { |
5288 | 0 | const char *desc = "main error log"; |
5289 | 0 | if (s->defn_name) |
5290 | 0 | desc = apr_psprintf(p, "error log of vhost defined at %s:%d", |
5291 | 0 | s->defn_name, s->defn_line_number); |
5292 | 0 | ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_EMERG, rv, |
5293 | 0 | ap_server_conf, APLOGNO(02291) |
5294 | 0 | "Cannot access directory '%s' for %s", dir, desc); |
5295 | 0 | return !OK; |
5296 | 0 | } |
5297 | 0 | } |
5298 | 0 | return OK; |
5299 | 0 | } |
5300 | | |
5301 | | static int core_check_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) |
5302 | 0 | { |
5303 | 0 | int rv = OK; |
5304 | 0 | while (s) { |
5305 | 0 | if (check_errorlog_dir(ptemp, s) != OK) |
5306 | 0 | rv = !OK; |
5307 | 0 | s = s->next; |
5308 | 0 | } |
5309 | 0 | return rv; |
5310 | 0 | } |
5311 | | |
5312 | | |
5313 | | static int core_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp) |
5314 | 0 | { |
5315 | 0 | ap_mutex_init(pconf); |
5316 | |
|
5317 | 0 | if (!saved_server_config_defines) |
5318 | 0 | init_config_defines(pconf); |
5319 | 0 | apr_pool_cleanup_register(pconf, NULL, reset_config, apr_pool_cleanup_null); |
5320 | |
|
5321 | 0 | ap_regcomp_set_default_cflags(AP_REG_DEFAULT); |
5322 | |
|
5323 | 0 | mpm_common_pre_config(pconf); |
5324 | |
|
5325 | 0 | return OK; |
5326 | 0 | } |
5327 | | |
5328 | | static int core_post_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) |
5329 | 0 | { |
5330 | 0 | ap__logio_add_bytes_out = APR_RETRIEVE_OPTIONAL_FN(ap_logio_add_bytes_out); |
5331 | 0 | ident_lookup = APR_RETRIEVE_OPTIONAL_FN(ap_ident_lookup); |
5332 | 0 | ap__authz_ap_some_auth_required = APR_RETRIEVE_OPTIONAL_FN(authz_some_auth_required); |
5333 | 0 | authn_ap_auth_type = APR_RETRIEVE_OPTIONAL_FN(authn_ap_auth_type); |
5334 | 0 | authn_ap_auth_name = APR_RETRIEVE_OPTIONAL_FN(authn_ap_auth_name); |
5335 | 0 | access_compat_ap_satisfies = APR_RETRIEVE_OPTIONAL_FN(access_compat_ap_satisfies); |
5336 | |
|
5337 | 0 | set_banner(pconf); |
5338 | 0 | ap_setup_make_content_type(pconf); |
5339 | 0 | ap_setup_auth_internal(ptemp); |
5340 | 0 | ap_setup_ssl_optional_fns(pconf); |
5341 | 0 | if (!sys_privileges) { |
5342 | 0 | ap_log_error(APLOG_MARK, APLOG_CRIT, 0, NULL, APLOGNO(00136) |
5343 | 0 | "Server MUST relinquish startup privileges before " |
5344 | 0 | "accepting connections. Please ensure mod_unixd " |
5345 | 0 | "or other system security module is loaded."); |
5346 | 0 | return !OK; |
5347 | 0 | } |
5348 | 0 | apr_pool_cleanup_register(pconf, NULL, ap_mpm_end_gen_helper, |
5349 | 0 | apr_pool_cleanup_null); |
5350 | 0 | return OK; |
5351 | 0 | } |
5352 | | |
5353 | | static void core_insert_filter(request_rec *r) |
5354 | 0 | { |
5355 | 0 | core_dir_config *conf = (core_dir_config *) |
5356 | 0 | ap_get_core_module_config(r->per_dir_config); |
5357 | 0 | const char *filter, *filters = conf->output_filters; |
5358 | |
|
5359 | 0 | if (filters) { |
5360 | 0 | while (*filters && (filter = ap_getword(r->pool, &filters, ';'))) { |
5361 | 0 | ap_add_output_filter(filter, NULL, r, r->connection); |
5362 | 0 | } |
5363 | 0 | } |
5364 | |
|
5365 | 0 | filters = conf->input_filters; |
5366 | 0 | if (filters) { |
5367 | 0 | while (*filters && (filter = ap_getword(r->pool, &filters, ';'))) { |
5368 | 0 | ap_add_input_filter(filter, NULL, r, r->connection); |
5369 | 0 | } |
5370 | 0 | } |
5371 | 0 | } |
5372 | | |
5373 | | static apr_size_t num_request_notes = AP_NUM_STD_NOTES; |
5374 | | |
5375 | | static apr_status_t reset_request_notes(void *dummy) |
5376 | 0 | { |
5377 | 0 | num_request_notes = AP_NUM_STD_NOTES; |
5378 | 0 | return APR_SUCCESS; |
5379 | 0 | } |
5380 | | |
5381 | | AP_DECLARE(apr_size_t) ap_register_request_note(void) |
5382 | 0 | { |
5383 | 0 | apr_pool_cleanup_register(apr_hook_global_pool, NULL, reset_request_notes, |
5384 | 0 | apr_pool_cleanup_null); |
5385 | 0 | return num_request_notes++; |
5386 | 0 | } |
5387 | | |
5388 | | AP_DECLARE(void **) ap_get_request_note(request_rec *r, apr_size_t note_num) |
5389 | 0 | { |
5390 | 0 | core_request_config *req_cfg; |
5391 | |
|
5392 | 0 | if (note_num >= num_request_notes) { |
5393 | 0 | return NULL; |
5394 | 0 | } |
5395 | | |
5396 | 0 | req_cfg = (core_request_config *) |
5397 | 0 | ap_get_core_module_config(r->request_config); |
5398 | |
|
5399 | 0 | if (!req_cfg) { |
5400 | 0 | return NULL; |
5401 | 0 | } |
5402 | | |
5403 | 0 | return &(req_cfg->notes[note_num]); |
5404 | 0 | } |
5405 | | |
5406 | | AP_DECLARE(apr_socket_t *) ap_get_conn_socket(conn_rec *c) |
5407 | 0 | { |
5408 | 0 | conn_config_t *conn_config = ap_get_core_module_config(c->conn_config); |
5409 | |
|
5410 | 0 | return AP_CORE_DEFAULT(conn_config, socket, NULL); |
5411 | 0 | } |
5412 | | |
5413 | | static int core_create_req(request_rec *r) |
5414 | 0 | { |
5415 | | /* Alloc the config struct and the array of request notes in |
5416 | | * a single block for efficiency |
5417 | | */ |
5418 | 0 | core_request_config *req_cfg; |
5419 | |
|
5420 | 0 | req_cfg = apr_pcalloc(r->pool, sizeof(core_request_config) + |
5421 | 0 | sizeof(void *) * num_request_notes); |
5422 | 0 | req_cfg->notes = (void **)((char *)req_cfg + sizeof(core_request_config)); |
5423 | | |
5424 | | /* ### temporarily enable script delivery as the default */ |
5425 | 0 | req_cfg->deliver_script = 1; |
5426 | |
|
5427 | 0 | if (r->main) { |
5428 | 0 | core_request_config *main_req_cfg = (core_request_config *) |
5429 | 0 | ap_get_core_module_config(r->main->request_config); |
5430 | 0 | req_cfg->bb = main_req_cfg->bb; |
5431 | 0 | } |
5432 | 0 | else { |
5433 | 0 | req_cfg->bb = apr_brigade_create(r->pool, r->connection->bucket_alloc); |
5434 | 0 | } |
5435 | |
|
5436 | 0 | ap_set_core_module_config(r->request_config, req_cfg); |
5437 | |
|
5438 | 0 | return OK; |
5439 | 0 | } |
5440 | | |
5441 | | static int core_create_proxy_req(request_rec *r, request_rec *pr) |
5442 | 0 | { |
5443 | 0 | return core_create_req(pr); |
5444 | 0 | } |
5445 | | |
5446 | | static conn_rec *core_create_conn(apr_pool_t *ptrans, server_rec *s, |
5447 | | apr_socket_t *csd, long id, void *sbh, |
5448 | | apr_bucket_alloc_t *alloc) |
5449 | 0 | { |
5450 | 0 | apr_status_t rv; |
5451 | 0 | apr_pool_t *pool; |
5452 | 0 | conn_rec *c = (conn_rec *) apr_pcalloc(ptrans, sizeof(conn_rec)); |
5453 | 0 | core_server_config *sconf = ap_get_core_module_config(s->module_config); |
5454 | |
|
5455 | 0 | c->sbh = sbh; |
5456 | 0 | ap_update_child_status(c->sbh, SERVER_BUSY_READ, NULL); |
5457 | | |
5458 | | /* Got a connection structure, so initialize what fields we can |
5459 | | * (the rest are zeroed out by pcalloc). |
5460 | | */ |
5461 | 0 | apr_pool_create(&pool, ptrans); |
5462 | 0 | apr_pool_tag(pool, "master_conn"); |
5463 | 0 | c->pool = pool; |
5464 | |
|
5465 | 0 | c->conn_config = ap_create_conn_config(c->pool); |
5466 | 0 | c->notes = apr_table_make(c->pool, 5); |
5467 | 0 | c->slaves = apr_array_make(c->pool, 20, sizeof(conn_slave_rec *)); |
5468 | 0 | c->requests = apr_array_make(c->pool, 20, sizeof(request_rec *)); |
5469 | |
|
5470 | 0 | if ((rv = apr_socket_addr_get(&c->local_addr, APR_LOCAL, csd)) |
5471 | 0 | != APR_SUCCESS) { |
5472 | 0 | ap_log_error(APLOG_MARK, APLOG_INFO, rv, s, APLOGNO(00137) |
5473 | 0 | "apr_socket_addr_get(APR_LOCAL)"); |
5474 | 0 | apr_socket_close(csd); |
5475 | 0 | return NULL; |
5476 | 0 | } |
5477 | 0 | if (apr_sockaddr_ip_get(&c->local_ip, c->local_addr)) { |
5478 | 0 | #if APR_HAVE_SOCKADDR_UN |
5479 | 0 | if (c->local_addr->family == APR_UNIX) { |
5480 | 0 | c->local_ip = apr_pstrndup(c->pool, c->local_addr->ipaddr_ptr, |
5481 | 0 | c->local_addr->ipaddr_len); |
5482 | 0 | } |
5483 | 0 | else |
5484 | 0 | #endif |
5485 | 0 | c->local_ip = apr_pstrdup(c->pool, "unknown"); |
5486 | 0 | } |
5487 | |
|
5488 | 0 | if ((rv = apr_socket_addr_get(&c->client_addr, APR_REMOTE, csd)) |
5489 | 0 | != APR_SUCCESS) { |
5490 | 0 | ap_log_error(APLOG_MARK, APLOG_INFO, rv, s, APLOGNO(00138) |
5491 | 0 | "apr_socket_addr_get(APR_REMOTE)"); |
5492 | 0 | apr_socket_close(csd); |
5493 | 0 | return NULL; |
5494 | 0 | } |
5495 | 0 | if (apr_sockaddr_ip_get(&c->client_ip, c->client_addr)) { |
5496 | 0 | #if APR_HAVE_SOCKADDR_UN |
5497 | 0 | if (c->client_addr->family == APR_UNIX) { |
5498 | 0 | c->client_ip = apr_pstrndup(c->pool, c->client_addr->ipaddr_ptr, |
5499 | 0 | c->client_addr->ipaddr_len); |
5500 | 0 | } |
5501 | 0 | else |
5502 | 0 | #endif |
5503 | 0 | c->client_ip = apr_pstrdup(c->pool, "unknown"); |
5504 | 0 | } |
5505 | |
|
5506 | 0 | c->base_server = s; |
5507 | |
|
5508 | 0 | c->id = id; |
5509 | 0 | c->bucket_alloc = alloc; |
5510 | 0 | c->async_filter = sconf->async_filter; |
5511 | |
|
5512 | 0 | c->clogging_input_filters = 0; |
5513 | |
|
5514 | 0 | if (sconf->conn_log_level) { |
5515 | 0 | int i; |
5516 | 0 | conn_log_config *conf; |
5517 | 0 | const struct ap_logconf *log = NULL; |
5518 | 0 | struct ap_logconf *merged; |
5519 | |
|
5520 | 0 | for (i = 0; i < sconf->conn_log_level->nelts; i++) { |
5521 | 0 | conf = APR_ARRAY_IDX(sconf->conn_log_level, i, conn_log_config *); |
5522 | 0 | if (apr_ipsubnet_test(conf->subnet, c->client_addr)) |
5523 | 0 | log = &conf->log; |
5524 | 0 | } |
5525 | 0 | if (log) { |
5526 | 0 | merged = ap_new_log_config(c->pool, log); |
5527 | 0 | ap_merge_log_config(&s->log, merged); |
5528 | 0 | c->log = merged; |
5529 | 0 | } |
5530 | 0 | } |
5531 | |
|
5532 | 0 | return c; |
5533 | 0 | } |
5534 | | |
5535 | | static conn_rec *core_create_secondary_conn(apr_pool_t *ptrans, |
5536 | | conn_rec *master, |
5537 | | apr_bucket_alloc_t *alloc) |
5538 | 0 | { |
5539 | 0 | apr_pool_t *pool; |
5540 | 0 | conn_config_t *conn_config; |
5541 | 0 | conn_rec *c = (conn_rec *) apr_pmemdup(ptrans, master, sizeof(*c)); |
5542 | | |
5543 | | /* Got a connection structure, so initialize what fields we can |
5544 | | * (the rest are zeroed out by pcalloc). |
5545 | | */ |
5546 | 0 | apr_pool_create(&pool, ptrans); |
5547 | 0 | apr_pool_tag(pool, "secondary_conn"); |
5548 | | |
5549 | | /* we copied everything, now replace what is different */ |
5550 | 0 | c->master = master; |
5551 | 0 | c->pool = pool; |
5552 | 0 | c->bucket_alloc = alloc; |
5553 | 0 | c->conn_config = ap_create_conn_config(pool); |
5554 | 0 | c->notes = apr_table_make(pool, 5); |
5555 | 0 | c->slaves = apr_array_make(pool, 20, sizeof(conn_slave_rec *)); |
5556 | 0 | c->requests = apr_array_make(pool, 20, sizeof(request_rec *)); |
5557 | 0 | c->input_filters = NULL; |
5558 | 0 | c->output_filters = NULL; |
5559 | 0 | c->filter_conn_ctx = NULL; |
5560 | | |
5561 | | /* prevent mpm_event from making wrong assumptions about this connection, |
5562 | | * like e.g. using its socket for an async read check. */ |
5563 | 0 | c->clogging_input_filters = 1; |
5564 | |
|
5565 | 0 | c->log = NULL; |
5566 | 0 | c->aborted = 0; |
5567 | 0 | c->keepalives = 0; |
5568 | | |
5569 | | /* FIXME: mpms (and maybe other) parts think that there is always |
5570 | | * a socket for a connection. We cannot use the master socket for |
5571 | | * secondary connections, as this gets modified (closed?) when |
5572 | | * the secondary connection terminates. |
5573 | | * There seem to be some checks for c->master necessary in other |
5574 | | * places. |
5575 | | */ |
5576 | 0 | conn_config = apr_pcalloc(pool, sizeof(*conn_config)); |
5577 | 0 | conn_config->socket = dummy_socket; |
5578 | 0 | ap_set_core_module_config(c->conn_config, conn_config); |
5579 | |
|
5580 | 0 | return c; |
5581 | 0 | } |
5582 | | |
5583 | | static int core_pre_connection(conn_rec *c, void *csd) |
5584 | 0 | { |
5585 | 0 | conn_config_t *conn_config; |
5586 | 0 | apr_status_t rv; |
5587 | | |
5588 | | /* only the master connection talks to the network */ |
5589 | 0 | if (c->master) { |
5590 | 0 | return DONE; |
5591 | 0 | } |
5592 | | |
5593 | | /* The Nagle algorithm says that we should delay sending partial |
5594 | | * packets in hopes of getting more data. We don't want to do |
5595 | | * this; we are not telnet. There are bad interactions between |
5596 | | * persistent connections and Nagle's algorithm that have very severe |
5597 | | * performance penalties. (Failing to disable Nagle is not much of a |
5598 | | * problem with simple HTTP.) |
5599 | | */ |
5600 | 0 | rv = apr_socket_opt_set(csd, APR_TCP_NODELAY, 1); |
5601 | 0 | if (rv != APR_SUCCESS && rv != APR_ENOTIMPL) { |
5602 | | /* expected cause is that the client disconnected already, |
5603 | | * hence the debug level |
5604 | | */ |
5605 | 0 | ap_log_cerror(APLOG_MARK, APLOG_DEBUG, rv, c, APLOGNO(00139) |
5606 | 0 | "apr_socket_opt_set(APR_TCP_NODELAY)"); |
5607 | 0 | } |
5608 | | |
5609 | | /* The core filter requires the timeout mode to be set, which |
5610 | | * incidentally sets the socket to be nonblocking. If this |
5611 | | * is not initialized correctly, Linux - for example - will |
5612 | | * be initially blocking, while Solaris will be non blocking |
5613 | | * and any initial read will fail. |
5614 | | */ |
5615 | 0 | rv = apr_socket_timeout_set(csd, c->base_server->timeout); |
5616 | 0 | if (rv != APR_SUCCESS) { |
5617 | | /* expected cause is that the client disconnected already */ |
5618 | 0 | ap_log_cerror(APLOG_MARK, APLOG_DEBUG, rv, c, APLOGNO(00140) |
5619 | 0 | "apr_socket_timeout_set"); |
5620 | 0 | } |
5621 | |
|
5622 | 0 | conn_config = apr_pcalloc(c->pool, sizeof(*conn_config)); |
5623 | 0 | conn_config->socket = csd; |
5624 | 0 | ap_set_core_module_config(c->conn_config, conn_config); |
5625 | |
|
5626 | 0 | ap_add_input_filter_handle(ap_core_input_filter_handle, NULL, NULL, c); |
5627 | 0 | ap_add_output_filter_handle(ap_core_output_filter_handle, NULL, NULL, c); |
5628 | |
|
5629 | 0 | return DONE; |
5630 | 0 | } |
5631 | | |
5632 | | AP_DECLARE(int) ap_pre_connection(conn_rec *c, void *csd) |
5633 | 0 | { |
5634 | 0 | int rc = OK; |
5635 | |
|
5636 | 0 | rc = ap_run_pre_connection(c, csd); |
5637 | 0 | if (rc != OK && rc != DONE) { |
5638 | 0 | c->aborted = 1; |
5639 | | /* |
5640 | | * In case we errored, the pre_connection hook of the core |
5641 | | * module maybe did not run (it is APR_HOOK_REALLY_LAST) and |
5642 | | * hence we missed to |
5643 | | * |
5644 | | * - Put the socket in c->conn_config |
5645 | | * - Setup core output and input filters |
5646 | | * - Set socket options and timeouts |
5647 | | * |
5648 | | * Hence call it in this case. |
5649 | | */ |
5650 | 0 | if (!ap_get_conn_socket(c)) { |
5651 | 0 | core_pre_connection(c, csd); |
5652 | 0 | } |
5653 | 0 | } |
5654 | 0 | return rc; |
5655 | 0 | } |
5656 | | |
5657 | | AP_CORE_DECLARE(conn_rec *) ap_create_slave_connection(conn_rec *c) |
5658 | 0 | { |
5659 | 0 | apr_pool_t *pool; |
5660 | 0 | conn_slave_rec *new; |
5661 | 0 | conn_rec *sc = (conn_rec *) apr_palloc(c->pool, sizeof(conn_rec)); |
5662 | |
|
5663 | 0 | apr_pool_create(&pool, c->pool); |
5664 | 0 | apr_pool_tag(pool, "slave_conn"); |
5665 | 0 | memcpy(sc, c, sizeof(conn_rec)); |
5666 | 0 | sc->slaves = NULL; |
5667 | 0 | sc->master = c; |
5668 | 0 | sc->input_filters = NULL; |
5669 | 0 | sc->output_filters = NULL; |
5670 | 0 | sc->filter_conn_ctx = NULL; |
5671 | 0 | sc->pool = pool; |
5672 | 0 | new = apr_array_push(c->slaves); |
5673 | 0 | new->c = sc; |
5674 | 0 | return sc; |
5675 | 0 | } |
5676 | | |
5677 | | AP_DECLARE(int) ap_state_query(int query) |
5678 | 0 | { |
5679 | 0 | switch (query) { |
5680 | 0 | case AP_SQ_MAIN_STATE: |
5681 | 0 | return ap_main_state; |
5682 | 0 | case AP_SQ_RUN_MODE: |
5683 | 0 | return ap_run_mode; |
5684 | 0 | case AP_SQ_CONFIG_GEN: |
5685 | 0 | return ap_config_generation; |
5686 | 0 | default: |
5687 | 0 | return AP_SQ_NOT_SUPPORTED; |
5688 | 0 | } |
5689 | 0 | } |
5690 | | |
5691 | | AP_DECLARE(char *) ap_state_dir_relative(apr_pool_t *p, const char *file) |
5692 | 0 | { |
5693 | 0 | char *newpath = NULL; |
5694 | 0 | apr_status_t rv; |
5695 | 0 | const char *state_dir; |
5696 | |
|
5697 | 0 | state_dir = core_state_dir |
5698 | 0 | ? core_state_dir |
5699 | 0 | : ap_server_root_relative(p, DEFAULT_REL_STATEDIR); |
5700 | |
|
5701 | 0 | rv = apr_filepath_merge(&newpath, state_dir, file, APR_FILEPATH_TRUENAME, p); |
5702 | 0 | if (newpath && (rv == APR_SUCCESS || APR_STATUS_IS_EPATHWILD(rv) |
5703 | 0 | || APR_STATUS_IS_ENOENT(rv) |
5704 | 0 | || APR_STATUS_IS_ENOTDIR(rv))) { |
5705 | 0 | return newpath; |
5706 | 0 | } |
5707 | 0 | else { |
5708 | 0 | return NULL; |
5709 | 0 | } |
5710 | 0 | } |
5711 | | |
5712 | | |
5713 | | static apr_random_t *rng = NULL; |
5714 | | #if APR_HAS_THREADS |
5715 | | static apr_thread_mutex_t *rng_mutex = NULL; |
5716 | | #endif |
5717 | | |
5718 | | static void core_child_init(apr_pool_t *pchild, server_rec *s) |
5719 | 0 | { |
5720 | 0 | apr_proc_t proc; |
5721 | 0 | #if APR_HAS_THREADS |
5722 | 0 | { |
5723 | 0 | int threaded_mpm; |
5724 | 0 | if (ap_mpm_query(AP_MPMQ_IS_THREADED, &threaded_mpm) == APR_SUCCESS |
5725 | 0 | && threaded_mpm) |
5726 | 0 | { |
5727 | 0 | apr_thread_mutex_create(&rng_mutex, APR_THREAD_MUTEX_DEFAULT, pchild); |
5728 | 0 | } |
5729 | 0 | } |
5730 | 0 | #endif |
5731 | | /* The MPMs use plain fork() and not apr_proc_fork(), so we have to call |
5732 | | * apr_random_after_fork() manually in the child |
5733 | | */ |
5734 | 0 | proc.pid = getpid(); |
5735 | 0 | apr_random_after_fork(&proc); |
5736 | | |
5737 | | /* needed for secondary connections so people do not change the master |
5738 | | * connection socket. */ |
5739 | 0 | apr_socket_create(&dummy_socket, APR_INET, SOCK_STREAM, |
5740 | 0 | APR_PROTO_TCP, pchild); |
5741 | 0 | } |
5742 | | |
5743 | | static void core_optional_fn_retrieve(void) |
5744 | 0 | { |
5745 | 0 | ap_init_scoreboard(NULL); |
5746 | 0 | } |
5747 | | |
5748 | | AP_CORE_DECLARE(void) ap_random_parent_after_fork(void) |
5749 | 0 | { |
5750 | | /* |
5751 | | * To ensure that the RNG state in the parent changes after the fork, we |
5752 | | * pull some data from the RNG and discard it. This ensures that the RNG |
5753 | | * states in the children are different even after the pid wraps around. |
5754 | | * As we only use apr_random for insecure random bytes, pulling 2 bytes |
5755 | | * should be enough. |
5756 | | * XXX: APR should probably have some dedicated API to do this, but it |
5757 | | * XXX: currently doesn't. |
5758 | | */ |
5759 | 0 | apr_uint16_t data; |
5760 | 0 | apr_random_insecure_bytes(rng, &data, sizeof(data)); |
5761 | 0 | } |
5762 | | |
5763 | | AP_CORE_DECLARE(void) ap_init_rng(apr_pool_t *p) |
5764 | 0 | { |
5765 | 0 | unsigned char seed[8]; |
5766 | 0 | apr_status_t rv; |
5767 | 0 | rng = apr_random_standard_new(p); |
5768 | 0 | do { |
5769 | 0 | rv = apr_generate_random_bytes(seed, sizeof(seed)); |
5770 | 0 | if (rv != APR_SUCCESS) |
5771 | 0 | goto error; |
5772 | 0 | apr_random_add_entropy(rng, seed, sizeof(seed)); |
5773 | 0 | rv = apr_random_insecure_ready(rng); |
5774 | 0 | } while (rv == APR_ENOTENOUGHENTROPY); |
5775 | 0 | if (rv == APR_SUCCESS) |
5776 | 0 | return; |
5777 | 0 | error: |
5778 | 0 | ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL, APLOGNO(00141) |
5779 | 0 | "Could not initialize random number generator"); |
5780 | 0 | exit(1); |
5781 | 0 | } |
5782 | | |
5783 | | AP_DECLARE(void) ap_random_insecure_bytes(void *buf, apr_size_t size) |
5784 | 0 | { |
5785 | 0 | #if APR_HAS_THREADS |
5786 | 0 | if (rng_mutex) |
5787 | 0 | apr_thread_mutex_lock(rng_mutex); |
5788 | 0 | #endif |
5789 | | /* apr_random_insecure_bytes can only fail with APR_ENOTENOUGHENTROPY, |
5790 | | * and we have ruled that out during initialization. Therefore we don't |
5791 | | * need to check the return code. |
5792 | | */ |
5793 | 0 | apr_random_insecure_bytes(rng, buf, size); |
5794 | 0 | #if APR_HAS_THREADS |
5795 | 0 | if (rng_mutex) |
5796 | 0 | apr_thread_mutex_unlock(rng_mutex); |
5797 | 0 | #endif |
5798 | 0 | } |
5799 | | |
5800 | | /* |
5801 | | * Finding a random number in a range. |
5802 | | * n' = a + n(b-a+1)/(M+1) |
5803 | | * where: |
5804 | | * n' = random number in range |
5805 | | * a = low end of range |
5806 | | * b = high end of range |
5807 | | * n = random number of 0..M |
5808 | | * M = maxint |
5809 | | * Algorithm 'borrowed' from PHP's rand() function. |
5810 | | */ |
5811 | 0 | #define RAND_RANGE(__n, __min, __max, __tmax) \ |
5812 | 0 | (__n) = (__min) + (long) ((double) ((__max) - (__min) + 1.0) * ((__n) / ((__tmax) + 1.0))) |
5813 | | AP_DECLARE(apr_uint32_t) ap_random_pick(apr_uint32_t min, apr_uint32_t max) |
5814 | 0 | { |
5815 | 0 | apr_uint32_t number; |
5816 | 0 | #if (!__GNUC__ || __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) || \ |
5817 | 0 | !__sparc__ || APR_SIZEOF_VOIDP != 8) |
5818 | | /* This triggers a gcc bug on sparc/64bit with gcc < 4.8, PR 52900 */ |
5819 | 0 | if (max < 16384) { |
5820 | 0 | apr_uint16_t num16; |
5821 | 0 | ap_random_insecure_bytes(&num16, sizeof(num16)); |
5822 | 0 | RAND_RANGE(num16, min, max, APR_UINT16_MAX); |
5823 | 0 | number = num16; |
5824 | 0 | } |
5825 | 0 | else |
5826 | 0 | #endif |
5827 | 0 | { |
5828 | 0 | ap_random_insecure_bytes(&number, sizeof(number)); |
5829 | 0 | RAND_RANGE(number, min, max, APR_UINT32_MAX); |
5830 | 0 | } |
5831 | 0 | return number; |
5832 | 0 | } |
5833 | | |
5834 | | static apr_status_t core_insert_network_bucket(conn_rec *c, |
5835 | | apr_bucket_brigade *bb, |
5836 | | apr_socket_t *socket) |
5837 | 0 | { |
5838 | 0 | apr_bucket *e = apr_bucket_socket_create(socket, c->bucket_alloc); |
5839 | 0 | APR_BRIGADE_INSERT_TAIL(bb, e); |
5840 | 0 | return APR_SUCCESS; |
5841 | 0 | } |
5842 | | |
5843 | | static apr_status_t core_dirwalk_stat(apr_finfo_t *finfo, request_rec *r, |
5844 | | apr_int32_t wanted) |
5845 | 0 | { |
5846 | 0 | return apr_stat(finfo, r->filename, wanted, r->pool); |
5847 | 0 | } |
5848 | | |
5849 | | static void core_dump_config(apr_pool_t *p, server_rec *s) |
5850 | 0 | { |
5851 | 0 | core_server_config *sconf = ap_get_core_module_config(s->module_config); |
5852 | 0 | apr_file_t *out = NULL; |
5853 | 0 | const char *tmp; |
5854 | 0 | const char **defines; |
5855 | 0 | int i; |
5856 | 0 | if (!ap_exists_config_define("DUMP_RUN_CFG")) |
5857 | 0 | return; |
5858 | | |
5859 | 0 | apr_file_open_stdout(&out, p); |
5860 | 0 | apr_file_printf(out, "ServerRoot: \"%s\"\n", ap_server_root); |
5861 | 0 | tmp = ap_server_root_relative(p, sconf->ap_document_root); |
5862 | 0 | apr_file_printf(out, "Main DocumentRoot: \"%s\"\n", tmp); |
5863 | 0 | if (s->error_fname[0] != '|' && s->errorlog_provider == NULL) |
5864 | 0 | tmp = ap_server_root_relative(p, s->error_fname); |
5865 | 0 | else |
5866 | 0 | tmp = s->error_fname; |
5867 | 0 | apr_file_printf(out, "Main ErrorLog: \"%s\"\n", tmp); |
5868 | 0 | if (ap_scoreboard_fname) { |
5869 | 0 | tmp = ap_runtime_dir_relative(p, ap_scoreboard_fname); |
5870 | 0 | apr_file_printf(out, "ScoreBoardFile: \"%s\"\n", tmp); |
5871 | 0 | } |
5872 | 0 | ap_dump_mutexes(p, s, out); |
5873 | 0 | ap_mpm_dump_pidfile(p, out); |
5874 | |
|
5875 | 0 | defines = (const char **)ap_server_config_defines->elts; |
5876 | 0 | for (i = 0; i < ap_server_config_defines->nelts; i++) { |
5877 | 0 | const char *name = defines[i]; |
5878 | 0 | const char *val = NULL; |
5879 | 0 | if (server_config_defined_vars) |
5880 | 0 | val = apr_table_get(server_config_defined_vars, name); |
5881 | 0 | if (val) |
5882 | 0 | apr_file_printf(out, "Define: %s=%s\n", name, val); |
5883 | 0 | else |
5884 | 0 | apr_file_printf(out, "Define: %s\n", name); |
5885 | 0 | } |
5886 | 0 | } |
5887 | | |
5888 | | static int core_upgrade_handler(request_rec *r) |
5889 | 0 | { |
5890 | 0 | conn_rec *c = r->connection; |
5891 | 0 | const char *upgrade; |
5892 | |
|
5893 | 0 | if (c->master) { |
5894 | | /* Not possible to perform an HTTP/1.1 upgrade from a slave |
5895 | | * connection. */ |
5896 | 0 | return DECLINED; |
5897 | 0 | } |
5898 | | |
5899 | 0 | upgrade = apr_table_get(r->headers_in, "Upgrade"); |
5900 | 0 | if (upgrade && *upgrade) { |
5901 | 0 | const char *conn = apr_table_get(r->headers_in, "Connection"); |
5902 | 0 | if (ap_find_token(r->pool, conn, "upgrade")) { |
5903 | 0 | apr_array_header_t *offers = NULL; |
5904 | 0 | const char *err; |
5905 | | |
5906 | 0 | err = ap_parse_token_list_strict(r->pool, upgrade, &offers, 0); |
5907 | 0 | if (err) { |
5908 | 0 | ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02910) |
5909 | 0 | "parsing Upgrade header: %s", err); |
5910 | 0 | return DECLINED; |
5911 | 0 | } |
5912 | | |
5913 | 0 | if (offers && offers->nelts > 0) { |
5914 | 0 | const char *protocol = ap_select_protocol(c, r, NULL, offers); |
5915 | 0 | if (protocol && strcmp(protocol, ap_get_protocol(c))) { |
5916 | 0 | ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02909) |
5917 | 0 | "Upgrade selects '%s'", protocol); |
5918 | | /* Let the client know what we are upgrading to. */ |
5919 | 0 | apr_table_clear(r->headers_out); |
5920 | 0 | apr_table_setn(r->headers_out, "Upgrade", protocol); |
5921 | 0 | apr_table_setn(r->headers_out, "Connection", "Upgrade"); |
5922 | | |
5923 | 0 | r->status = HTTP_SWITCHING_PROTOCOLS; |
5924 | 0 | r->status_line = ap_get_status_line(r->status); |
5925 | 0 | ap_send_interim_response(r, 1); |
5926 | |
|
5927 | 0 | ap_switch_protocol(c, r, r->server, protocol); |
5928 | | |
5929 | | /* make sure httpd closes the connection after this */ |
5930 | 0 | c->keepalive = AP_CONN_CLOSE; |
5931 | 0 | return DONE; |
5932 | 0 | } |
5933 | 0 | } |
5934 | 0 | } |
5935 | 0 | } |
5936 | 0 | else if (!c->keepalives) { |
5937 | | /* first request on a master connection, if we have protocols other |
5938 | | * than the current one enabled here, announce them to the |
5939 | | * client. If the client is already talking a protocol with requests |
5940 | | * on slave connections, leave it be. */ |
5941 | 0 | const apr_array_header_t *upgrades; |
5942 | 0 | ap_get_protocol_upgrades(c, r, NULL, 0, &upgrades); |
5943 | 0 | if (upgrades && upgrades->nelts > 0) { |
5944 | 0 | char *protocols = apr_array_pstrcat(r->pool, upgrades, ','); |
5945 | 0 | apr_table_setn(r->headers_out, "Upgrade", protocols); |
5946 | 0 | apr_table_setn(r->headers_out, "Connection", "Upgrade"); |
5947 | 0 | } |
5948 | 0 | } |
5949 | | |
5950 | 0 | return DECLINED; |
5951 | 0 | } |
5952 | | |
5953 | | static int core_upgrade_storage(request_rec *r) |
5954 | 0 | { |
5955 | 0 | if ((r->method_number == M_OPTIONS) && r->uri && (r->uri[0] == '*') && |
5956 | 0 | (r->uri[1] == '\0')) { |
5957 | 0 | return core_upgrade_handler(r); |
5958 | 0 | } |
5959 | 0 | return DECLINED; |
5960 | 0 | } |
5961 | | |
5962 | | static void register_hooks(apr_pool_t *p) |
5963 | 0 | { |
5964 | 0 | errorlog_hash = apr_hash_make(p); |
5965 | 0 | ap_register_log_hooks(p); |
5966 | 0 | ap_register_config_hooks(p); |
5967 | 0 | ap_expr_init(p); |
5968 | | |
5969 | | /* create_connection and pre_connection should always be hooked |
5970 | | * APR_HOOK_REALLY_LAST by core to give other modules the opportunity |
5971 | | * to install alternate network transports and stop other functions |
5972 | | * from being run. |
5973 | | */ |
5974 | 0 | ap_hook_create_connection(core_create_conn, NULL, NULL, |
5975 | 0 | APR_HOOK_REALLY_LAST); |
5976 | 0 | ap_hook_create_secondary_connection(core_create_secondary_conn, NULL, NULL, |
5977 | 0 | APR_HOOK_REALLY_LAST); |
5978 | 0 | ap_hook_pre_connection(core_pre_connection, NULL, NULL, |
5979 | 0 | APR_HOOK_REALLY_LAST); |
5980 | |
|
5981 | 0 | ap_hook_pre_config(core_pre_config, NULL, NULL, APR_HOOK_REALLY_FIRST); |
5982 | 0 | ap_hook_post_config(core_post_config,NULL,NULL,APR_HOOK_REALLY_FIRST); |
5983 | 0 | ap_hook_check_config(core_check_config,NULL,NULL,APR_HOOK_FIRST); |
5984 | 0 | ap_hook_test_config(core_dump_config,NULL,NULL,APR_HOOK_FIRST); |
5985 | 0 | ap_hook_translate_name(ap_core_translate,NULL,NULL,APR_HOOK_REALLY_LAST); |
5986 | 0 | ap_hook_map_to_storage(core_upgrade_storage,NULL,NULL,APR_HOOK_REALLY_FIRST); |
5987 | 0 | ap_hook_map_to_storage(core_map_to_storage,NULL,NULL,APR_HOOK_REALLY_LAST); |
5988 | 0 | ap_hook_open_logs(ap_open_logs,NULL,NULL,APR_HOOK_REALLY_FIRST); |
5989 | 0 | ap_hook_child_init(core_child_init,NULL,NULL,APR_HOOK_REALLY_FIRST); |
5990 | 0 | ap_hook_child_init(ap_logs_child_init,NULL,NULL,APR_HOOK_MIDDLE); |
5991 | 0 | ap_hook_handler(core_upgrade_handler,NULL,NULL,APR_HOOK_REALLY_FIRST); |
5992 | 0 | ap_hook_handler(default_handler,NULL,NULL,APR_HOOK_REALLY_LAST); |
5993 | | /* FIXME: I suspect we can eliminate the need for these do_nothings - Ben */ |
5994 | 0 | ap_hook_type_checker(do_nothing,NULL,NULL,APR_HOOK_REALLY_LAST); |
5995 | 0 | ap_hook_fixups(core_override_type,NULL,NULL,APR_HOOK_REALLY_FIRST); |
5996 | 0 | ap_hook_create_request(core_create_req, NULL, NULL, APR_HOOK_MIDDLE); |
5997 | 0 | APR_OPTIONAL_HOOK(proxy, create_req, core_create_proxy_req, NULL, NULL, |
5998 | 0 | APR_HOOK_MIDDLE); |
5999 | 0 | ap_hook_pre_mpm(ap_create_scoreboard, NULL, NULL, APR_HOOK_MIDDLE); |
6000 | 0 | ap_hook_child_status(ap_core_child_status, NULL, NULL, APR_HOOK_MIDDLE); |
6001 | 0 | ap_hook_insert_network_bucket(core_insert_network_bucket, NULL, NULL, |
6002 | 0 | APR_HOOK_REALLY_LAST); |
6003 | 0 | ap_hook_dirwalk_stat(core_dirwalk_stat, NULL, NULL, APR_HOOK_REALLY_LAST); |
6004 | 0 | ap_hook_open_htaccess(ap_open_htaccess, NULL, NULL, APR_HOOK_REALLY_LAST); |
6005 | 0 | ap_hook_optional_fn_retrieve(core_optional_fn_retrieve, NULL, NULL, |
6006 | 0 | APR_HOOK_MIDDLE); |
6007 | |
|
6008 | 0 | ap_hook_input_pending(ap_filter_input_pending, NULL, NULL, |
6009 | 0 | APR_HOOK_MIDDLE); |
6010 | 0 | ap_hook_output_pending(ap_filter_output_pending, NULL, NULL, |
6011 | 0 | APR_HOOK_MIDDLE); |
6012 | | |
6013 | | /* register the core's insert_filter hook and register core-provided |
6014 | | * filters |
6015 | | */ |
6016 | 0 | ap_hook_insert_filter(core_insert_filter, NULL, NULL, APR_HOOK_MIDDLE); |
6017 | |
|
6018 | 0 | ap_core_input_filter_handle = |
6019 | 0 | ap_register_input_filter("CORE_IN", ap_core_input_filter, |
6020 | 0 | NULL, AP_FTYPE_NETWORK); |
6021 | 0 | ap_content_length_filter_handle = |
6022 | 0 | ap_register_output_filter("CONTENT_LENGTH", ap_content_length_filter, |
6023 | 0 | NULL, AP_FTYPE_PROTOCOL); |
6024 | 0 | ap_core_output_filter_handle = |
6025 | 0 | ap_register_output_filter("CORE", ap_core_output_filter, |
6026 | 0 | NULL, AP_FTYPE_NETWORK); |
6027 | 0 | ap_subreq_core_filter_handle = |
6028 | 0 | ap_register_output_filter("SUBREQ_CORE", ap_sub_req_output_filter, |
6029 | 0 | NULL, AP_FTYPE_CONTENT_SET); |
6030 | 0 | ap_old_write_func = |
6031 | 0 | ap_register_output_filter("OLD_WRITE", ap_old_write_filter, |
6032 | 0 | NULL, AP_FTYPE_RESOURCE - 10); |
6033 | 0 | } |
6034 | | |
6035 | | AP_DECLARE_MODULE(core) = { |
6036 | | MPM20_MODULE_STUFF, |
6037 | | AP_PLATFORM_REWRITE_ARGS_HOOK, /* hook to run before apache parses args */ |
6038 | | create_core_dir_config, /* create per-directory config structure */ |
6039 | | merge_core_dir_configs, /* merge per-directory config structures */ |
6040 | | create_core_server_config, /* create per-server config structure */ |
6041 | | merge_core_server_configs, /* merge per-server config structures */ |
6042 | | core_cmds, /* command apr_table_t */ |
6043 | | register_hooks /* register hooks */ |
6044 | | }; |