diff options
author | Damien Miller <djm@mindrot.org> | 2001-02-10 00:40:03 +1100 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2001-02-10 00:40:03 +1100 |
commit | d7686fd1fbe842baa8ce77f018c040d5e1d3438a (patch) | |
tree | a5d6ad5b4b232e06185a49b1b5aabe4761a3d8ed /sftp-client.c | |
parent | 4192c467916f96668fad5b53d90d83dfbfdcacb5 (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.c | 51 |
1 files changed, 28 insertions, 23 deletions
diff --git a/sftp-client.c b/sftp-client.c index e8b9007fe..490c00bdd 100644 --- a/sftp-client.c +++ b/sftp-client.c | |||
@@ -29,7 +29,7 @@ | |||
29 | /* XXX: copy between two remote sites */ | 29 | /* XXX: copy between two remote sites */ |
30 | 30 | ||
31 | #include "includes.h" | 31 | #include "includes.h" |
32 | RCSID("$OpenBSD: sftp-client.c,v 1.4 2001/02/06 23:30:28 djm Exp $"); | 32 | RCSID("$OpenBSD: sftp-client.c,v 1.8 2001/02/08 17:11:23 stevesk Exp $"); |
33 | 33 | ||
34 | #include "ssh.h" | 34 | #include "ssh.h" |
35 | #include "buffer.h" | 35 | #include "buffer.h" |
@@ -338,7 +338,9 @@ do_ls(int fd_in, int fd_out, char *path) | |||
338 | SSH2_FXP_NAME, type); | 338 | SSH2_FXP_NAME, type); |
339 | 339 | ||
340 | count = buffer_get_int(&msg); | 340 | count = buffer_get_int(&msg); |
341 | debug3("Received %i SSH2_FXP_NAME responses", count); | 341 | if (count == 0) |
342 | break; | ||
343 | debug3("Received %d SSH2_FXP_NAME responses", count); | ||
342 | for(i = 0; i < count; i++) { | 344 | for(i = 0; i < count; i++) { |
343 | char *filename, *longname; | 345 | char *filename, *longname; |
344 | Attrib *a; | 346 | Attrib *a; |
@@ -556,6 +558,7 @@ do_download(int fd_in, int fd_out, char *remote_path, char *local_path, | |||
556 | char *handle; | 558 | char *handle; |
557 | Buffer msg; | 559 | Buffer msg; |
558 | Attrib junk, *a; | 560 | Attrib junk, *a; |
561 | int status; | ||
559 | 562 | ||
560 | a = do_stat(fd_in, fd_out, remote_path); | 563 | a = do_stat(fd_in, fd_out, remote_path); |
561 | if (a == NULL) | 564 | if (a == NULL) |
@@ -635,7 +638,7 @@ do_download(int fd_in, int fd_out, char *remote_path, char *local_path, | |||
635 | if (id != expected_id) | 638 | if (id != expected_id) |
636 | fatal("ID mismatch (%d != %d)", id, expected_id); | 639 | fatal("ID mismatch (%d != %d)", id, expected_id); |
637 | if (type == SSH2_FXP_STATUS) { | 640 | if (type == SSH2_FXP_STATUS) { |
638 | int status = buffer_get_int(&msg); | 641 | status = buffer_get_int(&msg); |
639 | 642 | ||
640 | if (status == SSH2_FX_EOF) | 643 | if (status == SSH2_FX_EOF) |
641 | break; | 644 | break; |
@@ -644,10 +647,7 @@ do_download(int fd_in, int fd_out, char *remote_path, char *local_path, | |||
644 | "file \"%s\" : %s", remote_path, | 647 | "file \"%s\" : %s", remote_path, |
645 | fx2txt(status)); | 648 | fx2txt(status)); |
646 | do_close(fd_in, fd_out, handle, handle_len); | 649 | do_close(fd_in, fd_out, handle, handle_len); |
647 | xfree(handle); | 650 | goto done; |
648 | close(local_fd); | ||
649 | buffer_free(&msg); | ||
650 | return(status); | ||
651 | } | 651 | } |
652 | } else if (type != SSH2_FXP_DATA) { | 652 | } else if (type != SSH2_FXP_DATA) { |
653 | fatal("Expected SSH2_FXP_DATA(%d) packet, got %d", | 653 | 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, | |||
659 | fatal("Received more data than asked for %d > %d", | 659 | fatal("Received more data than asked for %d > %d", |
660 | len, COPY_SIZE); | 660 | len, COPY_SIZE); |
661 | 661 | ||
662 | debug3("In read loop, got %d offset %lld", len, | 662 | debug3("In read loop, got %d offset %llu", len, |
663 | (unsigned long long)offset); | 663 | (unsigned long long)offset); |
664 | if (atomicio(write, local_fd, data, len) != len) { | 664 | if (atomicio(write, local_fd, data, len) != len) { |
665 | error("Couldn't write to \"%s\": %s", local_path, | 665 | error("Couldn't write to \"%s\": %s", local_path, |
666 | strerror(errno)); | 666 | strerror(errno)); |
667 | do_close(fd_in, fd_out, handle, handle_len); | 667 | do_close(fd_in, fd_out, handle, handle_len); |
668 | xfree(handle); | 668 | status = -1; |
669 | close(local_fd); | ||
670 | xfree(data); | 669 | xfree(data); |
671 | buffer_free(&msg); | 670 | goto done; |
672 | return(-1); | ||
673 | } | 671 | } |
674 | 672 | ||
675 | offset += len; | 673 | offset += len; |
676 | xfree(data); | 674 | xfree(data); |
677 | } | 675 | } |
678 | xfree(handle); | 676 | status = do_close(fd_in, fd_out, handle, handle_len); |
679 | buffer_free(&msg); | ||
680 | close(local_fd); | ||
681 | 677 | ||
682 | return(do_close(fd_in, fd_out, handle, handle_len)); | 678 | done: |
679 | close(local_fd); | ||
680 | buffer_free(&msg); | ||
681 | xfree(handle); | ||
682 | return status; | ||
683 | } | 683 | } |
684 | 684 | ||
685 | int | 685 | int |
@@ -693,6 +693,7 @@ do_upload(int fd_in, int fd_out, char *local_path, char *remote_path, | |||
693 | Buffer msg; | 693 | Buffer msg; |
694 | struct stat sb; | 694 | struct stat sb; |
695 | Attrib a; | 695 | Attrib a; |
696 | int status; | ||
696 | 697 | ||
697 | if ((local_fd = open(local_path, O_RDONLY, 0)) == -1) { | 698 | if ((local_fd = open(local_path, O_RDONLY, 0)) == -1) { |
698 | error("Couldn't open local file \"%s\" for reading: %s", | 699 | 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, | |||
743 | for(;;) { | 744 | for(;;) { |
744 | int len; | 745 | int len; |
745 | char data[COPY_SIZE]; | 746 | char data[COPY_SIZE]; |
746 | u_int status; | ||
747 | 747 | ||
748 | /* | 748 | /* |
749 | * Can't use atomicio here because it returns 0 on EOF, thus losing | 749 | * 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, | |||
774 | error("Couldn't write to remote file \"%s\": %s", | 774 | error("Couldn't write to remote file \"%s\": %s", |
775 | remote_path, fx2txt(status)); | 775 | remote_path, fx2txt(status)); |
776 | do_close(fd_in, fd_out, handle, handle_len); | 776 | do_close(fd_in, fd_out, handle, handle_len); |
777 | xfree(handle); | ||
778 | close(local_fd); | 777 | close(local_fd); |
779 | return(-1); | 778 | goto done; |
780 | } | 779 | } |
781 | debug3("In write loop, got %d offset %llu", len, | 780 | debug3("In write loop, got %d offset %llu", len, |
782 | (unsigned long long)offset); | 781 | (unsigned long long)offset); |
783 | 782 | ||
784 | offset += len; | 783 | offset += len; |
785 | } | 784 | } |
786 | xfree(handle); | ||
787 | buffer_free(&msg); | ||
788 | 785 | ||
789 | if (close(local_fd) == -1) { | 786 | if (close(local_fd) == -1) { |
790 | error("Couldn't close local file \"%s\": %s", local_path, | 787 | error("Couldn't close local file \"%s\": %s", local_path, |
791 | strerror(errno)); | 788 | strerror(errno)); |
792 | do_close(fd_in, fd_out, handle, handle_len); | 789 | do_close(fd_in, fd_out, handle, handle_len); |
793 | return(-1); | 790 | status = -1; |
791 | goto done; | ||
794 | } | 792 | } |
795 | 793 | ||
796 | return(do_close(fd_in, fd_out, handle, handle_len)); | 794 | status = do_close(fd_in, fd_out, handle, handle_len); |
795 | |||
796 | done: | ||
797 | xfree(handle); | ||
798 | buffer_free(&msg); | ||
799 | return status; | ||
797 | } | 800 | } |
801 | |||
802 | |||