*/
#include "includes.h"
-RCSID("$OpenBSD: scp.c,v 1.77 2001/07/18 16:45:52 mouring Exp $");
+RCSID("$OpenBSD: scp.c,v 1.89 2002/06/08 12:36:53 markus Exp $");
#include "xmalloc.h"
#include "atomicio.h"
/* For progressmeter() -- number of seconds before xfer considered "stalled" */
#define STALLTIME 5
-
-/* Progress meter bar */
-#define BAR \
- "************************************************************"\
- "************************************************************"\
- "************************************************************"\
- "************************************************************"
-#define MAX_BARLENGTH (sizeof(BAR) - 1)
+/* alarm() interval for updating progress meter */
+#define PROGRESSTIME 1
/* Visual statistics about files as they are transferred. */
void progressmeter(int);
int pin[2], pout[2], reserved[2];
if (verbose_mode)
- fprintf(stderr, "Executing: program %s host %s, user %s, command %s\n",
- ssh_program, host, remuser ? remuser : "(unspecified)", cmd);
+ fprintf(stderr,
+ "Executing: program %s host %s, user %s, command %s\n",
+ ssh_program, host,
+ remuser ? remuser : "(unspecified)", cmd);
/*
* Reserve two descriptors so that the real pipes won't get
#define CMDNEEDS 64
char cmd[CMDNEEDS]; /* must hold "rcp -r -p -d\0" */
-int main(int, char *[]);
int response(void);
void rsource(char *, struct stat *);
void sink(int, char *[]);
args.list = NULL;
addargs(&args, "ssh"); /* overwritten with ssh_program */
addargs(&args, "-x");
- addargs(&args, "-oFallBackToRsh no");
+ addargs(&args, "-oForwardAgent no");
+ addargs(&args, "-oClearAllForwardings yes");
fflag = tflag = 0;
- while ((ch = getopt(argc, argv, "dfprtvBCc:i:P:q46S:o:")) != -1)
+ while ((ch = getopt(argc, argv, "dfprtvBCc:i:P:q46S:o:F:")) != -1)
switch (ch) {
/* User-visible flags. */
case '4':
case 'o':
case 'c':
case 'i':
+ case 'F':
addargs(&args, "-%c%s", ch, optarg);
break;
case 'P':
for (i = 0; i < argc - 1; i++) {
src = colon(argv[i]);
if (src) { /* remote to remote */
+ static char *ssh_options =
+ "-x -o'ClearAllForwardings yes'";
*src++ = 0;
if (*src == 0)
src = ".";
host = strchr(argv[i], '@');
len = strlen(ssh_program) + strlen(argv[i]) +
strlen(src) + (tuser ? strlen(tuser) : 0) +
- strlen(thost) + strlen(targ) + CMDNEEDS + 32;
+ strlen(thost) + strlen(targ) +
+ strlen(ssh_options) + CMDNEEDS + 20;
bp = xmalloc(len);
if (host) {
*host++ = 0;
else if (!okname(suser))
continue;
snprintf(bp, len,
- "%s%s -x -o'FallBackToRsh no' -n "
+ "%s%s %s -n "
"-l %s %s %s %s '%s%s%s:%s'",
ssh_program, verbose_mode ? " -v" : "",
- suser, host, cmd, src,
+ ssh_options, suser, host, cmd, src,
tuser ? tuser : "", tuser ? "@" : "",
thost, targ);
} else {
host = cleanhostname(argv[i]);
snprintf(bp, len,
- "exec %s%s -x -o'FallBackToRsh no' -n %s "
+ "exec %s%s %s -n %s "
"%s %s '%s%s%s:%s'",
ssh_program, verbose_mode ? " -v" : "",
- host, cmd, src,
+ ssh_options, host, cmd, src,
tuser ? tuser : "", tuser ? "@" : "",
thost, targ);
}
len = strlen(name);
while (len > 1 && name[len-1] == '/')
name[--len] = '\0';
+ if (strchr(name, '\n') != NULL) {
+ run_err("%s: skipping, filename contains a newline",
+ name);
+ goto next;
+ }
if ((fd = open(name, O_RDONLY, 0)) < 0)
goto syserr;
if (fstat(fd, &stb) < 0) {
#ifdef HAVE_LONG_LONG_INT
snprintf(buf, sizeof buf, "C%04o %lld %s\n",
(u_int) (stb.st_mode & FILEMODEMASK),
- (long long) stb.st_size, last);
+ (long long)stb.st_size, last);
#else
/* XXX: Handle integer overflow? */
snprintf(buf, sizeof buf, "C%04o %lu %s\n",
(u_int) (stb.st_mode & FILEMODEMASK),
(u_long) stb.st_size, last);
#endif
-
if (verbose_mode) {
fprintf(stderr, "Sending file modes: %s", buf);
fflush(stderr);
cursize = need;
}
(void) snprintf(namebuf, need, "%s%s%s", targ,
- *targ ? "/" : "", cp);
+ strcmp(targ, "/") ? "/" : "", cp);
np = namebuf;
} else
np = targ;
count += amt;
do {
j = read(remin, cp, amt);
- if (j == -1 && (errno == EINTR || errno == EAGAIN)) {
+ if (j == -1 && (errno == EINTR ||
+ errno == EAGAIN)) {
continue;
} else if (j <= 0) {
run_err("%s", j ? strerror(errno) :
}
int
-response()
+response(void)
{
char ch, *cp, resp, rbuf[2048];
}
void
-usage()
+usage(void)
{
- (void) fprintf(stderr, "usage: scp "
- "[-pqrvBC46] [-S ssh] [-P port] [-c cipher] [-i identity] "
- "[-o option] f1 f2\n"
+ (void) fprintf(stderr,
+ "usage: scp [-pqrvBC46] [-F config] [-S ssh] [-P port] [-c cipher] [-i identity]\n"
+ " [-o option] f1 f2\n"
" or: scp [options] f1 ... fn directory\n");
exit(1);
}
int fd, blksize;
{
size_t size;
-#ifdef HAVE_ST_BLKSIZE
+#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
struct stat stb;
if (fstat(fd, &stb) < 0) {
else
size = blksize + (stb.st_blksize - blksize % stb.st_blksize) %
stb.st_blksize;
-#else /* HAVE_ST_BLKSIZE */
+#else /* HAVE_STRUCT_STAT_ST_BLKSIZE */
size = blksize;
-#endif /* HAVE_ST_BLKSIZE */
+#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
if (bp->cnt >= size)
return (bp);
if (bp->buf == NULL)
bp->buf = xmalloc(size);
else
bp->buf = xrealloc(bp->buf, size);
+ memset(bp->buf, 0, size);
bp->cnt = size;
return (bp);
}
exit(1);
}
-
-static void
-alarmtimer(int wait)
-{
- struct itimerval itv;
-
- itv.it_value.tv_sec = wait;
- itv.it_value.tv_usec = 0;
- itv.it_interval = itv.it_value;
- setitimer(ITIMER_REAL, &itv, NULL);
-}
-
static void
updateprogressmeter(int ignore)
{
int save_errno = errno;
progressmeter(0);
+ signal(SIGALRM, updateprogressmeter);
+ alarm(PROGRESSTIME);
errno = save_errno;
}
off_t cursize, abbrevsize;
double elapsed;
int ratio, barlength, i, remaining;
- char buf[256];
+ char buf[512];
if (flag == -1) {
(void) gettimeofday(&start, (struct timezone *) 0);
snprintf(buf, sizeof(buf), "\r%-20.20s %3d%% ", curfile, ratio);
barlength = getttywidth() - 51;
- barlength = (barlength <= MAX_BARLENGTH)?barlength:MAX_BARLENGTH;
if (barlength > 0) {
i = barlength * ratio / 100;
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
- "|%.*s%*s|", i, BAR, barlength - i, "");
+ "|%.*s%*s|", i,
+ "*******************************************************"
+ "*******************************************************"
+ "*******************************************************"
+ "*******************************************************"
+ "*******************************************************"
+ "*******************************************************"
+ "*******************************************************",
+ barlength - i, "");
}
i = 0;
abbrevsize = cursize;
if (flag == -1) {
mysignal(SIGALRM, updateprogressmeter);
- alarmtimer(1);
+ alarm(PROGRESSTIME);
} else if (flag == 1) {
- alarmtimer(0);
+ alarm(0);
atomicio(write, fileno(stdout), "\n", 1);
statbytes = 0;
}