don't pause after exiting from help file
[unix-history] / usr / src / usr.bin / rdist / docmd.c
index 2456813..8eda930 100644 (file)
@@ -1,9 +1,31 @@
+/*
+ * 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
 #ifndef lint
-static char *sccsid = "@(#)docmd.c     4.20 (Berkeley) 84/05/03";
-#endif
+static char sccsid[] = "@(#)docmd.c    5.3 (Berkeley) %G%";
+#endif /* not lint */
 
 #include "defs.h"
 #include <setjmp.h>
 
 #include "defs.h"
 #include <setjmp.h>
+#include <netdb.h>
+
+#ifndef RDIST
+#define RDIST "/usr/ucb/rdist"
+#endif
 
 FILE   *lfp;                   /* log file for recording files updated */
 struct subcmd *subcmds;        /* list of sub-commands for current cmd */
 
 FILE   *lfp;                   /* log file for recording files updated */
 struct subcmd *subcmds;        /* list of sub-commands for current cmd */
@@ -15,7 +37,8 @@ int   lostconn();
 /*
  * Do the commands in cmds (initialized by yyparse).
  */
 /*
  * Do the commands in cmds (initialized by yyparse).
  */
-docmds(argc, argv)
+docmds(dhosts, argc, argv)
+       char **dhosts;
        int argc;
        char **argv;
 {
        int argc;
        char **argv;
 {
@@ -30,6 +53,13 @@ docmds(argc, argv)
        signal(SIGTERM, cleanup);
 
        for (c = cmds; c != NULL; c = c->c_next) {
        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 &&
                if (argc) {
                        for (cpp = argv; *cpp; cpp++) {
                                if (c->c_label != NULL &&
@@ -71,7 +101,7 @@ doarrow(filev, files, rhost, cmds)
        register struct namelist *f;
        register struct subcmd *sc;
        register char **cpp;
        register struct namelist *f;
        register struct subcmd *sc;
        register char **cpp;
-       int n, ddir;
+       int n, ddir, opts = options;
 
        if (debug)
                printf("doarrow(%x, %s, %x)\n", files, rhost, cmds);
 
        if (debug)
                printf("doarrow(%x, %s, %x)\n", files, rhost, cmds);
@@ -113,6 +143,7 @@ doarrow(filev, files, rhost, cmds)
                        n++;
                        install(f->n_name, sc->sc_name,
                                sc->sc_name == NULL ? 0 : ddir, sc->sc_options);
                        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);
                }
                if (n == 0)
                        install(f->n_name, NULL, 0, options);
@@ -126,8 +157,16 @@ done:
        for (sc = cmds; sc != NULL; sc = sc->sc_next)
                if (sc->sc_type == NOTIFY)
                        notify(tmpfile, rhost, sc->sc_args, 0);
        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);
                (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);
+               }
+       }
 }
 
 /*
 }
 
 /*
@@ -138,8 +177,11 @@ makeconn(rhost)
 {
        register char *ruser, *cp;
        static char *cur_host = NULL;
 {
        register char *ruser, *cp;
        static char *cur_host = NULL;
+       static int port = -1;
+       char tuser[20];
        int n;
        extern char user[];
        int n;
        extern char user[];
+       extern int userid;
 
        if (debug)
                printf("makeconn(%s)\n", rhost);
 
        if (debug)
                printf("makeconn(%s)\n", rhost);
@@ -149,26 +191,42 @@ makeconn(rhost)
                        return(1);
                closeconn();
        }
                        return(1);
                closeconn();
        }
-
-       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);
                        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", 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) {
 
        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);
                printf("buf = %s\n", buf);
        }
 
        fflush(stdout);
-       cur_host = rhost;
-       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;
        if (rem < 0)
                return(0);
        cp = buf;
@@ -186,8 +244,9 @@ makeconn(rhost)
                        n = (n * 10) + (*cp++ - '0');
                if (*cp == '\0' && n == VERSION)
                        return(1);
                        n = (n * 10) + (*cp++ - '0');
                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);
 }
        closeconn();
        return(0);
 }