Browse files

git-daemon: set REMOTE_ADDR to client address

This allows hooks like pre-receive to look at the client's IP

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 <>
Signed-off-by: Junio C Hamano <>
  • Loading branch information...
joeyh authored and gitster committed Oct 24, 2008
1 parent 759ad19 commit 53ffb878a94c3eae7c7f57e05568aedcfb77e57f
Showing with 13 additions and 0 deletions.
  1. +9 −0 Documentation/git-daemon.txt
  2. +4 −0 daemon.c
@@ -270,6 +270,15 @@ selectively enable/disable services per repository::
+'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.
Written by Linus Torvalds <>, YOSHIFUJI Hideaki
@@ -537,6 +537,10 @@ static int execute(struct sockaddr *addr)
loginfo("Connection from %s:%d", addrbuf, port);
+ setenv("REMOTE_ADDR", addrbuf, 1);
+ }
+ else {
+ unsetenv("REMOTE_ADDR");
alarm(init_timeout ? init_timeout : timeout);

0 comments on commit 53ffb87

Please sign in to comment.