user.c (5289B)
1/* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20#include "channels/audio-input/audio-input.h" 21#include "channels/cliprdr.h" 22#include "channels/pipe-svc.h" 23#include "common/cursor.h" 24#include "common/display.h" 25#include "config.h" 26#include "input.h" 27#include "rdp.h" 28#include "settings.h" 29#include "upload.h" 30#include "user.h" 31 32#ifdef ENABLE_COMMON_SSH 33#include "sftp.h" 34#endif 35 36#include <guacamole/argv.h> 37#include <guacamole/audio.h> 38#include <guacamole/client.h> 39#include <guacamole/protocol.h> 40#include <guacamole/socket.h> 41#include <guacamole/stream.h> 42#include <guacamole/user.h> 43 44#include <pthread.h> 45#include <stddef.h> 46 47int guac_rdp_user_join_handler(guac_user* user, int argc, char** argv) { 48 49 guac_rdp_client* rdp_client = (guac_rdp_client*) user->client->data; 50 51 /* Parse provided arguments */ 52 guac_rdp_settings* settings = guac_rdp_parse_args(user, 53 argc, (const char**) argv); 54 55 /* Fail if settings cannot be parsed */ 56 if (settings == NULL) { 57 guac_user_log(user, GUAC_LOG_INFO, 58 "Badly formatted client arguments."); 59 return 1; 60 } 61 62 /* Store settings at user level */ 63 user->data = settings; 64 65 /* Connect via RDP if owner */ 66 if (user->owner) { 67 68 /* Store owner's settings at client level */ 69 rdp_client->settings = settings; 70 71 /* Start client thread */ 72 if (pthread_create(&rdp_client->client_thread, NULL, 73 guac_rdp_client_thread, user->client)) { 74 guac_user_log(user, GUAC_LOG_ERROR, 75 "Unable to start RDP client thread."); 76 return 1; 77 } 78 79 /* Handle inbound audio streams if audio input is enabled */ 80 if (settings->enable_audio_input) 81 user->audio_handler = guac_rdp_audio_handler; 82 83 } 84 85 /* Only handle events if not read-only */ 86 if (!settings->read_only) { 87 88 /* General mouse/keyboard events */ 89 user->mouse_handler = guac_rdp_user_mouse_handler; 90 user->key_handler = guac_rdp_user_key_handler; 91 92 /* Multi-touch events */ 93 if (settings->enable_touch) 94 user->touch_handler = guac_rdp_user_touch_handler; 95 96 /* Inbound (client to server) clipboard transfer */ 97 if (!settings->disable_paste) 98 user->clipboard_handler = guac_rdp_clipboard_handler; 99 100 /* Display size change events */ 101 user->size_handler = guac_rdp_user_size_handler; 102 103 /* Set generic (non-filesystem) file upload handler */ 104 user->file_handler = guac_rdp_user_file_handler; 105 106 /* Inbound arbitrary named pipes */ 107 user->pipe_handler = guac_rdp_pipe_svc_pipe_handler; 108 109 /* If we own it, register handler for updating parameters during connection. */ 110 if (user->owner) 111 user->argv_handler = guac_argv_handler; 112 113 } 114 115 return 0; 116 117} 118 119int guac_rdp_user_file_handler(guac_user* user, guac_stream* stream, 120 char* mimetype, char* filename) { 121 122 guac_rdp_client* rdp_client = (guac_rdp_client*) user->client->data; 123 guac_rdp_settings* settings = rdp_client->settings; 124 125#ifdef ENABLE_COMMON_SSH 126 127 /* If SFTP is enabled and SFTP uploads have not been disabled, it should be 128 * used for default uploads only if RDPDR is not enabled or its upload 129 * directory has been set */ 130 if (rdp_client->sftp_filesystem != NULL && !settings->sftp_disable_upload) { 131 if (!settings->drive_enabled || settings->sftp_directory != NULL) 132 return guac_rdp_sftp_file_handler(user, stream, mimetype, filename); 133 } 134#endif 135 136 /* Default to using RDPDR uploads (if enabled) */ 137 if (rdp_client->filesystem != NULL && !settings->disable_upload) 138 return guac_rdp_upload_file_handler(user, stream, mimetype, filename); 139 140 /* File transfer not enabled */ 141 guac_protocol_send_ack(user->socket, stream, "File transfer disabled", 142 GUAC_PROTOCOL_STATUS_UNSUPPORTED); 143 guac_socket_flush(user->socket); 144 145 return 0; 146} 147 148int guac_rdp_user_leave_handler(guac_user* user) { 149 150 guac_rdp_client* rdp_client = (guac_rdp_client*) user->client->data; 151 152 /* Update shared cursor state if the display still exists */ 153 if (rdp_client->display != NULL) 154 guac_common_cursor_remove_user(rdp_client->display->cursor, user); 155 156 /* Free settings if not owner (owner settings will be freed with client) */ 157 if (!user->owner) { 158 guac_rdp_settings* settings = (guac_rdp_settings*) user->data; 159 guac_rdp_settings_free(settings); 160 } 161 162 return 0; 163} 164