10 #include <sys/capability.h> 13 #include <sys/prctl.h> 17 #define EXECUTABLE "/var/tmp/granted" 19 int main(
int argc,
char *argv[])
26 cmd = string(
"cp ") + string(argv[1]) + string(
" " EXECUTABLE);
27 if (system(cmd.c_str()) == -1) {
31 if (chown(
EXECUTABLE, getuid(), getgid()) < 0) {
37 const char *cap_text =
"cap_ipc_lock=ep cap_net_raw=ep cap_sys_nice=ep cap_net_admin=ep";
38 cap_t cap_d = cap_from_text(cap_text);
40 perror(
"cap_from_text");
47 fprintf(stderr,
"Failed to set capabilities on file `%s' (%s)\n", argv[1], strerror(errno));
58 retval = setuid(getuid());
59 retval = setgid(getgid());
62 prctl(PR_SET_DUMPABLE, 1, 0, 0, 0);
int main(int argc, char *argv[])