diff --git a/src/core/selinux-setup.c b/src/core/selinux-setup.c index bc1a24914e6..89f736b47bb 100644 --- a/src/core/selinux-setup.c +++ b/src/core/selinux-setup.c @@ -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(); diff --git a/src/core/socket.c b/src/core/socket.c index 66733a269e5..339d77fb975 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -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; diff --git a/src/portable/portable.c b/src/portable/portable.c index 53418c417b5..08e9bc01139 100644 --- a/src/portable/portable.c +++ b/src/portable/portable.c @@ -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; diff --git a/src/shared/selinux-util.c b/src/shared/selinux-util.c index d2b1a3e5543..e626a60026e 100644 --- a/src/shared/selinux-util.c +++ b/src/shared/selinux-util.c @@ -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; diff --git a/src/shared/selinux-util.h b/src/shared/selinux-util.h index 97ab5ebb2f4..038456fcca6 100644 --- a/src/shared/selinux-util.h +++ b/src/shared/selinux-util.h @@ -13,9 +13,15 @@ #include 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); diff --git a/src/test/meson.build b/src/test/meson.build index 3abbb94d9fb..217f38bb058 100644 --- a/src/test/meson.build +++ b/src/test/meson.build @@ -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, diff --git a/src/test/test-selinux.c b/src/test/test-selinux.c index 04b5ba146d9..e7371a81e3a 100644 --- a/src/test/test-selinux.c +++ b/src/test/test-selinux.c @@ -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;