Subject: bin/37288: su fails if home on nfs without root privileges
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org>
From: None <arto.huusko@pp2.inet.fi>
List: netbsd-bugs
Date: 11/06/2007 09:55:00
>Number:         37288
>Category:       bin
>Synopsis:       su fails if home on nfs without root privileges
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Nov 06 09:55:00 +0000 2007
>Originator:     Arto Huusko
>Release:        4.99.34
>Organization:
>Environment:
NetBSD wmli019400.local 4.99.34 NetBSD 4.99.34 (DUUNI) #33: Mon Nov  5 12:34:59 EET 2007
>Description:
su fails with output

su: no directory

when home directory of the target user is on an NFS mount, and the NFS server does not grant special privileges for root user of NFS clients.

This is because su apparently does the chdir to target user's home directory as root.

Amusing (not) effects of this are, for example, that user can't su to self, root can't su to the user, etc.
>How-To-Repeat:
$ whoami
huuskart
$ pwd
/koti/home/huuskart
$ ls -ld .
drwx------  51 huuskart  medi  4096 Nov  6 11:41 .
$ mount
...
nfsserver:/home on /koti/home type nfs
...
$ su - huuskart
su: no directory
$ su -     
Password:
# cd /koti/home/huuskart/
cd: can't cd to /koti/home/huuskart/
# su - huuskart
su: no directory

>Fix:
Change su to do the chdir to target user's home directory as the target user, not root.

It would not hurt to change the no directory error report to use err() instead of errx() so that reason of the error is also shown.