settings.c (14471B)
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 "argv.h" 21#include "settings.h" 22#include "terminal/terminal.h" 23 24#include <guacamole/mem.h> 25#include <guacamole/user.h> 26 27#include <stdlib.h> 28 29/* Client plugin arguments */ 30const char* GUAC_KUBERNETES_CLIENT_ARGS[] = { 31 "hostname", 32 "port", 33 "namespace", 34 "pod", 35 "container", 36 "exec-command", 37 "use-ssl", 38 "client-cert", 39 "client-key", 40 "ca-cert", 41 "ignore-cert", 42 GUAC_KUBERNETES_ARGV_FONT_NAME, 43 GUAC_KUBERNETES_ARGV_FONT_SIZE, 44 GUAC_KUBERNETES_ARGV_COLOR_SCHEME, 45 "typescript-path", 46 "typescript-name", 47 "create-typescript-path", 48 "recording-path", 49 "recording-name", 50 "recording-exclude-output", 51 "recording-exclude-mouse", 52 "recording-include-keys", 53 "create-recording-path", 54 "read-only", 55 "backspace", 56 "scrollback", 57 "disable-copy", 58 "disable-paste", 59 NULL 60}; 61 62enum KUBERNETES_ARGS_IDX { 63 64 /** 65 * The hostname to connect to. Required. 66 */ 67 IDX_HOSTNAME, 68 69 /** 70 * The port to connect to. Optional. 71 */ 72 IDX_PORT, 73 74 /** 75 * The name of the Kubernetes namespace of the pod containing the container 76 * being attached to. If omitted, the default namespace will be used. 77 */ 78 IDX_NAMESPACE, 79 80 /** 81 * The name of the Kubernetes pod containing with the container being 82 * attached to. Required. 83 */ 84 IDX_POD, 85 86 /** 87 * The name of the container to attach to. If omitted, the first container 88 * in the pod will be used. 89 */ 90 IDX_CONTAINER, 91 92 /** 93 * The command used by exec call. If omitted, attach call will be used. 94 */ 95 IDX_EXEC_COMMAND, 96 97 /** 98 * Whether SSL/TLS should be used. If omitted, SSL/TLS will not be used. 99 */ 100 IDX_USE_SSL, 101 102 /** 103 * The certificate to use if performing SSL/TLS client authentication to 104 * authenticate with the Kubernetes server, in PEM format. If omitted, SSL 105 * client authentication will not be performed. 106 */ 107 IDX_CLIENT_CERT, 108 109 /** 110 * The key to use if performing SSL/TLS client authentication to 111 * authenticate with the Kubernetes server, in PEM format. If omitted, SSL 112 * client authentication will not be performed. 113 */ 114 IDX_CLIENT_KEY, 115 116 /** 117 * The certificate of the certificate authority that signed the certificate 118 * of the Kubernetes server, in PEM format. If omitted. verification of 119 * the Kubernetes server certificate will use the systemwide certificate 120 * authorities. 121 */ 122 IDX_CA_CERT, 123 124 /** 125 * Whether the certificate used by the Kubernetes server for SSL/TLS should 126 * be ignored if it cannot be validated. 127 */ 128 IDX_IGNORE_CERT, 129 130 /** 131 * The name of the font to use within the terminal. 132 */ 133 IDX_FONT_NAME, 134 135 /** 136 * The size of the font to use within the terminal, in points. 137 */ 138 IDX_FONT_SIZE, 139 140 /** 141 * The color scheme to use, as a series of semicolon-separated color-value 142 * pairs: "background: <color>", "foreground: <color>", or 143 * "color<n>: <color>", where <n> is a number from 0 to 255, and <color> is 144 * "color<n>" or an X11 color code (e.g. "aqua" or "rgb:12/34/56"). 145 * The color scheme can also be one of the special values: "black-white", 146 * "white-black", "gray-black", or "green-black". 147 */ 148 IDX_COLOR_SCHEME, 149 150 /** 151 * The full absolute path to the directory in which typescripts should be 152 * written. 153 */ 154 IDX_TYPESCRIPT_PATH, 155 156 /** 157 * The name that should be given to typescripts which are written in the 158 * given path. Each typescript will consist of two files: "NAME" and 159 * "NAME.timing". 160 */ 161 IDX_TYPESCRIPT_NAME, 162 163 /** 164 * Whether the specified typescript path should automatically be created 165 * if it does not yet exist. 166 */ 167 IDX_CREATE_TYPESCRIPT_PATH, 168 169 /** 170 * The full absolute path to the directory in which screen recordings 171 * should be written. 172 */ 173 IDX_RECORDING_PATH, 174 175 /** 176 * The name that should be given to screen recordings which are written in 177 * the given path. 178 */ 179 IDX_RECORDING_NAME, 180 181 /** 182 * Whether output which is broadcast to each connected client (graphics, 183 * streams, etc.) should NOT be included in the session recording. Output 184 * is included by default, as it is necessary for any recording which must 185 * later be viewable as video. 186 */ 187 IDX_RECORDING_EXCLUDE_OUTPUT, 188 189 /** 190 * Whether changes to mouse state, such as position and buttons pressed or 191 * released, should NOT be included in the session recording. Mouse state 192 * is included by default, as it is necessary for the mouse cursor to be 193 * rendered in any resulting video. 194 */ 195 IDX_RECORDING_EXCLUDE_MOUSE, 196 197 /** 198 * Whether keys pressed and released should be included in the session 199 * recording. Key events are NOT included by default within the recording, 200 * as doing so has privacy and security implications. Including key events 201 * may be necessary in certain auditing contexts, but should only be done 202 * with caution. Key events can easily contain sensitive information, such 203 * as passwords, credit card numbers, etc. 204 */ 205 IDX_RECORDING_INCLUDE_KEYS, 206 207 /** 208 * Whether the specified screen recording path should automatically be 209 * created if it does not yet exist. 210 */ 211 IDX_CREATE_RECORDING_PATH, 212 213 /** 214 * "true" if this connection should be read-only (user input should be 215 * dropped), "false" or blank otherwise. 216 */ 217 IDX_READ_ONLY, 218 219 /** 220 * ASCII code, as an integer to use for the backspace key, or 221 * GUAC_TERMINAL_DEFAULT_BACKSPACE if not specified. 222 */ 223 IDX_BACKSPACE, 224 225 /** 226 * The maximum size of the scrollback buffer in rows. 227 */ 228 IDX_SCROLLBACK, 229 230 /** 231 * Whether outbound clipboard access should be blocked. If set to "true", 232 * it will not be possible to copy data from the terminal to the client 233 * using the clipboard. By default, clipboard access is not blocked. 234 */ 235 IDX_DISABLE_COPY, 236 237 /** 238 * Whether inbound clipboard access should be blocked. If set to "true", it 239 * will not be possible to paste data from the client to the terminal using 240 * the clipboard. By default, clipboard access is not blocked. 241 */ 242 IDX_DISABLE_PASTE, 243 244 KUBERNETES_ARGS_COUNT 245}; 246 247guac_kubernetes_settings* guac_kubernetes_parse_args(guac_user* user, 248 int argc, const char** argv) { 249 250 /* Validate arg count */ 251 if (argc != KUBERNETES_ARGS_COUNT) { 252 guac_user_log(user, GUAC_LOG_WARNING, "Incorrect number of connection " 253 "parameters provided: expected %i, got %i.", 254 KUBERNETES_ARGS_COUNT, argc); 255 return NULL; 256 } 257 258 guac_kubernetes_settings* settings = 259 guac_mem_zalloc(sizeof(guac_kubernetes_settings)); 260 261 /* Read hostname */ 262 settings->hostname = 263 guac_user_parse_args_string(user, GUAC_KUBERNETES_CLIENT_ARGS, argv, 264 IDX_HOSTNAME, ""); 265 266 /* Read port */ 267 settings->port = 268 guac_user_parse_args_int(user, GUAC_KUBERNETES_CLIENT_ARGS, argv, 269 IDX_PORT, GUAC_KUBERNETES_DEFAULT_PORT); 270 271 /* Read Kubernetes namespace */ 272 settings->kubernetes_namespace = 273 guac_user_parse_args_string(user, GUAC_KUBERNETES_CLIENT_ARGS, argv, 274 IDX_NAMESPACE, GUAC_KUBERNETES_DEFAULT_NAMESPACE); 275 276 /* Read name of Kubernetes pod (required) */ 277 settings->kubernetes_pod = 278 guac_user_parse_args_string(user, GUAC_KUBERNETES_CLIENT_ARGS, argv, 279 IDX_POD, NULL); 280 281 /* Read container of pod (optional) */ 282 settings->kubernetes_container = 283 guac_user_parse_args_string(user, GUAC_KUBERNETES_CLIENT_ARGS, argv, 284 IDX_CONTAINER, NULL); 285 286 /* Read exec command (optional) */ 287 settings->exec_command = 288 guac_user_parse_args_string(user, GUAC_KUBERNETES_CLIENT_ARGS, argv, 289 IDX_EXEC_COMMAND, NULL); 290 291 /* Parse whether SSL should be used */ 292 settings->use_ssl = 293 guac_user_parse_args_boolean(user, GUAC_KUBERNETES_CLIENT_ARGS, argv, 294 IDX_USE_SSL, false); 295 296 /* Read SSL/TLS connection details only if enabled */ 297 if (settings->use_ssl) { 298 299 settings->client_cert = 300 guac_user_parse_args_string(user, GUAC_KUBERNETES_CLIENT_ARGS, 301 argv, IDX_CLIENT_CERT, NULL); 302 303 settings->client_key = 304 guac_user_parse_args_string(user, GUAC_KUBERNETES_CLIENT_ARGS, 305 argv, IDX_CLIENT_KEY, NULL); 306 307 settings->ca_cert = 308 guac_user_parse_args_string(user, GUAC_KUBERNETES_CLIENT_ARGS, 309 argv, IDX_CA_CERT, NULL); 310 311 settings->ignore_cert = 312 guac_user_parse_args_boolean(user, GUAC_KUBERNETES_CLIENT_ARGS, 313 argv, IDX_IGNORE_CERT, false); 314 315 } 316 317 /* Read-only mode */ 318 settings->read_only = 319 guac_user_parse_args_boolean(user, GUAC_KUBERNETES_CLIENT_ARGS, argv, 320 IDX_READ_ONLY, false); 321 322 /* Read maximum scrollback size */ 323 settings->max_scrollback = 324 guac_user_parse_args_int(user, GUAC_KUBERNETES_CLIENT_ARGS, argv, 325 IDX_SCROLLBACK, GUAC_TERMINAL_DEFAULT_MAX_SCROLLBACK); 326 327 /* Read font name */ 328 settings->font_name = 329 guac_user_parse_args_string(user, GUAC_KUBERNETES_CLIENT_ARGS, argv, 330 IDX_FONT_NAME, GUAC_TERMINAL_DEFAULT_FONT_NAME); 331 332 /* Read font size */ 333 settings->font_size = 334 guac_user_parse_args_int(user, GUAC_KUBERNETES_CLIENT_ARGS, argv, 335 IDX_FONT_SIZE, GUAC_TERMINAL_DEFAULT_FONT_SIZE); 336 337 /* Copy requested color scheme */ 338 settings->color_scheme = 339 guac_user_parse_args_string(user, GUAC_KUBERNETES_CLIENT_ARGS, argv, 340 IDX_COLOR_SCHEME, GUAC_TERMINAL_DEFAULT_COLOR_SCHEME); 341 342 /* Pull width/height/resolution directly from user */ 343 settings->width = user->info.optimal_width; 344 settings->height = user->info.optimal_height; 345 settings->resolution = user->info.optimal_resolution; 346 347 /* Read typescript path */ 348 settings->typescript_path = 349 guac_user_parse_args_string(user, GUAC_KUBERNETES_CLIENT_ARGS, argv, 350 IDX_TYPESCRIPT_PATH, NULL); 351 352 /* Read typescript name */ 353 settings->typescript_name = 354 guac_user_parse_args_string(user, GUAC_KUBERNETES_CLIENT_ARGS, argv, 355 IDX_TYPESCRIPT_NAME, GUAC_KUBERNETES_DEFAULT_TYPESCRIPT_NAME); 356 357 /* Parse path creation flag */ 358 settings->create_typescript_path = 359 guac_user_parse_args_boolean(user, GUAC_KUBERNETES_CLIENT_ARGS, argv, 360 IDX_CREATE_TYPESCRIPT_PATH, false); 361 362 /* Read recording path */ 363 settings->recording_path = 364 guac_user_parse_args_string(user, GUAC_KUBERNETES_CLIENT_ARGS, argv, 365 IDX_RECORDING_PATH, NULL); 366 367 /* Read recording name */ 368 settings->recording_name = 369 guac_user_parse_args_string(user, GUAC_KUBERNETES_CLIENT_ARGS, argv, 370 IDX_RECORDING_NAME, GUAC_KUBERNETES_DEFAULT_RECORDING_NAME); 371 372 /* Parse output exclusion flag */ 373 settings->recording_exclude_output = 374 guac_user_parse_args_boolean(user, GUAC_KUBERNETES_CLIENT_ARGS, argv, 375 IDX_RECORDING_EXCLUDE_OUTPUT, false); 376 377 /* Parse mouse exclusion flag */ 378 settings->recording_exclude_mouse = 379 guac_user_parse_args_boolean(user, GUAC_KUBERNETES_CLIENT_ARGS, argv, 380 IDX_RECORDING_EXCLUDE_MOUSE, false); 381 382 /* Parse key event inclusion flag */ 383 settings->recording_include_keys = 384 guac_user_parse_args_boolean(user, GUAC_KUBERNETES_CLIENT_ARGS, argv, 385 IDX_RECORDING_INCLUDE_KEYS, false); 386 387 /* Parse path creation flag */ 388 settings->create_recording_path = 389 guac_user_parse_args_boolean(user, GUAC_KUBERNETES_CLIENT_ARGS, argv, 390 IDX_CREATE_RECORDING_PATH, false); 391 392 /* Parse backspace key code */ 393 settings->backspace = 394 guac_user_parse_args_int(user, GUAC_KUBERNETES_CLIENT_ARGS, argv, 395 IDX_BACKSPACE, GUAC_TERMINAL_DEFAULT_BACKSPACE); 396 397 /* Parse clipboard copy disable flag */ 398 settings->disable_copy = 399 guac_user_parse_args_boolean(user, GUAC_KUBERNETES_CLIENT_ARGS, argv, 400 IDX_DISABLE_COPY, false); 401 402 /* Parse clipboard paste disable flag */ 403 settings->disable_paste = 404 guac_user_parse_args_boolean(user, GUAC_KUBERNETES_CLIENT_ARGS, argv, 405 IDX_DISABLE_PASTE, false); 406 407 /* Parsing was successful */ 408 return settings; 409 410} 411 412void guac_kubernetes_settings_free(guac_kubernetes_settings* settings) { 413 414 /* Free network connection information */ 415 guac_mem_free(settings->hostname); 416 417 /* Free Kubernetes pod/container details */ 418 guac_mem_free(settings->kubernetes_namespace); 419 guac_mem_free(settings->kubernetes_pod); 420 guac_mem_free(settings->kubernetes_container); 421 422 /* Free Kubernetes exec command */ 423 guac_mem_free(settings->exec_command); 424 425 /* Free SSL/TLS details */ 426 guac_mem_free(settings->client_cert); 427 guac_mem_free(settings->client_key); 428 guac_mem_free(settings->ca_cert); 429 430 /* Free display preferences */ 431 guac_mem_free(settings->font_name); 432 guac_mem_free(settings->color_scheme); 433 434 /* Free typescript settings */ 435 guac_mem_free(settings->typescript_name); 436 guac_mem_free(settings->typescript_path); 437 438 /* Free screen recording settings */ 439 guac_mem_free(settings->recording_name); 440 guac_mem_free(settings->recording_path); 441 442 /* Free overall structure */ 443 guac_mem_free(settings); 444 445} 446