From: Junio C Hamano Date: Mon, 25 Mar 2013 20:45:42 +0000 (-0700) Subject: Merge branch 'dm/ni-maxhost-may-be-missing' into maint-1.8.1 X-Git-Tag: v1.8.1.6~22 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/2b0dda53189d3829e58187ee91143b35036573fb?ds=inline;hp=-c Merge branch 'dm/ni-maxhost-may-be-missing' into maint-1.8.1 Some sources failed to compile on systems that lack NI_MAXHOST in their system header. * dm/ni-maxhost-may-be-missing: git-compat-util.h: Provide missing netdb.h definitions --- 2b0dda53189d3829e58187ee91143b35036573fb diff --combined daemon.c index 4602b46a5c,34d95c1674..df8c0ab058 --- a/daemon.c +++ b/daemon.c @@@ -9,10 -9,6 +9,6 @@@ #define HOST_NAME_MAX 256 #endif - #ifndef NI_MAXSERV - #define NI_MAXSERV 32 - #endif - #ifdef NO_INITGROUPS #define initgroups(x, y) (0) /* nothing */ #endif @@@ -30,7 -26,6 +26,7 @@@ static const char daemon_usage[] " [--interpolated-path=]\n" " [--reuseaddr] [--pid-file=]\n" " [--(enable|disable|allow-override|forbid-override)=]\n" +" [--access-hook=]\n" " [--inetd | [--listen=] [--port=]\n" " [--detach] [--user= [--group=]]\n" " [...]"; @@@ -257,71 -252,6 +253,71 @@@ static int daemon_error(const char *dir return -1; } +static char *access_hook; + +static int run_access_hook(struct daemon_service *service, const char *dir, const char *path) +{ + struct child_process child; + struct strbuf buf = STRBUF_INIT; + const char *argv[8]; + const char **arg = argv; + char *eol; + int seen_errors = 0; + +#define STRARG(x) ((x) ? (x) : "") + *arg++ = access_hook; + *arg++ = service->name; + *arg++ = path; + *arg++ = STRARG(hostname); + *arg++ = STRARG(canon_hostname); + *arg++ = STRARG(ip_address); + *arg++ = STRARG(tcp_port); + *arg = NULL; +#undef STRARG + + memset(&child, 0, sizeof(child)); + child.use_shell = 1; + child.argv = argv; + child.no_stdin = 1; + child.no_stderr = 1; + child.out = -1; + if (start_command(&child)) { + logerror("daemon access hook '%s' failed to start", + access_hook); + goto error_return; + } + if (strbuf_read(&buf, child.out, 0) < 0) { + logerror("failed to read from pipe to daemon access hook '%s'", + access_hook); + strbuf_reset(&buf); + seen_errors = 1; + } + if (close(child.out) < 0) { + logerror("failed to close pipe to daemon access hook '%s'", + access_hook); + seen_errors = 1; + } + if (finish_command(&child)) + seen_errors = 1; + + if (!seen_errors) { + strbuf_release(&buf); + return 0; + } + +error_return: + strbuf_ltrim(&buf); + if (!buf.len) + strbuf_addstr(&buf, "service rejected"); + eol = strchr(buf.buf, '\n'); + if (eol) + *eol = '\0'; + errno = EACCES; + daemon_error(dir, buf.buf); + strbuf_release(&buf); + return -1; +} + static int run_service(char *dir, struct daemon_service *service) { const char *path; @@@ -369,13 -299,6 +365,13 @@@ return daemon_error(dir, "service not enabled"); } + /* + * Optionally, a hook can choose to deny access to the + * repository depending on the phase of the moon. + */ + if (access_hook && run_access_hook(service, dir, path)) + return -1; + /* * We'll ignore SIGTERM from now on, we have a * good client. @@@ -1215,10 -1138,6 +1211,10 @@@ int main(int argc, char **argv export_all_trees = 1; continue; } + if (!prefixcmp(arg, "--access-hook=")) { + access_hook = arg + 14; + continue; + } if (!prefixcmp(arg, "--timeout=")) { timeout = atoi(arg+10); continue; diff --combined git-compat-util.h index 590d5d3188,503282c863..9c01e9bc2e --- a/git-compat-util.h +++ b/git-compat-util.h @@@ -74,8 -74,7 +74,8 @@@ # define _XOPEN_SOURCE 500 # endif #elif !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__USLC__) && \ - !defined(_M_UNIX) && !defined(__sgi) && !defined(__DragonFly__) + !defined(_M_UNIX) && !defined(__sgi) && !defined(__DragonFly__) && \ + !defined(__TANDEM) #define _XOPEN_SOURCE 600 /* glibc2 and AIX 5.3L need 500, OpenBSD needs 600 for S_ISLNK() */ #define _XOPEN_SOURCE_EXTENDED 1 /* AIX 5.3L needs this */ #endif @@@ -99,9 -98,6 +99,9 @@@ #include #include #include +#ifdef __TANDEM /* or HAVE_STRINGS_H or !NO_STRINGS_H? */ +#include /* for strcasecmp() */ +#endif #include #include #include @@@ -145,17 -141,6 +145,17 @@@ #else #include #endif +#ifdef NO_INTPTR_T +/* + * On I16LP32, ILP32 and LP64 "long" is the save bet, however + * on LLP86, IL33LLP64 and P64 it needs to be "long long", + * while on IP16 and IP16L32 it is "int" (resp. "short") + * Size needs to match (or exceed) 'sizeof(void *)'. + * We can't take "long long" here as not everybody has it. + */ +typedef long intptr_t; +typedef unsigned long uintptr_t; +#endif #if defined(__CYGWIN__) #undef _XOPEN_SOURCE #include @@@ -177,22 -162,6 +177,22 @@@ #define probe_utf8_pathname_composition(a,b) #endif +#ifdef MKDIR_WO_TRAILING_SLASH +#define mkdir(a,b) compat_mkdir_wo_trailing_slash((a),(b)) +extern int compat_mkdir_wo_trailing_slash(const char*, mode_t); +#endif + +#ifdef NO_STRUCT_ITIMERVAL +struct itimerval { + struct timeval it_interval; + struct timeval it_value; +} +#endif + +#ifdef NO_SETITIMER +#define setitimer(which,value,ovalue) +#endif + #ifndef NO_LIBGEN_H #include #else @@@ -209,6 -178,17 +209,17 @@@ extern char *gitbasename(char *) #include #endif + /* On most systems would have given us this, but + * not on some systems (e.g. z/OS). + */ + #ifndef NI_MAXHOST + #define NI_MAXHOST 1025 + #endif + + #ifndef NI_MAXSERV + #define NI_MAXSERV 32 + #endif + /* On most systems would have given us this, but * not on some systems (e.g. GNU/Hurd). */ @@@ -506,7 -486,6 +517,7 @@@ extern const char tolower_trans_tbl[256 #undef isdigit #undef isalpha #undef isalnum +#undef isprint #undef islower #undef isupper #undef tolower @@@ -524,7 -503,6 +535,7 @@@ extern unsigned char sane_ctype[256] #define isdigit(x) sane_istest(x,GIT_DIGIT) #define isalpha(x) sane_istest(x,GIT_ALPHA) #define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT) +#define isprint(x) ((x) >= 0x20 && (x) <= 0x7e) #define islower(x) sane_iscase(x, 1) #define isupper(x) sane_iscase(x, 0) #define is_glob_special(x) sane_istest(x,GIT_GLOB_SPECIAL) @@@ -637,12 -615,8 +648,12 @@@ int rmdir_or_warn(const char *path) */ int remove_or_warn(unsigned int mode, const char *path); -/* Call access(2), but warn for any error besides ENOENT. */ +/* + * Call access(2), but warn for any error except "missing file" + * (ENOENT or ENOTDIR). + */ int access_or_warn(const char *path, int mode); +int access_or_die(const char *path, int mode); /* Warn on an inaccessible file that ought to be accessible */ void warn_on_inaccessible(const char *path);