GUACAMOLE-574: Redirect STDIN from pipe stream named "STDIN" for SSH and telnet.

This commit is contained in:
Michael Jumper 2018-05-19 14:32:30 -07:00
parent 97593958e4
commit b650bef139
8 changed files with 196 additions and 0 deletions

View File

@ -26,6 +26,7 @@ libguac_client_ssh_la_SOURCES = \
client.c \
clipboard.c \
input.c \
pipe.c \
settings.c \
sftp.c \
ssh.c \
@ -36,6 +37,7 @@ noinst_HEADERS = \
client.h \
clipboard.h \
input.h \
pipe.h \
settings.h \
sftp.h \
ssh.h \

50
src/protocols/ssh/pipe.c Normal file
View File

@ -0,0 +1,50 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#include "config.h"
#include "pipe.h"
#include "ssh.h"
#include "terminal/terminal.h"
#include <guacamole/protocol.h>
#include <guacamole/socket.h>
#include <guacamole/user.h>
#include <string.h>
int guac_ssh_pipe_handler(guac_user* user, guac_stream* stream,
char* mimetype, char* name) {
guac_client* client = user->client;
guac_ssh_client* ssh_client = (guac_ssh_client*) client->data;
/* Redirect STDIN if pipe has required name */
if (strcmp(name, GUAC_SSH_STDIN_PIPE_NAME) == 0) {
guac_terminal_send_stream(ssh_client->term, user, stream);
return 0;
}
/* No other inbound pipe streams are supported */
guac_protocol_send_ack(user->socket, stream, "No such input stream.",
GUAC_PROTOCOL_STATUS_RESOURCE_NOT_FOUND);
guac_socket_flush(user->socket);
return 0;
}

42
src/protocols/ssh/pipe.h Normal file
View File

@ -0,0 +1,42 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#ifndef GUAC_SSH_PIPE_H
#define GUAC_SSH_PIPE_H
#include "config.h"
#include <guacamole/user.h>
/**
* The name reserved for the inbound pipe stream which forces the terminal
* emulator's STDIN to be received from the pipe.
*/
#define GUAC_SSH_STDIN_PIPE_NAME "STDIN"
/**
* Handles an incoming stream from a Guacamole "pipe" instruction. If the pipe
* is named "STDIN", the the contents of the pipe stream are redirected to
* STDIN of the terminal emulator for as long as the pipe is open.
*/
guac_user_pipe_handler guac_ssh_pipe_handler;
#endif

View File

@ -23,6 +23,7 @@
#include "common/display.h"
#include "input.h"
#include "user.h"
#include "pipe.h"
#include "sftp.h"
#include "ssh.h"
#include "settings.h"
@ -83,6 +84,9 @@ int guac_ssh_user_join_handler(guac_user* user, int argc, char** argv) {
user->mouse_handler = guac_ssh_user_mouse_handler;
user->clipboard_handler = guac_ssh_clipboard_handler;
/* STDIN redirection */
user->pipe_handler = guac_ssh_pipe_handler;
/* Display size change events */
user->size_handler = guac_ssh_user_size_handler;

View File

@ -26,6 +26,7 @@ libguac_client_telnet_la_SOURCES = \
client.c \
clipboard.c \
input.c \
pipe.c \
settings.c \
telnet.c \
user.c
@ -34,6 +35,7 @@ noinst_HEADERS = \
client.h \
clipboard.h \
input.h \
pipe.h \
settings.h \
telnet.h \
user.h

View File

@ -0,0 +1,50 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#include "config.h"
#include "pipe.h"
#include "telnet.h"
#include "terminal/terminal.h"
#include <guacamole/protocol.h>
#include <guacamole/socket.h>
#include <guacamole/user.h>
#include <string.h>
int guac_telnet_pipe_handler(guac_user* user, guac_stream* stream,
char* mimetype, char* name) {
guac_client* client = user->client;
guac_telnet_client* telnet_client = (guac_telnet_client*) client->data;
/* Redirect STDIN if pipe has required name */
if (strcmp(name, GUAC_TELNET_STDIN_PIPE_NAME) == 0) {
guac_terminal_send_stream(telnet_client->term, user, stream);
return 0;
}
/* No other inbound pipe streams are supported */
guac_protocol_send_ack(user->socket, stream, "No such input stream.",
GUAC_PROTOCOL_STATUS_RESOURCE_NOT_FOUND);
guac_socket_flush(user->socket);
return 0;
}

View File

@ -0,0 +1,42 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#ifndef GUAC_TELNET_PIPE_H
#define GUAC_TELNET_PIPE_H
#include "config.h"
#include <guacamole/user.h>
/**
* The name reserved for the inbound pipe stream which forces the terminal
* emulator's STDIN to be received from the pipe.
*/
#define GUAC_TELNET_STDIN_PIPE_NAME "STDIN"
/**
* Handles an incoming stream from a Guacamole "pipe" instruction. If the pipe
* is named "STDIN", the the contents of the pipe stream are redirected to
* STDIN of the terminal emulator for as long as the pipe is open.
*/
guac_user_pipe_handler guac_telnet_pipe_handler;
#endif

View File

@ -21,6 +21,7 @@
#include "clipboard.h"
#include "input.h"
#include "pipe.h"
#include "settings.h"
#include "telnet.h"
#include "terminal/terminal.h"
@ -82,6 +83,9 @@ int guac_telnet_user_join_handler(guac_user* user, int argc, char** argv) {
user->mouse_handler = guac_telnet_user_mouse_handler;
user->clipboard_handler = guac_telnet_clipboard_handler;
/* STDIN redirection */
user->pipe_handler = guac_telnet_pipe_handler;
/* Display size change events */
user->size_handler = guac_telnet_user_size_handler;