{"thread":{"id":"4588","subject":"[PATCH] Log peer address when git-daemon called from inetd","startedAt":"2006-06-20T14:38:13Z","lastAt":"2006-06-20T21:31:29Z","messageCount":2,"participants":["David Woodhouse","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"22141","messageId":"1150814294.17609.68.camel@hades.cambridge.redhat.com","threadId":"4588","inReplyTo":null,"subject":"[PATCH] Log peer address when git-daemon called from inetd","fromName":"David Woodhouse","fromEmail":"dwmw2@infradead.org","sentAt":"2006-06-20T14:38:13Z","receivedAt":"2006-06-20T14:38:13Z","isPatch":true,"sender":{"key":"dwmw2@infradead.org","avatar":"https://gravatar.com/avatar/7afd4f07e0cf7d7e046ae2d23678296b37777c96488e6f3451e78a5514154ebd?d=mp&s=160"},"body":"When we run git-daemon from inetd, even with the --verbose option, it\ndoesn't log the peer address. That logic was only in the standalone\ndæmon code -- move it to the execute() function instead. Tested with\nboth IPv6 and Legacy IP clients, in both inetd and dæmon mode.\n\nSigned-off-by: David Woodhouse <dwmw2@infradead.org>\nAcked-by: Jon Loeliger <jdl@jdl.com>\n\ndiff --git a/daemon.c b/daemon.c\nindex 2f03f99..7d30302 100644\n--- a/daemon.c\n+++ b/daemon.c\n@@ -264,11 +264,34 @@ static int upload(char *dir)\n \treturn -1;\n }\n \n-static int execute(void)\n+static int execute(struct sockaddr *addr)\n {\n \tstatic char line[1000];\n \tint pktlen, len;\n \n+\tif (addr) {\n+\t\tchar addrbuf[256] = \"\";\n+\t\tint port = -1;\n+\n+\t\tif (addr->sa_family == AF_INET) {\n+\t\t\tstruct sockaddr_in *sin_addr = (void *) addr;\n+\t\t\tinet_ntop(addr->sa_family, &sin_addr->sin_addr, addrbuf, sizeof(addrbuf));\n+\t\t\tport = sin_addr->sin_port;\n+#ifndef NO_IPV6\n+\t\t} else if (addr && addr->sa_family == AF_INET6) {\n+\t\t\tstruct sockaddr_in6 *sin6_addr = (void *) addr;\n+\t\t\t\n+\t\t\tchar *buf = addrbuf;\n+\t\t\t*buf++ = '['; *buf = '\\0'; /* stpcpy() is cool */\n+\t\t\tinet_ntop(AF_INET6, &sin6_addr->sin6_addr, buf, sizeof(addrbuf) - 1);\n+\t\t\tstrcat(buf, \"]\");\n+\n+\t\t\tport = sin6_addr->sin6_port;\n+#endif\n+\t\t}\n+\t\tloginfo(\"Connection from %s:%d\", addrbuf, port);\n+\t}\n+\n \talarm(init_timeout ? init_timeout : timeout);\n \tpktlen = packet_read_line(0, line, sizeof(line));\n \talarm(0);\n@@ -414,8 +437,6 @@ static void check_max_connections(void)\n static void handle(int incoming, struct sockaddr *addr, int addrlen)\n {\n \tpid_t pid = fork();\n-\tchar addrbuf[256] = \"\";\n-\tint port = -1;\n \n \tif (pid) {\n \t\tunsigned idx;\n@@ -436,26 +457,7 @@ static void handle(int incoming, struct \n \tdup2(incoming, 1);\n \tclose(incoming);\n \n-\tif (addr->sa_family == AF_INET) {\n-\t\tstruct sockaddr_in *sin_addr = (void *) addr;\n-\t\tinet_ntop(AF_INET, &sin_addr->sin_addr, addrbuf, sizeof(addrbuf));\n-\t\tport = sin_addr->sin_port;\n-\n-#ifndef NO_IPV6\n-\t} else if (addr->sa_family == AF_INET6) {\n-\t\tstruct sockaddr_in6 *sin6_addr = (void *) addr;\n-\n-\t\tchar *buf = addrbuf;\n-\t\t*buf++ = '['; *buf = '\\0'; /* stpcpy() is cool */\n-\t\tinet_ntop(AF_INET6, &sin6_addr->sin6_addr, buf, sizeof(addrbuf) - 1);\n-\t\tstrcat(buf, \"]\");\n-\n-\t\tport = sin6_addr->sin6_port;\n-#endif\n-\t}\n-\tloginfo(\"Connection from %s:%d\", addrbuf, port);\n-\n-\texit(execute());\n+\texit(execute(addr));\n }\n \n static void child_handler(int signo)\n@@ -751,8 +753,16 @@ int main(int argc, char **argv)\n \t}\n \n \tif (inetd_mode) {\n+\t\tstruct sockaddr_storage ss;\n+\t\tstruct sockaddr *peer = (struct sockaddr *)&ss;\n+\t\tsocklen_t slen = sizeof(ss);\n+\n \t\tfclose(stderr); //FIXME: workaround\n-\t\treturn execute();\n+\n+\t\tif (getpeername(0, peer, &slen))\n+\t\t\tpeer = NULL;\n+\n+\t\treturn execute(peer);\n \t}\n \n \treturn serve(port);\n\n\n-- \ndwmw2\n"},{"id":"22165","messageId":"7vsllz5xam.fsf@assigned-by-dhcp.cox.net","threadId":"4588","inReplyTo":"1150814294.17609.68.camel@hades.cambridge.redhat.com","subject":"Re: [PATCH] Log peer address when git-daemon called from inetd","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-06-20T21:31:29Z","receivedAt":"2006-06-20T21:31:29Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks.\n"}]}