Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-1-5]: src/crypto/dist/ssh Pull up revisions 1.2-1.7 (requested by...
details: https://anonhg.NetBSD.org/src/rev/d7fa5f4074e2
branches: netbsd-1-5
changeset: 490704:d7fa5f4074e2
user: he <he%NetBSD.org@localhost>
date: Mon Feb 26 20:27:01 2001 +0000
description:
Pull up revisions 1.2-1.7 (requested by itojun):
Update SSH to version found on trunk as of 26 Feb 2001.
diffstat:
crypto/dist/ssh/sftp-server.c | 987 ++++++++++++++++++++++++++++++++++++++++++
1 files changed, 987 insertions(+), 0 deletions(-)
diffs (truncated from 991 to 300 lines):
diff -r b00dd0e39b45 -r d7fa5f4074e2 crypto/dist/ssh/sftp-server.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/crypto/dist/ssh/sftp-server.c Mon Feb 26 20:27:01 2001 +0000
@@ -0,0 +1,987 @@
+/*
+ * Copyright (c) 2000 Markus Friedl. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "includes.h"
+RCSID("$OpenBSD: sftp-server.c,v 1.19 2001/02/07 18:01:18 itojun Exp $");
+
+#include "buffer.h"
+#include "bufaux.h"
+#include "getput.h"
+#include "log.h"
+#include "xmalloc.h"
+
+#include "sftp.h"
+#include "sftp-common.h"
+
+/* helper */
+#define get_int64() buffer_get_int64(&iqueue);
+#define get_int() buffer_get_int(&iqueue);
+#define get_string(lenp) buffer_get_string(&iqueue, lenp);
+#define TRACE debug
+
+/* input and output queue */
+Buffer iqueue;
+Buffer oqueue;
+
+/* portable attibutes, etc. */
+
+typedef struct Stat Stat;
+
+struct Stat {
+ char *name;
+ char *long_name;
+ Attrib attrib;
+};
+
+static int
+errno_to_portable(int unixerrno)
+{
+ int ret = 0;
+ switch (unixerrno) {
+ case 0:
+ ret = SSH2_FX_OK;
+ break;
+ case ENOENT:
+ case ENOTDIR:
+ case EBADF:
+ case ELOOP:
+ ret = SSH2_FX_NO_SUCH_FILE;
+ break;
+ case EPERM:
+ case EACCES:
+ case EFAULT:
+ ret = SSH2_FX_PERMISSION_DENIED;
+ break;
+ case ENAMETOOLONG:
+ case EINVAL:
+ ret = SSH2_FX_BAD_MESSAGE;
+ break;
+ default:
+ ret = SSH2_FX_FAILURE;
+ break;
+ }
+ return ret;
+}
+
+static int
+flags_from_portable(int pflags)
+{
+ int flags = 0;
+ if (pflags & SSH2_FXF_READ &&
+ pflags & SSH2_FXF_WRITE) {
+ flags = O_RDWR;
+ } else if (pflags & SSH2_FXF_READ) {
+ flags = O_RDONLY;
+ } else if (pflags & SSH2_FXF_WRITE) {
+ flags = O_WRONLY;
+ }
+ if (pflags & SSH2_FXF_CREAT)
+ flags |= O_CREAT;
+ if (pflags & SSH2_FXF_TRUNC)
+ flags |= O_TRUNC;
+ if (pflags & SSH2_FXF_EXCL)
+ flags |= O_EXCL;
+ return flags;
+}
+
+static Attrib *
+get_attrib(void)
+{
+ return decode_attrib(&iqueue);
+}
+
+/* handle handles */
+
+typedef struct Handle Handle;
+struct Handle {
+ int use;
+ DIR *dirp;
+ int fd;
+ char *name;
+};
+enum {
+ HANDLE_UNUSED,
+ HANDLE_DIR,
+ HANDLE_FILE
+};
+Handle handles[100];
+
+static void
+handle_init(void)
+{
+ int i;
+ for(i = 0; i < sizeof(handles)/sizeof(Handle); i++)
+ handles[i].use = HANDLE_UNUSED;
+}
+
+static int
+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;
+ handles[i].dirp = dirp;
+ handles[i].fd = fd;
+ handles[i].name = name;
+ return i;
+ }
+ }
+ return -1;
+}
+
+static int
+handle_is_ok(int i, int type)
+{
+ return i >= 0 && i < sizeof(handles)/sizeof(Handle) &&
+ handles[i].use == type;
+}
+
+static int
+handle_to_string(int handle, char **stringp, int *hlenp)
+{
+ if (stringp == NULL || hlenp == NULL)
+ return -1;
+ *stringp = xmalloc(sizeof(int32_t));
+ PUT_32BIT(*stringp, handle);
+ *hlenp = sizeof(int32_t);
+ return 0;
+}
+
+static int
+handle_from_string(char *handle, u_int hlen)
+{
+ int val;
+ if (hlen != sizeof(int32_t))
+ return -1;
+ val = GET_32BIT(handle);
+ if (handle_is_ok(val, HANDLE_FILE) ||
+ handle_is_ok(val, HANDLE_DIR))
+ return val;
+ return -1;
+}
+
+static char *
+handle_to_name(int handle)
+{
+ if (handle_is_ok(handle, HANDLE_DIR)||
+ handle_is_ok(handle, HANDLE_FILE))
+ return handles[handle].name;
+ return NULL;
+}
+
+static DIR *
+handle_to_dir(int handle)
+{
+ if (handle_is_ok(handle, HANDLE_DIR))
+ return handles[handle].dirp;
+ return NULL;
+}
+
+static int
+handle_to_fd(int handle)
+{
+ if (handle_is_ok(handle, HANDLE_FILE))
+ return handles[handle].fd;
+ return -1;
+}
+
+static int
+handle_close(int handle)
+{
+ int ret = -1;
+ if (handle_is_ok(handle, HANDLE_FILE)) {
+ ret = close(handles[handle].fd);
+ handles[handle].use = HANDLE_UNUSED;
+ } else if (handle_is_ok(handle, HANDLE_DIR)) {
+ ret = closedir(handles[handle].dirp);
+ handles[handle].use = HANDLE_UNUSED;
+ } else {
+ errno = ENOENT;
+ }
+ return ret;
+}
+
+static int
+get_handle(void)
+{
+ char *handle;
+ int val = -1;
+ u_int hlen;
+ handle = get_string(&hlen);
+ if (hlen < 256)
+ val = handle_from_string(handle, hlen);
+ xfree(handle);
+ return val;
+}
+
+/* send replies */
+
+static void
+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);
+}
+
+static void
+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);
+ buffer_put_int(&msg, id);
+ buffer_put_int(&msg, error);
+ send_msg(&msg);
+ buffer_free(&msg);
+}
+static void
+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);
+ buffer_put_string(&msg, data, dlen);
+ send_msg(&msg);
+ buffer_free(&msg);
+}
+
+static void
+send_data(u_int32_t id, char *data, int dlen)
+{
+ TRACE("sent data id %d len %d", id, dlen);
+ send_data_or_handle(SSH2_FXP_DATA, id, data, dlen);
+}
+
+static void
+send_handle(u_int32_t id, int handle)
+{
+ 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);
+ xfree(string);
+}
+
+static void
+send_names(u_int32_t id, int count, Stat *stats)
+{
+ Buffer msg;
+ int i;
+ buffer_init(&msg);
Home |
Main Index |
Thread Index |
Old Index