Skip to content

Commit 53ffb87

Browse files
joeyhgitster
authored andcommitted
git-daemon: set REMOTE_ADDR to client address
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>
1 parent 759ad19 commit 53ffb87

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

Documentation/git-daemon.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,15 @@ selectively enable/disable services per repository::
270270
----------------------------------------------------------------
271271

272272

273+
ENVIRONMENT
274+
-----------
275+
'git-daemon' will set REMOTE_ADDR to the IP address of the client
276+
that connected to it, if the IP address is available. REMOTE_ADDR will
277+
be available in the environment of hooks called when
278+
services are performed.
279+
280+
281+
273282
Author
274283
------
275284
Written by Linus Torvalds <torvalds@osdl.org>, YOSHIFUJI Hideaki

daemon.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,10 @@ static int execute(struct sockaddr *addr)
537537
#endif
538538
}
539539
loginfo("Connection from %s:%d", addrbuf, port);
540+
setenv("REMOTE_ADDR", addrbuf, 1);
541+
}
542+
else {
543+
unsetenv("REMOTE_ADDR");
540544
}
541545

542546
alarm(init_timeout ? init_timeout : timeout);

0 commit comments

Comments
 (0)