|
|
905b4d |
From ac992d1ae46ec5ff44a1300718f12c10b1cbd60a Mon Sep 17 00:00:00 2001
|
|
|
905b4d |
From: Sumit Bose <sbose@redhat.com>
|
|
|
905b4d |
Date: Mon, 27 Oct 2014 13:33:08 +0100
|
|
|
905b4d |
Subject: [PATCH 60/64] sysdb_get_user_attr_with_views: add mandatory override
|
|
|
905b4d |
attributes
|
|
|
905b4d |
|
|
|
905b4d |
This patch add another attribute with is needs for override processing
|
|
|
905b4d |
to the attribute list of sysdb_get_user_attr_with_views(). With two
|
|
|
905b4d |
attribute it does not seem useful to check for existence and add each of
|
|
|
905b4d |
the attributes conditionally. With this patch they are added
|
|
|
905b4d |
unconditionally if the domain has views. Additionally the attributes are
|
|
|
905b4d |
not removed in the end because it is expected that they do not cause any
|
|
|
905b4d |
harm.
|
|
|
905b4d |
|
|
|
905b4d |
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
|
|
|
905b4d |
---
|
|
|
905b4d |
src/db/sysdb_search.c | 47 ++++++++---------------------------------------
|
|
|
905b4d |
1 file changed, 8 insertions(+), 39 deletions(-)
|
|
|
905b4d |
|
|
|
905b4d |
diff --git a/src/db/sysdb_search.c b/src/db/sysdb_search.c
|
|
|
905b4d |
index bbc5af8a02777c1519a9d0b5d77c50559e66f462..dacbd239db6be7e4c738d5bd6b495b613411b126 100644
|
|
|
905b4d |
--- a/src/db/sysdb_search.c
|
|
|
905b4d |
+++ b/src/db/sysdb_search.c
|
|
|
905b4d |
@@ -1037,11 +1037,11 @@ int sysdb_get_user_attr_with_views(TALLOC_CTX *mem_ctx,
|
|
|
905b4d |
int ret;
|
|
|
905b4d |
struct ldb_result *orig_obj = NULL;
|
|
|
905b4d |
struct ldb_result *override_obj = NULL;
|
|
|
905b4d |
- struct ldb_message_element *el = NULL;
|
|
|
905b4d |
const char **attrs = NULL;
|
|
|
905b4d |
- bool has_override_dn;
|
|
|
905b4d |
+ const char *mandatory_override_attrs[] = {SYSDB_OVERRIDE_DN,
|
|
|
905b4d |
+ SYSDB_OVERRIDE_OBJECT_DN,
|
|
|
905b4d |
+ NULL};
|
|
|
905b4d |
TALLOC_CTX *tmp_ctx;
|
|
|
905b4d |
- int count;
|
|
|
905b4d |
|
|
|
905b4d |
tmp_ctx = talloc_new(NULL);
|
|
|
905b4d |
if (tmp_ctx == NULL) {
|
|
|
905b4d |
@@ -1049,35 +1049,15 @@ int sysdb_get_user_attr_with_views(TALLOC_CTX *mem_ctx,
|
|
|
905b4d |
return ENOMEM;
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
- /* Assume that overrideDN is requested to simplify the code. If no view
|
|
|
905b4d |
- * is applied it doesn't really matter. */
|
|
|
905b4d |
- has_override_dn = true;
|
|
|
905b4d |
attrs = attributes;
|
|
|
905b4d |
|
|
|
905b4d |
/* If there are views we first have to search the overrides for matches */
|
|
|
905b4d |
if (DOM_HAS_VIEWS(domain)) {
|
|
|
905b4d |
- /* We need overrideDN for views, so append it if missing. */
|
|
|
905b4d |
- has_override_dn = false;
|
|
|
905b4d |
- for (count = 0; attributes[count] != NULL; count++) {
|
|
|
905b4d |
- if (strcmp(attributes[count], SYSDB_OVERRIDE_DN) == 0) {
|
|
|
905b4d |
- has_override_dn = true;
|
|
|
905b4d |
- break;
|
|
|
905b4d |
- }
|
|
|
905b4d |
- }
|
|
|
905b4d |
-
|
|
|
905b4d |
- if (!has_override_dn) {
|
|
|
905b4d |
- /* Copy original attributes and add overrideDN. */
|
|
|
905b4d |
- attrs = talloc_zero_array(tmp_ctx, const char *, count + 2);
|
|
|
905b4d |
- if (attrs == NULL) {
|
|
|
905b4d |
- ret = ENOMEM;
|
|
|
905b4d |
- goto done;
|
|
|
905b4d |
- }
|
|
|
905b4d |
-
|
|
|
905b4d |
- for (count = 0; attributes[count] != NULL; count++) {
|
|
|
905b4d |
- attrs[count] = attributes[count];
|
|
|
905b4d |
- }
|
|
|
905b4d |
-
|
|
|
905b4d |
- attrs[count] = SYSDB_OVERRIDE_DN;
|
|
|
905b4d |
+ ret = add_strings_lists(tmp_ctx, attributes, mandatory_override_attrs,
|
|
|
905b4d |
+ false, discard_const(&attrs));
|
|
|
905b4d |
+ if (ret != EOK) {
|
|
|
905b4d |
+ DEBUG(SSSDBG_OP_FAILURE, "add_strings_lists failed.\n");
|
|
|
905b4d |
+ goto done;
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
ret = sysdb_search_user_override_attrs_by_name(tmp_ctx, domain, name,
|
|
|
905b4d |
@@ -1121,17 +1101,6 @@ int sysdb_get_user_attr_with_views(TALLOC_CTX *mem_ctx,
|
|
|
905b4d |
}
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
- /* Remove overrideDN if needed. */
|
|
|
905b4d |
- if (!has_override_dn && orig_obj != NULL && orig_obj->count == 1) {
|
|
|
905b4d |
- el = ldb_msg_find_element(orig_obj->msgs[0], SYSDB_OVERRIDE_DN);
|
|
|
905b4d |
- if (el == NULL) {
|
|
|
905b4d |
- ret = EINVAL;
|
|
|
905b4d |
- goto done;
|
|
|
905b4d |
- }
|
|
|
905b4d |
-
|
|
|
905b4d |
- ldb_msg_remove_element(orig_obj->msgs[0], el);
|
|
|
905b4d |
- }
|
|
|
905b4d |
-
|
|
|
905b4d |
*_res = talloc_steal(mem_ctx, orig_obj);
|
|
|
905b4d |
ret = EOK;
|
|
|
905b4d |
|
|
|
905b4d |
--
|
|
|
905b4d |
1.9.3
|
|
|
905b4d |
|