summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--sftp-int.c11
-rw-r--r--sftp.19
-rw-r--r--sftp.c28
4 files changed, 39 insertions, 18 deletions
diff --git a/ChangeLog b/ChangeLog
index 0e48d5743..9985b57ff 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
120040121
2 - (djm) OpenBSD CVS Sync
3 - djm@cvs.openbsd.org 2004/01/13 09:25:05
4 [sftp-int.c sftp.1 sftp.c]
5 Tidy sftp batchmode handling, eliminate junk to stderr (bugzilla #754) and
6 enable use of "-b -" to accept batchfile from stdin; ok markus@
7
120040114 820040114
2 - (dtucker) [auth-pam.c] Have monitor die if PAM authentication thread exits 9 - (dtucker) [auth-pam.c] Have monitor die if PAM authentication thread exits
3 unexpectedly. with & ok djm@ 10 unexpectedly. with & ok djm@
@@ -1666,4 +1673,4 @@
1666 - Fix sshd BindAddress and -b options for systems using fake-getaddrinfo. 1673 - Fix sshd BindAddress and -b options for systems using fake-getaddrinfo.
1667 Report from murple@murple.net, diagnosis from dtucker@zip.com.au 1674 Report from murple@murple.net, diagnosis from dtucker@zip.com.au
1668 1675
1669$Id: ChangeLog,v 1.3169 2004/01/14 13:15:07 dtucker Exp $ 1676$Id: ChangeLog,v 1.3170 2004/01/20 23:58:47 djm Exp $
diff --git a/sftp-int.c b/sftp-int.c
index edb475bbb..a9423fe69 100644
--- a/sftp-int.c
+++ b/sftp-int.c
@@ -25,7 +25,7 @@
25/* XXX: recursive operations */ 25/* XXX: recursive operations */
26 26
27#include "includes.h" 27#include "includes.h"
28RCSID("$OpenBSD: sftp-int.c,v 1.65 2003/11/21 11:57:03 djm Exp $"); 28RCSID("$OpenBSD: sftp-int.c,v 1.66 2004/01/13 09:25:05 djm Exp $");
29 29
30#include "buffer.h" 30#include "buffer.h"
31#include "xmalloc.h" 31#include "xmalloc.h"
@@ -41,6 +41,9 @@ RCSID("$OpenBSD: sftp-int.c,v 1.65 2003/11/21 11:57:03 djm Exp $");
41/* File to read commands from */ 41/* File to read commands from */
42extern FILE *infile; 42extern FILE *infile;
43 43
44/* Are we in batchfile mode? */
45extern int batchmode;
46
44/* Size of buffer used when copying files */ 47/* Size of buffer used when copying files */
45extern size_t copy_buffer_len; 48extern size_t copy_buffer_len;
46 49
@@ -1172,14 +1175,16 @@ interactive_loop(int fd_in, int fd_out, char *file1, char *file2)
1172 if (fgets(cmd, sizeof(cmd), infile) == NULL) { 1175 if (fgets(cmd, sizeof(cmd), infile) == NULL) {
1173 printf("\n"); 1176 printf("\n");
1174 break; 1177 break;
1175 } else if (infile != stdin) /* Bluff typing */ 1178 }
1179
1180 if (batchmode) /* Echo command */
1176 printf("%s", cmd); 1181 printf("%s", cmd);
1177 1182
1178 cp = strrchr(cmd, '\n'); 1183 cp = strrchr(cmd, '\n');
1179 if (cp) 1184 if (cp)
1180 *cp = '\0'; 1185 *cp = '\0';
1181 1186
1182 err = parse_dispatch_command(conn, cmd, &pwd, infile != stdin); 1187 err = parse_dispatch_command(conn, cmd, &pwd, batchmode);
1183 if (err != 0) 1188 if (err != 0)
1184 break; 1189 break;
1185 } 1190 }
diff --git a/sftp.1 b/sftp.1
index 8563e2bdd..cfa2e10b3 100644
--- a/sftp.1
+++ b/sftp.1
@@ -1,4 +1,4 @@
1.\" $OpenBSD: sftp.1,v 1.49 2003/12/16 15:49:51 markus Exp $ 1.\" $OpenBSD: sftp.1,v 1.50 2004/01/13 09:25:05 djm Exp $
2.\" 2.\"
3.\" Copyright (c) 2001 Damien Miller. All rights reserved. 3.\" Copyright (c) 2001 Damien Miller. All rights reserved.
4.\" 4.\"
@@ -99,7 +99,12 @@ Batch mode reads a series of commands from an input
99instead of 99instead of
100.Em stdin . 100.Em stdin .
101Since it lacks user interaction it should be used in conjunction with 101Since it lacks user interaction it should be used in conjunction with
102non-interactive authentication. 102non-interactive authentication.
103A
104.Ar batchfile
105of
106.Sq Ic \-
107may be used to indicate standard input.
103.Nm 108.Nm
104will abort if any of the following 109will abort if any of the following
105commands fail: 110commands fail:
diff --git a/sftp.c b/sftp.c
index fddc6875f..e288302fa 100644
--- a/sftp.c
+++ b/sftp.c
@@ -24,7 +24,7 @@
24 24
25#include "includes.h" 25#include "includes.h"
26 26
27RCSID("$OpenBSD: sftp.c,v 1.38 2003/10/08 08:27:36 jmc Exp $"); 27RCSID("$OpenBSD: sftp.c,v 1.39 2004/01/13 09:25:05 djm Exp $");
28 28
29#include "buffer.h" 29#include "buffer.h"
30#include "xmalloc.h" 30#include "xmalloc.h"
@@ -43,7 +43,8 @@ extern char *__progname;
43char *__progname; 43char *__progname;
44#endif 44#endif
45 45
46FILE* infile; 46FILE* infile = stdin;
47int batchmode = 0;
47size_t copy_buffer_len = 32768; 48size_t copy_buffer_len = 32768;
48size_t num_requests = 16; 49size_t num_requests = 16;
49static pid_t sshpid = -1; 50static pid_t sshpid = -1;
@@ -141,7 +142,6 @@ main(int argc, char **argv)
141 addargs(&args, "-oForwardAgent no"); 142 addargs(&args, "-oForwardAgent no");
142 addargs(&args, "-oClearAllForwardings yes"); 143 addargs(&args, "-oClearAllForwardings yes");
143 ll = SYSLOG_LEVEL_INFO; 144 ll = SYSLOG_LEVEL_INFO;
144 infile = stdin; /* Read from STDIN unless changed by -b */
145 145
146 while ((ch = getopt(argc, argv, "1hvCo:s:S:b:B:F:P:R:")) != -1) { 146 while ((ch = getopt(argc, argv, "1hvCo:s:S:b:B:F:P:R:")) != -1) {
147 switch (ch) { 147 switch (ch) {
@@ -171,13 +171,15 @@ main(int argc, char **argv)
171 ssh_program = optarg; 171 ssh_program = optarg;
172 break; 172 break;
173 case 'b': 173 case 'b':
174 if (infile == stdin) { 174 if (batchmode)
175 infile = fopen(optarg, "r"); 175 fatal("Batch file already specified.");
176 if (infile == NULL) 176
177 fatal("%s (%s).", strerror(errno), optarg); 177 /* Allow "-" as stdin */
178 } else 178 if (strcmp(optarg, "-") != 0 &&
179 fatal("Filename already specified."); 179 (infile = fopen(optarg, "r")) == NULL)
180 fatal("%s (%s).", strerror(errno), optarg);
180 showprogress = 0; 181 showprogress = 0;
182 batchmode = 1;
181 break; 183 break;
182 case 'P': 184 case 'P':
183 sftp_direct = optarg; 185 sftp_direct = optarg;
@@ -241,13 +243,15 @@ main(int argc, char **argv)
241 sftp_server : "sftp")); 243 sftp_server : "sftp"));
242 args.list[0] = ssh_program; 244 args.list[0] = ssh_program;
243 245
244 fprintf(stderr, "Connecting to %s...\n", host); 246 if (!batchmode)
247 fprintf(stderr, "Connecting to %s...\n", host);
245 connect_to_server(ssh_program, args.list, &in, &out); 248 connect_to_server(ssh_program, args.list, &in, &out);
246 } else { 249 } else {
247 args.list = NULL; 250 args.list = NULL;
248 addargs(&args, "sftp-server"); 251 addargs(&args, "sftp-server");
249 252
250 fprintf(stderr, "Attaching to %s...\n", sftp_direct); 253 if (!batchmode)
254 fprintf(stderr, "Attaching to %s...\n", sftp_direct);
251 connect_to_server(sftp_direct, args.list, &in, &out); 255 connect_to_server(sftp_direct, args.list, &in, &out);
252 } 256 }
253 257
@@ -260,7 +264,7 @@ main(int argc, char **argv)
260 264
261 close(in); 265 close(in);
262 close(out); 266 close(out);
263 if (infile != stdin) 267 if (batchmode)
264 fclose(infile); 268 fclose(infile);
265 269
266 while (waitpid(sshpid, NULL, 0) == -1) 270 while (waitpid(sshpid, NULL, 0) == -1)