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
*/
#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>
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,
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,
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,
}
/* 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);
*/
#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"
* 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)
* 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
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 *);
*/
#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"
/* 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);
}
/*
* 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;
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
buffer->alloc += len + 32768;
buffer->buf = xrealloc(buffer->buf, buffer->alloc);
goto restart;
+ /* NOTREACHED */
}
/* Returns the number of bytes of data in the 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",
/* Returns a pointer to the first used byte in the buffer. */
-char *
+void *
buffer_ptr(Buffer *buffer)
{
return buffer->buf + buffer->offset;
* 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. */
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);
*/
#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"
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);
}
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);
}
/* 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));
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++) {
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 */
/* 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);
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);
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);
/*
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)
*length_ptr = buffer_get_bignum2(&incoming_packet, value);
}
-char *
+void *
packet_get_raw(int *length_ptr)
{
int bytes = buffer_len(&incoming_packet);
* 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);
* 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
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);
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)));
*/
#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>
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();
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 */
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));