Wrap setting leases in become_root()/unbecome_root() to ensure correct delivery of...
authorJeremy Allison <jra@samba.org>
Wed, 31 Jul 2013 23:32:20 +0000 (16:32 -0700)
committerKarolin Seeger <kseeger@samba.org>
Mon, 12 Aug 2013 07:09:45 +0000 (09:09 +0200)
Remove workaround for Linux kernel bug https://bugzilla.kernel.org/show_bug.cgi?id=43336
as we don't need to set capabilities when we're already root.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Simo Sorce <idra@samba.org>
(cherry picked from commit 363025491d97171e130a7b8dd03296b9559799a0)

source3/smbd/oplock_linux.c

index 02bd32a3fcb740ce42811fe6dc5ce60648b8f135..82523f2dce53357806927aa13795f0889d89bd6c 100644 (file)
@@ -75,26 +75,33 @@ int linux_set_lease_sighandler(int fd)
 int linux_setlease(int fd, int leasetype)
 {
        int ret;
+       int saved_errno;
+
+       /*
+        * Ensure the lease owner is root to allow
+        * correct delivery of lease-break signals.
+        */
+
+       become_root();
 
        /* First set the signal handler. */
        if (linux_set_lease_sighandler(fd) == -1) {
-               return -1;
+               saved_errno = errno;
+               ret = -1;
+               goto out;
        }
        ret = fcntl(fd, F_SETLEASE, leasetype);
-       if (ret == -1 && errno == EACCES) {
-               set_effective_capability(LEASE_CAPABILITY);
-               /*
-                * Bug 8974 - work around Linux kernel bug
-                * https://bugzilla.kernel.org/show_bug.cgi?id=43336.
-                * "fcntl(F_SETLEASE) resets signal number when
-                *  called multiple times"
-                */
-               if (linux_set_lease_sighandler(fd) == -1) {
-                       return -1;
-               }
-               ret = fcntl(fd, F_SETLEASE, leasetype);
+       if (ret == -1) {
+               saved_errno = errno;
        }
 
+  out:
+
+       unbecome_root();
+
+       if (ret == -1) {
+               errno = saved_errno;
+       }
        return ret;
 }