Coverage Report

Created: 2026-10-17 06:38

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