From 010c28949c17f3a846d78e4938ae53f165b6b3f1 Mon Sep 17 00:00:00 2001 From: Glenn Strauss Date: Mon, 25 Nov 2019 01:54:08 -0500 Subject: [PATCH] [multiple] prefer (connection *) to (srv *) convert all log_error_write() to log_error() and pass (log_error_st *) use con->errh in preference to srv->errh (even though currently same) avoid passing (server *) when previously used only for logging (errh) --- src/array.c | 3 - src/base.h | 8 +- src/chunk.c | 38 ++-- src/chunk.h | 10 +- src/configfile-glue.c | 40 ++-- src/configfile.c | 80 +++---- src/connections-glue.c | 89 ++++---- src/connections.c | 133 ++++++------ src/connections.h | 4 +- src/fdevent.c | 23 +- src/fdevent_solaris_port.c | 4 +- src/gw_backend.c | 428 +++++++++++++++++++------------------ src/http-header-glue.c | 249 +++++++++++---------- src/http_auth.h | 6 +- src/http_chunk.c | 79 +++---- src/http_chunk.h | 14 +- src/log.c | 15 -- src/log.h | 3 - src/mod_access.c | 6 +- src/mod_accesslog.c | 6 +- src/mod_auth.c | 229 ++++++++++---------- src/mod_authn_file.c | 71 +++--- src/mod_authn_gssapi.c | 129 +++++------ src/mod_authn_ldap.c | 76 +++---- src/mod_authn_mysql.c | 88 ++++---- src/mod_authn_pam.c | 12 +- src/mod_authn_sasl.c | 15 +- src/mod_cgi.c | 78 ++++--- src/mod_cml.c | 21 +- src/mod_cml.h | 2 +- src/mod_cml_lua.c | 35 ++- src/mod_compress.c | 105 +++++---- src/mod_deflate.c | 140 ++++++------ src/mod_dirlisting.c | 36 ++-- src/mod_evasive.c | 6 +- src/mod_evhost.c | 5 +- src/mod_expire.c | 28 ++- src/mod_extforward.c | 113 +++++----- src/mod_fastcgi.c | 51 ++--- src/mod_flv_streaming.c | 5 +- src/mod_indexfile.c | 11 +- src/mod_magnet.c | 34 ++- src/mod_mysql_vhost.c | 9 +- src/mod_openssl.c | 317 +++++++++++++-------------- src/mod_proxy.c | 12 +- src/mod_redirect.c | 6 +- src/mod_rewrite.c | 16 +- src/mod_rrdtool.c | 17 +- src/mod_scgi.c | 3 +- src/mod_secdownload.c | 32 +-- src/mod_simple_vhost.c | 4 +- src/mod_sockproxy.c | 2 +- src/mod_ssi.c | 242 ++++++++++----------- src/mod_ssi.h | 3 +- src/mod_ssi_expr.c | 51 ++--- src/mod_ssi_expr.h | 2 - src/mod_staticfile.c | 12 +- src/mod_status.c | 1 - src/mod_trigger_b4_dl.c | 31 ++- src/mod_uploadprogress.c | 7 +- src/mod_userdir.c | 3 +- src/mod_vhostdb.c | 6 +- src/mod_vhostdb_dbi.c | 22 +- src/mod_vhostdb_ldap.c | 61 +++--- src/mod_vhostdb_mysql.c | 12 +- src/mod_vhostdb_pgsql.c | 13 +- src/mod_webdav.c | 46 ++-- src/mod_wstunnel.c | 29 ++- src/network.c | 83 +++---- src/network_write.c | 101 +++++---- src/network_write.h | 1 + src/plugin.c | 55 ++--- src/plugin_config.h | 4 +- src/request.c | 6 +- src/response.c | 208 +++++++++--------- src/response.h | 25 ++- src/server.c | 247 ++++++++++----------- src/sock_addr.c | 99 ++++----- src/sock_addr.h | 8 +- src/stat_cache.c | 26 ++- src/t/test_request.c | 12 +- 81 files changed, 2121 insertions(+), 2241 deletions(-) diff --git a/src/array.c b/src/array.c index 9b1e912c..f40bf637 100644 --- a/src/array.c +++ b/src/array.c @@ -8,9 +8,6 @@ #include #include -#include -#include - __attribute_cold__ static void array_extend(array * const a, uint32_t n) { a->size += n; diff --git a/src/base.h b/src/base.h index 98f10eec..5a29606c 100644 --- a/src/base.h +++ b/src/base.h @@ -86,6 +86,7 @@ typedef struct { const buffer *error_handler; const buffer *error_handler_404; const buffer *errorfile_prefix; + log_error_st *errh; unsigned short max_keep_alive_requests; unsigned short max_keep_alive_idle; @@ -211,7 +212,6 @@ struct connection { int mode; /* DIRECT (0) or plugin id */ int async_callback; - log_error_st *errh; server *srv; void **plugin_ctx; /* plugin connection specific config */ @@ -230,8 +230,8 @@ struct connection { http_method_t error_handler_saved_method; struct server_socket *srv_socket; /* reference to the server-socket */ - int (* network_write)(struct server *srv, struct connection *con, chunkqueue *cq, off_t max_bytes); - int (* network_read)(struct server *srv, struct connection *con, chunkqueue *cq, off_t max_bytes); + int (* network_write)(struct connection *con, chunkqueue *cq, off_t max_bytes); + int (* network_read)(struct connection *con, chunkqueue *cq, off_t max_bytes); }; typedef struct { @@ -322,7 +322,7 @@ struct server { struct stat_cache *stat_cache; struct fdevents *ev; - int (* network_backend_write)(struct server *srv, int fd, chunkqueue *cq, off_t max_bytes); + int (* network_backend_write)(int fd, chunkqueue *cq, off_t max_bytes, log_error_st *errh); handler_t (* request_env)(struct server *srv, connection *con); /* buffers */ diff --git a/src/chunk.c b/src/chunk.c index d1095c0f..a1e853a2 100644 --- a/src/chunk.c +++ b/src/chunk.c @@ -503,7 +503,7 @@ void chunkqueue_steal(chunkqueue *dest, chunkqueue *src, off_t len) { } } -static chunk *chunkqueue_get_append_tempfile(server *srv, chunkqueue *cq) { +static chunk *chunkqueue_get_append_tempfile(chunkqueue *cq, log_error_st *errh) { chunk *c; buffer *template = buffer_init_string("/var/tmp/lighttpd-upload-XXXXXX"); int fd = -1; @@ -525,9 +525,8 @@ static chunk *chunkqueue_get_append_tempfile(server *srv, chunkqueue *cq) { if (fd < 0) { /* (report only the last error to mkstemp() * if multiple temp dirs attempted) */ - log_error_write(srv, __FILE__, __LINE__, "sbs", - "opening temp-file failed:", - template, strerror(errno)); + log_perror(errh, __FILE__, __LINE__, + "opening temp-file failed: %s", template->ptr); buffer_free(template); return NULL; } @@ -541,7 +540,7 @@ static chunk *chunkqueue_get_append_tempfile(server *srv, chunkqueue *cq) { return c; } -int chunkqueue_append_mem_to_tempfile(server *srv, chunkqueue *dest, const char *mem, size_t len) { +int chunkqueue_append_mem_to_tempfile(chunkqueue *dest, const char *mem, size_t len, log_error_st *errh) { chunk *dst_c; ssize_t written; @@ -569,9 +568,8 @@ int chunkqueue_append_mem_to_tempfile(server *srv, chunkqueue *dest, const char int rc = close(dst_c->file.fd); dst_c->file.fd = -1; if (0 != rc) { - log_error_write(srv, __FILE__, __LINE__, "sbss", - "close() temp-file", dst_c->mem, "failed:", - strerror(errno)); + log_perror(errh, __FILE__, __LINE__, + "close() temp-file %s failed", dst_c->mem->ptr); return -1; } dst_c = NULL; @@ -580,7 +578,7 @@ int chunkqueue_append_mem_to_tempfile(server *srv, chunkqueue *dest, const char dst_c = NULL; } - if (NULL == dst_c && NULL == (dst_c = chunkqueue_get_append_tempfile(srv, dest))) { + if (NULL == dst_c && NULL == (dst_c = chunkqueue_get_append_tempfile(dest, errh))) { return -1; } #ifdef __COVERITY__ @@ -609,9 +607,8 @@ int chunkqueue_append_mem_to_tempfile(server *srv, chunkqueue *dest, const char } else { int retry = (errno == ENOSPC && dest->tempdirs && ++dest->tempdir_idx < dest->tempdirs->used); if (!retry) { - log_error_write(srv, __FILE__, __LINE__, "sbs", - "write() temp-file", dst_c->mem, "failed:", - strerror(errno)); + log_perror(errh, __FILE__, __LINE__, + "write() temp-file %s failed", dst_c->mem->ptr); } if (0 == chunk_remaining_length(dst_c)) { @@ -621,9 +618,8 @@ int chunkqueue_append_mem_to_tempfile(server *srv, chunkqueue *dest, const char int rc = close(dst_c->file.fd); dst_c->file.fd = -1; if (0 != rc) { - log_error_write(srv, __FILE__, __LINE__, "sbss", - "close() temp-file", dst_c->mem, "failed:", - strerror(errno)); + log_perror(errh, __FILE__, __LINE__, + "close() temp-file %s failed", dst_c->mem->ptr); return -1; } } @@ -637,7 +633,7 @@ int chunkqueue_append_mem_to_tempfile(server *srv, chunkqueue *dest, const char return -1; } -int chunkqueue_steal_with_tempfiles(server *srv, chunkqueue *dest, chunkqueue *src, off_t len) { +int chunkqueue_steal_with_tempfiles(chunkqueue *dest, chunkqueue *src, off_t len, log_error_st *errh) { while (len > 0) { chunk *c = src->first; off_t clen = 0, use; @@ -676,7 +672,7 @@ int chunkqueue_steal_with_tempfiles(server *srv, chunkqueue *dest, chunkqueue *s case MEM_CHUNK: /* store "use" bytes from memory chunk in tempfile */ - if (0 != chunkqueue_append_mem_to_tempfile(srv, dest, c->mem->ptr + c->offset, use)) { + if (0 != chunkqueue_append_mem_to_tempfile(dest, c->mem->ptr + c->offset, use, errh)) { return -1; } @@ -783,7 +779,7 @@ void chunkqueue_compact_mem(chunkqueue *cq, size_t clen) { * no data added/removed from chunkqueue; consolidated only */ } -int chunkqueue_open_file_chunk(server *srv, chunkqueue *cq) { +int chunkqueue_open_file_chunk(chunkqueue *cq, log_error_st *errh) { chunk* const c = cq->first; off_t offset, toSend; struct stat st; @@ -798,7 +794,7 @@ int chunkqueue_open_file_chunk(server *srv, chunkqueue *cq) { if (-1 == c->file.fd) { /* (permit symlinks; should already have been checked. However, TOC-TOU remains) */ if (-1 == (c->file.fd = fdevent_open_cloexec(c->mem->ptr, 1, O_RDONLY, 0))) { - log_error_write(srv, __FILE__, __LINE__, "ssb", "open failed:", strerror(errno), c->mem); + log_perror(errh, __FILE__, __LINE__, "open failed: %s",c->mem->ptr); return -1; } } @@ -807,12 +803,12 @@ int chunkqueue_open_file_chunk(server *srv, chunkqueue *cq) { if (c->file.is_temp) return 0; if (-1 == fstat(c->file.fd, &st)) { - log_error_write(srv, __FILE__, __LINE__, "ss", "fstat failed:", strerror(errno)); + log_perror(errh, __FILE__, __LINE__, "fstat failed"); return -1; } if (offset > st.st_size || toSend > st.st_size || offset > st.st_size - toSend) { - log_error_write(srv, __FILE__, __LINE__, "sb", "file shrunk:", c->mem); + log_error(errh, __FILE__, __LINE__, "file shrunk: %s", c->mem->ptr); return -1; } diff --git a/src/chunk.h b/src/chunk.h index bf0a39fe..f9d905b4 100644 --- a/src/chunk.h +++ b/src/chunk.h @@ -9,6 +9,8 @@ #include "buffer.h" #include "array.h" +struct log_error_st; /*(declaration)*/ + typedef struct chunk { struct chunk *next; enum { MEM_CHUNK, FILE_CHUNK } type; @@ -85,8 +87,7 @@ buffer * chunkqueue_append_buffer_open(chunkqueue *cq); void chunkqueue_append_buffer_commit(chunkqueue *cq); -struct server; /*(declaration)*/ -int chunkqueue_append_mem_to_tempfile(struct server *srv, chunkqueue *cq, const char *mem, size_t len); +int chunkqueue_append_mem_to_tempfile(chunkqueue *cq, const char *mem, size_t len, struct log_error_st *errh); /* functions to handle buffers to read into: */ /* obtain/reserve memory in chunkqueue at least len (input) size, @@ -109,10 +110,9 @@ void chunkqueue_mark_written(chunkqueue *cq, off_t len); void chunkqueue_remove_finished_chunks(chunkqueue *cq); void chunkqueue_steal(chunkqueue *dest, chunkqueue *src, off_t len); -struct server; -int chunkqueue_steal_with_tempfiles(struct server *srv, chunkqueue *dest, chunkqueue *src, off_t len); +int chunkqueue_steal_with_tempfiles(chunkqueue *dest, chunkqueue *src, off_t len, struct log_error_st *errh); -int chunkqueue_open_file_chunk(struct server *srv, chunkqueue *cq); +int chunkqueue_open_file_chunk(chunkqueue *cq, struct log_error_st *errh); void chunkqueue_compact_mem(chunkqueue *cq, size_t clen); diff --git a/src/configfile-glue.c b/src/configfile-glue.c index 9b000a21..6290ec7b 100644 --- a/src/configfile-glue.c +++ b/src/configfile-glue.c @@ -270,7 +270,7 @@ static void config_cond_result_trace(connection *con, const data_config *dc, int case COND_RESULT_TRUE: msg = "true"; break; default: msg = "invalid cond_result_t"; break; } - log_error(con->errh, __FILE__, __LINE__, "%d (%s) result: %s", + log_error(con->conf.errh, __FILE__, __LINE__, "%d (%s) result: %s", dc->context_ndx, "uncached"+(cached ? 2 : 0), msg); } @@ -305,16 +305,16 @@ static int config_addrstr_eq_remote_ip_mask(connection *con, const char *addrstr sock_addr addr; if (1 == sock_addr_inet_pton(&addr, addrstr, AF_INET, 0)) { if (nm_bits > 32) { - log_error(con->errh, __FILE__, __LINE__, "ERROR: ipv4 netmask too large: %d", nm_bits); + log_error(con->conf.errh, __FILE__, __LINE__, "ERROR: ipv4 netmask too large: %d", nm_bits); return -1; } } else if (1 == sock_addr_inet_pton(&addr, addrstr, AF_INET6, 0)) { if (nm_bits > 128) { - log_error(con->errh, __FILE__, __LINE__, "ERROR: ipv6 netmask too large: %d", nm_bits); + log_error(con->conf.errh, __FILE__, __LINE__, "ERROR: ipv6 netmask too large: %d", nm_bits); return -1; } } else { - log_error(con->errh, __FILE__, __LINE__, "ERROR: ip addr is invalid: %s", addrstr); + log_error(con->conf.errh, __FILE__, __LINE__, "ERROR: ip addr is invalid: %s", addrstr); return -1; } return sock_addr_is_addr_eq_bits(&addr, rmt, nm_bits); @@ -327,21 +327,21 @@ static int config_addrbuf_eq_remote_ip_mask(connection *con, const buffer *strin char addrstr[64]; /*(larger than INET_ADDRSTRLEN and INET6_ADDRSTRLEN)*/ if (*err) { - log_error(con->errh, __FILE__, __LINE__, "ERROR: non-digit found in netmask: %s %s", string->ptr, err); + log_error(con->conf.errh, __FILE__, __LINE__, "ERROR: non-digit found in netmask: %s %s", string->ptr, err); return -1; } if (nm_bits <= 0) { if (*(nm_slash+1) == '\0') { - log_error(con->errh, __FILE__, __LINE__, "ERROR: no number after / %s", string->ptr); + log_error(con->conf.errh, __FILE__, __LINE__, "ERROR: no number after / %s", string->ptr); } else { - log_error(con->errh, __FILE__, __LINE__, "ERROR: invalid netmask <= 0: %s %s", string->ptr, err); + log_error(con->conf.errh, __FILE__, __LINE__, "ERROR: invalid netmask <= 0: %s %s", string->ptr, err); } return -1; } if (addrstrlen >= sizeof(addrstr)) { - log_error(con->errh, __FILE__, __LINE__, "ERROR: address string too long: %s", string->ptr); + log_error(con->conf.errh, __FILE__, __LINE__, "ERROR: address string too long: %s", string->ptr); return -1; } @@ -368,7 +368,7 @@ static cond_result_t config_check_cond_nocache(connection *con, const data_confi * if the parent is not decided yet or false, we can't be true either */ if (debug_cond) { - log_error(con->errh, __FILE__, __LINE__, "go parent %s", dc->parent->key.ptr); + log_error(con->conf.errh, __FILE__, __LINE__, "go parent %s", dc->parent->key.ptr); } switch (config_check_cond_cached(con, dc->parent, debug_cond)) { @@ -391,7 +391,7 @@ static cond_result_t config_check_cond_nocache(connection *con, const data_confi * was evaluated as "false" (not unset/skipped/true) */ if (debug_cond) { - log_error(con->errh, __FILE__, __LINE__, "go prev %s", dc->prev->key.ptr); + log_error(con->conf.errh, __FILE__, __LINE__, "go prev %s", dc->prev->key.ptr); } /* make sure prev is checked first */ @@ -411,7 +411,7 @@ static cond_result_t config_check_cond_nocache(connection *con, const data_confi if (!(con->conditional_is_valid & (1 << dc->comp))) { if (debug_cond) { - log_error(con->errh, __FILE__, __LINE__, "%d %s not available yet", + log_error(con->conf.errh, __FILE__, __LINE__, "%d %s not available yet", dc->comp, dc->key.ptr); } @@ -505,6 +505,7 @@ static cond_result_t config_check_cond_nocache(connection *con, const data_confi case COMP_HTTP_QUERY_STRING: l = con->uri.query; + if (NULL == l->ptr) l = (buffer *)&empty_string; break; case COMP_SERVER_SOCKET: @@ -525,12 +526,12 @@ static cond_result_t config_check_cond_nocache(connection *con, const data_confi } if (NULL == l) { /*(should not happen)*/ - log_error(con->errh, __FILE__, __LINE__, + log_error(con->conf.errh, __FILE__, __LINE__, "%s () compare to NULL", dc->comp_key->ptr); return COND_RESULT_FALSE; } else if (debug_cond) { - log_error(con->errh, __FILE__, __LINE__, + log_error(con->conf.errh, __FILE__, __LINE__, "%s (%s) compare to %s", dc->comp_key->ptr, l->ptr, dc->string.ptr); } @@ -566,7 +567,7 @@ static cond_result_t config_check_cond_calc(connection *con, const int context_n con->srv->config_context->data[context_ndx]; const int debug_cond = con->conf.log_condition_handling; if (debug_cond) { - log_error(con->errh, __FILE__, __LINE__, + log_error(con->conf.errh, __FILE__, __LINE__, "=== start of condition block ==="); } return config_check_cond_nocache_calc(con, dc, debug_cond, cache); @@ -604,10 +605,11 @@ static void config_cond_clear_node(cond_cache_t * const cond_cache, const data_c * * if the item is COND_LAST_ELEMENT we reset all items */ -void config_cond_cache_reset_item(server *srv, connection *con, comp_key_t item) { +void config_cond_cache_reset_item(connection *con, comp_key_t item) { cond_cache_t * const cond_cache = con->cond_cache; - for (uint32_t i = 0; i < srv->config_context->used; ++i) { - const data_config *dc = (data_config *)srv->config_context->data[i]; + const array * const config_context = con->srv->config_context; + for (uint32_t i = 0; i < config_context->used; ++i) { + const data_config *dc = (data_config *)config_context->data[i]; if (item == dc->comp) { /* clear local_result */ @@ -621,11 +623,11 @@ void config_cond_cache_reset_item(server *srv, connection *con, comp_key_t item) /** * reset the config cache to its initial state at connection start */ -void config_cond_cache_reset(server *srv, connection *con) { +void config_cond_cache_reset(connection *con) { con->conditional_is_valid = 0; /* resetting all entries; no need to follow children as in config_cond_cache_reset_item */ /* static_assert(0 == COND_RESULT_UNSET); */ - const uint32_t used = srv->config_context->used; + const uint32_t used = con->srv->config_context->used; if (used > 1) memset(con->cond_cache, 0, used*sizeof(cond_cache_t)); } diff --git a/src/configfile.c b/src/configfile.c index dbdb3ee6..1eed3949 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -231,7 +231,7 @@ static int config_burl_normalize_cond (server *srv) { #if defined(HAVE_MYSQL) || (defined(HAVE_LDAP_H) && defined(HAVE_LBER_H) && defined(HAVE_LIBLDAP) && defined(HAVE_LIBLBER)) static void config_warn_authn_module (server *srv, const char *module, size_t len) { - for (size_t i = 0; i < srv->config_context->used; ++i) { + for (uint32_t i = 0; i < srv->config_context->used; ++i) { const data_config *config = (data_config const*)srv->config_context->data[i]; const data_unset *du = array_get_element_klen(config->value, CONST_STR_LEN("auth.backend")); if (NULL != du && du->type == TYPE_STRING) { @@ -240,7 +240,12 @@ static void config_warn_authn_module (server *srv, const char *module, size_t le buffer_copy_string_len(srv->tmp_buf, CONST_STR_LEN("mod_authn_")); buffer_append_string_len(srv->tmp_buf, module, len); array_insert_value(srv->srvconf.modules, CONST_BUF_LEN(srv->tmp_buf)); - log_error_write(srv, __FILE__, __LINE__, "SSSsSSS", "Warning: please add \"mod_authn_", module, "\" to server.modules list in lighttpd.conf. A future release of lighttpd 1.4.x will not automatically load mod_authn_", module, "and lighttpd will fail to start up since your lighttpd.conf uses auth.backend = \"", module, "\"."); + log_error(srv->errh, __FILE__, __LINE__, + "Warning: please add \"mod_authn_%s\" to server.modules list " + "in lighttpd.conf. A future release of lighttpd 1.4.x will " + "not automatically load mod_authn_%s and lighttpd will fail " + "to start up since your lighttpd.conf uses " + "auth.backend = \"%s\".", module, module, module); return; } } @@ -250,14 +255,19 @@ static void config_warn_authn_module (server *srv, const char *module, size_t le #ifdef USE_OPENSSL_CRYPTO static void config_warn_openssl_module (server *srv) { - for (size_t i = 0; i < srv->config_context->used; ++i) { + for (uint32_t i = 0; i < srv->config_context->used; ++i) { const data_config *config = (data_config const*)srv->config_context->data[i]; - for (size_t j = 0; j < config->value->used; ++j) { + for (uint32_t j = 0; j < config->value->used; ++j) { data_unset *du = config->value->data[j]; if (0 == strncmp(du->key.ptr, "ssl.", sizeof("ssl.")-1)) { /* mod_openssl should be loaded after mod_extforward */ array_insert_value(srv->srvconf.modules, CONST_STR_LEN("mod_openssl")); - log_error_write(srv, __FILE__, __LINE__, "S", "Warning: please add \"mod_openssl\" to server.modules list in lighttpd.conf. A future release of lighttpd 1.4.x *will not* automatically load mod_openssl and lighttpd *will not* use SSL/TLS where your lighttpd.conf contains ssl.* directives"); + log_error(srv->errh, __FILE__, __LINE__, + "Warning: please add \"mod_openssl\" to server.modules list " + "in lighttpd.conf. A future release of lighttpd 1.4.x " + "*will not* automatically load mod_openssl and lighttpd " + "*will not* use SSL/TLS where your lighttpd.conf contains " + "ssl.* directives"); return; } } @@ -942,6 +952,7 @@ static int config_insert(server *srv) { } } + p->defaults.errh = srv->errh; p->defaults.max_keep_alive_requests = 100; p->defaults.max_keep_alive_idle = 5; p->defaults.max_read_idle = 60; @@ -1461,7 +1472,7 @@ static int config_tokenizer(server *srv, tokenizer_t *t, int *token_id, buffer * *token_id = tid; return 1; } else if (t->offset < t->size) { - log_error_write(srv, __FILE__, __LINE__, "Dsb", tid, ",", token); + log_error(srv->errh, __FILE__, __LINE__, "%d, %s", tid, token->ptr); } return 0; } @@ -1524,8 +1535,8 @@ static int config_parse_file_stream(server *srv, config_t *context, const char * stream s; if (0 != stream_open(&s, fn)) { - log_error(srv->errh, __FILE__, __LINE__, - "opening configfile %s failed: %s", fn, strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, + "opening configfile %s failed", fn); return -1; } @@ -1566,12 +1577,12 @@ int config_parse_file(server *srv, config_t *context, const char *fn) { ret = 0; /* not an error if no files match glob pattern */ } else { - log_error_write(srv, __FILE__, __LINE__, "sb", "include file not found: ", filename); + log_error(srv->errh, __FILE__, __LINE__, "include file not found: %s", filename->ptr); } break; case GLOB_ABORTED: case GLOB_NOSPACE: - log_error_write(srv, __FILE__, __LINE__, "sbss", "glob()", filename, "failed:", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, "glob() %s failed", filename->ptr); break; } @@ -1601,22 +1612,20 @@ int config_parse_cmd(server *srv, config_t *context, const char *cmd) { char oldpwd[PATH_MAX]; if (NULL == getcwd(oldpwd, sizeof(oldpwd))) { - log_error_write(srv, __FILE__, __LINE__, "s", - "cannot get cwd", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, "getcwd()"); return -1; } if (!buffer_string_is_empty(context->basedir)) { if (0 != chdir(context->basedir->ptr)) { - log_error_write(srv, __FILE__, __LINE__, "sbs", - "cannot change directory to", context->basedir, strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, + "cannot change directory to %s", context->basedir->ptr); return -1; } } if (pipe(fds)) { - log_error_write(srv, __FILE__, __LINE__, "ss", - "pipe failed: ", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, "pipe()"); ret = -1; } else { @@ -1631,8 +1640,7 @@ int config_parse_cmd(server *srv, config_t *context, const char *cmd) { fdevent_setfd_cloexec(fds[0]); pid = fdevent_fork_execve(args[0], args, NULL, -1, fds[1], -1, -1); if (-1 == pid) { - log_error_write(srv, __FILE__, __LINE__, "SSss", - "fork/exec(", cmd, "):", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, "fork/exec(%s)", cmd); ret = -1; } else { @@ -1647,21 +1655,20 @@ int config_parse_cmd(server *srv, config_t *context, const char *cmd) { if (rd >= 0) buffer_commit(out, (size_t)rd); } while (rd > 0 || (-1 == rd && errno == EINTR)); if (0 != rd) { - log_error_write(srv, __FILE__, __LINE__, "SSss", - "read \"", cmd, "\" failed:", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, "read \"%s\"", cmd); ret = -1; } close(fds[0]); fds[0] = -1; while (-1 == (wpid = waitpid(pid, &wstatus, 0)) && errno == EINTR) ; if (wpid != pid) { - log_error_write(srv, __FILE__, __LINE__, "SSss", - "waitpid \"", cmd, "\" failed:", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, "waitpid \"%s\"",cmd); ret = -1; } if (0 != wstatus) { - log_error_write(srv, __FILE__, __LINE__, "SSsd", - "command \"", cmd, "\" exited non-zero:", WEXITSTATUS(wstatus)); + log_error(srv->errh, __FILE__, __LINE__, + "command \"%s\" exited non-zero: %d", + cmd, WEXITSTATUS(wstatus)); ret = -1; } @@ -1675,8 +1682,8 @@ int config_parse_cmd(server *srv, config_t *context, const char *cmd) { } if (0 != chdir(oldpwd)) { - log_error_write(srv, __FILE__, __LINE__, "sss", - "cannot change directory to", oldpwd, strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, + "cannot change directory to %s", oldpwd); ret = -1; } return ret; @@ -1761,13 +1768,15 @@ int config_set_defaults(server *srv) { if (!buffer_string_is_empty(srv->srvconf.changeroot)) { if (-1 == stat(srv->srvconf.changeroot->ptr, &st1)) { - log_error_write(srv, __FILE__, __LINE__, "sb", - "server.chroot doesn't exist:", srv->srvconf.changeroot); + log_error(srv->errh, __FILE__, __LINE__, + "server.chroot doesn't exist: %s", + srv->srvconf.changeroot->ptr); return -1; } if (!S_ISDIR(st1.st_mode)) { - log_error_write(srv, __FILE__, __LINE__, "sb", - "server.chroot isn't a directory:", srv->srvconf.changeroot); + log_error(srv->errh, __FILE__, __LINE__, + "server.chroot isn't a directory: %s", + srv->srvconf.changeroot->ptr); return -1; } } @@ -1793,11 +1802,11 @@ int config_set_defaults(server *srv) { buffer_string_set_length(b, len); /*(truncate)*/ buffer_append_string_buffer(b, &ds->value); if (-1 == stat(b->ptr, &st1)) { - log_error_write(srv, __FILE__, __LINE__, "sb", - "server.upload-dirs doesn't exist:", b); + log_error(srv->errh, __FILE__, __LINE__, + "server.upload-dirs doesn't exist: %s", b->ptr); } else if (!S_ISDIR(st1.st_mode)) { - log_error_write(srv, __FILE__, __LINE__, "sb", - "server.upload-dirs isn't a directory:", b); + log_error(srv->errh, __FILE__, __LINE__, + "server.upload-dirs isn't a directory: %s", b->ptr); } } } @@ -1807,8 +1816,7 @@ int config_set_defaults(server *srv) { srv->srvconf.upload_temp_file_size); if (buffer_string_is_empty(s->document_root)) { - log_error_write(srv, __FILE__, __LINE__, "s", - "document-root is not set"); + log_error(srv->errh, __FILE__, __LINE__, "document-root is not set"); return -1; } diff --git a/src/connections-glue.c b/src/connections-glue.c index 8e77c97b..f4bcaf44 100644 --- a/src/connections-glue.c +++ b/src/connections-glue.c @@ -8,7 +8,6 @@ #include "log.h" #include "response.h" -#include #include #include @@ -109,9 +108,7 @@ static int connection_handle_read_post_chunked_crlf(chunkqueue *cq) { return 0; } -handler_t connection_handle_read_post_error(server *srv, connection *con, int http_status) { - UNUSED(srv); - +handler_t connection_handle_read_post_error(connection *con, int http_status) { con->keep_alive = 0; /*(do not change status if response headers already set and possibly sent)*/ @@ -123,7 +120,7 @@ handler_t connection_handle_read_post_error(server *srv, connection *con, int ht return HANDLER_FINISHED; } -static handler_t connection_handle_read_post_chunked(server *srv, connection *con, chunkqueue *cq, chunkqueue *dst_cq) { +static handler_t connection_handle_read_post_chunked(connection *con, chunkqueue *cq, chunkqueue *dst_cq) { /* con->conf.max_request_size is in kBytes */ const off_t max_request_size = (off_t)con->conf.max_request_size << 10; @@ -142,29 +139,29 @@ static handler_t connection_handle_read_post_chunked(server *srv, connection *co unsigned char *s = (unsigned char *)c->mem->ptr+c->offset; for (unsigned char u;(u=(unsigned char)hex2int(*s))!=0xFF;++s) { if (te_chunked > (off_t)(1uLL<<(8*sizeof(off_t)-5))-1) { - log_error_write(srv, __FILE__, __LINE__, "s", - "chunked data size too large -> 400"); + log_error(con->conf.errh, __FILE__, __LINE__, + "chunked data size too large -> 400"); /* 400 Bad Request */ - return connection_handle_read_post_error(srv, con, 400); + return connection_handle_read_post_error(con, 400); } te_chunked <<= 4; te_chunked |= u; } while (*s == ' ' || *s == '\t') ++s; if (*s != '\r' && *s != ';') { - log_error_write(srv, __FILE__, __LINE__, "s", - "chunked header invalid chars -> 400"); + log_error(con->conf.errh, __FILE__, __LINE__, + "chunked header invalid chars -> 400"); /* 400 Bad Request */ - return connection_handle_read_post_error(srv, con, 400); + return connection_handle_read_post_error(con, 400); } if (hsz >= 1024) { /* prevent theoretical integer overflow * casting to (size_t) and adding 2 (for "\r\n") */ - log_error_write(srv, __FILE__, __LINE__, "s", - "chunked header line too long -> 400"); + log_error(con->conf.errh, __FILE__, __LINE__, + "chunked header line too long -> 400"); /* 400 Bad Request */ - return connection_handle_read_post_error(srv, con, 400); + return connection_handle_read_post_error(con, 400); } if (0 == te_chunked) { @@ -188,7 +185,7 @@ static handler_t connection_handle_read_post_chunked(server *srv, connection *co * potentially received by backend, if in the future * these trailers are added to request headers)*/ if ((off_t)buffer_string_length(c->mem) - c->offset - < srv->srvconf.max_request_field_size) { + < con->srv->srvconf.max_request_field_size) { break; } else { @@ -216,11 +213,11 @@ static handler_t connection_handle_read_post_chunked(server *srv, connection *co if (0 !=max_request_size && (max_request_size < te_chunked || max_request_size - te_chunked < dst_cq->bytes_in)) { - log_error_write(srv, __FILE__, __LINE__, "sos", - "request-size too long:", - dst_cq->bytes_in + te_chunked, "-> 413"); + log_error(con->conf.errh, __FILE__, __LINE__, + "request-size too long: %lld -> 413", + (long long)(dst_cq->bytes_in + te_chunked)); /* 413 Payload Too Large */ - return connection_handle_read_post_error(srv, con, 413); + return connection_handle_read_post_error(con, 413); } te_chunked += 2; /*(for trailing "\r\n" after chunked data)*/ @@ -231,10 +228,10 @@ static handler_t connection_handle_read_post_chunked(server *srv, connection *co /*(likely better ways to handle chunked header crossing chunkqueue * chunks, but this situation is not expected to occur frequently)*/ if ((off_t)buffer_string_length(c->mem) - c->offset >= 1024) { - log_error_write(srv, __FILE__, __LINE__, "s", - "chunked header line too long -> 400"); + log_error(con->conf.errh, __FILE__, __LINE__, + "chunked header line too long -> 400"); /* 400 Bad Request */ - return connection_handle_read_post_error(srv, con, 400); + return connection_handle_read_post_error(con, 400); } else if (!connection_handle_read_post_cq_compact(cq)) { break; @@ -248,9 +245,10 @@ static handler_t connection_handle_read_post_chunked(server *srv, connection *co /* avoid buffering request bodies <= 64k on disk */ chunkqueue_steal(dst_cq, cq, len); } - else if (0 != chunkqueue_steal_with_tempfiles(srv,dst_cq,cq,len)) { + else if (0 != chunkqueue_steal_with_tempfiles(dst_cq, cq, len, + con->conf.errh)) { /* 500 Internal Server Error */ - return connection_handle_read_post_error(srv, con, 500); + return connection_handle_read_post_error(con, 500); } te_chunked -= len; len = cq->bytes_in - cq->bytes_out; @@ -260,10 +258,10 @@ static handler_t connection_handle_read_post_chunked(server *srv, connection *co if (2 == te_chunked) { if (-1 == connection_handle_read_post_chunked_crlf(cq)) { - log_error_write(srv, __FILE__, __LINE__, "s", - "chunked data missing end CRLF -> 400"); + log_error(con->conf.errh, __FILE__, __LINE__, + "chunked data missing end CRLF -> 400"); /* 400 Bad Request */ - return connection_handle_read_post_error(srv, con, 400); + return connection_handle_read_post_error(con, 400); } chunkqueue_mark_written(cq, 2);/*consume \r\n at end of chunk data*/ te_chunked -= 2; @@ -275,21 +273,20 @@ static handler_t connection_handle_read_post_chunked(server *srv, connection *co return HANDLER_GO_ON; } -static handler_t connection_handle_read_body_unknown(server *srv, connection *con, chunkqueue *cq, chunkqueue *dst_cq) { +static handler_t connection_handle_read_body_unknown(connection *con, chunkqueue *cq, chunkqueue *dst_cq) { /* con->conf.max_request_size is in kBytes */ const off_t max_request_size = (off_t)con->conf.max_request_size << 10; chunkqueue_append_chunkqueue(dst_cq, cq); if (0 != max_request_size && dst_cq->bytes_in > max_request_size) { - log_error_write(srv, __FILE__, __LINE__, "sos", - "request-size too long:", dst_cq->bytes_in, "-> 413"); + log_error(con->conf.errh, __FILE__, __LINE__, + "request-size too long: %lld -> 413", (long long)dst_cq->bytes_in); /* 413 Payload Too Large */ - return connection_handle_read_post_error(srv, con, 413); + return connection_handle_read_post_error(con, 413); } return HANDLER_GO_ON; } -static off_t connection_write_throttle(server *srv, connection *con, off_t max_bytes) { - UNUSED(srv); +static off_t connection_write_throttle(connection *con, off_t max_bytes) { if (con->conf.global_bytes_per_second) { off_t limit = (off_t)con->conf.global_bytes_per_second - *(con->conf.global_bytes_per_second_cnt_ptr); if (limit <= 0) { @@ -317,14 +314,14 @@ static off_t connection_write_throttle(server *srv, connection *con, off_t max_b return max_bytes; } -int connection_write_chunkqueue(server *srv, connection *con, chunkqueue *cq, off_t max_bytes) { +int connection_write_chunkqueue(connection *con, chunkqueue *cq, off_t max_bytes) { int ret = -1; off_t written = 0; #ifdef TCP_CORK int corked = 0; #endif - max_bytes = connection_write_throttle(srv, con, max_bytes); + max_bytes = connection_write_throttle(con, max_bytes); if (0 == max_bytes) return 1; written = cq->bytes_out; @@ -347,7 +344,7 @@ int connection_write_chunkqueue(server *srv, connection *con, chunkqueue *cq, of } #endif - ret = con->network_write(srv, con, cq, max_bytes); + ret = con->network_write(con, cq, max_bytes); if (ret >= 0) { ret = chunkqueue_is_empty(cq) ? 0 : 1; } @@ -368,7 +365,7 @@ int connection_write_chunkqueue(server *srv, connection *con, chunkqueue *cq, of return ret; } -static int connection_write_100_continue(server *srv, connection *con) { +static int connection_write_100_continue(connection *con) { /* Make best effort to send all or none of "HTTP/1.1 100 Continue" */ /* (Note: also choosing not to update con->write_request_ts * which differs from connections.c:connection_handle_write()) */ @@ -378,7 +375,7 @@ static int connection_write_100_continue(server *srv, connection *con) { int rc; off_t max_bytes = - connection_write_throttle(srv, con, sizeof(http_100_continue)-1); + connection_write_throttle(con, sizeof(http_100_continue)-1); if (max_bytes < (off_t)sizeof(http_100_continue)-1) { return 1; /* success; skip sending if throttled to partial */ } @@ -387,7 +384,7 @@ static int connection_write_100_continue(server *srv, connection *con) { written = cq->bytes_out; chunkqueue_append_mem(cq,http_100_continue,sizeof(http_100_continue)-1); - rc = con->network_write(srv, con, cq, sizeof(http_100_continue)-1); + rc = con->network_write(con, cq, sizeof(http_100_continue)-1); written = cq->bytes_out - written; con->bytes_written += written; @@ -423,7 +420,7 @@ handler_t connection_handle_read_post_state(server *srv, connection *con) { if (con->is_readable) { con->read_idle_ts = srv->cur_ts; - switch(con->network_read(srv, con, con->read_queue, MAX_READ_LIMIT)) { + switch(con->network_read(con, con->read_queue, MAX_READ_LIMIT)) { case -1: con->state = CON_STATE_ERROR; return HANDLER_ERROR; @@ -445,7 +442,7 @@ handler_t connection_handle_read_post_state(server *srv, connection *con) { const buffer *vb = http_header_request_get(con, HTTP_HEADER_EXPECT, CONST_STR_LEN("Expect")); if (NULL != vb && buffer_eq_icase_slen(vb, CONST_STR_LEN("100-continue"))) { http_header_request_unset(con, HTTP_HEADER_EXPECT, CONST_STR_LEN("Expect")); - if (!connection_write_100_continue(srv, con)) { + if (!connection_write_100_continue(con)) { return HANDLER_ERROR; } } @@ -454,17 +451,17 @@ handler_t connection_handle_read_post_state(server *srv, connection *con) { if (con->request.content_length < 0) { /*(-1: Transfer-Encoding: chunked, -2: unspecified length)*/ handler_t rc = (-1 == con->request.content_length) - ? connection_handle_read_post_chunked(srv, con, cq, dst_cq) - : connection_handle_read_body_unknown(srv, con, cq, dst_cq); + ? connection_handle_read_post_chunked(con, cq, dst_cq) + : connection_handle_read_body_unknown(con, cq, dst_cq); if (HANDLER_GO_ON != rc) return rc; } else if (con->request.content_length <= 64*1024) { /* don't buffer request bodies <= 64k on disk */ chunkqueue_steal(dst_cq, cq, (off_t)con->request.content_length - dst_cq->bytes_in); } - else if (0 != chunkqueue_steal_with_tempfiles(srv, dst_cq, cq, (off_t)con->request.content_length - dst_cq->bytes_in)) { + else if (0 != chunkqueue_steal_with_tempfiles(dst_cq, cq, (off_t)con->request.content_length - dst_cq->bytes_in, con->conf.errh)) { /* writing to temp file failed */ - return connection_handle_read_post_error(srv, con, 500); /* Internal Server Error */ + return connection_handle_read_post_error(con, 500); /* Internal Server Error */ } chunkqueue_remove_finished_chunks(cq); @@ -478,7 +475,7 @@ handler_t connection_handle_read_post_state(server *srv, connection *con) { return HANDLER_GO_ON; } else if (is_closed) { #if 0 - return connection_handle_read_post_error(srv, con, 400); /* Bad Request */ + return connection_handle_read_post_error(con, 400); /* Bad Request */ #endif return HANDLER_ERROR; } else { diff --git a/src/connections.c b/src/connections.c index 799317a3..a66a54c0 100644 --- a/src/connections.c +++ b/src/connections.c @@ -108,8 +108,8 @@ static void connection_plugin_ctx_check(server *srv, connection *con) { plugin *p = ((plugin **)(srv->plugins.ptr))[i]; plugin_data_base *pd = p->data; if (!pd || NULL == con->plugin_ctx[pd->id]) continue; - log_error_write(srv, __FILE__, __LINE__, "ss", - "missing cleanup in", p->name); + log_error(con->conf.errh, __FILE__, __LINE__, + "missing cleanup in %s", p->name); con->plugin_ctx[pd->id] = NULL; } } @@ -126,23 +126,18 @@ static int connection_close(server *srv, connection *con) { fdevent_unregister(srv->ev, con->fd); con->fdn = NULL; #ifdef __WIN32 - if (closesocket(con->fd)) { - log_error_write(srv, __FILE__, __LINE__, "sds", - "(warning) close:", con->fd, strerror(errno)); - } + if (0 == closesocket(con->fd)) #else - if (close(con->fd)) { - log_error_write(srv, __FILE__, __LINE__, "sds", - "(warning) close:", con->fd, strerror(errno)); - } + if (0 == close(con->fd)) #endif - else { - srv->cur_fds--; - } + --srv->cur_fds; + else + log_perror(con->conf.errh, __FILE__, __LINE__, + "(warning) close: %d", con->fd); if (srv->srvconf.log_state_handling) { - log_error_write(srv, __FILE__, __LINE__, "sd", - "connection closed for fd", con->fd); + log_error(con->conf.errh, __FILE__, __LINE__, + "connection closed for fd %d", con->fd); } con->fd = -1; con->is_ssl_sock = 0; @@ -185,7 +180,7 @@ static void connection_read_for_eos_plain(server *srv, connection *con) { } static void connection_read_for_eos_ssl(server *srv, connection *con) { - if (con->network_read(srv, con, con->read_queue, MAX_READ_LIMIT) < 0) + if (con->network_read(con, con->read_queue, MAX_READ_LIMIT) < 0) con->close_timeout_ts = srv->cur_ts - (HTTP_LINGER_TIMEOUT+1); chunkqueue_reset(con->read_queue); } @@ -217,8 +212,8 @@ static void connection_handle_shutdown(server *srv, connection *con) { connection_set_state(con, CON_STATE_CLOSE); if (srv->srvconf.log_state_handling) { - log_error_write(srv, __FILE__, __LINE__, "sd", - "shutdown for fd", con->fd); + log_error(con->conf.errh, __FILE__, __LINE__, + "shutdown for fd %d", con->fd); } } else { connection_close(srv, con); @@ -226,8 +221,8 @@ static void connection_handle_shutdown(server *srv, connection *con) { } __attribute_cold__ -static void connection_fdwaitqueue_append(server *srv, connection *con) { - connection_list_append(&srv->fdwaitqueue, con); +static void connection_fdwaitqueue_append(connection *con) { + connection_list_append(&con->srv->fdwaitqueue, con); } static void connection_handle_response_end_state(server *srv, connection *con) { @@ -296,7 +291,7 @@ static void connection_handle_errdoc(connection *con) { buffer_copy_buffer(con->physical.path, con->conf.errorfile_prefix); buffer_append_int(con->physical.path, con->http_status); buffer_append_string_len(con->physical.path, CONST_STR_LEN(".html")); - if (0 == http_chunk_append_file(srv, con, con->physical.path)) { + if (0 == http_chunk_append_file(con, con->physical.path)) { stat_cache_entry *sce = NULL; if (stat_cache_get_entry(srv, con, con->physical.path, &sce) != HANDLER_ERROR) { @@ -330,7 +325,7 @@ static void connection_handle_errdoc(connection *con) { "\n" " \n" "\n")); - (void)http_chunk_append_mem(srv, con, CONST_BUF_LEN(b)); + (void)http_chunk_append_mem(con, CONST_BUF_LEN(b)); http_header_response_set(con, HTTP_HEADER_CONTENT_TYPE, CONST_STR_LEN("Content-Type"), @@ -393,7 +388,7 @@ static int connection_handle_write_prepare(server *srv, connection *con) { case HANDLER_FINISHED: break; default: - log_error_write(srv, __FILE__, __LINE__, "s", "response_start plugin failed"); + log_error(con->conf.errh,__FILE__,__LINE__,"response_start plugin failed"); return -1; } @@ -420,8 +415,11 @@ static int connection_handle_write_prepare(server *srv, connection *con) { /* qlen = 0 is important for Redirects (301, ...) as they MAY have * a content. Browsers are waiting for a Content otherwise */ - buffer_copy_int(srv->tmp_buf, qlen); - http_header_response_set(con, HTTP_HEADER_CONTENT_LENGTH, CONST_STR_LEN("Content-Length"), CONST_BUF_LEN(srv->tmp_buf)); + buffer * const tb = con->srv->tmp_buf; + buffer_copy_int(tb, qlen); + http_header_response_set(con, HTTP_HEADER_CONTENT_LENGTH, + CONST_STR_LEN("Content-Length"), + CONST_BUF_LEN(tb)); } } } else { @@ -465,34 +463,33 @@ static int connection_handle_write_prepare(server *srv, connection *con) { con->file_finished = 1; } - http_response_write_header(srv, con); + http_response_write_header(con); return 0; } static void connection_handle_write(server *srv, connection *con) { - switch(connection_write_chunkqueue(srv, con, con->write_queue, MAX_WRITE_LIMIT)) { + switch(connection_write_chunkqueue(con, con->write_queue, MAX_WRITE_LIMIT)) { case 0: - con->write_request_ts = srv->cur_ts; if (con->file_finished) { connection_set_state(con, CON_STATE_RESPONSE_END); } break; case -1: /* error on our side */ - log_error_write(srv, __FILE__, __LINE__, "sd", - "connection closed: write failed on fd", con->fd); + log_error(con->conf.errh, __FILE__, __LINE__, + "connection closed: write failed on fd %d", con->fd); connection_set_state(con, CON_STATE_ERROR); break; case -2: /* remote close */ connection_set_state(con, CON_STATE_ERROR); break; case 1: - con->write_request_ts = srv->cur_ts; con->is_writable = 0; /* not finished yet -> WRITE */ break; } + con->write_request_ts = srv->cur_ts; } static void connection_handle_write_state(server *srv, connection *con) { @@ -516,13 +513,13 @@ static void connection_handle_write_state(server *srv, connection *con) { case HANDLER_GO_ON: break; case HANDLER_WAIT_FOR_FD: - connection_fdwaitqueue_append(srv, con); + connection_fdwaitqueue_append(con); break; case HANDLER_COMEBACK: default: - log_error_write(srv, __FILE__, __LINE__, "sdd", - "unexpected subrequest handler ret-value:", - con->fd, r); + log_error(con->conf.errh, __FILE__, __LINE__, + "unexpected subrequest handler ret-value: %d %d", + con->fd, r); /* fall through */ case HANDLER_ERROR: connection_set_state(con, CON_STATE_ERROR); @@ -700,7 +697,7 @@ static int connection_reset(server *srv, connection *con) { chunkqueue_reset(con->request_content_queue); /* The cond_cache gets reset in response.c */ - /* config_cond_cache_reset(srv, con); */ + /* config_cond_cache_reset(con); */ con->async_callback = 0; con->error_handler_saved_status = 0; @@ -726,7 +723,7 @@ static chunk * connection_read_header_more(connection *con, chunkqueue *cq, chun if ((NULL == c || NULL == c->next) && con->is_readable) { server * const srv = con->srv; con->read_idle_ts = srv->cur_ts; - if (0 != con->network_read(srv, con, cq, MAX_READ_LIMIT)) + if (0 != con->network_read(con, cq, MAX_READ_LIMIT)) connection_set_state(con, CON_STATE_ERROR); } @@ -808,7 +805,7 @@ static int connection_handle_read_state(server * const srv, connection * const c srv->srvconf.max_request_field_size; if ((con->header_len ? con->header_len : clen) > max_request_field_size || hoff[0] >= sizeof(hoff)/sizeof(hoff[0])-1) { - log_error(con->errh, __FILE__, __LINE__, "%s", + log_error(con->conf.errh, __FILE__, __LINE__, "%s", "oversized request-header -> sending Status 431"); con->http_status = 431; /* Request Header Fields Too Large */ con->keep_alive = 0; @@ -853,7 +850,7 @@ static int connection_handle_read_state(server * const srv, connection * const c } if (con->conf.log_request_header) { - log_error(con->errh, __FILE__, __LINE__, + log_error(con->conf.errh, __FILE__, __LINE__, "fd: %d request-len: %d\n%.*s", con->fd, (int)con->header_len, (int)con->header_len, hdrs); } @@ -866,7 +863,7 @@ static int connection_handle_read_state(server * const srv, connection * const c if (srv->srvconf.log_request_header_on_error) { /*(http_request_parse() modifies hdrs only to * undo line-wrapping in-place using spaces)*/ - log_error(con->errh, __FILE__, __LINE__, "request-header:\n%.*s", + log_error(con->conf.errh, __FILE__, __LINE__, "request-header:\n%.*s", (int)con->header_len, hdrs); } } @@ -954,8 +951,8 @@ static handler_t connection_handle_fdevent(server *srv, void *context, int reven } else if (revents & FDEVENT_ERR) { /* error, connection reset */ connection_set_state(con, CON_STATE_ERROR); } else { - log_error_write(srv, __FILE__, __LINE__, "sd", - "connection closed: poll() -> ???", revents); + log_error(con->conf.errh, __FILE__, __LINE__, + "connection closed: poll() -> ??? %d", revents); } } @@ -994,7 +991,7 @@ connection *connection_accept(server *srv, server_socket *srv_socket) { /* out of fds */ break; default: - log_error_write(srv, __FILE__, __LINE__, "ssd", "accept failed:", strerror(errno), errno); + log_perror(srv->errh, __FILE__, __LINE__, "accept failed"); } return NULL; } else { @@ -1007,7 +1004,7 @@ connection *connection_accept(server *srv, server_socket *srv_socket) { /* 0: everything ok, -1: error, -2: con closed */ -static int connection_read_cq(server *srv, connection *con, chunkqueue *cq, off_t max_bytes) { +static int connection_read_cq(connection *con, chunkqueue *cq, off_t max_bytes) { ssize_t len; char *mem = NULL; size_t mem_len = 0; @@ -1051,7 +1048,7 @@ static int connection_read_cq(server *srv, connection *con, chunkqueue *cq, off_ /* suppress logging for this error, expected for keep-alive */ break; default: - log_error_write(srv, __FILE__, __LINE__, "sd", "connection closed - recv failed: ", lastError); + log_error(con->conf.errh, __FILE__, __LINE__, "connection closed - recv failed: %d", lastError); break; } } @@ -1067,7 +1064,7 @@ static int connection_read_cq(server *srv, connection *con, chunkqueue *cq, off_ /* suppress logging for this error, expected for keep-alive */ break; default: - log_error_write(srv, __FILE__, __LINE__, "ssd", "connection closed - read failed: ", strerror(errno), errno); + log_perror(con->conf.errh, __FILE__, __LINE__, "connection closed - read failed"); break; } #endif /* __WIN32 */ @@ -1093,8 +1090,9 @@ static int connection_read_cq(server *srv, connection *con, chunkqueue *cq, off_ } -static int connection_write_cq(server *srv, connection *con, chunkqueue *cq, off_t max_bytes) { - return srv->network_backend_write(srv, con->fd, cq, max_bytes); +static int connection_write_cq(connection *con, chunkqueue *cq, off_t max_bytes) { + server * const srv = con->srv; + return srv->network_backend_write(con->fd, cq, max_bytes, con->conf.errh); } @@ -1105,13 +1103,12 @@ connection *connection_accepted(server *srv, server_socket *srv_socket, sock_add /* ok, we have the connection, register it */ #if 0 - log_error_write(srv, __FILE__, __LINE__, "sd", - "appected()", cnt); + log_error(srv->errh, __FILE__, __LINE__, "accepted() %d", cnt); #endif srv->con_opened++; con = connections_get_new_connection(srv); - con->errh = srv->errh; + con->conf.errh = srv->errh; con->srv = srv; con->fd = cnt; @@ -1127,7 +1124,7 @@ connection *connection_accepted(server *srv, server_socket *srv_socket, sock_add con->srv_socket = srv_socket; con->is_ssl_sock = srv_socket->is_ssl; - config_cond_cache_reset(srv, con); + config_cond_cache_reset(con); con->conditional_is_valid |= (1 << COMP_SERVER_SOCKET) | (1 << COMP_HTTP_REMOTE_IP); @@ -1229,7 +1226,7 @@ static int connection_handle_request(server *srv, connection *con) { connection_set_state(con, CON_STATE_RESPONSE_START); break; case HANDLER_WAIT_FOR_FD: - connection_fdwaitqueue_append(srv, con); + connection_fdwaitqueue_append(con); break; case HANDLER_COMEBACK: if (con->mode == DIRECT && buffer_is_empty(con->physical.path)) { @@ -1241,7 +1238,7 @@ static int connection_handle_request(server *srv, connection *con) { connection_set_state(con, CON_STATE_ERROR); break; default: - log_error_write(srv, __FILE__, __LINE__, "sdd", "unknown ret-value: ", con->fd, r); + log_error(con->conf.errh, __FILE__, __LINE__, "unknown ret-value: %d %d", con->fd, r); break; } @@ -1255,16 +1252,14 @@ int connection_state_machine(server *srv, connection *con) { const int log_state_handling = srv->srvconf.log_state_handling; if (log_state_handling) { - log_error_write(srv, __FILE__, __LINE__, "sds", - "state at enter", - con->fd, - connection_get_state(con->state)); + log_error(con->conf.errh, __FILE__, __LINE__, + "state at enter %d %s", con->fd, connection_get_state(con->state)); } do { if (log_state_handling) { - log_error_write(srv, __FILE__, __LINE__, "sds", - "state for fd", con->fd, connection_get_state(con->state)); + log_error(con->conf.errh, __FILE__, __LINE__, + "state for fd %d %s", con->fd, connection_get_state(con->state)); } switch ((ostate = con->state)) { @@ -1325,17 +1320,15 @@ int connection_state_machine(server *srv, connection *con) { case CON_STATE_CONNECT: break; default: - log_error_write(srv, __FILE__, __LINE__, "sdd", - "unknown state:", con->fd, con->state); + log_error(con->conf.errh, __FILE__, __LINE__, + "unknown state: %d %d", con->fd, con->state); break; } } while (ostate != con->state); if (log_state_handling) { - log_error_write(srv, __FILE__, __LINE__, "sds", - "state at exit:", - con->fd, - connection_get_state(con->state)); + log_error(con->conf.errh, __FILE__, __LINE__, + "state at exit: %d %s", con->fd, connection_get_state(con->state)); } r = 0; @@ -1408,7 +1401,7 @@ static void connection_check_timeout (server * const srv, const time_t cur_ts, c if (cur_ts - con->read_idle_ts > con->conf.max_read_idle) { /* time - out */ if (con->conf.log_request_handling) { - log_error(con->errh, __FILE__, __LINE__, + log_error(con->conf.errh, __FILE__, __LINE__, "connection closed - read timeout: %d", con->fd); } @@ -1419,7 +1412,7 @@ static void connection_check_timeout (server * const srv, const time_t cur_ts, c if (cur_ts - con->read_idle_ts > con->keep_alive_idle) { /* time - out */ if (con->conf.log_request_handling) { - log_error(con->errh, __FILE__, __LINE__, + log_error(con->conf.errh, __FILE__, __LINE__, "connection closed - keep-alive timeout: %d", con->fd); } @@ -1439,7 +1432,7 @@ static void connection_check_timeout (server * const srv, const time_t cur_ts, c (con->write_request_ts != 0)) { #if 0 if (cur_ts - con->write_request_ts > 60) { - log_error(con->errh, __FILE__, __LINE__, + log_error(con->conf.errh, __FILE__, __LINE__, "connection closed - pre-write-request-timeout: %d %d", con->fd, cur_ts - con->write_request_ts); } @@ -1448,7 +1441,7 @@ static void connection_check_timeout (server * const srv, const time_t cur_ts, c if (cur_ts - con->write_request_ts > con->conf.max_write_idle) { /* time - out */ if (con->conf.log_timeouts) { - log_error(con->errh, __FILE__, __LINE__, + log_error(con->conf.errh, __FILE__, __LINE__, "NOTE: a request from %.*s for %.*s timed out after writing " "%zd bytes. We waited %d seconds. If this is a problem, " "increase server.max-write-idle", diff --git a/src/connections.h b/src/connections.h index 8c5fe967..f4a2bae6 100644 --- a/src/connections.h +++ b/src/connections.h @@ -19,8 +19,8 @@ const char * connection_get_state(connection_state_t state); const char * connection_get_short_state(connection_state_t state); int connection_state_machine(server *srv, connection *con); handler_t connection_handle_read_post_state(server *srv, connection *con); -handler_t connection_handle_read_post_error(server *srv, connection *con, int http_status); -int connection_write_chunkqueue(server *srv, connection *con, chunkqueue *c, off_t max_bytes); +handler_t connection_handle_read_post_error(connection *con, int http_status); +int connection_write_chunkqueue(connection *con, chunkqueue *c, off_t max_bytes); void connection_response_reset(server *srv, connection *con); #define joblist_append(srv, con) connection_list_append(&(srv)->joblist, (con)) diff --git a/src/fdevent.c b/src/fdevent.c index 0535b615..40a34520 100644 --- a/src/fdevent.c +++ b/src/fdevent.c @@ -65,8 +65,8 @@ int fdevent_config(server *srv) { srv->event_handler = event_handlers[0].et; if (FDEVENT_HANDLER_UNSET == srv->event_handler) { - log_error_write(srv, __FILE__, __LINE__, "s", - "sorry, there is no event handler for this system"); + log_error(srv->errh, __FILE__, __LINE__, + "sorry, there is no event handler for this system"); return -1; } @@ -193,8 +193,8 @@ fdevents *fdevent_init(server *srv) { ev->srv = srv; ev->fdarray = calloc(maxfds, sizeof(*ev->fdarray)); if (NULL == ev->fdarray) { - log_error_write(srv, __FILE__, __LINE__, "SDS", - "server.max-fds too large? (", maxfds-1, ")"); + log_error(srv->errh, __FILE__, __LINE__, + "server.max-fds too large? (%zu)", maxfds-1); free(ev); return NULL; } @@ -340,7 +340,7 @@ static void fdevent_sched_run(fdevents *ev) { #endif if (0 != rc) { - log_error_write(srv, __FILE__, __LINE__, "sds", "close failed ", fd, strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, "close failed %d", fd); } else { --srv->cur_fds; @@ -372,9 +372,8 @@ static int fdevent_fdnode_event_unsetter_retry(fdevents *ev, fdnode *fdn) { /*case ENOMEM:*/ default: /* unrecoverable error; might leak fd */ - log_error_write(ev->srv, __FILE__, __LINE__, "sDsS", - "fdevent event_del failed on fd", fdn->fd, ":", - strerror(errno)); + log_perror(ev->srv->errh, __FILE__, __LINE__, + "fdevent event_del failed on fd %d", fdn->fd); return 0; } } while (0 != ev->event_del(ev, fdn)); @@ -406,9 +405,8 @@ static int fdevent_fdnode_event_setter_retry(fdevents *ev, fdnode *fdn, int even /*case ENOMEM:*/ default: /* unrecoverable error */ - log_error_write(ev->srv, __FILE__, __LINE__, "sDsS", - "fdevent event_set failed on fd", fdn->fd, ":", - strerror(errno)); + log_perror(ev->srv->errh, __FILE__, __LINE__, + "fdevent event_set failed on fd %d", fdn->fd); return 0; } } while (0 != ev->event_set(ev, fdn, events)); @@ -448,8 +446,7 @@ int fdevent_poll(fdevents *ev, int timeout_ms) { if (n >= 0) fdevent_sched_run(ev); else if (errno != EINTR) - log_error_write(ev->srv, __FILE__, __LINE__, "SS", - "fdevent_poll failed: ", strerror(errno)); + log_perror(ev->srv->errh, __FILE__, __LINE__, "fdevent_poll failed"); return n; } diff --git a/src/fdevent_solaris_port.c b/src/fdevent_solaris_port.c index ac50bb60..0ce5269e 100644 --- a/src/fdevent_solaris_port.c +++ b/src/fdevent_solaris_port.c @@ -64,8 +64,8 @@ static int fdevent_solaris_port_poll(fdevents *ev, int timeout_ms) { int revents = ev->port_events[i].portev_events; if (0 == ((uintptr_t)fdn & 0x3)) { if (port_associate(pfd,PORT_SOURCE_FD,fd,(int)ud,(void*)ud) < 0) { - log_error_write(ev->srv, __FILE__, __LINE__, "SS", - "port_associate failed: ", strerror(errno)); + log_error(ev->srv->errh, __FILE__, __LINE__, + "port_associate failed"); } (*fdn->handler)(ev->srv, fdn->ctx, revents); } diff --git a/src/gw_backend.c b/src/gw_backend.c index 55a9f503..541c5721 100644 --- a/src/gw_backend.c +++ b/src/gw_backend.c @@ -199,18 +199,18 @@ static void gw_proc_connect_success(server *srv, gw_host *host, gw_proc *proc, i proc->last_used = srv->cur_ts; if (debug) { - log_error_write(srv, __FILE__, __LINE__, "ssdsbsd", - "got proc:", - "pid:", proc->pid, - "socket:", proc->connection_name, - "load:", proc->load); + log_error(srv->errh, __FILE__, __LINE__, + "got proc: pid: %d socket: %s load: %d", + proc->pid, proc->connection_name->ptr, proc->load); } } +__attribute_cold__ static void gw_proc_connect_error(server *srv, gw_host *host, gw_proc *proc, pid_t pid, int errnum, int debug) { - log_error_write(srv, __FILE__, __LINE__, "sssb", - "establishing connection failed:", strerror(errnum), - "socket:", proc->connection_name); + log_error_st *errh = srv->errh; + log_error(errh, __FILE__, __LINE__, + "establishing connection failed: socket: %s: %s", + proc->connection_name->ptr, strerror(errnum)); if (!proc->is_local) { proc->disabled_until = srv->cur_ts + host->disable_time; @@ -225,24 +225,24 @@ static void gw_proc_connect_error(server *srv, gw_host *host, gw_proc *proc, pid * If a new proc was started with the old struct, this might * otherwise lead to marking a perfectly good proc as dead */ - log_error_write(srv, __FILE__, __LINE__, "sdssd", - "backend error; we'll disable for", host->disable_time, - "secs and send the request to another backend instead:", - "load:", host->load); + log_error(errh, __FILE__, __LINE__, + "backend error; we'll disable for %d" + "secs and send the request to another backend instead:" + "load: %d", host->disable_time, host->load); if (EAGAIN == errnum) { /* - EAGAIN: cool down the backend; it is overloaded */ #ifdef __linux__ - log_error_write(srv, __FILE__, __LINE__, "s", + log_error(errh, __FILE__, __LINE__, "If this happened on Linux: You have run out of local ports. " "Check the manual, section Performance how to handle this."); #endif if (debug) { - log_error_write(srv, __FILE__, __LINE__, "sbsd", + log_error(errh, __FILE__, __LINE__, "This means that you have more incoming requests than your " "FastCGI backend can handle in parallel. It might help to " "spawn more FastCGI backends or PHP children; if not, " "decrease server.max-connections. The load for this FastCGI " - "backend", proc->connection_name, "is", proc->load); + "backend %s is %d", proc->connection_name->ptr, proc->load); } proc->disabled_until = srv->cur_ts + host->disable_time; gw_proc_set_state(host, proc, PROC_STATE_OVERLOADED); @@ -273,11 +273,9 @@ static void gw_proc_release(server *srv, gw_host *host, gw_proc *proc, int debug gw_proc_load_dec(srv, host, proc); if (debug) { - log_error_write(srv, __FILE__, __LINE__, "ssdsbsd", - "released proc:", - "pid:", proc->pid, - "socket:", proc->connection_name, - "load:", proc->load); + log_error(srv->errh, __FILE__, __LINE__, + "released proc: pid: %d socket: %s load: %u", + proc->pid, proc->connection_name->ptr, proc->load); } } @@ -287,28 +285,29 @@ static void gw_proc_check_enable(server *srv, gw_host *host, gw_proc *proc) { gw_proc_set_state(host, proc, PROC_STATE_RUNNING); - log_error_write(srv, __FILE__, __LINE__, "sbbdb", - "gw-server re-enabled:", proc->connection_name, - host->host, host->port, host->unixsocket); + log_error(srv->errh, __FILE__, __LINE__, + "gw-server re-enabled: %s %s %hu %s", + proc->connection_name->ptr, host->host->ptr, host->port, + host->unixsocket->ptr ? host->unixsocket->ptr : ""); } static void gw_proc_waitpid_log(server *srv, gw_host *host, gw_proc *proc, int status) { UNUSED(host); if (WIFEXITED(status)) { if (proc->state != PROC_STATE_KILLED) { - log_error_write(srv, __FILE__, __LINE__, "sdb", - "child exited:", - WEXITSTATUS(status), proc->connection_name); + log_error(srv->errh, __FILE__, __LINE__, + "child exited: %d %s", + WEXITSTATUS(status), proc->connection_name->ptr); } } else if (WIFSIGNALED(status)) { if (WTERMSIG(status) != SIGTERM && WTERMSIG(status) != SIGINT && WTERMSIG(status) != host->kill_signal) { - log_error_write(srv, __FILE__, __LINE__, "sd", - "child signalled:", WTERMSIG(status)); + log_error(srv->errh, __FILE__, __LINE__, + "child signalled: %d", WTERMSIG(status)); } } else { - log_error_write(srv, __FILE__, __LINE__, "sd", - "child died somehow:", status); + log_error(srv->errh, __FILE__, __LINE__, + "child died somehow: %d", status); } } @@ -327,9 +326,8 @@ static int gw_proc_waitpid(server *srv, gw_host *host, gw_proc *proc) { if (-1 == rc) { /* EINVAL or ECHILD no child processes */ /* should not happen; someone else has cleaned up for us */ - log_error_write(srv, __FILE__, __LINE__, "sddss", - "pid ", proc->pid, proc->state, - "not found:", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, + "pid %d %d not found", proc->pid, proc->state); } else { gw_proc_waitpid_log(srv, host, proc, status); @@ -347,8 +345,8 @@ static int gw_proc_sockaddr_init(server *srv, gw_host *host, gw_proc *proc) { socklen_t addrlen; if (!buffer_string_is_empty(proc->unixsocket)) { - if (1 != sock_addr_from_str_hints(srv, &addr, &addrlen, - proc->unixsocket->ptr, AF_UNIX, 0)) { + if (1 != sock_addr_from_str_hints(&addr,&addrlen,proc->unixsocket->ptr, + AF_UNIX, 0, srv->errh)) { errno = EINVAL; return -1; } @@ -357,8 +355,8 @@ static int gw_proc_sockaddr_init(server *srv, gw_host *host, gw_proc *proc) { } else { /*(note: name resolution here is *blocking* if IP string not supplied)*/ - if (1 != sock_addr_from_str_hints(srv, &addr, &addrlen, - host->host->ptr, 0, proc->port)) { + if (1 != sock_addr_from_str_hints(&addr, &addrlen, host->host->ptr, + 0, proc->port, srv->errh)) { errno = EINVAL; return -1; } @@ -425,14 +423,14 @@ static int gw_spawn_connection(server *srv, gw_host *host, gw_proc *proc, int de struct timeval tv = { 0, 10 * 1000 }; if (debug) { - log_error_write(srv, __FILE__, __LINE__, "sdb", - "new proc, socket:", proc->port, proc->unixsocket); + log_error(srv->errh, __FILE__, __LINE__, + "new proc, socket: %hu %s", + proc->port, proc->unixsocket->ptr ? proc->unixsocket->ptr : ""); } gw_fd = fdevent_socket_cloexec(proc->saddr->sa_family, SOCK_STREAM, 0); if (-1 == gw_fd) { - log_error_write(srv, __FILE__, __LINE__, "ss", - "failed:", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, "socket()"); return -1; } @@ -442,9 +440,8 @@ static int gw_spawn_connection(server *srv, gw_host *host, gw_proc *proc, int de if (-1 == status && errno != ENOENT && !buffer_string_is_empty(proc->unixsocket)) { - log_error_write(srv, __FILE__, __LINE__, "sbss", - "unlink", proc->unixsocket, - "after connect failed:", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, + "unlink %s after connect failed", proc->unixsocket->ptr); unlink(proc->unixsocket->ptr); } @@ -459,31 +456,26 @@ static int gw_spawn_connection(server *srv, gw_host *host, gw_proc *proc, int de /* reopen socket */ gw_fd = fdevent_socket_cloexec(proc->saddr->sa_family, SOCK_STREAM, 0); if (-1 == gw_fd) { - log_error_write(srv, __FILE__, __LINE__, "ss", - "socket failed:", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, "socket()"); return -1; } if (fdevent_set_so_reuseaddr(gw_fd, 1) < 0) { - log_error_write(srv, __FILE__, __LINE__, "ss", - "socketsockopt failed:", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, "socketsockopt()"); close(gw_fd); return -1; } /* create socket */ if (-1 == bind(gw_fd, proc->saddr, proc->saddrlen)) { - log_error_write(srv, __FILE__, __LINE__, "sbs", - "bind failed for:", - proc->connection_name, - strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, + "bind failed for: %s", proc->connection_name->ptr); close(gw_fd); return -1; } if (-1 == listen(gw_fd, host->listen_backlog)) { - log_error_write(srv, __FILE__, __LINE__, "ss", - "listen failed:", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, "listen()"); close(gw_fd); return -1; } @@ -543,9 +535,8 @@ static int gw_spawn_connection(server *srv, gw_host *host, gw_proc *proc, int de dfd = fdevent_open_dirname(host->args.ptr[0], 1); /* permit symlinks */ if (-1 == dfd) { - log_error_write(srv, __FILE__, __LINE__, "sss", - "open dirname failed:", strerror(errno), - host->args.ptr[0]); + log_perror(srv->errh, __FILE__, __LINE__, + "open dirname failed: %s", host->args.ptr[0]); } /*(FCGI_LISTENSOCK_FILENO == STDIN_FILENO == 0)*/ @@ -560,8 +551,8 @@ static int gw_spawn_connection(server *srv, gw_host *host, gw_proc *proc, int de close(gw_fd); if (-1 == proc->pid) { - log_error_write(srv, __FILE__, __LINE__, "sb", - "gw-backend failed to start:", host->bin_path); + log_error(srv->errh, __FILE__, __LINE__, + "gw-backend failed to start: %s", host->bin_path->ptr); proc->pid = 0; proc->disabled_until = srv->cur_ts; return -1; @@ -575,9 +566,9 @@ static int gw_spawn_connection(server *srv, gw_host *host, gw_proc *proc, int de select(0, NULL, NULL, NULL, &tv); if (0 != gw_proc_waitpid(srv, host, proc)) { - log_error_write(srv, __FILE__, __LINE__, "sb", - "gw-backend failed to start:", host->bin_path); - log_error_write(srv, __FILE__, __LINE__, "s", + log_error(srv->errh, __FILE__, __LINE__, + "gw-backend failed to start: %s", host->bin_path->ptr); + log_error(srv->errh, __FILE__, __LINE__, "If you're trying to run your app as a FastCGI backend, make " "sure you're using the FastCGI-enabled version. If this is PHP " "on Gentoo, add 'fastcgi' to the USE flags. If this is PHP, try " @@ -589,9 +580,9 @@ static int gw_spawn_connection(server *srv, gw_host *host, gw_proc *proc, int de proc->pid = 0; if (debug) { - log_error_write(srv, __FILE__, __LINE__, "sb", - "(debug) socket is already used; won't spawn:", - proc->connection_name); + log_error(srv->errh, __FILE__, __LINE__, + "(debug) socket is already used; won't spawn: %s", + proc->connection_name->ptr); } } @@ -638,14 +629,14 @@ static void gw_proc_spawn(server *srv, gw_host *host, int debug) { if (0 != gw_proc_sockaddr_init(srv, host, proc)) { /*(should not happen if host->host validated at startup, * and translated from name to IP address at startup)*/ - log_error_write(srv, __FILE__, __LINE__, "s", - "ERROR: spawning backend failed."); + log_error(srv->errh, __FILE__, __LINE__, + "ERROR: spawning backend failed."); --host->num_procs; if (proc->id == host->max_id-1) --host->max_id; gw_proc_free(proc); } else if (gw_spawn_connection(srv, host, proc, debug)) { - log_error_write(srv, __FILE__, __LINE__, "s", - "ERROR: spawning backend failed."); + log_error(srv->errh, __FILE__, __LINE__, + "ERROR: spawning backend failed."); proc->next = host->unused_procs; if (host->unused_procs) host->unused_procs->prev = proc; @@ -783,9 +774,8 @@ static gw_host * gw_host_get(server *srv, connection *con, gw_extension *extensi /* hash balancing */ if (debug) { - log_error_write(srv, __FILE__, __LINE__, "sd", - "proxy - used hash balancing, hosts:", - extension->used); + log_error(srv->errh, __FILE__, __LINE__, + "proxy - used hash balancing, hosts: %u", extension->used); } for (k = 0, ndx = -1, last_max = ULONG_MAX; k < extension->used; ++k) { @@ -798,9 +788,9 @@ static gw_host * gw_host_get(server *srv, connection *con, gw_extension *extensi + generate_crc32c(CONST_BUF_LEN(con->uri.authority)); if (debug) { - log_error_write(srv, __FILE__, __LINE__, "sbbbd", - "proxy - election:", con->uri.path, - host->host, con->uri.authority, cur_max); + log_error(srv->errh, __FILE__, __LINE__, + "proxy - election: %s %s %s %lu", con->uri.path->ptr, + host->host->ptr, con->uri.authority->ptr, cur_max); } if (last_max < cur_max || last_max == ULONG_MAX) { @@ -813,8 +803,8 @@ static gw_host * gw_host_get(server *srv, connection *con, gw_extension *extensi case GW_BALANCE_LEAST_CONNECTION: /* fair balancing */ if (debug) { - log_error_write(srv, __FILE__, __LINE__, "s", - "proxy - used least connection"); + log_error(srv->errh, __FILE__, __LINE__, + "proxy - used least connection"); } for (k = 0, ndx = -1, max_usage = INT_MAX; k < extension->used; ++k) { @@ -831,8 +821,8 @@ static gw_host * gw_host_get(server *srv, connection *con, gw_extension *extensi case GW_BALANCE_RR: /* round robin */ if (debug) { - log_error_write(srv, __FILE__, __LINE__, "s", - "proxy - used round-robin balancing"); + log_error(srv->errh, __FILE__, __LINE__, + "proxy - used round-robin balancing"); } /* just to be sure */ @@ -868,9 +858,8 @@ static gw_host * gw_host_get(server *srv, connection *con, gw_extension *extensi /* source sticky balancing */ if (debug) { - log_error_write(srv, __FILE__, __LINE__, "sd", - "proxy - used sticky balancing, hosts:", - extension->used); + log_error(srv->errh, __FILE__, __LINE__, + "proxy - used sticky balancing, hosts: %u", extension->used); } for (k = 0, ndx = -1, last_max = ULONG_MAX; k < extension->used; ++k) { @@ -884,9 +873,9 @@ static gw_host * gw_host_get(server *srv, connection *con, gw_extension *extensi + host->port; if (debug) { - log_error_write(srv, __FILE__, __LINE__, "sbbdd", - "proxy - election:", con->dst_addr_buf, - host->host, host->port, cur_max); + log_error(srv->errh, __FILE__, __LINE__, + "proxy - election: %s %s %hu %ld", con->dst_addr_buf->ptr, + host->host->ptr, host->port, cur_max); } if (last_max < cur_max || last_max == ULONG_MAX) { @@ -905,8 +894,8 @@ static gw_host * gw_host_get(server *srv, connection *con, gw_extension *extensi host = extension->hosts[ndx]; if (debug) { - log_error_write(srv, __FILE__, __LINE__, "sbd", - "gw - found a host", host->host, host->port); + log_error(srv->errh, __FILE__, __LINE__, + "gw - found a host %s %hu", host->host->ptr, host->port); } return host; @@ -930,9 +919,10 @@ static gw_host * gw_host_get(server *srv, connection *con, gw_extension *extensi /* only send the 'no handler' once */ if (!extension->note_is_sent) { extension->note_is_sent = 1; - log_error_write(srv, __FILE__, __LINE__, "sBSbsbs", - "all handlers for", con->uri.path, "?", - con->uri.query, "on", &extension->key, "are down."); + log_error(srv->errh, __FILE__, __LINE__, + "all handlers for %s?%.*s on %s are down.", + con->uri.path->ptr, BUFFER_INTLEN_PTR(con->uri.query), + extension->key.ptr); } return NULL; @@ -940,13 +930,11 @@ static gw_host * gw_host_get(server *srv, connection *con, gw_extension *extensi static int gw_establish_connection(server *srv, gw_host *host, gw_proc *proc, pid_t pid, int gw_fd, int debug) { if (-1 == connect(gw_fd, proc->saddr, proc->saddrlen)) { - if (errno == EINPROGRESS || - errno == EALREADY || - errno == EINTR) { + if (errno == EINPROGRESS || errno == EALREADY || errno == EINTR) { if (debug > 2) { - log_error_write(srv, __FILE__, __LINE__, "sb", - "connect delayed; will continue later:", - proc->connection_name); + log_error(srv->errh, __FILE__, __LINE__, + "connect delayed; will continue later: %s", + proc->connection_name->ptr); } return 1; @@ -957,8 +945,8 @@ static int gw_establish_connection(server *srv, gw_host *host, gw_proc *proc, pi } if (debug > 1) { - log_error_write(srv, __FILE__, __LINE__, "sd", - "connect succeeded: ", gw_fd); + log_error(srv->errh, __FILE__, __LINE__, + "connect succeeded: %d", gw_fd); } return 0; @@ -967,9 +955,9 @@ static int gw_establish_connection(server *srv, gw_host *host, gw_proc *proc, pi static void gw_restart_dead_procs(server *srv, gw_host *host, int debug, int trigger) { for (gw_proc *proc = host->first; proc; proc = proc->next) { if (debug > 2) { - log_error_write(srv, __FILE__, __LINE__, "sbdddd", - "proc:", proc->connection_name, proc->state, - proc->is_local, proc->load, proc->pid); + log_error(srv->errh, __FILE__, __LINE__, + "proc: %s %d %d %d %d", proc->connection_name->ptr, + proc->state, proc->is_local, proc->load, proc->pid); } switch (proc->state) { @@ -1014,15 +1002,16 @@ static void gw_restart_dead_procs(server *srv, gw_host *host, int debug, int tri /* restart the child */ if (debug) { - log_error_write(srv, __FILE__, __LINE__, "ssbsdsd", - "--- gw spawning", - "\n\tsocket", proc->connection_name, - "\n\tcurrent:", 1, "/", host->max_procs); + log_error(srv->errh, __FILE__, __LINE__, + "--- gw spawning" + "\n\tsocket %s" + "\n\tcurrent: 1 / %u", + proc->connection_name->ptr, host->max_procs); } if (gw_spawn_connection(srv, host, proc, debug)) { - log_error_write(srv, __FILE__, __LINE__, "s", - "ERROR: spawning gw failed."); + log_error(srv->errh, __FILE__, __LINE__, + "ERROR: spawning gw failed."); } } else { gw_proc_check_enable(srv, host, proc); @@ -1443,19 +1432,18 @@ int gw_set_defaults_backend(server *srv, gw_plugin_data *p, const array *a, gw_p for (uint32_t m = 0; m < da_host->value.used; ++m) { if (NULL != strchr(da_host->value.data[m]->key.ptr, '_')) { - log_error_write(srv, __FILE__, __LINE__, "sb", - "incorrect directive contains underscore ('_') instead of dash ('-'):", - &da_host->value.data[m]->key); + log_error(srv->errh, __FILE__, __LINE__, + "incorrect directive contains underscore ('_') instead of dash ('-'): %s", + da_host->value.data[m]->key.ptr); } } if ((!buffer_string_is_empty(host->host) || host->port) && !buffer_string_is_empty(host->unixsocket)) { - log_error_write(srv, __FILE__, __LINE__, "sssbsbs", - "either host/port or socket have to be set in:", - cpkkey, "= (", - &da_ext->key, " => (", - &da_host->key, " ( ..."); + log_error(srv->errh, __FILE__, __LINE__, + "either host/port or socket have to be set in: " + "%s = (%s => (%s ( ...", cpkkey, da_ext->key.ptr, + da_host->key.ptr); goto error; } @@ -1470,11 +1458,9 @@ int gw_set_defaults_backend(server *srv, gw_plugin_data *p, const array *a, gw_p struct sockaddr_un un; if (buffer_string_length(host->unixsocket) + 1 > sizeof(un.sun_path) - 2) { - log_error_write(srv, __FILE__, __LINE__, "sssbsbs", - "unixsocket is too long in:", - cpkkey, "= (", - &da_ext->key, " => (", - &da_host->key, " ( ..."); + log_error(srv->errh, __FILE__, __LINE__, + "unixsocket is too long in: %s = (%s => (%s ( ...", + cpkkey, da_ext->key.ptr, da_host->key.ptr); goto error; } @@ -1483,9 +1469,9 @@ int gw_set_defaults_backend(server *srv, gw_plugin_data *p, const array *a, gw_p gw_host *duplicate = unixsocket_is_dup(p, host->unixsocket); if (NULL != duplicate) { if (!buffer_is_equal(host->bin_path, duplicate->bin_path)) { - log_error_write(srv, __FILE__, __LINE__, "sb", - "duplicate unixsocket path:", - host->unixsocket); + log_error(srv->errh, __FILE__, __LINE__, + "duplicate unixsocket path: %s", + host->unixsocket->ptr); goto error; } gw_host_free(host); @@ -1500,11 +1486,10 @@ int gw_set_defaults_backend(server *srv, gw_plugin_data *p, const array *a, gw_p if (buffer_string_is_empty(host->host) && buffer_string_is_empty(host->bin_path)) { - log_error_write(srv, __FILE__, __LINE__, "sssbsbs", - "host or bin-path have to be set in:", - cpkkey, "= (", - &da_ext->key, " => (", - &da_host->key, " ( ..."); + log_error(srv->errh, __FILE__, __LINE__, + "host or bin-path have to be set in: " + "%s = (%s => (%s ( ...", cpkkey, da_ext->key.ptr, + da_host->key.ptr); goto error; } else if (0 == host->port) { @@ -1529,10 +1514,10 @@ int gw_set_defaults_backend(server *srv, gw_plugin_data *p, const array *a, gw_p parse_binpath(&host->args, host->bin_path); if (0 != stat(host->args.ptr[0], &st) || !S_ISREG(st.st_mode) || !(st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))) { - log_error_write(srv, __FILE__, __LINE__, "SSs", - "invalid \"bin-path\" => \"", host->bin_path->ptr, - "\" (check that file exists, is regular file, " - "and is executable by lighttpd)"); + log_error(srv->errh, __FILE__, __LINE__, + "invalid \"bin-path\" => \"%s\" " + "(check that file exists, is regular file, " + "and is executable by lighttpd)", host->bin_path->ptr); } if (sh_exec) { @@ -1569,21 +1554,28 @@ int gw_set_defaults_backend(server *srv, gw_plugin_data *p, const array *a, gw_p if (host->min_procs!= host->max_procs && 0 != srv->srvconf.max_worker) { host->min_procs = host->max_procs; - log_error_write(srv, __FILE__, __LINE__, "s", - "adaptive backend spawning disabled " - "(server.max_worker is non-zero)"); + log_error(srv->errh, __FILE__, __LINE__, + "adaptive backend spawning disabled " + "(server.max_worker is non-zero)"); } if (host->max_load_per_proc < 1) host->max_load_per_proc = 0; if (s->debug) { - log_error_write(srv, __FILE__, __LINE__, "ssbsdsbsdsd", - "--- gw spawning local", - "\n\tproc:", host->bin_path, - "\n\tport:", host->port, - "\n\tsocket", host->unixsocket, - "\n\tmin-procs:", host->min_procs, - "\n\tmax-procs:", host->max_procs); + log_error(srv->errh, __FILE__, __LINE__, + "--- gw spawning local" + "\n\tproc: %s" + "\n\tport: %hu" + "\n\tsocket %s" + "\n\tmin-procs: %d" + "\n\tmax-procs: %d", + host->bin_path->ptr, + host->port, + host->unixsocket && host->unixsocket->ptr + ? host->unixsocket->ptr + : "", + host->min_procs, + host->max_procs); } for (uint32_t pno = 0; pno < host->min_procs; ++pno) { @@ -1601,11 +1593,16 @@ int gw_set_defaults_backend(server *srv, gw_plugin_data *p, const array *a, gw_p } if (s->debug) { - log_error_write(srv, __FILE__, __LINE__, "ssdsbsdsd", - "--- gw spawning", - "\n\tport:", host->port, - "\n\tsocket", host->unixsocket, - "\n\tcurrent:", pno, "/", host->max_procs); + log_error(srv->errh, __FILE__, __LINE__, + "--- gw spawning" + "\n\tport: %hu" + "\n\tsocket %s" + "\n\tcurrent: %u / %u", + host->port, + host->unixsocket && host->unixsocket->ptr + ? host->unixsocket->ptr + : "", + pno, host->max_procs); } if (0 != gw_proc_sockaddr_init(srv, host, proc)) { @@ -1615,8 +1612,8 @@ int gw_set_defaults_backend(server *srv, gw_plugin_data *p, const array *a, gw_p if (!srv->srvconf.preflight_check && gw_spawn_connection(srv, host, proc, s->debug)) { - log_error_write(srv, __FILE__, __LINE__, "s", - "[ERROR]: spawning gw failed."); + log_error(srv->errh, __FILE__, __LINE__, + "[ERROR]: spawning gw failed."); gw_proc_free(proc); goto error; } @@ -1700,10 +1697,9 @@ int gw_get_defaults_balance(server *srv, const buffer *b) { if (buffer_eq_slen(b, CONST_STR_LEN("sticky"))) return GW_BALANCE_STICKY; - log_error_write(srv, __FILE__, __LINE__, "sb", - "xxxxx.balance has to be one of: " - "least-connection, round-robin, hash, sticky, but not:", - b); + log_error(srv->errh, __FILE__, __LINE__, + "xxxxx.balance has to be one of: " + "least-connection, round-robin, hash, sticky, but not: %s", b->ptr); return GW_BALANCE_LEAST_CONNECTION; } @@ -1754,7 +1750,7 @@ static void gw_connection_close(server *srv, gw_handler_ctx *hctx) { con->plugin_ctx[p->id] = NULL; if (con->mode == p->id) { - http_response_backend_done(srv, con); + http_response_backend_done(con); } } @@ -1828,16 +1824,16 @@ static handler_t gw_write_request(server *srv, gw_handler_ctx *hctx) { hctx->fd = fdevent_socket_nb_cloexec(hctx->host->family,SOCK_STREAM,0); if (-1 == hctx->fd) { + log_error_st * const errh = hctx->remote_conn->conf.errh; if (errno == EMFILE || errno == EINTR) { - log_error_write(srv, __FILE__, __LINE__, "sd", - "wait for fd at connection:", - hctx->remote_conn->fd); + log_error(errh, __FILE__, __LINE__, + "wait for fd at connection: %d", + hctx->remote_conn->fd); return HANDLER_WAIT_FOR_FD; } - log_error_write(srv, __FILE__, __LINE__, "ssdd", - "socket failed:", strerror(errno), - srv->cur_fds, srv->max_fds); + log_perror(errh, __FILE__, __LINE__, + "socket failed %d %d", srv->cur_fds, srv->max_fds); return HANDLER_ERROR; } @@ -1905,15 +1901,16 @@ static handler_t gw_write_request(server *srv, gw_handler_ctx *hctx) { case GW_STATE_WRITE: if (!chunkqueue_is_empty(hctx->wb)) { int ret; + log_error_st * const errh = hctx->remote_conn->conf.errh; #if 0 if (hctx->conf.debug > 1) { - log_error_write(srv, __FILE__, __LINE__, "sdsx", - "send data to backend ( fd =", hctx->fd, - "), size =", chunkqueue_length(hctx->wb)); + log_error(errh, __FILE__, __LINE__, "sdsx", + "send data to backend (fd=%d), size=%zu", + hctx->fd, chunkqueue_length(hctx->wb)); } #endif - ret = srv->network_backend_write(srv, hctx->fd, hctx->wb, - MAX_WRITE_LIMIT); + ret = srv->network_backend_write(hctx->fd, hctx->wb, + MAX_WRITE_LIMIT, errh); if (ret < 0) { switch(errno) { @@ -1924,15 +1921,15 @@ static handler_t gw_write_request(server *srv, gw_handler_ctx *hctx) { * we don't care about that -- * if you accept() it, you have to handle it. */ - log_error_write(srv, __FILE__, __LINE__, "ssosb", - "connection was dropped after accept() " - "(perhaps the gw process died),", - "write-offset:", hctx->wb->bytes_out, - "socket:", hctx->proc->connection_name); + log_error(errh, __FILE__, __LINE__, + "connection was dropped after accept() " + "(perhaps the gw process died), " + "write-offset: %lld socket: %s", + (long long)hctx->wb->bytes_out, + hctx->proc->connection_name->ptr); return HANDLER_ERROR; default: - log_error_write(srv, __FILE__, __LINE__, "ssd", - "write failed:", strerror(errno), errno); + log_perror(errh, __FILE__, __LINE__, "write failed"); return HANDLER_ERROR; } } @@ -1970,7 +1967,8 @@ static handler_t gw_write_request(server *srv, gw_handler_ctx *hctx) { /* waiting for a response */ return HANDLER_WAIT_FOR_EVENT; default: - log_error_write(srv, __FILE__, __LINE__, "s", "(debug) unknown state"); + log_error(hctx->remote_conn->conf.errh, __FILE__, __LINE__, + "(debug) unknown state"); return HANDLER_ERROR; } } @@ -2081,7 +2079,7 @@ handler_t gw_handle_subrequest(server *srv, connection *con, void *p_d) { * Content-Length with request if request body is present, so * send 411 Length Required if Content-Length missing. */ if (-1 == con->request.content_length) { - return connection_handle_read_post_error(srv, con, 411); + return connection_handle_read_post_error(con, 411); } } } @@ -2109,9 +2107,10 @@ static handler_t gw_recv_response(server *srv, gw_handler_ctx *hctx) { buffer *b = hctx->opts.backend == BACKEND_FASTCGI ? chunk_buffer_acquire() : hctx->response; + log_error_st *errh; handler_t rc = - http_response_read(srv, hctx->remote_conn, &hctx->opts, b, hctx->fdn); + http_response_read(hctx->remote_conn, &hctx->opts, b, hctx->fdn); if (b != hctx->response) chunk_buffer_release(b); @@ -2143,9 +2142,9 @@ static handler_t gw_recv_response(server *srv, gw_handler_ctx *hctx) { /* don't do more than 6 loops here; normally shouldn't happen */ if (++con->loops_per_request > 5) { - log_error_write(srv, __FILE__, __LINE__, "sb", - "too many loops while processing request:", - con->request.orig_uri); + log_error(hctx->remote_conn->conf.errh, __FILE__, __LINE__, + "too many loops while processing request: %s", + con->request.orig_uri->ptr); con->http_status = 500; /* Internal Server Error */ con->mode = DIRECT; return HANDLER_FINISHED; @@ -2173,21 +2172,21 @@ static handler_t gw_recv_response(server *srv, gw_handler_ctx *hctx) { case HANDLER_ERROR: /* (optimization to detect backend process exit while processing a * large number of ready events; (this block could be removed)) */ + errh = hctx->remote_conn->conf.errh; if (proc->is_local && 1 == proc->load && proc->pid == hctx->pid && proc->state != PROC_STATE_DIED && 0 == srv->srvconf.max_worker) { /* intentionally check proc->disabed_until before gw_proc_waitpid */ if (proc->disabled_until < srv->cur_ts && 0 != gw_proc_waitpid(srv, host, proc)) { if (hctx->conf.debug) { - log_error_write(srv, __FILE__, __LINE__, "ssbsdsd", - "--- gw spawning", - "\n\tsocket", proc->connection_name, - "\n\tcurrent:", 1, "/", host->num_procs); + log_error(errh, __FILE__, __LINE__, + "--- gw spawning\n\tsocket %s\n\tcurrent: 1/%d", + proc->connection_name->ptr, host->num_procs); } if (gw_spawn_connection(srv, host, proc, hctx->conf.debug)) { - log_error_write(srv, __FILE__, __LINE__, "s", - "respawning failed, will retry later"); + log_error(errh, __FILE__, __LINE__, + "respawning failed, will retry later"); } } } @@ -2198,27 +2197,30 @@ static handler_t gw_recv_response(server *srv, gw_handler_ctx *hctx) { if (hctx->wb->bytes_out == 0 && hctx->reconnects++ < 5) { - log_error_write(srv, __FILE__, __LINE__, "ssbsBSBs", - "response not received, request not sent", - "on socket:", proc->connection_name, - "for", con->uri.path, "?", con->uri.query, ", reconnecting"); + log_error(errh, __FILE__, __LINE__, + "response not received, request not sent on " + "socket: %s for %s?%.*s, reconnecting", + proc->connection_name->ptr, + con->uri.path->ptr, BUFFER_INTLEN_PTR(con->uri.query)); return gw_reconnect(srv, hctx); } - log_error_write(srv, __FILE__, __LINE__, "sosbsBSBs", - "response not received, request sent:", hctx->wb->bytes_out, - "on socket:", proc->connection_name, "for", - con->uri.path, "?", con->uri.query, ", closing connection"); + log_error(errh, __FILE__, __LINE__, + "response not received, request sent: %lld on " + "socket: %s for %s?%.*s, closing connection", + (long long)hctx->wb->bytes_out, proc->connection_name->ptr, + con->uri.path->ptr, BUFFER_INTLEN_PTR(con->uri.query)); } else { - log_error_write(srv, __FILE__, __LINE__, "ssbsBSBs", - "response already sent out, but backend returned error", - "on socket:", proc->connection_name, "for", - con->uri.path, "?", con->uri.query, ", terminating connection"); + log_error(errh, __FILE__, __LINE__, + "response already sent out, but backend returned error on " + "socket: %s for %s?%.*s, terminating connection", + proc->connection_name->ptr, + con->uri.path->ptr, BUFFER_INTLEN_PTR(con->uri.query)); } if (hctx->backend_error) hctx->backend_error(hctx); - http_response_backend_error(srv, con); + http_response_backend_error(con); gw_connection_close(srv, hctx); return HANDLER_FINISHED; } @@ -2270,20 +2272,20 @@ static handler_t gw_handle_fdevent(server *srv, void *ctx, int revents) { return rc; /* HANDLER_FINISHED or HANDLER_ERROR */ } else { gw_proc *proc = hctx->proc; - log_error_write(srv, __FILE__, __LINE__, "sBSbsbsd", - "error: unexpected close of gw connection for", - con->uri.path, "?", con->uri.query, - "(no gw process on socket:", proc->connection_name, "?)", - hctx->state); + log_error(con->conf.errh, __FILE__, __LINE__, + "error: unexpected close of gw connection for %s?%.*s " + "(no gw process on socket: %s ?) %d", + con->uri.path->ptr, BUFFER_INTLEN_PTR(con->uri.query), + proc->connection_name->ptr, hctx->state); gw_connection_close(srv, hctx); } } else if (revents & FDEVENT_ERR) { - log_error_write(srv, __FILE__, __LINE__, "s", - "gw: got a FDEVENT_ERR. Don't know why."); + log_error(con->conf.errh, __FILE__, __LINE__, + "gw: got a FDEVENT_ERR. Don't know why."); if (hctx->backend_error) hctx->backend_error(hctx); - http_response_backend_error(srv, con); + http_response_backend_error(con); gw_connection_close(srv, hctx); } @@ -2497,7 +2499,7 @@ handler_t gw_check_extension(server *srv, connection *con, gw_plugin_data *p, in con->mode = p->id; if (con->conf.log_request_handling) { - log_error_write(srv, __FILE__, __LINE__, "s", "handling it in mod_gw"); + log_error(con->conf.errh, __FILE__, __LINE__, "handling it in mod_gw"); } return HANDLER_GO_ON; @@ -2541,8 +2543,8 @@ static void gw_handle_trigger_host(server *srv, gw_host *host, int debug) { if (overload && host->num_procs && host->num_procs < host->max_procs) { /* overload, spawn new child */ if (debug) { - log_error_write(srv, __FILE__, __LINE__, "s", - "overload detected, spawning a new child"); + log_error(srv->errh, __FILE__, __LINE__, + "overload detected, spawning a new child"); } gw_proc_spawn(srv, host, debug); @@ -2557,9 +2559,9 @@ static void gw_handle_trigger_host(server *srv, gw_host *host, int debug) { /* terminate proc that has been idling for a long time */ if (debug) { - log_error_write(srv, __FILE__, __LINE__, "ssbsd", - "idle-timeout reached, terminating child:", - "socket:", proc->unixsocket, "pid", proc->pid); + log_error(srv->errh, __FILE__, __LINE__, + "idle-timeout reached, terminating child: socket: %s pid %d", + proc->unixsocket->ptr, proc->pid); } gw_proc_kill(srv, host, proc); @@ -2682,8 +2684,8 @@ handler_t gw_handle_waitpid_cb(server *srv, void *p_d, pid_t pid, int status) { if (proc->state != PROC_STATE_KILLED) proc->disabled_until = srv->cur_ts; if (gw_spawn_connection(srv, host, proc, debug)) { - log_error_write(srv, __FILE__, __LINE__, "s", - "ERROR: spawning gw failed."); + log_error(srv->errh, __FILE__, __LINE__, + "ERROR: spawning gw failed."); } } diff --git a/src/http-header-glue.c b/src/http-header-glue.c index 62c8d62a..1cd83c10 100644 --- a/src/http-header-glue.c +++ b/src/http-header-glue.c @@ -23,7 +23,7 @@ #include -int http_response_buffer_append_authority(server *srv, connection *con, buffer *o) { +static int http_response_buffer_append_authority(connection *con, buffer *o) { if (!buffer_string_is_empty(con->uri.authority)) { buffer_append_string_buffer(o, con->uri.authority); } else { @@ -37,8 +37,7 @@ int http_response_buffer_append_authority(server *srv, connection *con, buffer * if (-1 == getsockname(con->fd, (struct sockaddr *)&our_addr, &our_addr_len) || our_addr_len > (socklen_t)sizeof(our_addr)) { con->http_status = 500; - log_error_write(srv, __FILE__, __LINE__, "ss", - "can't get sockname", strerror(errno)); + log_perror(con->conf.errh, __FILE__, __LINE__, "can't get sockname"); return -1; } @@ -51,7 +50,7 @@ int http_response_buffer_append_authority(server *srv, connection *con, buffer * } else { size_t olen = buffer_string_length(o); - if (0 == sock_addr_nameinfo_append_buffer(srv, o, &our_addr)) { + if (0 == sock_addr_nameinfo_append_buffer(o, &our_addr, con->conf.errh)) { lhost_len = buffer_string_length(o) - olen; if (lhost_len < sizeof(lhost)) { memcpy(lhost, o->ptr+olen, lhost_len+1); /*(+1 for '\0')*/ @@ -70,7 +69,7 @@ int http_response_buffer_append_authority(server *srv, connection *con, buffer * buffer_append_string_buffer(o, con->server_name); } else /* Lookup name: secondly try to get hostname for bind address */ - if (0 != sock_addr_nameinfo_append_buffer(srv, o, &our_addr)) { + if (0 != sock_addr_nameinfo_append_buffer(o, &our_addr, con->conf.errh)) { con->http_status = 500; return -1; } @@ -81,7 +80,7 @@ int http_response_buffer_append_authority(server *srv, connection *con, buffer * if (buffer_is_equal_string(con->uri.scheme, CONST_STR_LEN("https"))) { default_port = 443; } - if (0 == listen_port) listen_port = srv->srvconf.port; + if (0 == listen_port) listen_port = con->srv->srvconf.port; if (default_port != listen_port) { buffer_append_string_len(o, CONST_STR_LEN(":")); buffer_append_int(o, listen_port); @@ -91,11 +90,11 @@ int http_response_buffer_append_authority(server *srv, connection *con, buffer * return 0; } -int http_response_redirect_to_directory(server *srv, connection *con, int status) { - buffer *o = srv->tmp_buf; +int http_response_redirect_to_directory(connection *con, int status) { + buffer *o = con->srv->tmp_buf; buffer_copy_buffer(o, con->uri.scheme); buffer_append_string_len(o, CONST_STR_LEN("://")); - if (0 != http_response_buffer_append_authority(srv, con, o)) { + if (0 != http_response_buffer_append_authority(con, o)) { return -1; } buffer_append_string_encoded(o, CONST_BUF_LEN(con->uri.path), ENCODING_REL_URI); @@ -140,12 +139,11 @@ const buffer * strftime_cache_get(server *srv, time_t last_mod) { } -int http_response_handle_cachable(server *srv, connection *con, const buffer *mtime) { +int http_response_handle_cachable(connection *con, const buffer *mtime) { const buffer *vb; int head_or_get = ( HTTP_METHOD_GET == con->request.http_method || HTTP_METHOD_HEAD == con->request.http_method); - UNUSED(srv); /* * 14.26 If-None-Match @@ -238,7 +236,7 @@ void http_response_body_clear (connection *con, int preserve_length) { } -static int http_response_parse_range(server *srv, connection *con, buffer *path, stat_cache_entry *sce, const char *range) { +static int http_response_parse_range(connection *con, buffer *path, stat_cache_entry *sce, const char *range) { int multipart = 0; int error; off_t start, end; @@ -363,7 +361,7 @@ static int http_response_parse_range(server *srv, connection *con, buffer *path, if (!error) { if (multipart) { /* write boundary-header */ - buffer *b = srv->tmp_buf; + buffer *b = con->srv->tmp_buf; buffer_copy_string_len(b, CONST_STR_LEN("\r\n--")); buffer_append_string_len(b, boundary, sizeof(boundary)-1); @@ -395,34 +393,35 @@ static int http_response_parse_range(server *srv, connection *con, buffer *path, /* something went wrong */ if (error) return -1; + buffer * const tb = con->srv->tmp_buf; + if (multipart) { /* add boundary end */ - buffer *b = srv->tmp_buf; - buffer_copy_string_len(b, "\r\n--", 4); - buffer_append_string_len(b, boundary, sizeof(boundary)-1); - buffer_append_string_len(b, "--\r\n", 4); + buffer_copy_string_len(tb, "\r\n--", 4); + buffer_append_string_len(tb, boundary, sizeof(boundary)-1); + buffer_append_string_len(tb, "--\r\n", 4); - con->response.content_length += buffer_string_length(b); - chunkqueue_append_mem(con->write_queue, CONST_BUF_LEN(b)); + con->response.content_length += buffer_string_length(tb); + chunkqueue_append_mem(con->write_queue, CONST_BUF_LEN(tb)); /* set header-fields */ - buffer_copy_string_len(srv->tmp_buf, CONST_STR_LEN("multipart/byteranges; boundary=")); - buffer_append_string_len(srv->tmp_buf, boundary, sizeof(boundary)-1); + buffer_copy_string_len(tb, CONST_STR_LEN("multipart/byteranges; boundary=")); + buffer_append_string_len(tb, boundary, sizeof(boundary)-1); /* overwrite content-type */ - http_header_response_set(con, HTTP_HEADER_CONTENT_TYPE, CONST_STR_LEN("Content-Type"), CONST_BUF_LEN(srv->tmp_buf)); + http_header_response_set(con, HTTP_HEADER_CONTENT_TYPE, CONST_STR_LEN("Content-Type"), CONST_BUF_LEN(tb)); } else { /* add Content-Range-header */ - buffer_copy_string_len(srv->tmp_buf, CONST_STR_LEN("bytes ")); - buffer_append_int(srv->tmp_buf, start); - buffer_append_string_len(srv->tmp_buf, CONST_STR_LEN("-")); - buffer_append_int(srv->tmp_buf, end); - buffer_append_string_len(srv->tmp_buf, CONST_STR_LEN("/")); - buffer_append_int(srv->tmp_buf, sce->st.st_size); + buffer_copy_string_len(tb, CONST_STR_LEN("bytes ")); + buffer_append_int(tb, start); + buffer_append_string_len(tb, CONST_STR_LEN("-")); + buffer_append_int(tb, end); + buffer_append_string_len(tb, CONST_STR_LEN("/")); + buffer_append_int(tb, sce->st.st_size); - http_header_response_set(con, HTTP_HEADER_OTHER, CONST_STR_LEN("Content-Range"), CONST_BUF_LEN(srv->tmp_buf)); + http_header_response_set(con, HTTP_HEADER_OTHER, CONST_STR_LEN("Content-Range"), CONST_BUF_LEN(tb)); } /* ok, the file is set-up */ @@ -430,7 +429,8 @@ static int http_response_parse_range(server *srv, connection *con, buffer *path, } -void http_response_send_file (server *srv, connection *con, buffer *path) { +void http_response_send_file (connection *con, buffer *path) { + server * const srv = con->srv; stat_cache_entry *sce = NULL; const buffer *mtime = NULL; const buffer *vb; @@ -438,36 +438,31 @@ void http_response_send_file (server *srv, connection *con, buffer *path) { if (HANDLER_ERROR == stat_cache_get_entry(srv, con, path, &sce)) { con->http_status = (errno == ENOENT) ? 404 : 403; - - log_error_write(srv, __FILE__, __LINE__, "sbsb", - "not a regular file:", con->uri.path, - "->", path); - + log_error(con->conf.errh, __FILE__, __LINE__, + "not a regular file: %s -> %s", con->uri.path->ptr, path->ptr); return; } if (!con->conf.follow_symlink && 0 != stat_cache_path_contains_symlink(con, path)) { con->http_status = 403; - if (con->conf.log_request_handling) { - log_error_write(srv, __FILE__, __LINE__, "s", "-- access denied due symlink restriction"); - log_error_write(srv, __FILE__, __LINE__, "sb", "Path :", path); + log_error(con->conf.errh, __FILE__, __LINE__, + "-- access denied due symlink restriction"); + log_error(con->conf.errh, __FILE__, __LINE__, + "Path : %s", path->ptr); } - return; } /* we only handle regular files */ if (!S_ISREG(sce->st.st_mode)) { con->http_status = 403; - if (con->conf.log_file_not_found) { - log_error_write(srv, __FILE__, __LINE__, "sbsb", - "not a regular file:", con->uri.path, - "->", sce->name); + log_error(con->conf.errh, __FILE__, __LINE__, + "not a regular file: %s -> %s", + con->uri.path->ptr, sce->name->ptr); } - return; } @@ -479,7 +474,8 @@ void http_response_send_file (server *srv, connection *con, buffer *path) { if (fd < 0 && 0 != sce->st.st_size) { con->http_status = (errno == ENOENT) ? 404 : 403; if (con->conf.log_request_handling) { - log_error_write(srv, __FILE__, __LINE__, "sbs", "file open failed:", path, strerror(errno)); + log_perror(con->conf.errh, __FILE__, __LINE__, + "file open failed: %s", path->ptr); } return; } @@ -525,7 +521,7 @@ void http_response_send_file (server *srv, connection *con, buffer *path) { http_header_response_set(con, HTTP_HEADER_LAST_MODIFIED, CONST_STR_LEN("Last-Modified"), CONST_BUF_LEN(mtime)); } - if (HANDLER_FINISHED == http_response_handle_cachable(srv, con, mtime)) { + if (HANDLER_FINISHED == http_response_handle_cachable(con, mtime)) { if (fd >= 0) close(fd); return; } @@ -577,7 +573,7 @@ void http_response_send_file (server *srv, connection *con, buffer *path) { /* content prepared, I'm done */ con->file_finished = 1; - if (0 == http_response_parse_range(srv, con, path, sce, range->ptr+6)) { + if (0 == http_response_parse_range(con, path, sce, range->ptr+6)) { con->http_status = 206; } close(fd); @@ -591,7 +587,7 @@ void http_response_send_file (server *srv, connection *con, buffer *path) { * the HEAD request will drop it afterwards again */ - if (0 == http_chunk_append_file_fd(srv, con, path, fd, sce->st.st_size)) { + if (0 == http_chunk_append_file_fd(con, path, fd, sce->st.st_size)) { con->http_status = 200; con->file_finished = 1; } @@ -601,7 +597,7 @@ void http_response_send_file (server *srv, connection *con, buffer *path) { } -static void http_response_xsendfile (server *srv, connection *con, buffer *path, const array *xdocroot) { +static void http_response_xsendfile (connection *con, buffer *path, const array *xdocroot) { const int status = con->http_status; int valid = 1; @@ -616,8 +612,8 @@ static void http_response_xsendfile (server *srv, connection *con, buffer *path, buffer_urldecode_path(path); if (!buffer_is_valid_UTF8(path)) { - log_error_write(srv, __FILE__, __LINE__, "sb", - "X-Sendfile invalid UTF-8 after url-decode:", path); + log_error(con->conf.errh, __FILE__, __LINE__, + "X-Sendfile invalid UTF-8 after url-decode: %s", path->ptr); if (con->http_status < 400) { con->http_status = 502; con->mode = DIRECT; @@ -646,15 +642,14 @@ static void http_response_xsendfile (server *srv, connection *con, buffer *path, } } if (i == xdocroot->used && 0 != i) { - log_error_write(srv, __FILE__, __LINE__, "SBs", - "X-Sendfile (", path, - ") not under configured x-sendfile-docroot(s)"); + log_error(con->conf.errh, __FILE__, __LINE__, + "X-Sendfile (%s) not under configured x-sendfile-docroot(s)", path->ptr); con->http_status = 403; valid = 0; } } - if (valid) http_response_send_file(srv, con, path); + if (valid) http_response_send_file(con, path); if (con->http_status >= 400 && status < 300) { con->mode = DIRECT; @@ -664,9 +659,9 @@ static void http_response_xsendfile (server *srv, connection *con, buffer *path, } -static void http_response_xsendfile2(server *srv, connection *con, const buffer *value, const array *xdocroot) { +static void http_response_xsendfile2(connection *con, const buffer *value, const array *xdocroot) { const char *pos = value->ptr; - buffer *b = srv->tmp_buf; + buffer * const b = con->srv->tmp_buf; const int status = con->http_status; /* reset Content-Length, if set by backend */ @@ -686,8 +681,8 @@ static void http_response_xsendfile2(server *srv, connection *con, const buffer filename = pos; if (NULL == (range = strchr(pos, ' '))) { /* missing range */ - log_error_write(srv, __FILE__, __LINE__, "ss", - "Couldn't find range after filename:", filename); + log_error(con->conf.errh, __FILE__, __LINE__, + "Couldn't find range after filename: %s", filename); con->http_status = 502; break; } @@ -698,8 +693,8 @@ static void http_response_xsendfile2(server *srv, connection *con, const buffer buffer_urldecode_path(b); if (!buffer_is_valid_UTF8(b)) { - log_error_write(srv, __FILE__, __LINE__, "sb", - "X-Sendfile2 invalid UTF-8 after url-decode:", b); + log_error(con->conf.errh, __FILE__, __LINE__, + "X-Sendfile2 invalid UTF-8 after url-decode: %s", b->ptr); con->http_status = 502; break; } @@ -720,24 +715,23 @@ static void http_response_xsendfile2(server *srv, connection *con, const buffer } } if (i == xdocroot->used && 0 != i) { - log_error_write(srv, __FILE__, __LINE__, "SBs", - "X-Sendfile2 (", b, - ") not under configured x-sendfile-docroot(s)"); + log_error(con->conf.errh, __FILE__, __LINE__, + "X-Sendfile2 (%s) not under configured x-sendfile-docroot(s)", + b->ptr); con->http_status = 403; break; } } - if (HANDLER_ERROR == stat_cache_get_entry(srv, con, b, &sce)) { - log_error_write(srv, __FILE__, __LINE__, "sb", "send-file error: " - "couldn't get stat_cache entry for X-Sendfile2:", - b); + if (HANDLER_ERROR == stat_cache_get_entry(con->srv, con, b, &sce)) { + log_error(con->conf.errh, __FILE__, __LINE__, + "send-file error: couldn't get stat_cache entry for " + "X-Sendfile2: %s", b->ptr); con->http_status = 404; break; } else if (!S_ISREG(sce->st.st_mode)) { - log_error_write(srv, __FILE__, __LINE__, "sb", - "send-file error: wrong filetype for X-Sendfile2:", - b); + log_error(con->conf.errh, __FILE__, __LINE__, + "send-file error: wrong filetype for X-Sendfile2: %s", b->ptr); con->http_status = 502; break; } @@ -763,8 +757,8 @@ static void http_response_xsendfile2(server *srv, connection *con, const buffer goto range_success; range_failed: - log_error_write(srv, __FILE__, __LINE__, "ss", - "Couldn't decode range after filename:", filename); + log_error(con->conf.errh, __FILE__, __LINE__, + "Couldn't decode range after filename: %s", filename); con->http_status = 502; break; @@ -785,8 +779,8 @@ range_success: ; break; } if (range_len != 0) { - if (0 != http_chunk_append_file_range(srv, con, b, - begin_range, range_len)) { + if (0 != + http_chunk_append_file_range(con, b, begin_range, range_len)) { con->http_status = 502; break; } @@ -803,8 +797,7 @@ range_success: ; } -void http_response_backend_error (server *srv, connection *con) { - UNUSED(srv); +void http_response_backend_error (connection *con) { if (con->file_started) { /*(response might have been already started, kill the connection)*/ /*(mode == DIRECT to avoid later call to http_response_backend_done())*/ @@ -814,7 +807,7 @@ void http_response_backend_error (server *srv, connection *con) { } /*(else error status set later by http_response_backend_done())*/ } -void http_response_backend_done (server *srv, connection *con) { +void http_response_backend_done (connection *con) { /* (not CON_STATE_ERROR and not CON_STATE_RESPONSE_END, * i.e. not called from handle_connection_close or connection_reset * hooks, except maybe from errdoc handler, which later resets state)*/ @@ -829,7 +822,7 @@ void http_response_backend_done (server *srv, connection *con) { } /* else fall through */ case CON_STATE_WRITE: if (!con->file_finished) { - http_chunk_close(srv, con); + http_chunk_close(con); con->file_finished = 1; } default: @@ -838,9 +831,8 @@ void http_response_backend_done (server *srv, connection *con) { } -void http_response_upgrade_read_body_unknown(server *srv, connection *con) { +void http_response_upgrade_read_body_unknown(connection *con) { /* act as transparent proxy */ - UNUSED(srv); if (!(con->conf.stream_request_body & FDEVENT_STREAM_REQUEST)) con->conf.stream_request_body |= (FDEVENT_STREAM_REQUEST_BUFMIN | FDEVENT_STREAM_REQUEST); @@ -853,7 +845,7 @@ void http_response_upgrade_read_body_unknown(server *srv, connection *con) { } -static handler_t http_response_process_local_redir(server *srv, connection *con, size_t blen) { +static handler_t http_response_process_local_redir(connection *con, size_t blen) { /* [RFC3875] The Common Gateway Interface (CGI) Version 1.1 * [RFC3875] 6.2.2 Local Redirect Response * @@ -890,9 +882,9 @@ static handler_t http_response_process_local_redir(server *srv, connection *con, && !(con->response.htags & HTTP_HEADER_STATUS) /*no "Status" or NPH response*/ && 1 == con->response.headers.used) { if (++con->loops_per_request > 5) { - log_error_write(srv, __FILE__, __LINE__, "sb", - "too many internal loops while processing request:", - con->request.orig_uri); + log_error(con->conf.errh, __FILE__, __LINE__, + "too many internal loops while processing request: %s", + con->request.orig_uri->ptr); con->http_status = 500; /* Internal Server Error */ con->mode = DIRECT; return HANDLER_FINISHED; @@ -916,8 +908,8 @@ static handler_t http_response_process_local_redir(server *srv, connection *con, } /*(caller must reset request as follows)*/ - /*connection_response_reset(srv, con);*/ /*(sets con->http_status = 0)*/ - /*plugins_call_connection_reset(srv, con);*/ + /*connection_response_reset(con->srv, con);*/ /*(sets con->http_status = 0)*/ + /*plugins_call_connection_reset(con->srv, con);*/ return HANDLER_COMEBACK; } @@ -926,7 +918,7 @@ static handler_t http_response_process_local_redir(server *srv, connection *con, } -static int http_response_process_headers(server *srv, connection *con, http_response_opts *opts, buffer *hdrs) { +static int http_response_process_headers(connection *con, http_response_opts *opts, buffer *hdrs) { char *ns; const char *s; int line = 0; @@ -954,8 +946,8 @@ static int http_response_process_headers(server *srv, connection *con, http_resp } if (0 == con->http_status) { - log_error_write(srv, __FILE__, __LINE__, "ss", - "invalid HTTP status line:", s); + log_error(con->conf.errh, __FILE__, __LINE__, + "invalid HTTP status line: %s", s); con->http_status = 502; /* Bad Gateway */ con->mode = DIRECT; return -1; @@ -1032,9 +1024,9 @@ static int http_response_process_headers(server *srv, connection *con, http_resp break; case HTTP_HEADER_TRANSFER_ENCODING: if (opts->backend == BACKEND_PROXY) { - log_error_write(srv, __FILE__, __LINE__, "s", - "proxy backend sent invalid response header " - "(Transfer-Encoding) to HTTP/1.0 request"); + log_error(con->conf.errh, __FILE__, __LINE__, + "proxy backend sent invalid response header " + "(Transfer-Encoding) to HTTP/1.0 request"); con->http_status = 502; /* Bad Gateway */ con->mode = DIRECT; return -1; @@ -1057,7 +1049,7 @@ static int http_response_process_headers(server *srv, connection *con, http_resp } -handler_t http_response_parse_headers(server *srv, connection *con, http_response_opts *opts, buffer *b) { +handler_t http_response_parse_headers(connection *con, http_response_opts *opts, buffer *b) { /** * possible formats of response headers: * @@ -1111,7 +1103,7 @@ handler_t http_response_parse_headers(server *srv, connection *con, http_respons } else if (opts->backend == BACKEND_CGI) { /* no HTTP headers, but a body (special-case for CGI compat) */ /* no colon found; does not appear to be HTTP headers */ - if (0 != http_chunk_append_buffer(srv, con, b)) { + if (0 != http_chunk_append_buffer(con, b)) { return HANDLER_ERROR; } con->http_status = 200; /* OK */ @@ -1128,8 +1120,8 @@ handler_t http_response_parse_headers(server *srv, connection *con, http_respons /*(reuse MAX_HTTP_REQUEST_HEADER as max size * for response headers from backends)*/ if (header_len > MAX_HTTP_REQUEST_HEADER) { - log_error_write(srv, __FILE__, __LINE__, "sb", - "response headers too large for", con->uri.path); + log_error(con->conf.errh, __FILE__, __LINE__, + "response headers too large for %s", con->uri.path->ptr); con->http_status = 502; /* Bad Gateway */ con->mode = DIRECT; return HANDLER_FINISHED; @@ -1155,7 +1147,7 @@ handler_t http_response_parse_headers(server *srv, connection *con, http_respons return HANDLER_FINISHED; } - if (0 != http_response_process_headers(srv, con, opts, b)) { + if (0 != http_response_process_headers(con, opts, b)) { return HANDLER_ERROR; } @@ -1172,7 +1164,7 @@ handler_t http_response_parse_headers(server *srv, connection *con, http_respons if (opts->local_redir && con->http_status >= 300 && con->http_status < 400){ /*(con->response.htags & HTTP_HEADER_LOCATION)*/ - handler_t rc = http_response_process_local_redir(srv, con, blen); + handler_t rc = http_response_process_local_redir(con, blen); if (con->mode == DIRECT) con->file_started = 0; if (rc != HANDLER_GO_ON) return rc; } @@ -1182,7 +1174,7 @@ handler_t http_response_parse_headers(server *srv, connection *con, http_respons /* X-Sendfile2 is deprecated; historical for fastcgi */ if (opts->backend == BACKEND_FASTCGI && NULL != (vb = http_header_response_get(con, HTTP_HEADER_OTHER, CONST_STR_LEN("X-Sendfile2")))) { - http_response_xsendfile2(srv, con, vb, opts->xsendfile_docroot); + http_response_xsendfile2(con, vb, opts->xsendfile_docroot); /* http_header_response_unset() shortcut for HTTP_HEADER_OTHER */ buffer_clear(vb); /*(do not send to client)*/ if (con->mode == DIRECT) con->file_started = 0; @@ -1190,7 +1182,7 @@ handler_t http_response_parse_headers(server *srv, connection *con, http_respons } else if (NULL != (vb = http_header_response_get(con, HTTP_HEADER_OTHER, CONST_STR_LEN("X-Sendfile"))) || (opts->backend == BACKEND_FASTCGI /* X-LIGHTTPD-send-file is deprecated; historical for fastcgi */ && NULL != (vb = http_header_response_get(con, HTTP_HEADER_OTHER, CONST_STR_LEN("X-LIGHTTPD-send-file"))))) { - http_response_xsendfile(srv, con, vb, opts->xsendfile_docroot); + http_response_xsendfile(con, vb, opts->xsendfile_docroot); /* http_header_response_unset() shortcut for HTTP_HEADER_OTHER */ buffer_clear(vb); /*(do not send to client)*/ if (con->mode == DIRECT) con->file_started = 0; @@ -1199,17 +1191,17 @@ handler_t http_response_parse_headers(server *srv, connection *con, http_respons } if (blen > 0) { - if (0 != http_chunk_append_mem(srv, con, bstart, blen)) { + if (0 != http_chunk_append_mem(con, bstart, blen)) { return HANDLER_ERROR; } } /* (callback for response headers complete) */ - return (opts->headers) ? opts->headers(srv, con, opts) : HANDLER_GO_ON; + return (opts->headers) ? opts->headers(con, opts) : HANDLER_GO_ON; } -handler_t http_response_read(server *srv, connection *con, http_response_opts *opts, buffer *b, fdnode *fdn) { +handler_t http_response_read(connection *con, http_response_opts *opts, buffer *b, fdnode *fdn) { const int fd = fdn->fd; while (1) { ssize_t n; @@ -1253,7 +1245,7 @@ handler_t http_response_read(server *srv, connection *con, http_response_opts *o * immediately, unless !con->is_writable, where * connection_state_machine() might not loop back to call * mod_proxy_handle_subrequest())*/ - fdevent_fdnode_event_clr(srv->ev, fdn, FDEVENT_IN); + fdevent_fdnode_event_clr(con->srv->ev, fdn, FDEVENT_IN); } if (cqlen >= 65536-1) return HANDLER_GO_ON; toread = 65536 - 1 - (unsigned int)cqlen; @@ -1284,8 +1276,8 @@ handler_t http_response_read(server *srv, connection *con, http_response_opts *o case EINTR: return HANDLER_GO_ON; default: - log_error_write(srv, __FILE__, __LINE__, "ssdd", - "read():", strerror(errno), con->fd, fd); + log_perror(con->conf.errh, __FILE__, __LINE__, + "read() %d %d", con->fd, fd); return HANDLER_ERROR; } } @@ -1293,7 +1285,7 @@ handler_t http_response_read(server *srv, connection *con, http_response_opts *o buffer_commit(b, (size_t)n); if (NULL != opts->parse) { - handler_t rc = opts->parse(srv, con, opts, b, (size_t)n); + handler_t rc = opts->parse(con, opts, b, (size_t)n); if (rc != HANDLER_GO_ON) return rc; } else if (0 == n) { /* note: no further data is sent to backend after read EOF on socket @@ -1303,12 +1295,12 @@ handler_t http_response_read(server *srv, connection *con, http_response_opts *o return HANDLER_FINISHED; /* read finished */ } else if (0 == con->file_started) { /* split header from body */ - handler_t rc = http_response_parse_headers(srv, con, opts, b); + handler_t rc = http_response_parse_headers(con, opts, b); if (rc != HANDLER_GO_ON) return rc; /* accumulate response in b until headers completed (or error) */ if (con->file_started) buffer_clear(b); } else { - if (0 != http_chunk_append_buffer(srv, con, b)) { + if (0 != http_chunk_append_buffer(con, b)) { /* error writing to tempfile; * truncate response or send 500 if nothing sent yet */ return HANDLER_ERROR; @@ -1324,7 +1316,7 @@ handler_t http_response_read(server *srv, connection *con, http_response_opts *o * data immediately, unless !con->is_writable, where * connection_state_machine() might not loop back to * call the subrequest handler)*/ - fdevent_fdnode_event_clr(srv->ev, fdn, FDEVENT_IN); + fdevent_fdnode_event_clr(con->srv->ev, fdn, FDEVENT_IN); } break; } @@ -1337,12 +1329,13 @@ handler_t http_response_read(server *srv, connection *con, http_response_opts *o } -int http_cgi_headers (server *srv, connection *con, http_cgi_opts *opts, http_cgi_header_append_cb cb, void *vdata) { +int http_cgi_headers (connection *con, http_cgi_opts *opts, http_cgi_header_append_cb cb, void *vdata) { /* CGI-SPEC 6.1.2, FastCGI spec 6.3 and SCGI spec */ int rc = 0; - server_socket *srv_sock = con->srv_socket; + server_socket * const srv_sock = con->srv_socket; + buffer * const tb = con->srv->tmp_buf; const char *s; size_t n; char buf[LI_ITOSTRING_LENGTH]; @@ -1416,13 +1409,13 @@ int http_cgi_headers (server *srv, connection *con, http_cgi_opts *opts, http_cg CONST_BUF_LEN(con->request.pathinfo)); /* PATH_TRANSLATED is only defined if PATH_INFO is set */ if (!buffer_string_is_empty(opts->docroot)) { - buffer_copy_buffer(srv->tmp_buf, opts->docroot); + buffer_copy_buffer(tb, opts->docroot); } else { - buffer_copy_buffer(srv->tmp_buf, con->physical.basedir); + buffer_copy_buffer(tb, con->physical.basedir); } - buffer_append_string_buffer(srv->tmp_buf, con->request.pathinfo); + buffer_append_string_buffer(tb, con->request.pathinfo); rc |= cb(vdata, CONST_STR_LEN("PATH_TRANSLATED"), - CONST_BUF_LEN(srv->tmp_buf)); + CONST_BUF_LEN(tb)); } } @@ -1435,10 +1428,10 @@ int http_cgi_headers (server *srv, connection *con, http_cgi_opts *opts, http_cg if (!buffer_string_is_empty(opts->docroot)) { /* alternate docroot, e.g. for remote FastCGI or SCGI server */ - buffer_copy_buffer(srv->tmp_buf, opts->docroot); - buffer_append_string_buffer(srv->tmp_buf, con->uri.path); + buffer_copy_buffer(tb, opts->docroot); + buffer_append_string_buffer(tb, con->uri.path); rc |= cb(vdata, CONST_STR_LEN("SCRIPT_FILENAME"), - CONST_BUF_LEN(srv->tmp_buf)); + CONST_BUF_LEN(tb)); rc |= cb(vdata, CONST_STR_LEN("DOCUMENT_ROOT"), CONST_BUF_LEN(opts->docroot)); } else { @@ -1448,10 +1441,10 @@ int http_cgi_headers (server *srv, connection *con, http_cgi_opts *opts, http_cg * * see src/sapi/cgi_main.c, init_request_info() */ - buffer_copy_buffer(srv->tmp_buf, con->physical.path); - buffer_append_string_buffer(srv->tmp_buf, con->request.pathinfo); + buffer_copy_buffer(tb, con->physical.path); + buffer_append_string_buffer(tb, con->request.pathinfo); rc |= cb(vdata, CONST_STR_LEN("SCRIPT_FILENAME"), - CONST_BUF_LEN(srv->tmp_buf)); + CONST_BUF_LEN(tb)); } else { rc |= cb(vdata, CONST_STR_LEN("SCRIPT_FILENAME"), CONST_BUF_LEN(con->physical.path)); @@ -1541,21 +1534,21 @@ int http_cgi_headers (server *srv, connection *con, http_cgi_opts *opts, http_cg CONST_STR_LEN("Proxy"))) { continue; } - buffer_copy_string_encoded_cgi_varnames(srv->tmp_buf, + buffer_copy_string_encoded_cgi_varnames(tb, CONST_BUF_LEN(&ds->key), 1); - rc |= cb(vdata, CONST_BUF_LEN(srv->tmp_buf), + rc |= cb(vdata, CONST_BUF_LEN(tb), CONST_BUF_LEN(&ds->value)); } } - srv->request_env(srv, con); + con->srv->request_env(con->srv, con); for (n = 0; n < con->environment.used; n++) { data_string *ds = (data_string *)con->environment.data[n]; if (!buffer_is_empty(&ds->value) && !buffer_is_empty(&ds->key)) { - buffer_copy_string_encoded_cgi_varnames(srv->tmp_buf, + buffer_copy_string_encoded_cgi_varnames(tb, CONST_BUF_LEN(&ds->key), 0); - rc |= cb(vdata, CONST_BUF_LEN(srv->tmp_buf), + rc |= cb(vdata, CONST_BUF_LEN(tb), CONST_BUF_LEN(&ds->value)); } } diff --git a/src/http_auth.h b/src/http_auth.h index 3d9314ec..a07857da 100644 --- a/src/http_auth.h +++ b/src/http_auth.h @@ -53,14 +53,14 @@ typedef struct http_auth_info_t { typedef struct http_auth_backend_t { const char *name; - handler_t(*basic)(server *srv, connection *con, void *p_d, const http_auth_require_t *require, const buffer *username, const char *pw); - handler_t(*digest)(server *srv, connection *con, void *p_d, http_auth_info_t *ai); + handler_t(*basic)(connection *con, void *p_d, const http_auth_require_t *require, const buffer *username, const char *pw); + handler_t(*digest)(connection *con, void *p_d, http_auth_info_t *ai); void *p_d; } http_auth_backend_t; typedef struct http_auth_scheme_t { const char *name; - handler_t(*checkfn)(server *srv, connection *con, void *p_d, const struct http_auth_require_t *require, const struct http_auth_backend_t *backend); + handler_t(*checkfn)(connection *con, void *p_d, const struct http_auth_require_t *require, const struct http_auth_backend_t *backend); /*(backend is arg only because auth.backend is separate config directive)*/ void *p_d; } http_auth_scheme_t; diff --git a/src/http_chunk.c b/src/http_chunk.c index 22c6950c..d939a77c 100644 --- a/src/http_chunk.c +++ b/src/http_chunk.c @@ -29,8 +29,8 @@ static buffer * http_chunk_header(buffer *b, uintmax_t len) { return b; } -static void http_chunk_append_len(server *srv, connection *con, uintmax_t len) { - buffer *b = http_chunk_header(srv->tmp_chunk_len, len); +static void http_chunk_append_len(connection *con, uintmax_t len) { + buffer *b = http_chunk_header(con->srv->tmp_chunk_len, len); chunkqueue_append_mem(con->write_queue, CONST_BUF_LEN(b)); } @@ -43,7 +43,7 @@ static int http_chunk_append_file_open_fstat(connection *con, buffer *fn, struct return stat_cache_open_rdonly_fstat(fn, st, con->conf.follow_symlink); } -static int http_chunk_append_read_fd_range(server *srv, connection *con, buffer *fn, int fd, off_t offset, off_t len) { +static int http_chunk_append_read_fd_range(connection *con, buffer *fn, int fd, off_t offset, off_t len) { /* note: this routine should not be used for range requests * unless the total size of ranges requested is small */ /* note: future: could read into existing MEM_CHUNK in cq->last if @@ -52,7 +52,7 @@ static int http_chunk_append_read_fd_range(server *srv, connection *con, buffer UNUSED(fn); if (con->response.send_chunked) { - http_chunk_append_len(srv, con, (uintmax_t)len); + http_chunk_append_len(con, (uintmax_t)len); } if (0 != offset && -1 == lseek(fd, offset, SEEK_SET)) return -1; @@ -73,11 +73,11 @@ static int http_chunk_append_read_fd_range(server *srv, connection *con, buffer return (rd >= 0) ? 0 : -1; } -static void http_chunk_append_file_fd_range(server *srv, connection *con, buffer *fn, int fd, off_t offset, off_t len) { +static void http_chunk_append_file_fd_range(connection *con, buffer *fn, int fd, off_t offset, off_t len) { chunkqueue *cq = con->write_queue; if (con->response.send_chunked) { - http_chunk_append_len(srv, con, (uintmax_t)len); + http_chunk_append_len(con, (uintmax_t)len); } chunkqueue_append_file_fd(cq, fn, fd, offset, len); @@ -87,7 +87,7 @@ static void http_chunk_append_file_fd_range(server *srv, connection *con, buffer } } -int http_chunk_append_file_range(server *srv, connection *con, buffer *fn, off_t offset, off_t len) { +int http_chunk_append_file_range(connection *con, buffer *fn, off_t offset, off_t len) { struct stat st; const int fd = http_chunk_append_file_open_fstat(con, fn, &st); if (fd < 0) return -1; @@ -103,47 +103,48 @@ int http_chunk_append_file_range(server *srv, connection *con, buffer *fn, off_t return -1; } - http_chunk_append_file_fd_range(srv, con, fn, fd, offset, len); + http_chunk_append_file_fd_range(con, fn, fd, offset, len); return 0; } -int http_chunk_append_file(server *srv, connection *con, buffer *fn) { +int http_chunk_append_file(connection *con, buffer *fn) { struct stat st; const int fd = http_chunk_append_file_open_fstat(con, fn, &st); if (fd < 0) return -1; - http_chunk_append_file_fd(srv, con, fn, fd, st.st_size); + http_chunk_append_file_fd(con, fn, fd, st.st_size); return 0; } -int http_chunk_append_file_fd(server *srv, connection *con, buffer *fn, int fd, off_t sz) { +int http_chunk_append_file_fd(connection *con, buffer *fn, int fd, off_t sz) { if (sz > 32768) { - http_chunk_append_file_fd_range(srv, con, fn, fd, 0, sz); + http_chunk_append_file_fd_range(con, fn, fd, 0, sz); return 0; } else { int rc = (0 != sz) /*(read small files into memory)*/ - ? http_chunk_append_read_fd_range(srv, con, fn, fd, 0, sz) + ? http_chunk_append_read_fd_range(con, fn, fd, 0, sz) : 0; close(fd); return rc; } } -static int http_chunk_append_to_tempfile(server *srv, connection *con, const char * mem, size_t len) { +static int http_chunk_append_to_tempfile(connection *con, const char * mem, size_t len) { chunkqueue * const cq = con->write_queue; + log_error_st * const errh = con->conf.errh; if (con->response.send_chunked) { - buffer *b = http_chunk_header(srv->tmp_chunk_len, len); - if (0 != chunkqueue_append_mem_to_tempfile(srv, cq, CONST_BUF_LEN(b))) { + buffer *b = http_chunk_header(con->srv->tmp_chunk_len, len); + if (0 != chunkqueue_append_mem_to_tempfile(cq, CONST_BUF_LEN(b), errh)) { return -1; } } - if (0 != chunkqueue_append_mem_to_tempfile(srv, cq, mem, len)) { + if (0 != chunkqueue_append_mem_to_tempfile(cq, mem, len, errh)) { return -1; } if (con->response.send_chunked) { - if (0 != chunkqueue_append_mem_to_tempfile(srv, cq, CONST_STR_LEN("\r\n"))) { + if (0 != chunkqueue_append_mem_to_tempfile(cq, CONST_STR_LEN("\r\n"), errh)) { return -1; } } @@ -151,22 +152,24 @@ static int http_chunk_append_to_tempfile(server *srv, connection *con, const cha return 0; } -static int http_chunk_append_cq_to_tempfile(server *srv, connection *con, chunkqueue *src, size_t len) { +static int http_chunk_append_cq_to_tempfile(connection *con, chunkqueue *src, size_t len) { chunkqueue * const cq = con->write_queue; + log_error_st * const errh = con->conf.errh; if (con->response.send_chunked) { - buffer *b = http_chunk_header(srv->tmp_chunk_len, len); - if (0 != chunkqueue_append_mem_to_tempfile(srv, cq, CONST_BUF_LEN(b))) { + buffer *b = http_chunk_header(con->srv->tmp_chunk_len, len); + if (0 != chunkqueue_append_mem_to_tempfile(cq, CONST_BUF_LEN(b), errh)) { return -1; } } - if (0 != chunkqueue_steal_with_tempfiles(srv, cq, src, len)) { + if (0 != chunkqueue_steal_with_tempfiles(cq, src, len, errh)) { return -1; } if (con->response.send_chunked) { - if (0!=chunkqueue_append_mem_to_tempfile(srv,cq,CONST_STR_LEN("\r\n"))){ + if (0 != + chunkqueue_append_mem_to_tempfile(cq,CONST_STR_LEN("\r\n"),errh)) { return -1; } } @@ -174,10 +177,9 @@ static int http_chunk_append_cq_to_tempfile(server *srv, connection *con, chunkq return 0; } -static int http_chunk_uses_tempfile(server *srv, connection *con, size_t len) { +static int http_chunk_uses_tempfile(connection *con, size_t len) { chunkqueue * const cq = con->write_queue; chunk *c = cq->last; - UNUSED(srv); /* current usage does not append_mem or append_buffer after appending * file, so not checking if users of this interface have appended large @@ -197,17 +199,17 @@ static int http_chunk_uses_tempfile(server *srv, connection *con, size_t len) { return 0; } -int http_chunk_append_buffer(server *srv, connection *con, buffer *mem) { +int http_chunk_append_buffer(connection *con, buffer *mem) { chunkqueue * const cq = con->write_queue; size_t len = buffer_string_length(mem); if (0 == len) return 0; - if (http_chunk_uses_tempfile(srv, con, len)) { - return http_chunk_append_to_tempfile(srv, con, mem->ptr, len); + if (http_chunk_uses_tempfile(con, len)) { + return http_chunk_append_to_tempfile(con, mem->ptr, len); } if (con->response.send_chunked) { - http_chunk_append_len(srv, con, len); + http_chunk_append_len(con, len); } /*(chunkqueue_append_buffer() might steal buffer contents)*/ @@ -220,17 +222,17 @@ int http_chunk_append_buffer(server *srv, connection *con, buffer *mem) { return 0; } -int http_chunk_append_mem(server *srv, connection *con, const char * mem, size_t len) { +int http_chunk_append_mem(connection *con, const char * mem, size_t len) { chunkqueue * const cq = con->write_queue; if (0 == len) return 0; force_assert(NULL != mem); - if (http_chunk_uses_tempfile(srv, con, len)) { - return http_chunk_append_to_tempfile(srv, con, mem, len); + if (http_chunk_uses_tempfile(con, len)) { + return http_chunk_append_to_tempfile(con, mem, len); } if (con->response.send_chunked) { - http_chunk_append_len(srv, con, len); + http_chunk_append_len(con, len); } chunkqueue_append_mem(cq, mem, len); @@ -242,16 +244,16 @@ int http_chunk_append_mem(server *srv, connection *con, const char * mem, size_t return 0; } -int http_chunk_transfer_cqlen(server *srv, connection *con, chunkqueue *src, size_t len) { +int http_chunk_transfer_cqlen(connection *con, chunkqueue *src, size_t len) { chunkqueue * const cq = con->write_queue; if (0 == len) return 0; - if (http_chunk_uses_tempfile(srv, con, len)) { - return http_chunk_append_cq_to_tempfile(srv, con, src, len); + if (http_chunk_uses_tempfile(con, len)) { + return http_chunk_append_cq_to_tempfile(con, src, len); } if (con->response.send_chunked) { - http_chunk_append_len(srv, con, len); + http_chunk_append_len(con, len); } chunkqueue_steal(cq, src, len); @@ -263,8 +265,7 @@ int http_chunk_transfer_cqlen(server *srv, connection *con, chunkqueue *src, siz return 0; } -void http_chunk_close(server *srv, connection *con) { - UNUSED(srv); +void http_chunk_close(connection *con) { force_assert(NULL != con); if (con->response.send_chunked) { diff --git a/src/http_chunk.h b/src/http_chunk.h index d426a997..baf557d0 100644 --- a/src/http_chunk.h +++ b/src/http_chunk.h @@ -4,12 +4,12 @@ #include "base_decls.h" -int http_chunk_append_mem(server *srv, connection *con, const char * mem, size_t len); /* copies memory */ -int http_chunk_append_buffer(server *srv, connection *con, buffer *mem); /* may reset "mem" */ -int http_chunk_transfer_cqlen(server *srv, connection *con, chunkqueue *src, size_t len); -int http_chunk_append_file(server *srv, connection *con, buffer *fn); /* copies "fn" */ -int http_chunk_append_file_fd(server *srv, connection *con, buffer *fn, int fd, off_t sz); -int http_chunk_append_file_range(server *srv, connection *con, buffer *fn, off_t offset, off_t len); /* copies "fn" */ -void http_chunk_close(server *srv, connection *con); +int http_chunk_append_mem(connection *con, const char * mem, size_t len); /* copies memory */ +int http_chunk_append_buffer(connection *con, buffer *mem); /* may reset "mem" */ +int http_chunk_transfer_cqlen(connection *con, chunkqueue *src, size_t len); +int http_chunk_append_file(connection *con, buffer *fn); /* copies "fn" */ +int http_chunk_append_file_fd(connection *con, buffer *fn, int fd, off_t sz); +int http_chunk_append_file_range(connection *con, buffer *fn, off_t offset, off_t len); /* copies "fn" */ +void http_chunk_close(connection *con); #endif diff --git a/src/log.c b/src/log.c index 45d22e16..45d7f0d3 100644 --- a/src/log.c +++ b/src/log.c @@ -166,21 +166,6 @@ static void log_write(const log_error_st *errh, buffer *b) { } } -int log_error_write(server *srv, const char *filename, unsigned int line, const char *fmt, ...) { - const log_error_st *errh = srv->errh; - buffer *b = errh->b; - if (-1 == log_buffer_prepare(errh, filename, line, b)) return 0; - - va_list ap; - va_start(ap, fmt); - log_buffer_append_printf(b, fmt, ap); - va_end(ap); - - log_write(errh, b); - - return 0; -} - int log_error_write_multiline_buffer(server *srv, const char *filename, unsigned int line, buffer *multiline, const char *fmt, ...) { const log_error_st *errh = srv->errh; buffer *b = errh->b; diff --git a/src/log.h b/src/log.h index ea4ed530..556cb56c 100644 --- a/src/log.h +++ b/src/log.h @@ -10,9 +10,6 @@ int log_clock_gettime_realtime (struct timespec *ts); ssize_t write_all(int fd, const void* buf, size_t count); -__attribute_cold__ -int log_error_write(server *srv, const char *filename, unsigned int line, const char *fmt, ...); - __attribute_cold__ int log_error_write_multiline_buffer(server *srv, const char *filename, unsigned int line, buffer *multiline, const char *fmt, ...); diff --git a/src/mod_access.c b/src/mod_access.c index 11263b97..8b426284 100644 --- a/src/mod_access.c +++ b/src/mod_access.c @@ -104,11 +104,11 @@ __attribute_cold__ static handler_t mod_access_reject (connection * const con, plugin_data * const p) { if (con->conf.log_request_handling) { if (p->conf.access_allow && p->conf.access_allow->used) - log_error(con->errh, __FILE__, __LINE__, + log_error(con->conf.errh, __FILE__, __LINE__, "url denied as failed to match any from access_allow %s", con->uri.path->ptr); else - log_error(con->errh, __FILE__, __LINE__, + log_error(con->conf.errh, __FILE__, __LINE__, "url denied as we match access_deny %s", con->uri.path->ptr); } @@ -158,7 +158,7 @@ URIHANDLER_FUNC(mod_access_uri_handler) { } if (con->conf.log_request_handling) { - log_error(con->errh, __FILE__, __LINE__, + log_error(con->conf.errh, __FILE__, __LINE__, "-- mod_access_uri_handler called"); } diff --git a/src/mod_accesslog.c b/src/mod_accesslog.c index 1b2fdb09..4464ccfa 100644 --- a/src/mod_accesslog.c +++ b/src/mod_accesslog.c @@ -16,7 +16,6 @@ #include #include #include -#include #include #ifdef HAVE_SYSLOG_H @@ -1145,8 +1144,9 @@ REQUESTDONE_FUNC(log_access_write) { if (flush || buffer_string_length(b) >= BUFFER_MAX_REUSE_SIZE) { if (!accesslog_write_all(p->conf.log_access_fd, b)) { - log_error_write(srv, __FILE__, __LINE__, "sbs", - "writing access log entry failed:", p->conf.access_logfile, strerror(errno)); + log_perror(con->conf.errh, __FILE__, __LINE__, + "writing access log entry failed: %s", + p->conf.access_logfile->ptr); } } } diff --git a/src/mod_auth.c b/src/mod_auth.c index 269bccd5..f11080be 100644 --- a/src/mod_auth.c +++ b/src/mod_auth.c @@ -30,9 +30,9 @@ typedef struct { plugin_config conf; } plugin_data; -static handler_t mod_auth_check_basic(server *srv, connection *con, void *p_d, const struct http_auth_require_t *require, const struct http_auth_backend_t *backend); -static handler_t mod_auth_check_digest(server *srv, connection *con, void *p_d, const struct http_auth_require_t *require, const struct http_auth_backend_t *backend); -static handler_t mod_auth_check_extern(server *srv, connection *con, void *p_d, const struct http_auth_require_t *require, const struct http_auth_backend_t *backend); +static handler_t mod_auth_check_basic(connection *con, void *p_d, const struct http_auth_require_t *require, const struct http_auth_backend_t *backend); +static handler_t mod_auth_check_digest(connection *con, void *p_d, const struct http_auth_require_t *require, const struct http_auth_backend_t *backend); +static handler_t mod_auth_check_extern(connection *con, void *p_d, const struct http_auth_require_t *require, const struct http_auth_backend_t *backend); INIT_FUNC(mod_auth_init) { static const http_auth_scheme_t http_auth_scheme_basic = { "basic", mod_auth_check_basic, NULL }; @@ -188,17 +188,18 @@ static int mod_auth_require_parse (server *srv, http_auth_require_t * const requ len = NULL != p ? (size_t)(p - str) : strlen(str); eq = memchr(str, '=', len); if (NULL == eq) { - log_error_write(srv, __FILE__, __LINE__, "sssbss", - "error parsing auth.require 'require' field: missing '='", - "(expecting \"valid-user\" or \"user=a|user=b|group=g|host=h\").", - "error value:", b, "error near:", str); + log_error(srv->errh, __FILE__, __LINE__, + "error parsing auth.require 'require' field: missing '=' " + "(expecting \"valid-user\" or \"user=a|user=b|group=g|host=h\"). " + "error value: %s error near: %s", b->ptr, str); return 0; } if (eq[1] == '|' || eq[1] == '\0') { - log_error_write(srv, __FILE__, __LINE__, "sssbss", - "error parsing auth.require 'require' field: missing token after '='", - "(expecting \"valid-user\" or \"user=a|user=b|group=g|host=h\").", - "error value:", b, "error near:", str); + log_error(srv->errh, __FILE__, __LINE__, + "error parsing auth.require 'require' field: " + "missing token after '=' " + "(expecting \"valid-user\" or \"user=a|user=b|group=g|host=h\"). " + "error value: %s error near: %s", b->ptr, str); return 0; } @@ -212,9 +213,9 @@ static int mod_auth_require_parse (server *srv, http_auth_require_t * const requ else if (0 == memcmp(str, CONST_STR_LEN("host"))) { /*("host=" is 5)*/ array_set_key_value(&require->host, str+5, len-5, CONST_STR_LEN("")); - log_error_write(srv, __FILE__, __LINE__, "ssb", - "warning parsing auth.require 'require' field: 'host' not implemented;", - "field value:", b); + log_error(srv->errh, __FILE__, __LINE__, + "warning parsing auth.require 'require' field: " + "'host' not implemented; field value: %s", b->ptr); continue; } break; /* to error */ @@ -223,19 +224,20 @@ static int mod_auth_require_parse (server *srv, http_auth_require_t * const requ /*("group=" is 6)*/ array_set_key_value(&require->group, str+6, len-6, CONST_STR_LEN("")); #if 0/*(supported by mod_authn_ldap, but not all other backends)*/ - log_error_write(srv, __FILE__, __LINE__, "ssb", - "warning parsing auth.require 'require' field: 'group' not implemented;", - "field value:", b); + log_error(srv->errh, __FILE__, __LINE__, + "warning parsing auth.require 'require' field: " + "'group' not implemented; field value: %s", b->ptr); #endif continue; } break; /* to error */ case 10: if (0 == memcmp(str, CONST_STR_LEN("valid-user"))) { - log_error_write(srv, __FILE__, __LINE__, "sssb", - "error parsing auth.require 'require' field: valid user can not be combined with other require rules", - "(expecting \"valid-user\" or \"user=a|user=b|group=g|host=h\").", - "error value:", b); + log_error(srv->errh, __FILE__, __LINE__, + "error parsing auth.require 'require' field: " + "valid user can not be combined with other require rules " + "(expecting \"valid-user\" or " + "\"user=a|user=b|group=g|host=h\"). error value: %s", b->ptr); return 0; } break; /* to error */ @@ -243,10 +245,11 @@ static int mod_auth_require_parse (server *srv, http_auth_require_t * const requ break; /* to error */ } - log_error_write(srv, __FILE__, __LINE__, "sssbss", - "error parsing auth.require 'require' field: invalid/unsupported token", - "(expecting \"valid-user\" or \"user=a|user=b|group=g|host=h\").", - "error value:", b, "error near:", str); + log_error(srv->errh, __FILE__, __LINE__, + "error parsing auth.require 'require' field: " + "invalid/unsupported token " + "(expecting \"valid-user\" or \"user=a|user=b|group=g|host=h\"). " + "error value: %s error near: %s", b->ptr, str); return 0; } while (p && *((str = p+1))); @@ -265,9 +268,9 @@ static handler_t mod_auth_require_parse_array(server *srv, const array *value, a int algorithm = HTTP_AUTH_DIGEST_SESS; if (!array_is_kvstring(&da_file->value)) { - log_error_write(srv, __FILE__, __LINE__, "ss", - "unexpected value for auth.require; expected ", - "auth.require = ( \"urlpath\" => ( \"option\" => \"value\" ) )"); + log_error(srv->errh, __FILE__, __LINE__, + "unexpected value for auth.require; expected " + "auth.require = ( \"urlpath\" => ( \"option\" => \"value\" ) )"); return HANDLER_ERROR; } @@ -284,60 +287,58 @@ static handler_t mod_auth_require_parse_array(server *srv, const array *value, a } else if (buffer_is_equal_string(&ds->key, CONST_STR_LEN("algorithm"))) { algos = &ds->value; } else { - log_error_write(srv, __FILE__, __LINE__, "ssbs", - "the field is unknown in:", - "auth.require = ( \"...\" => ( ..., -> \"", - &da_file->value.data[m]->key, - "\" <- => \"...\" ) )"); + log_error(srv->errh, __FILE__, __LINE__, + "the field is unknown in: " + "auth.require = ( \"...\" => ( ..., -> \"%s\" <- => \"...\" ) )", + da_file->value.data[m]->key.ptr); return HANDLER_ERROR; } } else { - log_error_write(srv, __FILE__, __LINE__, "ssbs", - "a string was expected for:", - "auth.require = ( \"...\" => ( ..., -> \"", - &da_file->value.data[m]->key, - "\" <- => \"...\" ) )"); + log_error(srv->errh, __FILE__, __LINE__, + "a string was expected for: " + "auth.require = ( \"...\" => ( ..., -> \"%s\" <- => \"...\" ) )", + da_file->value.data[m]->key.ptr); return HANDLER_ERROR; } } if (buffer_string_is_empty(method)) { - log_error_write(srv, __FILE__, __LINE__, "ss", - "the method field is missing or blank in:", - "auth.require = ( \"...\" => ( ..., \"method\" => \"...\" ) )"); + log_error(srv->errh, __FILE__, __LINE__, + "the method field is missing or blank in: " + "auth.require = ( \"...\" => ( ..., \"method\" => \"...\" ) )"); return HANDLER_ERROR; } else { auth_scheme = http_auth_scheme_get(method); if (NULL == auth_scheme) { - log_error_write(srv, __FILE__, __LINE__, "sbss", - "unknown method", method, "(e.g. \"basic\", \"digest\" or \"extern\") in", - "auth.require = ( \"...\" => ( ..., \"method\" => \"...\") )"); + log_error(srv->errh, __FILE__, __LINE__, + "unknown method %s (e.g. \"basic\", \"digest\" or \"extern\") in " + "auth.require = ( \"...\" => ( ..., \"method\" => \"...\") )", method->ptr); return HANDLER_ERROR; } } if (buffer_is_empty(realm)) { - log_error_write(srv, __FILE__, __LINE__, "ss", - "the realm field is missing in:", - "auth.require = ( \"...\" => ( ..., \"realm\" => \"...\" ) )"); + log_error(srv->errh, __FILE__, __LINE__, + "the realm field is missing in: " + "auth.require = ( \"...\" => ( ..., \"realm\" => \"...\" ) )"); return HANDLER_ERROR; } if (buffer_string_is_empty(require)) { - log_error_write(srv, __FILE__, __LINE__, "ss", - "the require field is missing or blank in:", - "auth.require = ( \"...\" => ( ..., \"require\" => \"...\" ) )"); + log_error(srv->errh, __FILE__, __LINE__, + "the require field is missing or blank in: " + "auth.require = ( \"...\" => ( ..., \"require\" => \"...\" ) )"); return HANDLER_ERROR; } if (buffer_string_is_empty(algos)) { algorithm |= HTTP_AUTH_DIGEST_MD5; } else if (!mod_auth_algorithms_parse(&algorithm, algos)) { - log_error_write(srv, __FILE__, __LINE__, "ss", - "invalid algorithm in:", - "auth.require = ( \"...\" => ( ..., \"algorithm\" => \"...\" ) )"); + log_error(srv->errh, __FILE__, __LINE__, + "invalid algorithm in: " + "auth.require = ( \"...\" => ( ..., \"algorithm\" => \"...\" ) )"); return HANDLER_ERROR; } @@ -468,6 +469,7 @@ SETDEFAULTS_FUNC(mod_auth_set_defaults) { static handler_t mod_auth_uri_handler(server *srv, connection *con, void *p_d) { plugin_data *p = p_d; data_auth *dauth; + UNUSED(srv); mod_auth_patch_config(con, p); @@ -488,7 +490,7 @@ static handler_t mod_auth_uri_handler(server *srv, connection *con, void *p_d) { return HANDLER_GO_ON; } } - return scheme->checkfn(srv, con, scheme->p_d, dauth->require, p->conf.auth_backend); + return scheme->checkfn(con, scheme->p_d, dauth->require, p->conf.auth_backend); } } @@ -518,8 +520,8 @@ int mod_auth_plugin_init(plugin *p) { #include "rand.h" #include "http_header.h" -static handler_t mod_auth_send_400_bad_request(server *srv, connection *con) { - UNUSED(srv); +__attribute_cold__ +static handler_t mod_auth_send_400_bad_request(connection *con) { /* a field was missing or invalid */ con->http_status = 400; /* Bad Request */ @@ -528,20 +530,21 @@ static handler_t mod_auth_send_400_bad_request(server *srv, connection *con) { return HANDLER_FINISHED; } -static handler_t mod_auth_send_401_unauthorized_basic(server *srv, connection *con, const buffer *realm) { +static handler_t mod_auth_send_401_unauthorized_basic(connection *con, const buffer *realm) { con->http_status = 401; con->mode = DIRECT; - buffer_copy_string_len(srv->tmp_buf, CONST_STR_LEN("Basic realm=\"")); - buffer_append_string_buffer(srv->tmp_buf, realm); - buffer_append_string_len(srv->tmp_buf, CONST_STR_LEN("\", charset=\"UTF-8\"")); + buffer * const tb = con->srv->tmp_buf; + buffer_copy_string_len(tb, CONST_STR_LEN("Basic realm=\"")); + buffer_append_string_buffer(tb, realm); + buffer_append_string_len(tb, CONST_STR_LEN("\", charset=\"UTF-8\"")); - http_header_response_set(con, HTTP_HEADER_OTHER, CONST_STR_LEN("WWW-Authenticate"), CONST_BUF_LEN(srv->tmp_buf)); + http_header_response_set(con, HTTP_HEADER_OTHER, CONST_STR_LEN("WWW-Authenticate"), CONST_BUF_LEN(tb)); return HANDLER_FINISHED; } -static handler_t mod_auth_check_basic(server *srv, connection *con, void *p_d, const struct http_auth_require_t *require, const struct http_auth_backend_t *backend) { +static handler_t mod_auth_check_basic(connection *con, void *p_d, const struct http_auth_require_t *require, const struct http_auth_backend_t *backend) { const buffer *b = http_header_request_get(con, HTTP_HEADER_AUTHORIZATION, CONST_STR_LEN("Authorization")); buffer *username; char *pw; @@ -550,22 +553,22 @@ static handler_t mod_auth_check_basic(server *srv, connection *con, void *p_d, c UNUSED(p_d); if (NULL == backend) { - log_error_write(srv, __FILE__, __LINE__, "sb", "auth.backend not configured for", con->uri.path); + log_error(con->conf.errh, __FILE__, __LINE__, "auth.backend not configured for %s", con->uri.path->ptr); con->http_status = 500; con->mode = DIRECT; return HANDLER_FINISHED; } if (NULL == b) { - return mod_auth_send_401_unauthorized_basic(srv, con, require->realm); + return mod_auth_send_401_unauthorized_basic(con, require->realm); } if (!buffer_eq_icase_ssn(b->ptr, CONST_STR_LEN("Basic "))) { - return mod_auth_send_401_unauthorized_basic(srv, con, require->realm); + return mod_auth_send_401_unauthorized_basic(con, require->realm); } #ifdef __COVERITY__ if (buffer_string_length(b) < sizeof("Basic ")-1) { - return mod_auth_send_400_bad_request(srv, con); + return mod_auth_send_400_bad_request(con); } #endif @@ -573,24 +576,24 @@ static handler_t mod_auth_check_basic(server *srv, connection *con, void *p_d, c /* coverity[overflow_sink : FALSE] */ if (!buffer_append_base64_decode(username, b->ptr+sizeof("Basic ")-1, buffer_string_length(b)-(sizeof("Basic ")-1), BASE64_STANDARD)) { - log_error_write(srv, __FILE__, __LINE__, "sb", "decoding base64-string failed", username); + log_error(con->conf.errh, __FILE__, __LINE__, "decoding base64-string failed %s", b->ptr+sizeof("Basic ")-1); buffer_free(username); - return mod_auth_send_400_bad_request(srv, con); + return mod_auth_send_400_bad_request(con); } /* r2 == user:password */ if (NULL == (pw = strchr(username->ptr, ':'))) { - log_error_write(srv, __FILE__, __LINE__, "sb", "missing ':' in", username); + log_error(con->conf.errh, __FILE__, __LINE__, "missing ':' in %s", username->ptr); buffer_free(username); - return mod_auth_send_400_bad_request(srv, con); + return mod_auth_send_400_bad_request(con); } buffer_string_set_length(username, pw - username->ptr); pw++; - rc = backend->basic(srv, con, backend->p_d, require, username, pw); + rc = backend->basic(con, backend->p_d, require, username, pw); switch (rc) { case HANDLER_GO_ON: http_auth_setenv(con, CONST_BUF_LEN(username), CONST_STR_LEN("Basic")); @@ -600,14 +603,16 @@ static handler_t mod_auth_check_basic(server *srv, connection *con, void *p_d, c break; case HANDLER_ERROR: default: - log_error_write(srv, __FILE__, __LINE__, "sbsBsB", "password doesn't match for", con->uri.path, "username:", username, ", IP:", con->dst_addr_buf); + log_error(con->conf.errh, __FILE__, __LINE__, + "password doesn't match for %s username: %s IP: %s", + con->uri.path->ptr, username->ptr, con->dst_addr_buf->ptr); con->keep_alive = 0; /*(disable keep-alive if bad password)*/ rc = HANDLER_UNSET; break; } buffer_free(username); - return (HANDLER_UNSET != rc) ? rc : mod_auth_send_401_unauthorized_basic(srv, con, require->realm); + return (HANDLER_UNSET != rc) ? rc : mod_auth_send_401_unauthorized_basic(con, require->realm); } @@ -915,9 +920,9 @@ typedef struct { char **ptr; } digest_kv; -static handler_t mod_auth_send_401_unauthorized_digest(server *srv, connection *con, const struct http_auth_require_t *require, int nonce_stale); +static handler_t mod_auth_send_401_unauthorized_digest(connection *con, const struct http_auth_require_t *require, int nonce_stale); -static handler_t mod_auth_check_digest(server *srv, connection *con, void *p_d, const struct http_auth_require_t *require, const struct http_auth_backend_t *backend) { +static handler_t mod_auth_check_digest(connection *con, void *p_d, const struct http_auth_require_t *require, const struct http_auth_backend_t *backend) { const buffer *vb = http_header_request_get(con, HTTP_HEADER_AUTHORIZATION, CONST_STR_LEN("Authorization")); char *username = NULL; @@ -969,23 +974,24 @@ static handler_t mod_auth_check_digest(server *srv, connection *con, void *p_d, UNUSED(p_d); if (NULL == backend) { - log_error_write(srv, __FILE__, __LINE__, "sb", "auth.backend not configured for", con->uri.path); + log_error(con->conf.errh, __FILE__, __LINE__, + "auth.backend not configured for %s", con->uri.path->ptr); con->http_status = 500; con->mode = DIRECT; return HANDLER_FINISHED; } if (NULL == vb) { - return mod_auth_send_401_unauthorized_digest(srv, con, require, 0); + return mod_auth_send_401_unauthorized_digest(con, require, 0); } if (!buffer_eq_icase_ssn(vb->ptr, CONST_STR_LEN("Digest "))) { - return mod_auth_send_401_unauthorized_digest(srv, con, require, 0); + return mod_auth_send_401_unauthorized_digest(con, require, 0); } else { size_t n = buffer_string_length(vb); #ifdef __COVERITY__ if (n < sizeof("Digest ")-1) { - return mod_auth_send_400_bad_request(srv, con); + return mod_auth_send_400_bad_request(con); } #endif n -= (sizeof("Digest ")-1); @@ -1033,11 +1039,11 @@ static handler_t mod_auth_check_digest(server *srv, connection *con, void *p_d, !respons ) { /* missing field */ - log_error_write(srv, __FILE__, __LINE__, "s", - "digest: missing field"); + log_error(con->conf.errh, __FILE__, __LINE__, + "digest: missing field"); buffer_free(b); - return mod_auth_send_400_bad_request(srv, con); + return mod_auth_send_400_bad_request(con); } ai.username = username; @@ -1046,29 +1052,29 @@ static handler_t mod_auth_check_digest(server *srv, connection *con, void *p_d, ai.rlen = strlen(realm); if (!buffer_is_equal_string(require->realm, ai.realm, ai.rlen)) { - log_error_write(srv, __FILE__, __LINE__, "s", - "digest: realm mismatch"); + log_error(con->conf.errh, __FILE__, __LINE__, + "digest: realm mismatch"); buffer_free(b); - return mod_auth_send_401_unauthorized_digest(srv, con, require, 0); + return mod_auth_send_401_unauthorized_digest(con, require, 0); } if (!mod_auth_algorithm_parse(&ai, algorithm) || !(require->algorithm & ai.dalgo & ~HTTP_AUTH_DIGEST_SESS)) { - log_error_write(srv, __FILE__, __LINE__, "SSS", - "digest: (", algorithm, "): invalid"); + log_error(con->conf.errh, __FILE__, __LINE__, + "digest: (%s): invalid", algorithm); buffer_free(b); - return mod_auth_send_400_bad_request(srv, con); + return mod_auth_send_400_bad_request(con); } /** * protect the md5-sess against missing cnonce and nonce */ if ((ai.dalgo & HTTP_AUTH_DIGEST_SESS) && (!nonce || !cnonce)) { - log_error_write(srv, __FILE__, __LINE__, "SSS", - "digest: (", algorithm, "): missing field"); + log_error(con->conf.errh, __FILE__, __LINE__, + "digest: (%s): missing field", algorithm); buffer_free(b); - return mod_auth_send_400_bad_request(srv, con); + return mod_auth_send_400_bad_request(con); } { @@ -1076,19 +1082,19 @@ static handler_t mod_auth_check_digest(server *srv, connection *con, void *p_d, if (0 != http_auth_digest_hex2bin(respons, resplen, rdigest, sizeof(rdigest)) || resplen != (ai.dlen << 1)) { - log_error_write(srv, __FILE__, __LINE__, "SSS", - "digest: (", respons, "): invalid format"); + log_error(con->conf.errh, __FILE__, __LINE__, + "digest: (%s): invalid format", respons); buffer_free(b); - return mod_auth_send_400_bad_request(srv, con); + return mod_auth_send_400_bad_request(con); } } if (qop && buffer_eq_icase_ss(qop, strlen(qop), CONST_STR_LEN("auth-int"))){ - log_error_write(srv, __FILE__, __LINE__, "s", - "digest: qop=auth-int not supported"); + log_error(con->conf.errh, __FILE__, __LINE__, + "digest: qop=auth-int not supported"); buffer_free(b); - return mod_auth_send_400_bad_request(srv, con); + return mod_auth_send_400_bad_request(con); } m = get_http_method_name(con->request.http_method); @@ -1105,14 +1111,15 @@ static handler_t mod_auth_check_digest(server *srv, connection *con, void *p_d, { const size_t ulen = strlen(uri); if (!buffer_is_equal_string(con->request.orig_uri, uri, ulen)) { - log_error_write(srv, __FILE__, __LINE__, "sbsssB", - "digest: auth failed: uri mismatch (", con->request.orig_uri, "!=", uri, "), IP:", con->dst_addr_buf); + log_error(con->conf.errh, __FILE__, __LINE__, + "digest: auth failed: uri mismatch (%s != %s), IP: %s", + con->request.orig_uri->ptr, uri, con->dst_addr_buf->ptr); buffer_free(b); - return mod_auth_send_400_bad_request(srv, con); + return mod_auth_send_400_bad_request(con); } } - switch (backend->digest(srv, con, backend->p_d, &ai)) { + switch (backend->digest(con, backend->p_d, &ai)) { case HANDLER_GO_ON: break; case HANDLER_WAIT_FOR_EVENT: @@ -1125,25 +1132,26 @@ static handler_t mod_auth_check_digest(server *srv, connection *con, void *p_d, default: con->keep_alive = 0; /*(disable keep-alive if unknown user)*/ buffer_free(b); - return mod_auth_send_401_unauthorized_digest(srv, con, require, 0); + return mod_auth_send_401_unauthorized_digest(con, require, 0); } mod_auth_digest_mutate(&ai,m,uri,nonce,cnonce,nc,qop); if (!http_auth_const_time_memeq(rdigest, ai.digest, ai.dlen)) { /* digest not ok */ - log_error_write(srv, __FILE__, __LINE__, "sssB", - "digest: auth failed for ", username, ": wrong password, IP:", con->dst_addr_buf); + log_error(con->conf.errh, __FILE__, __LINE__, + "digest: auth failed for %s: wrong password, IP: %s", + username, con->dst_addr_buf->ptr); con->keep_alive = 0; /*(disable keep-alive if bad password)*/ buffer_free(b); - return mod_auth_send_401_unauthorized_digest(srv, con, require, 0); + return mod_auth_send_401_unauthorized_digest(con, require, 0); } /* value is our allow-rules */ if (!http_auth_match_rules(require, username, NULL, NULL)) { buffer_free(b); - return mod_auth_send_401_unauthorized_digest(srv, con, require, 0); + return mod_auth_send_401_unauthorized_digest(con, require, 0); } /* check age of nonce. Note, random data is used in nonce generation @@ -1161,11 +1169,12 @@ static handler_t mod_auth_check_digest(server *srv, connection *con, void *p_d, for (i = 0; i < 8 && light_isxdigit(nonce_uns[i]); ++i) { ts = (ts << 4) + hex2int(nonce_uns[i]); } + server * const srv = con->srv; if (nonce[i] != ':' || ts > srv->cur_ts || srv->cur_ts - ts > 600) { /*(10 mins)*/ /* nonce is stale; have client regenerate digest */ buffer_free(b); - return mod_auth_send_401_unauthorized_digest(srv, con, require, ai.dalgo); + return mod_auth_send_401_unauthorized_digest(con, require, ai.dalgo); } else if (srv->cur_ts - ts > 540) { /*(9 mins)*/ /*(send nextnonce when expiration is approaching)*/ @@ -1181,7 +1190,8 @@ static handler_t mod_auth_check_digest(server *srv, connection *con, void *p_d, return HANDLER_GO_ON; } -static handler_t mod_auth_send_401_unauthorized_digest(server *srv, connection *con, const struct http_auth_require_t *require, int nonce_stale) { +static handler_t mod_auth_send_401_unauthorized_digest(connection *con, const struct http_auth_require_t *require, int nonce_stale) { + server *srv = con->srv; mod_auth_digest_www_authenticate(srv->tmp_buf, srv->cur_ts, require, nonce_stale); http_header_response_set(con, HTTP_HEADER_OTHER, CONST_STR_LEN("WWW-Authenticate"), CONST_BUF_LEN(srv->tmp_buf)); @@ -1190,10 +1200,9 @@ static handler_t mod_auth_send_401_unauthorized_digest(server *srv, connection * return HANDLER_FINISHED; } -static handler_t mod_auth_check_extern(server *srv, connection *con, void *p_d, const struct http_auth_require_t *require, const struct http_auth_backend_t *backend) { +static handler_t mod_auth_check_extern(connection *con, void *p_d, const struct http_auth_require_t *require, const struct http_auth_backend_t *backend) { /* require REMOTE_USER already set */ const buffer *vb = http_header_env_get(con, CONST_STR_LEN("REMOTE_USER")); - UNUSED(srv); UNUSED(p_d); UNUSED(backend); if (NULL != vb && http_auth_match_rules(require, vb->ptr, NULL, NULL)) { diff --git a/src/mod_authn_file.c b/src/mod_authn_file.c index 02922595..52667e84 100644 --- a/src/mod_authn_file.c +++ b/src/mod_authn_file.c @@ -38,7 +38,6 @@ #include #include #include -#include #include #include @@ -59,11 +58,11 @@ typedef struct { plugin_config conf; } plugin_data; -static handler_t mod_authn_file_htdigest_digest(server *srv, connection *con, void *p_d, http_auth_info_t *ai); -static handler_t mod_authn_file_htdigest_basic(server *srv, connection *con, void *p_d, const http_auth_require_t *require, const buffer *username, const char *pw); -static handler_t mod_authn_file_plain_digest(server *srv, connection *con, void *p_d, http_auth_info_t *ai); -static handler_t mod_authn_file_plain_basic(server *srv, connection *con, void *p_d, const http_auth_require_t *require, const buffer *username, const char *pw); -static handler_t mod_authn_file_htpasswd_basic(server *srv, connection *con, void *p_d, const http_auth_require_t *require, const buffer *username, const char *pw); +static handler_t mod_authn_file_htdigest_digest(connection *con, void *p_d, http_auth_info_t *ai); +static handler_t mod_authn_file_htdigest_basic(connection *con, void *p_d, const http_auth_require_t *require, const buffer *username, const char *pw); +static handler_t mod_authn_file_plain_digest(connection *con, void *p_d, http_auth_info_t *ai); +static handler_t mod_authn_file_plain_basic(connection *con, void *p_d, const http_auth_require_t *require, const buffer *username, const char *pw); +static handler_t mod_authn_file_htpasswd_basic(connection *con, void *p_d, const http_auth_require_t *require, const buffer *username, const char *pw); INIT_FUNC(mod_authn_file_init) { static http_auth_backend_t http_auth_backend_htdigest = @@ -215,7 +214,7 @@ static void mod_authn_file_digest(http_auth_info_t *ai, const char *pw, size_t p -static int mod_authn_file_htdigest_get_loop(server *srv, FILE *fp, const buffer *auth_fn, http_auth_info_t *ai) { +static int mod_authn_file_htdigest_get_loop(FILE *fp, const buffer *auth_fn, http_auth_info_t *ai, log_error_st *errh) { char f_user[1024]; while (NULL != fgets(f_user, sizeof(f_user), fp)) { @@ -231,19 +230,11 @@ static int mod_authn_file_htdigest_get_loop(server *srv, FILE *fp, const buffer * user:realm:md5(user:realm:password) */ - if (NULL == (f_realm = strchr(f_user, ':'))) { - log_error_write(srv, __FILE__, __LINE__, "sbs", - "parsed error in", auth_fn, - "expected 'username:realm:hashed password'"); - - continue; /* skip bad lines */ - } - - if (NULL == (f_pwd = strchr(f_realm + 1, ':'))) { - log_error_write(srv, __FILE__, __LINE__, "sbs", - "parsed error in", auth_fn, - "expected 'username:realm:hashed password'"); - + if (NULL == (f_realm = strchr(f_user, ':')) + || NULL == (f_pwd = strchr(f_realm + 1, ':'))) { + log_error(errh, __FILE__, __LINE__, + "parsed error in %s expected 'username:realm:hashed password'", + auth_fn->ptr); continue; /* skip bad lines */ } @@ -270,7 +261,7 @@ static int mod_authn_file_htdigest_get_loop(server *srv, FILE *fp, const buffer return -1; } -static int mod_authn_file_htdigest_get(server *srv, connection *con, void *p_d, http_auth_info_t *ai) { +static int mod_authn_file_htdigest_get(connection *con, void *p_d, http_auth_info_t *ai) { plugin_data *p = (plugin_data *)p_d; const buffer *auth_fn; FILE *fp; @@ -281,23 +272,24 @@ static int mod_authn_file_htdigest_get(server *srv, connection *con, void *p_d, fp = fopen(auth_fn->ptr, "r"); if (NULL != fp) { - int rc = mod_authn_file_htdigest_get_loop(srv, fp, auth_fn, ai); + int rc = mod_authn_file_htdigest_get_loop(fp,auth_fn,ai,con->conf.errh); fclose(fp); return rc; } else { - log_error_write(srv, __FILE__, __LINE__, "sbss", "opening digest-userfile", auth_fn, "failed:", strerror(errno)); + log_perror(con->conf.errh, __FILE__, __LINE__, + "opening digest-userfile %s", auth_fn->ptr); return -1; } } -static handler_t mod_authn_file_htdigest_digest(server *srv, connection *con, void *p_d, http_auth_info_t *ai) { - return (0 == mod_authn_file_htdigest_get(srv, con, p_d, ai)) +static handler_t mod_authn_file_htdigest_digest(connection *con, void *p_d, http_auth_info_t *ai) { + return (0 == mod_authn_file_htdigest_get(con, p_d, ai)) ? HANDLER_GO_ON : HANDLER_ERROR; } -static handler_t mod_authn_file_htdigest_basic(server *srv, connection *con, void *p_d, const http_auth_require_t *require, const buffer *username, const char *pw) { +static handler_t mod_authn_file_htdigest_basic(connection *con, void *p_d, const http_auth_require_t *require, const buffer *username, const char *pw) { http_auth_info_t ai; unsigned char htdigest[sizeof(ai.digest)]; @@ -309,7 +301,7 @@ static handler_t mod_authn_file_htdigest_basic(server *srv, connection *con, voi ai.realm = require->realm->ptr; ai.rlen = buffer_string_length(require->realm); - if (mod_authn_file_htdigest_get(srv, con, p_d, &ai)) return HANDLER_ERROR; + if (mod_authn_file_htdigest_get(con, p_d, &ai)) return HANDLER_ERROR; if (ai.dlen > sizeof(htdigest)) return HANDLER_ERROR;/*(should not happen)*/ memcpy(htdigest, ai.digest, ai.dlen); /*(save digest before reuse of ai)*/ @@ -325,7 +317,7 @@ static handler_t mod_authn_file_htdigest_basic(server *srv, connection *con, voi -static int mod_authn_file_htpasswd_get(server *srv, const buffer *auth_fn, const char *username, size_t userlen, buffer *password) { +static int mod_authn_file_htpasswd_get(const buffer *auth_fn, const char *username, size_t userlen, buffer *password, log_error_st *errh) { FILE *fp; char f_user[1024]; @@ -334,8 +326,8 @@ static int mod_authn_file_htpasswd_get(server *srv, const buffer *auth_fn, const if (buffer_string_is_empty(auth_fn)) return -1; fp = fopen(auth_fn->ptr, "r"); if (NULL == fp) { - log_error_write(srv, __FILE__, __LINE__, "sbss", - "opening plain-userfile", auth_fn, "failed:", strerror(errno)); + log_perror(errh, __FILE__, __LINE__, + "opening plain-userfile %s", auth_fn->ptr); return -1; } @@ -354,10 +346,9 @@ static int mod_authn_file_htpasswd_get(server *srv, const buffer *auth_fn, const */ if (NULL == (f_pwd = strchr(f_user, ':'))) { - log_error_write(srv, __FILE__, __LINE__, "sbs", - "parsed error in", auth_fn, - "expected 'username:hashed password'"); - + log_error(errh, __FILE__, __LINE__, + "parsed error in %s expected 'username:hashed password'", + auth_fn->ptr); continue; /* skip bad lines */ } @@ -382,12 +373,12 @@ static int mod_authn_file_htpasswd_get(server *srv, const buffer *auth_fn, const return -1; } -static handler_t mod_authn_file_plain_digest(server *srv, connection *con, void *p_d, http_auth_info_t *ai) { +static handler_t mod_authn_file_plain_digest(connection *con, void *p_d, http_auth_info_t *ai) { plugin_data *p = (plugin_data *)p_d; buffer *password_buf = buffer_init();/* password-string from auth-backend */ int rc; mod_authn_file_patch_config(con, p); - rc = mod_authn_file_htpasswd_get(srv, p->conf.auth_plain_userfile, ai->username, ai->ulen, password_buf); + rc = mod_authn_file_htpasswd_get(p->conf.auth_plain_userfile, ai->username, ai->ulen, password_buf, con->conf.errh); if (0 == rc) { /* generate password from plain-text */ mod_authn_file_digest(ai, CONST_BUF_LEN(password_buf)); @@ -396,12 +387,12 @@ static handler_t mod_authn_file_plain_digest(server *srv, connection *con, void return (0 == rc) ? HANDLER_GO_ON : HANDLER_ERROR; } -static handler_t mod_authn_file_plain_basic(server *srv, connection *con, void *p_d, const http_auth_require_t *require, const buffer *username, const char *pw) { +static handler_t mod_authn_file_plain_basic(connection *con, void *p_d, const http_auth_require_t *require, const buffer *username, const char *pw) { plugin_data *p = (plugin_data *)p_d; buffer *password_buf = buffer_init();/* password-string from auth-backend */ int rc; mod_authn_file_patch_config(con, p); - rc = mod_authn_file_htpasswd_get(srv, p->conf.auth_plain_userfile, CONST_BUF_LEN(username), password_buf); + rc = mod_authn_file_htpasswd_get(p->conf.auth_plain_userfile, CONST_BUF_LEN(username), password_buf, con->conf.errh); if (0 == rc) { rc = http_auth_const_time_memeq_pad(CONST_BUF_LEN(password_buf), pw, strlen(pw)) ? 0 : -1; } @@ -620,12 +611,12 @@ static void apr_sha_encode(const char *pw, char *result, size_t nbytes) { result[5 + base64_written] = '\0'; /* terminate string */ } -static handler_t mod_authn_file_htpasswd_basic(server *srv, connection *con, void *p_d, const http_auth_require_t *require, const buffer *username, const char *pw) { +static handler_t mod_authn_file_htpasswd_basic(connection *con, void *p_d, const http_auth_require_t *require, const buffer *username, const char *pw) { plugin_data *p = (plugin_data *)p_d; buffer *password = buffer_init();/* password-string from auth-backend */ int rc; mod_authn_file_patch_config(con, p); - rc = mod_authn_file_htpasswd_get(srv, p->conf.auth_htpasswd_userfile, CONST_BUF_LEN(username), password); + rc = mod_authn_file_htpasswd_get(p->conf.auth_htpasswd_userfile, CONST_BUF_LEN(username), password, con->conf.errh); if (0 == rc) { char sample[256]; rc = -1; diff --git a/src/mod_authn_gssapi.c b/src/mod_authn_gssapi.c index 6ce112d2..e23a9a09 100644 --- a/src/mod_authn_gssapi.c +++ b/src/mod_authn_gssapi.c @@ -32,7 +32,6 @@ #include "log.h" #include "base64.h" -#include #include #include #include @@ -49,8 +48,8 @@ typedef struct { plugin_config conf; } plugin_data; -static handler_t mod_authn_gssapi_check(server *srv, connection *con, void *p_d, const struct http_auth_require_t *require, const struct http_auth_backend_t *backend); -static handler_t mod_authn_gssapi_basic(server *srv, connection *con, void *p_d, const http_auth_require_t *require, const buffer *username, const char *pw); +static handler_t mod_authn_gssapi_check(connection *con, void *p_d, const struct http_auth_require_t *require, const struct http_auth_backend_t *backend); +static handler_t mod_authn_gssapi_basic(connection *con, void *p_d, const http_auth_require_t *require, const buffer *username, const char *pw); INIT_FUNC(mod_authn_gssapi_init) { static http_auth_scheme_t http_auth_scheme_gssapi = @@ -132,15 +131,16 @@ SETDEFAULTS_FUNC(mod_authn_gssapi_set_defaults) { return HANDLER_GO_ON; } -static handler_t mod_authn_gssapi_send_400_bad_request (server *srv, connection *con) +__attribute_cold__ +static handler_t mod_authn_gssapi_send_400_bad_request (connection *con) { - UNUSED(srv); con->http_status = 400; con->mode = DIRECT; return HANDLER_FINISHED; } -static void mod_authn_gssapi_log_gss_error(server *srv, const char *file, unsigned int line, const char *func, const char *extra, OM_uint32 err_maj, OM_uint32 err_min) +__attribute_cold__ +static void mod_authn_gssapi_log_gss_error(log_error_st *errh, const char *file, unsigned int line, const char *func, const char *extra, OM_uint32 err_maj, OM_uint32 err_min) { buffer * const msg = buffer_init_string(func); OM_uint32 maj_stat, min_stat; @@ -170,19 +170,20 @@ static void mod_authn_gssapi_log_gss_error(server *srv, const char *file, unsign } } while (!GSS_ERROR(maj_stat) && msg_ctx != 0); - log_error_write(srv, file, line, "b", msg); + log_error(errh, file, line, "%s", msg->ptr); buffer_free(msg); } -static void mod_authn_gssapi_log_krb5_error(server *srv, const char *file, unsigned int line, const char *func, const char *extra, krb5_context context, int code) +__attribute_cold__ +static void mod_authn_gssapi_log_krb5_error(log_error_st *errh, const char *file, unsigned int line, const char *func, const char *extra, krb5_context context, int code) { UNUSED(context); /*(extra might be NULL)*/ - log_error_write(srv, file, line, "sssss", func, "(", extra, "):", - error_message(code)); + log_error(errh, file, line, + "%s (%s): %s", func, extra ? extra : "", error_message(code)); } -static int mod_authn_gssapi_create_krb5_ccache(server *srv, connection *con, plugin_data *p, krb5_context kcontext, krb5_principal princ, krb5_ccache *ccache) +static int mod_authn_gssapi_create_krb5_ccache(connection *con, plugin_data *p, krb5_context kcontext, krb5_principal princ, krb5_ccache *ccache) { buffer * const kccname = buffer_init_string("FILE:/tmp/krb5cc_gssapi_XXXXXX"); char * const ccname = kccname->ptr + sizeof("FILE:")-1; @@ -195,7 +196,7 @@ static int mod_authn_gssapi_create_krb5_ccache(server *srv, connection *con, plu /* coverity[secure_temp : FALSE] */ int fd = mkstemp(ccname); if (fd < 0) { - log_error_write(srv, __FILE__, __LINE__, "sss", "mkstemp():", ccname, strerror(errno)); + log_perror(con->conf.errh, __FILE__, __LINE__, "mkstemp(): %s", ccname); buffer_free(kccname); return -1; } @@ -206,13 +207,13 @@ static int mod_authn_gssapi_create_krb5_ccache(server *srv, connection *con, plu problem = krb5_cc_resolve(kcontext, kccname->ptr, ccache); if (problem) { - mod_authn_gssapi_log_krb5_error(srv, __FILE__, __LINE__, "krb5_cc_resolve", NULL, kcontext, problem); + mod_authn_gssapi_log_krb5_error(con->conf.errh, __FILE__, __LINE__, "krb5_cc_resolve", NULL, kcontext, problem); break; } problem = krb5_cc_initialize(kcontext, *ccache, princ); if (problem) { - mod_authn_gssapi_log_krb5_error(srv, __FILE__, __LINE__, "krb5_cc_initialize", kccname->ptr, kcontext, problem); + mod_authn_gssapi_log_krb5_error(con->conf.errh, __FILE__, __LINE__, "krb5_cc_initialize", kccname->ptr, kcontext, problem); break; } @@ -254,7 +255,7 @@ static handler_t mod_authn_gssapi_send_401_unauthorized_negotiate (connection *c return HANDLER_FINISHED; } -static int mod_authn_gssapi_store_gss_creds(server *srv, connection *con, plugin_data *p, char *princ_name, gss_cred_id_t delegated_cred) +static int mod_authn_gssapi_store_gss_creds(connection *con, plugin_data *p, char *princ_name, gss_cred_id_t delegated_cred) { OM_uint32 maj_stat, min_stat; krb5_principal princ = NULL; @@ -264,22 +265,22 @@ static int mod_authn_gssapi_store_gss_creds(server *srv, connection *con, plugin problem = krb5_init_context(&context); if (problem) { - mod_authn_gssapi_log_krb5_error(srv, __FILE__, __LINE__, "krb5_init_context", NULL, context, problem); + mod_authn_gssapi_log_krb5_error(con->conf.errh, __FILE__, __LINE__, "krb5_init_context", NULL, context, problem); return 0; } problem = krb5_parse_name(context, princ_name, &princ); if (problem) { - mod_authn_gssapi_log_krb5_error(srv, __FILE__, __LINE__, "krb5_parse_name", NULL, context, problem); + mod_authn_gssapi_log_krb5_error(con->conf.errh, __FILE__, __LINE__, "krb5_parse_name", NULL, context, problem); goto end; } - if (mod_authn_gssapi_create_krb5_ccache(srv, con, p, context, princ, &ccache)) + if (mod_authn_gssapi_create_krb5_ccache(con, p, context, princ, &ccache)) goto end; maj_stat = gss_krb5_copy_ccache(&min_stat, delegated_cred, ccache); if (GSS_ERROR(maj_stat)) { - mod_authn_gssapi_log_gss_error(srv, __FILE__, __LINE__, "gss_krb5_copy_ccache", princ_name, maj_stat, min_stat); + mod_authn_gssapi_log_gss_error(con->conf.errh, __FILE__, __LINE__, "gss_krb5_copy_ccache", princ_name, maj_stat, min_stat); goto end; } @@ -298,7 +299,7 @@ static int mod_authn_gssapi_store_gss_creds(server *srv, connection *con, plugin return 0; } -static handler_t mod_authn_gssapi_check_spnego(server *srv, connection *con, plugin_data *p, const http_auth_require_t *require, const char *realm_str) +static handler_t mod_authn_gssapi_check_spnego(connection *con, plugin_data *p, const http_auth_require_t *require, const char *realm_str) { OM_uint32 st_major, st_minor, acc_flags; gss_buffer_desc token_s = GSS_C_EMPTY_BUFFER; @@ -315,9 +316,9 @@ static handler_t mod_authn_gssapi_check_spnego(server *srv, connection *con, plu buffer *t_in = buffer_init(); if (!buffer_append_base64_decode(t_in, realm_str, strlen(realm_str), BASE64_STANDARD)) { - log_error_write(srv, __FILE__, __LINE__, "ss", "decoding GSSAPI authentication header failed", realm_str); + log_error(con->conf.errh, __FILE__, __LINE__, "decoding GSSAPI authentication header failed %s", realm_str); buffer_free(t_in); - return mod_authn_gssapi_send_400_bad_request(srv, con); + return mod_authn_gssapi_send_400_bad_request(con); } mod_authn_gssapi_patch_config(con, p); @@ -358,21 +359,21 @@ static handler_t mod_authn_gssapi_check_spnego(server *srv, connection *con, plu token_s.length = buffer_string_length(sprinc); st_major = gss_import_name(&st_minor, &token_s, (gss_OID) GSS_KRB5_NT_PRINCIPAL_NAME, &server_name); if (GSS_ERROR(st_major)) { - mod_authn_gssapi_log_gss_error(srv, __FILE__, __LINE__, "gss_import_name", NULL, st_major, st_minor); + mod_authn_gssapi_log_gss_error(con->conf.errh, __FILE__, __LINE__, "gss_import_name", NULL, st_major, st_minor); goto end; } memset(&token_s, 0, sizeof(token_s)); st_major = gss_display_name(&st_minor, server_name, &token_s, NULL); if (GSS_ERROR(st_major)) { - mod_authn_gssapi_log_gss_error(srv, __FILE__, __LINE__, "gss_display_name", NULL, st_major, st_minor); + mod_authn_gssapi_log_gss_error(con->conf.errh, __FILE__, __LINE__, "gss_display_name", NULL, st_major, st_minor); goto end; } /* acquire server's own credentials */ st_major = gss_acquire_cred(&st_minor, server_name, GSS_C_INDEFINITE, GSS_C_NO_OID_SET, GSS_C_ACCEPT, &server_cred, NULL, NULL); if (GSS_ERROR(st_major)) { - mod_authn_gssapi_log_gss_error(srv, __FILE__, __LINE__, "gss_acquire_cred", sprinc->ptr, st_major, st_minor); + mod_authn_gssapi_log_gss_error(con->conf.errh, __FILE__, __LINE__, "gss_acquire_cred", sprinc->ptr, st_major, st_minor); goto end; } @@ -382,19 +383,19 @@ static handler_t mod_authn_gssapi_check_spnego(server *srv, connection *con, plu st_major = gss_accept_sec_context(&st_minor, &context, server_cred, &token_in, GSS_C_NO_CHANNEL_BINDINGS, &client_name, NULL, &token_out, &acc_flags, NULL, &client_cred); if (GSS_ERROR(st_major)) { - mod_authn_gssapi_log_gss_error(srv, __FILE__, __LINE__, "gss_accept_sec_context", NULL, st_major, st_minor); + mod_authn_gssapi_log_gss_error(con->conf.errh, __FILE__, __LINE__, "gss_accept_sec_context", NULL, st_major, st_minor); goto end; } /* fetch the username */ st_major = gss_display_name(&st_minor, client_name, &token_out, NULL); if (GSS_ERROR(st_major)) { - mod_authn_gssapi_log_gss_error(srv, __FILE__, __LINE__, "gss_display_name", NULL, st_major, st_minor); + mod_authn_gssapi_log_gss_error(con->conf.errh, __FILE__, __LINE__, "gss_display_name", NULL, st_major, st_minor); goto end; } if (!(acc_flags & GSS_C_CONF_FLAG)) { - log_error_write(srv, __FILE__, __LINE__, "ss", "No confidentiality for user:", token_out.value); + log_error(con->conf.errh, __FILE__, __LINE__, "No confidentiality for user: %s", (char *)token_out.value); goto end; } @@ -405,10 +406,10 @@ static handler_t mod_authn_gssapi_check_spnego(server *srv, connection *con, plu if (p->conf.auth_gssapi_store_creds) { if (!(acc_flags & GSS_C_DELEG_FLAG)) { - log_error_write(srv, __FILE__, __LINE__, "ss", "Unable to delegate credentials for user:", token_out.value); + log_error(con->conf.errh, __FILE__, __LINE__, "Unable to delegate credentials for user: %s", (char *)token_out.value); goto end; } - else if (!mod_authn_gssapi_store_gss_creds(srv, con, p, token_out.value, client_cred)) { + else if (!mod_authn_gssapi_store_gss_creds(con, p, token_out.value, client_cred)) { rc = mod_authn_gssapi_send_500_server_error(con); goto end; } @@ -444,7 +445,7 @@ static handler_t mod_authn_gssapi_check_spnego(server *srv, connection *con, plu return rc != HANDLER_UNSET ? rc : mod_authn_gssapi_send_401_unauthorized_negotiate(con); } -static handler_t mod_authn_gssapi_check (server *srv, connection *con, void *p_d, const struct http_auth_require_t *require, const struct http_auth_backend_t *backend) +static handler_t mod_authn_gssapi_check (connection *con, void *p_d, const struct http_auth_require_t *require, const struct http_auth_backend_t *backend) { const buffer *vb = http_header_request_get(con, HTTP_HEADER_AUTHORIZATION, CONST_STR_LEN("Authorization")); @@ -454,17 +455,17 @@ static handler_t mod_authn_gssapi_check (server *srv, connection *con, void *p_d } if (!buffer_eq_icase_ssn(vb->ptr, CONST_STR_LEN("Negotiate "))) { - return mod_authn_gssapi_send_400_bad_request(srv, con); + return mod_authn_gssapi_send_400_bad_request(con); } - return mod_authn_gssapi_check_spnego(srv, con, (plugin_data *)p_d, require, vb->ptr+sizeof("Negotiate ")-1); + return mod_authn_gssapi_check_spnego(con, (plugin_data *)p_d, require, vb->ptr+sizeof("Negotiate ")-1); } /* * HTTP auth Basic realm="kerberos" */ -static krb5_error_code mod_authn_gssapi_verify_krb5_init_creds(server *srv, krb5_context context, krb5_creds *creds, krb5_principal ap_req_server, krb5_keytab ap_req_keytab) +static krb5_error_code mod_authn_gssapi_verify_krb5_init_creds(krb5_context context, krb5_creds *creds, krb5_principal ap_req_server, krb5_keytab ap_req_keytab, log_error_st *errh) { krb5_error_code ret; krb5_data req; @@ -485,26 +486,26 @@ static krb5_error_code mod_authn_gssapi_verify_krb5_init_creds(server *srv, krb5 ret = krb5_cc_resolve(context, "MEMORY:", &local_ccache); if (ret) { - log_error_write(srv, __FILE__, __LINE__, "s", "krb5_cc_resolve() failed when verifying KDC"); + log_error(errh, __FILE__, __LINE__, "krb5_cc_resolve() failed when verifying KDC"); /* return ret; */ goto end; } ret = krb5_cc_initialize(context, local_ccache, creds->client); if (ret) { - log_error_write(srv, __FILE__, __LINE__, "s", "krb5_cc_initialize() failed when verifying KDC"); + log_error(errh, __FILE__, __LINE__, "krb5_cc_initialize() failed when verifying KDC"); goto end; } ret = krb5_cc_store_cred(context, local_ccache, creds); if (ret) { - log_error_write(srv, __FILE__, __LINE__, "s", "krb5_cc_store_cred() failed when verifying KDC"); + log_error(errh, __FILE__, __LINE__, "krb5_cc_store_cred() failed when verifying KDC"); goto end; } ret = krb5_unparse_name(context, ap_req_server, &server_name); if (ret) { - log_error_write(srv, __FILE__, __LINE__, "s", "krb5_unparse_name() failed when verifying KDC"); + log_error(errh, __FILE__, __LINE__, "krb5_unparse_name() failed when verifying KDC"); goto end; } krb5_free_unparsed_name(context, server_name); @@ -519,7 +520,7 @@ static krb5_error_code mod_authn_gssapi_verify_krb5_init_creds(server *srv, krb5 ret = krb5_get_credentials(context, 0, local_ccache, &match_cred, &new_creds); if (ret) { - log_error_write(srv, __FILE__, __LINE__, "s", "krb5_get_credentials() failed when verifying KDC"); + log_error(errh, __FILE__, __LINE__, "krb5_get_credentials() failed when verifying KDC"); goto end; } creds = new_creds; @@ -527,7 +528,7 @@ static krb5_error_code mod_authn_gssapi_verify_krb5_init_creds(server *srv, krb5 ret = krb5_mk_req_extended(context, &auth_context, 0, NULL, creds, &req); if (ret) { - log_error_write(srv, __FILE__, __LINE__, "s", "krb5_mk_req_extended() failed when verifying KDC"); + log_error(errh, __FILE__, __LINE__, "krb5_mk_req_extended() failed when verifying KDC"); goto end; } @@ -535,7 +536,7 @@ static krb5_error_code mod_authn_gssapi_verify_krb5_init_creds(server *srv, krb5 auth_context = NULL; ret = krb5_auth_con_init(context, &auth_context); if (ret) { - log_error_write(srv, __FILE__, __LINE__, "s", "krb5_auth_con_init() failed when verifying KDC"); + log_error(errh, __FILE__, __LINE__, "krb5_auth_con_init() failed when verifying KDC"); goto end; } @@ -543,7 +544,7 @@ static krb5_error_code mod_authn_gssapi_verify_krb5_init_creds(server *srv, krb5 krb5_auth_con_setflags(context, auth_context, KRB5_AUTH_CONTEXT_DO_SEQUENCE); ret = krb5_rd_req(context, &auth_context, &req, ap_req_server, keytab, 0, NULL); if (ret) { - log_error_write(srv, __FILE__, __LINE__, "s", "krb5_rd_req() failed when verifying KDC"); + log_error(errh, __FILE__, __LINE__, "krb5_rd_req() failed when verifying KDC"); goto end; } @@ -561,7 +562,7 @@ static krb5_error_code mod_authn_gssapi_verify_krb5_init_creds(server *srv, krb5 return ret; } -static int mod_authn_gssapi_store_krb5_creds(server *srv, connection *con, plugin_data *p, +static int mod_authn_gssapi_store_krb5_creds(connection *con, plugin_data *p, krb5_context kcontext, krb5_ccache delegated_cred) { krb5_error_code problem; @@ -570,17 +571,17 @@ static int mod_authn_gssapi_store_krb5_creds(server *srv, connection *con, plugi problem = krb5_cc_get_principal(kcontext, delegated_cred, &princ); if (problem) { - mod_authn_gssapi_log_krb5_error(srv, __FILE__, __LINE__, "krb5_cc_get_principal", NULL, kcontext, problem); + mod_authn_gssapi_log_krb5_error(con->conf.errh, __FILE__, __LINE__, "krb5_cc_get_principal", NULL, kcontext, problem); goto end; } - if (mod_authn_gssapi_create_krb5_ccache(srv, con, p, kcontext, princ, &ccache)) { + if (mod_authn_gssapi_create_krb5_ccache(con, p, kcontext, princ, &ccache)) { goto end; } problem = krb5_cc_copy_creds(kcontext, delegated_cred, ccache); if (problem) { - mod_authn_gssapi_log_krb5_error(srv, __FILE__, __LINE__, "krb5_cc_copy_creds", NULL, kcontext, problem); + mod_authn_gssapi_log_krb5_error(con->conf.errh, __FILE__, __LINE__, "krb5_cc_copy_creds", NULL, kcontext, problem); goto end; } @@ -604,7 +605,7 @@ static handler_t mod_authn_gssapi_send_401_unauthorized_basic (connection *con) return HANDLER_FINISHED; } -static handler_t mod_authn_gssapi_basic(server *srv, connection *con, void *p_d, const http_auth_require_t *require, const buffer *username, const char *pw) +static handler_t mod_authn_gssapi_basic(connection *con, void *p_d, const http_auth_require_t *require, const buffer *username, const char *pw) { krb5_context kcontext = NULL; krb5_keytab keytab = NULL; @@ -620,7 +621,7 @@ static handler_t mod_authn_gssapi_basic(server *srv, connection *con, void *p_d, plugin_data * const p = (plugin_data *)p_d; if (*pw == '\0') { - log_error_write(srv, __FILE__, __LINE__, "s", "Empty passwords are not accepted"); + log_error(con->conf.errh, __FILE__, __LINE__, "Empty passwords are not accepted"); return mod_authn_gssapi_send_401_unauthorized_basic(con); } @@ -628,18 +629,18 @@ static handler_t mod_authn_gssapi_basic(server *srv, connection *con, void *p_d, code = krb5_init_context(&kcontext); if (code) { - log_error_write(srv, __FILE__, __LINE__, "sd", "krb5_init_context():", code); + log_error(con->conf.errh, __FILE__, __LINE__, "krb5_init_context(): %d", code); return mod_authn_gssapi_send_401_unauthorized_basic(con); /*(well, should be 500)*/ } if (buffer_string_is_empty(p->conf.auth_gssapi_keytab)) { - log_error_write(srv, __FILE__, __LINE__, "s", "auth.backend.gssapi.keytab not configured"); + log_error(con->conf.errh, __FILE__, __LINE__, "auth.backend.gssapi.keytab not configured"); return mod_authn_gssapi_send_401_unauthorized_basic(con); /*(well, should be 500)*/ } code = krb5_kt_resolve(kcontext, p->conf.auth_gssapi_keytab->ptr, &keytab); if (code) { - log_error_write(srv, __FILE__, __LINE__, "sdb", "krb5_kt_resolve():", code, p->conf.auth_gssapi_keytab); + log_error(con->conf.errh, __FILE__, __LINE__, "krb5_kt_resolve(): %d %s", code, p->conf.auth_gssapi_keytab->ptr); return mod_authn_gssapi_send_401_unauthorized_basic(con); /*(well, should be 500)*/ } @@ -660,7 +661,7 @@ static handler_t mod_authn_gssapi_basic(server *srv, connection *con, void *p_d, ret = krb5_parse_name(kcontext, sprinc->ptr, &s_princ); if (ret) { - mod_authn_gssapi_log_krb5_error(srv, __FILE__, __LINE__, "krb5_parse_name", sprinc->ptr, kcontext, ret); + mod_authn_gssapi_log_krb5_error(con->conf.errh, __FILE__, __LINE__, "krb5_parse_name", sprinc->ptr, kcontext, ret); ret = -1; goto end; } @@ -673,7 +674,7 @@ static handler_t mod_authn_gssapi_basic(server *srv, connection *con, void *p_d, ret = krb5_parse_name(kcontext, (user_at_realm ? user_at_realm->ptr : username->ptr), &c_princ); if (ret) { - mod_authn_gssapi_log_krb5_error(srv, __FILE__, __LINE__, "krb5_parse_name", (user_at_realm ? user_at_realm->ptr : username->ptr), kcontext, ret); + mod_authn_gssapi_log_krb5_error(con->conf.errh, __FILE__, __LINE__, "krb5_parse_name", (user_at_realm ? user_at_realm->ptr : username->ptr), kcontext, ret); if (user_at_realm) buffer_free(user_at_realm); ret = -1; goto end; @@ -689,20 +690,20 @@ static handler_t mod_authn_gssapi_basic(server *srv, connection *con, void *p_d, * char *name = NULL; * ret = krb5_unparse_name(kcontext, c_princ, &name); * if (ret == 0) { - * log_error_write(srv, __FILE__, __LINE__, "sbss", "Trying to get TGT for user:", username, "password:", pw); + * log_error(con->conf.errh, __FILE__, __LINE__, "Trying to get TGT for user: %s password: %s", username->ptr, pw); * } * krb5_free_unparsed_name(kcontext, name); */ ret = krb5_get_init_creds_password(kcontext, &c_creds, c_princ, pw, NULL, NULL, 0, NULL, NULL); if (ret) { - mod_authn_gssapi_log_krb5_error(srv, __FILE__, __LINE__, "krb5_get_init_creds_password", NULL, kcontext, ret); + mod_authn_gssapi_log_krb5_error(con->conf.errh, __FILE__, __LINE__, "krb5_get_init_creds_password", NULL, kcontext, ret); goto end; } - ret = mod_authn_gssapi_verify_krb5_init_creds(srv, kcontext, &c_creds, s_princ, keytab); + ret = mod_authn_gssapi_verify_krb5_init_creds(kcontext, &c_creds, s_princ, keytab, con->conf.errh); if (ret) { - mod_authn_gssapi_log_krb5_error(srv, __FILE__, __LINE__, "mod_authn_gssapi_verify_krb5_init_creds", NULL, kcontext, ret); + mod_authn_gssapi_log_krb5_error(con->conf.errh, __FILE__, __LINE__, "mod_authn_gssapi_verify_krb5_init_creds", NULL, kcontext, ret); goto end; } @@ -710,19 +711,19 @@ static handler_t mod_authn_gssapi_basic(server *srv, connection *con, void *p_d, ret = krb5_cc_resolve(kcontext, "MEMORY:", &ret_ccache); if (ret) { - mod_authn_gssapi_log_krb5_error(srv, __FILE__, __LINE__, "krb5_cc_resolve", NULL, kcontext, ret); + mod_authn_gssapi_log_krb5_error(con->conf.errh, __FILE__, __LINE__, "krb5_cc_resolve", NULL, kcontext, ret); goto end; } ret = krb5_cc_initialize(kcontext, ret_ccache, c_princ); if (ret) { - mod_authn_gssapi_log_krb5_error(srv, __FILE__, __LINE__, "krb5_cc_initialize", NULL, kcontext, ret); + mod_authn_gssapi_log_krb5_error(con->conf.errh, __FILE__, __LINE__, "krb5_cc_initialize", NULL, kcontext, ret); goto end; } ret = krb5_cc_store_cred(kcontext, ret_ccache, &c_creds); if (ret) { - mod_authn_gssapi_log_krb5_error(srv, __FILE__, __LINE__, "krb5_cc_store_cred", NULL, kcontext, ret); + mod_authn_gssapi_log_krb5_error(con->conf.errh, __FILE__, __LINE__, "krb5_cc_store_cred", NULL, kcontext, ret); goto end; } @@ -735,8 +736,8 @@ static handler_t mod_authn_gssapi_basic(server *srv, connection *con, void *p_d, if (ret_ccache) krb5_cc_destroy(kcontext, ret_ccache); - if (!ret && c_ccache && (ret = mod_authn_gssapi_store_krb5_creds(srv, con, p, kcontext, c_ccache))) { - log_error_write(srv, __FILE__, __LINE__, "sb", "mod_authn_gssapi_store_krb5_creds failed for", username); + if (!ret && c_ccache && (ret = mod_authn_gssapi_store_krb5_creds(con, p, kcontext, c_ccache))) { + log_error(con->conf.errh, __FILE__, __LINE__, "mod_authn_gssapi_store_krb5_creds failed for %s", username->ptr); } buffer_free(sprinc); @@ -756,7 +757,9 @@ static handler_t mod_authn_gssapi_basic(server *srv, connection *con, void *p_d, } else { /* ret == KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN or no authz rules match */ - log_error_write(srv, __FILE__, __LINE__, "sbsBsB", "password doesn't match for", con->uri.path, "username:", username, ", IP:", con->dst_addr_buf); + log_error(con->conf.errh, __FILE__, __LINE__, + "password doesn't match for %s username: %s IP: %s", + con->uri.path->ptr, username->ptr, con->dst_addr_buf->ptr); return mod_authn_gssapi_send_401_unauthorized_basic(con); } } diff --git a/src/mod_authn_ldap.c b/src/mod_authn_ldap.c index dcb3dd65..ba02c968 100644 --- a/src/mod_authn_ldap.c +++ b/src/mod_authn_ldap.c @@ -7,13 +7,12 @@ #include "log.h" #include "plugin.h" -#include #include #include typedef struct { LDAP *ldap; - server *srv; + log_error_st *errh; const char *auth_ldap_hostname; const char *auth_ldap_binddn; const char *auth_ldap_bindpw; @@ -42,7 +41,7 @@ typedef struct { buffer ldap_filter; } plugin_data; -static handler_t mod_authn_ldap_basic(server *srv, connection *con, void *p_d, const http_auth_require_t *require, const buffer *username, const char *pw); +static handler_t mod_authn_ldap_basic(connection *con, void *p_d, const http_auth_require_t *require, const buffer *username, const char *pw); INIT_FUNC(mod_authn_ldap_init) { static http_auth_backend_t http_auth_backend_ldap = @@ -218,7 +217,7 @@ SETDEFAULTS_FUNC(mod_authn_ldap_set_defaults) { mod_authn_add_scheme(srv, b); ldc = malloc(sizeof(plugin_config_ldap)); force_assert(ldc); - ldc->srv = srv; + ldc->errh = srv->errh; ldc->auth_ldap_hostname = b->ptr; cpv->v.v = ldc; } @@ -308,17 +307,17 @@ SETDEFAULTS_FUNC(mod_authn_ldap_set_defaults) { } __attribute_cold__ -static void mod_authn_ldap_err(server *srv, const char *file, unsigned long line, const char *fn, int err) +static void mod_authn_ldap_err(log_error_st *errh, const char *file, unsigned long line, const char *fn, int err) { - log_error_write(srv,file,line,"sSss","ldap:",fn,":",ldap_err2string(err)); + log_error(errh, file, line, "ldap: %s: %s", fn, ldap_err2string(err)); } __attribute_cold__ -static void mod_authn_ldap_opt_err(server *srv, const char *file, unsigned long line, const char *fn, LDAP *ld) +static void mod_authn_ldap_opt_err(log_error_st *errh, const char *file, unsigned long line, const char *fn, LDAP *ld) { int err; ldap_get_option(ld, LDAP_OPT_ERROR_NUMBER, &err); - mod_authn_ldap_err(srv, file, line, fn, err); + mod_authn_ldap_err(errh, file, line, fn, err); } static void mod_authn_append_ldap_dn_escape(buffer * const filter, const buffer * const raw) { @@ -452,22 +451,21 @@ static void mod_authn_append_ldap_filter_escape(buffer * const filter, const buf } } -static LDAP * mod_authn_ldap_host_init(server *srv, plugin_config_ldap *s) { +static LDAP * mod_authn_ldap_host_init(log_error_st *errh, plugin_config_ldap *s) { LDAP *ld; int ret; if (NULL == s->auth_ldap_hostname) return NULL; if (LDAP_SUCCESS != ldap_initialize(&ld, s->auth_ldap_hostname)) { - log_error_write(srv, __FILE__, __LINE__, "sss", "ldap:", - "ldap_initialize():", strerror(errno)); + log_perror(errh, __FILE__, __LINE__, "ldap: ldap_initialize()"); return NULL; } ret = LDAP_VERSION3; ret = ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, &ret); if (LDAP_OPT_SUCCESS != ret) { - mod_authn_ldap_err(srv, __FILE__, __LINE__, "ldap_set_option()", ret); + mod_authn_ldap_err(errh, __FILE__, __LINE__, "ldap_set_option()", ret); ldap_destroy(ld); return NULL; } @@ -482,7 +480,7 @@ static LDAP * mod_authn_ldap_host_init(server *srv, plugin_config_ldap *s) { ret = ldap_set_option(NULL, LDAP_OPT_X_TLS_CACERTFILE, s->auth_ldap_cafile); if (LDAP_OPT_SUCCESS != ret) { - mod_authn_ldap_err(srv, __FILE__, __LINE__, + mod_authn_ldap_err(errh, __FILE__, __LINE__, "ldap_set_option(LDAP_OPT_X_TLS_CACERTFILE)", ret); ldap_destroy(ld); @@ -492,7 +490,7 @@ static LDAP * mod_authn_ldap_host_init(server *srv, plugin_config_ldap *s) { ret = ldap_start_tls_s(ld, NULL, NULL); if (LDAP_OPT_SUCCESS != ret) { - mod_authn_ldap_err(srv,__FILE__,__LINE__,"ldap_start_tls_s()",ret); + mod_authn_ldap_err(errh,__FILE__,__LINE__,"ldap_start_tls_s()",ret); ldap_destroy(ld); return NULL; } @@ -501,7 +499,7 @@ static LDAP * mod_authn_ldap_host_init(server *srv, plugin_config_ldap *s) { return ld; } -static int mod_authn_ldap_bind(server *srv, LDAP *ld, const char *dn, const char *pw) { +static int mod_authn_ldap_bind(log_error_st *errh, LDAP *ld, const char *dn, const char *pw) { struct berval creds; int ret; @@ -517,7 +515,7 @@ static int mod_authn_ldap_bind(server *srv, LDAP *ld, const char *dn, const char ret = ldap_sasl_bind_s(ld,dn,LDAP_SASL_SIMPLE,&creds,NULL,NULL,NULL); if (ret != LDAP_SUCCESS) { - mod_authn_ldap_err(srv, __FILE__, __LINE__, "ldap_sasl_bind_s()", ret); + mod_authn_ldap_err(errh, __FILE__, __LINE__, "ldap_sasl_bind_s()", ret); } return ret; @@ -529,13 +527,13 @@ static int mod_authn_ldap_rebind_proc (LDAP *ld, LDAP_CONST char *url, ber_tag_t UNUSED(ldap_request); UNUSED(msgid); return s->auth_ldap_binddn - ? mod_authn_ldap_bind(s->srv, ld, + ? mod_authn_ldap_bind(s->errh, ld, s->auth_ldap_binddn, s->auth_ldap_bindpw) - : mod_authn_ldap_bind(s->srv, ld, NULL, NULL); + : mod_authn_ldap_bind(s->errh, ld, NULL, NULL); } -static LDAPMessage * mod_authn_ldap_search(server *srv, plugin_config_ldap *s, const char *base, const char *filter) { +static LDAPMessage * mod_authn_ldap_search(log_error_st *errh, plugin_config_ldap *s, const char *base, const char *filter) { LDAPMessage *lm = NULL; char *attrs[] = { LDAP_NO_ATTRS, NULL }; int ret; @@ -564,7 +562,7 @@ static LDAPMessage * mod_authn_ldap_search(server *srv, plugin_config_ldap *s, c ldap_unbind_ext_s(s->ldap, NULL, NULL); } - s->ldap = mod_authn_ldap_host_init(srv, s); + s->ldap = mod_authn_ldap_host_init(errh, s); if (NULL == s->ldap) { return NULL; } @@ -580,8 +578,8 @@ static LDAPMessage * mod_authn_ldap_search(server *srv, plugin_config_ldap *s, c ret = ldap_search_ext_s(s->ldap, base, LDAP_SCOPE_SUBTREE, filter, attrs, 0, NULL, NULL, NULL, 0, &lm); if (LDAP_SUCCESS != ret) { - log_error_write(srv, __FILE__, __LINE__, "sSss", - "ldap:", ldap_err2string(ret), "; filter:", filter); + log_error(errh, __FILE__, __LINE__, + "ldap: %s; filter: %s", ldap_err2string(ret), filter); ldap_unbind_ext_s(s->ldap, NULL, NULL); s->ldap = NULL; return NULL; @@ -590,13 +588,13 @@ static LDAPMessage * mod_authn_ldap_search(server *srv, plugin_config_ldap *s, c return lm; } -static char * mod_authn_ldap_get_dn(server *srv, plugin_config_ldap *s, const char *base, const char *filter) { +static char * mod_authn_ldap_get_dn(log_error_st *errh, plugin_config_ldap *s, const char *base, const char *filter) { LDAP *ld; LDAPMessage *lm, *first; char *dn; int count; - lm = mod_authn_ldap_search(srv, s, base, filter); + lm = mod_authn_ldap_search(errh, s, base, filter); if (NULL == lm) { return NULL; } @@ -608,19 +606,19 @@ static char * mod_authn_ldap_get_dn(server *srv, plugin_config_ldap *s, const ch ldap_msgfree(lm); return NULL; } else if (count > 1) { - log_error_write(srv, __FILE__, __LINE__, "sss", - "ldap:", "more than one record returned. " - "you might have to refine the filter:", filter); + log_error(errh, __FILE__, __LINE__, + "ldap: more than one record returned. " + "you might have to refine the filter: %s", filter); } if (NULL == (first = ldap_first_entry(ld, lm))) { - mod_authn_ldap_opt_err(srv,__FILE__,__LINE__,"ldap_first_entry()",ld); + mod_authn_ldap_opt_err(errh,__FILE__,__LINE__,"ldap_first_entry()",ld); ldap_msgfree(lm); return NULL; } if (NULL == (dn = ldap_get_dn(ld, first))) { - mod_authn_ldap_opt_err(srv,__FILE__,__LINE__,"ldap_get_dn()",ld); + mod_authn_ldap_opt_err(errh,__FILE__,__LINE__,"ldap_get_dn()",ld); ldap_msgfree(lm); return NULL; } @@ -629,7 +627,7 @@ static char * mod_authn_ldap_get_dn(server *srv, plugin_config_ldap *s, const ch return dn; } -static handler_t mod_authn_ldap_memberOf(server *srv, plugin_config *s, const http_auth_require_t *require, const buffer *username, const char *userdn) { +static handler_t mod_authn_ldap_memberOf(log_error_st *errh, plugin_config *s, const http_auth_require_t *require, const buffer *username, const char *userdn) { const array *groups = &require->group; buffer *filter = buffer_init(); handler_t rc = HANDLER_ERROR; @@ -648,7 +646,7 @@ static handler_t mod_authn_ldap_memberOf(server *srv, plugin_config *s, const ht plugin_config_ldap * const ldc = s->ldc; for (size_t i = 0; i < groups->used; ++i) { const char *base = groups->data[i]->key.ptr; - LDAPMessage *lm = mod_authn_ldap_search(srv, ldc, base, filter->ptr); + LDAPMessage *lm = mod_authn_ldap_search(errh, ldc, base, filter->ptr); if (NULL != lm) { int count = ldap_count_entries(ldc->ldap, lm); ldap_msgfree(lm); @@ -663,7 +661,7 @@ static handler_t mod_authn_ldap_memberOf(server *srv, plugin_config *s, const ht return rc; } -static handler_t mod_authn_ldap_basic(server *srv, connection *con, void *p_d, const http_auth_require_t *require, const buffer *username, const char *pw) { +static handler_t mod_authn_ldap_basic(connection *con, void *p_d, const http_auth_require_t *require, const buffer *username, const char *pw) { plugin_data *p = (plugin_data *)p_d; LDAP *ld; char *dn; @@ -677,6 +675,8 @@ static handler_t mod_authn_ldap_basic(server *srv, connection *con, void *p_d, c if (NULL == template) return HANDLER_ERROR; + log_error_st * const errh = con->conf.errh; + /* build filter to get DN for uid = username */ buffer * const ldap_filter = &p->ldap_filter; buffer_clear(ldap_filter); @@ -701,7 +701,7 @@ static handler_t mod_authn_ldap_basic(server *srv, connection *con, void *p_d, c } /* ldap_search for DN (synchronous; blocking) */ - dn = mod_authn_ldap_get_dn(srv, p->conf.ldc, + dn = mod_authn_ldap_get_dn(errh, p->conf.ldc, p->conf.auth_ldap_basedn, ldap_filter->ptr); if (NULL == dn) return HANDLER_ERROR; } @@ -719,7 +719,7 @@ static handler_t mod_authn_ldap_basic(server *srv, connection *con, void *p_d, c || p->conf.ldc->auth_ldap_bindpw != p->conf.auth_ldap_bindpw || p->conf.ldc->auth_ldap_cafile != p->conf.auth_ldap_cafile ) { ldc_custom.ldap = NULL; - ldc_custom.srv = srv; + ldc_custom.errh = errh; ldc_custom.auth_ldap_hostname = ldc_base->auth_ldap_hostname; ldc_custom.auth_ldap_starttls = p->conf.auth_ldap_starttls; ldc_custom.auth_ldap_binddn = p->conf.auth_ldap_binddn; @@ -732,18 +732,18 @@ static handler_t mod_authn_ldap_basic(server *srv, connection *con, void *p_d, c do { /* auth against LDAP server (synchronous; blocking) */ - ld = mod_authn_ldap_host_init(srv, p->conf.ldc); + ld = mod_authn_ldap_host_init(errh, p->conf.ldc); if (NULL == ld) break; /* Disable referral tracking; target user should be in provided scope */ int ret = ldap_set_option(ld, LDAP_OPT_REFERRALS, LDAP_OPT_OFF); if (LDAP_OPT_SUCCESS != ret) { - mod_authn_ldap_err(srv,__FILE__,__LINE__,"ldap_set_option()",ret); + mod_authn_ldap_err(errh,__FILE__,__LINE__,"ldap_set_option()",ret); break; } - if (LDAP_SUCCESS != mod_authn_ldap_bind(srv, ld, dn, pw)) + if (LDAP_SUCCESS != mod_authn_ldap_bind(errh, ld, dn, pw)) break; ldap_unbind_ext_s(ld, NULL, NULL); /* disconnect */ @@ -754,7 +754,7 @@ static handler_t mod_authn_ldap_basic(server *srv, connection *con, void *p_d, c } else if (require->group.used) { /*(must not re-use ldap_filter, since it might be used for dn)*/ - rc = mod_authn_ldap_memberOf(srv,&p->conf,require,username,dn); + rc = mod_authn_ldap_memberOf(errh,&p->conf,require,username,dn); } } while (0); diff --git a/src/mod_authn_mysql.c b/src/mod_authn_mysql.c index 14e53bc3..0f1e5d75 100644 --- a/src/mod_authn_mysql.c +++ b/src/mod_authn_mysql.c @@ -26,7 +26,6 @@ #include "md5.h" #include "plugin.h" -#include #include #include #include @@ -49,6 +48,7 @@ typedef struct { const char *auth_mysql_col_user; const char *auth_mysql_col_pass; const char *auth_mysql_col_realm; + log_error_st *errh; } plugin_config; typedef struct { @@ -72,7 +72,7 @@ static void mod_authn_mysql_sock_close(void *p_d) { } } -static MYSQL * mod_authn_mysql_sock_connect(server *srv, plugin_data *p) { +static MYSQL * mod_authn_mysql_sock_connect(plugin_data *p) { plugin_config * const pconf = &p->conf; if (NULL != p->mysql_conn) { /* reuse open db connection if same ptrs to host user pass db port */ @@ -108,27 +108,24 @@ static MYSQL * mod_authn_mysql_sock_connect(server *srv, plugin_data *p) { } else { /*(note: any of these params might be NULL)*/ - log_error_write(srv, __FILE__, __LINE__, "ssss"/*ss*/"ssss", - "opening connection to mysql:", - pconf->auth_mysql_host ? pconf->auth_mysql_host : NULL, - "user:", - pconf->auth_mysql_user ? pconf->auth_mysql_user : NULL, + log_error(pconf->errh, __FILE__, __LINE__, + "opening connection to mysql: %s user: %s db: %s failed: %s", + pconf->auth_mysql_host ? pconf->auth_mysql_host : "", + pconf->auth_mysql_user ? pconf->auth_mysql_user : "", /*"pass:",*//*(omit pass from logs)*/ - /*pconf->auth_mysql_pass ? pconf->auth_mysql_pass : NULL,*/ - "db:", - pconf->auth_mysql_db ? pconf->auth_mysql_db : NULL, - "failed:", mysql_error(p->mysql_conn)); + /*p->conf.auth_mysql_pass ? p->conf.auth_mysql_pass : "",*/ + pconf->auth_mysql_db ? pconf->auth_mysql_db : "", + mysql_error(p->mysql_conn)); mod_authn_mysql_sock_close(p); return NULL; } } -static MYSQL * mod_authn_mysql_sock_acquire(server *srv, plugin_data *p) { - return mod_authn_mysql_sock_connect(srv, p); +static MYSQL * mod_authn_mysql_sock_acquire(plugin_data *p) { + return mod_authn_mysql_sock_connect(p); } -static void mod_authn_mysql_sock_release(server *srv, plugin_data *p) { - UNUSED(srv); +static void mod_authn_mysql_sock_release(plugin_data *p) { UNUSED(p); /*(empty; leave db connection open)*/ /* Note: mod_authn_mysql_result() calls mod_authn_mysql_sock_error() @@ -136,13 +133,13 @@ static void mod_authn_mysql_sock_release(server *srv, plugin_data *p) { * Must check if (NULL == p->mysql_conn) */ } -static void mod_authn_mysql_sock_error(server *srv, plugin_data *p) { - UNUSED(srv); +__attribute_cold__ +static void mod_authn_mysql_sock_error(plugin_data *p) { mod_authn_mysql_sock_close(p); } -static handler_t mod_authn_mysql_basic(server *srv, connection *con, void *p_d, const http_auth_require_t *require, const buffer *username, const char *pw); -static handler_t mod_authn_mysql_digest(server *srv, connection *con, void *p_d, http_auth_info_t *dig); +static handler_t mod_authn_mysql_basic(connection *con, void *p_d, const http_auth_require_t *require, const buffer *username, const char *pw); +static handler_t mod_authn_mysql_digest(connection *con, void *p_d, http_auth_info_t *dig); INIT_FUNC(mod_authn_mysql_init) { static http_auth_backend_t http_auth_backend_mysql = @@ -281,6 +278,7 @@ SETDEFAULTS_FUNC(mod_authn_mysql_set_defaults) { p->defaults.auth_mysql_col_user = "user"; p->defaults.auth_mysql_col_pass = "password"; p->defaults.auth_mysql_col_realm = "realm"; + p->defaults.errh = srv->errh; /* initialize p->defaults from global config context */ if (p->nconfig > 0 && p->cvlist->v.u2[1]) { @@ -347,7 +345,7 @@ static int mod_authn_mysql_password_cmp(const char *userpw, unsigned long userpw return -1; } -static int mod_authn_mysql_result(server *srv, plugin_data *p, http_auth_info_t *ai, const char *pw) { +static int mod_authn_mysql_result(plugin_data *p, http_auth_info_t *ai, const char *pw) { MYSQL_RES *result = mysql_store_result(p->mysql_conn); int rc = -1; my_ulonglong num_rows; @@ -355,10 +353,10 @@ static int mod_authn_mysql_result(server *srv, plugin_data *p, http_auth_info_t if (NULL == result) { /*(future: might log mysql_error() string)*/ #if 0 - log_error_write(srv, __FILE__, __LINE__, "ss", "mysql_store_result:", - mysql_error(p->mysql_conn)); + log_error(errh, __FILE__, __LINE__, + "mysql_store_result: %s", mysql_error(p->mysql_conn)); #endif - mod_authn_mysql_sock_error(srv, p); + mod_authn_mysql_sock_error(p); return -1; } @@ -391,17 +389,18 @@ static int mod_authn_mysql_result(server *srv, plugin_data *p, http_auth_info_t return rc; } -static handler_t mod_authn_mysql_query(server *srv, connection *con, void *p_d, http_auth_info_t *ai, const char *pw) { +static handler_t mod_authn_mysql_query(connection *con, void *p_d, http_auth_info_t *ai, const char *pw) { plugin_data *p = (plugin_data *)p_d; int rc = -1; mod_authn_mysql_patch_config(con, p); + p->conf.errh = con->conf.errh; if (NULL == p->conf.auth_mysql_users_table) { /*(auth.backend.mysql.host, auth.backend.mysql.db might be NULL; do not log)*/ - log_error_write(srv, __FILE__, __LINE__, "sb", - "auth config missing auth.backend.mysql.users_table for uri:", - con->request.uri); + log_error(con->conf.errh, __FILE__, __LINE__, + "auth config missing auth.backend.mysql.users_table for uri: %s", + con->request.uri->ptr); return HANDLER_ERROR; } @@ -414,7 +413,7 @@ static handler_t mod_authn_mysql_query(server *srv, connection *con, void *p_d, if (ai->rlen > sizeof(urealm)/2-1) return HANDLER_ERROR; - if (!mod_authn_mysql_sock_acquire(srv, p)) { + if (!mod_authn_mysql_sock_acquire(p)) { return HANDLER_ERROR; } @@ -453,39 +452,36 @@ static handler_t mod_authn_mysql_query(server *srv, connection *con, void *p_d, /* for now we stay synchronous */ if (0 != mysql_query(p->mysql_conn, q)) { /* reconnect to db and retry once if query error occurs */ - mod_authn_mysql_sock_error(srv, p); - if (!mod_authn_mysql_sock_acquire(srv, p)) { + mod_authn_mysql_sock_error(p); + if (!mod_authn_mysql_sock_acquire(p)) { rc = -1; break; } if (0 != mysql_query(p->mysql_conn, q)) { /*(note: any of these params might be bufs w/ b->ptr == NULL)*/ - log_error_write(srv, __FILE__, __LINE__, "ssss"/*ss*/"ssssss", - "mysql_query host:", - p->conf.auth_mysql_host ? p->conf.auth_mysql_host : NULL, - "user:", - p->conf.auth_mysql_user ? p->conf.auth_mysql_user : NULL, + log_error(con->conf.errh, __FILE__, __LINE__, + "mysql_query host: %s user: %s db: %s query: %s failed: %s", + p->conf.auth_mysql_host ? p->conf.auth_mysql_host : "", + p->conf.auth_mysql_user ? p->conf.auth_mysql_user : "", /*"pass:",*//*(omit pass from logs)*/ - /*p->conf.auth_mysql_pass ? p->conf.auth_mysql_pass : NULL,*/ - "db:", - p->conf.auth_mysql_db ? p->conf.auth_mysql_db : NULL, - "query:", q, - "failed:", mysql_error(p->mysql_conn)); + /*p->conf.auth_mysql_pass ? p->conf.auth_mysql_pass : "",*/ + p->conf.auth_mysql_db ? p->conf.auth_mysql_db : "", + q, mysql_error(p->mysql_conn)); rc = -1; break; } } - rc = mod_authn_mysql_result(srv, p, ai, pw); + rc = mod_authn_mysql_result(p, ai, pw); } while (0); - mod_authn_mysql_sock_release(srv, p); + mod_authn_mysql_sock_release(p); return (0 == rc) ? HANDLER_GO_ON : HANDLER_ERROR; } -static handler_t mod_authn_mysql_basic(server *srv, connection *con, void *p_d, const http_auth_require_t *require, const buffer *username, const char *pw) { +static handler_t mod_authn_mysql_basic(connection *con, void *p_d, const http_auth_require_t *require, const buffer *username, const char *pw) { handler_t rc; http_auth_info_t ai; ai.dalgo = HTTP_AUTH_DIGEST_NONE; @@ -494,15 +490,15 @@ static handler_t mod_authn_mysql_basic(server *srv, connection *con, void *p_d, ai.ulen = buffer_string_length(username); ai.realm = require->realm->ptr; ai.rlen = buffer_string_length(require->realm); - rc = mod_authn_mysql_query(srv, con, p_d, &ai, pw); + rc = mod_authn_mysql_query(con, p_d, &ai, pw); if (HANDLER_GO_ON != rc) return rc; return http_auth_match_rules(require, username->ptr, NULL, NULL) ? HANDLER_GO_ON /* access granted */ : HANDLER_ERROR; } -static handler_t mod_authn_mysql_digest(server *srv, connection *con, void *p_d, http_auth_info_t *ai) { - return mod_authn_mysql_query(srv, con, p_d, ai, NULL); +static handler_t mod_authn_mysql_digest(connection *con, void *p_d, http_auth_info_t *ai) { + return mod_authn_mysql_query(con, p_d, ai, NULL); } int mod_authn_mysql_plugin_init(plugin *p); diff --git a/src/mod_authn_pam.c b/src/mod_authn_pam.c index 6ffb725b..618baaca 100644 --- a/src/mod_authn_pam.c +++ b/src/mod_authn_pam.c @@ -31,7 +31,7 @@ typedef struct { plugin_config conf; } plugin_data; -static handler_t mod_authn_pam_basic(server *srv, connection *con, void *p_d, const http_auth_require_t *require, const buffer *username, const char *pw); +static handler_t mod_authn_pam_basic(connection *con, void *p_d, const http_auth_require_t *require, const buffer *username, const char *pw); INIT_FUNC(mod_authn_pam_init) { static http_auth_backend_t http_auth_backend_pam = @@ -131,7 +131,7 @@ static int mod_authn_pam_fn_conv(int num_msg, const struct pam_message **msg, st return PAM_SUCCESS; } -static handler_t mod_authn_pam_query(server *srv, connection *con, void *p_d, const buffer *username, const char *realm, const char *pw) { +static handler_t mod_authn_pam_query(connection *con, void *p_d, const buffer *username, const char *realm, const char *pw) { plugin_data *p = (plugin_data *)p_d; pam_handle_t *pamh = NULL; struct pam_conv conv = { mod_authn_pam_fn_conv, NULL }; @@ -147,15 +147,15 @@ static handler_t mod_authn_pam_query(server *srv, connection *con, void *p_d, co || PAM_SUCCESS !=(rc = pam_set_item(pamh,PAM_RHOST,con->dst_addr_buf->ptr)) || PAM_SUCCESS !=(rc = pam_authenticate(pamh, flags)) || PAM_SUCCESS !=(rc = pam_acct_mgmt(pamh, flags))) - log_error_write(srv, __FILE__, __LINE__, "ss", - "pam:", pam_strerror(pamh, rc)); + log_error(con->conf.errh, __FILE__, __LINE__, + "pam: %s", pam_strerror(pamh, rc)); pam_end(pamh, rc); return (PAM_SUCCESS == rc) ? HANDLER_GO_ON : HANDLER_ERROR; } -static handler_t mod_authn_pam_basic(server *srv, connection *con, void *p_d, const http_auth_require_t *require, const buffer *username, const char *pw) { +static handler_t mod_authn_pam_basic(connection *con, void *p_d, const http_auth_require_t *require, const buffer *username, const char *pw) { char *realm = require->realm->ptr; - handler_t rc = mod_authn_pam_query(srv, con, p_d, username, realm, pw); + handler_t rc = mod_authn_pam_query(con, p_d, username, realm, pw); if (HANDLER_GO_ON != rc) return rc; return http_auth_match_rules(require, username->ptr, NULL, NULL) ? HANDLER_GO_ON /* access granted */ diff --git a/src/mod_authn_sasl.c b/src/mod_authn_sasl.c index 4ced62c7..f763cc55 100644 --- a/src/mod_authn_sasl.c +++ b/src/mod_authn_sasl.c @@ -37,7 +37,7 @@ typedef struct { int initonce; } plugin_data; -static handler_t mod_authn_sasl_basic(server *srv, connection *con, void *p_d, const http_auth_require_t *require, const buffer *username, const char *pw); +static handler_t mod_authn_sasl_basic(connection *con, void *p_d, const http_auth_require_t *require, const buffer *username, const char *pw); INIT_FUNC(mod_authn_sasl_init) { static http_auth_backend_t http_auth_backend_sasl = @@ -230,7 +230,7 @@ static int mod_authn_sasl_cb_getopt(void *p_d, const char *plugin_name, const ch return SASL_OK; } -static int mod_authn_sasl_cb_log(void *vsrv, int level, const char *message) { +static int mod_authn_sasl_cb_log(void *vcon, int level, const char *message) { switch (level) { #if 0 case SASL_LOG_NONE: @@ -244,18 +244,19 @@ static int mod_authn_sasl_cb_log(void *vsrv, int level, const char *message) { case SASL_LOG_ERR: case SASL_LOG_FAIL: case SASL_LOG_WARN: /* (might omit SASL_LOG_WARN if too noisy in logs) */ - log_error_write((server *)vsrv, __FILE__, __LINE__, "s", message); + log_error(((connection *)vcon)->conf.errh, __FILE__, __LINE__, + "%s", message); break; } return SASL_OK; } -static handler_t mod_authn_sasl_query(server *srv, connection *con, void *p_d, const buffer *username, const char *realm, const char *pw) { +static handler_t mod_authn_sasl_query(connection *con, void *p_d, const buffer *username, const char *realm, const char *pw) { plugin_data *p = (plugin_data *)p_d; sasl_conn_t *sc; sasl_callback_t const cb[] = { { SASL_CB_GETOPT, (int(*)())mod_authn_sasl_cb_getopt, (void *) p }, - { SASL_CB_LOG, (int(*)())mod_authn_sasl_cb_log, (void *) srv }, + { SASL_CB_LOG, (int(*)())mod_authn_sasl_cb_log, (void *) con }, { SASL_CB_LIST_END, NULL, NULL } }; int rc; @@ -279,9 +280,9 @@ static handler_t mod_authn_sasl_query(server *srv, connection *con, void *p_d, c return (SASL_OK == rc) ? HANDLER_GO_ON : HANDLER_ERROR; } -static handler_t mod_authn_sasl_basic(server *srv, connection *con, void *p_d, const http_auth_require_t *require, const buffer *username, const char *pw) { +static handler_t mod_authn_sasl_basic(connection *con, void *p_d, const http_auth_require_t *require, const buffer *username, const char *pw) { char *realm = require->realm->ptr; - handler_t rc = mod_authn_sasl_query(srv, con, p_d, username, realm, pw); + handler_t rc = mod_authn_sasl_query(con, p_d, username, realm, pw); if (HANDLER_GO_ON != rc) return rc; return http_auth_match_rules(require, username->ptr, NULL, NULL) ? HANDLER_GO_ON /* access granted */ diff --git a/src/mod_cgi.c b/src/mod_cgi.c index 2474e740..3ab4c6df 100644 --- a/src/mod_cgi.c +++ b/src/mod_cgi.c @@ -349,7 +349,7 @@ static void cgi_connection_close(server *srv, handler_ctx *hctx) { /* finish response (if not already con->file_started, con->file_finished) */ if (con->mode == p->id) { - http_response_backend_done(srv, con); + http_response_backend_done(con); } } @@ -394,7 +394,7 @@ static handler_t cgi_handle_fdevent_send (server *srv, void *ctx, int revents) { } else if (revents & FDEVENT_ERR) { /* kill all connections to the cgi process */ #if 1 - log_error_write(srv, __FILE__, __LINE__, "s", "cgi-FDEVENT_ERR"); + log_error(con->conf.errh, __FILE__, __LINE__, "cgi-FDEVENT_ERR"); #endif cgi_connection_close(srv, hctx); return HANDLER_ERROR; @@ -404,14 +404,14 @@ static handler_t cgi_handle_fdevent_send (server *srv, void *ctx, int revents) { } -static handler_t cgi_response_headers(server *srv, connection *con, struct http_response_opts_t *opts) { +static handler_t cgi_response_headers(connection *con, struct http_response_opts_t *opts) { /* response headers just completed */ handler_ctx *hctx = (handler_ctx *)opts->pdata; if (con->response.htags & HTTP_HEADER_UPGRADE) { if (hctx->conf.upgrade && con->http_status == 101) { /* 101 Switching Protocols; transition to transparent proxy */ - http_response_upgrade_read_body_unknown(srv, con); + http_response_upgrade_read_body_unknown(con); } else { con->response.htags &= ~HTTP_HEADER_UPGRADE; @@ -429,7 +429,7 @@ static handler_t cgi_response_headers(server *srv, connection *con, struct http_ chunkqueue *cq = con->request_content_queue; hctx->conf.upgrade = 0; if (cq->bytes_out == (off_t)con->request.content_length) { - cgi_connection_close_fdtocgi(srv, hctx); /*(closes hctx->fdtocgi)*/ + cgi_connection_close_fdtocgi(con->srv, hctx); /*(closes hctx->fdtocgi)*/ } } @@ -438,12 +438,12 @@ static handler_t cgi_response_headers(server *srv, connection *con, struct http_ static int cgi_recv_response(server *srv, handler_ctx *hctx) { - switch (http_response_read(srv, hctx->remote_conn, &hctx->opts, + switch (http_response_read(hctx->remote_conn, &hctx->opts, hctx->response, hctx->fdn)) { default: return HANDLER_GO_ON; case HANDLER_ERROR: - http_response_backend_error(srv, hctx->remote_conn); + http_response_backend_error(hctx->remote_conn); /* fall through */ case HANDLER_FINISHED: cgi_connection_close(srv, hctx); @@ -490,7 +490,7 @@ static handler_t cgi_handle_fdevent(server *srv, void *ctx, int revents) { } else if (!buffer_string_is_empty(hctx->response)) { /* unfinished header package which is a body in reality */ con->file_started = 1; - if (0 != http_chunk_append_buffer(srv, con, hctx->response)) { + if (0 != http_chunk_append_buffer(con, hctx->response)) { cgi_connection_close(srv, hctx); return HANDLER_ERROR; } @@ -555,7 +555,7 @@ static off_t mmap_align_offset(off_t start) { * * Also always use mmap; the files are "trusted", as we created them. */ -static ssize_t cgi_write_file_chunk_mmap(server *srv, connection *con, int fd, chunkqueue *cq) { +static ssize_t cgi_write_file_chunk_mmap(connection *con, int fd, chunkqueue *cq) { chunk* const c = cq->first; off_t offset, toSend, file_end; ssize_t r; @@ -579,7 +579,7 @@ static ssize_t cgi_write_file_chunk_mmap(server *srv, connection *con, int fd, c UNUSED(con); if (-1 == c->file.fd) { if (-1 == (c->file.fd = fdevent_open_cloexec(c->mem->ptr, con->conf.follow_symlink, O_RDONLY, 0))) { - log_error_write(srv, __FILE__, __LINE__, "ssb", "open failed:", strerror(errno), c->mem); + log_perror(con->conf.errh, __FILE__, __LINE__, "open failed: %s", c->mem->ptr); return -1; } } @@ -604,11 +604,13 @@ static ssize_t cgi_write_file_chunk_mmap(server *srv, connection *con, int fd, c if (-1 == lseek(c->file.fd, offset, SEEK_SET) || 0 >= (toSend = read(c->file.fd, data, toSend))) { if (-1 == toSend) { - log_error_write(srv, __FILE__, __LINE__, "ssbdo", "lseek/read failed:", - strerror(errno), c->mem, c->file.fd, offset); + log_perror(con->conf.errh, __FILE__, __LINE__, + "lseek/read %s %d %lld failed:", + c->mem->ptr, c->file.fd, (long long)offset); } else { /*(0 == toSend)*/ - log_error_write(srv, __FILE__, __LINE__, "sbdo", "unexpected EOF (input truncated?):", - c->mem, c->file.fd, offset); + log_error(con->conf.errh, __FILE__, __LINE__, + "unexpected EOF (input truncated?): %s %d %lld", + c->mem->ptr, c->file.fd, (long long)offset); } free(data); return -1; @@ -639,8 +641,8 @@ static ssize_t cgi_write_file_chunk_mmap(server *srv, connection *con, int fd, c case ECONNRESET: return -2; default: - log_error_write(srv, __FILE__, __LINE__, "ssd", - "write failed:", strerror(errno), fd); + log_perror(con->conf.errh, __FILE__, __LINE__, + "write %d failed", fd); return -1; } } @@ -664,7 +666,7 @@ static int cgi_write_request(server *srv, handler_ctx *hctx, int fd) { switch(c->type) { case FILE_CHUNK: - r = cgi_write_file_chunk_mmap(srv, con, fd, cq); + r = cgi_write_file_chunk_mmap(con, fd, cq); break; case MEM_CHUNK: @@ -682,7 +684,7 @@ static int cgi_write_request(server *srv, handler_ctx *hctx, int fd) { break; default: /* fatal error */ - log_error_write(srv, __FILE__, __LINE__, "ss", "write failed due to: ", strerror(errno)); + log_perror(con->conf.errh, __FILE__, __LINE__, "write() failed"); r = -1; break; } @@ -700,7 +702,8 @@ static int cgi_write_request(server *srv, handler_ctx *hctx, int fd) { return -1; case -2: /* connection reset */ - log_error_write(srv, __FILE__, __LINE__, "s", "failed to send post data to cgi, connection closed by CGI"); + log_error(con->conf.errh, __FILE__, __LINE__, + "failed to send post data to cgi, connection closed by CGI"); /* skip all remaining data */ chunkqueue_mark_written(cq, chunkqueue_length(cq)); break; @@ -715,7 +718,7 @@ static int cgi_write_request(server *srv, handler_ctx *hctx, int fd) { if (-1 == hctx->fdtocgi) { /*(received request body sent in initial send to pipe buffer)*/ --srv->cur_fds; if (close(fd)) { - log_error_write(srv, __FILE__, __LINE__, "sds", "cgi stdin close failed ", fd, strerror(errno)); + log_perror(con->conf.errh, __FILE__, __LINE__, "cgi stdin close %d failed", fd); } } else { cgi_connection_close_fdtocgi(srv, hctx); /*(closes only hctx->fdtocgi)*/ @@ -763,21 +766,20 @@ static int cgi_create_env(server *srv, connection *con, plugin_data *p, handler_ if (!buffer_string_is_empty(cgi_handler)) { if (NULL == cgi_stat(srv, con, cgi_handler)) { - log_error_write(srv, __FILE__, __LINE__, "sbss", - "stat for cgi-handler", cgi_handler, - "failed:", strerror(errno)); + log_perror(con->conf.errh, __FILE__, __LINE__, + "stat for cgi-handler %s", cgi_handler->ptr); return -1; } } if (pipe_cloexec(to_cgi_fds)) { - log_error_write(srv, __FILE__, __LINE__, "ss", "pipe failed:", strerror(errno)); + log_perror(con->conf.errh, __FILE__, __LINE__, "pipe failed"); return -1; } if (pipe_cloexec(from_cgi_fds)) { close(to_cgi_fds[0]); close(to_cgi_fds[1]); - log_error_write(srv, __FILE__, __LINE__, "ss", "pipe failed:", strerror(errno)); + log_perror(con->conf.errh, __FILE__, __LINE__, "pipe failed"); return -1; } fdevent_setfd_cloexec(to_cgi_fds[1]); @@ -792,7 +794,7 @@ static int cgi_create_env(server *srv, connection *con, plugin_data *p, handler_ /* create environment */ - http_cgi_headers(srv, con, &opts, cgi_env_add, env); + http_cgi_headers(con, &opts, cgi_env_add, env); /* for valgrind */ if (p->env.ld_preload) { @@ -830,14 +832,14 @@ static int cgi_create_env(server *srv, connection *con, plugin_data *p, handler_ dfd = fdevent_open_dirname(con->physical.path->ptr, con->conf.follow_symlink); if (-1 == dfd) { - log_error_write(srv, __FILE__, __LINE__, "ssb", "open dirname failed:", strerror(errno), con->physical.path); + log_perror(con->conf.errh, __FILE__, __LINE__, "open dirname %s failed", con->physical.path->ptr); } hctx->pid = (dfd >= 0) ? fdevent_fork_execve(args[0], args, p->env.eptr, to_cgi_fds[0], from_cgi_fds[1], -1, dfd) : -1; if (-1 == hctx->pid) { /* log error with errno prior to calling close() (might change errno) */ - log_error_write(srv, __FILE__, __LINE__, "ss", "fork failed:", strerror(errno)); + log_perror(con->conf.errh, __FILE__, __LINE__, "fork failed"); if (-1 != dfd) close(dfd); close(from_cgi_fds[0]); close(from_cgi_fds[1]); @@ -860,7 +862,7 @@ static int cgi_create_env(server *srv, connection *con, plugin_data *p, handler_ } else { /* there is content to send */ if (-1 == fdevent_fcntl_set_nb(srv->ev, to_cgi_fds[1])) { - log_error_write(srv, __FILE__, __LINE__, "ss", "fcntl failed: ", strerror(errno)); + log_perror(con->conf.errh, __FILE__, __LINE__, "fcntl failed"); close(to_cgi_fds[1]); cgi_connection_close(srv, hctx); return -1; @@ -877,7 +879,7 @@ static int cgi_create_env(server *srv, connection *con, plugin_data *p, handler_ hctx->fdn = fdevent_register(srv->ev, hctx->fd, cgi_handle_fdevent, hctx); if (-1 == fdevent_fcntl_set_nb(srv->ev, hctx->fd)) { - log_error_write(srv, __FILE__, __LINE__, "ss", "fcntl failed: ", strerror(errno)); + log_perror(con->conf.errh, __FILE__, __LINE__, "fcntl failed"); cgi_connection_close(srv, hctx); return -1; } @@ -978,7 +980,7 @@ SUBREQUEST_FUNC(mod_cgi_handle_subrequest) { * (occurs here if client sends Transfer-Encoding: chunked * and module is flagged to stream request body to backend) */ if (-1 == con->request.content_length) { - return connection_handle_read_post_error(srv, con, 411); + return connection_handle_read_post_error(con, 411); } } } @@ -1018,13 +1020,19 @@ static handler_t cgi_waitpid_cb(server *srv, void *p_d, pid_t pid, int status) { else if (WIFSIGNALED(status)) { /* ignore SIGTERM if sent by cgi_connection_close() (NULL == hctx)*/ if (WTERMSIG(status) != SIGTERM || NULL != hctx) { - log_error_write(srv, __FILE__, __LINE__, "sdsd", "CGI pid", pid, - "died with signal", WTERMSIG(status)); + log_error_st *errh = hctx + ? hctx->remote_conn->conf.errh + : srv->errh; + log_error(errh, __FILE__, __LINE__, + "CGI pid %d died with signal %d", pid, WTERMSIG(status)); } } else { - log_error_write(srv, __FILE__, __LINE__, "sds", - "CGI pid", pid, "ended unexpectedly"); + log_error_st *errh = hctx + ? hctx->remote_conn->conf.errh + : srv->errh; + log_error(errh, __FILE__, __LINE__, + "CGI pid %d ended unexpectedly", pid); } return HANDLER_FINISHED; diff --git a/src/mod_cml.c b/src/mod_cml.c index 314c4036..37438ff0 100644 --- a/src/mod_cml.c +++ b/src/mod_cml.c @@ -12,7 +12,6 @@ #include #include -#include INIT_FUNC(mod_cml_init) { return calloc(1, sizeof(plugin_data)); @@ -178,7 +177,7 @@ SETDEFAULTS_FUNC(mod_cml_set_defaults) { return HANDLER_GO_ON; } -static int cache_call_lua(server *srv, connection *con, plugin_data *p, const buffer *cml_file) { +static int cache_call_lua(connection *con, plugin_data *p, const buffer *cml_file) { buffer *b; char *c; @@ -204,11 +203,12 @@ static int cache_call_lua(server *srv, connection *con, plugin_data *p, const bu * - cookie-based * - get-param-based */ - return cache_parse_lua(srv, con, p, cml_file); + return cache_parse_lua(con, p, cml_file); } URIHANDLER_FUNC(mod_cml_power_magnet) { plugin_data *p = p_d; + UNUSED(srv); mod_cml_patch_config(con, p); @@ -235,17 +235,17 @@ URIHANDLER_FUNC(mod_cml_power_magnet) { * * */ - switch(cache_call_lua(srv, con, p, p->conf.power_magnet)) { + switch(cache_call_lua(con, p, p->conf.power_magnet)) { case -1: /* error */ if (con->conf.log_request_handling) { - log_error_write(srv, __FILE__, __LINE__, "s", "cache-error"); + log_error(con->conf.errh, __FILE__, __LINE__, "cache-error"); } con->http_status = 500; return HANDLER_COMEBACK; case 0: if (con->conf.log_request_handling) { - log_error_write(srv, __FILE__, __LINE__, "s", "cache-hit"); + log_error(con->conf.errh, __FILE__, __LINE__, "cache-hit"); } /* cache-hit */ buffer_reset(con->physical.path); @@ -261,6 +261,7 @@ URIHANDLER_FUNC(mod_cml_power_magnet) { URIHANDLER_FUNC(mod_cml_is_handled) { plugin_data *p = p_d; + UNUSED(srv); if (buffer_string_is_empty(con->physical.path)) return HANDLER_ERROR; @@ -276,24 +277,24 @@ URIHANDLER_FUNC(mod_cml_is_handled) { buffer_clear(&p->baseurl); buffer_clear(&p->trigger_handler); - switch(cache_call_lua(srv, con, p, con->physical.path)) { + switch(cache_call_lua(con, p, con->physical.path)) { case -1: /* error */ if (con->conf.log_request_handling) { - log_error_write(srv, __FILE__, __LINE__, "s", "cache-error"); + log_error(con->conf.errh, __FILE__, __LINE__, "cache-error"); } con->http_status = 500; return HANDLER_COMEBACK; case 0: if (con->conf.log_request_handling) { - log_error_write(srv, __FILE__, __LINE__, "s", "cache-hit"); + log_error(con->conf.errh, __FILE__, __LINE__, "cache-hit"); } /* cache-hit */ buffer_reset(con->physical.path); return HANDLER_FINISHED; case 1: if (con->conf.log_request_handling) { - log_error_write(srv, __FILE__, __LINE__, "s", "cache-miss"); + log_error(con->conf.errh, __FILE__, __LINE__, "cache-miss"); } /* cache miss */ return HANDLER_COMEBACK; diff --git a/src/mod_cml.h b/src/mod_cml.h index a2a4f0be..0f5eb138 100644 --- a/src/mod_cml.h +++ b/src/mod_cml.h @@ -32,6 +32,6 @@ typedef struct { buffer trigger_handler; } plugin_data; -int cache_parse_lua(server *srv, connection *con, plugin_data *p, const buffer *fn); +int cache_parse_lua(connection *con, plugin_data *p, const buffer *fn); #endif diff --git a/src/mod_cml_lua.c b/src/mod_cml_lua.c index 41ea2842..4f3fc5b2 100644 --- a/src/mod_cml_lua.c +++ b/src/mod_cml_lua.c @@ -101,7 +101,7 @@ static int cache_export_get_params(lua_State *L, int tbl, buffer *qrystr) { return 0; } -int cache_parse_lua(server *srv, connection *con, plugin_data *p, const buffer *fn) { +int cache_parse_lua(connection *con, plugin_data *p, const buffer *fn) { lua_State *L; int ret = -1; buffer *b; @@ -165,20 +165,16 @@ int cache_parse_lua(server *srv, connection *con, plugin_data *p, const buffer * /* load lua program */ ret = luaL_loadfile(L, fn->ptr); if (0 != ret) { - log_error_write(srv, __FILE__, __LINE__, "sbsS", - "failed loading cml_lua script", - fn, - ":", - lua_tostring(L, -1)); + log_error(con->conf.errh, __FILE__, __LINE__, + "failed loading cml_lua script %s: %s", + fn->ptr, lua_tostring(L, -1)); goto error; } if (lua_pcall(L, 0, 1, 0)) { - log_error_write(srv, __FILE__, __LINE__, "sbsS", - "failed running cml_lua script", - fn, - ":", - lua_tostring(L, -1)); + log_error(con->conf.errh, __FILE__, __LINE__, + "failed running cml_lua script %s: %s", + fn->ptr, lua_tostring(L, -1)); goto error; } @@ -200,8 +196,8 @@ int cache_parse_lua(server *srv, connection *con, plugin_data *p, const buffer * time_t mtime = 0; if (!lua_to_c_is_table(L, "output_include")) { - log_error_write(srv, __FILE__, __LINE__, "s", - "output_include is missing or not a table"); + log_error(con->conf.errh, __FILE__, __LINE__, + "output_include is missing or not a table"); ret = -1; goto error; @@ -246,16 +242,16 @@ int cache_parse_lua(server *srv, connection *con, plugin_data *p, const buffer * if (!buffer_string_is_empty(&p->trigger_handler)) { ret = 1; /* cache-miss */ - log_error_write(srv, __FILE__, __LINE__, "s", - "a file is missing, calling handler"); + log_error(con->conf.errh, __FILE__, __LINE__, + "a file is missing, calling handler"); break; } else { /* handler not set -> 500 */ ret = -1; - log_error_write(srv, __FILE__, __LINE__, "s", - "a file missing and no handler set"); + log_error(con->conf.errh, __FILE__, __LINE__, + "a file missing and no handler set"); break; } @@ -270,8 +266,7 @@ int cache_parse_lua(server *srv, connection *con, plugin_data *p, const buffer * } else { /* not a string */ ret = -1; - log_error_write(srv, __FILE__, __LINE__, "s", - "not a string"); + log_error(con->conf.errh, __FILE__, __LINE__, "not a string"); break; } @@ -293,7 +288,7 @@ int cache_parse_lua(server *srv, connection *con, plugin_data *p, const buffer * con->file_finished = 1; - if (HANDLER_FINISHED == http_response_handle_cachable(srv, con, vb)) { + if (HANDLER_FINISHED == http_response_handle_cachable(con, vb)) { /* ok, the client already has our content, * no need to send it again */ diff --git a/src/mod_compress.c b/src/mod_compress.c index a932667e..215e0ff7 100644 --- a/src/mod_compress.c +++ b/src/mod_compress.c @@ -310,15 +310,12 @@ SETDEFAULTS_FUNC(mod_compress_set_defaults) { #ifdef USE_ZLIB -static int deflate_file_to_buffer_gzip(server *srv, connection *con, plugin_data *p, char *start, off_t st_size, time_t mtime) { +static int deflate_file_to_buffer_gzip(plugin_data *p, char *start, off_t st_size, time_t mtime) { unsigned char *c; unsigned long crc; z_stream z; size_t outlen; - UNUSED(srv); - UNUSED(con); - z.zalloc = Z_NULL; z.zfree = Z_NULL; z.opaque = Z_NULL; @@ -388,12 +385,9 @@ static int deflate_file_to_buffer_gzip(server *srv, connection *con, plugin_data return 0; } -static int deflate_file_to_buffer_deflate(server *srv, connection *con, plugin_data *p, unsigned char *start, off_t st_size) { +static int deflate_file_to_buffer_deflate(plugin_data *p, unsigned char *start, off_t st_size) { z_stream z; - UNUSED(srv); - UNUSED(con); - z.zalloc = Z_NULL; z.zfree = Z_NULL; z.opaque = Z_NULL; @@ -435,12 +429,9 @@ static int deflate_file_to_buffer_deflate(server *srv, connection *con, plugin_d #endif #ifdef USE_BZ2LIB -static int deflate_file_to_buffer_bzip2(server *srv, connection *con, plugin_data *p, unsigned char *start, off_t st_size) { +static int deflate_file_to_buffer_bzip2(plugin_data *p, unsigned char *start, off_t st_size) { bz_stream bz; - UNUSED(srv); - UNUSED(con); - bz.bzalloc = NULL; bz.bzfree = NULL; bz.opaque = NULL; @@ -483,7 +474,7 @@ static int deflate_file_to_buffer_bzip2(server *srv, connection *con, plugin_dat } #endif -static void mod_compress_note_ratio(server *srv, connection *con, off_t in, off_t out) { +static void mod_compress_note_ratio(connection *con, off_t in, off_t out) { /* store compression ratio in environment * for possible logging by mod_accesslog * (late in response handling, so not seen by most other modules) */ @@ -492,7 +483,6 @@ static void mod_compress_note_ratio(server *srv, connection *con, off_t in, off_ if (0 == in) return; li_itostrn(ratio, sizeof(ratio), out * 100 / in); http_header_env_set(con, CONST_STR_LEN("ratio"), ratio, strlen(ratio)); - UNUSED(srv); } static int deflate_file_to_file(server *srv, connection *con, plugin_data *p, int ifd, buffer *fn, stat_cache_entry *sce, int type) { @@ -538,7 +528,8 @@ static int deflate_file_to_file(server *srv, connection *con, plugin_data *p, in buffer_append_string_len(p->ofn, CONST_STR_LEN("-bzip2-")); break; default: - log_error_write(srv, __FILE__, __LINE__, "sd", "unknown compression type", type); + log_error(con->conf.errh, __FILE__, __LINE__, + "unknown compression type %d", type); return -1; } @@ -548,9 +539,9 @@ static int deflate_file_to_file(server *srv, connection *con, plugin_data *p, in if (0 == sce->st.st_size) return -1; /* cache file being created */ /* cache-entry exists */ #if 0 - log_error_write(srv, __FILE__, __LINE__, "bs", p->ofn, "compress-cache hit"); + log_error(con->conf.errh, __FILE__, __LINE__, "%s compress-cache hit", p->ofn->ptr); #endif - mod_compress_note_ratio(srv, con, sce->st.st_size, sce_ofn->st.st_size); + mod_compress_note_ratio(con, sce->st.st_size, sce_ofn->st.st_size); buffer_copy_buffer(con->physical.path, p->ofn); return 0; } @@ -560,7 +551,8 @@ static int deflate_file_to_file(server *srv, connection *con, plugin_data *p, in } if (-1 == mkdir_for_file(p->ofn->ptr)) { - log_error_write(srv, __FILE__, __LINE__, "sb", "couldn't create directory for file", p->ofn); + log_error(con->conf.errh, __FILE__, __LINE__, + "couldn't create directory for file %s", p->ofn->ptr); return -1; } @@ -570,12 +562,13 @@ static int deflate_file_to_file(server *srv, connection *con, plugin_data *p, in return -1; /* cache file being created */ } - log_error_write(srv, __FILE__, __LINE__, "sbss", "creating cachefile", p->ofn, "failed", strerror(errno)); + log_perror(con->conf.errh, __FILE__, __LINE__, + "creating cachefile %s failed", p->ofn->ptr); return -1; } #if 0 - log_error_write(srv, __FILE__, __LINE__, "bs", p->ofn, "compress-cache miss"); + log_error(con->conf.errh, __FILE__, __LINE__, "%s compress-cache miss", p->ofn->ptr); #endif #ifdef USE_MMAP @@ -587,15 +580,16 @@ static int deflate_file_to_file(server *srv, connection *con, plugin_data *p, in if (0 != sigsetjmp(sigbus_jmp, 1)) { sigbus_jmp_valid = 0; - log_error_write(srv, __FILE__, __LINE__, "sbd", "SIGBUS in mmap:", - fn, ifd); + log_error(con->conf.errh, __FILE__, __LINE__, + "SIGBUS in mmap: %s %d", fn->ptr, ifd); munmap(start, sce->st.st_size); close(ofd); /* Remove the incomplete cache file, so that later hits aren't served from it */ if (-1 == unlink(p->ofn->ptr)) { - log_error_write(srv, __FILE__, __LINE__, "sbss", "unlinking incomplete cachefile", p->ofn, "failed:", strerror(errno)); + log_perror(con->conf.errh, __FILE__, __LINE__, + "unlinking incomplete cachefile %s failed", p->ofn->ptr); } return -1; @@ -603,14 +597,16 @@ static int deflate_file_to_file(server *srv, connection *con, plugin_data *p, in } else #endif /* FIXME: might attempt to read very large file completely into memory; see compress.max-filesize config option */ if (NULL == (start = malloc(sce->st.st_size)) || sce->st.st_size != read(ifd, start, sce->st.st_size)) { - log_error_write(srv, __FILE__, __LINE__, "sbss", "reading", fn, "failed", strerror(errno)); + log_perror(con->conf.errh, __FILE__, __LINE__, + "reading %s failed", fn->ptr); close(ofd); free(start); /* Remove the incomplete cache file, so that later hits aren't served from it */ if (-1 == unlink(p->ofn->ptr)) { - log_error_write(srv, __FILE__, __LINE__, "sbss", "unlinking incomplete cachefile", p->ofn, "failed:", strerror(errno)); + log_perror(con->conf.errh, __FILE__, __LINE__, + "unlinking incomplete cachefile %s failed", p->ofn->ptr); } return -1; @@ -621,16 +617,16 @@ static int deflate_file_to_file(server *srv, connection *con, plugin_data *p, in #ifdef USE_ZLIB case HTTP_ACCEPT_ENCODING_GZIP: case HTTP_ACCEPT_ENCODING_X_GZIP: - ret = deflate_file_to_buffer_gzip(srv, con, p, start, sce->st.st_size, sce->st.st_mtime); + ret = deflate_file_to_buffer_gzip(p, start, sce->st.st_size, sce->st.st_mtime); break; case HTTP_ACCEPT_ENCODING_DEFLATE: - ret = deflate_file_to_buffer_deflate(srv, con, p, start, sce->st.st_size); + ret = deflate_file_to_buffer_deflate(p, start, sce->st.st_size); break; #endif #ifdef USE_BZ2LIB case HTTP_ACCEPT_ENCODING_BZIP2: case HTTP_ACCEPT_ENCODING_X_BZIP2: - ret = deflate_file_to_buffer_bzip2(srv, con, p, start, sce->st.st_size); + ret = deflate_file_to_buffer_bzip2(p, start, sce->st.st_size); break; #endif } @@ -638,10 +634,13 @@ static int deflate_file_to_file(server *srv, connection *con, plugin_data *p, in if (ret == 0) { r = write(ofd, CONST_BUF_LEN(p->b)); if (-1 == r) { - log_error_write(srv, __FILE__, __LINE__, "sbss", "writing cachefile", p->ofn, "failed:", strerror(errno)); + log_perror(con->conf.errh, __FILE__, __LINE__, + "writing cachefile %s failed", p->ofn->ptr); ret = -1; } else if ((size_t)r != buffer_string_length(p->b)) { - log_error_write(srv, __FILE__, __LINE__, "sbs", "writing cachefile", p->ofn, "failed: not enough bytes written"); + log_error(con->conf.errh, __FILE__, __LINE__, + "writing cachefile %s failed: not enough bytes written", + p->ofn->ptr); ret = -1; } } @@ -656,19 +655,21 @@ static int deflate_file_to_file(server *srv, connection *con, plugin_data *p, in if (0 != close(ofd) || ret != 0) { if (0 == ret) { - log_error_write(srv, __FILE__, __LINE__, "sbss", "writing cachefile", p->ofn, "failed:", strerror(errno)); + log_perror(con->conf.errh, __FILE__, __LINE__, + "writing cachefile %s failed", p->ofn->ptr); } /* Remove the incomplete cache file, so that later hits aren't served from it */ if (-1 == unlink(p->ofn->ptr)) { - log_error_write(srv, __FILE__, __LINE__, "sbss", "unlinking incomplete cachefile", p->ofn, "failed:", strerror(errno)); + log_perror(con->conf.errh, __FILE__, __LINE__, + "unlinking incomplete cachefile %s failed", p->ofn->ptr); } return -1; } buffer_copy_buffer(con->physical.path, p->ofn); - mod_compress_note_ratio(srv, con, sce->st.st_size, + mod_compress_note_ratio(con, sce->st.st_size, (off_t)buffer_string_length(p->b)); return 0; @@ -697,7 +698,7 @@ static int deflate_file_to_buffer(server *srv, connection *con, plugin_data *p, if (-1 == ifd) { /* not called; call exists to de-optimize and avoid "clobbered by 'longjmp'" compiler warning */ - log_error_write(srv, __FILE__, __LINE__, "s", ""); + log_error(con->conf.errh, __FILE__, __LINE__, " "); return -1; } @@ -709,18 +710,15 @@ static int deflate_file_to_buffer(server *srv, connection *con, plugin_data *p, sigbus_jmp_valid = 1; if (0 != sigsetjmp(sigbus_jmp, 1)) { sigbus_jmp_valid = 0; - - log_error_write(srv, __FILE__, __LINE__, "sbd", "SIGBUS in mmap:", - fn, ifd); - + log_error(con->conf.errh, __FILE__, __LINE__, + "SIGBUS in mmap: %s %d", fn->ptr, ifd); munmap(start, sce->st.st_size); return -1; } } else #endif /* FIXME: might attempt to read very large file completely into memory; see compress.max-filesize config option */ if (NULL == (start = malloc(sce->st.st_size)) || sce->st.st_size != read(ifd, start, sce->st.st_size)) { - log_error_write(srv, __FILE__, __LINE__, "sbss", "reading", fn, "failed", strerror(errno)); - + log_perror(con->conf.errh, __FILE__, __LINE__, "reading %s failed", fn->ptr); free(start); return -1; } @@ -729,16 +727,16 @@ static int deflate_file_to_buffer(server *srv, connection *con, plugin_data *p, #ifdef USE_ZLIB case HTTP_ACCEPT_ENCODING_GZIP: case HTTP_ACCEPT_ENCODING_X_GZIP: - ret = deflate_file_to_buffer_gzip(srv, con, p, start, sce->st.st_size, sce->st.st_mtime); + ret = deflate_file_to_buffer_gzip(p, start, sce->st.st_size, sce->st.st_mtime); break; case HTTP_ACCEPT_ENCODING_DEFLATE: - ret = deflate_file_to_buffer_deflate(srv, con, p, start, sce->st.st_size); + ret = deflate_file_to_buffer_deflate(p, start, sce->st.st_size); break; #endif #ifdef USE_BZ2LIB case HTTP_ACCEPT_ENCODING_BZIP2: case HTTP_ACCEPT_ENCODING_X_BZIP2: - ret = deflate_file_to_buffer_bzip2(srv, con, p, start, sce->st.st_size); + ret = deflate_file_to_buffer_bzip2(p, start, sce->st.st_size); break; #endif default: @@ -756,7 +754,7 @@ static int deflate_file_to_buffer(server *srv, connection *con, plugin_data *p, if (ret != 0) return -1; - mod_compress_note_ratio(srv, con, sce->st.st_size, + mod_compress_note_ratio(con, sce->st.st_size, (off_t)buffer_string_length(p->b)); chunkqueue_reset(con->write_queue); chunkqueue_append_buffer(con->write_queue, p->b); @@ -814,16 +812,15 @@ PHYSICALPATH_FUNC(mod_compress_physical) { } if (con->conf.log_request_handling) { - log_error_write(srv, __FILE__, __LINE__, "s", "-- handling file as static file"); + log_error(con->conf.errh, __FILE__, __LINE__, + "-- handling file as static file"); } if (HANDLER_ERROR == stat_cache_get_entry(srv, con, con->physical.path, &sce)) { con->http_status = 403; - - log_error_write(srv, __FILE__, __LINE__, "sbsb", - "not a regular file:", con->uri.path, - "->", con->physical.path); - + log_error(con->conf.errh, __FILE__, __LINE__, + "not a regular file: %s -> %s", + con->uri.path->ptr, con->physical.path->ptr); return HANDLER_FINISHED; } @@ -910,8 +907,8 @@ PHYSICALPATH_FUNC(mod_compress_physical) { const int fd = fdevent_open_cloexec(con->physical.path->ptr, con->conf.follow_symlink, O_RDONLY, 0); if (fd < 0) { - log_error_write(srv, __FILE__, __LINE__, "sbss", - "opening plain-file", con->physical.path, "failed", strerror(errno)); + log_perror(con->conf.errh, __FILE__, __LINE__, + "opening plain-file %s failed", con->physical.path->ptr); return HANDLER_GO_ON; } @@ -920,7 +917,7 @@ PHYSICALPATH_FUNC(mod_compress_physical) { /* try matching original etag of uncompressed version */ if (use_etag) { etag_mutate(con->physical.etag, sce->etag); - if (HANDLER_FINISHED == http_response_handle_cachable(srv, con, mtime)) { + if (HANDLER_FINISHED == http_response_handle_cachable(con, mtime)) { http_header_response_set(con, HTTP_HEADER_CONTENT_TYPE, CONST_STR_LEN("Content-Type"), CONST_BUF_LEN(sce->content_type)); http_header_response_set(con, HTTP_HEADER_LAST_MODIFIED, CONST_STR_LEN("Last-Modified"), CONST_BUF_LEN(mtime)); http_header_response_set(con, HTTP_HEADER_ETAG, CONST_STR_LEN("ETag"), CONST_BUF_LEN(con->physical.etag)); @@ -956,7 +953,7 @@ PHYSICALPATH_FUNC(mod_compress_physical) { etag_mutate(con->physical.etag, srv->tmp_buf); } - if (HANDLER_FINISHED == http_response_handle_cachable(srv, con, mtime)) { + if (HANDLER_FINISHED == http_response_handle_cachable(con, mtime)) { http_header_response_set(con, HTTP_HEADER_CONTENT_ENCODING, CONST_STR_LEN("Content-Encoding"), compression_name, strlen(compression_name)); http_header_response_set(con, HTTP_HEADER_CONTENT_TYPE, CONST_STR_LEN("Content-Type"), CONST_BUF_LEN(sce->content_type)); http_header_response_set(con, HTTP_HEADER_LAST_MODIFIED, CONST_STR_LEN("Last-Modified"), CONST_BUF_LEN(mtime)); diff --git a/src/mod_deflate.c b/src/mod_deflate.c index ea465ca1..b6fce661 100644 --- a/src/mod_deflate.c +++ b/src/mod_deflate.c @@ -204,6 +204,7 @@ typedef struct { buffer *output; plugin_data *plugin_data; int compression_type; + log_error_st *errh; } handler_ctx; static handler_ctx *handler_ctx_init() { @@ -442,9 +443,9 @@ SETDEFAULTS_FUNC(mod_deflate_set_defaults) { #if defined(USE_ZLIB) || defined(USE_BZ2LIB) -static int stream_http_chunk_append_mem(server *srv, connection *con, handler_ctx *hctx, size_t len) { +static int stream_http_chunk_append_mem(connection *con, handler_ctx *hctx, size_t len) { /* future: might also write stream to hctx temporary file in compressed file cache */ - return http_chunk_append_mem(srv, con, hctx->output->ptr, len); + return http_chunk_append_mem(con, hctx->output->ptr, len); } #endif @@ -478,7 +479,7 @@ static int stream_deflate_init(handler_ctx *hctx) { return 0; } -static int stream_deflate_compress(server *srv, connection *con, handler_ctx *hctx, unsigned char *start, off_t st_size) { +static int stream_deflate_compress(connection *con, handler_ctx *hctx, unsigned char *start, off_t st_size) { z_stream * const z = &(hctx->u.z); size_t len; @@ -493,7 +494,7 @@ static int stream_deflate_compress(server *srv, connection *con, handler_ctx *hc if (z->avail_out == 0 || z->avail_in > 0) { len = hctx->output->size - z->avail_out; hctx->bytes_out += len; - stream_http_chunk_append_mem(srv, con, hctx, len); + stream_http_chunk_append_mem(con, hctx, len); z->next_out = (unsigned char *)hctx->output->ptr; z->avail_out = hctx->output->size; } @@ -502,7 +503,7 @@ static int stream_deflate_compress(server *srv, connection *con, handler_ctx *hc return 0; } -static int stream_deflate_flush(server *srv, connection *con, handler_ctx *hctx, int end) { +static int stream_deflate_flush(connection *con, handler_ctx *hctx, int end) { z_stream * const z = &(hctx->u.z); const plugin_data *p = hctx->plugin_data; size_t len; @@ -532,7 +533,7 @@ static int stream_deflate_flush(server *srv, connection *con, handler_ctx *hctx, len = hctx->output->size - z->avail_out; if (z->avail_out == 0 || (len > 0 && (end || p->conf.sync_flush))) { hctx->bytes_out += len; - stream_http_chunk_append_mem(srv, con, hctx, len); + stream_http_chunk_append_mem(con, hctx, len); z->next_out = (unsigned char *)hctx->output->ptr; z->avail_out = hctx->output->size; } @@ -541,17 +542,17 @@ static int stream_deflate_flush(server *srv, connection *con, handler_ctx *hctx, return 0; } -static int stream_deflate_end(server *srv, handler_ctx *hctx) { +static int stream_deflate_end(handler_ctx *hctx) { z_stream * const z = &(hctx->u.z); int rc = deflateEnd(z); if (Z_OK == rc || Z_DATA_ERROR == rc) return 0; if (z->msg != NULL) { - log_error_write(srv, __FILE__, __LINE__, "sdss", - "deflateEnd error ret=", rc, ", msg=", z->msg); + log_error(hctx->errh, __FILE__, __LINE__, + "deflateEnd error ret=%d, msg=%s", rc, z->msg); } else { - log_error_write(srv, __FILE__, __LINE__, "sd", - "deflateEnd error ret=", rc); + log_error(hctx->errh, __FILE__, __LINE__, + "deflateEnd error ret=%d", rc); } return -1; } @@ -586,7 +587,7 @@ static int stream_bzip2_init(handler_ctx *hctx) { return 0; } -static int stream_bzip2_compress(server *srv, connection *con, handler_ctx *hctx, unsigned char *start, off_t st_size) { +static int stream_bzip2_compress(connection *con, handler_ctx *hctx, unsigned char *start, off_t st_size) { bz_stream * const bz = &(hctx->u.bz); size_t len; @@ -601,7 +602,7 @@ static int stream_bzip2_compress(server *srv, connection *con, handler_ctx *hctx if (bz->avail_out == 0 || bz->avail_in > 0) { len = hctx->output->size - bz->avail_out; hctx->bytes_out += len; - stream_http_chunk_append_mem(srv, con, hctx, len); + stream_http_chunk_append_mem(con, hctx, len); bz->next_out = hctx->output->ptr; bz->avail_out = hctx->output->size; } @@ -610,7 +611,7 @@ static int stream_bzip2_compress(server *srv, connection *con, handler_ctx *hctx return 0; } -static int stream_bzip2_flush(server *srv, connection *con, handler_ctx *hctx, int end) { +static int stream_bzip2_flush(connection *con, handler_ctx *hctx, int end) { bz_stream * const bz = &(hctx->u.bz); const plugin_data *p = hctx->plugin_data; size_t len; @@ -640,7 +641,7 @@ static int stream_bzip2_flush(server *srv, connection *con, handler_ctx *hctx, i len = hctx->output->size - bz->avail_out; if (bz->avail_out == 0 || (len > 0 && (end || p->conf.sync_flush))) { hctx->bytes_out += len; - stream_http_chunk_append_mem(srv, con, hctx, len); + stream_http_chunk_append_mem(con, hctx, len); bz->next_out = hctx->output->ptr; bz->avail_out = hctx->output->size; } @@ -649,13 +650,13 @@ static int stream_bzip2_flush(server *srv, connection *con, handler_ctx *hctx, i return 0; } -static int stream_bzip2_end(server *srv, handler_ctx *hctx) { +static int stream_bzip2_end(handler_ctx *hctx) { bz_stream * const bz = &(hctx->u.bz); int rc = BZ2_bzCompressEnd(bz); if (BZ_OK == rc || BZ_DATA_ERROR == rc) return 0; - log_error_write(srv, __FILE__, __LINE__, "sd", - "BZ2_bzCompressEnd error ret=", rc); + log_error(hctx->errh, __FILE__, __LINE__, + "BZ2_bzCompressEnd error ret=%d", rc); return -1; } @@ -678,47 +679,45 @@ static int mod_deflate_stream_init(handler_ctx *hctx) { } } -static int mod_deflate_compress(server *srv, connection *con, handler_ctx *hctx, unsigned char *start, off_t st_size) { +static int mod_deflate_compress(connection *con, handler_ctx *hctx, unsigned char *start, off_t st_size) { if (0 == st_size) return 0; switch(hctx->compression_type) { #ifdef USE_ZLIB case HTTP_ACCEPT_ENCODING_GZIP: case HTTP_ACCEPT_ENCODING_DEFLATE: - return stream_deflate_compress(srv, con, hctx, start, st_size); + return stream_deflate_compress(con, hctx, start, st_size); #endif #ifdef USE_BZ2LIB case HTTP_ACCEPT_ENCODING_BZIP2: - return stream_bzip2_compress(srv, con, hctx, start, st_size); + return stream_bzip2_compress(con, hctx, start, st_size); #endif default: - UNUSED(srv); UNUSED(con); UNUSED(start); return -1; } } -static int mod_deflate_stream_flush(server *srv, connection *con, handler_ctx *hctx, int end) { +static int mod_deflate_stream_flush(connection *con, handler_ctx *hctx, int end) { if (0 == hctx->bytes_in) return 0; switch(hctx->compression_type) { #ifdef USE_ZLIB case HTTP_ACCEPT_ENCODING_GZIP: case HTTP_ACCEPT_ENCODING_DEFLATE: - return stream_deflate_flush(srv, con, hctx, end); + return stream_deflate_flush(con, hctx, end); #endif #ifdef USE_BZ2LIB case HTTP_ACCEPT_ENCODING_BZIP2: - return stream_bzip2_flush(srv, con, hctx, end); + return stream_bzip2_flush(con, hctx, end); #endif default: - UNUSED(srv); UNUSED(con); UNUSED(end); return -1; } } -static void mod_deflate_note_ratio(server *srv, connection *con, handler_ctx *hctx) { +static void mod_deflate_note_ratio(connection *con, handler_ctx *hctx) { /* store compression ratio in environment * for possible logging by mod_accesslog * (late in response handling, so not seen by most other modules) */ @@ -727,38 +726,37 @@ static void mod_deflate_note_ratio(server *srv, connection *con, handler_ctx *hc if (0 == hctx->bytes_in) return; li_itostrn(ratio, sizeof(ratio), hctx->bytes_out * 100 / hctx->bytes_in); http_header_env_set(con, CONST_STR_LEN("ratio"), ratio, strlen(ratio)); - UNUSED(srv); } -static int mod_deflate_stream_end(server *srv, handler_ctx *hctx) { +static int mod_deflate_stream_end(handler_ctx *hctx) { switch(hctx->compression_type) { #ifdef USE_ZLIB case HTTP_ACCEPT_ENCODING_GZIP: case HTTP_ACCEPT_ENCODING_DEFLATE: - return stream_deflate_end(srv, hctx); + return stream_deflate_end(hctx); #endif #ifdef USE_BZ2LIB case HTTP_ACCEPT_ENCODING_BZIP2: - return stream_bzip2_end(srv, hctx); + return stream_bzip2_end(hctx); #endif default: - UNUSED(srv); return -1; } } -static void deflate_compress_cleanup(server *srv, connection *con, handler_ctx *hctx) { +static void deflate_compress_cleanup(connection *con, handler_ctx *hctx) { const plugin_data *p = hctx->plugin_data; con->plugin_ctx[p->id] = NULL; - if (0 != mod_deflate_stream_end(srv, hctx)) { - log_error_write(srv, __FILE__, __LINE__, "s", "error closing stream"); + if (0 != mod_deflate_stream_end(hctx)) { + log_error(con->conf.errh, __FILE__, __LINE__, "error closing stream"); } #if 1 /* unnecessary if deflate.min-compress-size is set to a reasonable value */ if (hctx->bytes_in < hctx->bytes_out) { - log_error_write(srv, __FILE__, __LINE__, "sbsdsd", - "uri ", con->uri.path_raw, " in=", hctx->bytes_in, " smaller than out=", hctx->bytes_out); + log_error(con->conf.errh, __FILE__, __LINE__, + "uri %s in=%lld smaller than out=%lld", con->uri.path_raw->ptr, + (long long)hctx->bytes_in, (long long)hctx->bytes_out); } #endif @@ -766,7 +764,7 @@ static void deflate_compress_cleanup(server *srv, connection *con, handler_ctx * } -static int mod_deflate_file_chunk(server *srv, connection *con, handler_ctx *hctx, chunk *c, off_t st_size) { +static int mod_deflate_file_chunk(connection *con, handler_ctx *hctx, chunk *c, off_t st_size) { off_t abs_offset; off_t toSend = -1; char *start; @@ -780,8 +778,7 @@ static int mod_deflate_file_chunk(server *srv, connection *con, handler_ctx *hct if (-1 == c->file.fd) { /* open the file if not already open */ if (-1 == (c->file.fd = fdevent_open_cloexec(c->mem->ptr, con->conf.follow_symlink, O_RDONLY, 0))) { - log_error_write(srv, __FILE__, __LINE__, "sbs", "open failed for:", c->mem, strerror(errno)); - + log_perror(con->conf.errh, __FILE__, __LINE__, "open failed %s", c->mem->ptr); return -1; } } @@ -840,8 +837,8 @@ static int mod_deflate_file_chunk(server *srv, connection *con, handler_ctx *hct if (MAP_FAILED == (c->file.mmap.start = mmap(0, (size_t)to_mmap, PROT_READ, MAP_SHARED, c->file.fd, c->file.mmap.offset)) && (errno != EINVAL || MAP_FAILED == (c->file.mmap.start = mmap(0, (size_t)to_mmap, PROT_READ, MAP_PRIVATE, c->file.fd, c->file.mmap.offset)))) { - log_error_write(srv, __FILE__, __LINE__, "ssbd", "mmap failed:", - strerror(errno), c->mem, c->file.fd); + log_perror(con->conf.errh, __FILE__, __LINE__, + "mmap failed %s %d", c->mem->ptr, c->file.fd); return -1; } @@ -851,8 +848,8 @@ static int mod_deflate_file_chunk(server *srv, connection *con, handler_ctx *hct /* don't advise files < 64Kb */ if (c->file.mmap.length > (64 KByte) && 0 != madvise(c->file.mmap.start, c->file.mmap.length, MADV_WILLNEED)) { - log_error_write(srv, __FILE__, __LINE__, "ssbd", "madvise failed:", - strerror(errno), c->mem, c->file.fd); + log_perror(con->conf.errh, __FILE__, __LINE__, + "madvise failed %s %d", c->mem->ptr, c->file.fd); } #endif @@ -864,12 +861,12 @@ static int mod_deflate_file_chunk(server *srv, connection *con, handler_ctx *hct if (toSend > we_want_to_send) toSend = we_want_to_send; if (toSend < 0) { - log_error_write(srv, __FILE__, __LINE__, "soooo", - "toSend is negative:", - toSend, - c->file.mmap.length, - abs_offset, - c->file.mmap.offset); + log_error(con->conf.errh, __FILE__, __LINE__, + "toSend is negative: %lld %lld %lld %lld", + (long long)toSend, + (long long)c->file.mmap.length, + (long long)abs_offset, + (long long)c->file.mmap.offset); force_assert(toSend < 0); } @@ -881,7 +878,7 @@ static int mod_deflate_file_chunk(server *srv, connection *con, handler_ctx *hct toSend = st_size; if (toSend > 2 MByte) toSend = 2 MByte; if (NULL == (start = malloc((size_t)toSend)) || -1 == lseek(c->file.fd, abs_offset, SEEK_SET) || toSend != read(c->file.fd, start, (size_t)toSend)) { - log_error_write(srv, __FILE__, __LINE__, "sbss", "reading", c->mem, "failed:", strerror(errno)); + log_perror(con->conf.errh, __FILE__, __LINE__, "reading %s failed", c->mem->ptr); free(start); return -1; @@ -896,17 +893,16 @@ static int mod_deflate_file_chunk(server *srv, connection *con, handler_ctx *hct if (0 != sigsetjmp(sigbus_jmp, 1)) { sigbus_jmp_valid = 0; - log_error_write(srv, __FILE__, __LINE__, "sbd", "SIGBUS in mmap:", - c->mem, c->file.fd); + log_error(con->conf.errh, __FILE__, __LINE__, + "SIGBUS in mmap: %s %d", c->mem->ptr, c->file.fd); return -1; } } #endif - if (mod_deflate_compress(srv, con, hctx, + if (mod_deflate_compress(con, hctx, (unsigned char *)start + (abs_offset - c->file.mmap.offset), toSend) < 0) { - log_error_write(srv, __FILE__, __LINE__, "s", - "compress failed."); + log_error(con->conf.errh, __FILE__, __LINE__, "compress failed."); toSend = -1; } @@ -921,7 +917,7 @@ static int mod_deflate_file_chunk(server *srv, connection *con, handler_ctx *hct } -static handler_t deflate_compress_response(server *srv, connection *con, handler_ctx *hctx) { +static handler_t deflate_compress_response(connection *con, handler_ctx *hctx) { off_t len, max; int close_stream; @@ -949,23 +945,21 @@ static handler_t deflate_compress_response(server *srv, connection *con, handler case MEM_CHUNK: len = buffer_string_length(c->mem) - c->offset; if (len > max) len = max; - if (mod_deflate_compress(srv, con, hctx, (unsigned char *)c->mem->ptr+c->offset, len) < 0) { - log_error_write(srv, __FILE__, __LINE__, "s", - "compress failed."); + if (mod_deflate_compress(con, hctx, (unsigned char *)c->mem->ptr+c->offset, len) < 0) { + log_error(con->conf.errh, __FILE__, __LINE__, "compress failed."); return HANDLER_ERROR; } break; case FILE_CHUNK: len = c->file.length - c->offset; if (len > max) len = max; - if ((len = mod_deflate_file_chunk(srv, con, hctx, c, len)) < 0) { - log_error_write(srv, __FILE__, __LINE__, "s", - "compress file chunk failed."); + if ((len = mod_deflate_file_chunk(con, hctx, c, len)) < 0) { + log_error(con->conf.errh, __FILE__, __LINE__, "compress file chunk failed."); return HANDLER_ERROR; } break; default: - log_error_write(srv, __FILE__, __LINE__, "ds", c, "type not known"); + log_error(con->conf.errh, __FILE__, __LINE__, "%d type not known", c->type); return HANDLER_ERROR; } @@ -976,8 +970,8 @@ static handler_t deflate_compress_response(server *srv, connection *con, handler /*(currently should always be true)*/ /*(current implementation requires response be complete)*/ close_stream = (con->file_finished && chunkqueue_is_empty(hctx->in_queue)); - if (mod_deflate_stream_flush(srv, con, hctx, close_stream) < 0) { - log_error_write(srv, __FILE__, __LINE__, "s", "flush error"); + if (mod_deflate_stream_flush(con, hctx, close_stream) < 0) { + log_error(con->conf.errh, __FILE__, __LINE__, "flush error"); return HANDLER_ERROR; } @@ -1224,14 +1218,15 @@ CONNECTION_FUNC(mod_deflate_handle_response_start) { hctx = handler_ctx_init(); hctx->plugin_data = p; hctx->compression_type = compression_type; + hctx->errh = con->conf.errh; /* setup output buffer */ buffer_clear(&p->tmp_buf); hctx->output = &p->tmp_buf; if (0 != mod_deflate_stream_init(hctx)) { /*(should not happen unless ENOMEM)*/ handler_ctx_free(hctx); - log_error_write(srv, __FILE__, __LINE__, "ss", - "Failed to initialize compression", label); + log_error(con->conf.errh, __FILE__, __LINE__, + "Failed to initialize compression %s", label); /* restore prior Etag and unset Content-Encoding */ if (etaglen) { vb->ptr[etaglen-1] = '"'; /*(overwrite '-')*/ @@ -1246,12 +1241,12 @@ CONNECTION_FUNC(mod_deflate_handle_response_start) { } con->plugin_ctx[p->id] = hctx; - rc = deflate_compress_response(srv, con, hctx); + rc = deflate_compress_response(con, hctx); if (HANDLER_GO_ON != rc) { if (HANDLER_FINISHED == rc) { - mod_deflate_note_ratio(srv, con, hctx); + mod_deflate_note_ratio(con, hctx); } - deflate_compress_cleanup(srv, con, hctx); + deflate_compress_cleanup(con, hctx); if (HANDLER_ERROR == rc) return HANDLER_ERROR; } @@ -1262,8 +1257,9 @@ static handler_t mod_deflate_cleanup(server *srv, connection *con, void *p_d) { plugin_data *p = p_d; handler_ctx *hctx = con->plugin_ctx[p->id]; - if (NULL != hctx) deflate_compress_cleanup(srv, con, hctx); + if (NULL != hctx) deflate_compress_cleanup(con, hctx); + UNUSED(srv); return HANDLER_GO_ON; } diff --git a/src/mod_dirlisting.c b/src/mod_dirlisting.c index 1cd0d351..6e4b96d9 100644 --- a/src/mod_dirlisting.c +++ b/src/mod_dirlisting.c @@ -85,7 +85,7 @@ static pcre ** mod_dirlisting_parse_excludes(server *srv, const array *a) { return regexes; } -static int mod_dirlisting_exclude(server *srv, pcre **regex, const char *name, size_t len) { +static int mod_dirlisting_exclude(log_error_st *errh, pcre **regex, const char *name, size_t len) { for(; *regex; ++regex) { #define N 10 int ovec[N * 3]; @@ -93,7 +93,7 @@ static int mod_dirlisting_exclude(server *srv, pcre **regex, const char *name, s if ((n = pcre_exec(*regex, NULL, name, len, 0, 0, ovec, 3 * N)) < 0) { if (n == PCRE_ERROR_NOMATCH) continue; - log_error(srv->errh, __FILE__, __LINE__, + log_error(errh, __FILE__, __LINE__, "execution error while matching: %d", n); /* aborting would require a lot of manual cleanup here. * skip instead (to not leak names that break pcre matching) @@ -670,8 +670,7 @@ static void http_dirlist_append_js_table_resort (buffer *b, connection *con) { buffer_append_string_len(b, CONST_STR_LEN(");\n\n// -->\n\n\n")); } -static void http_list_directory_header(server *srv, connection *con, plugin_data *p, buffer *out) { - UNUSED(srv); +static void http_list_directory_header(connection *con, plugin_data *p, buffer *out) { if (p->conf.auto_layout) { buffer_append_string_len(out, CONST_STR_LEN( @@ -773,8 +772,7 @@ static void http_list_directory_header(server *srv, connection *con, plugin_data } } -static void http_list_directory_footer(server *srv, connection *con, plugin_data *p, buffer *out) { - UNUSED(srv); +static void http_list_directory_footer(connection *con, plugin_data *p, buffer *out) { buffer_append_string_len(out, CONST_STR_LEN( "\n" @@ -840,6 +838,7 @@ static int http_list_directory(server *srv, connection *con, plugin_data *p, buf char datebuf[sizeof("2005-Jan-01 22:23:24")]; const char *content_type; long name_max; + log_error_st * const errh = con->conf.errh; #if defined(HAVE_XATTR) || defined(HAVE_EXTATTR) char attrval[128]; int attrlen; @@ -847,6 +846,7 @@ static int http_list_directory(server *srv, connection *con, plugin_data *p, buf #ifdef HAVE_LOCALTIME_R struct tm tm; #endif + UNUSED(srv); if (buffer_string_is_empty(dir)) return -1; @@ -873,8 +873,8 @@ static int http_list_directory(server *srv, connection *con, plugin_data *p, buf path_file = path + i; if (NULL == (dp = opendir(path))) { - log_error(con->errh, __FILE__, __LINE__, - "opendir failed: %s", dir->ptr); + log_error(errh, __FILE__, __LINE__, + "opendir failed: %s", dir->ptr); free(path); return -1; @@ -914,7 +914,7 @@ static int http_list_directory(server *srv, connection *con, plugin_data *p, buf * elements, skipping any that match. */ if (p->conf.excludes - && mod_dirlisting_exclude(srv, p->conf.excludes, dent->d_name, i)) + && mod_dirlisting_exclude(errh, p->conf.excludes, dent->d_name, i)) continue; /* NOTE: the manual says, d_name is never more than NAME_MAX @@ -951,7 +951,7 @@ static int http_list_directory(server *srv, connection *con, plugin_data *p, buf if (files.used) http_dirls_sort(files.ent, files.used); out = chunkqueue_append_buffer_open(con->write_queue); - http_list_directory_header(srv, con, p, out); + http_list_directory_header(con, p, out); /* directories */ for (i = 0; i < dirs.used; i++) { @@ -1031,7 +1031,7 @@ static int http_list_directory(server *srv, connection *con, plugin_data *p, buf free(dirs.ent); free(path); - http_list_directory_footer(srv, con, p, out); + http_list_directory_footer(con, p, out); /* Insert possible charset to Content-Type */ if (buffer_string_is_empty(p->conf.encoding)) { @@ -1054,8 +1054,6 @@ URIHANDLER_FUNC(mod_dirlisting_subrequest) { plugin_data *p = p_d; stat_cache_entry *sce = NULL; - UNUSED(srv); - /* we only handle GET and HEAD */ switch(con->request.http_method) { case HTTP_METHOD_GET: @@ -1076,13 +1074,17 @@ URIHANDLER_FUNC(mod_dirlisting_subrequest) { if (!p->conf.dir_listing) return HANDLER_GO_ON; if (con->conf.log_request_handling) { - log_error_write(srv, __FILE__, __LINE__, "s", "-- handling the request as Dir-Listing"); - log_error_write(srv, __FILE__, __LINE__, "sb", "URI :", con->uri.path); + log_error(con->conf.errh, __FILE__, __LINE__, + "-- handling the request as Dir-Listing"); + log_error(con->conf.errh, __FILE__, __LINE__, + "URI : %s", con->uri.path->ptr); } if (HANDLER_ERROR == stat_cache_get_entry(srv, con, con->physical.path, &sce)) { - log_error_write(srv, __FILE__, __LINE__, "SB", "stat_cache_get_entry failed: ", con->physical.path); - SEGFAULT(); + log_error(con->conf.errh, __FILE__, __LINE__, + "stat_cache_get_entry failed: %s", con->physical.path->ptr); + con->http_status = 500; + return HANDLER_FINISHED; } if (!S_ISDIR(sce->st.st_mode)) return HANDLER_GO_ON; diff --git a/src/mod_evasive.c b/src/mod_evasive.c index 40c9e492..b830fe45 100644 --- a/src/mod_evasive.c +++ b/src/mod_evasive.c @@ -123,9 +123,9 @@ URIHANDLER_FUNC(mod_evasive_uri_handler) { if (conns_by_ip > p->conf.max_conns) { if (!p->conf.silent) { - log_error_write(srv, __FILE__, __LINE__, "bs", - con->dst_addr_buf, - "turned away. Too many connections."); + log_error(con->conf.errh, __FILE__, __LINE__, + "%s turned away. Too many connections.", + con->dst_addr_buf->ptr); } if (!buffer_is_empty(p->conf.location)) { diff --git a/src/mod_evhost.c b/src/mod_evhost.c index 3bc143b4..092bab0a 100644 --- a/src/mod_evhost.c +++ b/src/mod_evhost.c @@ -7,7 +7,6 @@ #include #include -#include /** * @@ -340,9 +339,9 @@ static handler_t mod_evhost_uri_handler(server *srv, connection *con, void *p_d) mod_evhost_build_doc_root_path(b, &p->split_vals, con->uri.authority, p->conf.path_pieces); if (HANDLER_ERROR == stat_cache_get_entry(srv, con, b, &sce)) { - log_error_write(srv, __FILE__, __LINE__, "sb", strerror(errno), b); + log_perror(con->conf.errh, __FILE__, __LINE__, "%s", b->ptr); } else if(!S_ISDIR(sce->st.st_mode)) { - log_error_write(srv, __FILE__, __LINE__, "sb", "not a directory:", b); + log_error(con->conf.errh, __FILE__, __LINE__, "not a directory: %s", b->ptr); } else { buffer_copy_buffer(con->physical.doc_root, b); } diff --git a/src/mod_expire.c b/src/mod_expire.c index d722d0d7..dd63d3c3 100644 --- a/src/mod_expire.c +++ b/src/mod_expire.c @@ -32,7 +32,7 @@ INIT_FUNC(mod_expire_init) { return calloc(1, sizeof(plugin_data)); } -static int mod_expire_get_offset(server *srv, plugin_data *p, const buffer *expire, time_t *offset) { +static int mod_expire_get_offset(log_error_st *errh, plugin_data *p, const buffer *expire, time_t *offset) { char *ts; int type = -1; time_t retts = 0; @@ -48,8 +48,7 @@ static int mod_expire_get_offset(server *srv, plugin_data *p, const buffer *expi */ if (buffer_string_is_empty(expire)) { - log_error_write(srv, __FILE__, __LINE__, "s", - "empty:"); + log_error(errh, __FILE__, __LINE__, "mod_expire empty string"); return -1; } @@ -66,8 +65,7 @@ static int mod_expire_get_offset(server *srv, plugin_data *p, const buffer *expi ts += 13; } else { /* invalid type-prefix */ - log_error_write(srv, __FILE__, __LINE__, "ss", - "invalid :", ts); + log_error(errh, __FILE__, __LINE__, "invalid : %s", ts); return -1; } @@ -82,15 +80,15 @@ static int mod_expire_get_offset(server *srv, plugin_data *p, const buffer *expi int num; if (NULL == (space = strchr(ts, ' '))) { - log_error_write(srv, __FILE__, __LINE__, "ss", - "missing space after :", ts); + log_error(errh, __FILE__, __LINE__, + "missing space after : %s", ts); return -1; } num = strtol(ts, &err, 10); if (*err != ' ') { - log_error_write(srv, __FILE__, __LINE__, "ss", - "missing after :", ts); + log_error(errh, __FILE__, __LINE__, + "missing after : %s", ts); return -1; } @@ -124,8 +122,7 @@ static int mod_expire_get_offset(server *srv, plugin_data *p, const buffer *expi 0 == strncmp(ts, "seconds", slen)) { num *= 1; } else { - log_error_write(srv, __FILE__, __LINE__, "ss", - "unknown type:", ts); + log_error(errh, __FILE__, __LINE__, "unknown type: %s", ts); return -1; } @@ -148,8 +145,7 @@ static int mod_expire_get_offset(server *srv, plugin_data *p, const buffer *expi } else if (0 == strcmp(ts, "seconds")) { num *= 1; } else { - log_error_write(srv, __FILE__, __LINE__, "ss", - "unknown type:", ts); + log_error(errh, __FILE__, __LINE__, "unknown type: %s", ts); return -1; } @@ -225,7 +221,7 @@ SETDEFAULTS_FUNC(mod_expire_set_defaults) { for (uint32_t k = 0; k < cpv->v.a->used; ++k) { /* parse lines */ data_string *ds = (data_string *)cpv->v.a->data[k]; - if (-1 == mod_expire_get_offset(srv, p, &ds->value, NULL)) { + if (-1==mod_expire_get_offset(srv->errh,p,&ds->value,NULL)){ log_error(srv->errh, __FILE__, __LINE__, "parsing expire.url failed: %s", ds->value.ptr); return HANDLER_ERROR; @@ -252,7 +248,7 @@ SETDEFAULTS_FUNC(mod_expire_set_defaults) { buffer_string_set_length(&ds->key, klen-1); /* parse lines */ - if (-1 == mod_expire_get_offset(srv, p, &ds->value, NULL)) { + if (-1==mod_expire_get_offset(srv->errh,p,&ds->value,NULL)){ log_error(srv->errh, __FILE__, __LINE__, "parsing expire.mimetypes failed: %s", ds->value.ptr); return HANDLER_ERROR; @@ -315,7 +311,7 @@ CONNECTION_FUNC(mod_expire_handler) { time_t ts, expires; stat_cache_entry *sce = NULL; - switch(mod_expire_get_offset(srv, p, vb, &ts)) { + switch(mod_expire_get_offset(con->conf.errh, p, vb, &ts)) { case 0: /* access */ expires = (ts + srv->cur_ts); diff --git a/src/mod_extforward.c b/src/mod_extforward.c index cb0736a1..494dce1c 100644 --- a/src/mod_extforward.c +++ b/src/mod_extforward.c @@ -117,7 +117,7 @@ typedef struct { buffer *saved_remote_addr_buf; /* hap-PROXY protocol prior to receiving first request */ - int(*saved_network_read)(server *, connection *, chunkqueue *, off_t); + int(*saved_network_read)(connection *, chunkqueue *, off_t); /* connection-level state applied to requests in handle_request_env */ array *env; @@ -257,7 +257,7 @@ static void * mod_extforward_parse_forwarder(server *srv, const array *forwarder struct sock_addr_mask * const sm = fwd->addrs + fwd->addrs_used++; sm->bits = nm_bits; *nm_slash = '\0'; - rc = sock_addr_from_str_numeric(srv, &sm->addr, ds->key.ptr); + rc = sock_addr_from_str_numeric(&sm->addr, ds->key.ptr, srv->errh); *nm_slash = '/'; if (1 != rc) { free(fwd); @@ -441,7 +441,7 @@ SETDEFAULTS_FUNC(mod_extforward_set_defaults) { for (; i < srv->srvconf.modules->used; ++i) { data_string *ds = (data_string *)srv->srvconf.modules->data[i]; if (buffer_eq_slen(&ds->value, CONST_STR_LEN("mod_openssl"))) { - log_error_write(srv, __FILE__, __LINE__, "s", + log_error(srv->errh, __FILE__, __LINE__, "mod_extforward must be loaded after mod_openssl in " "server.modules when extforward.hap-PROXY = \"enable\""); break; @@ -550,24 +550,24 @@ static const char *last_not_in_array(array *a, plugin_data *p) return NULL; } -static int mod_extforward_set_addr(server *srv, connection *con, plugin_data *p, const char *addr) { +static int mod_extforward_set_addr(connection *con, plugin_data *p, const char *addr) { sock_addr sock; handler_ctx *hctx = con->plugin_ctx[p->id]; if (con->conf.log_request_handling) { - log_error_write(srv, __FILE__, __LINE__, "ss", "using address:", addr); + log_error(con->conf.errh, __FILE__, __LINE__, "using address: %s", addr); } sock.plain.sa_family = AF_UNSPEC; - if (1 != sock_addr_from_str_numeric(srv, &sock, addr)) return 0; + if (1 != sock_addr_from_str_numeric(&sock, addr, con->conf.errh)) return 0; if (sock.plain.sa_family == AF_UNSPEC) return 0; /* we found the remote address, modify current connection and save the old address */ if (hctx) { if (hctx->saved_remote_addr_buf) { if (con->conf.log_request_handling) { - log_error_write(srv, __FILE__, __LINE__, "s", - "-- mod_extforward_uri_handler already patched this connection, resetting state"); + log_error(con->conf.errh, __FILE__, __LINE__, + "-- mod_extforward_uri_handler already patched this connection, resetting state"); } con->dst_addr = hctx->saved_remote_addr; buffer_free(con->dst_addr_buf); @@ -588,17 +588,17 @@ static int mod_extforward_set_addr(server *srv, connection *con, plugin_data *p, con->dst_addr_buf = buffer_init_string(addr); if (con->conf.log_request_handling) { - log_error_write(srv, __FILE__, __LINE__, "ss", - "patching con->dst_addr_buf for the accesslog:", addr); + log_error(con->conf.errh, __FILE__, __LINE__, + "patching con->dst_addr_buf for the accesslog: %s", addr); } /* Now, clean the conf_cond cache, because we may have changed the results of tests */ - config_cond_cache_reset_item(srv, con, COMP_HTTP_REMOTE_IP); + config_cond_cache_reset_item(con, COMP_HTTP_REMOTE_IP); return 1; } -static void mod_extforward_set_proto(server *srv, connection *con, const char *proto, size_t protolen) { +static void mod_extforward_set_proto(connection *con, const char *proto, size_t protolen) { if (0 != protolen && !buffer_is_equal_caseless_string(con->uri.scheme, proto, protolen)) { /* update scheme if X-Forwarded-Proto is set * Limitations: @@ -616,15 +616,15 @@ static void mod_extforward_set_proto(server *srv, connection *con, const char *p } if (buffer_eq_icase_ss(proto, protolen, CONST_STR_LEN("https"))) { buffer_copy_string_len(con->uri.scheme, CONST_STR_LEN("https")); - config_cond_cache_reset_item(srv, con, COMP_HTTP_SCHEME); + config_cond_cache_reset_item(con, COMP_HTTP_SCHEME); } else if (buffer_eq_icase_ss(proto, protolen, CONST_STR_LEN("http"))) { buffer_copy_string_len(con->uri.scheme, CONST_STR_LEN("http")); - config_cond_cache_reset_item(srv, con, COMP_HTTP_SCHEME); + config_cond_cache_reset_item(con, COMP_HTTP_SCHEME); } } } -static handler_t mod_extforward_X_Forwarded_For(server *srv, connection *con, plugin_data *p, const buffer *x_forwarded_for) { +static handler_t mod_extforward_X_Forwarded_For(connection *con, plugin_data *p, const buffer *x_forwarded_for) { /* build forward_array from forwarded data_string */ array *forward_array = extract_forward_array(x_forwarded_for); const char *real_remote_addr = last_not_in_array(forward_array, p); @@ -638,8 +638,8 @@ static handler_t mod_extforward_X_Forwarded_For(server *srv, connection *con, pl * as in X-Forwarded-For to find proto set by last trusted proxy) */ const buffer *x_forwarded_proto = http_header_request_get(con, HTTP_HEADER_X_FORWARDED_PROTO, CONST_STR_LEN("X-Forwarded-Proto")); - if (mod_extforward_set_addr(srv, con, p, real_remote_addr) && NULL != x_forwarded_proto) { - mod_extforward_set_proto(srv, con, CONST_BUF_LEN(x_forwarded_proto)); + if (mod_extforward_set_addr(con, p, real_remote_addr) && NULL != x_forwarded_proto) { + mod_extforward_set_proto(con, CONST_BUF_LEN(x_forwarded_proto)); } } array_free(forward_array); @@ -692,7 +692,7 @@ static int buffer_backslash_unescape (buffer * const b) { return 1; } -static handler_t mod_extforward_Forwarded (server *srv, connection *con, plugin_data *p, const buffer *forwarded) { +static handler_t mod_extforward_Forwarded (connection *con, plugin_data *p, const buffer *forwarded) { /* HTTP list need not consist of param=value tokens, * but this routine expect such for HTTP Forwarded header * Since info in each set of params is only used if from @@ -728,8 +728,8 @@ static handler_t mod_extforward_Forwarded (server *srv, connection *con, plugin_ i = find_next_semicolon_or_comma_or_eq(s, i); if (i < 0) { /*(reject IP spoofing if attacker sets improper quoted-string)*/ - log_error_write(srv, __FILE__, __LINE__, "s", - "invalid quoted-string in Forwarded header"); + log_error(con->conf.errh, __FILE__, __LINE__, + "invalid quoted-string in Forwarded header"); con->http_status = 400; /* Bad Request */ con->mode = DIRECT; return HANDLER_FINISHED; @@ -740,8 +740,8 @@ static handler_t mod_extforward_Forwarded (server *srv, connection *con, plugin_ i = find_next_semicolon_or_comma(s, i); if (i < 0) { /*(reject IP spoofing if attacker sets improper quoted-string)*/ - log_error_write(srv, __FILE__, __LINE__, "s", - "invalid quoted-string in Forwarded header"); + log_error(con->conf.errh, __FILE__, __LINE__, + "invalid quoted-string in Forwarded header"); con->http_status = 400; /* Bad Request */ con->mode = DIRECT; return HANDLER_FINISHED; @@ -763,8 +763,8 @@ static handler_t mod_extforward_Forwarded (server *srv, connection *con, plugin_ if (j >= (int)(sizeof(offsets)/sizeof(int))-4) { /* error processing Forwarded; too many params; fail closed */ - log_error_write(srv, __FILE__, __LINE__, "s", - "Too many params in Forwarded header"); + log_error(con->conf.errh, __FILE__, __LINE__, + "Too many params in Forwarded header"); con->http_status = 400; /* Bad Request */ con->mode = DIRECT; return HANDLER_FINISHED; @@ -798,8 +798,8 @@ static handler_t mod_extforward_Forwarded (server *srv, connection *con, plugin_ ++v; do { --vlen; } while (vlen > v && s[vlen] != ']'); if (v == vlen) { - log_error_write(srv, __FILE__, __LINE__, "s", - "Invalid IPv6 addr in Forwarded header"); + log_error(con->conf.errh, __FILE__, __LINE__, + "Invalid IPv6 addr in Forwarded header"); con->http_status = 400; /* Bad Request */ con->mode = DIRECT; return HANDLER_FINISHED; @@ -842,7 +842,7 @@ static handler_t mod_extforward_Forwarded (server *srv, connection *con, plugin_ char c = *ipend; int rc; *ipend = '\0'; - rc = mod_extforward_set_addr(srv, con, p, s+offsets[ofor+2]); + rc = mod_extforward_set_addr(con, p, s+offsets[ofor+2]); *ipend = c; if (!rc) return HANDLER_GO_ON; /* invalid addr; make no changes */ } @@ -896,7 +896,7 @@ static handler_t mod_extforward_Forwarded (server *srv, connection *con, plugin_ vlen = v + offsets[oproto+3]; while (vlen > v && (s[vlen-1] == ' ' || s[vlen-1] == '\t')) --vlen; if (vlen > v+1 && s[v] == '"' && s[vlen-1] == '"') { ++v; --vlen; } - mod_extforward_set_proto(srv, con, s+v, vlen-v); + mod_extforward_set_proto(con, s+v, vlen-v); } if (p->conf.opts & PROXY_FORWARDED_HOST) { @@ -939,8 +939,8 @@ static handler_t mod_extforward_Forwarded (server *srv, connection *con, plugin_ ++v; --vlen; buffer_copy_string_len(con->request.http_host, s+v, vlen-v); if (!buffer_backslash_unescape(con->request.http_host)) { - log_error_write(srv, __FILE__, __LINE__, "s", - "invalid host= value in Forwarded header"); + log_error(con->conf.errh, __FILE__, __LINE__, + "invalid host= value in Forwarded header"); con->http_status = 400; /* Bad Request */ con->mode = DIRECT; return HANDLER_FINISHED; @@ -953,14 +953,14 @@ static handler_t mod_extforward_Forwarded (server *srv, connection *con, plugin_ if (0 != http_request_host_policy(con, con->request.http_host, con->uri.scheme)) { /*(reject invalid chars in Host)*/ - log_error_write(srv, __FILE__, __LINE__, "s", - "invalid host= value in Forwarded header"); + log_error(con->conf.errh, __FILE__, __LINE__, + "invalid host= value in Forwarded header"); con->http_status = 400; /* Bad Request */ con->mode = DIRECT; return HANDLER_FINISHED; } - config_cond_cache_reset_item(srv, con, COMP_HTTP_HOST); + config_cond_cache_reset_item(con, COMP_HTTP_HOST); } } @@ -988,7 +988,7 @@ static handler_t mod_extforward_Forwarded (server *srv, connection *con, plugin_ euser = http_header_env_get(con, CONST_STR_LEN("REMOTE_USER")); force_assert(NULL != euser); if (!buffer_backslash_unescape(euser)) { - log_error_write(srv, __FILE__, __LINE__, "s", + log_error(con->conf.errh, __FILE__, __LINE__, "invalid remote_user= value in Forwarded header"); con->http_status = 400; /* Bad Request */ con->mode = DIRECT; @@ -1007,7 +1007,7 @@ static handler_t mod_extforward_Forwarded (server *srv, connection *con, plugin_ && NULL == http_header_request_get(con, HTTP_HEADER_X_FORWARDED_FOR, CONST_STR_LEN("X-Forwarded-For"))) { /* create X-Forwarded-For if not present * (and at least original connecting IP is a trusted proxy) */ - buffer *xff = srv->tmp_buf; + buffer *xff = con->srv->tmp_buf; buffer_clear(xff); for (j = 0; j < used; ) { if (-1 == offsets[j]) { ++j; continue; } @@ -1051,12 +1051,13 @@ URIHANDLER_FUNC(mod_extforward_uri_handler) { const buffer *forwarded = NULL; handler_ctx *hctx = con->plugin_ctx[p->id]; int is_forwarded_header = 0; + UNUSED(srv); mod_extforward_patch_config(con, p); if (con->conf.log_request_handling) { - log_error_write(srv, __FILE__, __LINE__, "s", - "-- mod_extforward_uri_handler called"); + log_error(con->conf.errh, __FILE__, __LINE__, + "-- mod_extforward_uri_handler called"); } if (p->conf.hap_PROXY_ssl_client_verify) { @@ -1091,7 +1092,8 @@ URIHANDLER_FUNC(mod_extforward_uri_handler) { } if (NULL == forwarded) { if (con->conf.log_request_handling) { - log_error_write(srv, __FILE__, __LINE__, "s", "no forward header found, skipping"); + log_error(con->conf.errh, __FILE__, __LINE__, + "no forward header found, skipping"); } return HANDLER_GO_ON; @@ -1100,18 +1102,19 @@ URIHANDLER_FUNC(mod_extforward_uri_handler) { /* if the remote ip itself is not trusted, then do nothing */ if (!is_connection_trusted(con, p)) { if (con->conf.log_request_handling) { - log_error_write(srv, __FILE__, __LINE__, "sbs", - "remote address", con->dst_addr_buf, "is NOT a trusted proxy, skipping"); + log_error(con->conf.errh, __FILE__, __LINE__, + "remote address %s is NOT a trusted proxy, skipping", + con->dst_addr_buf->ptr); } return HANDLER_GO_ON; } if (is_forwarded_header) { - return mod_extforward_Forwarded(srv, con, p, forwarded); + return mod_extforward_Forwarded(con, p, forwarded); } - return mod_extforward_X_Forwarded_For(srv, con, p, forwarded); + return mod_extforward_X_Forwarded_For(con, p, forwarded); } @@ -1134,6 +1137,7 @@ CONNECTION_FUNC(mod_extforward_handle_request_env) { CONNECTION_FUNC(mod_extforward_restore) { plugin_data *p = p_d; handler_ctx *hctx = con->plugin_ctx[p->id]; + UNUSED(srv); if (!hctx) return HANDLER_GO_ON; @@ -1148,7 +1152,7 @@ CONNECTION_FUNC(mod_extforward_restore) { con->dst_addr_buf = hctx->saved_remote_addr_buf; hctx->saved_remote_addr_buf = NULL; /* Now, clean the conf_cond cache, because we may have changed the results of tests */ - config_cond_cache_reset_item(srv, con, COMP_HTTP_REMOTE_IP); + config_cond_cache_reset_item(con, COMP_HTTP_REMOTE_IP); } if (NULL == hctx->env) { @@ -1185,11 +1189,12 @@ CONNECTION_FUNC(mod_extforward_handle_con_close) } -static int mod_extforward_network_read (server *srv, connection *con, chunkqueue *cq, off_t max_bytes); +static int mod_extforward_network_read (connection *con, chunkqueue *cq, off_t max_bytes); CONNECTION_FUNC(mod_extforward_handle_con_accept) { plugin_data *p = p_d; + UNUSED(srv); mod_extforward_patch_config(con, p); if (!p->conf.hap_PROXY) return HANDLER_GO_ON; if (NULL == p->conf.forwarder) return HANDLER_GO_ON; @@ -1201,9 +1206,9 @@ CONNECTION_FUNC(mod_extforward_handle_con_accept) } else { if (con->conf.log_request_handling) { - log_error_write(srv, __FILE__, __LINE__, "sbs", - "remote address", con->dst_addr_buf, - "is NOT a trusted proxy, skipping"); + log_error(con->conf.errh, __FILE__, __LINE__, + "remote address %s is NOT a trusted proxy, skipping", + con->dst_addr_buf->ptr); } } return HANDLER_GO_ON; @@ -1659,7 +1664,7 @@ static int mod_extforward_hap_PROXY_v2 (connection * const con, } -static int mod_extforward_network_read (server *srv, connection *con, +static int mod_extforward_network_read (connection *con, chunkqueue *cq, off_t max_bytes) { /* XXX: when using hap-PROXY protocol, currently avoid overhead of setting @@ -1673,16 +1678,14 @@ static int mod_extforward_network_read (server *srv, connection *con, case 2: rc = mod_extforward_hap_PROXY_v2(con, &hdr); break; case 1: rc = mod_extforward_hap_PROXY_v1(con, &hdr); break; case 0: return 0; /*(errno == EAGAIN || errno == EWOULDBLOCK)*/ - case -1: log_error_write(srv, __FILE__, __LINE__, "ss", - "hap-PROXY recv()", strerror(errno)); + case -1: log_perror(con->conf.errh,__FILE__,__LINE__,"hap-PROXY recv()"); rc = -1; break; - case -2: log_error_write(srv, __FILE__, __LINE__, "s", - "hap-PROXY proto received " - "invalid/unsupported request"); + case -2: log_error(con->conf.errh,__FILE__,__LINE__, + "hap-PROXY proto received invalid/unsupported request"); /* fall through */ default: rc = -1; break; } - mod_extforward_restore(srv, con, mod_extforward_plugin_data_singleton); - return (0 == rc) ? con->network_read(srv, con, cq, max_bytes) : rc; + mod_extforward_restore(con->srv, con, mod_extforward_plugin_data_singleton); + return (0 == rc) ? con->network_read(con, cq, max_bytes) : rc; } diff --git a/src/mod_fastcgi.c b/src/mod_fastcgi.c index 3615a2ae..e2f04077 100644 --- a/src/mod_fastcgi.c +++ b/src/mod_fastcgi.c @@ -290,8 +290,8 @@ static handler_t fcgi_create_env(server *srv, handler_ctx *hctx) { if (hctx->request_id == 0) { hctx->request_id = 1; /* always use id 1 as we don't use multiplexing */ } else { - log_error_write(srv, __FILE__, __LINE__, "sd", - "fcgi-request is already in use:", hctx->request_id); + log_error(con->conf.errh, __FILE__, __LINE__, + "fcgi-request is already in use: %d", hctx->request_id); } request_id = hctx->request_id; @@ -307,7 +307,7 @@ static handler_t fcgi_create_env(server *srv, handler_ctx *hctx) { /* send FCGI_PARAMS */ - if (0 != http_cgi_headers(srv, con, &opts, fcgi_env_add, b)) { + if (0 != http_cgi_headers(con, &opts, fcgi_env_add, b)) { con->http_status = 400; con->mode = DIRECT; buffer_clear(b); @@ -345,14 +345,17 @@ typedef struct { int request_id; } fastcgi_response_packet; -static int fastcgi_get_packet(server *srv, handler_ctx *hctx, fastcgi_response_packet *packet) { +static int fastcgi_get_packet(handler_ctx *hctx, fastcgi_response_packet *packet) { FCGI_Header header; size_t toread = sizeof(FCGI_Header), flen = 0; off_t rblen = chunkqueue_length(hctx->rb); if (rblen < (off_t)sizeof(FCGI_Header)) { /* no header */ if (hctx->conf.debug && 0 != rblen) { - log_error_write(srv, __FILE__, __LINE__, "sosds", "FastCGI: header too small:", rblen, "bytes <", sizeof(FCGI_Header), "bytes, waiting for more data"); + connection *con = hctx->remote_conn; + log_error(con->conf.errh, __FILE__, __LINE__, + "FastCGI: header too small: %lld bytes < %zu bytes, " + "waiting for more data", (long long)rblen, sizeof(FCGI_Header)); } return -1; } @@ -401,7 +404,7 @@ static void fastcgi_get_packet_body(buffer *b, handler_ctx *hctx, fastcgi_respon chunkqueue_mark_written(hctx->rb, packet->len); } -static handler_t fcgi_recv_parse(server *srv, connection *con, struct http_response_opts_t *opts, buffer *b, size_t n) { +static handler_t fcgi_recv_parse(connection *con, struct http_response_opts_t *opts, buffer *b, size_t n) { handler_ctx *hctx = (handler_ctx *)opts->pdata; int fin = 0; @@ -410,10 +413,10 @@ static handler_t fcgi_recv_parse(server *srv, connection *con, struct http_respo if (!(fdevent_fdnode_interest(hctx->fdn) & FDEVENT_IN) && !(con->conf.stream_response_body & FDEVENT_STREAM_RESPONSE_POLLRDHUP)) return HANDLER_GO_ON; - log_error_write(srv, __FILE__, __LINE__, "ssdsb", - "unexpected end-of-file (perhaps the fastcgi process died):", - "pid:", hctx->proc->pid, - "socket:", hctx->proc->connection_name); + log_error(con->conf.errh, __FILE__, __LINE__, + "unexpected end-of-file (perhaps the fastcgi process died):" + "pid: %d socket: %s", + hctx->proc->pid, hctx->proc->connection_name->ptr); return HANDLER_ERROR; } @@ -428,7 +431,7 @@ static handler_t fcgi_recv_parse(server *srv, connection *con, struct http_respo fastcgi_response_packet packet; /* check if we have at least one packet */ - if (0 != fastcgi_get_packet(srv, hctx, &packet)) { + if (0 != fastcgi_get_packet(hctx, &packet)) { /* no full packet */ break; } @@ -442,11 +445,11 @@ static handler_t fcgi_recv_parse(server *srv, connection *con, struct http_respo /* split header from body */ buffer *hdrs = hctx->response; if (NULL == hdrs) { - hdrs = srv->tmp_buf; - buffer_clear(srv->tmp_buf); + hdrs = con->srv->tmp_buf; + buffer_clear(hdrs); } fastcgi_get_packet_body(hdrs, hctx, &packet); - if (HANDLER_GO_ON != http_response_parse_headers(srv, con, &hctx->opts, hdrs)) { + if (HANDLER_GO_ON != http_response_parse_headers(con, &hctx->opts, hdrs)) { hctx->send_content_body = 0; fin = 1; break; @@ -463,7 +466,7 @@ static handler_t fcgi_recv_parse(server *srv, connection *con, struct http_respo hctx->send_content_body = 0; } } else if (hctx->send_content_body) { - if (0 != http_chunk_transfer_cqlen(srv, con, hctx->rb, packet.len - packet.padding)) { + if (0 != http_chunk_transfer_cqlen(con, hctx->rb, packet.len - packet.padding)) { /* error writing to tempfile; * truncate response or send 500 if nothing sent yet */ fin = 1; @@ -474,21 +477,21 @@ static handler_t fcgi_recv_parse(server *srv, connection *con, struct http_respo } break; case FCGI_STDERR: - if (packet.len == 0) break; - - buffer_clear(srv->tmp_buf); - fastcgi_get_packet_body(srv->tmp_buf, hctx, &packet); - log_error_write_multiline_buffer(srv, __FILE__, __LINE__, srv->tmp_buf, "s", - "FastCGI-stderr:"); - + if (packet.len) { + buffer * const tb = con->srv->tmp_buf; + buffer_clear(tb); + fastcgi_get_packet_body(tb, hctx, &packet); + log_error_write_multiline_buffer(con->srv, __FILE__, __LINE__, tb, "s", + "FastCGI-stderr:"); + } break; case FCGI_END_REQUEST: hctx->request_id = -1; /*(flag request ended)*/ fin = 1; break; default: - log_error_write(srv, __FILE__, __LINE__, "sd", - "FastCGI: header.type not handled: ", packet.type); + log_error(con->conf.errh, __FILE__, __LINE__, + "FastCGI: header.type not handled: %d", packet.type); chunkqueue_mark_written(hctx->rb, packet.len); break; } diff --git a/src/mod_flv_streaming.c b/src/mod_flv_streaming.c index 291bd3fc..13532f28 100644 --- a/src/mod_flv_streaming.c +++ b/src/mod_flv_streaming.c @@ -113,6 +113,7 @@ static off_t get_param_value(buffer *qb, const char *m, size_t mlen) { URIHANDLER_FUNC(mod_flv_streaming_path_handler) { plugin_data *p = p_d; + UNUSED(srv); if (con->mode != DIRECT) return HANDLER_GO_ON; if (buffer_string_is_empty(con->physical.path)) return HANDLER_GO_ON; @@ -140,8 +141,8 @@ URIHANDLER_FUNC(mod_flv_streaming_path_handler) { * otherwise send rest of file, starting from start */ /* let's build a flv header */ - http_chunk_append_mem(srv, con, CONST_STR_LEN("FLV\x1\x1\0\0\0\x9\0\0\0\x9")); - if (0 != http_chunk_append_file_range(srv, con, con->physical.path, start, len)) { + http_chunk_append_mem(con, CONST_STR_LEN("FLV\x1\x1\0\0\0\x9\0\0\0\x9")); + if (0 != http_chunk_append_file_range(con, con->physical.path, start, len)) { chunkqueue_reset(con->write_queue); return HANDLER_GO_ON; } diff --git a/src/mod_indexfile.c b/src/mod_indexfile.c index 57aa7c20..0c65f93c 100644 --- a/src/mod_indexfile.c +++ b/src/mod_indexfile.c @@ -115,8 +115,8 @@ URIHANDLER_FUNC(mod_indexfile_subrequest) { if (NULL == p->conf.indexfiles) return HANDLER_GO_ON; if (con->conf.log_request_handling) { - log_error_write(srv, __FILE__, __LINE__, "s", "-- handling the request as Indexfile"); - log_error_write(srv, __FILE__, __LINE__, "sb", "URI :", con->uri.path); + log_error(con->conf.errh, __FILE__, __LINE__, "-- handling the request as Indexfile"); + log_error(con->conf.errh, __FILE__, __LINE__, "URI : %s", con->uri.path->ptr); } /* indexfile */ @@ -145,10 +145,9 @@ URIHANDLER_FUNC(mod_indexfile_subrequest) { errno != ENOTDIR) { /* we have no idea what happend. let's tell the user so. */ con->http_status = 500; - log_error_write(srv, __FILE__, __LINE__, "ssbsb", - "file not found ... or so: ", strerror(errno), - con->uri.path, - "->", con->physical.path); + log_perror(con->conf.errh, __FILE__, __LINE__, + "file not found ... or so: %s -> %s", + con->uri.path->ptr, con->physical.path->ptr); buffer_reset(con->physical.path); return HANDLER_FINISHED; } diff --git a/src/mod_magnet.c b/src/mod_magnet.c index 48830af5..e92f103e 100644 --- a/src/mod_magnet.c +++ b/src/mod_magnet.c @@ -284,8 +284,8 @@ static buffer* magnet_checkbuffer(lua_State *L, int index) { static int magnet_print(lua_State *L) { const_buffer cb = magnet_checkconstbuffer(L, 1); - log_error_write(magnet_get_server(L), __FILE__, __LINE__, "ss", - "(lua-print)", cb.ptr); + connection *con = magnet_get_connection(L); + log_error(con->conf.errh, __FILE__, __LINE__, "(lua-print) %s", cb.ptr); return 0; } @@ -375,8 +375,8 @@ static int magnet_stat(lua_State *L) { static int magnet_atpanic(lua_State *L) { const_buffer cb = magnet_checkconstbuffer(L, 1); - log_error_write(magnet_get_server(L), __FILE__, __LINE__, "ss", - "(lua-atpanic)", cb.ptr); + connection *con = magnet_get_connection(L); + log_error(con->conf.errh, __FILE__, __LINE__, "(lua-atpanic) %s", cb.ptr); longjmp(exceptionjmp, 1); } @@ -684,7 +684,7 @@ static int magnet_copy_response_header(connection *con, lua_State *L, int lighty * * return 200 */ -static int magnet_attach_content(server *srv, connection *con, lua_State *L, int lighty_table_ndx) { +static int magnet_attach_content(connection *con, lua_State *L, int lighty_table_ndx) { force_assert(lua_istable(L, lighty_table_ndx)); lua_getfield(L, lighty_table_ndx, "content"); /* lighty.content */ @@ -720,7 +720,7 @@ static int magnet_attach_content(server *srv, connection *con, lua_State *L, int if (0 != len) { buffer *fn = magnet_checkbuffer(L, -3); - int rc = http_chunk_append_file_range(srv, con, fn, off, len); + int rc = http_chunk_append_file_range(con, fn, off, len); buffer_free(fn); if (0 != rc) { return luaL_error(L, "error opening file content '%s' at offset %lld", lua_tostring(L, -3), (long long)off); @@ -791,12 +791,8 @@ static handler_t magnet_attract(server *srv, connection *con, plugin_data *p, bu L = script_cache_get_script(srv, con, &p->cache, name); if (lua_isstring(L, -1)) { - log_error_write(srv, __FILE__, __LINE__, - "sbss", - "loading script", - name, - "failed:", - lua_tostring(L, -1)); + log_error(con->conf.errh, __FILE__, __LINE__, + "loading script %s failed: %s", name->ptr, lua_tostring(L, -1)); lua_pop(L, 1); @@ -937,10 +933,8 @@ static handler_t magnet_attract(server *srv, connection *con, plugin_data *p, bu magnet_setfenv_mainfn(L, 1); /* (sp -= 1) */ if (0 != ret) { - log_error_write(srv, __FILE__, __LINE__, - "ss", - "lua_pcall():", - lua_tostring(L, -1)); + log_error(con->conf.errh, __FILE__, __LINE__, + "lua_pcall(): %s", lua_tostring(L, -1)); lua_pop(L, 2); /* remove the error-msg and the lighty table at index 2 */ force_assert(lua_gettop(L) == 1); /* only the function should be on the stack */ @@ -961,10 +955,8 @@ static handler_t magnet_attract(server *srv, connection *con, plugin_data *p, bu lua_return_value = (int) luaL_optinteger(L, -1, -1); break; default: - log_error_write(srv, __FILE__, __LINE__, "sss", - "lua_pcall():", - "unexpected return type:", - luaL_typename(L, -1)); + log_error(con->conf.errh, __FILE__, __LINE__, + "lua_pcall(): unexpected return type: %s", luaL_typename(L, -1)); lua_return_value = -1; break; } @@ -982,7 +974,7 @@ static handler_t magnet_attract(server *srv, connection *con, plugin_data *p, bu /* try { ...*/ if (0 == setjmp(exceptionjmp)) { - magnet_attach_content(srv, con, L, lighty_table_ndx); + magnet_attach_content(con, L, lighty_table_ndx); if (!chunkqueue_is_empty(con->write_queue)) { con->mode = p->id; } diff --git a/src/mod_mysql_vhost.c b/src/mod_mysql_vhost.c index 88f6f7a3..d9979ef1 100644 --- a/src/mod_mysql_vhost.c +++ b/src/mod_mysql_vhost.c @@ -1,7 +1,6 @@ #include "first.h" #include -#include #include #include @@ -165,7 +164,7 @@ static MYSQL * mod_mysql_vhost_db_setup (server *srv, const char *dbname, const #endif if (!mysql_real_connect(my, host, user, pass, dbname, port, sock, flags)) { - log_error_write(srv, __FILE__, __LINE__, "s", mysql_error(my)); + log_error(srv->errh, __FILE__, __LINE__, "%s", mysql_error(my)); mysql_close(my); return NULL; } @@ -310,7 +309,7 @@ CONNECTION_FUNC(mod_mysql_vhost_handle_docroot) { } } if (mysql_real_query(p->conf.mysql, CONST_BUF_LEN(b))) { - log_error_write(srv, __FILE__, __LINE__, "s", mysql_error(p->conf.mysql)); + log_error(con->conf.errh, __FILE__, __LINE__, "%s", mysql_error(p->conf.mysql)); goto ERR500; } result = mysql_store_result(p->conf.mysql); @@ -330,11 +329,11 @@ CONNECTION_FUNC(mod_mysql_vhost_handle_docroot) { buffer_append_slash(b); if (HANDLER_ERROR == stat_cache_get_entry(srv, con, b, &sce)) { - log_error_write(srv, __FILE__, __LINE__, "sb", strerror(errno), b); + log_perror(con->conf.errh, __FILE__, __LINE__, "%s", b->ptr); goto ERR500; } if (!S_ISDIR(sce->st.st_mode)) { - log_error_write(srv, __FILE__, __LINE__, "sb", "Not a directory", b); + log_error(con->conf.errh, __FILE__, __LINE__, "Not a directory %s", b->ptr); goto ERR500; } diff --git a/src/mod_openssl.c b/src/mod_openssl.c index 67647862..4796aa1d 100644 --- a/src/mod_openssl.c +++ b/src/mod_openssl.c @@ -173,8 +173,8 @@ static int mod_openssl_init_once_openssl (server *srv) ssl_is_init = 1; if (0 == RAND_status()) { - log_error_write(srv, __FILE__, __LINE__, "ss", "SSL:", - "not enough entropy in the pool"); + log_error(srv->errh, __FILE__, __LINE__, + "SSL: not enough entropy in the pool"); return 0; } @@ -420,7 +420,6 @@ verify_callback(int preverify_ok, X509_STORE_CTX *ctx) int err, depth; SSL *ssl; handler_ctx *hctx; - server *srv; err = X509_STORE_CTX_get_error(ctx); depth = X509_STORE_CTX_get_error_depth(ctx); @@ -431,7 +430,6 @@ verify_callback(int preverify_ok, X509_STORE_CTX *ctx) */ ssl = X509_STORE_CTX_get_ex_data(ctx, SSL_get_ex_data_X509_STORE_CTX_idx()); hctx = (handler_ctx *) SSL_get_app_data(ssl); - srv = hctx->srv; /* * Catch a too long certificate chain. The depth limit set using @@ -488,10 +486,10 @@ verify_callback(int preverify_ok, X509_STORE_CTX *ctx) #endif if (NULL == err_cert) return !hctx->conf.ssl_verifyclient_enforce; safer_X509_NAME_oneline(X509_get_subject_name(err_cert),buf,sizeof(buf)); - log_error_write(srv, __FILE__, __LINE__, "SDSSSDSS", - "SSL: verify error:num=", err, ":", - X509_verify_cert_error_string(err), ":depth=", depth, - ":subject=", buf); + log_error_st *errh = hctx->con->conf.errh; + log_error(errh, __FILE__, __LINE__, + "SSL: verify error:num=%d:%s:depth=%d:subject=%s", + err, X509_verify_cert_error_string(err), depth, buf); /* * At this point, err contains the last verification error. We can use @@ -500,7 +498,7 @@ verify_callback(int preverify_ok, X509_STORE_CTX *ctx) if (!preverify_ok && (err == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY || err == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT)) { safer_X509_NAME_oneline(X509_get_issuer_name(err_cert),buf,sizeof(buf)); - log_error_write(srv, __FILE__, __LINE__, "SS", "SSL: issuer=", buf); + log_error(errh, __FILE__, __LINE__, "SSL: issuer=%s", buf); } return !hctx->conf.ssl_verifyclient_enforce; @@ -508,16 +506,16 @@ verify_callback(int preverify_ok, X509_STORE_CTX *ctx) #ifndef OPENSSL_NO_TLSEXT static int -mod_openssl_SNI (SSL *ssl, server *srv, handler_ctx *hctx, const char *servername, size_t len) +mod_openssl_SNI (SSL *ssl, handler_ctx *hctx, const char *servername, size_t len) { + connection * const con = hctx->con; if (len >= 1024) { /*(expecting < 256; TLSEXT_MAXLEN_host_name is 255)*/ - log_error(srv->errh, __FILE__, __LINE__, + log_error(con->conf.errh, __FILE__, __LINE__, "SSL: SNI name too long %.*s", (int)len, servername); return SSL_TLSEXT_ERR_ALERT_FATAL; } /* use SNI to patch mod_openssl config and then reset COMP_HTTP_HOST */ - connection * const con = hctx->con; buffer_copy_string_len(con->uri.authority, servername, len); buffer_to_lower(con->uri.authority); #if 0 @@ -544,7 +542,7 @@ mod_openssl_SNI (SSL *ssl, server *srv, handler_ctx *hctx, const char *servernam || NULL == hctx->conf.ssl_pemfile_pkey) { /* x509/pkey available <=> pemfile was set <=> pemfile got patched: * so this should never happen, unless you nest $SERVER["socket"] */ - log_error(srv->errh, __FILE__, __LINE__, + log_error(con->conf.errh, __FILE__, __LINE__, "SSL: no certificate/private key for TLS server name %s", con->uri.authority->ptr); return SSL_TLSEXT_ERR_ALERT_FATAL; @@ -553,14 +551,14 @@ mod_openssl_SNI (SSL *ssl, server *srv, handler_ctx *hctx, const char *servernam /* first set certificate! * setting private key checks whether certificate matches it */ if (1 != SSL_use_certificate(ssl, hctx->conf.ssl_pemfile_x509)) { - log_error(srv->errh, __FILE__, __LINE__, + log_error(con->conf.errh, __FILE__, __LINE__, "SSL: failed to set certificate for TLS server name %s: %s", con->uri.authority->ptr, ERR_error_string(ERR_get_error(), NULL)); return SSL_TLSEXT_ERR_ALERT_FATAL; } if (1 != SSL_use_PrivateKey(ssl, hctx->conf.ssl_pemfile_pkey)) { - log_error(srv->errh, __FILE__, __LINE__, + log_error(con->conf.errh, __FILE__, __LINE__, "SSL: failed to set private key for TLS server name %s: %s", con->uri.authority->ptr, ERR_error_string(ERR_get_error(), NULL)); return SSL_TLSEXT_ERR_ALERT_FATAL; @@ -573,11 +571,10 @@ mod_openssl_SNI (SSL *ssl, server *srv, handler_ctx *hctx, const char *servernam ? hctx->conf.ssl_ca_dn_file : hctx->conf.ssl_ca_file; if (NULL == cert_names) { - log_error_write(srv, __FILE__, __LINE__, "ssb:s", "SSL:", - "can't verify client without ssl.ca-file " - "or ssl.ca-dn-file for TLS server name", - con->uri.authority, - ERR_error_string(ERR_get_error(), NULL)); + log_error(con->conf.errh, __FILE__, __LINE__, + "SSL: can't verify client without ssl.ca-file " + "or ssl.ca-dn-file for TLS server name %s: %s", + con->uri.authority->ptr, ERR_error_string(ERR_get_error(), NULL)); return SSL_TLSEXT_ERR_ALERT_FATAL; } @@ -603,6 +600,7 @@ mod_openssl_client_hello_cb (SSL *ssl, int *al, void *srv) { handler_ctx *hctx = (handler_ctx *) SSL_get_app_data(ssl); buffer_copy_string(hctx->con->uri.scheme, "https"); + UNUSED(srv); const unsigned char *name; size_t len, slen; @@ -615,7 +613,7 @@ mod_openssl_client_hello_cb (SSL *ssl, int *al, void *srv) && (size_t)((name[0] << 8) + name[1]) == len-2 && name[2] == TLSEXT_TYPE_server_name && (slen = (name[3] << 8) + name[4]) <= len-5) { /*(first)*/ - int rc = mod_openssl_SNI(ssl, srv, hctx, (const char *)name+5, slen); + int rc = mod_openssl_SNI(ssl, hctx, (const char *)name+5, slen); if (rc == SSL_TLSEXT_ERR_OK) return SSL_CLIENT_HELLO_SUCCESS; } @@ -630,10 +628,11 @@ network_ssl_servername_callback (SSL *ssl, int *al, server *srv) handler_ctx *hctx = (handler_ctx *) SSL_get_app_data(ssl); buffer_copy_string(hctx->con->uri.scheme, "https"); UNUSED(al); + UNUSED(srv); const char *servername = SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name); return (NULL != servername) - ? mod_openssl_SNI(ssl, srv, hctx, servername, strlen(servername)) + ? mod_openssl_SNI(ssl, hctx, servername, strlen(servername)) : SSL_TLSEXT_ERR_NOACK; /* client did not provide SNI */ } #endif @@ -641,28 +640,28 @@ network_ssl_servername_callback (SSL *ssl, int *al, server *srv) static X509 * -x509_load_pem_file (server *srv, const char *file) +x509_load_pem_file (const char *file, log_error_st *errh) { BIO *in; X509 *x = NULL; in = BIO_new(BIO_s_file()); if (NULL == in) { - log_error_write(srv, __FILE__, __LINE__, "S", - "SSL: BIO_new(BIO_s_file()) failed"); + log_error(errh, __FILE__, __LINE__, + "SSL: BIO_new(BIO_s_file()) failed"); goto error; } if (BIO_read_filename(in,file) <= 0) { - log_error_write(srv, __FILE__, __LINE__, "SSS", - "SSL: BIO_read_filename('", file,"') failed"); + log_error(errh, __FILE__, __LINE__, + "SSL: BIO_read_filename('%s') failed", file); goto error; } x = PEM_read_bio_X509(in, NULL, NULL, NULL); if (NULL == x) { - log_error_write(srv, __FILE__, __LINE__, "SSS", - "SSL: couldn't read X509 certificate from '", file,"'"); + log_error(errh, __FILE__, __LINE__, + "SSL: couldn't read X509 certificate from '%s'", file); goto error; } @@ -676,28 +675,28 @@ error: static EVP_PKEY * -evp_pkey_load_pem_file (server *srv, const char *file) +evp_pkey_load_pem_file (const char *file, log_error_st *errh) { BIO *in; EVP_PKEY *x = NULL; in = BIO_new(BIO_s_file()); if (NULL == in) { - log_error_write(srv, __FILE__, __LINE__, "s", - "SSL: BIO_new(BIO_s_file()) failed"); + log_error(errh, __FILE__, __LINE__, + "SSL: BIO_new(BIO_s_file()) failed"); goto error; } if (BIO_read_filename(in,file) <= 0) { - log_error_write(srv, __FILE__, __LINE__, "SSS", - "SSL: BIO_read_filename('", file,"') failed"); + log_error(errh, __FILE__, __LINE__, + "SSL: BIO_read_filename('%s') failed", file); goto error; } x = PEM_read_bio_PrivateKey(in, NULL, NULL, NULL); if (NULL == x) { - log_error_write(srv, __FILE__, __LINE__, "SSS", - "SSL: couldn't read private key from '", file,"'"); + log_error(errh, __FILE__, __LINE__, + "SSL: couldn't read private key from '%s'", file); goto error; } @@ -715,11 +714,11 @@ network_openssl_load_pemfile (server *srv, const buffer *pemfile, const buffer * { if (!mod_openssl_init_once_openssl(srv)) return NULL; - X509 *ssl_pemfile_x509 = x509_load_pem_file(srv, pemfile->ptr); + X509 *ssl_pemfile_x509 = x509_load_pem_file(pemfile->ptr, srv->errh); if (NULL == ssl_pemfile_x509) return NULL; - EVP_PKEY *ssl_pemfile_pkey = evp_pkey_load_pem_file(srv, privkey->ptr); + EVP_PKEY *ssl_pemfile_pkey = evp_pkey_load_pem_file(privkey->ptr, srv->errh); if (NULL == ssl_pemfile_pkey) { X509_free(ssl_pemfile_x509); return NULL; @@ -752,9 +751,9 @@ network_openssl_load_pemfile (server *srv, const buffer *pemfile, const buffer * static int mod_openssl_acme_tls_1 (SSL *ssl, handler_ctx *hctx) { - server *srv = hctx->srv; - buffer *b = srv->tmp_buf; + buffer * const b = hctx->srv->tmp_buf; buffer *name = hctx->con->uri.authority; + log_error_st *errh = hctx->con->conf.errh; X509 *ssl_pemfile_x509 = NULL; EVP_PKEY *ssl_pemfile_pkey = NULL; size_t len; @@ -781,27 +780,28 @@ mod_openssl_acme_tls_1 (SSL *ssl, handler_ctx *hctx) do { buffer_append_string_len(b, CONST_STR_LEN(".crt.pem")); - ssl_pemfile_x509 = x509_load_pem_file(srv, b->ptr); + ssl_pemfile_x509 = x509_load_pem_file(b->ptr, errh); if (NULL == ssl_pemfile_x509) { - log_error_write(srv, __FILE__, __LINE__, "ssb", "SSL:", - "Failed to load acme-tls/1 pemfile:", b); + log_error(errh, __FILE__, __LINE__, + "SSL: Failed to load acme-tls/1 pemfile: %s", b->ptr); break; } buffer_string_set_length(b, len); /*(remove ".crt.pem")*/ buffer_append_string_len(b, CONST_STR_LEN(".key.pem")); - ssl_pemfile_pkey = evp_pkey_load_pem_file(srv, b->ptr); + ssl_pemfile_pkey = evp_pkey_load_pem_file(b->ptr, errh); if (NULL == ssl_pemfile_pkey) { - log_error_write(srv, __FILE__, __LINE__, "ssb", "SSL:", - "Failed to load acme-tls/1 pemfile:", b); + log_error(errh, __FILE__, __LINE__, + "SSL: Failed to load acme-tls/1 pemfile: %s", b->ptr); break; } #if 0 /* redundant with below? */ if (!X509_check_private_key(ssl_pemfile_x509, ssl_pemfile_pkey)) { - log_error_write(srv, __FILE__, __LINE__, "sssb", "SSL:", - "Private key does not match acme-tls/1 certificate public key," - " reason:" ERR_error_string(ERR_get_error(), NULL), b); + log_error(errh, __FILE__, __LINE__, + "SSL: Private key does not match acme-tls/1 " + "certificate public key, reason: %s %s" + ERR_error_string(ERR_get_error(), NULL), b->ptr); break; } #endif @@ -809,16 +809,16 @@ mod_openssl_acme_tls_1 (SSL *ssl, handler_ctx *hctx) /* first set certificate! * setting private key checks whether certificate matches it */ if (1 != SSL_use_certificate(ssl, ssl_pemfile_x509)) { - log_error_write(srv, __FILE__, __LINE__, "ssb:s", "SSL:", - "failed to set acme-tls/1 certificate for TLS server name", - name, ERR_error_string(ERR_get_error(), NULL)); + log_error(errh, __FILE__, __LINE__, + "SSL: failed to set acme-tls/1 certificate for TLS server " + "name %s: %s", name->ptr, ERR_error_string(ERR_get_error(),NULL)); break; } if (1 != SSL_use_PrivateKey(ssl, ssl_pemfile_pkey)) { - log_error_write(srv, __FILE__, __LINE__, "ssb:s", "SSL:", - "failed to set acme-tls/1 private key for TLS server name", - name, ERR_error_string(ERR_get_error(), NULL)); + log_error(errh, __FILE__, __LINE__, + "SSL: failed to set acme-tls/1 private key for TLS server " + "name %s: %s", name->ptr, ERR_error_string(ERR_get_error(),NULL)); break; } @@ -933,18 +933,18 @@ network_openssl_ssl_conf_cmd (server *srv, plugin_config_socket *s) ds = (data_string *)s->ssl_conf_cmd->data[i]; ERR_clear_error(); if (SSL_CONF_cmd(cctx, ds->key.ptr, ds->value.ptr) <= 0) { - log_error_write(srv, __FILE__, __LINE__, "ssbbss", "SSL:", - "SSL_CONF_cmd", &ds->key, &ds->value, ":", - ERR_error_string(ERR_get_error(), NULL)); + log_error(srv->errh, __FILE__, __LINE__, + "SSL: SSL_CONF_cmd %s %s: %s", ds->key.ptr, ds->value.ptr, + ERR_error_string(ERR_get_error(), NULL)); rc = -1; break; } } if (0 == rc && 1 != SSL_CONF_CTX_finish(cctx)) { - log_error_write(srv, __FILE__, __LINE__, "sss", "SSL:", - "SSL_CONF_CTX_finish():", - ERR_error_string(ERR_get_error(), NULL)); + log_error(srv->errh, __FILE__, __LINE__, + "SSL: SSL_CONF_CTX_finish(): %s", + ERR_error_string(ERR_get_error(), NULL)); rc = -1; } @@ -954,8 +954,8 @@ network_openssl_ssl_conf_cmd (server *srv, plugin_config_socket *s) #else UNUSED(s); - log_error_write(srv, __FILE__, __LINE__, "ss", "SSL:", - "ssl.openssl.ssl-conf-cmd not available; ignored"); + log_error(srv->errh, __FILE__, __LINE__, + "SSL: ssl.openssl.ssl-conf-cmd not available; ignored"); return 0; #endif @@ -1026,8 +1026,8 @@ network_init_ssl (server *srv, plugin_config_socket *s, plugin_data *p) s->ssl_ctx = SSL_CTX_new(SSLv23_server_method()); #endif if (NULL == s->ssl_ctx) { - log_error_write(srv, __FILE__, __LINE__, "ss", "SSL:", - ERR_error_string(ERR_get_error(), NULL)); + log_error(srv->errh, __FILE__, __LINE__, + "SSL: %s", ERR_error_string(ERR_get_error(), NULL)); return -1; } @@ -1035,9 +1035,9 @@ network_init_ssl (server *srv, plugin_config_socket *s, plugin_data *p) * required for client cert verification to work with sessions */ if (0 == SSL_CTX_set_session_id_context( s->ssl_ctx,(const unsigned char*)CONST_STR_LEN("lighttpd"))){ - log_error_write(srv, __FILE__, __LINE__, "ss:s", "SSL:", - "failed to set session context", - ERR_error_string(ERR_get_error(), NULL)); + log_error(srv->errh, __FILE__, __LINE__, + "SSL: failed to set session context: %s", + ERR_error_string(ERR_get_error(), NULL)); return -1; } @@ -1046,9 +1046,9 @@ network_init_ssl (server *srv, plugin_config_socket *s, plugin_data *p) ssloptions &= ~SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS; #else ssloptions &= ~0x00000800L; /* hardcode constant */ - log_error_write(srv, __FILE__, __LINE__, "ss", "WARNING: SSL:", - "'insert empty fragments' not supported by the " - "openssl version used to compile lighttpd with"); + log_error(srv->errh, __FILE__, __LINE__, + "WARNING: SSL: 'insert empty fragments' not supported by the " + "openssl version used to compile lighttpd with"); #endif } @@ -1061,8 +1061,8 @@ network_init_ssl (server *srv, plugin_config_socket *s, plugin_data *p) if ((SSL_OP_NO_SSLv2 & SSL_CTX_set_options(s->ssl_ctx, SSL_OP_NO_SSLv2)) != SSL_OP_NO_SSLv2) { - log_error_write(srv, __FILE__, __LINE__, "ss", "SSL:", - ERR_error_string(ERR_get_error(), NULL)); + log_error(srv->errh, __FILE__, __LINE__, + "SSL: %s", ERR_error_string(ERR_get_error(), NULL)); return -1; } } @@ -1073,8 +1073,8 @@ network_init_ssl (server *srv, plugin_config_socket *s, plugin_data *p) if ((SSL_OP_NO_SSLv3 & SSL_CTX_set_options(s->ssl_ctx, SSL_OP_NO_SSLv3)) != SSL_OP_NO_SSLv3) { - log_error_write(srv, __FILE__, __LINE__, "ss", "SSL:", - ERR_error_string(ERR_get_error(), NULL)); + log_error(srv->errh, __FILE__, __LINE__, + "SSL: %s", ERR_error_string(ERR_get_error(), NULL)); return -1; } } @@ -1082,8 +1082,8 @@ network_init_ssl (server *srv, plugin_config_socket *s, plugin_data *p) if (!buffer_string_is_empty(s->ssl_cipher_list)) { /* Disable support for low encryption ciphers */ if (SSL_CTX_set_cipher_list(s->ssl_ctx,s->ssl_cipher_list->ptr)!=1){ - log_error_write(srv, __FILE__, __LINE__, "ss", "SSL:", - ERR_error_string(ERR_get_error(), NULL)); + log_error(srv->errh, __FILE__, __LINE__, + "SSL: %s", ERR_error_string(ERR_get_error(), NULL)); return -1; } @@ -1101,17 +1101,15 @@ network_init_ssl (server *srv, plugin_config_socket *s, plugin_data *p) BIO *bio; bio = BIO_new_file((char *) s->ssl_dh_file->ptr, "r"); if (bio == NULL) { - log_error_write(srv, __FILE__, __LINE__, "ss", - "SSL: Unable to open file", - s->ssl_dh_file->ptr); + log_error(srv->errh, __FILE__, __LINE__, + "SSL: Unable to open file %s", s->ssl_dh_file->ptr); return -1; } dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL); BIO_free(bio); if (dh == NULL) { - log_error_write(srv, __FILE__, __LINE__, "ss", - "SSL: PEM_read_bio_DHparams failed", - s->ssl_dh_file->ptr); + log_error(srv->errh, __FILE__, __LINE__, + "SSL: PEM_read_bio_DHparams failed %s", s->ssl_dh_file->ptr); return -1; } } else { @@ -1119,16 +1117,16 @@ network_init_ssl (server *srv, plugin_config_socket *s, plugin_data *p) /* Default DH parameters from RFC5114 */ dh = DH_new(); if (dh == NULL) { - log_error_write(srv, __FILE__, __LINE__, "s", - "SSL: DH_new () failed"); + log_error(srv->errh, __FILE__, __LINE__, + "SSL: DH_new () failed"); return -1; } dh_p = BN_bin2bn(dh1024_p,sizeof(dh1024_p), NULL); dh_g = BN_bin2bn(dh1024_g,sizeof(dh1024_g), NULL); if ((dh_p == NULL) || (dh_g == NULL)) { DH_free(dh); - log_error_write(srv, __FILE__, __LINE__, "s", - "SSL: BN_bin2bn () failed"); + log_error(srv->errh, __FILE__, __LINE__, + "SSL: BN_bin2bn () failed"); return -1; } #if OPENSSL_VERSION_NUMBER < 0x10100000L \ @@ -1147,9 +1145,9 @@ network_init_ssl (server *srv, plugin_config_socket *s, plugin_data *p) } #else if (!buffer_string_is_empty(s->ssl_dh_file)) { - log_error_write(srv, __FILE__, __LINE__, "ss", - "SSL: openssl compiled without DH support, " - "can't load parameters from", s->ssl_dh_file->ptr); + log_error(srv->errh, __FILE__, __LINE__, + "SSL: openssl compiled without DH support, " + "can't load parameters from %s", s->ssl_dh_file->ptr); } #endif @@ -1163,9 +1161,8 @@ network_init_ssl (server *srv, plugin_config_socket *s, plugin_data *p) * from RFC 4492, section 5.1.1. */ nid = OBJ_sn2nid((char *) s->ssl_ec_curve->ptr); if (nid == 0) { - log_error_write(srv, __FILE__, __LINE__, "ss", - "SSL: Unknown curve name", - s->ssl_ec_curve->ptr); + log_error(srv->errh, __FILE__, __LINE__, + "SSL: Unknown curve name %s", s->ssl_ec_curve->ptr); return -1; } } else { @@ -1175,8 +1172,8 @@ network_init_ssl (server *srv, plugin_config_socket *s, plugin_data *p) #elif OPENSSL_VERSION_NUMBER < 0x10100000L \ || defined(LIBRESSL_VERSION_NUMBER) if (!SSL_CTX_set_ecdh_auto(s->ssl_ctx, 1)) { - log_error_write(srv, __FILE__, __LINE__, "s", - "SSL: SSL_CTX_set_ecdh_auto() failed"); + log_error(srv->errh, __FILE__, __LINE__, + "SSL: SSL_CTX_set_ecdh_auto() failed"); } #endif } @@ -1184,9 +1181,8 @@ network_init_ssl (server *srv, plugin_config_socket *s, plugin_data *p) EC_KEY *ecdh; ecdh = EC_KEY_new_by_curve_name(nid); if (ecdh == NULL) { - log_error_write(srv, __FILE__, __LINE__, "ss", - "SSL: Unable to create curve", - s->ssl_ec_curve->ptr); + log_error(srv->errh, __FILE__, __LINE__, + "SSL: Unable to create curve %s", s->ssl_ec_curve->ptr); return -1; } SSL_CTX_set_tmp_ecdh(s->ssl_ctx,ecdh); @@ -1207,9 +1203,9 @@ network_init_ssl (server *srv, plugin_config_socket *s, plugin_data *p) ? s->ssl_ca_dn_file : s->ssl_ca_file; if (NULL == cert_names) { - log_error_write(srv, __FILE__, __LINE__, "s", - "SSL: You specified ssl.verifyclient.activate " - "but no ssl.ca-file or ssl.ca-dn-file"); + log_error(srv->errh, __FILE__, __LINE__, + "SSL: You specified ssl.verifyclient.activate " + "but no ssl.ca-file or ssl.ca-dn-file"); return -1; } SSL_CTX_set_client_CA_list(s->ssl_ctx, SSL_dup_CA_list(cert_names)); @@ -1222,8 +1218,9 @@ network_init_ssl (server *srv, plugin_config_socket *s, plugin_data *p) if (!buffer_string_is_empty(s->ssl_ca_crl_file)) { X509_STORE *store = SSL_CTX_get_cert_store(s->ssl_ctx); if (1 != X509_STORE_load_locations(store, s->ssl_ca_crl_file->ptr, NULL)) { - log_error_write(srv, __FILE__, __LINE__, "ssb", "SSL:", - ERR_error_string(ERR_get_error(), NULL), s->ssl_ca_crl_file); + log_error(srv->errh, __FILE__, __LINE__, + "SSL: %s %s", ERR_error_string(ERR_get_error(), NULL), + s->ssl_ca_crl_file->ptr); return -1; } X509_STORE_set_flags(store, X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL); @@ -1232,25 +1229,24 @@ network_init_ssl (server *srv, plugin_config_socket *s, plugin_data *p) if (1 != SSL_CTX_use_certificate_chain_file(s->ssl_ctx, s->ssl_pemfile->ptr)) { - log_error_write(srv, __FILE__, __LINE__, "ssb", "SSL:", - ERR_error_string(ERR_get_error(), NULL), - s->ssl_pemfile); + log_error(srv->errh, __FILE__, __LINE__, + "SSL: %s %s", ERR_error_string(ERR_get_error(), NULL), + s->ssl_pemfile->ptr); return -1; } if (1 != SSL_CTX_use_PrivateKey(s->ssl_ctx, s->ssl_pemfile_pkey)) { - log_error_write(srv, __FILE__, __LINE__, "ssbb", "SSL:", - ERR_error_string(ERR_get_error(), NULL), - s->ssl_pemfile, s->ssl_privkey); + log_error(srv->errh, __FILE__, __LINE__, + "SSL: %s %s %s", ERR_error_string(ERR_get_error(), NULL), + s->ssl_pemfile->ptr, s->ssl_privkey->ptr); return -1; } if (SSL_CTX_check_private_key(s->ssl_ctx) != 1) { - log_error_write(srv, __FILE__, __LINE__, "sssbb", "SSL:", - "Private key does not match the certificate public " - "key, reason:", - ERR_error_string(ERR_get_error(), NULL), - s->ssl_pemfile, s->ssl_privkey); + log_error(srv->errh, __FILE__, __LINE__, + "SSL: Private key does not match the certificate public key, " + "reason: %s %s %s", ERR_error_string(ERR_get_error(), NULL), + s->ssl_pemfile->ptr, s->ssl_privkey->ptr); return -1; } SSL_CTX_set_default_read_ahead(s->ssl_ctx, s->ssl_read_ahead); @@ -1266,10 +1262,9 @@ network_init_ssl (server *srv, plugin_config_socket *s, plugin_data *p) if (!SSL_CTX_set_tlsext_servername_callback( s->ssl_ctx, network_ssl_servername_callback) || !SSL_CTX_set_tlsext_servername_arg(s->ssl_ctx, srv)) { - log_error_write(srv, __FILE__, __LINE__, "ss", "SSL:", - "failed to initialize TLS servername callback, " - "openssl library does not support TLS servername " - "extension"); + log_error(srv->errh, __FILE__, __LINE__, + "SSL: failed to initialize TLS servername callback, " + "openssl library does not support TLS servername extension"); return -1; } #endif @@ -1694,7 +1689,7 @@ SETDEFAULTS_FUNC(mod_openssl_set_defaults) static int -load_next_chunk (server *srv, chunkqueue *cq, off_t max_bytes, +load_next_chunk (connection *con, chunkqueue *cq, off_t max_bytes, const char **data, size_t *data_len) { chunk *c = cq->first; @@ -1752,7 +1747,7 @@ load_next_chunk (server *srv, chunkqueue *cq, off_t max_bytes, return 0; case FILE_CHUNK: - if (0 != chunkqueue_open_file_chunk(srv, cq)) return -1; + if (0 != chunkqueue_open_file_chunk(cq, con->conf.errh)) return -1; { off_t offset, toSend; @@ -1765,13 +1760,11 @@ load_next_chunk (server *srv, chunkqueue *cq, off_t max_bytes, if (toSend > max_bytes) toSend = max_bytes; if (-1 == lseek(c->file.fd, offset, SEEK_SET)) { - log_error_write(srv, __FILE__, __LINE__, "ss", - "lseek: ", strerror(errno)); + log_perror(con->conf.errh, __FILE__, __LINE__, "lseek"); return -1; } if (-1 == (toSend = read(c->file.fd, local_send_buffer, toSend))) { - log_error_write(srv, __FILE__, __LINE__, "ss", - "read: ", strerror(errno)); + log_perror(con->conf.errh, __FILE__, __LINE__, "read"); return -1; } @@ -1786,17 +1779,16 @@ load_next_chunk (server *srv, chunkqueue *cq, off_t max_bytes, static int -mod_openssl_close_notify(server *srv, handler_ctx *hctx); +mod_openssl_close_notify(handler_ctx *hctx); static int -connection_write_cq_ssl (server *srv, connection *con, - chunkqueue *cq, off_t max_bytes) +connection_write_cq_ssl (connection *con, chunkqueue *cq, off_t max_bytes) { handler_ctx *hctx = con->plugin_ctx[plugin_data_singleton->id]; SSL *ssl = hctx->ssl; - if (0 != hctx->close_notify) return mod_openssl_close_notify(srv, hctx); + if (0 != hctx->close_notify) return mod_openssl_close_notify(hctx); chunkqueue_remove_finished_chunks(cq); @@ -1805,7 +1797,7 @@ connection_write_cq_ssl (server *srv, connection *con, size_t data_len; int r; - if (0 != load_next_chunk(srv,cq,max_bytes,&data,&data_len)) return -1; + if (0 != load_next_chunk(con,cq,max_bytes,&data,&data_len)) return -1; /** * SSL_write man-page @@ -1821,7 +1813,7 @@ connection_write_cq_ssl (server *srv, connection *con, if (hctx->renegotiations > 1 && hctx->conf.ssl_disable_client_renegotiation) { - log_error_write(srv, __FILE__, __LINE__, "s", + log_error(con->conf.errh, __FILE__, __LINE__, "SSL: renegotiation initiated by client, killing connection"); return -1; } @@ -1841,9 +1833,8 @@ connection_write_cq_ssl (server *srv, connection *con, /* perhaps we have error waiting in our error-queue */ if (0 != (err = ERR_get_error())) { do { - log_error_write(srv, __FILE__, __LINE__, "sdds", - "SSL:", ssl_r, r, - ERR_error_string(err, NULL)); + log_error(con->conf.errh, __FILE__, __LINE__, + "SSL: %d %d %s",ssl_r,r,ERR_error_string(err,NULL)); } while((err = ERR_get_error())); } else if (r == -1) { /* no, but we have errno */ @@ -1852,16 +1843,14 @@ connection_write_cq_ssl (server *srv, connection *con, case ECONNRESET: return -2; default: - log_error_write(srv, __FILE__, __LINE__, "sddds", - "SSL:", ssl_r, r, errno, - strerror(errno)); + log_perror(con->conf.errh, __FILE__, __LINE__, + "SSL: %d %d", ssl_r, r); break; } } else { /* neither error-queue nor errno ? */ - log_error_write(srv, __FILE__, __LINE__, "sddds", - "SSL (error):", ssl_r, r, errno, - strerror(errno)); + log_perror(con->conf.errh, __FILE__, __LINE__, + "SSL (error): %d %d", ssl_r, r); } break; @@ -1873,9 +1862,8 @@ connection_write_cq_ssl (server *srv, connection *con, /* fall through */ default: while((err = ERR_get_error())) { - log_error_write(srv, __FILE__, __LINE__, "sdds", - "SSL:", ssl_r, r, - ERR_error_string(err, NULL)); + log_error(con->conf.errh, __FILE__, __LINE__, + "SSL: %d %d %s", ssl_r, r, ERR_error_string(err, NULL)); } break; } @@ -1893,8 +1881,7 @@ connection_write_cq_ssl (server *srv, connection *con, static int -connection_read_cq_ssl (server *srv, connection *con, - chunkqueue *cq, off_t max_bytes) +connection_read_cq_ssl (connection *con, chunkqueue *cq, off_t max_bytes) { handler_ctx *hctx = con->plugin_ctx[plugin_data_singleton->id]; int r, ssl_err, len; @@ -1905,7 +1892,7 @@ connection_read_cq_ssl (server *srv, connection *con, force_assert(cq == con->read_queue); UNUSED(max_bytes); - if (0 != hctx->close_notify) return mod_openssl_close_notify(srv, hctx); + if (0 != hctx->close_notify) return mod_openssl_close_notify(hctx); ERR_clear_error(); do { @@ -1923,7 +1910,7 @@ connection_read_cq_ssl (server *srv, connection *con, if (hctx->renegotiations > 1 && hctx->conf.ssl_disable_client_renegotiation) { - log_error_write(srv, __FILE__, __LINE__, "s", + log_error(con->conf.errh, __FILE__, __LINE__, "SSL: renegotiation initiated by client, killing connection"); return -1; } @@ -1976,8 +1963,8 @@ connection_read_cq_ssl (server *srv, connection *con, */ while((ssl_err = ERR_get_error())) { /* get all errors from the error-queue */ - log_error_write(srv, __FILE__, __LINE__, "sds", "SSL:", - r, ERR_error_string(ssl_err, NULL)); + log_error(con->conf.errh, __FILE__, __LINE__, + "SSL: %d %s", r, ERR_error_string(ssl_err, NULL)); } switch(oerrno) { @@ -1990,9 +1977,8 @@ connection_read_cq_ssl (server *srv, connection *con, if (0==oerrno && 0==cq->bytes_in && !hctx->conf.ssl_log_noise) break; - log_error_write(srv, __FILE__, __LINE__, "sddds", "SSL:", - len, r, oerrno, - strerror(oerrno)); + log_error(con->conf.errh, __FILE__, __LINE__, + "SSL: %d %d %d %s", len, r, oerrno, strerror(oerrno)); break; } @@ -2024,8 +2010,8 @@ connection_read_cq_ssl (server *srv, connection *con, break; } /* get all errors from the error-queue */ - log_error_write(srv, __FILE__, __LINE__, "sds", "SSL:", - r, ERR_error_string(ssl_err, NULL)); + log_error(con->conf.errh, __FILE__, __LINE__, + "SSL: %d %s", r, ERR_error_string(ssl_err, NULL)); } break; } @@ -2066,7 +2052,7 @@ CONNECTION_FUNC(mod_openssl_handle_con_accept) return HANDLER_GO_ON; } else { - log_error(srv->errh, __FILE__, __LINE__, + log_error(con->conf.errh, __FILE__, __LINE__, "SSL: %s", ERR_error_string(ERR_get_error(), NULL)); return HANDLER_ERROR; } @@ -2091,10 +2077,11 @@ CONNECTION_FUNC(mod_openssl_handle_con_shut_wr) plugin_data *p = p_d; handler_ctx *hctx = con->plugin_ctx[p->id]; if (NULL == hctx) return HANDLER_GO_ON; + UNUSED(srv); hctx->close_notify = -2; if (SSL_is_init_finished(hctx->ssl)) { - mod_openssl_close_notify(srv, hctx); + mod_openssl_close_notify(hctx); } else { mod_openssl_detach(hctx); @@ -2105,10 +2092,11 @@ CONNECTION_FUNC(mod_openssl_handle_con_shut_wr) static int -mod_openssl_close_notify(server *srv, handler_ctx *hctx) +mod_openssl_close_notify(handler_ctx *hctx) { int ret, ssl_r; unsigned long err; + log_error_st *errh; if (1 == hctx->close_notify) return -2; @@ -2175,11 +2163,11 @@ mod_openssl_close_notify(server *srv, handler_ctx *hctx) return 0; /* try again later */ case SSL_ERROR_SYSCALL: /* perhaps we have error waiting in our error-queue */ + errh = hctx->con->conf.errh; if (0 != (err = ERR_get_error())) { do { - log_error_write(srv, __FILE__, __LINE__, "sdds", - "SSL:", ssl_r, ret, - ERR_error_string(err, NULL)); + log_error(errh, __FILE__, __LINE__, + "SSL: %d %d %s",ssl_r,ret,ERR_error_string(err,NULL)); } while((err = ERR_get_error())); } else if (errno != 0) { /*ssl bug (see lighttpd ticket #2213): sometimes errno==0*/ @@ -2188,19 +2176,18 @@ mod_openssl_close_notify(server *srv, handler_ctx *hctx) case ECONNRESET: break; default: - log_error_write(srv, __FILE__, __LINE__, "sddds", - "SSL (error):", ssl_r, ret, errno, - strerror(errno)); + log_perror(errh, __FILE__, __LINE__, + "SSL (error): %d %d", ssl_r, ret); break; } } break; default: + errh = hctx->con->conf.errh; while((err = ERR_get_error())) { - log_error_write(srv, __FILE__, __LINE__, "sdds", - "SSL:", ssl_r, ret, - ERR_error_string(err, NULL)); + log_error(errh, __FILE__, __LINE__, + "SSL: %d %d %s", ssl_r, ret, ERR_error_string(err, NULL)); } break; diff --git a/src/mod_proxy.c b/src/mod_proxy.c index fcb523eb..f28e0ca6 100644 --- a/src/mod_proxy.c +++ b/src/mod_proxy.c @@ -860,8 +860,8 @@ static handler_t proxy_create_env(server *srv, gw_handler_ctx *gwhctx) { if (hctx->conf.replace_http_host && !buffer_string_is_empty(hctx->gw.host->id)) { if (hctx->gw.conf.debug > 1) { - log_error_write(srv, __FILE__, __LINE__, "SBS", - "proxy - using \"", hctx->gw.host->id, "\" as HTTP Host"); + log_error(con->conf.errh, __FILE__, __LINE__, + "proxy - using \"%s\" as HTTP Host", hctx->gw.host->id->ptr); } buffer_append_string_len(b, CONST_STR_LEN("Host: ")); buffer_append_string_buffer(b, hctx->gw.host->id); @@ -990,22 +990,22 @@ static handler_t proxy_create_env_connect(server *srv, gw_handler_ctx *gwhctx) { con->http_status = 200; /* OK */ con->file_started = 1; gw_set_transparent(srv, &hctx->gw); - http_response_upgrade_read_body_unknown(srv, con); + http_response_upgrade_read_body_unknown(con); status_counter_inc(srv, CONST_STR_LEN("proxy.requests")); return HANDLER_GO_ON; } -static handler_t proxy_response_headers(server *srv, connection *con, struct http_response_opts_t *opts) { +static handler_t proxy_response_headers(connection *con, struct http_response_opts_t *opts) { /* response headers just completed */ handler_ctx *hctx = (handler_ctx *)opts->pdata; if (con->response.htags & HTTP_HEADER_UPGRADE) { if (hctx->conf.header.upgrade && con->http_status == 101) { /* 101 Switching Protocols; transition to transparent proxy */ - gw_set_transparent(srv, &hctx->gw); - http_response_upgrade_read_body_unknown(srv, con); + gw_set_transparent(con->srv, &hctx->gw); + http_response_upgrade_read_body_unknown(con); } else { con->response.htags &= ~HTTP_HEADER_UPGRADE; diff --git a/src/mod_redirect.c b/src/mod_redirect.c index 78a0d11f..68ca7930 100644 --- a/src/mod_redirect.c +++ b/src/mod_redirect.c @@ -188,9 +188,9 @@ URIHANDLER_FUNC(mod_redirect_uri_handler) { con->file_finished = 1; } else if (HANDLER_ERROR == rc) { - log_error_write(srv, __FILE__, __LINE__, "sb", - "pcre_exec() error while processing uri:", - con->request.uri); + log_error(con->conf.errh, __FILE__, __LINE__, + "pcre_exec() error while processing uri: %s", + con->request.uri->ptr); } return rc; } diff --git a/src/mod_rewrite.c b/src/mod_rewrite.c index 9abfb3fa..0f8ad311 100644 --- a/src/mod_rewrite.c +++ b/src/mod_rewrite.c @@ -271,7 +271,7 @@ static handler_t process_rewrite_rules(server *srv, connection *con, plugin_data if (0 != kvb->x0) { config_cond_info cfginfo; config_get_config_cond_info(srv, kvb->x0, &cfginfo); - log_error(con->errh, __FILE__, __LINE__, + log_error(con->conf.errh, __FILE__, __LINE__, "ENDLESS LOOP IN rewrite-rule DETECTED ... aborting request, " "perhaps you want to use url.rewrite-once instead of " "url.rewrite-repeat ($%s %s \"%s\")", cfginfo.comp_key->ptr, @@ -279,7 +279,7 @@ static handler_t process_rewrite_rules(server *srv, connection *con, plugin_data return HANDLER_ERROR; } - log_error(con->errh, __FILE__, __LINE__, + log_error(con->conf.errh, __FILE__, __LINE__, "ENDLESS LOOP IN rewrite-rule DETECTED ... aborting request"); return HANDLER_ERROR; } @@ -313,14 +313,14 @@ static handler_t process_rewrite_rules(server *srv, connection *con, plugin_data } else if (HANDLER_FINISHED == rc) { rc = HANDLER_ERROR; - log_error_write(srv, __FILE__, __LINE__, "sb", - "mod_rewrite invalid result (not beginning with '/') while processing uri:", - con->request.uri); + log_error(con->conf.errh, __FILE__, __LINE__, + "mod_rewrite invalid result (not beginning with '/') " + "while processing uri: %s", con->request.uri->ptr); } else if (HANDLER_ERROR == rc) { - log_error_write(srv, __FILE__, __LINE__, "sb", - "pcre_exec() error while processing uri:", - con->request.uri); + log_error(con->conf.errh, __FILE__, __LINE__, + "pcre_exec() error " + "while processing uri: %s", con->request.uri->ptr); } return rc; } diff --git a/src/mod_rrdtool.c b/src/mod_rrdtool.c index 4f27ca87..3f68779c 100644 --- a/src/mod_rrdtool.c +++ b/src/mod_rrdtool.c @@ -263,8 +263,8 @@ static int mod_rrdtool_create_rrd(server *srv, plugin_data *p, rrd_config *s, ch if (0 == stat(s->path_rrd->ptr, &st)) { /* check if it is plain file */ if (!S_ISREG(st.st_mode)) { - log_error_write(srv, __FILE__, __LINE__, "sb", - "not a regular file:", s->path_rrd); + log_error(srv->errh, __FILE__, __LINE__, + "not a regular file: %s", s->path_rrd->ptr); return HANDLER_ERROR; } @@ -297,23 +297,18 @@ static int mod_rrdtool_create_rrd(server *srv, plugin_data *p, rrd_config *s, ch "RRA:MIN:0.5:288:797\n")); if (-1 == (safe_write(p->write_fd, CONST_BUF_LEN(cmd)))) { - log_error_write(srv, __FILE__, __LINE__, "ss", - "rrdtool-write: failed", strerror(errno)); - + log_perror(srv->errh, __FILE__, __LINE__, "rrdtool-write: failed"); return HANDLER_ERROR; } if (-1 == safe_read(p->read_fd, resp, respsz)) { - log_error_write(srv, __FILE__, __LINE__, "ss", - "rrdtool-read: failed", strerror(errno)); - + log_perror(srv->errh, __FILE__, __LINE__, "rrdtool-read: failed"); return HANDLER_ERROR; } if (resp[0] != 'O' || resp[1] != 'K') { - log_error_write(srv, __FILE__, __LINE__, "sbs", - "rrdtool-response:", cmd, resp); - + log_error(srv->errh, __FILE__, __LINE__, + "rrdtool-response: %s %s", cmd->ptr, resp); return HANDLER_ERROR; } diff --git a/src/mod_scgi.c b/src/mod_scgi.c index 8e5cd12a..aa9184d4 100644 --- a/src/mod_scgi.c +++ b/src/mod_scgi.c @@ -1,7 +1,6 @@ #include "first.h" #include -#include #include #include #include @@ -231,7 +230,7 @@ static handler_t scgi_create_env(server *srv, handler_ctx *hctx) { * currently limited to 64k (65535, so 5 chars) */ buffer_copy_string_len(b, CONST_STR_LEN(" ")); - if (0 != http_cgi_headers(srv, con, &opts, scgi_env_add, b)) { + if (0 != http_cgi_headers(con, &opts, scgi_env_add, b)) { con->http_status = 400; con->mode = DIRECT; buffer_clear(b); diff --git a/src/mod_secdownload.c b/src/mod_secdownload.c index 82f03b32..d419c383 100644 --- a/src/mod_secdownload.c +++ b/src/mod_secdownload.c @@ -141,8 +141,8 @@ static size_t secdl_algorithm_mac_length(secdl_algorithm alg) { return 0; } -static int secdl_verify_mac(server *srv, plugin_config *config, const char* protected_path, const char* mac, size_t maclen) { - UNUSED(srv); +static int secdl_verify_mac(plugin_config *config, const char* protected_path, const char* mac, size_t maclen, log_error_st *errh) { + UNUSED(errh); if (0 == maclen || secdl_algorithm_mac_length(config->algorithm) != maclen) return 0; switch (config->algorithm) { @@ -187,8 +187,8 @@ static int secdl_verify_mac(server *srv, plugin_config *config, const char* prot (unsigned char const*) config->secret->ptr, buffer_string_length(config->secret), (unsigned char const*) protected_path, strlen(protected_path), digest, NULL)) { - log_error_write(srv, __FILE__, __LINE__, "s", - "hmac-sha1: HMAC() failed"); + log_error(errh, __FILE__, __LINE__, + "hmac-sha1: HMAC() failed"); return 0; } @@ -209,8 +209,8 @@ static int secdl_verify_mac(server *srv, plugin_config *config, const char* prot (unsigned char const*) config->secret->ptr, buffer_string_length(config->secret), (unsigned char const*) protected_path, strlen(protected_path), digest, NULL)) { - log_error_write(srv, __FILE__, __LINE__, "s", - "hmac-sha256: HMAC() failed"); + log_error(errh, __FILE__, __LINE__, + "hmac-sha256: HMAC() failed"); return 0; } @@ -431,22 +431,22 @@ URIHANDLER_FUNC(mod_secdownload_uri_handler) { if (buffer_string_is_empty(p->conf.uri_prefix)) return HANDLER_GO_ON; if (buffer_string_is_empty(p->conf.secret)) { - log_error_write(srv, __FILE__, __LINE__, "s", - "secdownload.secret has to be set"); + log_error(con->conf.errh, __FILE__, __LINE__, + "secdownload.secret has to be set"); con->http_status = 500; return HANDLER_FINISHED; } if (buffer_string_is_empty(p->conf.doc_root)) { - log_error_write(srv, __FILE__, __LINE__, "s", - "secdownload.document-root has to be set"); + log_error(con->conf.errh, __FILE__, __LINE__, + "secdownload.document-root has to be set"); con->http_status = 500; return HANDLER_FINISHED; } if (SECDL_INVALID == p->conf.algorithm) { - log_error_write(srv, __FILE__, __LINE__, "s", - "secdownload.algorithm has to be set"); + log_error(con->conf.errh, __FILE__, __LINE__, + "secdownload.algorithm has to be set"); con->http_status = 500; return HANDLER_FINISHED; } @@ -505,13 +505,13 @@ URIHANDLER_FUNC(mod_secdownload_uri_handler) { protected_path = b->ptr; } - if (!secdl_verify_mac(srv, &p->conf, protected_path, mac_str, mac_len)) { + if (!secdl_verify_mac(&p->conf, protected_path, mac_str, mac_len, + con->conf.errh)) { con->http_status = 403; if (con->conf.log_request_handling) { - log_error_write(srv, __FILE__, __LINE__, "sb", - "mac invalid:", - con->uri.path); + log_error(con->conf.errh, __FILE__, __LINE__, + "mac invalid: %s", con->uri.path->ptr); } return HANDLER_FINISHED; diff --git a/src/mod_simple_vhost.c b/src/mod_simple_vhost.c index 4d56b786..181d2691 100644 --- a/src/mod_simple_vhost.c +++ b/src/mod_simple_vhost.c @@ -9,7 +9,6 @@ #include #include -#include typedef struct { const buffer *server_root; @@ -161,8 +160,7 @@ static int build_doc_root(server *srv, connection *con, plugin_data *p, buffer * if (HANDLER_ERROR == stat_cache_get_entry(srv, con, out, &sce)) { if (p->conf.debug) { - log_error_write(srv, __FILE__, __LINE__, "sb", - strerror(errno), out); + log_perror(con->conf.errh, __FILE__, __LINE__, "%s", out->ptr); } return 0; } else if (!S_ISDIR(sce->st.st_mode)) { diff --git a/src/mod_sockproxy.c b/src/mod_sockproxy.c index c4d62da9..72946bfb 100644 --- a/src/mod_sockproxy.c +++ b/src/mod_sockproxy.c @@ -128,7 +128,7 @@ static handler_t sockproxy_create_env_connect(server *srv, handler_ctx *hctx) { connection *con = hctx->remote_conn; con->file_started = 1; gw_set_transparent(srv, hctx); - http_response_upgrade_read_body_unknown(srv, con); + http_response_upgrade_read_body_unknown(con); status_counter_inc(srv, CONST_STR_LEN("sockproxy.requests")); return HANDLER_GO_ON; diff --git a/src/mod_ssi.c b/src/mod_ssi.c index daf878df..57ba4f46 100644 --- a/src/mod_ssi.c +++ b/src/mod_ssi.c @@ -37,9 +37,10 @@ #include "etag.h" -static handler_ctx * handler_ctx_init(plugin_data *p) { +static handler_ctx * handler_ctx_init(plugin_data *p, log_error_st *errh) { handler_ctx *hctx = calloc(1, sizeof(*hctx)); force_assert(hctx); + hctx->errh = errh; hctx->timefmt = p->timefmt; hctx->stat_fn = p->stat_fn; hctx->ssi_vars = p->ssi_vars; @@ -183,7 +184,7 @@ static int ssi_env_add(void *venv, const char *key, size_t klen, const char *val return 0; } -static int build_ssi_cgi_vars(server *srv, connection *con, handler_ctx *p) { +static int build_ssi_cgi_vars(connection *con, handler_ctx *p) { http_cgi_opts opts = { 0, 0, NULL, NULL }; /* temporarily remove Authorization from request headers * so that Authorization does not end up in SSI environment */ @@ -196,7 +197,7 @@ static int build_ssi_cgi_vars(server *srv, connection *con, handler_ctx *p) { array_reset_data_strings(p->ssi_cgi_env); - if (0 != http_cgi_headers(srv, con, &opts, ssi_env_add, p->ssi_cgi_env)) { + if (0 != http_cgi_headers(con, &opts, ssi_env_add, p->ssi_cgi_env)) { con->http_status = 400; return -1; } @@ -208,9 +209,9 @@ static int build_ssi_cgi_vars(server *srv, connection *con, handler_ctx *p) { return 0; } -static int mod_ssi_process_file(server *srv, connection *con, handler_ctx *p, struct stat *st); +static int mod_ssi_process_file(connection *con, handler_ctx *p, struct stat *st); -static int process_ssi_stmt(server *srv, connection *con, handler_ctx *p, const char **l, size_t n, struct stat *st) { +static int process_ssi_stmt(connection *con, handler_ctx *p, const char **l, size_t n, struct stat *st) { /** * @@ -273,7 +274,7 @@ static int process_ssi_stmt(server *srv, connection *con, handler_ctx *p, const size_t i, ssicmd = 0; char buf[255]; - buffer *b = NULL; + buffer *tb = NULL; static const struct { const char *var; @@ -375,36 +376,33 @@ static int process_ssi_stmt(server *srv, connection *con, handler_ctx *p, const } */ } else { - log_error_write(srv, __FILE__, __LINE__, "sss", - "ssi: unknown attribute for ", - l[1], l[i]); + log_error(con->conf.errh, __FILE__, __LINE__, + "ssi: unknown attribute for %s %s", l[1], l[i]); } } if (p->if_is_false) break; if (!var_val) { - log_error_write(srv, __FILE__, __LINE__, "sss", - "ssi: ", - l[1], "var is missing"); + log_error(con->conf.errh, __FILE__, __LINE__, + "ssi: %s var is missing", l[1]); break; } switch(var) { case SSI_ECHO_USER_NAME: { - struct passwd *pw; - - b = srv->tmp_buf; + tb = con->srv->tmp_buf; #ifdef HAVE_PWD_H + struct passwd *pw; if (NULL == (pw = getpwuid(st->st_uid))) { - buffer_copy_int(b, st->st_uid); + buffer_copy_int(tb, st->st_uid); } else { - buffer_copy_string(b, pw->pw_name); + buffer_copy_string(tb, pw->pw_name); } #else - buffer_copy_int(b, st->st_uid); + buffer_copy_int(tb, st->st_uid); #endif - chunkqueue_append_mem(con->write_queue, CONST_BUF_LEN(b)); + chunkqueue_append_mem(con->write_queue, CONST_BUF_LEN(tb)); break; } case SSI_ECHO_LAST_MODIFIED: { @@ -501,29 +499,28 @@ static int process_ssi_stmt(server *srv, connection *con, handler_ctx *p, const } else if (0 == strcmp(l[i], "virtual")) { virt_path = l[i+1]; } else { - log_error_write(srv, __FILE__, __LINE__, "sss", - "ssi: unknown attribute for ", - l[1], l[i]); + log_error(con->conf.errh, __FILE__, __LINE__, + "ssi: unknown attribute for %s %s", l[1], l[i]); } } if (!file_path && !virt_path) { - log_error_write(srv, __FILE__, __LINE__, "sss", - "ssi: ", - l[1], "file or virtual are missing"); + log_error(con->conf.errh, __FILE__, __LINE__, + "ssi: %s file or virtual is missing", l[1]); break; } if (file_path && virt_path) { - log_error_write(srv, __FILE__, __LINE__, "sss", - "ssi: ", - l[1], "only one of file and virtual is allowed here"); + log_error(con->conf.errh, __FILE__, __LINE__, + "ssi: %s only one of file and virtual is allowed here", l[1]); break; } if (p->if_is_false) break; + tb = con->srv->tmp_buf; + if (file_path) { /* current doc-root */ if (NULL == (sl = strrchr(con->physical.path->ptr, '/'))) { @@ -532,36 +529,36 @@ static int process_ssi_stmt(server *srv, connection *con, handler_ctx *p, const buffer_copy_string_len(p->stat_fn, con->physical.path->ptr, sl - con->physical.path->ptr + 1); } - buffer_copy_string(srv->tmp_buf, file_path); - buffer_urldecode_path(srv->tmp_buf); - if (!buffer_is_valid_UTF8(srv->tmp_buf)) { - log_error_write(srv, __FILE__, __LINE__, "sb", - "SSI invalid UTF-8 after url-decode:", srv->tmp_buf); + buffer_copy_string(tb, file_path); + buffer_urldecode_path(tb); + if (!buffer_is_valid_UTF8(tb)) { + log_error(con->conf.errh, __FILE__, __LINE__, + "SSI invalid UTF-8 after url-decode: %s", tb->ptr); break; } - buffer_path_simplify(srv->tmp_buf, srv->tmp_buf); - buffer_append_string_buffer(p->stat_fn, srv->tmp_buf); + buffer_path_simplify(tb, tb); + buffer_append_string_buffer(p->stat_fn, tb); } else { /* virtual */ size_t remain; if (virt_path[0] == '/') { - buffer_copy_string(srv->tmp_buf, virt_path); + buffer_copy_string(tb, virt_path); } else { /* there is always a / */ sl = strrchr(con->uri.path->ptr, '/'); - buffer_copy_string_len(srv->tmp_buf, con->uri.path->ptr, sl - con->uri.path->ptr + 1); - buffer_append_string(srv->tmp_buf, virt_path); + buffer_copy_string_len(tb, con->uri.path->ptr, sl - con->uri.path->ptr + 1); + buffer_append_string(tb, virt_path); } - buffer_urldecode_path(srv->tmp_buf); - if (!buffer_is_valid_UTF8(srv->tmp_buf)) { - log_error_write(srv, __FILE__, __LINE__, "sb", - "SSI invalid UTF-8 after url-decode:", srv->tmp_buf); + buffer_urldecode_path(tb); + if (!buffer_is_valid_UTF8(tb)) { + log_error(con->conf.errh, __FILE__, __LINE__, + "SSI invalid UTF-8 after url-decode: %s", tb->ptr); break; } - buffer_path_simplify(srv->tmp_buf, srv->tmp_buf); + buffer_path_simplify(tb, tb); /* we have an uri */ @@ -585,12 +582,12 @@ static int process_ssi_stmt(server *srv, connection *con, handler_ctx *p, const { const char *sep, *sep2; sep = con->uri.path->ptr; - sep2 = srv->tmp_buf->ptr; + sep2 = tb->ptr; for (i = 0; sep[i] && sep[i] == sep2[i]; ++i) ; while (i != 0 && sep[--i] != '/') ; /* find matching directory path */ } if (con->conf.force_lowercase_filenames) { - buffer_to_lower(srv->tmp_buf); + buffer_to_lower(tb); } remain = buffer_string_length(con->uri.path) - i; if (!con->conf.force_lowercase_filenames @@ -598,12 +595,12 @@ static int process_ssi_stmt(server *srv, connection *con, handler_ctx *p, const :(buffer_string_length(con->physical.path) >= remain && buffer_eq_icase_ssn(con->physical.path->ptr+buffer_string_length(con->physical.path)-remain, con->physical.rel_path->ptr+i, remain))) { buffer_copy_string_len(p->stat_fn, con->physical.path->ptr, buffer_string_length(con->physical.path)-remain); - buffer_append_string_len(p->stat_fn, srv->tmp_buf->ptr+i, buffer_string_length(srv->tmp_buf)-i); + buffer_append_string_len(p->stat_fn, tb->ptr+i, buffer_string_length(tb)-i); } else { /* unable to perform physical path remap here; * assume doc_root/rel_path and no remapping */ buffer_copy_buffer(p->stat_fn, con->physical.doc_root); - buffer_append_string_buffer(p->stat_fn, srv->tmp_buf); + buffer_append_string_buffer(p->stat_fn, tb); } } @@ -618,7 +615,6 @@ static int process_ssi_stmt(server *srv, connection *con, handler_ctx *p, const switch (ssicmd) { case SSI_FSIZE: - b = srv->tmp_buf; if (p->sizefmt) { int j = 0; const char *abr[] = { " B", " kB", " MB", " GB", " TB", NULL }; @@ -627,12 +623,12 @@ static int process_ssi_stmt(server *srv, connection *con, handler_ctx *p, const for (j = 0; s > 1024 && abr[j+1]; s /= 1024, j++); - buffer_copy_int(b, s); - buffer_append_string(b, abr[j]); + buffer_copy_int(tb, s); + buffer_append_string(tb, abr[j]); } else { - buffer_copy_int(b, stb.st_size); + buffer_copy_int(tb, stb.st_size); } - chunkqueue_append_mem(con->write_queue, CONST_BUF_LEN(b)); + chunkqueue_append_mem(con->write_queue, CONST_BUF_LEN(tb)); break; case SSI_FLASTMOD: if (0 == strftime(buf, sizeof(buf), p->timefmt->ptr, localtime(&t))) { @@ -667,7 +663,7 @@ static int process_ssi_stmt(server *srv, connection *con, handler_ctx *p, const /* save and restore con->physical.path, con->physical.rel_path, and con->uri.path around include * - * srv->tmp_buf contains url-decoded, path-simplified, and lowercased (if con->conf.force_lowercase) uri path of target. + * tb contains url-decoded, path-simplified, and lowercased (if con->conf.force_lowercase) uri path of target. * con->uri.path and con->physical.rel_path are set to the same since we only operate on filenames here, * not full re-run of all modules for subrequest */ upsave = con->uri.path; @@ -677,14 +673,14 @@ static int process_ssi_stmt(server *srv, connection *con, handler_ctx *p, const con->physical.path = p->stat_fn; p->stat_fn = buffer_init(); - con->uri.path = con->physical.rel_path = buffer_init_buffer(srv->tmp_buf); + con->uri.path = con->physical.rel_path = buffer_init_buffer(tb); close(fd); fd = -1; /*(ignore return value; muddle along as best we can if error occurs)*/ ++p->ssi_recursion_depth; - mod_ssi_process_file(srv, con, p, &stb); + mod_ssi_process_file(con, p, &stb); --p->ssi_recursion_depth; buffer_free(con->uri.path); @@ -701,9 +697,8 @@ static int process_ssi_stmt(server *srv, connection *con, handler_ctx *p, const if (fd >= 0) close(fd); } else { - log_error_write(srv, __FILE__, __LINE__, "sbs", - "ssi: stating failed ", - p->stat_fn, strerror(errno)); + log_perror(con->conf.errh, __FILE__, __LINE__, + "ssi: stating %s failed", p->stat_fn->ptr); } break; } @@ -715,9 +710,8 @@ static int process_ssi_stmt(server *srv, connection *con, handler_ctx *p, const } else if (0 == strcmp(l[i], "value")) { val = l[i+1]; } else { - log_error_write(srv, __FILE__, __LINE__, "sss", - "ssi: unknown attribute for ", - l[1], l[i]); + log_error(con->conf.errh, __FILE__, __LINE__, + "ssi: unknown attribute for %s %s", l[1], l[i]); } } @@ -726,11 +720,11 @@ static int process_ssi_stmt(server *srv, connection *con, handler_ctx *p, const if (key && val) { array_set_key_value(p->ssi_vars, key, strlen(key), val, strlen(val)); } else if (key || val) { - log_error_write(srv, __FILE__, __LINE__, "sSSss", - "ssi: var and value have to be set in "); + log_error(con->conf.errh, __FILE__, __LINE__, + "ssi: var and value have to be set in ", l[1], l[2]); } else { - log_error_write(srv, __FILE__, __LINE__, "s", - "ssi: var and value have to be set in "); + log_error(con->conf.errh, __FILE__, __LINE__, + "ssi: var and value have to be set in "); } break; } @@ -746,47 +740,45 @@ static int process_ssi_stmt(server *srv, connection *con, handler_ctx *p, const } else if (0 == strcmp(l[i+1], "bytes")) { p->sizefmt = 0; } else { - log_error_write(srv, __FILE__, __LINE__, "sssss", - "ssi: unknown value for attribute '", - l[i], - "' for ", - l[1], l[i+1]); + log_error(con->conf.errh, __FILE__, __LINE__, + "ssi: unknown value for attribute '%s' for %s %s", + l[i], l[1], l[i+1]); } } else { - log_error_write(srv, __FILE__, __LINE__, "sss", - "ssi: unknown attribute for ", - l[1], l[i]); + log_error(con->conf.errh, __FILE__, __LINE__, + "ssi: unknown attribute for %s %s", l[1], l[i]); } } break; case SSI_PRINTENV: if (p->if_is_false) break; - b = srv->tmp_buf; - buffer_clear(b); + tb = con->srv->tmp_buf; + buffer_clear(tb); for (i = 0; i < p->ssi_vars->used; i++) { data_string *ds = (data_string *)p->ssi_vars->sorted[i]; - buffer_append_string_buffer(b, &ds->key); - buffer_append_string_len(b, CONST_STR_LEN("=")); - buffer_append_string_encoded(b, CONST_BUF_LEN(&ds->value), ENCODING_MINIMAL_XML); - buffer_append_string_len(b, CONST_STR_LEN("\n")); + buffer_append_string_buffer(tb, &ds->key); + buffer_append_string_len(tb, CONST_STR_LEN("=")); + buffer_append_string_encoded(tb, CONST_BUF_LEN(&ds->value), ENCODING_MINIMAL_XML); + buffer_append_string_len(tb, CONST_STR_LEN("\n")); } for (i = 0; i < p->ssi_cgi_env->used; i++) { data_string *ds = (data_string *)p->ssi_cgi_env->sorted[i]; - buffer_append_string_buffer(b, &ds->key); - buffer_append_string_len(b, CONST_STR_LEN("=")); - buffer_append_string_encoded(b, CONST_BUF_LEN(&ds->value), ENCODING_MINIMAL_XML); - buffer_append_string_len(b, CONST_STR_LEN("\n")); + buffer_append_string_buffer(tb, &ds->key); + buffer_append_string_len(tb, CONST_STR_LEN("=")); + buffer_append_string_encoded(tb, CONST_BUF_LEN(&ds->value), ENCODING_MINIMAL_XML); + buffer_append_string_len(tb, CONST_STR_LEN("\n")); } - chunkqueue_append_mem(con->write_queue, CONST_BUF_LEN(b)); + chunkqueue_append_mem(con->write_queue, CONST_BUF_LEN(tb)); break; case SSI_EXEC: { const char *cmd = NULL; pid_t pid; chunk *c; char *args[4]; + log_error_st *errh = p->errh; if (!p->conf.ssi_exec) { /* disabled by config */ break; @@ -796,9 +788,8 @@ static int process_ssi_stmt(server *srv, connection *con, handler_ctx *p, const if (0 == strcmp(l[i], "cmd")) { cmd = l[i+1]; } else { - log_error_write(srv, __FILE__, __LINE__, "sss", - "ssi: unknown attribute for ", - l[1], l[i]); + log_error(errh, __FILE__, __LINE__, + "ssi: unknown attribute for %s %s", l[1], l[i]); } } @@ -811,7 +802,7 @@ static int process_ssi_stmt(server *srv, connection *con, handler_ctx *p, const if (!cmd) break; /* send cmd output to a temporary file */ - if (0 != chunkqueue_append_mem_to_tempfile(srv, con->write_queue, "", 0)) break; + if (0 != chunkqueue_append_mem_to_tempfile(con->write_queue, "", 0, errh)) break; c = con->write_queue->last; *(const char **)&args[0] = "/bin/sh"; @@ -822,7 +813,7 @@ static int process_ssi_stmt(server *srv, connection *con, handler_ctx *p, const /*(expects STDIN_FILENO open to /dev/null)*/ pid = fdevent_fork_execve(args[0], args, NULL, -1, c->file.fd, -1, -1); if (-1 == pid) { - log_error_write(srv, __FILE__, __LINE__, "sss", "spawning exec failed:", strerror(errno), cmd); + log_perror(errh, __FILE__, __LINE__, "spawning exec failed: %s", cmd); } else { struct stat stb; int status; @@ -835,12 +826,12 @@ static int process_ssi_stmt(server *srv, connection *con, handler_ctx *p, const */ while (-1 == waitpid(pid, &status, 0)) { if (errno != EINTR) { - log_error_write(srv, __FILE__, __LINE__, "ss", "waitpid failed:", strerror(errno)); + log_perror(errh, __FILE__, __LINE__, "waitpid failed"); break; } } if (!WIFEXITED(status)) { - log_error_write(srv, __FILE__, __LINE__, "ss", "process exited abnormally:", cmd); + log_error(errh, __FILE__, __LINE__, "process exited abnormally: %s", cmd); } if (0 == fstat(c->file.fd, &stb)) { c->file.length = stb.st_size; @@ -856,23 +847,21 @@ static int process_ssi_stmt(server *srv, connection *con, handler_ctx *p, const if (0 == strcmp(l[i], "expr")) { expr = l[i+1]; } else { - log_error_write(srv, __FILE__, __LINE__, "sss", - "ssi: unknown attribute for ", - l[1], l[i]); + log_error(con->conf.errh, __FILE__, __LINE__, + "ssi: unknown attribute for %s %s", l[1], l[i]); } } if (!expr) { - log_error_write(srv, __FILE__, __LINE__, "sss", - "ssi: ", - l[1], "expr missing"); + log_error(con->conf.errh, __FILE__, __LINE__, + "ssi: %s expr missing", l[1]); break; } if ((!p->if_is_false) && ((p->if_is_false_level == 0) || (p->if_level < p->if_is_false_level))) { - switch (ssi_eval_expr(srv, con, p, expr)) { + switch (ssi_eval_expr(p, expr)) { case -1: case 0: p->if_is_false = 1; @@ -910,16 +899,14 @@ static int process_ssi_stmt(server *srv, connection *con, handler_ctx *p, const if (0 == strcmp(l[i], "expr")) { expr = l[i+1]; } else { - log_error_write(srv, __FILE__, __LINE__, "sss", - "ssi: unknown attribute for ", - l[1], l[i]); + log_error(con->conf.errh, __FILE__, __LINE__, + "ssi: unknown attribute for %s %s", l[1], l[i]); } } if (!expr) { - log_error_write(srv, __FILE__, __LINE__, "sss", - "ssi: ", - l[1], "expr missing"); + log_error(con->conf.errh, __FILE__, __LINE__, + "ssi: %s expr missing", l[1]); break; } @@ -928,7 +915,7 @@ static int process_ssi_stmt(server *srv, connection *con, handler_ctx *p, const if (p->if_level == p->if_is_false_level) { if ((p->if_is_false) && (p->if_is_false_endif == 0)) { - switch (ssi_eval_expr(srv, con, p, expr)) { + switch (ssi_eval_expr(p, expr)) { case -1: case 0: p->if_is_false = 1; @@ -961,9 +948,8 @@ static int process_ssi_stmt(server *srv, connection *con, handler_ctx *p, const case SSI_COMMENT: break; default: - log_error_write(srv, __FILE__, __LINE__, "ss", - "ssi: unknown ssi-command:", - l[1]); + log_error(con->conf.errh, __FILE__, __LINE__, + "ssi: unknown ssi-command: %s", l[1]); break; } @@ -1045,7 +1031,7 @@ static int mod_ssi_parse_ssi_stmt_offlen(int o[10], const char * const s, const return -1; } -static void mod_ssi_parse_ssi_stmt(server *srv, connection *con, handler_ctx *p, char *s, int len, struct stat *st) { +static void mod_ssi_parse_ssi_stmt(connection *con, handler_ctx *p, char *s, int len, struct stat *st) { /** * @@ -1090,7 +1076,7 @@ static void mod_ssi_parse_ssi_stmt(server *srv, connection *con, handler_ctx *p, } } - process_ssi_stmt(srv, con, p, (const char **)l, 1+(n>>1), st); + process_ssi_stmt(con, p, (const char **)l, 1+(n>>1), st); #if 0 free(l[0]); @@ -1121,7 +1107,7 @@ static int mod_ssi_stmt_len(const char *s, const int len) { return 0; /* incomplete directive "" */ } -static void mod_ssi_read_fd(server *srv, connection *con, handler_ctx *p, struct stat *st, int fd) { +static void mod_ssi_read_fd(connection *con, handler_ctx *p, struct stat *st, int fd) { ssize_t rd; size_t offset, pretag; size_t bufsz = 8192; @@ -1145,7 +1131,7 @@ static void mod_ssi_read_fd(server *srv, connection *con, handler_ctx *p, struct len = mod_ssi_stmt_len(buf+prelen, offset-prelen); if (len) { /* num of chars to be consumed */ - mod_ssi_parse_ssi_stmt(srv, con, p, buf+prelen, len, st); + mod_ssi_parse_ssi_stmt(con, p, buf+prelen, len, st); prelen += (len - 1); /* offset to '>' at end of SSI directive; incremented at top of loop */ pretag = prelen + 1; if (pretag == offset) { @@ -1189,7 +1175,8 @@ static void mod_ssi_read_fd(server *srv, connection *con, handler_ctx *p, struct } if (0 != rd) { - log_error_write(srv, __FILE__, __LINE__, "SsB", "read(): ", strerror(errno), con->physical.path); + log_perror(con->conf.errh, __FILE__, __LINE__, + "read(): %s", con->physical.path->ptr); } if (offset - pretag) { @@ -1203,29 +1190,29 @@ static void mod_ssi_read_fd(server *srv, connection *con, handler_ctx *p, struct } -static int mod_ssi_process_file(server *srv, connection *con, handler_ctx *p, struct stat *st) { +static int mod_ssi_process_file(connection *con, handler_ctx *p, struct stat *st) { int fd = fdevent_open_cloexec(con->physical.path->ptr, con->conf.follow_symlink, O_RDONLY, 0); if (-1 == fd) { - log_error_write(srv, __FILE__, __LINE__, "SsB", "open(): ", - strerror(errno), con->physical.path); + log_perror(con->conf.errh, __FILE__, __LINE__, + "open(): %s", con->physical.path->ptr); return -1; } if (0 != fstat(fd, st)) { - log_error_write(srv, __FILE__, __LINE__, "SsB", "fstat(): ", - strerror(errno), con->physical.path); + log_perror(con->conf.errh, __FILE__, __LINE__, + "fstat(): %s", con->physical.path->ptr); close(fd); return -1; } - mod_ssi_read_fd(srv, con, p, st, fd); + mod_ssi_read_fd(con, p, st, fd); close(fd); return 0; } -static int mod_ssi_handle_request(server *srv, connection *con, handler_ctx *p) { +static int mod_ssi_handle_request(connection *con, handler_ctx *p) { struct stat st; /* get a stream to the file */ @@ -1233,12 +1220,12 @@ static int mod_ssi_handle_request(server *srv, connection *con, handler_ctx *p) array_reset_data_strings(p->ssi_vars); array_reset_data_strings(p->ssi_cgi_env); buffer_copy_string_len(p->timefmt, CONST_STR_LEN("%a, %d %b %Y %H:%M:%S %Z")); - build_ssi_cgi_vars(srv, con, p); + build_ssi_cgi_vars(con, p); /* Reset the modified time of included files */ include_file_last_mtime = 0; - if (mod_ssi_process_file(srv, con, p, &st)) return -1; + if (mod_ssi_process_file(con, p, &st)) return -1; con->file_started = 1; con->file_finished = 1; @@ -1261,10 +1248,10 @@ static int mod_ssi_handle_request(server *srv, connection *con, handler_ctx *p) etag_mutate(con->physical.etag, con->physical.etag); http_header_response_set(con, HTTP_HEADER_ETAG, CONST_STR_LEN("ETag"), CONST_BUF_LEN(con->physical.etag)); - mtime = strftime_cache_get(srv, st.st_mtime); + mtime = strftime_cache_get(con->srv, st.st_mtime); http_header_response_set(con, HTTP_HEADER_LAST_MODIFIED, CONST_STR_LEN("Last-Modified"), CONST_BUF_LEN(mtime)); - if (HANDLER_FINISHED == http_response_handle_cachable(srv, con, mtime)) { + if (HANDLER_FINISHED == http_response_handle_cachable(con, mtime)) { /* ok, the client already has our content, * no need to send it again */ @@ -1292,8 +1279,8 @@ URIHANDLER_FUNC(mod_ssi_physical_path) { if (NULL == p->conf.ssi_extension) return HANDLER_GO_ON; if (array_match_value_suffix(p->conf.ssi_extension, con->physical.path)) { - con->plugin_ctx[p->id] = handler_ctx_init(p); - con->mode = p->id; + con->plugin_ctx[p->id] = handler_ctx_init(p, con->conf.errh); + con->mode = p->id; } return HANDLER_GO_ON; @@ -1304,6 +1291,7 @@ SUBREQUEST_FUNC(mod_ssi_handle_subrequest) { handler_ctx *hctx = con->plugin_ctx[p->id]; if (NULL == hctx) return HANDLER_GO_ON; if (con->mode != p->id) return HANDLER_GO_ON; /* not my job */ + UNUSED(srv); /* * NOTE: if mod_ssi modified to use fdevents, HANDLER_WAIT_FOR_EVENT, * instead of blocking to completion, then hctx->timefmt, hctx->ssi_vars, @@ -1312,7 +1300,7 @@ SUBREQUEST_FUNC(mod_ssi_handle_subrequest) { /* handle ssi-request */ - if (mod_ssi_handle_request(srv, con, hctx)) { + if (mod_ssi_handle_request(con, hctx)) { /* on error */ con->http_status = 500; con->mode = DIRECT; diff --git a/src/mod_ssi.h b/src/mod_ssi.h index fb5848af..96d7cd0a 100644 --- a/src/mod_ssi.h +++ b/src/mod_ssi.h @@ -41,9 +41,10 @@ typedef struct { int if_level, if_is_false_level, if_is_false, if_is_false_endif; unsigned short ssi_recursion_depth; + log_error_st *errh; plugin_config conf; } handler_ctx; -int ssi_eval_expr(server *srv, connection *con, handler_ctx *p, const char *expr); +int ssi_eval_expr(handler_ctx *p, const char *expr); #endif diff --git a/src/mod_ssi_expr.c b/src/mod_ssi_expr.c index 0c7f4e72..5e727242 100644 --- a/src/mod_ssi_expr.c +++ b/src/mod_ssi_expr.c @@ -44,13 +44,11 @@ int ssi_val_tobool(ssi_val_t *B) { } } -static int ssi_expr_tokenizer(server *srv, connection *con, handler_ctx *p, +static int ssi_expr_tokenizer(handler_ctx *p, ssi_tokenizer_t *t, int *token_id, buffer *token) { int tid = 0; size_t i; - UNUSED(con); - for (tid = 0; tid == 0 && t->offset < t->size && t->input[t->offset] ; ) { char c = t->input[t->offset]; const data_string *ds; @@ -129,9 +127,8 @@ static int ssi_expr_tokenizer(server *srv, connection *con, handler_ctx *p, buffer_copy_string_len(token, CONST_STR_LEN("(&&)")); } else { - log_error_write(srv, __FILE__, __LINE__, "sds", - "pos:", t->line_pos, - "missing second &"); + log_error(p->errh, __FILE__, __LINE__, + "pos: %d missing second &", t->line_pos); return -1; } @@ -145,9 +142,8 @@ static int ssi_expr_tokenizer(server *srv, connection *con, handler_ctx *p, buffer_copy_string_len(token, CONST_STR_LEN("(||)")); } else { - log_error_write(srv, __FILE__, __LINE__, "sds", - "pos:", t->line_pos, - "missing second |"); + log_error(p->errh, __FILE__, __LINE__, + "pos: %d missing second |", t->line_pos); return -1; } @@ -171,11 +167,8 @@ static int ssi_expr_tokenizer(server *srv, connection *con, handler_ctx *p, t->line_pos += i + 1; } else { /* ERROR */ - - log_error_write(srv, __FILE__, __LINE__, "sds", - "pos:", t->line_pos, - "missing closing quote"); - + log_error(p->errh, __FILE__, __LINE__, + "pos: %d missing closing quote", t->line_pos); return -1; } @@ -201,10 +194,8 @@ static int ssi_expr_tokenizer(server *srv, connection *con, handler_ctx *p, for (i = 2; t->input[t->offset + i] && t->input[t->offset + i] != '}'; i++); if (t->input[t->offset + i] != '}') { - log_error_write(srv, __FILE__, __LINE__, "sds", - "pos:", t->line_pos, - "missing closing quote"); - + log_error(p->errh, __FILE__, __LINE__, + "pos: %d missing closing curly-brace", t->line_pos); return -1; } @@ -266,14 +257,13 @@ static int ssi_expr_tokenizer(server *srv, connection *con, handler_ctx *p, return 1; } else if (t->offset < t->size) { - log_error_write(srv, __FILE__, __LINE__, "sds", - "pos:", t->line_pos, - "foobar"); + log_error(p->errh, __FILE__, __LINE__, + "pos: %d foobar", t->line_pos); } return 0; } -int ssi_eval_expr(server *srv, connection *con, handler_ctx *p, const char *expr) { +int ssi_eval_expr(handler_ctx *p, const char *expr) { ssi_tokenizer_t t; void *pParser; int token_id; @@ -291,14 +281,13 @@ int ssi_eval_expr(server *srv, connection *con, handler_ctx *p, const char *expr t.in_cond = 0; context.ok = 1; - context.srv = srv; /* default context */ pParser = ssiexprparserAlloc( malloc ); force_assert(pParser); token = buffer_init(); - while((1 == (ret = ssi_expr_tokenizer(srv, con, p, &t, &token_id, token))) && context.ok) { + while((1 == (ret = ssi_expr_tokenizer(p, &t, &token_id, token))) && context.ok) { ssiexprparser(pParser, token_id, token, &context); token = buffer_init(); @@ -309,22 +298,18 @@ int ssi_eval_expr(server *srv, connection *con, handler_ctx *p, const char *expr buffer_free(token); if (ret == -1) { - log_error_write(srv, __FILE__, __LINE__, "s", - "expr parser failed"); + log_error(p->errh, __FILE__, __LINE__, "expr parser failed"); return -1; } if (context.ok == 0) { - log_error_write(srv, __FILE__, __LINE__, "sds", - "pos:", t.line_pos, - "parser failed somehow near here"); + log_error(p->errh, __FILE__, __LINE__, + "pos: %d parser failed somehow near here", t.line_pos); return -1; } #if 0 - log_error_write(srv, __FILE__, __LINE__, "ssd", - "expr: ", - expr, - context.val.bo); + log_error(p->errh, __FILE__, __LINE__, + "expr: %s %d", expr, context.val.bo); #endif return context.val.bo; } diff --git a/src/mod_ssi_expr.h b/src/mod_ssi_expr.h index 17cd73ec..7108686f 100644 --- a/src/mod_ssi_expr.h +++ b/src/mod_ssi_expr.h @@ -15,8 +15,6 @@ typedef struct { int ok; ssi_val_t val; - - void *srv; } ssi_ctx_t; typedef enum { SSI_COND_UNSET, SSI_COND_LE, SSI_COND_GE, SSI_COND_EQ, SSI_COND_NE, SSI_COND_LT, SSI_COND_GT } ssi_expr_cond; diff --git a/src/mod_staticfile.c b/src/mod_staticfile.c index 0e640c44..0f74340f 100644 --- a/src/mod_staticfile.c +++ b/src/mod_staticfile.c @@ -117,6 +117,7 @@ SETDEFAULTS_FUNC(mod_staticfile_set_defaults) { URIHANDLER_FUNC(mod_staticfile_subrequest) { plugin_data *p = p_d; + UNUSED(srv); /* someone else has done a decision for us */ if (con->http_status != 0) return HANDLER_GO_ON; @@ -139,7 +140,8 @@ URIHANDLER_FUNC(mod_staticfile_subrequest) { if (p->conf.disable_pathinfo && !buffer_string_is_empty(con->request.pathinfo)) { if (con->conf.log_request_handling) { - log_error_write(srv, __FILE__, __LINE__, "s", "-- NOT handling file as static file, pathinfo forbidden"); + log_error(con->conf.errh, __FILE__, __LINE__, + "-- NOT handling file as static file, pathinfo forbidden"); } return HANDLER_GO_ON; } @@ -147,18 +149,20 @@ URIHANDLER_FUNC(mod_staticfile_subrequest) { /* ignore certain extensions */ if (p->conf.exclude_ext && array_match_value_suffix(p->conf.exclude_ext, con->physical.path)) { if (con->conf.log_request_handling) { - log_error_write(srv, __FILE__, __LINE__, "s", "-- NOT handling file as static file, extension forbidden"); + log_error(con->conf.errh, __FILE__, __LINE__, + "-- NOT handling file as static file, extension forbidden"); } return HANDLER_GO_ON; } if (con->conf.log_request_handling) { - log_error_write(srv, __FILE__, __LINE__, "s", "-- handling file as static file"); + log_error(con->conf.errh, __FILE__, __LINE__, + "-- handling file as static file"); } if (!p->conf.etags_used) con->conf.etag_flags = 0; - http_response_send_file(srv, con, con->physical.path); + http_response_send_file(con, con->physical.path); return HANDLER_FINISHED; } diff --git a/src/mod_status.c b/src/mod_status.c index 5669df06..ece54cb4 100644 --- a/src/mod_status.c +++ b/src/mod_status.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include diff --git a/src/mod_trigger_b4_dl.c b/src/mod_trigger_b4_dl.c index 178f276d..a44e8c84 100644 --- a/src/mod_trigger_b4_dl.c +++ b/src/mod_trigger_b4_dl.c @@ -347,7 +347,7 @@ static handler_t mod_trigger_b4_dl_deny(connection * const con, const plugin_dat con->http_status = 307; } else { - log_error(con->errh, __FILE__, __LINE__, + log_error(con->conf.errh, __FILE__, __LINE__, "trigger-before-download.deny-url not configured"); con->http_status = 500; } @@ -394,14 +394,14 @@ URIHANDLER_FUNC(mod_trigger_b4_dl_uri_handler) { } if (p->conf.debug) { - log_error_write(srv, __FILE__, __LINE__, "ss", "(debug) remote-ip:", remote_ip); + log_error(con->conf.errh, __FILE__, __LINE__, "(debug) remote-ip: %s", remote_ip->ptr); } /* check if URL is a trigger -> insert IP into DB */ if ((n = pcre_exec(p->conf.trigger_regex, NULL, CONST_BUF_LEN(con->uri.path), 0, 0, ovec, 3 * N)) < 0) { if (n != PCRE_ERROR_NOMATCH) { - log_error_write(srv, __FILE__, __LINE__, "sd", - "execution error while matching:", n); + log_error(con->conf.errh, __FILE__, __LINE__, + "execution error while matching: %d", n); return HANDLER_ERROR; } @@ -418,8 +418,7 @@ URIHANDLER_FUNC(mod_trigger_b4_dl_uri_handler) { val.dsize = sizeof(srv->cur_ts); if (0 != gdbm_store(p->conf.db, key, val, GDBM_REPLACE)) { - log_error_write(srv, __FILE__, __LINE__, "s", - "insert failed"); + log_error(con->conf.errh, __FILE__, __LINE__, "insert failed"); } } # endif @@ -429,15 +428,14 @@ URIHANDLER_FUNC(mod_trigger_b4_dl_uri_handler) { mod_trigger_b4_dl_memcached_key(b, p, remote_ip); if (p->conf.debug) { - log_error_write(srv, __FILE__, __LINE__, "sb", "(debug) triggered IP:", b); + log_error(con->conf.errh, __FILE__, __LINE__, "(debug) triggered IP: %s", b->ptr); } if (MEMCACHED_SUCCESS != memcached_set(p->conf.memc, CONST_BUF_LEN(b), (const char *)&(srv->cur_ts), sizeof(srv->cur_ts), p->conf.trigger_timeout, 0)) { - log_error_write(srv, __FILE__, __LINE__, "s", - "insert failed"); + log_error(con->conf.errh, __FILE__, __LINE__, "insert failed"); } } # endif @@ -446,8 +444,8 @@ URIHANDLER_FUNC(mod_trigger_b4_dl_uri_handler) { /* check if URL is a download -> check IP in DB, update timestamp */ if ((n = pcre_exec(p->conf.download_regex, NULL, CONST_BUF_LEN(con->uri.path), 0, 0, ovec, 3 * N)) < 0) { if (n != PCRE_ERROR_NOMATCH) { - log_error_write(srv, __FILE__, __LINE__, "sd", - "execution error while matching: ", n); + log_error(con->conf.errh, __FILE__, __LINE__, + "execution error while matching: %d", n); return HANDLER_ERROR; } } else { @@ -476,8 +474,7 @@ URIHANDLER_FUNC(mod_trigger_b4_dl_uri_handler) { if (p->conf.db) { if (0 != gdbm_delete(p->conf.db, key)) { - log_error_write(srv, __FILE__, __LINE__, "s", - "delete failed"); + log_error(con->conf.errh, __FILE__, __LINE__, "delete failed"); } } @@ -488,8 +485,7 @@ URIHANDLER_FUNC(mod_trigger_b4_dl_uri_handler) { val.dsize = sizeof(srv->cur_ts); if (0 != gdbm_store(p->conf.db, key, val, GDBM_REPLACE)) { - log_error_write(srv, __FILE__, __LINE__, "s", - "insert failed"); + log_error(con->conf.errh, __FILE__, __LINE__, "insert failed"); } } # endif @@ -499,7 +495,7 @@ URIHANDLER_FUNC(mod_trigger_b4_dl_uri_handler) { mod_trigger_b4_dl_memcached_key(b, p, remote_ip); if (p->conf.debug) { - log_error_write(srv, __FILE__, __LINE__, "sb", "(debug) checking IP:", b); + log_error(con->conf.errh, __FILE__, __LINE__, "(debug) checking IP: %s", b->ptr); } /** @@ -517,8 +513,7 @@ URIHANDLER_FUNC(mod_trigger_b4_dl_uri_handler) { CONST_BUF_LEN(b), (const char *)&(srv->cur_ts), sizeof(srv->cur_ts), p->conf.trigger_timeout, 0)) { - log_error_write(srv, __FILE__, __LINE__, "s", - "insert failed"); + log_error(con->conf.errh, __FILE__, __LINE__, "insert failed"); } } # endif diff --git a/src/mod_uploadprogress.c b/src/mod_uploadprogress.c index e7a5ddac..204947b1 100644 --- a/src/mod_uploadprogress.c +++ b/src/mod_uploadprogress.c @@ -244,8 +244,8 @@ URIHANDLER_FUNC(mod_uploadprogress_uri_handler) { for (len = 0; light_isxdigit(id[len]); ++len) ; if (len != 32) { if (!pathinfo) { /*(reduce false positive noise in error log)*/ - log_error_write(srv, __FILE__, __LINE__, "ss", - "invalid progress-id; non-xdigit or len != 32:", id); + log_error(con->conf.errh, __FILE__, __LINE__, + "invalid progress-id; non-xdigit or len != 32: %s", id); } return HANDLER_GO_ON; } @@ -268,8 +268,7 @@ URIHANDLER_FUNC(mod_uploadprogress_uri_handler) { /* get the connection */ if (NULL == (post_con = connection_map_get_connection(&p->con_map, id, len))) { - log_error_write(srv, __FILE__, __LINE__, "ss", - "ID not known:", id); + log_error(con->conf.errh, __FILE__, __LINE__, "ID not known: %s", id); chunkqueue_append_mem(con->write_queue, CONST_STR_LEN("not in progress")); diff --git a/src/mod_userdir.c b/src/mod_userdir.c index 0c95bbf6..bc73b301 100644 --- a/src/mod_userdir.c +++ b/src/mod_userdir.c @@ -248,6 +248,7 @@ static handler_t mod_userdir_docroot_construct(connection * const con, plugin_da URIHANDLER_FUNC(mod_userdir_docroot_handler) { /* /~user/foo.html -> /home/user/public_html/foo.html */ + UNUSED(srv); if (buffer_is_empty(con->uri.path)) return HANDLER_GO_ON; @@ -266,7 +267,7 @@ URIHANDLER_FUNC(mod_userdir_docroot_handler) { const char * const rel_url = strchr(uptr, '/'); if (NULL == rel_url) { /* / is missing -> redirect to .../ as we are a user - DIRECTORY ! :) */ - http_response_redirect_to_directory(srv, con, 301); + http_response_redirect_to_directory(con, 301); return HANDLER_FINISHED; } diff --git a/src/mod_vhostdb.c b/src/mod_vhostdb.c index a127c27f..c57fca8a 100644 --- a/src/mod_vhostdb.c +++ b/src/mod_vhostdb.c @@ -6,7 +6,6 @@ #include "log.h" #include "stat_cache.h" -#include #include #include @@ -193,11 +192,12 @@ CONNECTION_FUNC(mod_vhostdb_handle_docroot) { /* sanity check that really is a directory */ buffer_append_slash(b); if (HANDLER_ERROR == stat_cache_get_entry(srv, con, b, &sce)) { - log_error_write(srv, __FILE__, __LINE__, "sb", strerror(errno), b); + log_perror(con->conf.errh, __FILE__, __LINE__, "%s", b->ptr); return mod_vhostdb_error_500(con); /* HANDLER_FINISHED */ } if (!S_ISDIR(sce->st.st_mode)) { - log_error_write(srv, __FILE__, __LINE__, "sb", "Not a directory", b); + log_error(con->conf.errh, __FILE__, __LINE__, + "Not a directory: %s", b->ptr); return mod_vhostdb_error_500(con); /* HANDLER_FINISHED */ } diff --git a/src/mod_vhostdb_dbi.c b/src/mod_vhostdb_dbi.c index aaa70bf3..f67cbdc1 100644 --- a/src/mod_vhostdb_dbi.c +++ b/src/mod_vhostdb_dbi.c @@ -25,7 +25,7 @@ typedef struct { dbi_conn dbconn; dbi_inst dbinst; const buffer *sqlquery; - server *srv; + log_error_st *errh; short reconnect_count; } vhostdb_config; @@ -54,8 +54,7 @@ static void mod_vhostdb_dbi_error_callback (dbi_conn dbconn, void *vdata) } dbi_conn_error(dbconn, &errormsg); - log_error_write(dbconf->srv, __FILE__, __LINE__, "ss", - "dbi_conn_connect():", errormsg); + log_error(dbconf->errh,__FILE__,__LINE__,"dbi_conn_connect(): %s",errormsg); } static void mod_vhostdb_dbconf_free (void *vdata) @@ -106,16 +105,16 @@ static int mod_vhostdb_dbconf_setup (server *srv, const array *opts, void **vdat dbi_inst dbinst = NULL; dbi_conn dbconn; if (dbi_initialize_r(NULL, &dbinst) < 1) { - log_error_write(srv, __FILE__, __LINE__, "s", - "dbi_initialize_r() failed. " - "Do you have the DBD for this db type installed?"); + log_error(srv->errh, __FILE__, __LINE__, + "dbi_initialize_r() failed. " + "Do you have the DBD for this db type installed?"); return -1; } dbconn = dbi_conn_new_r(dbtype->ptr, dbinst); if (NULL == dbconn) { - log_error_write(srv, __FILE__, __LINE__, "s", - "dbi_conn_new_r() failed. " - "Do you have the DBD for this db type installed?"); + log_error(srv->errh, __FILE__, __LINE__, + "dbi_conn_new_r() failed. " + "Do you have the DBD for this db type installed?"); dbi_shutdown_r(dbinst); return -1; } @@ -141,7 +140,7 @@ static int mod_vhostdb_dbconf_setup (server *srv, const array *opts, void **vdat dbconf->dbinst = dbinst; dbconf->dbconn = dbconn; dbconf->sqlquery = sqlquery; - dbconf->srv = srv; + dbconf->errh = srv->errh; dbconf->reconnect_count = 0; *vdata = dbconf; @@ -163,6 +162,7 @@ static void mod_vhostdb_patch_config (connection * const con, plugin_data * cons static int mod_vhostdb_dbi_query(server *srv, connection *con, void *p_d, buffer *docroot) { + UNUSED(srv); plugin_data *p = (plugin_data *)p_d; vhostdb_config *dbconf; dbi_result result; @@ -205,7 +205,7 @@ static int mod_vhostdb_dbi_query(server *srv, connection *con, void *p_d, buffer if (!result) { const char *errmsg; dbi_conn_error(dbconf->dbconn, &errmsg); - log_error_write(srv, __FILE__, __LINE__, "s", errmsg); + log_error(con->conf.errh, __FILE__, __LINE__, "%s", errmsg); return -1; } diff --git a/src/mod_vhostdb_ldap.c b/src/mod_vhostdb_ldap.c index 90c19d44..f7b88ca2 100644 --- a/src/mod_vhostdb_ldap.c +++ b/src/mod_vhostdb_ldap.c @@ -2,7 +2,6 @@ #include -#include #include #include @@ -18,7 +17,7 @@ typedef struct { LDAP *ldap; const buffer *filter; - server *srv; + log_error_st *errh; const char *attr; const char *host; @@ -129,8 +128,8 @@ static int mod_vhostdb_dbconf_setup (server *srv, const array *opts, void **vdat vhostdb_config *dbconf; if (NULL == strchr(filter->ptr, '?')) { - log_error_write(srv, __FILE__, __LINE__, "s", - "ldap: filter is missing a replace-operator '?'"); + log_error(srv->errh, __FILE__, __LINE__, + "ldap: filter is missing a replace-operator '?'"); return -1; } @@ -160,16 +159,18 @@ static int mod_vhostdb_dbconf_setup (server *srv, const array *opts, void **vdat * and (const char *) strings in vhostdb_config instead of (buffer *). */ -static void mod_authn_ldap_err(server *srv, const char *file, unsigned long line, const char *fn, int err) +__attribute_cold__ +static void mod_authn_ldap_err(log_error_st *errh, const char *file, unsigned long line, const char *fn, int err) { - log_error_write(srv,file,line,"sSss","ldap:",fn,":",ldap_err2string(err)); + log_error(errh, file, line, "ldap: %s: %s", fn, ldap_err2string(err)); } -static void mod_authn_ldap_opt_err(server *srv, const char *file, unsigned long line, const char *fn, LDAP *ld) +__attribute_cold__ +static void mod_authn_ldap_opt_err(log_error_st *errh, const char *file, unsigned long line, const char *fn, LDAP *ld) { int err; ldap_get_option(ld, LDAP_OPT_ERROR_NUMBER, &err); - mod_authn_ldap_err(srv, file, line, fn, err); + mod_authn_ldap_err(errh, file, line, fn, err); } static void mod_authn_append_ldap_filter_escape(buffer * const filter, const buffer * const raw) { @@ -237,21 +238,20 @@ static void mod_authn_append_ldap_filter_escape(buffer * const filter, const buf } } -static LDAP * mod_authn_ldap_host_init(server *srv, vhostdb_config *s) { +static LDAP * mod_authn_ldap_host_init(log_error_st *errh, vhostdb_config *s) { LDAP *ld; int ret; ret = ldap_initialize(&ld, s->host); if (LDAP_SUCCESS != ret) { - log_error_write(srv, __FILE__, __LINE__, "sss", "ldap:", - "ldap_initialize():", strerror(errno)); + log_perror(errh, __FILE__, __LINE__, "ldap: ldap_initialize()"); return NULL; } ret = LDAP_VERSION3; ret = ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, &ret); if (LDAP_OPT_SUCCESS != ret) { - mod_authn_ldap_err(srv, __FILE__, __LINE__, "ldap_set_options()", ret); + mod_authn_ldap_err(errh, __FILE__, __LINE__, "ldap_set_options()", ret); ldap_destroy(ld); return NULL; } @@ -265,9 +265,8 @@ static LDAP * mod_authn_ldap_host_init(server *srv, vhostdb_config *s) { if (s->cafile) { ret = ldap_set_option(NULL, LDAP_OPT_X_TLS_CACERTFILE, s->cafile); if (LDAP_OPT_SUCCESS != ret) { - mod_authn_ldap_err(srv, __FILE__, __LINE__, - "ldap_set_option(LDAP_OPT_X_TLS_CACERTFILE)", - ret); + mod_authn_ldap_err(errh, __FILE__, __LINE__, + "ldap_set_option(LDAP_OPT_X_TLS_CACERTFILE)", ret); ldap_destroy(ld); return NULL; } @@ -275,7 +274,7 @@ static LDAP * mod_authn_ldap_host_init(server *srv, vhostdb_config *s) { ret = ldap_start_tls_s(ld, NULL, NULL); if (LDAP_OPT_SUCCESS != ret) { - mod_authn_ldap_err(srv,__FILE__,__LINE__,"ldap_start_tls_s()",ret); + mod_authn_ldap_err(errh,__FILE__,__LINE__,"ldap_start_tls_s()",ret); ldap_destroy(ld); return NULL; } @@ -284,7 +283,7 @@ static LDAP * mod_authn_ldap_host_init(server *srv, vhostdb_config *s) { return ld; } -static int mod_authn_ldap_bind(server *srv, LDAP *ld, const char *dn, const char *pw) { +static int mod_authn_ldap_bind(log_error_st *errh, LDAP *ld, const char *dn, const char *pw) { struct berval creds; int ret; @@ -300,7 +299,7 @@ static int mod_authn_ldap_bind(server *srv, LDAP *ld, const char *dn, const char ret = ldap_sasl_bind_s(ld,dn,LDAP_SASL_SIMPLE,&creds,NULL,NULL,NULL); if (ret != LDAP_SUCCESS) { - mod_authn_ldap_err(srv, __FILE__, __LINE__, "ldap_sasl_bind_s()", ret); + mod_authn_ldap_err(errh, __FILE__, __LINE__, "ldap_sasl_bind_s()", ret); } return ret; @@ -311,10 +310,10 @@ static int mod_authn_ldap_rebind_proc (LDAP *ld, LDAP_CONST char *url, ber_tag_t UNUSED(url); UNUSED(ldap_request); UNUSED(msgid); - return mod_authn_ldap_bind(s->srv, ld, s->binddn, s->bindpw); + return mod_authn_ldap_bind(s->errh, ld, s->binddn, s->bindpw); } -static LDAPMessage * mod_authn_ldap_search(server *srv, vhostdb_config *s, char *base, char *filter) { +static LDAPMessage * mod_authn_ldap_search(log_error_st *errh, vhostdb_config *s, char *base, char *filter) { LDAPMessage *lm = NULL; char *attrs[] = { LDAP_NO_ATTRS, NULL }; int ret; @@ -343,13 +342,13 @@ static LDAPMessage * mod_authn_ldap_search(server *srv, vhostdb_config *s, char ldap_unbind_ext_s(s->ldap, NULL, NULL); } - s->ldap = mod_authn_ldap_host_init(srv, s); + s->ldap = mod_authn_ldap_host_init(errh, s); if (NULL == s->ldap) { return NULL; } ldap_set_rebind_proc(s->ldap, mod_authn_ldap_rebind_proc, s); - ret = mod_authn_ldap_bind(srv, s->ldap, s->binddn, s->bindpw); + ret = mod_authn_ldap_bind(errh, s->ldap, s->binddn, s->bindpw); if (LDAP_SUCCESS != ret) { ldap_destroy(s->ldap); s->ldap = NULL; @@ -359,8 +358,8 @@ static LDAPMessage * mod_authn_ldap_search(server *srv, vhostdb_config *s, char ret = ldap_search_ext_s(s->ldap, base, LDAP_SCOPE_SUBTREE, filter, attrs, 0, NULL, NULL, NULL, 0, &lm); if (LDAP_SUCCESS != ret) { - log_error_write(srv, __FILE__, __LINE__, "sSss", - "ldap:", ldap_err2string(ret), "; filter:", filter); + log_error(errh, __FILE__, __LINE__, + "ldap: %s; filter: %s", ldap_err2string(ret), filter); ldap_unbind_ext_s(s->ldap, NULL, NULL); s->ldap = NULL; return NULL; @@ -373,6 +372,7 @@ static void mod_vhostdb_patch_config (connection * const con, plugin_data * cons static int mod_vhostdb_ldap_query(server *srv, connection *con, void *p_d, buffer *docroot) { + UNUSED(srv); plugin_data *p = (plugin_data *)p_d; vhostdb_config *dbconf; LDAP *ld; @@ -389,7 +389,8 @@ static int mod_vhostdb_ldap_query(server *srv, connection *con, void *p_d, buffe mod_vhostdb_patch_config(con, p); if (NULL == p->conf.vdata) return 0; /*(after resetting docroot)*/ dbconf = (vhostdb_config *)p->conf.vdata; - dbconf->srv = srv; + log_error_st * const errh = con->conf.errh; + dbconf->errh = errh; template = dbconf->filter; for (char *b = template->ptr, *d; *b; b = d+1) { @@ -407,7 +408,7 @@ static int mod_vhostdb_ldap_query(server *srv, connection *con, void *p_d, buffe *(const char **)&basedn = dbconf->basedn; /* ldap_search (synchronous; blocking) */ - lm = mod_authn_ldap_search(srv, dbconf, basedn, filter->ptr); + lm = mod_authn_ldap_search(errh, dbconf, basedn, filter->ptr); if (NULL == lm) { return -1; } @@ -417,9 +418,9 @@ static int mod_vhostdb_ldap_query(server *srv, connection *con, void *p_d, buffe count = ldap_count_entries(ld, lm); if (count > 1) { - log_error_write(srv, __FILE__, __LINE__, "ssb", - "ldap:", "more than one record returned. " - "you might have to refine the filter:", filter); + log_error(errh, __FILE__, __LINE__, + "ldap: more than one record returned. " + "you might have to refine the filter: %s", filter->ptr); } buffer_clear(docroot); /*(reset buffer to store result)*/ @@ -430,7 +431,7 @@ static int mod_vhostdb_ldap_query(server *srv, connection *con, void *p_d, buffe } if (NULL == (first = ldap_first_entry(ld, lm))) { - mod_authn_ldap_opt_err(srv,__FILE__,__LINE__,"ldap_first_entry()",ld); + mod_authn_ldap_opt_err(errh,__FILE__,__LINE__,"ldap_first_entry()",ld); ldap_msgfree(lm); return -1; } diff --git a/src/mod_vhostdb_mysql.c b/src/mod_vhostdb_mysql.c index 766ee8e9..5f66c35c 100644 --- a/src/mod_vhostdb_mysql.c +++ b/src/mod_vhostdb_mysql.c @@ -82,8 +82,8 @@ static int mod_vhostdb_dbconf_setup (server *srv, const array *opts, void **vdat vhostdb_config *dbconf; MYSQL *dbconn = mysql_init(NULL); if (NULL == dbconn) { - log_error_write(srv, __FILE__, __LINE__, "s", - "mysql_init() failed, exiting..."); + log_error(srv->errh, __FILE__, __LINE__, + "mysql_init() failed, exiting..."); return -1; } @@ -103,8 +103,7 @@ static int mod_vhostdb_dbconf_setup (server *srv, const array *opts, void **vdat #endif if (!mysql_real_connect(dbconn, host, user, pass, dbname, port, sock, CLIENT_MULTI_STATEMENTS)) { - log_error_write(srv, __FILE__, __LINE__, "s", - mysql_error(dbconn)); + log_error(srv->errh, __FILE__, __LINE__, "%s", mysql_error(dbconn)); mysql_close(dbconn); return -1; } @@ -124,6 +123,7 @@ static void mod_vhostdb_patch_config (connection * const con, plugin_data * cons static int mod_vhostdb_mysql_query(server *srv, connection *con, void *p_d, buffer *docroot) { + UNUSED(srv); plugin_data *p = (plugin_data *)p_d; vhostdb_config *dbconf; unsigned cols; @@ -157,8 +157,8 @@ static int mod_vhostdb_mysql_query(server *srv, connection *con, void *p_d, buff } if (mysql_real_query(dbconf->dbconn, CONST_BUF_LEN(sqlquery))) { - log_error_write(srv, __FILE__, __LINE__, "s", - mysql_error(dbconf->dbconn)); + log_error(con->conf.errh, __FILE__, __LINE__, "%s", + mysql_error(dbconf->dbconn)); buffer_clear(docroot); /*(reset buffer; no result)*/ return -1; } diff --git a/src/mod_vhostdb_pgsql.c b/src/mod_vhostdb_pgsql.c index 3dad465a..3b885890 100644 --- a/src/mod_vhostdb_pgsql.c +++ b/src/mod_vhostdb_pgsql.c @@ -76,14 +76,14 @@ static int mod_vhostdb_dbconf_setup (server *srv, const array *opts, void **vdat vhostdb_config *dbconf; PGconn *dbconn = PQsetdbLogin(host,port,NULL,NULL,dbname,user,pass); if (NULL == dbconn) { - log_error_write(srv, __FILE__, __LINE__, "s", - "PGsetdbLogin() failed, exiting..."); + log_error(srv->errh, __FILE__, __LINE__, + "PGsetdbLogin() failed, exiting..."); return -1; } if (CONNECTION_OK != PQstatus(dbconn)) { - log_error_write(srv, __FILE__, __LINE__, "s", - "Failed to login to database, exiting..."); + log_error(srv->errh, __FILE__, __LINE__, + "Failed to login to database, exiting..."); PQfinish(dbconn); return -1; } @@ -103,6 +103,7 @@ static void mod_vhostdb_patch_config(connection * const con, plugin_data * const static int mod_vhostdb_pgsql_query(server *srv, connection *con, void *p_d, buffer *docroot) { + UNUSED(srv); plugin_data *p = (plugin_data *)p_d; vhostdb_config *dbconf; PGresult *res; @@ -140,8 +141,8 @@ static int mod_vhostdb_pgsql_query(server *srv, connection *con, void *p_d, buff buffer_clear(docroot); /*(reset buffer to store result)*/ if (PGRES_TUPLES_OK != PQresultStatus(res)) { - log_error_write(srv, __FILE__, __LINE__, "s", - PQerrorMessage(dbconf->dbconn)); + log_error(con->conf.errh, __FILE__, __LINE__, "%s", + PQerrorMessage(dbconf->dbconn)); PQclear(res); return -1; } diff --git a/src/mod_webdav.c b/src/mod_webdav.c index 7c0a7f2e..28d3ec5d 100644 --- a/src/mod_webdav.c +++ b/src/mod_webdav.c @@ -852,7 +852,7 @@ webdav_xml_doc_multistatus (connection * const con, "\n")); if (pconf->log_xml) - log_error(con->errh, __FILE__, __LINE__, + log_error(con->conf.errh, __FILE__, __LINE__, "XML-response-body: %.*s", BUFFER_INTLEN_PTR(b)); chunkqueue_append_buffer_commit(con->write_queue); @@ -881,7 +881,7 @@ webdav_xml_doc_multistatus_response (connection * const con, "\n")); if (pconf->log_xml) - log_error(con->errh, __FILE__, __LINE__, + log_error(con->conf.errh, __FILE__, __LINE__, "XML-response-body: %.*s", BUFFER_INTLEN_PTR(b)); chunkqueue_append_buffer_commit(con->write_queue); @@ -918,7 +918,7 @@ webdav_xml_doc_lock_acquired (connection * const con, "\n")); if (pconf->log_xml) - log_error(con->errh, __FILE__, __LINE__, + log_error(con->conf.errh, __FILE__, __LINE__, "XML-response-body: %.*s", BUFFER_INTLEN_PTR(b)); chunkqueue_append_buffer_commit(con->write_queue); @@ -3411,12 +3411,12 @@ webdav_parse_chunkqueue (connection * const con, switch (errno) { case ENOSYS: case ENODEV: case EINVAL: break; default: - log_perror(con->errh, __FILE__, __LINE__, + log_perror(con->conf.errh, __FILE__, __LINE__, "open() or mmap() '%*.s'", BUFFER_INTLEN_PTR(c->mem)); } if (webdav_open_chunk_file_rd(c) < 0) { - log_perror(con->errh, __FILE__, __LINE__, + log_perror(con->conf.errh, __FILE__, __LINE__, "open() '%*.s'", BUFFER_INTLEN_PTR(c->mem)); err = XML_IO_UNKNOWN; @@ -3435,7 +3435,7 @@ webdav_parse_chunkqueue (connection * const con, weHave = (size_t)rd; } else { - log_perror(con->errh, __FILE__, __LINE__, + log_perror(con->conf.errh, __FILE__, __LINE__, "read() '%*.s'", BUFFER_INTLEN_PTR(c->mem)); err = XML_IO_UNKNOWN; @@ -3444,7 +3444,7 @@ webdav_parse_chunkqueue (connection * const con, } } else { - log_error(con->errh, __FILE__, __LINE__, + log_error(con->conf.errh, __FILE__, __LINE__, "unrecognized chunk type: %d", c->type); err = XML_IO_UNKNOWN; break; @@ -3453,11 +3453,11 @@ webdav_parse_chunkqueue (connection * const con, if (weHave > weWant) weHave = weWant; if (pconf->log_xml) - log_error(con->errh, __FILE__, __LINE__, + log_error(con->conf.errh, __FILE__, __LINE__, "XML-request-body: %.*s", (int)weHave, xmlstr); if (XML_ERR_OK != (err = xmlParseChunk(ctxt, xmlstr, weHave, 0))) { - log_error(con->errh, __FILE__, __LINE__, + log_error(con->conf.errh, __FILE__, __LINE__, "xmlParseChunk failed at: %lld %zu %d", (long long int)cq->bytes_out, weHave, err); break; @@ -3478,7 +3478,7 @@ webdav_parse_chunkqueue (connection * const con, } break; default: - log_error(con->errh, __FILE__, __LINE__, + log_error(con->conf.errh, __FILE__, __LINE__, "xmlParseChunk failed at final packet: %d", err); break; } @@ -3794,11 +3794,11 @@ mod_webdav_propfind (connection * const con, const plugin_config * const pconf) sizeof("Microsoft-WebDAV-MiniRedir/")-1)) { /* workaround Microsoft-WebDAV-MiniRedir bug */ /* (MS File Explorer unable to open folder if not redirected) */ - http_response_redirect_to_directory(pconf->srv, con, 308); + http_response_redirect_to_directory(con, 308); return HANDLER_FINISHED; } /* set "Content-Location" instead of sending 308 redirect to dir */ - if (!http_response_redirect_to_directory(pconf->srv, con, 0)) + if (!http_response_redirect_to_directory(con, 0)) return HANDLER_FINISHED; buffer_append_string_len(con->physical.path, CONST_STR_LEN("/")); buffer_append_string_len(con->physical.rel_path,CONST_STR_LEN("/")); @@ -3846,7 +3846,7 @@ mod_webdav_propfind (connection * const con, const plugin_config * const pconf) if (prop->ns && '\0' == *(char *)prop->ns->href && '\0' != *(char *)prop->ns->prefix) { - log_error(con->errh, __FILE__, __LINE__, + log_error(con->conf.errh, __FILE__, __LINE__, "no name space for: %s", prop->name); /* 422 Unprocessable Entity */ http_status_set_error(con, 422); @@ -3859,7 +3859,7 @@ mod_webdav_propfind (connection * const con, const plugin_config * const pconf) if (pb.proplist.size == pb.proplist.used) { if (pb.proplist.size == 32) { /* arbitrarily chosen limit of 32 */ - log_error(con->errh, __FILE__, __LINE__, + log_error(con->conf.errh, __FILE__, __LINE__, "too many properties in request (> 32)"); http_status_set_error(con, 400); /* Bad Request */ free(pb.proplist.ptr); @@ -3945,7 +3945,7 @@ mod_webdav_propfind (connection * const con, const plugin_config * const pconf) "\n")); if (pconf->log_xml) - log_error(con->errh, __FILE__, __LINE__, "XML-response-body: %.*s", + log_error(con->conf.errh, __FILE__, __LINE__, "XML-response-body: %.*s", BUFFER_INTLEN_PTR(pb.b)); http_status_set_fin(con, 207); /* Multi-status */ @@ -3999,7 +3999,7 @@ mod_webdav_delete (connection * const con, const plugin_config * const pconf) if (S_ISDIR(st.st_mode)) { if (con->physical.path->ptr[con->physical.path->used - 2] != '/') { #if 0 /*(issues warning for /usr/bin/litmus copymove test)*/ - http_response_redirect_to_directory(pconf->srv, con, 308); + http_response_redirect_to_directory(con, 308); return HANDLER_FINISHED; /* 308 Permanent Redirect */ /* Alternatively, could append '/' to con->physical.path * and con->physical.rel_path, set Content-Location in @@ -4087,7 +4087,7 @@ mod_webdav_write_cq_first_chunk (connection * const con, chunkqueue * const cq, switch (errno) { case ENOSYS: case ENODEV: case EINVAL: break; default: - log_perror(con->errh, __FILE__, __LINE__, + log_perror(con->conf.errh, __FILE__, __LINE__, "open() or mmap() '%*.s'", BUFFER_INTLEN_PTR(c->mem)); } @@ -4112,7 +4112,7 @@ mod_webdav_write_cq_first_chunk (connection * const con, chunkqueue * const cq, break; } else { - log_perror(con->errh, __FILE__, __LINE__, + log_perror(con->conf.errh, __FILE__, __LINE__, "read() '%*.s'", BUFFER_INTLEN_PTR(c->mem)); http_status_set_error(con, 500); /* Internal Server Error */ @@ -4749,7 +4749,7 @@ mod_webdav_copymove_b (connection * const con, const plugin_config * const pconf if (S_ISDIR(st.st_mode)) { if (con->physical.path->ptr[con->physical.path->used - 2] != '/') { - http_response_redirect_to_directory(pconf->srv, con, 308); + http_response_redirect_to_directory(con, 308); return HANDLER_FINISHED; /* 308 Permanent Redirect */ /* Alternatively, could append '/' to con->physical.path * and con->physical.rel_path, set Content-Location in @@ -4986,11 +4986,11 @@ mod_webdav_proppatch (connection * const con, const plugin_config * const pconf) /* workaround Microsoft-WebDAV-MiniRedir bug */ /* (might not be necessary for PROPPATCH here, * but match behavior in mod_webdav_propfind() for PROPFIND) */ - http_response_redirect_to_directory(pconf->srv, con, 308); + http_response_redirect_to_directory(con, 308); return HANDLER_FINISHED; } /* set "Content-Location" instead of sending 308 redirect to dir */ - if (!http_response_redirect_to_directory(pconf->srv, con, 0)) + if (!http_response_redirect_to_directory(con, 0)) return HANDLER_FINISHED; buffer_append_string_len(con->physical.path, CONST_STR_LEN("/")); buffer_append_string_len(con->physical.rel_path,CONST_STR_LEN("/")); @@ -5051,7 +5051,7 @@ mod_webdav_proppatch (connection * const con, const plugin_config * const pconf) if (prop->ns && '\0' == *(char *)prop->ns->href && '\0' != *(char *)prop->ns->prefix) { /* error: missing namespace for property */ - log_error(con->errh, __FILE__, __LINE__, + log_error(con->conf.errh, __FILE__, __LINE__, "no namespace for: %s", prop->name); if (!ms) ms = buffer_init(); /* Unprocessable Entity */ webdav_xml_propstat_status(ms, "", (char *)prop->name, 422); @@ -5388,7 +5388,7 @@ mod_webdav_lock (connection * const con, const plugin_config * const pconf) else if (S_ISDIR(st.st_mode)) { if (con->physical.path->ptr[con->physical.path->used - 2] != '/') { /* 308 Permanent Redirect */ - http_response_redirect_to_directory(pconf->srv, con, 308); + http_response_redirect_to_directory(con, 308); break; /* clean up resources and return HANDLER_FINISHED */ /* Alternatively, could append '/' to con->physical.path * and con->physical.rel_path, set Content-Location in diff --git a/src/mod_wstunnel.c b/src/mod_wstunnel.c index b64cd3c6..db9805f8 100644 --- a/src/mod_wstunnel.c +++ b/src/mod_wstunnel.c @@ -367,7 +367,7 @@ static handler_t wstunnel_create_env(server *srv, gw_handler_ctx *gwhctx) { connection *con = hctx->gw.remote_conn; handler_t rc; if (0 == con->request.content_length) { - http_response_upgrade_read_body_unknown(srv, con); + http_response_upgrade_read_body_unknown(con); chunkqueue_append_chunkqueue(con->request_content_queue, con->read_queue); } @@ -403,7 +403,7 @@ static handler_t wstunnel_stdin_append(server *srv, gw_handler_ctx *gwhctx) { } } -static handler_t wstunnel_recv_parse(server *srv, connection *con, http_response_opts *opts, buffer *b, size_t n) { +static handler_t wstunnel_recv_parse(connection *con, http_response_opts *opts, buffer *b, size_t n) { handler_ctx *hctx = (handler_ctx *)opts->pdata; DEBUG_LOG_DEBUG("recv data from backend (fd=%d), size=%zx", hctx->gw.fd, n); if (0 == n) return HANDLER_FINISHED; @@ -412,7 +412,6 @@ static handler_t wstunnel_recv_parse(server *srv, connection *con, http_response return HANDLER_ERROR; } buffer_clear(b); - UNUSED(srv); UNUSED(con); return HANDLER_GO_ON; } @@ -498,7 +497,7 @@ static handler_t wstunnel_handler_setup (server *srv, connection *con, plugin_da handler_ctx *hctx = con->plugin_ctx[p->id]; int hybivers; hctx->srv = srv; - hctx->errh = con->errh;/*(for mod_wstunnel module-specific DEBUG_* macros)*/ + hctx->errh = con->conf.errh;/*(for mod_wstunnel-specific DEBUG_* macros)*/ hctx->conf = p->conf; /*(copies struct)*/ hybivers = wstunnel_check_request(con, hctx); if (hybivers < 0) return HANDLER_FINISHED; @@ -911,7 +910,6 @@ handler_t mod_wstunnel_handshake_create_response(handler_ctx *hctx) { static int send_ietf_00(handler_ctx *hctx, mod_wstunnel_frame_type_t type, const char *payload, size_t siz) { static const char head = 0; /* 0x00 */ static const char tail = ~0; /* 0xff */ - server *srv = hctx->srv; connection *con = hctx->gw.remote_conn; char *mem; size_t len; @@ -919,27 +917,27 @@ static int send_ietf_00(handler_ctx *hctx, mod_wstunnel_frame_type_t type, const switch (type) { case MOD_WEBSOCKET_FRAME_TYPE_TEXT: if (0 == siz) return 0; - http_chunk_append_mem(srv, con, &head, 1); - http_chunk_append_mem(srv, con, payload, siz); - http_chunk_append_mem(srv, con, &tail, 1); + http_chunk_append_mem(con, &head, 1); + http_chunk_append_mem(con, payload, siz); + http_chunk_append_mem(con, &tail, 1); len = siz+2; break; case MOD_WEBSOCKET_FRAME_TYPE_BIN: if (0 == siz) return 0; - http_chunk_append_mem(srv, con, &head, 1); + http_chunk_append_mem(con, &head, 1); len = 4*(siz/3)+4+1; /* avoid accumulating too much data in memory; send to tmpfile */ mem = malloc(len); force_assert(mem); len=li_to_base64(mem,len,(unsigned char *)payload,siz,BASE64_STANDARD); - http_chunk_append_mem(srv, con, mem, len); + http_chunk_append_mem(con, mem, len); free(mem); - http_chunk_append_mem(srv, con, &tail, 1); + http_chunk_append_mem(con, &tail, 1); len += 2; break; case MOD_WEBSOCKET_FRAME_TYPE_CLOSE: - http_chunk_append_mem(srv, con, &tail, 1); - http_chunk_append_mem(srv, con, &head, 1); + http_chunk_append_mem(con, &tail, 1); + http_chunk_append_mem(con, &head, 1); len = 2; break; default: @@ -1064,7 +1062,6 @@ static int recv_ietf_00(handler_ctx *hctx) { #define MOD_WEBSOCKET_FRAME_LEN63_CNT 8 static int send_rfc_6455(handler_ctx *hctx, mod_wstunnel_frame_type_t type, const char *payload, size_t siz) { - server *srv = hctx->srv; connection *con = hctx->gw.remote_conn; char mem[10]; size_t len; @@ -1122,8 +1119,8 @@ static int send_rfc_6455(handler_ctx *hctx, mod_wstunnel_frame_type_t type, cons mem[9] = siz & 0xff; len = 1+MOD_WEBSOCKET_FRAME_LEN63_CNT+1; } - http_chunk_append_mem(srv, con, mem, len); - if (siz) http_chunk_append_mem(srv, con, payload, siz); + http_chunk_append_mem(con, mem, len); + if (siz) http_chunk_append_mem(con, payload, siz); DEBUG_LOG_DEBUG("send data to client (fd=%d), frame size=%zx", con->fd, len+siz); return 0; diff --git a/src/network.c b/src/network.c index f1c8f6c2..f27ae520 100644 --- a/src/network.c +++ b/src/network.c @@ -51,10 +51,8 @@ static handler_t network_server_handle_fdevent(server *srv, void *context, int r UNUSED(context); if (0 == (revents & FDEVENT_IN)) { - log_error_write(srv, __FILE__, __LINE__, "sdd", - "strange event for server socket", - srv_socket->fd, - revents); + log_error(srv->errh, __FILE__, __LINE__, + "strange event for server socket %d %d", srv_socket->fd, revents); return HANDLER_ERROR; } @@ -83,18 +81,20 @@ static int network_host_parse_addr(server *srv, sock_addr *addr, socklen_t *addr sa_family_t family = use_ipv6 ? AF_INET6 : AF_INET; unsigned int port = srv->srvconf.port; if (buffer_string_is_empty(host)) { - log_error_write(srv, __FILE__, __LINE__, "s", "value of $SERVER[\"socket\"] must not be empty"); + log_error(srv->errh, __FILE__, __LINE__, + "value of $SERVER[\"socket\"] must not be empty"); return -1; } h = host->ptr; if (h[0] == '/') { #ifdef HAVE_SYS_UN_H - return (1 == sock_addr_from_str_hints(srv,addr,addr_len,h,AF_UNIX,0)) + return (1 == + sock_addr_from_str_hints(addr,addr_len,h,AF_UNIX,0,srv->errh)) ? 0 : -1; #else - log_error_write(srv, __FILE__, __LINE__, "s", - "ERROR: Unix Domain sockets are not supported."); + log_error(srv, __FILE__, __LINE__, + "ERROR: Unix Domain sockets are not supported."); return -1; #endif } @@ -115,13 +115,14 @@ static int network_host_parse_addr(server *srv, sock_addr *addr, socklen_t *addr *colon++ = '\0'; port = strtol(colon, NULL, 10); if (port == 0 || port > 65535) { - log_error_write(srv, __FILE__, __LINE__, "sd", - "port not set or out of range:", port); + log_error(srv->errh, __FILE__, __LINE__, + "port not set or out of range: %hd", port); return -1; } } chost = *h ? h : family == AF_INET ? "0.0.0.0" : "::"; - if (1 != sock_addr_from_str_hints(srv,addr,addr_len,chost,family,port)) { + if (1 != + sock_addr_from_str_hints(addr,addr_len,chost,family,port,srv->errh)) { return -1; } return 0; @@ -197,7 +198,8 @@ static int network_server_init(server *srv, network_socket_config *s, buffer *ho int set_v6only = 0; if (buffer_string_is_empty(host_token)) { - log_error_write(srv, __FILE__, __LINE__, "s", "value of $SERVER[\"socket\"] must not be empty"); + log_error(srv->errh, __FILE__, __LINE__, + "value of $SERVER[\"socket\"] must not be empty"); return -1; } @@ -212,15 +214,17 @@ static int network_server_init(server *srv, network_socket_config *s, buffer *ho host = host_token->ptr; if ((s->use_ipv6 && (*host == '\0' || *host == ':')) || (host[0] == '[' && host[1] == ']')) { - log_error_write(srv, __FILE__, __LINE__, "s", "warning: please use server.use-ipv6 only for hostnames, not without server.bind / empty address; your config will break if the kernel default for IPV6_V6ONLY changes"); + log_error(srv->errh, __FILE__, __LINE__, + "warning: please use server.use-ipv6 only for hostnames, " + "not without server.bind / empty address; your config will " + "break if the kernel default for IPV6_V6ONLY changes"); } if (*host == '[') s->use_ipv6 = 1; memset(&addr, 0, sizeof(addr)); if (-1 != stdin_fd) { if (-1 == getsockname(stdin_fd, (struct sockaddr *)&addr, &addr_len)) { - log_error_write(srv, __FILE__, __LINE__, "ss", - "getsockname()", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, "getsockname()"); return -1; } } else if (0 != network_host_parse_addr(srv, &addr, &addr_len, host_token, s->use_ipv6)) { @@ -234,7 +238,9 @@ static int network_server_init(server *srv, network_socket_config *s, buffer *ho if (s->set_v6only) { set_v6only = 1; } else { - log_error_write(srv, __FILE__, __LINE__, "s", "warning: server.set-v6only will be removed soon, update your config to have different sockets for ipv4 and ipv6"); + log_error(srv->errh, __FILE__, __LINE__, + "warning: server.set-v6only will be removed soon, " + "update your config to have different sockets for ipv4 and ipv6"); } } #endif @@ -281,7 +287,7 @@ static int network_server_init(server *srv, network_socket_config *s, buffer *ho if (-1 != stdin_fd) { srv_socket->fd = stdin_fd; if (-1 == fdevent_fcntl_set_nb_cloexec(srv->ev, stdin_fd)) { - log_error_write(srv, __FILE__, __LINE__, "ss", "fcntl:", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, "fcntl"); return -1; } } else @@ -290,15 +296,12 @@ static int network_server_init(server *srv, network_socket_config *s, buffer *ho /* check if the socket exists and try to connect to it. */ force_assert(host); /*(static analysis hint)*/ if (-1 == (srv_socket->fd = fdevent_socket_cloexec(AF_UNIX, SOCK_STREAM, 0))) { - log_error_write(srv, __FILE__, __LINE__, "ss", "socket failed:", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, "socket"); return -1; } if (0 == connect(srv_socket->fd, (struct sockaddr *) &(srv_socket->addr), addr_len)) { - log_error_write(srv, __FILE__, __LINE__, "ss", - "server socket is still in use:", - host); - - + log_error(srv->errh, __FILE__, __LINE__, + "server socket is still in use: %s", host); return -1; } @@ -310,22 +313,20 @@ static int network_server_init(server *srv, network_socket_config *s, buffer *ho case ENOENT: break; default: - log_error_write(srv, __FILE__, __LINE__, "sds", - "testing socket failed:", - host, strerror(errno)); - + log_perror(srv->errh, __FILE__, __LINE__, + "testing socket failed: %s", host); return -1; } if (-1 == fdevent_fcntl_set_nb(srv->ev, srv_socket->fd)) { - log_error_write(srv, __FILE__, __LINE__, "ss", "fcntl:", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, "fcntl"); return -1; } } else #endif { if (-1 == (srv_socket->fd = fdevent_socket_nb_cloexec(family, SOCK_STREAM, IPPROTO_TCP))) { - log_error_write(srv, __FILE__, __LINE__, "ss", "socket failed:", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, "socket"); return -1; } } @@ -334,7 +335,7 @@ static int network_server_init(server *srv, network_socket_config *s, buffer *ho if (set_v6only && -1 == stdin_fd) { int val = 1; if (-1 == setsockopt(srv_socket->fd, IPPROTO_IPV6, IPV6_V6ONLY, &val, sizeof(val))) { - log_error_write(srv, __FILE__, __LINE__, "ss", "setsockopt(IPV6_V6ONLY) failed:", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, "setsockopt(IPV6_V6ONLY)"); return -1; } } @@ -344,21 +345,21 @@ static int network_server_init(server *srv, network_socket_config *s, buffer *ho srv->cur_fds = srv_socket->fd; if (fdevent_set_so_reuseaddr(srv_socket->fd, 1) < 0) { - log_error_write(srv, __FILE__, __LINE__, "ss", "setsockopt(SO_REUSEADDR) failed:", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, "setsockopt(SO_REUSEADDR)"); return -1; } if (family != AF_UNIX) { if (fdevent_set_tcp_nodelay(srv_socket->fd, 1) < 0) { - log_error_write(srv, __FILE__, __LINE__, "ss", "setsockopt(TCP_NODELAY) failed:", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, "setsockopt(TCP_NODELAY)"); return -1; } } if (-1 != stdin_fd) { } else if (0 != bind(srv_socket->fd, (struct sockaddr *) &(srv_socket->addr), addr_len)) { - log_error_write(srv, __FILE__, __LINE__, "sss", - "can't bind to socket:", host, strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, + "can't bind to socket: %s", host); return -1; } @@ -370,13 +371,14 @@ static int network_server_init(server *srv, network_socket_config *s, buffer *ho m |= (*str - '0'); } if (0 != m && -1 == chmod(host, m)) { - log_error_write(srv, __FILE__, __LINE__, "sssbss", "chmod(\"", host, "\", ", s->socket_perms, "):", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, + "chmod(\"%s\", %s)", host, s->socket_perms->ptr); } } if (-1 != stdin_fd) { } else if (-1 == listen(srv_socket->fd, s->listen_backlog)) { - log_error_write(srv, __FILE__, __LINE__, "ss", "listen failed: ", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, "listen"); return -1; } @@ -385,7 +387,7 @@ static int network_server_init(server *srv, network_socket_config *s, buffer *ho } else if (s->defer_accept) { int v = s->defer_accept; if (-1 == setsockopt(srv_socket->fd, IPPROTO_TCP, TCP_DEFER_ACCEPT, &v, sizeof(v))) { - log_error_write(srv, __FILE__, __LINE__, "ss", "can't set TCP_DEFER_ACCEPT: ", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, "can't set TCP_DEFER_ACCEPT"); } #endif #if defined(__FreeBSD__) || defined(__NetBSD__) \ @@ -400,7 +402,8 @@ static int network_server_init(server *srv, network_socket_config *s, buffer *ho strncpy(afa.af_name, s->bsd_accept_filter->ptr, sizeof(afa.af_name)); if (setsockopt(srv_socket->fd, SOL_SOCKET, SO_ACCEPTFILTER, &afa, sizeof(afa)) < 0) { if (errno != ENOENT) { - log_error_write(srv, __FILE__, __LINE__, "SBss", "can't set accept-filter '", s->bsd_accept_filter, "':", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, + "can't set accept-filter '%s'", s->bsd_accept_filter->ptr); } } #endif @@ -456,8 +459,8 @@ static int network_socket_activation_nfds(server *srv, network_socket_config *s, for (int fd = 3; fd < nfds; ++fd) { addr_len = sizeof(sock_addr); if (-1 == (rc = getsockname(fd, (struct sockaddr *)&addr, &addr_len))) { - log_error_write(srv, __FILE__, __LINE__, "ss", - "socket activation getsockname()", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, + "socket activation getsockname()"); break; } network_host_normalize_addr_str(host, &addr); diff --git a/src/network_write.c b/src/network_write.c index 325546bb..577ef172 100644 --- a/src/network_write.c +++ b/src/network_write.c @@ -67,7 +67,7 @@ #endif -static int network_write_error(server *srv, int fd) { +static int network_write_error(int fd, log_error_st *errh) { #if defined(__WIN32) int lastError = WSAGetLastError(); switch (lastError) { @@ -79,8 +79,7 @@ static int network_write_error(server *srv, int fd) { case WSAECONNABORTED: return -2; default: - log_error_write(srv, __FILE__, __LINE__, "sdd", - "send failed: ", lastError, fd); + log_error(errh,__FILE__,__LINE__,"send failed: %d %d",lastError,fd); return -1; } #else /* __WIN32 */ @@ -92,8 +91,7 @@ static int network_write_error(server *srv, int fd) { case ECONNRESET: return -2; default: - log_error_write(srv, __FILE__, __LINE__, "ssd", - "write failed:", strerror(errno), fd); + log_perror(errh,__FILE__,__LINE__,"write failed: %d",fd); return -1; } #endif /* __WIN32 */ @@ -114,7 +112,7 @@ static ssize_t network_write_data_len(int fd, const char *data, off_t len) { /* write next chunk(s); finished chunks are removed afterwards after successful writes. * return values: similar as backends (0 succes, -1 error, -2 remote close, -3 try again later (EINTR/EAGAIN)) */ /* next chunk must be MEM_CHUNK. use write()/send() */ -static int network_write_mem_chunk(server *srv, int fd, chunkqueue *cq, off_t *p_max_bytes) { +static int network_write_mem_chunk(int fd, chunkqueue *cq, off_t *p_max_bytes, log_error_st *errh) { chunk* const c = cq->first; ssize_t wr; off_t c_len = (off_t)buffer_string_length(c->mem); @@ -133,7 +131,7 @@ static int network_write_mem_chunk(server *srv, int fd, chunkqueue *cq, off_t *p chunkqueue_mark_written(cq, wr); return (wr > 0 && wr == c_len) ? 0 : -3; } else { - return network_write_error(srv, fd); + return network_write_error(fd, errh); } } @@ -142,10 +140,11 @@ static int network_write_mem_chunk(server *srv, int fd, chunkqueue *cq, off_t *p #if !defined(NETWORK_WRITE_USE_MMAP) -static int network_write_file_chunk_no_mmap(server *srv, int fd, chunkqueue *cq, off_t *p_max_bytes) { +static int network_write_file_chunk_no_mmap(int fd, chunkqueue *cq, off_t *p_max_bytes, log_error_st *errh) { chunk* const c = cq->first; off_t offset, toSend; ssize_t wr; + char buf[16384]; /* max read 16kb in one step */ force_assert(c->offset >= 0 && c->offset <= c->file.length); @@ -158,27 +157,26 @@ static int network_write_file_chunk_no_mmap(server *srv, int fd, chunkqueue *cq, return 0; } - if (0 != chunkqueue_open_file_chunk(srv, cq)) return -1; + if (0 != chunkqueue_open_file_chunk(cq, errh)) return -1; - if (toSend > 64*1024) toSend = 64*1024; /* max read 64kb in one step */ - buffer_string_prepare_copy(srv->tmp_buf, toSend); + if (toSend > (off_t)sizeof(buf)) toSend = (off_t)sizeof(buf); if (-1 == lseek(c->file.fd, offset, SEEK_SET)) { - log_error_write(srv, __FILE__, __LINE__, "ss","lseek:",strerror(errno)); + log_perror(errh, __FILE__, __LINE__, "lseek"); return -1; } - if (-1 == (toSend = read(c->file.fd, srv->tmp_buf->ptr, toSend))) { - log_error_write(srv, __FILE__, __LINE__, "ss","read:",strerror(errno)); + if (-1 == (toSend = read(c->file.fd, buf, toSend))) { + log_perror(errh, __FILE__, __LINE__, "read"); return -1; } - wr = network_write_data_len(fd, srv->tmp_buf->ptr, toSend); + wr = network_write_data_len(fd, buf, toSend); if (wr >= 0) { *p_max_bytes -= wr; chunkqueue_mark_written(cq, wr); return (wr > 0 && wr == toSend) ? 0 : -3; } else { - return network_write_error(srv, fd); + return network_write_error(fd, errh); } } @@ -216,7 +214,7 @@ static void sigbus_handler(int sig) { } /* next chunk must be FILE_CHUNK. send mmap()ed file with write() */ -static int network_write_file_chunk_mmap(server *srv, int fd, chunkqueue *cq, off_t *p_max_bytes) { +static int network_write_file_chunk_mmap(int fd, chunkqueue *cq, off_t *p_max_bytes, log_error_st *errh) { chunk* const c = cq->first; off_t offset, toSend, file_end; ssize_t r; @@ -235,7 +233,7 @@ static int network_write_file_chunk_mmap(server *srv, int fd, chunkqueue *cq, of return 0; } - if (0 != chunkqueue_open_file_chunk(srv, cq)) return -1; + if (0 != chunkqueue_open_file_chunk(cq, errh)) return -1; /* mmap buffer if offset is outside old mmap area or not mapped at all */ if (MAP_FAILED == c->file.mmap.start @@ -280,9 +278,9 @@ static int network_write_file_chunk_mmap(server *srv, int fd, chunkqueue *cq, of c->file.mmap.start = mmap(NULL, c->file.mmap.length, PROT_READ, MAP_SHARED, c->file.fd, c->file.mmap.offset); if (MAP_FAILED == c->file.mmap.start) { - log_error_write(srv, __FILE__, __LINE__, "ssbdoo", "mmap failed:", - strerror(errno), c->mem, c->file.fd, - c->file.mmap.offset, (off_t) c->file.mmap.length); + log_perror(errh, __FILE__, __LINE__, + "mmap failed: %s %d %lld %zu", c->mem->ptr, c->file.fd, + (long long)c->file.mmap.offset, c->file.mmap.length); return -1; } @@ -316,8 +314,8 @@ static int network_write_file_chunk_mmap(server *srv, int fd, chunkqueue *cq, of } else { sigbus_jmp_valid = 0; - log_error_write(srv, __FILE__, __LINE__, "sbd", "SIGBUS in mmap:", - c->mem, c->file.fd); + log_error(errh, __FILE__, __LINE__, + "SIGBUS in mmap: %s %d", c->mem->ptr, c->file.fd); munmap(c->file.mmap.start, c->file.mmap.length); c->file.mmap.start = MAP_FAILED; @@ -329,7 +327,7 @@ static int network_write_file_chunk_mmap(server *srv, int fd, chunkqueue *cq, of chunkqueue_mark_written(cq, r); return (r > 0 && r == toSend) ? 0 : -3; } else { - return network_write_error(srv, fd); + return network_write_error(fd, errh); } } @@ -368,7 +366,7 @@ static int network_write_file_chunk_mmap(server *srv, int fd, chunkqueue *cq, of #endif /* next chunk must be MEM_CHUNK. send multiple mem chunks using writev() */ -static int network_writev_mem_chunks(server *srv, int fd, chunkqueue *cq, off_t *p_max_bytes) { +static int network_writev_mem_chunks(int fd, chunkqueue *cq, off_t *p_max_bytes, log_error_st *errh) { struct iovec chunks[MAX_CHUNKS]; size_t num_chunks = 0; off_t max_bytes = *p_max_bytes; @@ -407,8 +405,7 @@ static int network_writev_mem_chunks(server *srv, int fd, chunkqueue *cq, off_t case ECONNRESET: return -2; default: - log_error_write(srv, __FILE__, __LINE__, "ssd", - "writev failed:", strerror(errno), fd); + log_perror(errh, __FILE__, __LINE__, "writev failed: %d", fd); return -1; } @@ -437,7 +434,7 @@ static int network_writev_mem_chunks(server *srv, int fd, chunkqueue *cq, off_t #include #endif -static int network_write_file_chunk_sendfile(server *srv, int fd, chunkqueue *cq, off_t *p_max_bytes) { +static int network_write_file_chunk_sendfile(int fd, chunkqueue *cq, off_t *p_max_bytes, log_error_st *errh) { chunk * const c = cq->first; ssize_t r; off_t offset; @@ -455,7 +452,7 @@ static int network_write_file_chunk_sendfile(server *srv, int fd, chunkqueue *cq return 0; } - if (0 != chunkqueue_open_file_chunk(srv, cq)) return -1; + if (0 != chunkqueue_open_file_chunk(cq, errh)) return -1; /* Darwin, FreeBSD, and Solaris variants support iovecs and could * be optimized to send more than just file in single syscall */ @@ -519,13 +516,12 @@ static int network_write_file_chunk_sendfile(server *srv, int fd, chunkqueue *cq case EAFNOSUPPORT: #endif #ifdef NETWORK_WRITE_USE_MMAP - return network_write_file_chunk_mmap(srv, fd, cq, p_max_bytes); + return network_write_file_chunk_mmap(fd, cq, p_max_bytes, errh); #else - return network_write_file_chunk_no_mmap(srv, fd, cq, p_max_bytes); + return network_write_file_chunk_no_mmap(fd, cq, p_max_bytes, errh); #endif default: - log_error_write(srv, __FILE__, __LINE__, "ssdSd", - "sendfile():", strerror(errno), errno, "fd:", fd); + log_perror(errh, __FILE__, __LINE__, "sendfile(): fd: %d", fd); return -1; } } @@ -549,19 +545,19 @@ static int network_write_file_chunk_sendfile(server *srv, int fd, chunkqueue *cq * -2 : remote close */ -static int network_write_chunkqueue_write(server *srv, int fd, chunkqueue *cq, off_t max_bytes) { +static int network_write_chunkqueue_write(int fd, chunkqueue *cq, off_t max_bytes, log_error_st *errh) { while (max_bytes > 0 && NULL != cq->first) { int r = -1; switch (cq->first->type) { case MEM_CHUNK: - r = network_write_mem_chunk(srv, fd, cq, &max_bytes); + r = network_write_mem_chunk(fd, cq, &max_bytes, errh); break; case FILE_CHUNK: #ifdef NETWORK_WRITE_USE_MMAP - r = network_write_file_chunk_mmap(srv, fd, cq, &max_bytes); + r = network_write_file_chunk_mmap(fd, cq, &max_bytes, errh); #else - r = network_write_file_chunk_no_mmap(srv, fd, cq, &max_bytes); + r = network_write_file_chunk_no_mmap(fd, cq, &max_bytes, errh); #endif break; } @@ -574,23 +570,23 @@ static int network_write_chunkqueue_write(server *srv, int fd, chunkqueue *cq, o } #if defined(NETWORK_WRITE_USE_WRITEV) -static int network_write_chunkqueue_writev(server *srv, int fd, chunkqueue *cq, off_t max_bytes) { +static int network_write_chunkqueue_writev(int fd, chunkqueue *cq, off_t max_bytes, log_error_st *errh) { while (max_bytes > 0 && NULL != cq->first) { int r = -1; switch (cq->first->type) { case MEM_CHUNK: #if defined(NETWORK_WRITE_USE_WRITEV) - r = network_writev_mem_chunks(srv, fd, cq, &max_bytes); + r = network_writev_mem_chunks(fd, cq, &max_bytes, errh); #else - r = network_write_mem_chunk(srv, fd, cq, &max_bytes); + r = network_write_mem_chunk(fd, cq, &max_bytes, errh); #endif break; case FILE_CHUNK: #ifdef NETWORK_WRITE_USE_MMAP - r = network_write_file_chunk_mmap(srv, fd, cq, &max_bytes); + r = network_write_file_chunk_mmap(fd, cq, &max_bytes, errh); #else - r = network_write_file_chunk_no_mmap(srv, fd, cq, &max_bytes); + r = network_write_file_chunk_no_mmap(fd, cq, &max_bytes, errh); #endif break; } @@ -604,25 +600,25 @@ static int network_write_chunkqueue_writev(server *srv, int fd, chunkqueue *cq, #endif #if defined(NETWORK_WRITE_USE_SENDFILE) -static int network_write_chunkqueue_sendfile(server *srv, int fd, chunkqueue *cq, off_t max_bytes) { +static int network_write_chunkqueue_sendfile(int fd, chunkqueue *cq, off_t max_bytes, log_error_st *errh) { while (max_bytes > 0 && NULL != cq->first) { int r = -1; switch (cq->first->type) { case MEM_CHUNK: #if defined(NETWORK_WRITE_USE_WRITEV) - r = network_writev_mem_chunks(srv, fd, cq, &max_bytes); + r = network_writev_mem_chunks(fd, cq, &max_bytes, errh); #else - r = network_write_mem_chunk(srv, fd, cq, &max_bytes); + r = network_write_mem_chunk(fd, cq, &max_bytes, errh); #endif break; case FILE_CHUNK: #if defined(NETWORK_WRITE_USE_SENDFILE) - r = network_write_file_chunk_sendfile(srv, fd, cq, &max_bytes); + r = network_write_file_chunk_sendfile(fd, cq, &max_bytes, errh); #elif defined(NETWORK_WRITE_USE_MMAP) - r = network_write_file_chunk_mmap(srv, fd, cq, &max_bytes); + r = network_write_file_chunk_mmap(fd, cq, &max_bytes, errh); #else - r = network_write_file_chunk_no_mmap(srv, fd, cq, &max_bytes); + r = network_write_file_chunk_no_mmap(fd, cq, &max_bytes, errh); #endif break; } @@ -664,17 +660,16 @@ int network_write_init(server *srv) { /* match name against known types */ if (!buffer_string_is_empty(srv->srvconf.network_backend)) { - const char *name; + const char *name, *confname = srv->srvconf.network_backend->ptr; for (size_t i = 0; NULL != (name = network_backends[i].name); ++i) { - if (0 == strcmp(srv->srvconf.network_backend->ptr, name)) { + if (0 == strcmp(confname, name)) { backend = network_backends[i].nb; break; } } if (NULL == name) { - log_error_write(srv, __FILE__, __LINE__, "sb", - "server.network-backend has an unknown value:", - srv->srvconf.network_backend); + log_error(srv->errh, __FILE__, __LINE__, + "server.network-backend has an unknown value: %s", confname); return -1; } } diff --git a/src/network_write.h b/src/network_write.h index 375b3c1e..16114c00 100644 --- a/src/network_write.h +++ b/src/network_write.h @@ -3,6 +3,7 @@ #include "first.h" #include "base_decls.h" +__attribute_cold__ int network_write_init(server *srv); __attribute_cold__ diff --git a/src/plugin.c b/src/plugin.c index 3923e20d..139aa8fb 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -121,27 +121,26 @@ static const plugin_load_functions load_functions[] = { }; int plugins_load(server *srv) { - plugin *p; - size_t i, j; - - for (i = 0; i < srv->srvconf.modules->used; i++) { + for (uint32_t i = 0; i < srv->srvconf.modules->used; ++i) { data_string *ds = (data_string *)srv->srvconf.modules->data[i]; char *module = ds->value.ptr; - for (j = 0; j < i; j++) { + uint32_t j; + for (j = 0; j < i; ++j) { if (buffer_is_equal(&ds->value, &((data_string *) srv->srvconf.modules->data[j])->value)) { - log_error_write(srv, __FILE__, __LINE__, "sbs", - "Cannot load plugin", &ds->value, - "more than once, please fix your config (lighttpd may not accept such configs in future releases)"); + log_error(srv->errh, __FILE__, __LINE__, + "Cannot load plugin %s " + "more than once, please fix your config (lighttpd may not accept such configs in future releases)", + ds->value.ptr); continue; } } for (j = 0; load_functions[j].name; ++j) { if (0 == strcmp(load_functions[j].name, module)) { - p = plugin_init(); + plugin * const p = plugin_init(); if ((*load_functions[j].plugin_init)(p)) { - log_error_write(srv, __FILE__, __LINE__, "ss", module, "plugin init failed" ); + log_error(srv->errh, __FILE__, __LINE__, "%s plugin init failed", module); plugin_free(p); return -1; } @@ -150,7 +149,7 @@ int plugins_load(server *srv) { } } if (!load_functions[j].name) { - log_error_write(srv, __FILE__, __LINE__, "ss", module, " plugin not found" ); + log_error(srv->errh, __FILE__, __LINE__, "%s plugin not found", module); return -1; } } @@ -169,9 +168,10 @@ int plugins_load(server *srv) { for (j = 0; j < i; j++) { if (buffer_is_equal(&ds->value, &((data_string *) srv->srvconf.modules->data[j])->value)) { - log_error_write(srv, __FILE__, __LINE__, "sbs", - "Cannot load plugin", &ds->value, - "more than once, please fix your config (lighttpd may not accept such configs in future releases)"); + log_error(srv->errh, __FILE__, __LINE__, + "Cannot load plugin %s " + "more than once, please fix your config (lighttpd may not accept such configs in future releases)", + ds->value.ptr); continue; } } @@ -199,8 +199,8 @@ int plugins_load(server *srv) { (LPTSTR) &lpMsgBuf, 0, NULL); - log_error_write(srv, __FILE__, __LINE__, "ssb", "LoadLibrary() failed", - lpMsgBuf, srv->tmp_buf); + log_error(srv->errh, __FILE__, __LINE__, + "LoadLibrary() failed %s %s", lpMsgBuf, srv->tmp_buf->ptr); plugin_free(p); @@ -209,8 +209,8 @@ int plugins_load(server *srv) { } #else if (NULL == (p->lib = dlopen(srv->tmp_buf->ptr, RTLD_NOW|RTLD_GLOBAL))) { - log_error_write(srv, __FILE__, __LINE__, "sbs", "dlopen() failed for:", - srv->tmp_buf, dlerror()); + log_error(srv->errh, __FILE__, __LINE__, + "dlopen() failed for: %s %s", srv->tmp_buf->ptr, dlerror()); plugin_free(p); @@ -235,7 +235,8 @@ int plugins_load(server *srv) { (LPTSTR) &lpMsgBuf, 0, NULL); - log_error_write(srv, __FILE__, __LINE__, "sbs", "getprocaddress failed:", srv->tmp_buf, lpMsgBuf); + log_error(srv->errh, __FILE__, __LINE__, + "getprocaddress failed: %s %s", srv->tmp_buf->ptr, lpMsgBuf); plugin_free(p); return -1; @@ -250,9 +251,9 @@ int plugins_load(server *srv) { if (NULL == init) { const char *error = dlerror(); if (error != NULL) { - log_error_write(srv, __FILE__, __LINE__, "ss", "dlsym:", error); + log_error(srv->errh, __FILE__, __LINE__, "dlsym: %s", error); } else { - log_error_write(srv, __FILE__, __LINE__, "ss", "dlsym symbol not found:", srv->tmp_buf->ptr); + log_error(srv->errh, __FILE__, __LINE__, "dlsym symbol not found: %s", srv->tmp_buf->ptr); } plugin_free(p); @@ -261,13 +262,13 @@ int plugins_load(server *srv) { #endif if ((*init)(p)) { - log_error_write(srv, __FILE__, __LINE__, "ss", module, "plugin init failed" ); + log_error(srv->errh, __FILE__, __LINE__, "%s plugin init failed", module); plugin_free(p); return -1; } #if 0 - log_error_write(srv, __FILE__, __LINE__, "ss", module, "plugin loaded" ); + log_error(srv->errh, __FILE__, __LINE__, "%s plugin loaded", module); #endif plugins_register(srv, p); } @@ -424,8 +425,8 @@ handler_t plugins_call_init(server *srv) { if (p->init) { if (NULL == (p->data = p->init())) { - log_error_write(srv, __FILE__, __LINE__, "ss", - "plugin-init failed for module", p->name); + log_error(srv->errh, __FILE__, __LINE__, + "plugin-init failed for module %s", p->name); return HANDLER_ERROR; } @@ -433,8 +434,8 @@ handler_t plugins_call_init(server *srv) { ((plugin_data_base *)(p->data))->id = i + 1; if (p->version != LIGHTTPD_VERSION_ID) { - log_error_write(srv, __FILE__, __LINE__, "ss", - "plugin-version doesn't match lighttpd-version for", p->name); + log_error(srv->errh, __FILE__, __LINE__, + "plugin-version doesn't match lighttpd-version for %s", p->name); return HANDLER_ERROR; } } diff --git a/src/plugin_config.h b/src/plugin_config.h index 16540a37..67bd44af 100644 --- a/src/plugin_config.h +++ b/src/plugin_config.h @@ -74,8 +74,8 @@ void config_reset_config_bytes_sec(void *p); void config_reset_config(server *srv, connection *con); void config_patch_config(server *srv, connection *con); -void config_cond_cache_reset(server *srv, connection *con); -void config_cond_cache_reset_item(server *srv, connection *con, comp_key_t item); +void config_cond_cache_reset(connection *con); +void config_cond_cache_reset_item(connection *con, comp_key_t item); typedef enum { T_CONFIG_UNSET, T_CONFIG_STRING, diff --git a/src/request.c b/src/request.c index 7d76c8bc..b27e26f0 100644 --- a/src/request.c +++ b/src/request.c @@ -355,7 +355,7 @@ __attribute_cold__ __attribute_noinline__ static int http_request_header_line_invalid(connection * const con, const int status, const char * const msg) { if (con->srv->srvconf.log_request_header_on_error) { - if (msg) log_error(con->errh, __FILE__, __LINE__, "%s", msg); + if (msg) log_error(con->conf.errh, __FILE__, __LINE__, "%s", msg); } return status; } @@ -365,10 +365,10 @@ __attribute_noinline__ static int http_request_header_char_invalid(connection * const con, const char ch, const char * const msg) { if (con->srv->srvconf.log_request_header_on_error) { if ((unsigned char)ch > 32 && ch != 127) { - log_error(con->errh, __FILE__, __LINE__, "%s ('%c')", msg, ch); + log_error(con->conf.errh, __FILE__, __LINE__, "%s ('%c')", msg, ch); } else { - log_error(con->errh, __FILE__, __LINE__, "%s (0x%x)", msg, ch); + log_error(con->conf.errh, __FILE__, __LINE__, "%s (0x%x)", msg, ch); } } return 400; diff --git a/src/response.c b/src/response.c index 3f53163b..2d98ea06 100644 --- a/src/response.c +++ b/src/response.c @@ -45,7 +45,7 @@ static int http_response_omit_header(connection *con, const data_string * const return 0; } -int http_response_write_header(server *srv, connection *con) { +int http_response_write_header(connection *con) { buffer * const b = chunkqueue_prepend_buffer_open(con->write_queue); if (con->request.http_version == HTTP_VERSION_1_1) { @@ -99,6 +99,7 @@ int http_response_write_header(server *srv, connection *con) { buffer_append_string_len(b, CONST_STR_LEN("\r\nDate: ")); /* cache the generated timestamp */ + server * const srv = con->srv; if (srv->cur_ts != srv->last_generated_date_ts) { buffer_clear(srv->ts_date_str); buffer_append_strftime(srv->ts_date_str, "%a, %d %b %Y %H:%M:%S GMT", gmtime(&(srv->cur_ts))); @@ -120,7 +121,7 @@ int http_response_write_header(server *srv, connection *con) { con->bytes_header = buffer_string_length(b); if (con->conf.log_response_header) { - log_error_write(srv, __FILE__, __LINE__, "sSb", "Response-Header:", "\n", b); + log_error(con->conf.errh,__FILE__,__LINE__,"Response-Header:\n%s",b->ptr); } chunkqueue_prepend_buffer_commit(con->write_queue); @@ -139,8 +140,10 @@ static handler_t http_response_physical_path_check(server *srv, connection *con) con->http_status = 403; if (con->conf.log_request_handling) { - log_error_write(srv, __FILE__, __LINE__, "s", "-- access denied"); - log_error_write(srv, __FILE__, __LINE__, "sb", "Path :", con->physical.path); + log_error(con->conf.errh, __FILE__, __LINE__, + "-- access denied"); + log_error(con->conf.errh, __FILE__, __LINE__, + "Path : %s", con->physical.path->ptr); } buffer_reset(con->physical.path); @@ -157,8 +160,10 @@ static handler_t http_response_physical_path_check(server *srv, connection *con) con->http_status = 404; if (con->conf.log_request_handling) { - log_error_write(srv, __FILE__, __LINE__, "s", "-- file not found"); - log_error_write(srv, __FILE__, __LINE__, "sb", "Path :", con->physical.path); + log_error(con->conf.errh, __FILE__, __LINE__, + "-- file not found"); + log_error(con->conf.errh, __FILE__, __LINE__, + "Path : %s", con->physical.path->ptr); } buffer_reset(con->physical.path); @@ -168,10 +173,9 @@ static handler_t http_response_physical_path_check(server *srv, connection *con) break; default: /* we have no idea what happend. let's tell the user so. */ - log_error_write(srv, __FILE__, __LINE__, "ssbsb", - "file not found ... or so: ", strerror(errno), - con->uri.path, - "->", con->physical.path); + log_error(con->conf.errh, __FILE__, __LINE__, + "file not found ... or so: %s -> %s", + con->uri.path->ptr, con->physical.path->ptr); con->http_status = 500; buffer_reset(con->physical.path); @@ -194,10 +198,11 @@ static handler_t http_response_physical_path_check(server *srv, connection *con) } } + buffer * const tb = srv->tmp_buf; for (char *pprev = pathinfo; pathinfo; pprev = pathinfo, pathinfo = strchr(pathinfo+1, '/')) { stat_cache_entry *nsce = NULL; - buffer_copy_string_len(srv->tmp_buf, con->physical.path->ptr, pathinfo - con->physical.path->ptr); - if (HANDLER_ERROR == stat_cache_get_entry(srv, con, srv->tmp_buf, &nsce)) { + buffer_copy_string_len(tb, con->physical.path->ptr, pathinfo - con->physical.path->ptr); + if (HANDLER_ERROR == stat_cache_get_entry(srv, con, tb, &nsce)) { pathinfo = pathinfo != pprev ? pprev : NULL; break; } @@ -210,9 +215,9 @@ static handler_t http_response_physical_path_check(server *srv, connection *con) con->http_status = 404; if (con->conf.log_file_not_found) { - log_error_write(srv, __FILE__, __LINE__, "sbsb", - "file not found:", con->uri.path, - "->", con->physical.path); + log_error(con->conf.errh, __FILE__, __LINE__, + "file not found: %s -> %s", + con->uri.path->ptr, con->physical.path->ptr); } buffer_reset(con->physical.path); @@ -249,8 +254,10 @@ static handler_t http_response_physical_path_check(server *srv, connection *con) con->http_status = 403; if (con->conf.log_request_handling) { - log_error_write(srv, __FILE__, __LINE__, "s", "-- access denied due symlink restriction"); - log_error_write(srv, __FILE__, __LINE__, "sb", "Path :", con->physical.path); + log_error(con->conf.errh, __FILE__, __LINE__, + "-- access denied due symlink restriction"); + log_error(con->conf.errh, __FILE__, __LINE__, + "Path : %s", con->physical.path->ptr); } buffer_reset(con->physical.path); @@ -261,7 +268,7 @@ static handler_t http_response_physical_path_check(server *srv, connection *con) if (con->uri.path->ptr[buffer_string_length(con->uri.path) - 1] != '/') { /* redirect to .../ */ - http_response_redirect_to_directory(srv, con, 301); + http_response_redirect_to_directory(con, 301); return HANDLER_FINISHED; } @@ -303,10 +310,10 @@ handler_t http_response_prepare(server *srv, connection *con) { if (!con->async_callback) { - config_cond_cache_reset(srv, con); + config_cond_cache_reset(con); if (con->conf.log_condition_handling) { - log_error_write(srv, __FILE__, __LINE__, "s", "run condition"); + log_error(con->conf.errh, __FILE__, __LINE__, "run condition"); } /** @@ -352,9 +359,9 @@ handler_t http_response_prepare(server *srv, connection *con) { /*uint32_t len = (uint32_t)buffer_string_length(con->request.uri);*/ int qs = burl_normalize(con->request.uri, srv->tmp_buf, con->conf.http_parseopts); if (-2 == qs) { - log_error_write(srv, __FILE__, __LINE__, "sb", - "invalid character in URI -> 400", - con->request.uri); + log_error(con->conf.errh, __FILE__, __LINE__, + "invalid character in URI -> 400 %s", + con->request.uri->ptr); con->keep_alive = 0; con->http_status = 400; /* Bad Request */ con->file_finished = 1; @@ -376,8 +383,8 @@ handler_t http_response_prepare(server *srv, connection *con) { return HANDLER_FINISHED; } if (con->header_len > MAX_HTTP_REQUEST_HEADER) { - log_error_write(srv, __FILE__, __LINE__, "sds", - "request header fields too large:", con->header_len, "-> 431"); + log_error(con->conf.errh, __FILE__, __LINE__, + "request header fields too large: %u -> 431", con->header_len); con->keep_alive = 0; con->http_status = 431; /* Request Header Fields Too Large */ con->file_finished = 1; @@ -416,8 +423,8 @@ handler_t http_response_prepare(server *srv, connection *con) { buffer_urldecode_path(con->uri.path); buffer_path_simplify(con->uri.path, con->uri.path); if (buffer_string_is_empty(con->uri.path) || con->uri.path->ptr[0] != '/') { - log_error_write(srv, __FILE__, __LINE__, "sbs", - "uri-path does not begin with '/':", con->uri.path, "-> 400"); + log_error(con->conf.errh, __FILE__, __LINE__, + "uri-path does not begin with '/': %s -> 400", con->uri.path->ptr); con->keep_alive = 0; con->http_status = 400; con->file_finished = 1; @@ -441,20 +448,28 @@ handler_t http_response_prepare(server *srv, connection *con) { } if (con->conf.log_request_handling) { - log_error_write(srv, __FILE__, __LINE__, "s", "-- splitting Request-URI"); - log_error_write(srv, __FILE__, __LINE__, "sb", "Request-URI : ", con->request.uri); - log_error_write(srv, __FILE__, __LINE__, "sb", "URI-scheme : ", con->uri.scheme); - log_error_write(srv, __FILE__, __LINE__, "sb", "URI-authority : ", con->uri.authority); - log_error_write(srv, __FILE__, __LINE__, "sb", "URI-path (raw) : ", con->uri.path_raw); - log_error_write(srv, __FILE__, __LINE__, "sb", "URI-path (clean): ", con->uri.path); - log_error_write(srv, __FILE__, __LINE__, "sb", "URI-query : ", con->uri.query); + log_error(con->conf.errh, __FILE__, __LINE__, + "-- splitting Request-URI"); + log_error(con->conf.errh, __FILE__, __LINE__, + "Request-URI : %s", con->request.uri->ptr); + log_error(con->conf.errh, __FILE__, __LINE__, + "URI-scheme : %s", con->uri.scheme->ptr); + log_error(con->conf.errh, __FILE__, __LINE__, + "URI-authority : %s", con->uri.authority->ptr); + log_error(con->conf.errh, __FILE__, __LINE__, + "URI-path (raw) : %s", con->uri.path_raw->ptr); + log_error(con->conf.errh, __FILE__, __LINE__, + "URI-path (clean): %s", con->uri.path->ptr); + log_error(con->conf.errh, __FILE__, __LINE__, + "URI-query : %.*s", + BUFFER_INTLEN_PTR(con->uri.query)); } /* con->conf.max_request_size is in kBytes */ if (0 != con->conf.max_request_size && (off_t)con->request.content_length > ((off_t)con->conf.max_request_size << 10)) { - log_error_write(srv, __FILE__, __LINE__, "sos", - "request-size too long:", (off_t) con->request.content_length, "-> 413"); + log_error(con->conf.errh, __FILE__, __LINE__, + "request-size too long: %lld -> 413", (long long) con->request.content_length); con->keep_alive = 0; con->http_status = 413; con->file_finished = 1; @@ -475,18 +490,8 @@ handler_t http_response_prepare(server *srv, connection *con) { * */ - switch(r = plugins_call_handle_uri_raw(srv, con)) { - case HANDLER_GO_ON: - break; - case HANDLER_FINISHED: - case HANDLER_COMEBACK: - case HANDLER_WAIT_FOR_EVENT: - case HANDLER_ERROR: - return r; - default: - log_error_write(srv, __FILE__, __LINE__, "sd", "handle_uri_raw: unknown return value", r); - break; - } + r = plugins_call_handle_uri_raw(srv, con); + if (HANDLER_GO_ON != r) return r; /** * @@ -496,18 +501,8 @@ handler_t http_response_prepare(server *srv, connection *con) { * */ - switch(r = plugins_call_handle_uri_clean(srv, con)) { - case HANDLER_GO_ON: - break; - case HANDLER_FINISHED: - case HANDLER_COMEBACK: - case HANDLER_WAIT_FOR_EVENT: - case HANDLER_ERROR: - return r; - default: - log_error_write(srv, __FILE__, __LINE__, ""); - break; - } + r = plugins_call_handle_uri_clean(srv, con); + if (HANDLER_GO_ON != r) return r; if (con->request.http_method == HTTP_METHOD_OPTIONS && con->uri.path->ptr[0] == '*' && con->uri.path->ptr[1] == '\0') { @@ -592,26 +587,20 @@ handler_t http_response_prepare(server *srv, connection *con) { #endif if (con->conf.log_request_handling) { - log_error_write(srv, __FILE__, __LINE__, "s", "-- before doc_root"); - log_error_write(srv, __FILE__, __LINE__, "sb", "Doc-Root :", con->physical.doc_root); - log_error_write(srv, __FILE__, __LINE__, "sb", "Rel-Path :", con->physical.rel_path); - log_error_write(srv, __FILE__, __LINE__, "sb", "Path :", con->physical.path); + log_error(con->conf.errh, __FILE__, __LINE__, + "-- before doc_root"); + log_error(con->conf.errh, __FILE__, __LINE__, + "Doc-Root : %s", con->physical.doc_root->ptr); + log_error(con->conf.errh, __FILE__, __LINE__, + "Rel-Path : %s", con->physical.rel_path->ptr); + log_error(con->conf.errh, __FILE__, __LINE__, + "Path : %s", con->physical.path->ptr); } /* the docroot plugin should set the doc_root and might also set the physical.path * for us (all vhost-plugins are supposed to set the doc_root) * */ - switch(r = plugins_call_handle_docroot(srv, con)) { - case HANDLER_GO_ON: - break; - case HANDLER_FINISHED: - case HANDLER_COMEBACK: - case HANDLER_WAIT_FOR_EVENT: - case HANDLER_ERROR: - return r; - default: - log_error_write(srv, __FILE__, __LINE__, ""); - break; - } + r = plugins_call_handle_docroot(srv, con); + if (HANDLER_GO_ON != r) return r; /* MacOS X and Windows can't distiguish between upper and lower-case * @@ -637,10 +626,14 @@ handler_t http_response_prepare(server *srv, connection *con) { buffer_append_path_len(con->physical.path, CONST_BUF_LEN(con->physical.rel_path)); if (con->conf.log_request_handling) { - log_error_write(srv, __FILE__, __LINE__, "s", "-- after doc_root"); - log_error_write(srv, __FILE__, __LINE__, "sb", "Doc-Root :", con->physical.doc_root); - log_error_write(srv, __FILE__, __LINE__, "sb", "Rel-Path :", con->physical.rel_path); - log_error_write(srv, __FILE__, __LINE__, "sb", "Path :", con->physical.path); + log_error(con->conf.errh, __FILE__, __LINE__, + "-- after doc_root"); + log_error(con->conf.errh, __FILE__, __LINE__, + "Doc-Root : %s", con->physical.doc_root->ptr); + log_error(con->conf.errh, __FILE__, __LINE__, + "Rel-Path : %s", con->physical.rel_path->ptr); + log_error(con->conf.errh, __FILE__, __LINE__, + "Path : %s", con->physical.path->ptr); } if (con->request.http_method == HTTP_METHOD_CONNECT) { @@ -649,26 +642,22 @@ handler_t http_response_prepare(server *srv, connection *con) { /* (This check is located here so that con->physical.path * is filled in above to avoid repeating work next time * http_response_prepare() is called while processing request) */ - } else - switch(r = plugins_call_handle_physical(srv, con)) { - case HANDLER_GO_ON: - break; - case HANDLER_FINISHED: - case HANDLER_COMEBACK: - case HANDLER_WAIT_FOR_EVENT: - case HANDLER_ERROR: - return r; - default: - log_error_write(srv, __FILE__, __LINE__, ""); - break; - } + } else { + r = plugins_call_handle_physical(srv, con); + if (HANDLER_GO_ON != r) return r; - if (con->conf.log_request_handling) { - log_error_write(srv, __FILE__, __LINE__, "s", "-- logical -> physical"); - log_error_write(srv, __FILE__, __LINE__, "sb", "Doc-Root :", con->physical.doc_root); - log_error_write(srv, __FILE__, __LINE__, "sb", "Basedir :", con->physical.basedir); - log_error_write(srv, __FILE__, __LINE__, "sb", "Rel-Path :", con->physical.rel_path); - log_error_write(srv, __FILE__, __LINE__, "sb", "Path :", con->physical.path); + if (con->conf.log_request_handling) { + log_error(con->conf.errh, __FILE__, __LINE__, + "-- logical -> physical"); + log_error(con->conf.errh, __FILE__, __LINE__, + "Doc-Root : %s", con->physical.doc_root->ptr); + log_error(con->conf.errh, __FILE__, __LINE__, + "Basedir : %s", con->physical.basedir->ptr); + log_error(con->conf.errh, __FILE__, __LINE__, + "Rel-Path : %s", con->physical.rel_path->ptr); + log_error(con->conf.errh, __FILE__, __LINE__, + "Path : %s", con->physical.path->ptr); + } } } @@ -680,25 +669,32 @@ handler_t http_response_prepare(server *srv, connection *con) { if (con->mode == DIRECT) { if (con->conf.log_request_handling) { - log_error_write(srv, __FILE__, __LINE__, "s", "-- handling physical path"); - log_error_write(srv, __FILE__, __LINE__, "sb", "Path :", con->physical.path); + log_error(con->conf.errh, __FILE__, __LINE__, + "-- handling physical path"); + log_error(con->conf.errh, __FILE__, __LINE__, + "Path : %s", con->physical.path->ptr); } r = http_response_physical_path_check(srv, con); if (HANDLER_GO_ON != r) return r; if (con->conf.log_request_handling) { - log_error_write(srv, __FILE__, __LINE__, "s", "-- handling subrequest"); - log_error_write(srv, __FILE__, __LINE__, "sb", "Path :", con->physical.path); - log_error_write(srv, __FILE__, __LINE__, "sb", "URI :", con->uri.path); - log_error_write(srv, __FILE__, __LINE__, "sb", "Pathinfo :", con->request.pathinfo); + log_error(con->conf.errh, __FILE__, __LINE__, + "-- handling subrequest"); + log_error(con->conf.errh, __FILE__, __LINE__, + "Path : %s", con->physical.path->ptr); + log_error(con->conf.errh, __FILE__, __LINE__, + "URI : %s", con->uri.path->ptr); + log_error(con->conf.errh, __FILE__, __LINE__, + "Pathinfo : %s", con->request.pathinfo->ptr); } /* call the handlers */ r = plugins_call_handle_subrequest_start(srv, con); if (HANDLER_GO_ON != r) { if (con->conf.log_request_handling) { - log_error_write(srv, __FILE__, __LINE__, "s", "-- subrequest finished"); + log_error(con->conf.errh, __FILE__, __LINE__, + "-- subrequest finished"); } return r; } diff --git a/src/response.h b/src/response.h index 6f4938a8..c6b367ae 100644 --- a/src/response.h +++ b/src/response.h @@ -9,7 +9,7 @@ #include int http_response_parse(server *srv, connection *con); -int http_response_write_header(server *srv, connection *con); +int http_response_write_header(connection *con); typedef struct http_cgi_opts_t { int authorizer; @@ -34,24 +34,23 @@ typedef struct http_response_opts_t { unsigned short xsendfile_allow; const array *xsendfile_docroot; void *pdata; - handler_t(*parse)(server *, connection *, struct http_response_opts_t *, buffer *, size_t); - handler_t(*headers)(server *, connection *, struct http_response_opts_t *); + handler_t(*parse)(connection *, struct http_response_opts_t *, buffer *, size_t); + handler_t(*headers)(connection *, struct http_response_opts_t *); } http_response_opts; typedef int (*http_cgi_header_append_cb)(void *vdata, const char *k, size_t klen, const char *v, size_t vlen); -int http_cgi_headers(server *srv, connection *con, http_cgi_opts *opts, http_cgi_header_append_cb cb, void *vdata); +int http_cgi_headers(connection *con, http_cgi_opts *opts, http_cgi_header_append_cb cb, void *vdata); -handler_t http_response_parse_headers(server *srv, connection *con, http_response_opts *opts, buffer *hdrs); -handler_t http_response_read(server *srv, connection *con, http_response_opts *opts, buffer *b, fdnode *fdn); +handler_t http_response_parse_headers(connection *con, http_response_opts *opts, buffer *hdrs); +handler_t http_response_read(connection *con, http_response_opts *opts, buffer *b, fdnode *fdn); handler_t http_response_prepare(server *srv, connection *con); -int http_response_buffer_append_authority(server *srv, connection *con, buffer *b); -int http_response_redirect_to_directory(server *srv, connection *con, int status); -int http_response_handle_cachable(server *srv, connection *con, const buffer * mtime); +int http_response_redirect_to_directory(connection *con, int status); +int http_response_handle_cachable(connection *con, const buffer * mtime); void http_response_body_clear(connection *con, int preserve_length); -void http_response_send_file (server *srv, connection *con, buffer *path); -void http_response_backend_done (server *srv, connection *con); -void http_response_backend_error (server *srv, connection *con); -void http_response_upgrade_read_body_unknown(server *srv, connection *con); +void http_response_send_file (connection *con, buffer *path); +void http_response_backend_done (connection *con); +void http_response_backend_error (connection *con); +void http_response_upgrade_read_body_unknown(connection *con); const buffer * strftime_cache_get(server *srv, time_t last_mod); #endif diff --git a/src/server.c b/src/server.c index bf2a9e5c..8868530c 100644 --- a/src/server.c +++ b/src/server.c @@ -308,11 +308,8 @@ static void remove_pid_file(server *srv) { if (pid_fd <= -2) return; if (!buffer_string_is_empty(srv->srvconf.pid_file) && 0 <= pid_fd) { if (0 != ftruncate(pid_fd, 0)) { - log_error_write(srv, __FILE__, __LINE__, "sbds", - "ftruncate failed for:", - srv->srvconf.pid_file, - errno, - strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, + "ftruncate failed for: %s", srv->srvconf.pid_file->ptr); } } if (0 <= pid_fd) { @@ -323,11 +320,8 @@ static void remove_pid_file(server *srv) { buffer_string_is_empty(srv->srvconf.changeroot)) { if (0 != unlink(srv->srvconf.pid_file->ptr)) { if (errno != EACCES && errno != EPERM) { - log_error_write(srv, __FILE__, __LINE__, "sbds", - "unlink failed for:", - srv->srvconf.pid_file, - errno, - strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, + "unlink failed for: %s", srv->srvconf.pid_file->ptr); } } } @@ -353,7 +347,7 @@ static server_socket * server_oneshot_getsock(server *srv, sock_addr *cnt_addr) } else if (srv->srv_sockets.used) { return srv->srv_sockets.ptr[0]; } else { - log_error_write(srv, __FILE__, __LINE__, "s", "no sockets configured"); + log_error(srv->errh, __FILE__, __LINE__, "no sockets configured"); return NULL; } } @@ -380,20 +374,21 @@ static int server_oneshot_init(server *srv, int fd) { struct stat st; if (0 != fstat(fd, &st)) { - log_error_write(srv, __FILE__, __LINE__, "ss", "fstat:", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, "fstat()"); return 0; } if (!S_ISSOCK(st.st_mode)) { /* require that fd is a socket * (modules might expect STDIN_FILENO and STDOUT_FILENO opened to /dev/null) */ - log_error_write(srv, __FILE__, __LINE__, "s", "lighttpd -1 stdin is not a socket"); + log_error(srv->errh, __FILE__, __LINE__, + "lighttpd -1 stdin is not a socket"); return 0; } cnt_len = sizeof(cnt_addr); if (0 != getsockname(fd, (struct sockaddr *)&cnt_addr, &cnt_len)) { - log_error_write(srv, __FILE__, __LINE__, "ss", "getsockname:", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, "getsockname()"); return 0; } @@ -402,13 +397,13 @@ static int server_oneshot_init(server *srv, int fd) { cnt_len = sizeof(cnt_addr); if (0 != getpeername(fd, (struct sockaddr *)&cnt_addr, &cnt_len)) { - log_error_write(srv, __FILE__, __LINE__, "ss", "getpeername:", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, "getpeername()"); return 0; } /*(must set flags; fd did not pass through fdevent accept() logic)*/ if (-1 == fdevent_fcntl_set_nb_cloexec(srv->ev, fd)) { - log_error_write(srv, __FILE__, __LINE__, "ss", "fcntl:", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, "fcntl()"); return 0; } @@ -630,10 +625,10 @@ static int log_error_open(server *srv) { } } if (-1 == facility) { - log_error_write(srv, __FILE__, __LINE__, "SBS", - "unrecognized server.syslog-facility: \"", - srv->srvconf.syslog_facility, - "\"; defaulting to \"daemon\" facility"); + log_error(srv->errh, __FILE__, __LINE__, + "unrecognized server.syslog-facility: \"%s\"; " + "defaulting to \"daemon\" facility", + srv->srvconf.syslog_facility->ptr); } } openlog("lighttpd", LOG_CONS|LOG_PID, -1==facility ? LOG_DAEMON : facility); @@ -649,9 +644,8 @@ static int log_error_open(server *srv) { const char *logfile = srv->srvconf.errorlog_file->ptr; int fd = fdevent_open_logger(logfile); if (-1 == fd) { - log_error_write(srv, __FILE__, __LINE__, "SSSS", - "opening errorlog '", logfile, - "' failed: ", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, + "opening errorlog '%s' failed", logfile); return -1; } errh->errorlog_fd = fd; @@ -675,9 +669,8 @@ static int log_error_open(server *srv) { } if (-1 == (errfd = fdevent_open_logger(logfile))) { - log_error_write(srv, __FILE__, __LINE__, "SSSS", - "opening errorlog '", logfile, - "' failed: ", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, + "opening errorlog '%s' failed", logfile); return -1; } @@ -686,8 +679,7 @@ static int log_error_open(server *srv) { else if (!srv->srvconf.dont_daemonize) { /* move STDERR_FILENO to /dev/null */ if (-1 == (errfd = fdevent_open_devnull())) { - log_error_write(srv, __FILE__, __LINE__, "ss", - "opening /dev/null failed:", strerror(errno)); + log_perror(srv->errh,__FILE__,__LINE__,"opening /dev/null failed"); return -1; } } @@ -697,8 +689,7 @@ static int log_error_open(server *srv) { } if (0 != fdevent_set_stdin_stdout_stderr(-1, -1, errfd)) { - log_error_write(srv, __FILE__, __LINE__, "ss", - "setting stderr failed:", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, "setting stderr failed"); #ifdef FD_CLOEXEC if (-1 != errfd) close(errfd); #endif @@ -724,9 +715,8 @@ static int log_error_cycle(server *srv) { const char *logfile = srv->srvconf.errorlog_file->ptr; if (-1 == fdevent_cycle_logger(logfile, &errh->errorlog_fd)) { /* write to old log */ - log_error_write(srv, __FILE__, __LINE__, "SSSS", - "cycling errorlog '", logfile, - "' failed: ", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, + "cycling errorlog '%s' failed", logfile); } } @@ -782,8 +772,7 @@ static int server_sockets_set_nb_cloexec (server *srv) { for (uint32_t i = 0; i < srv->srv_sockets.used; ++i) { server_socket *srv_socket = srv->srv_sockets.ptr[i]; if (-1 == fdevent_fcntl_set_nb_cloexec_sock(srv->ev, srv_socket->fd)) { - log_error_write(srv, __FILE__, __LINE__, "ss", - "fcntl failed:", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, "fcntl()"); return -1; } } @@ -833,8 +822,7 @@ static void server_graceful_state (server *srv) { if (!oneshot_fd && (2 == srv->sockets_disabled || 3 == srv->sockets_disabled)) return; - log_error_write(srv, __FILE__, __LINE__, "s", - "[note] graceful shutdown started"); + log_error(srv->errh,__FILE__,__LINE__,"[note] graceful shutdown started"); /* no graceful restart if chroot()ed, if oneshot mode, or if idle timeout */ if (!buffer_string_is_empty(srv->srvconf.changeroot) @@ -857,18 +845,17 @@ __attribute_cold__ static void server_sockets_enable (server *srv) { server_sockets_set_event(srv, FDEVENT_IN); srv->sockets_disabled = 0; - log_error_write(srv, __FILE__, __LINE__, "s", - "[note] sockets enabled again"); + log_error(srv->errh, __FILE__, __LINE__, "[note] sockets enabled again"); } __attribute_cold__ static void server_sockets_disable (server *srv) { server_sockets_set_event(srv, 0); srv->sockets_disabled = 1; - log_error_write(srv, __FILE__, __LINE__, "s", - (srv->conns.used >= srv->max_conns) - ? "[note] sockets disabled, connection limit reached" - : "[note] sockets disabled, out-of-fds"); + log_error(srv->errh, __FILE__, __LINE__, + (srv->conns.used >= srv->max_conns) + ? "[note] sockets disabled, connection limit reached" + : "[note] sockets disabled, out-of-fds"); } __attribute_cold__ @@ -945,8 +932,8 @@ static int server_main (server * const srv, int argc, char **argv) { switch(o) { case 'f': if (srv->config_data_base) { - log_error_write(srv, __FILE__, __LINE__, "s", - "Can only read one config file. Use the include command to use multiple config files."); + log_error(srv->errh, __FILE__, __LINE__, + "Can only read one config file. Use the include command to use multiple config files."); return -1; } if (config_read(srv, optarg)) { @@ -960,8 +947,8 @@ static int server_main (server * const srv, int argc, char **argv) { char *endptr; long timeout = strtol(optarg, &endptr, 0); if (!*optarg || *endptr || timeout < 0) { - log_error_write(srv, __FILE__, __LINE__, "ss", - "Invalid idle timeout value:", optarg); + log_error(srv->errh, __FILE__, __LINE__, + "Invalid idle timeout value: %s", optarg); return -1; } idle_limit = (time_t)timeout; @@ -985,7 +972,7 @@ static int server_main (server * const srv, int argc, char **argv) { if (!srv->config_data_base && NULL != getenv("NSSM_SERVICE_NAME")) { char *dir = getenv("NSSM_SERVICE_DIR"); if (NULL != dir && 0 != chdir(dir)) { - log_error_write(srv, __FILE__, __LINE__, "sss", "chdir failed:", dir, strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, "chdir %s failed", dir); return -1; } srv->srvconf.dont_daemonize = 1; @@ -995,8 +982,8 @@ static int server_main (server * const srv, int argc, char **argv) { #endif if (!srv->config_data_base) { - log_error_write(srv, __FILE__, __LINE__, "s", - "No configuration available. Try using -f option."); + log_error(srv->errh, __FILE__, __LINE__, + "No configuration available. Try using -f option."); return -1; } @@ -1022,8 +1009,8 @@ static int server_main (server * const srv, int argc, char **argv) { if (oneshot_fd) { if (oneshot_fd <= STDERR_FILENO) { - log_error_write(srv, __FILE__, __LINE__, "s", - "Invalid fds at startup with lighttpd -1"); + log_error(srv->errh, __FILE__, __LINE__, + "Invalid fds at startup with lighttpd -1"); return -1; } graceful_shutdown = 1; @@ -1032,16 +1019,16 @@ static int server_main (server * const srv, int argc, char **argv) { if (srv->srvconf.pid_file) buffer_clear(srv->srvconf.pid_file); if (srv->srvconf.max_worker) { srv->srvconf.max_worker = 0; - log_error_write(srv, __FILE__, __LINE__, "s", - "server one-shot command line option disables server.max-worker config file option."); + log_error(srv->errh, __FILE__, __LINE__, + "server one-shot command line option disables server.max-worker config file option."); } } if (srv->srvconf.bindhost && buffer_is_equal_string(srv->srvconf.bindhost, CONST_STR_LEN("/dev/stdin"))) { stdin_fd = dup(STDIN_FILENO); if (stdin_fd <= STDERR_FILENO) { - log_error_write(srv, __FILE__, __LINE__, "s", - "Invalid fds at startup"); + log_error(srv->errh, __FILE__, __LINE__, + "Invalid fds at startup"); return -1; } } @@ -1059,14 +1046,14 @@ static int server_main (server * const srv, int argc, char **argv) { #endif } while (-1 != devnull && devnull <= STDERR_FILENO); if (-1 == devnull) { - log_error_write(srv, __FILE__, __LINE__, "ss", - "opening /dev/null failed:", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, + "opening /dev/null failed"); return -1; } errfd = (0 == fstat(STDERR_FILENO, &st)) ? -1 : devnull; if (0 != fdevent_set_stdin_stdout_stderr(devnull, devnull, errfd)) { - log_error_write(srv, __FILE__, __LINE__, "ss", - "setting default fds failed:", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, + "setting default fds failed"); #ifdef FD_CLOEXEC if (-1 != errfd) close(errfd); if (devnull != errfd) close(devnull); @@ -1080,19 +1067,20 @@ static int server_main (server * const srv, int argc, char **argv) { } if (0 != config_set_defaults(srv)) { - log_error_write(srv, __FILE__, __LINE__, "s", - "setting default values failed"); + log_error(srv->errh, __FILE__, __LINE__, + "setting default values failed"); return -1; } if (plugins_load(srv)) { - log_error_write(srv, __FILE__, __LINE__, "s", - "loading plugins finally failed"); + log_error(srv->errh, __FILE__, __LINE__, + "loading plugins finally failed"); return -1; } if (HANDLER_GO_ON != plugins_call_init(srv)) { - log_error_write(srv, __FILE__, __LINE__, "s", "Initialization of plugins failed. Going down."); + log_error(srv->errh, __FILE__, __LINE__, + "Initialization of plugins failed. Going down."); return -1; } @@ -1101,8 +1089,8 @@ static int server_main (server * const srv, int argc, char **argv) { for (const char *pname = NULL; i < srv->plugins.used; ++i) { plugin *p = ((plugin **)srv->plugins.ptr)[i]; if (NULL != pname && 0 == strcmp(p->name, "indexfile")) { - log_error_write(srv, __FILE__, __LINE__, "SS", - "Warning: mod_indexfile should be listed in server.modules prior to mod_", pname); + log_error(srv->errh, __FILE__, __LINE__, + "Warning: mod_indexfile should be listed in server.modules prior to mod_%s", pname); break; } if (p->handle_subrequest_start && p->handle_subrequest) { @@ -1113,28 +1101,29 @@ static int server_main (server * const srv, int argc, char **argv) { /* open pid file BEFORE chroot */ if (-2 == pid_fd) pid_fd = -1; /*(initial startup state)*/ if (-1 == pid_fd && !buffer_string_is_empty(srv->srvconf.pid_file)) { - if (-1 == (pid_fd = fdevent_open_cloexec(srv->srvconf.pid_file->ptr, 0, O_WRONLY | O_CREAT | O_EXCL | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH))) { + const char *pidfile = srv->srvconf.pid_file->ptr; + if (-1 == (pid_fd = fdevent_open_cloexec(pidfile, 0, O_WRONLY | O_CREAT | O_EXCL | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH))) { struct stat st; if (errno != EEXIST) { - log_error_write(srv, __FILE__, __LINE__, "sbs", - "opening pid-file failed:", srv->srvconf.pid_file, strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, + "opening pid-file failed: %s", pidfile); return -1; } - if (0 != stat(srv->srvconf.pid_file->ptr, &st)) { - log_error_write(srv, __FILE__, __LINE__, "sbs", - "stating existing pid-file failed:", srv->srvconf.pid_file, strerror(errno)); + if (0 != stat(pidfile, &st)) { + log_perror(srv->errh, __FILE__, __LINE__, + "stating existing pid-file failed: %s", pidfile); } if (!S_ISREG(st.st_mode)) { - log_error_write(srv, __FILE__, __LINE__, "sb", - "pid-file exists and isn't regular file:", srv->srvconf.pid_file); + log_error(srv->errh, __FILE__, __LINE__, + "pid-file exists and isn't regular file: %s", pidfile); return -1; } - if (-1 == (pid_fd = fdevent_open_cloexec(srv->srvconf.pid_file->ptr, 0, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH))) { - log_error_write(srv, __FILE__, __LINE__, "sbs", - "opening pid-file failed:", srv->srvconf.pid_file, strerror(errno)); + if (-1 == (pid_fd = fdevent_open_cloexec(pidfile, 0, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH))) { + log_perror(srv->errh, __FILE__, __LINE__, + "opening pid-file failed: %s", pidfile); return -1; } } @@ -1149,9 +1138,7 @@ static int server_main (server * const srv, int argc, char **argv) { #endif if (0 != getrlimit(RLIMIT_NOFILE, &rlim)) { - log_error_write(srv, __FILE__, __LINE__, - "ss", "couldn't get 'max filedescriptors'", - strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, "getrlimit()"); return -1; } @@ -1166,9 +1153,7 @@ static int server_main (server * const srv, int argc, char **argv) { if (i_am_root) rlim.rlim_max = srv->srvconf.max_fds; if (0 != setrlimit(RLIMIT_NOFILE, &rlim)) { - log_error_write(srv, __FILE__, __LINE__, - "ss", "couldn't set 'max filedescriptors'", - strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, "setrlimit()"); return -1; } } @@ -1199,36 +1184,36 @@ static int server_main (server * const srv, int argc, char **argv) { if (!buffer_string_is_empty(srv->srvconf.groupname)) { if (NULL == (grp = getgrnam(srv->srvconf.groupname->ptr))) { - log_error_write(srv, __FILE__, __LINE__, "sb", - "can't find groupname", srv->srvconf.groupname); + log_error(srv->errh, __FILE__, __LINE__, + "can't find groupname %s", srv->srvconf.groupname->ptr); return -1; } } if (!buffer_string_is_empty(srv->srvconf.username)) { if (NULL == (pwd = getpwnam(srv->srvconf.username->ptr))) { - log_error_write(srv, __FILE__, __LINE__, "sb", - "can't find username", srv->srvconf.username); + log_error(srv->errh, __FILE__, __LINE__, + "can't find username %s", srv->srvconf.username->ptr); return -1; } if (pwd->pw_uid == 0) { - log_error_write(srv, __FILE__, __LINE__, "s", - "I will not set uid to 0\n"); + log_error(srv->errh, __FILE__, __LINE__, + "I will not set uid to 0\n"); return -1; } if (NULL == grp && NULL == (grp = getgrgid(pwd->pw_gid))) { - log_error_write(srv, __FILE__, __LINE__, "sd", - "can't find group id", pwd->pw_gid); + log_error(srv->errh, __FILE__, __LINE__, + "can't find group id %d", (int)pwd->pw_gid); return -1; } } if (NULL != grp) { if (grp->gr_gid == 0) { - log_error_write(srv, __FILE__, __LINE__, "s", - "I will not set gid to 0\n"); + log_error(srv->errh, __FILE__, __LINE__, + "I will not set gid to 0\n"); return -1; } } @@ -1239,11 +1224,11 @@ static int server_main (server * const srv, int argc, char **argv) { * */ if (NULL != grp) { if (-1 == setgid(grp->gr_gid)) { - log_error_write(srv, __FILE__, __LINE__, "ss", "setgid failed: ", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, "setgid()"); return -1; } if (-1 == setgroups(0, NULL)) { - log_error_write(srv, __FILE__, __LINE__, "ss", "setgroups failed: ", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, "setgroups()"); return -1; } if (!buffer_string_is_empty(srv->srvconf.username)) { @@ -1256,11 +1241,11 @@ static int server_main (server * const srv, int argc, char **argv) { tzset(); if (-1 == chroot(srv->srvconf.changeroot->ptr)) { - log_error_write(srv, __FILE__, __LINE__, "ss", "chroot failed: ", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, "chroot()"); return -1; } if (-1 == chdir("/")) { - log_error_write(srv, __FILE__, __LINE__, "ss", "chdir failed: ", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, "chdir()"); return -1; } } @@ -1269,7 +1254,7 @@ static int server_main (server * const srv, int argc, char **argv) { /* drop root privs */ if (NULL != pwd) { if (-1 == setuid(pwd->pw_uid)) { - log_error_write(srv, __FILE__, __LINE__, "ss", "setuid failed: ", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, "setuid()"); return -1; } } @@ -1287,7 +1272,9 @@ static int server_main (server * const srv, int argc, char **argv) { /* set max-conns */ if (srv->srvconf.max_conns > srv->max_fds/2) { /* we can't have more connections than max-fds/2 */ - log_error_write(srv, __FILE__, __LINE__, "sdd", "can't have more connections than fds/2: ", srv->srvconf.max_conns, srv->max_fds); + log_error(srv->errh, __FILE__, __LINE__, + "can't have more connections than fds/2: %hu %d", + srv->srvconf.max_conns, srv->max_fds); srv->max_conns = srv->max_fds/2; } else if (srv->srvconf.max_conns) { /* otherwise respect the wishes of the user */ @@ -1355,7 +1342,7 @@ static int server_main (server * const srv, int argc, char **argv) { buffer_copy_int(srv->tmp_buf, srv->pid); buffer_append_string_len(srv->tmp_buf, CONST_STR_LEN("\n")); if (-1 == write_all(pid_fd, CONST_BUF_LEN(srv->tmp_buf))) { - log_error_write(srv, __FILE__, __LINE__, "ss", "Couldn't write pid file:", strerror(errno)); + log_perror(srv->errh, __FILE__, __LINE__, "Couldn't write pid file"); close(pid_fd); pid_fd = -1; return -1; @@ -1368,14 +1355,14 @@ static int server_main (server * const srv, int argc, char **argv) { * is being written to that fd which may not be valid anymore. */ if (!srv->srvconf.preflight_check) { if (-1 == log_error_open(srv)) { - log_error_write(srv, __FILE__, __LINE__, "s", "Opening errorlog failed. Going down."); + log_error(srv->errh, __FILE__, __LINE__, "Opening errorlog failed. Going down."); return -1; } - log_error_write(srv, __FILE__, __LINE__, "s", "server started (" PACKAGE_DESC ")"); + log_error(srv->errh, __FILE__, __LINE__, "server started (" PACKAGE_DESC ")"); } if (HANDLER_GO_ON != plugins_call_set_defaults(srv)) { - log_error_write(srv, __FILE__, __LINE__, "s", "Configuration of plugins failed. Going down."); + log_error(srv->errh, __FILE__, __LINE__, "Configuration of plugins failed. Going down."); return -1; } @@ -1401,8 +1388,8 @@ static int server_main (server * const srv, int argc, char **argv) { if (idle_limit && srv->srvconf.max_worker) { srv->srvconf.max_worker = 0; - log_error_write(srv, __FILE__, __LINE__, "s", - "server idle time limit command line option disables server.max-worker config file option."); + log_error(srv->errh, __FILE__, __LINE__, + "server idle time limit command line option disables server.max-worker config file option."); } /* start watcher and workers */ @@ -1537,8 +1524,7 @@ static int server_main (server * const srv, int argc, char **argv) { #endif if (NULL == (srv->ev = fdevent_init(srv))) { - log_error_write(srv, __FILE__, __LINE__, - "s", "fdevent_init failed"); + log_error(srv->errh, __FILE__, __LINE__, "fdevent_init failed"); return -1; } @@ -1563,8 +1549,8 @@ static int server_main (server * const srv, int argc, char **argv) { /* might fail if user is using fam (not gamin) and famd isn't running */ if (NULL == (srv->stat_cache = stat_cache_init(srv))) { - log_error_write(srv, __FILE__, __LINE__, "s", - "stat-cache could not be setup, dieing."); + log_error(srv->errh, __FILE__, __LINE__, + "stat-cache could not be setup, dieing."); return -1; } @@ -1577,13 +1563,12 @@ static int server_main (server * const srv, int argc, char **argv) { interval.it_value.tv_sec = 1; interval.it_value.tv_usec = 0; if (setitimer(ITIMER_REAL, &interval, NULL)) { - log_error_write(srv, __FILE__, __LINE__, "s", "setting timer failed"); + log_perror(srv->errh, __FILE__, __LINE__, "setitimer()"); return -1; } } #endif - /* get the current number of FDs */ { int fd = fdevent_open_devnull(); @@ -1617,19 +1602,19 @@ static int server_handle_sighup (server * const srv) { plugins_call_handle_sighup(srv); if (-1 == log_error_cycle(srv)) { - log_error_write(srv, __FILE__, __LINE__, "s", "cycling errorlog failed, dying"); + log_error(srv->errh, __FILE__, __LINE__, + "cycling errorlog failed, dying"); return -1; } else { #ifdef HAVE_SIGACTION - log_error_write(srv, __FILE__, __LINE__, "sdsd", - "logfiles cycled UID =", - last_sighup_info.si_uid, - "PID =", - last_sighup_info.si_pid); + log_error(srv->errh, __FILE__, __LINE__, + "logfiles cycled UID = %d PID = %d", + (int)last_sighup_info.si_uid, + (int)last_sighup_info.si_pid); #else - log_error_write(srv, __FILE__, __LINE__, "s", - "logfiles cycled"); + log_error(srv->errh, __FILE__, __LINE__, + "logfiles cycled"); #endif } @@ -1645,8 +1630,9 @@ static void server_handle_sigalrm (server * const srv, time_t min_ts, time_t las /* check idle time limit, if enabled */ if (idle_limit && idle_limit < min_ts - last_active_ts && !graceful_shutdown) { - log_error_write(srv, __FILE__, __LINE__, "sDs", "[note] idle timeout", (int)idle_limit, - "s exceeded, initiating graceful shutdown"); + log_error(srv->errh, __FILE__, __LINE__, + "[note] idle timeout %ds exceeded, " + "initiating graceful shutdown", (int)idle_limit); graceful_shutdown = 2; /* value 2 indicates idle timeout */ if (graceful_restart) { graceful_restart = 0; @@ -1791,18 +1777,17 @@ int main (int argc, char **argv) { } if (2 == graceful_shutdown) { /* value 2 indicates idle timeout */ - log_error_write(srv, __FILE__, __LINE__, "s", - "server stopped after idle timeout"); + log_error(srv->errh, __FILE__, __LINE__, + "server stopped after idle timeout"); } else { #ifdef HAVE_SIGACTION - log_error_write(srv, __FILE__, __LINE__, "sdsd", - "server stopped by UID =", - last_sigterm_info.si_uid, - "PID =", - last_sigterm_info.si_pid); + log_error(srv->errh, __FILE__, __LINE__, + "server stopped by UID = %d PID = %d", + (int)last_sigterm_info.si_uid, + (int)last_sigterm_info.si_pid); #else - log_error_write(srv, __FILE__, __LINE__, "s", - "server stopped"); + log_error(srv->errh, __FILE__, __LINE__, + "server stopped"); #endif } } diff --git a/src/sock_addr.c b/src/sock_addr.c index b0938364..dc8f8075 100644 --- a/src/sock_addr.c +++ b/src/sock_addr.c @@ -331,7 +331,7 @@ int sock_addr_stringify_append_buffer(buffer *b, const sock_addr *saddr) } -int sock_addr_nameinfo_append_buffer(server *srv, buffer *b, const sock_addr *saddr) +int sock_addr_nameinfo_append_buffer(buffer *b, const sock_addr *saddr, log_error_st *errh) { /*(this routine originates from * http-header-glue.c:http_response_redirect_to_directory())*/ @@ -342,9 +342,9 @@ int sock_addr_nameinfo_append_buffer(server *srv, buffer *b, const sock_addr *sa struct hostent *he = gethostbyaddr((char *)&saddr->ipv4.sin_addr, sizeof(struct in_addr), AF_INET); if (NULL == he) { - log_error_write(srv, __FILE__, __LINE__, - "SdS", "NOTICE: gethostbyaddr failed: ", - h_errno, ", using ip-address instead"); + log_error(errh, __FILE__, __LINE__, + "NOTICE: gethostbyaddr failed: %d, using ip-address instead", + h_errno); sock_addr_inet_ntop_append_buffer(b, saddr); } else { @@ -359,9 +359,8 @@ int sock_addr_nameinfo_append_buffer(server *srv, buffer *b, const sock_addr *sa if (0 != getnameinfo((const struct sockaddr *)(&saddr->ipv6), sizeof(saddr->ipv6), hbuf, sizeof(hbuf), NULL, 0, 0)) { - log_error_write(srv, __FILE__, __LINE__, - "SSS", "NOTICE: getnameinfo failed: ", - strerror(errno), ", using ip-address instead"); + log_perror(errh, __FILE__, __LINE__, + "NOTICE: getnameinfo failed; using ip-address instead"); buffer_append_string_len(b, CONST_STR_LEN("[")); sock_addr_inet_ntop_append_buffer(b, saddr); @@ -373,14 +372,13 @@ int sock_addr_nameinfo_append_buffer(server *srv, buffer *b, const sock_addr *sa } #endif default: - log_error_write(srv, __FILE__, __LINE__, - "S", "ERROR: unsupported address-type"); + log_error(errh, __FILE__, __LINE__, "ERROR: unsupported address-type"); return -1; } } -int sock_addr_from_str_hints(server *srv, sock_addr *saddr, socklen_t *len, const char *str, int family, unsigned short port) +int sock_addr_from_str_hints(sock_addr *saddr, socklen_t *len, const char *str, int family, unsigned short port, log_error_st *errh) { /*(note: name resolution here is *blocking*)*/ switch(family) { @@ -404,9 +402,8 @@ int sock_addr_from_str_hints(server *srv, sock_addr *saddr, socklen_t *len, cons hints.ai_protocol = IPPROTO_TCP; if (0 != (r = getaddrinfo(str, NULL, &hints, &res))) { - log_error_write(srv, __FILE__, __LINE__, - "sssss", "getaddrinfo failed: ", - gai_strerror(r), "'", str, "'"); + log_error(errh, __FILE__, __LINE__, + "getaddrinfo failed: %s '%s'", gai_strerror(r), str); return 0; } @@ -461,9 +458,8 @@ int sock_addr_from_str_hints(server *srv, sock_addr *saddr, socklen_t *len, cons return 1; } - log_error_write(srv, __FILE__, __LINE__, - "sssss", "getaddrinfo failed: ", - gai_strerror(r), "'", str, "'"); + log_error(errh, __FILE__, __LINE__, + "getaddrinfo failed: %s '%s'", gai_strerror(r), str); return 0; } @@ -495,9 +491,8 @@ int sock_addr_from_str_hints(server *srv, sock_addr *saddr, socklen_t *len, cons hints.ai_protocol = IPPROTO_TCP; if (0 != (r = getaddrinfo(str, NULL, &hints, &res))) { - log_error_write(srv, __FILE__, __LINE__, - "sssss", "getaddrinfo failed: ", - gai_strerror(r), "'", str, "'"); + log_error(errh, __FILE__, __LINE__, + "getaddrinfo failed: %s '%s'", gai_strerror(r), str); return 0; } @@ -506,20 +501,20 @@ int sock_addr_from_str_hints(server *srv, sock_addr *saddr, socklen_t *len, cons #else struct hostent *he = gethostbyname(str); if (NULL == he) { - log_error_write(srv, __FILE__, __LINE__, "sds", - "gethostbyname failed:", h_errno, str); + log_error(errh, __FILE__, __LINE__, + "gethostbyname failed: %d %s", h_errno, str); return 0; } if (he->h_addrtype != AF_INET) { - log_error_write(srv, __FILE__, __LINE__, "sd", - "addr-type != AF_INET:", he->h_addrtype); + log_error(errh, __FILE__, __LINE__, + "addr-type != AF_INET: %d", he->h_addrtype); return 0; } if (he->h_length != sizeof(struct in_addr)) { - log_error_write(srv, __FILE__, __LINE__, "sd", - "addr-length != sizeof(in_addr):",he->h_length); + log_error(errh, __FILE__, __LINE__, + "addr-length != sizeof(in_addr): %d", he->h_length); return 0; } @@ -537,8 +532,8 @@ int sock_addr_from_str_hints(server *srv, sock_addr *saddr, socklen_t *len, cons { size_t hostlen = strlen(str) + 1; if (hostlen > sizeof(saddr->un.sun_path)) { - log_error_write(srv, __FILE__, __LINE__, "sS", - "unix socket filename too long:", str); + log_error(errh, __FILE__, __LINE__, + "unix socket filename too long: %s", str); /*errno = ENAMETOOLONG;*/ return 0; } @@ -552,20 +547,20 @@ int sock_addr_from_str_hints(server *srv, sock_addr *saddr, socklen_t *len, cons return 1; #else case AF_UNIX: - log_error_write(srv, __FILE__, __LINE__, "s", - "unix domain sockets are not supported."); + log_error(errh, __FILE__, __LINE__, + "unix domain sockets are not supported."); return 0; #endif default: - log_error_write(srv, __FILE__, __LINE__, "sd", - "address family unsupported:", family); + log_error(errh, __FILE__, __LINE__, + "address family unsupported: %d", family); /*errno = EAFNOSUPPORT;*/ return 0; } } -int sock_addr_from_str_numeric(server *srv, sock_addr *saddr, const char *str) +int sock_addr_from_str_numeric(sock_addr *saddr, const char *str, log_error_st *errh) { /*(note: does not handle port if getaddrinfo() is not available)*/ /*(note: getaddrinfo() is stricter than inet_aton() in what is accepted)*/ @@ -591,14 +586,14 @@ int sock_addr_from_str_numeric(server *srv, sock_addr *saddr, const char *str) result = getaddrinfo(str, NULL, &hints, &addrlist); if (result != 0) { - log_error_write(srv, __FILE__, __LINE__, "SSSs(S)", - "could not parse ip address ", str, " because ", - gai_strerror(result), strerror(errno)); + log_perror(errh, __FILE__, __LINE__, + "could not parse ip address %s because %s", + str, gai_strerror(result)); return result; } else if (addrlist == NULL) { - log_error_write(srv, __FILE__, __LINE__, "SSS", - "Problem in parsing ip address ", str, - ": succeeded, but no information returned"); + log_error(errh, __FILE__, __LINE__, + "Problem in parsing ip address %s:" + "succeeded, but no information returned", str); return -1; } else switch (addrlist->ai_family) { case AF_INET: @@ -610,9 +605,9 @@ int sock_addr_from_str_numeric(server *srv, sock_addr *saddr, const char *str) force_assert(AF_INET6 == saddr->plain.sa_family); break; default: - log_error_write(srv, __FILE__, __LINE__, "SSS", - "Problem in parsing ip address ", str, - ": succeeded, but unknown family"); + log_error(errh, __FILE__, __LINE__, + "Problem in parsing ip address %s:" + "succeeded, but unknown family", str); result = -1; break; } @@ -620,7 +615,7 @@ int sock_addr_from_str_numeric(server *srv, sock_addr *saddr, const char *str) freeaddrinfo(addrlist); return (0 == result); #else - UNUSED(srv); + UNUSED(errh); saddr->ipv4.sin_addr.s_addr = inet_addr(str); saddr->plain.sa_family = AF_INET; return (saddr->ipv4.sin_addr.s_addr != 0xFFFFFFFF); @@ -628,7 +623,7 @@ int sock_addr_from_str_numeric(server *srv, sock_addr *saddr, const char *str) } -int sock_addr_from_buffer_hints_numeric(server *srv, sock_addr *saddr, socklen_t *len, const buffer *b, int family, unsigned short port) +int sock_addr_from_buffer_hints_numeric(sock_addr *saddr, socklen_t *len, const buffer *b, int family, unsigned short port, log_error_st *errh) { /*(this routine originates from mod_fastcgi.c and mod_scgi.c)*/ if (buffer_string_is_empty(b)) { @@ -649,8 +644,8 @@ int sock_addr_from_buffer_hints_numeric(server *srv, sock_addr *saddr, socklen_t } #if defined(HAVE_IPV6) && defined(HAVE_INET_PTON) else if (family == AF_INET6) { - log_error_write(srv, __FILE__, __LINE__, "sb", - "invalid IPv6 address literal:", b); + log_error(errh, __FILE__, __LINE__, + "invalid IPv6 address literal: %s", b->ptr); return 0; } #endif @@ -658,20 +653,20 @@ int sock_addr_from_buffer_hints_numeric(server *srv, sock_addr *saddr, socklen_t else { struct hostent *he = gethostbyname(b->ptr); if (NULL == he) { - log_error_write(srv, __FILE__, __LINE__, "sdb", - "gethostbyname failed:", h_errno, b); + log_error(errh, __FILE__, __LINE__, + "gethostbyname failed: %d %s", h_errno, b->ptr); return 0; } if (he->h_addrtype != AF_INET) { - log_error_write(srv, __FILE__, __LINE__, "sd", - "addr-type != AF_INET:", he->h_addrtype); + log_error(errh, __FILE__, __LINE__, + "addr-type != AF_INET: %d", he->h_addrtype); return 0; } if (he->h_length != sizeof(struct in_addr)) { - log_error_write(srv, __FILE__, __LINE__, "sd", - "addr-length != sizeof(in_addr):",he->h_length); + log_error(errh, __FILE__, __LINE__, + "addr-length != sizeof(in_addr): %d", he->h_length); return 0; } @@ -682,7 +677,7 @@ int sock_addr_from_buffer_hints_numeric(server *srv, sock_addr *saddr, socklen_t *len = sizeof(struct sockaddr_in); } #else - UNUSED(srv); + UNUSED(errh); #endif return 0; diff --git a/src/sock_addr.h b/src/sock_addr.h index e949e7ef..f5a0e64d 100644 --- a/src/sock_addr.h +++ b/src/sock_addr.h @@ -41,11 +41,11 @@ const char * sock_addr_inet_ntop(const sock_addr *saddr, char *buf, socklen_t sz int sock_addr_inet_ntop_copy_buffer(buffer *b, const sock_addr *saddr); int sock_addr_inet_ntop_append_buffer(buffer *b, const sock_addr *saddr); int sock_addr_stringify_append_buffer(buffer *b, const sock_addr *saddr); -int sock_addr_nameinfo_append_buffer(server *srv, buffer *b, const sock_addr *saddr); +int sock_addr_nameinfo_append_buffer(buffer *b, const sock_addr *saddr, log_error_st *errh); -int sock_addr_from_buffer_hints_numeric(server *srv, sock_addr *saddr, socklen_t *len, const buffer *b, int family, unsigned short port); -int sock_addr_from_str_hints(server *srv, sock_addr *saddr, socklen_t *len, const char *str, int family, unsigned short port); -int sock_addr_from_str_numeric(server *srv, sock_addr *saddr, const char *str); +int sock_addr_from_buffer_hints_numeric(sock_addr *saddr, socklen_t *len, const buffer *b, int family, unsigned short port, log_error_st *errh); +int sock_addr_from_str_hints(sock_addr *saddr, socklen_t *len, const char *str, int family, unsigned short port, log_error_st *errh); +int sock_addr_from_str_numeric(sock_addr *saddr, const char *str, log_error_st *errh); #endif diff --git a/src/stat_cache.c b/src/stat_cache.c index 2558fc09..90e70c41 100644 --- a/src/stat_cache.c +++ b/src/stat_cache.c @@ -342,8 +342,8 @@ static handler_t stat_cache_handle_fdevent(server *srv, void *_fce, int revent) if (revent & (FDEVENT_HUP|FDEVENT_RDHUP)) { /* fam closed the connection */ - log_error_write(srv, __FILE__, __LINE__, "s", - "FAM connection closed; disabling stat_cache."); + log_error(srv->errh, __FILE__, __LINE__, + "FAM connection closed; disabling stat_cache."); /* (although effectively STAT_CACHE_ENGINE_NONE, * do not change here so that periodic jobs clean up memory)*/ /*srv->srvconf.stat_cache_engine = STAT_CACHE_ENGINE_NONE; */ @@ -365,8 +365,8 @@ static stat_cache_fam * stat_cache_init_fam(server *srv) { /* setup FAM */ if (0 != FAMOpen2(&scf->fam, "lighttpd")) { - log_error_write(srv, __FILE__, __LINE__, "s", - "could not open a fam connection, dieing."); + log_error(srv->errh, __FILE__, __LINE__, + "could not open a fam connection, dieing."); return NULL; } #ifdef HAVE_FAMNOEXISTS @@ -481,11 +481,9 @@ static fam_dir_entry * fam_dir_monitor(server *srv, stat_cache_fam *scf, char *f if (0 != FAMMonitorDirectory(&scf->fam,fam_dir->name->ptr,&fam_dir->req, (void *)(intptr_t)dir_ndx)) { - log_error_write(srv, __FILE__, __LINE__, "sbsss", - "monitoring dir failed:", - fam_dir->name, - "file:", fn, - FamErrlist[FAMErrno]); + log_error(srv->errh, __FILE__, __LINE__, + "monitoring dir failed: %s file: %s %s", + fam_dir->name->ptr, fn, FamErrlist[FAMErrno]); fam_dir_entry_free(fam_dir); return NULL; } @@ -598,12 +596,12 @@ int stat_cache_choose_engine (server *srv, const buffer *stat_cache_string) { } else if (buffer_is_equal_string(stat_cache_string, CONST_STR_LEN("disable"))) { srv->srvconf.stat_cache_engine = STAT_CACHE_ENGINE_NONE; } else { - log_error_write(srv, __FILE__, __LINE__, "sb", - "server.stat-cache-engine can be one of \"disable\", \"simple\"," + log_error(srv->errh, __FILE__, __LINE__, + "server.stat-cache-engine can be one of \"disable\", \"simple\"," #ifdef HAVE_FAM_H - " \"fam\"," + " \"fam\"," #endif - " but not:", stat_cache_string); + " but not: %s", stat_cache_string->ptr); return -1; } return 0; @@ -1036,7 +1034,7 @@ int stat_cache_path_contains_symlink(connection *con, buffer *name) { if (S_ISLNK(st.st_mode)) return 1; } else { - log_perror(con->errh, __FILE__, __LINE__, + log_perror(con->conf.errh, __FILE__, __LINE__, "lstat failed for: %s", buf); return -1; } diff --git a/src/t/test_request.c b/src/t/test_request.c index 9d75da52..e5cef04d 100644 --- a/src/t/test_request.c +++ b/src/t/test_request.c @@ -585,12 +585,12 @@ int main (void) srv.errh->errorlog_fd = -1; /* (disable) */ memset(&con, 0, sizeof(connection)); - con.errh = srv.errh; - con.srv = &srv; - con.proto = buffer_init(); - con.request.request = buffer_init(); - con.request.orig_uri = buffer_init(); - con.request.uri = buffer_init(); + con.srv = &srv; + con.proto = buffer_init(); + con.request.request = buffer_init(); + con.request.orig_uri = buffer_init(); + con.request.uri = buffer_init(); + con.conf.errh = srv.errh; con.conf.allow_http11 = 1; con.conf.http_parseopts = HTTP_PARSEOPT_HEADER_STRICT | HTTP_PARSEOPT_HOST_STRICT