summaryrefslogtreecommitdiff
path: root/daemon.c
AgeCommit message (Collapse)Author
2010-05-31Rewrite dynamic structure initializations to runtime assignmentGary V. Vaughan
Unfortunately, there are still plenty of production systems with vendor compilers that choke unless all compound declarations can be determined statically at compile time, for example hpux10.20 (I can provide a comprehensive list of our supported platforms that exhibit this problem if necessary). This patch simply breaks apart any compound declarations with dynamic initialisation expressions, and moves the initialisation until after the last declaration in the same block, in all the places necessary to have the offending compilers accept the code. Signed-off-by: Gary V. Vaughan <gary@thewrittenword.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-04-03Merge branch 'bc/maint-daemon-sans-ss-family'Junio C Hamano
* bc/maint-daemon-sans-ss-family: daemon.c: avoid accessing ss_family member of struct sockaddr_storage
2010-03-20daemon: parse_host_and_port SIGSEGV if port is specifiedImre Deak
This typo will lead to git-daemon dying any time the connect string includes a port after the host= attribute. This can lead for example to one of the following error messages on the client side when someone tries git clone git://...:<port>. When the daemon is running on localhost: fatal: The remote end hung up unexpectedly or when the daemon is connected through an ssh tunnel: fatal: protocol error: bad line length character: erro In the latter case 'erro' comes from the daemon's reply: error: git-daemon died of signal 11 Signed-off-by: Imre Deak <imre.deak@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-03-17daemon.c: avoid accessing ss_family member of struct sockaddr_storageBrandon Casey
When NO_SOCKADDR_STORAGE is set for a platform, either sockaddr_in or sockaddr_in6 is used intead. Neither of which has an ss_family member. They have an sin_family and sin6_family member respectively. Since the addrcmp() function accesses the ss_family member of a sockaddr_storage struct, compilation fails on platforms which define NO_SOCKADDR_STORAGE. Since any sockaddr_* structure can be cast to a struct sockaddr and have its sa_family member read, do so here to workaround this issue. Thanks to Martin Storsjö for pointing out the fix, and Gary Vaughan for drawing attention to the issue. Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-02-04Typofixes outside documentation areaJunio C Hamano
begining -> beginning canonicalizations -> canonicalization comand -> command dewrapping -> unwrapping dirtyness -> dirtiness DISCLAMER -> DISCLAIMER explicitely -> explicitly feeded -> fed impiled -> implied madatory -> mandatory mimick -> mimic preceeding -> preceding reqeuest -> request substition -> substitution Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-27Merge branch 'il/maint-colon-address'Junio C Hamano
* il/maint-colon-address: Allow use of []-wrapped addresses in git:// Support addresses with ':' in git-daemon
2010-01-26Support addresses with ':' in git-daemonIlari Liusvaara
If host address could have ':' in it (e.g. numeric IPv6 address), then host and port could not be uniquely parsed. Fix this by parsing the "["<host>"]":<port> and "["<host>"]" notations. Currently the built-in git:// client would send <host>:<port> or <host> for such thing, but it doesn't matter as due to bugs, resolving address fails if <host> contains ':'. Signed-off-by: Ilari Liusvaara <ilari.liusvaara@elisanet.fi> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-20Merge branch 'jk/warn-author-committer-after-commit'Junio C Hamano
* jk/warn-author-committer-after-commit: user_ident_sufficiently_given(): refactor the logic to be usable from elsewhere commit.c::print_summary: do not release the format string too early commit: allow suppression of implicit identity advice commit: show interesting ident information in summary strbuf: add strbuf_addbuf_percentquote strbuf_expand: convert "%%" to "%" Conflicts: builtin-commit.c ident.c
2010-01-14strbuf_expand: convert "%%" to "%"Jeff King
The only way to safely quote arbitrary text in a pretty-print user format is to replace instances of "%" with "%x25". This is slightly unreadable, and many users would expect "%%" to produce a single "%", as that is what printf format specifiers do. This patch converts "%%" to "%" for all users of strbuf_expand(): (1) git-daemon interpolated paths (2) pretty-print user formats (3) merge driver command lines Case (1) was already doing the conversion itself outside of strbuf_expand(). Case (2) is the intended beneficiary of this patch. Case (3) users probably won't notice, but as this is user-facing behavior, consistently providing the quoting mechanism makes sense. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-10daemon: consider only address in kill_some_child()Erik Faye-Lund
kill_some_child() compares the entire sockaddr_storage structure (with the pad-bits zeroed out) when trying to find out if connections originate from the same host. However, sockaddr_storage contains the port-number for the connection (which varies between connections), so the comparison always fails. Change the code so we only consider the host-address, by introducing the addrcmp()-function that inspects the address family and compare as appropriate. Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-11-23Merge branch 'tc/format-attribute'Junio C Hamano
* tc/format-attribute: Check the format of more printf-type functions
2009-11-16Check the format of more printf-type functionsTarmigan Casebolt
We already have these checks in many printf-type functions that have prototypes which are in header files. Add these same checks to some more prototypes in header functions and to static functions in .c files. cc: Miklos Vajna <vmiklos@frugalware.org> Signed-off-by: Tarmigan Casebolt <tarmigan+git@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-11-10http-backend: Protect GIT_PROJECT_ROOT from /../ requestsShawn O. Pearce
Eons ago HPA taught git-daemon how to protect itself from /../ attacks, which Junio brought back into service in d79374c7b58d ("daemon.c and path.enter_repo(): revamp path validation"). I did not carry this into git-http-backend as originally we relied only upon PATH_TRANSLATED, and assumed the HTTP server had done its access control checks to validate the resolved path was within a directory permitting access from the remote client. This would usually be sufficient to protect a server from requests for its /etc/passwd file by http://host/smart/../etc/passwd sorts of URLs. However in 917adc036086 Mark Lodato added GIT_PROJECT_ROOT as an additional method of configuring the CGI. When this environment variable is used the web server does not generate the final access path and therefore may blindly pass through "/../etc/passwd" in PATH_INFO under the assumption that "/../" might have special meaning to the invoked CGI. Instead of permitting these sorts of malformed path requests, we now reject them back at the client, with an error message for the server log. This matches git-daemon behavior. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-07-06Merge branch 'tr/die_errno'Junio C Hamano
* tr/die_errno: Use die_errno() instead of die() when checking syscalls Convert existing die(..., strerror(errno)) to die_errno() die_errno(): double % in strerror() output just in case Introduce die_errno() that appends strerror(errno) to die()
2009-07-02Merge branch 'js/daemon-log'Junio C Hamano
* js/daemon-log: receive-pack: do not send error details to the client upload-pack: squelch progress indicator if client cannot see it daemon: send stderr of service programs to the syslog
2009-06-27Convert existing die(..., strerror(errno)) to die_errno()Thomas Rast
Change calls to die(..., strerror(errno)) to use the new die_errno(). In the process, also make slight style adjustments: at least state _something_ about the function that failed (instead of just printing the pathname), and put paths in single quotes. Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-06-21Fix various sparse warnings in the git source codeLinus Torvalds
There are a few remaining ones, but this fixes the trivial ones. It boils down to two main issues that sparse complains about: - warning: Using plain integer as NULL pointer Sparse doesn't like you using '0' instead of 'NULL'. For various good reasons, not the least of which is just the visual confusion. A NULL pointer is not an integer, and that whole "0 works as NULL" is a historical accident and not very pretty. A few of these remain: zlib is a total mess, and Z_NULL is just a 0. I didn't touch those. - warning: symbol 'xyz' was not declared. Should it be static? Sparse wants to see declarations for any functions you export. A lack of a declaration tends to mean that you should either add one, or you should mark the function 'static' to show that it's in file scope. A few of these remain: I only did the ones that should obviously just be made static. That 'wt_status_submodule_summary' one is debatable. It has a few related flags (like 'wt_status_use_color') which _are_ declared, and are used by builtin-commit.c. So maybe we'd like to export it at some point, but it's not declared now, and not used outside of that file, so 'static' it is in this patch. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-06-18daemon: send stderr of service programs to the syslogJohannes Sixt
If git-daemon is run with --detach or --inetd, then stderr is explicitly redirected to /dev/null. But notice that the service programs were spawned via execl_git_cmd(), in particular, the stderr channel is inherited from the daemon. This means that errors that the programs wrote to stderr (for example, via die()), went to /dev/null. This patch arranges that the daemon does not merely exec the service program, but forks it and monitors stderr of the child; it writes the errors that it produces to the daemons log via logerror(). A consequence is that the daemon process remains in memory for the full duration of the service program, but this cannot be avoided. Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-06-06daemon: Strictly parse the "extra arg" part of the commandShawn O. Pearce
Since 1.4.4.5 (49ba83fb67 "Add virtualization support to git-daemon") git daemon enters an infinite loop and never terminates if a client hides any extra arguments in the initial request line which is not exactly "\0host=blah\0". Since that change, a client must never insert additional extra arguments, or attempt to use any argument other than "host=", as any daemon will get stuck parsing the request line and will never complete the request. Since the client can't tell if the daemon is patched or not, it is not possible to know if additional extra args might actually be able to be safely requested. If we ever need to extend the git daemon protocol to support a new feature, we may have to do something like this to the exchange: # If both support git:// v2 # C: 000cgit://v2 S: 0010ok host user C: 0018host git.kernel.org C: 0027git-upload-pack /pub/linux-2.6.git S: ...git-upload-pack header... # If client supports git:// v2, server does not: # C: 000cgit://v2 S: <EOF> C: 003bgit-upload-pack /pub/linux-2.6.git\0host=git.kernel.org\0 S: ...git-upload-pack header... This requires the client to create two TCP connections to talk to an older git daemon, however all daemons since the introduction of daemon.c will safely reject the unknown "git://v2" command request, so the client can quite easily determine the server supports an older protocol. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-04-29daemon.c: fix segfault on OS XBenjamin Kramer
On OS X (and maybe other unices), getaddrinfo(3) returns NULL in the ai_canonname field if it's called with an IP address for the hostname. We'll now use the IP address for the hostname if ai_canonname was NULL, this also matches the behaviour on Linux. steps to reproduce: $ git daemon --export-all $ git clone git://127.0.0.1/frotz => git daemon's fork (silently) segfaults. Remove the pointless loop while at it. There is only one iteration because of the break; on the last line and there are no continues. Signed-off-by: Benjamin Kramer <benny.kra@googlemail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-03-05improve missing repository error messageJeff King
Certain remote commands, when asked to do something in a particular directory that was not actually a git repository, would say "unable to chdir or not a git archive". The "chdir" bit is an unnecessary detail, and the term "git archive" is much less common these days than "git repository". So let's switch them all to: fatal: '%s' does not appear to be a git repository Signed-off-by: Jeff King <peff@peff.net> Acked-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-01-26Add calls to git_extract_argv0_path() in programs that call git_config_*Steffen Prohaska
Programs that use git_config need to find the global configuration. When runtime prefix computation is enabled, this requires that git_extract_argv0_path() is called early in the program's main(). This commit adds the necessary calls. Signed-off-by: Steffen Prohaska <prohaska@zib.de> Acked-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-01-05remove trailing LF in die() messagesAlexander Potashev
LF at the end of format strings given to die() is redundant because die already adds one on its own. Signed-off-by: Alexander Potashev <aspotashev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-12-27daemon: cleanup: factor out xstrdup_tolower()René Scharfe
Add xstrdup_tolower(), a helper to get a lower case copy of a string, and use it in two cases. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-12-27daemon: cleanup: replace loop with ifRené Scharfe
Replace a loop around an enter_repo() call, which was used to retry a single time with a different parameter in case the first call fails, with two calls and an if. This is shorter and cleaner. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-12-27daemon: handle freopen() failureRené Scharfe
Die if stderr couldn't be sent to /dev/null when operating in inetd mode and report the error message from the OS. This fixes a compiler warning about the return value of freopen() being ignored on Ubuntu 8.10. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-11-24daemon: deglobalize variable 'directory'René Scharfe
Remove the global variable 'directory' and pass it as a parameter of the two functions that use it instead, (almost) restoring their interface to how it was before 49ba83fb67d9e447b86953965ce5f949c6a93b81. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-11-24daemon: inline fill_in_extra_table_entries()René Scharfe
Having fill_in_extra_table_entries() as a separate function has no advantage -- a function with no parameters and return values might as well be an anonymous block of code. Its name still refers to the table of interpolate() which has been removed earlier, so it's better to inline it at its only call site. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-11-24daemon: use strbuf_expand() instead of interpolate()René Scharfe
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-10-24git-daemon: set REMOTE_ADDR to client addressJoey Hess
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>
2008-09-25Merge branch 'jc/alternate-push'Shawn O. Pearce
* jc/alternate-push: push: receiver end advertises refs from alternate repositories push: prepare sender to receive extended ref information from the receiver receive-pack: make it a builtin is_directory(): a generic helper function
2008-09-09is_directory(): a generic helper functionJunio C Hamano
A simple "grep -e stat --and -e S_ISDIR" revealed there are many open-coded implementations of this function. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-09-07daemon.c: avoid setlinebuf()Junio C Hamano
This function is outside POSIX (Linux and recent BSD have it). Replace it with setvbuf() which is POSIX. I am not sure about the value this patch passes as size argument to setvbuf(), though. I know the call this patch makes is equivalent to calling setlinebuf() with GNU libc, but POSIX itself leaves what happens to the size argument quite vague, saying only "otherwise [i.e. when buf is a null pointer], size _may_ determine the size of a buffer allocated by the setvbuf() function." If passing size=0 causes stdio to allocate very small buffer, and while stdio tries to line buffer the output, it might make it to fail to buffer an entire line, causing early flushing of the stream. Even if that turns out to be a problem on minorority platforms, we won't know it until the issue actually hurts them, so let's push this change out and see what happens. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-08-31cast pid_t's to uintmax_t to improve portabilityDavid Soria Parra
Some systems (like e.g. OpenSolaris) define pid_t as long, therefore all our sprintf that use %i/%d cause a compiler warning beacuse of the implicit long->int cast. To make sure that we fit the limits, we display pids as PRIuMAX and cast them explicitly to uintmax_t. Signed-off-by: David Soria Parra <dsp@php.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-08-26daemon.c: minor style fixupJunio C Hamano
* "else" on the same line as "}" that closes corresponding "if (...) {"; * multi-line comments begin with "/*\n"; * sizeof, even it is not a function, is written as "sizeof(...)"; * no need to check x?alloc() return value -- it would have died; * "if (...) { ... }" that covers the whole function body can be dedented by returning from the function early with "if (!...) return;"; * SP on each side of an operator, i.e. "a > 0", not "a>0"; Also removes stale comment describing how remove_child() used to do its thing. Signed-off-by: Junio C Hamano <gitster@pobox.com>: Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-08-18git-daemon: rewrite kindergarden, new option --max-connectionsStephen R. van den Berg
Get rid of the fixed array of children and make max-connections dynamic and configurable. Fix the killing code to actually kill the newest connections from duplicate IP-addresses. Avoid forking if too busy already. Signed-off-by: Stephen R. van den Berg <srb@cuci.nl> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-08-18git-daemon: Simplify dead-children reaping logicStephen R. van den Berg
Move almost all code out of the child_handler() into check_dead_children(). The fact that systemcalls get interrupted by signals allows us to make the SIGCHLD signal handler almost a no-op by simply running check_dead_children() right before waiting on poll(). In case some systems do not interrupt systemcalls upon signal receipt, all zombies will eventually be collected before the next poll() cycle. Signed-off-by: Stephen R. van den Berg <srb@cuci.nl> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-08-18git-daemon: use LOG_PID, simplify logging codeStephen R. van den Berg
Make git-daemon use LOG_PID like most daemons, instead of prepending the pid to the message ourselves, when using syslog(3). Simplify the logging code by setting stderr to line buffered, instead of building a single string and writing it out with a single write(2). Give an extra log message at the daemon start-up. Signed-off-by: Stephen R. van den Berg <srb@cuci.nl> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-08-18git-daemon: call logerror() instead of error()Stephen R. van den Berg
Use logerror(), not error(), so that the messages won't be lost, especially when running the daemon with its log sent to the syslog facility. Signed-off-by: Stephen R. van den Berg <srb@cuci.nl> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-08-12git-daemon: SysV needs the signal handler reinstated.Stephen R. van den Berg
Fixes the bug on (amongst others) Solaris that only the first child ever is reaped. Signed-off-by: Stephen R. van den Berg <srb@cuci.nl> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-07-23git daemon: avoid waking up too oftenJohannes Schindelin
To avoid waking up unnecessarily, a pipe is set up that is only ever written to by child_handler(), when a child disconnects, as suggested per Junio. This avoids waking up the main process every second to see if a child was disconnected. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-07-13Make usage strings dash-lessStephan Beyer
When you misuse a git command, you are shown the usage string. But this is currently shown in the dashed form. So if you just copy what you see, it will not work, when the dashed form is no longer supported. This patch makes git commands show the dash-less version. For shell scripts that do not specify OPTIONS_SPEC, git-sh-setup.sh generates a dash-less usage string now. Signed-off-by: Stephan Beyer <s-beyer@gmx.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-07-07git daemon: avoid calling syslog() from a signal handlerJohannes Schindelin
Signal handlers should never call syslog(), as that can raise signals of its own. Instead, call the syslog() from the master process. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-05-14Provide git_config with a callback-data parameterJohannes Schindelin
git_config() only had a function parameter, but no callback data parameter. This assumes that all callback functions only modify global variables. With this patch, every callback gets a void * parameter, and it is hoped that this will help the libification effort. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-02-27daemon: ensure that base-path is an existing directoryJohannes Sixt
Any request to the daemon would fail if base-path (if specified) is not a directory. We now check for this condition early. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-02-27daemon: send more error messages to the syslogJohannes Sixt
There were a number of die() calls before the syslog was opened; hence, these error messages would have been sent to /dev/null in detached mode. Now we install the daemon-specific die routine before any error message is generated so that these messages go to the syslog. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-11-08Style: place opening brace of a function definition at column 1Junio C Hamano
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-11-06git-daemon: fix remote port number in log entryGerrit Pape
The port number in struct sockaddr_in needs to be converted from network byte order to host byte order (on some architectures). Signed-off-by: Gerrit Pape <pape@smarden.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-10-19Define NI_MAXSERV if not defined by operating systemPatrick Welche
I found I needed NI_MAXSERV as it is defined in netdb.h, which is not included by daemon.c. Rather than including the whole header we can define a reasonable fallback value. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2007-08-01--base-path-relaxed optionJens Axboe
I switched git.kernel.dk to --base-path a few minutes ago, to get rid of a /data/git postfix in the posted urls. But transitioning is tricky, since now all old paths will fail miserably. So I added this --base-path-relaxed option, that will make git-daemon try the absolute path without prefixing --base-path before giving up. With this in place and --base-path-relaxed added, both my new url of git://git.kernel.dk/linux-2.6-block.git and the old git://git.kernel.dk/data/git/linux-2.6-block.git work fine. Signed-off-by: Jens Axboe <jens.axboe@oracle.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>