Annotation of researchv10no/cmd/nupas/libc/getlog.c, revision 1.1

1.1     ! root        1: /*
        !             2:  *     getlog() -- paranoid version of getlogin.
        !             3:  *     Unnecessary but harmless in V9; may be essential in Sys V
        !             4:  *             with botched layers implementations
        !             5:  *
        !             6:  *     Try getlogin().
        !             7:  *     If that fails, look in the password file.
        !             8:  *     if that fails, give up.
        !             9:  */
        !            10: 
        !            11: #include <pwd.h>
        !            12: 
        !            13: extern int getuid();
        !            14: extern char *getlogin(), *getenv();
        !            15: 
        !            16: #define NULL 0
        !            17: 
        !            18: char *
        !            19: getlog()
        !            20: {
        !            21:        char *p;
        !            22:        struct passwd *pw;
        !            23: 
        !            24:        if ((p = getlogin()) != NULL)
        !            25:                return p;
        !            26:        
        !            27:        /* If LOGNAME is set, and it matches getuid(), use it */
        !            28:        p = getenv ("LOGNAME");
        !            29:        if (p != NULL && *p != '\0') {
        !            30:                pw = getpwnam(p);
        !            31:                if (pw != NULL && pw->pw_uid == getuid())
        !            32:                        return p;
        !            33:        }
        !            34: 
        !            35:        /* Try to get the password file entry for getuid() */
        !            36:        if ((pw = getpwuid(getuid())) != NULL)
        !            37:                return pw->pw_name;
        !            38:        
        !            39:        /* Give up */
        !            40:        return NULL;
        !            41: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.