diff options
author | Kevin Steves <stevesk@cvs.openbsd.org> | 2001-12-19 17:16:14 +0000 |
---|---|---|
committer | Kevin Steves <stevesk@cvs.openbsd.org> | 2001-12-19 17:16:14 +0000 |
commit | fb7295d0200e1cb76061b4158bee69352ada0777 (patch) | |
tree | 0234746395c86c403c5ff9e554917845bd1d593a | |
parent | 12e3e05f75a15027550556cec07fc6ad1b331544 (diff) |
change the buffer/packet interface to use void* vs. char*; ok markus@
-rw-r--r-- | usr.bin/ssh/authfile.c | 10 | ||||
-rw-r--r-- | usr.bin/ssh/bufaux.c | 6 | ||||
-rw-r--r-- | usr.bin/ssh/bufaux.h | 4 | ||||
-rw-r--r-- | usr.bin/ssh/buffer.c | 25 | ||||
-rw-r--r-- | usr.bin/ssh/buffer.h | 12 | ||||
-rw-r--r-- | usr.bin/ssh/packet.c | 25 | ||||
-rw-r--r-- | usr.bin/ssh/packet.h | 10 | ||||
-rw-r--r-- | usr.bin/ssh/ssh.c | 10 |
8 files changed, 53 insertions, 49 deletions
diff --git a/usr.bin/ssh/authfile.c b/usr.bin/ssh/authfile.c index 476ec693a7d..0da14f25ada 100644 --- a/usr.bin/ssh/authfile.c +++ b/usr.bin/ssh/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/usr.bin/ssh/bufaux.c b/usr.bin/ssh/bufaux.c index e607f92a6cd..0fcc7296a9b 100644 --- a/usr.bin/ssh/bufaux.c +++ b/usr.bin/ssh/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" @@ -187,11 +187,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/usr.bin/ssh/bufaux.h b/usr.bin/ssh/bufaux.h index eb4f413f4fb..6606265386b 100644 --- a/usr.bin/ssh/bufaux.h +++ b/usr.bin/ssh/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 @@ -32,7 +32,7 @@ void buffer_put_int64(Buffer *, u_int64_t); 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/usr.bin/ssh/buffer.c b/usr.bin/ssh/buffer.c index 044caafb5d7..a1152d1d6f5 100644 --- a/usr.bin/ssh/buffer.c +++ b/usr.bin/ssh/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/usr.bin/ssh/buffer.h b/usr.bin/ssh/buffer.h index 845bfb69707..badd16f3bb8 100644 --- a/usr.bin/ssh/buffer.h +++ b/usr.bin/ssh/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/usr.bin/ssh/packet.c b/usr.bin/ssh/packet.c index aaa4ba07901..352bd8ccfce 100644 --- a/usr.bin/ssh/packet.c +++ b/usr.bin/ssh/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/usr.bin/ssh/packet.h b/usr.bin/ssh/packet.h index d5473001c50..d281042f1c7 100644 --- a/usr.bin/ssh/packet.h +++ b/usr.bin/ssh/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/usr.bin/ssh/ssh.c b/usr.bin/ssh/ssh.c index bed8a775ddc..4483284822c 100644 --- a/usr.bin/ssh/ssh.c +++ b/usr.bin/ssh/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> @@ -977,7 +977,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(); @@ -1006,7 +1006,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 */ @@ -1065,14 +1065,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)); |