summaryrefslogtreecommitdiff
path: root/sftp-client.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2005-05-26 12:23:44 +1000
committerDamien Miller <djm@mindrot.org>2005-05-26 12:23:44 +1000
commitb253cc42136649e3eac80e02667f8fbc1e43baaa (patch)
treee3824a905c7b12e4901e60e87ecdc968228e645e /sftp-client.c
parent02e754f1f01470c11a175a0d07381361afe37fff (diff)
- avsm@cvs.openbsd.org 2005/05/24 17:32:44
[atomicio.c atomicio.h authfd.c monitor_wrap.c msg.c scp.c sftp-client.c] [ssh-keyscan.c sshconnect.c] Switch atomicio to use a simpler interface; it now returns a size_t (containing number of bytes read/written), and indicates error by returning 0. EOF is signalled by errno==EPIPE. Typical use now becomes: if (atomicio(read, ..., len) != len) err(1,"read"); ok deraadt@, cloder@, djm@
Diffstat (limited to 'sftp-client.c')
-rw-r--r--sftp-client.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/sftp-client.c b/sftp-client.c
index 92df42751..47297898a 100644
--- a/sftp-client.c
+++ b/sftp-client.c
@@ -20,7 +20,7 @@
20/* XXX: copy between two remote sites */ 20/* XXX: copy between two remote sites */
21 21
22#include "includes.h" 22#include "includes.h"
23RCSID("$OpenBSD: sftp-client.c,v 1.53 2005/03/10 22:01:05 deraadt Exp $"); 23RCSID("$OpenBSD: sftp-client.c,v 1.54 2005/05/24 17:32:44 avsm Exp $");
24 24
25#include "openbsd-compat/sys-queue.h" 25#include "openbsd-compat/sys-queue.h"
26 26
@@ -64,10 +64,10 @@ send_msg(int fd, Buffer *m)
64 64
65 /* Send length first */ 65 /* Send length first */
66 PUT_32BIT(mlen, buffer_len(m)); 66 PUT_32BIT(mlen, buffer_len(m));
67 if (atomicio(vwrite, fd, mlen, sizeof(mlen)) <= 0) 67 if (atomicio(vwrite, fd, mlen, sizeof(mlen)) != sizeof(mlen))
68 fatal("Couldn't send packet: %s", strerror(errno)); 68 fatal("Couldn't send packet: %s", strerror(errno));
69 69
70 if (atomicio(vwrite, fd, buffer_ptr(m), buffer_len(m)) <= 0) 70 if (atomicio(vwrite, fd, buffer_ptr(m), buffer_len(m)) != buffer_len(m))
71 fatal("Couldn't send packet: %s", strerror(errno)); 71 fatal("Couldn't send packet: %s", strerror(errno));
72 72
73 buffer_clear(m); 73 buffer_clear(m);
@@ -76,26 +76,27 @@ send_msg(int fd, Buffer *m)
76static void 76static void
77get_msg(int fd, Buffer *m) 77get_msg(int fd, Buffer *m)
78{ 78{
79 ssize_t len;
80 u_int msg_len; 79 u_int msg_len;
81 80
82 buffer_append_space(m, 4); 81 buffer_append_space(m, 4);
83 len = atomicio(read, fd, buffer_ptr(m), 4); 82 if (atomicio(read, fd, buffer_ptr(m), 4) != 4) {
84 if (len == 0) 83 if (errno == EPIPE)
85 fatal("Connection closed"); 84 fatal("Connection closed");
86 else if (len == -1) 85 else
87 fatal("Couldn't read packet: %s", strerror(errno)); 86 fatal("Couldn't read packet: %s", strerror(errno));
87 }
88 88
89 msg_len = buffer_get_int(m); 89 msg_len = buffer_get_int(m);
90 if (msg_len > MAX_MSG_LENGTH) 90 if (msg_len > MAX_MSG_LENGTH)
91 fatal("Received message too long %u", msg_len); 91 fatal("Received message too long %u", msg_len);
92 92
93 buffer_append_space(m, msg_len); 93 buffer_append_space(m, msg_len);
94 len = atomicio(read, fd, buffer_ptr(m), msg_len); 94 if (atomicio(read, fd, buffer_ptr(m), msg_len) != msg_len) {
95 if (len == 0) 95 if (errno == EPIPE)
96 fatal("Connection closed"); 96 fatal("Connection closed");
97 else if (len == -1) 97 else
98 fatal("Read packet: %s", strerror(errno)); 98 fatal("Read packet: %s", strerror(errno));
99 }
99} 100}
100 101
101static void 102static void