* 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
#endif /* not lint */
#ifndef lint
-static char sccsid[] = "@(#)rcp.c 5.31 (Berkeley) %G%";
+static char sccsid[] = "@(#)rcp.c 5.32 (Berkeley) 2/25/91";
#endif /* not lint */
/*
* rcp
*/
#include <sys/param.h>
-#include <sys/file.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/ioctl.h>
-#include <sys/dir.h>
-#include <sys/signal.h>
+#include <sys/socket.h>
+#include <sys/wait.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
+#include <dirent.h>
+#include <fcntl.h>
+#include <signal.h>
#include <pwd.h>
#include <netdb.h>
#include <errno.h>
-#include <string.h>
+#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <ctype.h>
#include "pathnames.h"
CREDENTIALS cred;
Key_schedule schedule;
extern char *krb_realmofhost();
-#define OPTIONS "dfkprt"
+#ifdef CRYPT
+int doencrypt = 0;
+#define OPTIONS "dfk:prtx"
+#else
+#define OPTIONS "dfk:prt"
+#endif
#else
#define OPTIONS "dfprt"
#endif
-extern int errno;
struct passwd *pwd;
u_short port;
uid_t userid;
char *buf;
} BUF;
+void lostconn();
+
main(argc, argv)
int argc;
char **argv;
{
extern int optind;
+ extern char *optarg;
struct servent *sp;
int ch, fflag, tflag;
char *targ, *shell, *colon();
- struct passwd *getpwuid();
- int lostconn();
fflag = tflag = 0;
while ((ch = getopt(argc, argv, OPTIONS)) != EOF)
break;
#ifdef KERBEROS
case 'k':
- strncpy(dst_realm_buf, ++argv, REALM_SZ);
+ strncpy(dst_realm_buf, optarg, REALM_SZ);
dest_realm = dst_realm_buf;
break;
+#ifdef CRYPT
+ case 'x':
+ doencrypt = 1;
+ /* des_set_key(cred.session, schedule); */
+ break;
+#endif
#endif
/* rshd-invoked options (server) */
case 'd':
argv += optind;
#ifdef KERBEROS
+#ifdef CRYPT
+ shell = doencrypt ? "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",
- shell);
+ (void)snprintf(msgbuf, sizeof(msgbuf),
+ "can't get entry for %s/tcp service", shell);
old_warning(msgbuf);
sp = getservbyname(shell = "shell", "tcp");
}
rem = -1;
/* command to be executed on remote system using "rsh" */
#ifdef KERBEROS
- (void)sprintf(cmd, "rcp%s%s%s%s", iamrecursive ? " -r" : "",
+ (void)snprintf(cmd, sizeof(cmd),
+ "rcp%s%s%s%s", iamrecursive ? " -r" : "",
+#ifdef CRYPT
+ ((doencrypt && use_kerberos) ? " -x" : ""),
+#else
"",
+#endif
pflag ? " -p" : "", targetshouldbedirectory ? " -d" : "");
#else
- (void)sprintf(cmd, "rcp%s%s%s", iamrecursive ? " -r" : "",
- pflag ? " -p" : "", targetshouldbedirectory ? " -d" : "");
+ (void)snprintf(cmd, sizeof(cmd), "rcp%s%s%s",
+ iamrecursive ? " -r" : "", pflag ? " -p" : "",
+ targetshouldbedirectory ? " -d" : "");
#endif
(void)signal(SIGPIPE, lostconn);
int argc;
char **argv;
{
- int i, tos;
+ int i, len, tos;
char *bp, *host, *src, *suser, *thost, *tuser;
char *colon();
if (*src == 0)
src = ".";
host = index(argv[i], '@');
- if (!(bp = malloc(strlen(_PATH_RSH) +
- strlen(argv[i]) + strlen(src) +
- (tuser ? strlen(tuser) : 0) +
- strlen(thost) +
- strlen(targ) + CMDNEEDS + 20)))
- nospace();
+ len = strlen(_PATH_RSH) + strlen(argv[i]) +
+ strlen(src) + (tuser ? strlen(tuser) : 0) +
+ strlen(thost) + strlen(targ) + CMDNEEDS + 20;
+ if (!(bp = malloc(len)))
+ nospace();
if (host) {
*host++ = 0;
suser = argv[i];
suser = pwd->pw_name;
else if (!okname(suser))
continue;
- (void)sprintf(bp,
+ (void)snprintf(bp, len,
"%s %s -l %s -n %s %s '%s%s%s:%s'",
_PATH_RSH, host, suser, cmd, src,
tuser ? tuser : "", tuser ? "@" : "",
thost, targ);
} else
- (void)sprintf(bp, "%s %s -n %s %s '%s%s%s:%s'",
+ (void)snprintf(bp, len,
+ "%s %s -n %s %s '%s%s%s:%s'",
_PATH_RSH, argv[i], cmd, src,
tuser ? tuser : "", tuser ? "@" : "",
thost, targ);
(void)free(bp);
} else { /* local to remote */
if (rem == -1) {
- if (!(bp = malloc(strlen(targ) +
- CMDNEEDS + 20)))
+ len = strlen(targ) + CMDNEEDS + 20;
+ if (!(bp = malloc(len)))
nospace();
- (void)sprintf(bp, "%s -t %s", cmd, targ);
+ (void)snprintf(bp, len, "%s -t %s", cmd, targ);
host = thost;
#ifdef KERBEROS
if (use_kerberos)
int argc;
char **argv;
{
- int i, tos;
+ int i, len, tos;
char *bp, *host, *src, *suser;
char *colon();
for (i = 0; i < argc - 1; i++) {
if (!(src = colon(argv[i]))) { /* local to local */
- if (!(bp = malloc(strlen(_PATH_CP) +
- strlen(argv[i]) + strlen(argv[argc - 1]) + 20)))
+ len = strlen(_PATH_CP) + strlen(argv[i]) +
+ strlen(argv[argc - 1]) + 20;
+ if (!(bp = malloc(len)))
nospace();
- (void)sprintf(bp, "%s%s%s %s %s", _PATH_CP,
+ (void)snprintf(bp, len, "%s%s%s %s %s", _PATH_CP,
iamrecursive ? " -r" : "", pflag ? " -p" : "",
argv[i], argv[argc - 1]);
(void)susystem(bp);
host = argv[i];
suser = pwd->pw_name;
}
- if (!(bp = malloc(strlen(src) + CMDNEEDS + 20)))
+ len = strlen(src) + CMDNEEDS + 20;
+ if (!(bp = malloc(len)))
nospace();
- (void)sprintf(bp, "%s -f %s", cmd, src);
+ (void)snprintf(bp, len, "%s -f %s", cmd, src);
#ifdef KERBEROS
if (use_kerberos)
rem = kerberos(&host, bp, pwd->pw_name, suser);
* Make it compatible with possible future
* versions expecting microseconds.
*/
- (void)sprintf(buf, "T%ld 0 %ld 0\n", stb.st_mtime,
- stb.st_atime);
+ (void)snprintf(buf, sizeof(buf),
+ "T%ld 0 %ld 0\n", stb.st_mtime, stb.st_atime);
(void)write(rem, buf, (int)strlen(buf));
if (response() < 0) {
(void)close(f);
continue;
}
}
- (void)sprintf(buf, "C%04o %ld %s\n", stb.st_mode&07777,
- stb.st_size, last);
+ (void)snprintf(buf, sizeof(buf),
+ "C%04o %ld %s\n", stb.st_mode&07777, stb.st_size, last);
(void)write(rem, buf, (int)strlen(buf));
if (response() < 0) {
(void)close(f);
char *name;
struct stat *statp;
{
- DIR *d;
- struct direct *dp;
+ DIR *dirp;
+ struct dirent *dp;
char *last, *vect[1], path[MAXPATHLEN];
- if (!(d = opendir(name))) {
+ if (!(dirp = opendir(name))) {
error("rcp: %s: %s\n", name, strerror(errno));
return;
}
else
last++;
if (pflag) {
- (void)sprintf(path, "T%ld 0 %ld 0\n", statp->st_mtime,
- statp->st_atime);
+ (void)snprintf(path, sizeof(path),
+ "T%ld 0 %ld 0\n", statp->st_mtime, statp->st_atime);
(void)write(rem, path, (int)strlen(path));
if (response() < 0) {
- closedir(d);
+ closedir(dirp);
return;
}
}
- (void)sprintf(path, "D%04o %d %s\n", statp->st_mode&07777, 0, last);
+ (void)snprintf(path, sizeof(path),
+ "D%04o %d %s\n", statp->st_mode&07777, 0, last);
(void)write(rem, path, (int)strlen(path));
if (response() < 0) {
- closedir(d);
+ closedir(dirp);
return;
}
- while (dp = readdir(d)) {
+ while (dp = readdir(dirp)) {
if (dp->d_ino == 0)
continue;
if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, ".."))
error("%s/%s: name too long.\n", name, dp->d_name);
continue;
}
- (void)sprintf(path, "%s/%s", name, dp->d_name);
+ (void)snprintf(path, sizeof(path), "%s/%s", name, dp->d_name);
vect[0] = path;
source(1, vect);
}
- closedir(d);
+ closedir(dirp);
(void)write(rem, "E\n", 2);
(void)response();
}
/*NOTREACHED*/
}
+void
lostconn()
{
if (!iamremote)
if (!(namebuf = malloc(need)))
error("out of memory\n");
}
- (void)sprintf(namebuf, "%s%s%s", targ,
+ (void)snprintf(namebuf, need, "%s%s%s", targ,
*targ ? "/" : "", cp);
np = namebuf;
}
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");
+#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");
if (dest_realm == NULL)
dest_realm = krb_realmofhost(*host);
+#ifdef CRYPT
+ if (doencrypt)
+ rem = krcmd_mutual(
+ host, port,
+ user, bp, 0,
+ dest_realm,
+ &cred, schedule);
+ else
+#endif
rem = krcmd(
host, port,
user, bp, 0, dest_realm);
goto again;
}
} else {
+#ifdef CRYPT
+ if (doencrypt) {
+ fprintf(stderr,
+ "The -x option requires Kerberos authentication\n");
+ exit(1);
+ }
+#endif
rem = rcmd(host, sp->s_port, locuser, user, bp, 0);
}
return(rem);