summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Lindstrom <mouring@eviladmin.org>2002-06-23 21:27:18 +0000
committerBen Lindstrom <mouring@eviladmin.org>2002-06-23 21:27:18 +0000
commitb1f483f472da5fd2dbcb009d9988088f43c21579 (patch)
tree2d3f0c9906f6bb38e2d8f1e2a8f673191fdd3769
parent5c3855210ef20be5931d4b58f641d71bc3b203e8 (diff)
- deraadt@cvs.openbsd.org 2002/06/23 09:30:14
[sftp-client.c sftp-client.h sftp-common.c sftp-int.c sftp-server.c sftp.c] bunch of u_int vs int stuff
-rw-r--r--ChangeLog6
-rw-r--r--sftp-client.c65
-rw-r--r--sftp-client.h8
-rw-r--r--sftp-common.c4
-rw-r--r--sftp-int.c4
-rw-r--r--sftp-server.c54
-rw-r--r--sftp.c5
7 files changed, 77 insertions, 69 deletions
diff --git a/ChangeLog b/ChangeLog
index e39eeba6e..df78f3fe4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,6 +10,10 @@
10 [scard.c ssh-dss.c ssh-rsa.c sshconnect.c sshconnect2.c sshd.c sshlogin.c 10 [scard.c ssh-dss.c ssh-rsa.c sshconnect.c sshconnect2.c sshd.c sshlogin.c
11 sshpty.c] 11 sshpty.c]
12 various KNF and %d for unsigned 12 various KNF and %d for unsigned
13 - deraadt@cvs.openbsd.org 2002/06/23 09:30:14
14 [sftp-client.c sftp-client.h sftp-common.c sftp-int.c sftp-server.c
15 sftp.c]
16 bunch of u_int vs int stuff
13 17
1420020623 1820020623
15 - (stevesk) [configure.ac] bug #255 LOGIN_NEEDS_UTMPX for AIX. 19 - (stevesk) [configure.ac] bug #255 LOGIN_NEEDS_UTMPX for AIX.
@@ -1054,4 +1058,4 @@
1054 - (stevesk) entropy.c: typo in debug message 1058 - (stevesk) entropy.c: typo in debug message
1055 - (djm) ssh-keygen -i needs seeded RNG; report from markus@ 1059 - (djm) ssh-keygen -i needs seeded RNG; report from markus@
1056 1060
1057$Id: ChangeLog,v 1.2256 2002/06/23 21:23:20 mouring Exp $ 1061$Id: ChangeLog,v 1.2257 2002/06/23 21:27:18 mouring Exp $
diff --git a/sftp-client.c b/sftp-client.c
index 779ef2fe8..10b7992d0 100644
--- a/sftp-client.c
+++ b/sftp-client.c
@@ -28,7 +28,7 @@
28/* XXX: copy between two remote sites */ 28/* XXX: copy between two remote sites */
29 29
30#include "includes.h" 30#include "includes.h"
31RCSID("$OpenBSD: sftp-client.c,v 1.32 2002/06/09 13:32:01 markus Exp $"); 31RCSID("$OpenBSD: sftp-client.c,v 1.33 2002/06/23 09:30:14 deraadt Exp $");
32 32
33#include "openbsd-compat/fake-queue.h" 33#include "openbsd-compat/fake-queue.h"
34 34
@@ -88,7 +88,7 @@ get_msg(int fd, Buffer *m)
88 88
89 msg_len = GET_32BIT(buf); 89 msg_len = GET_32BIT(buf);
90 if (msg_len > 256 * 1024) 90 if (msg_len > 256 * 1024)
91 fatal("Received message too long %d", msg_len); 91 fatal("Received message too long %u", msg_len);
92 92
93 while (msg_len) { 93 while (msg_len) {
94 len = atomicio(read, fd, buf, MIN(msg_len, sizeof(buf))); 94 len = atomicio(read, fd, buf, MIN(msg_len, sizeof(buf)));
@@ -113,7 +113,7 @@ send_string_request(int fd, u_int id, u_int code, char *s,
113 buffer_put_int(&msg, id); 113 buffer_put_int(&msg, id);
114 buffer_put_string(&msg, s, len); 114 buffer_put_string(&msg, s, len);
115 send_msg(fd, &msg); 115 send_msg(fd, &msg);
116 debug3("Sent message fd %d T:%d I:%d", fd, code, id); 116 debug3("Sent message fd %d T:%u I:%u", fd, code, id);
117 buffer_free(&msg); 117 buffer_free(&msg);
118} 118}
119 119
@@ -129,12 +129,12 @@ send_string_attrs_request(int fd, u_int id, u_int code, char *s,
129 buffer_put_string(&msg, s, len); 129 buffer_put_string(&msg, s, len);
130 encode_attrib(&msg, a); 130 encode_attrib(&msg, a);
131 send_msg(fd, &msg); 131 send_msg(fd, &msg);
132 debug3("Sent message fd %d T:%d I:%d", fd, code, id); 132 debug3("Sent message fd %d T:%u I:%u", fd, code, id);
133 buffer_free(&msg); 133 buffer_free(&msg);
134} 134}
135 135
136static u_int 136static u_int
137get_status(int fd, int expected_id) 137get_status(int fd, u_int expected_id)
138{ 138{
139 Buffer msg; 139 Buffer msg;
140 u_int type, id, status; 140 u_int type, id, status;
@@ -145,15 +145,15 @@ get_status(int fd, int expected_id)
145 id = buffer_get_int(&msg); 145 id = buffer_get_int(&msg);
146 146
147 if (id != expected_id) 147 if (id != expected_id)
148 fatal("ID mismatch (%d != %d)", id, expected_id); 148 fatal("ID mismatch (%u != %u)", id, expected_id);
149 if (type != SSH2_FXP_STATUS) 149 if (type != SSH2_FXP_STATUS)
150 fatal("Expected SSH2_FXP_STATUS(%d) packet, got %d", 150 fatal("Expected SSH2_FXP_STATUS(%u) packet, got %u",
151 SSH2_FXP_STATUS, type); 151 SSH2_FXP_STATUS, type);
152 152
153 status = buffer_get_int(&msg); 153 status = buffer_get_int(&msg);
154 buffer_free(&msg); 154 buffer_free(&msg);
155 155
156 debug3("SSH2_FXP_STATUS %d", status); 156 debug3("SSH2_FXP_STATUS %u", status);
157 157
158 return(status); 158 return(status);
159} 159}
@@ -171,14 +171,14 @@ get_handle(int fd, u_int expected_id, u_int *len)
171 id = buffer_get_int(&msg); 171 id = buffer_get_int(&msg);
172 172
173 if (id != expected_id) 173 if (id != expected_id)
174 fatal("ID mismatch (%d != %d)", id, expected_id); 174 fatal("ID mismatch (%u != %u)", id, expected_id);
175 if (type == SSH2_FXP_STATUS) { 175 if (type == SSH2_FXP_STATUS) {
176 int status = buffer_get_int(&msg); 176 int status = buffer_get_int(&msg);
177 177
178 error("Couldn't get handle: %s", fx2txt(status)); 178 error("Couldn't get handle: %s", fx2txt(status));
179 return(NULL); 179 return(NULL);
180 } else if (type != SSH2_FXP_HANDLE) 180 } else if (type != SSH2_FXP_HANDLE)
181 fatal("Expected SSH2_FXP_HANDLE(%d) packet, got %d", 181 fatal("Expected SSH2_FXP_HANDLE(%u) packet, got %u",
182 SSH2_FXP_HANDLE, type); 182 SSH2_FXP_HANDLE, type);
183 183
184 handle = buffer_get_string(&msg, len); 184 handle = buffer_get_string(&msg, len);
@@ -200,9 +200,9 @@ get_decode_stat(int fd, u_int expected_id, int quiet)
200 type = buffer_get_char(&msg); 200 type = buffer_get_char(&msg);
201 id = buffer_get_int(&msg); 201 id = buffer_get_int(&msg);
202 202
203 debug3("Received stat reply T:%d I:%d", type, id); 203 debug3("Received stat reply T:%u I:%u", type, id);
204 if (id != expected_id) 204 if (id != expected_id)
205 fatal("ID mismatch (%d != %d)", id, expected_id); 205 fatal("ID mismatch (%u != %u)", id, expected_id);
206 if (type == SSH2_FXP_STATUS) { 206 if (type == SSH2_FXP_STATUS) {
207 int status = buffer_get_int(&msg); 207 int status = buffer_get_int(&msg);
208 208
@@ -212,7 +212,7 @@ get_decode_stat(int fd, u_int expected_id, int quiet)
212 error("Couldn't stat remote file: %s", fx2txt(status)); 212 error("Couldn't stat remote file: %s", fx2txt(status));
213 return(NULL); 213 return(NULL);
214 } else if (type != SSH2_FXP_ATTRS) { 214 } else if (type != SSH2_FXP_ATTRS) {
215 fatal("Expected SSH2_FXP_ATTRS(%d) packet, got %d", 215 fatal("Expected SSH2_FXP_ATTRS(%u) packet, got %u",
216 SSH2_FXP_ATTRS, type); 216 SSH2_FXP_ATTRS, type);
217 } 217 }
218 a = decode_attrib(&msg); 218 a = decode_attrib(&msg);
@@ -224,7 +224,8 @@ get_decode_stat(int fd, u_int expected_id, int quiet)
224struct sftp_conn * 224struct sftp_conn *
225do_init(int fd_in, int fd_out, u_int transfer_buflen, u_int num_requests) 225do_init(int fd_in, int fd_out, u_int transfer_buflen, u_int num_requests)
226{ 226{
227 int type, version; 227 u_int type;
228 int version;
228 Buffer msg; 229 Buffer msg;
229 struct sftp_conn *ret; 230 struct sftp_conn *ret;
230 231
@@ -239,7 +240,7 @@ do_init(int fd_in, int fd_out, u_int transfer_buflen, u_int num_requests)
239 240
240 /* Expecting a VERSION reply */ 241 /* Expecting a VERSION reply */
241 if ((type = buffer_get_char(&msg)) != SSH2_FXP_VERSION) { 242 if ((type = buffer_get_char(&msg)) != SSH2_FXP_VERSION) {
242 error("Invalid packet back from SSH2_FXP_INIT (type %d)", 243 error("Invalid packet back from SSH2_FXP_INIT (type %u)",
243 type); 244 type);
244 buffer_free(&msg); 245 buffer_free(&msg);
245 return(NULL); 246 return(NULL);
@@ -294,7 +295,7 @@ do_close(struct sftp_conn *conn, char *handle, u_int handle_len)
294 buffer_put_int(&msg, id); 295 buffer_put_int(&msg, id);
295 buffer_put_string(&msg, handle, handle_len); 296 buffer_put_string(&msg, handle, handle_len);
296 send_msg(conn->fd_out, &msg); 297 send_msg(conn->fd_out, &msg);
297 debug3("Sent message SSH2_FXP_CLOSE I:%d", id); 298 debug3("Sent message SSH2_FXP_CLOSE I:%u", id);
298 299
299 status = get_status(conn->fd_in, id); 300 status = get_status(conn->fd_in, id);
300 if (status != SSH2_FX_OK) 301 if (status != SSH2_FX_OK)
@@ -339,7 +340,7 @@ do_lsreaddir(struct sftp_conn *conn, char *path, int printflag,
339 340
340 id = expected_id = conn->msg_id++; 341 id = expected_id = conn->msg_id++;
341 342
342 debug3("Sending SSH2_FXP_READDIR I:%d", id); 343 debug3("Sending SSH2_FXP_READDIR I:%u", id);
343 344
344 buffer_clear(&msg); 345 buffer_clear(&msg);
345 buffer_put_char(&msg, SSH2_FXP_READDIR); 346 buffer_put_char(&msg, SSH2_FXP_READDIR);
@@ -354,10 +355,10 @@ do_lsreaddir(struct sftp_conn *conn, char *path, int printflag,
354 type = buffer_get_char(&msg); 355 type = buffer_get_char(&msg);
355 id = buffer_get_int(&msg); 356 id = buffer_get_int(&msg);
356 357
357 debug3("Received reply T:%d I:%d", type, id); 358 debug3("Received reply T:%u I:%u", type, id);
358 359
359 if (id != expected_id) 360 if (id != expected_id)
360 fatal("ID mismatch (%d != %d)", id, expected_id); 361 fatal("ID mismatch (%u != %u)", id, expected_id);
361 362
362 if (type == SSH2_FXP_STATUS) { 363 if (type == SSH2_FXP_STATUS) {
363 int status = buffer_get_int(&msg); 364 int status = buffer_get_int(&msg);
@@ -373,7 +374,7 @@ do_lsreaddir(struct sftp_conn *conn, char *path, int printflag,
373 return(status); 374 return(status);
374 } 375 }
375 } else if (type != SSH2_FXP_NAME) 376 } else if (type != SSH2_FXP_NAME)
376 fatal("Expected SSH2_FXP_NAME(%d) packet, got %d", 377 fatal("Expected SSH2_FXP_NAME(%u) packet, got %u",
377 SSH2_FXP_NAME, type); 378 SSH2_FXP_NAME, type);
378 379
379 count = buffer_get_int(&msg); 380 count = buffer_get_int(&msg);
@@ -584,7 +585,7 @@ do_realpath(struct sftp_conn *conn, char *path)
584 id = buffer_get_int(&msg); 585 id = buffer_get_int(&msg);
585 586
586 if (id != expected_id) 587 if (id != expected_id)
587 fatal("ID mismatch (%d != %d)", id, expected_id); 588 fatal("ID mismatch (%u != %u)", id, expected_id);
588 589
589 if (type == SSH2_FXP_STATUS) { 590 if (type == SSH2_FXP_STATUS) {
590 u_int status = buffer_get_int(&msg); 591 u_int status = buffer_get_int(&msg);
@@ -592,7 +593,7 @@ do_realpath(struct sftp_conn *conn, char *path)
592 error("Couldn't canonicalise: %s", fx2txt(status)); 593 error("Couldn't canonicalise: %s", fx2txt(status));
593 return(NULL); 594 return(NULL);
594 } else if (type != SSH2_FXP_NAME) 595 } else if (type != SSH2_FXP_NAME)
595 fatal("Expected SSH2_FXP_NAME(%d) packet, got %d", 596 fatal("Expected SSH2_FXP_NAME(%u) packet, got %u",
596 SSH2_FXP_NAME, type); 597 SSH2_FXP_NAME, type);
597 598
598 count = buffer_get_int(&msg); 599 count = buffer_get_int(&msg);
@@ -690,7 +691,7 @@ do_readlink(struct sftp_conn *conn, char *path)
690 id = buffer_get_int(&msg); 691 id = buffer_get_int(&msg);
691 692
692 if (id != expected_id) 693 if (id != expected_id)
693 fatal("ID mismatch (%d != %d)", id, expected_id); 694 fatal("ID mismatch (%u != %u)", id, expected_id);
694 695
695 if (type == SSH2_FXP_STATUS) { 696 if (type == SSH2_FXP_STATUS) {
696 u_int status = buffer_get_int(&msg); 697 u_int status = buffer_get_int(&msg);
@@ -698,7 +699,7 @@ do_readlink(struct sftp_conn *conn, char *path)
698 error("Couldn't readlink: %s", fx2txt(status)); 699 error("Couldn't readlink: %s", fx2txt(status));
699 return(NULL); 700 return(NULL);
700 } else if (type != SSH2_FXP_NAME) 701 } else if (type != SSH2_FXP_NAME)
701 fatal("Expected SSH2_FXP_NAME(%d) packet, got %d", 702 fatal("Expected SSH2_FXP_NAME(%u) packet, got %u",
702 SSH2_FXP_NAME, type); 703 SSH2_FXP_NAME, type);
703 704
704 count = buffer_get_int(&msg); 705 count = buffer_get_int(&msg);
@@ -790,7 +791,7 @@ do_download(struct sftp_conn *conn, char *remote_path, char *local_path,
790 attrib_clear(&junk); /* Send empty attributes */ 791 attrib_clear(&junk); /* Send empty attributes */
791 encode_attrib(&msg, &junk); 792 encode_attrib(&msg, &junk);
792 send_msg(conn->fd_out, &msg); 793 send_msg(conn->fd_out, &msg);
793 debug3("Sent message SSH2_FXP_OPEN I:%d P:%s", id, remote_path); 794 debug3("Sent message SSH2_FXP_OPEN I:%u P:%s", id, remote_path);
794 795
795 handle = get_handle(conn->fd_in, id, &handle_len); 796 handle = get_handle(conn->fd_in, id, &handle_len);
796 if (handle == NULL) { 797 if (handle == NULL) {
@@ -835,7 +836,7 @@ do_download(struct sftp_conn *conn, char *remote_path, char *local_path,
835 get_msg(conn->fd_in, &msg); 836 get_msg(conn->fd_in, &msg);
836 type = buffer_get_char(&msg); 837 type = buffer_get_char(&msg);
837 id = buffer_get_int(&msg); 838 id = buffer_get_int(&msg);
838 debug3("Received reply T:%d I:%d R:%d", type, id, max_req); 839 debug3("Received reply T:%u I:%u R:%d", type, id, max_req);
839 840
840 /* Find the request in our queue */ 841 /* Find the request in our queue */
841 for(req = TAILQ_FIRST(&requests); 842 for(req = TAILQ_FIRST(&requests);
@@ -862,7 +863,7 @@ do_download(struct sftp_conn *conn, char *remote_path, char *local_path,
862 (unsigned long long)req->offset + len - 1); 863 (unsigned long long)req->offset + len - 1);
863 if (len > req->len) 864 if (len > req->len)
864 fatal("Received more data than asked for " 865 fatal("Received more data than asked for "
865 "%d > %d", len, req->len); 866 "%u > %u", len, req->len);
866 if ((lseek(local_fd, req->offset, SEEK_SET) == -1 || 867 if ((lseek(local_fd, req->offset, SEEK_SET) == -1 ||
867 atomicio(write, local_fd, data, len) != len) && 868 atomicio(write, local_fd, data, len) != len) &&
868 !write_error) { 869 !write_error) {
@@ -907,7 +908,7 @@ do_download(struct sftp_conn *conn, char *remote_path, char *local_path,
907 } 908 }
908 break; 909 break;
909 default: 910 default:
910 fatal("Expected SSH2_FXP_DATA(%d) packet, got %d", 911 fatal("Expected SSH2_FXP_DATA(%u) packet, got %u",
911 SSH2_FXP_DATA, type); 912 SSH2_FXP_DATA, type);
912 } 913 }
913 } 914 }
@@ -1006,7 +1007,7 @@ do_upload(struct sftp_conn *conn, char *local_path, char *remote_path,
1006 buffer_put_int(&msg, SSH2_FXF_WRITE|SSH2_FXF_CREAT|SSH2_FXF_TRUNC); 1007 buffer_put_int(&msg, SSH2_FXF_WRITE|SSH2_FXF_CREAT|SSH2_FXF_TRUNC);
1007 encode_attrib(&msg, &a); 1008 encode_attrib(&msg, &a);
1008 send_msg(conn->fd_out, &msg); 1009 send_msg(conn->fd_out, &msg);
1009 debug3("Sent message SSH2_FXP_OPEN I:%d P:%s", id, remote_path); 1010 debug3("Sent message SSH2_FXP_OPEN I:%u P:%s", id, remote_path);
1010 1011
1011 buffer_clear(&msg); 1012 buffer_clear(&msg);
1012 1013
@@ -1051,7 +1052,7 @@ do_upload(struct sftp_conn *conn, char *local_path, char *remote_path,
1051 buffer_put_int64(&msg, offset); 1052 buffer_put_int64(&msg, offset);
1052 buffer_put_string(&msg, data, len); 1053 buffer_put_string(&msg, data, len);
1053 send_msg(conn->fd_out, &msg); 1054 send_msg(conn->fd_out, &msg);
1054 debug3("Sent message SSH2_FXP_WRITE I:%d O:%llu S:%u", 1055 debug3("Sent message SSH2_FXP_WRITE I:%u O:%llu S:%u",
1055 id, (unsigned long long)offset, len); 1056 id, (unsigned long long)offset, len);
1056 } else if (TAILQ_FIRST(&acks) == NULL) 1057 } else if (TAILQ_FIRST(&acks) == NULL)
1057 break; 1058 break;
@@ -1081,7 +1082,7 @@ do_upload(struct sftp_conn *conn, char *local_path, char *remote_path,
1081 ack = TAILQ_NEXT(ack, tq)) 1082 ack = TAILQ_NEXT(ack, tq))
1082 ; 1083 ;
1083 if (ack == NULL) 1084 if (ack == NULL)
1084 fatal("Can't find request for ID %d", r_id); 1085 fatal("Can't find request for ID %u", r_id);
1085 TAILQ_REMOVE(&acks, ack, tq); 1086 TAILQ_REMOVE(&acks, ack, tq);
1086 1087
1087 if (status != SSH2_FX_OK) { 1088 if (status != SSH2_FX_OK) {
@@ -1091,7 +1092,7 @@ do_upload(struct sftp_conn *conn, char *local_path, char *remote_path,
1091 close(local_fd); 1092 close(local_fd);
1092 goto done; 1093 goto done;
1093 } 1094 }
1094 debug3("In write loop, ack for %u %d bytes at %llu", 1095 debug3("In write loop, ack for %u %u bytes at %llu",
1095 ack->id, ack->len, (unsigned long long)ack->offset); 1096 ack->id, ack->len, (unsigned long long)ack->offset);
1096 ++ackid; 1097 ++ackid;
1097 free(ack); 1098 free(ack);
diff --git a/sftp-client.h b/sftp-client.h
index ceda879b9..b06171168 100644
--- a/sftp-client.h
+++ b/sftp-client.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: sftp-client.h,v 1.9 2002/02/13 00:59:23 djm Exp $ */ 1/* $OpenBSD: sftp-client.h,v 1.10 2002/06/23 09:30:14 deraadt Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2001,2002 Damien Miller. All rights reserved. 4 * Copyright (c) 2001,2002 Damien Miller. All rights reserved.
@@ -41,11 +41,9 @@ struct SFTP_DIRENT {
41 * Initialiase a SSH filexfer connection. Returns -1 on error or 41 * Initialiase a SSH filexfer connection. Returns -1 on error or
42 * protocol version on success. 42 * protocol version on success.
43 */ 43 */
44struct sftp_conn * 44struct sftp_conn *do_init(int, int, u_int, u_int);
45do_init(int, int, u_int, u_int);
46 45
47u_int 46u_int sftp_proto_version(struct sftp_conn *);
48sftp_proto_version(struct sftp_conn *);
49 47
50/* Close file referred to by 'handle' */ 48/* Close file referred to by 'handle' */
51int do_close(struct sftp_conn *, char *, u_int); 49int do_close(struct sftp_conn *, char *, u_int);
diff --git a/sftp-common.c b/sftp-common.c
index 4fb449655..6bed0ab8a 100644
--- a/sftp-common.c
+++ b/sftp-common.c
@@ -24,7 +24,7 @@
24 */ 24 */
25 25
26#include "includes.h" 26#include "includes.h"
27RCSID("$OpenBSD: sftp-common.c,v 1.5 2001/12/02 02:08:32 deraadt Exp $"); 27RCSID("$OpenBSD: sftp-common.c,v 1.6 2002/06/23 09:30:14 deraadt Exp $");
28 28
29#include "buffer.h" 29#include "buffer.h"
30#include "bufaux.h" 30#include "bufaux.h"
@@ -70,6 +70,7 @@ Attrib *
70decode_attrib(Buffer *b) 70decode_attrib(Buffer *b)
71{ 71{
72 static Attrib a; 72 static Attrib a;
73
73 attrib_clear(&a); 74 attrib_clear(&a);
74 a.flags = buffer_get_int(b); 75 a.flags = buffer_get_int(b);
75 if (a.flags & SSH2_FILEXFER_ATTR_SIZE) 76 if (a.flags & SSH2_FILEXFER_ATTR_SIZE)
@@ -88,6 +89,7 @@ decode_attrib(Buffer *b)
88 if (a.flags & SSH2_FILEXFER_ATTR_EXTENDED) { 89 if (a.flags & SSH2_FILEXFER_ATTR_EXTENDED) {
89 char *type, *data; 90 char *type, *data;
90 int i, count; 91 int i, count;
92
91 count = buffer_get_int(b); 93 count = buffer_get_int(b);
92 for (i = 0; i < count; i++) { 94 for (i = 0; i < count; i++) {
93 type = buffer_get_string(b, NULL); 95 type = buffer_get_string(b, NULL);
diff --git a/sftp-int.c b/sftp-int.c
index 5b1d3848e..b13e5da5d 100644
--- a/sftp-int.c
+++ b/sftp-int.c
@@ -26,7 +26,7 @@
26/* XXX: recursive operations */ 26/* XXX: recursive operations */
27 27
28#include "includes.h" 28#include "includes.h"
29RCSID("$OpenBSD: sftp-int.c,v 1.46 2002/03/30 18:51:15 markus Exp $"); 29RCSID("$OpenBSD: sftp-int.c,v 1.47 2002/06/23 09:30:14 deraadt Exp $");
30 30
31#include "buffer.h" 31#include "buffer.h"
32#include "xmalloc.h" 32#include "xmalloc.h"
@@ -835,7 +835,7 @@ parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd)
835 help(); 835 help();
836 break; 836 break;
837 case I_VERSION: 837 case I_VERSION:
838 printf("SFTP protocol version %d\n", sftp_proto_version(conn)); 838 printf("SFTP protocol version %u\n", sftp_proto_version(conn));
839 break; 839 break;
840 default: 840 default:
841 fatal("%d is not implemented", cmdnum); 841 fatal("%d is not implemented", cmdnum);
diff --git a/sftp-server.c b/sftp-server.c
index 9db28e7d3..c3eee3802 100644
--- a/sftp-server.c
+++ b/sftp-server.c
@@ -22,7 +22,7 @@
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */ 23 */
24#include "includes.h" 24#include "includes.h"
25RCSID("$OpenBSD: sftp-server.c,v 1.35 2002/06/06 17:30:11 markus Exp $"); 25RCSID("$OpenBSD: sftp-server.c,v 1.36 2002/06/23 09:30:14 deraadt Exp $");
26 26
27#include "buffer.h" 27#include "buffer.h"
28#include "bufaux.h" 28#include "bufaux.h"
@@ -282,7 +282,7 @@ send_status(u_int32_t id, u_int32_t error)
282 "Unknown error" /* Others */ 282 "Unknown error" /* Others */
283 }; 283 };
284 284
285 TRACE("sent status id %d error %d", id, error); 285 TRACE("sent status id %u error %u", id, error);
286 buffer_init(&msg); 286 buffer_init(&msg);
287 buffer_put_char(&msg, SSH2_FXP_STATUS); 287 buffer_put_char(&msg, SSH2_FXP_STATUS);
288 buffer_put_int(&msg, id); 288 buffer_put_int(&msg, id);
@@ -311,7 +311,7 @@ send_data_or_handle(char type, u_int32_t id, char *data, int dlen)
311static void 311static void
312send_data(u_int32_t id, char *data, int dlen) 312send_data(u_int32_t id, char *data, int dlen)
313{ 313{
314 TRACE("sent data id %d len %d", id, dlen); 314 TRACE("sent data id %u len %d", id, dlen);
315 send_data_or_handle(SSH2_FXP_DATA, id, data, dlen); 315 send_data_or_handle(SSH2_FXP_DATA, id, data, dlen);
316} 316}
317 317
@@ -322,7 +322,7 @@ send_handle(u_int32_t id, int handle)
322 int hlen; 322 int hlen;
323 323
324 handle_to_string(handle, &string, &hlen); 324 handle_to_string(handle, &string, &hlen);
325 TRACE("sent handle id %d handle %d", id, handle); 325 TRACE("sent handle id %u handle %d", id, handle);
326 send_data_or_handle(SSH2_FXP_HANDLE, id, string, hlen); 326 send_data_or_handle(SSH2_FXP_HANDLE, id, string, hlen);
327 xfree(string); 327 xfree(string);
328} 328}
@@ -337,7 +337,7 @@ send_names(u_int32_t id, int count, Stat *stats)
337 buffer_put_char(&msg, SSH2_FXP_NAME); 337 buffer_put_char(&msg, SSH2_FXP_NAME);
338 buffer_put_int(&msg, id); 338 buffer_put_int(&msg, id);
339 buffer_put_int(&msg, count); 339 buffer_put_int(&msg, count);
340 TRACE("sent names id %d count %d", id, count); 340 TRACE("sent names id %u count %d", id, count);
341 for (i = 0; i < count; i++) { 341 for (i = 0; i < count; i++) {
342 buffer_put_cstring(&msg, stats[i].name); 342 buffer_put_cstring(&msg, stats[i].name);
343 buffer_put_cstring(&msg, stats[i].long_name); 343 buffer_put_cstring(&msg, stats[i].long_name);
@@ -352,7 +352,7 @@ send_attrib(u_int32_t id, Attrib *a)
352{ 352{
353 Buffer msg; 353 Buffer msg;
354 354
355 TRACE("sent attrib id %d have 0x%x", id, a->flags); 355 TRACE("sent attrib id %u have 0x%x", id, a->flags);
356 buffer_init(&msg); 356 buffer_init(&msg);
357 buffer_put_char(&msg, SSH2_FXP_ATTRS); 357 buffer_put_char(&msg, SSH2_FXP_ATTRS);
358 buffer_put_int(&msg, id); 358 buffer_put_int(&msg, id);
@@ -391,7 +391,7 @@ process_open(void)
391 a = get_attrib(); 391 a = get_attrib();
392 flags = flags_from_portable(pflags); 392 flags = flags_from_portable(pflags);
393 mode = (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) ? a->perm : 0666; 393 mode = (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) ? a->perm : 0666;
394 TRACE("open id %d name %s flags %d mode 0%o", id, name, pflags, mode); 394 TRACE("open id %u name %s flags %d mode 0%o", id, name, pflags, mode);
395 fd = open(name, flags, mode); 395 fd = open(name, flags, mode);
396 if (fd < 0) { 396 if (fd < 0) {
397 status = errno_to_portable(errno); 397 status = errno_to_portable(errno);
@@ -417,7 +417,7 @@ process_close(void)
417 417
418 id = get_int(); 418 id = get_int();
419 handle = get_handle(); 419 handle = get_handle();
420 TRACE("close id %d handle %d", id, handle); 420 TRACE("close id %u handle %d", id, handle);
421 ret = handle_close(handle); 421 ret = handle_close(handle);
422 status = (ret == -1) ? errno_to_portable(errno) : SSH2_FX_OK; 422 status = (ret == -1) ? errno_to_portable(errno) : SSH2_FX_OK;
423 send_status(id, status); 423 send_status(id, status);
@@ -436,7 +436,7 @@ process_read(void)
436 off = get_int64(); 436 off = get_int64();
437 len = get_int(); 437 len = get_int();
438 438
439 TRACE("read id %d handle %d off %llu len %d", id, handle, 439 TRACE("read id %u handle %d off %llu len %d", id, handle,
440 (u_int64_t)off, len); 440 (u_int64_t)off, len);
441 if (len > sizeof buf) { 441 if (len > sizeof buf) {
442 len = sizeof buf; 442 len = sizeof buf;
@@ -477,7 +477,7 @@ process_write(void)
477 off = get_int64(); 477 off = get_int64();
478 data = get_string(&len); 478 data = get_string(&len);
479 479
480 TRACE("write id %d handle %d off %llu len %d", id, handle, 480 TRACE("write id %u handle %d off %llu len %d", id, handle,
481 (u_int64_t)off, len); 481 (u_int64_t)off, len);
482 fd = handle_to_fd(handle); 482 fd = handle_to_fd(handle);
483 if (fd >= 0) { 483 if (fd >= 0) {
@@ -512,7 +512,7 @@ process_do_stat(int do_lstat)
512 512
513 id = get_int(); 513 id = get_int();
514 name = get_string(NULL); 514 name = get_string(NULL);
515 TRACE("%sstat id %d name %s", do_lstat ? "l" : "", id, name); 515 TRACE("%sstat id %u name %s", do_lstat ? "l" : "", id, name);
516 ret = do_lstat ? lstat(name, &st) : stat(name, &st); 516 ret = do_lstat ? lstat(name, &st) : stat(name, &st);
517 if (ret < 0) { 517 if (ret < 0) {
518 status = errno_to_portable(errno); 518 status = errno_to_portable(errno);
@@ -548,7 +548,7 @@ process_fstat(void)
548 548
549 id = get_int(); 549 id = get_int();
550 handle = get_handle(); 550 handle = get_handle();
551 TRACE("fstat id %d handle %d", id, handle); 551 TRACE("fstat id %u handle %d", id, handle);
552 fd = handle_to_fd(handle); 552 fd = handle_to_fd(handle);
553 if (fd >= 0) { 553 if (fd >= 0) {
554 ret = fstat(fd, &st); 554 ret = fstat(fd, &st);
@@ -582,13 +582,12 @@ process_setstat(void)
582 Attrib *a; 582 Attrib *a;
583 u_int32_t id; 583 u_int32_t id;
584 char *name; 584 char *name;
585 int ret; 585 int status = SSH2_FX_OK, ret;
586 int status = SSH2_FX_OK;
587 586
588 id = get_int(); 587 id = get_int();
589 name = get_string(NULL); 588 name = get_string(NULL);
590 a = get_attrib(); 589 a = get_attrib();
591 TRACE("setstat id %d name %s", id, name); 590 TRACE("setstat id %u name %s", id, name);
592 if (a->flags & SSH2_FILEXFER_ATTR_SIZE) { 591 if (a->flags & SSH2_FILEXFER_ATTR_SIZE) {
593 ret = truncate(name, a->size); 592 ret = truncate(name, a->size);
594 if (ret == -1) 593 if (ret == -1)
@@ -625,7 +624,7 @@ process_fsetstat(void)
625 id = get_int(); 624 id = get_int();
626 handle = get_handle(); 625 handle = get_handle();
627 a = get_attrib(); 626 a = get_attrib();
628 TRACE("fsetstat id %d handle %d", id, handle); 627 TRACE("fsetstat id %u handle %d", id, handle);
629 fd = handle_to_fd(handle); 628 fd = handle_to_fd(handle);
630 name = handle_to_name(handle); 629 name = handle_to_name(handle);
631 if (fd < 0 || name == NULL) { 630 if (fd < 0 || name == NULL) {
@@ -677,7 +676,7 @@ process_opendir(void)
677 676
678 id = get_int(); 677 id = get_int();
679 path = get_string(NULL); 678 path = get_string(NULL);
680 TRACE("opendir id %d path %s", id, path); 679 TRACE("opendir id %u path %s", id, path);
681 dirp = opendir(path); 680 dirp = opendir(path);
682 if (dirp == NULL) { 681 if (dirp == NULL) {
683 status = errno_to_portable(errno); 682 status = errno_to_portable(errno);
@@ -713,13 +712,13 @@ ls_file(char *name, struct stat *st)
713 if ((pw = getpwuid(st->st_uid)) != NULL) { 712 if ((pw = getpwuid(st->st_uid)) != NULL) {
714 user = pw->pw_name; 713 user = pw->pw_name;
715 } else { 714 } else {
716 snprintf(ubuf, sizeof ubuf, "%d", st->st_uid); 715 snprintf(ubuf, sizeof ubuf, "%u", st->st_uid);
717 user = ubuf; 716 user = ubuf;
718 } 717 }
719 if ((gr = getgrgid(st->st_gid)) != NULL) { 718 if ((gr = getgrgid(st->st_gid)) != NULL) {
720 group = gr->gr_name; 719 group = gr->gr_name;
721 } else { 720 } else {
722 snprintf(gbuf, sizeof gbuf, "%d", st->st_gid); 721 snprintf(gbuf, sizeof gbuf, "%u", st->st_gid);
723 group = gbuf; 722 group = gbuf;
724 } 723 }
725 if (ltime != NULL) { 724 if (ltime != NULL) {
@@ -749,7 +748,7 @@ process_readdir(void)
749 748
750 id = get_int(); 749 id = get_int();
751 handle = get_handle(); 750 handle = get_handle();
752 TRACE("readdir id %d handle %d", id, handle); 751 TRACE("readdir id %u handle %d", id, handle);
753 dirp = handle_to_dir(handle); 752 dirp = handle_to_dir(handle);
754 path = handle_to_name(handle); 753 path = handle_to_name(handle);
755 if (dirp == NULL || path == NULL) { 754 if (dirp == NULL || path == NULL) {
@@ -759,6 +758,7 @@ process_readdir(void)
759 char pathname[1024]; 758 char pathname[1024];
760 Stat *stats; 759 Stat *stats;
761 int nstats = 10, count = 0, i; 760 int nstats = 10, count = 0, i;
761
762 stats = xmalloc(nstats * sizeof(Stat)); 762 stats = xmalloc(nstats * sizeof(Stat));
763 while ((dp = readdir(dirp)) != NULL) { 763 while ((dp = readdir(dirp)) != NULL) {
764 if (count >= nstats) { 764 if (count >= nstats) {
@@ -802,7 +802,7 @@ process_remove(void)
802 802
803 id = get_int(); 803 id = get_int();
804 name = get_string(NULL); 804 name = get_string(NULL);
805 TRACE("remove id %d name %s", id, name); 805 TRACE("remove id %u name %s", id, name);
806 ret = unlink(name); 806 ret = unlink(name);
807 status = (ret == -1) ? errno_to_portable(errno) : SSH2_FX_OK; 807 status = (ret == -1) ? errno_to_portable(errno) : SSH2_FX_OK;
808 send_status(id, status); 808 send_status(id, status);
@@ -822,7 +822,7 @@ process_mkdir(void)
822 a = get_attrib(); 822 a = get_attrib();
823 mode = (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) ? 823 mode = (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) ?
824 a->perm & 0777 : 0777; 824 a->perm & 0777 : 0777;
825 TRACE("mkdir id %d name %s mode 0%o", id, name, mode); 825 TRACE("mkdir id %u name %s mode 0%o", id, name, mode);
826 ret = mkdir(name, mode); 826 ret = mkdir(name, mode);
827 status = (ret == -1) ? errno_to_portable(errno) : SSH2_FX_OK; 827 status = (ret == -1) ? errno_to_portable(errno) : SSH2_FX_OK;
828 send_status(id, status); 828 send_status(id, status);
@@ -838,7 +838,7 @@ process_rmdir(void)
838 838
839 id = get_int(); 839 id = get_int();
840 name = get_string(NULL); 840 name = get_string(NULL);
841 TRACE("rmdir id %d name %s", id, name); 841 TRACE("rmdir id %u name %s", id, name);
842 ret = rmdir(name); 842 ret = rmdir(name);
843 status = (ret == -1) ? errno_to_portable(errno) : SSH2_FX_OK; 843 status = (ret == -1) ? errno_to_portable(errno) : SSH2_FX_OK;
844 send_status(id, status); 844 send_status(id, status);
@@ -858,7 +858,7 @@ process_realpath(void)
858 xfree(path); 858 xfree(path);
859 path = xstrdup("."); 859 path = xstrdup(".");
860 } 860 }
861 TRACE("realpath id %d path %s", id, path); 861 TRACE("realpath id %u path %s", id, path);
862 if (realpath(path, resolvedname) == NULL) { 862 if (realpath(path, resolvedname) == NULL) {
863 send_status(id, errno_to_portable(errno)); 863 send_status(id, errno_to_portable(errno));
864 } else { 864 } else {
@@ -881,7 +881,7 @@ process_rename(void)
881 id = get_int(); 881 id = get_int();
882 oldpath = get_string(NULL); 882 oldpath = get_string(NULL);
883 newpath = get_string(NULL); 883 newpath = get_string(NULL);
884 TRACE("rename id %d old %s new %s", id, oldpath, newpath); 884 TRACE("rename id %u old %s new %s", id, oldpath, newpath);
885 /* fail if 'newpath' exists */ 885 /* fail if 'newpath' exists */
886 if (stat(newpath, &st) == -1) { 886 if (stat(newpath, &st) == -1) {
887 ret = rename(oldpath, newpath); 887 ret = rename(oldpath, newpath);
@@ -902,7 +902,7 @@ process_readlink(void)
902 902
903 id = get_int(); 903 id = get_int();
904 path = get_string(NULL); 904 path = get_string(NULL);
905 TRACE("readlink id %d path %s", id, path); 905 TRACE("readlink id %u path %s", id, path);
906 if ((len = readlink(path, link, sizeof(link) - 1)) == -1) 906 if ((len = readlink(path, link, sizeof(link) - 1)) == -1)
907 send_status(id, errno_to_portable(errno)); 907 send_status(id, errno_to_portable(errno));
908 else { 908 else {
@@ -927,7 +927,7 @@ process_symlink(void)
927 id = get_int(); 927 id = get_int();
928 oldpath = get_string(NULL); 928 oldpath = get_string(NULL);
929 newpath = get_string(NULL); 929 newpath = get_string(NULL);
930 TRACE("symlink id %d old %s new %s", id, oldpath, newpath); 930 TRACE("symlink id %u old %s new %s", id, oldpath, newpath);
931 /* fail if 'newpath' exists */ 931 /* fail if 'newpath' exists */
932 if (stat(newpath, &st) == -1) { 932 if (stat(newpath, &st) == -1) {
933 ret = symlink(oldpath, newpath); 933 ret = symlink(oldpath, newpath);
diff --git a/sftp.c b/sftp.c
index f941d18fa..fac2564de 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.29 2002/04/02 17:37:48 markus Exp $"); 27RCSID("$OpenBSD: sftp.c,v 1.30 2002/06/23 09:30:14 deraadt Exp $");
28 28
29/* XXX: short-form remote directory listings (like 'ls -C') */ 29/* XXX: short-form remote directory listings (like 'ls -C') */
30 30
@@ -53,8 +53,10 @@ static void
53connect_to_server(char *path, char **args, int *in, int *out, pid_t *sshpid) 53connect_to_server(char *path, char **args, int *in, int *out, pid_t *sshpid)
54{ 54{
55 int c_in, c_out; 55 int c_in, c_out;
56
56#ifdef USE_PIPES 57#ifdef USE_PIPES
57 int pin[2], pout[2]; 58 int pin[2], pout[2];
59
58 if ((pipe(pin) == -1) || (pipe(pout) == -1)) 60 if ((pipe(pin) == -1) || (pipe(pout) == -1))
59 fatal("pipe: %s", strerror(errno)); 61 fatal("pipe: %s", strerror(errno));
60 *in = pin[0]; 62 *in = pin[0];
@@ -63,6 +65,7 @@ connect_to_server(char *path, char **args, int *in, int *out, pid_t *sshpid)
63 c_out = pin[1]; 65 c_out = pin[1];
64#else /* USE_PIPES */ 66#else /* USE_PIPES */
65 int inout[2]; 67 int inout[2];
68
66 if (socketpair(AF_UNIX, SOCK_STREAM, 0, inout) == -1) 69 if (socketpair(AF_UNIX, SOCK_STREAM, 0, inout) == -1)
67 fatal("socketpair: %s", strerror(errno)); 70 fatal("socketpair: %s", strerror(errno));
68 *in = *out = inout[0]; 71 *in = *out = inout[0];