mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 05:07:41 +00:00
Moved library/protocol loading and argument parsing into libguac for future connect message. Proxy no longer uses command-line specified protocol and connection info.
This commit is contained in:
@@ -10,6 +10,7 @@ AC_PROG_CC
|
|||||||
AC_PROG_LIBTOOL
|
AC_PROG_LIBTOOL
|
||||||
|
|
||||||
# Checks for libraries.
|
# Checks for libraries.
|
||||||
|
AC_CHECK_LIB([dl], [dlopen],, AC_MSG_ERROR("libdl is required for loading client plugins"))
|
||||||
AC_CHECK_LIB([png], [png_write_png])
|
AC_CHECK_LIB([png], [png_write_png])
|
||||||
|
|
||||||
# Checks for header files.
|
# Checks for header files.
|
||||||
|
@@ -75,6 +75,11 @@ struct guac_client {
|
|||||||
*/
|
*/
|
||||||
GUACIO* io;
|
GUACIO* io;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to dlopen'd client plugin.
|
||||||
|
*/
|
||||||
|
void* client_plugin_handle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Arbitrary reference to proxy client-specific data. Implementors of a
|
* Arbitrary reference to proxy client-specific data. Implementors of a
|
||||||
* Guacamole proxy client can store any data they want here, which can then
|
* Guacamole proxy client can store any data they want here, which can then
|
||||||
@@ -192,18 +197,14 @@ struct guac_client {
|
|||||||
typedef int guac_client_init_handler(guac_client* client, int argc, char** argv);
|
typedef int guac_client_init_handler(guac_client* client, int argc, char** argv);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize and return a new guac_client using the specified client init handler (guac_client_init_handler).
|
* Initialize and return a new guac_client. The pluggable client will be chosen based on
|
||||||
* This will normally be the guac_client_init function as provided by any of the pluggable proxy clients.
|
* the first connect message received on the given file descriptor.
|
||||||
*
|
*
|
||||||
* @param client_fd The file descriptor associated with the socket associated with the connection to the
|
* @param client_fd The file descriptor associated with the socket associated with the connection to the
|
||||||
* web-client tunnel.
|
* web-client tunnel.
|
||||||
* @param client_init Function pointer to the client init handler which will initialize the new guac_client
|
* @return A pointer to the newly initialized client.
|
||||||
* when called. The given hostname and port will be passed to this handler.
|
|
||||||
* @param argc The number of arguments being passed to this client.
|
|
||||||
* @param argv The arguments being passed to this client.
|
|
||||||
* @return A pointer to the newly initialized (or found) client.
|
|
||||||
*/
|
*/
|
||||||
guac_client* guac_get_client(int client_fd, guac_client_init_handler* client_init, int argc, char** argv);
|
guac_client* guac_get_client(int client_fd);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter the main network message handling loop for the given client.
|
* Enter the main network message handling loop for the given client.
|
||||||
|
@@ -23,6 +23,8 @@
|
|||||||
|
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
|
||||||
|
#include <dlfcn.h>
|
||||||
|
|
||||||
#include "guacio.h"
|
#include "guacio.h"
|
||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
@@ -68,32 +70,49 @@ guac_client* __guac_alloc_client(GUACIO* io) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
guac_client* guac_get_client(int client_fd, guac_client_init_handler* client_init, int argc, char** argv) {
|
guac_client* guac_get_client(int client_fd) {
|
||||||
|
|
||||||
guac_client* client;
|
guac_client* client;
|
||||||
GUACIO* io = guac_open(client_fd);
|
GUACIO* io = guac_open(client_fd);
|
||||||
|
|
||||||
/* Make copies of arguments */
|
/* Pluggable client */
|
||||||
char** safe_argv = malloc(argc * sizeof(char*));
|
char* protocol;
|
||||||
char** scratch_argv = malloc(argc * sizeof(char*));
|
char protocol_lib[256] = "libguac_client_";
|
||||||
|
|
||||||
|
union {
|
||||||
|
guac_client_init_handler* client_init;
|
||||||
|
void* obj;
|
||||||
|
} alias;
|
||||||
|
|
||||||
|
char* error;
|
||||||
|
|
||||||
|
strcat(protocol_lib, protocol);
|
||||||
|
strcat(protocol_lib, ".so");
|
||||||
|
|
||||||
|
/* Load client plugin */
|
||||||
|
client->client_plugin_handle = dlopen(protocol_lib, RTLD_LAZY);
|
||||||
|
if (!(client->client_plugin_handle)) {
|
||||||
|
fprintf(stderr, "Could not open client plugin for protocol \"%s\": %s\n", protocol, dlerror());
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
dlerror(); /* Clear errors */
|
||||||
|
|
||||||
|
/* Get init function */
|
||||||
|
alias.obj = dlsym(client->client_plugin_handle, "guac_client_init");
|
||||||
|
|
||||||
|
if ((error = dlerror()) != NULL) {
|
||||||
|
fprintf(stderr, "Could not get guac_client_init in plugin: %s\n", error);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
int i;
|
|
||||||
for (i=0; i<argc; i++)
|
|
||||||
scratch_argv[i] = safe_argv[i] = strdup(argv[i]);
|
|
||||||
|
|
||||||
/* Create new client */
|
/* Create new client */
|
||||||
client = __guac_alloc_client(io);
|
client = __guac_alloc_client(io);
|
||||||
|
|
||||||
if (client_init(client, argc, scratch_argv) != 0)
|
if (alias.client_init(client, argc, argv) != 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* Free memory used for arg copy */
|
|
||||||
for (i=0; i<argc; i++)
|
|
||||||
free(safe_argv[i]);
|
|
||||||
|
|
||||||
free(safe_argv);
|
|
||||||
free(scratch_argv);
|
|
||||||
|
|
||||||
return client;
|
return client;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -108,6 +127,11 @@ void guac_free_client(guac_client* client) {
|
|||||||
|
|
||||||
guac_close(client->io);
|
guac_close(client->io);
|
||||||
|
|
||||||
|
/* Unload client plugin */
|
||||||
|
if (dlclose(client->client_plugin_handle)) {
|
||||||
|
syslog(LOG_ERR, "Could not close client plugin while unloading client: %s", dlerror());
|
||||||
|
}
|
||||||
|
|
||||||
free(client);
|
free(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -8,7 +8,6 @@ AM_INIT_AUTOMAKE(guacd, 0.0.1)
|
|||||||
AC_PROG_CC
|
AC_PROG_CC
|
||||||
|
|
||||||
# Checks for libraries.
|
# Checks for libraries.
|
||||||
AC_CHECK_LIB([dl], [dlopen],, AC_MSG_ERROR("libdl is required for loading client plugins"))
|
|
||||||
AC_CHECK_LIB([guac], [guac_get_client],, AC_MSG_ERROR("libguac must be installed first"))
|
AC_CHECK_LIB([guac], [guac_get_client],, AC_MSG_ERROR("libguac must be installed first"))
|
||||||
AC_CHECK_LIB([pthread], [pthread_create],, AC_MSG_ERROR("POSIX threads (libpthread) must be installed"))
|
AC_CHECK_LIB([pthread], [pthread_create],, AC_MSG_ERROR("POSIX threads (libpthread) must be installed"))
|
||||||
|
|
||||||
|
@@ -24,7 +24,6 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <dlfcn.h>
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@@ -35,10 +34,6 @@
|
|||||||
typedef struct client_thread_data {
|
typedef struct client_thread_data {
|
||||||
|
|
||||||
int fd;
|
int fd;
|
||||||
guac_client_init_handler* client_init;
|
|
||||||
|
|
||||||
int argc;
|
|
||||||
char** argv;
|
|
||||||
|
|
||||||
} client_thread_data;
|
} client_thread_data;
|
||||||
|
|
||||||
@@ -51,7 +46,7 @@ void* start_client_thread(void* data) {
|
|||||||
syslog(LOG_INFO, "Spawning client");
|
syslog(LOG_INFO, "Spawning client");
|
||||||
|
|
||||||
/* Load and start client */
|
/* Load and start client */
|
||||||
client = guac_get_client(thread_data->fd, thread_data->client_init, thread_data->argc, thread_data->argv);
|
client = guac_get_client(thread_data->fd);
|
||||||
|
|
||||||
if (client == NULL) {
|
if (client == NULL) {
|
||||||
syslog(LOG_ERR, "Client retrieval failed");
|
syslog(LOG_ERR, "Client retrieval failed");
|
||||||
@@ -77,16 +72,6 @@ void* start_client_thread(void* data) {
|
|||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
|
|
||||||
/* Pluggable client */
|
|
||||||
void* client_plugin_handle;
|
|
||||||
|
|
||||||
union {
|
|
||||||
guac_client_init_handler* client_init;
|
|
||||||
void* obj;
|
|
||||||
} alias;
|
|
||||||
|
|
||||||
char* error;
|
|
||||||
|
|
||||||
/* Server */
|
/* Server */
|
||||||
int socket_fd;
|
int socket_fd;
|
||||||
struct sockaddr_in server_addr;
|
struct sockaddr_in server_addr;
|
||||||
@@ -96,18 +81,12 @@ int main(int argc, char* argv[]) {
|
|||||||
unsigned int client_addr_len;
|
unsigned int client_addr_len;
|
||||||
int connected_socket_fd;
|
int connected_socket_fd;
|
||||||
|
|
||||||
|
/* Arguments */
|
||||||
int listen_port = -1;
|
int listen_port = -1;
|
||||||
char* protocol = NULL;
|
|
||||||
|
|
||||||
int client_argc;
|
|
||||||
char** client_argv;
|
|
||||||
|
|
||||||
char protocol_lib[256] = "libguac_client_";
|
|
||||||
|
|
||||||
int opt;
|
int opt;
|
||||||
|
|
||||||
/* Parse arguments */
|
/* Parse arguments */
|
||||||
while ((opt = getopt(argc, argv, "l:p:")) != -1) {
|
while ((opt = getopt(argc, argv, "l:")) != -1) {
|
||||||
if (opt == 'l') {
|
if (opt == 'l') {
|
||||||
listen_port = atoi(optarg);
|
listen_port = atoi(optarg);
|
||||||
if (listen_port <= 0) {
|
if (listen_port <= 0) {
|
||||||
@@ -115,34 +94,18 @@ int main(int argc, char* argv[]) {
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (opt == 'p') {
|
|
||||||
protocol = optarg;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
fprintf(stderr, "USAGE: %s [-l LISTENPORT] [-p PROTOCOL [PROTOCOL OPTIONS ...]]\n", argv[0]);
|
fprintf(stderr, "USAGE: %s -l LISTENPORT\n", argv[0]);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Validate arguments */
|
/* Validate arguments */
|
||||||
|
|
||||||
if (listen_port < 0) {
|
if (listen_port < 0) {
|
||||||
fprintf(stderr, "The port to listen on must be specified.\n");
|
fprintf(stderr, "The port to listen on must be specified.\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (protocol == NULL) {
|
|
||||||
fprintf(stderr, "The protocol must be specified.\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
strcat(protocol_lib, protocol);
|
|
||||||
strcat(protocol_lib, ".so");
|
|
||||||
|
|
||||||
client_argc = argc - optind;
|
|
||||||
client_argv = &(argv[optind]);
|
|
||||||
|
|
||||||
/* Get binding address */
|
/* Get binding address */
|
||||||
memset(&server_addr, 0, sizeof(server_addr)); /* Zero struct */
|
memset(&server_addr, 0, sizeof(server_addr)); /* Zero struct */
|
||||||
server_addr.sin_family = AF_INET;
|
server_addr.sin_family = AF_INET;
|
||||||
@@ -163,24 +126,6 @@ int main(int argc, char* argv[]) {
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Load client plugin */
|
|
||||||
client_plugin_handle = dlopen(protocol_lib, RTLD_LAZY);
|
|
||||||
if (!client_plugin_handle) {
|
|
||||||
fprintf(stderr, "Could not open client plugin for protocol \"%s\": %s\n", protocol, dlerror());
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
dlerror(); /* Clear errors */
|
|
||||||
|
|
||||||
/* Get init function */
|
|
||||||
alias.obj = dlsym(client_plugin_handle, "guac_client_init");
|
|
||||||
|
|
||||||
if ((error = dlerror()) != NULL) {
|
|
||||||
fprintf(stderr, "Could not get guac_client_init in plugin: %s\n", error);
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
syslog(LOG_INFO, "Started, listening on port %i", listen_port);
|
syslog(LOG_INFO, "Started, listening on port %i", listen_port);
|
||||||
|
|
||||||
|
|
||||||
@@ -205,11 +150,7 @@ int main(int argc, char* argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data = malloc(sizeof(client_thread_data));
|
data = malloc(sizeof(client_thread_data));
|
||||||
|
|
||||||
data->fd = connected_socket_fd;
|
data->fd = connected_socket_fd;
|
||||||
data->client_init = alias.client_init;
|
|
||||||
data->argc = client_argc;
|
|
||||||
data->argv = client_argv;
|
|
||||||
|
|
||||||
if (pthread_create(&thread, NULL, start_client_thread, (void*) data)) {
|
if (pthread_create(&thread, NULL, start_client_thread, (void*) data)) {
|
||||||
syslog(LOG_ERR, "Could not create client thread: %s", strerror(errno));
|
syslog(LOG_ERR, "Could not create client thread: %s", strerror(errno));
|
||||||
@@ -224,13 +165,6 @@ int main(int argc, char* argv[]) {
|
|||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Load client plugin */
|
|
||||||
if (dlclose(client_plugin_handle)) {
|
|
||||||
syslog(LOG_ERR, "Could not close client plugin: %s", dlerror());
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user