Fix access when mode metadata is missing (owner root, no permissions).
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Wed, 18 Dec 2013 18:44:40 +0000 (19:44 +0100)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Sun, 23 Feb 2014 13:16:21 +0000 (14:16 +0100)
src/VfsNs.cpp

index da7c898..cf32d5c 100644 (file)
@@ -28,9 +28,9 @@
 #define IS_VFS_XATTR(NAME) (strncmp((NAME), VFS_XATTR, VFS_XATTR_LENGTH) == 0)
 #define IS_VFS_FILE(NAME) (strncmp((NAME), VFS_FILE, VFS_FILE_LENGTH) == 0)
 
-// force everything to current owner for now
-#define VFS_UID_NONE xStat.stat.st_uid
-#define VFS_GID_NONE xStat.stat.st_gid
+// no owner or group ==> root
+#define VFS_UID_NONE 0
+#define VFS_GID_NONE 0
 
 #define INODE_CACHE_SIZE 256
 
@@ -201,6 +201,9 @@ void VfsCatalog::vfsUpdateStat(ExtendedStat &xStat, Extensible xattrs) throw (Dm
   xStat.stat.st_uid = xattrs.getUnsigned(VFS_XATTR "owner", VFS_UID_NONE);
 
   modeStr = xattrs.getString(VFS_XATTR "mode", "");
+  // 1) prefer type from the filesystem
+  // 2) no permissions at all when not in xattrs
+  xStat.stat.st_mode &= S_IFMT;
   if (!modeStr.empty()) {
     errno = 0;
     mode = strtoull(modeStr.c_str(), &parse, 8);
@@ -213,8 +216,6 @@ void VfsCatalog::vfsUpdateStat(ExtendedStat &xStat, Extensible xattrs) throw (Dm
       log(LOG_ERR, "conversion of the mode '%s' failed on '%s'", modeStr.c_str(), xStat.name.c_str());
 #endif
     } else {
-      // prefer type from the filesystem
-      mode &= ~S_IFMT;
       mode |= xStat.stat.st_mode & S_IFMT;
       // use xattr for everything else
       xStat.stat.st_mode = mode;