version 1.15, 2003/05/06 22:10:11 |
version 1.16, 2003/05/14 01:34:35 |
|
|
* SUCH DAMAGE. |
* SUCH DAMAGE. |
*/ |
*/ |
|
|
|
#include "defs.h" |
|
#include "y.tab.h" |
|
|
#ifndef lint |
#ifndef lint |
#if 0 |
#if 0 |
static char RCSid[] = |
static char RCSid[] __attribute__((__unused__)) = |
"$From: rdist.c,v 6.65 1995/12/12 00:20:39 mcooper Exp $"; |
"$From: rdist.c,v 1.6 2001/03/12 18:16:36 kim Exp $"; |
#else |
#else |
static char RCSid[] = |
static char RCSid[] __attribute__((__unused__)) = |
"$OpenBSD$"; |
"$OpenBSD$"; |
#endif |
#endif |
|
|
static char sccsid[] = "@(#)main.c 5.1 (Berkeley) 6/6/85"; |
static char sccsid[] __attribute__((__unused__)) = |
|
"@(#)main.c 5.1 (Berkeley) 6/6/85"; |
|
|
static char copyright[] = |
static char copyright[] __attribute__((__unused__)) = |
"@(#) Copyright (c) 1983 Regents of the University of California.\n\ |
"@(#) Copyright (c) 1983 Regents of the University of California.\n\ |
All rights reserved.\n"; |
All rights reserved.\n"; |
#endif /* not lint */ |
#endif /* not lint */ |
|
|
|
|
#include "defs.h" |
|
#include "y.tab.h" |
|
#include <netdb.h> |
#include <netdb.h> |
#include <sys/ioctl.h> |
#include <sys/ioctl.h> |
|
|
|
|
* Remote distribution program. |
* Remote distribution program. |
*/ |
*/ |
|
|
void docmdargs(int, char **); |
|
void usage(void); |
|
|
|
char *distfile = NULL; /* Name of distfile to use */ |
char *distfile = NULL; /* Name of distfile to use */ |
int maxchildren = MAXCHILDREN; /* Max no of concurrent PIDs */ |
int maxchildren = MAXCHILDREN; /* Max no of concurrent PIDs */ |
int nflag = 0; /* Say without doing */ |
int nflag = 0; /* Say without doing */ |
long min_freespace = 0; /* Min filesys free space */ |
long min_freespace = 0; /* Min filesys free space */ |
long min_freefiles = 0; /* Min filesys free # files */ |
long min_freefiles = 0; /* Min filesys free # files */ |
FILE *fin = NULL; /* Input file pointer */ |
FILE *fin = NULL; /* Input file pointer */ |
struct group *gr = NULL; /* Static area for getgrent */ |
|
char localmsglist[] = "stdout=all:notify=all:syslog=nerror,ferror"; |
char localmsglist[] = "stdout=all:notify=all:syslog=nerror,ferror"; |
char *remotemsglist = NULL; |
char *remotemsglist = NULL; |
char optchars[] = "A:a:bcd:DFf:hil:L:M:m:NnOo:p:P:qRrst:Vvwxy"; |
char optchars[] = "A:a:bcd:DFf:hil:L:M:m:NnOo:p:P:qRrst:Vvwxy"; |
FILE *opendist(); |
|
char *path_rdistd = _PATH_RDISTD; |
char *path_rdistd = _PATH_RDISTD; |
char *path_remsh = NULL; |
char *path_remsh = NULL; |
|
|
|
static void addhostlist(char *, struct namelist **); |
|
static void usage(void); |
|
int main(int, char **, char **); |
|
|
/* |
/* |
* Add a hostname to the host list |
* Add a hostname to the host list |
*/ |
*/ |
static void addhostlist(name, hostlist) |
static void |
char *name; |
addhostlist(char *name, struct namelist **hostlist) |
struct namelist **hostlist; |
|
{ |
{ |
struct namelist *ptr, *new; |
struct namelist *ptr, *new; |
|
|
|
|
} |
} |
|
|
int |
int |
main(argc, argv, envp) |
main(int argc, char **argv, char **envp) |
int argc; |
|
char *argv[]; |
|
char **envp; |
|
{ |
{ |
|
extern char *__progname; |
struct namelist *hostlist = NULL; |
struct namelist *hostlist = NULL; |
int x; |
int x; |
char *cp; |
char *cp; |
int cmdargs = 0; |
int cmdargs = 0; |
int c; |
int c; |
|
|
/* |
progname = __progname; |
* We initialize progname here instead of init() because |
|
* things in msgparseopts() need progname set. |
|
*/ |
|
setprogname(argv); |
|
|
|
if ((cp = msgparseopts(localmsglist, TRUE))) { |
if ((cp = msgparseopts(localmsglist, TRUE)) != NULL) { |
error("Bad builtin log option (%s): %s.", |
error("Bad builtin log option (%s): %s.", |
localmsglist, cp); |
localmsglist, cp); |
usage(); |
usage(); |
} |
} |
|
|
|
if ((cp = getenv("RDIST_OPTIONS")) != NULL) |
|
if (parsedistopts(cp, &options, TRUE)) { |
|
error("Bad dist option environment string \"%s\".", |
|
cp); |
|
exit(1); |
|
} |
|
|
if (init(argc, argv, envp) < 0) |
if (init(argc, argv, envp) < 0) |
exit(1); |
exit(1); |
|
|
|
|
while ((c = getopt(argc, argv, optchars)) != -1) |
while ((c = getopt(argc, argv, optchars)) != -1) |
switch (c) { |
switch (c) { |
case 'l': |
case 'l': |
if ((cp = msgparseopts(optarg, TRUE))) { |
if ((cp = msgparseopts(optarg, TRUE)) != NULL) { |
error("Bad log option \"%s\": %s.", optarg,cp); |
error("Bad log option \"%s\": %s.", optarg,cp); |
usage(); |
usage(); |
} |
} |
|
|
case 'a': |
case 'a': |
case 'M': |
case 'M': |
case 't': |
case 't': |
if (!isdigit(*optarg)) { |
if (!isdigit((unsigned char)*optarg)) { |
error("\"%s\" is not a number.", optarg); |
error("\"%s\" is not a number.", optarg); |
usage(); |
usage(); |
} |
} |
|
|
|
|
case 'D': |
case 'D': |
debug = DM_ALL; |
debug = DM_ALL; |
if ((cp = msgparseopts("stdout=all,debug", TRUE))) { |
if ((cp = msgparseopts("stdout=all,debug", |
|
TRUE)) != NULL) { |
error("Enable debug messages failed: %s.", cp); |
error("Enable debug messages failed: %s.", cp); |
usage(); |
usage(); |
} |
} |
|
|
error("No path specified to \"-P\"."); |
error("No path specified to \"-P\"."); |
usage(); |
usage(); |
} |
} |
if ((cp = searchpath(optarg))) |
if ((cp = searchpath(optarg)) != NULL) |
path_remsh = xstrdup(cp); |
path_remsh = xstrdup(cp); |
else { |
else { |
error("No component of path \"%s\" exists.", |
error("No component of path \"%s\" exists.", |
|
|
if ((cp = getenv("RSH")) != NULL && *cp != '\0') |
if ((cp = getenv("RSH")) != NULL && *cp != '\0') |
path_remsh = cp; |
path_remsh = cp; |
else |
else |
path_remsh = _PATH_SSH; |
path_remsh = _PATH_REMSH; |
} |
} |
|
|
/* |
/* |
|
|
/* |
/* |
* Open a distfile |
* Open a distfile |
*/ |
*/ |
FILE *opendist(distfile) |
FILE * |
char *distfile; |
opendist(char *distfile) |
{ |
{ |
char *file = NULL; |
char *file = NULL; |
FILE *fp; |
FILE *fp; |
|
|
/* |
/* |
* Print usage message and exit. |
* Print usage message and exit. |
*/ |
*/ |
void |
static void |
usage() |
usage(void) |
{ |
{ |
char *sopts = "cDFnv"; |
char *sopts = "cDFnv"; |
|
|
|
|
* rcp like interface for distributing files. |
* rcp like interface for distributing files. |
*/ |
*/ |
void |
void |
docmdargs(nargs, args) |
docmdargs(int nargs, char **args) |
int nargs; |
|
char *args[]; |
|
{ |
{ |
struct namelist *nl, *prev; |
struct namelist *nl, *prev; |
char *cp; |
char *cp; |
|
|
debugmsg(DM_MISC, "host = %s", getnlstr(hosts)); |
debugmsg(DM_MISC, "host = %s", getnlstr(hosts)); |
|
|
insert(NULL, files, hosts, cmds); |
insert(NULL, files, hosts, cmds); |
docmds(0, NULL, 0, (char **)NULL); |
docmds(NULL, 0, NULL); |
} |
} |
|
|
/* |
/* |
* Get a list of NAME blocks (mostly for debugging). |
* Get a list of NAME blocks (mostly for debugging). |
*/ |
*/ |
extern char *getnlstr(nl) |
char * |
struct namelist *nl; |
getnlstr(struct namelist *nl) |
{ |
{ |
static char buf[16384]; |
static char buf[16384]; |
int count = 0, len = 0; |
size_t len = 0; |
|
|
(void) snprintf(buf, sizeof buf, "("); |
(void) snprintf(buf, sizeof(buf), "("); |
|
|
while (nl != NULL) { |
while (nl != NULL) { |
if (nl->n_name == NULL) |
if (nl->n_name == NULL) |
|
|
len += strlen(nl->n_name) + 2; |
len += strlen(nl->n_name) + 2; |
if (len >= sizeof(buf)) { |
if (len >= sizeof(buf)) { |
(void) strlcpy(buf, |
(void) strlcpy(buf, |
"getnlstr() Buffer not large enough", |
"getnlstr() Buffer not large enough", |
sizeof buf); |
sizeof(buf)); |
return(buf); |
return(buf); |
} |
} |
++count; |
(void) strlcat(buf, " ", sizeof(buf)); |
(void) strlcat(buf, " ", sizeof buf); |
(void) strlcat(buf, nl->n_name, sizeof(buf)); |
(void) strlcat(buf, nl->n_name, sizeof buf); |
|
nl = nl->n_next; |
nl = nl->n_next; |
} |
} |
|
|
(void) strlcat(buf, " )", sizeof buf); |
(void) strlcat(buf, " )", sizeof(buf)); |
|
|
return(buf); |
return(buf); |
} |
} |