dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone

Blame SOURCES/0001-util-Move-semanage-related-functions-to-src-util.patch

905b4d
From 40dac78bce81ebf65ccbcd4f346de9e91d3da58b Mon Sep 17 00:00:00 2001
905b4d
From: Michal Zidek <mzidek@redhat.com>
905b4d
Date: Wed, 24 Sep 2014 15:50:04 +0200
905b4d
Subject: [PATCH 01/22] util: Move semanage related functions to src/util
905b4d
MIME-Version: 1.0
905b4d
Content-Type: text/plain; charset=UTF-8
905b4d
Content-Transfer-Encoding: 8bit
905b4d
905b4d
These functions will be reused by IPA provider.
905b4d
905b4d
Reviewed-by: Lukáš Slebodník <lslebodn@redhat.com>
905b4d
---
905b4d
 Makefile.am                                  |  37 ++-
905b4d
 src/tests/dlopen-tests.c                     |   1 +
905b4d
 src/tools/selinux.c                          | 334 ---------------------------
905b4d
 src/tools/tools_util.h                       |   2 -
905b4d
 src/{tools/selinux.c => util/sss_semanage.c} |  61 +----
905b4d
 src/util/util.h                              |   4 +
905b4d
 6 files changed, 35 insertions(+), 404 deletions(-)
905b4d
 copy src/{tools/selinux.c => util/sss_semanage.c} (87%)
905b4d
905b4d
diff --git a/Makefile.am b/Makefile.am
905b4d
index 6a8124b5ad30f9e54a0325dc574a96c91ec4e805..49acdb107cb45410493dfabe30a2ea4553a23669 100644
905b4d
--- a/Makefile.am
905b4d
+++ b/Makefile.am
905b4d
@@ -476,10 +476,6 @@ if BUILD_SELINUX
905b4d
     PYTHON_BINDINGS_LIBS += $(SELINUX_LIBS)
905b4d
     TOOLS_LIBS += $(SELINUX_LIBS)
905b4d
 endif
905b4d
-if BUILD_SEMANAGE
905b4d
-    PYTHON_BINDINGS_LIBS += $(SEMANAGE_LIBS)
905b4d
-    TOOLS_LIBS += $(SEMANAGE_LIBS)
905b4d
-endif
905b4d
 
905b4d
 dist_noinst_HEADERS = \
905b4d
     src/monitor/monitor.h \
905b4d
@@ -728,11 +724,26 @@ libsss_util_la_SOURCES += \
905b4d
 endif
905b4d
 libsss_util_la_LDFLAGS = -avoid-version
905b4d
 
905b4d
+pkglib_LTLIBRARIES += libsss_semanage.la
905b4d
+libsss_semanage_la_SOURCES = \
905b4d
+    src/util/sss_semanage.c \
905b4d
+    $(NULL)
905b4d
+libsss_semanage_la_LIBADD = \
905b4d
+    libsss_debug.la \
905b4d
+    $(NULL)
905b4d
+if BUILD_SEMANAGE
905b4d
+libsss_semanage_la_LIBADD += $(SEMANAGE_LIBS)
905b4d
+endif
905b4d
+
905b4d
+libsss_semanage_la_LDFLAGS = \
905b4d
+    -avoid-version
905b4d
+
905b4d
 SSSD_INTERNAL_LTLIBS = \
905b4d
     libsss_util.la \
905b4d
     libsss_crypt.la \
905b4d
     libsss_debug.la \
905b4d
-    libsss_child.la
905b4d
+    libsss_child.la \
905b4d
+    $(NULL)
905b4d
 
905b4d
 if BUILD_IFP
905b4d
 if BUILD_CONFIG_LIB
905b4d
@@ -1065,7 +1076,9 @@ sss_useradd_SOURCES = \
905b4d
     $(SSSD_TOOLS_OBJ)
905b4d
 sss_useradd_LDADD = \
905b4d
     $(TOOLS_LIBS) \
905b4d
-    $(SSSD_INTERNAL_LTLIBS)
905b4d
+    $(SSSD_INTERNAL_LTLIBS) \
905b4d
+    libsss_semanage.la \
905b4d
+    $(NULL)
905b4d
 
