Annotation of 40BSD/cmd/uucp/uux.c, revision 1.1

1.1     ! root        1:        /*  uux 2.2  5/24/79  18:33:11  */
        !             2: #include "uucp.h"
        !             3: #include "uucpdefs.h"
        !             4: 
        !             5: static char SiD[] = "@(#)uux   2.2";
        !             6: 
        !             7: #define NOSYSPART 0
        !             8: #define HASSYSPART 1
        !             9: 
        !            10: #define APPCMD(d) {\
        !            11: char *p;\
        !            12: for (p = d; *p != '\0';) *cmdp++ = *p++;\
        !            13: *cmdp++ = ' ';\
        !            14: *cmdp = '\0';}
        !            15: 
        !            16: #define GENSEND(f, a, b, c, d) {\
        !            17: fprintf(f, "S %s %s %s - %s 0666\n", a, b, c, d);\
        !            18: }
        !            19: #define GENRCV(f, a, b, c) {\
        !            20: fprintf(f, "R %s %s %s - \n", a, b, c);\
        !            21: }
        !            22: /*
        !            23:  *     
        !            24:  */
        !            25: 
        !            26: main(argc, argv)
        !            27: char *argv[];
        !            28: {
        !            29:        char cfile[NAMESIZE];   /* send commands for files from here */
        !            30:        char dfile[NAMESIZE];   /* used for all data files from here */
        !            31:        char rxfile[NAMESIZE];  /* to be sent to xqt file (X. ...) */
        !            32:        char tfile[NAMESIZE];   /* temporary file name */
        !            33:        char tcfile[NAMESIZE];  /* temporary file name */
        !            34:        char t2file[NAMESIZE];  /* temporary file name */
        !            35:        int cflag = 0;          /*  commands in C. file flag  */
        !            36:        int rflag = 0;          /*  C. files for receiving flag  */
        !            37:        char buf[BUFSIZ];
        !            38:        char inargs[BUFSIZ];
        !            39:        int pipein = 0;
        !            40:        int startjob = 1;
        !            41:        char path[MAXFULLNAME];
        !            42:        char cmd[BUFSIZ];
        !            43:        char *ap, *cmdp;
        !            44:        char prm[BUFSIZ];
        !            45:        char syspart[8], rest[MAXFULLNAME];
        !            46:        char xsys[8], local[8];
        !            47:        FILE *fprx, *fpc, *fpd, *fp;
        !            48:        FILE *xqtstr();
        !            49:        extern char *getprm(), *index(), *lastpart();
        !            50:        int uid, ret;
        !            51:        char redir = '\0';
        !            52: 
        !            53:        uucpname(Myname);
        !            54:        Ofn = 1;
        !            55:        Ifn = 0;
        !            56:        while (argc>1 && argv[1][0] == '-') {
        !            57:                switch(argv[1][1]){
        !            58:                case 'p':
        !            59:                case '\0':
        !            60:                        pipein = 1;
        !            61:                        break;
        !            62:                case 'r':
        !            63:                        startjob = 0;
        !            64:                        break;
        !            65:                case 'x':
        !            66:                        Debug = atoi(&argv[1][2]);
        !            67:                        if (Debug <= 0)
        !            68:                                Debug = 1;
        !            69:                        break;
        !            70:                default:
        !            71:                        sprintf(stderr, "unknown flag %s\n", argv[1]);
        !            72:                                break;
        !            73:                }
        !            74:                --argc;  argv++;
        !            75:        }
        !            76: 
        !            77:        DEBUG(4, "\n\n** %s **\n", "START");
        !            78: 
        !            79:        inargs[0] = '\0';
        !            80:        for (argv++; argc > 1; argc--) {
        !            81:                DEBUG(4, "arg - %s:", *argv);
        !            82:                strcat(inargs, " ");
        !            83:                strcat(inargs, *argv++);
        !            84:        }
        !            85:        DEBUG(4, "arg - %s\n", inargs);
        !            86:        ret = gwd(Wrkdir);
        !            87:        if (ret != 0) {
        !            88:                fprintf(stderr, "can't get working directory; will try to continue\n");
        !            89:                strcpy(Wrkdir, "/UNKNOWN");
        !            90:        }
        !            91:        chdir(Spool);
        !            92:        uid = getuid();
        !            93:        guinfo(uid, User, path);
        !            94: 
        !            95:        sprintf(local, "%.7s", Myname);
        !            96:        cmdp = cmd;
        !            97:        *cmdp = '\0';
        !            98:        gename(DATAPRE, local, 'X', rxfile);
        !            99:        fprx = fopen(rxfile, "w");
        !           100:        ASSERT(fprx != NULL, "CAN'T OPEN %s", rxfile);
        !           101:        chmod(rxfile, 0666);
        !           102:        gename(DATAPRE, local, 'T', tcfile);
        !           103:        fpc = fopen(tcfile, "w");
        !           104:        ASSERT(fpc != NULL, "CAN'T OPEN %s", tcfile);
        !           105:        chmod(tcfile, 0666);
        !           106:        fprintf(fprx, "%c %s %s\n", X_USER, User, local);
        !           107: 
        !           108:        /* find remote system name */
        !           109:        ap = inargs;
        !           110:        while ((ap = getprm(ap, prm)) != NULL) {
        !           111:                if (prm[0] == '>' || prm[0] == '<') {
        !           112:                        ap = getprm(ap, prm);
        !           113:                        continue;
        !           114:                }
        !           115: 
        !           116:                if (prm[0] == ';') {
        !           117:                        APPCMD(prm);
        !           118:                        continue;
        !           119:                }
        !           120: 
        !           121:                split(prm, xsys, rest);
        !           122:                if (xsys[0] == '\0')
        !           123:                        strcpy(xsys, local);
        !           124:                break;
        !           125:        }
        !           126:        DEBUG(4, "xsys %s\n", xsys);
        !           127:        if (versys(xsys) != 0) {
        !           128:                /*  bad system name  */
        !           129:                fprintf(stderr, "bad system name: %s\n", xsys);
        !           130:                fclose(fprx);
        !           131:                fclose(fpc);
        !           132:                unlink(rxfile);
        !           133:                unlink(tcfile);
        !           134:                cleanup(101);
        !           135:        }
        !           136: 
        !           137:        if (pipein) {
        !           138:                register int c;
        !           139: 
        !           140:                gename(DATAPRE, xsys, 'B', dfile);
        !           141:                fpd = fopen(dfile, "w");
        !           142:                ASSERT(fpd != NULL, "CAN'T OPEN %s", dfile);
        !           143:                chmod(dfile, 0666);
        !           144:                while ((c = getc(stdin)) != EOF)
        !           145:                        putc(c, fpd);
        !           146: #ifdef notdef
        !           147:                while (fgets(buf, BUFSIZ, stdin) != NULL)
        !           148:                        fputs(buf, fpd);
        !           149: #endif
        !           150:                fclose(fpd);
        !           151:                if (strcmp(local, xsys) != SAME) {
        !           152:                        GENSEND(fpc, dfile, dfile, User, dfile);
        !           153:                        cflag++;
        !           154:                }
        !           155:                fprintf(fprx, "%c %s\n", X_RQDFILE, dfile);
        !           156:                fprintf(fprx, "%c %s\n", X_STDIN, dfile);
        !           157:        }
        !           158:        /* parse command */
        !           159:        ap = inargs;
        !           160:        while ((ap = getprm(ap, prm)) != NULL) {
        !           161:                DEBUG(4, "prm - %s\n", prm);
        !           162:                if (prm[0] == '>' || prm[0] == '<') {
        !           163:                        redir = prm[0];
        !           164:                        continue;
        !           165:                }
        !           166: 
        !           167:                if (prm[0] == '|' || prm[0] == '^') {
        !           168:                        if (cmdp != cmd)
        !           169:                                APPCMD(prm);
        !           170:                        continue;
        !           171:                }
        !           172: 
        !           173:                /* process command or file or option */
        !           174:                ret = split(prm, syspart, rest);
        !           175:                DEBUG(4, "s - %s, ", syspart);
        !           176:                DEBUG(4, "r - %s, ", rest);
        !           177:                DEBUG(4, "ret - %d\n", ret);
        !           178:                if (syspart[0] == '\0')
        !           179:                        strcpy(syspart, local);
        !           180: 
        !           181:                if (cmdp == cmd && redir == '\0') {
        !           182:                        /* command */
        !           183:                        APPCMD(rest);
        !           184:                        continue;
        !           185:                }
        !           186: 
        !           187:                /* process file or option */
        !           188:                DEBUG(4, "file s- %s, ", syspart);
        !           189:                DEBUG(4, "local - %s\n", local);
        !           190:                /* process file */
        !           191:                if (redir == '>') {
        !           192:                        if (rest[0] != '~')
        !           193:                                expfile(rest);
        !           194:                        fprintf(fprx, "%c %s %s\n", X_STDOUT, rest,
        !           195:                         syspart);
        !           196:                        redir = '\0';
        !           197:                        continue;
        !           198:                }
        !           199: 
        !           200:                if (ret == NOSYSPART) {
        !           201:                        /* option */
        !           202:                        APPCMD(rest);
        !           203:                        continue;
        !           204:                }
        !           205: 
        !           206:                if (strcmp(xsys, local) == SAME
        !           207:                 && strcmp(xsys, syspart) == SAME) {
        !           208:                        expfile(rest);
        !           209:                        if (redir == '<')
        !           210:                                fprintf(fprx, "%c %s\n", X_STDIN, rest);
        !           211:                        else
        !           212:                                APPCMD(rest);
        !           213:                        redir = '\0';
        !           214:                        continue;
        !           215:                }
        !           216: 
        !           217:                if (strcmp(syspart, local) == SAME) {
        !           218:                        /*  generate send file */
        !           219:                        expfile(rest);
        !           220:                        gename(DATAPRE, xsys, 'A', dfile);
        !           221:                        DEBUG(4, "rest %s\n", rest);
        !           222:                        if ((chkpth(User, "", rest) || anyread(rest)) != 0) {
        !           223:                                fprintf(stderr, "permission denied %s\n", rest);
        !           224:                                cleanup(1);
        !           225:                        }
        !           226:                        if (xcp(rest, dfile) != 0) {
        !           227:                                fprintf(stderr, "can't copy %s to %s\n", rest, dfile);
        !           228:                                cleanup(1);
        !           229:                        }
        !           230:                        GENSEND(fpc, rest, dfile, User, dfile);
        !           231:                        cflag++;
        !           232:                        if (redir == '<') {
        !           233:                                fprintf(fprx, "%c %s\n", X_STDIN, dfile);
        !           234:                                fprintf(fprx, "%c %s\n", X_RQDFILE, dfile);
        !           235:                        }
        !           236:                        else {
        !           237:                                APPCMD(lastpart(rest));
        !           238:                                fprintf(fprx, "%c %s %s\n", X_RQDFILE,
        !           239:                                 dfile, lastpart(rest));
        !           240:                        }
        !           241:                        redir = '\0';
        !           242:                        continue;
        !           243:                }
        !           244: 
        !           245:                if (strcmp(local, xsys) == SAME) {
        !           246:                        /*  generate local receive  */
        !           247:                        gename(CMDPRE, syspart, 'R', tfile);
        !           248:                        strcpy(dfile, tfile);
        !           249:                        dfile[0] = DATAPRE;
        !           250:                        fp = fopen(tfile, "w");
        !           251:                        ASSERT(fp != NULL, "CAN'T OPEN %s", tfile);
        !           252:                        chmod(tfile, 0666);
        !           253:                        expfile(rest);
        !           254:                        GENRCV(fp, rest, dfile, User);
        !           255:                        fclose(fp);
        !           256:                        rflag++;
        !           257:                        if (rest[0] != '~')
        !           258:                                expfile(rest);
        !           259:                        if (redir == '<') {
        !           260:                                fprintf(fprx, "%c %s\n", X_RQDFILE, dfile);
        !           261:                                fprintf(fprx, "%c %s\n", X_STDIN, dfile);
        !           262:                        }
        !           263:                        else {
        !           264:                                fprintf(fprx, "%c %s %s\n", X_RQDFILE, dfile,
        !           265:                                  lastpart(rest));
        !           266:                                APPCMD(lastpart(rest));
        !           267:                        }
        !           268: 
        !           269:                        redir = '\0';
        !           270:                        continue;
        !           271:                }
        !           272: 
        !           273:                if (strcmp(syspart, xsys) != SAME) {
        !           274:                        /* generate remote receives */
        !           275:                        gename(DATAPRE, syspart, 'R', dfile);
        !           276:                        strcpy(tfile, dfile);
        !           277:                        tfile[0] = CMDPRE;
        !           278:                        fpd = fopen(dfile, "w");
        !           279:                        ASSERT(fpd != NULL, "CAN'T OPEN %s", dfile);
        !           280:                        chmod(dfile, 0666);
        !           281:                        gename(DATAPRE, xsys, 'T', t2file);
        !           282:                        GENRCV(fpd, rest, t2file, User);
        !           283:                        fclose(fpd);
        !           284:                        GENSEND(fpc, dfile, tfile, User, dfile);
        !           285:                        cflag++;
        !           286:                        if (redir == '<') {
        !           287:                                fprintf(fprx, "%c %s\n", X_RQDFILE, t2file);
        !           288:                                fprintf(fprx, "%c %s\n", X_STDIN, t2file);
        !           289:                        }
        !           290:                        else {
        !           291:                                fprintf(fprx, "%c %s %s\n", X_RQDFILE, t2file,
        !           292:                                  lastpart(rest));
        !           293:                                APPCMD(lastpart(rest));
        !           294:                        }
        !           295:                        redir = '\0';
        !           296:                        continue;
        !           297:                }
        !           298: 
        !           299:                /* file on remote system */
        !           300:                if (rest[0] != '~')
        !           301:                        expfile(rest);
        !           302:                if (redir == '<')
        !           303:                        fprintf(fprx, "%c %s\n", X_STDIN, rest);
        !           304:                else
        !           305:                        APPCMD(rest);
        !           306:                redir = '\0';
        !           307:                continue;
        !           308: 
        !           309:        }
        !           310: 
        !           311:        fprintf(fprx, "%c %s\n", X_CMD, cmd);
        !           312:        fclose(fprx);
        !           313: 
        !           314:        strcpy(tfile, rxfile);
        !           315:        tfile[0] = XQTPRE;
        !           316:        if (strcmp(xsys, local) == SAME) {
        !           317:                link(rxfile, tfile);
        !           318:                unlink(rxfile);
        !           319:                if (startjob)
        !           320:                        if (rflag)
        !           321:                                xuucico("");
        !           322:                        else
        !           323:                                xuuxqt();
        !           324:        }
        !           325:        else {
        !           326:                GENSEND(fpc, rxfile, tfile, User, rxfile);
        !           327:                cflag++;
        !           328:        }
        !           329: 
        !           330:        fclose(fpc);
        !           331:        if (cflag) {
        !           332:                gename(CMDPRE, xsys, 'A', cfile);
        !           333:                link(tcfile, cfile);
        !           334:                unlink(tcfile);
        !           335:                if (startjob)
        !           336:                        xuucico(xsys);
        !           337:                cleanup(0);
        !           338:        }
        !           339:        else
        !           340:                unlink(tcfile);
        !           341: }
        !           342: 
        !           343: 
        !           344: cleanup(code)
        !           345: int code;
        !           346: {
        !           347:        rmlock(NULL);
        !           348:        DEBUG(1, "exit code %d\n", code);
        !           349:        exit(code);
        !           350: }

unix.superglobalmegacorp.com

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