necouchman commented on a change in pull request #228:
URL: https://github.com/apache/guacamole-server/pull/228#discussion_r489763257
##########
File path: src/protocols/vnc/auth.c
##########
@@ -19,27 +19,110 @@
#include "config.h"
+#include "argv.h"
#include "auth.h"
#include "vnc.h"
#include <guacamole/client.h>
+#include <guacamole/protocol.h>
+#include <guacamole/socket.h>
#include <rfb/rfbclient.h>
#include <rfb/rfbproto.h>
+#include <pthread.h>
+#include <string.h>
+
char* guac_vnc_get_password(rfbClient* client) {
guac_client* gc = rfbClientGetClientData(client, GUAC_VNC_CLIENT_KEY);
- return ((guac_vnc_client*) gc->data)->settings->password;
+ guac_vnc_client* vnc_client = ((guac_vnc_client*) gc->data);
+ guac_vnc_settings* settings = vnc_client->settings;
+
+ /* If the client does not support the "required" instruction, just return
+ the configuration data. */
+ if (!guac_client_owner_supports_required(gc))
+ return ((guac_vnc_client*) gc->data)->settings->password;
+
+ /* If password isn't around, prompt for it. */
+ if (settings->password == NULL || strcmp(settings->password, "") == 0) {
+ /* Lock the thread. */
+ pthread_mutex_lock(&(vnc_client->vnc_credential_lock));
+
+ /* Send the request for password to the owner. */
+ guac_client_owner_send_required(gc,
+ (const char* []) {GUAC_VNC_ARGV_PASSWORD, NULL});
+
+ /* Set the conditional flag. */
+ vnc_client->vnc_credential_flags |= GUAC_VNC_COND_FLAG_PASSWORD;
+
+ /* Wait for the condition. */
+ pthread_cond_wait(&(vnc_client->vnc_credential_cond),
+ &(vnc_client->vnc_credential_lock));
+
+ /* Unlock the thread. */
+ pthread_mutex_unlock(&(vnc_client->vnc_credential_lock));
+ }
+
+ return settings->password;
+
}
rfbCredential* guac_vnc_get_credentials(rfbClient* client, int credentialType)
{
guac_client* gc = rfbClientGetClientData(client, GUAC_VNC_CLIENT_KEY);
- guac_vnc_settings* settings = ((guac_vnc_client*) gc->data)->settings;
+ guac_vnc_client* vnc_client = ((guac_vnc_client*) gc->data);
+ guac_vnc_settings* settings = vnc_client->settings;
+ /* Handle request for Username/Password credentials */
if (credentialType == rfbCredentialTypeUser) {
rfbCredential *creds = malloc(sizeof(rfbCredential));
- creds->userCredential.username = settings->username;
- creds->userCredential.password = settings->password;
- return creds;
+
+ /* If the client does not support the "required" instruction, just
return
+ the parameters already configured. */
+ if (!guac_client_owner_supports_required(gc)) {
+ creds->userCredential.username = settings->username;
+ creds->userCredential.password = settings->password;
+ return creds;
+ }
+
+ char* params[2] = {NULL};
+ int i = 0;
+
+ /* Check if username is null or empty. */
+ if (settings->username == NULL) {
+ params[i] = GUAC_VNC_ARGV_USERNAME;
+ i++;
+ vnc_client->vnc_credential_flags |= GUAC_VNC_COND_FLAG_USERNAME;
+ }
+
+ /* Check if password is null or empty. */
+ if (settings->password == NULL) {
+ params[i] = GUAC_VNC_ARGV_PASSWORD;
+ i++;
+ vnc_client->vnc_credential_flags |= GUAC_VNC_COND_FLAG_PASSWORD;
+ }
+
+ /* If we have empty parameters, request them. */
+ if (i > 0) {
+ /* Lock the thread. */
+ pthread_mutex_lock(&(vnc_client->vnc_credential_lock));
+
+ /* Send required parameters to owner. */
+ guac_client_owner_send_required(gc, (const char**) params);
+
+ /* Wait for the parameters to be returned. */
+ pthread_cond_wait(&(vnc_client->vnc_credential_cond),
+ &(vnc_client->vnc_credential_lock));
Review comment:
Yeah, I think that was half the point of implementing the `argv` common
stuff...
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]