GUAC-1389: Add convenience function for exposing SFTP filesystems to specific users.
This commit is contained in:
parent
cb70c6e8b9
commit
48143f6a0a
@ -716,9 +716,22 @@ static int guac_common_ssh_sftp_put_handler(guac_user* user,
|
||||
return 0;
|
||||
}
|
||||
|
||||
void* guac_common_ssh_expose_sftp_filesystem(guac_user* user, void* data) {
|
||||
|
||||
guac_common_ssh_sftp_filesystem* filesystem =
|
||||
(guac_common_ssh_sftp_filesystem*) data;
|
||||
|
||||
/* No need to expose if there is no filesystem or the user has left */
|
||||
if (user == NULL || filesystem == NULL)
|
||||
return NULL;
|
||||
|
||||
/* Allocate and expose filesystem object for user */
|
||||
return guac_common_ssh_alloc_sftp_filesystem_object(filesystem, user);
|
||||
|
||||
}
|
||||
|
||||
guac_object* guac_common_ssh_alloc_sftp_filesystem_object(
|
||||
guac_common_ssh_sftp_filesystem* filesystem, guac_user* user,
|
||||
const char* name) {
|
||||
guac_common_ssh_sftp_filesystem* filesystem, guac_user* user) {
|
||||
|
||||
/* Init filesystem */
|
||||
guac_object* fs_object = guac_user_alloc_object(user);
|
||||
@ -727,7 +740,7 @@ guac_object* guac_common_ssh_alloc_sftp_filesystem_object(
|
||||
fs_object->data = filesystem;
|
||||
|
||||
/* Send filesystem to user */
|
||||
guac_protocol_send_filesystem(user->socket, fs_object, name);
|
||||
guac_protocol_send_filesystem(user->socket, fs_object, filesystem->name);
|
||||
guac_socket_flush(user->socket);
|
||||
|
||||
return fs_object;
|
||||
@ -735,7 +748,7 @@ guac_object* guac_common_ssh_alloc_sftp_filesystem_object(
|
||||
}
|
||||
|
||||
guac_common_ssh_sftp_filesystem* guac_common_ssh_create_sftp_filesystem(
|
||||
guac_common_ssh_session* session) {
|
||||
guac_common_ssh_session* session, const char* name) {
|
||||
|
||||
/* Request SFTP */
|
||||
LIBSSH2_SFTP* sftp_session = libssh2_sftp_init(session->session);
|
||||
@ -747,6 +760,7 @@ guac_common_ssh_sftp_filesystem* guac_common_ssh_create_sftp_filesystem(
|
||||
malloc(sizeof(guac_common_ssh_sftp_filesystem));
|
||||
|
||||
/* Associate SSH session with SFTP data and user */
|
||||
filesystem->name = strdup(name);
|
||||
filesystem->ssh_session = session;
|
||||
filesystem->sftp_session = sftp_session;
|
||||
|
||||
@ -765,6 +779,7 @@ void guac_common_ssh_destroy_sftp_filesystem(
|
||||
libssh2_sftp_shutdown(filesystem->sftp_session);
|
||||
|
||||
/* Free associated memory */
|
||||
free(filesystem->name);
|
||||
free(filesystem);
|
||||
|
||||
}
|
||||
|
@ -42,6 +42,11 @@
|
||||
*/
|
||||
typedef struct guac_common_ssh_sftp_filesystem {
|
||||
|
||||
/**
|
||||
* The human-readable display name of this filesystem.
|
||||
*/
|
||||
char* name;
|
||||
|
||||
/**
|
||||
* The distinct SSH session used for SFTP.
|
||||
*/
|
||||
@ -101,11 +106,15 @@ typedef struct guac_common_ssh_sftp_ls_state {
|
||||
* The session to use to provide SFTP. This session will automatically be
|
||||
* destroyed when this filesystem is destroyed.
|
||||
*
|
||||
* @param name
|
||||
* The name to send as the name of the filesystem whenever it is exposed
|
||||
* to a user.
|
||||
*
|
||||
* @return
|
||||
* A new SFTP filesystem object, not yet exposed to users.
|
||||
*/
|
||||
guac_common_ssh_sftp_filesystem* guac_common_ssh_create_sftp_filesystem(
|
||||
guac_common_ssh_session* session);
|
||||
guac_common_ssh_session* session, const char* name);
|
||||
|
||||
/**
|
||||
* Destroys the given filesystem object, disconnecting from SFTP and freeing
|
||||
@ -129,16 +138,39 @@ void guac_common_ssh_destroy_sftp_filesystem(
|
||||
* @param user
|
||||
* The user that the SFTP filesystem should be exposed to.
|
||||
*
|
||||
* @param name
|
||||
* The name to send as the name of the filesystem.
|
||||
*
|
||||
* @return
|
||||
* A new Guacamole filesystem object, configured to use SFTP for uploading
|
||||
* and downloading files.
|
||||
*/
|
||||
guac_object* guac_common_ssh_alloc_sftp_filesystem_object(
|
||||
guac_common_ssh_sftp_filesystem* filesystem, guac_user* user,
|
||||
const char* name);
|
||||
guac_common_ssh_sftp_filesystem* filesystem, guac_user* user);
|
||||
|
||||
/**
|
||||
* Allocates a new filesystem guac_object for the given user, returning the
|
||||
* resulting guac_object. This function is provided for convenience, as it is
|
||||
* can be used as the callback for guac_client_foreach_user() or
|
||||
* guac_client_for_owner(). Note that this guac_object will be tracked
|
||||
* internally by libguac, will be provided to us in the parameters of handlers
|
||||
* related to that guac_object, and will automatically be freed when the
|
||||
* associated guac_user is freed, so the return value of this function can
|
||||
* safely be ignored.
|
||||
*
|
||||
* If either the given user or the given filesystem are NULL, then this
|
||||
* function has no effect.
|
||||
*
|
||||
* @param user
|
||||
* The use to expose the filesystem to, or NULL if nothing should be
|
||||
* exposed.
|
||||
*
|
||||
* @param data
|
||||
* A pointer to the guac_common_ssh_sftp_filesystem instance to expose
|
||||
* to the given user, or NULL if nothing should be exposed.
|
||||
*
|
||||
* @return
|
||||
* The guac_object allocated for the newly-exposed filesystem, or NULL if
|
||||
* no filesystem object could be allocated.
|
||||
*/
|
||||
void* guac_common_ssh_expose_sftp_filesystem(guac_user* user, void* data);
|
||||
|
||||
/**
|
||||
* Initiates an SFTP file download to the user via the Guacamole "file"
|
||||
|
Loading…
Reference in New Issue
Block a user