Newer
Older
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
s++;
switch (*s) {
case 'r':
*d++ = '\r';
s++;
break;
case 'n':
*d++ = '\n';
s++;
break;
case 't':
*d++ = '\t';
s++;
break;
case '\0':
/* handle end of string */
*d++ = '\\';
break;
default:
/* copy next char verbatim */
*d++ = *s++;
break;
}
}
}
*d = '\0';
it->arg = apr_pstrdup(p, scratch);
*sa = s;
return NULL;
}
static char *parse_errorlog_item(apr_pool_t *p, ap_errorlog_format_item *it,
const char **sa)
{
const char *s = *sa;
ap_errorlog_handler *handler;
int i;
if (*s != '%') {
if (*s == ' ') {
it->flags |= AP_ERRORLOG_FLAG_FIELD_SEP;
}
return parse_errorlog_misc_string(p, it, sa);
}
++s;
if (*s == ' ') {
/* percent-space (% ) is a field separator */
it->flags |= AP_ERRORLOG_FLAG_FIELD_SEP;
*sa = ++s;
/* recurse */
return parse_errorlog_item(p, it, sa);
}
else if (*s == '%') {
it->arg = "%";
it->func = log_constant_item;
*sa = ++s;
return NULL;
}
while (*s) {
switch (*s) {
case '{':
++s;
it->arg = ap_getword(p, &s, '}');
break;
case '+':
++s;
it->flags |= AP_ERRORLOG_FLAG_REQUIRED;
break;
case '-':
++s;
it->flags |= AP_ERRORLOG_FLAG_NULL_AS_HYPHEN;
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
i = *s - '0';
while (apr_isdigit(*++s))
i = i * 10 + (*s) - '0';
it->min_loglevel = i;
break;
case 'M':
it->func = NULL;
it->flags |= AP_ERRORLOG_FLAG_MESSAGE;
*sa = ++s;
return NULL;
default:
handler = (ap_errorlog_handler *)apr_hash_get(errorlog_hash, s, 1);
if (!handler) {
char dummy[2];
dummy[0] = *s;
dummy[1] = '\0';
return apr_pstrcat(p, "Unrecognized error log format directive %",
dummy, NULL);
}
it->func = handler->func;
*sa = ++s;
return NULL;
}
}
return "Ran off end of error log format parsing args to some directive";
}
static apr_array_header_t *parse_errorlog_string(apr_pool_t *p,
const char *s,
const char **err,
int is_main_fmt)
{
apr_array_header_t *a = apr_array_make(p, 30,
sizeof(ap_errorlog_format_item));
char *res;
int seen_msg_fmt = 0;
while (s && *s) {
ap_errorlog_format_item *item =
(ap_errorlog_format_item *)apr_array_push(a);
memset(item, 0, sizeof(*item));
res = parse_errorlog_item(p, item, &s);
if (res) {
*err = res;
return NULL;
}
if (item->flags & AP_ERRORLOG_FLAG_MESSAGE) {
if (!is_main_fmt) {
*err = "%M cannot be used in once-per-request or "
"once-per-connection formats";
return NULL;
}
seen_msg_fmt = 1;
}
if (is_main_fmt && item->flags & AP_ERRORLOG_FLAG_REQUIRED) {
*err = "The '+' flag cannot be used in the main error log format";
return NULL;
}
if (!is_main_fmt && item->min_loglevel) {
*err = "The loglevel cannot be used as a condition in "
"once-per-request or once-per-connection formats";
return NULL;
}
if (item->min_loglevel > APLOG_TRACE8) {
*err = "The specified loglevel modifier is out of range";
return NULL;
}
}
if (is_main_fmt && !seen_msg_fmt) {
*err = "main ErrorLogFormat must contain message format string '%M'";
return NULL;
}
return a;
}
static const char *set_errorlog_format(cmd_parms *cmd, void *dummy,
const char *arg1, const char *arg2)
{
const char *err_string = NULL;
core_server_config *conf =
ap_get_core_module_config(cmd->server->module_config);
if (!arg2) {
conf->error_log_format = parse_errorlog_string(cmd->pool, arg1,
&err_string, 1);
}
else if (!strcasecmp(arg1, "connection")) {
if (!conf->error_log_conn) {
conf->error_log_conn = apr_array_make(cmd->pool, 5,
sizeof(apr_array_header_t *));
}
if (*arg2) {
apr_array_header_t **e;
e = (apr_array_header_t **) apr_array_push(conf->error_log_conn);
*e = parse_errorlog_string(cmd->pool, arg2, &err_string, 0);
}
}
else if (!strcasecmp(arg1, "request")) {
if (!conf->error_log_req) {
conf->error_log_req = apr_array_make(cmd->pool, 5,
sizeof(apr_array_header_t *));
}
if (*arg2) {
apr_array_header_t **e;
e = (apr_array_header_t **) apr_array_push(conf->error_log_req);
*e = parse_errorlog_string(cmd->pool, arg2, &err_string, 0);
}
}
else {
err_string = "ErrorLogFormat type must be one of request, connection";
}
return err_string;
}
AP_DECLARE(void) ap_register_errorlog_handler(apr_pool_t *p, char *tag,
ap_errorlog_handler_fn_t *handler,
int flags)
{
ap_errorlog_handler *log_struct = apr_palloc(p, sizeof(*log_struct));
log_struct->func = handler;
log_struct->flags = flags;
apr_hash_set(errorlog_hash, tag, 1, (const void *)log_struct);
}
static const char *set_merge_trailers(cmd_parms *cmd, void *dummy, int arg)
{
core_server_config *conf = ap_get_module_config(cmd->server->module_config,
&core_module);
conf->merge_trailers = (arg ? AP_MERGE_TRAILERS_ENABLE :
AP_MERGE_TRAILERS_DISABLE);
return NULL;
}
/* Note --- ErrorDocument will now work from .htaccess files.
* The AllowOverride of Fileinfo allows webmasters to turn it off
*/
static const command_rec core_cmds[] = {
/* Old access config file commands */
AP_INIT_RAW_ARGS("<Directory", dirsection, NULL, RSRC_CONF,
"Container for directives affecting resources located in the specified "
"directories"),
AP_INIT_RAW_ARGS("<Location", urlsection, NULL, RSRC_CONF,
"Container for directives affecting resources accessed through the "
"specified URL paths"),
AP_INIT_RAW_ARGS("<VirtualHost", virtualhost_section, NULL, RSRC_CONF,
"Container to map directives to a particular virtual host, takes one or "
"more host addresses"),
AP_INIT_RAW_ARGS("<Files", filesection, NULL, OR_ALL,
"Container for directives affecting files matching specified patterns"),
AP_INIT_RAW_ARGS("<Limit", ap_limit_section, NULL, OR_LIMIT | OR_AUTHCFG,
"Container for authentication directives when accessed using specified HTTP "
"methods"),
AP_INIT_RAW_ARGS("<LimitExcept", ap_limit_section, (void*)1,
OR_LIMIT | OR_AUTHCFG,
"Container for authentication directives to be applied when any HTTP "
"method other than those specified is used to access the resource"),
AP_INIT_TAKE1("<IfModule", start_ifmod, NULL, EXEC_ON_READ | OR_ALL,
"Container for directives based on existence of specified modules"),
AP_INIT_TAKE1("<IfDefine", start_ifdefine, NULL, EXEC_ON_READ | OR_ALL,
"Container for directives based on existence of command line defines"),
AP_INIT_RAW_ARGS("<DirectoryMatch", dirsection, (void*)1, RSRC_CONF,
"Container for directives affecting resources located in the "
"specified directories"),
AP_INIT_RAW_ARGS("<LocationMatch", urlsection, (void*)1, RSRC_CONF,
"Container for directives affecting resources accessed through the "
"specified URL paths"),
AP_INIT_RAW_ARGS("<FilesMatch", filesection, (void*)1, OR_ALL,
"Container for directives affecting files matching specified patterns"),
#ifdef GPROF
AP_INIT_TAKE1("GprofDir", set_gprof_dir, NULL, RSRC_CONF,
"Directory to plop gmon.out files"),
#endif
AP_INIT_TAKE1("AddDefaultCharset", set_add_default_charset, NULL, OR_FILEINFO,
"The name of the default charset to add to any Content-Type without one or 'Off' to disable"),
AP_INIT_TAKE1("AcceptPathInfo", set_accept_path_info, NULL, OR_FILEINFO,
"Set to on or off for PATH_INFO to be accepted by handlers, or default for the per-handler preference"),
AP_INIT_TAKE12("Define", set_define, NULL, EXEC_ON_READ|ACCESS_CONF|RSRC_CONF,
"Define a variable, optionally to a value. Same as passing -D to the command line."),
AP_INIT_TAKE1("UnDefine", unset_define, NULL, EXEC_ON_READ|ACCESS_CONF|RSRC_CONF,
"Undefine the existence of a variable. Undo a Define."),
AP_INIT_RAW_ARGS("Error", generate_error, NULL, OR_ALL,
"Generate error message from within configuration"),
AP_INIT_RAW_ARGS("<If", ifsection, COND_IF, OR_ALL,
"Container for directives to be conditionally applied"),
AP_INIT_RAW_ARGS("<ElseIf", ifsection, COND_ELSEIF, OR_ALL,
"Container for directives to be conditionally applied"),
AP_INIT_RAW_ARGS("<Else", ifsection, COND_ELSE, OR_ALL,
"Container for directives to be conditionally applied"),
/* Old resource config file commands */
AP_INIT_RAW_ARGS("AccessFileName", set_access_name, NULL, RSRC_CONF,
"Name(s) of per-directory config files (default: .htaccess)"),
AP_INIT_TAKE1("DocumentRoot", set_document_root, NULL, RSRC_CONF,
"Root directory of the document tree"),
AP_INIT_TAKE2("ErrorDocument", set_error_document, NULL, OR_FILEINFO,
"Change responses for HTTP errors"),
AP_INIT_RAW_ARGS("AllowOverride", set_override, NULL, ACCESS_CONF,
"Controls what groups of directives can be configured by per-directory "
"config files"),
AP_INIT_TAKE_ARGV("AllowOverrideList", set_override_list, NULL, ACCESS_CONF,
"Controls what individual directives can be configured by per-directory "
"config files"),
AP_INIT_RAW_ARGS("Options", set_options, NULL, OR_OPTIONS,
"Set a number of attributes for a given directory"),
AP_INIT_TAKE1("DefaultType", set_default_type, NULL, OR_FILEINFO,
"the default media type for otherwise untyped files (DEPRECATED)"),
AP_INIT_RAW_ARGS("FileETag", set_etag_bits, NULL, OR_FILEINFO,
"Specify components used to construct a file's ETag"),
AP_INIT_TAKE1("EnableMMAP", set_enable_mmap, NULL, OR_FILEINFO,
"Controls whether memory-mapping may be used to read files"),
AP_INIT_TAKE1("EnableSendfile", set_enable_sendfile, NULL, OR_FILEINFO,
"Controls whether sendfile may be used to transmit files"),
/* Old server config file commands */
AP_INIT_TAKE1("Protocol", set_protocol, NULL, RSRC_CONF,
"Set the Protocol for httpd to use."),
AP_INIT_TAKE2("AcceptFilter", set_accf_map, NULL, RSRC_CONF,
"Set the Accept Filter to use for a protocol"),
AP_INIT_TAKE1("Port", ap_set_deprecated, NULL, RSRC_CONF,
"Port was replaced with Listen in Apache 2.0"),
AP_INIT_TAKE1("HostnameLookups", set_hostname_lookups, NULL,
ACCESS_CONF|RSRC_CONF,
"\"on\" to enable, \"off\" to disable reverse DNS lookups, or \"double\" to "
"enable double-reverse DNS lookups"),
AP_INIT_TAKE1("ServerAdmin", set_server_string_slot,
(void *)APR_OFFSETOF(server_rec, server_admin), RSRC_CONF,
"The email address of the server administrator"),
AP_INIT_TAKE1("ServerName", server_hostname_port, NULL, RSRC_CONF,
"The hostname and port of the server"),
AP_INIT_TAKE1("ServerSignature", set_signature_flag, NULL, OR_ALL,
"En-/disable server signature (on|off|email)"),
AP_INIT_TAKE1("ServerRoot", set_server_root, NULL, RSRC_CONF | EXEC_ON_READ,
"Common directory of server-related files (logs, confs, etc.)"),
AP_INIT_TAKE1("DefaultRuntimeDir", set_runtime_dir, NULL, RSRC_CONF | EXEC_ON_READ,
"Common directory for run-time files (shared memory, locks, etc.)"),
AP_INIT_TAKE1("ErrorLog", set_server_string_slot,
(void *)APR_OFFSETOF(server_rec, error_fname), RSRC_CONF,
"The filename of the error log"),
AP_INIT_TAKE12("ErrorLogFormat", set_errorlog_format, NULL, RSRC_CONF,
"Format string for the ErrorLog"),
AP_INIT_RAW_ARGS("ServerAlias", set_server_alias, NULL, RSRC_CONF,
"A name or names alternately used to access the server"),
AP_INIT_TAKE1("ServerPath", set_serverpath, NULL, RSRC_CONF,
"The pathname the server can be reached at"),
AP_INIT_TAKE1("Timeout", set_timeout, NULL, RSRC_CONF,
"Timeout duration (sec)"),
AP_INIT_FLAG("ContentDigest", set_content_md5, NULL, OR_OPTIONS,
"whether or not to send a Content-MD5 header with each request"),
AP_INIT_TAKE1("UseCanonicalName", set_use_canonical_name, NULL,
RSRC_CONF|ACCESS_CONF,
"How to work out the ServerName : Port when constructing URLs"),
AP_INIT_TAKE1("UseCanonicalPhysicalPort", set_use_canonical_phys_port, NULL,
RSRC_CONF|ACCESS_CONF,
"Whether to use the physical Port when constructing URLs"),
/* TODO: RlimitFoo should all be part of mod_cgi, not in the core */
/* TODO: ListenBacklog in MPM */
AP_INIT_TAKE1("Include", include_config, NULL,
(RSRC_CONF | ACCESS_CONF | EXEC_ON_READ),
"Name(s) of the config file(s) to be included; fails if the wildcard does "
"not match at least one file"),
AP_INIT_TAKE1("IncludeOptional", include_config, (void*)1,
(RSRC_CONF | ACCESS_CONF | EXEC_ON_READ),
"Name or pattern of the config file(s) to be included; ignored if the file "
"does not exist or the pattern does not match any files"),
AP_INIT_ITERATE("LogLevel", set_loglevel, NULL, RSRC_CONF|ACCESS_CONF,
"Level of verbosity in error logging"),
AP_INIT_TAKE1("NameVirtualHost", ap_set_name_virtual_host, NULL, RSRC_CONF,
"A numeric IP address:port, or the name of a host"),
AP_INIT_TAKE1("ServerTokens", set_serv_tokens, NULL, RSRC_CONF,
"Determine tokens displayed in the Server: header - Min(imal), "
"Major, Minor, Prod(uctOnly), OS, or Full"),
AP_INIT_TAKE1("LimitRequestLine", set_limit_req_line, NULL, RSRC_CONF,
"Limit on maximum size of an HTTP request line"),
AP_INIT_TAKE1("LimitRequestFieldsize", set_limit_req_fieldsize, NULL,
RSRC_CONF,
"Limit on maximum size of an HTTP request header field"),
AP_INIT_TAKE1("LimitRequestFields", set_limit_req_fields, NULL, RSRC_CONF,
"Limit (0 = unlimited) on max number of header fields in a request message"),
AP_INIT_TAKE1("LimitRequestBody", set_limit_req_body,
(void*)APR_OFFSETOF(core_dir_config, limit_req_body), OR_ALL,
"Limit (in bytes) on maximum size of request message body"),
AP_INIT_TAKE1("LimitXMLRequestBody", set_limit_xml_req_body, NULL, OR_ALL,
"Limit (in bytes) on maximum size of an XML-based request "
"body"),
AP_INIT_RAW_ARGS("Mutex", ap_set_mutex, NULL, RSRC_CONF,
"mutex (or \"default\") and mechanism"),
AP_INIT_TAKE1("MaxRanges", set_max_ranges, NULL, RSRC_CONF|ACCESS_CONF,
"Maximum number of Ranges in a request before returning the entire "
"resource, or 0 for unlimited"),
AP_INIT_TAKE1("MaxRangeOverlaps", set_max_overlaps, NULL, RSRC_CONF|ACCESS_CONF,
"Maximum number of overlaps in Ranges in a request before returning the entire "
"resource, or 0 for unlimited"),
AP_INIT_TAKE1("MaxRangeReversals", set_max_reversals, NULL, RSRC_CONF|ACCESS_CONF,
"Maximum number of reversals in Ranges in a request before returning the entire "
"resource, or 0 for unlimited"),
/* System Resource Controls */
#ifdef RLIMIT_CPU
AP_INIT_TAKE12("RLimitCPU", set_limit_cpu,
(void*)APR_OFFSETOF(core_dir_config, limit_cpu),
OR_ALL, "Soft/hard limits for max CPU usage in seconds"),
#else
AP_INIT_TAKE12("RLimitCPU", no_set_limit, NULL,
OR_ALL, "Soft/hard limits for max CPU usage in seconds"),
#endif
#if defined (RLIMIT_DATA) || defined (RLIMIT_VMEM) || defined (RLIMIT_AS)
AP_INIT_TAKE12("RLimitMEM", set_limit_mem,
(void*)APR_OFFSETOF(core_dir_config, limit_mem),
OR_ALL, "Soft/hard limits for max memory usage per process"),
#else
AP_INIT_TAKE12("RLimitMEM", no_set_limit, NULL,
OR_ALL, "Soft/hard limits for max memory usage per process"),
#endif
#ifdef RLIMIT_NPROC
AP_INIT_TAKE12("RLimitNPROC", set_limit_nproc,
(void*)APR_OFFSETOF(core_dir_config, limit_nproc),
OR_ALL, "soft/hard limits for max number of processes per uid"),
#else
AP_INIT_TAKE12("RLimitNPROC", no_set_limit, NULL,
OR_ALL, "soft/hard limits for max number of processes per uid"),
#endif
/* internal recursion stopper */
AP_INIT_TAKE12("LimitInternalRecursion", set_recursion_limit, NULL, RSRC_CONF,
"maximum recursion depth of internal redirects and subrequests"),
AP_INIT_FLAG("CGIPassAuth", set_cgi_pass_auth, NULL, OR_AUTHCFG,
"Controls whether HTTP authorization headers, normally hidden, will "
"be passed to scripts"),
AP_INIT_TAKE2("CGIVar", set_cgi_var, NULL, OR_FILEINFO,
"Controls how some CGI variables are set"),
AP_INIT_FLAG("QualifyRedirectURL", set_qualify_redirect_url, NULL, OR_FILEINFO,
"Controls whether HTTP authorization headers, normally hidden, will "
"be passed to scripts"),
AP_INIT_TAKE1("ForceType", ap_set_string_slot_lower,
(void *)APR_OFFSETOF(core_dir_config, mime_type), OR_FILEINFO,
"a mime type that overrides other configured type"),
AP_INIT_TAKE1("SetHandler", set_sethandler, NULL, OR_FILEINFO,
"a handler name that overrides any other configured handler"),
AP_INIT_TAKE1("SetOutputFilter", ap_set_string_slot,
(void *)APR_OFFSETOF(core_dir_config, output_filters), OR_FILEINFO,
"filter (or ; delimited list of filters) to be run on the request content"),
AP_INIT_TAKE1("SetInputFilter", ap_set_string_slot,
(void *)APR_OFFSETOF(core_dir_config, input_filters), OR_FILEINFO,
"filter (or ; delimited list of filters) to be run on the request body"),
AP_INIT_TAKE1("AllowEncodedSlashes", set_allow2f, NULL, RSRC_CONF,
"Allow URLs containing '/' encoded as '%2F'"),
/* scoreboard.c directives */
AP_INIT_TAKE1("ScoreBoardFile", ap_set_scoreboard, NULL, RSRC_CONF,
"A file for Apache to maintain runtime process management information"),
AP_INIT_FLAG("ExtendedStatus", ap_set_extended_status, NULL, RSRC_CONF,
"\"On\" to track extended status information, \"Off\" to disable"),
AP_INIT_FLAG("SeeRequestTail", ap_set_reqtail, NULL, RSRC_CONF,
"For extended status, \"On\" to see the last 63 chars of "
"the request line, \"Off\" (default) to see the first 63"),
/*
* These are default configuration directives that mpms can/should
* pay attention to.
* XXX These are not for all platforms, and even some Unix MPMs might not want
* some directives.
*/
AP_INIT_TAKE1("PidFile", ap_mpm_set_pidfile, NULL, RSRC_CONF,
"A file for logging the server process ID"),
AP_INIT_TAKE1("MaxRequestsPerChild", ap_mpm_set_max_requests, NULL, RSRC_CONF,
"Maximum number of connections a particular child serves before "
"dying. (DEPRECATED, use MaxConnectionsPerChild)"),
AP_INIT_TAKE1("MaxConnectionsPerChild", ap_mpm_set_max_requests, NULL, RSRC_CONF,
"Maximum number of connections a particular child serves before dying."),
AP_INIT_TAKE1("CoreDumpDirectory", ap_mpm_set_coredumpdir, NULL, RSRC_CONF,
"The location of the directory Apache changes to before dumping core"),
AP_INIT_TAKE1("MaxMemFree", ap_mpm_set_max_mem_free, NULL, RSRC_CONF,
"Maximum number of 1k blocks a particular child's allocator may hold."),
AP_INIT_TAKE1("ThreadStackSize", ap_mpm_set_thread_stacksize, NULL, RSRC_CONF,
"Size in bytes of stack used by threads handling client connections"),
#if AP_ENABLE_EXCEPTION_HOOK
AP_INIT_TAKE1("EnableExceptionHook", ap_mpm_set_exception_hook, NULL, RSRC_CONF,
"Controls whether exception hook may be called after a crash"),
#endif
AP_INIT_TAKE1("TraceEnable", set_trace_enable, NULL, RSRC_CONF,
"'on' (default), 'off' or 'extended' to trace request body content"),
AP_INIT_FLAG("MergeTrailers", set_merge_trailers, NULL, RSRC_CONF,
"merge request trailers into request headers or not"),
AP_INIT_ITERATE("Protocols", set_protocols, NULL, RSRC_CONF,
"Controls which protocols are allowed"),
AP_INIT_TAKE1("ProtocolsHonorOrder", set_protocols_honor_order, NULL, RSRC_CONF,
"'off' (default) or 'on' to respect given order of protocols, "
"by default the client specified order determines selection"),
AP_INIT_ITERATE("HttpProtocolOptions", set_http_protocol_options, NULL, RSRC_CONF,
"'Allow0.9' or 'Require1.0' (default); "
"'RegisteredMethods' or 'LenientMethods' (default); "
"'Unsafe' or 'Strict' (default). Sets HTTP acceptance rules"),
AP_INIT_ITERATE("RegisterHttpMethod", set_http_method, NULL, RSRC_CONF,
"Registers non-standard HTTP methods"),
{ NULL }
};
/*****************************************************************
*
* Core handlers for various phases of server operation...
*/
AP_DECLARE_NONSTD(int) ap_core_translate(request_rec *r)
{
apr_status_t rv;
char *path;
/* XXX this seems too specific, this should probably become
* some general-case test
*/
if (r->proxyreq) {
return HTTP_FORBIDDEN;
}
if (!r->uri || ((r->uri[0] != '/') && strcmp(r->uri, "*"))) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00126)
"Invalid URI in request %s", r->the_request);
return HTTP_BAD_REQUEST;
}
if (r->server->path
&& !strncmp(r->uri, r->server->path, r->server->pathlen)
&& (r->server->path[r->server->pathlen - 1] == '/'
|| r->uri[r->server->pathlen] == '/'
|| r->uri[r->server->pathlen] == '\0'))
{
path = r->uri + r->server->pathlen;
}
else {
path = r->uri;
}
/*
* Make sure that we do not mess up the translation by adding two
* /'s in a row. This happens under windows when the document
* root ends with a /
*/
/* skip all leading /'s (e.g. http://localhost///foo)
* so we are looking at only the relative path.
*/
while (*path == '/') {
++path;
}
if ((rv = apr_filepath_merge(&r->filename, ap_document_root(r), path,
APR_FILEPATH_TRUENAME
| APR_FILEPATH_SECUREROOT, r->pool))
!= APR_SUCCESS) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(00127)
"Cannot map %s to file", r->the_request);
return HTTP_FORBIDDEN;
}
r->canonical_filename = r->filename;
return OK;
}
/*****************************************************************
*
* Test the filesystem name through directory_walk and file_walk
*/
static int core_map_to_storage(request_rec *r)
{
int access_status;
if ((access_status = ap_directory_walk(r))) {
return access_status;
}
if ((access_status = ap_file_walk(r))) {
return access_status;
}
return OK;
}
static int do_nothing(request_rec *r) { return OK; }
static int core_override_type(request_rec *r)
{
core_dir_config *conf =
(core_dir_config *)ap_get_core_module_config(r->per_dir_config);
/* Check for overrides with ForceType / SetHandler
*/
if (conf->mime_type && strcmp(conf->mime_type, "none"))
ap_set_content_type(r, (char*) conf->mime_type);
if (conf->expr_handler) {
const char *err;
const char *val;
val = ap_expr_str_exec(r, conf->expr_handler, &err);
if (err) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(03154)
"Can't evaluate handler expression: %s", err);
return HTTP_INTERNAL_SERVER_ERROR;
}
if (val != ap_strstr_c(val, "proxy:unix")) {
/* Retained for compatibility -- but not for UDS */
char *tmp = apr_pstrdup(r->pool, val);
ap_str_tolower(tmp);
val = tmp;
}
if (strcmp(val, "none")) {
r->handler = val;
}
}
else if (conf->handler && strcmp(conf->handler, "none")) {
r->handler = conf->handler;
}
/* Deal with the poor soul who is trying to force path_info to be
* accepted within the core_handler, where they will let the subreq
* address its contents. This is toggled by the user in the very
* beginning of the fixup phase (here!), so modules should override the user's
* discretion in their own module fixup phase. It is tristate, if
* the user doesn't specify, the result is AP_REQ_DEFAULT_PATH_INFO.
* (which the module may interpret to its own customary behavior.)
* It won't be touched if the value is no longer AP_ACCEPT_PATHINFO_UNSET,
* so any module changing the value prior to the fixup phase
* OVERRIDES the user's choice.
*/
if ((r->used_path_info == AP_REQ_DEFAULT_PATH_INFO)
&& (conf->accept_path_info != AP_ACCEPT_PATHINFO_UNSET)) {
/* No module knew better, and the user coded AcceptPathInfo */
r->used_path_info = conf->accept_path_info;
}
return OK;
}
static int default_handler(request_rec *r)
{
conn_rec *c = r->connection;
apr_bucket_brigade *bb;
apr_bucket *e;
core_dir_config *d;
int errstatus;
apr_file_t *fd = NULL;
apr_status_t status;
/* XXX if/when somebody writes a content-md5 filter we either need to
* remove this support or coordinate when to use the filter vs.
* when to use this code
* The current choice of when to compute the md5 here matches the 1.3
* support fairly closely (unlike 1.3, we don't handle computing md5
* when the charset is translated).
*/
int bld_content_md5;
d = (core_dir_config *)ap_get_core_module_config(r->per_dir_config);
bld_content_md5 = (d->content_md5 == AP_CONTENT_MD5_ON)
&& r->output_filters->frec->ftype != AP_FTYPE_RESOURCE;
ap_allow_standard_methods(r, MERGE_ALLOW, M_GET, M_OPTIONS, M_POST, -1);
/* If filters intend to consume the request body, they must
* register an InputFilter to slurp the contents of the POST
* data from the POST input stream. It no longer exists when
* the output filters are invoked by the default handler.
*/
if ((errstatus = ap_discard_request_body(r)) != OK) {
return errstatus;
}
if (r->method_number == M_GET || r->method_number == M_POST) {
if (r->finfo.filetype == APR_NOFILE) {
ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(00128)
"File does not exist: %s",
apr_pstrcat(r->pool, r->filename, r->path_info, NULL));
return HTTP_NOT_FOUND;
}
/* Don't try to serve a dir. Some OSs do weird things with
* raw I/O on a dir.
*/
if (r->finfo.filetype == APR_DIR) {
ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(00129)
"Attempt to serve directory: %s", r->filename);
return HTTP_NOT_FOUND;
}
if ((r->used_path_info != AP_REQ_ACCEPT_PATH_INFO) &&
r->path_info && *r->path_info)
{
/* default to reject */
ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(00130)
"File does not exist: %s",
apr_pstrcat(r->pool, r->filename, r->path_info, NULL));
return HTTP_NOT_FOUND;
}
/* We understood the (non-GET) method, but it might not be legal for
this particular resource. Check to see if the 'deliver_script'
flag is set. If so, then we go ahead and deliver the file since
it isn't really content (only GET normally returns content).
Note: based on logic further above, the only possible non-GET
method at this point is POST. In the future, we should enable
script delivery for all methods. */
if (r->method_number != M_GET) {
core_request_config *req_cfg;
req_cfg = ap_get_core_module_config(r->request_config);
if (!req_cfg->deliver_script) {
/* The flag hasn't been set for this request. Punt. */
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00131)
"This resource does not accept the %s method.",
r->method);
return HTTP_METHOD_NOT_ALLOWED;
}
}
if ((status = apr_file_open(&fd, r->filename, APR_READ | APR_BINARY
#if APR_HAS_SENDFILE
| AP_SENDFILE_ENABLED(d->enable_sendfile)
#endif
, 0, r->pool)) != APR_SUCCESS) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00132)
"file permissions deny server access: %s", r->filename);
return HTTP_FORBIDDEN;
}
ap_update_mtime(r, r->finfo.mtime);
ap_set_last_modified(r);
ap_set_etag(r);
ap_set_accept_ranges(r);
ap_set_content_length(r, r->finfo.size);
if (bld_content_md5) {
apr_table_setn(r->headers_out, "Content-MD5",
ap_md5digest(r->pool, fd));
}
bb = apr_brigade_create(r->pool, c->bucket_alloc);
if ((errstatus = ap_meets_conditions(r)) != OK) {
apr_file_close(fd);
r->status = errstatus;
}
else {
e = apr_brigade_insert_file(bb, fd, 0, r->finfo.size, r->pool);
#if APR_HAS_MMAP
if (d->enable_mmap == ENABLE_MMAP_OFF) {
(void)apr_bucket_file_enable_mmap(e, 0);
}
#endif
}
e = apr_bucket_eos_create(c->bucket_alloc);
APR_BRIGADE_INSERT_TAIL(bb, e);
status = ap_pass_brigade(r->output_filters, bb);
if (status == APR_SUCCESS
|| r->status != HTTP_OK
|| c->aborted) {
return OK;
}
else {
/* no way to know what type of error occurred */
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, APLOGNO(00133)
"default_handler: ap_pass_brigade returned %i",
status);
return AP_FILTER_ERROR;
}
}
else { /* unusual method (not GET or POST) */
if (r->method_number == M_INVALID) {
/* See if this looks like an undecrypted SSL handshake attempt.
* It's safe to look a couple bytes into the_request if it exists, as it's
* always allocated at least MIN_LINE_ALLOC (80) bytes.
*/
if (r->the_request
&& r->the_request[0] == 0x16
&& (r->the_request[1] == 0x2 || r->the_request[1] == 0x3)) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00134)
"Invalid method in request %s - possible attempt to establish SSL connection on non-SSL port", r->the_request);
} else {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00135)
"Invalid method in request %s", r->the_request);
}
return HTTP_NOT_IMPLEMENTED;
}
if (r->method_number == M_OPTIONS) {
return ap_send_http_options(r);
}
return HTTP_METHOD_NOT_ALLOWED;
}
}
/* Optional function coming from mod_logio, used for logging of output
* traffic
*/
APR_OPTIONAL_FN_TYPE(ap_logio_add_bytes_out) *ap__logio_add_bytes_out;
APR_OPTIONAL_FN_TYPE(authz_some_auth_required) *ap__authz_ap_some_auth_required;
/* Insist that at least one module will undertake to provide system
* security by dropping startup privileges.
*/
static int sys_privileges = 0;
AP_DECLARE(int) ap_sys_privileges_handlers(int inc)
{
sys_privileges += inc;
return sys_privileges;
}
static int check_errorlog_dir(apr_pool_t *p, server_rec *s)
{
if (!s->error_fname || s->error_fname[0] == '|'
|| strcmp(s->error_fname, "syslog") == 0) {
return APR_SUCCESS;
}
else {
char *abs = ap_server_root_relative(p, s->error_fname);
char *dir = ap_make_dirstr_parent(p, abs);
apr_finfo_t finfo;
apr_status_t rv = apr_stat(&finfo, dir, APR_FINFO_TYPE, p);
if (rv == APR_SUCCESS && finfo.filetype != APR_DIR)
rv = APR_ENOTDIR;
if (rv != APR_SUCCESS) {
const char *desc = "main error log";
if (s->defn_name)
desc = apr_psprintf(p, "error log of vhost defined at %s:%d",
s->defn_name, s->defn_line_number);
ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_EMERG, rv,
ap_server_conf, APLOGNO(02291)
"Cannot access directory '%s' for %s", dir, desc);
return !OK;
}
}
return OK;
}
static int core_check_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
{
int rv = OK;
while (s) {
if (check_errorlog_dir(ptemp, s) != OK)
rv = !OK;
s = s->next;
}
return rv;
}
static int core_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp)
{
ap_mutex_init(pconf);
if (!saved_server_config_defines)
init_config_defines(pconf);
apr_pool_cleanup_register(pconf, NULL, reset_config_defines,
apr_pool_cleanup_null);
mpm_common_pre_config(pconf);
return OK;
}
static int core_post_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
{
ap__logio_add_bytes_out = APR_RETRIEVE_OPTIONAL_FN(ap_logio_add_bytes_out);
ident_lookup = APR_RETRIEVE_OPTIONAL_FN(ap_ident_lookup);
ap__authz_ap_some_auth_required = APR_RETRIEVE_OPTIONAL_FN(authz_some_auth_required);
authn_ap_auth_type = APR_RETRIEVE_OPTIONAL_FN(authn_ap_auth_type);
authn_ap_auth_name = APR_RETRIEVE_OPTIONAL_FN(authn_ap_auth_name);
access_compat_ap_satisfies = APR_RETRIEVE_OPTIONAL_FN(access_compat_ap_satisfies);
set_banner(pconf);
ap_setup_make_content_type(pconf);
ap_setup_auth_internal(ptemp);
if (!sys_privileges) {
ap_log_error(APLOG_MARK, APLOG_CRIT, 0, NULL, APLOGNO(00136)
"Server MUST relinquish startup privileges before "
"accepting connections. Please ensure mod_unixd "
"or other system security module is loaded.");
return !OK;
}
apr_pool_cleanup_register(pconf, NULL, ap_mpm_end_gen_helper,
apr_pool_cleanup_null);
return OK;
}
static void core_insert_filter(request_rec *r)
{
core_dir_config *conf = (core_dir_config *)
ap_get_core_module_config(r->per_dir_config);
const char *filter, *filters = conf->output_filters;
if (filters) {
while (*filters && (filter = ap_getword(r->pool, &filters, ';'))) {
ap_add_output_filter(filter, NULL, r, r->connection);
}
}
filters = conf->input_filters;
if (filters) {
while (*filters && (filter = ap_getword(r->pool, &filters, ';'))) {
ap_add_input_filter(filter, NULL, r, r->connection);
}
}
}
static apr_size_t num_request_notes = AP_NUM_STD_NOTES;
static apr_status_t reset_request_notes(void *dummy)
{
num_request_notes = AP_NUM_STD_NOTES;
return APR_SUCCESS;
}
AP_DECLARE(apr_size_t) ap_register_request_note(void)
{
apr_pool_cleanup_register(apr_hook_global_pool, NULL, reset_request_notes,
apr_pool_cleanup_null);
return num_request_notes++;
}
AP_DECLARE(void **) ap_get_request_note(request_rec *r, apr_size_t note_num)
{
core_request_config *req_cfg;
if (note_num >= num_request_notes) {
return NULL;
}
req_cfg = (core_request_config *)
ap_get_core_module_config(r->request_config);
if (!req_cfg) {
return NULL;
}
return &(req_cfg->notes[note_num]);
}
AP_DECLARE(apr_socket_t *) ap_get_conn_socket(conn_rec *c)
{
return ap_get_core_module_config(c->conn_config);
}
static int core_create_req(request_rec *r)
{
/* Alloc the config struct and the array of request notes in
* a single block for efficiency
*/
core_request_config *req_cfg;
req_cfg = apr_pcalloc(r->pool, sizeof(core_request_config) +
sizeof(void *) * num_request_notes);
req_cfg->notes = (void **)((char *)req_cfg + sizeof(core_request_config));
/* ### temporarily enable script delivery as the default */
req_cfg->deliver_script = 1;
if (r->main) {
core_request_config *main_req_cfg = (core_request_config *)
ap_get_core_module_config(r->main->request_config);
req_cfg->bb = main_req_cfg->bb;
}
else {
req_cfg->bb = apr_brigade_create(r->pool, r->connection->bucket_alloc);
}
ap_set_core_module_config(r->request_config, req_cfg);
return OK;
}
static int core_create_proxy_req(request_rec *r, request_rec *pr)
{
return core_create_req(pr);
}
static conn_rec *core_create_conn(apr_pool_t *ptrans, server_rec *server,
apr_socket_t *csd, long id, void *sbh,
apr_bucket_alloc_t *alloc)
{
apr_status_t rv;
conn_rec *c = (conn_rec *) apr_pcalloc(ptrans, sizeof(conn_rec));
c->sbh = sbh;
ap_update_child_status(c->sbh, SERVER_BUSY_READ, NULL);
/* Got a connection structure, so initialize what fields we can
* (the rest are zeroed out by pcalloc).
*/
c->conn_config = ap_create_conn_config(ptrans);
c->notes = apr_table_make(ptrans, 5);
c->pool = ptrans;
if ((rv = apr_socket_addr_get(&c->local_addr, APR_LOCAL, csd))
!= APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_INFO, rv, server, APLOGNO(00137)
"apr_socket_addr_get(APR_LOCAL)");
apr_socket_close(csd);