diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-08-21 19:30:01 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-08-21 19:30:01 +0200 |
commit | 200bcc851acbe1ba30fe90b5cf918f88370a5d15 (patch) | |
tree | 50f4d5ac42869548b78b00470d7b80b50a28157a /libbb/capability.c | |
parent | 44b3f2ffbc01c0a9fcfb5d60af3e292f505ac67c (diff) | |
download | busybox-w32-200bcc851acbe1ba30fe90b5cf918f88370a5d15.tar.gz busybox-w32-200bcc851acbe1ba30fe90b5cf918f88370a5d15.tar.bz2 busybox-w32-200bcc851acbe1ba30fe90b5cf918f88370a5d15.zip |
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/capability.c')
-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 692024f2f..f60062bfc 100644 --- a/libbb/capability.c +++ b/libbb/capability.c | |||
@@ -6,6 +6,14 @@ | |||
6 | //kbuild:lib-$(CONFIG_PLATFORM_LINUX) += capability.o | 6 | //kbuild:lib-$(CONFIG_PLATFORM_LINUX) += capability.o |
7 | 7 | ||
8 | #include <linux/capability.h> | 8 | #include <linux/capability.h> |
9 | // #include <sys/capability.h> | ||
10 | // This header is in libcap, but the functions are in libc. | ||
11 | // Comment in the header says this above capset/capget: | ||
12 | /* system calls - look to libc for function to system call mapping */ | ||
13 | extern int capset(cap_user_header_t header, cap_user_data_t data); | ||
14 | extern int capget(cap_user_header_t header, const cap_user_data_t data); | ||
15 | // so for bbox, let's just repeat the declarations. | ||
16 | // This way, libcap needs not be installed in build environment. | ||
9 | #include "libbb.h" | 17 | #include "libbb.h" |
10 | 18 | ||
11 | static const char *const capabilities[] = { | 19 | static const char *const capabilities[] = { |
@@ -77,3 +85,42 @@ void FAST_FUNC printf_cap(const char *pfx, unsigned cap_no) | |||
77 | } | 85 | } |
78 | printf("%scap_%u", pfx, cap_no); | 86 | printf("%scap_%u", pfx, cap_no); |
79 | } | 87 | } |
88 | |||
89 | DEFINE_STRUCT_CAPS; | ||
90 | |||
91 | void FAST_FUNC getcaps(void *arg) | ||
92 | { | ||
93 | static const uint8_t versions[] = { | ||
94 | _LINUX_CAPABILITY_U32S_3, /* = 2 (fits into byte) */ | ||
95 | _LINUX_CAPABILITY_U32S_2, /* = 2 */ | ||
96 | _LINUX_CAPABILITY_U32S_1, /* = 1 */ | ||
97 | }; | ||
98 | int i; | ||
99 | struct caps *caps = arg; | ||
100 | |||
101 | caps->header.pid = 0; | ||
102 | for (i = 0; i < ARRAY_SIZE(versions); i++) { | ||
103 | caps->header.version = versions[i]; | ||
104 | if (capget(&caps->header, NULL) == 0) | ||
105 | goto got_it; | ||
106 | } | ||
107 | bb_simple_perror_msg_and_die("capget"); | ||
108 | got_it: | ||
109 | |||
110 | switch (caps->header.version) { | ||
111 | case _LINUX_CAPABILITY_VERSION_1: | ||
112 | caps->u32s = _LINUX_CAPABILITY_U32S_1; | ||
113 | break; | ||
114 | case _LINUX_CAPABILITY_VERSION_2: | ||
115 | caps->u32s = _LINUX_CAPABILITY_U32S_2; | ||
116 | break; | ||
117 | case _LINUX_CAPABILITY_VERSION_3: | ||
118 | caps->u32s = _LINUX_CAPABILITY_U32S_3; | ||
119 | break; | ||
120 | default: | ||
121 | bb_error_msg_and_die("unsupported capability version"); | ||
122 | } | ||
123 | |||
124 | if (capget(&caps->header, caps->data) != 0) | ||
125 | bb_simple_perror_msg_and_die("capget"); | ||
126 | } | ||