Coverage Report

Created: 2025-11-11 06:05

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