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.1-1.6 (requested by...



details:   https://anonhg.NetBSD.org/src/rev/fcc226bf8226
branches:  netbsd-1-5
changeset: 490713:fcc226bf8226
user:      he <he%NetBSD.org@localhost>
date:      Mon Feb 26 20:27:30 2001 +0000

description:
Pull up revisions 1.1-1.6 (requested by itojun):
  Update SSH to version found on trunk as of 26 Feb 2001.

diffstat:

 crypto/dist/ssh/sftp-client.c |  800 ++++++++++++++++++++++++++++++++++++++++++
 crypto/dist/ssh/ssh-keyscan.c |  602 +++++++++++++++++++++++++++++++
 2 files changed, 1402 insertions(+), 0 deletions(-)

diffs (truncated from 1410 to 300 lines):

diff -r b94df79cab1c -r fcc226bf8226 crypto/dist/ssh/sftp-client.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/crypto/dist/ssh/sftp-client.c     Mon Feb 26 20:27:30 2001 +0000
@@ -0,0 +1,800 @@
+/*
+ * Copyright (c) 2001 Damien Miller.  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.
+ */
+
+/* XXX: memleaks */
+/* XXX: signed vs unsigned */
+/* XXX: redesign to allow concurrent overlapped operations */
+/* XXX: we use fatal too much, error may be more appropriate in places */
+/* XXX: copy between two remote sites */
+
+#include "includes.h"
+RCSID("$OpenBSD: sftp-client.c,v 1.10 2001/02/14 09:46:03 djm Exp $");
+
+#include "ssh.h"
+#include "buffer.h"
+#include "bufaux.h"
+#include "getput.h"
+#include "xmalloc.h"
+#include "log.h"
+#include "atomicio.h"
+#include "pathnames.h"
+
+#include "sftp.h"
+#include "sftp-common.h"
+#include "sftp-client.h"
+
+/* How much data to read/write at at time during copies */
+/* XXX: what should this be? */
+#define COPY_SIZE      8192
+
+/* Message ID */
+static u_int msg_id = 1;
+
+static void
+send_msg(int fd, Buffer *m)
+{
+       int mlen = buffer_len(m);
+       int len;
+       Buffer oqueue;
+
+       buffer_init(&oqueue);
+       buffer_put_int(&oqueue, mlen);
+       buffer_append(&oqueue, buffer_ptr(m), mlen);
+       buffer_consume(m, mlen);
+
+       len = atomic_write(fd, buffer_ptr(&oqueue), buffer_len(&oqueue));
+       if (len <= 0)
+               fatal("Couldn't send packet: %s", strerror(errno));
+
+       buffer_free(&oqueue);
+}
+
+static void
+get_msg(int fd, Buffer *m)
+{
+       u_int len, msg_len;
+       unsigned char buf[4096];
+
+       len = atomic_read(fd, buf, 4);
+       if (len != 4)
+               fatal("Couldn't read packet: %s", strerror(errno));
+
+       msg_len = GET_32BIT(buf);
+       if (msg_len > 256 * 1024)
+               fatal("Received message too long %d", msg_len);
+
+       while (msg_len) {
+               len = atomic_read(fd, buf, MIN(msg_len, sizeof(buf)));
+               if (len <= 0)
+                       fatal("Couldn't read packet: %s", strerror(errno));
+
+               msg_len -= len;
+               buffer_append(m, buf, len);
+       }
+}
+
+static void
+send_string_request(int fd, u_int id, u_int code, char *s,
+    u_int len)
+{
+       Buffer msg;
+
+       buffer_init(&msg);
+       buffer_put_char(&msg, code);
+       buffer_put_int(&msg, id);
+       buffer_put_string(&msg, s, len);
+       send_msg(fd, &msg);
+       debug3("Sent message fd %d T:%d I:%d", fd, code, id);
+       buffer_free(&msg);
+}
+
+static void
+send_string_attrs_request(int fd, u_int id, u_int code, char *s,
+    u_int len, Attrib *a)
+{
+       Buffer msg;
+
+       buffer_init(&msg);
+       buffer_put_char(&msg, code);
+       buffer_put_int(&msg, id);
+       buffer_put_string(&msg, s, len);
+       encode_attrib(&msg, a);
+       send_msg(fd, &msg);
+       debug3("Sent message fd %d T:%d I:%d", fd, code, id);
+       buffer_free(&msg);
+}
+
+static u_int
+get_status(int fd, int expected_id)
+{
+       Buffer msg;
+       u_int type, id, status;
+
+       buffer_init(&msg);
+       get_msg(fd, &msg);
+       type = buffer_get_char(&msg);
+       id = buffer_get_int(&msg);
+
+       if (id != expected_id)
+               fatal("ID mismatch (%d != %d)", id, expected_id);
+       if (type != SSH2_FXP_STATUS)
+               fatal("Expected SSH2_FXP_STATUS(%d) packet, got %d",
+                   SSH2_FXP_STATUS, type);
+
+       status = buffer_get_int(&msg);
+       buffer_free(&msg);
+
+       debug3("SSH2_FXP_STATUS %d", status);
+
+       return(status);
+}
+
+static char *
+get_handle(int fd, u_int expected_id, u_int *len)
+{
+       Buffer msg;
+       u_int type, id;
+       char *handle;
+
+       buffer_init(&msg);
+       get_msg(fd, &msg);
+       type = buffer_get_char(&msg);
+       id = buffer_get_int(&msg);
+
+       if (id != expected_id)
+               fatal("ID mismatch (%d != %d)", id, expected_id);
+       if (type == SSH2_FXP_STATUS) {
+               int status = buffer_get_int(&msg);
+
+               error("Couldn't get handle: %s", fx2txt(status));
+               return(NULL);
+       } else if (type != SSH2_FXP_HANDLE)
+               fatal("Expected SSH2_FXP_HANDLE(%d) packet, got %d",
+                   SSH2_FXP_HANDLE, type);
+
+       handle = buffer_get_string(&msg, len);
+       buffer_free(&msg);
+
+       return(handle);
+}
+
+static Attrib *
+get_decode_stat(int fd, u_int expected_id)
+{
+       Buffer msg;
+       u_int type, id;
+       Attrib *a;
+
+       buffer_init(&msg);
+       get_msg(fd, &msg);
+
+       type = buffer_get_char(&msg);
+       id = buffer_get_int(&msg);
+
+       debug3("Received stat reply T:%d I:%d", type, id);
+       if (id != expected_id)
+               fatal("ID mismatch (%d != %d)", id, expected_id);
+       if (type == SSH2_FXP_STATUS) {
+               int status = buffer_get_int(&msg);
+
+               error("Couldn't stat remote file: %s", fx2txt(status));
+               return(NULL);
+       } else if (type != SSH2_FXP_ATTRS) {
+               fatal("Expected SSH2_FXP_ATTRS(%d) packet, got %d",
+                   SSH2_FXP_ATTRS, type);
+       }
+       a = decode_attrib(&msg);
+       buffer_free(&msg);
+
+       return(a);
+}
+
+int
+do_init(int fd_in, int fd_out)
+{
+       int type, version;
+       Buffer msg;
+
+       buffer_init(&msg);
+       buffer_put_char(&msg, SSH2_FXP_INIT);
+       buffer_put_int(&msg, SSH2_FILEXFER_VERSION);
+       send_msg(fd_out, &msg);
+
+       buffer_clear(&msg);
+
+       get_msg(fd_in, &msg);
+
+       /* Expecting a VERSION reply */
+       if ((type = buffer_get_char(&msg)) != SSH2_FXP_VERSION) {
+               error("Invalid packet back from SSH2_FXP_INIT (type %d)",
+                   type);
+               buffer_free(&msg);
+               return(-1);
+       }
+       version = buffer_get_int(&msg);
+
+       debug2("Remote version: %d", version);
+
+       /* Check for extensions */
+       while (buffer_len(&msg) > 0) {
+               char *name = buffer_get_string(&msg, NULL);
+               char *value = buffer_get_string(&msg, NULL);
+
+               debug2("Init extension: \"%s\"", name);
+               xfree(name);
+               xfree(value);
+       }
+
+       buffer_free(&msg);
+       return(0);
+}
+
+int
+do_close(int fd_in, int fd_out, char *handle, u_int handle_len)
+{
+       u_int id, status;
+       Buffer msg;
+
+       buffer_init(&msg);
+
+       id = msg_id++;
+       buffer_put_char(&msg, SSH2_FXP_CLOSE);
+       buffer_put_int(&msg, id);
+       buffer_put_string(&msg, handle, handle_len);
+       send_msg(fd_out, &msg);
+       debug3("Sent message SSH2_FXP_CLOSE I:%d", id);
+
+       status = get_status(fd_in, id);
+       if (status != SSH2_FX_OK)
+               error("Couldn't close file: %s", fx2txt(status));
+
+       buffer_free(&msg);
+
+       return(status);
+}
+
+int
+do_ls(int fd_in, int fd_out, char *path)
+{
+       Buffer msg;
+       u_int type, id, handle_len, i, expected_id;
+       char *handle;
+
+       id = msg_id++;
+
+       buffer_init(&msg);
+       buffer_put_char(&msg, SSH2_FXP_OPENDIR);
+       buffer_put_int(&msg, id);
+       buffer_put_cstring(&msg, path);
+       send_msg(fd_out, &msg);
+
+       buffer_clear(&msg);
+
+       handle = get_handle(fd_in, id, &handle_len);
+       if (handle == NULL)
+               return(-1);



Home | Main Index | Thread Index | Old Index