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

Defined functions

docmdargs defined in line 194; used 1 times
main defined in line 47; never used
prnames defined in line 249; used 5 times
usage defined in line 184; used 5 times
warn defined in line 261; never used

Defined variables

copyright defined in line 8; never used
distfile defined in line 25; used 7 times
gr defined in line 45; used 14 times
groupid defined in line 42; used 1 times
  • in line 62
homedir defined in line 40; used 1 times
  • in line 61
host defined in line 37; used 26 times
iamremote defined in line 33; used 10 times
nerrs defined in line 38; used 15 times
nflag defined in line 30; used 14 times
options defined in line 32; used 30 times
pw defined in line 44; used 29 times
qflag defined in line 31; used 6 times
rem defined in line 36; used 53 times
sccsid defined in line 14; never used
tmpfile defined in line 26; used 12 times
tmpname defined in line 27; never used
user defined in line 39; used 1 times
  • in line 60
userid defined in line 41; used 2 times

Defined macros

NHOSTS defined in line 19; used 2 times
Last modified: 1985-06-06
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1373
Valid CSS Valid XHTML 1.0 Strict