mirror of
git://anongit.mindrot.org/openssh.git
synced 2025-02-17 06:16:55 +00:00
- djm@cvs.openbsd.org 2003/01/10 08:48:15
[sftp-client.c] Simplify and avoid redundancy in packet send and receive functions; ok fgs@
This commit is contained in:
parent
62d57f605a
commit
a7f3aaadc3
@ -13,6 +13,10 @@
|
|||||||
sftp progress meter support.
|
sftp progress meter support.
|
||||||
original diffs by Nils Nordman <nino at nforced dot com> via
|
original diffs by Nils Nordman <nino at nforced dot com> via
|
||||||
markus@, merged to -current by me, djm@ ok.
|
markus@, merged to -current by me, djm@ ok.
|
||||||
|
- djm@cvs.openbsd.org 2003/01/10 08:48:15
|
||||||
|
[sftp-client.c]
|
||||||
|
Simplify and avoid redundancy in packet send and receive
|
||||||
|
functions; ok fgs@
|
||||||
|
|
||||||
20030108
|
20030108
|
||||||
- (djm) Sync openbsd-compat/ with OpenBSD -current
|
- (djm) Sync openbsd-compat/ with OpenBSD -current
|
||||||
@ -981,4 +985,4 @@
|
|||||||
save auth method before monitor_reset_key_state(); bugzilla bug #284;
|
save auth method before monitor_reset_key_state(); bugzilla bug #284;
|
||||||
ok provos@
|
ok provos@
|
||||||
|
|
||||||
$Id: ChangeLog,v 1.2560 2003/01/10 10:43:24 djm Exp $
|
$Id: ChangeLog,v 1.2561 2003/01/10 10:43:58 djm Exp $
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2001,2002 Damien Miller. All rights reserved.
|
* Copyright (c) 2001-2003 Damien Miller. All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@ -28,7 +28,7 @@
|
|||||||
/* XXX: copy between two remote sites */
|
/* XXX: copy between two remote sites */
|
||||||
|
|
||||||
#include "includes.h"
|
#include "includes.h"
|
||||||
RCSID("$OpenBSD: sftp-client.c,v 1.39 2003/01/10 08:19:07 fgsch Exp $");
|
RCSID("$OpenBSD: sftp-client.c,v 1.40 2003/01/10 08:48:15 djm Exp $");
|
||||||
|
|
||||||
#include "openbsd-compat/sys-queue.h"
|
#include "openbsd-compat/sys-queue.h"
|
||||||
|
|
||||||
@ -49,6 +49,9 @@ extern int showprogress;
|
|||||||
/* Minimum amount of data to read at at time */
|
/* Minimum amount of data to read at at time */
|
||||||
#define MIN_READ_SIZE 512
|
#define MIN_READ_SIZE 512
|
||||||
|
|
||||||
|
/* Maximum packet size */
|
||||||
|
#define MAX_MSG_LENGTH (256 * 1024)
|
||||||
|
|
||||||
struct sftp_conn {
|
struct sftp_conn {
|
||||||
int fd_in;
|
int fd_in;
|
||||||
int fd_out;
|
int fd_out;
|
||||||
@ -61,48 +64,45 @@ struct sftp_conn {
|
|||||||
static void
|
static void
|
||||||
send_msg(int fd, Buffer *m)
|
send_msg(int fd, Buffer *m)
|
||||||
{
|
{
|
||||||
int mlen = buffer_len(m);
|
u_char mlen[4];
|
||||||
int len;
|
|
||||||
Buffer oqueue;
|
|
||||||
|
|
||||||
buffer_init(&oqueue);
|
if (buffer_len(m) > MAX_MSG_LENGTH)
|
||||||
buffer_put_int(&oqueue, mlen);
|
fatal("Outbound message too long %u", buffer_len(m));
|
||||||
buffer_append(&oqueue, buffer_ptr(m), mlen);
|
|
||||||
buffer_consume(m, mlen);
|
|
||||||
|
|
||||||
len = atomicio(write, fd, buffer_ptr(&oqueue), buffer_len(&oqueue));
|
/* Send length first */
|
||||||
if (len <= 0)
|
PUT_32BIT(mlen, buffer_len(m));
|
||||||
|
if (atomicio(write, fd, mlen, sizeof(mlen)) <= 0)
|
||||||
fatal("Couldn't send packet: %s", strerror(errno));
|
fatal("Couldn't send packet: %s", strerror(errno));
|
||||||
|
|
||||||
buffer_free(&oqueue);
|
if (atomicio(write, fd, buffer_ptr(m), buffer_len(m)) <= 0)
|
||||||
|
fatal("Couldn't send packet: %s", strerror(errno));
|
||||||
|
|
||||||
|
buffer_clear(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
get_msg(int fd, Buffer *m)
|
get_msg(int fd, Buffer *m)
|
||||||
{
|
{
|
||||||
u_int len, msg_len;
|
ssize_t len;
|
||||||
unsigned char buf[4096];
|
u_int msg_len;
|
||||||
|
|
||||||
len = atomicio(read, fd, buf, 4);
|
buffer_append_space(m, 4);
|
||||||
|
len = atomicio(read, fd, buffer_ptr(m), 4);
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
fatal("Connection closed");
|
fatal("Connection closed");
|
||||||
else if (len == -1)
|
else if (len == -1)
|
||||||
fatal("Couldn't read packet: %s", strerror(errno));
|
fatal("Couldn't read packet: %s", strerror(errno));
|
||||||
|
|
||||||
msg_len = GET_32BIT(buf);
|
msg_len = buffer_get_int(m);
|
||||||
if (msg_len > 256 * 1024)
|
if (msg_len > MAX_MSG_LENGTH)
|
||||||
fatal("Received message too long %u", msg_len);
|
fatal("Received message too long %u", msg_len);
|
||||||
|
|
||||||
while (msg_len) {
|
buffer_append_space(m, msg_len);
|
||||||
len = atomicio(read, fd, buf, MIN(msg_len, sizeof(buf)));
|
len = atomicio(read, fd, buffer_ptr(m), msg_len);
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
fatal("Connection closed");
|
fatal("Connection closed");
|
||||||
else if (len == -1)
|
else if (len == -1)
|
||||||
fatal("Couldn't read packet: %s", strerror(errno));
|
fatal("Read packet: %s", strerror(errno));
|
||||||
|
|
||||||
msg_len -= len;
|
|
||||||
buffer_append(m, buf, len);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user