cscg24-guacamole

CSCG 2024 Challenge 'Guacamole Mashup'
git clone https://git.sinitax.com/sinitax/cscg24-guacamole
Log | Files | Refs | sfeed.txt

settings.h (18835B)


      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#ifndef GUAC_RDP_SETTINGS_H
     21#define GUAC_RDP_SETTINGS_H
     22
     23#include "config.h"
     24#include "keymap.h"
     25
     26#include <freerdp/freerdp.h>
     27#include <guacamole/client.h>
     28#include <guacamole/user.h>
     29
     30/**
     31 * The maximum number of bytes in the client hostname claimed during
     32 * connection.
     33 */
     34#define RDP_CLIENT_HOSTNAME_SIZE 32
     35
     36/**
     37 * The default RDP port.
     38 */
     39#define RDP_DEFAULT_PORT 3389
     40
     41/**
     42 * The default RDP port used by Hyper-V "VMConnect".
     43 */
     44#define RDP_DEFAULT_VMCONNECT_PORT 2179
     45
     46/**
     47 * Default screen width, in pixels.
     48 */
     49#define RDP_DEFAULT_WIDTH  1024
     50
     51/**
     52 * Default screen height, in pixels.
     53 */
     54#define RDP_DEFAULT_HEIGHT 768 
     55
     56/**
     57 * Default color depth, in bits.
     58 */
     59#define RDP_DEFAULT_DEPTH  16 
     60
     61/**
     62 * The filename to use for the screen recording, if not specified.
     63 */
     64#define GUAC_RDP_DEFAULT_RECORDING_NAME "recording"
     65
     66/**
     67 * The number of entries contained within the OrderSupport BYTE array
     68 * referenced by the rdpSettings structure. This value is defined by the RDP
     69 * negotiation process (there are 32 bytes available within the order
     70 * negotiation field sent during the connection handshake) and is hard-coded
     71 * within FreeRDP. There is no public constant for this value defined within
     72 * the FreeRDP headers.
     73 */
     74#define GUAC_RDP_ORDER_SUPPORT_LENGTH 32
     75
     76/**
     77 * All supported combinations of security types.
     78 */
     79typedef enum guac_rdp_security {
     80
     81    /**
     82     * Legacy RDP encryption.
     83     */
     84    GUAC_SECURITY_RDP,
     85
     86    /**
     87     * TLS encryption.
     88     */
     89    GUAC_SECURITY_TLS,
     90
     91    /**
     92     * Network level authentication.
     93     */
     94    GUAC_SECURITY_NLA,
     95
     96    /**
     97     * Extended network level authentication.
     98     */
     99    GUAC_SECURITY_EXTENDED_NLA,
    100
    101    /**
    102     * Negotiate security methods supported by Hyper-V's "VMConnect" feature.
    103     */
    104    GUAC_SECURITY_VMCONNECT,
    105
    106    /**
    107     * Negotiate a security method supported by both server and client.
    108     */
    109    GUAC_SECURITY_ANY
    110
    111} guac_rdp_security;
    112
    113/**
    114 * All supported combinations screen resize methods.
    115 */
    116typedef enum guac_rdp_resize_method {
    117
    118    /**
    119     * Dynamic resizing of the display will not be attempted.
    120     */
    121    GUAC_RESIZE_NONE,
    122
    123    /**
    124     * Dynamic resizing will be attempted through sending requests along the
    125     * Display Update channel. This will only work with recent versions of
    126     * Windows and relatively-recent versions of FreeRDP.
    127     */
    128    GUAC_RESIZE_DISPLAY_UPDATE,
    129
    130    /**
    131     * Guacamole will automatically disconnect and reconnect to the RDP server
    132     * whenever the screen size changes, requesting the new size during
    133     * reconnect.
    134     */
    135    GUAC_RESIZE_RECONNECT
    136
    137} guac_rdp_resize_method;
    138
    139/**
    140 * All settings supported by the Guacamole RDP client.
    141 */
    142typedef struct guac_rdp_settings {
    143
    144    /**
    145     * The hostname to connect to.
    146     */
    147    char* hostname;
    148
    149    /**
    150     * The port to connect to.
    151     */
    152    int port;
    153
    154    /**
    155     * The domain of the user logging in.
    156     */
    157    char* domain;
    158
    159    /**
    160     * The username of the user logging in.
    161     */
    162    char* username;
    163
    164    /**
    165     * The password of the user logging in.
    166     */
    167    char* password;
    168
    169    /**
    170     * Whether this connection is read-only, and user input should be dropped.
    171     */
    172    int read_only;
    173
    174    /**
    175     * The color depth of the display to request, in bits.
    176     */
    177    int color_depth;
    178
    179    /**
    180     * The width of the display to request, in pixels.
    181     */
    182    int width;
    183    
    184    /**
    185     * The height of the display to request, in pixels.
    186     */
    187    int height;
    188
    189    /**
    190     * The DPI of the remote display to assume when converting between
    191     * client pixels and remote pixels.
    192     */
    193    int resolution;
    194
    195    /**
    196     * Whether all graphical updates for this connection should use lossless
    197     * compression only.
    198     */
    199    int lossless;
    200
    201    /**
    202     * Whether audio is enabled.
    203     */
    204    int audio_enabled;
    205
    206    /**
    207     * Whether printing is enabled.
    208     */
    209    int printing_enabled;
    210
    211    /**
    212     * Name of the redirected printer.
    213     */
    214    char* printer_name;
    215
    216    /**
    217     * Whether the virtual drive is enabled.
    218     */
    219    int drive_enabled;
    220    
    221    /**
    222     * The name of the virtual drive to pass through to the RDP connection.
    223     */
    224    char* drive_name;
    225
    226    /**
    227     * The local system path which will be used to persist the
    228     * virtual drive.
    229     */
    230    char* drive_path;
    231
    232    /**
    233     * Whether to automatically create the local system path if it does not
    234     * exist.
    235     */
    236    int create_drive_path;
    237    
    238    /**
    239     * Whether or not to disable file download over RDP.
    240     */
    241    int disable_download;
    242    
    243    /**
    244     * Wether or not to disable file upload over RDP.
    245     */
    246    int disable_upload;
    247
    248    /**
    249     * Whether this session is a console session.
    250     */
    251    int console;
    252
    253    /**
    254     * Whether to allow audio in the console session.
    255     */
    256    int console_audio;
    257
    258    /**
    259     * The keymap chosen as the layout of the server.
    260     */
    261    const guac_rdp_keymap* server_layout;
    262
    263    /**
    264     * The initial program to run, if any.
    265     */
    266    char* initial_program;
    267
    268    /**
    269     * The name of the client to submit to the RDP server upon connection, or
    270     * NULL if the name is not specified.
    271     */
    272    char* client_name;
    273
    274    /**
    275     * The type of security to use for the connection.
    276     */
    277    guac_rdp_security security_mode;
    278
    279    /**
    280     * Whether bad server certificates should be ignored.
    281     */
    282    int ignore_certificate;
    283
    284    /**
    285     * Whether authentication should be disabled. This is different from the
    286     * authentication that takes place when a user provides their username
    287     * and password. Authentication is required by definition for NLA.
    288     */
    289    int disable_authentication;
    290
    291    /**
    292     * The application to launch, if RemoteApp is in use.
    293     */
    294    char* remote_app;
    295
    296    /**
    297     * The working directory of the remote application, if RemoteApp is in use.
    298     */
    299    char* remote_app_dir;
    300
    301    /**
    302     * The arguments to pass to the remote application, if RemoteApp is in use.
    303     */
    304    char* remote_app_args;
    305
    306    /**
    307     * NULL-terminated list of all static virtual channel names, or NULL if
    308     * no channels whatsoever.
    309     */
    310    char** svc_names;
    311
    312    /**
    313     * Whether outbound clipboard access should be blocked. If set, it will not
    314     * be possible to copy data from the remote desktop to the client using the
    315     * clipboard.
    316     */
    317    int disable_copy;
    318
    319    /**
    320     * Whether inbound clipboard access should be blocked. If set, it will not
    321     * be possible to paste data from the client to the remote desktop using
    322     * the clipboard.
    323     */
    324    int disable_paste;
    325
    326    /**
    327     * Whether line endings within the clipboard should be automatically
    328     * normalized to Unix-style newline characters.
    329     */
    330    int normalize_clipboard;
    331
    332    /**
    333     * Whether Unix-style newline characters within the clipboard should be
    334     * automatically translated to CRLF sequences before transmission to the
    335     * RDP server.
    336     */
    337    int clipboard_crlf;
    338
    339    /**
    340     * Whether the desktop wallpaper should be visible. If unset, the desktop
    341     * wallpaper will be hidden, reducing the amount of bandwidth required.
    342     */
    343    int wallpaper_enabled;
    344
    345    /**
    346     * Whether desktop and window theming should be allowed. If unset, theming
    347     * is temporarily disabled on the desktop of the RDP server for the sake of
    348     * performance, reducing the amount of bandwidth required.
    349     */
    350    int theming_enabled;
    351
    352    /**
    353     * Whether glyphs should be smoothed with antialiasing (ClearType). If
    354     * unset, glyphs will be rendered with sharp edges and using single colors,
    355     * effectively 1-bit images, reducing the amount of bandwidth required.
    356     */
    357    int font_smoothing_enabled;
    358
    359    /**
    360     * Whether windows contents should be shown as they are moved. If unset,
    361     * only a window border will be shown during window move operations,
    362     * reducing the amount of bandwidth required.
    363     */
    364    int full_window_drag_enabled;
    365
    366    /**
    367     * Whether desktop composition (Aero) should be enabled during the session.
    368     * As desktop composition provides alpha blending and other special
    369     * effects, this increases the amount of bandwidth used. If unset, desktop
    370     * composition will be disabled.
    371     */
    372    int desktop_composition_enabled;
    373
    374    /**
    375     * Whether menu animations should be shown. If unset, menus will not be
    376     * animated, reducing the amount of bandwidth required.
    377     */
    378    int menu_animations_enabled;
    379
    380    /**
    381     * Whether bitmap caching should be disabled. By default it is
    382     * enabled - this allows users to explicitly disable it.
    383     */
    384    int disable_bitmap_caching;
    385
    386    /**
    387     * Whether offscreen caching should be disabled. By default it is
    388     * enabled - this allows users to explicitly disable it.
    389     */
    390    int disable_offscreen_caching;
    391
    392    /**
    393     * Whether glyph caching should be disabled. By default it is enabled
    394     * - this allows users to explicitly disable it.
    395     */
    396    int disable_glyph_caching;
    397
    398    /**
    399     * The preconnection ID to send within the preconnection PDU when
    400     * initiating an RDP connection, if any. If no preconnection ID is
    401     * specified, this will be -1.
    402     */
    403    int preconnection_id;
    404
    405    /**
    406     * The preconnection BLOB (PCB) to send to the RDP server prior to full RDP
    407     * connection negotiation. This value is used by Hyper-V to select the
    408     * destination VM.
    409     */
    410    char* preconnection_blob;
    411
    412    /**
    413     * The timezone to pass through to the RDP connection.
    414     */
    415    char* timezone;
    416
    417#ifdef ENABLE_COMMON_SSH
    418    /**
    419     * Whether SFTP should be enabled for the RDP connection.
    420     */
    421    int enable_sftp;
    422
    423    /**
    424     * The hostname of the SSH server to connect to for SFTP.
    425     */
    426    char* sftp_hostname;
    427
    428    /**
    429     * The public SSH host key.
    430     */
    431    char* sftp_host_key;
    432
    433    /**
    434     * The port of the SSH server to connect to for SFTP.
    435     */
    436    char* sftp_port;
    437
    438    /**
    439     * The username to provide when authenticating with the SSH server for
    440     * SFTP.
    441     */
    442    char* sftp_username;
    443
    444    /**
    445     * The password to provide when authenticating with the SSH server for
    446     * SFTP (if not using a private key).
    447     */
    448    char* sftp_password;
    449
    450    /**
    451     * The base64-encoded private key to use when authenticating with the SSH
    452     * server for SFTP (if not using a password).
    453     */
    454    char* sftp_private_key;
    455
    456    /**
    457     * The passphrase to use to decrypt the provided base64-encoded private
    458     * key.
    459     */
    460    char* sftp_passphrase;
    461
    462    /**
    463     * The default location for file uploads within the SSH server. This will
    464     * apply only to uploads which do not use the filesystem guac_object (where
    465     * the destination directory is otherwise ambiguous).
    466     */
    467    char* sftp_directory;
    468
    469    /**
    470     * The path of the directory within the SSH server to expose as a
    471     * filesystem guac_object.
    472     */
    473    char* sftp_root_directory;
    474
    475    /**
    476     * The interval at which SSH keepalive messages are sent to the server for
    477     * SFTP connections. The default is 0 (disabling keepalives), and a value
    478     * of 1 is automatically increased to 2 by libssh2 to avoid busy loop corner
    479     * cases.
    480     */
    481    int sftp_server_alive_interval;
    482    
    483    /**
    484     * Whether or not to disable file download over SFTP.
    485     */
    486    int sftp_disable_download;
    487    
    488    /**
    489     * Whether or not to disable file upload over SFTP.
    490     */
    491    int sftp_disable_upload;
    492#endif
    493
    494    /**
    495     * The path in which the screen recording should be saved, if enabled. If
    496     * no screen recording should be saved, this will be NULL.
    497     */
    498    char* recording_path;
    499
    500    /**
    501     * The filename to use for the screen recording, if enabled.
    502     */
    503    char* recording_name;
    504
    505    /**
    506     * Whether the screen recording path should be automatically created if it
    507     * does not already exist.
    508     */
    509    int create_recording_path;
    510
    511    /**
    512     * Non-zero if output which is broadcast to each connected client
    513     * (graphics, streams, etc.) should NOT be included in the session
    514     * recording, zero otherwise. Output is included by default, as it is
    515     * necessary for any recording which must later be viewable as video.
    516     */
    517    int recording_exclude_output;
    518
    519    /**
    520     * Non-zero if changes to mouse state, such as position and buttons pressed
    521     * or released, should NOT be included in the session recording, zero
    522     * otherwise. Mouse state is included by default, as it is necessary for
    523     * the mouse cursor to be rendered in any resulting video.
    524     */
    525    int recording_exclude_mouse;
    526
    527    /**
    528     * Non-zero if changes to touch state should NOT be included in the session
    529     * recording, zero otherwise. Touch state is included by default, as it may
    530     * be necessary for touch interactions to be rendered in any resulting
    531     * video.
    532     */
    533    int recording_exclude_touch;
    534
    535    /**
    536     * Non-zero if keys pressed and released should be included in the session
    537     * recording, zero otherwise. Key events are NOT included by default within
    538     * the recording, as doing so has privacy and security implications.
    539     * Including key events may be necessary in certain auditing contexts, but
    540     * should only be done with caution. Key events can easily contain
    541     * sensitive information, such as passwords, credit card numbers, etc.
    542     */
    543    int recording_include_keys;
    544
    545    /**
    546     * The method to apply when the user's display changes size.
    547     */
    548    guac_rdp_resize_method resize_method;
    549
    550    /**
    551     * Whether audio input (microphone) is enabled.
    552     */
    553    int enable_audio_input;
    554
    555    /**
    556     * Whether multi-touch support is enabled.
    557     */
    558    int enable_touch;
    559
    560    /**
    561     * The hostname of the remote desktop gateway that should be used as an
    562     * intermediary for the remote desktop connection. If no gateway should
    563     * be used, this will be NULL.
    564     */
    565    char* gateway_hostname;
    566
    567    /**
    568     * The port of the remote desktop gateway that should be used as an
    569     * intermediary for the remote desktop connection. NOTE: versions of
    570     * FreeRDP prior to 1.2 which have gateway support ignore this value, and
    571     * instead use a hard-coded value of 443.
    572     */
    573    int gateway_port;
    574
    575    /**
    576     * The domain of the user authenticating with the remote desktop gateway,
    577     * if a gateway is being used. This is not necessarily the same as the
    578     * user actually using the remote desktop connection.
    579     */
    580    char* gateway_domain;
    581
    582    /**
    583     * The username of the user authenticating with the remote desktop gateway,
    584     * if a gateway is being used. This is not necessarily the same as the
    585     * user actually using the remote desktop connection.
    586     */
    587    char* gateway_username;
    588
    589    /**
    590     * The password to provide when authenticating with the remote desktop
    591     * gateway, if a gateway is being used.
    592     */
    593    char* gateway_password;
    594
    595    /**
    596     * The load balancing information/cookie which should be provided to
    597     * the connection broker, if a connection broker is being used.
    598     */
    599    char* load_balance_info;
    600    
    601    /**
    602     * Whether or not to send a magic WoL packet to wake up the host before
    603     * trying to connect.  Zero will disable sending the packet, non-zero
    604     * values will trigger sending the packet.
    605     */
    606    int wol_send_packet;
    607    
    608    /**
    609     * The mac address to put in the magic WoL packet.
    610     */
    611    char* wol_mac_addr;
    612    
    613    /**
    614     * The broadcast address to send the magic WoL packet to.
    615     */
    616    char* wol_broadcast_addr;
    617    
    618    /**
    619     * The UDP port to use when sending the magic WoL packet.
    620     */
    621    unsigned short wol_udp_port;
    622    
    623    /**
    624     * The amount of time to wait after sending the magic WoL packet before
    625     * continuing the connection.
    626     */
    627    int wol_wait_time;
    628
    629} guac_rdp_settings;
    630
    631/**
    632 * Parses all given args, storing them in a newly-allocated settings object. If
    633 * the args fail to parse, NULL is returned.
    634 *
    635 * @param user
    636 *     The user who submitted the given arguments while joining the
    637 *     connection.
    638 *
    639 * @param argc
    640 *     The number of arguments within the argv array.
    641 *
    642 * @param argv
    643 *     The values of all arguments provided by the user.
    644 *
    645 * @return
    646 *     A newly-allocated settings object which must be freed with
    647 *     guac_rdp_settings_free() when no longer needed. If the arguments fail
    648 *     to parse, NULL is returned.
    649 */
    650guac_rdp_settings* guac_rdp_parse_args(guac_user* user,
    651        int argc, const char** argv);
    652
    653/**
    654 * Frees the given guac_rdp_settings object, having been previously allocated
    655 * via guac_rdp_parse_args().
    656 *
    657 * @param settings
    658 *     The settings object to free.
    659 */
    660void guac_rdp_settings_free(guac_rdp_settings* settings);
    661
    662/**
    663 * NULL-terminated array of accepted client args.
    664 */
    665extern const char* GUAC_RDP_CLIENT_ARGS[];
    666
    667/**
    668 * Save all given settings to the given freerdp instance.
    669 *
    670 * @param client
    671 *     The guac_client object providing the settings.
    672 *
    673 * @param guac_settings
    674 *     The guac_rdp_settings object to save.
    675 *
    676 * @param rdp
    677 *     The RDP instance to save settings to.
    678 */
    679void guac_rdp_push_settings(guac_client* client,
    680        guac_rdp_settings* guac_settings, freerdp* rdp);
    681
    682/**
    683 * Returns the width of the RDP session display.
    684 *
    685 * @param rdp
    686 *     The RDP instance to retrieve the width from.
    687 *
    688 * @return
    689 *     The current width of the RDP display, in pixels.
    690 */
    691int guac_rdp_get_width(freerdp* rdp);
    692
    693/**
    694 * Returns the height of the RDP session display.
    695 *
    696 * @param rdp
    697 *     The RDP instance to retrieve the height from.
    698 *
    699 * @return
    700 *     The current height of the RDP display, in pixels.
    701 */
    702int guac_rdp_get_height(freerdp* rdp);
    703
    704/**
    705 * Returns the depth of the RDP session display.
    706 *
    707 * @param rdp
    708 *     The RDP instance to retrieve the depth from.
    709 *
    710 * @return
    711 *     The current depth of the RDP display, in bits per pixel.
    712 */
    713int guac_rdp_get_depth(freerdp* rdp);
    714
    715#endif
    716