Repository navigation
GUACAMOLE-1536: return file size and file permission information when uploading files and displaying file directories #367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
0fb3b42
e6c1c2b
4c7d49a
3f9e19d
e06698d
e8d367d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) { | ||
|
|
@@ -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}", | ||
| 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; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we should just re-assign this string to
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 If there are standard parameters for this, we can use them, or failing that we can define our own.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hello Mike, 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, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) { | ||
|
|
@@ -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; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As with above - just assigning this |
||
|
|
||
| /* Write entry */ | ||
| blob_written |= guac_common_json_write_property(user, stream, | ||
|
|
||
There was a problem hiding this comment.
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
sprintfis 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.There was a problem hiding this comment.
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 likeguac_common_json_write_property().