cap_get_flag usage giving invalid parameter
by vlrk from LinuxQuestions.org on (#6G0E4)
Hi ,
I am trying out simple example for cap_get_flag.
setting some capability and in next line try to get the same .
some how it is giving a error.
Not able to know, what exactly missing here.
Any pointers would be highly helpfull.
Code:#include <stdio.h>
#include <sys/capability.h>
#include <sys/types.h>
#include <syslog.h>
int main() {
cap_t caps;
cap_value_t cap_list[3];
cap_list[0] = CAP_SETUID;
cap_list[1] = CAP_SETGID;
cap_list[2] = CAP_NET_ADMIN;
caps = cap_get_proc();
if(caps != NULL) {
cap_set_flag(caps, CAP_EFFECTIVE, 2, cap_list, CAP_SET);
cap_set_flag(caps, CAP_INHERITABLE, 2, cap_list, CAP_SET);
cap_set_flag(caps, CAP_PERMITTED, 2, cap_list, CAP_SET);
cap_set_proc(caps);
} else {
syslog(LOG_DEBUG, "Cap_get_proc() failed");
}
if (caps == NULL) {
perror("cap_get_proc");
return 1;
}
cap_flag_value_t flag_value;
if (cap_get_flag(caps, CAP_EFFECTIVE, CAP_NET_ADMIN, &flag_value) == -1) {
perror("cap_get_flag");
return 1;
}
if (flag_value == CAP_SET) {
printf("CAP_NET_BIND_SERVICE capability is set.\n");
} else {
printf("CAP_NET_BIND_SERVICE capability is not set.\n");
}
cap_free(caps);
return 0;
}output:
[root@141179 cprog]# ./a.out
cap_get_flag: Invalid argument
I am trying out simple example for cap_get_flag.
setting some capability and in next line try to get the same .
some how it is giving a error.
Not able to know, what exactly missing here.
Any pointers would be highly helpfull.
Code:#include <stdio.h>
#include <sys/capability.h>
#include <sys/types.h>
#include <syslog.h>
int main() {
cap_t caps;
cap_value_t cap_list[3];
cap_list[0] = CAP_SETUID;
cap_list[1] = CAP_SETGID;
cap_list[2] = CAP_NET_ADMIN;
caps = cap_get_proc();
if(caps != NULL) {
cap_set_flag(caps, CAP_EFFECTIVE, 2, cap_list, CAP_SET);
cap_set_flag(caps, CAP_INHERITABLE, 2, cap_list, CAP_SET);
cap_set_flag(caps, CAP_PERMITTED, 2, cap_list, CAP_SET);
cap_set_proc(caps);
} else {
syslog(LOG_DEBUG, "Cap_get_proc() failed");
}
if (caps == NULL) {
perror("cap_get_proc");
return 1;
}
cap_flag_value_t flag_value;
if (cap_get_flag(caps, CAP_EFFECTIVE, CAP_NET_ADMIN, &flag_value) == -1) {
perror("cap_get_flag");
return 1;
}
if (flag_value == CAP_SET) {
printf("CAP_NET_BIND_SERVICE capability is set.\n");
} else {
printf("CAP_NET_BIND_SERVICE capability is not set.\n");
}
cap_free(caps);
return 0;
}output:
[root@141179 cprog]# ./a.out
cap_get_flag: Invalid argument