Skip to content

Commit

Permalink
git-daemon: set REMOTE_ADDR to client address
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Joey Hess authored and Junio C Hamano committed Oct 24, 2008
1 parent 759ad19 commit 53ffb87
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Documentation/git-daemon.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 53ffb87

Please sign in to comment.