]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
client: add support for O_NOFOLLOW in Client::open().
authorRadoslaw Zarzynski <rzarzynski@mirantis.com>
Mon, 26 Jan 2015 14:40:14 +0000 (15:40 +0100)
committerRadoslaw Zarzynski <rzarzynski@mirantis.com>
Wed, 4 Feb 2015 09:00:53 +0000 (10:00 +0100)
Fixes: #4920
Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>
src/client/Client.cc
src/test/libcephfs/test.cc

index e62ab1f816d325b94950ec47718b76c07b2e6713..8d5e192ba7cab5ac9a5b5d27fbd0272913703b4e 100644 (file)
@@ -6378,9 +6378,16 @@ int Client::open(const char *relpath, int flags, mode_t mode, int stripe_unit,
   filepath path(relpath);
   Inode *in;
   bool created = false;
-  int r = path_walk(path, &in);
+  /* O_CREATE with O_EXCL enforces O_NOFOLLOW. */
+  bool followsym = !((flags & O_NOFOLLOW) || ((flags & O_CREAT) && (flags & O_EXCL)));
+  int r = path_walk(path, &in, followsym);
+
   if (r == 0 && (flags & O_CREAT) && (flags & O_EXCL))
     return -EEXIST;
+
+  if (r == 0 && in->is_symlink() && (flags & O_NOFOLLOW))
+    return -ELOOP;
+
   if (r == -ENOENT && (flags & O_CREAT)) {
     filepath dirpath = path;
     string dname = dirpath.last_dentry();
index ccedaa1230580424b2c4a942e95448c29d8b2f64..00cd36c080e29ea43f575016be3866f71396bd1e 100644 (file)
@@ -673,6 +673,10 @@ TEST(LibCephFS, Symlinks) {
 
   ASSERT_EQ(ceph_symlink(cmount, test_file, test_symlink), 0);
 
+  // test the O_NOFOLLOW case
+  fd = ceph_open(cmount, test_symlink, O_NOFOLLOW, 0);
+  ASSERT_EQ(fd, -ELOOP);
+
   // stat the original file
   struct stat stbuf_orig;
   ASSERT_EQ(ceph_stat(cmount, test_file, &stbuf_orig), 0);