Skip to content

Commit

Permalink
src: use cap_get_proc
Browse files Browse the repository at this point in the history
This commit uses cap_get_proc from libcap as an alternative to using
getcap.
  • Loading branch information
danbev committed Mar 23, 2021
1 parent 9e3b90e commit b52cd99
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@
}],
[ 'OS in "linux freebsd openbsd solaris aix"', {
'cflags': [ '-pthread' ],
'ldflags': [ '-pthread' ],
'ldflags': [ '-pthread', '-lcap' ],
}],
[ 'OS in "linux freebsd openbsd solaris android aix cloudabi"', {
'cflags': [ '-Wall', '-Wextra', '-Wno-unused-parameter', ],
Expand Down
14 changes: 7 additions & 7 deletions src/node_credentials.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ namespace credentials {
#if !defined(__CloudABI__) && !defined(_WIN32)
// Returns true if the current process has effective capabilities and the
// passed-in capability is in that set.
bool HasCapability(int capability) {
bool HasCapability(cap_value_t capability) {
DCHECK(cap_valid(capability));
struct __user_cap_header_struct cap_header_data = {
_LINUX_CAPABILITY_VERSION_1, getpid()
};
struct __user_cap_data_struct cap_data;

if (capget(&cap_header_data, &cap_data) == -1) {
cap_t cap = cap_get_proc();
if (cap == nullptr) {
return false;
}
cap_flag_value_t cap_flag_value;
cap_get_flag(cap, capability, CAP_EFFECTIVE, &cap_flag_value);

return cap_data.effective & CAP_TO_MASK(capability);
cap_free(cap);
return cap_flag_value == 1;
}
#endif

Expand Down

0 comments on commit b52cd99

Please sign in to comment.