From ffc34c8b840650c3df0d6be0a4d9c717a439b112 Mon Sep 17 00:00:00 2001 From: Mark Eichin Date: Fri, 21 Apr 1995 21:15:52 +0000 Subject: [PATCH] More changes from ian@cygnus.com to support testing > Fri Mar 24 15:04:25 1995 Ian Lance Taylor * krcp.c (forcenet): New global vraiable. (main): Accept -D and -N arguments. Pass Kerberos realm to remote rcp execution. (hosteq): If -N specified, always return 0. * rcp.M: Document -D and -N. * krshd.c (ARGSTR): Add "P:" to KERBEROS version. (kprogdir): New global variable. (main): Handle -P. (path): Remove global variable. (path_rest): Remove explicit size. (envinit): Use 0 instead of path. (PATHENV): define. (doit): Use kprogdir variable instead of KPROGDIR macro when setting path. Build path in allocated memory rather than using a fixed size array. If the command starts with "rcp ", force use of kprogdir/rcp if it exists. * krshd.M: Document -P. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@5429 dc483132-0cff-0310-8789-dd5450dbe970 --- src/appl/bsd/ChangeLog | 24 +++++++++++++++++ src/appl/bsd/krcp.c | 33 +++++++++++++++++++---- src/appl/bsd/krshd.M | 6 ++++- src/appl/bsd/krshd.c | 60 +++++++++++++++++++++++++++++++++++------- src/appl/bsd/rcp.M | 17 +++++++++++- 5 files changed, 124 insertions(+), 16 deletions(-) diff --git a/src/appl/bsd/ChangeLog b/src/appl/bsd/ChangeLog index c770feefc..68c974658 100644 --- a/src/appl/bsd/ChangeLog +++ b/src/appl/bsd/ChangeLog @@ -1,3 +1,27 @@ +Fri Apr 21 17:13:48 1995 Mark Eichin + + More changes from ian@cygnus.com to support testing. + +> Fri Mar 24 15:04:25 1995 Ian Lance Taylor + + * krcp.c (forcenet): New global vraiable. + (main): Accept -D and -N arguments. Pass Kerberos realm to remote + rcp execution. + (hosteq): If -N specified, always return 0. + * rcp.M: Document -D and -N. + * krshd.c (ARGSTR): Add "P:" to KERBEROS version. + (kprogdir): New global variable. + (main): Handle -P. + (path): Remove global variable. + (path_rest): Remove explicit size. + (envinit): Use 0 instead of path. + (PATHENV): define. + (doit): Use kprogdir variable instead of KPROGDIR macro when + setting path. Build path in allocated memory rather than using a + fixed size array. If the command starts with "rcp ", force use of + kprogdir/rcp if it exists. + * krshd.M: Document -P. + Fri Apr 21 14:07:15 1995 Mark Eichin Added Ian's changes with minor tweaks. These are used by the testsuite. diff --git a/src/appl/bsd/krcp.c b/src/appl/bsd/krcp.c index 7eaee827e..25f36dce1 100644 --- a/src/appl/bsd/krcp.c +++ b/src/appl/bsd/krcp.c @@ -109,6 +109,7 @@ extern char *sys_errlist[]; int iamremote, targetshouldbedirectory; int iamrecursive; int pflag; +int forcenet; struct passwd *pwd; int userid; int port; @@ -133,7 +134,8 @@ main(argc, argv) char *targ, *host, *src; char *suser, *tuser, *thost; int i; - char buf[BUFSIZ], cmd[16]; + char buf[BUFSIZ], cmdbuf[16]; + char *cmd = cmdbuf; struct servent *sp; static char curhost[256]; #ifdef POSIX_SIGNALS @@ -181,6 +183,17 @@ main(argc, argv) pflag++; break; + case 'D': + argc--, argv++; + if (argc == 0) + usage(); + port = atoi(*argv); + goto next_arg; + + case 'N': + forcenet++; + break; + #ifdef KERBEROS case 'x': encryptflag++; @@ -223,9 +236,7 @@ main(argc, argv) default: usage(); } -#ifdef KERBEROS next_arg: ; -#endif /* KERBEROS */ } if (argc < 2) @@ -234,10 +245,19 @@ main(argc, argv) targetshouldbedirectory = 1; rem = -1; #ifdef KERBEROS - (void) sprintf(cmd, "rcp%s%s%s%s", + if (krb_realm != NULL) { + cmd = (char *) malloc(strlen(krb_realm) + 20); + if (cmd == NULL) { + fprintf(stderr, "rcp: Cannot malloc.\n"); + exit(1); + } + } + (void) sprintf(cmd, "rcp%s%s%s%s%s%s", iamrecursive ? " -r" : "", pflag ? " -p" : "", encryptflag ? " -x" : "", - targetshouldbedirectory ? " -d" : ""); + targetshouldbedirectory ? " -d" : "", + krb_realm != NULL ? " -k " : "", + krb_realm != NULL ? krb_realm : ""); #else /* !KERBEROS */ (void) sprintf(cmd, "rcp%s%s%s", iamrecursive ? " -r" : "", pflag ? " -p" : "", @@ -1083,6 +1103,9 @@ hosteq(h1, h2) struct hostent *h_ptr; char hname1[256]; + if (forcenet) + return(0); + /* get the official names for the two hosts */ if ((h_ptr = gethostbyname(h1)) == NULL) diff --git a/src/appl/bsd/krshd.M b/src/appl/bsd/krshd.M index a5d1f12c2..20a0d2b83 100644 --- a/src/appl/bsd/krshd.M +++ b/src/appl/bsd/krshd.M @@ -68,7 +68,7 @@ behaviour of the program exactly as with the command-line arguments. If the \fB\-r\fP or \fB\-R\fP options are used, the client must connect from a privileged port. .PP -\fIKrshd\fP supports three options which may be used for testing: +\fIKrshd\fP supports four options which may be used for testing: .IP \fB\-S\ srvtab\fP 10 Set the \fIsrvtab\fP file to use. @@ -78,6 +78,10 @@ Set the Kerberos realm to use. .IP \fB\-A\fP Don't allocate a reserved port for the stderr connection. + +.IP \fB\-P\ path\fP +Use the argument to find the Kerberos binaries. Normally a compiled +in argument is used. .SH DIAGNOSTICS Except for the last one listed below, all diagnostic messages diff --git a/src/appl/bsd/krshd.c b/src/appl/bsd/krshd.c index 2ce15a99b..eab21635c 100644 --- a/src/appl/bsd/krshd.c +++ b/src/appl/bsd/krshd.c @@ -158,7 +158,7 @@ char copyright[] = #include "com_err.h" #include "loginpaths.h" -#define ARGSTR "rRxXeEkKD:S:M:A?" +#define ARGSTR "rRxXeEkKD:S:M:AP:?" #define SECURE_MESSAGE "This rsh session is using DES encryption for all data transmissions.\r\n" @@ -186,6 +186,7 @@ int (*des_write)() = v5_des_write; int do_encrypt = 0; int anyport = 0; +char *kprogdir = KPROGDIR; int netf; #else /* !KERBEROS */ @@ -327,6 +328,10 @@ main(argc, argv) case 'A': anyport = 1; break; + + case 'P': + kprogdir = optarg; + break; #endif case 'D': debug_port = atoi(optarg); @@ -416,25 +421,26 @@ char username[20] = "USER="; char homedir[64] = "HOME="; char shell[64] = "SHELL="; char term[64] = "TERM=network"; -char path[128] = "PATH="; -char path_rest[64] = RPATH; +char path_rest[] = RPATH; #ifdef CRAY char *envinit[] = -{homedir, shell, path, username, "TZ=GMT0", tmpdir, term, 0}; +{homedir, shell, 0, username, "TZ=GMT0", tmpdir, term, 0}; #define TZENV 4 #define TMPDIRENV 5 char *getenv(); #else /* CRAY */ #ifdef KERBEROS char *envinit[] = -{homedir, shell, path, username, term, 0}; +{homedir, shell, 0, username, term, 0}; #else /* KERBEROS */ char *envinit[] = -{homedir, shell, path, username, term, 0}; +{homedir, shell, 0, username, term, 0}; #endif /* KERBEROS */ #endif /* CRAY */ +#define PATHENV 2 + extern char **environ; char ttyn[12]; /* Line string for wtmp entries */ @@ -487,6 +493,7 @@ doit(f, fromp) register char *p; char *crypt(); struct passwd *pwd; + char *path; #ifdef CRAY #ifndef NO_UDB @@ -1219,15 +1226,50 @@ doit(f, fromp) strncat(homedir, pwd->pw_dir, sizeof(homedir)-6); strncat(shell, pwd->pw_shell, sizeof(shell)-7); strncat(username, pwd->pw_name, sizeof(username)-6); - strcat(path, KPROGDIR); - strcat(path, ":"); - strcat(path, path_rest); + path = (char *) malloc(strlen(kprogdir) + strlen(path_rest) + 7); + if (path == NULL) { + perror("malloc"); + _exit(1); + } + sprintf(path, "PATH=%s:%s", kprogdir, path_rest); + envinit[PATHENV] = path; cp = strrchr(pwd->pw_shell, '/'); if (cp) cp++; else cp = pwd->pw_shell; +#ifdef KERBEROS + /* To make Kerberos rcp work correctly, we must ensure that we + invoke Kerberos rcp on this end, not normal rcp, even if the + shell startup files change PATH. */ + if (!strncmp(cmdbuf, "rcp ", 4) || + (do_encrypt && !strncmp(cmdbuf, "-x rcp ", 7))) { + char *copy; + struct stat s; + + copy = malloc(strlen(cmdbuf) + 1); + if (copy == NULL) { + perror("malloc"); + _exit(1); + } + strcpy(copy, cmdbuf); + if (do_encrypt && !strncmp(cmdbuf, "-x ", 3)) { + strcpy(cmdbuf + 3, kprogdir); + cp = copy + 6; + } else { + strcpy(cmdbuf, kprogdir); + cp = copy + 3; + } + strcat(cmdbuf, "/rcp"); + if (stat(cmdbuf, &s) >= 0) + strcat(cmdbuf, cp); + else + strcpy(cmdbuf, copy); + free(copy); + } +#endif + if (do_encrypt && !strncmp(cmdbuf, "-x ", 3)) { execl(pwd->pw_shell, cp, "-c", (char *)cmdbuf + 3, 0); } diff --git a/src/appl/bsd/rcp.M b/src/appl/bsd/rcp.M index 7e826f345..7df82a6f0 100644 --- a/src/appl/bsd/rcp.M +++ b/src/appl/bsd/rcp.M @@ -30,7 +30,11 @@ rcp \- remote file copy .B \-x ] [ .B \-k -realm ] file1 file2 +realm ] [ +.B \-D +port ] [ +.B \-N +] file1 file2 .br .B rcp [ @@ -41,6 +45,10 @@ realm ] file1 file2 .B \-k realm ] [ .B \-r +] [ +.B \-D +port ] [ +.B \-N ] file ... directory .SH DESCRIPTION .I Rcp @@ -113,6 +121,13 @@ to obtain tickets for the remote host in instead of the remote host's realm as determined by .IR krb_realmofhost (3). .PP +The +.B \-D +option specifies the port to connect to on the remote machine. The +.B \-N +option tells rcp to use a network connection even when copying files +on the local machine. These options are used for testing purposes. +.PP .I Rcp handles third party copies, where neither source nor target files are on the current machine. -- 2.26.2