GUACAMOLE-221: Use constants for parameters updated via argv or required instructions.

This commit is contained in:
Nick Couchman 2020-06-27 18:29:38 -04:00
parent 5881209f12
commit 5ec2551761
15 changed files with 202 additions and 28 deletions

View File

@ -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 */

View File

@ -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 <guacamole/client.h>
@ -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) {

View File

@ -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.

View File

@ -20,6 +20,7 @@
#include "config.h"
#include "argv.h"
#include "rdp.h"
#include "settings.h"
#include <guacamole/protocol.h>
#include <guacamole/socket.h>
@ -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 */

View File

@ -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++;
}

View File

@ -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",

View File

@ -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.
*/

View File

@ -20,6 +20,7 @@
#include "config.h"
#include "argv.h"
#include "ssh.h"
#include "common-ssh/ssh-constants.h"
#include "terminal/terminal.h"
#include <guacamole/protocol.h>
@ -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) {

View File

@ -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.

View File

@ -22,6 +22,7 @@
#include "argv.h"
#include "client.h"
#include "common/defaults.h"
#include "common-ssh/ssh-constants.h"
#include "settings.h"
#include <guacamole/user.h>
@ -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

View File

@ -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,

View File

@ -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 */

View File

@ -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;
}

View File

@ -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",

View File

@ -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.
*/