|
|
ecf709 |
From 3abbd7569f96a980676e0323d95301c50acdf062 Mon Sep 17 00:00:00 2001
|
|
|
ecf709 |
From: Jakub Hrozek <jhrozek@redhat.com>
|
|
|
ecf709 |
Date: Wed, 22 Mar 2017 13:06:08 +0100
|
|
|
ecf709 |
Subject: [PATCH 70/72] LDAP: save non-POSIX users in application domains
|
|
|
ecf709 |
|
|
|
ecf709 |
Related to:
|
|
|
ecf709 |
https://pagure.io/SSSD/sssd/issue/3310
|
|
|
ecf709 |
|
|
|
ecf709 |
If a user being saved by the LDAP provider does not have a UID or GID
|
|
|
ecf709 |
and the domain type is application, we save the user entry as non-POSIX.
|
|
|
ecf709 |
|
|
|
ecf709 |
Reviewed-by: Sumit Bose <sbose@redhat.com>
|
|
|
ecf709 |
---
|
|
|
ecf709 |
src/providers/ldap/sdap_async_users.c | 72 +++++++++++++++++++++++++++--------
|
|
|
ecf709 |
1 file changed, 57 insertions(+), 15 deletions(-)
|
|
|
ecf709 |
|
|
|
ecf709 |
diff --git a/src/providers/ldap/sdap_async_users.c b/src/providers/ldap/sdap_async_users.c
|
|
|
ecf709 |
index 3d957ab584865f74499bc732395388a78965fe5f..265cd7e4f7929c295d5bdcfbd781221b74601f13 100644
|
|
|
ecf709 |
--- a/src/providers/ldap/sdap_async_users.c
|
|
|
ecf709 |
+++ b/src/providers/ldap/sdap_async_users.c
|
|
|
ecf709 |
@@ -112,6 +112,28 @@ done:
|
|
|
ecf709 |
return ret;
|
|
|
ecf709 |
}
|
|
|
ecf709 |
|
|
|
ecf709 |
+static errno_t sdap_set_non_posix_flag(struct sysdb_attrs *attrs,
|
|
|
ecf709 |
+ const char *pkey)
|
|
|
ecf709 |
+{
|
|
|
ecf709 |
+ errno_t ret;
|
|
|
ecf709 |
+
|
|
|
ecf709 |
+ ret = sysdb_attrs_add_uint32(attrs, pkey, 0);
|
|
|
ecf709 |
+ if (ret != EOK) {
|
|
|
ecf709 |
+ DEBUG(SSSDBG_CRIT_FAILURE,
|
|
|
ecf709 |
+ "Failed to add a zero ID to a non-posix object!\n");
|
|
|
ecf709 |
+ return ret;
|
|
|
ecf709 |
+ }
|
|
|
ecf709 |
+
|
|
|
ecf709 |
+ ret = sysdb_attrs_add_bool(attrs, SYSDB_POSIX, false);
|
|
|
ecf709 |
+ if (ret != EOK) {
|
|
|
ecf709 |
+ DEBUG(SSSDBG_OP_FAILURE,
|
|
|
ecf709 |
+ "Error: Failed to mark objects as non-posix!\n");
|
|
|
ecf709 |
+ return ret;
|
|
|
ecf709 |
+ }
|
|
|
ecf709 |
+
|
|
|
ecf709 |
+ return EOK;
|
|
|
ecf709 |
+}
|
|
|
ecf709 |
+
|
|
|
ecf709 |
/* FIXME: support storing additional attributes */
|
|
|
ecf709 |
int sdap_save_user(TALLOC_CTX *memctx,
|
|
|
ecf709 |
struct sdap_options *opts,
|
|
|
ecf709 |
@@ -130,8 +152,8 @@ int sdap_save_user(TALLOC_CTX *memctx,
|
|
|
ecf709 |
const char *homedir;
|
|
|
ecf709 |
const char *shell;
|
|
|
ecf709 |
const char *orig_dn = NULL;
|
|
|
ecf709 |
- uid_t uid;
|
|
|
ecf709 |
- gid_t gid;
|
|
|
ecf709 |
+ uid_t uid = 0;
|
|
|
ecf709 |
+ gid_t gid = 0;
|
|
|
ecf709 |
struct sysdb_attrs *user_attrs;
|
|
|
ecf709 |
char *upn = NULL;
|
|
|
ecf709 |
size_t i;
|
|
|
ecf709 |
@@ -146,6 +168,7 @@ int sdap_save_user(TALLOC_CTX *memctx,
|
|
|
ecf709 |
size_t c;
|
|
|
ecf709 |
char *p1;
|
|
|
ecf709 |
char *p2;
|
|
|
ecf709 |
+ bool is_posix = true;
|
|
|
ecf709 |
|
|
|
ecf709 |
DEBUG(SSSDBG_TRACE_FUNC, "Save user\n");
|
|
|
ecf709 |
|
|
|
ecf709 |
@@ -295,19 +318,29 @@ int sdap_save_user(TALLOC_CTX *memctx,
|
|
|
ecf709 |
ret = sysdb_attrs_get_uint32_t(attrs,
|
|
|
ecf709 |
opts->user_map[SDAP_AT_USER_UID].sys_name,
|
|
|
ecf709 |
&uid);
|
|
|
ecf709 |
- if (ret != EOK) {
|
|
|
ecf709 |
+ if (ret == ENOENT && dom->type == DOM_TYPE_APPLICATION) {
|
|
|
ecf709 |
+ DEBUG(SSSDBG_TRACE_INTERNAL,
|
|
|
ecf709 |
+ "Marking object as non-posix and setting ID=0!\n");
|
|
|
ecf709 |
+ ret = sdap_set_non_posix_flag(user_attrs,
|
|
|
ecf709 |
+ opts->user_map[SDAP_AT_USER_UID].sys_name);
|
|
|
ecf709 |
+ if (ret != EOK) {
|
|
|
ecf709 |
+ goto done;
|
|
|
ecf709 |
+ }
|
|
|
ecf709 |
+ is_posix = false;
|
|
|
ecf709 |
+ } else if (ret != EOK) {
|
|
|
ecf709 |
DEBUG(SSSDBG_CRIT_FAILURE,
|
|
|
ecf709 |
- "no uid provided for [%s] in domain [%s].\n",
|
|
|
ecf709 |
+ "Cannot retrieve UID for [%s] in domain [%s].\n",
|
|
|
ecf709 |
user_name, dom->name);
|
|
|
ecf709 |
- ret = EINVAL;
|
|
|
ecf709 |
+ ret = ERR_NO_POSIX;
|
|
|
ecf709 |
goto done;
|
|
|
ecf709 |
}
|
|
|
ecf709 |
}
|
|
|
ecf709 |
- /* check that the uid is valid for this domain */
|
|
|
ecf709 |
- if (OUT_OF_ID_RANGE(uid, dom->id_min, dom->id_max)) {
|
|
|
ecf709 |
- DEBUG(SSSDBG_OP_FAILURE,
|
|
|
ecf709 |
- "User [%s] filtered out! (uid out of range)\n",
|
|
|
ecf709 |
- user_name);
|
|
|
ecf709 |
+
|
|
|
ecf709 |
+ /* check that the uid is valid for this domain if the user is a POSIX one */
|
|
|
ecf709 |
+ if (is_posix == true && OUT_OF_ID_RANGE(uid, dom->id_min, dom->id_max)) {
|
|
|
ecf709 |
+ DEBUG(SSSDBG_OP_FAILURE,
|
|
|
ecf709 |
+ "User [%s] filtered out! (uid out of range)\n",
|
|
|
ecf709 |
+ user_name);
|
|
|
ecf709 |
ret = EINVAL;
|
|
|
ecf709 |
goto done;
|
|
|
ecf709 |
}
|
|
|
ecf709 |
@@ -349,17 +382,26 @@ int sdap_save_user(TALLOC_CTX *memctx,
|
|
|
ecf709 |
ret = sysdb_attrs_get_uint32_t(attrs,
|
|
|
ecf709 |
opts->user_map[SDAP_AT_USER_GID].sys_name,
|
|
|
ecf709 |
&gid;;
|
|
|
ecf709 |
- if (ret != EOK) {
|
|
|
ecf709 |
+ if (ret == ENOENT && dom->type == DOM_TYPE_APPLICATION) {
|
|
|
ecf709 |
+ DEBUG(SSSDBG_TRACE_INTERNAL,
|
|
|
ecf709 |
+ "Marking object as non-posix and setting ID=0!\n");
|
|
|
ecf709 |
+ ret = sdap_set_non_posix_flag(attrs,
|
|
|
ecf709 |
+ opts->user_map[SDAP_AT_USER_GID].sys_name);
|
|
|
ecf709 |
+ if (ret != EOK) {
|
|
|
ecf709 |
+ goto done;
|
|
|
ecf709 |
+ }
|
|
|
ecf709 |
+ is_posix = false;
|
|
|
ecf709 |
+ } else if (ret != EOK) {
|
|
|
ecf709 |
DEBUG(SSSDBG_CRIT_FAILURE,
|
|
|
ecf709 |
- "no gid provided for [%s] in domain [%s].\n",
|
|
|
ecf709 |
- user_name, dom->name);
|
|
|
ecf709 |
- ret = EINVAL;
|
|
|
ecf709 |
+ "Cannot retrieve GID for [%s] in domain [%s].\n",
|
|
|
ecf709 |
+ user_name, dom->name);
|
|
|
ecf709 |
+ ret = ERR_NO_POSIX;
|
|
|
ecf709 |
goto done;
|
|
|
ecf709 |
}
|
|
|
ecf709 |
}
|
|
|
ecf709 |
|
|
|
ecf709 |
/* check that the gid is valid for this domain */
|
|
|
ecf709 |
- if (IS_SUBDOMAIN(dom) == false &&
|
|
|
ecf709 |
+ if (is_posix == true && IS_SUBDOMAIN(dom) == false &&
|
|
|
ecf709 |
OUT_OF_ID_RANGE(gid, dom->id_min, dom->id_max)) {
|
|
|
ecf709 |
DEBUG(SSSDBG_CRIT_FAILURE,
|
|
|
ecf709 |
"User [%s] filtered out! (primary gid out of range)\n",
|
|
|
ecf709 |
--
|
|
|
ecf709 |
2.9.3
|
|
|
ecf709 |
|