Solved "chown nobody" not working

Since some time back, not sure when it began, my 9.2-RELEASE-p12 amd64 server's periodic/weekly output has said:

Code:
Rebuilding locate database:
chown: nobody: illegal user name
su: unknown login: nobody

This comes from /etc/periodic/weekly/310.locate which tries to chown the locate database to nobody:
Code:
[root@aknot /etc]# grep nobody /etc/periodic/weekly/310.locate 
	chown nobody $locdb || rc=3
	echo /usr/libexec/locate.updatedb | nice -n 5 su -fm nobody || rc=3

When I started investigating, I noticed I can not even chown an arbitrary file to nobody:
Code:
[root@aknot /tmp]# touch /tmp/myfile
[root@aknot /tmp]# chown nobody /tmp/myfile
chown: nobody: illegal user name

As far as I can see, the nobody user exists:
Code:
[root@aknot /etc]# grep nobody /etc/passwd /etc/group 
/etc/passwd:nobody:*:65534:65534:Unprivileged user:/nonexistent:/usr/sbin/nologin
/etc/group:nobody:*:65534:
and /nonexistent is just that, nonexistent:
Code:
[root@aknot /etc]# ls -l /nonexistent
ls: /nonexistent: No such file or directory

The locate.database, the target of the periodic script, exists and is owned by 65534 (it's possible to chown anything to numerical uid 65534), but as demonstrated, I can't use the nobody name with chown.
Code:
[root@aknot /var/db]# ls -l /var/db/locate.database 
-r--r--r--  1 65534  wheel  16313969 Oct  5 22:49 /var/db/locate.database

What can be the cause for this?
 
Re: "chown nobody" not working

Some digging done in /usr/src/usr.sbin/chown/chown.c:

Code:
uid_t
id(const char *name, const char *type)
{
        uid_t val;
        char *ep;
                        
        /*
         * XXX
         * We know that uid_t's and gid_t's are unsigned longs.
         */
        errno = 0;
        val = strtoul(name, &ep, 10);
        if (errno || *ep != '\0')
                errx(1, "%s: illegal %s name", name, type);
        return (val);
}

The const char *name input here is actually "nobody" when chown is called as above, not the uid, so the strtoul operation fails, obviously. If I read this correctly, it's supposed to be the numeric uid at this point?
 
Re: "chown nobody" not working

Follow up: the getpwnam operation in a_uid() failed for "nobody".

On a whim, I tried using vipw to manually rewrite the nobody line in /etc/passwd, writing it exactly like it already existed. The original line had no trailing whitespace, nothing strange at all to the naked eye, but now chown nobody works again. :beer grin

But still a bit worrying: who messed up my nobody entry in passwd?
 
There might not have been an issue with /etc/passwd. Opening vipw and saving might have forced a refresh of /etc/pwd.db and /etc/spwd.db and that might have been what fixed the problem.
 
ag74 said:
Sounds reasonable. Under what circumstances does pwd.db break?
Not sure why but it does happen sometimes. It just gets out of sync with /etc/passwd.
 
Back
Top