|
|
1.1 ! root 1: /* main.c -- driver for the client program */ ! 2: ! 3: /* ! 4: * $Header: /f/osi/others/idist/RCS/main.c,v 7.0 89/11/23 21:58:37 mrose Rel $ ! 5: * ! 6: * Major changes to this file have been the ripping out of the server ! 7: * code. This is entirely the client part now. Also changed are the ! 8: * argument parsing stuff and a few bits and pieces. ! 9: * ! 10: * Julian Onions <[email protected]> ! 11: * Nottingham University Computer Science. ! 12: * ! 13: * ! 14: * $Log: main.c,v $ ! 15: * Revision 7.0 89/11/23 21:58:37 mrose ! 16: * Release 6.0 ! 17: * ! 18: */ ! 19: ! 20: ! 21: /* ! 22: * Copyright (c) 1983 Regents of the University of California. ! 23: * All rights reserved. The Berkeley software License Agreement ! 24: * specifies the terms and conditions for redistribution. ! 25: */ ! 26: ! 27: #ifndef lint ! 28: char copyright[] = ! 29: "@(#) Copyright (c) 1983 Regents of the University of California.\n\ ! 30: All rights reserved.\n"; ! 31: #endif ! 32: ! 33: #ifndef lint ! 34: static char sccsid[] = "@(#)main.c 5.1 (Berkeley) 6/6/85"; ! 35: static char *rcsid = "$Header: /f/osi/others/idist/RCS/main.c,v 7.0 89/11/23 21:58:37 mrose Rel $"; ! 36: #endif ! 37: ! 38: #include "defs.h" ! 39: ! 40: #define NHOSTS 100 ! 41: ! 42: /* ! 43: * Remote distribution program. ! 44: * ! 45: * -u option (controlled by "#ifdef UW") to update only (don't install ! 46: * the file, assuming the workstation owner doesn't want that file) ! 47: */ ! 48: ! 49: char *distfile = NULL; ! 50: char utmpfile[] = "/tmp/idistXXXXXX"; ! 51: char *tmpname = &utmpfile[5]; ! 52: ! 53: int debug; /* debugging flag */ ! 54: int nflag; /* NOP flag, just print commands without executing */ ! 55: int qflag; /* Quiet. Don't print messages */ ! 56: int options; /* global options */ ! 57: int iamremote; /* act as remote server for transfering files */ ! 58: ! 59: FILE *fin = NULL; /* input file pointer */ ! 60: char *host; /* host name */ ! 61: int nerrs; /* number of errors while sending/receiving */ ! 62: char user[10]; /* user's name */ ! 63: char homedir[128]; /* user's home directory */ ! 64: int userid; /* user's user ID */ ! 65: int groupid; /* user's group ID */ ! 66: ! 67: struct passwd *pw; /* pointer to static area used by getpwent */ ! 68: struct group *gr; /* pointer to static area used by getgrent */ ! 69: char *myname = "idist"; ! 70: ! 71: main(argc, argv) ! 72: int argc; ! 73: char *argv[]; ! 74: { ! 75: int cmdargs = 0; ! 76: char *dhosts[NHOSTS], **hp = dhosts; ! 77: extern int optind; ! 78: extern char *optarg; ! 79: int opt; ! 80: ! 81: if (myname = rindex (argv[0], '/')) ! 82: myname++; ! 83: if (myname == NULL || *myname == NULL) ! 84: myname = argv[0]; ! 85: ! 86: isodetailor (myname, 1); ! 87: ! 88: pw = getpwuid(userid = getuid()); ! 89: if (pw == NULL) ! 90: adios (NULLCP, "Who are you?"); ! 91: ! 92: (void) strcpy(user, pw->pw_name); ! 93: (void) strcpy(homedir, pw->pw_dir); ! 94: groupid = pw->pw_gid; ! 95: host = getlocalhost (); ! 96: ! 97: while ((opt = getopt (argc, argv, "f:m:d:DcnqbuRvwyhiQ")) != EOF) ! 98: switch (opt) { ! 99: case 'f': ! 100: distfile = optarg; ! 101: if (distfile[0] == '-' && distfile[1] == '\0') ! 102: fin = stdin; ! 103: break; ! 104: ! 105: case 'm': ! 106: if (hp >= &dhosts[NHOSTS-2]) ! 107: adios (NULLCP, "too many destination hosts"); ! 108: *hp++ = optarg; ! 109: break; ! 110: ! 111: case 'd': ! 112: define(optarg); ! 113: break; ! 114: ! 115: case 'D': ! 116: debug++; ! 117: break; ! 118: ! 119: case 'c': ! 120: cmdargs++; ! 121: break; ! 122: ! 123: case 'n': ! 124: if (options & VERIFY) { ! 125: advise (NULLCP, "-n overrides -v"); ! 126: options &= ~VERIFY; ! 127: } ! 128: nflag++; ! 129: break; ! 130: ! 131: case 'q': ! 132: qflag++; ! 133: break; ! 134: ! 135: case 'b': ! 136: options |= COMPARE; ! 137: break; ! 138: #ifdef UW ! 139: case 'u': ! 140: options |= NOINSTALL; ! 141: break; ! 142: #endif UW ! 143: case 'R': ! 144: options |= REMOVE; ! 145: break; ! 146: ! 147: case 'v': ! 148: if (nflag) { ! 149: advise (NULLCP, "-n overrides -v"); ! 150: break; ! 151: } ! 152: options |= VERIFY; ! 153: break; ! 154: ! 155: case 'w': ! 156: options |= WHOLE; ! 157: break; ! 158: ! 159: case 'y': ! 160: options |= YOUNGER; ! 161: break; ! 162: ! 163: case 'h': ! 164: options |= FOLLOW; ! 165: break; ! 166: ! 167: case 'i': ! 168: options |= IGNLNKS; ! 169: break; ! 170: ! 171: case 'Q': ! 172: options |= QUERYM; ! 173: break; ! 174: ! 175: default: ! 176: usage(); ! 177: break; ! 178: } ! 179: *hp = NULL; ! 180: argc -= optind; ! 181: argv += optind; ! 182: ! 183: (void) mktemp(utmpfile); ! 184: ! 185: if (cmdargs) ! 186: docmdargs(argc, argv); ! 187: else { ! 188: if (fin == NULL) { ! 189: if(distfile == NULL) { ! 190: if((fin = fopen("distfile","r")) == NULL) ! 191: fin = fopen("Distfile", "r"); ! 192: } else ! 193: fin = fopen(distfile, "r"); ! 194: if(fin == NULL) { ! 195: adios (distfile, "Can't open file"); ! 196: } ! 197: } ! 198: (void) yyparse(); ! 199: if (nerrs == 0) ! 200: docmds(dhosts, argc, argv); ! 201: } ! 202: ! 203: exit(nerrs != 0); ! 204: } ! 205: ! 206: usage() ! 207: { ! 208: advise (NULLCP, ! 209: "Usage: %s [-nqbhirvwyD] [-f distfile] [-d var=value] [-m host] [file ...]\n", ! 210: myname); ! 211: adios(NULLCP, "or: %s [-nqbhirvwyD] -c source [...] machine[:dest]\n", ! 212: myname); ! 213: } ! 214: ! 215: /* ! 216: * rcp like interface for distributing files. ! 217: */ ! 218: docmdargs(nargs, args) ! 219: int nargs; ! 220: char *args[]; ! 221: { ! 222: register struct namelist *nl, *prev; ! 223: register char *cp; ! 224: struct namelist *files, *hosts; ! 225: struct subcmd *cmds; ! 226: char *dest; ! 227: static struct namelist tnl = { NULL, NULL }; ! 228: int i; ! 229: ! 230: if (nargs < 2) ! 231: usage(); ! 232: ! 233: prev = NULL; ! 234: for (i = 0; i < nargs - 1; i++) { ! 235: nl = makenl(args[i]); ! 236: if (prev == NULL) ! 237: files = prev = nl; ! 238: else { ! 239: prev->n_next = nl; ! 240: prev = nl; ! 241: } ! 242: } ! 243: ! 244: cp = args[i]; ! 245: if ((dest = index(cp, ':')) != NULL) ! 246: *dest++ = '\0'; ! 247: tnl.n_name = cp; ! 248: hosts = expand(&tnl, E_ALL); ! 249: if (nerrs) ! 250: exit(1); ! 251: ! 252: if (dest == NULL || *dest == '\0') ! 253: cmds = NULL; ! 254: else { ! 255: cmds = makesubcmd(INSTALL); ! 256: cmds->sc_options = options; ! 257: cmds->sc_name = dest; ! 258: } ! 259: ! 260: if (debug) { ! 261: printf("docmdargs()\nfiles = "); ! 262: prnames(files); ! 263: printf("hosts = "); ! 264: prnames(hosts); ! 265: } ! 266: insert((char *)NULL, files, hosts, cmds); ! 267: docmds((char **)NULL, 0, (char **)NULL); ! 268: } ! 269: ! 270: /* ! 271: * Print a list of NAME blocks (mostly for debugging). ! 272: */ ! 273: prnames(nl) ! 274: register struct namelist *nl; ! 275: { ! 276: printf("( "); ! 277: while (nl != NULL) { ! 278: printf("%s ", nl->n_name); ! 279: nl = nl->n_next; ! 280: } ! 281: printf(")\n"); ! 282: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.