# 2.11BSD#431 - /usr/src/ucb/rdist/main.c

##### Functions

    docmdargs         X
    main              X
    prnames           X
    usage             X

##### Variables

    copyright         X
    debug             X
    distfile          X
    gr                X
    groupid           X
    homedir           X
    host              X
    iamremote         X
    nerrs             X
    nflag             X
    options           X
    pw                X
    qflag             X
    rem               X
    tempfile          X
    tempname          X
    user              X
    userid            X

##### Macros

    NHOSTS            X
    _RDIST_TMP        X

       1: /*
       2:  * Copyright (c) 1983 Regents of the University of California.
       3:  * All rights reserved.  The Berkeley software License Agreement
       4:  * specifies the terms and conditions for redistribution.
       5:  */
       6:
       7: #if !defined(lint) && defined(DOSCCS)
       8: char copyright[] =
       9: "@(#) Copyright (c) 1983 Regents of the University of California.\n\
      10:  All rights reserved.\n";
      11:
      12: static char sccsid[] = "@(#)main.c	5.1.2 (2.11BSD) 1997/07/03";
      13: #endif
      14:
      15: #include <paths.h>
      16: #include "defs.h"
      17:
      18: #define NHOSTS 100
      19:
      20: /*
      21:  * Remote distribution program.
      22:  */
      23:
      24: char    *distfile = NULL;
      25: #define _RDIST_TMP  "/rdistXXXXXX"
      26: /* Can't use "sizeof (_PATH_TMP) + sizeof (_RDIST_TMP) + 1" because of xstr */
      27: char    tempfile[24];
      28: char    *tempname;
      29:
      30: int debug;      /* debugging flag */
      31: int nflag;      /* NOP flag, just print commands without executing */
      32: int qflag;      /* Quiet. Don't print messages */
      33: int options;    /* global options */
      34: int iamremote;  /* act as remote server for transfering files */
      35:
      36: FILE    *fin = NULL;    /* input file pointer */
      37: int rem = -1;   /* file descriptor to remote source/sink process */
      38: char    host[MAXHOSTNAMELEN];   /* host name */
      39: int nerrs;      /* number of errors while sending/receiving */
      40: char    user[20];   /* user's name */
      41: char    homedir[128];   /* user's home directory */
      42: int userid;     /* user's user ID */
      43: int groupid;    /* user's group ID */
      44:
      45: struct  passwd *pw; /* pointer to static area used by getpwent */
      46: struct  group *gr;  /* pointer to static area used by getgrent */
      47:
      48: main(argc, argv)
      49:     int argc;
      50:     char *argv[];
      51: {
      52:     register char *arg;
      53:     int cmdargs = 0;
      54:     char *dhosts[NHOSTS], **hp = dhosts;
      55:     char ebuf[128], obuf[256], ibuf[256];
      56:
      57:     setbuffer(stdin, ibuf, sizeof ibuf);
      58:     setvbuf(stdout, obuf, _IOLBF, sizeof obuf);
      59:     setvbuf(stderr, ebuf, _IOLBF, sizeof ebuf);
      60:
      61:     pw = getpwuid(userid = getuid());
      62:     if (pw == NULL) {
      63:         fprintf(stderr, "%s: Who are you?\n", argv[0]);
      64:         exit(1);
      65:     }
      66:     strcpy(user, pw->pw_name);
      67:     strcpy(homedir, pw->pw_dir);
      68:     groupid = pw->pw_gid;
      69:     gethostname(host, sizeof(host));
      70:     strcpy(tempfile, _PATH_TMP);
      71:     strcat(tempfile, _RDIST_TMP);
      72:     tempname = rindex(tempfile, '/') + 1;
      73:
      74:     while (--argc > 0) {
      75:         if ((arg = *++argv)[0] != '-')
      76:             break;
      77:         if (!strcmp(arg, "-Server"))
      78:             iamremote++;
      79:         else while (*++arg)
      80:             switch (*arg) {
      81:             case 'f':
      82:                 if (--argc <= 0)
      83:                     usage();
      84:                 distfile = *++argv;
      85:                 if (distfile[0] == '-' && distfile[1] == '\0')
      86:                     fin = stdin;
      87:                 break;
      88:
      89:             case 'm':
      90:                 if (--argc <= 0)
      91:                     usage();
      92:                 if (hp >= &dhosts[NHOSTS-2]) {
      93:                     fprintf(stderr, "rdist: too many destination hosts\n");
      94:                     exit(1);
      95:                 }
      96:                 *hp++ = *++argv;
      97:                 break;
      98:
      99:             case 'd':
     100:                 if (--argc <= 0)
     101:                     usage();
     102:                 define(*++argv);
     103:                 break;
     104:
     105:             case 'D':
     106:                 debug++;
     107:                 break;
     108:
     109:             case 'c':
     110:                 cmdargs++;
     111:                 break;
     112:
     113:             case 'n':
     114:                 if (options & VERIFY) {
     115:                     printf("rdist: -n overrides -v\n");
     116:                     options &= ~VERIFY;
     117:                 }
     118:                 nflag++;
     119:                 break;
     120:
     121:             case 'q':
     122:                 qflag++;
     123:                 break;
     124:
     125:             case 'b':
     126:                 options |= COMPARE;
     127:                 break;
     128:
     129:             case 'R':
     130:                 options |= REMOVE;
     131:                 break;
     132:
     133:             case 'v':
     134:                 if (nflag) {
     135:                     printf("rdist: -n overrides -v\n");
     136:                     break;
     137:                 }
     138:                 options |= VERIFY;
     139:                 break;
     140:
     141:             case 'w':
     142:                 options |= WHOLE;
     143:                 break;
     144:
     145:             case 'y':
     146:                 options |= YOUNGER;
     147:                 break;
     148:
     149:             case 'h':
     150:                 options |= FOLLOW;
     151:                 break;
     152:
     153:             case 'i':
     154:                 options |= IGNLNKS;
     155:                 break;
     156:
     157:             default:
     158:                 usage();
     159:             }
     160:     }
     161:     *hp = NULL;
     162:
     163:     setreuid(0, userid);
     164:     mktemp(tempfile);
     165:
     166:     if (iamremote) {
     167:         server();
     168:         exit(nerrs != 0);
     169:     }
     170:
     171:     if (cmdargs)
     172:         docmdargs(argc, argv);
     173:     else {
     174:         if (fin == NULL) {
     175:             if(distfile == NULL) {
     176:                 if((fin = fopen("distfile","r")) == NULL)
     177:                     fin = fopen("Distfile", "r");
     178:             } else
     179:                 fin = fopen(distfile, "r");
     180:             if(fin == NULL) {
     181:                 perror(distfile ? distfile : "distfile");
     182:                 exit(1);
     183:             }
     184:         }
     185:         yyparse();
     186:         if (nerrs == 0)
     187:             docmds(dhosts, argc, argv);
     188:     }
     189:
     190:     exit(nerrs != 0);
     191: }
     192:
     193: usage()
     194: {
     195:     printf("Usage: rdist [-nqbhirvwyD] [-f distfile] [-d var=value] [-m host] [file ...]\n");
     196:     printf("or: rdist [-nqbhirvwyD] -c source [...] machine[:dest]\n");
     197:     exit(1);
     198: }
     199:
     200: /*
     201:  * rcp like interface for distributing files.
     202:  */
     203: docmdargs(nargs, args)
     204:     int nargs;
     205:     char *args[];
     206: {
     207:     register struct namelist *nl, *prev;
     208:     register char *cp;
     209:     struct namelist *files, *hosts;
     210:     struct subcmd *cmds;
     211:     char *dest;
     212:     static struct namelist tnl = { NULL, NULL };
     213:     int i;
     214:
     215:     if (nargs < 2)
     216:         usage();
     217:
     218:     prev = NULL;
     219:     for (i = 0; i < nargs - 1; i++) {
     220:         nl = makenl(args[i]);
     221:         if (prev == NULL)
     222:             files = prev = nl;
     223:         else {
     224:             prev->n_next = nl;
     225:             prev = nl;
     226:         }
     227:     }
     228:
     229:     cp = args[i];
     230:     if ((dest = index(cp, ':')) != NULL)
     231:         *dest++ = '\0';
     232:     tnl.n_name = cp;
     233:     hosts = expand(&tnl, E_ALL);
     234:     if (nerrs)
     235:         exit(1);
     236:
     237:     if (dest == NULL || *dest == '\0')
     238:         cmds = NULL;
     239:     else {
     240:         cmds = makesubcmd(INSTALL);
     241:         cmds->sc_options = options;
     242:         cmds->sc_name = dest;
     243:     }
     244:
     245:     if (debug) {
     246:         printf("docmdargs()\nfiles = ");
     247:         prnames(files);
     248:         printf("hosts = ");
     249:         prnames(hosts);
     250:     }
     251:     insert(NULL, files, hosts, cmds);
     252:     docmds(NULL, 0, NULL);
     253: }
     254:
     255: /*
     256:  * Print a list of NAME blocks (mostly for debugging).
     257:  */
     258: prnames(nl)
     259:     register struct namelist *nl;
     260: {
     261:     printf("( ");
     262:     while (nl != NULL) {
     263:         printf("%s ", nl->n_name);
     264:         nl = nl->n_next;
     265:     }
     266:     printf(")\n");
     267: }

