summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2013-05-21 15:27:20 +0200
committerAndreas Schneider <asn@cryptomilk.org>2013-07-13 14:59:21 +0200
commitdb20a22e51d578de1bb3b9edd240296091c3dc94 (patch)
tree2c6a8087828aec90f8f3572fd32bcf56cb7cb300
parent560b5087714e793ccb8a2776e2ec1fdbd8b8ee3f (diff)
downloadlibssh-db20a22e51d578de1bb3b9edd240296091c3dc94.tar.gz
libssh-db20a22e51d578de1bb3b9edd240296091c3dc94.tar.xz
libssh-db20a22e51d578de1bb3b9edd240296091c3dc94.zip
server: added 2 missing channel callbacks
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r--include/libssh/callbacks.h41
-rw-r--r--src/messages.c22
2 files changed, 62 insertions, 1 deletions
diff --git a/include/libssh/callbacks.h b/include/libssh/callbacks.h
index 8804370..a838bdc 100644
--- a/include/libssh/callbacks.h
+++ b/include/libssh/callbacks.h
@@ -540,6 +540,37 @@ typedef int (*ssh_channel_pty_window_change_callback) (ssh_session session,
int pxwidth, int pwheight,
void *userdata);
+/**
+ * @brief SSH channel Exec request from a client.
+ * @param channel the channel
+ * @param command the shell command to be executed
+ * @param userdata Userdata to be passed to the callback function.
+ * @returns 0 if the exec request is accepted
+ * @returns 1 if the request is denied
+ */
+typedef int (*ssh_channel_exec_request_callback) (ssh_session session,
+ ssh_channel channel,
+ const char *command,
+ void *userdata);
+
+/**
+ * @brief SSH channel environment request from a client.
+ * @param channel the channel
+ * @param env_name name of the environment value to be set
+ * @param env_value value of the environment value to be set
+ * @param userdata Userdata to be passed to the callback function.
+ * @returns 0 if the env request is accepted
+ * @returns 1 if the request is denied
+ * @warning some environment variables can be dangerous if changed (e.g.
+ * LD_PRELOAD) and should not be fulfilled.
+ */
+typedef int (*ssh_channel_env_request_callback) (ssh_session session,
+ ssh_channel channel,
+ const char *env_name,
+ const char *env_value,
+ void *userdata);
+
+
struct ssh_channel_callbacks_struct {
/** DON'T SET THIS use ssh_callbacks_init() instead. */
size_t size;
@@ -591,8 +622,16 @@ struct ssh_channel_callbacks_struct {
* window change.
*/
ssh_channel_pty_window_change_callback channel_pty_window_change_function;
-
+ /** This function will be called when a client requests a
+ * command execution.
+ */
+ ssh_channel_exec_request_callback channel_exec_request_function;
+ /** This function will be called when a client requests an environment
+ * variable to be set.
+ */
+ ssh_channel_env_request_callback channel_env_request_function;
};
+
typedef struct ssh_channel_callbacks_struct *ssh_channel_callbacks;
/**
diff --git a/src/messages.c b/src/messages.c
index 4e55056..450b323 100644
--- a/src/messages.c
+++ b/src/messages.c
@@ -176,6 +176,28 @@ static int ssh_execute_server_callbacks(ssh_session session, ssh_message msg){
msg->channel_request.pxheight, msg->channel_request.pxwidth,
channel->callbacks->userdata);
}
+ } else if(msg->channel_request.type == SSH_CHANNEL_REQUEST_EXEC ){
+ if(ssh_callbacks_exists(channel->callbacks, channel_exec_request_function)){
+ rc = channel->callbacks->channel_exec_request_function(session, channel,
+ msg->channel_request.command,
+ channel->callbacks->userdata);
+ if(rc == 0)
+ ssh_message_channel_request_reply_success(msg);
+ else
+ ssh_message_reply_default(msg);
+ return SSH_OK;
+ }
+ } else if(msg->channel_request.type == SSH_CHANNEL_REQUEST_ENV){
+ if(ssh_callbacks_exists(channel->callbacks, channel_env_request_function)){
+ rc = channel->callbacks->channel_env_request_function(session, channel,
+ msg->channel_request.var_name, msg->channel_request.var_value,
+ channel->callbacks->userdata);
+ if(rc == 0)
+ ssh_message_channel_request_reply_success(msg);
+ else
+ ssh_message_reply_default(msg);
+ return SSH_OK;
+ }
}
break;
case SSH_REQUEST_SERVICE: