Skip to content

Commit b52cd99

Browse files
committed
src: use cap_get_proc
This commit uses cap_get_proc from libcap as an alternative to using getcap.
1 parent 9e3b90e commit b52cd99

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

common.gypi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@
371371
}],
372372
[ 'OS in "linux freebsd openbsd solaris aix"', {
373373
'cflags': [ '-pthread' ],
374-
'ldflags': [ '-pthread' ],
374+
'ldflags': [ '-pthread', '-lcap' ],
375375
}],
376376
[ 'OS in "linux freebsd openbsd solaris android aix cloudabi"', {
377377
'cflags': [ '-Wall', '-Wextra', '-Wno-unused-parameter', ],

src/node_credentials.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,18 @@ namespace credentials {
3737
#if !defined(__CloudABI__) && !defined(_WIN32)
3838
// Returns true if the current process has effective capabilities and the
3939
// passed-in capability is in that set.
40-
bool HasCapability(int capability) {
40+
bool HasCapability(cap_value_t capability) {
4141
DCHECK(cap_valid(capability));
42-
struct __user_cap_header_struct cap_header_data = {
43-
_LINUX_CAPABILITY_VERSION_1, getpid()
44-
};
45-
struct __user_cap_data_struct cap_data;
4642

47-
if (capget(&cap_header_data, &cap_data) == -1) {
43+
cap_t cap = cap_get_proc();
44+
if (cap == nullptr) {
4845
return false;
4946
}
47+
cap_flag_value_t cap_flag_value;
48+
cap_get_flag(cap, capability, CAP_EFFECTIVE, &cap_flag_value);
5049

51-
return cap_data.effective & CAP_TO_MASK(capability);
50+
cap_free(cap);
51+
return cap_flag_value == 1;
5252
}
5353
#endif
5454

0 commit comments

Comments
 (0)