git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Duy Nguyen <pclouds@gmail.com>
Cc: Taylor Braun-Jones <taylor@braun-jones.org>,
	Git Mailing List <git@vger.kernel.org>
Subject: Re: git-clone fails when current user is not in /etc/passwd
Date: Thu, 10 Dec 2015 10:43:17 -0800	[thread overview]
Message-ID: <xmqqoadyi1q2.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <CACsJy8Dc3Lsqa2zccoqH7UkDitqDbOTX3EXsUCcN9OHY=LfaKw@mail.gmail.com> (Duy Nguyen's message of "Wed, 9 Dec 2015 19:24:13 +0100")

Duy Nguyen <pclouds@gmail.com> writes:

> Well.. reflog needs it. So either you disable reflog at clone time or
> define name/email via config file. I don't see anything wrong with
> this behavior.

Hmm, I am not quite sure about that.

In the codepath that computes ident_default_email(), which is one
half of what the "reflog" code you cite wants to do, copy_email()
calls copy_email() which in turn calls add_domainname().  If your
getpwuid() gave you some username, but your gethostname() gave you a
NULL, we do not barf but add "(none)" as and then issue a warning.

Perhaps we can do the same by returning a structure with members set
to a set of fake values.  Because we already have checks in places
that really matter to the recorded history (read: not reflog) in the
form of *_ident_sufficiently_given() functions, potential damage due
to having phoney names returned from here would not be too bad.

Totally untested...

 ident.c   | 13 ++++++++++---
 wrapper.c |  4 ----
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/ident.c b/ident.c
index 4e7f99d..2ccae2c 100644
--- a/ident.c
+++ b/ident.c
@@ -31,7 +31,7 @@ static void copy_gecos(const struct passwd *w, struct strbuf *name)
 	 * with commas.  Also & stands for capitalized form of the login name.
 	 */
 
-	for (src = get_gecos(w); *src && *src != ','; src++) {
+	for (src = w ? get_gecos(w) : "&"; *src && *src != ','; src++) {
 		int ch = *src;
 		if (ch != '&')
 			strbuf_addch(name, ch);
@@ -117,7 +117,7 @@ static void copy_email(const struct passwd *pw, struct strbuf *email)
 	 * Make up a fake email address
 	 * (name + '@' + hostname [+ '.' + domainname])
 	 */
-	strbuf_addstr(email, pw->pw_name);
+	strbuf_addstr(email, pw ? pw->pw_name : "unknown");
 	strbuf_addch(email, '@');
 
 	if (!add_mailname_host(email))
@@ -332,8 +332,15 @@ const char *fmt_ident(const char *name, const char *email,
 				fputs(env_hint, stderr);
 			die("empty ident name (for <%s>) not allowed", email);
 		}
+		errno = 0;
 		pw = xgetpwuid_self();
-		name = pw->pw_name;
+		if (!pw) {
+			warning(_("unable to look up current user: %s"),
+				errno ? strerror(errno) : _("no such user"));
+			name = "unknown";
+		} else {
+			name = pw->pw_name;
+		}
 	}
 
 	if (strict && email == git_default_email.buf &&
diff --git a/wrapper.c b/wrapper.c
index 6fcaa4d..16ab45f 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -605,11 +605,7 @@ struct passwd *xgetpwuid_self(void)
 {
 	struct passwd *pw;
 
-	errno = 0;
 	pw = getpwuid(getuid());
-	if (!pw)
-		die(_("unable to look up current user in the passwd file: %s"),
-		    errno ? strerror(errno) : _("no such user"));
 	return pw;
 }
 

  parent reply	other threads:[~2015-12-10 18:43 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-02 20:10 git-clone fails when current user is not in /etc/passwd Taylor Braun-Jones
2015-12-09 15:23 ` Taylor Braun-Jones
2015-12-09 16:08 ` Duy Nguyen
2015-12-09 18:24   ` Duy Nguyen
2015-12-09 22:35     ` Taylor Braun-Jones
2015-12-10 18:33       ` Taylor Braun-Jones
2015-12-10 18:34       ` Jeff King
2015-12-10 19:57         ` Junio C Hamano
2015-12-10 20:40           ` Jeff King
2015-12-10 21:32             ` [PATCH 0/3] " Jeff King
2015-12-10 21:33               ` [PATCH 1/3] ident: make xgetpwuid_self() a static local helper Jeff King
2015-12-10 23:39                 ` Junio C Hamano
2015-12-10 21:35               ` [PATCH 2/3] ident: keep a flag for bogus default_email Jeff King
2015-12-10 22:54                 ` Jeff King
2015-12-10 21:41               ` [PATCH 3/3] ident: loosen getpwuid error in non-strict mode Jeff King
2015-12-14 15:07                 ` Jeff King
2015-12-10 23:44               ` [PATCH 0/3] git-clone fails when current user is not in /etc/passwd Junio C Hamano
2015-12-11  2:20               ` Taylor Braun-Jones
2015-12-10 18:43     ` Junio C Hamano [this message]
2015-12-10 18:52       ` Taylor Braun-Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqoadyi1q2.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=pclouds@gmail.com \
    --cc=taylor@braun-jones.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).