Annotation of 40BSD/cmd/ucbmail/ing.local.c, revision 1.1.1.1

1.1       root        1: #
                      2: 
                      3: /*
                      4:  * Mail -- a mail program
                      5:  *
                      6:  * Ingres 11/70.  Unix version 6.0
                      7:  *
                      8:  * Local routines that are installation dependent.
                      9:  * All fiddlers please note:  if you make careful note of
                     10:  * what you change here, I will incorporate your changes and
                     11:  * you won't have to remake them each release.
                     12:  */
                     13: 
                     14: #include "rcv.h"
                     15: #include       <errno.h>
                     16: 
                     17: /*
                     18:  * Locate the user's mailbox file (ie, the place where new, unread
                     19:  * mail is queued).  At Ingres, it's in /usr/spool/mail/loginname.
                     20:  */
                     21: 
                     22: findmail()
                     23: {
                     24:        register char *cp;
                     25: 
                     26:        cp = copy("/usr/spool/mail/", mailname);
                     27:        copy(myname, cp);
                     28: }
                     29: 
                     30: /*
                     31:  * Get rid of the queued mail.
                     32:  */
                     33: 
                     34: demail()
                     35: {
                     36:        if (unlink(mailname) >= 0)
                     37:                return;
                     38:        close(creat(mailname, 0666));
                     39:        alter(mailname);
                     40: }
                     41: 
                     42: /*
                     43:  * Get an environment variable.  At present, we only support
                     44:  * "SHELL" and "HOME".  This routine makes use of the getpw
                     45:  * routine in the neighboring getname.c stuff.
                     46:  */
                     47: 
                     48: char *
                     49: getenv(name)
                     50:        char name[];
                     51: {
                     52:        char pwline[LINESIZE];
                     53:        static char val[30];
                     54:        register char *cp, *dp;
                     55:        register int cc;
                     56: 
                     57:        if (equal(name, "SHELL"))
                     58:                cc = 6;
                     59:        else if (equal(name, "HOME"))
                     60:                cc = 5;
                     61:        else
                     62:                return(NOSTR);
                     63:        if (getpwnam(myname, pwline) < 0)
                     64:                return(NOSTR);
                     65:        for (cp = pwline; *cp && cc > 0;)
                     66:                if (*cp++ == ':')
                     67:                        cc--;
                     68:        dp = cp;
                     69:        while (*cp != ':' && *cp != '\0' && *cp != '\n')
                     70:                cp++;
                     71:        *cp = '\0';
                     72:        if (*dp == '\0')
                     73:                return(NOSTR);
                     74:        copy(dp, val);
                     75:        return(val);
                     76: }
                     77: 
                     78: /*
                     79:  * Discover user name.  On Ingres, user names are rarely 1-1 with uids,
                     80:  * so we look for this guy in the utmp file first, then try finding
                     81:  * him in the passwd file on basis of uid if that fails.
                     82:  */
                     83: 
                     84: struct utmp {
                     85:        char    u_name[8];              /* User login name. */
                     86:        char    u_tty;                  /* typewriter character */
                     87:        char    u_cfill;                /* Unused for now. */
                     88:        long    u_time;                 /* Login time */
                     89:        short   u_wfill;                /* Unused also */
                     90: };
                     91: 
                     92: username(uid, namebuf)
                     93:        char namebuf[];
                     94: {
                     95:        struct utmp ubuf;
                     96:        register char *cp;
                     97:        register int tty;
                     98:        register FILE *fwho;
                     99: 
                    100:        tty = ttyn(0);
                    101:        if (tty == 'x')
                    102:                goto useuid;
                    103:        
                    104:        /*
                    105:         * Dammit, I really do have to search the utmp file!
                    106:         */
                    107: 
                    108:        if ((fwho = fopen("/etc/utmp", "r")) == NULL)
                    109:                goto useuid;
                    110:        while (fread(&ubuf, 1, sizeof ubuf, fwho) > 0)
                    111:                if (ubuf.u_tty == tty) {
                    112:                        strncpy(namebuf, ubuf.u_name, 8);
                    113:                        namebuf[8] = 0;
                    114:                        cp = index(namebuf, ' ');
                    115:                        if (cp != NOSTR)
                    116:                                *cp = 0;
                    117:                        return(0);
                    118:                }
                    119:        fclose(fwho);
                    120: 
                    121: useuid:
                    122:        return(getname(uid, namebuf));
                    123: }
                    124: 
                    125: /*
                    126:  * Unix routine to do an "fopen" on file descriptor
                    127:  * The mode has to be repeated because you can't query its
                    128:  * status
                    129:  */
                    130: 
                    131: FILE *
                    132: fdopen(fd, mode)
                    133: register char *mode;
                    134: {
                    135:        extern int errno;
                    136:        register FILE *iop;
                    137:        extern FILE *_lastbuf;
                    138: 
                    139:        for (iop = _iob; iop->_flag&(_IOREAD|_IOWRT); iop++)
                    140:                if (iop >= _lastbuf)
                    141:                        return(NULL);
                    142:        iop->_cnt = 0;
                    143:        iop->_file = fd;
                    144:        if (*mode != 'r') {
                    145:                iop->_flag |= _IOWRT;
                    146:                if (*mode == 'a')
                    147:                        lseek(fd, 0L, 2);
                    148:        } else
                    149:                iop->_flag |= _IOREAD;
                    150:        return(iop);
                    151: }
                    152: 
                    153: /*
                    154:  * Copy s2 to s1, truncating or null-padding to always copy n bytes
                    155:  * return s1
                    156:  */
                    157: 
                    158: char *
                    159: strncpy(s1, s2, n)
                    160: register char *s1, *s2;
                    161: {
                    162:        register i;
                    163:        register char *os1;
                    164: 
                    165:        os1 = s1;
                    166:        for (i = 0; i < n; i++)
                    167:                if ((*s1++ = *s2++) == '\0') {
                    168:                        while (++i < n)
                    169:                                *s1++ = '\0';
                    170:                        return(os1);
                    171:                }
                    172:        return(os1);
                    173: }

unix.superglobalmegacorp.com

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