1From 0859d2570ddc7ff9ff5c7dc1309dea88eef2168a Mon Sep 17 00:00:00 2001
2From: Michael Forney <mforney@mforney.org>
3Date: Tue, 4 Jul 2023 19:20:51 -0700
4Subject: [PATCH] Use external string-to-cap function
5
6---
7 bubblewrap.c | 16 +++++++++++-----
8 1 file changed, 11 insertions(+), 5 deletions(-)
9
10diff --git a/bubblewrap.c b/bubblewrap.c
11index d834618..bc53891 100644
12--- a/bubblewrap.c
13+++ b/bubblewrap.c
14@@ -30,8 +30,8 @@
15 #include <sys/eventfd.h>
16 #include <sys/fsuid.h>
17 #include <sys/signalfd.h>
18-#include <sys/capability.h>
19 #include <sys/prctl.h>
20+#include <linux/capability.h>
21 #include <linux/sched.h>
22 #include <linux/seccomp.h>
23 #include <linux/filter.h>
24@@ -44,6 +44,10 @@
25 #define CLONE_NEWCGROUP 0x02000000 /* New cgroup namespace */
26 #endif
27
28+int capset(void *, void *);
29+int capget(void *, void *);
30+int cap_from_name(const char *);
31+
32 /* We limit the size of a tmpfs to half the architecture's address space,
33 * to avoid hitting arbitrary limits in the kernel.
34 * For example, on at least one x86_64 machine, the actual limit seems to be
35@@ -2604,7 +2608,7 @@ parse_args_recurse (int *argcp,
36 }
37 else if (strcmp (arg, "--cap-add") == 0)
38 {
39- cap_value_t cap;
40+ int cap;
41 if (argc < 2)
42 die ("--cap-add takes an argument");
43
44@@ -2616,7 +2620,8 @@ parse_args_recurse (int *argcp,
45 }
46 else
47 {
48- if (cap_from_name (argv[1], &cap) < 0)
49+ cap = cap_from_name (argv[1]);
50+ if (cap < 0)
51 die ("unknown cap: %s", argv[1]);
52
53 if (cap < 32)
54@@ -2630,7 +2635,7 @@ parse_args_recurse (int *argcp,
55 }
56 else if (strcmp (arg, "--cap-drop") == 0)
57 {
58- cap_value_t cap;
59+ int cap;
60 if (argc < 2)
61 die ("--cap-drop takes an argument");
62
63@@ -2642,7 +2647,8 @@ parse_args_recurse (int *argcp,
64 }
65 else
66 {
67- if (cap_from_name (argv[1], &cap) < 0)
68+ cap = cap_from_name (argv[1]);
69+ if (cap < 0)
70 die ("unknown cap: %s", argv[1]);
71
72 if (cap < 32)
73--
742.44.0
75