BSD 4_4_Lite1 release
[unix-history] / usr / src / bin / rcp / rcp.c
index 82f4a53..fc593a5 100644 (file)
@@ -2,7 +2,33 @@
  * Copyright (c) 1983, 1990, 1992, 1993
  *     The Regents of the University of California.  All rights reserved.
  *
  * Copyright (c) 1983, 1990, 1992, 1993
  *     The Regents of the University of California.  All rights reserved.
  *
- * %sccs.include.redist.c%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
@@ -12,7 +38,7 @@ static char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)rcp.c      8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)rcp.c      8.2 (Berkeley) 4/2/94";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -50,7 +76,12 @@ int  use_kerberos = 1;
 CREDENTIALS    cred;
 Key_schedule   schedule;
 extern char    *krb_realmofhost();
 CREDENTIALS    cred;
 Key_schedule   schedule;
 extern char    *krb_realmofhost();
+#ifdef CRYPT
+int    doencrypt = 0;
+#define        OPTIONS "dfKk:prtx"
+#else
 #define        OPTIONS "dfKk:prt"
 #define        OPTIONS "dfKk:prt"
+#endif
 #else
 #define        OPTIONS "dfprt"
 #endif
 #else
 #define        OPTIONS "dfprt"
 #endif
@@ -98,6 +129,12 @@ main(argc, argv)
                        dest_realm = dst_realm_buf;
                        (void)strncpy(dst_realm_buf, optarg, REALM_SZ);
                        break;
                        dest_realm = dst_realm_buf;
                        (void)strncpy(dst_realm_buf, optarg, REALM_SZ);
                        break;
+#ifdef CRYPT
+               case 'x':
+                       doencrypt = 1;
+                       /* des_set_key(cred.session, schedule); */
+                       break;
+#endif
 #endif
                case 'p':
                        pflag = 1;
 #endif
                case 'p':
                        pflag = 1;
