--user and --detach are disabled on Windows due to lack of fork(), setuid(), setgid(), setsid() and initgroups(). Signed-off-by: Erik Faye-Lund <kusmabite@xxxxxxxxx> --- Makefile | 6 +++--- compat/mingw.h | 1 + daemon.c | 19 ++++++++++++++----- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 3b01694..406ca81 100644 --- a/Makefile +++ b/Makefile @@ -352,6 +352,7 @@ EXTRA_PROGRAMS = # ... and all the rest that could be moved out of bindir to gitexecdir PROGRAMS += $(EXTRA_PROGRAMS) +PROGRAMS += git-daemon$X PROGRAMS += git-fast-import$X PROGRAMS += git-hash-object$X PROGRAMS += git-imap-send$X @@ -981,6 +982,8 @@ ifneq (,$(findstring MINGW,$(uname_S))) OBJECT_CREATION_USES_RENAMES = UnfortunatelyNeedsTo NO_REGEX = YesPlease BLK_SHA1 = YesPlease + NO_INET_PTON = YesPlease + NO_INET_NTOP = YesPlease COMPAT_CFLAGS += -D__USE_MINGW_ACCESS -DNOGDI -Icompat -Icompat/fnmatch COMPAT_CFLAGS += -DSTRIP_EXTENSION=\".exe\" # We have GCC, so let's make use of those nice options @@ -1079,9 +1082,6 @@ ifdef ZLIB_PATH endif EXTLIBS += -lz -ifndef NO_POSIX_ONLY_PROGRAMS - PROGRAMS += git-daemon$X -endif ifndef NO_OPENSSL OPENSSL_LIBSSL = -lssl ifdef OPENSSLDIR diff --git a/compat/mingw.h b/compat/mingw.h index 576b1a1..1b0dd5b 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -6,6 +6,7 @@ typedef int pid_t; typedef int socklen_t; +typedef unsigned int gid_t; #define hstrerror strerror #define S_IFLNK 0120000 /* Symbolic link */ diff --git a/daemon.c b/daemon.c index 130e951..5872ec7 100644 --- a/daemon.c +++ b/daemon.c @@ -616,7 +616,7 @@ static struct child { struct sockaddr_storage address; } *firstborn; -static void add_child(struct async *async, struct sockaddr *addr, int addrlen) +static void add_child(struct async *async, struct sockaddr *addr, socklen_t addrlen) { struct child *newborn, **cradle; @@ -679,7 +679,7 @@ int async_execute(int fd, void *data) return ret; } -static void handle(int incoming, struct sockaddr *addr, int addrlen) +static void handle(int incoming, struct sockaddr *addr, socklen_t addrlen) { struct sockaddr_storage *ss; struct async async = { 0 }; @@ -884,7 +884,7 @@ static int service_loop(int socknum, int *socklist) for (i = 0; i < socknum; i++) { if (pfd[i].revents & POLLIN) { struct sockaddr_storage ss; - unsigned int sslen = sizeof(ss); + socklen_t sslen = sizeof(ss); int incoming = accept(pfd[i].fd, (struct sockaddr *)&ss, &sslen); if (incoming < 0) { switch (errno) { @@ -916,6 +916,7 @@ static void sanitize_stdfds(void) static void daemonize(void) { +#ifndef WIN32 switch (fork()) { case 0: break; @@ -930,6 +931,9 @@ static void daemonize(void) close(1); close(2); sanitize_stdfds(); +#else + die("--detach is not supported on Windows"); +#endif } static void store_pid(const char *path) @@ -950,10 +954,12 @@ static int serve(char *listen_addr, int listen_port, struct passwd *pass, gid_t die("unable to allocate any listen sockets on host %s port %u", listen_addr, listen_port); +#ifndef WIN32 if (pass && gid && (initgroups(pass->pw_name, gid) || setgid (gid) || setuid(pass->pw_uid))) die("cannot drop privileges"); +#endif return service_loop(socknum, socklist); } @@ -966,7 +972,6 @@ int main(int argc, char **argv) const char *pid_file = NULL, *user_name = NULL, *group_name = NULL; int detach = 0; struct passwd *pass = NULL; - struct group *group; gid_t gid = 0; int i; @@ -1110,6 +1115,7 @@ int main(int argc, char **argv) die("--group supplied without --user"); if (user_name) { +#ifndef WIN32 pass = getpwnam(user_name); if (!pass) die("user not found - %s", user_name); @@ -1117,12 +1123,15 @@ int main(int argc, char **argv) if (!group_name) gid = pass->pw_gid; else { - group = getgrnam(group_name); + struct group *group = getgrnam(group_name); if (!group) die("group not found - %s", group_name); gid = group->gr_gid; } +#else + die("--user is not supported on Windows"); +#endif } if (strict_paths && (!ok_paths || !*ok_paths)) -- 1.6.5.rc2.7.g4f8d3 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html