386BSD 0.1 development
[unix-history] / usr / src / usr.bin / rlogin / rlogin.c
index 05d918c..2ba715c 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[] = "@(#)rlogin.c   5.33 (Berkeley) %G%";
+static char sccsid[] = "@(#)rlogin.c   5.33 (Berkeley) 3/1/91";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -161,6 +187,14 @@ main(argc, argv)
                case 'l':
                        user = optarg;
                        break;
                case 'l':
                        user = optarg;
                        break;
+#ifdef CRYPT
+#ifdef KERBEROS
+               case 'x':
+                       doencrypt = 1;
+                       des_set_key(cred.session, schedule);
+                       break;
+#endif
+#endif
                case '?':
                default:
                        usage();
                case '?':
                default:
                        usage();
@@ -221,6 +255,12 @@ try_connect:
                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, sp->s_port, user, term, 0,
+                           dest_realm, &cred, schedule);
+               else
+#endif /* CRYPT */
                        rem = krcmd(&host, sp->s_port, user, term, 0,
                            dest_realm);
                if (rem < 0) {
                        rem = krcmd(&host, sp->s_port, user, term, 0,
                            dest_realm);
                if (rem < 0) {
@@ -238,6 +278,13 @@ try_connect:
                        goto try_connect;
                }
        } else {
                        goto try_connect;
                }
        } else {
+#ifdef CRYPT
+               if (doencrypt) {
+                       (void)fprintf(stderr,
+                           "rlogin: the -x flag requires Kerberos authentication.\n");
+                       exit(1);
+               }
+#endif /* CRYPT */
                rem = rcmd(&host, sp->s_port, pw->pw_name, user, term, 0);
        }
 #else
                rem = rcmd(&host, sp->s_port, pw->pw_name, user, term, 0);
        }
 #else
@@ -425,9 +472,26 @@ writer()
                                continue;
                        }
                        if (c != escapechar)
                                continue;
                        }
                        if (c != escapechar)
+#ifdef CRYPT
+#ifdef KERBEROS
+                               if (doencrypt)
+                                       (void)des_write(rem, &escapechar, 1);
+                               else
+#endif
+#endif
                                        (void)write(rem, &escapechar, 1);
                }
 
                                        (void)write(rem, &escapechar, 1);
                }
 
+#ifdef CRYPT
+#ifdef KERBEROS
+               if (doencrypt) {
+                       if (des_write(rem, &c, 1) == 0) {
+                               msg("line gone");
+                               break;
+                       }
+               } else
+#endif
+#endif
                        if (write(rem, &c, 1) == 0) {
                                msg("line gone");
                                break;
                        if (write(rem, &c, 1) == 0) {
                                msg("line gone");
                                break;
@@ -501,6 +565,13 @@ sendwindow()
        wp->ws_xpixel = htons(winsize.ws_xpixel);
        wp->ws_ypixel = htons(winsize.ws_ypixel);
 
        wp->ws_xpixel = htons(winsize.ws_xpixel);
        wp->ws_ypixel = htons(winsize.ws_ypixel);
 
+#ifdef CRYPT
+#ifdef KERBEROS
+       if(doencrypt)
+               (void)des_write(rem, obuf, sizeof(obuf));
+       else
+#endif
+#endif
                (void)write(rem, obuf, sizeof(obuf));
 }
 
                (void)write(rem, obuf, sizeof(obuf));
 }
 
@@ -638,6 +709,13 @@ reader(omask)
                rcvcnt = 0;
                rcvstate = READING;
 
                rcvcnt = 0;
                rcvstate = READING;
 
+#ifdef CRYPT
+#ifdef KERBEROS
+               if (doencrypt)
+                       rcvcnt = des_read(rem, rcvbuf, sizeof(rcvbuf));
+               else
+#endif
+#endif
                        rcvcnt = read(rem, rcvbuf, sizeof (rcvbuf));
                if (rcvcnt == 0)
                        return (0);
                        rcvcnt = read(rem, rcvbuf, sizeof (rcvbuf));
                if (rcvcnt == 0)
                        return (0);
@@ -734,7 +812,11 @@ usage()
        (void)fprintf(stderr,
            "usage: rlogin [ -%s]%s[-e char] [ -l username ] host\n",
 #ifdef KERBEROS
        (void)fprintf(stderr,
            "usage: rlogin [ -%s]%s[-e char] [ -l username ] host\n",
 #ifdef KERBEROS
+#ifdef CRYPT
+           "8ELx", " [-k realm] ");
+#else
            "8EL", " [-k realm] ");
            "8EL", " [-k realm] ");
+#endif
 #else
            "8EL", " ");
 #endif
 #else
            "8EL", " ");
 #endif