ipa_subdomains.c revision 65393a294e635822c1d7a15fe5853dc457ad8a2a
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose IPA Subdomains Module
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose Sumit Bose <sbose@redhat.com>
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose Copyright (C) 2011 Red Hat
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose This program is free software; you can redistribute it and/or modify
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose it under the terms of the GNU General Public License as published by
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose the Free Software Foundation; either version 3 of the License, or
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose (at your option) any later version.
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose This program is distributed in the hope that it will be useful,
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose but WITHOUT ANY WARRANTY; without even the implied warranty of
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose GNU General Public License for more details.
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose You should have received a copy of the GNU General Public License
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose along with this program. If not, see <http://www.gnu.org/licenses/>.
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny#define SUBDOMAINS_FILTER "objectclass=ipaNTTrustedDomain"
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose#define MASTER_DOMAIN_FILTER "objectclass=ipaNTDomainAttrs"
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose#define IPA_TRUSTED_DOMAIN_SID "ipaNTTrustedDomainSID"
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose#define IPA_SECONDARY_BASE_RID "ipaSecondaryBaseRID"
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny/* do not refresh more often than every 5 seconds for now */
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny/* refresh automatically every 4 hours */
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny/* the directory domain - realm mappings are written to */
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny#define IPA_SUBDOMAIN_MAPPING_DIR PUBCONF_PATH"/krb5.include.d"
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose const char *filter;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose /* subdomain map cache */
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Boseconst char *get_flat_name_from_subdomain_name(struct be_ctx *be_ctx,
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose const char *name)
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ctx = talloc_get_type(be_ctx->bet_info[BET_SUBDOMAINS].pvt_bet_data,
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose DEBUG(SSSDBG_TRACE_ALL, ("Subdomains are not configured.\n"));
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose if (strcasecmp(ctx->subdoms[c].name, name) == 0 ||
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose strcasecmp(ctx->subdoms[c].flat_name, name) == 0)) {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bosestatic errno_t ipa_ranges_parse_results(TALLOC_CTX *mem_ctx,
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose const char *value;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose range_list = talloc_array(mem_ctx, struct range_info *, count + 1);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("talloc_array failed.\n"));
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose for (c = 0; c < count; c++) {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose range_list[c] = talloc_zero(range_list, struct range_info);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("talloc_zero failed.\n"));
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = sysdb_attrs_get_string(reply[c], IPA_CN, &value);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose range_list[c]->name = talloc_strdup(range_list[c], value);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("talloc_strdup failed.\n"));
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = sysdb_attrs_get_string(reply[c], IPA_TRUSTED_DOMAIN_SID, &value);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose range_list[c]->trusted_dom_sid = talloc_strdup(range_list[c],
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("talloc_strdup failed.\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = sysdb_attrs_get_uint32_t(reply[c], IPA_BASE_ID,
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = sysdb_attrs_get_uint32_t(reply[c], IPA_ID_RANGE_SIZE,
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = sysdb_attrs_get_uint32_t(reply[c], IPA_BASE_RID,
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = sysdb_attrs_get_uint32_t(reply[c], IPA_SECONDARY_BASE_RID,
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bosestatic errno_t ipa_subdom_parse(TALLOC_CTX *memctx,
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose const char *value;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = sysdb_attrs_get_string(attrs, IPA_CN, &value);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("subdomain name mismatch!\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose /* Add Realm as upper(domain name), this is generally always correct
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose * with AD domains */
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose subdom->realm = get_uppercase_realm(memctx, subdom->name);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = sysdb_attrs_get_string(attrs, IPA_FLATNAME, &value);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose /* in theory this may change, it should never happen, so we will log a
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose * warning if it does, but we will allow it for now */
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ("Flat name for subdomain changed!\n"));
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny subdom->flat_name = talloc_strdup(memctx, value);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = sysdb_attrs_get_string(attrs, IPA_TRUSTED_DOMAIN_SID, &value);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose /* in theory this may change, it should never happen, so we will log a
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose * warning if it does, but we will allow it for now */
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ("ID for subdomain changed!\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Boseipa_subdomains_write_mappings(struct sss_domain_info *domain,
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose mapping_file = talloc_asprintf(tmp_ctx, "%s/domain_realm_%s",
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose tmp_file = talloc_asprintf(tmp_ctx, "%sXXXXXX", mapping_file);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("creating the temp file [%s] for domain-realm "
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("fdopen failed [%d]: %s\n",
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ("fclose failed [%d][%s].\n", ret, strerror(ret)));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose /* Nothing to do here, just report the failure */
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose for (i = 0; i < num_subdoms; i++) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE, ("fprintf failed\n"));
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ("fclose failed [%d][%s].\n", ret, strerror(ret)));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ("rename failed [%d][%s].\n", ret, strerror(ret)));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ("fchmod failed [%d][%s].\n", ret, strerror(ret)));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ("fclose failed [%d][%s].\n", err, strerror(err)));
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny /* Nothing to do here, just report the failure */
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ("Could not remove file [%s]: [%d]: %s",
81165faf5d951aca69f410713730c26ff048ec44Sumit Bosestatic errno_t ipa_subdomains_refresh(struct ipa_subdomains_ctx *ctx,
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose const char *value;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose /* check existing subdoms in cache */
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose for (c = 0; c < count; c++) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = sysdb_attrs_get_string(reply[c], IPA_CN, &value);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose /* ok this subdomain does not exist anymore, let's clean up */
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose /* ok let's try to update it */
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = ipa_subdom_parse(ctx->subdoms, reply[c], &ctx->subdoms[i]);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("Failed to parse subdom data\n"));
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose /* all domains were already accounted for and have been updated */
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose /* if we get here it means we have changes to the subdomains list */
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose /* add space for unhandled domains */
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose for (c = 0; c < count; c++) {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose memset(&ctx->subdoms[i], 0, sizeof(struct sysdb_subdom));
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = ipa_subdom_parse(ctx->subdoms, reply[c], &ctx->subdoms[i]);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("Failed to parse subdom data\n"));
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zelenystatic void ipa_subdomains_get_conn_done(struct tevent_req *req);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zelenyipa_subdomains_handler_get(struct ipa_subdomains_req_ctx *ctx,
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zelenystatic void ipa_subdomains_handler_done(struct tevent_req *req);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zelenystatic void ipa_subdomains_handler_master_done(struct tevent_req *req);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zelenystatic void ipa_subdomains_handler_ranges_done(struct tevent_req *req);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zelenystatic struct ipa_subdomains_req_params subdomain_requests[] = {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny { IPA_CN, IPA_FLATNAME, IPA_TRUSTED_DOMAIN_SID, NULL }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny IPA_BASE_ID, IPA_BASE_RID, IPA_SECONDARY_BASE_RID,
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zelenystatic void ipa_subdomains_retrieve(struct ipa_subdomains_ctx *ctx, struct be_req *be_req)
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny req_ctx = talloc(be_req, struct ipa_subdomains_req_ctx);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny DEBUG(SSSDBG_OP_FAILURE, ("sdap_id_op_create failed.\n"));
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny req = sdap_id_op_connect_send(req_ctx->sdap_op, req_ctx, &ret);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny DEBUG(SSSDBG_OP_FAILURE, ("sdap_id_op_connect_send failed: %d(%s).\n",
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny tevent_req_set_callback(req, ipa_subdomains_get_conn_done, req_ctx);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bosestatic void ipa_subdomains_get_conn_done(struct tevent_req *req)
if (ret) {
goto fail;
goto fail;
fail:
static errno_t
return EINVAL;
return EOK;
return ENOMEM;
SDAP_SEARCH_TIMEOUT), false);
return ENOMEM;
return EAGAIN;
int ret;
bool refresh_has_changes = false;
goto done;
if (reply_count) {
goto done;
goto done;
goto done;
if (refresh_has_changes) {
goto done;
goto done;
done:
goto done;
goto done;
goto done;
goto done;
goto done;
done:
const char *tmp_str;
goto done;
if (reply_count) {
goto done;
goto done;
goto done;
goto done;
goto done;
goto done;
goto done;
goto done;
done:
void *pvt)
const char *errstr)
if (!ctx) {
if (ctx) {
bool *configured_explicit)
int ret;
char *tmp_str;
return ENOMEM;
&tmp_str);
goto done;
*configured_explicit = false;
*configured_explicit = true;
done:
return ret;
struct ipa_subdomains_ctx);
if (!ctx) {
void **pvt_data)
int ret;
bool configured_explicit = false;
return ret;
return ENOMEM;
return EOK;