Skip to contentSkip to conversation

exporting capability code/name pairs (try 2nd)

PATCH In review Kohei KaiGai 1 participant 1 message Jan 25, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 2/3 exporting capability code/name pairs (try 2nd)

We can apply this patch to libcap.
It enables to obtain the list of capabilities running kernel supported dynamically, from /sys/kernel/capability.

When we use libcap with this patch on the previous kernel, it apply static list of capabilities instead.

Thanks,
----

libcap/_makenames.c +1 -1
index 212f0b4..c57e940 100644
@@ -43,7 +43,7 @@ int main(void)
 	   "#define __CAP_BITS   %d\n"
 	   "\n"
 	   "#ifdef LIBCAP_PLEASE_INCLUDE_ARRAY\n"
-	   "  char const *_cap_names[__CAP_BITS] = {\n", maxcaps);
+	   "  static const char *_cap_names_fallback[__CAP_BITS] = {\n", maxcaps);
 
     for (i=0; i<maxcaps; ++i) {
 	if (pointers[i])
libcap/cap_flag.c +3 -3
index e521fcd..f490b29 100644
@@ -21,7 +21,7 @@ int cap_get_flag(cap_t cap_d, cap_value_t value, cap_flag_t set,
      * Is it a known capability?
      */
 
-    if (raised && good_cap_t(cap_d) && value >= 0 && value < __CAP_BITS
+    if (raised && good_cap_t(cap_d) && value >= 0 && value < _cap_names_num
 	&& set >= 0 && set < NUMBER_OF_CAP_SETS) {
 	*raised = isset_cap(cap_d,value,set) ? CAP_SET:CAP_CLEAR;
 	return 0;
@@ -45,12 +45,12 @@ int cap_set_flag(cap_t cap_d, cap_flag_t set,
      * Is it a known capability?
      */
 
-    if (good_cap_t(cap_d) && no_values > 0 && no_values <= __CAP_BITS
+    if (good_cap_t(cap_d) && no_values > 0 && no_values <= _cap_names_num
 	&& (set >= 0) && (set < NUMBER_OF_CAP_SETS)
 	&& (raise == CAP_SET || raise == CAP_CLEAR) ) {
 	int i;
 	for (i=0; i<no_values; ++i) {
-	    if (array_values[i] < 0 || array_values[i] >= __CAP_BITS) {
+	    if (array_values[i] < 0 || array_values[i] >= _cap_names_num) {
 		_cap_debug("weird capability (%d) - skipped", array_values[i]);
 	    } else {
 		int value = array_values[i];
libcap/cap_text.c +73 -4

119 lines not on this page · raw message

libcap/libcap.h +2 -2
index 0e4a167..b5a5deb 100644
@@ -22,8 +22,8 @@
 #define __u32   unsigned int
 #endif /* __u32 */
 
-/* include the names for the caps and a definition of __CAP_BITS */
-#include "cap_names.h"
+extern char **_cap_names;
+extern int _cap_names_num;
 
 /*
  * Do we match the local kernel?
Signature · 2 lines
OSS Platform Development Division, NEC
KaiGai Kohei <[email protected]>