diff --git a/src/protocols/rdp/Makefile.am b/src/protocols/rdp/Makefile.am index 327cadea..1dffd4c2 100644 --- a/src/protocols/rdp/Makefile.am +++ b/src/protocols/rdp/Makefile.am @@ -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 diff --git a/src/protocols/rdp/client.c b/src/protocols/rdp/client.c index cf1b3295..03cef18a 100644 --- a/src/protocols/rdp/client.c +++ b/src/protocols/rdp/client.c @@ -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."); diff --git a/src/protocols/rdp/sftp.c b/src/protocols/rdp/sftp.c new file mode 100644 index 00000000..a394ee63 --- /dev/null +++ b/src/protocols/rdp/sftp.c @@ -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 +#include + +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); + +} + diff --git a/src/protocols/rdp/sftp.h b/src/protocols/rdp/sftp.h new file mode 100644 index 00000000..40a85fee --- /dev/null +++ b/src/protocols/rdp/sftp.h @@ -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 +#include + +/** + * 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 + diff --git a/src/protocols/vnc/Makefile.am b/src/protocols/vnc/Makefile.am index cd4a4366..db5a909d 100644 --- a/src/protocols/vnc/Makefile.am +++ b/src/protocols/vnc/Makefile.am @@ -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 diff --git a/src/protocols/vnc/client.c b/src/protocols/vnc/client.c index ce0bd55e..49c53569 100644 --- a/src/protocols/vnc/client.c +++ b/src/protocols/vnc/client.c @@ -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 #include #include @@ -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."); diff --git a/src/protocols/vnc/sftp.c b/src/protocols/vnc/sftp.c new file mode 100644 index 00000000..59866330 --- /dev/null +++ b/src/protocols/vnc/sftp.c @@ -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 +#include + +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); + +} + diff --git a/src/protocols/vnc/sftp.h b/src/protocols/vnc/sftp.h new file mode 100644 index 00000000..67651557 --- /dev/null +++ b/src/protocols/vnc/sftp.h @@ -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 +#include + +/** + * 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 +