Coverage Report

Created: 2025-07-11 06:40

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