X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/346dad94e1643c03915f0d04c70b99ec7072a36e..bf766a3770736e890c75df2a66b09b4a40baca69:/usr/src/usr.bin/rdist/docmd.c diff --git a/usr/src/usr.bin/rdist/docmd.c b/usr/src/usr.bin/rdist/docmd.c index a6d5e66110..448c707a59 100644 --- a/usr/src/usr.bin/rdist/docmd.c +++ b/usr/src/usr.bin/rdist/docmd.c @@ -1,12 +1,30 @@ +/* + * Copyright (c) 1983 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms are permitted + * provided that the above copyright notice and this paragraph are + * duplicated in all such forms and that any documentation, + * advertising materials, and other materials related to such + * distribution and use acknowledge that the software was developed + * by the University of California, Berkeley. The name of the + * University may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + #ifndef lint -static char *sccsid = "@(#)docmd.c 4.17 (Berkeley) 84/03/14"; -#endif +static char sccsid[] = "@(#)docmd.c 5.4 (Berkeley) %G%"; +#endif /* not lint */ #include "defs.h" #include +#include FILE *lfp; /* log file for recording files updated */ -struct subcmd *special; /* list of special commands */ +struct subcmd *subcmds; /* list of sub-commands for current cmd */ jmp_buf env; int cleanup(); @@ -15,11 +33,14 @@ int lostconn(); /* * Do the commands in cmds (initialized by yyparse). */ -docmds(argc, argv) +docmds(dhosts, argc, argv) + char **dhosts; int argc; char **argv; { register struct cmd *c; + register struct namelist *f; + register char **cpp; extern struct cmd *cmds; signal(SIGHUP, cleanup); @@ -28,12 +49,34 @@ docmds(argc, argv) signal(SIGTERM, cleanup); for (c = cmds; c != NULL; c = c->c_next) { + if (dhosts != NULL && *dhosts != NULL) { + for (cpp = dhosts; *cpp; cpp++) + if (strcmp(c->c_name, *cpp) == 0) + goto fndhost; + continue; + } + fndhost: + if (argc) { + for (cpp = argv; *cpp; cpp++) { + if (c->c_label != NULL && + strcmp(c->c_label, *cpp) == 0) { + cpp = NULL; + goto found; + } + for (f = c->c_files; f != NULL; f = f->n_next) + if (strcmp(f->n_name, *cpp) == 0) + goto found; + } + continue; + } else + cpp = NULL; + found: switch (c->c_type) { case ARROW: - doarrow(c->c_files, c->c_name, c->c_cmds); + doarrow(cpp, c->c_files, c->c_name, c->c_cmds); break; case DCOLON: - dodcolon(c->c_files, c->c_name, c->c_cmds); + dodcolon(cpp, c->c_files, c->c_name, c->c_cmds); break; default: fatal("illegal command type %d\n", c->c_type); @@ -45,14 +88,16 @@ docmds(argc, argv) /* * Process commands for sending files to other machines. */ -doarrow(files, rhost, cmds) +doarrow(filev, files, rhost, cmds) + char **filev; struct namelist *files; char *rhost; struct subcmd *cmds; { register struct namelist *f; register struct subcmd *sc; - int n, ddir; + register char **cpp; + int n, ddir, opts = options; if (debug) printf("doarrow(%x, %s, %x)\n", files, rhost, cmds); @@ -61,12 +106,9 @@ doarrow(files, rhost, cmds) error("no files to be updated\n"); return; } - if (!mkexceptlist(cmds)) - return; - special = cmds; + subcmds = cmds; ddir = files->n_next != NULL; /* destination is a directory */ - if (nflag) printf("updating host %s\n", rhost); else { @@ -81,19 +123,15 @@ doarrow(files, rhost, cmds) } } for (f = files; f != NULL; f = f->n_next) { -#ifdef notdef - if (filec) { - register char **cpp; - + if (filev) { for (cpp = filev; *cpp; cpp++) - if (!strcmp(f->b_name, *cpp)) + if (strcmp(f->n_name, *cpp) == 0) goto found; if (!nflag) (void) fclose(lfp); continue; } found: -#endif n = 0; for (sc = cmds; sc != NULL; sc = sc->sc_next) { if (sc->sc_type != INSTALL) @@ -101,6 +139,7 @@ doarrow(files, rhost, cmds) n++; install(f->n_name, sc->sc_name, sc->sc_name == NULL ? 0 : ddir, sc->sc_options); + opts = sc->sc_options; } if (n == 0) install(f->n_name, NULL, 0, options); @@ -114,8 +153,16 @@ done: for (sc = cmds; sc != NULL; sc = sc->sc_next) if (sc->sc_type == NOTIFY) notify(tmpfile, rhost, sc->sc_args, 0); - if (!nflag) + if (!nflag) { (void) unlink(tmpfile); + for (; ihead != NULL; ihead = ihead->nextp) { + free(ihead); + if ((opts & IGNLNKS) || ihead->count == 0) + continue; + log(lfp, "%s: Warning: missing links\n", + ihead->pathname); + } + } } /* @@ -126,8 +173,11 @@ makeconn(rhost) { register char *ruser, *cp; static char *cur_host = NULL; + static int port = -1; + char tuser[20]; int n; extern char user[]; + extern int userid; if (debug) printf("makeconn(%s)\n", rhost); @@ -136,27 +186,43 @@ makeconn(rhost) if (strcmp(cur_host, rhost) == 0) return(1); closeconn(); - cur_host = NULL; } - - ruser = rindex(rhost, '.'); - if (ruser != NULL) { - *ruser++ = '\0'; - if (!okname(ruser)) + cur_host = rhost; + cp = index(rhost, '@'); + if (cp != NULL) { + char c = *cp; + + *cp = '\0'; + strncpy(tuser, rhost, sizeof(tuser)-1); + *cp = c; + rhost = cp + 1; + ruser = tuser; + if (*ruser == '\0') + ruser = user; + else if (!okname(ruser)) return(0); } else ruser = user; if (!qflag) printf("updating host %s\n", rhost); - (void) sprintf(buf, "/usr/local/rdist -Server%s", qflag ? " -q" : ""); + (void) sprintf(buf, "%s -Server%s", _PATH_RDIST, qflag ? " -q" : ""); + if (port < 0) { + struct servent *sp; + + if ((sp = getservbyname("shell", "tcp")) == NULL) + fatal("shell/tcp: unknown service"); + port = sp->s_port; + } if (debug) { - printf("luser = %s, ruser = %s\n", user, ruser); + printf("port = %d, luser = %s, ruser = %s\n", ntohs(port), user, ruser); printf("buf = %s\n", buf); } fflush(stdout); - rem = rcmd(&rhost, IPPORT_CMDSERVER, user, ruser, buf, 0); + setreuid(userid, 0); + rem = rcmd(&rhost, port, user, ruser, buf, 0); + setreuid(0, userid); if (rem < 0) return(0); cp = buf; @@ -172,12 +238,12 @@ makeconn(rhost) n = 0; while (*cp >= '0' && *cp <= '9') n = (n * 10) + (*cp++ - '0'); - if (*cp == '\0' && n == VERSION) { - cur_host = rhost; + if (*cp == '\0' && n == VERSION) return(1); - } - } - error("connection failed: version numbers don't match\n"); + error("connection failed: version numbers don't match (local %d, remote %d)\n", VERSION, n); + } else + error("connection failed: version numbers don't match\n"); + closeconn(); return(0); } @@ -231,7 +297,8 @@ extern char target[], *tp; /* * Process commands for comparing files to time stamp files. */ -dodcolon(files, stamp, cmds) +dodcolon(filev, files, stamp, cmds) + char **filev; struct namelist *files; char *stamp; struct subcmd *cmds; @@ -250,9 +317,6 @@ dodcolon(files, stamp, cmds) error("no files to be updated\n"); return; } - if (!mkexceptlist(cmds)) - return; - if (stat(stamp, &stb) < 0) { error("%s: %s\n", stamp, sys_errlist[errno]); return; @@ -260,6 +324,7 @@ dodcolon(files, stamp, cmds) if (debug) printf("%s: %d\n", stamp, stb.st_mtime); + subcmds = cmds; lastmod = stb.st_mtime; if (nflag || (options & VERIFY)) tfp = NULL; @@ -274,15 +339,13 @@ dodcolon(files, stamp, cmds) } for (f = files; f != NULL; f = f->n_next) { -#ifdef notdef - if (filec) { + if (filev) { for (cpp = filev; *cpp; cpp++) - if (!strcmp(b->b_name, *cpp)) + if (strcmp(f->n_name, *cpp) == 0) goto found; continue; } found: -#endif tp = NULL; cmptime(f->n_name); } @@ -307,7 +370,7 @@ cmptime(name) if (debug) printf("cmptime(%s)\n", name); - if (inlist(except, name)) + if (except(name)) return; if (nflag) { @@ -426,9 +489,10 @@ notify(file, rhost, to, lmod) /* * Create a pipe to mailling program. */ - pf = popen(MAILCMD, "w"); + (void)sprintf(buf, "%s -oi -t", _PATH_SENDMAIL); + pf = popen(buf, "w"); if (pf == NULL) { - error("notify: \"%s\" failed\n", MAILCMD); + error("notify: \"%s\" failed\n", _PATH_SENDMAIL); (void) close(fd); return; } @@ -463,8 +527,6 @@ notify(file, rhost, to, lmod) (void) pclose(pf); } -struct namelist *except; /* list of files to exclude */ - /* * Return true if name is in the list. */ @@ -481,35 +543,32 @@ inlist(list, file) } /* - * Build the exception list from the EXCEPT commands. + * Return TRUE if file is in the exception list. */ -mkexceptlist(cmds) - struct subcmd *cmds; +except(file) + char *file; { - register struct subcmd *sc; - register struct namelist *el, *nl; + register struct subcmd *sc; + register struct namelist *nl; if (debug) - printf("mkexceptlist()\n"); + printf("except(%s)\n", file); - except = el = NULL; - for (sc = cmds; sc != NULL; sc = sc->sc_next) { - if (sc->sc_type != EXCEPT) + for (sc = subcmds; sc != NULL; sc = sc->sc_next) { + if (sc->sc_type != EXCEPT && sc->sc_type != PATTERN) continue; for (nl = sc->sc_args; nl != NULL; nl = nl->n_next) { - if (el == NULL) - except = el = makenl(nl->n_name); - else { - el->n_next = makenl(nl->n_name); - el = el->n_next; + if (sc->sc_type == EXCEPT) { + if (!strcmp(file, nl->n_name)) + return(1); + continue; } + re_comp(nl->n_name); + if (re_exec(file) > 0) + return(1); } } - if (debug) { - printf("except = "); - prnames(except); - } - return(1); + return(0); } char *