git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git-clone fails when current user is not in /etc/passwd

From
Taylor Braun-Jones <taylor@braun-jones.org>
Date
Dec 10, 2015, 18:52 UTC
Message-ID
<CAKfKJYt__uD_=E=NBxsVSbv6TO4E7-GvsCdFnSuPPv8n-owhJA@mail.gmail.com>
In-Reply-To
<xmqqoadyi1q2.fsf@gitster.mtv.corp.google.com>
On Thu, Dec 10, 2015 at 1:43 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 81 quoted lines
> 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;
>  }
>
Yes, this looks better.
+1
Previous: Junio C Hamano
Message 20 of 20 in “git-clone fails when current user is not in /etc/passwd”
  1. Taylor Braun-JonesDec 2, 2015
  2. Taylor Braun-JonesDec 9, 2015
  3. Duy NguyenDec 9, 2015
  4. Duy NguyenDec 9, 2015
  5. Taylor Braun-JonesDec 9, 2015
  6. Taylor Braun-JonesDec 10, 2015
  7. Jeff KingDec 10, 2015
  8. Junio C HamanoDec 10, 2015
  9. Jeff KingDec 10, 2015
  10. 0/3 git-clone fails when current user is not in /etc/passwdJeff King, Dec 10, 2015
  11. 1/3 ident: make xgetpwuid_self() a static local helperJeff King, Dec 10, 2015
  12. Junio C HamanoDec 10, 2015
  13. 2/3 ident: keep a flag for bogus default_emailJeff King, Dec 10, 2015
  14. Jeff KingDec 10, 2015
  15. 3/3 ident: loosen getpwuid error in non-strict modeJeff King, Dec 10, 2015
  16. Jeff KingDec 14, 2015
  17. Junio C HamanoDec 10, 2015
  18. Taylor Braun-JonesDec 11, 2015
  19. Junio C HamanoDec 10, 2015
  20. Taylor Braun-JonesDec 10, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.