Annotation of coherent/d/bin/mail/lmail/util.c, revision 1.1.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:        else
                    110:                while (end-- > 0  &&  (c = getc(ifp))!=EOF)
                    111:                        putc(c, ofp);
                    112:        fflush(ofp);
                    113:        if (ferror(ofp))
                    114:                return (1);
                    115:        return (0);
                    116: }
                    117: 
                    118: #if XMAIL
                    119: 
                    120: char helpmessage[] = "\
                    121: \
                    122: mail -- computer mail\n\
                    123: xmail -- secret computer mail\n\
                    124: Usage: mail [ options ] [ user ... ]\n\
                    125: or:    xmail [ options ] user [ ... ]\n\
                    126: Options:\n\
                    127:        -f file         Print mail from 'file' instead of the default\n\
                    128:        -p              Print mail non-interactively\n\
                    129:        -q              Exit on interrupt, leaving mail unchanged\n\
                    130:        -r              Print mail in reverse order, latest first\n\
                    131:        -v              Verbose commentary on alias expansion\n\
                    132: If 'user' is present, send each a mail message read from standard input.\n\
                    133: If 'xmail' is the command, use xencode to encrypt the mail messages.\n\
                    134: Mail message ends with EOF of a line containing only '.'.  Otherwise, read\n\
                    135: and print the invoking user's mailbox.\n\
                    136: \
                    137: ";
                    138: 
                    139: #else
                    140: 
                    141: char helpmessage[] = "\
                    142: \
                    143: mail -- computer mail\n\
                    144: Usage: mail [ options ] [ user ... ]\n\
                    145: Options:\n\
                    146:        -f file         Print mail from 'file' instead of the default\n\
                    147:        -p              Print mail non-interactively\n\
                    148:        -q              Exit on interrupt, leaving mail unchanged\n\
                    149:        -r              Print mail in reverse order, latest first\n\
                    150:        -v              Verbose commentary on alias expansion\n\
                    151: If 'user' is present, send each a mail message read from standard input.\n\
                    152: Mail message ends with EOF of a line containing only '.'.  Otherwise, read\n\
                    153: and print the invoking user's mailbox.\n\
                    154: \
                    155: ";
                    156: #endif
                    157: 
                    158: usage()
                    159: {
                    160:        mmsg(helpmessage);
                    161:        rmexit(1);
                    162: }
                    163: 
                    164: #define        LOGFILE "/usr/spool/uucp/.Log/mail/lmail"
                    165: 
                    166: static char *logfile = LOGFILE;
                    167: static FILE *logfp = NULL;
                    168: 
                    169: logopen()
                    170: {
                    171:        time_t t;
                    172: 
                    173:        /* Try to open the log file.  If this fails, no big deal; we
                    174:           just won't log anything.  */
                    175:        time(&t);
                    176:        if ( (logfp=fopen(logfile, "a")) == NULL ) {
                    177: #if 0
                    178:                fprintf(stderr, "Can't open Log File: \"%s\"", logfile);
                    179: #endif
                    180:        } /* If open of logfile failed. */
                    181:        logdump("------------------\n");
                    182:        logdump(ctime(&t));
                    183: }
                    184: 
                    185: logclose()
                    186: {
                    187:        if ( logfp != NULL )  
                    188:                fclose(logfp);
                    189: }
                    190: 
                    191: logdump(x)
                    192: {
                    193:        if ( logfp != NULL )
                    194:                fprintf(logfp, "%r", &x);
                    195: }

unix.superglobalmegacorp.com

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