diff options
author | Simo Sorce <simo@redhat.com> | 2012-07-19 19:15:57 -0400 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2012-08-01 22:24:44 +0200 |
commit | 204cfc89a076fd32bf34f2abb3f809304aaa88ab (patch) | |
tree | 908b05e88f0648b5e22b334f6ea3de53eb139bc0 /src | |
parent | 067bfcaad9baae2d962528839fde30ebd1a5ba2b (diff) | |
download | sssd-204cfc89a076fd32bf34f2abb3f809304aaa88ab.tar.gz sssd-204cfc89a076fd32bf34f2abb3f809304aaa88ab.tar.xz sssd-204cfc89a076fd32bf34f2abb3f809304aaa88ab.zip |
Add realm paramter to subdomain list
This will be used later for setting domain_realm mappings in krb5.conf
Diffstat (limited to 'src')
-rw-r--r-- | src/db/sysdb.h | 8 | ||||
-rw-r--r-- | src/db/sysdb_subdomains.c | 58 | ||||
-rw-r--r-- | src/providers/ipa/ipa_subdomains.c | 27 | ||||
-rw-r--r-- | src/tests/sysdb-tests.c | 6 |
4 files changed, 93 insertions, 6 deletions
diff --git a/src/db/sysdb.h b/src/db/sysdb.h index 20641a753..0e2404c70 100644 --- a/src/db/sysdb.h +++ b/src/db/sysdb.h @@ -142,6 +142,7 @@ #define SYSDB_SSH_PUBKEY "sshPublicKey" +#define SYSDB_SUBDOMAIN_REALM "realmName" #define SYSDB_SUBDOMAIN_FLAT "flatName" #define SYSDB_SUBDOMAIN_ID "domainID" @@ -241,9 +242,10 @@ struct sysdb_attrs { struct sysdb_attrs *sysdb_new_attrs(TALLOC_CTX *mem_ctx); struct sysdb_subdom { - char *name; - char *flat_name; - char *id; + const char *realm; + const char *name; + const char *flat_name; + const char *id; }; struct range_info { diff --git a/src/db/sysdb_subdomains.c b/src/db/sysdb_subdomains.c index 533874f66..8f1df88be 100644 --- a/src/db/sysdb_subdomains.c +++ b/src/db/sysdb_subdomains.c @@ -32,6 +32,7 @@ errno_t sysdb_get_subdomains(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb, TALLOC_CTX *tmp_ctx; struct ldb_result *res; const char *attrs[] = {"cn", + SYSDB_SUBDOMAIN_REALM, SYSDB_SUBDOMAIN_FLAT, SYSDB_SUBDOMAIN_ID, NULL}; @@ -86,6 +87,16 @@ errno_t sysdb_get_subdomains(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb, } tmp_str = ldb_msg_find_attr_as_string(res->msgs[i], + SYSDB_SUBDOMAIN_REALM, NULL); + if (tmp_str != NULL) { + list[i]->realm = talloc_strdup(list, tmp_str); + if (list[i]->realm == NULL) { + ret = ENOMEM; + goto done; + } + } + + tmp_str = ldb_msg_find_attr_as_string(res->msgs[i], SYSDB_SUBDOMAIN_FLAT, NULL); if (tmp_str != NULL) { list[i]->flat_name = talloc_strdup(list, tmp_str); @@ -126,6 +137,7 @@ errno_t sysdb_master_domain_get_info(TALLOC_CTX *mem_ctx, struct sysdb_subdom *info; struct ldb_result *res; const char *attrs[] = {"cn", + SYSDB_SUBDOMAIN_REALM, SYSDB_SUBDOMAIN_FLAT, SYSDB_SUBDOMAIN_ID, NULL}; @@ -166,6 +178,16 @@ errno_t sysdb_master_domain_get_info(TALLOC_CTX *mem_ctx, goto done; } + tmp_str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_SUBDOMAIN_REALM, + NULL); + if (tmp_str != NULL) { + info->realm = talloc_strdup(info, tmp_str); + if (info->realm == NULL) { + ret = ENOMEM; + goto done; + } + } + tmp_str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_SUBDOMAIN_FLAT, NULL); if (tmp_str != NULL) { @@ -224,6 +246,26 @@ errno_t sysdb_master_domain_add_info(struct sysdb_ctx *sysdb, goto done; } + if (domain_info->realm != NULL && + (current_info->realm == NULL || + strcmp(current_info->realm, domain_info->realm) != 0) ) { + ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_REALM, + LDB_FLAG_MOD_REPLACE, NULL); + if (ret != LDB_SUCCESS) { + ret = sysdb_error_to_errno(ret); + goto done; + } + + ret = ldb_msg_add_string(msg, SYSDB_SUBDOMAIN_REALM, + domain_info->realm); + if (ret != LDB_SUCCESS) { + ret = sysdb_error_to_errno(ret); + goto done; + } + + do_update = true; + } + if (domain_info->flat_name != NULL && (current_info->flat_name == NULL || strcmp(current_info->flat_name, domain_info->flat_name) != 0) ) { @@ -322,6 +364,22 @@ static errno_t sysdb_add_subdomain_attributes(struct sysdb_ctx *sysdb, goto done; } + if (domain_info->realm != NULL) { + ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_REALM, LDB_FLAG_MOD_ADD, + NULL); + if (ret != LDB_SUCCESS) { + ret = sysdb_error_to_errno(ret); + goto done; + } + + ret = ldb_msg_add_string(msg, SYSDB_SUBDOMAIN_REALM, + domain_info->realm); + if (ret != LDB_SUCCESS) { + ret = sysdb_error_to_errno(ret); + goto done; + } + } + if (domain_info->flat_name != NULL) { ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_FLAT, LDB_FLAG_MOD_ADD, NULL); diff --git a/src/providers/ipa/ipa_subdomains.c b/src/providers/ipa/ipa_subdomains.c index e842e24bf..8a49c6343 100644 --- a/src/providers/ipa/ipa_subdomains.c +++ b/src/providers/ipa/ipa_subdomains.c @@ -25,6 +25,7 @@ #include "providers/ldap/sdap_async.h" #include "providers/ipa/ipa_subdomains.h" #include "providers/ipa/ipa_common.h" +#include <ctype.h> #define SUBDOMAINS_FILTER "objectclass=ipaNTTrustedDomain" #define MASTER_DOMAIN_FILTER "objectclass=ipaNTDomainAttrs" @@ -151,6 +152,22 @@ done: return ret; } +static char *name_to_realm(TALLOC_CTX *memctx, const char *name) +{ + char *realm; + char *p; + + realm = talloc_strdup(memctx, name); + if (!realm) { + return NULL; + } + for (p = realm; *p; p++) { + *p = toupper(*p); + } + + return realm; +} + static errno_t ipa_subdomains_parse_results(struct be_subdom_req *sd_data, size_t count, struct sysdb_attrs **reply) @@ -187,6 +204,16 @@ static errno_t ipa_subdomains_parse_results(struct be_subdom_req *sd_data, goto done; } + /* Add Realm as upper(domain name), this is generally always correct + * with AD domains */ + new_domain_list[c]->realm = name_to_realm(new_domain_list[c], + new_domain_list[c]->name); + if (!new_domain_list[c]->realm) { + DEBUG(SSSDBG_OP_FAILURE, ("talloc_strdup failed.\n")); + ret = ENOMEM; + goto done; + } + ret = sysdb_attrs_get_string(reply[c], IPA_FLATNAME, &value); if (ret == EOK) { new_domain_list[c]->flat_name = talloc_strdup(new_domain_list[c], diff --git a/src/tests/sysdb-tests.c b/src/tests/sysdb-tests.c index bf7f157ed..1eb9503f0 100644 --- a/src/tests/sysdb-tests.c +++ b/src/tests/sysdb-tests.c @@ -3388,9 +3388,9 @@ START_TEST(test_sysdb_original_dn_case_insensitive) } END_TEST -struct sysdb_subdom dom1 = { "dom1.sub", "dom1", "S-1" }; -struct sysdb_subdom dom2 = { "dom2.sub", "dom2", "S-2" }; -struct sysdb_subdom dom_t = { "test.sub", "test", "S-3" }; +struct sysdb_subdom dom1 = { "DOM1.SUB", "dom1.sub", "dom1", "S-1" }; +struct sysdb_subdom dom2 = { "DOM2.SUB", "dom2.sub", "dom2", "S-2" }; +struct sysdb_subdom dom_t = { "TEST.SUB", "test.sub", "test", "S-3" }; START_TEST(test_sysdb_subdomain_create) { |