- deraadt@cvs.openbsd.org 2001/03/03 22:07:50
[sftp-server.c]
KNF
diff --git a/sftp-server.c b/sftp-server.c
index 2b1a7e3..6575eb9 100644
--- a/sftp-server.c
+++ b/sftp-server.c
@@ -22,7 +22,7 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "includes.h"
-RCSID("$OpenBSD: sftp-server.c,v 1.21 2001/03/03 21:40:30 millert Exp $");
+RCSID("$OpenBSD: sftp-server.c,v 1.22 2001/03/03 22:07:50 deraadt Exp $");
#include "buffer.h"
#include "bufaux.h"
@@ -63,6 +63,7 @@
errno_to_portable(int unixerrno)
{
int ret = 0;
+
switch (unixerrno) {
case 0:
ret = SSH2_FX_OK;
@@ -93,6 +94,7 @@
flags_from_portable(int pflags)
{
int flags = 0;
+
if ((pflags & SSH2_FXF_READ) &&
(pflags & SSH2_FXF_WRITE)) {
flags = O_RDWR;
@@ -125,17 +127,20 @@
int fd;
char *name;
};
+
enum {
HANDLE_UNUSED,
HANDLE_DIR,
HANDLE_FILE
};
+
Handle handles[100];
void
handle_init(void)
{
int i;
+
for(i = 0; i < sizeof(handles)/sizeof(Handle); i++)
handles[i].use = HANDLE_UNUSED;
}
@@ -144,6 +149,7 @@
handle_new(int use, char *name, int fd, DIR *dirp)
{
int i;
+
for(i = 0; i < sizeof(handles)/sizeof(Handle); i++) {
if (handles[i].use == HANDLE_UNUSED) {
handles[i].use = use;
@@ -178,6 +184,7 @@
handle_from_string(char *handle, u_int hlen)
{
int val;
+
if (hlen != sizeof(int32_t))
return -1;
val = GET_32BIT(handle);
@@ -216,6 +223,7 @@
handle_close(int handle)
{
int ret = -1;
+
if (handle_is_ok(handle, HANDLE_FILE)) {
ret = close(handles[handle].fd);
handles[handle].use = HANDLE_UNUSED;
@@ -234,6 +242,7 @@
char *handle;
int val = -1;
u_int hlen;
+
handle = get_string(&hlen);
if (hlen < 256)
val = handle_from_string(handle, hlen);
@@ -247,6 +256,7 @@
send_msg(Buffer *m)
{
int mlen = buffer_len(m);
+
buffer_put_int(&oqueue, mlen);
buffer_append(&oqueue, buffer_ptr(m), mlen);
buffer_consume(m, mlen);
@@ -256,6 +266,7 @@
send_status(u_int32_t id, u_int32_t error)
{
Buffer msg;
+
TRACE("sent status id %d error %d", id, error);
buffer_init(&msg);
buffer_put_char(&msg, SSH2_FXP_STATUS);
@@ -268,6 +279,7 @@
send_data_or_handle(char type, u_int32_t id, char *data, int dlen)
{
Buffer msg;
+
buffer_init(&msg);
buffer_put_char(&msg, type);
buffer_put_int(&msg, id);
@@ -288,6 +300,7 @@
{
char *string;
int hlen;
+
handle_to_string(handle, &string, &hlen);
TRACE("sent handle id %d handle %d", id, handle);
send_data_or_handle(SSH2_FXP_HANDLE, id, string, hlen);
@@ -299,6 +312,7 @@
{
Buffer msg;
int i;
+
buffer_init(&msg);
buffer_put_char(&msg, SSH2_FXP_NAME);
buffer_put_int(&msg, id);
@@ -317,6 +331,7 @@
send_attrib(u_int32_t id, Attrib *a)
{
Buffer msg;
+
TRACE("sent attrib id %d have 0x%x", id, a->flags);
buffer_init(&msg);
buffer_put_char(&msg, SSH2_FXP_ATTRS);
@@ -533,6 +548,7 @@
attrib_to_tv(Attrib *a)
{
static struct timeval tv[2];
+
tv[0].tv_sec = a->atime;
tv[0].tv_usec = 0;
tv[1].tv_sec = a->mtime;