386BSD 0.1 development
[unix-history] / usr / src / bin / rcp / rcp.c
index d9d5e96..0d15b68 100644 (file)
@@ -2,7 +2,33 @@
  * Copyright (c) 1983, 1990 The Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1983, 1990 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 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)rcp.c      5.32 (Berkeley) %G%";
+static char sccsid[] = "@(#)rcp.c      5.32 (Berkeley) 2/25/91";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -49,7 +75,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 "dfk:prtx"
+#else
 #define        OPTIONS "dfk:prt"
 #define        OPTIONS "dfk:prt"
+#endif
 #else
 #define        OPTIONS "dfprt"
 #endif
 #else
 #define        OPTIONS "dfprt"
 #endif
@@ -95,6 +126,12 @@ main(argc, argv)
                        strncpy(dst_realm_buf, optarg, REALM_SZ);
                        dest_realm = dst_realm_buf;
                        break;
                        strncpy(dst_realm_buf, optarg, REALM_SZ);
                        dest_realm = dst_realm_buf;
                        break;
+#ifdef CRYPT
+               case 'x':
+                       doencrypt = 1;
+                       /* des_set_key(cred.session, schedule); */
+                       break;
+#endif
 #endif
                /* rshd-invoked options (server) */
                case 'd':
 #endif
                /* rshd-invoked options (server) */
                case 'd':
@@ -117,7 +154,11 @@ main(argc, argv)
        argv += optind;
 
 #ifdef KERBEROS
        argv += optind;
 
 #ifdef KERBEROS
+#ifdef CRYPT
+       shell = doencrypt ? "ekshell" : "kshell";
+#else
        shell = "kshell";
        shell = "kshell";
+#endif
        sp = getservbyname(shell, "tcp");
        if (sp == NULL) {
                char    msgbuf[64];
        sp = getservbyname(shell, "tcp");
        if (sp == NULL) {
                char    msgbuf[64];
@@ -166,7 +207,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",
@@ -856,9 +901,15 @@ nospace()
 usage()
 {
 #ifdef KERBEROS
 usage()
 {
 #ifdef KERBEROS
+#ifdef CRYPT
+       (void)fprintf(stderr, "%s\n\t%s\n",
+           "usage: rcp [-k realm] [-px] f1 f2",
+           "or: rcp [-k realm] [-rpx] f1 ... fn directory");
+#else
        (void)fprintf(stderr, "%s\n\t%s\n",
            "usage: rcp [-k realm] [-p] f1 f2",
            "or: rcp [-k realm] [-rp] f1 ... fn directory");
        (void)fprintf(stderr, "%s\n\t%s\n",
            "usage: rcp [-k realm] [-p] f1 f2",
            "or: rcp [-k realm] [-rp] f1 ... fn directory");
+#endif
 #else
        (void)fprintf(stderr,
            "usage: rcp [-p] f1 f2; or: rcp [-rp] f1 ... fn directory\n");
 #else
        (void)fprintf(stderr,
            "usage: rcp [-p] f1 f2; or: rcp [-rp] f1 ... fn directory\n");
@@ -887,6 +938,15 @@ again:
                if (dest_realm == NULL)
                        dest_realm = krb_realmofhost(*host);
 
                if (dest_realm == NULL)
                        dest_realm = krb_realmofhost(*host);
 
+#ifdef CRYPT
+               if (doencrypt)
+                       rem = krcmd_mutual(
+                               host, port,
+                               user, bp, 0,
+                               dest_realm,
+                               &cred, schedule);
+               else
+#endif
                        rem = krcmd(
                                host, port,
                                user, bp, 0, dest_realm);
                        rem = krcmd(
                                host, port,
                                user, bp, 0, dest_realm);
@@ -910,6 +970,13 @@ again:
                        goto again;
                }
        } else {
                        goto again;
                }
        } else {
+#ifdef CRYPT
+               if (doencrypt) {
+                       fprintf(stderr,
+                           "The -x option requires Kerberos authentication\n");
+                       exit(1);
+               }
+#endif
                rem = rcmd(host, sp->s_port, locuser, user, bp, 0);
        }
        return(rem);
                rem = rcmd(host, sp->s_port, locuser, user, bp, 0);
        }
        return(rem);