]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
selinux: kill mac_selinux_free() 33037/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 21 May 2024 12:41:38 +0000 (14:41 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 12 Jun 2024 13:21:21 +0000 (15:21 +0200)
It was a redundant wrapper around freecon.

test-selinux needs to be adjusted because it now needs to be linked to
libselinux, instead of pulling it in via libshared.

src/core/selinux-setup.c
src/core/socket.c
src/portable/portable.c
src/shared/selinux-util.c
src/shared/selinux-util.h
src/test/meson.build
src/test/test-selinux.c

index bc1a24914e69171646b3cee0107eb8d95138f100..89f736b47bb116cf7eb2fffbd65f638cc8556f4d 100644 (file)
@@ -63,7 +63,7 @@ int mac_selinux_setup(bool *loaded_policy) {
         before_load = now(CLOCK_MONOTONIC);
         r = selinux_init_load_policy(&enforce);
         if (r == 0) {
-                _cleanup_(mac_selinux_freep) char *label = NULL;
+                _cleanup_freecon_ char *label = NULL;
 
                 mac_selinux_retest();
 
index 66733a269e527cdeae67b844db853f519e4a8fda..339d77fb9754c360416bb833999b51a25cb97369 100644 (file)
@@ -1615,7 +1615,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(Socket *, socket_close_fds, NULL);
 
 static int socket_open_fds(Socket *orig_s) {
         _cleanup_(socket_close_fdsp) Socket *s = orig_s;
-        _cleanup_(mac_selinux_freep) char *label = NULL;
+        _cleanup_freecon_ char *label = NULL;
         bool know_label = false;
         int r;
 
index 53418c417b51d072f0545906a5966534dff345f9..08e9bc0113915d10de1c8c1bf913c0ae8646499b 100644 (file)
@@ -267,7 +267,7 @@ static int extract_now(
 
                 FOREACH_DIRENT(de, d, return log_debug_errno(errno, "Failed to read directory: %m")) {
                         _cleanup_(portable_metadata_unrefp) PortableMetadata *m = NULL;
-                        _cleanup_(mac_selinux_freep) char *con = NULL;
+                        _cleanup_freecon_ char *con = NULL;
                         _cleanup_close_ int fd = -EBADF;
                         struct stat st;
 
index d2b1a3e554330c94b1c3e797d3cbeeb026a61aca..e626a60026e41c7aa7ef60ff67fe793ddfe2ab30 100644 (file)
@@ -532,17 +532,6 @@ int mac_selinux_get_child_mls_label(int socket_fd, const char *exe, const char *
 #endif
 }
 
-char* mac_selinux_free(char *label) {
-
-#if HAVE_SELINUX
-        freecon(label);
-#else
-        assert(!label);
-#endif
-
-        return NULL;
-}
-
 #if HAVE_SELINUX
 static int selinux_create_file_prepare_abspath(const char *abspath, mode_t mode) {
         _cleanup_freecon_ char *filecon = NULL;
index 97ab5ebb2f43cfd8ebc6ed8755b424fba05a6c8e..038456fcca6574d79c33cbe3aca509bb6089da97 100644 (file)
 #include <selinux/selinux.h>
 
 DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(char*, freecon, NULL);
-#define _cleanup_freecon_ _cleanup_(freeconp)
+#else
+static inline char* freeconp(char **p) {
+        assert(*p == NULL);
+        return NULL;
+}
 #endif
 
+#define _cleanup_freecon_ _cleanup_(freeconp)
+
 bool mac_selinux_use(void);
 void mac_selinux_retest(void);
 bool mac_selinux_enforcing(void);
@@ -33,7 +39,6 @@ int mac_selinux_apply_fd(int fd, const char *path, const char *label);
 int mac_selinux_get_create_label_from_exe(const char *exe, char **label);
 int mac_selinux_get_our_label(char **label);
 int mac_selinux_get_child_mls_label(int socket_fd, const char *exe, const char *exec_label, char **label);
-char* mac_selinux_free(char *label);
 
 int mac_selinux_create_file_prepare_at(int dirfd, const char *path, mode_t mode);
 static inline int mac_selinux_create_file_prepare(const char *path, mode_t mode) {
@@ -46,5 +51,3 @@ int mac_selinux_create_socket_prepare(const char *label);
 void mac_selinux_create_socket_clear(void);
 
 int mac_selinux_bind(int fd, const struct sockaddr *addr, socklen_t addrlen);
-
-DEFINE_TRIVIAL_CLEANUP_FUNC(char*, mac_selinux_free);
index 3abbb94d9fb4877e6c86b09caa623e909780af18..217f38bb0581f1cbbb0311e27904760a5f626956 100644 (file)
@@ -156,7 +156,6 @@ simple_tests += files(
         'test-sd-hwdb.c',
         'test-sd-path.c',
         'test-secure-bits.c',
-        'test-selinux.c',
         'test-serialize.c',
         'test-set.c',
         'test-sha256.c',
@@ -404,6 +403,10 @@ executables += [
                 'dependencies' : libseccomp,
                 'conditions' : ['HAVE_SECCOMP'],
         },
+        test_template + {
+                'sources' : files('test-selinux.c'),
+                'dependencies' : libselinux,
+        },
         test_template + {
                 'sources' : files('test-set-disable-mempool.c'),
                 'dependencies' : threads,
index 04b5ba146d9282123a1bb1a9279d768eb91bdf8c..e7371a81e3aef745e837e86d47414c48ee2c5ee2 100644 (file)
@@ -54,7 +54,7 @@ static void test_cleanup(void) {
 }
 
 static void test_misc(const char* fname) {
-        _cleanup_(mac_selinux_freep) char *label = NULL, *label2 = NULL, *label3 = NULL;
+        _cleanup_freecon_ char *label = NULL, *label2 = NULL, *label3 = NULL;
         int r;
         _cleanup_close_ int fd = -EBADF;