ipa_deskprofile_config.c revision f982039c75ec064894deb676ae53ee57de868590
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio/*
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio SSSD
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio Authors:
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio Fabiano Fidêncio <fidencio@redhat.com>
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio Copyright (C) 2017 Red Hat
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio This program is free software; you can redistribute it and/or modify
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio it under the terms of the GNU General Public License as published by
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio the Free Software Foundation; either version 3 of the License, or
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio (at your option) any later version.
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio This program is distributed in the hope that it will be useful,
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio but WITHOUT ANY WARRANTY; without even the implied warranty of
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio GNU General Public License for more details.
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio You should have received a copy of the GNU General Public License
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio along with this program. If not, see <http://www.gnu.org/licenses/>.
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio*/
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio#include "util/util.h"
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio#include "providers/ipa/ipa_common.h"
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio#include "providers/ipa/ipa_deskprofile_private.h"
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio#include "providers/ipa/ipa_deskprofile_config.h"
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio#include "providers/ldap/sdap_async.h"
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidênciostruct ipa_deskprofile_config_state {
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio struct sysdb_attrs *config;
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio};
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidênciostatic void
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncioipa_deskprofile_get_config_done(struct tevent_req *subreq);
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidênciostruct tevent_req *
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncioipa_deskprofile_get_config_send(TALLOC_CTX *mem_ctx,
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio struct tevent_context *ev,
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio struct sdap_handle *sh,
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio struct sdap_options *opts,
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio struct dp_option *ipa_opts)
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio{
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio struct tevent_req *req = NULL;
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio struct tevent_req *subreq;
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio struct ipa_deskprofile_rule_state *state;
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio char *rule_filter;
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio const char *attrs[] = { IPA_DESKPROFILE_PRIORITY, NULL };
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio errno_t ret;
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio req = tevent_req_create(mem_ctx, &state,
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio struct ipa_deskprofile_config_state);
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio if (req == NULL) {
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio DEBUG(SSSDBG_CRIT_FAILURE, "tevent_req_create() failed.\n");
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio return NULL;
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio }
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio rule_filter = talloc_asprintf(state, "(objectclass=%s)",
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio IPA_DESKPROFILE_CONFIG);
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio if (rule_filter == NULL) {
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio ret = ENOMEM;
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio goto done;
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio }
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio subreq = sdap_get_generic_send(state, ev, opts, sh,
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio dp_opt_get_string(ipa_opts,
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio IPA_DESKPROFILE_SEARCH_BASE),
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio LDAP_SCOPE_BASE, rule_filter,
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio attrs, NULL, 0,
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio dp_opt_get_int(opts->basic,
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio SDAP_ENUM_SEARCH_TIMEOUT),
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio false);
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio if (subreq == NULL) {
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio ret = ENOMEM;
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio DEBUG(SSSDBG_CRIT_FAILURE, "sdap_get_generic_send failed.\n");
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio goto done;
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio }
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio tevent_req_set_callback(subreq, ipa_deskprofile_get_config_done, req);
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio ret = EOK;
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidênciodone:
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio if (ret != EOK) {
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio tevent_req_error(req, ret);
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio tevent_req_post(req, ev);
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio }
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio return req;
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio}
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidênciostatic void
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncioipa_deskprofile_get_config_done(struct tevent_req *subreq)
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio{
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio struct tevent_req *req;
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio struct ipa_deskprofile_config_state *state;
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio size_t reply_count;
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio struct sysdb_attrs **reply = NULL;
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio errno_t ret;
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio req = tevent_req_callback_data(subreq, struct tevent_req);
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio state = tevent_req_data(req, struct ipa_deskprofile_config_state);
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio ret = sdap_get_generic_recv(subreq, state, &reply_count, &reply);
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio if (ret != EOK) {
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio DEBUG(SSSDBG_MINOR_FAILURE,
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio "Could not retrieve Desktop Profile config\n");
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio goto done;
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio }
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio if (reply_count == 0) {
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio /*
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio * When connecting to an old server that doesn't support Desktop
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio * Profile, the reply_count will be zero.
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio * In order to not throw a unnecessary error and fail let's just
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio * return ENOENT and print a debug message about it.
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio */
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio DEBUG(SSSDBG_MINOR_FAILURE,
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio "Server doesn't support Desktop Profile.\n");
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio ret = ENOENT;
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio goto done;
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio } else if (reply_count != 1) {
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio DEBUG(SSSDBG_OP_FAILURE,
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio "Unexpected number of results, expected 1, got %zu.\n",
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio reply_count);
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio ret = EINVAL;
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio goto done;
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio }
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio state->config = reply[0];
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio ret = EOK;
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidênciodone:
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio if (ret != EOK) {
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio tevent_req_error(req, ret);
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio return;
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio }
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio tevent_req_done(req);
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio}
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncioerrno_t
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncioipa_deskprofile_get_config_recv(struct tevent_req *req,
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio TALLOC_CTX *mem_ctx,
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio struct sysdb_attrs **config)
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio{
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio struct ipa_deskprofile_config_state *state;
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio state = tevent_req_data(req, struct ipa_deskprofile_config_state);
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio TEVENT_REQ_RETURN_ON_ERROR(req);
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio *config = talloc_steal(mem_ctx, state->config);
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio return EOK;
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio}