Merge branch 'jk/ident-loosen-getpwuid'
authorJunio C Hamano <gitster@pobox.com>
Mon, 21 Dec 2015 18:59:07 +0000 (10:59 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 21 Dec 2015 18:59:07 +0000 (10:59 -0800)
When getpwuid() on the system returned NULL (e.g. the user is not
in the /etc/passwd file or other uid-to-name mappings), the
codepath to find who the user is to record it in the reflog barfed
and died. Loosen the check in this codepath, which already accepts
questionable ident string (e.g. host part of the e-mail address is
obviously bogus), and in general when we operate fmt_ident() function
in non-strict mode.

* jk/ident-loosen-getpwuid:
ident: loosen getpwuid error in non-strict mode
ident: keep a flag for bogus default_email
ident: make xgetpwuid_self() a static local helper

1  2 
git-compat-util.h
ident.c
wrapper.c
Simple merge
diff --cc ident.c
index 00a62e0c4276fb8889a0b158c9e71a22e3be092c,bb1b1743526446bac21abe7da28b15837c8185dc..daf7e1ea8370e5b6a60c5a33a1591ef939655664
+++ b/ident.c
@@@ -70,35 -91,10 +91,35 @@@ static int add_mailname_host(struct str
        return 0;
  }
  
- static void add_domainname(struct strbuf *out)
 +static int canonical_name(const char *host, struct strbuf *out)
 +{
 +      int status = -1;
 +
 +#ifndef NO_IPV6
 +      struct addrinfo hints, *ai;
 +      memset (&hints, '\0', sizeof (hints));
 +      hints.ai_flags = AI_CANONNAME;
 +      if (!getaddrinfo(host, NULL, &hints, &ai)) {
 +              if (ai && strchr(ai->ai_canonname, '.')) {
 +                      strbuf_addstr(out, ai->ai_canonname);
 +                      status = 0;
 +              }
 +              freeaddrinfo(ai);
 +      }
 +#else
 +      struct hostent *he = gethostbyname(host);
 +      if (he && strchr(he->h_name, '.')) {
 +              strbuf_addstr(out, he->h_name);
 +              status = 0;
 +      }
 +#endif /* NO_IPV6 */
 +
 +      return status;
 +}
 +
+ static void add_domainname(struct strbuf *out, int *is_bogus)
  {
        char buf[1024];
 -      struct hostent *he;
  
        if (gethostname(buf, sizeof(buf))) {
                warning("cannot get host name: %s", strerror(errno));
        }
        if (strchr(buf, '.'))
                strbuf_addstr(out, buf);
-       else if (canonical_name(buf, out) < 0)
 -      else if ((he = gethostbyname(buf)) && strchr(he->h_name, '.'))
 -              strbuf_addstr(out, he->h_name);
 -      else {
++      else if (canonical_name(buf, out) < 0) {
                strbuf_addf(out, "%s.(none)", buf);
+               *is_bogus = 1;
+       }
  }
  
- static void copy_email(const struct passwd *pw, struct strbuf *email)
+ static void copy_email(const struct passwd *pw, struct strbuf *email,
+                      int *is_bogus)
  {
        /*
         * Make up a fake email address
diff --cc wrapper.c
Simple merge