git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Log peer address when git-daemon called from inetd

From
David Woodhouse <dwmw2@infradead.org>
Date
Jun 20, 2006, 14:38 UTC
Message-ID
<1150814294.17609.68.camel@hades.cambridge.redhat.com>

When we run git-daemon from inetd, even with the --verbose option, it doesn't log the peer address. That logic was only in the standalone dæmon code -- move it to the execute() function instead. Tested with both IPv6 and Legacy IP clients, in both inetd and dæmon mode.

Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Acked-by: Jon Loeliger <jdl@jdl.com>
diff --git a/daemon.c b/daemon.c
index 2f03f99..7d30302 100644
--- a/daemon.c
+++ b/daemon.c
@@ -264,11 +264,34 @@ static int upload(char *dir)
 	return -1;
 }
 
-static int execute(void)
+static int execute(struct sockaddr *addr)
 {
 	static char line[1000];
 	int pktlen, len;
 
+	if (addr) {
+		char addrbuf[256] = "";
+		int port = -1;
+
+		if (addr->sa_family == AF_INET) {
+			struct sockaddr_in *sin_addr = (void *) addr;
+			inet_ntop(addr->sa_family, &sin_addr->sin_addr, addrbuf, sizeof(addrbuf));
+			port = sin_addr->sin_port;
+#ifndef NO_IPV6
+		} else if (addr && addr->sa_family == AF_INET6) {
+			struct sockaddr_in6 *sin6_addr = (void *) addr;
+			
+			char *buf = addrbuf;
+			*buf++ = '['; *buf = '\0'; /* stpcpy() is cool */
+			inet_ntop(AF_INET6, &sin6_addr->sin6_addr, buf, sizeof(addrbuf) - 1);
+			strcat(buf, "]");
+
+			port = sin6_addr->sin6_port;
+#endif
+		}
+		loginfo("Connection from %s:%d", addrbuf, port);
+	}
+
 	alarm(init_timeout ? init_timeout : timeout);
 	pktlen = packet_read_line(0, line, sizeof(line));
 	alarm(0);
@@ -414,8 +437,6 @@ static void check_max_connections(void)
 static void handle(int incoming, struct sockaddr *addr, int addrlen)
 {
 	pid_t pid = fork();
-	char addrbuf[256] = "";
-	int port = -1;
 
 	if (pid) {
 		unsigned idx;
@@ -436,26 +457,7 @@ static void handle(int incoming, struct 
 	dup2(incoming, 1);
 	close(incoming);
 
-	if (addr->sa_family == AF_INET) {
-		struct sockaddr_in *sin_addr = (void *) addr;
-		inet_ntop(AF_INET, &sin_addr->sin_addr, addrbuf, sizeof(addrbuf));
-		port = sin_addr->sin_port;
-
-#ifndef NO_IPV6
-	} else if (addr->sa_family == AF_INET6) {
-		struct sockaddr_in6 *sin6_addr = (void *) addr;
-
-		char *buf = addrbuf;
-		*buf++ = '['; *buf = '\0'; /* stpcpy() is cool */
-		inet_ntop(AF_INET6, &sin6_addr->sin6_addr, buf, sizeof(addrbuf) - 1);
-		strcat(buf, "]");
-
-		port = sin6_addr->sin6_port;
-#endif
-	}
-	loginfo("Connection from %s:%d", addrbuf, port);
-
-	exit(execute());
+	exit(execute(addr));
 }
 
 static void child_handler(int signo)
@@ -751,8 +753,16 @@ int main(int argc, char **argv)
 	}
 
 	if (inetd_mode) {
+		struct sockaddr_storage ss;
+		struct sockaddr *peer = (struct sockaddr *)&ss;
+		socklen_t slen = sizeof(ss);
+
 		fclose(stderr); //FIXME: workaround
-		return execute();
+
+		if (getpeername(0, peer, &slen))
+			peer = NULL;
+
+		return execute(peer);
 	}
 
 	return serve(port);
-- 
dwmw2
Next: Junio C Hamano
Message 1 of 2 in “Log peer address when git-daemon called from inetd”
  1. Log peer address when git-daemon called from inetdDavid Woodhouse, Jun 20, 2006
  2. Junio C HamanoJun 20, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.