mirror of
git://anongit.mindrot.org/openssh.git
synced 2025-02-27 03:11:00 +00:00
- djm@cvs.openbsd.org 2004/01/13 09:25:05
[sftp-int.c sftp.1 sftp.c] Tidy sftp batchmode handling, eliminate junk to stderr (bugzilla #754) and enable use of "-b -" to accept batchfile from stdin; ok markus@
This commit is contained in:
parent
a8df9248ce
commit
44f75c14f6
@ -1,3 +1,10 @@
|
||||
20040121
|
||||
- (djm) OpenBSD CVS Sync
|
||||
- djm@cvs.openbsd.org 2004/01/13 09:25:05
|
||||
[sftp-int.c sftp.1 sftp.c]
|
||||
Tidy sftp batchmode handling, eliminate junk to stderr (bugzilla #754) and
|
||||
enable use of "-b -" to accept batchfile from stdin; ok markus@
|
||||
|
||||
20040114
|
||||
- (dtucker) [auth-pam.c] Have monitor die if PAM authentication thread exits
|
||||
unexpectedly. with & ok djm@
|
||||
@ -1666,4 +1673,4 @@
|
||||
- Fix sshd BindAddress and -b options for systems using fake-getaddrinfo.
|
||||
Report from murple@murple.net, diagnosis from dtucker@zip.com.au
|
||||
|
||||
$Id: ChangeLog,v 1.3169 2004/01/14 13:15:07 dtucker Exp $
|
||||
$Id: ChangeLog,v 1.3170 2004/01/20 23:58:47 djm Exp $
|
||||
|
11
sftp-int.c
11
sftp-int.c
@ -25,7 +25,7 @@
|
||||
/* XXX: recursive operations */
|
||||
|
||||
#include "includes.h"
|
||||
RCSID("$OpenBSD: sftp-int.c,v 1.65 2003/11/21 11:57:03 djm Exp $");
|
||||
RCSID("$OpenBSD: sftp-int.c,v 1.66 2004/01/13 09:25:05 djm Exp $");
|
||||
|
||||
#include "buffer.h"
|
||||
#include "xmalloc.h"
|
||||
@ -41,6 +41,9 @@ RCSID("$OpenBSD: sftp-int.c,v 1.65 2003/11/21 11:57:03 djm Exp $");
|
||||
/* File to read commands from */
|
||||
extern FILE *infile;
|
||||
|
||||
/* Are we in batchfile mode? */
|
||||
extern int batchmode;
|
||||
|
||||
/* Size of buffer used when copying files */
|
||||
extern size_t copy_buffer_len;
|
||||
|
||||
@ -1172,14 +1175,16 @@ interactive_loop(int fd_in, int fd_out, char *file1, char *file2)
|
||||
if (fgets(cmd, sizeof(cmd), infile) == NULL) {
|
||||
printf("\n");
|
||||
break;
|
||||
} else if (infile != stdin) /* Bluff typing */
|
||||
}
|
||||
|
||||
if (batchmode) /* Echo command */
|
||||
printf("%s", cmd);
|
||||
|
||||
cp = strrchr(cmd, '\n');
|
||||
if (cp)
|
||||
*cp = '\0';
|
||||
|
||||
err = parse_dispatch_command(conn, cmd, &pwd, infile != stdin);
|
||||
err = parse_dispatch_command(conn, cmd, &pwd, batchmode);
|
||||
if (err != 0)
|
||||
break;
|
||||
}
|
||||
|
9
sftp.1
9
sftp.1
@ -1,4 +1,4 @@
|
||||
.\" $OpenBSD: sftp.1,v 1.49 2003/12/16 15:49:51 markus Exp $
|
||||
.\" $OpenBSD: sftp.1,v 1.50 2004/01/13 09:25:05 djm Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2001 Damien Miller. All rights reserved.
|
||||
.\"
|
||||
@ -99,7 +99,12 @@ Batch mode reads a series of commands from an input
|
||||
instead of
|
||||
.Em stdin .
|
||||
Since it lacks user interaction it should be used in conjunction with
|
||||
non-interactive authentication.
|
||||
non-interactive authentication.
|
||||
A
|
||||
.Ar batchfile
|
||||
of
|
||||
.Sq Ic \-
|
||||
may be used to indicate standard input.
|
||||
.Nm
|
||||
will abort if any of the following
|
||||
commands fail:
|
||||
|
28
sftp.c
28
sftp.c
@ -24,7 +24,7 @@
|
||||
|
||||
#include "includes.h"
|
||||
|
||||
RCSID("$OpenBSD: sftp.c,v 1.38 2003/10/08 08:27:36 jmc Exp $");
|
||||
RCSID("$OpenBSD: sftp.c,v 1.39 2004/01/13 09:25:05 djm Exp $");
|
||||
|
||||
#include "buffer.h"
|
||||
#include "xmalloc.h"
|
||||
@ -43,7 +43,8 @@ extern char *__progname;
|
||||
char *__progname;
|
||||
#endif
|
||||
|
||||
FILE* infile;
|
||||
FILE* infile = stdin;
|
||||
int batchmode = 0;
|
||||
size_t copy_buffer_len = 32768;
|
||||
size_t num_requests = 16;
|
||||
static pid_t sshpid = -1;
|
||||
@ -141,7 +142,6 @@ main(int argc, char **argv)
|
||||
addargs(&args, "-oForwardAgent no");
|
||||
addargs(&args, "-oClearAllForwardings yes");
|
||||
ll = SYSLOG_LEVEL_INFO;
|
||||
infile = stdin; /* Read from STDIN unless changed by -b */
|
||||
|
||||
while ((ch = getopt(argc, argv, "1hvCo:s:S:b:B:F:P:R:")) != -1) {
|
||||
switch (ch) {
|
||||
@ -171,13 +171,15 @@ main(int argc, char **argv)
|
||||
ssh_program = optarg;
|
||||
break;
|
||||
case 'b':
|
||||
if (infile == stdin) {
|
||||
infile = fopen(optarg, "r");
|
||||
if (infile == NULL)
|
||||
fatal("%s (%s).", strerror(errno), optarg);
|
||||
} else
|
||||
fatal("Filename already specified.");
|
||||
if (batchmode)
|
||||
fatal("Batch file already specified.");
|
||||
|
||||
/* Allow "-" as stdin */
|
||||
if (strcmp(optarg, "-") != 0 &&
|
||||
(infile = fopen(optarg, "r")) == NULL)
|
||||
fatal("%s (%s).", strerror(errno), optarg);
|
||||
showprogress = 0;
|
||||
batchmode = 1;
|
||||
break;
|
||||
case 'P':
|
||||
sftp_direct = optarg;
|
||||
@ -241,13 +243,15 @@ main(int argc, char **argv)
|
||||
sftp_server : "sftp"));
|
||||
args.list[0] = ssh_program;
|
||||
|
||||
fprintf(stderr, "Connecting to %s...\n", host);
|
||||
if (!batchmode)
|
||||
fprintf(stderr, "Connecting to %s...\n", host);
|
||||
connect_to_server(ssh_program, args.list, &in, &out);
|
||||
} else {
|
||||
args.list = NULL;
|
||||
addargs(&args, "sftp-server");
|
||||
|
||||
fprintf(stderr, "Attaching to %s...\n", sftp_direct);
|
||||
if (!batchmode)
|
||||
fprintf(stderr, "Attaching to %s...\n", sftp_direct);
|
||||
connect_to_server(sftp_direct, args.list, &in, &out);
|
||||
}
|
||||
|
||||
@ -260,7 +264,7 @@ main(int argc, char **argv)
|
||||
|
||||
close(in);
|
||||
close(out);
|
||||
if (infile != stdin)
|
||||
if (batchmode)
|
||||
fclose(infile);
|
||||
|
||||
while (waitpid(sshpid, NULL, 0) == -1)
|
||||
|
Loading…
Reference in New Issue
Block a user