Timo Sirainen:
> 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

Unfortunately, lack of complaints does not prove that rare errors
are handled correctly :-)  Witness the bug that led to this thread,
which is at least five years old.

Apple: POSIX as of which release?

AIX: POSIX as of which release?

Many systems are covered by the manpage collection at
http://www.freebsd.org/cgi/man.cgi

FreeBSD: POSIX as of 5.1 and later
     The functions getpwent_r(), getpwnam_r(), and getpwuid_r()
     return 0 if no error occurred, or an error number to indicate
     failure.  It is not an error if a matching entry is not found.

NetBSD: POSIX as of 3.0
     The functions getpwnam_r(), getpwuid_r(), and getpwent_r()
     return 0 on success or entry not found, and non-zero on failure.

OpenBSD: POSIX as of 4.4 and later
     The functions getpwnam_r() and getpwuid_r() update result to point to
     pwstore and then return 0 on success.

HP-UX POSIX as of which release?
     HP-UX 11.22 Claims POSIX.1c conformance but does not seem to
     describe what they actually do.

SunOS POSIX as of 5.5 but requires compile-time switch
     Solaris 2.4 and earlier releases provided definitions of the
     getpwnam_r() and getpwuid_r() functions as specified in POSIX.1c
     Draft 6. The final POSIX.1c standard changed the interface
     for these functions. 
     ...
     For POSIX.1c-conforming applications, the _POSIX_PTHREAD_SEMANTICS
     and _REENTRANT flags are automatically turned on  by defining
     the _POSIX_C_SOURCE flag with a value >=199506L.

Unfortunately, setting _POSIX_C_SOURCE changes more than just this,
and so should be done carefully.

In any case, this code should be used only after it is verified to
work. Manpages do not always describe reality.

        Wietse

Reply via email to