Skip Menu |
 

Download (untitled) / with headers
text/plain 13.2KiB
From schwim@whatmore.Stanford.EDU Wed May 20 22:37:59 1998
Received: from MIT.EDU (SOUTH-STATION-ANNEX.MIT.EDU [18.72.1.2]) by rt-11.MIT.EDU (8.7.5/8.7.3) with SMTP id WAA19237 for <bugs@RT-11.MIT.EDU>; Wed, 20 May 1998 22:37:58 -0400
Received: from whatmore.Stanford.EDU by MIT.EDU with SMTP
id AA07306; Wed, 20 May 98 22:37:50 EDT
Received: (from schwim@localhost)
by whatmore.Stanford.EDU (8.8.8/8.8.8) id TAA28688;
Wed, 20 May 1998 19:37:55 -0700 (PDT)
Message-Id: <199805210237.TAA28688@whatmore.Stanford.EDU>
Date: Wed, 20 May 1998 19:37:55 -0700 (PDT)
From: Larry Schwimmer <schwim@whatmore.Stanford.EDU>
To: krb5-bugs@MIT.EDU
Subject: PATCH: krb5-1.0.5 rsh patches

Show quoted text
>Number: 595
>Category: krb5-appl
>Synopsis: rsh krb4 support, non-recursion fix
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: krb5-unassigned
>State: open
>Class: change-request
>Submitter-Id: unknown
>Arrival-Date: Wed May 20 22:38:00 EDT 1998
>Last-Modified: Fri Sep 14 11:47:50 EDT 2001
>Originator: Larry Schwimmer
>Organization:
Stanford University
Show quoted text
>Release: krb5-1.0.5
>Environment:
ALL
Show quoted text
>Description:

1) krb4 fallback support

Added support to fallback to krb4 if compiled under
KRB5_KRB4_COMPAT and if krb5 fails or if the (added) -4 flag is
specified. Added a -k4 flag to specify the k4 realm.

2) non-recursion and runtime lookup of vendor rsh

If the krb5 rsh is installed in the vendor location and the
kerberos connection fails and encryption is not specified, the program
will call itself infinitely. I revised the try_normal code to stat
itself and the target file to be run to try to avoid this case.
In the process of redoing that code, I removed the hard-coded
default and changed it to do runtime lookup since the hard-coded
defaults are wrong on some systems (Linux, for example).

3) Support for username@hostname

rsh username@hostname

just seems intuitive and saves three keystrokes. (-: It's also really
easy to get used to.

4) Man page updates to document the features.

Show quoted text
>How-To-Repeat:
>Fix:

Patch at end of note.

yours,
Larry Schwimmer
schwim@leland.stanford.edu
Leland Systems Group


--- appl/bsd/krsh.c.orig Fri Feb 6 19:41:17 1998
+++ appl/bsd/krsh.c Wed May 20 16:12:13 1998
@@ -31,6 +31,7 @@
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/file.h>
+#include <sys/stat.h>
#include <sys/time.h>

#include <netinet/in.h>
@@ -81,10 +82,6 @@

#ifdef KERBEROS

-#ifndef UCB_RSH
-#define UCB_RSH "/usr/ucb/rsh"
-#endif
-
#define RSH_BUFSIZ 4096

char des_inbuf[2*RSH_BUFSIZ]; /* needs to be > largest read size */
@@ -98,10 +95,18 @@
char *krb_realm = (char *)0;
void try_normal();

+#ifdef KRB5_KRB4_COMPAT
+#include <kerberosIV/krb.h>
+char krb4_realm[REALM_SZ] = "";
+#endif
+
+int (*des_read)(), (*des_write)();
+int v5_des_read(), v5_des_write();
+
#else /* KERBEROS */

-#define des_read read
-#define des_write write
+#define (*des_read) read
+#define (*des_write) write

#endif /* KERBEROS */

