程式語言 - GNU - C/C++ - Set Capability



main.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/capability.h>

int main(int argc, char **argv)
{
    cap_t caps = {0};
    unsigned cap_num = 1;
    cap_value_t cap_list[1] = {CAP_SYS_ADMIN};

    caps = cap_init();
    cap_set_flag(caps, CAP_EFFECTIVE, cap_num, cap_list, CAP_SET);
    cap_set_flag(caps, CAP_INHERITABLE, cap_num, cap_list, CAP_SET);
    cap_set_flag(caps, CAP_PERMITTED, cap_num, cap_list, CAP_SET);
    cap_set_proc(caps);
    cap_free(caps);
    return 0;
}