Merge branch 'dm/ni-maxhost-may-be-missing' into maint-1.8.1
authorJunio C Hamano <gitster@pobox.com>
Mon, 25 Mar 2013 20:45:42 +0000 (13:45 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 25 Mar 2013 20:45:42 +0000 (13:45 -0700)
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

1  2 
daemon.c
git-compat-util.h
diff --combined daemon.c
index 4602b46a5c39e1d501143ab4e95b55aff5c8f23b,34d95c1674930aa6ea429f7ee9173c239aae6bd5..df8c0ab0588e70ad6e6f56195535030055782d85
+++ 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=<path>]\n"
  "           [--reuseaddr] [--pid-file=<file>]\n"
  "           [--(enable|disable|allow-override|forbid-override)=<service>]\n"
 +"           [--access-hook=<path>]\n"
  "           [--inetd | [--listen=<host_or_ipaddr>] [--port=<n>]\n"
  "                      [--detach] [--user=<user> [--group=<group>]]\n"
  "           [<directory>...]";
@@@ -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;
                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 590d5d3188aed8f3a2b0b7050f2502b28cb4f5fa,503282c863965bf54f6013b34a4a8d55e34c4932..9c01e9bc2eaaa9fe302228263bcc0e1e5e9196f8
@@@ -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 <stdlib.h>
  #include <stdarg.h>
  #include <string.h>
 +#ifdef __TANDEM /* or HAVE_STRINGS_H or !NO_STRINGS_H? */
 +#include <strings.h> /* for strcasecmp() */
 +#endif
  #include <errno.h>
  #include <limits.h>
  #include <sys/param.h>
  #else
  #include <stdint.h>
  #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 <grp.h>
  #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 <libgen.h>
  #else
@@@ -209,6 -178,17 +209,17 @@@ extern char *gitbasename(char *)
  #include <openssl/err.h>
  #endif
  
+ /* On most systems <netdb.h> 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 <limits.h> 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);