|
|
5e7617 |
From 0006bd76856787614f961001929fea95d0669fe5 Mon Sep 17 00:00:00 2001
|
|
|
5e7617 |
From: Justin Stephenson <jstephen@redhat.com>
|
|
|
5e7617 |
Date: Thu, 9 Mar 2017 17:21:37 -0500
|
|
|
5e7617 |
Subject: [PATCH 203/205] SELINUX: Use getseuserbyname to get IPA seuser
|
|
|
5e7617 |
MIME-Version: 1.0
|
|
|
5e7617 |
Content-Type: text/plain; charset=UTF-8
|
|
|
5e7617 |
Content-Transfer-Encoding: 8bit
|
|
|
5e7617 |
|
|
|
5e7617 |
The libselinux function getseuserbyname is more reliable method to retrieve
|
|
|
5e7617 |
SELinux usernames then functions from libsemanage `semanage_user_query`
|
|
|
5e7617 |
and is recommended by libsemanage developers.
|
|
|
5e7617 |
Replace get_seuser function with getseuserbyname.
|
|
|
5e7617 |
|
|
|
5e7617 |
Resolves:
|
|
|
5e7617 |
https://pagure.io/SSSD/sssd/issue/3308
|
|
|
5e7617 |
|
|
|
5e7617 |
Reviewed-by: Michal Židek <mzidek@redhat.com>
|
|
|
5e7617 |
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
|
|
|
5e7617 |
Reviewed-by: Petr Lautrbach <plautrba@redhat.com>
|
|
|
5e7617 |
(cherry picked from commit cfe87ca0c4fded9cbf907697d08fa0e6c8f8ebce)
|
|
|
5e7617 |
---
|
|
|
5e7617 |
Makefile.am | 1 +
|
|
|
5e7617 |
src/providers/ipa/selinux_child.c | 12 +++----
|
|
|
5e7617 |
src/util/sss_semanage.c | 73 ---------------------------------------
|
|
|
5e7617 |
src/util/util.h | 2 --
|
|
|
5e7617 |
4 files changed, 7 insertions(+), 81 deletions(-)
|
|
|
5e7617 |
|
|
|
5e7617 |
diff --git a/Makefile.am b/Makefile.am
|
|
|
5e7617 |
index cdd517d50679b876814303fb7d6c63d49bcd8d38..1eb398830e4817d4da0878a6577b45df101e920d 100644
|
|
|
5e7617 |
--- a/Makefile.am
|
|
|
5e7617 |
+++ b/Makefile.am
|
|
|
5e7617 |
@@ -4094,6 +4094,7 @@ selinux_child_LDADD = \
|
|
|
5e7617 |
$(POPT_LIBS) \
|
|
|
5e7617 |
$(DHASH_LIBS) \
|
|
|
5e7617 |
$(SEMANAGE_LIBS) \
|
|
|
5e7617 |
+ $(SELINUX_LIBS) \
|
|
|
5e7617 |
$(NULL)
|
|
|
5e7617 |
endif
|
|
|
5e7617 |
|
|
|
5e7617 |
diff --git a/src/providers/ipa/selinux_child.c b/src/providers/ipa/selinux_child.c
|
|
|
5e7617 |
index f8dd3954a7244df2dcbb910aabf8888f41306c09..073475094ee491bd5453898c6ba65214fa14fe59 100644
|
|
|
5e7617 |
--- a/src/providers/ipa/selinux_child.c
|
|
|
5e7617 |
+++ b/src/providers/ipa/selinux_child.c
|
|
|
5e7617 |
@@ -27,6 +27,7 @@
|
|
|
5e7617 |
#include <unistd.h>
|
|
|
5e7617 |
#include <sys/stat.h>
|
|
|
5e7617 |
#include <popt.h>
|
|
|
5e7617 |
+#include <selinux/selinux.h>
|
|
|
5e7617 |
|
|
|
5e7617 |
#include "util/util.h"
|
|
|
5e7617 |
#include "util/child_common.h"
|
|
|
5e7617 |
@@ -172,11 +173,10 @@ static bool seuser_needs_update(struct input_buffer *ibuf)
|
|
|
5e7617 |
char *db_mls_range = NULL;
|
|
|
5e7617 |
errno_t ret;
|
|
|
5e7617 |
|
|
|
5e7617 |
- ret = get_seuser(ibuf, ibuf->username, &db_seuser, &db_mls_range);
|
|
|
5e7617 |
+ ret = getseuserbyname(ibuf->username, &db_seuser, &db_mls_range);
|
|
|
5e7617 |
DEBUG(SSSDBG_TRACE_INTERNAL,
|
|
|
5e7617 |
- "get_seuser: ret: %d msg: [%s] seuser: %s mls: %s\n",
|
|
|
5e7617 |
- ret, sss_strerror(ret),
|
|
|
5e7617 |
- db_seuser ? db_seuser : "unknown",
|
|
|
5e7617 |
+ "getseuserbyname: ret: %d seuser: %s mls: %s\n",
|
|
|
5e7617 |
+ ret, db_seuser ? db_seuser : "unknown",
|
|
|
5e7617 |
db_mls_range ? db_mls_range : "unknown");
|
|
|
5e7617 |
if (ret == EOK && db_seuser && db_mls_range &&
|
|
|
5e7617 |
strcmp(db_seuser, ibuf->seuser) == 0 &&
|
|
|
5e7617 |
@@ -188,8 +188,8 @@ static bool seuser_needs_update(struct input_buffer *ibuf)
|
|
|
5e7617 |
needs_update = false;
|
|
|
5e7617 |
}
|
|
|
5e7617 |
|
|
|
5e7617 |
- talloc_free(db_seuser);
|
|
|
5e7617 |
- talloc_free(db_mls_range);
|
|
|
5e7617 |
+ free(db_seuser);
|
|
|
5e7617 |
+ free(db_mls_range);
|
|
|
5e7617 |
return needs_update;
|
|
|
5e7617 |
}
|
|
|
5e7617 |
|
|
|
5e7617 |
diff --git a/src/util/sss_semanage.c b/src/util/sss_semanage.c
|
|
|
5e7617 |
index 0da97aad4d8eba733b131c2749932e03ca4242c4..37278cc986a1ea49dc2218a635d52b9d54ca089d 100644
|
|
|
5e7617 |
--- a/src/util/sss_semanage.c
|
|
|
5e7617 |
+++ b/src/util/sss_semanage.c
|
|
|
5e7617 |
@@ -382,73 +382,6 @@ done:
|
|
|
5e7617 |
sss_semanage_close(handle);
|
|
|
5e7617 |
return ret;
|
|
|
5e7617 |
}
|
|
|
5e7617 |
-
|
|
|
5e7617 |
-int get_seuser(TALLOC_CTX *mem_ctx, const char *login_name,
|
|
|
5e7617 |
- char **_seuser, char **_mls_range)
|
|
|
5e7617 |
-{
|
|
|
5e7617 |
- errno_t ret;
|
|
|
5e7617 |
- const char *seuser;
|
|
|
5e7617 |
- const char *mls_range;
|
|
|
5e7617 |
- semanage_handle_t *sm_handle = NULL;
|
|
|
5e7617 |
- semanage_seuser_t *sm_user = NULL;
|
|
|
5e7617 |
- semanage_seuser_key_t *sm_key = NULL;
|
|
|
5e7617 |
-
|
|
|
5e7617 |
- ret = sss_semanage_init(&sm_handle);
|
|
|
5e7617 |
- if (ret == ERR_SELINUX_NOT_MANAGED) {
|
|
|
5e7617 |
- goto done;
|
|
|
5e7617 |
- } else if (ret != EOK) {
|
|
|
5e7617 |
- DEBUG(SSSDBG_CRIT_FAILURE, "Cannot create SELinux handle\n");
|
|
|
5e7617 |
- goto done;
|
|
|
5e7617 |
- }
|
|
|
5e7617 |
-
|
|
|
5e7617 |
- ret = semanage_seuser_key_create(sm_handle, login_name, &sm_key);
|
|
|
5e7617 |
- if (ret != EOK) {
|
|
|
5e7617 |
- DEBUG(SSSDBG_CRIT_FAILURE, "Cannot create key for %s\n", login_name);
|
|
|
5e7617 |
- ret = EIO;
|
|
|
5e7617 |
- goto done;
|
|
|
5e7617 |
- }
|
|
|
5e7617 |
-
|
|
|
5e7617 |
- ret = semanage_seuser_query(sm_handle, sm_key, &sm_user);
|
|
|
5e7617 |
- if (ret < 0) {
|
|
|
5e7617 |
- DEBUG(SSSDBG_CRIT_FAILURE, "Cannot query for %s\n", login_name);
|
|
|
5e7617 |
- ret = EIO;
|
|
|
5e7617 |
- goto done;
|
|
|
5e7617 |
- }
|
|
|
5e7617 |
-
|
|
|
5e7617 |
- seuser = semanage_seuser_get_sename(sm_user);
|
|
|
5e7617 |
- if (seuser != NULL) {
|
|
|
5e7617 |
- *_seuser = talloc_strdup(mem_ctx, seuser);
|
|
|
5e7617 |
- if (*_seuser == NULL) {
|
|
|
5e7617 |
- ret = ENOMEM;
|
|
|
5e7617 |
- goto done;
|
|
|
5e7617 |
- }
|
|
|
5e7617 |
- DEBUG(SSSDBG_OP_FAILURE,
|
|
|
5e7617 |
- "SELinux user for %s: %s\n", login_name, *_seuser);
|
|
|
5e7617 |
- } else {
|
|
|
5e7617 |
- DEBUG(SSSDBG_CRIT_FAILURE, "Cannot get sename for %s\n", login_name);
|
|
|
5e7617 |
- }
|
|
|
5e7617 |
-
|
|
|
5e7617 |
- mls_range = semanage_seuser_get_mlsrange(sm_user);
|
|
|
5e7617 |
- if (mls_range != NULL) {
|
|
|
5e7617 |
- *_mls_range = talloc_strdup(mem_ctx, mls_range);
|
|
|
5e7617 |
- if (*_mls_range == NULL) {
|
|
|
5e7617 |
- ret = ENOMEM;
|
|
|
5e7617 |
- goto done;
|
|
|
5e7617 |
- }
|
|
|
5e7617 |
- DEBUG(SSSDBG_OP_FAILURE,
|
|
|
5e7617 |
- "SELinux range for %s: %s\n", login_name, *_mls_range);
|
|
|
5e7617 |
- } else {
|
|
|
5e7617 |
- DEBUG(SSSDBG_CRIT_FAILURE, "Cannot get mlsrange for %s\n", login_name);
|
|
|
5e7617 |
- }
|
|
|
5e7617 |
-
|
|
|
5e7617 |
- ret = EOK;
|
|
|
5e7617 |
-done:
|
|
|
5e7617 |
- semanage_seuser_key_free(sm_key);
|
|
|
5e7617 |
- semanage_seuser_free(sm_user);
|
|
|
5e7617 |
- sss_semanage_close(sm_handle);
|
|
|
5e7617 |
- return ret;
|
|
|
5e7617 |
-}
|
|
|
5e7617 |
-
|
|
|
5e7617 |
#else /* HAVE_SEMANAGE */
|
|
|
5e7617 |
int set_seuser(const char *login_name, const char *seuser_name,
|
|
|
5e7617 |
const char *mls)
|
|
|
5e7617 |
@@ -460,10 +393,4 @@ int del_seuser(const char *login_name)
|
|
|
5e7617 |
{
|
|
|
5e7617 |
return EOK;
|
|
|
5e7617 |
}
|
|
|
5e7617 |
-
|
|
|
5e7617 |
-int get_seuser(TALLOC_CTX *mem_ctx, const char *login_name,
|
|
|
5e7617 |
- char **_seuser, char **_mls_range)
|
|
|
5e7617 |
-{
|
|
|
5e7617 |
- return EOK;
|
|
|
5e7617 |
-}
|
|
|
5e7617 |
#endif /* HAVE_SEMANAGE */
|
|
|
5e7617 |
diff --git a/src/util/util.h b/src/util/util.h
|
|
|
5e7617 |
index 72d4116e1206e9cc69715edc45bf5b9b91e37e6b..1719d8eec1b6b05877b9be3382589e442bff85be 100644
|
|
|
5e7617 |
--- a/src/util/util.h
|
|
|
5e7617 |
+++ b/src/util/util.h
|
|
|
5e7617 |
@@ -658,8 +658,6 @@ errno_t restore_creds(struct sss_creds *saved_creds);
|
|
|
5e7617 |
int set_seuser(const char *login_name, const char *seuser_name,
|
|
|
5e7617 |
const char *mlsrange);
|
|
|
5e7617 |
int del_seuser(const char *login_name);
|
|
|
5e7617 |
-int get_seuser(TALLOC_CTX *mem_ctx, const char *login_name,
|
|
|
5e7617 |
- char **_seuser, char **_mls_range);
|
|
|
5e7617 |
|
|
|
5e7617 |
/* convert time from generalized form to unix time */
|
|
|
5e7617 |
errno_t sss_utc_to_time_t(const char *str, const char *format, time_t *unix_time);
|
|
|
5e7617 |
--
|
|
|
5e7617 |
2.14.3
|
|
|
5e7617 |
|