summaryrefslogtreecommitdiffstats
path: root/sftp-client.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2001-02-10 00:40:03 +1100
committerDamien Miller <djm@mindrot.org>2001-02-10 00:40:03 +1100
commitd7686fd1fbe842baa8ce77f018c040d5e1d3438a (patch)
treea5d6ad5b4b232e06185a49b1b5aabe4761a3d8ed /sftp-client.c
parent4192c467916f96668fad5b53d90d83dfbfdcacb5 (diff)
- (djm) Sync sftp and scp stuff from OpenBSD:
- djm@cvs.openbsd.org 2001/02/07 03:55:13 [sftp-client.c] Don't free handles before we are done with them. Based on work from Corinna Vinschen <vinschen@redhat.com>. ok markus@ - djm@cvs.openbsd.org 2001/02/06 22:32:53 [sftp.1] Punctuation fix from Pekka Savola <pekkas@netcore.fi> - deraadt@cvs.openbsd.org 2001/02/07 04:07:29 [sftp.1] pretty up significantly - itojun@cvs.openbsd.org 2001/02/07 06:49:42 [sftp.1] .Bl-.El mismatch. markus ok - djm@cvs.openbsd.org 2001/02/07 06:12:30 [sftp-int.c] Check that target is a directory before doing ls; ok markus@ - itojun@cvs.openbsd.org 2001/02/07 11:01:18 [scp.c sftp-client.c sftp-server.c] unsigned long long -> %llu, not %qu. markus ok - stevesk@cvs.openbsd.org 2001/02/07 11:10:39 [sftp.1 sftp-int.c] more man page cleanup and sync of help text with man page; ok markus@ - markus@cvs.openbsd.org 2001/02/07 14:58:34 [sftp-client.c] older servers reply with SSH2_FXP_NAME + count==0 instead of EOF - djm@cvs.openbsd.org 2001/02/07 15:27:19 [sftp.c] Don't forward agent and X11 in sftp. Suggestion from Roumen Petrov <roumen.petrov@skalasoft.com> - stevesk@cvs.openbsd.org 2001/02/07 15:36:04 [sftp-int.c] portable; ok markus@ - stevesk@cvs.openbsd.org 2001/02/07 15:55:47 [sftp-int.c] lowercase cmds[].c also; ok markus@ - markus@cvs.openbsd.org 2001/02/07 17:04:52 [pathnames.h sftp.c] allow sftp over ssh protocol 1; ok djm@ - deraadt@cvs.openbsd.org 2001/02/08 07:38:55 [scp.c] memory leak fix, and snprintf throughout - deraadt@cvs.openbsd.org 2001/02/08 08:02:02 [sftp-int.c] plug a memory leak - stevesk@cvs.openbsd.org 2001/02/08 10:11:23 [session.c sftp-client.c] %i -> %d - stevesk@cvs.openbsd.org 2001/02/08 10:57:59 [sftp-int.c] typo - stevesk@cvs.openbsd.org 2001/02/08 15:28:07 [sftp-int.c pathnames.h] _PATH_LS; ok markus@ - djm@cvs.openbsd.org 2001/02/09 04:46:25 [sftp-int.c] Check for NULL attribs for chown, chmod & chgrp operations, only send relevant attribs back to server; ok markus@ - (djm) Update makefile.in for _PATH_SFTP_SERVER
Diffstat (limited to 'sftp-client.c')
-rw-r--r--sftp-client.c51
1 files changed, 28 insertions, 23 deletions
diff --git a/sftp-client.c b/sftp-client.c
index e8b9007f..490c00bd 100644
--- a/sftp-client.c
+++ b/sftp-client.c
@@ -29,7 +29,7 @@
/* XXX: copy between two remote sites */
#include "includes.h"
-RCSID("$OpenBSD: sftp-client.c,v 1.4 2001/02/06 23:30:28 djm Exp $");
+RCSID("$OpenBSD: sftp-client.c,v 1.8 2001/02/08 17:11:23 stevesk Exp $");
#include "ssh.h"
#include "buffer.h"
@@ -338,7 +338,9 @@ do_ls(int fd_in, int fd_out, char *path)
SSH2_FXP_NAME, type);
count = buffer_get_int(&msg);
- debug3("Received %i SSH2_FXP_NAME responses", count);
+ if (count == 0)
+ break;
+ debug3("Received %d SSH2_FXP_NAME responses", count);
for(i = 0; i < count; i++) {
char *filename, *longname;
Attrib *a;
@@ -556,6 +558,7 @@ do_download(int fd_in, int fd_out, char *remote_path, char *local_path,
char *handle;
Buffer msg;
Attrib junk, *a;
+ int status;
a = do_stat(fd_in, fd_out, remote_path);
if (a == NULL)
@@ -635,7 +638,7 @@ do_download(int fd_in, int fd_out, char *remote_path, char *local_path,
if (id != expected_id)
fatal("ID mismatch (%d != %d)", id, expected_id);
if (type == SSH2_FXP_STATUS) {
- int status = buffer_get_int(&msg);
+ status = buffer_get_int(&msg);
if (status == SSH2_FX_EOF)
break;
@@ -644,10 +647,7 @@ do_download(int fd_in, int fd_out, char *remote_path, char *local_path,
"file \"%s\" : %s", remote_path,
fx2txt(status));
do_close(fd_in, fd_out, handle, handle_len);
- xfree(handle);
- close(local_fd);
- buffer_free(&msg);
- return(status);
+ goto done;
}
} else if (type != SSH2_FXP_DATA) {
fatal("Expected SSH2_FXP_DATA(%d) packet, got %d",
@@ -659,27 +659,27 @@ do_download(int fd_in, int fd_out, char *remote_path, char *local_path,
fatal("Received more data than asked for %d > %d",
len, COPY_SIZE);
- debug3("In read loop, got %d offset %lld", len,
+ debug3("In read loop, got %d offset %llu", len,
(unsigned long long)offset);
if (atomicio(write, local_fd, data, len) != len) {
error("Couldn't write to \"%s\": %s", local_path,
strerror(errno));
do_close(fd_in, fd_out, handle, handle_len);
- xfree(handle);
- close(local_fd);
+ status = -1;
xfree(data);
- buffer_free(&msg);
- return(-1);
+ goto done;
}
offset += len;
xfree(data);
}
- xfree(handle);
- buffer_free(&msg);
- close(local_fd);
+ status = do_close(fd_in, fd_out, handle, handle_len);
- return(do_close(fd_in, fd_out, handle, handle_len));
+done:
+ close(local_fd);
+ buffer_free(&msg);
+ xfree(handle);
+ return status;
}
int
@@ -693,6 +693,7 @@ do_upload(int fd_in, int fd_out, char *local_path, char *remote_path,
Buffer msg;
struct stat sb;
Attrib a;
+ int status;
if ((local_fd = open(local_path, O_RDONLY, 0)) == -1) {
error("Couldn't open local file \"%s\" for reading: %s",
@@ -743,7 +744,6 @@ do_upload(int fd_in, int fd_out, char *local_path, char *remote_path,
for(;;) {
int len;
char data[COPY_SIZE];
- u_int status;
/*
* Can't use atomicio here because it returns 0 on EOF, thus losing
@@ -774,24 +774,29 @@ do_upload(int fd_in, int fd_out, char *local_path, char *remote_path,
error("Couldn't write to remote file \"%s\": %s",
remote_path, fx2txt(status));
do_close(fd_in, fd_out, handle, handle_len);
- xfree(handle);
close(local_fd);
- return(-1);
+ goto done;
}
debug3("In write loop, got %d offset %llu", len,
(unsigned long long)offset);
offset += len;
}
- xfree(handle);
- buffer_free(&msg);
if (close(local_fd) == -1) {
error("Couldn't close local file \"%s\": %s", local_path,
strerror(errno));
do_close(fd_in, fd_out, handle, handle_len);
- return(-1);
+ status = -1;
+ goto done;
}
- return(do_close(fd_in, fd_out, handle, handle_len));
+ status = do_close(fd_in, fd_out, handle, handle_len);
+
+done:
+ xfree(handle);
+ buffer_free(&msg);
+ return status;
}
+
+