Annotation of coherent/a/usr/bob/uusrc/dcp/dcpxf2.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * $Header: /newbits/usr/lib/uucp/dcp/RCS/dcpxf2.c,v 1.4 91/08/15 13:24:56 bin Exp Locker: bin $
                      3:  * $Log:       dcpxf2.c,v $
                      4:  * Revision 1.4  91/08/15  13:24:56  bin
                      5:  * changes by epstein for 7bit sites
                      6:  * 
                      7:  * Revision 1.6        90/03/29  10:54:13      wgl
                      8:  * Add check of the -d option and fail to create directory if option absent.
                      9:  * 
                     10:  * Revision 1.5        90/03/26  13:45:37      wgl
                     11:  * Add routine 'rebuildfn' to rebuild file name as needed on receive.
                     12:  * 
                     13:  * Revision 1.4        90/03/23  09:30:39      wgl
                     14:  * Add routines for cheking read and write permissions.
                     15:  * 
                     16:  * Revision 1.3        90/03/22  12:11:08      wgl
                     17:  * Add 'canwrite'.
                     18:  * 
                     19:  * Revision 1.2        90/03/22  08:59:23      wgl
                     20:  * Fixed error in from/to file reporting in status mail message.
                     21:  * 
                     22:  */
                     23: 
                     24: #include "dcp.h"
                     25: #include <signal.h>
                     26: #include <ctype.h>
                     27: #include <sys/timeb.h>
                     28: #include <sys/stat.h>
                     29: #include <access.h>
                     30: #include <pwd.h>
                     31: #include "perm.h" 
                     32: 
                     33: static char    uuxbuf [64];
                     34: static char    allowed [80];
                     35: static char    disallowed[80];
                     36: static char    *successmsg [2] = {
                     37:        "FAILED",
                     38:        "Successfully"
                     39: };
                     40: 
                     41: static char    tmpfilename[BUFSIZ];    /* Holds the converted file name */
                     42: extern char    reason[];
                     43: extern char    *strtok();
                     44: 
                     45: notifystatus(fromfilep, xtofile, sending, success, cdotctl)
                     46: char   *fromfilep, *xtofile;
                     47: int    success, cdotctl, sending;
                     48: {
                     49:        if (cdotctl) {
                     50:                if (index(optionp, 'm') != NULL) 
                     51:                        l3statmail(fromfilep, xtofile, sending, success);
                     52:        } else {
                     53:                if (index(optionp, 'n') != NULL)
                     54:                        notify2mail(fromfilep, xtofile, success);
                     55:        }
                     56: }
                     57: 
                     58: l3statmail(from, to, sending, success)
                     59: char   *from;
                     60: char   *to;
                     61: int    sending;
                     62: int    success;
                     63: {
                     64:        FILE    *fmp;
                     65: 
                     66:        (void) signal(SIGPIPE, SIG_IGN);
                     67:        sprintf(uuxbuf, "mail -auucp %s", usernamep);
                     68:        plog(M_TRANSFER, "Posting local status mail to user \"%s\"", usernamep);
                     69:        if ((fmp = popen(uuxbuf, "w")) == NULL)
                     70:                plog(M_TRANSFER, "Cannot send status mail");
                     71:        else {
                     72:                static char     *succp;
                     73:                fprintf(fmp, "From: UUCP V%s\n", version);
                     74:                fprintf(fmp, "Subject: UUCP file transfer status\n\n");
                     75:                succp = successmsg [success];
                     76:                if (sending) {
                     77:                        fprintf (fmp, "Sent file:\t%s\n", from);
                     78:                        fprintf (fmp, "       to:\t%s!%s\n%s\n",
                     79:                                rmtname, to, succp);
                     80:                } else {
                     81:                        fprintf (fmp,"Received file:\t%s\n", to);
                     82:                        fprintf (fmp, "        from:\t%s!%s\n%s\n",
                     83:                                rmtname, from, succp);
                     84:                }
                     85:                if (!success)
                     86:                        fprintf(fmp, "Reason: %s\n", reason);
                     87:                if (pclose(fmp) != 0)
                     88:                        plog(M_TRANSFER, "Status mail failed.");
                     89:        }
                     90: }
                     91: 
                     92: notify2mail(from, to, success)
                     93: char   *from;
                     94: char   *to;
                     95: int    success;
                     96: {
                     97:        FILE    *fmp;
                     98:        int     status;
                     99: 
                    100:        (void) signal(SIGPIPE, SIG_IGN);
                    101:        sprintf(uuxbuf, "mail -auucp %s", notifyp);
                    102:        plog(M_TRANSFER, "Notifying user \"%s\".", notifyp);
                    103:        if ((fmp = popen(uuxbuf, "w")) == NULL)
                    104:                plog(M_TRANSFER, "Cannot send notify mail (popen)");
                    105:        else {
                    106:                fprintf(fmp, "From: UUCP V%s\n", version);
                    107:                fprintf(fmp, "\nThe file:\t%s\nReceived from:\t%s!%s\n",
                    108:                        to, rmtname, from);
                    109:                fprintf(fmp, "%s\n", successmsg [success]);
                    110:                if (!success)
                    111:                        fprintf(fmp, "Reason: %s\n", reason);
                    112:                if ((status = pclose(fmp)) != 0) {
                    113:                        plog(M_TRANSFER, 
                    114:                                "Notify mail fails (pclose), code %d", status);
                    115:                }
                    116:        }
                    117: }
                    118: 
                    119: getoct(s)
                    120: char   *s;
                    121: {
                    122:        char    *cp;
                    123:        char    c;
                    124:        int     n;
                    125: 
                    126:        cp = s;
                    127:        n = 0;
                    128:        while ((c = *cp) != '\0') {
                    129:                n = (n * 8) + *cp++ -'0';
                    130:        }
                    131:        return n;
                    132: }
                    133:                
                    134: int
                    135: cantsend()
                    136: {
                    137:        plog(M_TRANSFER, "Cannot send packet");
                    138:        printmsg(M_TRANSFER, "Cannot send packet (cantsend)");
                    139:        terminatelevel++;
                    140:        return 'Y';
                    141: }
                    142: 
                    143: int
                    144: cantread()
                    145: {
                    146:        plog(M_TRANSFER, "Cannot read packet");
                    147:        printmsg(M_TRANSFER, "Cannot read packet (cantread)");
                    148:        terminatelevel++;
                    149:        return 'Y';
                    150: }
                    151: 
                    152: int
                    153: canwrite(fn)
                    154: char   *fn;
                    155: {
                    156:        static  dirname [120];
                    157:        struct  stat    statbuf;        
                    158:        char    *cp;
                    159: 
                    160:        strcpy(dirname, fn);
                    161:        if ((cp = rindex(dirname, '/')) != NULL) {
                    162:                *cp = '\0';
                    163:                if (index(optionp, 'd') != NULL) {
                    164:                        if (!ckdir(dirname)) {
                    165:                                plog(M_SPOOL, "unable to create directory %s", 
                    166:                                                                dirname);
                    167:                                return 0;
                    168:                        }
                    169:                }
                    170:        }
                    171:        if (stat(fn, &statbuf) == -1)
                    172:                return 1;
                    173:        if (access(fn, 0) == 0)
                    174:                return 1;
                    175:        return 0;
                    176: }
                    177: 
                    178: perm_write(fn)
                    179: char   *fn;
                    180: {
                    181:        strcpy(allowed, perm_value(write_e));
                    182:        strcpy(disallowed, perm_value(nowrite_e));
                    183:        return allowed_or_not(fn);
                    184: }
                    185: 
                    186: perm_read(fn)
                    187: char   *fn;
                    188: {
                    189:        strcpy(allowed, perm_value(read_e));
                    190:        strcpy(disallowed, perm_value(noread_e));
                    191:        return allowed_or_not(fn);
                    192: }
                    193: 
                    194: static int
                    195: allowed_or_not(fn)
                    196: char   *fn;
                    197: {
                    198:        char    *sp, *cp;
                    199: 
                    200:        strcat(allowed, ":/usr/spool/uucp");
                    201:        sp = disallowed;
                    202:        while ((cp = strtok(sp, ":")) != NULL) {
                    203:                sp = NULL;
                    204:                if (strncmp(fn, cp, strlen(cp)) == 0)
                    205:                        return 0;
                    206:        }
                    207:        sp = allowed;
                    208:        while ((cp = strtok(sp, ":")) != NULL) {
                    209:                sp = NULL;
                    210:                if (strncmp(fn, cp, strlen(cp)) == 0)
                    211:                        return 1;
                    212:        }
                    213:        return 0;
                    214: }
                    215: 
                    216: /*
                    217:  *     rebuildfn
                    218:  *     rebuild the destination file name for a transfer, handling
                    219:  *     directories and so on.
                    220:  */
                    221: char   *
                    222: rebuildfn(destfile)
                    223: char   *destfile;
                    224: {
                    225:        struct  passwd  *pwp;
                    226:        struct  stat    statbuf;
                    227:        char    *cp;
                    228: 
                    229:        if (*destfile == '~') {
                    230:                if (*(destfile + 1) == '/')
                    231:                        sprintf(tmpfilename, "%s/%s", PUBDIR, destfile + 2);
                    232:                else {
                    233:                        static  char    user [20];
                    234:                        strcpy(tmpfilename, destfile + 1);
                    235:                        if ((cp = strtok(tmpfilename, "/\n")) == NULL)
                    236:                                cp = tmpfilename;
                    237:                        strcpy(user, tmpfilename);
                    238:                        if ((pwp = getpwnam(user)) == NULL)
                    239:                                return NULL;
                    240:                        if ((cp = index(destfile, "/")) == NULL)
                    241:                                cp = "";
                    242:                        sprintf(tmpfilename, "%s/%s", pwp->pw_dir, cp);
                    243:                }
                    244:        } else if (*destfile == '/')
                    245:                sprintf(tmpfilename, "%s", destfile);
                    246:        else
                    247:                sprintf(tmpfilename, "%s/%s/%s", SPOOLDIR, rmtname, destfile);
                    248:        if ((cp = index(tmpfilename, '\n')) != NULL)
                    249:                *cp = '\0';
                    250:        if (((stat(tmpfilename, &statbuf) != -1) &&
                    251:                ((statbuf.st_mode & S_IFDIR) != 0)) ||
                    252:                (tmpfilename[strlen(tmpfilename) - 1] == '/')) {
                    253:                if ((cp = rindex(fromfilep, '/')) == NULL)
                    254:                        cp = fromfilep;
                    255:                else
                    256:                        cp++;
                    257:                if (tmpfilename[strlen(tmpfilename) - 1] != '/')
                    258:                        strcat(tmpfilename, "/");
                    259:                strcat(tmpfilename, cp);
                    260:        }
                    261:        return tmpfilename;
                    262: }

unix.superglobalmegacorp.com

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