Annotation of researchv10no/cmd/netnews/src/logdir.c, revision 1.1

1.1     ! root        1: /*
        !             2:  *     UNIX shell - logdir routine
        !             3:  *
        !             4:  *     Joe Steffen
        !             5:  *     Bell Telephone Laboratories
        !             6:  *
        !             7:  *     This routine does not use the getpwent(3) library routine
        !             8:  *     because the latter uses the stdio package.  The allocation of
        !             9:  *     storage in this package destroys the integrity of the shell's
        !            10:  *     storage allocation.
        !            11:  *
        !            12:  *     Modified 2/82 by DJ Molny
        !            13:  *
        !            14:  *     This routine now implements name cacheing, so multiple requests
        !            15:  *     for the same logdir do not result in multiple open/reads of
        !            16:  *     /etc/passwd.  If the previous request was successful and the name
        !            17:  *     is the same as the last request, the same login directory is returned.
        !            18:  */
        !            19: 
        !            20: #define        BUFSIZ  160
        !            21: 
        !            22: static char line[BUFSIZ+1];
        !            23: 
        !            24: char *
        !            25: logdir(name)
        !            26: char *name;
        !            27: {
        !            28:        int     pwf;
        !            29:        static char lastname[BUFSIZ+1];
        !            30:        static char lastdir[BUFSIZ+1];
        !            31:        register char *p;
        !            32:        register int i, j;
        !            33:        char *field();
        !            34:        
        !            35:        if (*lastdir && !strcmp(lastname,name))         /* djm */
        !            36:                return(lastdir);
        !            37: 
        !            38:        strcpy(lastname,name);                  /* djm */
        !            39:        strcpy(lastdir,"");                     /* djm */
        !            40: 
        !            41:        /* attempt to open the password file */
        !            42:        if ((pwf = open("/etc/passwd", 0)) == -1)
        !            43:                return(0);
        !            44:                
        !            45:        /* find the matching password entry */
        !            46:        do {
        !            47:                /* get the next line in the password file */
        !            48:                i = read(pwf, line, BUFSIZ);
        !            49:                for (j = 0; j < i; j++)
        !            50:                        if (line[j] == '\n')
        !            51:                                break;
        !            52:                /* return a null pointer if the whole file has been read */
        !            53:                if (j >= i)
        !            54:                        return(0);
        !            55:                line[++j] = 0;                  /* terminate the line */
        !            56:                lseek(pwf, (long) (j - i), 1);  /* point at the next line */
        !            57:                p = field(line);                /* get the logname */
        !            58:        } while (strcmp(name, line) != 0);
        !            59:        close(pwf);
        !            60:        
        !            61:        /* skip the intervening fields */
        !            62:        p = field(p);
        !            63:        p = field(p);
        !            64:        p = field(p);
        !            65:        p = field(p);
        !            66:        
        !            67:        /* return the login directory */
        !            68:        field(p);
        !            69:        strcpy(lastdir,p);                      /* djm */
        !            70:        return(p);
        !            71: }
        !            72: 
        !            73: static char *
        !            74: field(p)
        !            75: register char *p;
        !            76: {
        !            77:        while (*p && *p != ':')
        !            78:                ++p;
        !            79:        if (*p) *p++ = 0;
        !            80:        return(p);
        !            81: }

unix.superglobalmegacorp.com

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