diff options
author | Arno Töll <arno@debian.org> | 2012-11-21 23:03:52 +0100 |
---|---|---|
committer | Arno Töll <arno@debian.org> | 2012-11-21 23:03:52 +0100 |
commit | 36c2c9520cdf4e725d0597eaa28c350087f1d3c0 (patch) | |
tree | 9337d6a9fac555f4391cf529a6a3c805db0b6d3a /src/configfile.c | |
parent | f1532bfdd56dc641ae366f6ecd4c490c11117aac (diff) | |
download | lighttpd-36c2c9520cdf4e725d0597eaa28c350087f1d3c0.tar.gz |
Imported Upstream version 1.4.22upstream/1.4.22
Diffstat (limited to 'src/configfile.c')
-rw-r--r-- | src/configfile.c | 185 |
1 files changed, 108 insertions, 77 deletions
diff --git a/src/configfile.c b/src/configfile.c index 09fe87d..e45db85 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -7,6 +7,7 @@ #include <string.h> #include <stdio.h> #include <ctype.h> +#include <limits.h> #include <assert.h> #include "server.h" @@ -74,24 +75,27 @@ static int config_insert(server *srv) { { "debug.log-request-handling", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 32 */ { "debug.log-response-header", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 33 */ { "debug.log-request-header", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 34 */ - - { "server.protocol-http11", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 35 */ - { "debug.log-request-header-on-error", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 36 */ - { "debug.log-state-handling", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 37 */ - { "ssl.ca-file", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER }, /* 38 */ - - { "server.errorlog-use-syslog", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 39 */ - { "server.range-requests", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 40 */ - { "server.stat-cache-engine", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 41 */ - { "server.max-connections", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_SERVER }, /* 42 */ - { "server.network-backend", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 43 */ - { "server.upload-dirs", NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION }, /* 44 */ - { "server.core-files", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 45 */ - { "ssl.cipher-list", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER }, /* 46 */ - { "ssl.use-sslv2", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 47 */ - { "etag.use-inode", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 48 */ - { "etag.use-mtime", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 49 */ - { "etag.use-size", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 50 */ + { "debug.log-ssl-noise", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 35 */ + + { "server.protocol-http11", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 36 */ + { "debug.log-request-header-on-error", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 37 */ + { "debug.log-state-handling", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 38 */ + { "ssl.ca-file", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER }, /* 39 */ + + { "server.errorlog-use-syslog", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 40 */ + { "server.range-requests", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 41 */ + { "server.stat-cache-engine", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 42 */ + { "server.max-connections", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_SERVER }, /* 43 */ + { "server.network-backend", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 44 */ + { "server.upload-dirs", NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION }, /* 45 */ + { "server.core-files", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 46 */ + { "ssl.cipher-list", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER }, /* 47 */ + { "ssl.use-sslv2", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 48 */ + { "etag.use-inode", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 49 */ + { "etag.use-mtime", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 50 */ + { "etag.use-size", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 51 */ + { "server.reject-expect-100-with-417", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 52 */ + { "debug.log-timeouts", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 53 */ { "server.host", "use server.bind instead", T_CONFIG_DEPRECATED, T_CONFIG_SCOPE_UNSET }, { "server.docroot", "use server.document-root instead", T_CONFIG_DEPRECATED, T_CONFIG_SCOPE_UNSET }, { "server.virtual-root", "load mod_simple_vhost and use simple-vhost.server-root instead", T_CONFIG_DEPRECATED, T_CONFIG_SCOPE_UNSET }, @@ -120,19 +124,20 @@ static int config_insert(server *srv) { cv[13].destination = &(srv->srvconf.max_worker); cv[23].destination = &(srv->srvconf.max_fds); - cv[36].destination = &(srv->srvconf.log_request_header_on_error); - cv[37].destination = &(srv->srvconf.log_state_handling); + cv[37].destination = &(srv->srvconf.log_request_header_on_error); + cv[38].destination = &(srv->srvconf.log_state_handling); - cv[39].destination = &(srv->srvconf.errorlog_use_syslog); + cv[40].destination = &(srv->srvconf.errorlog_use_syslog); stat_cache_string = buffer_init(); - cv[41].destination = stat_cache_string; - cv[43].destination = srv->srvconf.network_backend; - cv[44].destination = srv->srvconf.upload_tempdirs; - cv[45].destination = &(srv->srvconf.enable_cores); + cv[42].destination = stat_cache_string; + cv[44].destination = srv->srvconf.network_backend; + cv[45].destination = srv->srvconf.upload_tempdirs; + cv[46].destination = &(srv->srvconf.enable_cores); - cv[42].destination = &(srv->srvconf.max_conns); + cv[43].destination = &(srv->srvconf.max_conns); cv[12].destination = &(srv->srvconf.max_request_size); + cv[52].destination = &(srv->srvconf.reject_expect_100_with_417); srv->config_storage = calloc(1, srv->config_context->used * sizeof(specific_config *)); assert(srv->config_storage); @@ -157,7 +162,7 @@ static int config_insert(server *srv) { s->max_write_idle = 360; s->use_xattr = 0; s->is_ssl = 0; - s->ssl_use_sslv2 = 1; + s->ssl_use_sslv2 = 0; s->use_ipv6 = 0; #ifdef HAVE_LSTAT s->follow_symlink = 1; @@ -204,16 +209,18 @@ static int config_insert(server *srv) { cv[32].destination = &(s->log_request_handling); cv[33].destination = &(s->log_response_header); cv[34].destination = &(s->log_request_header); + cv[35].destination = &(s->log_ssl_noise); + cv[53].destination = &(s->log_timeouts); - cv[35].destination = &(s->allow_http11); - cv[38].destination = s->ssl_ca_file; - cv[40].destination = &(s->range_requests); + cv[36].destination = &(s->allow_http11); + cv[39].destination = s->ssl_ca_file; + cv[41].destination = &(s->range_requests); - cv[46].destination = s->ssl_cipher_list; - cv[47].destination = &(s->ssl_use_sslv2); - cv[48].destination = &(s->etag_use_inode); - cv[49].destination = &(s->etag_use_mtime); - cv[50].destination = &(s->etag_use_size); + cv[47].destination = s->ssl_cipher_list; + cv[48].destination = &(s->ssl_use_sslv2); + cv[49].destination = &(s->etag_use_inode); + cv[50].destination = &(s->etag_use_mtime); + cv[51].destination = &(s->etag_use_size); srv->config_storage[i] = s; @@ -279,6 +286,7 @@ int config_setup_connection(server *srv, connection *con) { PATCH(log_request_handling); PATCH(log_condition_handling); PATCH(log_file_not_found); + PATCH(log_ssl_noise); PATCH(range_requests); PATCH(force_lowercase_filenames); @@ -305,9 +313,6 @@ int config_patch_connection(server *srv, connection *con, comp_key_t comp) { data_config *dc = (data_config *)srv->config_context->data[i]; specific_config *s = srv->config_storage[i]; - /* not our stage */ - if (comp != dc->comp) continue; - /* condition didn't match */ if (!config_check_cond(srv, con, dc)) continue; @@ -371,6 +376,10 @@ int config_patch_connection(server *srv, connection *con, comp_key_t comp) { PATCH(log_condition_handling); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("debug.log-file-not-found"))) { PATCH(log_file_not_found); + } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("debug.log-ssl-noise"))) { + PATCH(log_ssl_noise); + } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("debug.log-timeouts"))) { + PATCH(log_timeouts); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("server.protocol-http11"))) { PATCH(allow_http11); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("server.force-lowercase-filenames"))) { @@ -410,8 +419,8 @@ typedef struct { #if 0 static int tokenizer_open(server *srv, tokenizer_t *t, buffer *basedir, const char *fn) { - if (buffer_is_empty(basedir) && - (fn[0] == '/' || fn[0] == '\\') && + if (buffer_is_empty(basedir) || + (fn[0] == '/' || fn[0] == '\\') || (fn[0] == '.' && (fn[1] == '/' || fn[1] == '\\'))) { t->file = buffer_init_string(fn); } else { @@ -480,7 +489,7 @@ static int config_tokenizer(server *srv, tokenizer_t *t, int *token_id, buffer * if (t->input[t->offset + 1] == '>') { t->offset += 2; - buffer_copy_string(token, "=>"); + buffer_copy_string_len(token, CONST_STR_LEN("=>")); tid = TK_ARRAY_ASSIGN; } else { @@ -494,13 +503,13 @@ static int config_tokenizer(server *srv, tokenizer_t *t, int *token_id, buffer * if (t->input[t->offset + 1] == '=') { t->offset += 2; - buffer_copy_string(token, "=="); + buffer_copy_string_len(token, CONST_STR_LEN("==")); tid = TK_EQ; } else if (t->input[t->offset + 1] == '~') { t->offset += 2; - buffer_copy_string(token, "=~"); + buffer_copy_string_len(token, CONST_STR_LEN("=~")); tid = TK_MATCH; } else { @@ -533,13 +542,13 @@ static int config_tokenizer(server *srv, tokenizer_t *t, int *token_id, buffer * if (t->input[t->offset + 1] == '=') { t->offset += 2; - buffer_copy_string(token, "!="); + buffer_copy_string_len(token, CONST_STR_LEN("!=")); tid = TK_NE; } else if (t->input[t->offset + 1] == '~') { t->offset += 2; - buffer_copy_string(token, "!~"); + buffer_copy_string_len(token, CONST_STR_LEN("!~")); tid = TK_NOMATCH; } else { @@ -594,7 +603,7 @@ static int config_tokenizer(server *srv, tokenizer_t *t, int *token_id, buffer * } t->in_key = 1; tid = TK_EOL; - buffer_copy_string(token, "(EOL)"); + buffer_copy_string_len(token, CONST_STR_LEN("(EOL)")); } else { config_skip_newline(t); t->line_pos = 1; @@ -605,7 +614,7 @@ static int config_tokenizer(server *srv, tokenizer_t *t, int *token_id, buffer * if (t->in_brace > 0) { tid = TK_COMMA; - buffer_copy_string(token, "(COMMA)"); + buffer_copy_string_len(token, CONST_STR_LEN("(COMMA)")); } t->offset++; @@ -614,7 +623,7 @@ static int config_tokenizer(server *srv, tokenizer_t *t, int *token_id, buffer * case '"': /* search for the terminating " */ start = t->input + t->offset + 1; - buffer_copy_string(token, ""); + buffer_copy_string_len(token, CONST_STR_LEN("")); for (i = 1; t->input[t->offset + i]; i++) { if (t->input[t->offset + i] == '\\' && @@ -660,7 +669,7 @@ static int config_tokenizer(server *srv, tokenizer_t *t, int *token_id, buffer * tid = TK_LPARAN; - buffer_copy_string(token, "("); + buffer_copy_string_len(token, CONST_STR_LEN("(")); break; case ')': t->offset++; @@ -668,7 +677,7 @@ static int config_tokenizer(server *srv, tokenizer_t *t, int *token_id, buffer * tid = TK_RPARAN; - buffer_copy_string(token, ")"); + buffer_copy_string_len(token, CONST_STR_LEN(")")); break; case '$': t->offset++; @@ -677,19 +686,19 @@ static int config_tokenizer(server *srv, tokenizer_t *t, int *token_id, buffer * t->in_cond = 1; t->in_key = 0; - buffer_copy_string(token, "$"); + buffer_copy_string_len(token, CONST_STR_LEN("$")); break; case '+': if (t->input[t->offset + 1] == '=') { t->offset += 2; - buffer_copy_string(token, "+="); + buffer_copy_string_len(token, CONST_STR_LEN("+=")); tid = TK_APPEND; } else { t->offset++; tid = TK_PLUS; - buffer_copy_string(token, "+"); + buffer_copy_string_len(token, CONST_STR_LEN("+")); } break; @@ -698,7 +707,7 @@ static int config_tokenizer(server *srv, tokenizer_t *t, int *token_id, buffer * tid = TK_LCURLY; - buffer_copy_string(token, "{"); + buffer_copy_string_len(token, CONST_STR_LEN("{")); break; @@ -707,7 +716,7 @@ static int config_tokenizer(server *srv, tokenizer_t *t, int *token_id, buffer * tid = TK_RCURLY; - buffer_copy_string(token, "}"); + buffer_copy_string_len(token, CONST_STR_LEN("}")); break; @@ -716,7 +725,7 @@ static int config_tokenizer(server *srv, tokenizer_t *t, int *token_id, buffer * tid = TK_LBRACKET; - buffer_copy_string(token, "["); + buffer_copy_string_len(token, CONST_STR_LEN("[")); break; @@ -725,7 +734,7 @@ static int config_tokenizer(server *srv, tokenizer_t *t, int *token_id, buffer * tid = TK_RBRACKET; - buffer_copy_string(token, "]"); + buffer_copy_string_len(token, CONST_STR_LEN("]")); break; case '#': @@ -884,8 +893,8 @@ int config_parse_file(server *srv, config_t *context, const char *fn) { int ret; buffer *filename; - if (buffer_is_empty(context->basedir) && - (fn[0] == '/' || fn[0] == '\\') && + if (buffer_is_empty(context->basedir) || + (fn[0] == '/' || fn[0] == '\\') || (fn[0] == '.' && (fn[1] == '/' || fn[1] == '\\'))) { filename = buffer_init_string(fn); } else { @@ -912,15 +921,38 @@ int config_parse_file(server *srv, config_t *context, const char *fn) { return ret; } +static char* getCWD() { + char *s, *s1; + size_t len; +#ifdef PATH_MAX + len = PATH_MAX; +#else + len = 4096; +#endif + + s = malloc(len); + if (!s) return NULL; + while (NULL == getcwd(s, len)) { + if (errno != ERANGE || SSIZE_MAX - len < len) return NULL; + len *= 2; + s1 = realloc(s, len); + if (!s1) { + free(s); + return NULL; + } + s = s1; + } + return s; +} + int config_parse_cmd(server *srv, config_t *context, const char *cmd) { - proc_handler_t proc; tokenizer_t t; int ret; buffer *source; buffer *out; - char oldpwd[PATH_MAX]; + char *oldpwd; - if (NULL == getcwd(oldpwd, sizeof(oldpwd))) { + if (NULL == (oldpwd = getCWD())) { log_error_write(srv, __FILE__, __LINE__, "s", "cannot get cwd", strerror(errno)); return -1; @@ -933,7 +965,7 @@ int config_parse_cmd(server *srv, config_t *context, const char *cmd) { chdir(context->basedir->ptr); } - if (0 != proc_open_buffer(&proc, cmd, NULL, out, NULL)) { + if (0 != proc_open_buffer(cmd, NULL, out, NULL)) { log_error_write(srv, __FILE__, __LINE__, "sbss", "opening", source, "failed:", strerror(errno)); ret = -1; @@ -945,6 +977,7 @@ int config_parse_cmd(server *srv, config_t *context, const char *cmd) { buffer_free(source); buffer_free(out); chdir(oldpwd); + free(oldpwd); return ret; } @@ -973,20 +1006,18 @@ int config_read(server *srv, const char *fn) { context_init(srv, &context); context.all_configs = srv->config_context; - pos = strrchr(fn, #ifdef __WIN32 - '\\' + pos = strrchr(fn, '\\'); #else - '/' + pos = strrchr(fn, '/'); #endif - ); if (pos) { buffer_copy_string_len(context.basedir, fn, pos - fn + 1); fn = pos + 1; } dc = data_config_init(); - buffer_copy_string(dc->key, "global"); + buffer_copy_string_len(dc->key, CONST_STR_LEN("global")); assert(context.all_configs->used == 0); dc->context_ndx = context.all_configs->used; @@ -997,14 +1028,14 @@ int config_read(server *srv, const char *fn) { srv->config = dc->value; dpid = data_integer_init(); dpid->value = getpid(); - buffer_copy_string(dpid->key, "var.PID"); + buffer_copy_string_len(dpid->key, CONST_STR_LEN("var.PID")); array_insert_unique(srv->config, (data_unset *)dpid); dcwd = data_string_init(); buffer_prepare_copy(dcwd->value, 1024); if (NULL != getcwd(dcwd->value->ptr, dcwd->value->size - 1)) { dcwd->value->used = strlen(dcwd->value->ptr) + 1; - buffer_copy_string(dcwd->key, "var.CWD"); + buffer_copy_string_len(dcwd->key, CONST_STR_LEN("var.CWD")); array_insert_unique(srv->config, (data_unset *)dcwd); } @@ -1038,7 +1069,7 @@ int config_read(server *srv, const char *fn) { /* prepend default modules */ if (NULL == array_get_element(modules->value, "mod_indexfile")) { ds = data_string_init(); - buffer_copy_string(ds->value, "mod_indexfile"); + buffer_copy_string_len(ds->value, CONST_STR_LEN("mod_indexfile")); array_insert_unique(prepends->value, (data_unset *)ds); } @@ -1051,13 +1082,13 @@ int config_read(server *srv, const char *fn) { /* append default modules */ if (NULL == array_get_element(modules->value, "mod_dirlisting")) { ds = data_string_init(); - buffer_copy_string(ds->value, "mod_dirlisting"); + buffer_copy_string_len(ds->value, CONST_STR_LEN("mod_dirlisting")); array_insert_unique(modules->value, (data_unset *)ds); } if (NULL == array_get_element(modules->value, "mod_staticfile")) { ds = data_string_init(); - buffer_copy_string(ds->value, "mod_staticfile"); + buffer_copy_string_len(ds->value, CONST_STR_LEN("mod_staticfile")); array_insert_unique(modules->value, (data_unset *)ds); } } else { @@ -1067,18 +1098,18 @@ int config_read(server *srv, const char *fn) { /* server.modules is not set */ ds = data_string_init(); - buffer_copy_string(ds->value, "mod_indexfile"); + buffer_copy_string_len(ds->value, CONST_STR_LEN("mod_indexfile")); array_insert_unique(modules->value, (data_unset *)ds); ds = data_string_init(); - buffer_copy_string(ds->value, "mod_dirlisting"); + buffer_copy_string_len(ds->value, CONST_STR_LEN("mod_dirlisting")); array_insert_unique(modules->value, (data_unset *)ds); ds = data_string_init(); - buffer_copy_string(ds->value, "mod_staticfile"); + buffer_copy_string_len(ds->value, CONST_STR_LEN("mod_staticfile")); array_insert_unique(modules->value, (data_unset *)ds); - buffer_copy_string(modules->key, "server.modules"); + buffer_copy_string_len(modules->key, CONST_STR_LEN("server.modules")); array_insert_unique(srv->config, (data_unset *)modules); } |