ident: use full dns names to generate email addresses
[gitweb.git] / ident.c
diff --git a/ident.c b/ident.c
index 73a06a11fa22d5901fd17f2fa76b66f59c96742f..b111e34140656545bf4484aa5428d6e39ca4a7d1 100644 (file)
--- a/ident.c
+++ b/ident.c
@@ -65,23 +65,18 @@ static void add_domainname(struct strbuf *out)
 {
        char buf[1024];
        struct hostent *he;
-       const char *domainname;
 
        if (gethostname(buf, sizeof(buf))) {
                warning("cannot get host name: %s", strerror(errno));
                strbuf_addstr(out, "(none)");
                return;
        }
-       strbuf_addstr(out, buf);
        if (strchr(buf, '.'))
-               return;
-
-       he = gethostbyname(buf);
-       strbuf_addch(out, '.');
-       if (he && (domainname = strchr(he->h_name, '.')))
-               strbuf_addstr(out, domainname + 1);
+               strbuf_addstr(out, buf);
+       else if ((he = gethostbyname(buf)) && strchr(he->h_name, '.'))
+               strbuf_addstr(out, he->h_name);
        else
-               strbuf_addstr(out, "(none)");
+               strbuf_addf(out, "%s.(none)", buf);
 }
 
 static void copy_email(const struct passwd *pw, struct strbuf *email)
@@ -100,12 +95,8 @@ static void copy_email(const struct passwd *pw, struct strbuf *email)
 
 const char *ident_default_name(void)
 {
-       if (!git_default_name.len) {
-               struct passwd *pw = getpwuid(getuid());
-               if (!pw)
-                       die("You don't exist. Go away!");
-               copy_gecos(pw, &git_default_name);
-       }
+       if (!git_default_name.len)
+               copy_gecos(xgetpwuid_self(), &git_default_name);
        return git_default_name.buf;
 }
 
@@ -117,12 +108,8 @@ const char *ident_default_email(void)
                if (email && email[0]) {
                        strbuf_addstr(&git_default_email, email);
                        user_ident_explicitly_given |= IDENT_MAIL_GIVEN;
-               } else {
-                       struct passwd *pw = getpwuid(getuid());
-                       if (!pw)
-                               die("You don't exist. Go away!");
-                       copy_email(pw, &git_default_email);
-               }
+               } else
+                       copy_email(xgetpwuid_self(), &git_default_email);
        }
        return git_default_email.buf;
 }
@@ -303,9 +290,7 @@ const char *fmt_ident(const char *name, const char *email,
                                fputs(env_hint, stderr);
                        die("empty ident %s <%s> not allowed", name, email);
                }
-               pw = getpwuid(getuid());
-               if (!pw)
-                       die("You don't exist. Go away!");
+               pw = xgetpwuid_self();
                name = pw->pw_name;
        }