target / lorri

Your project's nix-env
Apache License 2.0
992 stars 69 forks source link

whoami: cannot find name for user ID <user-id> #331

Closed wpcarro closed 4 years ago

wpcarro commented 4 years ago

Describe the bug

When I'm in a directory in which lorri has been initialized and I run the command whoami, it prints whoami: cannot find name for user ID and exits with a 1 status code.

To Reproduce Steps to reproduce the behavior:

  1. cd path/to/lorri/dir
  2. whoami prints error message
  3. cd path/to/non-lorri/dir
  4. whoami returns wpcarro

Expected behavior

I expect whoami to exit with a non-zero code.

Metadata

$ lorri info
lorri version: 1
Lorri Project Configuration

expression: /home/wpcarro/briefcase/shell.nix
$ uname -a
Linux seneca 5.2.17-1rodete3-amd64 #1 SMP Debian 5.2.17-1rodete3 (2019-10-21 > 2018) x86_64 GNU/Linux

Additional context

I'm not sure if this is the intended behavior of lorri. If it is, I apologize for the noise. Thank you for making this project; I'm certainly enjoying it.

curiousleo commented 4 years ago

Hi, thanks for the report!

I noticed that lorri info gives you "lorri version: 1". We've now released version 1.0 to the nixos-unstable and nixos-19.09 release channels. I don't know how you installed lorri, but if it isn't too much hassle, perhaps you could upgrade lorri and try again?

With version 1.0, I get my correct user name from whoami from within a lorri direnv directory, a lorri shell (and also nix-shell, just to be sure).

Possibly related is https://github.com/target/lorri/blob/b2f1fe218ab95ce7c89c4b35644d01c4c1f1b21d/src/ops/direnv/envrc.bash#L129

wpcarro commented 4 years ago

@curiousleo - thank you for responding.

I'm using a computer with lorri version: 1.0, and whoami still returns an error.


lorri version: 1.0
gc roots exist, shell_gc_root: "/home/wpcarro/.cache/lorri/gc_roots/2a79f5b753b5de1aecbeba294ec5c3e7/gc_
root/shell_gc_root"```
wpcarro commented 4 years ago

Inside of a directory that lorri manages:

> which whoami
/nix/store/d7hlkykjjqs3f200jnmjm1y2hzgvbqa8-coreutils-8.31/bin/whoami
> whoami
whoami: cannot find name for user ID 646587

Outside of this directory:

> which whoami
/usr/bin/whoami
> whoami
wpcarro

Can you think of any workarounds? This is breaking some functions in my editor that depend on whoami working.

Profpatsch commented 4 years ago

When I strace whoami:

connect(3, {sa_family=AF_UNIX, sun_path="/var/run/nscd/socket"}, 110) = 0
sendto(3, "\2\0\0\0\v\0\0\0\7\0\0\0passwd\0", 19, MSG_NOSIGNAL, NULL, 0) = 19
poll([{fd=3, events=POLLIN|POLLERR|POLLHUP}], 1, 5000) = 1 ([{fd=3, revents=POLLIN|POLLHUP}])
recvmsg(3, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="passwd\0", iov_len=7}, {iov_base="\310O\3\0\0\0\0\0", iov_len=8}], msg_iovlen=2, msg_control=[{cmsg_len=20, cmsg_level=SOL_SOCKET, cmsg_type=SCM_RIGHTS, cmsg_data=[4]}], msg_controllen=20, msg_flags=MSG_CMSG_CLOEXEC}, MSG_CMSG_CLOEXEC) = 15
mmap(NULL, 217032, PROT_READ, MAP_SHARED, 4, 0) = 0x7fa22358c000
close(4)                                = 0
close(3)                                = 0
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0x9), ...}) = 0
write(1, "philip\n", 7philip

So it’s querying the socket of ncsd (instead of opening passwd directly). Does it do the same on your Debian system?

Profpatsch commented 4 years ago

Ping

wpcarro commented 4 years ago

@Profpatsch - Sorry for the delay. Looks like whoami attempts to read from nscd, but fails.

connect(3, {sa_family=AF_UNIX, sun_path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory)
close(3)                                = 0
socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 3
connect(3, {sa_family=AF_UNIX, sun_path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory)
close(3)                                = 0
openat(AT_FDCWD, "/etc/nsswitch.conf", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=396, ...}) = 0
read(3, "# $Id: //depot/google3/googledat"..., 4096) = 396
read(3, "", 4096)                       = 0
close(3)                                = 0
Profpatsch commented 4 years ago

openat(AT_FDCWD, "/etc/nsswitch.conf", O_RDONLY|O_CLOEXEC) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=396, ...}) = 0 read(3, "# $Id: //depot/google3/googledat"..., 4096) = 396

Now it really depends on how nsswitch (man nsswitch.conf) is configured in the Google distribution. cc @tazjin maybe‽ idk.

tazjin commented 4 years ago

This is likely not an issue with lorri. I'll talk to @wpcarro on work chat.

Profpatsch commented 4 years ago

Cool, closing.

Profpatsch commented 4 years ago

Also wtf, why is the Google distro uname -a lying that it’s Debian?