diff --git a/src/common-ssh/common-ssh/ssh-constants.h b/src/common-ssh/common-ssh/ssh-constants.h new file mode 100644 index 00000000..fc7efb80 --- /dev/null +++ b/src/common-ssh/common-ssh/ssh-constants.h @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#ifndef GUAC_COMMON_SSH_CONSTANTS_H +#define GUAC_COMMON_SSH_CONSTANTS_H + +/** + * The name of the parameter that Guacamole uses to collect the username from + * the Guacamole client and send it to the SSH server. + */ +#define GUAC_SSH_PARAMETER_NAME_USERNAME "username" + +/** + * The name of the parameter that Guacamole uses to collect the password from + * the Guacamole client and send it to the SSH server. + */ +#define GUAC_SSH_PARAMETER_NAME_PASSWORD "password" + +/** + * The name of the parameter that Guacamole uses to collect a SSH key passphrase + * from the Guacamole client in order to unlock a private key. + */ +#define GUAC_SSH_PARAMETER_NAME_PASSPHRASE "passphrase" + +/** + * The name of the parameter that Guacamole uses to collect the terminal + * color scheme from the Guacamole client. + */ +#define GUAC_SSH_PARAMETER_NAME_COLOR_SCHEME "color-scheme" + +/** + * The name of the parameter that Guacamole uses to collect the font name + * from the Guacamole client. + */ +#define GUAC_SSH_PARAMETER_NAME_FONT_NAME "font-name" + +/** + * The name of the parameter that Guacamole uses to collect the font size + * from the Guacamole client + */ +#define GUAC_SSH_PARAMETER_NAME_FONT_SIZE "font-size" + +#endif /* GUAC_COMMON_SSH_CONSTANTS_H */ + diff --git a/src/common-ssh/ssh.c b/src/common-ssh/ssh.c index eed4c003..07188d98 100644 --- a/src/common-ssh/ssh.c +++ b/src/common-ssh/ssh.c @@ -19,6 +19,7 @@ #include "common-ssh/key.h" #include "common-ssh/ssh.h" +#include "common-ssh/ssh-constants.h" #include "common-ssh/user.h" #include @@ -360,7 +361,7 @@ static int guac_common_ssh_authenticate(guac_common_ssh_session* common_session) /* Attempt authentication with username + password. */ if (user->password == NULL && common_session->credential_handler) - common_session->credential_handler(client, "password"); + common_session->credential_handler(client, GUAC_SSH_PARAMETER_NAME_PASSWORD); /* Authenticate with password, if provided */ if (user->password != NULL) { diff --git a/src/libguac/guacamole/protocol.h b/src/libguac/guacamole/protocol.h index 54e8d6f6..6ee1ad4e 100644 --- a/src/libguac/guacamole/protocol.h +++ b/src/libguac/guacamole/protocol.h @@ -800,7 +800,7 @@ int guac_protocol_send_rect(guac_socket* socket, const guac_layer* layer, * is needed to continue the connection. * * @param socket - * The guac_socket connection to use. + * The guac_socket connection to which to send the instruction. * * @param required * A NULL-terminated array of required parameters. diff --git a/src/protocols/rdp/argv.c b/src/protocols/rdp/argv.c index 946c0520..023a98df 100644 --- a/src/protocols/rdp/argv.c +++ b/src/protocols/rdp/argv.c @@ -20,6 +20,7 @@ #include "config.h" #include "argv.h" #include "rdp.h" +#include "settings.h" #include #include @@ -154,11 +155,11 @@ int guac_rdp_argv_handler(guac_user* user, guac_stream* stream, guac_rdp_argv_setting setting; /* Allow users to update authentication details */ - if (strcmp(name, "username") == 0) + if (strcmp(name, GUAC_RDP_PARAMETER_NAME_USERNAME) == 0) setting = GUAC_RDP_ARGV_SETTING_USERNAME; - else if (strcmp(name, "password") == 0) + else if (strcmp(name, GUAC_RDP_PARAMETER_NAME_PASSWORD) == 0) setting = GUAC_RDP_ARGV_SETTING_PASSWORD; - else if (strcmp(name, "domain") == 0) + else if (strcmp(name, GUAC_RDP_PARAMETER_NAME_DOMAIN) == 0) setting = GUAC_RDP_ARGV_SETTING_DOMAIN; /* No other connection parameters may be updated */ diff --git a/src/protocols/rdp/rdp.c b/src/protocols/rdp/rdp.c index 75a20bda..07e670e4 100644 --- a/src/protocols/rdp/rdp.c +++ b/src/protocols/rdp/rdp.c @@ -232,20 +232,20 @@ static BOOL rdp_freerdp_authenticate(freerdp* instance, char** username, char* params[4] = {}; int i = 0; - if (settings->username == NULL || strcmp(settings->username, "") == 0) { - params[i] = "username"; + if (settings->username == NULL) { + params[i] = GUAC_RDP_PARAMETER_NAME_USERNAME; rdp_client->rdp_credential_flags |= GUAC_RDP_CRED_FLAG_USERNAME; i++; } - if (settings->password == NULL || strcmp(settings->password, "") == 0) { - params[i] = "password"; + if (settings->password == NULL) { + params[i] = GUAC_RDP_PARAMETER_NAME_PASSWORD; rdp_client->rdp_credential_flags |= GUAC_RDP_CRED_FLAG_PASSWORD; i++; } - if (settings->domain == NULL || strcmp(settings->domain, "") == 0) { - params[i] = "domain"; + if (settings->domain == NULL) { + params[i] = GUAC_RDP_PARAMETER_NAME_DOMAIN; rdp_client->rdp_credential_flags |= GUAC_RDP_CRED_FLAG_DOMAIN; i++; } diff --git a/src/protocols/rdp/settings.c b/src/protocols/rdp/settings.c index 307c83ba..468df416 100644 --- a/src/protocols/rdp/settings.c +++ b/src/protocols/rdp/settings.c @@ -42,9 +42,9 @@ const char* GUAC_RDP_CLIENT_ARGS[] = { "hostname", "port", - "domain", - "username", - "password", + GUAC_RDP_PARAMETER_NAME_DOMAIN, + GUAC_RDP_PARAMETER_NAME_USERNAME, + GUAC_RDP_PARAMETER_NAME_PASSWORD, "width", "height", "dpi", diff --git a/src/protocols/rdp/settings.h b/src/protocols/rdp/settings.h index d8092216..e2257962 100644 --- a/src/protocols/rdp/settings.h +++ b/src/protocols/rdp/settings.h @@ -73,6 +73,24 @@ */ #define GUAC_RDP_ORDER_SUPPORT_LENGTH 32 +/** + * The name of the parameter that is used by Guacamole to collect the username + * from the Guacamole client and send it to the RDP server. + */ +#define GUAC_RDP_PARAMETER_NAME_USERNAME "username" + +/** + * The name of the parameter that is used by Guacamole to collect the password + * from the Guacamole client and send it to the RDP server. + */ +#define GUAC_RDP_PARAMETER_NAME_PASSWORD "password" + +/** + * The name of the parameter that is used by Guacamole to collect the domain + * name from the Guacamole client and send it to the RDP server. + */ +#define GUAC_RDP_PARAMETER_NAME_DOMAIN "domain" + /** * All supported combinations of security types. */ diff --git a/src/protocols/ssh/argv.c b/src/protocols/ssh/argv.c index ff32afde..802b6dd6 100644 --- a/src/protocols/ssh/argv.c +++ b/src/protocols/ssh/argv.c @@ -20,6 +20,7 @@ #include "config.h" #include "argv.h" #include "ssh.h" +#include "common-ssh/ssh-constants.h" #include "terminal/terminal.h" #include @@ -42,9 +43,70 @@ int guac_ssh_argv_callback(guac_user* user, const char* mimetype, if (strcmp(name, GUAC_SSH_ARGV_COLOR_SCHEME) == 0) guac_terminal_apply_color_scheme(terminal, value); +<<<<<<< HEAD /* Update font name */ else if (strcmp(name, GUAC_SSH_ARGV_FONT_NAME) == 0) guac_terminal_apply_font(terminal, value, -1, 0); +======= + /* Update username */ + case GUAC_SSH_ARGV_SETTING_USERNAME: + free(settings->username); + settings->username = strndup(argv->buffer, argv->length); + + pthread_cond_broadcast(&(ssh_client->ssh_credential_cond)); + break; + + /* Update password */ + case GUAC_SSH_ARGV_SETTING_PASSWORD: + + /* Update password in settings */ + free(settings->password); + settings->password = strndup(argv->buffer, argv->length); + + /* Update password in ssh user */ + guac_common_ssh_user* ssh_user = (guac_common_ssh_user*) ssh_client->user; + if (ssh_user != NULL) + guac_common_ssh_user_set_password(ssh_user, argv->buffer); + + pthread_cond_broadcast(&(ssh_client->ssh_credential_cond)); + break; + + /* Update private key passphrase */ + case GUAC_SSH_ARGV_SETTING_PASSPHRASE: + free(settings->key_passphrase); + settings->key_passphrase = strndup(argv->buffer, argv->length); + + pthread_cond_broadcast(&(ssh_client->ssh_credential_cond)); + break; + + /* Update color scheme */ + case GUAC_SSH_ARGV_SETTING_COLOR_SCHEME: + guac_terminal_apply_color_scheme(terminal, argv->buffer); + guac_client_stream_argv(client, client->socket, "text/plain", + GUAC_SSH_PARAMETER_NAME_COLOR_SCHEME, argv->buffer); + break; + + /* Update font name */ + case GUAC_SSH_ARGV_SETTING_FONT_NAME: + guac_terminal_apply_font(terminal, argv->buffer, -1, 0); + guac_client_stream_argv(client, client->socket, "text/plain", + GUAC_SSH_PARAMETER_NAME_FONT_NAME, argv->buffer); + break; + + /* Update font size */ + case GUAC_SSH_ARGV_SETTING_FONT_SIZE: + + /* Update only if font size is sane */ + size = atoi(argv->buffer); + if (size > 0) { + guac_terminal_apply_font(terminal, NULL, size, + ssh_client->settings->resolution); + guac_client_stream_argv(client, client->socket, "text/plain", + GUAC_SSH_PARAMETER_NAME_FONT_SIZE, argv->buffer); + } + + break; +>>>>>>> GUACAMOLE-221: Use constants for parameters updated via argv or required instructions. /* Update only if font size is sane */ else if (strcmp(name, GUAC_SSH_ARGV_FONT_SIZE) == 0) { diff --git a/src/protocols/ssh/argv.h b/src/protocols/ssh/argv.h index 4cbdb4c8..4dc24250 100644 --- a/src/protocols/ssh/argv.h +++ b/src/protocols/ssh/argv.h @@ -44,6 +44,24 @@ */ #define GUAC_SSH_ARGV_FONT_SIZE "font-size" +/** + * The name of the parameter that specifies/updates the username used by the + * connection. + */ +#define GUAC_SSH_ARGV_USERNAME "username" + +/** + * The name of the parameter that specifies/updates the password used by the + * connection. + */ +#define GUAC_SSH_ARGV_PASSWORD "password" + +/** + * The name of the parameter that specifies/updates the private ky passphrase + * used by the connection. + */ +#define GUAC_SSH_ARGV_PASSPHRASE "passphrase" + /** * Handles a received argument value from a Guacamole "argv" instruction, * updating the given connection parameter. diff --git a/src/protocols/ssh/settings.c b/src/protocols/ssh/settings.c index 242e1d29..8b057b6a 100644 --- a/src/protocols/ssh/settings.c +++ b/src/protocols/ssh/settings.c @@ -22,6 +22,7 @@ #include "argv.h" #include "client.h" #include "common/defaults.h" +#include "common-ssh/ssh-constants.h" #include "settings.h" #include @@ -36,8 +37,8 @@ const char* GUAC_SSH_CLIENT_ARGS[] = { "hostname", "host-key", "port", - "username", - "password", + GUAC_SSH_ARGV_USERNAME, + GUAC_SSH_ARGV_PASSWORD, GUAC_SSH_ARGV_FONT_NAME, GUAC_SSH_ARGV_FONT_SIZE, "enable-sftp", @@ -45,7 +46,7 @@ const char* GUAC_SSH_CLIENT_ARGS[] = { "sftp-disable-download", "sftp-disable-upload", "private-key", - "passphrase", + GUAC_SSH_ARGV_PASSPHRASE, #ifdef ENABLE_SSH_AGENT "enable-agent", #endif diff --git a/src/protocols/ssh/ssh.c b/src/protocols/ssh/ssh.c index d2bc5b12..6179694e 100644 --- a/src/protocols/ssh/ssh.c +++ b/src/protocols/ssh/ssh.c @@ -23,6 +23,7 @@ #include "common/recording.h" #include "common-ssh/sftp.h" #include "common-ssh/ssh.h" +#include "common-ssh/ssh-constants.h" #include "settings.h" #include "sftp.h" #include "ssh.h" @@ -108,7 +109,7 @@ static guac_common_ssh_user* guac_ssh_get_user(guac_client* client) { /* Get username */ while (settings->username == NULL) - guac_ssh_get_credential(client, "username"); + guac_ssh_get_credential(client, GUAC_SSH_PARAMETER_NAME_USERNAME); /* Create user object from username */ user = guac_common_ssh_create_user(settings->username); @@ -133,7 +134,7 @@ static guac_common_ssh_user* guac_ssh_get_user(guac_client* client) { /* Prompt for passphrase if missing */ while (settings->key_passphrase == NULL) - guac_ssh_get_credential(client, "passphrase"); + guac_ssh_get_credential(client, GUAC_SSH_PARAMETER_NAME_PASSPHRASE); /* Reattempt import with passphrase */ if (guac_common_ssh_user_import_key(user, diff --git a/src/protocols/vnc/argv.c b/src/protocols/vnc/argv.c index 0f8caebf..5bbe04fd 100644 --- a/src/protocols/vnc/argv.c +++ b/src/protocols/vnc/argv.c @@ -153,9 +153,9 @@ int guac_vnc_argv_handler(guac_user* user, guac_stream* stream, char* mimetype, guac_vnc_argv_setting setting; /* Allow users to update authentication information */ - if (strcmp(name, "username") == 0) + if (strcmp(name, GUAC_VNC_PARAMETER_NAME_USERNAME) == 0) setting = GUAC_VNC_ARGV_SETTING_USERNAME; - else if (strcmp(name, "password") == 0) + else if (strcmp(name, GUAC_VNC_PARAMETER_NAME_PASSWORD) == 0) setting = GUAC_VNC_ARGV_SETTING_PASSWORD; /* No other connection parameters may be updated */ diff --git a/src/protocols/vnc/auth.c b/src/protocols/vnc/auth.c index 6ea21a38..b5f93221 100644 --- a/src/protocols/vnc/auth.c +++ b/src/protocols/vnc/auth.c @@ -44,7 +44,7 @@ char* guac_vnc_get_password(rfbClient* client) { /* Send the request for password and flush the socket. */ guac_socket_require_keep_alive(gc->__owner->socket); guac_protocol_send_required(gc->__owner->socket, - (const char* []) {"password", NULL}); + (const char* []) {GUAC_VNC_PARAMETER_NAME_PASSWORD, NULL}); guac_socket_flush(gc->__owner->socket); /* Set the conditional flag. */ @@ -74,15 +74,15 @@ rfbCredential* guac_vnc_get_credentials(rfbClient* client, int credentialType) { int i = 0; /* Check if username is null or empty. */ - if (settings->username == NULL || strcmp(settings->username, "") == 0) { - params[i] = "username"; + if (settings->username == NULL) { + params[i] = GUAC_VNC_PARAMETER_NAME_USERNAME; i++; vnc_client->vnc_credential_flags |= GUAC_VNC_COND_FLAG_USERNAME; } /* Check if password is null or empty. */ - if (settings->password == NULL || strcmp(settings->password, "") == 0) { - params[i] = "password"; + if (settings->password == NULL) { + params[i] = GUAC_VNC_PARAMETER_NAME_PASSWORD; i++; vnc_client->vnc_credential_flags |= GUAC_VNC_COND_FLAG_PASSWORD; } diff --git a/src/protocols/vnc/settings.c b/src/protocols/vnc/settings.c index c0d14859..f4104754 100644 --- a/src/protocols/vnc/settings.c +++ b/src/protocols/vnc/settings.c @@ -37,8 +37,8 @@ const char* GUAC_VNC_CLIENT_ARGS[] = { "port", "read-only", "encodings", - "username", - "password", + GUAC_VNC_PARAMETER_NAME_USERNAME, + GUAC_VNC_PARAMETER_NAME_PASSWORD, "swap-red-blue", "color-depth", "cursor", diff --git a/src/protocols/vnc/settings.h b/src/protocols/vnc/settings.h index 8d5659ef..7a386833 100644 --- a/src/protocols/vnc/settings.h +++ b/src/protocols/vnc/settings.h @@ -30,6 +30,18 @@ */ #define GUAC_VNC_DEFAULT_RECORDING_NAME "recording" +/** + * The name of the parameter Guacamole will use to collect the username from the + * Guacamole client to send to the VNC server. + */ +#define GUAC_VNC_PARAMETER_NAME_USERNAME "username" + +/** + * The name of the parameter Guacamole will use to collect the password from the + * Guacamole client to send to the VNC server. + */ +#define GUAC_VNC_PARAMETER_NAME_PASSWORD "password" + /** * VNC-specific client data. */