]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
lib: add SELinux include and stub functions
authorAndrea Claudi <aclaudi@redhat.com>
Wed, 23 Aug 2023 17:30:01 +0000 (19:30 +0200)
committerDavid Ahern <dsahern@kernel.org>
Fri, 25 Aug 2023 00:34:31 +0000 (17:34 -0700)
ss provides some selinux stub functions, useful when iproute2 is
compiled without selinux support.

Move them to lib/ so we can use them in other iproute2 tools.

Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
include/selinux.h [new file with mode: 0644]
lib/Makefile
lib/selinux.c [new file with mode: 0644]
misc/ss.c

diff --git a/include/selinux.h b/include/selinux.h
new file mode 100644 (file)
index 0000000..499aa96
--- /dev/null
@@ -0,0 +1,9 @@
+#if HAVE_SELINUX
+#include <selinux/selinux.h>
+#else
+int is_selinux_enabled(void);
+void freecon(char *context);
+int getpidcon(pid_t pid, char **context);
+int getfilecon(const char *path, char **context);
+int security_get_initial_context(const char *name,  char **context);
+#endif
index ddedd37feb3293deec2705e55ab9d005c1ecb7f0..aa7bbd2ecb4d994223413289689733e48dcdcdb2 100644 (file)
@@ -13,6 +13,10 @@ UTILOBJ += bpf_libbpf.o
 endif
 endif
 
+ifneq ($(HAVE_SELINUX),y)
+UTILOBJ += selinux.o
+endif
+
 NLOBJ=libgenl.o libnetlink.o
 ifeq ($(HAVE_MNL),y)
 NLOBJ += mnl_utils.o
diff --git a/lib/selinux.c b/lib/selinux.c
new file mode 100644 (file)
index 0000000..4e6805f
--- /dev/null
@@ -0,0 +1,32 @@
+#include <stdlib.h>
+#include <unistd.h>
+#include "selinux.h"
+
+/* Stubs for SELinux functions */
+int is_selinux_enabled(void)
+{
+       return 0;
+}
+
+void freecon(char *context)
+{
+       free(context);
+}
+
+int getpidcon(pid_t pid, char **context)
+{
+       *context = NULL;
+       return -1;
+}
+
+int getfilecon(const char *path, char **context)
+{
+       *context = NULL;
+       return -1;
+}
+
+int security_get_initial_context(const char *name,  char **context)
+{
+       *context = NULL;
+       return -1;
+}
index b3183630fdac89c5643afa437afc2556ff796424..2ef19039e1f028facfd332b2216d0a6c13bb2789 100644 (file)
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -33,6 +33,7 @@
 #include "version.h"
 #include "rt_names.h"
 #include "cg_map.h"
+#include "selinux.h"
 
 #include <linux/tcp.h>
 #include <linux/unix_diag.h>
 #define BUF_CHUNKS_MAX 5       /* Maximum number of allocated buffer chunks */
 #define LEN_ALIGN(x) (((x) + 1) & ~1)
 
-#if HAVE_SELINUX
-#include <selinux/selinux.h>
-#else
-/* Stubs for SELinux functions */
-static int is_selinux_enabled(void)
-{
-       return 0;
-}
-
-static int getpidcon(pid_t pid, char **context)
-{
-       *context = NULL;
-       return -1;
-}
-
-static int getfilecon(const char *path, char **context)
-{
-       *context = NULL;
-       return -1;
-}
-
-static int security_get_initial_context(const char *name,  char **context)
-{
-       *context = NULL;
-       return -1;
-}
-
-static void freecon(char *context)
-{
-       free(context);
-}
-#endif
-
 int preferred_family = AF_UNSPEC;
 static int show_options;
 int show_details;