905b4d
 sss_userdel_SOURCES = \
905b4d
     src/tools/sss_userdel.c \
905b4d
@@ -1073,7 +1086,9 @@ sss_userdel_SOURCES = \
905b4d
 sss_userdel_LDADD = \
905b4d
     $(TOOLS_LIBS) \
905b4d
     $(SSSD_INTERNAL_LTLIBS) \
905b4d
-    $(CLIENT_LIBS)
905b4d
+    $(CLIENT_LIBS) \
905b4d
+    libsss_semanage.la \
905b4d
+    $(NULL)
905b4d
 sss_userdel_CFLAGS = \
905b4d
     $(AM_CFLAGS)
905b4d
 
905b4d
@@ -1099,7 +1114,9 @@ sss_usermod_SOURCES = \
905b4d
 sss_usermod_LDADD = \
905b4d
     $(TOOLS_LIBS) \
905b4d
     $(SSSD_INTERNAL_LTLIBS) \
905b4d
-    $(CLIENT_LIBS)
905b4d
+    $(CLIENT_LIBS) \
905b4d
+    libsss_semanage.la \
905b4d
+    $(NULL)
905b4d
 sss_usermod_CFLAGS = $(AM_CFLAGS)
905b4d
 
905b4d
 sss_groupmod_SOURCES = \
905b4d
@@ -2372,7 +2389,9 @@ libsss_ipa_la_LIBADD = \
905b4d
     libsss_ldap_common.la \
905b4d
     libsss_krb5_common.la \
905b4d
     libipa_hbac.la \
905b4d
-    libsss_idmap.la
905b4d
+    libsss_idmap.la \
905b4d
+    libsss_semanage.la \
905b4d
+    $(NULL)
905b4d
 libsss_ipa_la_LDFLAGS = \
905b4d
     -avoid-version \
905b4d
     -module
