Avoid that annoying "uses 32-bit capabilities (legacy support in use)" warning.
authorDaniel Hokka Zakrisson <daniel@hozac.com>
Sat, 3 May 2008 17:00:14 +0000 (17:00 +0000)
committerDaniel Hokka Zakrisson <daniel@hozac.com>
Sat, 3 May 2008 17:00:14 +0000 (17:00 +0000)
git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@2717 94cd875c-1c1d-0410-91d2-eb244daf1a30

src/capability-compat.h
src/rpm-fake.c
src/vserver-info.c

index 8493080..8a684c6 100644 (file)
@@ -29,3 +29,11 @@ extern int capget (struct __user_cap_header_struct *, struct __user_cap_data_str
 extern int capset (struct __user_cap_header_struct *, struct __user_cap_data_struct *);
 
 #endif
+
+#ifndef _LINUX_CAPABILITY_VERSION_1
+#  define _LINUX_CAPABILITY_VERSION_1  _LINUX_CAPABILITY_VERSION
+#endif
+
+#ifndef _LINUX_CAPABILITY_VERSION_2
+#  define _LINUX_CAPABILITY_VERSION_2  0x20071026
+#endif
index 26c5fa8..0e3a936 100644 (file)
@@ -419,22 +419,30 @@ initPwSocket()
 static void
 reduceCapabilities()
 {
+  int retried = 0;
   struct __user_cap_header_struct header;
-  struct __user_cap_data_struct user;
+  struct __user_cap_data_struct user[2];
   
-  header.version = _LINUX_CAPABILITY_VERSION;
+  header.version = _LINUX_CAPABILITY_VERSION_2;
   header.pid     = 0;
 
-  if (capget(&header, &user)==-1) {
+retry:
+  if (capget(&header, user)==-1) {
+    if (!retried &&
+       header.version != _LINUX_CAPABILITY_VERSION_2) {
+      header.version = _LINUX_CAPABILITY_VERSION_1;
+      retried = 1;
+      goto retry;
+    }
     perror("capget()");
     exit(wrapper_exit_code);
   }
 
-  user.effective   &= ~(1<<CAP_MKNOD);
-  user.permitted   &= ~(1<<CAP_MKNOD);
-  user.inheritable &= ~(1<<CAP_MKNOD);
+  user[0].effective   &= ~(1<<CAP_MKNOD);
+  user[0].permitted   &= ~(1<<CAP_MKNOD);
+  user[0].inheritable &= ~(1<<CAP_MKNOD);
 
-  if (capset(&header, &user)==-1) {
+  if (capset(&header, user)==-1) {
     perror("capset()");
     exit(wrapper_exit_code);
   }
index d28bf28..014489d 100644 (file)
@@ -185,9 +185,11 @@ verifyProc()
 static bool
 verifyCap()
 {
+  int retried = 0;
   struct __user_cap_header_struct header;
-  struct __user_cap_data_struct user;
-  header.version = _LINUX_CAPABILITY_VERSION;
+  struct __user_cap_data_struct user[2];
+
+  header.version = _LINUX_CAPABILITY_VERSION_2;
   header.pid     = 0;
 
   if (getuid()!=0) {
@@ -199,17 +201,24 @@ verifyCap()
 //    perror( "prctl:" );
 //    return false;
 //  }
-  
-  if (capget(&header, &user)==-1) {
+
+retry:
+  if (capget(&header, user)==-1) {
+    if (!retried &&
+       header.version != _LINUX_CAPABILITY_VERSION_2) {
+      header.version = _LINUX_CAPABILITY_VERSION_1;
+      retried = 1;
+      goto retry;
+    }
     perror("capget()");
     return false;
   }
 
-  user.effective   = 0;
-  user.permitted   = 0;
-  user.inheritable = 0;
+  user[0].effective   = user[1].effective   = 0;
+  user[0].permitted   = user[1].permitted   = 0;
+  user[0].inheritable = user[1].inheritable = 0;
 
-  if (capset(&header, &user)==-1) {
+  if (capset(&header, user)==-1) {
     perror("capset()");
     return false;
   }