Annotation of 43BSD/contrib/news/src/fullname.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * fullname.c - this file is made separate so that different local
        !             3:  * conventions can be applied.  The stock version understands two
        !             4:  * conventions:
        !             5:  *
        !             6:  * (a) Berkeley finger: the gecos field in /etc/passwd begins with
        !             7:  *     the full name, terminated with comma, semicolon, or end of
        !             8:  *     field.  & expands to the login name.
        !             9:  * (b) BTL RJE: the gecos field looks like
        !            10:  *     : junk - full name ( junk :
        !            11:  *     where the "junk -" is optional.
        !            12:  *
        !            13:  * If you have a different local convention, modify this file accordingly.
        !            14:  */
        !            15: 
        !            16: #ifdef SCCSID
        !            17: static char    *SccsId = "@(#)fullname.c       1.10    4/16/85";
        !            18: #endif /* SCCSID */
        !            19: 
        !            20: #include "params.h"
        !            21: 
        !            22: #ifndef LOCALNAME
        !            23: /*
        !            24:  * Figure out who is sending the message and sign it.
        !            25:  * We attempt to look up the user in the gecos field of /etc/passwd.
        !            26:  */
        !            27: char *
        !            28: fullname(un)
        !            29: char *un;
        !            30: {
        !            31:        static char inbuf[BUFLEN];
        !            32:        struct passwd *pw;
        !            33: 
        !            34:        pw = getpwnam(un);
        !            35:        if (pw == NULL)
        !            36:                return un;
        !            37:        buildfname(pw->pw_gecos, un, inbuf);
        !            38:        if (inbuf[0] == 0)
        !            39:                return un;
        !            40:        return inbuf;
        !            41: }
        !            42: 
        !            43: #else
        !            44: 
        !            45: /*
        !            46:  * Alternative version of fullname which asks the user for his full name.
        !            47:  * This is mainly suitable for systems that don't have a full name
        !            48:  * database somewhere.  It puts the answer in $HOME/.name
        !            49:  */
        !            50: char *
        !            51: fullname(un)
        !            52: char *un;
        !            53: {
        !            54:        static char inbuf[BUFLEN];
        !            55:        char fbuf[BUFLEN];
        !            56:        FILE *fd;
        !            57:        char *p, *index(), *getenv();
        !            58:        int pid;
        !            59: 
        !            60:        if (!isatty(2))
        !            61:                return un;
        !            62:        printf("What is your full name (for news article signatures): ");
        !            63:        fflush(stdout);
        !            64:        read(2, inbuf, sizeof inbuf);
        !            65:        if (inbuf[0] == 0)
        !            66:                return un;
        !            67:        p = index(inbuf, '\n');
        !            68:        if (p)
        !            69:                *p = 0;
        !            70:        if ((p = getenv("HOME")) == NULL) {
        !            71:                fprintf(stderr,
        !            72:                "inews: no HOME environment variable - .name not written\n");
        !            73:                return inbuf;
        !            74:        }
        !            75:        sprintf(fbuf, "%s/%s", p, ".name");
        !            76:        if ((pid = fork()) < 0) {
        !            77:                perror("inews");
        !            78:                return inbuf;
        !            79:        }
        !            80:        else if (pid != 0)
        !            81:                while (wait((int *)0) != pid)
        !            82:                        ;
        !            83:        else {
        !            84:                setuid(getuid());       /* become the user */
        !            85:                if ((fd = fopen(fbuf, "w")) == NULL)
        !            86:                        fprintf(stderr, "inews: can't create %s\n", fbuf);
        !            87:                else {
        !            88:                        fprintf(fd, "%s\n", inbuf);
        !            89:                        fclose(fd);
        !            90:                }
        !            91:                exit(0);
        !            92:        }
        !            93:        return inbuf;
        !            94: }
        !            95: #endif
        !            96: 
        !            97: #ifndef LOCALNAME
        !            98: /*
        !            99: **  BUILDFNAME -- build full name from gecos style entry.
        !           100: **     (routine lifted from sendmail)
        !           101: **
        !           102: **     This routine interprets the strange entry that would appear
        !           103: **     in the GECOS field of the password file.
        !           104: **
        !           105: **     Parameters:
        !           106: **             p -- name to build.
        !           107: **             login -- the login name of this user (for &).
        !           108: **             buf -- place to put the result.
        !           109: **
        !           110: **     Returns:
        !           111: **             none.
        !           112: **
        !           113: **     Side Effects:
        !           114: **             none.
        !           115: */
        !           116: 
        !           117: buildfname(p, login, buf)
        !           118:        register char *p;
        !           119:        char *login;
        !           120:        char *buf;
        !           121: {
        !           122:        register char *bp = buf;
        !           123: 
        !           124:        if (*p == '*')
        !           125:                p++;
        !           126:        while (*p != '\0' && *p != ',' && *p != ';' && *p != ':' && *p != '(')
        !           127:        {
        !           128:                if (*p == '-') {
        !           129:                        bp = buf;
        !           130:                        p++;
        !           131:                }
        !           132:                else if (*p == '&')
        !           133:                {
        !           134:                        strcpy(bp, login);
        !           135:                        if ((bp == buf || !isalpha(bp[-1])) && islower(*bp))
        !           136:                                *bp = toupper(*bp);
        !           137:                        while (*bp != '\0')
        !           138:                                bp++;
        !           139:                        p++;
        !           140:                }
        !           141:                else
        !           142:                        *bp++ = *p++;
        !           143:        }
        !           144:        *bp = '\0';
        !           145: }
        !           146: #endif

unix.superglobalmegacorp.com

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