On Wed, 2011-04-27 at 07:19 -0400, Wietse Venema wrote: > > It is clear. getpwnam_r() returns 0 both on success and "user not > > found", you just need to check if the result is NULL or not. If > > it returns anything else than 0 it's a transient error. If the > > NSS code internally messes this up, that's its fault then. But I > > think getpwnam_r() API is fine. > > Just checking: whose getpwnam_r() API are you talking about? > > I looked at some manpages and found that vendors have been changing > their getpwnam() and getpwnam_r() error reporting semantics over > time.
I think the POSIX API works in all OSes commonly used nowadays. FreeBSD 5.1, NetBSD 3.0, OpenBSD 4.4, Solaris 5(?), OS X (some version), Linux for last 5+ years. I wrote some wrappers for these and people haven't complained about them much yet (just that OpenBSD had a bug): http://hg.dovecot.org/dovecot-2.0/raw-file/tip/src/lib/ipwd.c > Just because a system has getpwnam_r(), that does not mean it works > like your API; and on some systems, getpwnam() does report errors > via errno (e.g. FreeBSD8), whereas the original UNIX getpwnam() > never returned for transient errors, because all reads were from > local files. Linux getpwnam() man page makes it sound like it's not a good idea to even try to check the errno after getpwnam()=NULL call.