@@ -126,6 +131,7 @@
{
int rem, pid;
char *host=0, *cp, **ap, buf[RSH_BUFSIZ], *args, **argv = argv0, *user = 0;
+ int host_offset = argc;
register int cc;
struct passwd *pwd;
fd_set readfrom, ready;
@@ -143,6 +149,12 @@
krb5_flags authopts;
krb5_error_code status;
int fflag = 0, Fflag = 0;
+#ifdef KRB5_KRB4_COMPAT
+ int do_krb4 = 0; /* Default to krb5 */
+ KRB4_32 v4_status;
+ KTEXT_ST v4_ticket;
+ KRB4_32 v4_authopts = 0;
+#endif /* KRB5_KRB4_COMPAT */
#endif /* KERBEROS */
int debug_port = 0;

@@ -157,6 +169,7 @@
another:
if (argc > 0 && host == 0 && strncmp(*argv, "-", 1)) {
host = *argv;
+ host_offset -= argc;
argv++, argc--;
goto another;
}
@@ -229,6 +242,24 @@
argv++, argc--;
goto another;
}
+#ifdef KRB5_KRB4_COMPAT
+ if (argc > 0 && !strcmp(*argv, "-4")) {
+ do_krb4 = 1;
+ argv++, argc--;
+ goto another;
+ }
+ if (argc > 0 && !strcmp(*argv, "-k4")) {
+ argv++, argc--;
+ if (argc == 0) {
+ fprintf(stderr,
+ "rlogin: -k4 flag must be followed with a realm name.\n");
+ exit (1);
+ }
+ strncpy(krb4_realm, *argv, REALM_SZ);
+ argv++, argc--;
+ goto another;
+ }
+#endif /* KRB5_KRB4_COMPAT */
#endif /* KERBEROS */
/*
* Ignore the -L, -w, -e and -8 flags to allow aliases with rlogin
@@ -284,6 +315,17 @@
#endif /* ATHENA */
if (host == 0)
goto usage;
+ /* Honor username@hostname */
+ {
+ char *np;
+
+ if ((np = strchr(host,'@')) != (char *)0 &&
+ (np != host) && (*(np+1) != '\0')) {
+ user = host;
+ host = np+1;
+ *np = '\0';
+ }
+ }
if (argv[0] == 0) {
execv(RLOGIN_PROGRAM, argv0);
perror(RLOGIN_PROGRAM);
@@ -347,35 +389,88 @@
if (Fflag)
authopts |= OPTS_FORWARDABLE_CREDS;

- status = kcmd(&rem, &host, debug_port,
- pwd->pw_name,
- user ? user : pwd->pw_name,
- args, &rfd2, "host", krb_realm,
- &cred,
- 0, /* No need for sequence number */
- 0, /* No need for server seq # */
- (struct sockaddr_in *) 0,
- (struct sockaddr_in *) 0,
- authopts,
- 1); /* Always set anyport, there is no need not to. --proven */
- if (status) {
+#ifdef KRB5_KRB4_COMPAT
+ if (!do_krb4)
+#endif
+ status = kcmd(&rem, &host, debug_port,
+ pwd->pw_name,
+ user ? user : pwd->pw_name,
+ args, &rfd2, "host", krb_realm,
+ &cred,
+ 0, /* No need for sequence number */
+ 0, /* No need for server seq # */
+ (struct sockaddr_in *) 0,
+ (struct sockaddr_in *) 0,
+ authopts,
+ 1); /* Always set anyport, there is no need not to. --proven */
+ if (status == 0
+#ifdef KRB5_KRB4_COMPAT
+ && !do_krb4
+#endif
+ ) {
+ des_read = &v5_des_read;
+ des_write = &v5_des_write;
+ } else {
/* check NO_TKT_FILE or equivalent... */
- if (status != -1)
- fprintf(stderr,
- "%s: kcmd to host %s failed - %s\n",argv0[0], host,
- error_message(status));
- try_normal(argv0);
+#ifdef KRB5_KRB4_COMPAT
+ if (encrypt_flag) {
+ if (status != -1) {
+ fprintf(stderr,
+ "%s: kcmd to host %s failed - %s\n",argv0[0],
+ host, error_message(status));
+ } else {
+ fprintf(stderr,
+ "%s: kcmd to host %s failed\n",argv0[0],host);
+ }
+ exit(1);
+ }
+ /* Try V4 kcmd */
+ v4_status = k4cmd(&rem, &host, debug_port,
+ pwd->pw_name,
+ user ? user : pwd->pw_name,
+ args, &rfd2, &v4_ticket, "rcmd", krb4_realm,
+ (CREDENTIALS *)0, (KRB4_32 *)0, (MSG_DAT *)0,
+ (struct sockaddr_in *) 0,
+ (struct sockaddr_in *) 0,
+ v4_authopts);
+
+ des_read = &read;
+ des_write = &write;
+ if (v4_status != 0) {
+ if (do_krb4 || status == KRB5_FCC_NOFILE)
+ fprintf(stderr, "%s: Kerberos rcmd failed: %s.\n",
+ argv0[0],
+ (v4_status == -1) ? "rcmd protocol failure" :
+ krb_err_txt[v4_status]);
+ if (!do_krb4 && status != KRB5_FCC_NOFILE)
+#endif
+ fprintf(stderr,
+ "%s: kcmd to host %s failed - %s\n",argv0[0],
+ host,
+ (status == -1) ?
+ "rcmd protocol failure" :
+ error_message(status));
+ try_normal(host_offset,argv0);
+#ifdef KRB5_KRB4_COMPAT
+ }
+#endif
}

/* Setup for des_read and write */
- desinbuf.data = des_inbuf;
- desoutbuf.data = des_outbuf;
- krb5_use_enctype(bsd_context, &eblock,cred->keyblock.enctype);
- if (status = krb5_process_key(bsd_context, &eblock,&cred->keyblock)) {
- fprintf(stderr, "%s: Cannot process session key : %s.\n",
- argv0, error_message(status));
- exit(1);
+#ifdef KRB5_KRB4_COMPAT
+ if (status == 0) {
+#endif
+ desinbuf.data = des_inbuf;
+ desoutbuf.data = des_outbuf;
+ krb5_use_enctype(bsd_context, &eblock,cred->keyblock.enctype);
+ if (status = krb5_process_key(bsd_context, &eblock,&cred->keyblock)) {
+ fprintf(stderr, "%s: Cannot process session key : %s.\n",
+ argv0, error_message(status));
+ exit(1);
+ }
+#ifdef KRB5_KRB4_COMPAT
}
+#endif
#ifdef HAVE_ISATTY
if(encrypt_flag&&isatty(2)) {
write(2,SECURE_MESSAGE, strlen(SECURE_MESSAGE));
@@ -471,7 +566,7 @@
}
if (FD_ISSET(rem, &rembits) == 0)
goto rewrite;
- wc = des_write(rem, bp, cc);
+ wc = (*des_write)(rem, bp, cc);
if (wc < 0) {
if ((errno == EWOULDBLOCK) || (errno == EAGAIN))
goto rewrite;
@@ -506,7 +601,7 @@
}
if (FD_ISSET(rfd2, &ready)) {
errno = 0;
- cc = des_read(rfd2, buf, sizeof buf);
+ cc = (*des_read)(rfd2, buf, sizeof buf);
if (cc <= 0) {
if ((errno != EWOULDBLOCK) && (errno != EAGAIN))
FD_CLR(rfd2, &readfrom);
@@ -515,7 +610,7 @@
}
if (FD_ISSET(rem, &ready)) {
errno = 0;
- cc = des_read(rem, buf, sizeof buf);
+ cc = (*des_read)(rem, buf, sizeof buf);
if (cc <= 0) {
if ((errno != EWOULDBLOCK) && (errno != EAGAIN))
FD_CLR(rem, &readfrom);
@@ -539,50 +634,97 @@
krb5_sigtype sendsig(signo)
char signo;
{
- (void) des_write(rfd2, &signo, 1);
+ (void) (*des_write)(rfd2, &signo, 1);
}



#ifdef KERBEROS
-void try_normal(argv)
+
+static char *ucb_rsh[] = {
+#ifdef __hpux
+ "/usr/bin/remsh",
+#else
+ "/usr/bin/rsh",
+ "/usr/ucb/rsh",
+ "/usr/bsd/rsh",
+#endif
+ ""
+};
+
+void try_normal(host_offset,argv)
+ int host_offset;
char **argv;
{
- char *host;
+ char **rsh;
+ char *host = argv[host_offset];
+ struct stat statbuf;
+ ino_t my_inode = 0;
+ dev_t my_device = 0;

-#ifndef KRB5_ATHENA_COMPAT
if (encrypt_flag)
exit(1);
-#endif
- /*
- * if we were invoked as 'rsh host mumble', strip off the rsh
- * from arglist.
- *
- * We always want to call the Berkeley rsh as 'host mumble'
+
+ /* Try to prevent recursion in case kerberos rsh is installed
+ * as the default rsh.
+ */
+ if (stat(argv[0],&statbuf) == 0) {
+ my_inode = statbuf.st_ino;
+ my_device = statbuf.st_dev;
+ }
+
+ /* Ensure hostname is first argument to be compatible with
+ * vendor version.
*/
- host = strrchr(argv[0], '/');
- if (host)
- host++;
- else
- host = argv[0];
+ if (host_offset > 1) {
+ int i;
+ /* Push it back to the first argument. */
+ for (i = host_offset; i > 1; i--) {
+ argv[i] = argv[i-1];
+ }
+ argv[1] = host;
+ }
+
+ /* Search standard paths to the vendor version. */
+ for (rsh = ucb_rsh; **rsh; rsh++) {
+ if (access(*rsh,X_OK) == 0) {
+ if (stat(*rsh,&statbuf) == 0 &&
+ (statbuf.st_ino != my_inode ||
+ statbuf.st_dev != my_device)) {
+ fprintf(stderr,"trying normal rsh (%s)\n",*rsh);
+ fflush(stderr);
+
+ /*
+ * if we were invoked as 'rsh host mumble', strip off
+ * the rsh from arglist.
+ *
+ * We always want to call the Berkeley rsh as 'host mumble'
+ * since if no arguments were given, we're really asking
+ * to run rlogin.
+ */
+ host = strrchr(argv[0], '/');
+ if (host)
+ host++;
+ else
+ host = argv[0];

- if (!strcmp(host, "rsh"))
- argv++;
+ if (!strcmp(host, "rsh"))
+ argv++;

- fprintf(stderr,"trying normal rsh (%s)\n",
- UCB_RSH);
- fflush(stderr);
- execv(UCB_RSH, argv);
- perror("exec");
+ execv(*rsh, argv);
+ perror("exec");
+ exit(1);
+ }
+ }
+ }
exit(1);
}

-
char storage[2*RSH_BUFSIZ];
int nstored = 0;
char *store_ptr = storage;

-int des_read(fd, buf, len)
+int v5_des_read(fd, buf, len)
int fd;
register char *buf;
int len;
@@ -651,7 +793,7 @@



-int des_write(fd, buf, len)
+int v5_des_write(fd, buf, len)
int fd;
char *buf;
int len;

--- appl/bsd/rsh.M.orig Fri Feb 6 19:41:18 1998
+++ appl/bsd/rsh.M Wed May 20 19:34:29 1998
@@ -24,7 +24,12 @@
.B rsh
.I host
[\fB\-l\fP \fIusername\fP] [\fB\-n\fP] [\fB\-d\fP] [\fB\-k\fP
-\fIrealm\fP] [\fB\-f\fP | \fB\-F\fP] [\fB\-x\fP]
+\fIrealm\fP] [\fB\-f\fP | \fB\-F\fP] [\fB\-x\fP] [\fB\-4\fP]
+[\fB\-k4\fP \fIkrb4realm\fP]
+.I command
+.br
+.B rsh
+.I [\fIusername\fP@\fIhost\fP] [\fBoptions\fP]
.I command
.SH DESCRIPTION
.B Rsh
@@ -52,6 +57,9 @@
account name using the aname -> lname mapping rules (see
.IR krb5_anadd (8)
for more details).
+.PP
+If rsh and rshd were compiled with kerberos IV support, the \&.klogin
+authorization list may be used, instead.
.SH OPTIONS
.TP
\fB\-l\fP \fIusername\fP
@@ -70,7 +78,8 @@
.I command
finishes. This option is mutually exclusive with the
.B \-F
-option.
+option. Forwardable tickets are not supported for kerberos IV
+connections.
.TP
\fB\-F\fP
cause
@@ -82,13 +91,27 @@
.I command
finishes. This option is mutually exclusive with the
.B \-f
-option.
+option. Forwardable tickets are not supported for kerberos IV
+connections.
+.TP
+.B \-4
+Default to kerberos IV. This option is only available if rsh was
+compiled with kerberos IV compatibility. The rsh default is to
+attempt a Version 5 connection and fallback to kerberos IV on failure.
.TP
\fB\-k\fP \fIrealm\fP
causes
.I rsh
to obtain tickets for the remote host in
.I realm
+instead of the remote host's realm as determined by
+.IR krb_realmofhost (3).
+.TP
+\fB\-k4\fP \fIkrb4realm\fP
+causes
+.I rsh
+to obtain kerberos IV tickets for the remote host in
+.I krb4realm
instead of the remote host's realm as determined by
.IR krb_realmofhost (3).
.TP
Show quoted text
>Audit-Trail:

Responsible-Changed-From-To: gnats-admin->krb5-unassigned
Responsible-Changed-By: raeburn
Responsible-Changed-When: Fri Sep 14 11:47:39 2001
Responsible-Changed-Why:
reformat/refile
Show quoted text
>Unformatted:
was fixed around 1.1.