]> xenbits.xensource.com Git - libvirt.git/commit
util: Don't fail virGetUserIDByName when user not found
authorChristophe Fergeau <cfergeau@redhat.com>
Wed, 5 Dec 2012 10:21:10 +0000 (11:21 +0100)
committerChristophe Fergeau <cfergeau@redhat.com>
Thu, 6 Dec 2012 16:21:54 +0000 (17:21 +0100)
commit6c6c03dc0e66db400beacc4453efa6e10ec08260
treedd36314c17f941adc94c484b642c81de0b5914e8
parentff33f807739dc2950e4df8c1d4007ce9f8b290c0
util: Don't fail virGetUserIDByName when user not found

virGetUserIDByName is documented as returning 1 if the username
cannot be found. getpwnam_r is documented as returning:
« 0 or ENOENT or ESRCH or EBADF or EPERM or ...  The given name
or uid was not found. »
 and that:
« The formulation given above under "RETURN VALUE" is from POSIX.1-2001.
It  does  not  call  "not  found"  an error, hence does not specify what
value errno might have in this situation.  But that makes it impossible to
recognize errors.  One might argue that according to POSIX errno should be
left unchanged if an entry is not found.  Experiments on various UNIX-like
systems shows that lots of different values occur in this situation: 0,
ENOENT, EBADF, ESRCH, EWOULDBLOCK, EPERM and probably others. »

virGetUserIDByName returns an error when the return value of getpwnam_r
is non-0. However on my RHEL system, getpwnam_r returns ENOENT when the
requested user cannot be found, which then causes virGetUserID not
to behave as documented (it returns an error instead of falling back
to parsing the passed-in value as an uid).

This commit makes virGetUserIDByName only report an error when errno
is set to one of the values in the posix description of getpwnam_r
(which are the same as the ones described in the manpage on my system).
src/util/util.c