diff options
Diffstat (limited to 'daemon/httpauthd.c')
-rw-r--r-- | daemon/httpauthd.c | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/daemon/httpauthd.c b/daemon/httpauthd.c index 28aacf7..8897d5f 100644 --- a/daemon/httpauthd.c +++ b/daemon/httpauthd.c @@ -1,5 +1,6 @@ #include <sys/types.h> +#include <sys/param.h> #include <stddef.h> #include <stdio.h> #include <errno.h> @@ -141,6 +142,8 @@ int main(int argc, char* argv[]) const char* pidfile = NULL; httpauth_thread_t* threads = NULL; httpauth_loaded_t* h; + char peername[MAXPATHLEN]; + struct sockaddr_any sany; int daemonize = 1; ha_buffer_t cbuf; int r, i, sock; @@ -227,8 +230,6 @@ int main(int argc, char* argv[]) if(!g_console) { - struct sockaddr_any sany; - /* Create the thread buffers */ threads = (httpauth_thread_t*)calloc(g_maxthreads, sizeof(httpauth_thread_t)); if(!threads) @@ -247,8 +248,8 @@ int main(int argc, char* argv[]) /* TODO: Is this safe? */ unlink(g_socket); - if(bind(sock, SANY_ADDR(sany), SANY_LEN(sany)) != 0) - err(1, "couldn't bind to socket: %s", g_socket); + if(bind(sock, &SANY_ADDR(sany), SANY_LEN(sany)) != 0) + err(1, "couldn't bind to address: %s", g_socket); /* Let 5 connections queue up */ if(listen(sock, 5) != 0) @@ -333,7 +334,12 @@ int main(int argc, char* argv[]) continue; } - ha_messagex(LOG_INFO, "accepted connection: %d", fd); + /* Get the peer name */ + if(getpeername(fd, &SANY_ADDR(sany), &SANY_LEN(sany)) == -1 || + sock_any_ntop(&sany, peername, MAXPATHLEN) == -1) + ha_messagex(LOG_WARNING, "%d: couldn't get peer address", fd); + else + ha_messagex(LOG_INFO, "%d: accepted connection from: %s", fd, peername); /* Look for thread and also clean up others */ for(i = 0; i < g_maxthreads; i++) @@ -363,7 +369,7 @@ int main(int argc, char* argv[]) break; } - ha_messagex(LOG_DEBUG, "created thread for connection: %d", fd); + ha_messagex(LOG_DEBUG, "%d: created thread for connection", fd); fd = -1; break; } @@ -461,7 +467,7 @@ static void* httpauth_thread(void* arg) /* call the processor */ r = httpauth_processor(thread->fd, thread->fd); - ha_messagex(LOG_INFO, "closed connection: %d", thread->fd); + ha_messagex(LOG_INFO, "%d: closed connection", thread->fd); /* mark this as done */ thread->fd = -1; @@ -513,7 +519,7 @@ void log_request(ha_request_t* req, ha_buffer_t* buf, int fd) ASSERT(t2); - ha_messagex(LOG_DEBUG, "received request (from %d): " + ha_messagex(LOG_DEBUG, "%d: received request: " "[ type: %s / args: %s ]", fd, t2, t); for(i = 0; i < HA_MAX_HEADERS; i++) @@ -521,7 +527,7 @@ void log_request(ha_request_t* req, ha_buffer_t* buf, int fd) if(req->headers[i].name) { ASSERT(req->headers[i].data); - ha_messagex(LOG_DEBUG, "received header (from %d): [ %s: %s ]", fd, + ha_messagex(LOG_DEBUG, "%d: received header: [ %s: %s ]", fd, req->headers[i].name, req->headers[i].data); } } @@ -534,7 +540,7 @@ void log_response(ha_response_t* resp, int fd) if(g_debuglevel < LOG_DEBUG) return; - ha_messagex(LOG_DEBUG, "sending response (to %d): " + ha_messagex(LOG_DEBUG, "%d: sending response: " "[ code: 200 / ccode: %d / detail: %s ]", fd, resp->code, resp->detail ? resp->detail : ""); @@ -543,7 +549,7 @@ void log_response(ha_response_t* resp, int fd) if(resp->headers[i].name) { ASSERT(resp->headers[i].data); - ha_messagex(LOG_DEBUG, "sending header (to %d): [ %s: %s ]", fd, + ha_messagex(LOG_DEBUG, "%d: sending header: [ %s: %s ]", fd, resp->headers[i].name, resp->headers[i].data); } } @@ -554,7 +560,7 @@ void log_respcode(int code, const char* msg, int fd) if(g_debuglevel < LOG_DEBUG) return; - ha_messagex(LOG_DEBUG, "sending response (to %d): " + ha_messagex(LOG_DEBUG, "%d: sending response: " "[ code: %d / detail: %s ]", fd, code, msg ? msg : ""); } @@ -1075,7 +1081,7 @@ static int httpauth_processor(int ifd, int ofd) break; default: - ha_messagex(LOG_WARNING, "received unknown command from client: %d", ifd); + ha_messagex(LOG_WARNING, "%d: received unknown command from client", ifd); r = httpauth_respond(ofd, HA_SERVER_BADREQ, 0, "Unknown command"); break; }; |