ipa_subdomains.c revision 3b533d57a737e2de1b3e85b073b14d3bfb49dafc
94968509d2764786208bd34b59a93c7cbe3aa6dbSimon Ulbricht IPA Subdomains Module
94968509d2764786208bd34b59a93c7cbe3aa6dbSimon Ulbricht Sumit Bose <sbose@redhat.com>
94968509d2764786208bd34b59a93c7cbe3aa6dbSimon Ulbricht Copyright (C) 2011 Red Hat
94968509d2764786208bd34b59a93c7cbe3aa6dbSimon Ulbricht This program is free software; you can redistribute it and/or modify
94968509d2764786208bd34b59a93c7cbe3aa6dbSimon Ulbricht it under the terms of the GNU General Public License as published by
94968509d2764786208bd34b59a93c7cbe3aa6dbSimon Ulbricht the Free Software Foundation; either version 3 of the License, or
94968509d2764786208bd34b59a93c7cbe3aa6dbSimon Ulbricht (at your option) any later version.
94968509d2764786208bd34b59a93c7cbe3aa6dbSimon Ulbricht This program is distributed in the hope that it will be useful,
94968509d2764786208bd34b59a93c7cbe3aa6dbSimon Ulbricht but WITHOUT ANY WARRANTY; without even the implied warranty of
94968509d2764786208bd34b59a93c7cbe3aa6dbSimon Ulbricht MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e4d1479434761dc3eb8d17b6c75de4eb24866f0bSimon Ulbricht GNU General Public License for more details.
e4d1479434761dc3eb8d17b6c75de4eb24866f0bSimon Ulbricht You should have received a copy of the GNU General Public License
4bf72807172000becf65e11bd225efc1dfd99713Simon Ulbricht along with this program. If not, see <http://www.gnu.org/licenses/>.
e4d1479434761dc3eb8d17b6c75de4eb24866f0bSimon Ulbricht#define SUBDOMAINS_FILTER "objectclass=ipaNTTrustedDomain"
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht#define MASTER_DOMAIN_FILTER "objectclass=ipaNTDomainAttrs"
94968509d2764786208bd34b59a93c7cbe3aa6dbSimon Ulbricht#define IPA_TRUSTED_DOMAIN_SID "ipaNTTrustedDomainSID"
e4d1479434761dc3eb8d17b6c75de4eb24866f0bSimon Ulbricht#define IPA_SECONDARY_BASE_RID "ipaSecondaryBaseRID"
94968509d2764786208bd34b59a93c7cbe3aa6dbSimon Ulbricht/* do not refresh more often than every 5 seconds for now */
4bf72807172000becf65e11bd225efc1dfd99713Simon Ulbricht/* refresh automatically every 4 hours */
024d83266148fc53f9d6f82bedd0b8cb4a6213a9Simon Ulbricht#define IPA_SUBDOMAIN_REFRESH_PERIOD (3600 * 4)
fe6a19b07759bc4190e88dda76a211d86bf32062Simon Ulbricht struct sdap_search_base **master_search_bases;
fe6a19b07759bc4190e88dda76a211d86bf32062Simon Ulbricht struct sdap_search_base **ranges_search_bases;
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht /* subdomain map cache */
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbrichtstatic void ipa_subdomains_reply(struct be_req *be_req, int dp_err, int result)
4bf72807172000becf65e11bd225efc1dfd99713Simon Ulbrichtstatic errno_t ipa_ranges_parse_results(TALLOC_CTX *mem_ctx,
4bf72807172000becf65e11bd225efc1dfd99713Simon Ulbricht range_list = talloc_array(mem_ctx, struct range_info *, count + 1);
4bf72807172000becf65e11bd225efc1dfd99713Simon Ulbricht DEBUG(SSSDBG_OP_FAILURE, ("talloc_array failed.\n"));
4bf72807172000becf65e11bd225efc1dfd99713Simon Ulbricht for (c = 0; c < count; c++) {
4bf72807172000becf65e11bd225efc1dfd99713Simon Ulbricht range_list[c] = talloc_zero(range_list, struct range_info);
4bf72807172000becf65e11bd225efc1dfd99713Simon Ulbricht DEBUG(SSSDBG_OP_FAILURE, ("talloc_zero failed.\n"));
4bf72807172000becf65e11bd225efc1dfd99713Simon Ulbricht ret = sysdb_attrs_get_string(reply[c], IPA_CN, &value);
4bf72807172000becf65e11bd225efc1dfd99713Simon Ulbricht DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
8600e22385bce13c5d1048f7b955f9394a5d94d6Simon Ulbricht range_list[c]->name = talloc_strdup(range_list[c], value);
5b93337fb97e848522fcc277e384f694595bc42cSimon Ulbricht DEBUG(SSSDBG_OP_FAILURE, ("talloc_strdup failed.\n"));
fe6a19b07759bc4190e88dda76a211d86bf32062Simon Ulbricht ret = sysdb_attrs_get_string(reply[c], IPA_TRUSTED_DOMAIN_SID, &value);
403c7e517cea70c01c7dd15695867fe4f8820ab4Simon Ulbricht range_list[c]->trusted_dom_sid = talloc_strdup(range_list[c],
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht if (range_list[c]->trusted_dom_sid == NULL) {
5b93337fb97e848522fcc277e384f694595bc42cSimon Ulbricht DEBUG(SSSDBG_OP_FAILURE, ("talloc_strdup failed.\n"));
4bf72807172000becf65e11bd225efc1dfd99713Simon Ulbricht DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
e4d1479434761dc3eb8d17b6c75de4eb24866f0bSimon Ulbricht ret = sysdb_attrs_get_uint32_t(reply[c], IPA_BASE_ID,
e4d1479434761dc3eb8d17b6c75de4eb24866f0bSimon Ulbricht DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht ret = sysdb_attrs_get_uint32_t(reply[c], IPA_ID_RANGE_SIZE,
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
fe6a19b07759bc4190e88dda76a211d86bf32062Simon Ulbricht ret = sysdb_attrs_get_uint32_t(reply[c], IPA_BASE_RID,
403c7e517cea70c01c7dd15695867fe4f8820ab4Simon Ulbricht DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
fe6a19b07759bc4190e88dda76a211d86bf32062Simon Ulbricht ret = sysdb_attrs_get_uint32_t(reply[c], IPA_SECONDARY_BASE_RID,
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
804459c3af78eeee3fd3c940c74594febd030dacSimon Ulbrichtstatic char *name_to_realm(TALLOC_CTX *memctx, const char *name)
fe6a19b07759bc4190e88dda76a211d86bf32062Simon Ulbricht for (p = realm; *p; p++) {
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbrichtstatic errno_t ipa_subdom_parse(TALLOC_CTX *memctx,
4d1df661384f74cd15d2ceba8a9a3c4760e9ddfbSimon Ulbricht ret = sysdb_attrs_get_string(attrs, IPA_CN, &value);
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
fe6a19b07759bc4190e88dda76a211d86bf32062Simon Ulbricht } else if (strcmp(subdom->name, value) != 0) {
fe6a19b07759bc4190e88dda76a211d86bf32062Simon Ulbricht DEBUG(SSSDBG_OP_FAILURE, ("subdomain name mismatch!\n"));
55be4caff6a01e4c32ec47ee27fe00b67dfd3db5Simon Ulbricht /* Add Realm as upper(domain name), this is generally always correct
55be4caff6a01e4c32ec47ee27fe00b67dfd3db5Simon Ulbricht * with AD domains */
55be4caff6a01e4c32ec47ee27fe00b67dfd3db5Simon Ulbricht subdom->realm = name_to_realm(memctx, subdom->name);
55be4caff6a01e4c32ec47ee27fe00b67dfd3db5Simon Ulbricht ret = sysdb_attrs_get_string(attrs, IPA_FLATNAME, &value);
5b93337fb97e848522fcc277e384f694595bc42cSimon Ulbricht DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
55be4caff6a01e4c32ec47ee27fe00b67dfd3db5Simon Ulbricht /* in theory this may change, it should never happen, so we will log a
55be4caff6a01e4c32ec47ee27fe00b67dfd3db5Simon Ulbricht * warning if it does, but we will allow it for now */
55be4caff6a01e4c32ec47ee27fe00b67dfd3db5Simon Ulbricht ("Flat name for subdomain changed!\n"));
55be4caff6a01e4c32ec47ee27fe00b67dfd3db5Simon Ulbricht talloc_free(discard_const(subdom->flat_name));
4d1df661384f74cd15d2ceba8a9a3c4760e9ddfbSimon Ulbricht subdom->flat_name = talloc_strdup(memctx, value);
4d1df661384f74cd15d2ceba8a9a3c4760e9ddfbSimon Ulbricht ret = sysdb_attrs_get_string(attrs, IPA_TRUSTED_DOMAIN_SID, &value);
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht /* in theory this may change, it should never happen, so we will log a
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht * warning if it does, but we will allow it for now */
5917663ca76c8f8b60b767f7fb959f1d1609576bSimon Ulbricht ("ID for subdomain changed!\n"));
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbrichtstatic errno_t ipa_subdomains_refresh(struct ipa_subdomains_ctx *ctx,
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht /* check existing subdoms in cache */
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht for (i = 0, h = 0; i < ctx->num_subdoms; i++) {
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht for (c = 0; c < count; c++) {
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht ret = sysdb_attrs_get_string(reply[c], IPA_CN, &value);
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
192498961d079b4a31585f9f63148233804cc1c9Simon Ulbricht if (strcmp(value, ctx->subdoms[i].name) == 0) {
3c606bbc21a488c9eaebbfcd833b0b31af25341aSimon Ulbricht /* ok this subdomain does not exist anymore, let's clean up */
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht /* ok let's try to update it */
e4d1479434761dc3eb8d17b6c75de4eb24866f0bSimon Ulbricht ret = ipa_subdom_parse(ctx->subdoms, reply[c], &ctx->subdoms[i]);
e4d1479434761dc3eb8d17b6c75de4eb24866f0bSimon Ulbricht DEBUG(SSSDBG_OP_FAILURE, ("Failed to parse subdom data\n"));
e3d7fd1b63d824960b1c17b6c7009d52d7528c1eChristian Maeder /* all domains were already accounted for and have been updated */
da4b55f4795a4b585f513eaceb67cda10485febfChristian Maeder /* if we get here it means we have changes to the subdomains list */
e4d1479434761dc3eb8d17b6c75de4eb24866f0bSimon Ulbricht /* add space for unhandled domains */
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht ctx->subdoms = talloc_realloc(ctx, ctx->subdoms,
fe6a19b07759bc4190e88dda76a211d86bf32062Simon Ulbricht for (c = 0; c < count; c++) {
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht memset(&ctx->subdoms[i], 0, sizeof(struct sysdb_subdom));
765f0ff34c8f2354a4e8a4fbb4467ec5e788c55fSimon Ulbricht ret = ipa_subdom_parse(ctx->subdoms, reply[c], &ctx->subdoms[i]);
fe6a19b07759bc4190e88dda76a211d86bf32062Simon Ulbricht DEBUG(SSSDBG_OP_FAILURE, ("Failed to parse subdom data\n"));
7577ca4229962db6f297853d160c2e0214bd2034Simon Ulbrichtstatic void ipa_subdomains_get_conn_done(struct tevent_req *req);
7577ca4229962db6f297853d160c2e0214bd2034Simon Ulbrichtipa_subdomains_handler_get(struct ipa_subdomains_req_ctx *ctx,
7577ca4229962db6f297853d160c2e0214bd2034Simon Ulbrichtstatic void ipa_subdomains_handler_done(struct tevent_req *req);
e4d1479434761dc3eb8d17b6c75de4eb24866f0bSimon Ulbrichtstatic void ipa_subdomains_handler_master_done(struct tevent_req *req);
da4b55f4795a4b585f513eaceb67cda10485febfChristian Maederstatic void ipa_subdomains_handler_ranges_done(struct tevent_req *req);
7577ca4229962db6f297853d160c2e0214bd2034Simon Ulbrichtstatic struct ipa_subdomains_req_params subdomain_requests[] = {
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht { IPA_CN, IPA_FLATNAME, IPA_TRUSTED_DOMAIN_SID, NULL }
9458e270eb4d18c8e76fdaa569023931ca7ca8dfSimon Ulbricht IPA_BASE_ID, IPA_BASE_RID, IPA_SECONDARY_BASE_RID,
689c36560d1509e6f040c096b719a31b31d2d84cSimon Ulbricht IPA_ID_RANGE_SIZE, IPA_TRUSTED_DOMAIN_SID, NULL
int ret;
goto done;
goto done;
goto done;
done:
int ret;
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)
if (!ctx) {
if (ctx) {
struct ipa_subdomains_ctx);
if (!ctx) {
void **pvt_data)
int ret;
return ENOMEM;
return EOK;