#### Defined functions

docmdargs defined in line 203; used 1 times

- in line 172

main defined in line 48; never used
prnames defined in line 258; used 5 times

- in line 247-249(2)
- in /usr/src/ucb/rdist/docmd.c line 463
- in /usr/src/ucb/rdist/expand.c line 60, 102

usage defined in line 193; used 5 times

- in line 83, 91, 101, 158, 216

#### Defined variables

copyright defined in line 8; never used
debug defined in line 30; used 34 times

- in line 106, 245
- in /usr/src/ucb/rdist/docmd.c line 92, 174, 209, 247, 305, 316, 362, 414, 546
- in /usr/src/ucb/rdist/expand.c line 58, 100
- in /usr/src/ucb/rdist/lookup.c line 36, 103
- in /usr/src/ucb/rdist/main.c line 106, 245
- in /usr/src/ucb/rdist/server.c line 203, 235, 241, 275, 321, 372, 382, 389, 420, 435, 472, 533, 540, 1075, 1082, 1103, 1446

distfile defined in line 24; used 7 times

- in line 84-85(3), 175-181(4)

gr defined in line 46; used 14 times

- in /usr/src/ucb/rdist/server.c line 256(2), 297-301(4), 1034-1036(3), 1042-1047(5)

groupid defined in line 43; used 1 times

