summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStef Walter <stef@memberwebs.com>2004-06-09 17:19:45 +0000
committerStef Walter <stef@memberwebs.com>2004-06-09 17:19:45 +0000
commit5995e2afd8f026de8f5eb9a392b59542a98bf7e5 (patch)
tree1bd4e661665c49fa62ea7813b793a18718d4d47b
parent88bdaea8c3ef28680a83ee6c82e77e97c6116fb4 (diff)
- Added peer name logging
- Reformatted connection logging
-rw-r--r--apache1x/mod_httpauth.c2
-rw-r--r--common/sock_any.c36
-rw-r--r--common/sock_any.h3
-rw-r--r--daemon/httpauthd.c32
4 files changed, 58 insertions, 15 deletions
diff --git a/apache1x/mod_httpauth.c b/apache1x/mod_httpauth.c
index 43dfa1b..91e6288 100644
--- a/apache1x/mod_httpauth.c
+++ b/apache1x/mod_httpauth.c
@@ -471,7 +471,7 @@ int connect_socket(httpauth_context_t* ctx, request_rec* r)
goto finally;
}
- if(connect(ctx->socket, SANY_ADDR(sany), SANY_LEN(sany)) != 0)
+ if(connect(ctx->socket, &SANY_ADDR(sany), SANY_LEN(sany)) != 0)
{
ap_log_rerror(APLOG_MARK, APLOG_CRIT, r,
"httpauth: Can't connect to httpauthd");
diff --git a/common/sock_any.c b/common/sock_any.c
index 7a128f2..acac8ee 100644
--- a/common/sock_any.c
+++ b/common/sock_any.c
@@ -237,3 +237,39 @@ int sock_any_pton(const char* addr, struct sockaddr_any* any, int defport)
return -1;
}
+int sock_any_ntop(struct sockaddr_any* any, char* addr, size_t addrlen)
+{
+ int len = 0;
+
+ switch(any->s.a.sa_family)
+ {
+ case AF_UNIX:
+ len = strlen(any->s.un.sun_path);
+ if(addrlen < len + 1)
+ {
+ errno = ENOSPC;
+ return -1;
+ }
+
+ strcpy(addr, any->s.un.sun_path);
+ break;
+
+ case AF_INET:
+ if(inet_ntop(any->s.a.sa_family, &(any->s.in.sin_addr), addr, addrlen) == NULL)
+ return -1;
+ break;
+
+#ifdef HAVE_INET6
+ case AF_INET6:
+ if(inet_ntop(any->s.a.sa_family, &(any->s.in6.sin6_addr), addr, addrlen) == NULL)
+ return -1;
+ break;
+#endif
+
+ default:
+ errno = EAFNOSUPPORT;
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/common/sock_any.h b/common/sock_any.h
index 5d733b1..693bd2a 100644
--- a/common/sock_any.h
+++ b/common/sock_any.h
@@ -23,10 +23,11 @@ struct sockaddr_any
size_t namelen;
};
-#define SANY_ADDR(any) (&((any).s.a))
+#define SANY_ADDR(any) ((any).s.a)
#define SANY_LEN(any) ((any).namelen)
#define SANY_TYPE(any) ((any).s.a.sa_family)
int sock_any_pton(const char* addr, struct sockaddr_any* any, int defport);
+int sock_any_ntop(struct sockaddr_any* any, char* addr, size_t addrlen);
#endif /* __SOCK_ANY_H__ */
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;
};