summaryrefslogtreecommitdiff
path: root/src/lookup_table.c
diff options
context:
space:
mode:
authorDariusz Michaluk <d.michaluk@samsung.com>2024-02-16 12:29:59 +0100
committerDariusz Michaluk <d.michaluk@samsung.com>2024-02-16 12:29:59 +0100
commit3ec0912f27cde058107543db7e8e6a65e44d18b3 (patch)
tree02a7601c2964f9c712b919a223dda094ff0c2369 /src/lookup_table.c
parentc591394f75d0462d9d9a17d66c1bcf800181a294 (diff)
downloadlibcap-ng-upstream.tar.gz
libcap-ng-upstream.tar.bz2
libcap-ng-upstream.zip
Imported Upstream version 0.8.4upstream/0.8.4upstream
Diffstat (limited to 'src/lookup_table.c')
-rw-r--r--src/lookup_table.c34
1 files changed, 24 insertions, 10 deletions
diff --git a/src/lookup_table.c b/src/lookup_table.c
index e12eb3d..63fd0bd 100644
--- a/src/lookup_table.c
+++ b/src/lookup_table.c
@@ -1,5 +1,5 @@
-/* lookup_table.c --
- * Copyright 2009 Red Hat Inc., Durham, North Carolina.
+/* lookup_table.c --
+ * Copyright 2009, 2013 Red Hat Inc.
* All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
@@ -12,9 +12,10 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; see the file COPYING.LIB. If not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1335, USA.
*
* Authors:
* Steve Grubb <sgrubb@redhat.com>
@@ -24,13 +25,15 @@
#include <stddef.h>
#include <linux/capability.h>
#include <strings.h>
+#include <stdio.h>
+#include <stdlib.h> // free
-#ifndef CAP_LAST_CAP
-#define CAP_LAST_CAP CAP_AUDIT_CONTROL
-#endif
+#define hidden __attribute__ ((visibility ("hidden")))
+extern unsigned int last_cap hidden;
+
#undef cap_valid
-#define cap_valid(x) ((x) <= CAP_LAST_CAP)
+#define cap_valid(x) ((x) <= last_cap)
struct transtab {
@@ -104,12 +107,23 @@ int capng_name_to_capability(const char *name)
CAP_NG_CAPABILITY_NAMES, name);
}
+static char *ptr2 = NULL;
const char *capng_capability_to_name(unsigned int capability)
{
+ const char *ptr;
+
if (!cap_valid(capability))
return NULL;
- return capng_lookup_number(captab, captab_msgstr.str,
+ ptr = capng_lookup_number(captab, captab_msgstr.str,
CAP_NG_CAPABILITY_NAMES, capability);
+ if (ptr == NULL) { // This leaks memory, but should almost never be used
+ free(ptr2);
+ if (asprintf(&ptr2, "cap_%u", capability) < 0)
+ ptr = NULL;
+ else
+ ptr = ptr2;
+ }
+ return ptr;
}