2
* Copyright (c) 1997-8 Andrew G. Morgan <morgan@kernel.org>
4
* This sets the capabilities of a given process.
13
#include <sys/capability.h>
16
static void usage(void)
19
"usage: setcap [-q] (-|<caps>) <pid> [ ... (-|<capsN>) <pid> ]\n\n"
20
" This program can be used to set the process capabilities of running\n"
21
" processes. In order to work, it needs to be executing with CAP_SETPCAP\n"
22
" raised, and the only capabilities that this program can bestow on others\n"
23
" are a subset of its effective set. This program is mostly intended as an\n"
24
" example -- a safe use of CAP_SETPCAP has yet to be demonstrated!\n\n"
25
"[Copyright (c) 1997-8 Andrew G. Morgan <morgan@kernel.org>]\n"
32
static int read_caps(int quiet, const char *filename, char *buffer)
37
fprintf(stderr, "Please enter caps for file [empty line to end]:\n");
40
int j = read(STDIN_FILENO, buffer, i);
43
fprintf(stderr, "\n[Error - aborting]\n");
47
if (j==0 || buffer[0] == '\n') {
61
return (i < MAXCAP ? 0:-1);
64
int main(int argc, char **argv)
66
char buffer[MAXCAP+1];
78
if (!strcmp(*++argv,"-q")) {
82
if (!strcmp(*argv,"-")) {
83
retval = read_caps(quiet, *argv, buffer);
90
cap_d = cap_from_text(text);
92
perror("fatal error");
100
result = cap_to_text(cap_d, &length);
101
fprintf(stderr, "[caps set to:\n%s\n]\n", result);
111
retval = capsetp(pid, cap_d);
114
fprintf(stderr, "Failed to set cap's on process `%d': (%s)\n",
115
pid, strerror(errno));
119
fprintf(stderr, "[caps set on %d]\n", pid);