1999-10-27 11:42:43 +08:00
|
|
|
/*
|
2000-09-16 10:29:08 +08:00
|
|
|
* scp - secure remote copy. This is basically patched BSD rcp which
|
|
|
|
* uses ssh to do the data transfer (instead of using rcmd).
|
2000-04-16 09:18:38 +08:00
|
|
|
*
|
2000-09-16 10:29:08 +08:00
|
|
|
* NOTE: This version should NOT be suid root. (This uses ssh to
|
|
|
|
* do the transfer and ssh has the necessary privileges.)
|
2000-04-16 09:18:38 +08:00
|
|
|
*
|
1999-11-24 21:26:21 +08:00
|
|
|
* 1995 Timo Rinne <tri@iki.fi>, Tatu Ylonen <ylo@cs.hut.fi>
|
2000-04-16 09:18:38 +08:00
|
|
|
*
|
2000-09-16 10:29:08 +08:00
|
|
|
* As far as I am concerned, the code I have written for this software
|
|
|
|
* can be used freely for any purpose. Any derived versions of this
|
|
|
|
* software must be clearly marked as such, and if the derived work is
|
|
|
|
* incompatible with the protocol description in the RFC file, it must be
|
|
|
|
* called by a name other than "ssh" or "Secure Shell".
|
|
|
|
*/
|
|
|
|
/*
|
2001-03-05 14:59:27 +08:00
|
|
|
* Copyright (c) 1999 Theo de Raadt. All rights reserved.
|
|
|
|
* Copyright (c) 1999 Aaron Campbell. All rights reserved.
|
2000-09-16 10:29:08 +08:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
|
|
|
*/
|
1999-10-27 11:42:43 +08:00
|
|
|
|
|
|
|
/*
|
2000-08-23 08:46:23 +08:00
|
|
|
* Parts from:
|
|
|
|
*
|
1999-10-27 11:42:43 +08:00
|
|
|
* Copyright (c) 1983, 1990, 1992, 1993, 1995
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "includes.h"
|
2002-12-23 10:53:08 +08:00
|
|
|
RCSID("$OpenBSD: scp.c,v 1.96 2002/12/13 15:20:52 markus Exp $");
|
1999-10-27 11:42:43 +08:00
|
|
|
|
|
|
|
#include "xmalloc.h"
|
2001-01-22 13:34:40 +08:00
|
|
|
#include "atomicio.h"
|
|
|
|
#include "pathnames.h"
|
|
|
|
#include "log.h"
|
2001-02-18 11:55:16 +08:00
|
|
|
#include "misc.h"
|
1999-10-27 11:42:43 +08:00
|
|
|
|
2000-11-17 11:47:20 +08:00
|
|
|
#ifdef HAVE___PROGNAME
|
|
|
|
extern char *__progname;
|
|
|
|
#else
|
|
|
|
char *__progname;
|
|
|
|
#endif
|
|
|
|
|
1999-10-27 11:42:43 +08:00
|
|
|
/* For progressmeter() -- number of seconds before xfer considered "stalled" */
|
|
|
|
#define STALLTIME 5
|
2001-08-07 06:48:19 +08:00
|
|
|
/* alarm() interval for updating progress meter */
|
|
|
|
#define PROGRESSTIME 1
|
1999-10-27 11:42:43 +08:00
|
|
|
|
|
|
|
/* Visual statistics about files as they are transferred. */
|
|
|
|
void progressmeter(int);
|
|
|
|
|
|
|
|
/* Returns width of the terminal (for progress meter calculations). */
|
|
|
|
int getttywidth(void);
|
2000-08-23 08:46:23 +08:00
|
|
|
int do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout, int argc);
|
1999-10-27 11:42:43 +08:00
|
|
|
|
2001-05-09 04:27:25 +08:00
|
|
|
/* Struct for addargs */
|
|
|
|
arglist args;
|
2000-10-14 13:23:11 +08:00
|
|
|
|
1999-10-27 11:42:43 +08:00
|
|
|
/* Time a transfer started. */
|
|
|
|
static struct timeval start;
|
|
|
|
|
|
|
|
/* Number of bytes of current file transferred so far. */
|
2001-04-23 01:13:20 +08:00
|
|
|
volatile off_t statbytes;
|
1999-10-27 11:42:43 +08:00
|
|
|
|
|
|
|
/* Total size of current file. */
|
1999-11-13 10:22:46 +08:00
|
|
|
off_t totalbytes = 0;
|
1999-10-27 11:42:43 +08:00
|
|
|
|
|
|
|
/* Name of current file being transferred. */
|
|
|
|
char *curfile;
|
|
|
|
|
|
|
|
/* This is set to non-zero to enable verbose mode. */
|
1999-11-24 21:26:21 +08:00
|
|
|
int verbose_mode = 0;
|
1999-10-27 11:42:43 +08:00
|
|
|
|
|
|
|
/* This is set to zero if the progressmeter is not desired. */
|
|
|
|
int showprogress = 1;
|
|
|
|
|
2000-08-23 08:46:23 +08:00
|
|
|
/* This is the program to execute for the secured connection. ("ssh" or -S) */
|
2001-01-22 13:34:40 +08:00
|
|
|
char *ssh_program = _PATH_SSH_PROGRAM;
|
2000-08-23 08:46:23 +08:00
|
|
|
|
2002-11-09 23:54:08 +08:00
|
|
|
/* This is used to store the pid of ssh_program */
|
|
|
|
pid_t do_cmd_pid;
|
|
|
|
|
1999-11-25 08:54:57 +08:00
|
|
|
/*
|
|
|
|
* This function executes the given command as the specified user on the
|
|
|
|
* given host. This returns < 0 if execution fails, and >= 0 otherwise. This
|
|
|
|
* assigns the input and output file descriptors on success.
|
|
|
|
*/
|
1999-10-27 11:42:43 +08:00
|
|
|
|
2000-04-16 09:18:38 +08:00
|
|
|
int
|
2000-08-23 08:46:23 +08:00
|
|
|
do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout, int argc)
|
1999-10-27 11:42:43 +08:00
|
|
|
{
|
1999-11-24 21:26:21 +08:00
|
|
|
int pin[2], pout[2], reserved[2];
|
|
|
|
|
|
|
|
if (verbose_mode)
|
2001-08-07 05:17:12 +08:00
|
|
|
fprintf(stderr,
|
|
|
|
"Executing: program %s host %s, user %s, command %s\n",
|
|
|
|
ssh_program, host,
|
|
|
|
remuser ? remuser : "(unspecified)", cmd);
|
1999-11-24 21:26:21 +08:00
|
|
|
|
1999-11-25 08:54:57 +08:00
|
|
|
/*
|
|
|
|
* Reserve two descriptors so that the real pipes won't get
|
|
|
|
* descriptors 0 and 1 because that will screw up dup2 below.
|
|
|
|
*/
|
1999-11-24 21:26:21 +08:00
|
|
|
pipe(reserved);
|
|
|
|
|
|
|
|
/* Create a socket pair for communicating with ssh. */
|
|
|
|
if (pipe(pin) < 0)
|
|
|
|
fatal("pipe: %s", strerror(errno));
|
|
|
|
if (pipe(pout) < 0)
|
|
|
|
fatal("pipe: %s", strerror(errno));
|
|
|
|
|
|
|
|
/* Free the reserved descriptors. */
|
|
|
|
close(reserved[0]);
|
|
|
|
close(reserved[1]);
|
|
|
|
|
|
|
|
/* For a child to execute the command on the remote host using ssh. */
|
2002-11-09 23:54:08 +08:00
|
|
|
do_cmd_pid = fork();
|
|
|
|
if (do_cmd_pid == 0) {
|
1999-11-24 21:26:21 +08:00
|
|
|
/* Child. */
|
|
|
|
close(pin[1]);
|
|
|
|
close(pout[0]);
|
|
|
|
dup2(pin[0], 0);
|
|
|
|
dup2(pout[1], 1);
|
|
|
|
close(pin[0]);
|
|
|
|
close(pout[1]);
|
|
|
|
|
2000-10-14 13:23:11 +08:00
|
|
|
args.list[0] = ssh_program;
|
|
|
|
if (remuser != NULL)
|
2001-05-09 04:27:25 +08:00
|
|
|
addargs(&args, "-l%s", remuser);
|
|
|
|
addargs(&args, "%s", host);
|
|
|
|
addargs(&args, "%s", cmd);
|
1999-11-24 21:26:21 +08:00
|
|
|
|
2000-10-14 13:23:11 +08:00
|
|
|
execvp(ssh_program, args.list);
|
2000-08-23 08:46:23 +08:00
|
|
|
perror(ssh_program);
|
1999-11-24 21:26:21 +08:00
|
|
|
exit(1);
|
2002-11-09 23:54:08 +08:00
|
|
|
} else if (do_cmd_pid == -1) {
|
|
|
|
fatal("fork: %s", strerror(errno));
|
1999-10-27 11:42:43 +08:00
|
|
|
}
|
1999-11-24 21:26:21 +08:00
|
|
|
/* Parent. Close the other side, and return the local side. */
|
|
|
|
close(pin[0]);
|
|
|
|
*fdout = pin[1];
|
|
|
|
close(pout[1]);
|
|
|
|
*fdin = pout[0];
|
|
|
|
return 0;
|
1999-10-27 11:42:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int cnt;
|
|
|
|
char *buf;
|
|
|
|
} BUF;
|
|
|
|
|
1999-11-24 21:26:21 +08:00
|
|
|
BUF *allocbuf(BUF *, int, int);
|
|
|
|
void lostconn(int);
|
|
|
|
void nospace(void);
|
|
|
|
int okname(char *);
|
|
|
|
void run_err(const char *,...);
|
|
|
|
void verifydir(char *);
|
1999-10-27 11:42:43 +08:00
|
|
|
|
|
|
|
struct passwd *pwd;
|
1999-11-24 21:26:21 +08:00
|
|
|
uid_t userid;
|
1999-10-27 11:42:43 +08:00
|
|
|
int errs, remin, remout;
|
|
|
|
int pflag, iamremote, iamrecursive, targetshouldbedirectory;
|
|
|
|
|
|
|
|
#define CMDNEEDS 64
|
|
|
|
char cmd[CMDNEEDS]; /* must hold "rcp -r -p -d\0" */
|
|
|
|
|
1999-11-24 21:26:21 +08:00
|
|
|
int response(void);
|
|
|
|
void rsource(char *, struct stat *);
|
|
|
|
void sink(int, char *[]);
|
|
|
|
void source(int, char *[]);
|
|
|
|
void tolocal(int, char *[]);
|
|
|
|
void toremote(char *, int, char *[]);
|
|
|
|
void usage(void);
|
1999-10-27 11:42:43 +08:00
|
|
|
|
|
|
|
int
|
|
|
|
main(argc, argv)
|
|
|
|
int argc;
|
|
|
|
char *argv[];
|
|
|
|
{
|
2002-11-09 23:54:08 +08:00
|
|
|
int ch, fflag, tflag, status;
|
1999-10-27 11:42:43 +08:00
|
|
|
char *targ;
|
|
|
|
extern char *optarg;
|
|
|
|
extern int optind;
|
|
|
|
|
2000-11-17 11:47:20 +08:00
|
|
|
__progname = get_progname(argv[0]);
|
|
|
|
|
2000-10-14 13:23:11 +08:00
|
|
|
args.list = NULL;
|
2002-06-21 08:41:51 +08:00
|
|
|
addargs(&args, "ssh"); /* overwritten with ssh_program */
|
2001-05-09 04:27:25 +08:00
|
|
|
addargs(&args, "-x");
|
2001-09-13 02:45:09 +08:00
|
|
|
addargs(&args, "-oForwardAgent no");
|
2001-09-20 08:57:55 +08:00
|
|
|
addargs(&args, "-oClearAllForwardings yes");
|
2000-10-14 13:23:11 +08:00
|
|
|
|
1999-10-27 11:42:43 +08:00
|
|
|
fflag = tflag = 0;
|
2001-09-18 13:38:44 +08:00
|
|
|
while ((ch = getopt(argc, argv, "dfprtvBCc:i:P:q46S:o:F:")) != -1)
|
1999-11-24 21:26:21 +08:00
|
|
|
switch (ch) {
|
|
|
|
/* User-visible flags. */
|
2000-01-14 12:45:46 +08:00
|
|
|
case '4':
|
|
|
|
case '6':
|
2000-10-14 13:23:11 +08:00
|
|
|
case 'C':
|
2001-05-09 04:27:25 +08:00
|
|
|
addargs(&args, "-%c", ch);
|
2000-01-14 12:45:46 +08:00
|
|
|
break;
|
2000-10-14 13:23:11 +08:00
|
|
|
case 'o':
|
|
|
|
case 'c':
|
|
|
|
case 'i':
|
2001-09-18 13:38:44 +08:00
|
|
|
case 'F':
|
2001-05-09 04:27:25 +08:00
|
|
|
addargs(&args, "-%c%s", ch, optarg);
|
1999-10-27 11:42:43 +08:00
|
|
|
break;
|
|
|
|
case 'P':
|
2001-05-09 04:27:25 +08:00
|
|
|
addargs(&args, "-p%s", optarg);
|
2000-10-14 13:23:11 +08:00
|
|
|
break;
|
|
|
|
case 'B':
|
2001-05-09 04:27:25 +08:00
|
|
|
addargs(&args, "-oBatchmode yes");
|
2000-10-14 13:23:11 +08:00
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
pflag = 1;
|
1999-11-24 21:26:21 +08:00
|
|
|
break;
|
1999-10-27 11:42:43 +08:00
|
|
|
case 'r':
|
|
|
|
iamrecursive = 1;
|
|
|
|
break;
|
2000-08-23 08:46:23 +08:00
|
|
|
case 'S':
|
2000-10-14 13:23:11 +08:00
|
|
|
ssh_program = xstrdup(optarg);
|
|
|
|
break;
|
|
|
|
case 'v':
|
2001-06-09 09:15:11 +08:00
|
|
|
addargs(&args, "-v");
|
2000-10-14 13:23:11 +08:00
|
|
|
verbose_mode = 1;
|
|
|
|
break;
|
|
|
|
case 'q':
|
|
|
|
showprogress = 0;
|
2000-08-23 08:46:23 +08:00
|
|
|
break;
|
|
|
|
|
1999-11-24 21:26:21 +08:00
|
|
|
/* Server options. */
|
1999-10-27 11:42:43 +08:00
|
|
|
case 'd':
|
|
|
|
targetshouldbedirectory = 1;
|
|
|
|
break;
|
1999-11-24 21:26:21 +08:00
|
|
|
case 'f': /* "from" */
|
1999-10-27 11:42:43 +08:00
|
|
|
iamremote = 1;
|
|
|
|
fflag = 1;
|
|
|
|
break;
|
1999-11-24 21:26:21 +08:00
|
|
|
case 't': /* "to" */
|
1999-10-27 11:42:43 +08:00
|
|
|
iamremote = 1;
|
|
|
|
tflag = 1;
|
2001-04-13 22:28:42 +08:00
|
|
|
#ifdef HAVE_CYGWIN
|
|
|
|
setmode(0, O_BINARY);
|
|
|
|
#endif
|
1999-10-27 11:42:43 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if ((pwd = getpwuid(userid = getuid())) == NULL)
|
1999-11-24 21:26:21 +08:00
|
|
|
fatal("unknown user %d", (int) userid);
|
1999-10-27 11:42:43 +08:00
|
|
|
|
1999-11-24 21:26:21 +08:00
|
|
|
if (!isatty(STDERR_FILENO))
|
1999-10-27 11:42:43 +08:00
|
|
|
showprogress = 0;
|
|
|
|
|
|
|
|
remin = STDIN_FILENO;
|
|
|
|
remout = STDOUT_FILENO;
|
|
|
|
|
2001-02-05 20:42:17 +08:00
|
|
|
if (fflag) {
|
1999-11-24 21:26:21 +08:00
|
|
|
/* Follow "protocol", send data. */
|
|
|
|
(void) response();
|
1999-10-27 11:42:43 +08:00
|
|
|
source(argc, argv);
|
|
|
|
exit(errs != 0);
|
|
|
|
}
|
1999-11-24 21:26:21 +08:00
|
|
|
if (tflag) {
|
|
|
|
/* Receive data. */
|
1999-10-27 11:42:43 +08:00
|
|
|
sink(argc, argv);
|
|
|
|
exit(errs != 0);
|
|
|
|
}
|
|
|
|
if (argc < 2)
|
|
|
|
usage();
|
|
|
|
if (argc > 2)
|
|
|
|
targetshouldbedirectory = 1;
|
|
|
|
|
|
|
|
remin = remout = -1;
|
2002-11-09 23:54:08 +08:00
|
|
|
do_cmd_pid = -1;
|
1999-10-27 11:42:43 +08:00
|
|
|
/* Command to be executed on remote system using "ssh". */
|
2001-02-09 09:23:39 +08:00
|
|
|
(void) snprintf(cmd, sizeof cmd, "scp%s%s%s%s",
|
|
|
|
verbose_mode ? " -v" : "",
|
2000-08-23 08:46:23 +08:00
|
|
|
iamrecursive ? " -r" : "", pflag ? " -p" : "",
|
|
|
|
targetshouldbedirectory ? " -d" : "");
|
1999-10-27 11:42:43 +08:00
|
|
|
|
1999-11-24 21:26:21 +08:00
|
|
|
(void) signal(SIGPIPE, lostconn);
|
1999-10-27 11:42:43 +08:00
|
|
|
|
|
|
|
if ((targ = colon(argv[argc - 1]))) /* Dest is remote host. */
|
|
|
|
toremote(targ, argc, argv);
|
|
|
|
else {
|
1999-11-24 21:26:21 +08:00
|
|
|
tolocal(argc, argv); /* Dest is local host. */
|
1999-10-27 11:42:43 +08:00
|
|
|
if (targetshouldbedirectory)
|
|
|
|
verifydir(argv[argc - 1]);
|
|
|
|
}
|
2002-11-09 23:54:08 +08:00
|
|
|
/*
|
|
|
|
* Finally check the exit status of the ssh process, if one was forked
|
|
|
|
* and no error has occured yet
|
|
|
|
*/
|
|
|
|
if (do_cmd_pid != -1 && errs == 0) {
|
|
|
|
if (remin != -1)
|
|
|
|
(void) close(remin);
|
|
|
|
if (remout != -1)
|
|
|
|
(void) close(remout);
|
|
|
|
if (waitpid(do_cmd_pid, &status, 0) == -1)
|
|
|
|
errs = 1;
|
|
|
|
else {
|
|
|
|
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
|
|
|
|
errs = 1;
|
|
|
|
}
|
|
|
|
}
|
1999-10-27 11:42:43 +08:00
|
|
|
exit(errs != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
toremote(targ, argc, argv)
|
|
|
|
char *targ, *argv[];
|
|
|
|
int argc;
|
|
|
|
{
|
|
|
|
int i, len;
|
|
|
|
char *bp, *host, *src, *suser, *thost, *tuser;
|
|
|
|
|
|
|
|
*targ++ = 0;
|
|
|
|
if (*targ == 0)
|
|
|
|
targ = ".";
|
|
|
|
|
2002-12-23 10:14:51 +08:00
|
|
|
if ((thost = strrchr(argv[argc - 1], '@'))) {
|
1999-10-27 11:42:43 +08:00
|
|
|
/* user@host */
|
|
|
|
*thost++ = 0;
|
|
|
|
tuser = argv[argc - 1];
|
|
|
|
if (*tuser == '\0')
|
|
|
|
tuser = NULL;
|
|
|
|
else if (!okname(tuser))
|
|
|
|
exit(1);
|
|
|
|
} else {
|
|
|
|
thost = argv[argc - 1];
|
|
|
|
tuser = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < argc - 1; i++) {
|
|
|
|
src = colon(argv[i]);
|
1999-11-24 21:26:21 +08:00
|
|
|
if (src) { /* remote to remote */
|
2001-09-20 08:57:55 +08:00
|
|
|
static char *ssh_options =
|
2002-06-10 04:06:29 +08:00
|
|
|
"-x -o'ClearAllForwardings yes'";
|
1999-10-27 11:42:43 +08:00
|
|
|
*src++ = 0;
|
|
|
|
if (*src == 0)
|
|
|
|
src = ".";
|
2002-12-23 10:14:51 +08:00
|
|
|
host = strrchr(argv[i], '@');
|
2000-08-23 08:46:23 +08:00
|
|
|
len = strlen(ssh_program) + strlen(argv[i]) +
|
|
|
|
strlen(src) + (tuser ? strlen(tuser) : 0) +
|
2001-09-20 08:57:55 +08:00
|
|
|
strlen(thost) + strlen(targ) +
|
|
|
|
strlen(ssh_options) + CMDNEEDS + 20;
|
1999-11-24 21:26:21 +08:00
|
|
|
bp = xmalloc(len);
|
1999-10-27 11:42:43 +08:00
|
|
|
if (host) {
|
|
|
|
*host++ = 0;
|
2000-01-14 12:45:46 +08:00
|
|
|
host = cleanhostname(host);
|
1999-10-27 11:42:43 +08:00
|
|
|
suser = argv[i];
|
|
|
|
if (*suser == '\0')
|
|
|
|
suser = pwd->pw_name;
|
|
|
|
else if (!okname(suser))
|
|
|
|
continue;
|
2001-02-09 09:23:39 +08:00
|
|
|
snprintf(bp, len,
|
2001-09-20 08:57:55 +08:00
|
|
|
"%s%s %s -n "
|
2001-02-09 09:23:39 +08:00
|
|
|
"-l %s %s %s %s '%s%s%s:%s'",
|
2000-12-16 07:03:10 +08:00
|
|
|
ssh_program, verbose_mode ? " -v" : "",
|
2001-09-20 08:57:55 +08:00
|
|
|
ssh_options, suser, host, cmd, src,
|
2000-12-16 07:03:10 +08:00
|
|
|
tuser ? tuser : "", tuser ? "@" : "",
|
|
|
|
thost, targ);
|
2000-01-14 12:45:46 +08:00
|
|
|
} else {
|
|
|
|
host = cleanhostname(argv[i]);
|
2001-02-09 09:23:39 +08:00
|
|
|
snprintf(bp, len,
|
2001-09-20 08:57:55 +08:00
|
|
|
"exec %s%s %s -n %s "
|
2001-02-09 09:23:39 +08:00
|
|
|
"%s %s '%s%s%s:%s'",
|
2000-12-16 07:03:10 +08:00
|
|
|
ssh_program, verbose_mode ? " -v" : "",
|
2001-09-20 08:57:55 +08:00
|
|
|
ssh_options, host, cmd, src,
|
2000-12-16 07:03:10 +08:00
|
|
|
tuser ? tuser : "", tuser ? "@" : "",
|
|
|
|
thost, targ);
|
2000-01-14 12:45:46 +08:00
|
|
|
}
|
1999-11-24 21:26:21 +08:00
|
|
|
if (verbose_mode)
|
|
|
|
fprintf(stderr, "Executing: %s\n", bp);
|
|
|
|
(void) system(bp);
|
|
|
|
(void) xfree(bp);
|
|
|
|
} else { /* local to remote */
|
1999-10-27 11:42:43 +08:00
|
|
|
if (remin == -1) {
|
|
|
|
len = strlen(targ) + CMDNEEDS + 20;
|
1999-11-24 21:26:21 +08:00
|
|
|
bp = xmalloc(len);
|
2001-02-09 09:23:39 +08:00
|
|
|
(void) snprintf(bp, len, "%s -t %s", cmd, targ);
|
2000-01-14 12:45:46 +08:00
|
|
|
host = cleanhostname(thost);
|
2000-08-23 08:46:23 +08:00
|
|
|
if (do_cmd(host, tuser, bp, &remin,
|
|
|
|
&remout, argc) < 0)
|
1999-11-24 21:26:21 +08:00
|
|
|
exit(1);
|
1999-10-27 11:42:43 +08:00
|
|
|
if (response() < 0)
|
|
|
|
exit(1);
|
1999-11-24 21:26:21 +08:00
|
|
|
(void) xfree(bp);
|
1999-10-27 11:42:43 +08:00
|
|
|
}
|
1999-11-24 21:26:21 +08:00
|
|
|
source(1, argv + i);
|
1999-10-27 11:42:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tolocal(argc, argv)
|
|
|
|
int argc;
|
|
|
|
char *argv[];
|
|
|
|
{
|
|
|
|
int i, len;
|
|
|
|
char *bp, *host, *src, *suser;
|
|
|
|
|
|
|
|
for (i = 0; i < argc - 1; i++) {
|
1999-11-24 21:26:21 +08:00
|
|
|
if (!(src = colon(argv[i]))) { /* Local to local. */
|
1999-10-27 11:42:43 +08:00
|
|
|
len = strlen(_PATH_CP) + strlen(argv[i]) +
|
2000-08-23 08:46:23 +08:00
|
|
|
strlen(argv[argc - 1]) + 20;
|
1999-10-27 11:42:43 +08:00
|
|
|
bp = xmalloc(len);
|
2001-02-09 09:23:39 +08:00
|
|
|
(void) snprintf(bp, len, "exec %s%s%s %s %s", _PATH_CP,
|
2000-08-23 08:46:23 +08:00
|
|
|
iamrecursive ? " -r" : "", pflag ? " -p" : "",
|
|
|
|
argv[i], argv[argc - 1]);
|
1999-11-24 21:26:21 +08:00
|
|
|
if (verbose_mode)
|
|
|
|
fprintf(stderr, "Executing: %s\n", bp);
|
1999-10-27 11:42:43 +08:00
|
|
|
if (system(bp))
|
|
|
|
++errs;
|
1999-11-24 21:26:21 +08:00
|
|
|
(void) xfree(bp);
|
1999-10-27 11:42:43 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
*src++ = 0;
|
|
|
|
if (*src == 0)
|
|
|
|
src = ".";
|
2002-12-23 10:14:51 +08:00
|
|
|
if ((host = strrchr(argv[i], '@')) == NULL) {
|
1999-10-27 11:42:43 +08:00
|
|
|
host = argv[i];
|
|
|
|
suser = NULL;
|
|
|
|
} else {
|
|
|
|
*host++ = 0;
|
|
|
|
suser = argv[i];
|
|
|
|
if (*suser == '\0')
|
|
|
|
suser = pwd->pw_name;
|
|
|
|
else if (!okname(suser))
|
|
|
|
continue;
|
|
|
|
}
|
2000-01-14 12:45:46 +08:00
|
|
|
host = cleanhostname(host);
|
1999-10-27 11:42:43 +08:00
|
|
|
len = strlen(src) + CMDNEEDS + 20;
|
1999-11-24 21:26:21 +08:00
|
|
|
bp = xmalloc(len);
|
2001-02-09 09:23:39 +08:00
|
|
|
(void) snprintf(bp, len, "%s -f %s", cmd, src);
|
2000-08-23 08:46:23 +08:00
|
|
|
if (do_cmd(host, suser, bp, &remin, &remout, argc) < 0) {
|
1999-11-24 21:26:21 +08:00
|
|
|
(void) xfree(bp);
|
|
|
|
++errs;
|
|
|
|
continue;
|
1999-10-27 11:42:43 +08:00
|
|
|
}
|
1999-11-24 21:26:21 +08:00
|
|
|
xfree(bp);
|
1999-10-27 11:42:43 +08:00
|
|
|
sink(1, argv + argc - 1);
|
1999-11-24 21:26:21 +08:00
|
|
|
(void) close(remin);
|
1999-10-27 11:42:43 +08:00
|
|
|
remin = remout = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
source(argc, argv)
|
|
|
|
int argc;
|
|
|
|
char *argv[];
|
|
|
|
{
|
|
|
|
struct stat stb;
|
|
|
|
static BUF buffer;
|
|
|
|
BUF *bp;
|
2001-04-23 01:13:20 +08:00
|
|
|
off_t i, amt, result;
|
|
|
|
int fd, haderr, indx;
|
1999-10-27 11:42:43 +08:00
|
|
|
char *last, *name, buf[2048];
|
2001-04-07 09:14:38 +08:00
|
|
|
int len;
|
1999-10-27 11:42:43 +08:00
|
|
|
|
|
|
|
for (indx = 0; indx < argc; ++indx) {
|
1999-11-24 21:26:21 +08:00
|
|
|
name = argv[indx];
|
1999-10-27 11:42:43 +08:00
|
|
|
statbytes = 0;
|
2001-04-07 09:14:38 +08:00
|
|
|
len = strlen(name);
|
|
|
|
while (len > 1 && name[len-1] == '/')
|
|
|
|
name[--len] = '\0';
|
2001-10-04 01:30:58 +08:00
|
|
|
if (strchr(name, '\n') != NULL) {
|
|
|
|
run_err("%s: skipping, filename contains a newline",
|
|
|
|
name);
|
|
|
|
goto next;
|
|
|
|
}
|
1999-10-27 11:42:43 +08:00
|
|
|
if ((fd = open(name, O_RDONLY, 0)) < 0)
|
|
|
|
goto syserr;
|
|
|
|
if (fstat(fd, &stb) < 0) {
|
|
|
|
syserr: run_err("%s: %s", name, strerror(errno));
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
switch (stb.st_mode & S_IFMT) {
|
|
|
|
case S_IFREG:
|
|
|
|
break;
|
|
|
|
case S_IFDIR:
|
|
|
|
if (iamrecursive) {
|
|
|
|
rsource(name, &stb);
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
default:
|
|
|
|
run_err("%s: not a regular file", name);
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
if ((last = strrchr(name, '/')) == NULL)
|
|
|
|
last = name;
|
|
|
|
else
|
|
|
|
++last;
|
|
|
|
curfile = last;
|
|
|
|
if (pflag) {
|
|
|
|
/*
|
|
|
|
* Make it compatible with possible future
|
|
|
|
* versions expecting microseconds.
|
|
|
|
*/
|
2001-02-09 09:23:39 +08:00
|
|
|
(void) snprintf(buf, sizeof buf, "T%lu 0 %lu 0\n",
|
2000-12-22 09:43:59 +08:00
|
|
|
(u_long) stb.st_mtime,
|
|
|
|
(u_long) stb.st_atime);
|
2000-05-01 19:10:33 +08:00
|
|
|
(void) atomicio(write, remout, buf, strlen(buf));
|
1999-10-27 11:42:43 +08:00
|
|
|
if (response() < 0)
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
#define FILEMODEMASK (S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO)
|
2001-03-19 09:56:14 +08:00
|
|
|
#ifdef HAVE_LONG_LONG_INT
|
2001-03-17 08:10:20 +08:00
|
|
|
snprintf(buf, sizeof buf, "C%04o %lld %s\n",
|
2000-12-22 09:43:59 +08:00
|
|
|
(u_int) (stb.st_mode & FILEMODEMASK),
|
2002-03-06 02:59:45 +08:00
|
|
|
(long long)stb.st_size, last);
|
2001-03-19 09:45:02 +08:00
|
|
|
#else
|
|
|
|
/* XXX: Handle integer overflow? */
|
2001-03-19 11:09:40 +08:00
|
|
|
snprintf(buf, sizeof buf, "C%04o %lu %s\n",
|
2001-03-19 09:45:02 +08:00
|
|
|
(u_int) (stb.st_mode & FILEMODEMASK),
|
2001-03-19 11:09:40 +08:00
|
|
|
(u_long) stb.st_size, last);
|
2001-03-19 09:45:02 +08:00
|
|
|
#endif
|
1999-11-24 21:26:21 +08:00
|
|
|
if (verbose_mode) {
|
|
|
|
fprintf(stderr, "Sending file modes: %s", buf);
|
|
|
|
}
|
2000-05-01 19:10:33 +08:00
|
|
|
(void) atomicio(write, remout, buf, strlen(buf));
|
1999-10-27 11:42:43 +08:00
|
|
|
if (response() < 0)
|
|
|
|
goto next;
|
|
|
|
if ((bp = allocbuf(&buffer, fd, 2048)) == NULL) {
|
1999-11-24 21:26:21 +08:00
|
|
|
next: (void) close(fd);
|
1999-10-27 11:42:43 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (showprogress) {
|
|
|
|
totalbytes = stb.st_size;
|
|
|
|
progressmeter(-1);
|
|
|
|
}
|
|
|
|
/* Keep writing after an error so that we stay sync'd up. */
|
|
|
|
for (haderr = i = 0; i < stb.st_size; i += bp->cnt) {
|
|
|
|
amt = bp->cnt;
|
|
|
|
if (i + amt > stb.st_size)
|
|
|
|
amt = stb.st_size - i;
|
|
|
|
if (!haderr) {
|
- Remove references to SSLeay.
- Big OpenBSD CVS update
- markus@cvs.openbsd.org
[clientloop.c]
- typo
[session.c]
- update proctitle on pty alloc/dealloc, e.g. w/ windows client
[session.c]
- update proctitle for proto 1, too
[channels.h nchan.c serverloop.c session.c sshd.c]
- use c-style comments
- deraadt@cvs.openbsd.org
[scp.c]
- more atomicio
- markus@cvs.openbsd.org
[channels.c]
- set O_NONBLOCK
[ssh.1]
- update AUTHOR
[readconf.c ssh-keygen.c ssh.h]
- default DSA key file ~/.ssh/id_dsa
[clientloop.c]
- typo, rm verbose debug
- deraadt@cvs.openbsd.org
[ssh-keygen.1]
- document DSA use of ssh-keygen
[sshd.8]
- a start at describing what i understand of the DSA side
[ssh-keygen.1]
- document -X and -x
[ssh-keygen.c]
- simplify usage
- markus@cvs.openbsd.org
[sshd.8]
- there is no rhosts_dsa
[ssh-keygen.1]
- document -y, update -X,-x
[nchan.c]
- fix close for non-open ssh1 channels
[servconf.c servconf.h ssh.h sshd.8 sshd.c ]
- s/DsaKey/HostDSAKey/, document option
[sshconnect2.c]
- respect number_of_password_prompts
[channels.c channels.h servconf.c servconf.h session.c sshd.8]
- GatewayPorts for sshd, ok deraadt@
[ssh-add.1 ssh-agent.1 ssh.1]
- more doc on: DSA, id_dsa, known_hosts2, authorized_keys2
[ssh.1]
- more info on proto 2
[sshd.8]
- sync AUTHOR w/ ssh.1
[key.c key.h sshconnect.c]
- print key type when talking about host keys
[packet.c]
- clear padding in ssh2
[dsa.c key.c radix.c ssh.h sshconnect1.c uuencode.c uuencode.h]
- replace broken uuencode w/ libc b64_ntop
[auth2.c]
- log failure before sending the reply
[key.c radix.c uuencode.c]
- remote trailing comments before calling __b64_pton
[auth2.c readconf.c readconf.h servconf.c servconf.h ssh.1]
[sshconnect2.c sshd.8]
- add DSAAuthetication option to ssh/sshd, document SSH2 in sshd.8
- Bring in b64_ntop and b64_pton from OpenBSD libc (bsd-base64.[ch])
2000-05-07 10:03:14 +08:00
|
|
|
result = atomicio(read, fd, bp->buf, amt);
|
1999-10-27 11:42:43 +08:00
|
|
|
if (result != amt)
|
|
|
|
haderr = result >= 0 ? EIO : errno;
|
|
|
|
}
|
|
|
|
if (haderr)
|
2000-05-01 19:10:33 +08:00
|
|
|
(void) atomicio(write, remout, bp->buf, amt);
|
1999-10-27 11:42:43 +08:00
|
|
|
else {
|
1999-12-15 08:04:25 +08:00
|
|
|
result = atomicio(write, remout, bp->buf, amt);
|
1999-10-27 11:42:43 +08:00
|
|
|
if (result != amt)
|
|
|
|
haderr = result >= 0 ? EIO : errno;
|
|
|
|
statbytes += result;
|
|
|
|
}
|
|
|
|
}
|
1999-11-24 21:26:21 +08:00
|
|
|
if (showprogress)
|
1999-10-27 11:42:43 +08:00
|
|
|
progressmeter(1);
|
|
|
|
|
|
|
|
if (close(fd) < 0 && !haderr)
|
|
|
|
haderr = errno;
|
|
|
|
if (!haderr)
|
2000-05-01 19:10:33 +08:00
|
|
|
(void) atomicio(write, remout, "", 1);
|
1999-10-27 11:42:43 +08:00
|
|
|
else
|
|
|
|
run_err("%s: %s", name, strerror(haderr));
|
1999-11-24 21:26:21 +08:00
|
|
|
(void) response();
|
1999-10-27 11:42:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rsource(name, statp)
|
|
|
|
char *name;
|
|
|
|
struct stat *statp;
|
|
|
|
{
|
|
|
|
DIR *dirp;
|
|
|
|
struct dirent *dp;
|
|
|
|
char *last, *vect[1], path[1100];
|
|
|
|
|
|
|
|
if (!(dirp = opendir(name))) {
|
|
|
|
run_err("%s: %s", name, strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
last = strrchr(name, '/');
|
|
|
|
if (last == 0)
|
|
|
|
last = name;
|
|
|
|
else
|
|
|
|
last++;
|
|
|
|
if (pflag) {
|
2001-02-09 09:23:39 +08:00
|
|
|
(void) snprintf(path, sizeof(path), "T%lu 0 %lu 0\n",
|
2000-12-22 09:43:59 +08:00
|
|
|
(u_long) statp->st_mtime,
|
|
|
|
(u_long) statp->st_atime);
|
2000-05-01 19:10:33 +08:00
|
|
|
(void) atomicio(write, remout, path, strlen(path));
|
1999-10-27 11:42:43 +08:00
|
|
|
if (response() < 0) {
|
|
|
|
closedir(dirp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2001-02-09 09:23:39 +08:00
|
|
|
(void) snprintf(path, sizeof path, "D%04o %d %.1024s\n",
|
2000-12-22 09:43:59 +08:00
|
|
|
(u_int) (statp->st_mode & FILEMODEMASK), 0, last);
|
1999-11-24 21:26:21 +08:00
|
|
|
if (verbose_mode)
|
|
|
|
fprintf(stderr, "Entering directory: %s", path);
|
2000-05-01 19:10:33 +08:00
|
|
|
(void) atomicio(write, remout, path, strlen(path));
|
1999-10-27 11:42:43 +08:00
|
|
|
if (response() < 0) {
|
|
|
|
closedir(dirp);
|
|
|
|
return;
|
|
|
|
}
|
2001-03-29 08:39:55 +08:00
|
|
|
while ((dp = readdir(dirp)) != NULL) {
|
1999-10-27 11:42:43 +08:00
|
|
|
if (dp->d_ino == 0)
|
|
|
|
continue;
|
|
|
|
if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, ".."))
|
|
|
|
continue;
|
|
|
|
if (strlen(name) + 1 + strlen(dp->d_name) >= sizeof(path) - 1) {
|
|
|
|
run_err("%s/%s: name too long", name, dp->d_name);
|
|
|
|
continue;
|
|
|
|
}
|
2001-02-09 09:23:39 +08:00
|
|
|
(void) snprintf(path, sizeof path, "%s/%s", name, dp->d_name);
|
1999-10-27 11:42:43 +08:00
|
|
|
vect[0] = path;
|
|
|
|
source(1, vect);
|
|
|
|
}
|
1999-11-24 21:26:21 +08:00
|
|
|
(void) closedir(dirp);
|
2000-05-01 19:10:33 +08:00
|
|
|
(void) atomicio(write, remout, "E\n", 2);
|
1999-11-24 21:26:21 +08:00
|
|
|
(void) response();
|
1999-10-27 11:42:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sink(argc, argv)
|
|
|
|
int argc;
|
|
|
|
char *argv[];
|
|
|
|
{
|
|
|
|
static BUF buffer;
|
|
|
|
struct stat stb;
|
1999-11-24 21:26:21 +08:00
|
|
|
enum {
|
|
|
|
YES, NO, DISPLAYED
|
|
|
|
} wrerr;
|
1999-10-27 11:42:43 +08:00
|
|
|
BUF *bp;
|
|
|
|
off_t i, j;
|
|
|
|
int amt, count, exists, first, mask, mode, ofd, omode;
|
2000-08-29 08:33:50 +08:00
|
|
|
off_t size;
|
|
|
|
int setimes, targisdir, wrerrno = 0;
|
1999-10-27 11:42:43 +08:00
|
|
|
char ch, *cp, *np, *targ, *why, *vect[1], buf[2048];
|
2000-09-23 14:15:56 +08:00
|
|
|
struct timeval tv[2];
|
1999-10-27 11:42:43 +08:00
|
|
|
|
2001-04-15 07:14:22 +08:00
|
|
|
#define atime tv[0]
|
|
|
|
#define mtime tv[1]
|
2001-06-25 12:28:30 +08:00
|
|
|
#define SCREWUP(str) do { why = str; goto screwup; } while (0)
|
1999-10-27 11:42:43 +08:00
|
|
|
|
|
|
|
setimes = targisdir = 0;
|
|
|
|
mask = umask(0);
|
|
|
|
if (!pflag)
|
1999-11-24 21:26:21 +08:00
|
|
|
(void) umask(mask);
|
1999-10-27 11:42:43 +08:00
|
|
|
if (argc != 1) {
|
|
|
|
run_err("ambiguous target");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
targ = *argv;
|
|
|
|
if (targetshouldbedirectory)
|
|
|
|
verifydir(targ);
|
1999-11-24 21:26:21 +08:00
|
|
|
|
2000-05-01 19:10:33 +08:00
|
|
|
(void) atomicio(write, remout, "", 1);
|
1999-10-27 11:42:43 +08:00
|
|
|
if (stat(targ, &stb) == 0 && S_ISDIR(stb.st_mode))
|
|
|
|
targisdir = 1;
|
|
|
|
for (first = 1;; first = 0) {
|
|
|
|
cp = buf;
|
- Remove references to SSLeay.
- Big OpenBSD CVS update
- markus@cvs.openbsd.org
[clientloop.c]
- typo
[session.c]
- update proctitle on pty alloc/dealloc, e.g. w/ windows client
[session.c]
- update proctitle for proto 1, too
[channels.h nchan.c serverloop.c session.c sshd.c]
- use c-style comments
- deraadt@cvs.openbsd.org
[scp.c]
- more atomicio
- markus@cvs.openbsd.org
[channels.c]
- set O_NONBLOCK
[ssh.1]
- update AUTHOR
[readconf.c ssh-keygen.c ssh.h]
- default DSA key file ~/.ssh/id_dsa
[clientloop.c]
- typo, rm verbose debug
- deraadt@cvs.openbsd.org
[ssh-keygen.1]
- document DSA use of ssh-keygen
[sshd.8]
- a start at describing what i understand of the DSA side
[ssh-keygen.1]
- document -X and -x
[ssh-keygen.c]
- simplify usage
- markus@cvs.openbsd.org
[sshd.8]
- there is no rhosts_dsa
[ssh-keygen.1]
- document -y, update -X,-x
[nchan.c]
- fix close for non-open ssh1 channels
[servconf.c servconf.h ssh.h sshd.8 sshd.c ]
- s/DsaKey/HostDSAKey/, document option
[sshconnect2.c]
- respect number_of_password_prompts
[channels.c channels.h servconf.c servconf.h session.c sshd.8]
- GatewayPorts for sshd, ok deraadt@
[ssh-add.1 ssh-agent.1 ssh.1]
- more doc on: DSA, id_dsa, known_hosts2, authorized_keys2
[ssh.1]
- more info on proto 2
[sshd.8]
- sync AUTHOR w/ ssh.1
[key.c key.h sshconnect.c]
- print key type when talking about host keys
[packet.c]
- clear padding in ssh2
[dsa.c key.c radix.c ssh.h sshconnect1.c uuencode.c uuencode.h]
- replace broken uuencode w/ libc b64_ntop
[auth2.c]
- log failure before sending the reply
[key.c radix.c uuencode.c]
- remote trailing comments before calling __b64_pton
[auth2.c readconf.c readconf.h servconf.c servconf.h ssh.1]
[sshconnect2.c sshd.8]
- add DSAAuthetication option to ssh/sshd, document SSH2 in sshd.8
- Bring in b64_ntop and b64_pton from OpenBSD libc (bsd-base64.[ch])
2000-05-07 10:03:14 +08:00
|
|
|
if (atomicio(read, remin, cp, 1) <= 0)
|
1999-10-27 11:42:43 +08:00
|
|
|
return;
|
|
|
|
if (*cp++ == '\n')
|
|
|
|
SCREWUP("unexpected <newline>");
|
|
|
|
do {
|
- Remove references to SSLeay.
- Big OpenBSD CVS update
- markus@cvs.openbsd.org
[clientloop.c]
- typo
[session.c]
- update proctitle on pty alloc/dealloc, e.g. w/ windows client
[session.c]
- update proctitle for proto 1, too
[channels.h nchan.c serverloop.c session.c sshd.c]
- use c-style comments
- deraadt@cvs.openbsd.org
[scp.c]
- more atomicio
- markus@cvs.openbsd.org
[channels.c]
- set O_NONBLOCK
[ssh.1]
- update AUTHOR
[readconf.c ssh-keygen.c ssh.h]
- default DSA key file ~/.ssh/id_dsa
[clientloop.c]
- typo, rm verbose debug
- deraadt@cvs.openbsd.org
[ssh-keygen.1]
- document DSA use of ssh-keygen
[sshd.8]
- a start at describing what i understand of the DSA side
[ssh-keygen.1]
- document -X and -x
[ssh-keygen.c]
- simplify usage
- markus@cvs.openbsd.org
[sshd.8]
- there is no rhosts_dsa
[ssh-keygen.1]
- document -y, update -X,-x
[nchan.c]
- fix close for non-open ssh1 channels
[servconf.c servconf.h ssh.h sshd.8 sshd.c ]
- s/DsaKey/HostDSAKey/, document option
[sshconnect2.c]
- respect number_of_password_prompts
[channels.c channels.h servconf.c servconf.h session.c sshd.8]
- GatewayPorts for sshd, ok deraadt@
[ssh-add.1 ssh-agent.1 ssh.1]
- more doc on: DSA, id_dsa, known_hosts2, authorized_keys2
[ssh.1]
- more info on proto 2
[sshd.8]
- sync AUTHOR w/ ssh.1
[key.c key.h sshconnect.c]
- print key type when talking about host keys
[packet.c]
- clear padding in ssh2
[dsa.c key.c radix.c ssh.h sshconnect1.c uuencode.c uuencode.h]
- replace broken uuencode w/ libc b64_ntop
[auth2.c]
- log failure before sending the reply
[key.c radix.c uuencode.c]
- remote trailing comments before calling __b64_pton
[auth2.c readconf.c readconf.h servconf.c servconf.h ssh.1]
[sshconnect2.c sshd.8]
- add DSAAuthetication option to ssh/sshd, document SSH2 in sshd.8
- Bring in b64_ntop and b64_pton from OpenBSD libc (bsd-base64.[ch])
2000-05-07 10:03:14 +08:00
|
|
|
if (atomicio(read, remin, &ch, sizeof(ch)) != sizeof(ch))
|
1999-10-27 11:42:43 +08:00
|
|
|
SCREWUP("lost connection");
|
|
|
|
*cp++ = ch;
|
|
|
|
} while (cp < &buf[sizeof(buf) - 1] && ch != '\n');
|
|
|
|
*cp = 0;
|
|
|
|
|
|
|
|
if (buf[0] == '\01' || buf[0] == '\02') {
|
|
|
|
if (iamremote == 0)
|
2000-05-01 19:10:33 +08:00
|
|
|
(void) atomicio(write, STDERR_FILENO,
|
2000-12-16 07:03:10 +08:00
|
|
|
buf + 1, strlen(buf + 1));
|
1999-10-27 11:42:43 +08:00
|
|
|
if (buf[0] == '\02')
|
|
|
|
exit(1);
|
|
|
|
++errs;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (buf[0] == 'E') {
|
2000-05-01 19:10:33 +08:00
|
|
|
(void) atomicio(write, remout, "", 1);
|
1999-10-27 11:42:43 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (ch == '\n')
|
|
|
|
*--cp = 0;
|
|
|
|
|
|
|
|
cp = buf;
|
|
|
|
if (*cp == 'T') {
|
|
|
|
setimes++;
|
|
|
|
cp++;
|
2001-04-15 07:14:22 +08:00
|
|
|
mtime.tv_sec = strtol(cp, &cp, 10);
|
|
|
|
if (!cp || *cp++ != ' ')
|
1999-10-27 11:42:43 +08:00
|
|
|
SCREWUP("mtime.sec not delimited");
|
2001-04-15 07:14:22 +08:00
|
|
|
mtime.tv_usec = strtol(cp, &cp, 10);
|
|
|
|
if (!cp || *cp++ != ' ')
|
1999-10-27 11:42:43 +08:00
|
|
|
SCREWUP("mtime.usec not delimited");
|
2001-04-15 07:14:22 +08:00
|
|
|
atime.tv_sec = strtol(cp, &cp, 10);
|
|
|
|
if (!cp || *cp++ != ' ')
|
1999-10-27 11:42:43 +08:00
|
|
|
SCREWUP("atime.sec not delimited");
|
2001-04-15 07:14:22 +08:00
|
|
|
atime.tv_usec = strtol(cp, &cp, 10);
|
|
|
|
if (!cp || *cp++ != '\0')
|
1999-10-27 11:42:43 +08:00
|
|
|
SCREWUP("atime.usec not delimited");
|
2000-05-01 19:10:33 +08:00
|
|
|
(void) atomicio(write, remout, "", 1);
|
1999-10-27 11:42:43 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (*cp != 'C' && *cp != 'D') {
|
|
|
|
/*
|
|
|
|
* Check for the case "rcp remote:foo\* local:bar".
|
|
|
|
* In this case, the line "No match." can be returned
|
|
|
|
* by the shell before the rcp command on the remote is
|
|
|
|
* executed so the ^Aerror_message convention isn't
|
|
|
|
* followed.
|
|
|
|
*/
|
|
|
|
if (first) {
|
|
|
|
run_err("%s", cp);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
SCREWUP("expected control record");
|
|
|
|
}
|
|
|
|
mode = 0;
|
|
|
|
for (++cp; cp < buf + 5; cp++) {
|
|
|
|
if (*cp < '0' || *cp > '7')
|
|
|
|
SCREWUP("bad mode");
|
|
|
|
mode = (mode << 3) | (*cp - '0');
|
|
|
|
}
|
|
|
|
if (*cp++ != ' ')
|
|
|
|
SCREWUP("mode not delimited");
|
|
|
|
|
2001-03-29 08:39:55 +08:00
|
|
|
for (size = 0; isdigit(*cp);)
|
1999-10-27 11:42:43 +08:00
|
|
|
size = size * 10 + (*cp++ - '0');
|
|
|
|
if (*cp++ != ' ')
|
|
|
|
SCREWUP("size not delimited");
|
|
|
|
if (targisdir) {
|
|
|
|
static char *namebuf;
|
|
|
|
static int cursize;
|
|
|
|
size_t need;
|
|
|
|
|
|
|
|
need = strlen(targ) + strlen(cp) + 250;
|
2001-02-09 09:23:39 +08:00
|
|
|
if (need > cursize) {
|
|
|
|
if (namebuf)
|
|
|
|
xfree(namebuf);
|
1999-11-24 21:26:21 +08:00
|
|
|
namebuf = xmalloc(need);
|
2001-02-09 09:23:39 +08:00
|
|
|
cursize = need;
|
|
|
|
}
|
|
|
|
(void) snprintf(namebuf, need, "%s%s%s", targ,
|
2002-04-07 02:29:59 +08:00
|
|
|
strcmp(targ, "/") ? "/" : "", cp);
|
1999-10-27 11:42:43 +08:00
|
|
|
np = namebuf;
|
|
|
|
} else
|
|
|
|
np = targ;
|
|
|
|
curfile = cp;
|
|
|
|
exists = stat(np, &stb) == 0;
|
|
|
|
if (buf[0] == 'D') {
|
|
|
|
int mod_flag = pflag;
|
|
|
|
if (exists) {
|
|
|
|
if (!S_ISDIR(stb.st_mode)) {
|
|
|
|
errno = ENOTDIR;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
if (pflag)
|
1999-11-24 21:26:21 +08:00
|
|
|
(void) chmod(np, mode);
|
1999-10-27 11:42:43 +08:00
|
|
|
} else {
|
1999-11-24 21:26:21 +08:00
|
|
|
/* Handle copying from a read-only
|
|
|
|
directory */
|
1999-10-27 11:42:43 +08:00
|
|
|
mod_flag = 1;
|
|
|
|
if (mkdir(np, mode | S_IRWXU) < 0)
|
|
|
|
goto bad;
|
|
|
|
}
|
2001-02-11 05:50:00 +08:00
|
|
|
vect[0] = xstrdup(np);
|
1999-10-27 11:42:43 +08:00
|
|
|
sink(1, vect);
|
|
|
|
if (setimes) {
|
|
|
|
setimes = 0;
|
2001-02-19 18:51:08 +08:00
|
|
|
if (utimes(vect[0], tv) < 0)
|
1999-11-24 21:26:21 +08:00
|
|
|
run_err("%s: set times: %s",
|
2001-02-19 18:51:08 +08:00
|
|
|
vect[0], strerror(errno));
|
1999-10-27 11:42:43 +08:00
|
|
|
}
|
|
|
|
if (mod_flag)
|
2001-02-19 18:51:08 +08:00
|
|
|
(void) chmod(vect[0], mode);
|
|
|
|
if (vect[0])
|
|
|
|
xfree(vect[0]);
|
1999-10-27 11:42:43 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
omode = mode;
|
|
|
|
mode |= S_IWRITE;
|
2001-06-06 03:31:41 +08:00
|
|
|
if ((ofd = open(np, O_WRONLY|O_CREAT, mode)) < 0) {
|
1999-10-27 11:42:43 +08:00
|
|
|
bad: run_err("%s: %s", np, strerror(errno));
|
|
|
|
continue;
|
|
|
|
}
|
2000-05-01 19:10:33 +08:00
|
|
|
(void) atomicio(write, remout, "", 1);
|
1999-10-27 11:42:43 +08:00
|
|
|
if ((bp = allocbuf(&buffer, ofd, 4096)) == NULL) {
|
1999-11-24 21:26:21 +08:00
|
|
|
(void) close(ofd);
|
1999-10-27 11:42:43 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
cp = bp->buf;
|
|
|
|
wrerr = NO;
|
|
|
|
|
|
|
|
if (showprogress) {
|
|
|
|
totalbytes = size;
|
|
|
|
progressmeter(-1);
|
|
|
|
}
|
|
|
|
statbytes = 0;
|
|
|
|
for (count = i = 0; i < size; i += 4096) {
|
|
|
|
amt = 4096;
|
|
|
|
if (i + amt > size)
|
|
|
|
amt = size - i;
|
|
|
|
count += amt;
|
|
|
|
do {
|
2000-10-28 11:19:58 +08:00
|
|
|
j = read(remin, cp, amt);
|
2001-08-07 05:17:12 +08:00
|
|
|
if (j == -1 && (errno == EINTR ||
|
|
|
|
errno == EAGAIN)) {
|
2000-10-28 11:19:58 +08:00
|
|
|
continue;
|
|
|
|
} else if (j <= 0) {
|
1999-10-27 11:42:43 +08:00
|
|
|
run_err("%s", j ? strerror(errno) :
|
2001-03-29 08:39:55 +08:00
|
|
|
"dropped connection");
|
1999-10-27 11:42:43 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
amt -= j;
|
|
|
|
cp += j;
|
1999-11-24 21:26:21 +08:00
|
|
|
statbytes += j;
|
1999-10-27 11:42:43 +08:00
|
|
|
} while (amt > 0);
|
|
|
|
if (count == bp->cnt) {
|
|
|
|
/* Keep reading so we stay sync'd up. */
|
|
|
|
if (wrerr == NO) {
|
- Remove references to SSLeay.
- Big OpenBSD CVS update
- markus@cvs.openbsd.org
[clientloop.c]
- typo
[session.c]
- update proctitle on pty alloc/dealloc, e.g. w/ windows client
[session.c]
- update proctitle for proto 1, too
[channels.h nchan.c serverloop.c session.c sshd.c]
- use c-style comments
- deraadt@cvs.openbsd.org
[scp.c]
- more atomicio
- markus@cvs.openbsd.org
[channels.c]
- set O_NONBLOCK
[ssh.1]
- update AUTHOR
[readconf.c ssh-keygen.c ssh.h]
- default DSA key file ~/.ssh/id_dsa
[clientloop.c]
- typo, rm verbose debug
- deraadt@cvs.openbsd.org
[ssh-keygen.1]
- document DSA use of ssh-keygen
[sshd.8]
- a start at describing what i understand of the DSA side
[ssh-keygen.1]
- document -X and -x
[ssh-keygen.c]
- simplify usage
- markus@cvs.openbsd.org
[sshd.8]
- there is no rhosts_dsa
[ssh-keygen.1]
- document -y, update -X,-x
[nchan.c]
- fix close for non-open ssh1 channels
[servconf.c servconf.h ssh.h sshd.8 sshd.c ]
- s/DsaKey/HostDSAKey/, document option
[sshconnect2.c]
- respect number_of_password_prompts
[channels.c channels.h servconf.c servconf.h session.c sshd.8]
- GatewayPorts for sshd, ok deraadt@
[ssh-add.1 ssh-agent.1 ssh.1]
- more doc on: DSA, id_dsa, known_hosts2, authorized_keys2
[ssh.1]
- more info on proto 2
[sshd.8]
- sync AUTHOR w/ ssh.1
[key.c key.h sshconnect.c]
- print key type when talking about host keys
[packet.c]
- clear padding in ssh2
[dsa.c key.c radix.c ssh.h sshconnect1.c uuencode.c uuencode.h]
- replace broken uuencode w/ libc b64_ntop
[auth2.c]
- log failure before sending the reply
[key.c radix.c uuencode.c]
- remote trailing comments before calling __b64_pton
[auth2.c readconf.c readconf.h servconf.c servconf.h ssh.1]
[sshconnect2.c sshd.8]
- add DSAAuthetication option to ssh/sshd, document SSH2 in sshd.8
- Bring in b64_ntop and b64_pton from OpenBSD libc (bsd-base64.[ch])
2000-05-07 10:03:14 +08:00
|
|
|
j = atomicio(write, ofd, bp->buf, count);
|
1999-10-27 11:42:43 +08:00
|
|
|
if (j != count) {
|
|
|
|
wrerr = YES;
|
1999-11-24 21:26:21 +08:00
|
|
|
wrerrno = j >= 0 ? EIO : errno;
|
1999-10-27 11:42:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
count = 0;
|
|
|
|
cp = bp->buf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (showprogress)
|
|
|
|
progressmeter(1);
|
|
|
|
if (count != 0 && wrerr == NO &&
|
- Remove references to SSLeay.
- Big OpenBSD CVS update
- markus@cvs.openbsd.org
[clientloop.c]
- typo
[session.c]
- update proctitle on pty alloc/dealloc, e.g. w/ windows client
[session.c]
- update proctitle for proto 1, too
[channels.h nchan.c serverloop.c session.c sshd.c]
- use c-style comments
- deraadt@cvs.openbsd.org
[scp.c]
- more atomicio
- markus@cvs.openbsd.org
[channels.c]
- set O_NONBLOCK
[ssh.1]
- update AUTHOR
[readconf.c ssh-keygen.c ssh.h]
- default DSA key file ~/.ssh/id_dsa
[clientloop.c]
- typo, rm verbose debug
- deraadt@cvs.openbsd.org
[ssh-keygen.1]
- document DSA use of ssh-keygen
[sshd.8]
- a start at describing what i understand of the DSA side
[ssh-keygen.1]
- document -X and -x
[ssh-keygen.c]
- simplify usage
- markus@cvs.openbsd.org
[sshd.8]
- there is no rhosts_dsa
[ssh-keygen.1]
- document -y, update -X,-x
[nchan.c]
- fix close for non-open ssh1 channels
[servconf.c servconf.h ssh.h sshd.8 sshd.c ]
- s/DsaKey/HostDSAKey/, document option
[sshconnect2.c]
- respect number_of_password_prompts
[channels.c channels.h servconf.c servconf.h session.c sshd.8]
- GatewayPorts for sshd, ok deraadt@
[ssh-add.1 ssh-agent.1 ssh.1]
- more doc on: DSA, id_dsa, known_hosts2, authorized_keys2
[ssh.1]
- more info on proto 2
[sshd.8]
- sync AUTHOR w/ ssh.1
[key.c key.h sshconnect.c]
- print key type when talking about host keys
[packet.c]
- clear padding in ssh2
[dsa.c key.c radix.c ssh.h sshconnect1.c uuencode.c uuencode.h]
- replace broken uuencode w/ libc b64_ntop
[auth2.c]
- log failure before sending the reply
[key.c radix.c uuencode.c]
- remote trailing comments before calling __b64_pton
[auth2.c readconf.c readconf.h servconf.c servconf.h ssh.1]
[sshconnect2.c sshd.8]
- add DSAAuthetication option to ssh/sshd, document SSH2 in sshd.8
- Bring in b64_ntop and b64_pton from OpenBSD libc (bsd-base64.[ch])
2000-05-07 10:03:14 +08:00
|
|
|
(j = atomicio(write, ofd, bp->buf, count)) != count) {
|
1999-10-27 11:42:43 +08:00
|
|
|
wrerr = YES;
|
1999-11-24 21:26:21 +08:00
|
|
|
wrerrno = j >= 0 ? EIO : errno;
|
1999-10-27 11:42:43 +08:00
|
|
|
}
|
|
|
|
if (ftruncate(ofd, size)) {
|
|
|
|
run_err("%s: truncate: %s", np, strerror(errno));
|
|
|
|
wrerr = DISPLAYED;
|
|
|
|
}
|
|
|
|
if (pflag) {
|
|
|
|
if (exists || omode != mode)
|
2000-09-29 20:01:36 +08:00
|
|
|
#ifdef HAVE_FCHMOD
|
1999-10-27 11:42:43 +08:00
|
|
|
if (fchmod(ofd, omode))
|
2000-09-29 20:01:36 +08:00
|
|
|
#else /* HAVE_FCHMOD */
|
|
|
|
if (chmod(np, omode))
|
|
|
|
#endif /* HAVE_FCHMOD */
|
1999-10-27 11:42:43 +08:00
|
|
|
run_err("%s: set mode: %s",
|
2001-03-29 08:39:55 +08:00
|
|
|
np, strerror(errno));
|
1999-10-27 11:42:43 +08:00
|
|
|
} else {
|
|
|
|
if (!exists && omode != mode)
|
2000-09-29 20:01:36 +08:00
|
|
|
#ifdef HAVE_FCHMOD
|
1999-10-27 11:42:43 +08:00
|
|
|
if (fchmod(ofd, omode & ~mask))
|
2000-09-29 20:01:36 +08:00
|
|
|
#else /* HAVE_FCHMOD */
|
|
|
|
if (chmod(np, omode & ~mask))
|
|
|
|
#endif /* HAVE_FCHMOD */
|
1999-10-27 11:42:43 +08:00
|
|
|
run_err("%s: set mode: %s",
|
2001-03-29 08:39:55 +08:00
|
|
|
np, strerror(errno));
|
1999-10-27 11:42:43 +08:00
|
|
|
}
|
2000-07-15 12:14:16 +08:00
|
|
|
if (close(ofd) == -1) {
|
|
|
|
wrerr = YES;
|
|
|
|
wrerrno = errno;
|
|
|
|
}
|
1999-11-24 21:26:21 +08:00
|
|
|
(void) response();
|
1999-10-27 11:42:43 +08:00
|
|
|
if (setimes && wrerr == NO) {
|
|
|
|
setimes = 0;
|
2000-09-23 14:15:56 +08:00
|
|
|
if (utimes(np, tv) < 0) {
|
1999-10-27 11:42:43 +08:00
|
|
|
run_err("%s: set times: %s",
|
2001-03-29 08:39:55 +08:00
|
|
|
np, strerror(errno));
|
1999-10-27 11:42:43 +08:00
|
|
|
wrerr = DISPLAYED;
|
|
|
|
}
|
|
|
|
}
|
1999-11-24 21:26:21 +08:00
|
|
|
switch (wrerr) {
|
1999-10-27 11:42:43 +08:00
|
|
|
case YES:
|
|
|
|
run_err("%s: %s", np, strerror(wrerrno));
|
|
|
|
break;
|
|
|
|
case NO:
|
2000-05-01 19:10:33 +08:00
|
|
|
(void) atomicio(write, remout, "", 1);
|
1999-10-27 11:42:43 +08:00
|
|
|
break;
|
|
|
|
case DISPLAYED:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
screwup:
|
|
|
|
run_err("protocol error: %s", why);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-12-07 01:55:26 +08:00
|
|
|
response(void)
|
1999-10-27 11:42:43 +08:00
|
|
|
{
|
|
|
|
char ch, *cp, resp, rbuf[2048];
|
|
|
|
|
- Remove references to SSLeay.
- Big OpenBSD CVS update
- markus@cvs.openbsd.org
[clientloop.c]
- typo
[session.c]
- update proctitle on pty alloc/dealloc, e.g. w/ windows client
[session.c]
- update proctitle for proto 1, too
[channels.h nchan.c serverloop.c session.c sshd.c]
- use c-style comments
- deraadt@cvs.openbsd.org
[scp.c]
- more atomicio
- markus@cvs.openbsd.org
[channels.c]
- set O_NONBLOCK
[ssh.1]
- update AUTHOR
[readconf.c ssh-keygen.c ssh.h]
- default DSA key file ~/.ssh/id_dsa
[clientloop.c]
- typo, rm verbose debug
- deraadt@cvs.openbsd.org
[ssh-keygen.1]
- document DSA use of ssh-keygen
[sshd.8]
- a start at describing what i understand of the DSA side
[ssh-keygen.1]
- document -X and -x
[ssh-keygen.c]
- simplify usage
- markus@cvs.openbsd.org
[sshd.8]
- there is no rhosts_dsa
[ssh-keygen.1]
- document -y, update -X,-x
[nchan.c]
- fix close for non-open ssh1 channels
[servconf.c servconf.h ssh.h sshd.8 sshd.c ]
- s/DsaKey/HostDSAKey/, document option
[sshconnect2.c]
- respect number_of_password_prompts
[channels.c channels.h servconf.c servconf.h session.c sshd.8]
- GatewayPorts for sshd, ok deraadt@
[ssh-add.1 ssh-agent.1 ssh.1]
- more doc on: DSA, id_dsa, known_hosts2, authorized_keys2
[ssh.1]
- more info on proto 2
[sshd.8]
- sync AUTHOR w/ ssh.1
[key.c key.h sshconnect.c]
- print key type when talking about host keys
[packet.c]
- clear padding in ssh2
[dsa.c key.c radix.c ssh.h sshconnect1.c uuencode.c uuencode.h]
- replace broken uuencode w/ libc b64_ntop
[auth2.c]
- log failure before sending the reply
[key.c radix.c uuencode.c]
- remote trailing comments before calling __b64_pton
[auth2.c readconf.c readconf.h servconf.c servconf.h ssh.1]
[sshconnect2.c sshd.8]
- add DSAAuthetication option to ssh/sshd, document SSH2 in sshd.8
- Bring in b64_ntop and b64_pton from OpenBSD libc (bsd-base64.[ch])
2000-05-07 10:03:14 +08:00
|
|
|
if (atomicio(read, remin, &resp, sizeof(resp)) != sizeof(resp))
|
1999-10-27 11:42:43 +08:00
|
|
|
lostconn(0);
|
|
|
|
|
|
|
|
cp = rbuf;
|
1999-11-24 21:26:21 +08:00
|
|
|
switch (resp) {
|
|
|
|
case 0: /* ok */
|
1999-10-27 11:42:43 +08:00
|
|
|
return (0);
|
|
|
|
default:
|
|
|
|
*cp++ = resp;
|
|
|
|
/* FALLTHROUGH */
|
1999-11-24 21:26:21 +08:00
|
|
|
case 1: /* error, followed by error msg */
|
|
|
|
case 2: /* fatal error, "" */
|
1999-10-27 11:42:43 +08:00
|
|
|
do {
|
- Remove references to SSLeay.
- Big OpenBSD CVS update
- markus@cvs.openbsd.org
[clientloop.c]
- typo
[session.c]
- update proctitle on pty alloc/dealloc, e.g. w/ windows client
[session.c]
- update proctitle for proto 1, too
[channels.h nchan.c serverloop.c session.c sshd.c]
- use c-style comments
- deraadt@cvs.openbsd.org
[scp.c]
- more atomicio
- markus@cvs.openbsd.org
[channels.c]
- set O_NONBLOCK
[ssh.1]
- update AUTHOR
[readconf.c ssh-keygen.c ssh.h]
- default DSA key file ~/.ssh/id_dsa
[clientloop.c]
- typo, rm verbose debug
- deraadt@cvs.openbsd.org
[ssh-keygen.1]
- document DSA use of ssh-keygen
[sshd.8]
- a start at describing what i understand of the DSA side
[ssh-keygen.1]
- document -X and -x
[ssh-keygen.c]
- simplify usage
- markus@cvs.openbsd.org
[sshd.8]
- there is no rhosts_dsa
[ssh-keygen.1]
- document -y, update -X,-x
[nchan.c]
- fix close for non-open ssh1 channels
[servconf.c servconf.h ssh.h sshd.8 sshd.c ]
- s/DsaKey/HostDSAKey/, document option
[sshconnect2.c]
- respect number_of_password_prompts
[channels.c channels.h servconf.c servconf.h session.c sshd.8]
- GatewayPorts for sshd, ok deraadt@
[ssh-add.1 ssh-agent.1 ssh.1]
- more doc on: DSA, id_dsa, known_hosts2, authorized_keys2
[ssh.1]
- more info on proto 2
[sshd.8]
- sync AUTHOR w/ ssh.1
[key.c key.h sshconnect.c]
- print key type when talking about host keys
[packet.c]
- clear padding in ssh2
[dsa.c key.c radix.c ssh.h sshconnect1.c uuencode.c uuencode.h]
- replace broken uuencode w/ libc b64_ntop
[auth2.c]
- log failure before sending the reply
[key.c radix.c uuencode.c]
- remote trailing comments before calling __b64_pton
[auth2.c readconf.c readconf.h servconf.c servconf.h ssh.1]
[sshconnect2.c sshd.8]
- add DSAAuthetication option to ssh/sshd, document SSH2 in sshd.8
- Bring in b64_ntop and b64_pton from OpenBSD libc (bsd-base64.[ch])
2000-05-07 10:03:14 +08:00
|
|
|
if (atomicio(read, remin, &ch, sizeof(ch)) != sizeof(ch))
|
1999-10-27 11:42:43 +08:00
|
|
|
lostconn(0);
|
|
|
|
*cp++ = ch;
|
|
|
|
} while (cp < &rbuf[sizeof(rbuf) - 1] && ch != '\n');
|
|
|
|
|
|
|
|
if (!iamremote)
|
2000-05-01 19:10:33 +08:00
|
|
|
(void) atomicio(write, STDERR_FILENO, rbuf, cp - rbuf);
|
1999-10-27 11:42:43 +08:00
|
|
|
++errs;
|
|
|
|
if (resp == 1)
|
|
|
|
return (-1);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-12-07 01:55:26 +08:00
|
|
|
usage(void)
|
1999-10-27 11:42:43 +08:00
|
|
|
{
|
2001-09-18 13:38:44 +08:00
|
|
|
(void) fprintf(stderr,
|
2002-06-21 08:10:58 +08:00
|
|
|
"usage: scp [-pqrvBC46] [-F config] [-S program] [-P port]\n"
|
|
|
|
" [-c cipher] [-i identity] [-o option]\n"
|
|
|
|
" [[user@]host1:]file1 [...] [[user@]host2:]file2\n");
|
1999-10-27 11:42:43 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-11-24 21:26:21 +08:00
|
|
|
run_err(const char *fmt,...)
|
1999-10-27 11:42:43 +08:00
|
|
|
{
|
|
|
|
static FILE *fp;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
++errs;
|
|
|
|
if (fp == NULL && !(fp = fdopen(remout, "w")))
|
|
|
|
return;
|
1999-11-24 21:26:21 +08:00
|
|
|
(void) fprintf(fp, "%c", 0x01);
|
|
|
|
(void) fprintf(fp, "scp: ");
|
1999-12-31 06:16:40 +08:00
|
|
|
va_start(ap, fmt);
|
1999-11-24 21:26:21 +08:00
|
|
|
(void) vfprintf(fp, fmt, ap);
|
1999-12-31 06:16:40 +08:00
|
|
|
va_end(ap);
|
1999-11-24 21:26:21 +08:00
|
|
|
(void) fprintf(fp, "\n");
|
|
|
|
(void) fflush(fp);
|
|
|
|
|
|
|
|
if (!iamremote) {
|
1999-12-31 06:16:40 +08:00
|
|
|
va_start(ap, fmt);
|
1999-11-24 21:26:21 +08:00
|
|
|
vfprintf(stderr, fmt, ap);
|
1999-12-31 06:16:40 +08:00
|
|
|
va_end(ap);
|
1999-11-24 21:26:21 +08:00
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
1999-10-27 11:42:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
verifydir(cp)
|
|
|
|
char *cp;
|
|
|
|
{
|
|
|
|
struct stat stb;
|
|
|
|
|
|
|
|
if (!stat(cp, &stb)) {
|
|
|
|
if (S_ISDIR(stb.st_mode))
|
|
|
|
return;
|
|
|
|
errno = ENOTDIR;
|
|
|
|
}
|
|
|
|
run_err("%s: %s", cp, strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
okname(cp0)
|
|
|
|
char *cp0;
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
cp = cp0;
|
|
|
|
do {
|
2001-06-25 12:28:30 +08:00
|
|
|
c = (int)*cp;
|
1999-10-27 11:42:43 +08:00
|
|
|
if (c & 0200)
|
|
|
|
goto bad;
|
2000-12-17 03:21:03 +08:00
|
|
|
if (!isalpha(c) && !isdigit(c) &&
|
2002-12-23 10:14:51 +08:00
|
|
|
c != '@' && c != '_' && c != '-' && c != '.' && c != '+')
|
1999-10-27 11:42:43 +08:00
|
|
|
goto bad;
|
|
|
|
} while (*++cp);
|
|
|
|
return (1);
|
|
|
|
|
- OpenBSD CVS updates to v1.2.3
[ssh.h atomicio.c]
- int atomicio -> ssize_t (for alpha). ok deraadt@
[auth-rsa.c]
- delay MD5 computation until client sends response, free() early, cleanup.
[cipher.c]
- void* -> unsigned char*, ok niels@
[hostfile.c]
- remove unused variable 'len'. fix comments.
- remove unused variable
[log-client.c log-server.c]
- rename a cpp symbol, to avoid param.h collision
[packet.c]
- missing xfree()
- getsockname() requires initialized tolen; andy@guildsoftware.com
- use getpeername() in packet_connection_is_on_socket(), fixes sshd -i;
from Holger.Trapp@Informatik.TU-Chemnitz.DE
[pty.c pty.h]
- register cleanup for pty earlier. move code for pty-owner handling to
pty.c ok provos@, dugsong@
[readconf.c]
- turn off x11-fwd for the client, too.
[rsa.c]
- PKCS#1 padding
[scp.c]
- allow '.' in usernames; from jedgar@fxp.org
[servconf.c]
- typo: ignore_user_known_hosts int->flag; naddy@mips.rhein-neckar.de
- sync with sshd_config
[ssh-keygen.c]
- enable ssh-keygen -l -f ~/.ssh/known_hosts, ok deraadt@
[ssh.1]
- Change invalid 'CHAT' loglevel to 'VERBOSE'
[ssh.c]
- suppress AAAA query host when '-4' is used; from shin@nd.net.fujitsu.co.jp
- turn off x11-fwd for the client, too.
[sshconnect.c]
- missing xfree()
- retry rresvport_af(), too. from sumikawa@ebina.hitachi.co.jp.
- read error vs. "Connection closed by remote host"
[sshd.8]
- ie. -> i.e.,
- do not link to a commercial page..
- sync with sshd_config
[sshd.c]
- no need for poll.h; from bright@wintelcom.net
- log with level log() not fatal() if peer behaves badly.
- don't panic if client behaves strange. ok deraadt@
- make no-port-forwarding for RSA keys deny both -L and -R style fwding
- delay close() of pty until the pty has been chowned back to root
- oops, fix comment, too.
- missing xfree()
- move XAUTHORITY to subdir. ok dugsong@. fixes debian bug #57907, too.
(http://cgi.debian.org/cgi-bin/bugreport.cgi?archive=no&bug=57907)
- register cleanup for pty earlier. move code for pty-owner handling to
pty.c ok provos@, dugsong@
- create x11 cookie file
- fix pr 1113, fclose() -> pclose(), todo: remote popen()
- version 1.2.3
- Cleaned up
2000-03-09 18:27:49 +08:00
|
|
|
bad: fprintf(stderr, "%s: invalid user name\n", cp0);
|
1999-10-27 11:42:43 +08:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
BUF *
|
|
|
|
allocbuf(bp, fd, blksize)
|
|
|
|
BUF *bp;
|
|
|
|
int fd, blksize;
|
|
|
|
{
|
|
|
|
size_t size;
|
2001-10-22 08:53:58 +08:00
|
|
|
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
|
1999-10-27 11:42:43 +08:00
|
|
|
struct stat stb;
|
|
|
|
|
|
|
|
if (fstat(fd, &stb) < 0) {
|
|
|
|
run_err("fstat: %s", strerror(errno));
|
|
|
|
return (0);
|
|
|
|
}
|
2002-12-23 10:22:09 +08:00
|
|
|
size = roundup(stb.st_blksize, blksize);
|
|
|
|
if (size == 0)
|
1999-11-24 21:26:21 +08:00
|
|
|
size = blksize;
|
2001-10-22 08:53:58 +08:00
|
|
|
#else /* HAVE_STRUCT_STAT_ST_BLKSIZE */
|
2001-02-05 20:42:17 +08:00
|
|
|
size = blksize;
|
2001-10-22 08:53:58 +08:00
|
|
|
#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
|
1999-10-27 11:42:43 +08:00
|
|
|
if (bp->cnt >= size)
|
|
|
|
return (bp);
|
1999-11-24 21:26:21 +08:00
|
|
|
if (bp->buf == NULL)
|
|
|
|
bp->buf = xmalloc(size);
|
|
|
|
else
|
|
|
|
bp->buf = xrealloc(bp->buf, size);
|
2001-09-13 01:49:48 +08:00
|
|
|
memset(bp->buf, 0, size);
|
1999-10-27 11:42:43 +08:00
|
|
|
bp->cnt = size;
|
|
|
|
return (bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
lostconn(signo)
|
|
|
|
int signo;
|
|
|
|
{
|
|
|
|
if (!iamremote)
|
2001-06-21 11:08:58 +08:00
|
|
|
write(STDERR_FILENO, "lost connection\n", 16);
|
|
|
|
if (signo)
|
|
|
|
_exit(1);
|
|
|
|
else
|
|
|
|
exit(1);
|
1999-10-27 11:42:43 +08:00
|
|
|
}
|
|
|
|
|
2001-06-25 13:01:22 +08:00
|
|
|
static void
|
2000-03-17 20:40:15 +08:00
|
|
|
updateprogressmeter(int ignore)
|
1999-10-27 11:42:43 +08:00
|
|
|
{
|
|
|
|
int save_errno = errno;
|
|
|
|
|
|
|
|
progressmeter(0);
|
2001-08-07 06:48:19 +08:00
|
|
|
signal(SIGALRM, updateprogressmeter);
|
|
|
|
alarm(PROGRESSTIME);
|
1999-10-27 11:42:43 +08:00
|
|
|
errno = save_errno;
|
|
|
|
}
|
|
|
|
|
2001-06-25 13:01:22 +08:00
|
|
|
static int
|
2001-02-09 10:11:24 +08:00
|
|
|
foregroundproc(void)
|
1999-11-18 06:28:11 +08:00
|
|
|
{
|
|
|
|
static pid_t pgrp = -1;
|
|
|
|
int ctty_pgrp;
|
|
|
|
|
|
|
|
if (pgrp == -1)
|
|
|
|
pgrp = getpgrp();
|
|
|
|
|
2001-02-03 02:58:33 +08:00
|
|
|
#ifdef HAVE_TCGETPGRP
|
2000-09-05 13:13:06 +08:00
|
|
|
return ((ctty_pgrp = tcgetpgrp(STDOUT_FILENO)) != -1 &&
|
|
|
|
ctty_pgrp == pgrp);
|
|
|
|
#else
|
1999-11-24 21:26:21 +08:00
|
|
|
return ((ioctl(STDOUT_FILENO, TIOCGPGRP, &ctty_pgrp) != -1 &&
|
|
|
|
ctty_pgrp == pgrp));
|
2000-09-05 13:13:06 +08:00
|
|
|
#endif
|
1999-11-18 06:28:11 +08:00
|
|
|
}
|
|
|
|
|
1999-10-27 11:42:43 +08:00
|
|
|
void
|
|
|
|
progressmeter(int flag)
|
|
|
|
{
|
2002-12-23 10:53:08 +08:00
|
|
|
static const char spaces[] = " "
|
|
|
|
" "
|
|
|
|
" "
|
|
|
|
" "
|
|
|
|
" "
|
|
|
|
" ";
|
1999-10-27 11:42:43 +08:00
|
|
|
static const char prefixes[] = " KMGTP";
|
|
|
|
static struct timeval lastupdate;
|
|
|
|
static off_t lastsize;
|
|
|
|
struct timeval now, td, wait;
|
2002-12-23 10:53:08 +08:00
|
|
|
off_t cursize, abbrevsize, bytespersec;
|
1999-10-27 11:42:43 +08:00
|
|
|
double elapsed;
|
2002-12-23 10:53:08 +08:00
|
|
|
int ratio, remaining, i, ai, bi, nspaces;
|
2002-04-03 04:17:43 +08:00
|
|
|
char buf[512];
|
1999-10-27 11:42:43 +08:00
|
|
|
|
|
|
|
if (flag == -1) {
|
1999-11-24 21:26:21 +08:00
|
|
|
(void) gettimeofday(&start, (struct timezone *) 0);
|
1999-10-27 11:42:43 +08:00
|
|
|
lastupdate = start;
|
|
|
|
lastsize = 0;
|
1999-11-24 21:26:21 +08:00
|
|
|
}
|
1999-11-18 06:28:11 +08:00
|
|
|
if (foregroundproc() == 0)
|
|
|
|
return;
|
|
|
|
|
1999-11-24 21:26:21 +08:00
|
|
|
(void) gettimeofday(&now, (struct timezone *) 0);
|
1999-10-27 11:42:43 +08:00
|
|
|
cursize = statbytes;
|
1999-11-13 10:22:46 +08:00
|
|
|
if (totalbytes != 0) {
|
1999-11-25 08:54:57 +08:00
|
|
|
ratio = 100.0 * cursize / totalbytes;
|
1999-10-27 11:42:43 +08:00
|
|
|
ratio = MAX(ratio, 0);
|
|
|
|
ratio = MIN(ratio, 100);
|
1999-11-24 21:26:21 +08:00
|
|
|
} else
|
1999-10-27 11:42:43 +08:00
|
|
|
ratio = 100;
|
|
|
|
|
|
|
|
abbrevsize = cursize;
|
2002-12-23 10:53:08 +08:00
|
|
|
for (ai = 0; abbrevsize >= 10000 && ai < sizeof(prefixes); ai++)
|
1999-10-27 11:42:43 +08:00
|
|
|
abbrevsize >>= 10;
|
|
|
|
|
|
|
|
timersub(&now, &lastupdate, &wait);
|
|
|
|
if (cursize > lastsize) {
|
|
|
|
lastupdate = now;
|
|
|
|
lastsize = cursize;
|
|
|
|
wait.tv_sec = 0;
|
|
|
|
}
|
|
|
|
timersub(&now, &start, &td);
|
|
|
|
elapsed = td.tv_sec + (td.tv_usec / 1000000.0);
|
|
|
|
|
2002-12-23 10:53:08 +08:00
|
|
|
bytespersec = 0;
|
|
|
|
if (statbytes > 0) {
|
|
|
|
bytespersec = statbytes;
|
|
|
|
if (elapsed > 0.0)
|
|
|
|
bytespersec /= elapsed;
|
|
|
|
}
|
|
|
|
for (bi = 1; bytespersec >= 1024000 && bi < sizeof(prefixes); bi++)
|
|
|
|
bytespersec >>= 10;
|
|
|
|
|
|
|
|
nspaces = MIN(getttywidth() - 79, sizeof(spaces) - 1);
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf),
|
|
|
|
"\r%-45.45s%.*s%3d%% %4lld%c%c %3lld.%01d%cB/s",
|
|
|
|
curfile,
|
|
|
|
nspaces,
|
|
|
|
spaces,
|
|
|
|
ratio,
|
|
|
|
(long long)abbrevsize,
|
|
|
|
prefixes[ai],
|
|
|
|
ai == 0 ? ' ' : 'B',
|
|
|
|
(long long)(bytespersec / 1024),
|
|
|
|
(int)((bytespersec % 1024) * 10 / 1024),
|
|
|
|
prefixes[bi]
|
|
|
|
);
|
|
|
|
|
2000-12-16 07:03:10 +08:00
|
|
|
if (flag != 1 &&
|
|
|
|
(statbytes <= 0 || elapsed <= 0.0 || cursize > totalbytes)) {
|
1999-10-27 11:42:43 +08:00
|
|
|
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
|
2000-12-16 07:03:10 +08:00
|
|
|
" --:-- ETA");
|
1999-10-27 11:42:43 +08:00
|
|
|
} else if (wait.tv_sec >= STALLTIME) {
|
|
|
|
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
|
2000-12-16 07:03:10 +08:00
|
|
|
" - stalled -");
|
1999-10-27 11:42:43 +08:00
|
|
|
} else {
|
2000-04-19 14:26:12 +08:00
|
|
|
if (flag != 1)
|
2000-12-16 07:03:10 +08:00
|
|
|
remaining = (int)(totalbytes / (statbytes / elapsed) -
|
|
|
|
elapsed);
|
2000-04-19 14:26:12 +08:00
|
|
|
else
|
|
|
|
remaining = elapsed;
|
|
|
|
|
1999-10-28 13:23:30 +08:00
|
|
|
i = remaining / 3600;
|
1999-10-27 11:42:43 +08:00
|
|
|
if (i)
|
|
|
|
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
|
2000-08-23 08:46:23 +08:00
|
|
|
"%2d:", i);
|
1999-10-27 11:42:43 +08:00
|
|
|
else
|
|
|
|
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
|
2000-08-23 08:46:23 +08:00
|
|
|
" ");
|
1999-10-27 11:42:43 +08:00
|
|
|
i = remaining % 3600;
|
|
|
|
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
|
2000-08-23 08:46:23 +08:00
|
|
|
"%02d:%02d%s", i / 60, i % 60,
|
|
|
|
(flag != 1) ? " ETA" : " ");
|
1999-10-27 11:42:43 +08:00
|
|
|
}
|
|
|
|
atomicio(write, fileno(stdout), buf, strlen(buf));
|
|
|
|
|
|
|
|
if (flag == -1) {
|
2001-02-18 11:55:16 +08:00
|
|
|
mysignal(SIGALRM, updateprogressmeter);
|
2001-08-07 06:48:19 +08:00
|
|
|
alarm(PROGRESSTIME);
|
1999-10-27 11:42:43 +08:00
|
|
|
} else if (flag == 1) {
|
2001-08-07 06:48:19 +08:00
|
|
|
alarm(0);
|
2000-05-01 19:10:33 +08:00
|
|
|
atomicio(write, fileno(stdout), "\n", 1);
|
1999-10-27 11:42:43 +08:00
|
|
|
statbytes = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
getttywidth(void)
|
|
|
|
{
|
|
|
|
struct winsize winsize;
|
|
|
|
|
|
|
|
if (ioctl(fileno(stdout), TIOCGWINSZ, &winsize) != -1)
|
1999-11-24 21:26:21 +08:00
|
|
|
return (winsize.ws_col ? winsize.ws_col : 80);
|
1999-10-27 11:42:43 +08:00
|
|
|
else
|
1999-11-24 21:26:21 +08:00
|
|
|
return (80);
|
1999-10-27 11:42:43 +08:00
|
|
|
}
|