diff options
author | Jan Zeleny <jzeleny@redhat.com> | 2012-05-15 06:33:13 -0400 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2012-06-10 15:45:42 -0400 |
commit | 84c611c1b7c04cc7735ab54d4e5f48284b79e6fb (patch) | |
tree | 003902da01986b7b5464a7f279146d8995b0f340 /src/db | |
parent | d1b9cd8de7b10f5d54501aace8731db9abbcc0b1 (diff) | |
download | sssd-84c611c1b7c04cc7735ab54d4e5f48284b79e6fb.tar.gz sssd-84c611c1b7c04cc7735ab54d4e5f48284b79e6fb.tar.bz2 sssd-84c611c1b7c04cc7735ab54d4e5f48284b79e6fb.zip |
IPA subdomains - ask for information about master domain
The query is performed only if there is missing information in the
cache. That means this should be done only once after restart when cache
doesn't exist. All subsequent requests for subdomains won't include the
request for master domain.
Diffstat (limited to 'src/db')
-rw-r--r-- | src/db/sysdb.h | 7 | ||||
-rw-r--r-- | src/db/sysdb_subdomains.c | 166 |
2 files changed, 173 insertions, 0 deletions
diff --git a/src/db/sysdb.h b/src/db/sysdb.h index 85dde2c4..5867b19c 100644 --- a/src/db/sysdb.h +++ b/src/db/sysdb.h @@ -340,6 +340,13 @@ errno_t sysdb_get_subdomain_context(TALLOC_CTX *mem_ctx, struct sss_domain_info *subdomain, struct sysdb_ctx **subdomain_ctx); +errno_t sysdb_master_domain_get_info(TALLOC_CTX *mem_ctx, + struct sysdb_ctx *sysdb, + struct subdomain_info **info); + +errno_t sysdb_master_domain_add_info(struct sysdb_ctx *sysdb, + struct subdomain_info *domain_info); + errno_t sysdb_search_domuser_by_name(TALLOC_CTX *mem_ctx, struct sss_domain_info *domain, diff --git a/src/db/sysdb_subdomains.c b/src/db/sysdb_subdomains.c index bac846ef..523a23a5 100644 --- a/src/db/sysdb_subdomains.c +++ b/src/db/sysdb_subdomains.c @@ -112,6 +112,172 @@ done: return ret; } +errno_t sysdb_master_domain_get_info(TALLOC_CTX *mem_ctx, + struct sysdb_ctx *sysdb, + struct subdomain_info **_info) +{ + errno_t ret; + TALLOC_CTX *tmp_ctx; + const char *tmp_str; + struct ldb_dn *basedn; + struct subdomain_info *info; + struct ldb_result *res; + const char *attrs[] = {"cn", + SYSDB_SUBDOMAIN_FLAT, + SYSDB_SUBDOMAIN_ID, + NULL}; + + tmp_ctx = talloc_new(NULL); + if (tmp_ctx == NULL) { + return ENOMEM; + } + + info = talloc_zero(tmp_ctx, struct subdomain_info); + if (info == NULL) { + ret = ENOMEM; + goto done; + } + + basedn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, SYSDB_DOM_BASE, + sysdb->domain->name); + if (basedn == NULL) { + ret = EIO; + goto done; + } + ret = ldb_search(sysdb->ldb, tmp_ctx, &res, basedn, LDB_SCOPE_BASE, attrs, + NULL); + if (ret != LDB_SUCCESS) { + ret = EIO; + goto done; + } + + if (res->count != 1) { + DEBUG(SSSDBG_OP_FAILURE, ("Base search returned [%d] results, " + "expected 1.\n")); + ret = EINVAL; + goto done; + } + + tmp_str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_SUBDOMAIN_FLAT, + NULL); + if (tmp_str != NULL) { + info->flat_name = talloc_strdup(info, tmp_str); + if (info->flat_name == NULL) { + ret = ENOMEM; + goto done; + } + } + + tmp_str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_SUBDOMAIN_ID, + NULL); + if (tmp_str != NULL) { + info->flat_name = talloc_strdup(info, tmp_str); + if (info->flat_name == NULL) { + ret = ENOMEM; + goto done; + } + } + + *_info = talloc_steal(mem_ctx, info); +done: + talloc_free(tmp_ctx); + return ret; +} + +errno_t sysdb_master_domain_add_info(struct sysdb_ctx *sysdb, + struct subdomain_info *domain_info) +{ + TALLOC_CTX *tmp_ctx; + struct ldb_message *msg; + int ret; + bool do_update = false; + struct subdomain_info *current_info; + + tmp_ctx = talloc_new(NULL); + if (tmp_ctx == NULL) { + return ENOMEM; + } + + ret = sysdb_master_domain_get_info(tmp_ctx, sysdb, ¤t_info); + if (ret != EOK) { + goto done; + } + + msg = ldb_msg_new(tmp_ctx); + if (msg == NULL) { + ret = ENOMEM; + goto done; + } + + msg->dn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, SYSDB_DOM_BASE, + sysdb->domain->name); + if (msg->dn == NULL) { + ret = EIO; + goto done; + } + + if (domain_info->flat_name != NULL && + (current_info->flat_name == NULL || + strcmp(current_info->flat_name, domain_info->flat_name) != 0) ) { + ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_FLAT, LDB_FLAG_MOD_REPLACE, + NULL); + if (ret != LDB_SUCCESS) { + ret = sysdb_error_to_errno(ret); + goto done; + } + + ret = ldb_msg_add_fmt(msg, SYSDB_SUBDOMAIN_FLAT, "%s", + domain_info->flat_name); + if (ret != LDB_SUCCESS) { + ret = sysdb_error_to_errno(ret);; + goto done; + } + + do_update = true; + } + + if (domain_info->id != NULL && + (current_info->flat_name == NULL || + strcmp(current_info->flat_name, domain_info->id) != 0) ) { + ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_ID, LDB_FLAG_MOD_REPLACE, + NULL); + if (ret != LDB_SUCCESS) { + ret = sysdb_error_to_errno(ret); + goto done; + } + + ret = ldb_msg_add_fmt(msg, SYSDB_SUBDOMAIN_ID, "%s", + domain_info->id); + if (ret != LDB_SUCCESS) { + ret = sysdb_error_to_errno(ret);; + goto done; + } + + do_update = true; + } + + if (do_update == false) { + ret = EOK; + goto done; + } + + ret = ldb_modify(sysdb->ldb, msg); + if (ret != LDB_SUCCESS) { + DEBUG(SSSDBG_FATAL_FAILURE, ("Failed to add subdomain attributes to " + "[%s]: [%d][%s]!\n", + domain_info->name, ret, + ldb_errstring(sysdb->ldb))); + ret = sysdb_error_to_errno(ret); + goto done; + } + + ret = EOK; + +done: + talloc_free(tmp_ctx); + + return ret; +} static errno_t sysdb_add_subdomain_attributes(struct sysdb_ctx *sysdb, struct subdomain_info *domain_info) { |