]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
client: Fix leading / issue with mds_check_access
authorKotresh HR <khiremat@redhat.com>
Fri, 26 Jul 2024 14:48:04 +0000 (20:18 +0530)
committerKotresh HR <khiremat@redhat.com>
Tue, 30 Jul 2024 17:49:13 +0000 (23:19 +0530)
The "Client::mds_check_access" expects the target_path without
leading '/' as it eventually calls the "MDSCapMatch::match_path"
which expects the target_path passed to be with out leading '/'
as well.

The single leading '/' was being removed. But absolute path
constructed did have leading '//', so removing all the leading
'/' was necessary.

This causes the clients not to be able to access a particular
path even though it has a rw permission on the specific path.

The patche fixes the leading '//' issue.

Fixes: https://tracker.ceph.com/issues/67212
Signed-off-by: Kotresh HR <khiremat@redhat.com>
src/client/Client.cc

index f8412139e621a7f6c2ab234ff164a12591cf573c..7e6f950332b44fcfe6bc288972e70f4e9fa5fc42 100644 (file)
@@ -5933,6 +5933,11 @@ int Client::mds_check_access(std::string& path, const UserPerm& perms, int mask)
     }
   }
 
+  // drop any leading /
+  while (path.length() && path[0] == '/') {
+    path = path.substr(1);
+  }
+
   for (auto& s: cap_auths) {
     ldout(cct, 20) << __func__ << " auth match path " << s.match.path << " r: " << s.readable
                    << " w: " << s.writeable << dendl;
@@ -8039,6 +8044,10 @@ bool Client::make_absolute_path_string(Inode *in, std::string& path)
     return false;
   }
 
+  // Make sure this function returns path with single leading '/'
+  if (path.length() && path[0] == '/' && path[1] == '/')
+    path = path.substr(1);
+
   return true;
 }
 
@@ -8086,8 +8095,6 @@ int Client::_do_setattr(Inode *in, struct ceph_statx *stx, int mask,
     std::string path;
     if (make_absolute_path_string(in, path)) {
       ldout(cct, 20) << " absolute path: " << path << dendl;
-      if (path.length())
-        path = path.substr(1);    // drop leading /
       res = mds_check_access(path, perms, MAY_WRITE);
       if (res) {
         goto out;
@@ -10329,8 +10336,6 @@ int Client::_open(Inode *in, int flags, mode_t mode, Fh **fhp,
     std::string path;
     if (make_absolute_path_string(in, path)) {
       ldout(cct, 20) << __func__ << " absolute path: " << path << dendl;
-      if (path.length())
-        path = path.substr(1);    // drop leading /
       result = mds_check_access(path, perms, mask);
       if (result) {
         return result;