@@ -126,7 +163,11 @@ main(argc, argv)
 
 #ifdef KERBEROS
        if (use_kerberos) {
 
 #ifdef KERBEROS
        if (use_kerberos) {
+#ifdef CRYPT
+               shell = doencrypt ? "ekshell" : "kshell";
+#else
                shell = "kshell";
                shell = "kshell";
+#endif
                if ((sp = getservbyname(shell, "tcp")) == NULL) {
                        use_kerberos = 0;
                        oldw("can't get entry for %s/tcp service", shell);
                if ((sp = getservbyname(shell, "tcp")) == NULL) {
                        use_kerberos = 0;
                        oldw("can't get entry for %s/tcp service", shell);
@@ -169,7 +210,11 @@ main(argc, argv)
 #ifdef KERBEROS
        (void)snprintf(cmd, sizeof(cmd),
            "rcp%s%s%s%s", iamrecursive ? " -r" : "",
 #ifdef KERBEROS
        (void)snprintf(cmd, sizeof(cmd),
            "rcp%s%s%s%s", iamrecursive ? " -r" : "",
+#ifdef CRYPT
+           (doencrypt && use_kerberos ? " -x" : ""),
+#else
            "",
            "",
+#endif
            pflag ? " -p" : "", targetshouldbedirectory ? " -d" : "");
 #else
        (void)snprintf(cmd, sizeof(cmd), "rcp%s%s%s",
            pflag ? " -p" : "", targetshouldbedirectory ? " -d" : "");
 #else
        (void)snprintf(cmd, sizeof(cmd), "rcp%s%s%s",
@@ -240,7 +285,7 @@ toremote(targ, argc, argv)
                                    thost, targ);
                        } else
                                (void)snprintf(bp, len,
                                    thost, targ);
                        } else
                                (void)snprintf(bp, len,
-                                   "%s %s -n %s %s '%s%s%s:%s'",
+                                   "exec %s %s -n %s %s '%s%s%s:%s'",
                                    _PATH_RSH, argv[i], cmd, src,
                                    tuser ? tuser : "", tuser ? "@" : "",
                                    thost, targ);
                                    _PATH_RSH, argv[i], cmd, src,
                                    tuser ? tuser : "", tuser ? "@" : "",
                                    thost, targ);
@@ -293,7 +338,7 @@ tolocal(argc, argv)
                            strlen(argv[argc - 1]) + 20;
                        if (!(bp = malloc(len)))
                                err(1, NULL);
                            strlen(argv[argc - 1]) + 20;
                        if (!(bp = malloc(len)))
                                err(1, NULL);
-                       (void)snprintf(bp, len, "%s%s%s %s %s", _PATH_CP,
+                       (void)snprintf(bp, len, "exec %s%s%s %s %s", _PATH_CP,
                            iamrecursive ? " -r" : "", pflag ? " -p" : "",
                            argv[i], argv[argc - 1]);
                        if (susystem(bp, userid))
                            iamrecursive ? " -r" : "", pflag ? " -p" : "",
                            argv[i], argv[argc - 1]);
                        if (susystem(bp, userid))
@@ -486,7 +531,6 @@ sink(argc, argv)
        char *argv[];
 {
        static BUF buffer;
        char *argv[];
 {
        static BUF buffer;
-       register char *cp;
        struct stat stb;
        struct timeval tv[2];
        enum { YES, NO, DISPLAYED } wrerr;
        struct stat stb;
        struct timeval tv[2];
        enum { YES, NO, DISPLAYED } wrerr;
@@ -494,7 +538,7 @@ sink(argc, argv)
        off_t i, j;
        int amt, count, exists, first, mask, mode, ofd, omode;
        int setimes, size, targisdir, wrerrno;
        off_t i, j;
        int amt, count, exists, first, mask, mode, ofd, omode;
        int setimes, size, targisdir, wrerrno;
-       char ch, *np, *targ, *why, *vect[1], buf[BUFSIZ];
+       char ch, *cp, *np, *targ, *why, *vect[1], buf[BUFSIZ];
 
 #define        atime   tv[0]
 #define        mtime   tv[1]
 
 #define        atime   tv[0]
 #define        mtime   tv[1]
@@ -735,6 +779,11 @@ again:
                if (dest_realm == NULL)
                        dest_realm = krb_realmofhost(*host);
                rem = 
                if (dest_realm == NULL)
                        dest_realm = krb_realmofhost(*host);
                rem = 
+#ifdef CRYPT
+                   doencrypt ? 
+                       krcmd_mutual(host,
+                           port, user, bp, 0, dest_realm, &cred, schedule) :
+#endif
                        krcmd(host, port, user, bp, 0, dest_realm);
 
                if (rem < 0) {
                        krcmd(host, port, user, bp, 0, dest_realm);
 
                if (rem < 0) {
@@ -749,6 +798,11 @@ again:
                        goto again;
                }
        } else {
                        goto again;
                }
        } else {
+#ifdef CRYPT
+               if (doencrypt)
+                       errx(1,
+                          "the -x option requires Kerberos authentication");
+#endif
                rem = rcmd(host, port, locuser, user, bp, 0);
        }
        return (rem);
                rem = rcmd(host, port, locuser, user, bp, 0);
        }
        return (rem);
@@ -758,8 +812,7 @@ again:
 int
 response()
 {
 int
 response()
 {
-       register char *cp;
-       char ch, resp, rbuf[BUFSIZ];
+       char ch, *cp, resp, rbuf[BUFSIZ];
 
        if (read(rem, &resp, sizeof(resp)) != sizeof(resp))
                lostconn(0);
 
        if (read(rem, &resp, sizeof(resp)) != sizeof(resp))
                lostconn(0);
@@ -793,9 +846,15 @@ void
 usage()
 {
 #ifdef KERBEROS
 usage()
 {
 #ifdef KERBEROS
+#ifdef CRYPT
+       (void)fprintf(stderr, "%s\n\t%s\n",
+           "usage: rcp [-Kpx] [-k realm] f1 f2",
+           "or: rcp [-Kprx] [-k realm] f1 ... fn directory");
+#else
        (void)fprintf(stderr, "%s\n\t%s\n",
            "usage: rcp [-Kp] [-k realm] f1 f2",
            "or: rcp [-Kpr] [-k realm] f1 ... fn directory");
        (void)fprintf(stderr, "%s\n\t%s\n",
            "usage: rcp [-Kp] [-k realm] f1 f2",
            "or: rcp [-Kpr] [-k realm] f1 ... fn directory");
+#endif
 #else
        (void)fprintf(stderr,
            "usage: rcp [-p] f1 f2; or: rcp [-pr] f1 ... fn directory\n");
 #else
        (void)fprintf(stderr,
            "usage: rcp [-p] f1 f2; or: rcp [-pr] f1 ... fn directory\n");