summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--sftp-server.c18
2 files changed, 21 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 5b27784ae..a0bb45a5b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -134,6 +134,9 @@
134 - millert@cvs.openbsd.org 2001/03/03 21:41:07 134 - millert@cvs.openbsd.org 2001/03/03 21:41:07
135 [packet.c] 135 [packet.c]
136 Dynamically allocate fd_set; deraadt@ OK 136 Dynamically allocate fd_set; deraadt@ OK
137 - deraadt@cvs.openbsd.org 2001/03/03 22:07:50
138 [sftp-server.c]
139 KNF
137 140
13820010304 14120010304
139 - (bal) Remove make-ssh-known-hosts.1 since it's no longer valid. 142 - (bal) Remove make-ssh-known-hosts.1 since it's no longer valid.
@@ -4326,4 +4329,4 @@
4326 - Wrote replacements for strlcpy and mkdtemp 4329 - Wrote replacements for strlcpy and mkdtemp
4327 - Released 1.0pre1 4330 - Released 1.0pre1
4328 4331
4329$Id: ChangeLog,v 1.892 2001/03/05 07:07:49 mouring Exp $ 4332$Id: ChangeLog,v 1.893 2001/03/05 07:09:11 mouring Exp $
diff --git a/sftp-server.c b/sftp-server.c
index 2b1a7e3e5..6575eb941 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.21 2001/03/03 21:40:30 millert Exp $"); 25RCSID("$OpenBSD: sftp-server.c,v 1.22 2001/03/03 22:07:50 deraadt Exp $");
26 26
27#include "buffer.h" 27#include "buffer.h"
28#include "bufaux.h" 28#include "bufaux.h"
@@ -63,6 +63,7 @@ int
63errno_to_portable(int unixerrno) 63errno_to_portable(int unixerrno)
64{ 64{
65 int ret = 0; 65 int ret = 0;
66
66 switch (unixerrno) { 67 switch (unixerrno) {
67 case 0: 68 case 0:
68 ret = SSH2_FX_OK; 69 ret = SSH2_FX_OK;
@@ -93,6 +94,7 @@ int
93flags_from_portable(int pflags) 94flags_from_portable(int pflags)
94{ 95{
95 int flags = 0; 96 int flags = 0;
97
96 if ((pflags & SSH2_FXF_READ) && 98 if ((pflags & SSH2_FXF_READ) &&
97 (pflags & SSH2_FXF_WRITE)) { 99 (pflags & SSH2_FXF_WRITE)) {
98 flags = O_RDWR; 100 flags = O_RDWR;
@@ -125,17 +127,20 @@ struct Handle {
125 int fd; 127 int fd;
126 char *name; 128 char *name;
127}; 129};
130
128enum { 131enum {
129 HANDLE_UNUSED, 132 HANDLE_UNUSED,
130 HANDLE_DIR, 133 HANDLE_DIR,
131 HANDLE_FILE 134 HANDLE_FILE
132}; 135};
136
133Handle handles[100]; 137Handle handles[100];
134 138
135void 139void
136handle_init(void) 140handle_init(void)
137{ 141{
138 int i; 142 int i;
143
139 for(i = 0; i < sizeof(handles)/sizeof(Handle); i++) 144 for(i = 0; i < sizeof(handles)/sizeof(Handle); i++)
140 handles[i].use = HANDLE_UNUSED; 145 handles[i].use = HANDLE_UNUSED;
141} 146}
@@ -144,6 +149,7 @@ int
144handle_new(int use, char *name, int fd, DIR *dirp) 149handle_new(int use, char *name, int fd, DIR *dirp)
145{ 150{
146 int i; 151 int i;
152
147 for(i = 0; i < sizeof(handles)/sizeof(Handle); i++) { 153 for(i = 0; i < sizeof(handles)/sizeof(Handle); i++) {
148 if (handles[i].use == HANDLE_UNUSED) { 154 if (handles[i].use == HANDLE_UNUSED) {
149 handles[i].use = use; 155 handles[i].use = use;
@@ -178,6 +184,7 @@ int
178handle_from_string(char *handle, u_int hlen) 184handle_from_string(char *handle, u_int hlen)
179{ 185{
180 int val; 186 int val;
187
181 if (hlen != sizeof(int32_t)) 188 if (hlen != sizeof(int32_t))
182 return -1; 189 return -1;
183 val = GET_32BIT(handle); 190 val = GET_32BIT(handle);
@@ -216,6 +223,7 @@ int
216handle_close(int handle) 223handle_close(int handle)
217{ 224{
218 int ret = -1; 225 int ret = -1;
226
219 if (handle_is_ok(handle, HANDLE_FILE)) { 227 if (handle_is_ok(handle, HANDLE_FILE)) {
220 ret = close(handles[handle].fd); 228 ret = close(handles[handle].fd);
221 handles[handle].use = HANDLE_UNUSED; 229 handles[handle].use = HANDLE_UNUSED;
@@ -234,6 +242,7 @@ get_handle(void)
234 char *handle; 242 char *handle;
235 int val = -1; 243 int val = -1;
236 u_int hlen; 244 u_int hlen;
245
237 handle = get_string(&hlen); 246 handle = get_string(&hlen);
238 if (hlen < 256) 247 if (hlen < 256)
239 val = handle_from_string(handle, hlen); 248 val = handle_from_string(handle, hlen);
@@ -247,6 +256,7 @@ void
247send_msg(Buffer *m) 256send_msg(Buffer *m)
248{ 257{
249 int mlen = buffer_len(m); 258 int mlen = buffer_len(m);
259
250 buffer_put_int(&oqueue, mlen); 260 buffer_put_int(&oqueue, mlen);
251 buffer_append(&oqueue, buffer_ptr(m), mlen); 261 buffer_append(&oqueue, buffer_ptr(m), mlen);
252 buffer_consume(m, mlen); 262 buffer_consume(m, mlen);
@@ -256,6 +266,7 @@ void
256send_status(u_int32_t id, u_int32_t error) 266send_status(u_int32_t id, u_int32_t error)
257{ 267{
258 Buffer msg; 268 Buffer msg;
269
259 TRACE("sent status id %d error %d", id, error); 270 TRACE("sent status id %d error %d", id, error);
260 buffer_init(&msg); 271 buffer_init(&msg);
261 buffer_put_char(&msg, SSH2_FXP_STATUS); 272 buffer_put_char(&msg, SSH2_FXP_STATUS);
@@ -268,6 +279,7 @@ void
268send_data_or_handle(char type, u_int32_t id, char *data, int dlen) 279send_data_or_handle(char type, u_int32_t id, char *data, int dlen)
269{ 280{
270 Buffer msg; 281 Buffer msg;
282
271 buffer_init(&msg); 283 buffer_init(&msg);
272 buffer_put_char(&msg, type); 284 buffer_put_char(&msg, type);
273 buffer_put_int(&msg, id); 285 buffer_put_int(&msg, id);
@@ -288,6 +300,7 @@ send_handle(u_int32_t id, int handle)
288{ 300{
289 char *string; 301 char *string;
290 int hlen; 302 int hlen;
303
291 handle_to_string(handle, &string, &hlen); 304 handle_to_string(handle, &string, &hlen);
292 TRACE("sent handle id %d handle %d", id, handle); 305 TRACE("sent handle id %d handle %d", id, handle);
293 send_data_or_handle(SSH2_FXP_HANDLE, id, string, hlen); 306 send_data_or_handle(SSH2_FXP_HANDLE, id, string, hlen);
@@ -299,6 +312,7 @@ send_names(u_int32_t id, int count, Stat *stats)
299{ 312{
300 Buffer msg; 313 Buffer msg;
301 int i; 314 int i;
315
302 buffer_init(&msg); 316 buffer_init(&msg);
303 buffer_put_char(&msg, SSH2_FXP_NAME); 317 buffer_put_char(&msg, SSH2_FXP_NAME);
304 buffer_put_int(&msg, id); 318 buffer_put_int(&msg, id);
@@ -317,6 +331,7 @@ void
317send_attrib(u_int32_t id, Attrib *a) 331send_attrib(u_int32_t id, Attrib *a)
318{ 332{
319 Buffer msg; 333 Buffer msg;
334
320 TRACE("sent attrib id %d have 0x%x", id, a->flags); 335 TRACE("sent attrib id %d have 0x%x", id, a->flags);
321 buffer_init(&msg); 336 buffer_init(&msg);
322 buffer_put_char(&msg, SSH2_FXP_ATTRS); 337 buffer_put_char(&msg, SSH2_FXP_ATTRS);
@@ -533,6 +548,7 @@ struct timeval *
533attrib_to_tv(Attrib *a) 548attrib_to_tv(Attrib *a)
534{ 549{
535 static struct timeval tv[2]; 550 static struct timeval tv[2];
551
536 tv[0].tv_sec = a->atime; 552 tv[0].tv_sec = a->atime;
537 tv[0].tv_usec = 0; 553 tv[0].tv_usec = 0;
538 tv[1].tv_sec = a->mtime; 554 tv[1].tv_sec = a->mtime;