aboutsummaryrefslogtreecommitdiff
path: root/libssh/messages.c
diff options
context:
space:
mode:
authorPreston A. Elder <prez@neuromancy.net>2009-07-28 10:21:40 -0700
committerAndreas Schneider <mail@cynapses.org>2009-07-29 18:41:48 +0200
commit4f70cc13e2aa28657e40f91dfcf03dd9c82a41e9 (patch)
tree5fd13768b42e2b0c93cc16f5f97a0f0a26088fa3 /libssh/messages.c
parentb4111c5c187cf9212eba0ae459edb630dbddb656 (diff)
downloadlibssh-4f70cc13e2aa28657e40f91dfcf03dd9c82a41e9.tar.gz
libssh-4f70cc13e2aa28657e40f91dfcf03dd9c82a41e9.tar.xz
libssh-4f70cc13e2aa28657e40f91dfcf03dd9c82a41e9.zip
Fleshed out server interface
- Enables channel_request_open types of DIRECT_TCPIP, FORWARDED_TCPIP and X11 (ie. implemented the handling of those channel_request_open types). - Adds functions to retrieve the extra information relating to channel_request_open messages and channel_request messages. - Adds a channel_write_stderr method (obviously for writing to the STDERR channel from server side) - well, technically just converted the exiting channel_write to take an extra argument and created two wrapper functions. - Actually does the invoking of message_handle() from channel_recv_request. - Implemented the handling of the window-change and env channel_requests. - Implemented a few functions in server.h that were declared but not defined (eg. ssh_message_channel_request_channel). Signed-off-by: Preston A. Elder <prez@neuromancy.net> Signed-off-by: Andreas Schneider <mail@cynapses.org>
Diffstat (limited to 'libssh/messages.c')
-rw-r--r--libssh/messages.c200
1 files changed, 198 insertions, 2 deletions
diff --git a/libssh/messages.c b/libssh/messages.c
index 151cdd7f..e5ddeab7 100644
--- a/libssh/messages.c
+++ b/libssh/messages.c
@@ -425,9 +425,9 @@ int ssh_message_auth_reply_pk_ok(SSH_MESSAGE *msg, ssh_string algo, ssh_string p
static SSH_MESSAGE *handle_channel_request_open(SSH_SESSION *session) {
SSH_MESSAGE *msg = NULL;
- ssh_string type = NULL;
+ ssh_string type = NULL, *originator = NULL, *destination = NULL;
char *type_c = NULL;
- uint32_t sender, window, packet;
+ uint32_t sender, window, packet, originator_port, destination_port;
enter_function();
@@ -467,6 +467,97 @@ static SSH_MESSAGE *handle_channel_request_open(SSH_SESSION *session) {
return msg;
}
+ if (strcmp(type_c,"direct-tcpip") == 0) {
+ destination = buffer_get_ssh_string(session->in_buffer);
+ if (destination == NULL) {
+ goto error;
+ }
+ msg->channel_request_open.destination = string_to_char(type);
+ if (msg->channel_request_open.destination == NULL) {
+ string_free(destination);
+ goto error;
+ }
+ string_free(destination);
+
+ buffer_get_u32(session->in_buffer, &destination_port);
+ msg->channel_request_open.destination_port = ntohl(destination_port);
+
+ originator = buffer_get_ssh_string(session->in_buffer);
+ if (originator == NULL) {
+ goto error;
+ }
+ msg->channel_request_open.originator = string_to_char(type);
+ if (msg->channel_request_open.originator == NULL) {
+ string_free(originator);
+ goto error;
+ }
+ string_free(originator);
+
+ buffer_get_u32(session->in_buffer, &originator_port);
+ msg->channel_request_open.originator_port = ntohl(originator_port);
+
+ msg->channel_request_open.type = SSH_CHANNEL_DIRECT_TCPIP;
+ SAFE_FREE(type_c);
+ leave_function();
+ return msg;
+ }
+
+ if (strcmp(type_c,"forwarded-tcpip") == 0) {
+ destination = buffer_get_ssh_string(session->in_buffer);
+ if (destination == NULL) {
+ goto error;
+ }
+ msg->channel_request_open.destination = string_to_char(type);
+ if (msg->channel_request_open.destination == NULL) {
+ string_free(destination);
+ goto error;
+ }
+ string_free(destination);
+
+ buffer_get_u32(session->in_buffer, &destination_port);
+ msg->channel_request_open.destination_port = ntohl(destination_port);
+
+ originator = buffer_get_ssh_string(session->in_buffer);
+ if (originator == NULL) {
+ goto error;
+ }
+ msg->channel_request_open.originator = string_to_char(type);
+ if (msg->channel_request_open.originator == NULL) {
+ string_free(originator);
+ goto error;
+ }
+ string_free(originator);
+
+ buffer_get_u32(session->in_buffer, &originator_port);
+ msg->channel_request_open.originator_port = ntohl(originator_port);
+
+ msg->channel_request_open.type = SSH_CHANNEL_FORWARDED_TCPIP;
+ SAFE_FREE(type_c);
+ leave_function();
+ return msg;
+ }
+
+ if (strcmp(type_c,"x11") == 0) {
+ originator = buffer_get_ssh_string(session->in_buffer);
+ if (originator == NULL) {
+ goto error;
+ }
+ msg->channel_request_open.originator = string_to_char(type);
+ if (msg->channel_request_open.originator == NULL) {
+ string_free(originator);
+ goto error;
+ }
+ string_free(originator);
+
+ buffer_get_u32(session->in_buffer, &originator_port);
+ msg->channel_request_open.originator_port = ntohl(originator_port);
+
+ msg->channel_request_open.type = SSH_CHANNEL_X11;
+ SAFE_FREE(type_c);
+ leave_function();
+ return msg;
+ }
+
msg->channel_request_open.type = SSH_CHANNEL_UNKNOWN;
SAFE_FREE(type_c);
@@ -642,6 +733,26 @@ static SSH_MESSAGE *handle_channel_request(SSH_SESSION *session) {
return msg;
}
+ if (strcmp(type_c, "window-change") == 0) {
+ STRING *term = NULL;
+ SAFE_FREE(type_c);
+
+ msg->channel_request.type = SSH_CHANNEL_REQUEST_WINDOW_CHANGE;
+
+ buffer_get_u32(session->in_buffer, &msg->channel_request.width);
+ buffer_get_u32(session->in_buffer, &msg->channel_request.height);
+ buffer_get_u32(session->in_buffer, &msg->channel_request.pxwidth);
+ buffer_get_u32(session->in_buffer, &msg->channel_request.pxheight);
+
+ msg->channel_request.width = ntohl(msg->channel_request.width);
+ msg->channel_request.height = ntohl(msg->channel_request.height);
+ msg->channel_request.pxwidth = ntohl(msg->channel_request.pxwidth);
+ msg->channel_request.pxheight = ntohl(msg->channel_request.pxheight);
+
+ leave_function();
+ return msg;
+ }
+
if (strcmp(type_c, "subsystem") == 0) {
ssh_string subsys = NULL;
char *subsys_c = NULL;
@@ -673,6 +784,7 @@ static SSH_MESSAGE *handle_channel_request(SSH_SESSION *session) {
leave_function();
return msg;
}
+
if (strcmp(type_c, "exec") == 0) {
ssh_string cmd = NULL;
@@ -695,6 +807,38 @@ static SSH_MESSAGE *handle_channel_request(SSH_SESSION *session) {
return msg;
}
+ if (strcmp(type_c, "env") == 0) {
+ STRING *name = NULL;
+ STRING *value = NULL;
+
+ SAFE_FREE(type_c);
+
+ name = buffer_get_ssh_string(session->in_buffer);
+ if (name == NULL) {
+ goto error;
+ }
+ value = buffer_get_ssh_string(session->in_buffer);
+ if (value == NULL) {
+ string_free(name);
+ goto error;
+ }
+
+ msg->channel_request.type = SSH_CHANNEL_REQUEST_ENV;
+ msg->channel_request.var_name = string_to_char(name);
+ msg->channel_request.var_value = string_to_char(value);
+ if (msg->channel_request.var_name == NULL ||
+ msg->channel_request.var_value == NULL) {
+ string_free(name);
+ string_free(value);
+ goto error;
+ }
+ string_free(name);
+ string_free(value);
+
+ leave_function();
+ return msg;
+ }
+
msg->channel_request.type = SSH_CHANNEL_UNKNOWN;
SAFE_FREE(type_c);
@@ -709,6 +853,58 @@ error:
return NULL;
}
+char *ssh_message_channel_request_open_originator(SSH_MESSAGE *msg){
+ return msg->channel_request_open.originator;
+}
+
+int ssh_message_channel_request_open_originator_port(SSH_MESSAGE *msg){
+ return msg->channel_request_open.originator_port;
+}
+
+char *ssh_message_channel_request_open_destination(SSH_MESSAGE *msg){
+ return msg->channel_request_open.destination;
+}
+
+int ssh_message_channel_request_open_destination_port(SSH_MESSAGE *msg){
+ return msg->channel_request_open.destination_port;
+}
+
+CHANNEL *ssh_message_channel_request_channel(SSH_MESSAGE *msg){
+ return msg->channel_request.channel;
+}
+
+char *ssh_message_channel_request_pty_term(SSH_MESSAGE *msg){
+ return msg->channel_request.TERM;
+}
+
+int ssh_message_channel_request_pty_width(SSH_MESSAGE *msg){
+ return msg->channel_request.width;
+}
+
+int ssh_message_channel_request_pty_height(SSH_MESSAGE *msg){
+ return msg->channel_request.height;
+}
+
+int ssh_message_channel_request_pty_pxwidth(SSH_MESSAGE *msg){
+ return msg->channel_request.pxwidth;
+}
+
+int ssh_message_channel_request_pty_pxheight(SSH_MESSAGE *msg){
+ return msg->channel_request.pxheight;
+}
+
+char *ssh_message_channel_request_env_name(SSH_MESSAGE *msg){
+ return msg->channel_request.var_name;
+}
+
+char *ssh_message_channel_request_env_value(SSH_MESSAGE *msg){
+ return msg->channel_request.var_value;
+}
+
+char *ssh_message_channel_request_command(SSH_MESSAGE *msg){
+ return msg->channel_request.command;
+}
+
char *ssh_message_channel_request_subsystem(SSH_MESSAGE *msg){
return msg->channel_request.subsystem;
}