After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 710906 - sftp doesn't implement any GFileCreateFlags
sftp doesn't implement any GFileCreateFlags
Status: RESOLVED FIXED
Product: gvfs
Classification: Core
Component: sftp backend
git master
Other Linux
: Normal enhancement
: ---
Assigned To: gvfs-maint
gvfs-maint
Depends on:
Blocks:
 
 
Reported: 2013-10-26 08:10 UTC by Ross Lagerwall
Modified: 2013-11-15 15:21 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
sftp: Implement GFileCreateFlags and improve permission handling (9.67 KB, patch)
2013-10-26 19:39 UTC, Ross Lagerwall
none Details | Review
sftp: Implement GFileCreateFlags and improve permission handling (10.09 KB, patch)
2013-11-15 05:31 UTC, Ross Lagerwall
none Details | Review
sftp: Implement GFileCreateFlags and improve permission handling (9.94 KB, patch)
2013-11-15 10:08 UTC, Ross Lagerwall
accepted-commit_now Details | Review

Description Ross Lagerwall 2013-10-26 08:10:44 UTC
sftp doesn't implement G_FILE_CREATE_PRIVATE.

Secondly, the replace code has a line which can set permissions to 0644 which is odd.

Also, the permissions are set to 0777 when replacing a symbolic link with G_FILE_CREATE_REPLACE_DESTINATION which is also odd.
Comment 1 Ross Lagerwall 2013-10-26 17:35:30 UTC
sftp doesn't implement G_FILE_CREATE_REPLACE_DESTINATION either.  In fact, it seems to behave as though that flag is set.
Comment 2 Ross Lagerwall 2013-10-26 19:39:55 UTC
Created attachment 258187 [details] [review]
sftp: Implement GFileCreateFlags and improve permission handling

Set the file permissions to 0600 when G_FILE_CREATE_PRIVATE is
specified and the file does not exist or
G_FILE_CREATE_REPLACE_DESTINATION is specified.
Otherwise, set the file permissions to the permissions of the existing
file only if it is a regular file (i.e. don't set the permissions to 777
because the existing destination is actually is a symlink).
Otherwise, use the default file permissions by not setting any file
permissions.

If G_FILE_CREATE_REPLACE_DESTINATION is not specified and the
destination file is a symbolic link, replace the destination of the
symbolic link by truncating it rather than the symbolic link itself.
Comment 3 Alexander Larsson 2013-11-14 08:13:56 UTC
Review of attachment 258187 [details] [review]:

::: daemon/gvfsbackendsftp.c
@@ +3452,3 @@
+      if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_UNIX_MODE) &&
+          g_file_info_get_file_type (info) == G_FILE_TYPE_REGULAR &&
+          !(op_job->flags & G_FILE_CREATE_REPLACE_DESTINATION))

Same check needs to happen with set_ownership. I.e. we only copy uid/gid if !REPLACE_DESTINATION.

@@ +3481,3 @@
 
+  /* If G_FILE_CREATE_REPLACE_DESTINATION is not specified and the destination
+   * is a symlink, replace the target of the symlink by truncating. */

This means we're removing the original in the case of a hard link. Its unfortunate that n_links is not in the sftp protocol. But it seems safer to use a rename-temp-over-dest in most cases for a slight risk of breaking hard links.
Comment 4 Ross Lagerwall 2013-11-15 05:31:55 UTC
Created attachment 259855 [details] [review]
sftp: Implement GFileCreateFlags and improve permission handling

Set the file permissions to 0600 when G_FILE_CREATE_PRIVATE is
specified and the file does not exist or
G_FILE_CREATE_REPLACE_DESTINATION is specified.
Otherwise, set the file permissions and ownership to the permissions and
ownership of the existing file only if it is a regular file (i.e. don't
set the permissions to 777 because the existing destination is actually
is a symlink).
Otherwise, use the default file permissions by not setting any file
permissions.

If G_FILE_CREATE_REPLACE_DESTINATION is not specified and the
destination file is a symbolic link, replace the destination of the
symbolic link by truncating it rather than the symbolic link itself.
Comment 5 Ross Lagerwall 2013-11-15 05:34:17 UTC
The updated patch adds a check for REPLACE_DESTINATION when setting ownership, as per the review.
Comment 6 Alexander Larsson 2013-11-15 08:42:52 UTC
Review of attachment 259855 [details] [review]:

::: daemon/gvfsbackendsftp.c
@@ +3460,3 @@
+      if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_UNIX_UID) &&
+          g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_UNIX_GID) &&
+          g_file_info_get_file_type (info) == G_FILE_TYPE_REGULAR &&

Is there any particular reason for the type == REGULAR checks here? 
Like, i realize we handle symlinks differently below so need not set perms/ownership in that case. But that could be a is_symlink check like below.

But what about other cases? I.e. !replace_destination a device node? A fifo?

Actually maybe its the is_symlink case below that is wrong. If you're writing to a fifo with !replace_destination we should maybe be using the truncate codepath...
Comment 7 Ross Lagerwall 2013-11-15 10:08:43 UTC
Created attachment 259860 [details] [review]
sftp: Implement GFileCreateFlags and improve permission handling

Set the file permissions to 0600 when G_FILE_CREATE_PRIVATE is
specified and the file does not exist or
G_FILE_CREATE_REPLACE_DESTINATION is specified.
Otherwise, set the file permissions and ownership to the permissions and
ownership of the existing file only if it is a regular file (i.e. don't
set the permissions to 777 because the existing destination is actually
is a symlink).
Otherwise, use the default file permissions by not setting any file
permissions.

If G_FILE_CREATE_REPLACE_DESTINATION is specified or the destination is
a regular file, write to a tempfile and rename; otherwise, replace by
truncating the destination.
Comment 8 Ross Lagerwall 2013-11-15 10:10:37 UTC
OK, so the updated patch:
* uses the tempfile method if replace_destination is specified or it is a regular file. If replace_destination wasn't specified, the ownership and permissions are maintained.
* uses the truncate method otherwise.

I hope this takes care of all situations.
Comment 9 Alexander Larsson 2013-11-15 14:05:06 UTC
Review of attachment 259860 [details] [review]:

looks good
Comment 10 Ross Lagerwall 2013-11-15 15:21:04 UTC
Pushed to master as 26163e67d5b31812c58ca661f57a8ab17b0d197b. Thanks for the reviews.