* 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
+ * 3. 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.
*
*/
#include "includes.h"
-RCSID("$OpenBSD: scp.c,v 1.102 2003/03/05 22:33:43 markus Exp $");
+RCSID("$OpenBSD: scp.c,v 1.108 2003/07/18 01:54:25 deraadt Exp $");
#include "xmalloc.h"
#include "atomicio.h"
char *ssh_program = _PATH_SSH_PROGRAM;
/* This is used to store the pid of ssh_program */
-pid_t do_cmd_pid;
+pid_t do_cmd_pid = -1;
+
+static void
+killchild(int signo)
+{
+ if (do_cmd_pid > 1)
+ kill(do_cmd_pid, signo);
+
+ _exit(1);
+}
/*
* This function executes the given command as the specified user on the
close(reserved[0]);
close(reserved[1]);
- /* For a child to execute the command on the remote host using ssh. */
+ /* Fork a child to execute the command on the remote host using ssh. */
do_cmd_pid = fork();
if (do_cmd_pid == 0) {
/* Child. */
*fdout = pin[1];
close(pout[1]);
*fdin = pout[0];
+ signal(SIGTERM, killchild);
+ signal(SIGINT, killchild);
+ signal(SIGHUP, killchild);
return 0;
}
void usage(void);
int
-main(argc, argv)
- int argc;
- char *argv[];
+main(int argc, char **argv)
{
int ch, fflag, tflag, status;
double speed;
extern char *optarg;
extern int optind;
- __progname = get_progname(argv[0]);
+ __progname = ssh_get_progname(argv[0]);
args.list = NULL;
addargs(&args, "ssh"); /* overwritten with ssh_program */
argv += optind;
if ((pwd = getpwuid(userid = getuid())) == NULL)
- fatal("unknown user %d", (int) userid);
+ fatal("unknown user %u", (u_int) userid);
if (!isatty(STDERR_FILENO))
showprogress = 0;
}
void
-toremote(targ, argc, argv)
- char *targ, *argv[];
- int argc;
+toremote(char *targ, int argc, char **argv)
{
int i, len;
char *bp, *host, *src, *suser, *thost, *tuser;
}
void
-tolocal(argc, argv)
- int argc;
- char *argv[];
+tolocal(int argc, char **argv)
{
int i, len;
char *bp, *host, *src, *suser;
}
void
-source(argc, argv)
- int argc;
- char *argv[];
+source(int argc, char **argv)
{
struct stat stb;
static BUF buffer;
(void) snprintf(buf, sizeof buf, "T%lu 0 %lu 0\n",
(u_long) stb.st_mtime,
(u_long) stb.st_atime);
- (void) atomicio(write, remout, buf, strlen(buf));
+ (void) atomicio(vwrite, remout, buf, strlen(buf));
if (response() < 0)
goto next;
}
#define FILEMODEMASK (S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO)
-#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);
-#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
+ (int64_t)stb.st_size, last);
if (verbose_mode) {
fprintf(stderr, "Sending file modes: %s", buf);
}
- (void) atomicio(write, remout, buf, strlen(buf));
+ (void) atomicio(vwrite, remout, buf, strlen(buf));
if (response() < 0)
goto next;
if ((bp = allocbuf(&buffer, fd, 2048)) == NULL) {
haderr = result >= 0 ? EIO : errno;
}
if (haderr)
- (void) atomicio(write, remout, bp->buf, amt);
+ (void) atomicio(vwrite, remout, bp->buf, amt);
else {
- result = atomicio(write, remout, bp->buf, amt);
+ result = atomicio(vwrite, remout, bp->buf, amt);
if (result != amt)
haderr = result >= 0 ? EIO : errno;
statbytes += result;
if (close(fd) < 0 && !haderr)
haderr = errno;
if (!haderr)
- (void) atomicio(write, remout, "", 1);
+ (void) atomicio(vwrite, remout, "", 1);
else
run_err("%s: %s", name, strerror(haderr));
(void) response();
}
void
-rsource(name, statp)
- char *name;
- struct stat *statp;
+rsource(char *name, struct stat *statp)
{
DIR *dirp;
struct dirent *dp;
(void) snprintf(path, sizeof(path), "T%lu 0 %lu 0\n",
(u_long) statp->st_mtime,
(u_long) statp->st_atime);
- (void) atomicio(write, remout, path, strlen(path));
+ (void) atomicio(vwrite, remout, path, strlen(path));
if (response() < 0) {
closedir(dirp);
return;
(u_int) (statp->st_mode & FILEMODEMASK), 0, last);
if (verbose_mode)
fprintf(stderr, "Entering directory: %s", path);
- (void) atomicio(write, remout, path, strlen(path));
+ (void) atomicio(vwrite, remout, path, strlen(path));
if (response() < 0) {
closedir(dirp);
return;
source(1, vect);
}
(void) closedir(dirp);
- (void) atomicio(write, remout, "E\n", 2);
+ (void) atomicio(vwrite, remout, "E\n", 2);
(void) response();
}
}
void
-sink(argc, argv)
- int argc;
- char *argv[];
+sink(int argc, char **argv)
{
static BUF buffer;
struct stat stb;
if (targetshouldbedirectory)
verifydir(targ);
- (void) atomicio(write, remout, "", 1);
+ (void) atomicio(vwrite, remout, "", 1);
if (stat(targ, &stb) == 0 && S_ISDIR(stb.st_mode))
targisdir = 1;
for (first = 1;; first = 0) {
if (buf[0] == '\01' || buf[0] == '\02') {
if (iamremote == 0)
- (void) atomicio(write, STDERR_FILENO,
+ (void) atomicio(vwrite, STDERR_FILENO,
buf + 1, strlen(buf + 1));
if (buf[0] == '\02')
exit(1);
continue;
}
if (buf[0] == 'E') {
- (void) atomicio(write, remout, "", 1);
+ (void) atomicio(vwrite, remout, "", 1);
return;
}
if (ch == '\n')
atime.tv_usec = strtol(cp, &cp, 10);
if (!cp || *cp++ != '\0')
SCREWUP("atime.usec not delimited");
- (void) atomicio(write, remout, "", 1);
+ (void) atomicio(vwrite, remout, "", 1);
continue;
}
if (*cp != 'C' && *cp != 'D') {
bad: run_err("%s: %s", np, strerror(errno));
continue;
}
- (void) atomicio(write, remout, "", 1);
+ (void) atomicio(vwrite, remout, "", 1);
if ((bp = allocbuf(&buffer, ofd, 4096)) == NULL) {
(void) close(ofd);
continue;
if (count == bp->cnt) {
/* Keep reading so we stay sync'd up. */
if (wrerr == NO) {
- j = atomicio(write, ofd, bp->buf, count);
+ j = atomicio(vwrite, ofd, bp->buf, count);
if (j != count) {
wrerr = YES;
wrerrno = j >= 0 ? EIO : errno;
if (showprogress)
stop_progress_meter();
if (count != 0 && wrerr == NO &&
- (j = atomicio(write, ofd, bp->buf, count)) != count) {
+ (j = atomicio(vwrite, ofd, bp->buf, count)) != count) {
wrerr = YES;
wrerrno = j >= 0 ? EIO : errno;
}
run_err("%s: %s", np, strerror(wrerrno));
break;
case NO:
- (void) atomicio(write, remout, "", 1);
+ (void) atomicio(vwrite, remout, "", 1);
break;
case DISPLAYED:
break;
} while (cp < &rbuf[sizeof(rbuf) - 1] && ch != '\n');
if (!iamremote)
- (void) atomicio(write, STDERR_FILENO, rbuf, cp - rbuf);
+ (void) atomicio(vwrite, STDERR_FILENO, rbuf, cp - rbuf);
++errs;
if (resp == 1)
return (-1);
}
void
-verifydir(cp)
- char *cp;
+verifydir(char *cp)
{
struct stat stb;
}
int
-okname(cp0)
- char *cp0;
+okname(char *cp0)
{
int c;
char *cp;
}
BUF *
-allocbuf(bp, fd, blksize)
- BUF *bp;
- int fd, blksize;
+allocbuf(BUF *bp, int fd, int blksize)
{
size_t size;
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
}
void
-lostconn(signo)
- int signo;
+lostconn(int signo)
{
if (!iamremote)
write(STDERR_FILENO, "lost connection\n", 16);