GUAC-1171: Set up handler for "file" instruction for SFTP filesystem, if no other handler is more appropriate.

This commit is contained in:
Michael Jumper 2015-07-10 22:12:30 -07:00
parent 43a534c98b
commit 2e5a3606f3
8 changed files with 234 additions and 3 deletions

View File

@ -97,6 +97,12 @@ noinst_HEADERS = \
resolution.h \
unicode.h
# Build SFTP support if enabled
if ENABLE_COMMON_SSH
noinst_HEADERS += sftp.h
libguac_client_rdp_la_SOURCES += sftp.c
endif
# Add compatibility layer for WinPR if not available
if ! ENABLE_WINPR
noinst_HEADERS += compat/winpr-stream.h compat/winpr-wtypes.h

View File

@ -35,6 +35,12 @@
#include "rdp_svc.h"
#include "resolution.h"
#ifdef ENABLE_COMMON_SSH
#include "guac_sftp.h"
#include "guac_ssh.h"
#include "sftp.h"
#endif
#ifdef HAVE_FREERDP_DISPLAY_UPDATE_SUPPORT
#include "rdp_disp.h"
#endif
@ -298,6 +304,7 @@ BOOL rdp_freerdp_pre_connect(freerdp* instance) {
if (guac_client_data->settings.drive_enabled) {
guac_client_data->filesystem =
guac_rdp_fs_alloc(client, guac_client_data->settings.drive_path);
client->file_handler = guac_rdp_upload_file_handler;
}
/* If RDPDR required, load it */
@ -469,7 +476,6 @@ BOOL rdp_freerdp_post_connect(freerdp* instance) {
/* Stream handlers */
client->clipboard_handler = guac_rdp_clipboard_handler;
client->file_handler = guac_rdp_upload_file_handler;
client->pipe_handler = guac_rdp_svc_pipe_handler;
return TRUE;
@ -885,6 +891,10 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
if (guac_client_data->sftp_filesystem == NULL)
return 1;
/* Use SFTP for basic uploads, if drive not enabled */
if (!settings->drive_enabled)
client->file_handler = guac_rdp_sftp_file_handler;
guac_client_log(client, GUAC_LOG_DEBUG,
"SFTP connection succeeded.");

43
src/protocols/rdp/sftp.c Normal file
View File

@ -0,0 +1,43 @@
/*
* Copyright (C) 2015 Glyptodon LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "config.h"
#include "client.h"
#include "guac_sftp.h"
#include "sftp.h"
#include <guacamole/client.h>
#include <guacamole/stream.h>
int guac_rdp_sftp_file_handler(guac_client* client, guac_stream* stream,
char* mimetype, char* filename) {
rdp_guac_client_data* client_data = (rdp_guac_client_data*) client->data;
guac_object* filesystem = client_data->sftp_filesystem;
/* Handle file upload */
return guac_common_ssh_sftp_handle_file_stream(filesystem, stream,
mimetype, filename);
}

58
src/protocols/rdp/sftp.h Normal file
View File

@ -0,0 +1,58 @@
/*
* Copyright (C) 2015 Glyptodon LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef GUAC_RDP_SFTP_H
#define GUAC_RDP_SFTP_H
#include "config.h"
#include <guacamole/client.h>
#include <guacamole/stream.h>
/**
* Handles an incoming stream from a Guacamole "file" instruction, saving the
* contents of that stream to the file having the given name within the
* upload directory set by guac_sftp_set_upload_path().
*
* @param client
* The client receiving the uploaded file.
*
* @param stream
* The stream through which the uploaded file data will be received.
*
* @param mimetype
* The mimetype of the data being received.
*
* @param filename
* The filename of the file to write to. This filename will always be taken
* relative to the upload path set by
* guac_common_ssh_sftp_set_upload_path().
*
* @return
* Zero if the incoming stream has been handled successfully, non-zero on
* failure.
*/
int guac_rdp_sftp_file_handler(guac_client* client, guac_stream* stream,
char* mimetype, char* filename);
#endif

View File

@ -37,6 +37,12 @@ noinst_HEADERS = \
guac_handlers.h \
vnc_handlers.h
# Optional SFTP support
if ENABLE_COMMON_SSH
libguac_client_vnc_la_SOURCES += sftp.c
noinst_HEADERS += sftp.h
endif
# Optional PulseAudio support
if ENABLE_PULSE
libguac_client_vnc_la_SOURCES += pulse.c

View File

@ -28,14 +28,18 @@
#include "guac_dot_cursor.h"
#include "guac_handlers.h"
#include "guac_pointer_cursor.h"
#include "guac_sftp.h"
#include "guac_ssh.h"
#include "vnc_handlers.h"
#ifdef ENABLE_PULSE
#include "pulse.h"
#endif
#ifdef ENABLE_COMMON_SSH
#include "guac_sftp.h"
#include "guac_ssh.h"
#include "sftp.h"
#endif
#include <rfb/rfbclient.h>
#include <rfb/rfbproto.h>
#include <guacamole/client.h>
@ -421,6 +425,9 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
if (guac_client_data->sftp_filesystem == NULL)
return 1;
/* Set file handler for basic uploads */
client->file_handler = guac_vnc_sftp_file_handler;
guac_client_log(client, GUAC_LOG_DEBUG,
"SFTP connection succeeded.");

43
src/protocols/vnc/sftp.c Normal file
View File

@ -0,0 +1,43 @@
/*
* Copyright (C) 2015 Glyptodon LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "config.h"
#include "client.h"
#include "guac_sftp.h"
#include "sftp.h"
#include <guacamole/client.h>
#include <guacamole/stream.h>
int guac_vnc_sftp_file_handler(guac_client* client, guac_stream* stream,
char* mimetype, char* filename) {
vnc_guac_client_data* client_data = (vnc_guac_client_data*) client->data;
guac_object* filesystem = client_data->sftp_filesystem;
/* Handle file upload */
return guac_common_ssh_sftp_handle_file_stream(filesystem, stream,
mimetype, filename);
}

58
src/protocols/vnc/sftp.h Normal file
View File

@ -0,0 +1,58 @@
/*
* Copyright (C) 2015 Glyptodon LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef GUAC_VNC_SFTP_H
#define GUAC_VNC_SFTP_H
#include "config.h"
#include <guacamole/client.h>
#include <guacamole/stream.h>
/**
* Handles an incoming stream from a Guacamole "file" instruction, saving the
* contents of that stream to the file having the given name within the
* upload directory set by guac_sftp_set_upload_path().
*
* @param client
* The client receiving the uploaded file.
*
* @param stream
* The stream through which the uploaded file data will be received.
*
* @param mimetype
* The mimetype of the data being received.
*
* @param filename
* The filename of the file to write to. This filename will always be taken
* relative to the upload path set by
* guac_common_ssh_sftp_set_upload_path().
*
* @return
* Zero if the incoming stream has been handled successfully, non-zero on
* failure.
*/
int guac_vnc_sftp_file_handler(guac_client* client, guac_stream* stream,
char* mimetype, char* filename);
#endif