diff options
author | Denys Vlasenko | 2017-08-21 19:30:01 +0200 |
---|---|---|
committer | Denys Vlasenko | 2017-08-21 19:30:01 +0200 |
commit | 200bcc851acbe1ba30fe90b5cf918f88370a5d15 (patch) | |
tree | 50f4d5ac42869548b78b00470d7b80b50a28157a /libbb | |
parent | 44b3f2ffbc01c0a9fcfb5d60af3e292f505ac67c (diff) | |
download | busybox-200bcc851acbe1ba30fe90b5cf918f88370a5d15.zip busybox-200bcc851acbe1ba30fe90b5cf918f88370a5d15.tar.gz |
run-init: new applet
function old new delta
switch_root_main 354 637 +283
drop_usermodehelper - 157 +157
cap_name_to_number - 77 +77
packed_usage 31707 31743 +36
applet_names 2665 2674 +9
applet_main 1544 1548 +4
applet_install_loc 193 194 +1
setpriv_main 933 928 -5
getcaps 131 122 -9
parse_cap 117 29 -88
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 5/3 up/down: 567/-102) Total: 465 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/capability.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/libbb/capability.c b/libbb/capability.c index 692024f..f60062b 100644 --- a/libbb/capability.c +++ b/libbb/capability.c @@ -6,6 +6,14 @@ //kbuild:lib-$(CONFIG_PLATFORM_LINUX) += capability.o #include <linux/capability.h> +// #include <sys/capability.h> +// This header is in libcap, but the functions are in libc. +// Comment in the header says this above capset/capget: +/* system calls - look to libc for function to system call mapping */ +extern int capset(cap_user_header_t header, cap_user_data_t data); +extern int capget(cap_user_header_t header, const cap_user_data_t data); +// so for bbox, let's just repeat the declarations. +// This way, libcap needs not be installed in build environment. #include "libbb.h" static const char *const capabilities[] = { @@ -77,3 +85,42 @@ void FAST_FUNC printf_cap(const char *pfx, unsigned cap_no) } printf("%scap_%u", pfx, cap_no); } + +DEFINE_STRUCT_CAPS; + +void FAST_FUNC getcaps(void *arg) +{ + static const uint8_t versions[] = { + _LINUX_CAPABILITY_U32S_3, /* = 2 (fits into byte) */ + _LINUX_CAPABILITY_U32S_2, /* = 2 */ + _LINUX_CAPABILITY_U32S_1, /* = 1 */ + }; + int i; + struct caps *caps = arg; + + caps->header.pid = 0; + for (i = 0; i < ARRAY_SIZE(versions); i++) { + caps->header.version = versions[i]; + if (capget(&caps->header, NULL) == 0) + goto got_it; + } + bb_simple_perror_msg_and_die("capget"); + got_it: + + switch (caps->header.version) { + case _LINUX_CAPABILITY_VERSION_1: + caps->u32s = _LINUX_CAPABILITY_U32S_1; + break; + case _LINUX_CAPABILITY_VERSION_2: + caps->u32s = _LINUX_CAPABILITY_U32S_2; + break; + case _LINUX_CAPABILITY_VERSION_3: + caps->u32s = _LINUX_CAPABILITY_U32S_3; + break; + default: + bb_error_msg_and_die("unsupported capability version"); + } + + if (capget(&caps->header, caps->data) != 0) + bb_simple_perror_msg_and_die("capget"); +} |