Annotation of coherent/b/bin/lmail/util.c, revision 1.1

1.1     ! root        1: #include <stdio.h>
        !             2: #include <sys/stat.h>
        !             3: #include <access.h>
        !             4: #include "mail.h"
        !             5: #include <time.h>
        !             6: #include <sys/types.h>
        !             7: 
        !             8: char   *parent();
        !             9: char   keyname[64];            /* Destination public key file name */
        !            10: 
        !            11: /*
        !            12:  *     Miscellaneous Routines
        !            13:  */
        !            14: 
        !            15: char *
        !            16: dupstr(str)
        !            17: {
        !            18:        return( strcpy(myalloc(strlen(str)+1), str) );
        !            19: }
        !            20: 
        !            21: char *
        !            22: myalloc(size)
        !            23: unsigned int size;
        !            24: {
        !            25:        register char *cp;
        !            26:        extern char *malloc();
        !            27: 
        !            28:        if ( (cp=malloc(size)) == NULL )
        !            29:                merr("Out of memory");
        !            30:        return(cp);
        !            31: }
        !            32: 
        !            33: fatal(x)
        !            34: {
        !            35:        fprintf(stderr, "Fatal Error: %r\n", &x);
        !            36:        fflush(stderr);
        !            37:        rmexit(1);
        !            38: }
        !            39: 
        !            40: /*
        !            41:  * Check access on a file.
        !            42:  */
        !            43: maccess(name)
        !            44: char *name;
        !            45: {
        !            46:        struct stat sb;
        !            47: 
        !            48:        if (stat(name, &sb) < 0) {
        !            49:                if (access(parent(name), ACREAT) < 0)
        !            50:                        return (-1);
        !            51:        } else if (access(name, AWRITE) < 0)
        !            52:                return (-1);
        !            53:        return (0);
        !            54: }
        !            55: 
        !            56: /*
        !            57:  * Check enrollment for xmail.
        !            58:  */
        !            59: xaccess(name) char *name;
        !            60: {
        !            61:        struct stat sb;
        !            62:        sprintf(keyname, "%s%s", PUBKEYDIR, name);
        !            63:        return stat(keyname, &sb) >= 0;
        !            64: }
        !            65: /*
        !            66:  * Find the parent directory for access permissions.
        !            67:  */
        !            68: char *
        !            69: parent(name)
        !            70: char *name;
        !            71: {
        !            72:        register char *cp, *xp;
        !            73:        static char p[256];
        !            74: 
        !            75:        xp = rindex(name, '/');
        !            76:        if (xp == NULL)
        !            77:                return (".");
        !            78:        if (xp == name)
        !            79:                return ("/");
        !            80:        if (xp - name >= 256)
        !            81:                return ("");
        !            82:        cp = p;
        !            83:        while (name < xp)
        !            84:                *cp++ = *name++;
        !            85:        *cp = 0;
        !            86:        return (p);
        !            87: }
        !            88: 
        !            89: /*
        !            90:  * Copy from the file stream `ifp' (starting at
        !            91:  * position `start' and ending at `end' or EOF)
        !            92:  * to the file stream `ofp' which is assumed
        !            93:  * to be already correctly positioned.
        !            94:  * Returns non-zero on errors.
        !            95:  * intstop == 1 means stop on interrupt
        !            96:  * intstop == 0 means ignore interrupt
        !            97:  */
        !            98: mcopy(ifp, ofp, start, end, intstop)
        !            99: register FILE *ifp, *ofp;
        !           100: fsize_t start, end;
        !           101: {
        !           102:        register int c;
        !           103: 
        !           104:        fseek(ifp, start, 0);
        !           105:        end -= start;
        !           106:        if (intstop)
        !           107:                while (!intcheck() && end-- > 0  &&  (c = getc(ifp))!=EOF){
        !           108:                        putc(c, ofp);
        !           109:                        fflush(ofp);
        !           110:                }
        !           111:        else
        !           112:                while (end-- > 0  &&  (c = getc(ifp))!=EOF){
        !           113:                        putc(c, ofp);
        !           114:                        fflush(ofp);
        !           115:                }
        !           116: 
        !           117:        if (ferror(ofp))
        !           118:                return (1);
        !           119:        return (0);
        !           120: }
        !           121: 
        !           122: #if XMAIL
        !           123: 
        !           124: char helpmessage[] = "\
        !           125: \
        !           126: mail -- computer mail\n\
        !           127: xmail -- secret computer mail\n\
        !           128: Usage: mail [ options ] [ user ... ]\n\
        !           129: or:    xmail [ options ] user [ ... ]\n\
        !           130: Options:\n\
        !           131:        -f file         Print mail from 'file' instead of the default\n\
        !           132:        -p              Print mail non-interactively\n\
        !           133:        -q              Exit on interrupt, leaving mail unchanged\n\
        !           134:        -r              Print mail in reverse order, latest first\n\
        !           135:        -v              Verbose commentary on alias expansion\n\
        !           136: If 'user' is present, send each a mail message read from standard input.\n\
        !           137: If 'xmail' is the command, use xencode to encrypt the mail messages.\n\
        !           138: Mail message ends with EOF of a line containing only '.'.  Otherwise, read\n\
        !           139: and print the invoking user's mailbox.\n\
        !           140: \
        !           141: ";
        !           142: 
        !           143: #else
        !           144: 
        !           145: char helpmessage[] = "\
        !           146: \
        !           147: mail -- computer mail\n\
        !           148: Usage: mail [ options ] [ user ... ]\n\
        !           149: Options:\n\
        !           150:        -f file         Print mail from 'file' instead of the default\n\
        !           151:        -p              Print mail non-interactively\n\
        !           152:        -q              Exit on interrupt, leaving mail unchanged\n\
        !           153:        -r              Print mail in reverse order, latest first\n\
        !           154:        -v              Verbose commentary on alias expansion\n\
        !           155: If 'user' is present, send each a mail message read from standard input.\n\
        !           156: Mail message ends with EOF of a line containing only '.'.  Otherwise, read\n\
        !           157: and print the invoking user's mailbox.\n\
        !           158: \
        !           159: ";
        !           160: #endif
        !           161: 
        !           162: usage()
        !           163: {
        !           164:        mmsg(helpmessage);
        !           165:        rmexit(1);
        !           166: }
        !           167: 
        !           168: #define        LOGFILE "/usr/spool/uucp/.Log/mail/lmail"
        !           169: 
        !           170: static char *logfile = LOGFILE;
        !           171: static FILE *logfp = NULL;
        !           172: 
        !           173: logopen()
        !           174: {
        !           175:        time_t t;
        !           176: 
        !           177:        /* Try to open the log file.  If this fails, no big deal; we
        !           178:           just won't log anything.  */
        !           179:        time(&t);
        !           180:        if ( (logfp=fopen(logfile, "a")) == NULL ) {
        !           181: #if 0
        !           182:                fprintf(stderr, "Can't open Log File: \"%s\"", logfile);
        !           183: #endif
        !           184:        } /* If open of logfile failed. */
        !           185:        logdump("------------------\n");
        !           186:        logdump(ctime(&t));
        !           187: }
        !           188: 
        !           189: logclose()
        !           190: {
        !           191:        if ( logfp != NULL )  
        !           192:                fclose(logfp);
        !           193: }
        !           194: 
        !           195: logdump(x)
        !           196: {
        !           197:        if ( logfp != NULL ){
        !           198:                fprintf(logfp, "%r", &x);
        !           199:                fflush(logfp);
        !           200:        }
        !           201: }

unix.superglobalmegacorp.com

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