Annotation of coherent/d/bin/mail/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: 
        !             6: char   *parent();
        !             7: char   keyname[64];            /* Destination public key file name */
        !             8: 
        !             9: 
        !            10: /*
        !            11:  * Check access on a file.
        !            12:  */
        !            13: maccess(name)
        !            14: char *name;
        !            15: {
        !            16:        struct stat sb;
        !            17: 
        !            18:        if (stat(name, &sb) < 0) {
        !            19:                if (access(parent(name), ACREAT) < 0)
        !            20:                        return (-1);
        !            21:        } else if (access(name, AWRITE) < 0)
        !            22:                return (-1);
        !            23:        return (0);
        !            24: }
        !            25: 
        !            26: /*
        !            27:  * Check enrollment for xmail.
        !            28:  */
        !            29: xaccess(name) char *name;
        !            30: {
        !            31:        struct stat sb;
        !            32:        sprintf(keyname, "%s%s", PUBKEYDIR, name);
        !            33:        return stat(keyname, &sb) >= 0;
        !            34: }
        !            35: /*
        !            36:  * Find the parent directory for access permissions.
        !            37:  */
        !            38: char *
        !            39: parent(name)
        !            40: char *name;
        !            41: {
        !            42:        register char *cp, *xp;
        !            43:        static char p[256];
        !            44:        char *rindex();
        !            45: 
        !            46:        xp = rindex(name, '/');
        !            47:        if (xp == NULL)
        !            48:                return (".");
        !            49:        if (xp == name)
        !            50:                return ("/");
        !            51:        if (xp - name >= 256)
        !            52:                return ("");
        !            53:        cp = p;
        !            54:        while (name < xp)
        !            55:                *cp++ = *name++;
        !            56:        *cp = 0;
        !            57:        return (p);
        !            58: }
        !            59: 
        !            60: /*
        !            61:  * Copy from the file stream `ifp' (starting at
        !            62:  * position `start' and ending at `end' or EOF)
        !            63:  * to the file stream `ofp' which is assumed
        !            64:  * to be already correctly positioned.
        !            65:  * Returns non-zero on errors.
        !            66:  * intstop == 1 means stop on interrupt
        !            67:  * intstop == 0 means ignore interrupt
        !            68:  */
        !            69: mcopy(ifp, ofp, start, end, intstop)
        !            70: register FILE *ifp, *ofp;
        !            71: fsize_t start, end;
        !            72: {
        !            73:        register int c;
        !            74: 
        !            75:        fseek(ifp, start, 0);
        !            76:        end -= start;
        !            77:        if (intstop)
        !            78:                while (!intcheck() && end-- > 0  &&  (c = getc(ifp))!=EOF)
        !            79:                        putc(c, ofp);
        !            80:        else
        !            81:                while (end-- > 0  &&  (c = getc(ifp))!=EOF)
        !            82:                        putc(c, ofp);
        !            83:        fflush(ofp);
        !            84:        if (ferror(ofp))
        !            85:                return (1);
        !            86:        return (0);
        !            87: }
        !            88: 
        !            89: char helpmessage[] = "\
        !            90: \
        !            91: mail -- computer mail\n\
        !            92: xmail -- secret computer mail\n\
        !            93: Usage: mail [ options ] [ user ... ]\n\
        !            94: or:    xmail [ options ] user [ ... ]\n\
        !            95: Options:\n\
        !            96:        -f file         Print mail from 'file' instead of the default\n\
        !            97:        -p              Print mail non-interactively\n\
        !            98:        -q              Exit on interrupt, leaving mail unchanged\n\
        !            99:        -r              Print mail in reverse order, latest first\n\
        !           100: If 'user' is present, send each a mail message read from standard input.\n\
        !           101: If 'xmail' is the command, use xencode to encrypt the mail messages.\n\
        !           102: Mail message ends with EOF of a line containing only '.'.  Otherwise, read\n\
        !           103: and print the invoking user's mailbox.\n\
        !           104: \
        !           105: ";
        !           106: 
        !           107: usage()
        !           108: {
        !           109:        mmsg(helpmessage);
        !           110:        rmexit(1);
        !           111: }
        !           112: 

unix.superglobalmegacorp.com

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