Annotation of 43BSDReno/usr.bin/rdist/main.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1983 Regents of the University of California.
        !             3:  * All rights reserved.
        !             4:  *
        !             5:  * Redistribution and use in source and binary forms are permitted
        !             6:  * provided that: (1) source distributions retain this entire copyright
        !             7:  * notice and comment, and (2) distributions including binaries display
        !             8:  * the following acknowledgement:  ``This product includes software
        !             9:  * developed by the University of California, Berkeley and its contributors''
        !            10:  * in the documentation or other materials provided with the distribution
        !            11:  * and in all advertising materials mentioning features or use of this
        !            12:  * software. Neither the name of the University nor the names of its
        !            13:  * contributors may be used to endorse or promote products derived
        !            14:  * from this software without specific prior written permission.
        !            15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
        !            16:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
        !            17:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            18:  */
        !            19: 
        !            20: #ifndef lint
        !            21: char copyright[] =
        !            22: "@(#) Copyright (c) 1983 Regents of the University of California.\n\
        !            23:  All rights reserved.\n";
        !            24: #endif /* not lint */
        !            25: 
        !            26: #ifndef lint
        !            27: static char sccsid[] = "@(#)main.c     5.5 (Berkeley) 6/1/90";
        !            28: #endif /* not lint */
        !            29: 
        !            30: #include "defs.h"
        !            31: 
        !            32: #define NHOSTS 100
        !            33: 
        !            34: /*
        !            35:  * Remote distribution program.
        !            36:  */
        !            37: 
        !            38: char   *distfile = NULL;
        !            39: char   tmpfile[] = _PATH_TMP;
        !            40: char   *tmpname = &tmpfile[5];
        !            41: 
        !            42: int    debug;          /* debugging flag */
        !            43: int    nflag;          /* NOP flag, just print commands without executing */
        !            44: int    qflag;          /* Quiet. Don't print messages */
        !            45: int    options;        /* global options */
        !            46: int    iamremote;      /* act as remote server for transfering files */
        !            47: 
        !            48: FILE   *fin = NULL;    /* input file pointer */
        !            49: int    rem = -1;       /* file descriptor to remote source/sink process */
        !            50: char   host[32];       /* host name */
        !            51: int    nerrs;          /* number of errors while sending/receiving */
        !            52: char   user[10];       /* user's name */
        !            53: char   homedir[128];   /* user's home directory */
        !            54: int    userid;         /* user's user ID */
        !            55: int    groupid;        /* user's group ID */
        !            56: 
        !            57: struct passwd *pw;     /* pointer to static area used by getpwent */
        !            58: struct group *gr;      /* pointer to static area used by getgrent */
        !            59: 
        !            60: main(argc, argv)
        !            61:        int argc;
        !            62:        char *argv[];
        !            63: {
        !            64:        register char *arg;
        !            65:        int cmdargs = 0;
        !            66:        char *dhosts[NHOSTS], **hp = dhosts;
        !            67: 
        !            68:        pw = getpwuid(userid = getuid());
        !            69:        if (pw == NULL) {
        !            70:                fprintf(stderr, "%s: Who are you?\n", argv[0]);
        !            71:                exit(1);
        !            72:        }
        !            73:        strcpy(user, pw->pw_name);
        !            74:        strcpy(homedir, pw->pw_dir);
        !            75:        groupid = pw->pw_gid;
        !            76:        gethostname(host, sizeof(host));
        !            77: 
        !            78:        while (--argc > 0) {
        !            79:                if ((arg = *++argv)[0] != '-')
        !            80:                        break;
        !            81:                if (!strcmp(arg, "-Server"))
        !            82:                        iamremote++;
        !            83:                else while (*++arg)
        !            84:                        switch (*arg) {
        !            85:                        case 'f':
        !            86:                                if (--argc <= 0)
        !            87:                                        usage();
        !            88:                                distfile = *++argv;
        !            89:                                if (distfile[0] == '-' && distfile[1] == '\0')
        !            90:                                        fin = stdin;
        !            91:                                break;
        !            92: 
        !            93:                        case 'm':
        !            94:                                if (--argc <= 0)
        !            95:                                        usage();
        !            96:                                if (hp >= &dhosts[NHOSTS-2]) {
        !            97:                                        fprintf(stderr, "rdist: too many destination hosts\n");
        !            98:                                        exit(1);
        !            99:                                }
        !           100:                                *hp++ = *++argv;
        !           101:                                break;
        !           102: 
        !           103:                        case 'd':
        !           104:                                if (--argc <= 0)
        !           105:                                        usage();
        !           106:                                define(*++argv);
        !           107:                                break;
        !           108: 
        !           109:                        case 'D':
        !           110:                                debug++;
        !           111:                                break;
        !           112: 
        !           113:                        case 'c':
        !           114:                                cmdargs++;
        !           115:                                break;
        !           116: 
        !           117:                        case 'n':
        !           118:                                if (options & VERIFY) {
        !           119:                                        printf("rdist: -n overrides -v\n");
        !           120:                                        options &= ~VERIFY;
        !           121:                                }
        !           122:                                nflag++;
        !           123:                                break;
        !           124: 
        !           125:                        case 'q':
        !           126:                                qflag++;
        !           127:                                break;
        !           128: 
        !           129:                        case 'b':
        !           130:                                options |= COMPARE;
        !           131:                                break;
        !           132: 
        !           133:                        case 'R':
        !           134:                                options |= REMOVE;
        !           135:                                break;
        !           136: 
        !           137:                        case 'v':
        !           138:                                if (nflag) {
        !           139:                                        printf("rdist: -n overrides -v\n");
        !           140:                                        break;
        !           141:                                }
        !           142:                                options |= VERIFY;
        !           143:                                break;
        !           144: 
        !           145:                        case 'w':
        !           146:                                options |= WHOLE;
        !           147:                                break;
        !           148: 
        !           149:                        case 'y':
        !           150:                                options |= YOUNGER;
        !           151:                                break;
        !           152: 
        !           153:                        case 'h':
        !           154:                                options |= FOLLOW;
        !           155:                                break;
        !           156: 
        !           157:                        case 'i':
        !           158:                                options |= IGNLNKS;
        !           159:                                break;
        !           160: 
        !           161:                        default:
        !           162:                                usage();
        !           163:                        }
        !           164:        }
        !           165:        *hp = NULL;
        !           166: 
        !           167:        setreuid(0, userid);
        !           168:        mktemp(tmpfile);
        !           169: 
        !           170:        if (iamremote) {
        !           171:                server();
        !           172:                exit(nerrs != 0);
        !           173:        }
        !           174: 
        !           175:        if (cmdargs)
        !           176:                docmdargs(argc, argv);
        !           177:        else {
        !           178:                if (fin == NULL) {
        !           179:                        if(distfile == NULL) {
        !           180:                                if((fin = fopen("distfile","r")) == NULL)
        !           181:                                        fin = fopen("Distfile", "r");
        !           182:                        } else
        !           183:                                fin = fopen(distfile, "r");
        !           184:                        if(fin == NULL) {
        !           185:                                perror(distfile ? distfile : "distfile");
        !           186:                                exit(1);
        !           187:                        }
        !           188:                }
        !           189:                yyparse();
        !           190:                if (nerrs == 0)
        !           191:                        docmds(dhosts, argc, argv);
        !           192:        }
        !           193: 
        !           194:        exit(nerrs != 0);
        !           195: }
        !           196: 
        !           197: usage()
        !           198: {
        !           199:        printf("Usage: rdist [-nqbhirvwyD] [-f distfile] [-d var=value] [-m host] [file ...]\n");
        !           200:        printf("or: rdist [-nqbhirvwyD] -c source [...] machine[:dest]\n");
        !           201:        exit(1);
        !           202: }
        !           203: 
        !           204: /*
        !           205:  * rcp like interface for distributing files.
        !           206:  */
        !           207: docmdargs(nargs, args)
        !           208:        int nargs;
        !           209:        char *args[];
        !           210: {
        !           211:        register struct namelist *nl, *prev;
        !           212:        register char *cp;
        !           213:        struct namelist *files, *hosts;
        !           214:        struct subcmd *cmds;
        !           215:        char *dest;
        !           216:        static struct namelist tnl = { NULL, NULL };
        !           217:        int i;
        !           218: 
        !           219:        if (nargs < 2)
        !           220:                usage();
        !           221: 
        !           222:        prev = NULL;
        !           223:        for (i = 0; i < nargs - 1; i++) {
        !           224:                nl = makenl(args[i]);
        !           225:                if (prev == NULL)
        !           226:                        files = prev = nl;
        !           227:                else {
        !           228:                        prev->n_next = nl;
        !           229:                        prev = nl;
        !           230:                }
        !           231:        }
        !           232: 
        !           233:        cp = args[i];
        !           234:        if ((dest = index(cp, ':')) != NULL)
        !           235:                *dest++ = '\0';
        !           236:        tnl.n_name = cp;
        !           237:        hosts = expand(&tnl, E_ALL);
        !           238:        if (nerrs)
        !           239:                exit(1);
        !           240: 
        !           241:        if (dest == NULL || *dest == '\0')
        !           242:                cmds = NULL;
        !           243:        else {
        !           244:                cmds = makesubcmd(INSTALL);
        !           245:                cmds->sc_options = options;
        !           246:                cmds->sc_name = dest;
        !           247:        }
        !           248: 
        !           249:        if (debug) {
        !           250:                printf("docmdargs()\nfiles = ");
        !           251:                prnames(files);
        !           252:                printf("hosts = ");
        !           253:                prnames(hosts);
        !           254:        }
        !           255:        insert(NULL, files, hosts, cmds);
        !           256:        docmds(NULL, 0, NULL);
        !           257: }
        !           258: 
        !           259: /*
        !           260:  * Print a list of NAME blocks (mostly for debugging).
        !           261:  */
        !           262: prnames(nl)
        !           263:        register struct namelist *nl;
        !           264: {
        !           265:        printf("( ");
        !           266:        while (nl != NULL) {
        !           267:                printf("%s ", nl->n_name);
        !           268:                nl = nl->n_next;
        !           269:        }
        !           270:        printf(")\n");
        !           271: }
        !           272: 
        !           273: /*VARARGS*/
        !           274: warn(fmt, a1, a2,a3)
        !           275:        char *fmt;
        !           276: {
        !           277:        extern int yylineno;
        !           278: 
        !           279:        fprintf(stderr, "rdist: line %d: Warning: ", yylineno);
        !           280:        fprintf(stderr, fmt, a1, a2, a3);
        !           281:        fputc('\n', stderr);
        !           282: }

unix.superglobalmegacorp.com

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