[gvfs] Don't trust remote permissions mask fully



commit 4e49395240190526efe8833c802ee49de8b3915f
Author: Alexander Larsson <alexl redhat com>
Date:   Fri Apr 17 11:33:21 2009 +0200

    Don't trust remote permissions mask fully
    
    We don't actually know what gids we're in, and also there may be other
    things not visible via sftp like ACLs that decide the user
    permissions. So, we only use the permissions for group and other if
    they result in a positive, otherwise we leave the attibute unset
    (meaning "don't know").
---
 daemon/gvfsbackendsftp.c |   32 +++++++++++++++++++++++++-------
 1 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/daemon/gvfsbackendsftp.c b/daemon/gvfsbackendsftp.c
index 1c130f8..3b510a7 100644
--- a/daemon/gvfsbackendsftp.c
+++ b/daemon/gvfsbackendsftp.c
@@ -1962,17 +1962,35 @@ error_from_lstat (GVfsBackendSftp *backend,
 }
 
 static void
-set_access_attributes (GFileInfo *info,
-                       guint32 perm)
+set_access_attributes_trusted (GFileInfo *info,
+			       guint32 perm)
 {
   g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ,
-                                     perm & 0x4);
+				     perm & 0x4);
   g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE,
-                                     perm & 0x2);
+				     perm & 0x2);
   g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE,
-                                     perm & 0x1);
+				     perm & 0x1);
 }
-  
+
+/* For files we don't own we can't trust a negative response to this check, as
+   something else could allow us to do the operation, for instance an ACL
+   or some sticky bit thing */
+static void
+set_access_attributes (GFileInfo *info,
+                       guint32 perm)
+{
+  if (perm & 0x4)
+    g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ,
+				       TRUE);
+  if (perm & 0x2)
+    g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE,
+				       TRUE);
+  if (perm & 0x1)
+    g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE,
+				       TRUE);
+}
+
 
 static void
 parse_attributes (GVfsBackendSftp *backend,
@@ -2099,7 +2117,7 @@ parse_attributes (GVfsBackendSftp *backend,
       if (has_uid && backend->my_uid != (guint32)-1)
         {
           if (uid == backend->my_uid)
-            set_access_attributes (info, (mode >> 6) & 0x7);
+            set_access_attributes_trusted (info, (mode >> 6) & 0x7);
           else if (gid == backend->my_gid)
             set_access_attributes (info, (mode >> 3) & 0x7);
           else



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]