]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
client: Fix permissions checking for O_WRONLY
authorSam Lang <sam.lang@inktank.com>
Thu, 18 Oct 2012 20:21:10 +0000 (15:21 -0500)
committerSam Lang <sam.lang@inktank.com>
Thu, 18 Oct 2012 22:16:35 +0000 (17:16 -0500)
O_RDONLY is 0 in glibc, so we have to assume the
flags bits are mutually exclusive, otherwise we always
request read perms and write-only modes break.

Signed-off-by: Sam Lang <sam.lang@inktank.com>
src/client/Inode.cc

index ee3191cd18583a51afd2cc13b435990e21585857..cef19ff77f458e920cc2944ebab796ec540b3ef6 100644 (file)
@@ -267,15 +267,14 @@ Dir *Inode::open_dir()
 
 bool Inode::check_mode(uid_t ruid, gid_t rgid, gid_t *sgids, int sgids_count, uint32_t rflags)
 {
-  unsigned mflags = rflags & O_ACCMODE;
   unsigned fmode = 0;
 
-  if ((mflags & O_WRONLY) == O_WRONLY)
-      fmode |= 2;
-  if ((mflags & O_RDONLY) == O_RDONLY)
-      fmode |= 4;
-  if ((mflags & O_RDWR) == O_RDWR)
-      fmode |= 6;
+  if ((rflags & O_ACCMODE) == O_WRONLY)
+      fmode = 2;
+  else if ((rflags & O_ACCMODE) == O_RDWR)
+      fmode = 6;
+  else if ((rflags & O_ACCMODE) == O_RDONLY)
+      fmode = 4;
 
   // if uid is owner, owner entry determines access
   if (uid == ruid) {