Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/common-ssh/sftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <libgen.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

int guac_common_ssh_sftp_normalize_path(char* fullpath,
const char* path) {
Expand Down Expand Up @@ -653,10 +654,19 @@ static int guac_common_ssh_sftp_ls_ack_handler(guac_user* user,

/* Determine mimetype */
const char* mimetype;
if (LIBSSH2_SFTP_S_ISDIR(attributes.permissions))
mimetype = GUAC_USER_STREAM_INDEX_MIMETYPE;
else
mimetype = "application/octet-stream";
//adding file size and permission
char tmpstr[150];
if (LIBSSH2_SFTP_S_ISDIR(attributes.permissions)) {
sprintf(tmpstr, "{\"mime\":\"%s\",\"size\":%llu,\"perm\":%lu}",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how JSON data is assembled elsewhere in the code - if sprintf is routinely used like this, or if there's a library that handles it? Might be worth checking that out - I'd be a little surprised if all of the other places in the guacd code that assemble JSON do it like this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use the various internal guac_common_json_*() functions like guac_common_json_write_property().

GUAC_USER_STREAM_INDEX_MIMETYPE, attributes.filesize,
attributes.permissions);
}
else {
sprintf(tmpstr, "{\"mime\":\"%s\",\"size\":%llu,\"perm\":%lu}",
"application/octet-stream", attributes.filesize,
attributes.permissions);
}
mimetype = tmpstr;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should just re-assign this string to mimetype, as the name mimetype implies that the data carried is the MIME type, not a string of information with various attributes about the file.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

This would also break compatibility with any implementation that expects the value to be a mimetype string, which is also what we have defined for the protocol: https://guacamole.apache.org/doc/gug/protocol-reference.html#get-instruction

I think a better approach would be to leverage mimetype parameters to encode the information in a compatible way within the mimetype itself. This would allow the same information to be encoded for other instructions like file, as well. For example:

application/octet-stream;size=12345;mode=0644;uid=123;gid=456

If there are standard parameters for this, we can use them, or failing that we can define our own.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello Mike,
I hope you're doing well. It's been some time since our last interaction, and I've taken this period to carefully consider and implement the MIME type encoding approach you recommended for the project.

With your guidance in mind, I've crafted a string that incorporates the additional file attributes as MIME type parameters, ensuring that the original distinction between files and directories is maintained. Here's the updated code snippet:

char property_value[256];

snprintf(property_value, sizeof(property_value), 
         "%s;size=%llu;mode=%o;uid=%d;gid=%d", 
         mimetype, 
         (unsigned long long) attributes.filesize, 
         attributes.permissions & 07777,
         attributes.uid, 
         attributes.gid);

guac_common_json_write_property(user, stream, &list_state->json_state, absolute_path, property_value);

I would be grateful for your feedback on this revision. Does this change correctly reflect the format you envisioned? Your further input would be incredibly valuable.

Thank you for your guidance and patience.


/* Write entry, waiting for next ack if a blob is written */
if (guac_common_json_write_property(user, stream,
Expand Down
16 changes: 12 additions & 4 deletions src/protocols/rdp/ls.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include <stdlib.h>
#include <string.h>
#include <stdio.h>

int guac_rdp_ls_ack_handler(guac_user* user, guac_stream* stream,
char* message, guac_protocol_status status) {
Expand Down Expand Up @@ -85,10 +86,17 @@ int guac_rdp_ls_ack_handler(guac_user* user, guac_stream* stream,

/* Determine mimetype */
const char* mimetype;
if (file->attributes & FILE_ATTRIBUTE_DIRECTORY)
mimetype = GUAC_USER_STREAM_INDEX_MIMETYPE;
else
mimetype = "application/octet-stream";
char tmpstr[150];
//adding file size
if (file->attributes & FILE_ATTRIBUTE_DIRECTORY) {
sprintf(tmpstr, "{\"mime\":\"%s\",\"size\":%lu}",
GUAC_USER_STREAM_INDEX_MIMETYPE, file->size);
}
else {
sprintf(tmpstr, "{\"mime\":\"%s\",\"size\":%lu}",
"application/octet-stream", file->size);
}
mimetype = tmpstr;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As with above - just assigning this tmpstr back to mimetype doesn't really make sense.


/* Write entry */
blob_written |= guac_common_json_write_property(user, stream,
Expand Down