3 #include <sys/socket.h>
7 #include <netinet/in.h>
16 #include "interpolate.h"
18 static int log_syslog;
22 static const char daemon_usage[] =
23 "git-daemon [--verbose] [--syslog] [--export-all]\n"
24 " [--timeout=n] [--init-timeout=n] [--strict-paths]\n"
25 " [--base-path=path] [--user-path | --user-path=path]\n"
26 " [--interpolated-path=path]\n"
27 " [--reuseaddr] [--detach] [--pid-file=file]\n"
28 " [--[enable|disable|allow-override|forbid-override]=service]\n"
29 " [--inetd | [--listen=host_or_ipaddr] [--port=n]\n"
30 " [--user=user [--group=group]]\n"
33 /* List of acceptable pathname prefixes */
34 static char **ok_paths;
35 static int strict_paths;
37 /* If this is set, git-daemon-export-ok is not required */
38 static int export_all_trees;
40 /* Take all paths relative to this one if non-NULL */
41 static char *base_path;
42 static char *interpolated_path;
44 /* Flag indicating client sent extra args. */
45 static int saw_extended_args;
47 /* If defined, ~user notation is allowed and the string is inserted
48 * after ~user/. E.g. a request to git://host/~alice/frotz would
49 * go to /home/alice/pub_git/frotz with --user-path=pub_git.
51 static const char *user_path;
53 /* Timeout, and initial timeout */
54 static unsigned int timeout;
55 static unsigned int init_timeout;
58 * Static table for now. Ugh.
59 * Feel free to make dynamic as needed.
61 #define INTERP_SLOT_HOST (0)
62 #define INTERP_SLOT_CANON_HOST (1)
63 #define INTERP_SLOT_IP (2)
64 #define INTERP_SLOT_PORT (3)
65 #define INTERP_SLOT_DIR (4)
66 #define INTERP_SLOT_PERCENT (5)
68 static struct interp interp_table[] = {
78 static void logreport(int priority, const char *err, va_list params)
80 /* We should do a single write so that it is atomic and output
81 * of several processes do not get intermingled. */
86 /* sizeof(buf) should be big enough for "[pid] \n" */
87 buflen = snprintf(buf, sizeof(buf), "[%ld] ", (long) getpid());
89 maxlen = sizeof(buf) - buflen - 1; /* -1 for our own LF */
90 msglen = vsnprintf(buf + buflen, maxlen, err, params);
93 syslog(priority, "%s", buf);
97 /* maxlen counted our own LF but also counts space given to
98 * vsnprintf for the terminating NUL. We want to make sure that
99 * we have space for our own LF and NUL after the "meat" of the
100 * message, so truncate it at maxlen - 1.
102 if (msglen > maxlen - 1)
105 msglen = 0; /* Protect against weird return values. */
108 buf[buflen++] = '\n';
111 write(2, buf, buflen);
114 static void logerror(const char *err, ...)
117 va_start(params, err);
118 logreport(LOG_ERR, err, params);
122 static void loginfo(const char *err, ...)
127 va_start(params, err);
128 logreport(LOG_INFO, err, params);
132 static void NORETURN daemon_die(const char *err, va_list params)
134 logreport(LOG_ERR, err, params);
138 static int avoid_alias(char *p)
143 * This resurrects the belts and suspenders paranoia check by HPA
144 * done in <435560F7.4080006@zytor.com> thread, now enter_repo()
145 * does not do getcwd() based path canonicalizations.
147 * sl becomes true immediately after seeing '/' and continues to
148 * be true as long as dots continue after that without intervening
151 if (!p || (*p != '/' && *p != '~'))
161 else if (ch == '/') {
163 /* reject //, /./ and /../ */
168 if (0 < ndot && ndot < 3)
169 /* reject /.$ and /..$ */
178 else if (ch == '/') {
185 static char *path_ok(struct interp *itable)
187 static char rpath[PATH_MAX];
188 static char interp_path[PATH_MAX];
192 dir = itable[INTERP_SLOT_DIR].value;
194 if (avoid_alias(dir)) {
195 logerror("'%s': aliased", dir);
201 logerror("'%s': User-path not allowed", dir);
205 /* Got either "~alice" or "~alice/foo";
206 * rewrite them to "~alice/%s" or
209 int namlen, restlen = strlen(dir);
210 char *slash = strchr(dir, '/');
212 slash = dir + restlen;
213 namlen = slash - dir;
215 loginfo("userpath <%s>, request <%s>, namlen %d, restlen %d, slash <%s>", user_path, dir, namlen, restlen, slash);
216 snprintf(rpath, PATH_MAX, "%.*s/%s%.*s",
217 namlen, dir, user_path, restlen, slash);
221 else if (interpolated_path && saw_extended_args) {
223 /* Allow only absolute */
224 logerror("'%s': Non-absolute path denied (interpolated-path active)", dir);
228 interpolate(interp_path, PATH_MAX, interpolated_path,
229 interp_table, ARRAY_SIZE(interp_table));
230 loginfo("Interpolated dir '%s'", interp_path);
234 else if (base_path) {
236 /* Allow only absolute */
237 logerror("'%s': Non-absolute path denied (base-path active)", dir);
240 snprintf(rpath, PATH_MAX, "%s%s", base_path, dir);
244 path = enter_repo(dir, strict_paths);
247 logerror("'%s': unable to chdir or not a git archive", dir);
251 if ( ok_paths && *ok_paths ) {
253 int pathlen = strlen(path);
255 /* The validation is done on the paths after enter_repo
256 * appends optional {.git,.git/.git} and friends, but
257 * it does not use getcwd(). So if your /pub is
258 * a symlink to /mnt/pub, you can whitelist /pub and
259 * do not have to say /mnt/pub.
262 for ( pp = ok_paths ; *pp ; pp++ ) {
263 int len = strlen(*pp);
264 if (len <= pathlen &&
265 !memcmp(*pp, path, len) &&
266 (path[len] == '\0' ||
267 (!strict_paths && path[len] == '/')))
272 /* be backwards compatible */
277 logerror("'%s': not in whitelist", path);
278 return NULL; /* Fallthrough. Deny by default */
281 typedef int (*daemon_service_fn)(void);
282 struct daemon_service {
284 const char *config_name;
285 daemon_service_fn fn;
290 static struct daemon_service *service_looking_at;
291 static int service_enabled;
293 static int git_daemon_config(const char *var, const char *value)
295 if (!strncmp(var, "daemon.", 7) &&
296 !strcmp(var + 7, service_looking_at->config_name)) {
297 service_enabled = git_config_bool(var, value);
301 /* we are not interested in parsing any other configuration here */
305 static int run_service(struct interp *itable, struct daemon_service *service)
308 int enabled = service->enabled;
310 loginfo("Request %s for '%s'",
312 itable[INTERP_SLOT_DIR].value);
314 if (!enabled && !service->overridable) {
315 logerror("'%s': service not enabled.", service->name);
320 if (!(path = path_ok(itable)))
324 * Security on the cheap.
326 * We want a readable HEAD, usable "objects" directory, and
327 * a "git-daemon-export-ok" flag that says that the other side
328 * is ok with us doing this.
330 * path_ok() uses enter_repo() and does whitelist checking.
331 * We only need to make sure the repository is exported.
334 if (!export_all_trees && access("git-daemon-export-ok", F_OK)) {
335 logerror("'%s': repository not exported.", path);
340 if (service->overridable) {
341 service_looking_at = service;
342 service_enabled = -1;
343 git_config(git_daemon_config);
344 if (0 <= service_enabled)
345 enabled = service_enabled;
348 logerror("'%s': service not enabled for '%s'",
349 service->name, path);
355 * We'll ignore SIGTERM from now on, we have a
358 signal(SIGTERM, SIG_IGN);
360 return service->fn();
363 static int upload_pack(void)
365 /* Timeout as string */
366 char timeout_buf[64];
368 snprintf(timeout_buf, sizeof timeout_buf, "--timeout=%u", timeout);
370 /* git-upload-pack only ever reads stuff, so this is safe */
371 execl_git_cmd("upload-pack", "--strict", timeout_buf, ".", NULL);
375 static int upload_archive(void)
377 execl_git_cmd("upload-archive", ".", NULL);
381 static struct daemon_service daemon_service[] = {
382 { "upload-archive", "uploadarch", upload_archive, 0, 1 },
383 { "upload-pack", "uploadpack", upload_pack, 1, 1 },
386 static void enable_service(const char *name, int ena) {
388 for (i = 0; i < ARRAY_SIZE(daemon_service); i++) {
389 if (!strcmp(daemon_service[i].name, name)) {
390 daemon_service[i].enabled = ena;
394 die("No such service %s", name);
397 static void make_service_overridable(const char *name, int ena) {
399 for (i = 0; i < ARRAY_SIZE(daemon_service); i++) {
400 if (!strcmp(daemon_service[i].name, name)) {
401 daemon_service[i].overridable = ena;
405 die("No such service %s", name);
409 * Separate the "extra args" information as supplied by the client connection.
410 * Any resulting data is squirrelled away in the given interpolation table.
412 static void parse_extra_args(struct interp *table, char *extra_args, int buflen)
416 char *end = extra_args + buflen;
418 while (extra_args < end && *extra_args) {
419 saw_extended_args = 1;
420 if (strncasecmp("host=", extra_args, 5) == 0) {
421 val = extra_args + 5;
422 vallen = strlen(val) + 1;
424 /* Split <host>:<port> at colon. */
426 char *port = strrchr(host, ':');
430 interp_set_entry(table, INTERP_SLOT_PORT, port);
432 interp_set_entry(table, INTERP_SLOT_HOST, host);
435 /* On to the next one */
436 extra_args = val + vallen;
441 void fill_in_extra_table_entries(struct interp *itable)
446 * Replace literal host with lowercase-ized hostname.
448 hp = interp_table[INTERP_SLOT_HOST].value;
453 * Locate canonical hostname and its IP address.
457 struct addrinfo hints;
458 struct addrinfo *ai, *ai0;
460 static char addrbuf[HOST_NAME_MAX + 1];
462 memset(&hints, 0, sizeof(hints));
463 hints.ai_flags = AI_CANONNAME;
465 gai = getaddrinfo(interp_table[INTERP_SLOT_HOST].value, 0, &hints, &ai0);
467 for (ai = ai0; ai; ai = ai->ai_next) {
468 struct sockaddr_in *sin_addr = (void *)ai->ai_addr;
470 inet_ntop(AF_INET, &sin_addr->sin_addr,
471 addrbuf, sizeof(addrbuf));
472 interp_set_entry(interp_table,
473 INTERP_SLOT_CANON_HOST, ai->ai_canonname);
474 interp_set_entry(interp_table,
475 INTERP_SLOT_IP, addrbuf);
483 struct hostent *hent;
484 struct sockaddr_in sa;
486 static char addrbuf[HOST_NAME_MAX + 1];
488 hent = gethostbyname(interp_table[INTERP_SLOT_HOST].value);
490 ap = hent->h_addr_list;
491 memset(&sa, 0, sizeof sa);
492 sa.sin_family = hent->h_addrtype;
493 sa.sin_port = htons(0);
494 memcpy(&sa.sin_addr, *ap, hent->h_length);
496 inet_ntop(hent->h_addrtype, &sa.sin_addr,
497 addrbuf, sizeof(addrbuf));
499 interp_set_entry(interp_table, INTERP_SLOT_CANON_HOST, hent->h_name);
500 interp_set_entry(interp_table, INTERP_SLOT_IP, addrbuf);
506 static int execute(struct sockaddr *addr)
508 static char line[1000];
512 char addrbuf[256] = "";
515 if (addr->sa_family == AF_INET) {
516 struct sockaddr_in *sin_addr = (void *) addr;
517 inet_ntop(addr->sa_family, &sin_addr->sin_addr, addrbuf, sizeof(addrbuf));
518 port = sin_addr->sin_port;
520 } else if (addr && addr->sa_family == AF_INET6) {
521 struct sockaddr_in6 *sin6_addr = (void *) addr;
524 *buf++ = '['; *buf = '\0'; /* stpcpy() is cool */
525 inet_ntop(AF_INET6, &sin6_addr->sin6_addr, buf, sizeof(addrbuf) - 1);
528 port = sin6_addr->sin6_port;
531 loginfo("Connection from %s:%d", addrbuf, port);
534 alarm(init_timeout ? init_timeout : timeout);
535 pktlen = packet_read_line(0, line, sizeof(line));
540 loginfo("Extended attributes (%d bytes) exist <%.*s>",
542 (int) pktlen - len, line + len + 1);
543 if (len && line[len-1] == '\n')
547 * Initialize the path interpolation table for this connection.
549 interp_clear_table(interp_table, ARRAY_SIZE(interp_table));
550 interp_set_entry(interp_table, INTERP_SLOT_PERCENT, "%");
553 parse_extra_args(interp_table, line + len + 1, pktlen - len - 1);
554 fill_in_extra_table_entries(interp_table);
557 for (i = 0; i < ARRAY_SIZE(daemon_service); i++) {
558 struct daemon_service *s = &(daemon_service[i]);
559 int namelen = strlen(s->name);
560 if (!strncmp("git-", line, 4) &&
561 !strncmp(s->name, line + 4, namelen) &&
562 line[namelen + 4] == ' ') {
564 * Note: The directory here is probably context sensitive,
565 * and might depend on the actual service being performed.
567 interp_set_entry(interp_table,
568 INTERP_SLOT_DIR, line + namelen + 5);
569 return run_service(interp_table, s);
573 logerror("Protocol error: '%s'", line);
579 * We count spawned/reaped separately, just to avoid any
580 * races when updating them from signals. The SIGCHLD handler
581 * will only update children_reaped, and the fork logic will
582 * only update children_spawned.
584 * MAX_CHILDREN should be a power-of-two to make the modulus
585 * operation cheap. It should also be at least twice
586 * the maximum number of connections we will ever allow.
588 #define MAX_CHILDREN 128
590 static int max_connections = 25;
592 /* These are updated by the signal handler */
593 static volatile unsigned int children_reaped;
594 static pid_t dead_child[MAX_CHILDREN];
596 /* These are updated by the main loop */
597 static unsigned int children_spawned;
598 static unsigned int children_deleted;
600 static struct child {
603 struct sockaddr_storage address;
604 } live_child[MAX_CHILDREN];
606 static void add_child(int idx, pid_t pid, struct sockaddr *addr, int addrlen)
608 live_child[idx].pid = pid;
609 live_child[idx].addrlen = addrlen;
610 memcpy(&live_child[idx].address, addr, addrlen);
614 * Walk from "deleted" to "spawned", and remove child "pid".
616 * We move everything up by one, since the new "deleted" will
619 static void remove_child(pid_t pid, unsigned deleted, unsigned spawned)
623 deleted %= MAX_CHILDREN;
624 spawned %= MAX_CHILDREN;
625 if (live_child[deleted].pid == pid) {
626 live_child[deleted].pid = -1;
629 n = live_child[deleted];
632 deleted = (deleted + 1) % MAX_CHILDREN;
633 if (deleted == spawned)
634 die("could not find dead child %d\n", pid);
635 m = live_child[deleted];
636 live_child[deleted] = n;
644 * This gets called if the number of connections grows
645 * past "max_connections".
647 * We _should_ start off by searching for connections
648 * from the same IP, and if there is some address wth
649 * multiple connections, we should kill that first.
651 * As it is, we just "randomly" kill 25% of the connections,
652 * and our pseudo-random generator sucks too. I have no
655 * Really, this is just a place-holder for a _real_ algorithm.
657 static void kill_some_children(int signo, unsigned start, unsigned stop)
659 start %= MAX_CHILDREN;
660 stop %= MAX_CHILDREN;
661 while (start != stop) {
663 kill(live_child[start].pid, signo);
664 start = (start + 1) % MAX_CHILDREN;
668 static void check_max_connections(void)
672 unsigned spawned, reaped, deleted;
674 spawned = children_spawned;
675 reaped = children_reaped;
676 deleted = children_deleted;
678 while (deleted < reaped) {
679 pid_t pid = dead_child[deleted % MAX_CHILDREN];
680 remove_child(pid, deleted, spawned);
683 children_deleted = deleted;
685 active = spawned - deleted;
686 if (active <= max_connections)
689 /* Kill some unstarted connections with SIGTERM */
690 kill_some_children(SIGTERM, deleted, spawned);
691 if (active <= max_connections << 1)
694 /* If the SIGTERM thing isn't helping use SIGKILL */
695 kill_some_children(SIGKILL, deleted, spawned);
700 static void handle(int incoming, struct sockaddr *addr, int addrlen)
711 idx = children_spawned % MAX_CHILDREN;
713 add_child(idx, pid, addr, addrlen);
715 check_max_connections();
726 static void child_handler(int signo)
730 pid_t pid = waitpid(-1, &status, WNOHANG);
733 unsigned reaped = children_reaped;
734 dead_child[reaped % MAX_CHILDREN] = pid;
735 children_reaped = reaped + 1;
736 /* XXX: Custom logging, since we don't wanna getpid() */
738 const char *dead = "";
739 if (!WIFEXITED(status) || WEXITSTATUS(status) > 0)
740 dead = " (with error)";
742 syslog(LOG_INFO, "[%d] Disconnected%s", pid, dead);
744 fprintf(stderr, "[%d] Disconnected%s\n", pid, dead);
752 static int set_reuse_addr(int sockfd)
758 return setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR,
764 static int socksetup(char *listen_addr, int listen_port, int **socklist_p)
766 int socknum = 0, *socklist = NULL;
768 char pbuf[NI_MAXSERV];
769 struct addrinfo hints, *ai0, *ai;
772 sprintf(pbuf, "%d", listen_port);
773 memset(&hints, 0, sizeof(hints));
774 hints.ai_family = AF_UNSPEC;
775 hints.ai_socktype = SOCK_STREAM;
776 hints.ai_protocol = IPPROTO_TCP;
777 hints.ai_flags = AI_PASSIVE;
779 gai = getaddrinfo(listen_addr, pbuf, &hints, &ai0);
781 die("getaddrinfo() failed: %s\n", gai_strerror(gai));
783 for (ai = ai0; ai; ai = ai->ai_next) {
786 sockfd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
789 if (sockfd >= FD_SETSIZE) {
790 error("too large socket descriptor.");
796 if (ai->ai_family == AF_INET6) {
798 setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY,
800 /* Note: error is not fatal */
804 if (set_reuse_addr(sockfd)) {
809 if (bind(sockfd, ai->ai_addr, ai->ai_addrlen) < 0) {
811 continue; /* not fatal */
813 if (listen(sockfd, 5) < 0) {
815 continue; /* not fatal */
818 socklist = xrealloc(socklist, sizeof(int) * (socknum + 1));
819 socklist[socknum++] = sockfd;
827 *socklist_p = socklist;
833 static int socksetup(char *lisen_addr, int listen_port, int **socklist_p)
835 struct sockaddr_in sin;
838 memset(&sin, 0, sizeof sin);
839 sin.sin_family = AF_INET;
840 sin.sin_port = htons(listen_port);
843 /* Well, host better be an IP address here. */
844 if (inet_pton(AF_INET, listen_addr, &sin.sin_addr.s_addr) <= 0)
847 sin.sin_addr.s_addr = htonl(INADDR_ANY);
850 sockfd = socket(AF_INET, SOCK_STREAM, 0);
854 if (set_reuse_addr(sockfd)) {
859 if ( bind(sockfd, (struct sockaddr *)&sin, sizeof sin) < 0 ) {
864 if (listen(sockfd, 5) < 0) {
869 *socklist_p = xmalloc(sizeof(int));
870 **socklist_p = sockfd;
876 static int service_loop(int socknum, int *socklist)
881 pfd = xcalloc(socknum, sizeof(struct pollfd));
883 for (i = 0; i < socknum; i++) {
884 pfd[i].fd = socklist[i];
885 pfd[i].events = POLLIN;
888 signal(SIGCHLD, child_handler);
893 if (poll(pfd, socknum, -1) < 0) {
894 if (errno != EINTR) {
895 error("poll failed, resuming: %s",
902 for (i = 0; i < socknum; i++) {
903 if (pfd[i].revents & POLLIN) {
904 struct sockaddr_storage ss;
905 unsigned int sslen = sizeof(ss);
906 int incoming = accept(pfd[i].fd, (struct sockaddr *)&ss, &sslen);
914 die("accept returned %s", strerror(errno));
917 handle(incoming, (struct sockaddr *)&ss, sslen);
923 /* if any standard file descriptor is missing open it to /dev/null */
924 static void sanitize_stdfds(void)
926 int fd = open("/dev/null", O_RDWR, 0);
927 while (fd != -1 && fd < 2)
930 die("open /dev/null or dup failed: %s", strerror(errno));
935 static void daemonize(void)
941 die("fork failed: %s", strerror(errno));
946 die("setsid failed: %s", strerror(errno));
953 static void store_pid(const char *path)
955 FILE *f = fopen(path, "w");
957 die("cannot open pid file %s: %s", path, strerror(errno));
958 fprintf(f, "%d\n", getpid());
962 static int serve(char *listen_addr, int listen_port, struct passwd *pass, gid_t gid)
964 int socknum, *socklist;
966 socknum = socksetup(listen_addr, listen_port, &socklist);
968 die("unable to allocate any listen sockets on host %s port %u",
969 listen_addr, listen_port);
972 (initgroups(pass->pw_name, gid) || setgid (gid) ||
973 setuid(pass->pw_uid)))
974 die("cannot drop privileges");
976 return service_loop(socknum, socklist);
979 int main(int argc, char **argv)
982 char *listen_addr = NULL;
984 const char *pid_file = NULL, *user_name = NULL, *group_name = NULL;
986 struct passwd *pass = NULL;
991 /* Without this we cannot rely on waitpid() to tell
992 * what happened to our children.
994 signal(SIGCHLD, SIG_DFL);
996 for (i = 1; i < argc; i++) {
999 if (!strncmp(arg, "--listen=", 9)) {
1001 char *ph = listen_addr = xmalloc(strlen(arg + 9) + 1);
1003 *ph++ = tolower(*p++);
1007 if (!strncmp(arg, "--port=", 7)) {
1010 n = strtoul(arg+7, &end, 0);
1011 if (arg[7] && !*end) {
1016 if (!strcmp(arg, "--inetd")) {
1021 if (!strcmp(arg, "--verbose")) {
1025 if (!strcmp(arg, "--syslog")) {
1029 if (!strcmp(arg, "--export-all")) {
1030 export_all_trees = 1;
1033 if (!strncmp(arg, "--timeout=", 10)) {
1034 timeout = atoi(arg+10);
1037 if (!strncmp(arg, "--init-timeout=", 15)) {
1038 init_timeout = atoi(arg+15);
1041 if (!strcmp(arg, "--strict-paths")) {
1045 if (!strncmp(arg, "--base-path=", 12)) {
1049 if (!strncmp(arg, "--interpolated-path=", 20)) {
1050 interpolated_path = arg+20;
1053 if (!strcmp(arg, "--reuseaddr")) {
1057 if (!strcmp(arg, "--user-path")) {
1061 if (!strncmp(arg, "--user-path=", 12)) {
1062 user_path = arg + 12;
1065 if (!strncmp(arg, "--pid-file=", 11)) {
1066 pid_file = arg + 11;
1069 if (!strcmp(arg, "--detach")) {
1074 if (!strncmp(arg, "--user=", 7)) {
1075 user_name = arg + 7;
1078 if (!strncmp(arg, "--group=", 8)) {
1079 group_name = arg + 8;
1082 if (!strncmp(arg, "--enable=", 9)) {
1083 enable_service(arg + 9, 1);
1086 if (!strncmp(arg, "--disable=", 10)) {
1087 enable_service(arg + 10, 0);
1090 if (!strncmp(arg, "--allow-override=", 17)) {
1091 make_service_overridable(arg + 17, 1);
1094 if (!strncmp(arg, "--forbid-override=", 18)) {
1095 make_service_overridable(arg + 18, 0);
1098 if (!strcmp(arg, "--")) {
1099 ok_paths = &argv[i+1];
1101 } else if (arg[0] != '-') {
1102 ok_paths = &argv[i];
1106 usage(daemon_usage);
1109 if (inetd_mode && (group_name || user_name))
1110 die("--user and --group are incompatible with --inetd");
1112 if (inetd_mode && (listen_port || listen_addr))
1113 die("--listen= and --port= are incompatible with --inetd");
1114 else if (listen_port == 0)
1115 listen_port = DEFAULT_GIT_PORT;
1117 if (group_name && !user_name)
1118 die("--group supplied without --user");
1121 pass = getpwnam(user_name);
1123 die("user not found - %s", user_name);
1128 group = getgrnam(group_name);
1130 die("group not found - %s", group_name);
1132 gid = group->gr_gid;
1137 openlog("git-daemon", 0, LOG_DAEMON);
1138 set_die_routine(daemon_die);
1141 if (strict_paths && (!ok_paths || !*ok_paths))
1142 die("option --strict-paths requires a whitelist");
1145 struct sockaddr_storage ss;
1146 struct sockaddr *peer = (struct sockaddr *)&ss;
1147 socklen_t slen = sizeof(ss);
1149 freopen("/dev/null", "w", stderr);
1151 if (getpeername(0, peer, &slen))
1154 return execute(peer);
1163 store_pid(pid_file);
1165 return serve(listen_addr, listen_port, pass, gid);