From: Sebastian Harl Date: Fri, 16 Jan 2015 13:31:42 +0000 (+0100) Subject: connection: Log peer information after accepting a connection. X-Git-Tag: sysdb-0.7.0~66 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=d24d97e4eaeb145fd6be0276ccf1570601a54d94;p=sysdb.git connection: Log peer information after accepting a connection. --- diff --git a/src/frontend/connection.c b/src/frontend/connection.c index 6b359d3..62e5f9d 100644 --- a/src/frontend/connection.c +++ b/src/frontend/connection.c @@ -44,10 +44,14 @@ #include #include +#include +#include + #include #include #include +#include /* * private variables @@ -410,6 +414,7 @@ sdb_conn_t * sdb_connection_accept(int fd, sdb_conn_setup_cb setup, void *user_data) { sdb_conn_t *conn; + const char *peer = "unknown"; if (fd < 0) return NULL; @@ -422,6 +427,22 @@ sdb_connection_accept(int fd, sdb_conn_setup_cb setup, void *user_data) sdb_object_deref(SDB_OBJ(conn)); return NULL; } + + if (conn->username) + peer = conn->username; + + if (conn->client_addr.ss_family == AF_UNIX) { + sdb_log(SDB_LOG_INFO, + "frontend: Accepted connection from peer %s", peer); + } + else { + char host[1024] = "", port[32] = ""; + getnameinfo((struct sockaddr *)&conn->client_addr, + conn->client_addr_len, host, sizeof(host), port, sizeof(port), + NI_NUMERICHOST | NI_NUMERICSERV); + sdb_log(SDB_LOG_INFO, "frontend: Accepted connection from " + "peer %s at %s:%s", peer, host, port); + } return conn; } /* sdb_connection_create */