summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2001-12-21 14:56:54 +1100
committerDamien Miller <djm@mindrot.org>2001-12-21 14:56:54 +1100
commit5a6b4fe22583394886092aad5787b5fa8355276e (patch)
treec6366cbaf2c3ea9bd1ac8f162f9452e1e9ca0434
parentf6681a3a96ae06d62db49594ba0dcf352f817801 (diff)
- stevesk@cvs.openbsd.org 2001/12/19 17:16:13
[authfile.c bufaux.c bufaux.h buffer.c buffer.h packet.c packet.h ssh.c] change the buffer/packet interface to use void* vs. char*; ok markus@
-rw-r--r--ChangeLog5
-rw-r--r--authfile.c10
-rw-r--r--bufaux.c6
-rw-r--r--bufaux.h4
-rw-r--r--buffer.c25
-rw-r--r--buffer.h12
-rw-r--r--packet.c25
-rw-r--r--packet.h10
-rw-r--r--ssh.c10
9 files changed, 57 insertions, 50 deletions
diff --git a/ChangeLog b/ChangeLog
index 7b821250..abf02912 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -44,6 +44,9 @@
to the pipe on SIGCHLD wakes up select(). using pselect() is not
portable and siglongjmp() ugly. W. R. Stevens suggests similar solution.
initial idea by pmenage@ensim.com; ok deraadt@, djm@
+ - stevesk@cvs.openbsd.org 2001/12/19 17:16:13
+ [authfile.c bufaux.c bufaux.h buffer.c buffer.h packet.c packet.h ssh.c]
+ change the buffer/packet interface to use void* vs. char*; ok markus@
20011219
- (stevesk) OpenBSD CVS sync X11 localhost display
@@ -7072,4 +7075,4 @@
- Wrote replacements for strlcpy and mkdtemp
- Released 1.0pre1
-$Id: ChangeLog,v 1.1702 2001/12/21 03:53:11 djm Exp $
+$Id: ChangeLog,v 1.1703 2001/12/21 03:56:54 djm Exp $
diff --git a/authfile.c b/authfile.c
index abf2877f..3bfca4ac 100644
--- a/authfile.c
+++ b/authfile.c
@@ -36,7 +36,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: authfile.c,v 1.41 2001/12/19 07:18:56 deraadt Exp $");
+RCSID("$OpenBSD: authfile.c,v 1.42 2001/12/19 17:16:13 stevesk Exp $");
#include <openssl/err.h>
#include <openssl/evp.h>
@@ -128,7 +128,7 @@ key_save_private_rsa1(Key *key, const char *filename, const char *passphrase,
buffer_put_cstring(&encrypted, comment);
/* Allocate space for the private part of the key in the buffer. */
- buffer_append_space(&encrypted, &cp, buffer_len(&buffer));
+ cp = buffer_append_space(&encrypted, buffer_len(&buffer));
cipher_set_key_string(&ciphercontext, cipher, passphrase);
cipher_encrypt(&ciphercontext, (u_char *) cp,
@@ -239,7 +239,7 @@ key_load_public_rsa1(int fd, const char *filename, char **commentp)
lseek(fd, (off_t) 0, SEEK_SET);
buffer_init(&buffer);
- buffer_append_space(&buffer, &cp, len);
+ cp = buffer_append_space(&buffer, len);
if (read(fd, cp, (size_t) len) != (size_t) len) {
debug("Read from key file %.200s failed: %.100s", filename,
@@ -324,7 +324,7 @@ key_load_private_rsa1(int fd, const char *filename, const char *passphrase,
lseek(fd, (off_t) 0, SEEK_SET);
buffer_init(&buffer);
- buffer_append_space(&buffer, &cp, len);
+ cp = buffer_append_space(&buffer, len);
if (read(fd, cp, (size_t) len) != (size_t) len) {
debug("Read from key file %.200s failed: %.100s", filename,
@@ -378,7 +378,7 @@ key_load_private_rsa1(int fd, const char *filename, const char *passphrase,
}
/* Initialize space for decrypted data. */
buffer_init(&decrypted);
- buffer_append_space(&decrypted, &cp, buffer_len(&buffer));
+ cp = buffer_append_space(&decrypted, buffer_len(&buffer));
/* Rest of the buffer is encrypted. Decrypt it using the passphrase. */
cipher_set_key_string(&ciphercontext, cipher, passphrase);
diff --git a/bufaux.c b/bufaux.c
index 5bc71862..7fbd0d02 100644
--- a/bufaux.c
+++ b/bufaux.c
@@ -37,7 +37,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: bufaux.c,v 1.19 2001/12/19 07:18:56 deraadt Exp $");
+RCSID("$OpenBSD: bufaux.c,v 1.20 2001/12/19 17:16:13 stevesk Exp $");
#include <openssl/bn.h>
#include "bufaux.h"
@@ -191,11 +191,11 @@ buffer_put_int64(Buffer *buffer, u_int64_t value)
* will be stored there. A null character will be automatically appended
* to the returned string, and is not counted in length.
*/
-char *
+void *
buffer_get_string(Buffer *buffer, u_int *length_ptr)
{
u_int len;
- char *value;
+ u_char *value;
/* Get the length. */
len = buffer_get_int(buffer);
if (len > 256 * 1024)
diff --git a/bufaux.h b/bufaux.h
index d1af0988..521ddf13 100644
--- a/bufaux.h
+++ b/bufaux.h
@@ -10,7 +10,7 @@
* called by a name other than "ssh" or "Secure Shell".
*/
-/* RCSID("$OpenBSD: bufaux.h,v 1.13 2001/06/26 17:27:22 markus Exp $"); */
+/* RCSID("$OpenBSD: bufaux.h,v 1.14 2001/12/19 17:16:13 stevesk Exp $"); */
#ifndef BUFAUX_H
#define BUFAUX_H
@@ -36,7 +36,7 @@ int buffer_get_char(Buffer *);
void buffer_put_char(Buffer *, int);
-char *buffer_get_string(Buffer *, u_int *);
+void *buffer_get_string(Buffer *, u_int *);
void buffer_put_string(Buffer *, const void *, u_int);
void buffer_put_cstring(Buffer *, const char *);
diff --git a/buffer.c b/buffer.c
index 044caafb..a1152d1d 100644
--- a/buffer.c
+++ b/buffer.c
@@ -12,7 +12,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: buffer.c,v 1.13 2001/04/12 19:15:24 markus Exp $");
+RCSID("$OpenBSD: buffer.c,v 1.14 2001/12/19 17:16:13 stevesk Exp $");
#include "xmalloc.h"
#include "buffer.h"
@@ -53,11 +53,11 @@ buffer_clear(Buffer *buffer)
/* Appends data to the buffer, expanding it if necessary. */
void
-buffer_append(Buffer *buffer, const char *data, u_int len)
+buffer_append(Buffer *buffer, const void *data, u_int len)
{
- char *cp;
- buffer_append_space(buffer, &cp, len);
- memcpy(cp, data, len);
+ void *p;
+ p = buffer_append_space(buffer, len);
+ memcpy(p, data, len);
}
/*
@@ -66,9 +66,11 @@ buffer_append(Buffer *buffer, const char *data, u_int len)
* to the allocated region.
*/
-void
-buffer_append_space(Buffer *buffer, char **datap, u_int len)
+void *
+buffer_append_space(Buffer *buffer, u_int len)
{
+ void *p;
+
/* If the buffer is empty, start using it from the beginning. */
if (buffer->offset == buffer->end) {
buffer->offset = 0;
@@ -77,9 +79,9 @@ buffer_append_space(Buffer *buffer, char **datap, u_int len)
restart:
/* If there is enough space to store all data, store it now. */
if (buffer->end + len < buffer->alloc) {
- *datap = buffer->buf + buffer->end;
+ p = buffer->buf + buffer->end;
buffer->end += len;
- return;
+ return p;
}
/*
* If the buffer is quite empty, but all data is at the end, move the
@@ -96,6 +98,7 @@ restart:
buffer->alloc += len + 32768;
buffer->buf = xrealloc(buffer->buf, buffer->alloc);
goto restart;
+ /* NOTREACHED */
}
/* Returns the number of bytes of data in the buffer. */
@@ -109,7 +112,7 @@ buffer_len(Buffer *buffer)
/* Gets data from the beginning of the buffer. */
void
-buffer_get(Buffer *buffer, char *buf, u_int len)
+buffer_get(Buffer *buffer, void *buf, u_int len)
{
if (len > buffer->end - buffer->offset)
fatal("buffer_get: trying to get more bytes %d than in buffer %d",
@@ -140,7 +143,7 @@ buffer_consume_end(Buffer *buffer, u_int bytes)
/* Returns a pointer to the first used byte in the buffer. */
-char *
+void *
buffer_ptr(Buffer *buffer)
{
return buffer->buf + buffer->offset;
diff --git a/buffer.h b/buffer.h
index 845bfb69..badd16f3 100644
--- a/buffer.h
+++ b/buffer.h
@@ -11,13 +11,13 @@
* called by a name other than "ssh" or "Secure Shell".
*/
-/* RCSID("$OpenBSD: buffer.h,v 1.9 2001/06/26 17:27:23 markus Exp $"); */
+/* RCSID("$OpenBSD: buffer.h,v 1.10 2001/12/19 17:16:13 stevesk Exp $"); */
#ifndef BUFFER_H
#define BUFFER_H
typedef struct {
- char *buf; /* Buffer for data. */
+ u_char *buf; /* Buffer for data. */
u_int alloc; /* Number of bytes allocated for data. */
u_int offset; /* Offset of first byte containing data. */
u_int end; /* Offset of last byte containing data. */
@@ -28,12 +28,12 @@ void buffer_clear(Buffer *);
void buffer_free(Buffer *);
u_int buffer_len(Buffer *);
-char *buffer_ptr(Buffer *);
+void *buffer_ptr(Buffer *);
-void buffer_append(Buffer *, const char *, u_int);
-void buffer_append_space(Buffer *, char **, u_int);
+void buffer_append(Buffer *, const void *, u_int);
+void *buffer_append_space(Buffer *, u_int);
-void buffer_get(Buffer *, char *, u_int);
+void buffer_get(Buffer *, void *, u_int);
void buffer_consume(Buffer *, u_int);
void buffer_consume_end(Buffer *, u_int);
diff --git a/packet.c b/packet.c
index 9aeda393..4b3eafc8 100644
--- a/packet.c
+++ b/packet.c
@@ -37,7 +37,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: packet.c,v 1.75 2001/12/19 07:18:56 deraadt Exp $");
+RCSID("$OpenBSD: packet.c,v 1.76 2001/12/19 17:16:13 stevesk Exp $");
#include "xmalloc.h"
#include "buffer.h"
@@ -329,7 +329,7 @@ packet_put_int(u_int value)
buffer_put_int(&outgoing_packet, value);
}
void
-packet_put_string(const char *buf, u_int len)
+packet_put_string(const void *buf, u_int len)
{
buffer_put_string(&outgoing_packet, buf, len);
}
@@ -339,7 +339,7 @@ packet_put_cstring(const char *str)
buffer_put_cstring(&outgoing_packet, str);
}
void
-packet_put_raw(const char *buf, u_int len)
+packet_put_raw(const void *buf, u_int len)
{
buffer_append(&outgoing_packet, buf, len);
}
@@ -412,7 +412,7 @@ packet_send1(void)
/* Append to output. */
PUT_32BIT(buf, len);
buffer_append(&output, buf, 4);
- buffer_append_space(&output, &cp, buffer_len(&outgoing_packet));
+ cp = buffer_append_space(&output, buffer_len(&outgoing_packet));
cipher_encrypt(&send_context, cp, buffer_ptr(&outgoing_packet),
buffer_len(&outgoing_packet));
@@ -546,7 +546,7 @@ packet_send2(void)
padlen += pad;
extra_pad = 0;
}
- buffer_append_space(&outgoing_packet, &cp, padlen);
+ cp = buffer_append_space(&outgoing_packet, padlen);
if (enc && enc->cipher->number != SSH_CIPHER_NONE) {
/* random padding */
for (i = 0; i < padlen; i++) {
@@ -574,7 +574,7 @@ packet_send2(void)
DBG(debug("done calc MAC out #%d", seqnr));
}
/* encrypt packet and append to output buffer. */
- buffer_append_space(&output, &cp, buffer_len(&outgoing_packet));
+ cp = buffer_append_space(&output, buffer_len(&outgoing_packet));
cipher_encrypt(&send_context, cp, buffer_ptr(&outgoing_packet),
buffer_len(&outgoing_packet));
/* append unencrypted MAC */
@@ -734,7 +734,7 @@ packet_read_poll1(int *payload_len_ptr)
/* Decrypt data to incoming_packet. */
buffer_clear(&incoming_packet);
- buffer_append_space(&incoming_packet, &cp, padded_len);
+ cp = buffer_append_space(&incoming_packet, padded_len);
cipher_decrypt(&receive_context, cp, buffer_ptr(&input), padded_len);
buffer_consume(&input, padded_len);
@@ -803,7 +803,7 @@ packet_read_poll2(int *payload_len_ptr)
if (buffer_len(&input) < block_size)
return SSH_MSG_NONE;
buffer_clear(&incoming_packet);
- buffer_append_space(&incoming_packet, &cp, block_size);
+ cp = buffer_append_space(&incoming_packet, block_size);
cipher_decrypt(&receive_context, cp, buffer_ptr(&input),
block_size);
ucp = (u_char *) buffer_ptr(&incoming_packet);
@@ -832,7 +832,7 @@ packet_read_poll2(int *payload_len_ptr)
fprintf(stderr, "read_poll enc/full: ");
buffer_dump(&input);
#endif
- buffer_append_space(&incoming_packet, &cp, need);
+ cp = buffer_append_space(&incoming_packet, need);
cipher_decrypt(&receive_context, cp, buffer_ptr(&input), need);
buffer_consume(&input, need);
/*
@@ -852,7 +852,8 @@ packet_read_poll2(int *payload_len_ptr)
log("incoming seqnr wraps around");
/* get padlen */
- cp = buffer_ptr(&incoming_packet) + 4;
+ cp = buffer_ptr(&incoming_packet);
+ cp += 4;
padlen = (u_char) *cp;
DBG(debug("input: padlen %d", padlen));
if (padlen < 4)
@@ -996,7 +997,7 @@ packet_get_bignum2(BIGNUM * value, int *length_ptr)
*length_ptr = buffer_get_bignum2(&incoming_packet, value);
}
-char *
+void *
packet_get_raw(int *length_ptr)
{
int bytes = buffer_len(&incoming_packet);
@@ -1018,7 +1019,7 @@ packet_remaining(void)
* integer into which the length of the string is stored.
*/
-char *
+void *
packet_get_string(u_int *length_ptr)
{
return buffer_get_string(&incoming_packet, length_ptr);
diff --git a/packet.h b/packet.h
index d5473001..d281042f 100644
--- a/packet.h
+++ b/packet.h
@@ -11,7 +11,7 @@
* called by a name other than "ssh" or "Secure Shell".
*/
-/* RCSID("$OpenBSD: packet.h,v 1.26 2001/11/07 16:03:17 markus Exp $"); */
+/* RCSID("$OpenBSD: packet.h,v 1.27 2001/12/19 17:16:13 stevesk Exp $"); */
#ifndef PACKET_H
#define PACKET_H
@@ -35,9 +35,9 @@ void packet_put_char(int ch);
void packet_put_int(u_int value);
void packet_put_bignum(BIGNUM * value);
void packet_put_bignum2(BIGNUM * value);
-void packet_put_string(const char *buf, u_int len);
+void packet_put_string(const void *buf, u_int len);
void packet_put_cstring(const char *str);
-void packet_put_raw(const char *buf, u_int len);
+void packet_put_raw(const void *buf, u_int len);
void packet_send(void);
int packet_read(int *payload_len_ptr);
@@ -49,8 +49,8 @@ u_int packet_get_char(void);
u_int packet_get_int(void);
void packet_get_bignum(BIGNUM * value, int *length_ptr);
void packet_get_bignum2(BIGNUM * value, int *length_ptr);
-char *packet_get_raw(int *length_ptr);
-char *packet_get_string(u_int *length_ptr);
+void *packet_get_raw(int *length_ptr);
+void *packet_get_string(u_int *length_ptr);
void packet_disconnect(const char *fmt,...) __attribute__((format(printf, 1, 2)));
void packet_send_debug(const char *fmt,...) __attribute__((format(printf, 1, 2)));
diff --git a/ssh.c b/ssh.c
index aa557eb0..9ec63ab9 100644
--- a/ssh.c
+++ b/ssh.c
@@ -39,7 +39,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: ssh.c,v 1.151 2001/12/19 07:18:56 deraadt Exp $");
+RCSID("$OpenBSD: ssh.c,v 1.152 2001/12/19 17:16:13 stevesk Exp $");
#include <openssl/evp.h>
#include <openssl/err.h>
@@ -997,7 +997,7 @@ ssh_session(void)
int len = buffer_len(&command);
if (len > 900)
len = 900;
- debug("Sending command: %.*s", len, buffer_ptr(&command));
+ debug("Sending command: %.*s", len, (u_char *)buffer_ptr(&command));
packet_start(SSH_CMSG_EXEC_CMD);
packet_put_string(buffer_ptr(&command), buffer_len(&command));
packet_send();
@@ -1026,7 +1026,7 @@ client_subsystem_reply(int type, int plen, void *ctxt)
packet_done();
if (type == SSH2_MSG_CHANNEL_FAILURE)
fatal("Request for subsystem '%.*s' failed on channel %d",
- len, buffer_ptr(&command), id);
+ len, (u_char *)buffer_ptr(&command), id);
}
/* request pty/x11/agent/tcpfwd/shell for channel */
@@ -1085,14 +1085,14 @@ ssh_session2_setup(int id, void *arg)
if (len > 900)
len = 900;
if (subsystem_flag) {
- debug("Sending subsystem: %.*s", len, buffer_ptr(&command));
+ debug("Sending subsystem: %.*s", len, (u_char *)buffer_ptr(&command));
channel_request_start(id, "subsystem", /*want reply*/ 1);
/* register callback for reply */
/* XXX we asume that client_loop has already been called */
dispatch_set(SSH2_MSG_CHANNEL_FAILURE, &client_subsystem_reply);
dispatch_set(SSH2_MSG_CHANNEL_SUCCESS, &client_subsystem_reply);
} else {
- debug("Sending command: %.*s", len, buffer_ptr(&command));
+ debug("Sending command: %.*s", len, (u_char *)buffer_ptr(&command));
channel_request_start(id, "exec", 0);
}
packet_put_string(buffer_ptr(&command), buffer_len(&command));