Improve handling of getpwnam_r() and getgrnam_r()

ERANGE from above functions are now correctly handled. Error is
correctly returned back (instead of using errno what is nonsense for
reentrant functions). Existence of user/group is now correctly
handled. Also numerical uid/gid works as expected.

Backport of 52f88d04eaf2ad6c65df34a3401417d0583c6a45,
005e7fd3b9de79bc32894f9f15431a7cf32a3b27 and
86b074dc1a72f9696ab5a3d302c7719b2961d8d6 from master

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Reviewed-by: Fabio M. Di Nitto <fdinitto@redhat.com>