2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * @(#) Copyright (c) 1983, 1993 The Regents of the University of California. All rights reserved.
30 * @(#)main.c 8.1 (Berkeley) 6/9/93
31 * $FreeBSD: src/usr.bin/rdist/main.c,v 1.5 1999/08/28 01:05:07 peter Exp $
34 * Remote distribution program.
42 #define _RDIST_TMP "/rdistXXXXXX"
44 char *distfile = NULL;
45 char tempfile[sizeof _PATH_TMP + sizeof _RDIST_TMP + 1];
48 int debug; /* debugging flag */
49 int nflag; /* NOP flag, just print commands without executing */
50 int qflag; /* Quiet. Don't print messages */
51 int options; /* global options */
52 int iamremote; /* act as remote server for transfering files */
54 FILE *fin = NULL; /* input file pointer */
55 int rem = -1; /* file descriptor to remote source/sink process */
56 char host[32]; /* host name */
57 int nerrs; /* number of errors while sending/receiving */
58 char user[10]; /* user's name */
59 char homedir[128]; /* user's home directory */
60 int userid; /* user's user ID */
61 int groupid; /* user's group ID */
62 char *path_rsh = _PATH_RSH; /* rsh (or equiv command) path */
64 struct passwd *pw; /* pointer to static area used by getpwent */
65 struct group *gr; /* pointer to static area used by getgrent */
67 static void usage(void);
68 static void docmdargs(int, char *[]);
71 main(int argc, char **argv)
75 char *dhosts[NHOSTS], **hp = dhosts;
79 pw = getpwuid(userid = getuid());
81 fprintf(stderr, "%s: Who are you?\n", argv[0]);
84 strcpy(user, pw->pw_name);
85 strcpy(homedir, pw->pw_dir);
87 gethostname(host, sizeof(host));
88 strcpy(tempfile, _PATH_TMP);
89 strcat(tempfile, _RDIST_TMP);
90 if ((tempname = rindex(tempfile, '/')) != NULL)
96 if ((arg = *++argv)[0] != '-')
98 if (!strcmp(arg, "-Server"))
112 if (distfile[0] == '-' && distfile[1] == '\0')
119 if (hp >= &dhosts[NHOSTS-2]) {
120 fprintf(stderr, "rdist: too many destination hosts\n");
141 if (options & VERIFY) {
142 printf("rdist: -n overrides -v\n");
162 printf("rdist: -n overrides -v\n");
199 docmdargs(argc, argv);
202 if(distfile == NULL) {
203 if((fin = fopen("distfile","r")) == NULL)
204 fin = fopen("Distfile", "r");
206 fin = fopen(distfile, "r");
208 perror(distfile ? distfile : "distfile");
214 docmds(dhosts, argc, argv);
223 printf("%s\n%s\n%s\n",
224 "usage: rdist [-nqbhirvwyD] [-P /path/to/rsh ] [-f distfile] [-d var=value]",
225 " [-m host] [file ...]",
226 " rdist [-nqbhirvwyD] [-P /path/to/rsh ] -c source [...] machine[:dest]");
231 * rcp like interface for distributing files.
234 docmdargs(int nargs, char **args)
236 struct namelist *nl, *prev;
238 struct namelist *files, *hosts;
241 static struct namelist tnl = { NULL, NULL };
250 for (i = 0; i < nargs - 1; i++) {
251 nl = makenl(args[i]);
261 if ((dest = index(cp, ':')) != NULL)
264 hosts = expand(&tnl, E_ALL);
268 if (dest == NULL || *dest == '\0')
271 cmds = makesubcmd(INSTALL);
272 cmds->sc_options = options;
273 cmds->sc_name = dest;
277 printf("docmdargs()\nfiles = ");
282 insert(NULL, files, hosts, cmds);
283 docmds(NULL, 0, NULL);
287 * Print a list of NAME blocks (mostly for debugging).
290 prnames(struct namelist *nl)
294 printf("%s ", nl->n_name);