summaryrefslogtreecommitdiffstats
path: root/src/db
diff options
context:
space:
mode:
authorSumit Bose <sbose@redhat.com>2016-07-01 12:54:39 +0200
committerJakub Hrozek <jhrozek@redhat.com>2016-07-18 17:10:59 +0200
commit20348a30feb4be619b3b691c24c9be8131507c46 (patch)
tree7aa7c86963d3cf7bdaddb188088738c873bdfe2f /src/db
parent132b31fd5fb74a7627896cdceaf29c7601ed4795 (diff)
downloadsssd-20348a30feb4be619b3b691c24c9be8131507c46.tar.gz
sssd-20348a30feb4be619b3b691c24c9be8131507c46.tar.xz
sssd-20348a30feb4be619b3b691c24c9be8131507c46.zip
sysdb: make subdomain calls aware of upn_suffixes
sysdb_subdomain_store() and sysdb_update_subdomains() can now update upn_suffixes as well. Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
Diffstat (limited to 'src/db')
-rw-r--r--src/db/sysdb.h3
-rw-r--r--src/db/sysdb_subdomains.c56
2 files changed, 55 insertions, 4 deletions
diff --git a/src/db/sysdb.h b/src/db/sysdb.h
index a8dcaa4a9..407ce3c18 100644
--- a/src/db/sysdb.h
+++ b/src/db/sysdb.h
@@ -466,7 +466,8 @@ errno_t sysdb_subdomain_store(struct sysdb_ctx *sysdb,
const char *name, const char *realm,
const char *flat_name, const char *domain_id,
bool mpg, bool enumerate, const char *forest,
- uint32_t trust_direction);
+ uint32_t trust_direction,
+ struct ldb_message_element *upn_suffixes);
errno_t sysdb_update_subdomains(struct sss_domain_info *domain);
diff --git a/src/db/sysdb_subdomains.c b/src/db/sysdb_subdomains.c
index c0a190f36..02206e470 100644
--- a/src/db/sysdb_subdomains.c
+++ b/src/db/sysdb_subdomains.c
@@ -237,6 +237,7 @@ errno_t sysdb_update_subdomains(struct sss_domain_info *domain)
SYSDB_SUBDOMAIN_ENUM,
SYSDB_SUBDOMAIN_FOREST,
SYSDB_SUBDOMAIN_TRUST_DIRECTION,
+ SYSDB_UPN_SUFFIXES,
NULL};
struct sss_domain_info *dom;
struct ldb_dn *basedn;
@@ -248,6 +249,8 @@ errno_t sysdb_update_subdomains(struct sss_domain_info *domain)
bool mpg;
bool enumerate;
uint32_t trust_direction;
+ struct ldb_message_element *tmp_el;
+ const char **upn_suffixes;
tmp_ctx = talloc_new(NULL);
if (tmp_ctx == NULL) {
@@ -308,6 +311,17 @@ errno_t sysdb_update_subdomains(struct sss_domain_info *domain)
forest = ldb_msg_find_attr_as_string(res->msgs[i],
SYSDB_SUBDOMAIN_FOREST, NULL);
+ upn_suffixes = NULL;
+ tmp_el = ldb_msg_find_element(res->msgs[0], SYSDB_UPN_SUFFIXES);
+ if (tmp_el != NULL) {
+ upn_suffixes = sss_ldb_el_to_string_list(tmp_ctx, tmp_el);
+ if (upn_suffixes == NULL) {
+ DEBUG(SSSDBG_OP_FAILURE, "sss_ldb_el_to_string_list failed.\n");
+ ret = ENOMEM;
+ goto done;
+ }
+ }
+
trust_direction = ldb_msg_find_attr_as_int(res->msgs[i],
SYSDB_SUBDOMAIN_TRUST_DIRECTION,
0);
@@ -382,6 +396,9 @@ errno_t sysdb_update_subdomains(struct sss_domain_info *domain)
}
}
+ talloc_zfree(dom->upn_suffixes);
+ dom->upn_suffixes = talloc_steal(dom, upn_suffixes);
+
if (!dom->has_views && dom->view_name == NULL) {
/* maybe views are not initialized, copy from parent */
dom->has_views = dom->parent->has_views;
@@ -448,7 +465,7 @@ errno_t sysdb_master_domain_update(struct sss_domain_info *domain)
errno_t ret;
TALLOC_CTX *tmp_ctx;
const char *tmp_str;
- struct ldb_message_element **tmp_el;
+ struct ldb_message_element *tmp_el;
struct ldb_dn *basedn;
struct ldb_result *res;
const char *attrs[] = {"cn",
@@ -806,7 +823,8 @@ errno_t sysdb_subdomain_store(struct sysdb_ctx *sysdb,
const char *name, const char *realm,
const char *flat_name, const char *domain_id,
bool mpg, bool enumerate, const char *forest,
- uint32_t trust_direction)
+ uint32_t trust_direction,
+ struct ldb_message_element *upn_suffixes)
{
TALLOC_CTX *tmp_ctx;
struct ldb_message *msg;
@@ -820,8 +838,10 @@ errno_t sysdb_subdomain_store(struct sysdb_ctx *sysdb,
SYSDB_SUBDOMAIN_ENUM,
SYSDB_SUBDOMAIN_FOREST,
SYSDB_SUBDOMAIN_TRUST_DIRECTION,
+ SYSDB_UPN_SUFFIXES,
NULL};
const char *tmp_str;
+ struct ldb_message_element *tmp_el;
bool tmp_bool;
bool store = false;
int realm_flags = 0;
@@ -831,6 +851,7 @@ errno_t sysdb_subdomain_store(struct sysdb_ctx *sysdb,
int enum_flags = 0;
int forest_flags = 0;
int td_flags = 0;
+ int upn_flags = 0;
uint32_t tmp_td;
int ret;
@@ -864,6 +885,7 @@ errno_t sysdb_subdomain_store(struct sysdb_ctx *sysdb,
enum_flags = LDB_FLAG_MOD_ADD;
if (forest) forest_flags = LDB_FLAG_MOD_ADD;
if (trust_direction) td_flags = LDB_FLAG_MOD_ADD;
+ if (upn_suffixes) upn_flags = LDB_FLAG_MOD_ADD;
} else if (res->count != 1) {
ret = EINVAL;
goto done;
@@ -915,11 +937,21 @@ errno_t sysdb_subdomain_store(struct sysdb_ctx *sysdb,
if (tmp_td != trust_direction) {
td_flags = LDB_FLAG_MOD_REPLACE;
}
+
+ if (upn_suffixes) {
+ tmp_el = ldb_msg_find_element(res->msgs[0], SYSDB_UPN_SUFFIXES);
+ /* Luckily ldb_msg_element_compare() only compares the values and
+ * not the name. */
+ if (tmp_el == NULL
+ || ldb_msg_element_compare(upn_suffixes, tmp_el) != 0) {
+ upn_flags = LDB_FLAG_MOD_REPLACE;
+ }
+ }
}
if (!store && realm_flags == 0 && flat_flags == 0 && id_flags == 0
&& mpg_flags == 0 && enum_flags == 0 && forest_flags == 0
- && td_flags == 0) {
+ && td_flags == 0 && upn_flags == 0) {
ret = EOK;
goto done;
}
@@ -1048,6 +1080,24 @@ errno_t sysdb_subdomain_store(struct sysdb_ctx *sysdb,
}
}
+ if (upn_flags) {
+ tmp_el = talloc_zero(tmp_ctx, struct ldb_message_element);
+ if (tmp_el == NULL) {
+ DEBUG(SSSDBG_OP_FAILURE, "talloc_zero failed.\n");
+ ret = ENOMEM;
+ goto done;
+ }
+
+ tmp_el->name = SYSDB_UPN_SUFFIXES;
+ tmp_el->num_values = upn_suffixes->num_values;
+ tmp_el->values = upn_suffixes->values;
+ ret = ldb_msg_add(msg, tmp_el, upn_flags);
+ if (ret != LDB_SUCCESS) {
+ ret = sysdb_error_to_errno(ret);
+ goto done;
+ }
+ }
+
ret = ldb_modify(sysdb->ldb, msg);
if (ret != LDB_SUCCESS) {
DEBUG(SSSDBG_FATAL_FAILURE, "Failed to add subdomain attributes to "