added depend label
[unix-history] / usr / src / usr.bin / rdist / docmd.c
index 37ef3f7..478d07c 100644 (file)
@@ -1,9 +1,16 @@
+/*
+ * Copyright (c) 1983 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)docmd.c     4.25 (Berkeley) 85/02/28";
-#endif
+static char sccsid[] = "@(#)docmd.c    5.1 (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"
 
 #ifndef RDIST
 #define RDIST "/usr/ucb/rdist"
@@ -159,6 +166,8 @@ 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[];
        extern int userid;
        int n;
        extern char user[];
        extern int userid;
@@ -171,27 +180,41 @@ 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);
        (void) sprintf(buf, "%s -Server%s", RDIST, qflag ? " -q" : "");
                        return(0);
        } else
                ruser = user;
        if (!qflag)
                printf("updating host %s\n", rhost);
        (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;
        setreuid(userid, 0);
        setreuid(userid, 0);
-       rem = rcmd(&rhost, IPPORT_CMDSERVER, user, ruser, buf, 0);
+       rem = rcmd(&rhost, port, user, ruser, buf, 0);
        setreuid(0, userid);
        if (rem < 0)
                return(0);
        setreuid(0, userid);
        if (rem < 0)
                return(0);