*/
#include "includes.h"
-RCSID("$OpenBSD: scp.c,v 1.42 2000/10/14 10:07:21 markus Exp $");
+RCSID("$OpenBSD: scp.c,v 1.51 2001/01/21 19:05:55 markus Exp $");
-#include "ssh.h"
#include "xmalloc.h"
+#include "atomicio.h"
+#include "pathnames.h"
+#include "log.h"
-#ifndef _PATH_CP
-#define _PATH_CP "cp"
+#ifdef HAVE___PROGNAME
+extern char *__progname;
+#else
+char *__progname;
#endif
/* For progressmeter() -- number of seconds before xfer considered "stalled" */
static struct timeval start;
/* Number of bytes of current file transferred so far. */
-volatile unsigned long statbytes;
+volatile u_long statbytes;
/* Total size of current file. */
off_t totalbytes = 0;
/* This is set to non-zero to enable verbose mode. */
int verbose_mode = 0;
-/* This is set to non-zero if compression is desired. */
-int compress_flag = 0;
-
/* This is set to zero if the progressmeter is not desired. */
int showprogress = 1;
/* This is the program to execute for the secured connection. ("ssh" or -S) */
-char *ssh_program = SSH_PROGRAM;
+char *ssh_program = _PATH_SSH_PROGRAM;
/* This is the list of arguments that scp passes to ssh */
struct {
return 0;
}
-void
-fatal(const char *fmt,...)
-{
- va_list ap;
- char buf[1024];
-
- va_start(ap, fmt);
- vsnprintf(buf, sizeof(buf), fmt, ap);
- va_end(ap);
- fprintf(stderr, "%s\n", buf);
- exit(255);
-}
-
typedef struct {
int cnt;
char *buf;
extern char *optarg;
extern int optind;
+ __progname = get_progname(argv[0]);
+
args.list = NULL;
addargs("ssh"); /* overwritten with ssh_program */
addargs("-x");
addargs("-oFallBackToRsh no");
fflag = tflag = 0;
- while ((ch = getopt(argc, argv, "dfprtvBCc:i:P:q46S:o:")) != EOF)
+ while ((ch = getopt(argc, argv, "dfprtvBCc:i:P:q46S:o:")) != -1)
switch (ch) {
/* User-visible flags. */
case '4':
suser = pwd->pw_name;
else if (!okname(suser))
continue;
- (void) sprintf(bp,
+ sprintf(bp,
"%s%s -x -o'FallBackToRsh no' -n -l %s %s %s %s '%s%s%s:%s'",
- ssh_program, verbose_mode ? " -v" : "",
- suser, host, cmd, src,
- tuser ? tuser : "", tuser ? "@" : "",
- thost, targ);
+ ssh_program, verbose_mode ? " -v" : "",
+ suser, host, cmd, src,
+ tuser ? tuser : "", tuser ? "@" : "",
+ thost, targ);
} else {
host = cleanhostname(argv[i]);
- (void) sprintf(bp,
+ sprintf(bp,
"exec %s%s -x -o'FallBackToRsh no' -n %s %s %s '%s%s%s:%s'",
- ssh_program, verbose_mode ? " -v" : "",
- host, cmd, src,
- tuser ? tuser : "", tuser ? "@" : "",
- thost, targ);
+ ssh_program, verbose_mode ? " -v" : "",
+ host, cmd, src,
+ tuser ? tuser : "", tuser ? "@" : "",
+ thost, targ);
}
if (verbose_mode)
fprintf(stderr, "Executing: %s\n", bp);
* versions expecting microseconds.
*/
(void) sprintf(buf, "T%lu 0 %lu 0\n",
- (unsigned long) stb.st_mtime,
- (unsigned long) stb.st_atime);
+ (u_long) stb.st_mtime,
+ (u_long) stb.st_atime);
(void) atomicio(write, remout, buf, strlen(buf));
if (response() < 0)
goto next;
}
#define FILEMODEMASK (S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO)
- (void) sprintf(buf, "C%04o %lu %s\n",
- (unsigned int) (stb.st_mode & FILEMODEMASK),
- (unsigned long) stb.st_size,
- last);
+ sprintf(buf, "C%04o %lu %s\n",
+ (u_int) (stb.st_mode & FILEMODEMASK),
+ (u_long) stb.st_size, last);
if (verbose_mode) {
fprintf(stderr, "Sending file modes: %s", buf);
fflush(stderr);
last++;
if (pflag) {
(void) sprintf(path, "T%lu 0 %lu 0\n",
- (unsigned long) statp->st_mtime,
- (unsigned long) statp->st_atime);
+ (u_long) statp->st_mtime,
+ (u_long) statp->st_atime);
(void) atomicio(write, remout, path, strlen(path));
if (response() < 0) {
closedir(dirp);
}
}
(void) sprintf(path, "D%04o %d %.1024s\n",
- (unsigned int) (statp->st_mode & FILEMODEMASK), 0, last);
+ (u_int) (statp->st_mode & FILEMODEMASK), 0, last);
if (verbose_mode)
fprintf(stderr, "Entering directory: %s", path);
(void) atomicio(write, remout, path, strlen(path));
if (buf[0] == '\01' || buf[0] == '\02') {
if (iamremote == 0)
(void) atomicio(write, STDERR_FILENO,
- buf + 1, strlen(buf + 1));
+ buf + 1, strlen(buf + 1));
if (buf[0] == '\02')
exit(1);
++errs;
amt = size - i;
count += amt;
do {
- j = atomicio(read, remin, cp, amt);
- if (j <= 0) {
+ j = read(remin, cp, amt);
+ if (j == -1 && (errno == EINTR || errno == EAGAIN)) {
+ continue;
+ } else if (j <= 0) {
run_err("%s", j ? strerror(errno) :
"dropped connection");
exit(1);
c = *cp;
if (c & 0200)
goto bad;
- if (!isalpha(c) && !isdigit(c) && c != '_' && c != '-')
+ if (!isalpha(c) && !isdigit(c) &&
+ c != '_' && c != '-' && c != '.' && c != '+')
goto bad;
} while (*++cp);
return (1);
if (pgrp == -1)
pgrp = getpgrp();
-#ifdef HAVE_CYGWIN
- /*
- * Cygwin only supports tcgetpgrp() for getting the controlling tty
- * currently.
- */
+#ifdef HAVE_TCGETPGRP
return ((ctty_pgrp = tcgetpgrp(STDOUT_FILENO)) != -1 &&
ctty_pgrp == pgrp);
#else
abbrevsize >>= 10;
}
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " %5d %c%c ",
- (int) abbrevsize, prefixes[i], prefixes[i] == ' ' ? ' ' :
- 'B');
+ (int) abbrevsize, prefixes[i], prefixes[i] == ' ' ? ' ' : 'B');
timersub(&now, &lastupdate, &wait);
if (cursize > lastsize) {
timersub(&now, &start, &td);
elapsed = td.tv_sec + (td.tv_usec / 1000000.0);
- if (statbytes <= 0 || elapsed <= 0.0 || cursize > totalbytes) {
+ if (flag != 1 &&
+ (statbytes <= 0 || elapsed <= 0.0 || cursize > totalbytes)) {
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
- " --:-- ETA");
+ " --:-- ETA");
} else if (wait.tv_sec >= STALLTIME) {
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
- " - stalled -");
+ " - stalled -");
} else {
if (flag != 1)
- remaining =
- (int)(totalbytes / (statbytes / elapsed) - elapsed);
+ remaining = (int)(totalbytes / (statbytes / elapsed) -
+ elapsed);
else
remaining = elapsed;