- in line 68

homedir defined in line 41; used 1 times

- in line 67

host defined in line 38; used 26 times

- in line 69(2)
- in /usr/src/ucb/rdist/docmd.c line 511
- in /usr/src/ucb/rdist/main.c line 69(2)
- in /usr/src/ucb/rdist/server.c line 635, 721, 755, 850, 862, 894, 903, 949, 956-966(3), 1019, 1038, 1058, 1167, 1179, 1189, 1243, 1257, 1267, 1277

iamremote defined in line 34; used 10 times

- in line 78, 166
- in /usr/src/ucb/rdist/docmd.c line 259
- in /usr/src/ucb/rdist/main.c line 78, 166
- in /usr/src/ucb/rdist/server.c line 560, 1128, 1390, 1421, 1475

nerrs defined in line 39; used 15 times

- in line 168, 186-190(2), 234
- in /usr/src/ucb/rdist/gram.y line 417
- in /usr/src/ucb/rdist/main.c line 168, 186-190(2), 234
- in /usr/src/ucb/rdist/server.c line 172, 558, 1126, 1387, 1418, 1473

nflag defined in line 31; used 14 times

- in line 118, 134
- in /usr/src/ucb/rdist/docmd.c line 102, 120, 138, 146, 321, 350, 368, 465
- in /usr/src/ucb/rdist/main.c line 118, 134
- in /usr/src/ucb/rdist/server.c line 203, 209

options defined in line 33; used 30 times

- in line 114-116(2), 126-130(2), 138-154(5), 241
- in /usr/src/ucb/rdist/docmd.c line 90, 135, 321, 350, 457
- in /usr/src/ucb/rdist/gram.y line 44, 109-112(2), 153
- in /usr/src/ucb/rdist/main.c line 114-116(2), 126-130(2), 138-154(5), 241
- in /usr/src/ucb/rdist/server.c line 1373

pw defined in line 45; used 29 times

- in line 61-68(5)
- in /usr/src/ucb/rdist/expand.c line 173-174(3), 180, 601-602(3), 611
- in /usr/src/ucb/rdist/main.c line 61-68(5)
- in /usr/src/ucb/rdist/server.c line 255(2), 290-294(4), 1015-1016(3), 1024-1026(2)

qflag defined in line 32; used 6 times

- in line 122
- in /usr/src/ucb/rdist/docmd.c line 198-200(2), 459
- in /usr/src/ucb/rdist/main.c line 122
- in /usr/src/ucb/rdist/server.c line 1369

rem defined in line 37; used 53 times

- in /usr/src/ucb/rdist/docmd.c line 177, 216-225(4), 250-253(4)
- in /usr/src/ucb/rdist/server.c line 18-20(2), 54-61(3), 68, 243, 323, 352, 374, 384-388(2), 422, 437, 450, 474, 542-546(2), 633, 643-648(2), 745, 780, 825, 881, 910, 1084, 1090, 1106-1110(3), 1193-1196(2), 1207-1212(2), 1284, 1338, 1344, 1388, 1419, 1451, 1515-1518(3)

sccsid defined in line 12; never used
tempfile defined in line 27; used 16 times

- in line 70-72(3), 164
- in /usr/src/ucb/rdist/docmd.c line 110-111(2), 145-147(2), 324, 349-351(2)
- in /usr/src/ucb/rdist/main.c line 70-72(3), 164
- in /usr/src/ucb/rdist/server.c line 1493

tempname defined in line 28; used 1 times

- in line 72

user defined in line 40; used 1 times

- in line 66

userid defined in line 42; used 2 times

- in line 61, 163

#### Defined macros

NHOSTS defined in line 18; used 2 times

- in line 54, 92

_RDIST_TMP defined in line 25; used 1 times

- in line 71

Last modified: 1997-07-30 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 1620 |