bug-glibc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

getpwnam() is non-conformant with SUSv3


From: Michael Kerrisk
Subject: getpwnam() is non-conformant with SUSv3
Date: Wed, 28 May 2003 14:19:22 +0200

>Submitter-Id:  net
>Originator:    Michael Kerrisk
>Organization:
>Confidential:  no
>Synopsis:      getpwnam() is non-formant with SUSv3
>Severity:      non-critical
>Priority:      low
>Category:      libc
>Class:         sw-bug
>Release:       libc-2.3.2
>Environment:
Host type: i586-suse-linux-gnu
System: Linux extern4 2.4.20-4GB #1 Mon Mar 17 17:54:44 UTC 2003 i686 unknown 
unknown GNU/Linux
Architecture: i686

Addons: db linuxthreads noversion
Build CFLAGS: -O2 -march=i586 -mcpu=i686 -fmessage-length=0 -g
Build CC: gcc
Compiler version: 3.3 20030226 (prerelease) (SuSE Linux)
Kernel headers: 2.4.20
Symbol versioning: yes
Build static: yes
Build shared: yes
Build pic-default: no
Build profile: yes
Build omitfp: no
Build bounded: no
Build static-nss: no

>Description:
[I've tried a number of times sending this to 
address@hidden but no acknowledgement comes back...]

In the specification for getpwnam(), SUSv3 says:

"Applications wishing to check for error situations should set
errno to 0 before calling getpwnam( ). If getpwnam( ) returns
a null pointer and errno is non-zero, an error occurred."

ands goes on to say:

"A null pointer shall be returned if the requested entry is not
found, or an error occurs. On error, errno shall be set to 
indicate the error."

My reading of this that if we set errno to 0 before the call 
to getpwnam(), then if the username cannot be found, then 
after the call NULL, should be returned, and errno should 
be 0.  However, the glibc implementation returns NULL + 
errno==ENOENT.

Some comparisons with other implementations in these 
circumstances:

Tru64 5.1b, HP/UX-11i, and Solaris 7 all return NULL + errno == 0
(i.e., consistent with my reading of SUSv3)

AIX 5.1 returns NULL + errno ==ESRCH

Irix 6.5 returns NULL + ENOENT (so glibc is consistent with Irix!)

>How-To-Repeat:
The following is a simple test program; run it specifying a 
non-existent username on the command line.  If we run this 
program we see:

$ a.out baduser
getpwnam: No such file or directory

when we should see:

$ a.out baduser
Username not found


#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <pwd.h>


int
main(int argc, char *argv[])
{
    struct passwd *pwd;
    
    errno = 0;
    pwd = getpwnam(argv[1]);
    if (pwd == NULL) {
        if (errno != 0) {       
            perror("getpwnam");
            exit(EXIT_FAILURE);
        } /* if */

        /* Not found case should come here (but doesn't) */

        fprintf(stderr, "Username not found\n");
        exit(EXIT_FAILURE);
    } /* if */

    printf("Name:     %s\n", pwd->pw_name);
    exit(EXIT_SUCCESS);
} /* main */
>Fix:
        <how to correct or work around the problem, if known (multiple lines)>

--
Michael Kerrisk
address@hidden

It is good to collect things, but it is better to go on walks

                    Anatole France







reply via email to

[Prev in Thread] Current Thread [Next in Thread]