|
7 | 7 | #include "linyaps_box/runtime.h" |
8 | 8 | #include "linyaps_box/status_directory_manager.h" |
9 | 9 |
|
| 10 | +#ifdef LINYAPS_BOX_ENABLE_CAP |
| 11 | +# include <sys/capability.h> |
| 12 | +#endif |
| 13 | + |
10 | 14 | auto linyaps_box::command::exec(const struct exec_options &options) -> int |
11 | 15 | { |
12 | 16 | status_directory_manager mgr(options.global_.get().root); |
@@ -37,30 +41,21 @@ auto linyaps_box::command::exec(const struct exec_options &options) -> int |
37 | 41 | option.proc.capabilities.emplace(); |
38 | 42 | } |
39 | 43 |
|
40 | | - auto transform_cap = [&caps](std::optional<std::vector<cap_value_t>> &cap_set) { |
41 | | - if (!cap_set) { |
42 | | - cap_set.emplace(); |
| 44 | + std::vector<cap_value_t> parsed; |
| 45 | + parsed.reserve(caps.size()); |
| 46 | + for (const auto &name : caps) { |
| 47 | + cap_value_t val{ }; |
| 48 | + if (cap_from_name(name.c_str(), &val) < 0) { |
| 49 | + throw std::system_error(errno, std::system_category(), "cap_from_name"); |
43 | 50 | } |
44 | 51 |
|
45 | | - cap_set->reserve(caps.size()); |
46 | | - std::transform( |
47 | | - caps.cbegin(), |
48 | | - caps.cend(), |
49 | | - std::back_inserter(*cap_set), |
50 | | - [](const std::string &cap) { |
51 | | - cap_value_t val{ 0 }; |
52 | | - if (cap_from_name(cap.c_str(), &val) < 0) { |
53 | | - throw std::system_error(errno, std::system_category(), "cap_from_name"); |
54 | | - } |
55 | | - |
56 | | - return val; |
57 | | - }); |
58 | | - }; |
| 52 | + parsed.push_back(val); |
| 53 | + } |
59 | 54 |
|
60 | | - transform_cap(option.proc.capabilities->effective); |
61 | | - transform_cap(option.proc.capabilities->ambient); |
62 | | - transform_cap(option.proc.capabilities->bounding); |
63 | | - transform_cap(option.proc.capabilities->permitted); |
| 55 | + option.proc.capabilities->effective = parsed; |
| 56 | + option.proc.capabilities->ambient = parsed; |
| 57 | + option.proc.capabilities->bounding = parsed; |
| 58 | + option.proc.capabilities->permitted = parsed; |
64 | 59 | } |
65 | 60 | #endif |
66 | 61 |
|
|
0 commit comments