git-daemon: set REMOTE_ADDR to client address
authorJoey Hess <joey@kitenet.net>
Fri, 24 Oct 2008 05:48:50 +0000 (01:48 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 24 Oct 2008 23:34:01 +0000 (16:34 -0700)
This allows hooks like pre-receive to look at the client's IP
address.

Of course the IP address can't be used to get strong security;
git-daemon isn't the right thing to use if you need that. However,
basic IP address checking can be good enough in some situations.

REMOTE_ADDR is the same environment variable used to communicate the
client's address to CGI scripts.

Signed-off-by: Joey Hess <joey@kitenet.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-daemon.txt
daemon.c

index b08a08cd95b6da192a008c58d7973769dfe3fc8c..f1a570a874ff0ccc2c2ffb6271ac76529506c4cc 100644 (file)
@@ -270,6 +270,15 @@ selectively enable/disable services per repository::
 ----------------------------------------------------------------
 
 
+ENVIRONMENT
+-----------
+'git-daemon' will set REMOTE_ADDR to the IP address of the client
+that connected to it, if the IP address is available. REMOTE_ADDR will
+be available in the environment of hooks called when
+services are performed.
+
+
+
 Author
 ------
 Written by Linus Torvalds <torvalds@osdl.org>, YOSHIFUJI Hideaki
index 3e5582d28921af22357f2d6068ef55f847bd016a..b9ba44c582b3b6cfac0f150f7f8901d60b48bbb3 100644 (file)
--- a/daemon.c
+++ b/daemon.c
@@ -537,6 +537,10 @@ static int execute(struct sockaddr *addr)
 #endif
                }
                loginfo("Connection from %s:%d", addrbuf, port);
+               setenv("REMOTE_ADDR", addrbuf, 1);
+       }
+       else {
+               unsetenv("REMOTE_ADDR");
        }
 
        alarm(init_timeout ? init_timeout : timeout);