+Fri Apr 21 17:13:48 1995 Mark Eichin <eichin@cygnus.com>
+
+ More changes from ian@cygnus.com to support testing.
+
+> Fri Mar 24 15:04:25 1995 Ian Lance Taylor <ian@cygnus.com>
+
+ * 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 <eichin@cygnus.com>
Added Ian's changes with minor tweaks. These are used by the testsuite.
int iamremote, targetshouldbedirectory;
int iamrecursive;
int pflag;
+int forcenet;
struct passwd *pwd;
int userid;
int port;
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
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++;
default:
usage();
}
-#ifdef KERBEROS
next_arg: ;
-#endif /* KERBEROS */
}
if (argc < 2)
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" : "",
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)
#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"
int do_encrypt = 0;
int anyport = 0;
+char *kprogdir = KPROGDIR;
int netf;
#else /* !KERBEROS */
case 'A':
anyport = 1;
break;
+
+ case 'P':
+ kprogdir = optarg;
+ break;
#endif
case 'D':
debug_port = atoi(optarg);
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 */
register char *p;
char *crypt();
struct passwd *pwd;
+ char *path;
#ifdef CRAY
#ifndef NO_UDB
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);
}