8 #include "configparser.h"
9 #include "configfile.h"
10 #include "proc_open.h"
25 static int config_insert(server
*srv
) {
28 buffer
*stat_cache_string
;
30 config_values_t cv
[] = {
31 { "server.bind", NULL
, T_CONFIG_STRING
, T_CONFIG_SCOPE_SERVER
}, /* 0 */
32 { "server.errorlog", NULL
, T_CONFIG_STRING
, T_CONFIG_SCOPE_SERVER
}, /* 1 */
33 { "server.errorfile-prefix", NULL
, T_CONFIG_STRING
, T_CONFIG_SCOPE_CONNECTION
}, /* 2 */
34 { "server.chroot", NULL
, T_CONFIG_STRING
, T_CONFIG_SCOPE_SERVER
}, /* 3 */
35 { "server.username", NULL
, T_CONFIG_STRING
, T_CONFIG_SCOPE_SERVER
}, /* 4 */
36 { "server.groupname", NULL
, T_CONFIG_STRING
, T_CONFIG_SCOPE_SERVER
}, /* 5 */
37 { "server.port", NULL
, T_CONFIG_SHORT
, T_CONFIG_SCOPE_SERVER
}, /* 6 */
38 { "server.tag", NULL
, T_CONFIG_STRING
, T_CONFIG_SCOPE_CONNECTION
}, /* 7 */
39 { "server.use-ipv6", NULL
, T_CONFIG_BOOLEAN
, T_CONFIG_SCOPE_CONNECTION
}, /* 8 */
40 { "server.modules", NULL
, T_CONFIG_ARRAY
, T_CONFIG_SCOPE_SERVER
}, /* 9 */
42 { "server.event-handler", NULL
, T_CONFIG_STRING
, T_CONFIG_SCOPE_SERVER
}, /* 10 */
43 { "server.pid-file", NULL
, T_CONFIG_STRING
, T_CONFIG_SCOPE_SERVER
}, /* 11 */
44 { "server.max-request-size", NULL
, T_CONFIG_INT
, T_CONFIG_SCOPE_SERVER
}, /* 12 */
45 { "server.max-worker", NULL
, T_CONFIG_SHORT
, T_CONFIG_SCOPE_SERVER
}, /* 13 */
46 { "server.document-root", NULL
, T_CONFIG_STRING
, T_CONFIG_SCOPE_CONNECTION
}, /* 14 */
47 { "server.force-lowercase-filenames", NULL
, T_CONFIG_BOOLEAN
, T_CONFIG_SCOPE_CONNECTION
}, /* 15 */
48 { "debug.log-condition-handling", NULL
, T_CONFIG_BOOLEAN
, T_CONFIG_SCOPE_CONNECTION
}, /* 16 */
49 { "server.max-keep-alive-requests", NULL
, T_CONFIG_SHORT
, T_CONFIG_SCOPE_CONNECTION
}, /* 17 */
50 { "server.name", NULL
, T_CONFIG_STRING
, T_CONFIG_SCOPE_CONNECTION
}, /* 18 */
51 { "server.max-keep-alive-idle", NULL
, T_CONFIG_SHORT
, T_CONFIG_SCOPE_CONNECTION
}, /* 19 */
53 { "server.max-read-idle", NULL
, T_CONFIG_SHORT
, T_CONFIG_SCOPE_CONNECTION
}, /* 20 */
54 { "server.max-write-idle", NULL
, T_CONFIG_SHORT
, T_CONFIG_SCOPE_CONNECTION
}, /* 21 */
55 { "server.error-handler-404", NULL
, T_CONFIG_STRING
, T_CONFIG_SCOPE_CONNECTION
}, /* 22 */
56 { "server.max-fds", NULL
, T_CONFIG_SHORT
, T_CONFIG_SCOPE_SERVER
}, /* 23 */
58 { "server.follow-symlink", NULL
, T_CONFIG_BOOLEAN
, T_CONFIG_SCOPE_CONNECTION
}, /* 24 */
60 { "server.follow-symlink",
61 "Your system lacks lstat(). We can not differ symlinks from files."
62 "Please remove server.follow-symlinks from your config.",
63 T_CONFIG_UNSUPPORTED
, T_CONFIG_SCOPE_UNSET
},
65 { "server.kbytes-per-second", NULL
, T_CONFIG_SHORT
, T_CONFIG_SCOPE_CONNECTION
}, /* 25 */
66 { "connection.kbytes-per-second", NULL
, T_CONFIG_SHORT
, T_CONFIG_SCOPE_CONNECTION
}, /* 26 */
67 { "mimetype.use-xattr", NULL
, T_CONFIG_BOOLEAN
, T_CONFIG_SCOPE_CONNECTION
}, /* 27 */
68 { "mimetype.assign", NULL
, T_CONFIG_ARRAY
, T_CONFIG_SCOPE_CONNECTION
}, /* 28 */
69 { "ssl.pemfile", NULL
, T_CONFIG_STRING
, T_CONFIG_SCOPE_CONNECTION
}, /* 29 */
71 { "ssl.engine", NULL
, T_CONFIG_BOOLEAN
, T_CONFIG_SCOPE_CONNECTION
}, /* 30 */
72 { "debug.log-file-not-found", NULL
, T_CONFIG_BOOLEAN
, T_CONFIG_SCOPE_CONNECTION
}, /* 31 */
73 { "debug.log-request-handling", NULL
, T_CONFIG_BOOLEAN
, T_CONFIG_SCOPE_CONNECTION
}, /* 32 */
74 { "debug.log-response-header", NULL
, T_CONFIG_BOOLEAN
, T_CONFIG_SCOPE_CONNECTION
}, /* 33 */
75 { "debug.log-request-header", NULL
, T_CONFIG_BOOLEAN
, T_CONFIG_SCOPE_CONNECTION
}, /* 34 */
76 { "debug.log-ssl-noise", NULL
, T_CONFIG_BOOLEAN
, T_CONFIG_SCOPE_CONNECTION
}, /* 35 */
77 { "server.protocol-http11", NULL
, T_CONFIG_BOOLEAN
, T_CONFIG_SCOPE_CONNECTION
}, /* 36 */
78 { "debug.log-request-header-on-error", NULL
, T_CONFIG_BOOLEAN
, T_CONFIG_SCOPE_SERVER
}, /* 37 */
79 { "debug.log-state-handling", NULL
, T_CONFIG_BOOLEAN
, T_CONFIG_SCOPE_SERVER
}, /* 38 */
80 { "ssl.ca-file", NULL
, T_CONFIG_STRING
, T_CONFIG_SCOPE_CONNECTION
}, /* 39 */
82 { "server.errorlog-use-syslog", NULL
, T_CONFIG_BOOLEAN
, T_CONFIG_SCOPE_SERVER
}, /* 40 */
83 { "server.range-requests", NULL
, T_CONFIG_BOOLEAN
, T_CONFIG_SCOPE_CONNECTION
}, /* 41 */
84 { "server.stat-cache-engine", NULL
, T_CONFIG_STRING
, T_CONFIG_SCOPE_SERVER
}, /* 42 */
85 { "server.max-connections", NULL
, T_CONFIG_SHORT
, T_CONFIG_SCOPE_SERVER
}, /* 43 */
86 { "server.network-backend", NULL
, T_CONFIG_STRING
, T_CONFIG_SCOPE_SERVER
}, /* 44 */
87 { "server.upload-dirs", NULL
, T_CONFIG_ARRAY
, T_CONFIG_SCOPE_SERVER
}, /* 45 */
88 { "server.core-files", NULL
, T_CONFIG_BOOLEAN
, T_CONFIG_SCOPE_SERVER
}, /* 46 */
89 { "ssl.cipher-list", NULL
, T_CONFIG_STRING
, T_CONFIG_SCOPE_CONNECTION
}, /* 47 */
90 { "ssl.use-sslv2", NULL
, T_CONFIG_BOOLEAN
, T_CONFIG_SCOPE_CONNECTION
}, /* 48 */
91 { "etag.use-inode", NULL
, T_CONFIG_BOOLEAN
, T_CONFIG_SCOPE_CONNECTION
}, /* 49 */
93 { "etag.use-mtime", NULL
, T_CONFIG_BOOLEAN
, T_CONFIG_SCOPE_CONNECTION
}, /* 50 */
94 { "etag.use-size", NULL
, T_CONFIG_BOOLEAN
, T_CONFIG_SCOPE_CONNECTION
}, /* 51 */
95 { "server.reject-expect-100-with-417", NULL
, T_CONFIG_BOOLEAN
, T_CONFIG_SCOPE_SERVER
}, /* 52 */
96 { "debug.log-timeouts", NULL
, T_CONFIG_BOOLEAN
, T_CONFIG_SCOPE_CONNECTION
}, /* 53 */
97 { "server.defer-accept", NULL
, T_CONFIG_SHORT
, T_CONFIG_SCOPE_CONNECTION
}, /* 54 */
98 { "server.breakagelog", NULL
, T_CONFIG_STRING
, T_CONFIG_SCOPE_SERVER
}, /* 55 */
99 { "ssl.verifyclient.activate", NULL
, T_CONFIG_BOOLEAN
, T_CONFIG_SCOPE_CONNECTION
}, /* 56 */
100 { "ssl.verifyclient.enforce", NULL
, T_CONFIG_BOOLEAN
, T_CONFIG_SCOPE_CONNECTION
}, /* 57 */
101 { "ssl.verifyclient.depth", NULL
, T_CONFIG_SHORT
, T_CONFIG_SCOPE_CONNECTION
}, /* 58 */
102 { "ssl.verifyclient.username", NULL
, T_CONFIG_STRING
, T_CONFIG_SCOPE_CONNECTION
}, /* 59 */
104 { "ssl.verifyclient.exportcert", NULL
, T_CONFIG_BOOLEAN
, T_CONFIG_SCOPE_CONNECTION
}, /* 60 */
105 { "server.set-v6only", NULL
, T_CONFIG_BOOLEAN
, T_CONFIG_SCOPE_CONNECTION
}, /* 61 */
106 { "ssl.use-sslv3", NULL
, T_CONFIG_BOOLEAN
, T_CONFIG_SCOPE_CONNECTION
}, /* 62 */
107 { "ssl.dh-file", NULL
, T_CONFIG_STRING
, T_CONFIG_SCOPE_CONNECTION
}, /* 63 */
108 { "ssl.ec-curve", NULL
, T_CONFIG_STRING
, T_CONFIG_SCOPE_CONNECTION
}, /* 64 */
109 { "ssl.disable-client-renegotiation", NULL
, T_CONFIG_BOOLEAN
, T_CONFIG_SCOPE_CONNECTION
}, /* 65 */
110 { "ssl.honor-cipher-order", NULL
, T_CONFIG_BOOLEAN
, T_CONFIG_SCOPE_CONNECTION
}, /* 66 */
111 { "ssl.empty-fragments", NULL
, T_CONFIG_BOOLEAN
, T_CONFIG_SCOPE_CONNECTION
}, /* 67 */
112 { "server.upload-temp-file-size", NULL
, T_CONFIG_INT
, T_CONFIG_SCOPE_SERVER
}, /* 68 */
115 "use server.bind instead",
116 T_CONFIG_DEPRECATED
, T_CONFIG_SCOPE_UNSET
},
118 "use server.document-root instead",
119 T_CONFIG_DEPRECATED
, T_CONFIG_SCOPE_UNSET
},
120 { "server.virtual-root",
121 "load mod_simple_vhost and use simple-vhost.server-root instead",
122 T_CONFIG_DEPRECATED
, T_CONFIG_SCOPE_UNSET
},
123 { "server.virtual-default-host",
124 "load mod_simple_vhost and use simple-vhost.default-host instead",
125 T_CONFIG_DEPRECATED
, T_CONFIG_SCOPE_UNSET
},
126 { "server.virtual-docroot",
127 "load mod_simple_vhost and use simple-vhost.document-root instead",
128 T_CONFIG_DEPRECATED
, T_CONFIG_SCOPE_UNSET
},
130 "use server.username instead",
131 T_CONFIG_DEPRECATED
, T_CONFIG_SCOPE_UNSET
},
133 "use server.groupname instead",
134 T_CONFIG_DEPRECATED
, T_CONFIG_SCOPE_UNSET
},
135 { "server.use-keep-alive",
136 "use server.max-keep-alive-requests = 0 instead",
137 T_CONFIG_DEPRECATED
, T_CONFIG_SCOPE_UNSET
},
138 { "server.force-lower-case-files",
139 "use server.force-lowercase-filenames instead",
140 T_CONFIG_DEPRECATED
, T_CONFIG_SCOPE_UNSET
},
142 { NULL
, NULL
, T_CONFIG_UNSET
, T_CONFIG_SCOPE_UNSET
}
145 /* all T_CONFIG_SCOPE_SERVER options */
146 cv
[0].destination
= srv
->srvconf
.bindhost
;
147 cv
[1].destination
= srv
->srvconf
.errorlog_file
;
148 cv
[3].destination
= srv
->srvconf
.changeroot
;
149 cv
[4].destination
= srv
->srvconf
.username
;
150 cv
[5].destination
= srv
->srvconf
.groupname
;
151 cv
[6].destination
= &(srv
->srvconf
.port
);
152 cv
[9].destination
= srv
->srvconf
.modules
;
154 cv
[10].destination
= srv
->srvconf
.event_handler
;
155 cv
[11].destination
= srv
->srvconf
.pid_file
;
156 cv
[12].destination
= &(srv
->srvconf
.max_request_size
);
157 cv
[13].destination
= &(srv
->srvconf
.max_worker
);
159 cv
[23].destination
= &(srv
->srvconf
.max_fds
);
161 cv
[37].destination
= &(srv
->srvconf
.log_request_header_on_error
);
162 cv
[38].destination
= &(srv
->srvconf
.log_state_handling
);
164 cv
[40].destination
= &(srv
->srvconf
.errorlog_use_syslog
);
165 stat_cache_string
= buffer_init();
166 cv
[42].destination
= stat_cache_string
;
167 cv
[43].destination
= &(srv
->srvconf
.max_conns
);
168 cv
[44].destination
= srv
->srvconf
.network_backend
;
169 cv
[45].destination
= srv
->srvconf
.upload_tempdirs
;
170 cv
[46].destination
= &(srv
->srvconf
.enable_cores
);
172 cv
[52].destination
= &(srv
->srvconf
.reject_expect_100_with_417
);
173 cv
[55].destination
= srv
->srvconf
.breakagelog_file
;
175 cv
[68].destination
= &(srv
->srvconf
.upload_temp_file_size
);
177 srv
->config_storage
= calloc(1, srv
->config_context
->used
* sizeof(specific_config
*));
179 force_assert(srv
->config_storage
);
181 for (i
= 0; i
< srv
->config_context
->used
; i
++) {
182 data_config
const* config
= (data_config
const*)srv
->config_context
->data
[i
];
185 s
= calloc(1, sizeof(specific_config
));
187 s
->document_root
= buffer_init();
188 s
->mimetypes
= array_init();
189 s
->server_name
= buffer_init();
190 s
->ssl_pemfile
= buffer_init();
191 s
->ssl_ca_file
= buffer_init();
192 s
->error_handler
= buffer_init();
193 s
->server_tag
= buffer_init();
194 s
->ssl_cipher_list
= buffer_init();
195 s
->ssl_dh_file
= buffer_init();
196 s
->ssl_ec_curve
= buffer_init();
197 s
->errorfile_prefix
= buffer_init();
198 s
->max_keep_alive_requests
= 16;
199 s
->max_keep_alive_idle
= 5;
200 s
->max_read_idle
= 60;
201 s
->max_write_idle
= 360;
204 s
->ssl_honor_cipher_order
= 1;
205 s
->ssl_empty_fragments
= 0;
206 s
->ssl_use_sslv2
= 0;
207 s
->ssl_use_sslv3
= 0;
212 s
->follow_symlink
= 1;
214 s
->kbytes_per_second
= 0;
216 s
->etag_use_inode
= 1;
217 s
->etag_use_mtime
= 1;
218 s
->etag_use_size
= 1;
219 s
->range_requests
= 1;
220 s
->force_lowercase_filenames
= (i
== 0) ? 2 : 0; /* we wan't to detect later if user changed this for global section */
221 s
->global_kbytes_per_second
= 0;
222 s
->global_bytes_per_second_cnt
= 0;
223 s
->global_bytes_per_second_cnt_ptr
= &s
->global_bytes_per_second_cnt
;
224 s
->ssl_verifyclient
= 0;
225 s
->ssl_verifyclient_enforce
= 1;
226 s
->ssl_verifyclient_username
= buffer_init();
227 s
->ssl_verifyclient_depth
= 9;
228 s
->ssl_verifyclient_export_cert
= 0;
229 s
->ssl_disable_client_renegotiation
= 1;
231 /* all T_CONFIG_SCOPE_CONNECTION options */
232 cv
[2].destination
= s
->errorfile_prefix
;
233 cv
[7].destination
= s
->server_tag
;
234 cv
[8].destination
= &(s
->use_ipv6
);
236 cv
[14].destination
= s
->document_root
;
237 cv
[15].destination
= &(s
->force_lowercase_filenames
);
238 cv
[16].destination
= &(s
->log_condition_handling
);
239 cv
[17].destination
= &(s
->max_keep_alive_requests
);
240 cv
[18].destination
= s
->server_name
;
241 cv
[19].destination
= &(s
->max_keep_alive_idle
);
243 cv
[20].destination
= &(s
->max_read_idle
);
244 cv
[21].destination
= &(s
->max_write_idle
);
245 cv
[22].destination
= s
->error_handler
;
247 cv
[24].destination
= &(s
->follow_symlink
);
249 cv
[25].destination
= &(s
->global_kbytes_per_second
);
250 cv
[26].destination
= &(s
->kbytes_per_second
);
251 cv
[27].destination
= &(s
->use_xattr
);
252 cv
[28].destination
= s
->mimetypes
;
253 cv
[29].destination
= s
->ssl_pemfile
;
255 cv
[30].destination
= &(s
->ssl_enabled
);
256 cv
[31].destination
= &(s
->log_file_not_found
);
257 cv
[32].destination
= &(s
->log_request_handling
);
258 cv
[33].destination
= &(s
->log_response_header
);
259 cv
[34].destination
= &(s
->log_request_header
);
260 cv
[35].destination
= &(s
->log_ssl_noise
);
261 cv
[36].destination
= &(s
->allow_http11
);
262 cv
[39].destination
= s
->ssl_ca_file
;
264 cv
[41].destination
= &(s
->range_requests
);
265 cv
[47].destination
= s
->ssl_cipher_list
;
266 cv
[48].destination
= &(s
->ssl_use_sslv2
);
267 cv
[49].destination
= &(s
->etag_use_inode
);
269 cv
[50].destination
= &(s
->etag_use_mtime
);
270 cv
[51].destination
= &(s
->etag_use_size
);
271 cv
[53].destination
= &(s
->log_timeouts
);
272 cv
[54].destination
= &(s
->defer_accept
);
273 cv
[56].destination
= &(s
->ssl_verifyclient
);
274 cv
[57].destination
= &(s
->ssl_verifyclient_enforce
);
275 cv
[58].destination
= &(s
->ssl_verifyclient_depth
);
276 cv
[59].destination
= s
->ssl_verifyclient_username
;
278 cv
[60].destination
= &(s
->ssl_verifyclient_export_cert
);
279 cv
[61].destination
= &(s
->set_v6only
);
280 cv
[62].destination
= &(s
->ssl_use_sslv3
);
281 cv
[63].destination
= s
->ssl_dh_file
;
282 cv
[64].destination
= s
->ssl_ec_curve
;
283 cv
[65].destination
= &(s
->ssl_disable_client_renegotiation
);
284 cv
[66].destination
= &(s
->ssl_honor_cipher_order
);
285 cv
[67].destination
= &(s
->ssl_empty_fragments
);
287 srv
->config_storage
[i
] = s
;
289 if (0 != (ret
= config_insert_values_global(srv
, config
->value
, cv
, i
== 0 ? T_CONFIG_SCOPE_SERVER
: T_CONFIG_SCOPE_CONNECTION
))) {
294 if (buffer_string_is_empty(stat_cache_string
)) {
295 srv
->srvconf
.stat_cache_engine
= STAT_CACHE_ENGINE_SIMPLE
;
296 } else if (buffer_is_equal_string(stat_cache_string
, CONST_STR_LEN("simple"))) {
297 srv
->srvconf
.stat_cache_engine
= STAT_CACHE_ENGINE_SIMPLE
;
299 } else if (buffer_is_equal_string(stat_cache_string
, CONST_STR_LEN("fam"))) {
300 srv
->srvconf
.stat_cache_engine
= STAT_CACHE_ENGINE_FAM
;
302 } else if (buffer_is_equal_string(stat_cache_string
, CONST_STR_LEN("disable"))) {
303 srv
->srvconf
.stat_cache_engine
= STAT_CACHE_ENGINE_NONE
;
305 log_error_write(srv
, __FILE__
, __LINE__
, "sb",
306 "server.stat-cache-engine can be one of \"disable\", \"simple\","
310 " but not:", stat_cache_string
);
314 buffer_free(stat_cache_string
);
321 #define PATCH(x) con->conf.x = s->x
322 int config_setup_connection(server
*srv
, connection
*con
) {
323 specific_config
*s
= srv
->config_storage
[0];
327 PATCH(document_root
);
328 PATCH(max_keep_alive_requests
);
329 PATCH(max_keep_alive_idle
);
330 PATCH(max_read_idle
);
331 PATCH(max_write_idle
);
333 PATCH(error_handler
);
334 PATCH(errorfile_prefix
);
336 PATCH(follow_symlink
);
339 PATCH(kbytes_per_second
);
340 PATCH(global_kbytes_per_second
);
341 PATCH(global_bytes_per_second_cnt
);
343 con
->conf
.global_bytes_per_second_cnt_ptr
= &s
->global_bytes_per_second_cnt
;
344 buffer_copy_buffer(con
->server_name
, s
->server_name
);
346 PATCH(log_request_header
);
347 PATCH(log_response_header
);
348 PATCH(log_request_handling
);
349 PATCH(log_condition_handling
);
350 PATCH(log_file_not_found
);
351 PATCH(log_ssl_noise
);
354 PATCH(range_requests
);
355 PATCH(force_lowercase_filenames
);
360 PATCH(ssl_pemfile_x509
);
361 PATCH(ssl_pemfile_pkey
);
365 PATCH(ssl_ca_file_cert_names
);
367 PATCH(ssl_cipher_list
);
370 PATCH(ssl_honor_cipher_order
);
371 PATCH(ssl_empty_fragments
);
372 PATCH(ssl_use_sslv2
);
373 PATCH(ssl_use_sslv3
);
374 PATCH(etag_use_inode
);
375 PATCH(etag_use_mtime
);
376 PATCH(etag_use_size
);
378 PATCH(ssl_verifyclient
);
379 PATCH(ssl_verifyclient_enforce
);
380 PATCH(ssl_verifyclient_depth
);
381 PATCH(ssl_verifyclient_username
);
382 PATCH(ssl_verifyclient_export_cert
);
383 PATCH(ssl_disable_client_renegotiation
);
388 int config_patch_connection(server
*srv
, connection
*con
) {
391 /* skip the first, the global context */
392 for (i
= 1; i
< srv
->config_context
->used
; i
++) {
393 data_config
*dc
= (data_config
*)srv
->config_context
->data
[i
];
394 specific_config
*s
= srv
->config_storage
[i
];
396 /* condition didn't match */
397 if (!config_check_cond(srv
, con
, dc
)) continue;
400 for (j
= 0; j
< dc
->value
->used
; j
++) {
401 data_unset
*du
= dc
->value
->data
[j
];
403 if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("server.document-root"))) {
404 PATCH(document_root
);
405 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("server.range-requests"))) {
406 PATCH(range_requests
);
407 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("server.error-handler-404"))) {
408 PATCH(error_handler
);
409 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("server.errorfile-prefix"))) {
410 PATCH(errorfile_prefix
);
411 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("mimetype.assign"))) {
413 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("server.max-keep-alive-requests"))) {
414 PATCH(max_keep_alive_requests
);
415 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("server.max-keep-alive-idle"))) {
416 PATCH(max_keep_alive_idle
);
417 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("server.max-write-idle"))) {
418 PATCH(max_write_idle
);
419 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("server.max-read-idle"))) {
420 PATCH(max_read_idle
);
421 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("mimetype.use-xattr"))) {
423 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("etag.use-inode"))) {
424 PATCH(etag_use_inode
);
425 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("etag.use-mtime"))) {
426 PATCH(etag_use_mtime
);
427 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("etag.use-size"))) {
428 PATCH(etag_use_size
);
429 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("ssl.pemfile"))) {
432 PATCH(ssl_pemfile_x509
);
433 PATCH(ssl_pemfile_pkey
);
435 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("ssl.ca-file"))) {
438 PATCH(ssl_ca_file_cert_names
);
440 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("ssl.honor-cipher-order"))) {
441 PATCH(ssl_honor_cipher_order
);
442 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("ssl.empty-fragments"))) {
443 PATCH(ssl_empty_fragments
);
444 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("ssl.use-sslv2"))) {
445 PATCH(ssl_use_sslv2
);
446 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("ssl.use-sslv3"))) {
447 PATCH(ssl_use_sslv3
);
448 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("ssl.cipher-list"))) {
449 PATCH(ssl_cipher_list
);
450 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("ssl.engine"))) {
452 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("ssl.dh-file"))) {
454 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("ssl.ec-curve"))) {
457 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("server.follow-symlink"))) {
458 PATCH(follow_symlink
);
460 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("server.name"))) {
461 buffer_copy_buffer(con
->server_name
, s
->server_name
);
462 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("server.tag"))) {
464 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("connection.kbytes-per-second"))) {
465 PATCH(kbytes_per_second
);
466 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("debug.log-request-handling"))) {
467 PATCH(log_request_handling
);
468 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("debug.log-request-header"))) {
469 PATCH(log_request_header
);
470 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("debug.log-response-header"))) {
471 PATCH(log_response_header
);
472 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("debug.log-condition-handling"))) {
473 PATCH(log_condition_handling
);
474 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("debug.log-file-not-found"))) {
475 PATCH(log_file_not_found
);
476 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("debug.log-ssl-noise"))) {
477 PATCH(log_ssl_noise
);
478 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("debug.log-timeouts"))) {
480 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("server.protocol-http11"))) {
482 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("server.force-lowercase-filenames"))) {
483 PATCH(force_lowercase_filenames
);
484 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("server.kbytes-per-second"))) {
485 PATCH(global_kbytes_per_second
);
486 PATCH(global_bytes_per_second_cnt
);
487 con
->conf
.global_bytes_per_second_cnt_ptr
= &s
->global_bytes_per_second_cnt
;
488 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("ssl.verifyclient.activate"))) {
489 PATCH(ssl_verifyclient
);
490 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("ssl.verifyclient.enforce"))) {
491 PATCH(ssl_verifyclient_enforce
);
492 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("ssl.verifyclient.depth"))) {
493 PATCH(ssl_verifyclient_depth
);
494 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("ssl.verifyclient.username"))) {
495 PATCH(ssl_verifyclient_username
);
496 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("ssl.verifyclient.exportcert"))) {
497 PATCH(ssl_verifyclient_export_cert
);
498 } else if (buffer_is_equal_string(du
->key
, CONST_STR_LEN("ssl.disable-client-renegotiation"))) {
499 PATCH(ssl_disable_client_renegotiation
);
504 con
->etag_flags
= (con
->conf
.etag_use_mtime
? ETAG_USE_MTIME
: 0) |
505 (con
->conf
.etag_use_inode
? ETAG_USE_INODE
: 0) |
506 (con
->conf
.etag_use_size
? ETAG_USE_SIZE
: 0);
516 const buffer
*source
;
530 static int tokenizer_open(server
*srv
, tokenizer_t
*t
, buffer
*basedir
, const char *fn
) {
531 if (buffer_string_is_empty(basedir
) ||
532 (fn
[0] == '/' || fn
[0] == '\\') ||
533 (fn
[0] == '.' && (fn
[1] == '/' || fn
[1] == '\\'))) {
534 t
->file
= buffer_init_string(fn
);
536 t
->file
= buffer_init_buffer(basedir
);
537 buffer_append_string(t
->file
, fn
);
540 if (0 != stream_open(&(t
->s
), t
->file
)) {
541 log_error_write(srv
, __FILE__
, __LINE__
, "sbss",
542 "opening configfile ", t
->file
, "failed:", strerror(errno
));
543 buffer_free(t
->file
);
547 t
->input
= t
->s
.start
;
559 static int tokenizer_close(server
*srv
, tokenizer_t
*t
) {
562 buffer_free(t
->file
);
563 return stream_close(&(t
->s
));
566 static int config_skip_newline(tokenizer_t
*t
) {
568 force_assert(t
->input
[t
->offset
] == '\r' || t
->input
[t
->offset
] == '\n');
569 if (t
->input
[t
->offset
] == '\r' && t
->input
[t
->offset
+ 1] == '\n') {
577 static int config_skip_comment(tokenizer_t
*t
) {
579 force_assert(t
->input
[t
->offset
] == '#');
580 for (i
= 1; t
->input
[t
->offset
+ i
] &&
581 (t
->input
[t
->offset
+ i
] != '\n' && t
->input
[t
->offset
+ i
] != '\r');
587 static int config_tokenizer(server
*srv
, tokenizer_t
*t
, int *token_id
, buffer
*token
) {
591 for (tid
= 0; tid
== 0 && t
->offset
< t
->size
&& t
->input
[t
->offset
] ; ) {
592 char c
= t
->input
[t
->offset
];
593 const char *start
= NULL
;
598 if (t
->input
[t
->offset
+ 1] == '>') {
601 buffer_copy_string_len(token
, CONST_STR_LEN("=>"));
603 tid
= TK_ARRAY_ASSIGN
;
605 log_error_write(srv
, __FILE__
, __LINE__
, "sbsdsds",
606 "source:", t
->source
,
607 "line:", t
->line
, "pos:", t
->line_pos
,
608 "use => for assignments in arrays");
611 } else if (t
->in_cond
) {
612 if (t
->input
[t
->offset
+ 1] == '=') {
615 buffer_copy_string_len(token
, CONST_STR_LEN("=="));
618 } else if (t
->input
[t
->offset
+ 1] == '~') {
621 buffer_copy_string_len(token
, CONST_STR_LEN("=~"));
625 log_error_write(srv
, __FILE__
, __LINE__
, "sbsdsds",
626 "source:", t
->source
,
627 "line:", t
->line
, "pos:", t
->line_pos
,
628 "only =~ and == are allowed in the condition");
633 } else if (t
->in_key
) {
636 buffer_copy_string_len(token
, t
->input
+ t
->offset
, 1);
641 log_error_write(srv
, __FILE__
, __LINE__
, "sbsdsds",
642 "source:", t
->source
,
643 "line:", t
->line
, "pos:", t
->line_pos
,
644 "unexpected equal-sign: =");
651 if (t
->input
[t
->offset
+ 1] == '=') {
654 buffer_copy_string_len(token
, CONST_STR_LEN("!="));
657 } else if (t
->input
[t
->offset
+ 1] == '~') {
660 buffer_copy_string_len(token
, CONST_STR_LEN("!~"));
664 log_error_write(srv
, __FILE__
, __LINE__
, "sbsdsds",
665 "source:", t
->source
,
666 "line:", t
->line
, "pos:", t
->line_pos
,
667 "only !~ and != are allowed in the condition");
673 log_error_write(srv
, __FILE__
, __LINE__
, "sbsdsds",
674 "source:", t
->source
,
675 "line:", t
->line
, "pos:", t
->line_pos
,
676 "unexpected exclamation-marks: !");
688 if (t
->in_brace
== 0) {
690 while (!done
&& t
->offset
< t
->size
) {
691 switch (t
->input
[t
->offset
]) {
694 config_skip_newline(t
);
700 t
->line_pos
+= config_skip_comment(t
);
715 buffer_copy_string_len(token
, CONST_STR_LEN("(EOL)"));
717 config_skip_newline(t
);
723 if (t
->in_brace
> 0) {
726 buffer_copy_string_len(token
, CONST_STR_LEN("(COMMA)"));
733 /* search for the terminating " */
734 start
= t
->input
+ t
->offset
+ 1;
735 buffer_copy_string_len(token
, CONST_STR_LEN(""));
737 for (i
= 1; t
->input
[t
->offset
+ i
]; i
++) {
738 if (t
->input
[t
->offset
+ i
] == '\\' &&
739 t
->input
[t
->offset
+ i
+ 1] == '"') {
741 buffer_append_string_len(token
, start
, t
->input
+ t
->offset
+ i
- start
);
743 start
= t
->input
+ t
->offset
+ i
+ 1;
751 if (t
->input
[t
->offset
+ i
] == '"') {
754 buffer_append_string_len(token
, start
, t
->input
+ t
->offset
+ i
- start
);
760 if (t
->input
[t
->offset
+ i
] == '\0') {
763 log_error_write(srv
, __FILE__
, __LINE__
, "sbsdsds",
764 "source:", t
->source
,
765 "line:", t
->line
, "pos:", t
->line_pos
,
766 "missing closing quote");
772 t
->line_pos
+= i
+ 1;
781 buffer_copy_string_len(token
, CONST_STR_LEN("("));
789 buffer_copy_string_len(token
, CONST_STR_LEN(")"));
798 buffer_copy_string_len(token
, CONST_STR_LEN("$"));
803 if (t
->input
[t
->offset
+ 1] == '=') {
805 buffer_copy_string_len(token
, CONST_STR_LEN("+="));
810 buffer_copy_string_len(token
, CONST_STR_LEN("+"));
819 buffer_copy_string_len(token
, CONST_STR_LEN("{"));
828 buffer_copy_string_len(token
, CONST_STR_LEN("}"));
837 buffer_copy_string_len(token
, CONST_STR_LEN("["));
846 buffer_copy_string_len(token
, CONST_STR_LEN("]"));
850 t
->line_pos
+= config_skip_comment(t
);
855 for (i
= 0; t
->input
[t
->offset
+ i
] &&
856 (isalpha((unsigned char)t
->input
[t
->offset
+ i
])
859 if (i
&& t
->input
[t
->offset
+ i
]) {
861 buffer_copy_string_len(token
, t
->input
+ t
->offset
, i
);
867 log_error_write(srv
, __FILE__
, __LINE__
, "sbsdsds",
868 "source:", t
->source
,
869 "line:", t
->line
, "pos:", t
->line_pos
,
870 "invalid character in condition");
873 } else if (isdigit((unsigned char)c
)) {
874 /* take all digits */
875 for (i
= 0; t
->input
[t
->offset
+ i
] && isdigit((unsigned char)t
->input
[t
->offset
+ i
]); i
++);
877 /* was there it least a digit ? */
881 buffer_copy_string_len(token
, t
->input
+ t
->offset
, i
);
887 /* the key might consist of [-.0-9a-z] */
888 for (i
= 0; t
->input
[t
->offset
+ i
] &&
889 (isalnum((unsigned char)t
->input
[t
->offset
+ i
]) ||
890 t
->input
[t
->offset
+ i
] == '.' ||
891 t
->input
[t
->offset
+ i
] == '_' || /* for env.* */
892 t
->input
[t
->offset
+ i
] == '-'
895 if (i
&& t
->input
[t
->offset
+ i
]) {
896 buffer_copy_string_len(token
, t
->input
+ t
->offset
, i
);
898 if (strcmp(token
->ptr
, "include") == 0) {
900 } else if (strcmp(token
->ptr
, "include_shell") == 0) {
901 tid
= TK_INCLUDE_SHELL
;
902 } else if (strcmp(token
->ptr
, "global") == 0) {
904 } else if (strcmp(token
->ptr
, "else") == 0) {
914 log_error_write(srv
, __FILE__
, __LINE__
, "sbsdsds",
915 "source:", t
->source
,
916 "line:", t
->line
, "pos:", t
->line_pos
,
917 "invalid character in variable name");
928 log_error_write(srv
, __FILE__
, __LINE__
, "sbsdsdbdd",
929 "source:", t
->source
,
930 "line:", t
->line
, "pos:", t
->line_pos
,
931 token
, token
->used
- 1, tid
);
935 } else if (t
->offset
< t
->size
) {
936 fprintf(stderr
, "%s.%d: %d, %s\n",
943 static int config_parse(server
*srv
, config_t
*context
, tokenizer_t
*t
) {
946 buffer
*token
, *lasttoken
;
949 pParser
= configparserAlloc( malloc
);
950 force_assert(pParser
);
951 lasttoken
= buffer_init();
952 token
= buffer_init();
953 while((1 == (ret
= config_tokenizer(srv
, t
, &token_id
, token
))) && context
->ok
) {
954 buffer_copy_buffer(lasttoken
, token
);
955 configparser(pParser
, token_id
, token
, context
);
957 token
= buffer_init();
961 if (ret
!= -1 && context
->ok
) {
962 /* add an EOL at EOF, better than say sorry */
963 configparser(pParser
, TK_EOL
, buffer_init_string("(EOL)"), context
);
965 configparser(pParser
, 0, NULL
, context
);
968 configparserFree(pParser
, free
);
971 log_error_write(srv
, __FILE__
, __LINE__
, "sb",
972 "configfile parser failed at:", lasttoken
);
973 } else if (context
->ok
== 0) {
974 log_error_write(srv
, __FILE__
, __LINE__
, "sbsdsdsb",
975 "source:", t
->source
,
976 "line:", t
->line
, "pos:", t
->line_pos
,
977 "parser failed somehow near here:", lasttoken
);
980 buffer_free(lasttoken
);
982 return ret
== -1 ? -1 : 0;
985 static int tokenizer_init(tokenizer_t
*t
, const buffer
*source
, const char *input
, size_t size
) {
1000 int config_parse_file(server
*srv
, config_t
*context
, const char *fn
) {
1006 if (buffer_string_is_empty(context
->basedir
) ||
1007 (fn
[0] == '/' || fn
[0] == '\\') ||
1008 (fn
[0] == '.' && (fn
[1] == '/' || fn
[1] == '\\'))) {
1009 filename
= buffer_init_string(fn
);
1011 filename
= buffer_init_buffer(context
->basedir
);
1012 buffer_append_string(filename
, fn
);
1015 if (0 != stream_open(&s
, filename
)) {
1016 log_error_write(srv
, __FILE__
, __LINE__
, "sbss",
1017 "opening configfile ", filename
, "failed:", strerror(errno
));
1020 tokenizer_init(&t
, filename
, s
.start
, s
.size
);
1021 ret
= config_parse(srv
, context
, &t
);
1025 buffer_free(filename
);
1029 static char* getCWD(void) {
1039 if (!s
) return NULL
;
1040 while (NULL
== getcwd(s
, len
)) {
1041 if (errno
!= ERANGE
|| SSIZE_MAX
- len
< len
) {
1046 s1
= realloc(s
, len
);
1056 int config_parse_cmd(server
*srv
, config_t
*context
, const char *cmd
) {
1063 if (NULL
== (oldpwd
= getCWD())) {
1064 log_error_write(srv
, __FILE__
, __LINE__
, "s",
1065 "cannot get cwd", strerror(errno
));
1069 if (!buffer_string_is_empty(context
->basedir
)) {
1070 if (0 != chdir(context
->basedir
->ptr
)) {
1071 log_error_write(srv
, __FILE__
, __LINE__
, "sbs",
1072 "cannot change directory to", context
->basedir
, strerror(errno
));
1078 source
= buffer_init_string(cmd
);
1079 out
= buffer_init();
1081 if (0 != proc_open_buffer(cmd
, NULL
, out
, NULL
)) {
1082 log_error_write(srv
, __FILE__
, __LINE__
, "sbss",
1083 "opening", source
, "failed:", strerror(errno
));
1086 tokenizer_init(&t
, source
, CONST_BUF_LEN(out
));
1087 ret
= config_parse(srv
, context
, &t
);
1090 buffer_free(source
);
1092 if (0 != chdir(oldpwd
)) {
1093 log_error_write(srv
, __FILE__
, __LINE__
, "sss",
1094 "cannot change directory to", oldpwd
, strerror(errno
));
1102 static void context_init(server
*srv
, config_t
*context
) {
1105 vector_config_weak_init(&context
->configs_stack
);
1106 context
->basedir
= buffer_init();
1109 static void context_free(config_t
*context
) {
1110 vector_config_weak_clear(&context
->configs_stack
);
1111 buffer_free(context
->basedir
);
1114 int config_read(server
*srv
, const char *fn
) {
1121 data_array
*modules
;
1123 context_init(srv
, &context
);
1124 context
.all_configs
= srv
->config_context
;
1127 pos
= strrchr(fn
, '\\');
1129 pos
= strrchr(fn
, '/');
1132 buffer_copy_string_len(context
.basedir
, fn
, pos
- fn
+ 1);
1136 dc
= data_config_init();
1137 buffer_copy_string_len(dc
->key
, CONST_STR_LEN("global"));
1139 force_assert(context
.all_configs
->used
== 0);
1140 dc
->context_ndx
= context
.all_configs
->used
;
1141 array_insert_unique(context
.all_configs
, (data_unset
*)dc
);
1142 context
.current
= dc
;
1144 /* default context */
1145 srv
->config
= dc
->value
;
1146 dpid
= data_integer_init();
1147 dpid
->value
= getpid();
1148 buffer_copy_string_len(dpid
->key
, CONST_STR_LEN("var.PID"));
1149 array_insert_unique(srv
->config
, (data_unset
*)dpid
);
1151 dcwd
= data_string_init();
1152 buffer_string_prepare_copy(dcwd
->value
, 1023);
1153 if (NULL
!= getcwd(dcwd
->value
->ptr
, dcwd
->value
->size
- 1)) {
1154 buffer_commit(dcwd
->value
, strlen(dcwd
->value
->ptr
));
1155 buffer_copy_string_len(dcwd
->key
, CONST_STR_LEN("var.CWD"));
1156 array_insert_unique(srv
->config
, (data_unset
*)dcwd
);
1158 dcwd
->free((data_unset
*) dcwd
);
1161 ret
= config_parse_file(srv
, &context
, fn
);
1163 /* remains nothing if parser is ok */
1164 force_assert(!(0 == ret
&& context
.ok
&& 0 != context
.configs_stack
.used
));
1165 context_free(&context
);
1171 if (NULL
!= (dc
= (data_config
*)array_get_element(srv
->config_context
, "global"))) {
1172 srv
->config
= dc
->value
;
1177 if (NULL
!= (modules
= (data_array
*)array_get_element(srv
->config
, "server.modules"))) {
1179 data_array
*prepends
;
1181 if (modules
->type
!= TYPE_ARRAY
) {
1182 fprintf(stderr
, "server.modules must be an array");
1186 prepends
= data_array_init();
1188 /* prepend default modules */
1189 if (NULL
== array_get_element(modules
->value
, "mod_indexfile")) {
1190 ds
= data_string_init();
1191 buffer_copy_string_len(ds
->value
, CONST_STR_LEN("mod_indexfile"));
1192 array_insert_unique(prepends
->value
, (data_unset
*)ds
);
1195 prepends
= (data_array
*)configparser_merge_data((data_unset
*)prepends
, (data_unset
*)modules
);
1196 force_assert(NULL
!= prepends
);
1197 buffer_copy_buffer(prepends
->key
, modules
->key
);
1198 array_replace(srv
->config
, (data_unset
*)prepends
);
1201 /* append default modules */
1202 if (NULL
== array_get_element(modules
->value
, "mod_dirlisting")) {
1203 ds
= data_string_init();
1204 buffer_copy_string_len(ds
->value
, CONST_STR_LEN("mod_dirlisting"));
1205 array_insert_unique(modules
->value
, (data_unset
*)ds
);
1208 if (NULL
== array_get_element(modules
->value
, "mod_staticfile")) {
1209 ds
= data_string_init();
1210 buffer_copy_string_len(ds
->value
, CONST_STR_LEN("mod_staticfile"));
1211 array_insert_unique(modules
->value
, (data_unset
*)ds
);
1216 modules
= data_array_init();
1218 /* server.modules is not set */
1219 ds
= data_string_init();
1220 buffer_copy_string_len(ds
->value
, CONST_STR_LEN("mod_indexfile"));
1221 array_insert_unique(modules
->value
, (data_unset
*)ds
);
1223 ds
= data_string_init();
1224 buffer_copy_string_len(ds
->value
, CONST_STR_LEN("mod_dirlisting"));
1225 array_insert_unique(modules
->value
, (data_unset
*)ds
);
1227 ds
= data_string_init();
1228 buffer_copy_string_len(ds
->value
, CONST_STR_LEN("mod_staticfile"));
1229 array_insert_unique(modules
->value
, (data_unset
*)ds
);
1231 buffer_copy_string_len(modules
->key
, CONST_STR_LEN("server.modules"));
1232 array_insert_unique(srv
->config
, (data_unset
*)modules
);
1236 if (0 != config_insert(srv
)) {
1243 int config_set_defaults(server
*srv
) {
1245 specific_config
*s
= srv
->config_storage
[0];
1246 struct stat st1
, st2
;
1248 struct ev_map
{ fdevent_handler_t et
; const char *name
; } event_handlers
[] =
1250 /* - epoll is most reliable
1251 * - select works everywhere
1253 #ifdef USE_LINUX_EPOLL
1254 { FDEVENT_HANDLER_LINUX_SYSEPOLL
, "linux-sysepoll" },
1257 { FDEVENT_HANDLER_POLL
, "poll" },
1260 { FDEVENT_HANDLER_SELECT
, "select" },
1263 { FDEVENT_HANDLER_LIBEV
, "libev" },
1265 #ifdef USE_SOLARIS_DEVPOLL
1266 { FDEVENT_HANDLER_SOLARIS_DEVPOLL
,"solaris-devpoll" },
1268 #ifdef USE_SOLARIS_PORT
1269 { FDEVENT_HANDLER_SOLARIS_PORT
, "solaris-eventports" },
1271 #ifdef USE_FREEBSD_KQUEUE
1272 { FDEVENT_HANDLER_FREEBSD_KQUEUE
, "freebsd-kqueue" },
1273 { FDEVENT_HANDLER_FREEBSD_KQUEUE
, "kqueue" },
1275 { FDEVENT_HANDLER_UNSET
, NULL
}
1278 if (!buffer_string_is_empty(srv
->srvconf
.changeroot
)) {
1279 if (-1 == stat(srv
->srvconf
.changeroot
->ptr
, &st1
)) {
1280 log_error_write(srv
, __FILE__
, __LINE__
, "sb",
1281 "server.chroot doesn't exist:", srv
->srvconf
.changeroot
);
1284 if (!S_ISDIR(st1
.st_mode
)) {
1285 log_error_write(srv
, __FILE__
, __LINE__
, "sb",
1286 "server.chroot isn't a directory:", srv
->srvconf
.changeroot
);
1291 if (buffer_string_is_empty(s
->document_root
)) {
1292 log_error_write(srv
, __FILE__
, __LINE__
, "s",
1293 "a default document-root has to be set");
1298 buffer_copy_buffer(srv
->tmp_buf
, s
->document_root
);
1300 buffer_to_lower(srv
->tmp_buf
);
1302 if (2 == s
->force_lowercase_filenames
) { /* user didn't configure it in global section? */
1303 s
->force_lowercase_filenames
= 0; /* default to 0 */
1305 if (0 == stat(srv
->tmp_buf
->ptr
, &st1
)) {
1308 is_lower
= buffer_is_equal(srv
->tmp_buf
, s
->document_root
);
1310 /* lower-case existed, check upper-case */
1311 buffer_copy_buffer(srv
->tmp_buf
, s
->document_root
);
1313 buffer_to_upper(srv
->tmp_buf
);
1315 /* we have to handle the special case that upper and lower-casing results in the same filename
1316 * as in server.document-root = "/" or "/12345/" */
1318 if (is_lower
&& buffer_is_equal(srv
->tmp_buf
, s
->document_root
)) {
1319 /* lower-casing and upper-casing didn't result in
1320 * an other filename, no need to stat(),
1321 * just assume it is case-sensitive. */
1323 s
->force_lowercase_filenames
= 0;
1324 } else if (0 == stat(srv
->tmp_buf
->ptr
, &st2
)) {
1326 /* upper case exists too, doesn't the FS handle this ? */
1328 /* upper and lower have the same inode -> case-insensitve FS */
1330 if (st1
.st_ino
== st2
.st_ino
) {
1331 /* upper and lower have the same inode -> case-insensitve FS */
1333 s
->force_lowercase_filenames
= 1;
1339 if (srv
->srvconf
.port
== 0) {
1340 srv
->srvconf
.port
= s
->ssl_enabled
? 443 : 80;
1343 if (buffer_string_is_empty(srv
->srvconf
.event_handler
)) {
1344 /* choose a good default
1346 * the event_handler list is sorted by 'goodness'
1347 * taking the first available should be the best solution
1349 srv
->event_handler
= event_handlers
[0].et
;
1351 if (FDEVENT_HANDLER_UNSET
== srv
->event_handler
) {
1352 log_error_write(srv
, __FILE__
, __LINE__
, "s",
1353 "sorry, there is no event handler for this system");
1362 for (i
= 0; event_handlers
[i
].name
; i
++) {
1363 if (0 == strcmp(event_handlers
[i
].name
, srv
->srvconf
.event_handler
->ptr
)) {
1364 srv
->event_handler
= event_handlers
[i
].et
;
1369 if (FDEVENT_HANDLER_UNSET
== srv
->event_handler
) {
1370 log_error_write(srv
, __FILE__
, __LINE__
, "sb",
1371 "the selected event-handler in unknown or not supported:",
1372 srv
->srvconf
.event_handler
);
1378 if (s
->ssl_enabled
) {
1379 if (buffer_string_is_empty(s
->ssl_pemfile
)) {
1380 /* PEM file is require */
1382 log_error_write(srv
, __FILE__
, __LINE__
, "s",
1383 "ssl.pemfile has to be set");
1388 log_error_write(srv
, __FILE__
, __LINE__
, "s",
1389 "ssl support is missing, recompile with --with-openssl");