add -DCRYPT to get -x processing
[unix-history] / usr / src / bin / rcp / rcp.c
index c0beab5..893129d 100644 (file)
@@ -1,28 +1,18 @@
 /*
 /*
- * Copyright (c) 1983 The Regents of the University of California.
+ * Copyright (c) 1983, 1990 The Regents of the University of California.
  * All rights reserved.
  *
  * 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 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * %sccs.include.redist.c%
  */
 
 #ifndef lint
 char copyright[] =
  */
 
 #ifndef lint
 char copyright[] =
-"@(#) Copyright (c) 1983 The Regents of the University of California.\n\
+"@(#) Copyright (c) 1983, 1990 The Regents of the University of California.\n\
  All rights reserved.\n";
 #endif /* not lint */
 
 #ifndef lint
  All rights reserved.\n";
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)rcp.c      5.23 (Berkeley) %G%";
+static char sccsid[] = "@(#)rcp.c      5.30 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -36,24 +26,32 @@ static char sccsid[] = "@(#)rcp.c   5.23 (Berkeley) %G%";
 #include <sys/dir.h>
 #include <sys/signal.h>
 #include <netinet/in.h>
 #include <sys/dir.h>
 #include <sys/signal.h>
 #include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/ip.h>
 #include <pwd.h>
 #include <netdb.h>
 #include <errno.h>
 #include <pwd.h>
 #include <netdb.h>
 #include <errno.h>
-#include <strings.h>
+#include <string.h>
 #include <stdio.h>
 #include <ctype.h>
 #include "pathnames.h"
 
 #ifdef KERBEROS
 #include <stdio.h>
 #include <ctype.h>
 #include "pathnames.h"
 
 #ifdef KERBEROS
-#include <krb.h>
+#include <kerberosIV/des.h>
+#include <kerberosIV/krb.h>
 char   dst_realm_buf[REALM_SZ];
 char   *dest_realm = NULL;
 char   dst_realm_buf[REALM_SZ];
 char   *dest_realm = NULL;
-int    use_kerberos = 1, encrypt = 0;
+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    encrypt = 0;
 #define        OPTIONS "dfkprtx"
 #else
 #define        OPTIONS "dfkprtx"
 #else
+#define        OPTIONS "dfkprt"
+#endif
+#else
 #define        OPTIONS "dfprt"
 #endif
 
 #define        OPTIONS "dfprt"
 #endif
 
@@ -79,7 +77,7 @@ main(argc, argv)
        extern int optind;
        struct servent *sp;
        int ch, fflag, tflag;
        extern int optind;
        struct servent *sp;
        int ch, fflag, tflag;
-       char *targ, *colon();
+       char *targ, *shell, *colon();
        struct passwd *getpwuid();
        int lostconn();
 
        struct passwd *getpwuid();
        int lostconn();
 
@@ -98,10 +96,12 @@ main(argc, argv)
                        strncpy(dst_realm_buf, ++argv, REALM_SZ);
                        dest_realm = dst_realm_buf;
                        break;
                        strncpy(dst_realm_buf, ++argv, REALM_SZ);
                        dest_realm = dst_realm_buf;
                        break;
+#ifdef CRYPT
                case 'x':
                        encrypt = 1;
                        /* des_set_key(cred.session, schedule); */
                        break;
                case 'x':
                        encrypt = 1;
                        /* des_set_key(cred.session, schedule); */
                        break;
+#endif
 #endif
                /* rshd-invoked options (server) */
                case 'd':
 #endif
                /* rshd-invoked options (server) */
                case 'd':
@@ -124,12 +124,17 @@ main(argc, argv)
        argv += optind;
 
 #ifdef KERBEROS
        argv += optind;
 
 #ifdef KERBEROS
-       sp = getservbyname((encrypt ? "ekshell" : "kshell"), "tcp");
+#ifdef CRYPT
+       shell = encrypt ? "ekshell" : "kshell";
+#else
+       shell = "kshell";
+#endif
+       sp = getservbyname(shell, "tcp");
        if (sp == NULL) {
                char    msgbuf[64];
                use_kerberos = 0;
                (void) sprintf(msgbuf, "can't get entry for %s/tcp service",
        if (sp == NULL) {
                char    msgbuf[64];
                use_kerberos = 0;
                (void) sprintf(msgbuf, "can't get entry for %s/tcp service",
-                       (encrypt ? "ekshell" : "kshell"));
+                       shell);
                old_warning(msgbuf);
                sp = getservbyname("shell", "tcp");
        }
                old_warning(msgbuf);
                sp = getservbyname("shell", "tcp");
        }
@@ -171,7 +176,11 @@ main(argc, argv)
        /* command to be executed on remote system using "rsh" */
 #ifdef KERBEROS
        (void)sprintf(cmd, "rcp%s%s%s%s", iamrecursive ? " -r" : "",
        /* command to be executed on remote system using "rsh" */
 #ifdef KERBEROS
        (void)sprintf(cmd, "rcp%s%s%s%s", iamrecursive ? " -r" : "",
+#ifdef CRYPT
            ((encrypt && use_kerberos) ? " -x" : ""),
            ((encrypt && use_kerberos) ? " -x" : ""),
+#else
+           "",
+#endif
            pflag ? " -p" : "", targetshouldbedirectory ? " -d" : "");
 #else
        (void)sprintf(cmd, "rcp%s%s%s", iamrecursive ? " -r" : "",
            pflag ? " -p" : "", targetshouldbedirectory ? " -d" : "");
 #else
        (void)sprintf(cmd, "rcp%s%s%s", iamrecursive ? " -r" : "",
@@ -195,7 +204,7 @@ toremote(targ, argc, argv)
        int argc;
        char **argv;
 {
        int argc;
        char **argv;
 {
-       int i;
+       int i, tos;
        char *bp, *host, *src, *suser, *thost, *tuser;
        char *colon(), *malloc();
 
        char *bp, *host, *src, *suser, *thost, *tuser;
        char *colon(), *malloc();
 
@@ -266,6 +275,10 @@ toremote(targ, argc, argv)
                                            bp, 0);
                                if (rem < 0)
                                        exit(1);
                                            bp, 0);
                                if (rem < 0)
                                        exit(1);
+                               tos = IPTOS_THROUGHPUT;
+                               if (setsockopt(rem, IPPROTO_IP, IP_TOS,
+                                   (char *)&tos, sizeof(int)) < 0)
+                                       perror("rcp: setsockopt TOS (ignored)");
                                if (response() < 0)
                                        exit(1);
                                (void)free(bp);
                                if (response() < 0)
                                        exit(1);
                                (void)free(bp);
@@ -280,7 +293,7 @@ tolocal(argc, argv)
        int argc;
        char **argv;
 {
        int argc;
        char **argv;
 {
-       int i;
+       int i, tos;
        char *bp, *host, *src, *suser;
        char *colon(), *malloc();
 
        char *bp, *host, *src, *suser;
        char *colon(), *malloc();
 
@@ -323,9 +336,13 @@ tolocal(argc, argv)
                (void)free(bp);
                if (rem < 0)
                        continue;
                (void)free(bp);
                if (rem < 0)
                        continue;
-               (void)setreuid(0, userid);
+               (void)seteuid(userid);
+               tos = IPTOS_THROUGHPUT;
+               if (setsockopt(rem, IPPROTO_IP, IP_TOS,
+                   (char *)&tos, sizeof(int)) < 0)
+                       perror("rcp: setsockopt TOS (ignored)");
                sink(1, argv + argc - 1);
                sink(1, argv + argc - 1);
-               (void)setreuid(userid, 0);
+               (void)seteuid(0);
                (void)close(rem);
                rem = -1;
        }
                (void)close(rem);
                rem = -1;
        }
@@ -848,9 +865,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");
        (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");
+#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");
@@ -879,6 +902,7 @@ again:
                if (dest_realm == NULL)
                        dest_realm = krb_realmofhost(*host);
 
                if (dest_realm == NULL)
                        dest_realm = krb_realmofhost(*host);
 
+#ifdef CRYPT
                if (encrypt)
                        rem = krcmd_mutual(
                                host, port,
                if (encrypt)
                        rem = krcmd_mutual(
                                host, port,
@@ -886,6 +910,7 @@ again:
                                dest_realm,
                                &cred, schedule);
                else
                                dest_realm,
                                &cred, schedule);
                else
+#endif
                        rem = krcmd(
                                host, port,
                                user, bp, 0, dest_realm);
                        rem = krcmd(
                                host, port,
                                user, bp, 0, dest_realm);
@@ -909,11 +934,13 @@ again:
                        goto again;
                }
        } else {
                        goto again;
                }
        } else {
+#ifdef CRYPT
                if (encrypt) {
                        fprintf(stderr,
                            "The -x option requires Kerberos authentication\n");
                        exit(1);
                }
                if (encrypt) {
                        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);