213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny/*
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny SSSD
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny IPA Backend Module -- configuration retrieval
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny Authors:
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny Jan Zeleny <jzeleny@redhat.com>
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny Copyright (C) 2012 Red Hat
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny This program is free software; you can redistribute it and/or modify
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny it under the terms of the GNU General Public License as published by
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny the Free Software Foundation; either version 3 of the License, or
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny (at your option) any later version.
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny This program is distributed in the hope that it will be useful,
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny but WITHOUT ANY WARRANTY; without even the implied warranty of
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny GNU General Public License for more details.
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny You should have received a copy of the GNU General Public License
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny along with this program. If not, see <http://www.gnu.org/licenses/>.
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny*/
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny#include "providers/ipa/ipa_config.h"
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny#include "providers/ipa/ipa_common.h"
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny#include "providers/ldap/sdap_async.h"
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zelenystruct ipa_get_config_state {
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny char *base;
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny const char **attrs;
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny struct sysdb_attrs *config;
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny};
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zelenystatic void ipa_get_config_done(struct tevent_req *subreq);
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zelenystruct tevent_req *
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zelenyipa_get_config_send(TALLOC_CTX *mem_ctx,
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny struct tevent_context *ev,
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny struct sdap_handle *sh,
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny struct sdap_options *opts,
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny const char *domain,
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny const char **attrs)
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny{
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny struct tevent_req *req;
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny struct tevent_req *subreq;
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny struct ipa_get_config_state *state;
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny errno_t ret;
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny char *ldap_basedn;
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny req = tevent_req_create(mem_ctx, &state, struct ipa_get_config_state);
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny if (req == NULL) {
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny return NULL;
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny }
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny if (attrs == NULL) {
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny state->attrs = talloc_zero_array(state, const char *, 4);
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny if (state->attrs == NULL) {
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny ret = ENOMEM;
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny goto done;
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny }
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny state->attrs[0] = IPA_CONFIG_MIGRATION_ENABLED;
fa0dba8f5536537a69d47218f2372d0f2582c12eJakub Hrozek state->attrs[1] = IPA_CONFIG_SELINUX_DEFAULT_USER_CTX;
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny state->attrs[2] = IPA_CONFIG_SELINUX_MAP_ORDER;
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny state->attrs[3] = NULL;
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny } else {
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny state->attrs = attrs;
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny }
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny ret = domain_to_basedn(state, domain, &ldap_basedn);
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "domain_to_basedn failed.\n");
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny goto done;
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny }
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny state->base = talloc_asprintf(state, IPA_CONFIG_SEARCH_BASE_TEMPLATE,
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny ldap_basedn);
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny if (state->base == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "talloc_asprintf failed.\n");
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny ret = ENOMEM;
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny goto done;
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny }
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny subreq = sdap_get_generic_send(state, ev, opts,
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny sh, state->base,
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny LDAP_SCOPE_SUBTREE, IPA_CONFIG_FILTER,
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny state->attrs, NULL, 0,
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny dp_opt_get_int(opts->basic,
2f3ee3f49019f5b60adbe073070f31e6e2d7c7abStephen Gallagher SDAP_ENUM_SEARCH_TIMEOUT),
2f3ee3f49019f5b60adbe073070f31e6e2d7c7abStephen Gallagher false);
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny if (subreq == NULL) {
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny ret = ENOMEM;
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny goto done;
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny }
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny tevent_req_set_callback(subreq, ipa_get_config_done, req);
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny ret = EOK;
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zelenydone:
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny if (ret != EOK) {
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny tevent_req_error(req, ret);
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny tevent_req_post(req, ev);
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny }
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny return req;
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny}
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zelenystatic void ipa_get_config_done(struct tevent_req *subreq)
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny{
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny struct tevent_req *req = tevent_req_callback_data(subreq,
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny struct tevent_req);
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny struct ipa_get_config_state *state = tevent_req_data(req,
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny struct ipa_get_config_state);
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny size_t reply_count;
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny struct sysdb_attrs **reply = NULL;
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny errno_t ret;
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny ret = sdap_get_generic_recv(subreq, state, &reply_count, &reply);
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny talloc_zfree(subreq);
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny if (ret) {
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny goto done;
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny }
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny if (reply_count != 1) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Unexpected number of results, expected 1, "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "got %zu.\n", reply_count);
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny ret = EINVAL;
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny goto done;
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny }
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny state->config = reply[0];
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny ret = EOK;
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zelenydone:
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny if (ret != EOK) {
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny tevent_req_error(req, ret);
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny } else {
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny tevent_req_done(req);
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny }
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny}
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zelenyerrno_t ipa_get_config_recv(struct tevent_req *req,
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny TALLOC_CTX *mem_ctx,
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny struct sysdb_attrs **config)
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny{
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny struct ipa_get_config_state *state = tevent_req_data(req,
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny struct ipa_get_config_state);
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny TEVENT_REQ_RETURN_ON_ERROR(req);
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny *config = talloc_steal(mem_ctx, state->config);
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny return EOK;
213ce2a78b1abe3921d8dc13c949a28130d00aecJan Zeleny}