905b4d
diff --git a/src/tests/dlopen-tests.c b/src/tests/dlopen-tests.c
905b4d
index 1dd80c49cf3e91e214ac6ffb2df1f98268571831..7e56d652461155045023fddeb988f4f4ba017277 100644
905b4d
--- a/src/tests/dlopen-tests.c
905b4d
+++ b/src/tests/dlopen-tests.c
905b4d
@@ -38,6 +38,7 @@ struct so {
905b4d
     const char *libs[6];
905b4d
 } so[] = {
905b4d
     { "libsss_debug.so", { LIBPFX"libsss_debug.so", NULL } },
905b4d
+    { "libsss_semanage.so", { LIBPFX"libsss_semanage.so", NULL } },
905b4d
     { "libipa_hbac.so", { LIBPFX"libipa_hbac.so", NULL } },
905b4d
     { "libsss_idmap.so", { LIBPFX"libsss_idmap.so", NULL } },
905b4d
     { "libsss_nss_idmap.so", { LIBPFX"libsss_nss_idmap.so", NULL } },
905b4d
diff --git a/src/tools/selinux.c b/src/tools/selinux.c
905b4d
index 1f87d40f99440b15ed71be9c225003b2860c5003..5e9c458f93340fcb4264eced7964a6cfecadc9e6 100644
905b4d
--- a/src/tools/selinux.c
905b4d
+++ b/src/tools/selinux.c
905b4d
@@ -27,16 +27,8 @@
905b4d
 #include <selinux/selinux.h>
905b4d
 #endif
905b4d
 
905b4d
-#ifdef HAVE_SEMANAGE
905b4d
-#include <semanage/semanage.h>
905b4d
-#endif
905b4d
-
905b4d
 #include "tools/tools_util.h"
905b4d
 
905b4d
-#ifndef DEFAULT_SERANGE
905b4d
-#define DEFAULT_SERANGE "s0"
905b4d
-#endif
905b4d
-
905b4d
 #ifdef HAVE_SELINUX
905b4d
 /*
905b4d
  * selinux_file_context - Set the security context before any file or
905b4d
@@ -89,329 +81,3 @@ int reset_selinux_file_context(void)
905b4d
     return EOK;
905b4d
 }
905b4d
 #endif  /* HAVE_SELINUX */
905b4d
-
905b4d
-#ifdef HAVE_SEMANAGE
905b4d
-/* turn libselinux messages into SSSD DEBUG() calls */
905b4d
-static void sss_semanage_error_callback(void *varg,
905b4d
-                                        semanage_handle_t *handle,
905b4d
-                                        const char *fmt, ...)
905b4d
-{
905b4d
-    int level = SSSDBG_INVALID;
905b4d
-    int ret;
905b4d
-    char * message = NULL;
905b4d
-    va_list ap;
905b4d
-
905b4d
-    switch (semanage_msg_get_level(handle)) {
905b4d
-        case SEMANAGE_MSG_ERR:
905b4d
-            level = SSSDBG_CRIT_FAILURE;
905b4d
-            break;
905b4d
-        case SEMANAGE_MSG_WARN:
905b4d
-            level = SSSDBG_MINOR_FAILURE;
905b4d
-            break;
905b4d
-        case SEMANAGE_MSG_INFO:
905b4d
-            level = SSSDBG_TRACE_FUNC;
905b4d
-            break;
905b4d
-    }
905b4d
-
905b4d
-    va_start(ap, fmt);
905b4d
-    ret = vasprintf(&message, fmt, ap);
905b4d
-    va_end(ap);
905b4d
-    if (ret < 0) {
905b4d
-        /* ENOMEM */
905b4d
-        return;
905b4d
-    }
905b4d
-
905b4d
-    if (DEBUG_IS_SET(level))
905b4d
-        debug_fn(__FILE__, __LINE__, "libsemanage", level, "%s\n", message);
905b4d
-    free(message);
905b4d
-}
905b4d
-
905b4d
-static semanage_handle_t *sss_semanage_init(void)
905b4d
-{
905b4d
-    int ret;
905b4d
-    semanage_handle_t *handle = NULL;
905b4d
-
905b4d
-    handle = semanage_handle_create();
905b4d
-    if (!handle) {
905b4d
-        DEBUG(SSSDBG_CRIT_FAILURE, "Cannot create SELinux management handle\n");
905b4d
-        return NULL;
905b4d
-    }
905b4d
-
905b4d
-    semanage_msg_set_callback(handle,
905b4d
-                              sss_semanage_error_callback,
905b4d
-                              NULL);
905b4d
-
905b4d
-    ret = semanage_is_managed(handle);
905b4d
-    if (ret != 1) {
905b4d
-        DEBUG(SSSDBG_CRIT_FAILURE, "SELinux policy not managed\n");
905b4d
-        goto fail;
905b4d
-    }
905b4d
-
905b4d
-    ret = semanage_access_check(handle);
905b4d
-    if (ret < SEMANAGE_CAN_READ) {
905b4d
-        DEBUG(SSSDBG_CRIT_FAILURE, "Cannot read SELinux policy store\n");
905b4d
-        goto fail;
905b4d
-    }
905b4d
-
905b4d
-    ret = semanage_connect(handle);
905b4d
-    if (ret != 0) {
905b4d
-        DEBUG(SSSDBG_CRIT_FAILURE,
905b4d
-              "Cannot estabilish SELinux management connection\n");
905b4d
-        goto fail;
905b4d
-    }
905b4d
-
905b4d
-    ret = semanage_begin_transaction(handle);
905b4d
-    if (ret != 0) {
905b4d
-        DEBUG(SSSDBG_CRIT_FAILURE, "Cannot begin SELinux transaction\n");
905b4d
-        goto fail;
905b4d
-    }
905b4d
-
905b4d
-    return handle;
905b4d
-fail:
905b4d
-    semanage_handle_destroy(handle);
905b4d
-    return NULL;
905b4d
-}
905b4d
-
905b4d
-static int sss_semanage_user_add(semanage_handle_t *handle,
905b4d
-                                 semanage_seuser_key_t *key,
905b4d
-                                 const char *login_name,
905b4d
-                                 const char *seuser_name)
905b4d
-{
905b4d
-    int ret;
905b4d
-    semanage_seuser_t *seuser = NULL;
905b4d
-
905b4d
-    ret = semanage_seuser_create(handle, &seuser);
905b4d
-    if (ret != 0) {
905b4d
-        DEBUG(SSSDBG_CRIT_FAILURE,
905b4d
-              "Cannot create SELinux login mapping for %s\n", login_name);
905b4d
-        ret = EIO;
905b4d
-        goto done;
905b4d
-    }
905b4d
-
905b4d
-    ret = semanage_seuser_set_name(handle, seuser, login_name);
905b4d
-    if (ret != 0) {
905b4d
-        DEBUG(SSSDBG_CRIT_FAILURE, "Could not set name for %s\n", login_name);
905b4d
-        ret = EIO;
905b4d
-        goto done;
905b4d
-    }
905b4d
-
905b4d
-    ret = semanage_seuser_set_mlsrange(handle, seuser, DEFAULT_SERANGE);
905b4d
-    if (ret != 0) {
905b4d
-        DEBUG(SSSDBG_CRIT_FAILURE,
905b4d
-              "Could not set serange for %s\n", login_name);
905b4d
-        ret = EIO;
905b4d
-        goto done;
905b4d
-    }
905b4d
-
905b4d
-    ret = semanage_seuser_set_sename(handle, seuser, seuser_name);
905b4d
-    if (ret != 0) {
905b4d
-        DEBUG(SSSDBG_CRIT_FAILURE,
905b4d
-              "Could not set SELinux user for %s\n", login_name);
905b4d
-        ret = EIO;
905b4d
-        goto done;
905b4d
-    }
905b4d
-
905b4d
-    ret = semanage_seuser_modify_local(handle, key, seuser);
905b4d
-    if (ret != 0) {
905b4d
-        DEBUG(SSSDBG_CRIT_FAILURE,
905b4d
-              "Could not add login mapping for %s\n", login_name);
905b4d
-        ret = EIO;
905b4d
-        goto done;
905b4d
-    }
905b4d
-
905b4d
-    ret = EOK;
905b4d
-done:
905b4d
-    semanage_seuser_free(seuser);
905b4d
-    return ret;
905b4d
-}
905b4d
-
905b4d
-static int sss_semanage_user_mod(semanage_handle_t *handle,
905b4d
-                                 semanage_seuser_key_t *key,
905b4d
-                                 const char *login_name,
905b4d
-                                 const char *seuser_name)
905b4d
-{
905b4d
-    int ret;
905b4d
-    semanage_seuser_t *seuser = NULL;
905b4d
-
905b4d
-    semanage_seuser_query(handle, key, &seuser);
905b4d
-    if (seuser == NULL) {
905b4d
-        DEBUG(SSSDBG_CRIT_FAILURE,
905b4d
-              "Could not query seuser for %s\n", login_name);
905b4d
-        ret = EIO;
905b4d
-        goto done;
905b4d
-    }
905b4d
-
905b4d
-    ret = semanage_seuser_set_mlsrange(handle, seuser, DEFAULT_SERANGE);
905b4d
-    if (ret != 0) {
905b4d
-        DEBUG(SSSDBG_CRIT_FAILURE,
905b4d
-              "Could not set serange for %s\n", login_name);
905b4d
-        ret = EIO;
905b4d
-        goto done;
905b4d
-    }
905b4d
-
905b4d
-    ret = semanage_seuser_set_sename(handle, seuser, seuser_name);
905b4d
-    if (ret != 0) {
905b4d
-        DEBUG(SSSDBG_CRIT_FAILURE, "Could not set sename for %s\n", login_name);
905b4d
-        ret = EIO;
905b4d
-        goto done;
905b4d
-    }
905b4d
-
905b4d
-    ret = semanage_seuser_modify_local(handle, key, seuser);
905b4d
-    if (ret != 0) {
905b4d
-        DEBUG(SSSDBG_CRIT_FAILURE,
905b4d
-              ("Could not modify login mapping for %s\n"), login_name);
905b4d
-        ret = EIO;
905b4d
-        goto done;
905b4d
-    }
905b4d
-
905b4d
-    ret = EOK;
905b4d
-done:
905b4d
-    semanage_seuser_free(seuser);
905b4d
-    return ret;
905b4d
-}
905b4d
-
905b4d
-int set_seuser(const char *login_name, const char *seuser_name)
905b4d
-{
905b4d
-    semanage_handle_t *handle = NULL;
905b4d
-    semanage_seuser_key_t *key = NULL;
905b4d
-    int ret;
905b4d
-    int seuser_exists = 0;
905b4d
-
905b4d
-    if (seuser_name == NULL) {
905b4d
-        /* don't care, just let system pick the defaults */
905b4d
-        return EOK;
905b4d
-    }
905b4d
-
905b4d
-    handle = sss_semanage_init();
905b4d
-    if (!handle) {
905b4d
-        DEBUG(SSSDBG_CRIT_FAILURE, "Cannot init SELinux management\n");
905b4d
-        ret = EIO;
905b4d
-        goto done;
905b4d
-    }
905b4d
-
905b4d
-    ret = semanage_seuser_key_create(handle, login_name, &key);
905b4d
-    if (ret != 0) {
905b4d
-        DEBUG(SSSDBG_CRIT_FAILURE, "Cannot create SELinux user key\n");
905b4d
-        ret = EIO;
905b4d
-        goto done;
905b4d
-    }
905b4d
-
905b4d
-    ret = semanage_seuser_exists(handle, key, &seuser_exists);
905b4d
-    if (ret < 0) {
905b4d
-        DEBUG(SSSDBG_CRIT_FAILURE, "Cannot verify the SELinux user\n");
905b4d
-        ret = EIO;
905b4d
-        goto done;
905b4d
-    }
905b4d
-
905b4d
-    if (seuser_exists) {
905b4d
-        ret = sss_semanage_user_mod(handle, key, login_name, seuser_name);
905b4d
-        if (ret != 0) {
905b4d
-            DEBUG(SSSDBG_CRIT_FAILURE, "Cannot modify SELinux user mapping\n");
905b4d
-            ret = EIO;
905b4d
-            goto done;
905b4d
-        }
905b4d
-    } else {
905b4d
-        ret = sss_semanage_user_add(handle, key, login_name, seuser_name);
905b4d
-        if (ret != 0) {
905b4d
-            DEBUG(SSSDBG_CRIT_FAILURE, "Cannot add SELinux user mapping\n");
905b4d
-            ret = EIO;
905b4d
-            goto done;
905b4d
-        }
905b4d
-    }
905b4d
-
905b4d
-    ret = semanage_commit(handle);
905b4d
-    if (ret < 0) {
905b4d
-        DEBUG(SSSDBG_CRIT_FAILURE, "Cannot commit SELinux transaction\n");
905b4d
-        ret = EIO;
905b4d
-        goto done;
905b4d
-    }
905b4d
-
905b4d
-    ret = EOK;
905b4d
-done:
905b4d
-    semanage_seuser_key_free(key);
905b4d
-    semanage_handle_destroy(handle);
905b4d
-    return ret;
905b4d
-}
905b4d
-
905b4d
-int del_seuser(const char *login_name)
905b4d
-{
905b4d
-    semanage_handle_t *handle = NULL;
905b4d
-    semanage_seuser_key_t *key = NULL;
905b4d
-    int ret;
905b4d
-    int exists = 0;
905b4d
-
905b4d
-    handle = sss_semanage_init();
905b4d
-    if (!handle) {
905b4d
-        DEBUG(SSSDBG_CRIT_FAILURE, "Cannot init SELinux management\n");
905b4d
-        ret = EIO;
905b4d
-        goto done;
905b4d
-    }
905b4d
-
905b4d
-    ret = semanage_seuser_key_create(handle, login_name, &key);
905b4d
-    if (ret != 0) {
905b4d
-        DEBUG(SSSDBG_CRIT_FAILURE, "Cannot create SELinux user key\n");
905b4d
-        ret = EIO;
905b4d
-        goto done;
905b4d
-    }
905b4d
-
905b4d
-    ret = semanage_seuser_exists(handle, key, &exists;;
905b4d
-    if (ret < 0) {
905b4d
-        DEBUG(SSSDBG_CRIT_FAILURE, "Cannot verify the SELinux user\n");
905b4d
-        ret = EIO;
905b4d
-        goto done;
905b4d
-    }
905b4d
-
905b4d
-    if (!exists) {
905b4d
-        DEBUG(SSSDBG_FUNC_DATA,
905b4d
-              "Login mapping for %s is not defined, OK if default mapping "
905b4d
-                  "was used\n", login_name);
905b4d
-        ret = EOK;  /* probably default mapping */
905b4d
-        goto done;
905b4d
-    }
905b4d
-
905b4d
-    ret = semanage_seuser_exists_local(handle, key, &exists;;
905b4d
-    if (ret < 0) {
905b4d
-        DEBUG(SSSDBG_CRIT_FAILURE, "Cannot verify the SELinux user\n");
905b4d
-        ret = EIO;
905b4d
-        goto done;
905b4d
-    }
905b4d
-
905b4d
-    if (!exists) {
905b4d
-        DEBUG(SSSDBG_CRIT_FAILURE, "Login mapping for %s is defined in policy, "
905b4d
-                  "cannot be deleted", login_name);
905b4d
-        ret = ENOENT;
905b4d
-        goto done;
905b4d
-    }
905b4d
-
905b4d
-    ret = semanage_seuser_del_local(handle, key);
905b4d
-    if (ret != 0) {
905b4d
-        DEBUG(SSSDBG_CRIT_FAILURE,
905b4d
-              "Could not delete login mapping for %s", login_name);
905b4d
-        ret = EIO;
905b4d
-        goto done;
905b4d
-    }
905b4d
-
905b4d
-    ret = semanage_commit(handle);
905b4d
-    if (ret < 0) {
905b4d
-        DEBUG(SSSDBG_CRIT_FAILURE, "Cannot commit SELinux transaction\n");
905b4d
-        ret = EIO;
905b4d
-        goto done;
905b4d
-    }
905b4d
-
905b4d
-    ret = EOK;
905b4d
-done:
905b4d
-    semanage_handle_destroy(handle);
905b4d
-    return ret;
905b4d
-}
905b4d
-
905b4d
-#else /* HAVE_SEMANAGE */
905b4d
-int set_seuser(const char *login_name, const char *seuser_name)
905b4d
-{
905b4d
-    return EOK;
905b4d
-}
905b4d
-
905b4d
-int del_seuser(const char *login_name)
905b4d
-{
905b4d
-    return EOK;
905b4d
-}
905b4d
-#endif  /* HAVE_SEMANAGE */
905b4d
diff --git a/src/tools/tools_util.h b/src/tools/tools_util.h
905b4d
index 87fe752eac49ef85d77043fe0a8c459bc4f5a74c..c5990b012892a25b315d744a056861e7b2130410 100644
905b4d
--- a/src/tools/tools_util.h
905b4d
+++ b/src/tools/tools_util.h
905b4d
@@ -123,7 +123,5 @@ int copy_tree(const char *src_root, const char *dst_root,
905b4d
 /* from selinux.c */
905b4d
 int selinux_file_context(const char *dst_name);
905b4d
 int reset_selinux_file_context(void);
905b4d
-int set_seuser(const char *login_name, const char *seuser_name);
905b4d
-int del_seuser(const char *login_name);
905b4d
 
905b4d
 #endif  /* __TOOLS_UTIL_H__ */
905b4d
diff --git a/src/tools/selinux.c b/src/util/sss_semanage.c
905b4d
similarity index 87%
905b4d
copy from src/tools/selinux.c
905b4d
copy to src/util/sss_semanage.c
905b4d
index 1f87d40f99440b15ed71be9c225003b2860c5003..dbef3b3437f9ac51021f30b510b9c15cd34e297a 100644
905b4d
--- a/src/tools/selinux.c
905b4d
+++ b/src/util/sss_semanage.c
905b4d
@@ -1,7 +1,7 @@
905b4d
 /*
905b4d
    SSSD
905b4d
 
905b4d
-   selinux.c
905b4d
+   sss_semanage.c
905b4d
 
905b4d
    Copyright (C) Jakub Hrozek <jhrozek@redhat.com>        2010
905b4d
 
905b4d
@@ -23,73 +23,16 @@
905b4d
 
905b4d
 #include <stdio.h>
905b4d
 
905b4d
-#ifdef HAVE_SELINUX
905b4d
-#include <selinux/selinux.h>
905b4d
-#endif
905b4d
-
905b4d
 #ifdef HAVE_SEMANAGE
905b4d
 #include <semanage/semanage.h>
905b4d
 #endif
905b4d
 
905b4d
-#include "tools/tools_util.h"
905b4d
+#include "util/util.h"
905b4d
 
905b4d
 #ifndef DEFAULT_SERANGE
905b4d
 #define DEFAULT_SERANGE "s0"
905b4d
 #endif
905b4d
 
905b4d
-#ifdef HAVE_SELINUX
905b4d
-/*
905b4d
- * selinux_file_context - Set the security context before any file or
905b4d
- *                        directory creation.
905b4d
- *
905b4d
- *  selinux_file_context () should be called before any creation of file,
905b4d
- *  symlink, directory, ...
905b4d
- *
905b4d
- *  Callers may have to Reset SELinux to create files with default
905b4d
- *  contexts:
905b4d
- *      reset_selinux_file_context();
905b4d
- */
905b4d
-int selinux_file_context(const char *dst_name)
905b4d
-{
905b4d
-    security_context_t scontext = NULL;
905b4d
-
905b4d
-    if (is_selinux_enabled() == 1) {
905b4d
-        /* Get the default security context for this file */
905b4d
-        if (matchpathcon(dst_name, 0, &scontext) < 0) {
905b4d
-            if (security_getenforce () != 0) {
905b4d
-                return 1;
905b4d
-            }
905b4d
-        }
905b4d
-        /* Set the security context for the next created file */
905b4d
-        if (setfscreatecon(scontext) < 0) {
905b4d
-            if (security_getenforce() != 0) {
905b4d
-                return 1;
905b4d
-            }
905b4d
-        }
905b4d
-        freecon(scontext);
905b4d
-    }
905b4d
-
905b4d
-    return 0;
905b4d
-}
905b4d
-
905b4d
-int reset_selinux_file_context(void)
905b4d
-{
905b4d
-    setfscreatecon(NULL);
905b4d
-    return EOK;
905b4d
-}
905b4d
-
905b4d
-#else   /* HAVE_SELINUX */
905b4d
-int selinux_file_context(const char *dst_name)
905b4d
-{
905b4d
-    return EOK;
905b4d
-}
905b4d
-
905b4d
-int reset_selinux_file_context(void)
905b4d
-{
905b4d
-    return EOK;
905b4d
-}
905b4d
-#endif  /* HAVE_SELINUX */
905b4d
-
905b4d
 #ifdef HAVE_SEMANAGE
905b4d
 /* turn libselinux messages into SSSD DEBUG() calls */
905b4d
 static void sss_semanage_error_callback(void *varg,
905b4d
diff --git a/src/util/util.h b/src/util/util.h
905b4d
index 0ac9b0104ca941b52bb37720dd16d2bbc9fbb9f8..b43ce6f5092e9920609826bead483976fef2f9b1 100644
905b4d
--- a/src/util/util.h
905b4d
+++ b/src/util/util.h
905b4d
@@ -591,4 +591,8 @@ errno_t switch_creds(TALLOC_CTX *mem_ctx,
905b4d
                      struct sss_creds **saved_creds);
905b4d
 errno_t restore_creds(struct sss_creds *saved_creds);
905b4d
 
905b4d
+/* from sss_semanage.c */
905b4d
+int set_seuser(const char *login_name, const char *seuser_name);
905b4d
+int del_seuser(const char *login_name);
905b4d
+
905b4d
 #endif /* __SSSD_UTIL_H__ */
905b4d
-- 
905b4d
1.9.3
905b4d