aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew G. Morgan <morgan@kernel.org>2008-05-26 17:20:06 -0700
committerAndrew G. Morgan <morgan@kernel.org>2008-05-26 17:20:06 -0700
commitebf9f5b9e2623732953f1842990ba50091fe775d (patch)
treecf876b0c3eaf07f6a4480931af7c59111b46a84e
parent85aaecf6a816ebcf01d76772677ea156d26887c3 (diff)
downloadlibcap-ebf9f5b9e2623732953f1842990ba50091fe775d.tar.gz
We're moving on to v3 capabilities, to overcome a header file snafu.
v3 capabilities are functionally equivalent to v2 capabilities, but having a different magic value allow the kernel to warn about possibly unsafe use of v2 capabilities. Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
-rw-r--r--libcap/cap_alloc.c4
-rw-r--r--libcap/cap_file.c8
-rw-r--r--libcap/cap_text.c6
-rw-r--r--libcap/include/linux/capability.h41
-rw-r--r--libcap/libcap.h14
5 files changed, 57 insertions, 16 deletions
diff --git a/libcap/cap_alloc.c b/libcap/cap_alloc.c
index c44c7b8..5fa5e93 100644
--- a/libcap/cap_alloc.c
+++ b/libcap/cap_alloc.c
@@ -40,6 +40,10 @@ cap_t cap_init(void)
case _LINUX_CAPABILITY_VERSION_2:
break;
#endif
+#ifdef _LINUX_CAPABILITY_VERSION_3
+ case _LINUX_CAPABILITY_VERSION_3:
+ break;
+#endif
default: /* No idea what to do */
cap_free(result);
result = NULL;
diff --git a/libcap/cap_file.c b/libcap/cap_file.c
index c025bf5..914ace1 100644
--- a/libcap/cap_file.c
+++ b/libcap/cap_file.c
@@ -112,6 +112,14 @@ static int _fcaps_save(struct vfs_cap_data *rawvfscap, cap_t cap_d,
break;
#endif
+#ifdef _LINUX_CAPABILITY_VERSION_3
+ case _LINUX_CAPABILITY_VERSION_3:
+ magic = VFS_CAP_REVISION_2;
+ tocopy = VFS_CAP_U32_2;
+ *bytes_p = XATTR_CAPS_SZ_2;
+ break;
+#endif
+
default:
errno = EINVAL;
return -1;
diff --git a/libcap/cap_text.c b/libcap/cap_text.c
index e736aee..1eaa7ae 100644
--- a/libcap/cap_text.c
+++ b/libcap/cap_text.c
@@ -158,6 +158,9 @@ cap_t cap_from_text(const char *str)
case _LINUX_CAPABILITY_VERSION_2:
cap_blks = _LINUX_CAPABILITY_U32S_2;
break;
+ case _LINUX_CAPABILITY_VERSION_3:
+ cap_blks = _LINUX_CAPABILITY_U32S_3;
+ break;
default:
errno = EINVAL;
return NULL;
@@ -387,6 +390,9 @@ char *cap_to_text(cap_t caps, ssize_t *length_p)
case _LINUX_CAPABILITY_VERSION_2:
cap_blks = _LINUX_CAPABILITY_U32S_2;
break;
+ case _LINUX_CAPABILITY_VERSION_3:
+ cap_blks = _LINUX_CAPABILITY_U32S_3;
+ break;
default:
errno = EINVAL;
return NULL;
diff --git a/libcap/include/linux/capability.h b/libcap/include/linux/capability.h
index eaab759..272e040 100644
--- a/libcap/include/linux/capability.h
+++ b/libcap/include/linux/capability.h
@@ -31,11 +31,11 @@ struct task_struct;
#define _LINUX_CAPABILITY_VERSION_1 0x19980330
#define _LINUX_CAPABILITY_U32S_1 1
-#define _LINUX_CAPABILITY_VERSION_2 0x20071026
+#define _LINUX_CAPABILITY_VERSION_2 0x20071026 /* depreciated - use v3 */
#define _LINUX_CAPABILITY_U32S_2 2
-#define _LINUX_CAPABILITY_VERSION _LINUX_CAPABILITY_VERSION_2
-#define _LINUX_CAPABILITY_U32S _LINUX_CAPABILITY_U32S_2
+#define _LINUX_CAPABILITY_VERSION_3 0x20080522
+#define _LINUX_CAPABILITY_U32S_3 2
typedef struct __user_cap_header_struct {
__u32 version;
@@ -77,10 +77,23 @@ struct vfs_cap_data {
} data[VFS_CAP_U32];
};
-#ifdef __KERNEL__
+#ifndef __KERNEL__
+
+/*
+ * Backwardly compatible definition for source code - trapped in a
+ * 32-bit world. If you find you need this, please consider using
+ * libcap to untrap yourself...
+ */
+#define _LINUX_CAPABILITY_VERSION _LINUX_CAPABILITY_VERSION_1
+#define _LINUX_CAPABILITY_U32S _LINUX_CAPABILITY_U32S_1
+
+#else
+
+#define _KERNEL_CAPABILITY_VERSION _LINUX_CAPABILITY_VERSION_3
+#define _KERNEL_CAPABILITY_U32S _LINUX_CAPABILITY_U32S_3
typedef struct kernel_cap_struct {
- __u32 cap[_LINUX_CAPABILITY_U32S];
+ __u32 cap[_KERNEL_CAPABILITY_U32S];
} kernel_cap_t;
#define _USER_CAP_HEADER_SIZE (sizeof(struct __user_cap_header_struct))
@@ -351,7 +364,7 @@ typedef struct kernel_cap_struct {
*/
#define CAP_FOR_EACH_U32(__capi) \
- for (__capi = 0; __capi < _LINUX_CAPABILITY_U32S; ++__capi)
+ for (__capi = 0; __capi < _KERNEL_CAPABILITY_U32S; ++__capi)
# define CAP_FS_MASK_B0 (CAP_TO_MASK(CAP_CHOWN) \
| CAP_TO_MASK(CAP_DAC_OVERRIDE) \
@@ -361,18 +374,18 @@ typedef struct kernel_cap_struct {
# define CAP_FS_MASK_B1 (CAP_TO_MASK(CAP_MAC_OVERRIDE))
-#if _LINUX_CAPABILITY_U32S != 2
+#if _KERNEL_CAPABILITY_U32S != 2
# error Fix up hand-coded capability macro initializers
#else /* HAND-CODED capability initializers */
-# define CAP_EMPTY_SET {{ 0, 0 }}
-# define CAP_FULL_SET {{ ~0, ~0 }}
-# define CAP_INIT_EFF_SET {{ ~CAP_TO_MASK(CAP_SETPCAP), ~0 }}
-# define CAP_FS_SET {{ CAP_FS_MASK_B0, CAP_FS_MASK_B1 } }
-# define CAP_NFSD_SET {{ CAP_FS_MASK_B0|CAP_TO_MASK(CAP_SYS_RESOURCE), \
- CAP_FS_MASK_B1 } }
+# define CAP_EMPTY_SET ((kernel_cap_t){{ 0, 0 }})
+# define CAP_FULL_SET ((kernel_cap_t){{ ~0, ~0 }})
+# define CAP_INIT_EFF_SET ((kernel_cap_t){{ ~CAP_TO_MASK(CAP_SETPCAP), ~0 }})
+# define CAP_FS_SET ((kernel_cap_t){{ CAP_FS_MASK_B0, CAP_FS_MASK_B1 } })
+# define CAP_NFSD_SET ((kernel_cap_t){{ CAP_FS_MASK_B0|CAP_TO_MASK(CAP_SYS_RESOURCE), \
+ CAP_FS_MASK_B1 } })
-#endif /* _LINUX_CAPABILITY_U32S != 2 */
+#endif /* _KERNEL_CAPABILITY_U32S != 2 */
#define CAP_INIT_INH_SET CAP_EMPTY_SET
diff --git a/libcap/libcap.h b/libcap/libcap.h
index c763b84..4f64bd9 100644
--- a/libcap/libcap.h
+++ b/libcap/libcap.h
@@ -50,6 +50,16 @@
# _LIBCAP_CAPABILITY_VERSION _LINUX_CAPABILITY_VERSION_1
# _LIBCAP_CAPABILITY_U32S _LINUX_CAPABILITY_U32S_1
+#elif defined(_LINUX_CAPABILITY_VERSION_3)
+
+# if (_LINUX_CAPABILITY_VERSION_3 != 0x20080522)
+# error Kernel <linux/capability.h> v3 does not match library
+# error file "libcap.h" --> fix and recompile libcap
+# else
+# define _LIBCAP_CAPABILITY_VERSION _LINUX_CAPABILITY_VERSION_3
+# define _LIBCAP_CAPABILITY_U32S _LINUX_CAPABILITY_U32S_3
+# endif
+
#elif (_LINUX_CAPABILITY_VERSION_2 != 0x20071026)
# error Kernel <linux/capability.h> does not match library
@@ -57,8 +67,8 @@
#else
-#define _LIBCAP_CAPABILITY_VERSION _LINUX_CAPABILITY_VERSION_2
-#define _LIBCAP_CAPABILITY_U32S _LINUX_CAPABILITY_U32S_2
+# define _LIBCAP_CAPABILITY_VERSION _LINUX_CAPABILITY_VERSION_2
+# define _LIBCAP_CAPABILITY_U32S _LINUX_CAPABILITY_U32S_2
#endif