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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Dec 9, 2015 at 5:35 PM, Taylor Braun-Jones
<taylor@xxxxxxxxxxxxxxx> wrote:
>
> On Wed, Dec 9, 2015 at 1:24 PM, Duy Nguyen <pclouds@xxxxxxxxx> wrote:
> > On Wed, Dec 9, 2015 at 5:08 PM, Duy Nguyen <pclouds@xxxxxxxxx> wrote:
> >> On Wed, Dec 2, 2015 at 9:10 PM, Taylor Braun-Jones
> >> <taylor@xxxxxxxxxxxxxxx> wrote:
> >>> My use case it running git clone inside a docker container with
> >>> `docker run --user $(id -u):$(id -g) --volume /foo:/foo ...`. I want
> >>> all /foo/* file creation/access from inside the Docker container to be
> >>> done as the current uid/gid of the host system.
> >>>
> >>> Steps to reproduce:
> >>>
> >>> mkdir /tmp/docker-git
> >>> cat > /tmp/docker-git/Dockerfile <<EOF
> >>> FROM ubuntu
> >>> RUN apt-get update && apt-get install -y git-core
> >>> EOF
> >>> docker build -t git /tmp/docker-git/
> >>> docker run --user $(id -u):$(id -g) git git clone
> >>> https://github.com/git/git.git /tmp/git
> >>> # fatal: unable to look up current user in the passwd file: no such user
> >>
> >> It probably helps if you could get the stack trace to this message
> >> (printed from function xgetpwuid_self). I haven't checked if my
> >> personal laptop has docker to reproduce this.. In general we won't ask
> >> passwd if the user specifies name/email in the config file. But I
> >> still don't see why git-clone needs that info in the first place.
> >
> > 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.
>
> Can't git just use "unknown" and "unknown@localhost" if the name or
> email can not be determined from xgetpwuid? This seems to be the way
> that Mercurial behaves.

See attached patch for an implementation of the fallback-to-unknown
idea. With this, I'm able to clone a repository under a UID that does
not exist in /etc/passwd and do everything that I'd expect to do with
a local git repository. Is there something that I've missed?

Taylor
From dd5c2ccf5df4104e677f8488fbb4be98ff1831c7 Mon Sep 17 00:00:00 2001
From: Taylor Braun-Jones <taylor@xxxxxxxxxxxxxxx>
Date: Thu, 10 Dec 2015 13:21:25 -0500
Subject: [PATCH] Warn (not die) when unable to look up current user in the
 passwd file

---
 wrapper.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/wrapper.c b/wrapper.c
index 6fcaa4d..8119068 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -604,12 +604,26 @@ int access_or_die(const char *path, int mode, unsigned flag)
 struct passwd *xgetpwuid_self(void)
 {
 	struct passwd *pw;
+	static struct passwd pw_unknown = {0};
 
+	uid_t uid = getuid();
 	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"));
+	pw = getpwuid(uid);
+	if (!pw) {
+		warning(_("unable to look up current user in the passwd file: %s"),
+		        errno ? strerror(errno) : _("no such user"));
+		pw_unknown.pw_name = "unknown";
+		pw_unknown.pw_passwd = NULL;
+		pw_unknown.pw_uid = uid;
+		pw_unknown.pw_gid = getgid();
+		pw_unknown.pw_dir = NULL;
+		pw_unknown.pw_shell = NULL;
+ #ifndef NO_GECOS_IN_PWENT
+		pw_unknown.pw_gecos = NULL;
+ #endif
+		pw = &pw_unknown;
+	}
+
 	return pw;
 }
 
-- 
2.6.3


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]