ipa_subdomains.c revision a56156c13c71a96166b0a8f3921e67f36470f8d7
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/>.
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose#define SUBDOMAINS_FILTER "objectclass=ipaNTTrustedDomain"
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny#define MASTER_DOMAIN_FILTER "objectclass=ipaNTDomainAttrs"
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose#define IPA_TRUSTED_DOMAIN_SID "ipaNTTrustedDomainSID"
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose#define IPA_SECONDARY_BASE_RID "ipaSecondaryBaseRID"
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny const char *filter;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bosestatic void ipa_subdomains_reply(struct be_req *be_req, int dp_err, int result)
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"));
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = sysdb_attrs_get_uint32_t(reply[c], IPA_BASE_ID,
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = sysdb_attrs_get_uint32_t(reply[c], IPA_ID_RANGE_SIZE,
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = sysdb_attrs_get_uint32_t(reply[c], IPA_BASE_RID,
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = sysdb_attrs_get_uint32_t(reply[c], IPA_SECONDARY_BASE_RID,
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose const char *value;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose new_domain_list = talloc_array(sd_data, struct subdomain_info *, count + 1);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("talloc_array failed.\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose for (c = 0; c < count; c++) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose new_domain_list[c] = talloc_zero(new_domain_list,
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("talloc_zero failed.\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = sysdb_attrs_get_string(reply[c], IPA_CN, &value);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose new_domain_list[c]->name = talloc_strdup(new_domain_list[c], value);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("talloc_strdup failed.\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = sysdb_attrs_get_string(reply[c], IPA_FLATNAME, &value);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose new_domain_list[c]->flat_name = talloc_strdup(new_domain_list[c],
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("talloc_strdup failed.\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = sysdb_attrs_get_string(reply[c], IPA_TRUSTED_DOMAIN_SID, &value);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose new_domain_list[c]->id = talloc_strdup(new_domain_list[c], value);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("talloc_strdup failed.\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bosestatic void ipa_subdomains_get_conn_done(struct tevent_req *req);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zelenyipa_subdomains_handler_get(struct ipa_subdomains_req_ctx *ctx,
81165faf5d951aca69f410713730c26ff048ec44Sumit Bosestatic void ipa_subdomains_handler_done(struct tevent_req *req);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zelenystatic void ipa_subdomains_handler_master_done(struct tevent_req *req);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bosestatic void ipa_subdomains_handler_ranges_done(struct tevent_req *req);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zelenystatic struct ipa_subdomains_req_params subdomain_requests[] = {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose { MASTER_DOMAIN_FILTER, ipa_subdomains_handler_master_done,
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose { SUBDOMAINS_FILTER, ipa_subdomains_handler_done,
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose {IPA_CN, IPA_FLATNAME, IPA_TRUSTED_DOMAIN_SID, NULL }},
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose { RANGE_FILTER, ipa_subdomains_handler_ranges_done,
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose {OBJECTCLASS, IPA_CN, IPA_BASE_ID, IPA_ID_RANGE_SIZE, IPA_BASE_RID,
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose IPA_SECONDARY_BASE_RID, IPA_TRUSTED_DOMAIN_SID, NULL }}
81165faf5d951aca69f410713730c26ff048ec44Sumit Bosevoid ipa_subdomains_handler(struct be_req *be_req)
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ctx = talloc(be_req, struct ipa_subdomains_req_ctx);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose be_req->be_ctx->bet_info[BET_SUBDOMAINS].pvt_bet_data,
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sdap_id_op_create failed.\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose req = sdap_id_op_connect_send(ctx->sdap_op, ctx, &ret);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sdap_id_op_connect_send failed: %d(%s).\n",
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose tevent_req_set_callback(req, ipa_subdomains_get_conn_done, ctx);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bosestatic void ipa_subdomains_get_conn_done(struct tevent_req *req)
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose struct ipa_subdomains_req_ctx *ctx = tevent_req_callback_data(req,
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ("No IPA server is available, cannot get the "
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose "subdomain list while offline\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose/* FIXME: return saved results ?? */
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ("Failed to connect to IPA server: [%d](%s)\n",
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = ipa_subdomains_handler_get(ctx, IPA_SUBDOMAINS_SLAVE);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zelenyipa_subdomains_handler_get(struct ipa_subdomains_req_ctx *ctx,
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ctx->current_filter = sdap_get_id_specific_filter(ctx, params->filter, base->filter);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose req = sdap_get_generic_send(ctx, ctx->be_req->be_ctx->ev,
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose dp_opt_get_int(ctx->sd_ctx->sdap_id_ctx->opts->basic,
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sdap_get_generic_send failed.\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bosestatic void ipa_subdomains_handler_done(struct tevent_req *req)
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose struct ipa_subdomains_req_ctx *ctx = tevent_req_callback_data(req,
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny sysdb = (be_req->sysdb)?be_req->sysdb:be_req->be_ctx->sysdb;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = sdap_get_generic_recv(req, ctx, &reply_count, &reply);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sdap_get_generic_send request failed.\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ctx->reply = talloc_realloc(ctx, ctx->reply, struct sysdb_attrs *,
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = ipa_subdomains_handler_get(ctx, IPA_SUBDOMAINS_SLAVE);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = ipa_subdomains_parse_results(ctx->sd_data, ctx->reply_count, ctx->reply);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("ipa_subdomains_parse_results request failed.\n"));
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = sysdb_update_subdomains(sysdb, ctx->sd_data->domain_list);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sysdb_update_subdomains failed.\n"));
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ctx->search_bases = ctx->sd_ctx->ranges_search_bases;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = ipa_subdomains_handler_get(ctx, IPA_SUBDOMAINS_RANGES);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("No search base for ranges available.\n"));
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bosestatic void ipa_subdomains_handler_ranges_done(struct tevent_req *req)
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose struct ipa_subdomains_req_ctx *ctx = tevent_req_callback_data(req,
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose sysdb = (be_req->sysdb)?be_req->sysdb:be_req->be_ctx->sysdb;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = sdap_get_generic_recv(req, ctx, &reply_count, &reply);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sdap_get_generic_send request failed.\n"));
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = ipa_ranges_parse_results(ctx, reply_count, reply, &range_list);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("ipa_ranges_parse_results request failed.\n"));
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sysdb_update_ranges failed.\n"));
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = sysdb_master_domain_get_info(ctx, sysdb, &domain_info);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ctx->search_bases = ctx->sd_ctx->master_search_bases;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = ipa_subdomains_handler_get(ctx, IPA_SUBDOMAINS_MASTER);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ipa_subdomains_reply(be_req, (ret == EOK ? DP_ERR_OK : DP_ERR_FATAL), ret);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zelenystatic void ipa_subdomains_handler_master_done(struct tevent_req *req)
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny struct ipa_subdomains_req_ctx *ctx = tevent_req_callback_data(req,
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = sdap_get_generic_recv(req, ctx, &reply_count, &reply);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny DEBUG(SSSDBG_OP_FAILURE, ("sdap_get_generic_send request failed.\n"));
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny domain_info = talloc_zero(ctx, struct subdomain_info);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = sysdb_attrs_get_string(reply[0], IPA_FLATNAME, &tmp_str);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny domain_info->flat_name = talloc_strdup(domain_info, tmp_str);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = sysdb_attrs_get_string(reply[0], IPA_SID, &tmp_str);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny domain_info->id = talloc_strdup(domain_info, tmp_str);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = sysdb_master_domain_add_info(be_req->be_ctx->sysdb, domain_info);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = ipa_subdomains_handler_get(ctx, IPA_SUBDOMAINS_MASTER);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny /* Right now we know there has been an error
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny * and we don't have the master domain record
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny DEBUG(SSSDBG_CRIT_FAILURE, ("Master domain record not found!\n"));