2 * Copyright (c) 2023 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * setcaps - Set capability restrictions on the parent process of this
36 * program (usually a shell).
38 #include <sys/types.h>
48 static void printallcaps(void);
49 static void listcaps(void);
52 main(int ac
, char **av
)
61 while ((c
= getopt(ac
, av
, "plqh")) != -1) {
76 fprintf(stderr
, "Bad option: -%c\n", c
);
77 fprintf(stderr
, "setcaps [-p] [-l] caps...\n");
78 fprintf(stderr
, " -p - list available caps\n");
79 fprintf(stderr
, " -l - list current caps\n");
80 fprintf(stderr
, " -q - ignore unknown caps\n");
81 fprintf(stderr
, " caps[:es] - set specific flags\n");
82 fprintf(stderr
, " If no args, current caps are "
92 for (j
= 0; j
< ac
; ++j
) {
96 int flags
= __SYSCAP_SELF
| __SYSCAP_EXEC
;
102 if ((scan
= strchr(which
, ':')) != NULL
) {
108 flags
|= __SYSCAP_SELF
;
111 flags
|= __SYSCAP_EXEC
;
114 fprintf(stderr
, "unknown flag %s:%c\n",
121 for (i
= 0; i
< __SYSCAP_COUNT
; ++i
) {
124 ptr
= SyscapAllStrings
[i
/ 16][i
& 15];
125 if (ptr
== NULL
|| strcmp(ptr
, which
) != 0)
128 res
= syscap_set(i
| __SYSCAP_INPARENT
, flags
, NULL
, 0);
130 fprintf(stderr
, "%s: %s\n",
131 which
, strerror(errno
));
134 printf("%s: ", which
);
135 if (res
& __SYSCAP_EXEC
)
137 if (res
& __SYSCAP_SELF
)
142 if (found
== 0 && quietopt
== 0) {
143 printf("%s: not-found\n", which
);
158 for (i
= 0; i
< __SYSCAP_COUNT
; ++i
) {
159 if ((ptr
= SyscapAllStrings
[i
/ 16][i
& 15]) != NULL
) {
160 printf("0x%04x %s\n", i
, ptr
);
170 for (i
= 0; i
< __SYSCAP_COUNT
; ++i
) {
174 res
= syscap_get(i
| __SYSCAP_INPARENT
, NULL
, 0);
178 if ((ptr
= SyscapAllStrings
[i
/ 16][i
& 15]) != NULL
) {
179 printf("%-15s", ptr
);
181 printf("0x%04x ", res
);
183 if (res
& __SYSCAP_EXEC
)
185 if (res
& __SYSCAP_SELF
)