c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny/*
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny Authors:
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny Jan Zeleny <jzeleny@redhat.com>
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny Copyright (C) 2011 Red Hat
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny This program is free software; you can redistribute it and/or modify
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny it under the terms of the GNU General Public License as published by
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny the Free Software Foundation; either version 3 of the License, or
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny (at your option) any later version.
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny This program is distributed in the hope that it will be useful,
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny but WITHOUT ANY WARRANTY; without even the implied warranty of
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny GNU General Public License for more details.
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny You should have received a copy of the GNU General Public License
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny along with this program. If not, see <http://www.gnu.org/licenses/>.
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny*/
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny#include "util/util.h"
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny#include "responder/common/responder.h"
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny#include "providers/data_provider.h"
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny#include "db/sysdb.h"
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek/* ========== Get subdomains for a domain ================= */
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozekstatic DBusMessage *sss_dp_get_domains_msg(void *pvt);
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zelenystruct sss_dp_domains_info {
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny struct sss_domain_info *dom;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny const char *hint;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny};
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozekstatic struct tevent_req *
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozekget_subdomains_send(TALLOC_CTX *mem_ctx, struct resp_ctx *rctx,
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek struct sss_domain_info *dom,
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek const char *hint)
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny{
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny errno_t ret;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny struct tevent_req *req;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek struct sss_dp_req_state *state;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny struct sss_dp_domains_info *info;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek char *key;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek req = tevent_req_create(mem_ctx, &state, struct sss_dp_req_state);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny if (req == NULL) {
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek return NULL;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny }
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek info = talloc_zero(state, struct sss_dp_domains_info);
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek if (!info) {
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek ret = ENOMEM;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek goto fail;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny }
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek info->hint = hint;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek info->dom = dom;
bdbf4f169e4d5d00b0616df19f7a55debb407f78Pavel Březina
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek key = talloc_asprintf(state, "domains@%s", dom->name);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny if (key == NULL) {
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek ret = ENOMEM;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek goto fail;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny }
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek ret = sss_dp_issue_request(state, rctx, key, dom,
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek sss_dp_get_domains_msg, info, req);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny talloc_free(key);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny if (ret != EOK) {
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek ret = EIO;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek goto fail;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny }
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek return req;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozekfail:
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek tevent_req_error(req, ret);
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek tevent_req_post(req, rctx->ev);
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek return req;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny}
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zelenystatic DBusMessage *
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zelenysss_dp_get_domains_msg(void *pvt)
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny{
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny struct sss_dp_domains_info *info;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny DBusMessage *msg = NULL;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny dbus_bool_t dbret;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny info = talloc_get_type(pvt, struct sss_dp_domains_info);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny msg = dbus_message_new_method_call(NULL,
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny DP_PATH,
04e870d99e72aa3160bdb6ab05d986fb4005c3edPavel Březina IFACE_DP,
04e870d99e72aa3160bdb6ab05d986fb4005c3edPavel Březina IFACE_DP_GETDOMAINS);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny if (msg == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Out of memory?!\n");
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny return NULL;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny }
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny DEBUG(SSSDBG_TRACE_FUNC,
ef2455b63380ecd17bea94270ceaabe15dcf6456Jakub Hrozek "Sending get domains request for [%s][%s]\n",
ef2455b63380ecd17bea94270ceaabe15dcf6456Jakub Hrozek info->dom->name, info->hint);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny /* Send the hint argument to provider as well. This will
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * be useful for some cases of transitional trust where
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * the server might not know all trusted domains
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny */
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny dbret = dbus_message_append_args(msg,
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny DBUS_TYPE_STRING, &info->hint,
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny DBUS_TYPE_INVALID);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny if (!dbret) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE ,"Failed to build message\n");
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny dbus_message_unref(msg);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny return NULL;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny }
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny return msg;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny}
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozekstatic errno_t
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozekget_next_domain_recv(TALLOC_CTX *mem_ctx,
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek struct tevent_req *req,
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek dbus_uint16_t *dp_err,
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek dbus_uint32_t *dp_ret,
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek char **err_msg)
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek{
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek return sss_dp_req_recv(mem_ctx, req, dp_err, dp_ret, err_msg);
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek}
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek/* ====== Iterate over all domains, searching for their subdomains ======= */
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židekstatic errno_t process_subdomains(struct sss_domain_info *dom,
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek struct confdb_ctx *confdb);
99bac83188601c2b07e0b141aac7dc7d882b464aSumit Bosestatic void set_time_of_last_request(struct resp_ctx *rctx);
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozekstatic errno_t check_last_request(struct resp_ctx *rctx, const char *hint);
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozekstruct sss_dp_get_domains_state {
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek struct resp_ctx *rctx;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek struct sss_domain_info *dom;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek const char *hint;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek};
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozekstatic void
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozeksss_dp_get_domains_process(struct tevent_req *subreq);
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozekstruct tevent_req *sss_dp_get_domains_send(TALLOC_CTX *mem_ctx,
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek struct resp_ctx *rctx,
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek bool force,
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek const char *hint)
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny{
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny errno_t ret;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek struct tevent_req *req;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek struct tevent_req *subreq;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek struct sss_dp_get_domains_state *state;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek req = tevent_req_create(mem_ctx, &state, struct sss_dp_get_domains_state);
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek if (req == NULL) {
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek return NULL;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek }
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek if (rctx->domains == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "No domains configured.\n");
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek ret = EINVAL;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek goto immediately;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek }
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek if (!force) {
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek ret = check_last_request(rctx, hint);
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek if (ret == EOK) {
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek DEBUG(SSSDBG_TRACE_FUNC,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Last call was too recent, nothing to do!\n");
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek goto immediately;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek } else if (ret != EAGAIN) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "check_domain_request failed with [%d][%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek goto immediately;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek }
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek }
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek state->rctx = rctx;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek if (hint != NULL) {
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek state->hint = hint;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek } else {
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek state->hint = talloc_strdup(state, "");
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek if (state->hint == NULL) {
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek ret = ENOMEM;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek goto immediately;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek }
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek }
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek state->dom = rctx->domains;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek while(state->dom != NULL && !NEED_CHECK_PROVIDER(state->dom->provider)) {
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek state->dom = get_next_domain(state->dom, 0);
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek }
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek if (state->dom == NULL) {
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek /* All domains were local */
66c8e92eb5a4985bb7f64c349a53b08030a000cfFabiano Fidêncio ret = sss_resp_populate_cr_domains(state->rctx);
66c8e92eb5a4985bb7f64c349a53b08030a000cfFabiano Fidêncio if (ret != EOK) {
66c8e92eb5a4985bb7f64c349a53b08030a000cfFabiano Fidêncio DEBUG(SSSDBG_CRIT_FAILURE,
66c8e92eb5a4985bb7f64c349a53b08030a000cfFabiano Fidêncio "sss_resp_populate_cr_domains() failed [%d]: [%s]\n",
66c8e92eb5a4985bb7f64c349a53b08030a000cfFabiano Fidêncio ret, sss_strerror(ret));
66c8e92eb5a4985bb7f64c349a53b08030a000cfFabiano Fidêncio goto immediately;
66c8e92eb5a4985bb7f64c349a53b08030a000cfFabiano Fidêncio }
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek ret = EOK;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek goto immediately;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek }
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
ef2455b63380ecd17bea94270ceaabe15dcf6456Jakub Hrozek subreq = get_subdomains_send(req, rctx, state->dom, state->hint);
b6d5f2a91fbce15c7ef4d382fa6b52407adb26ddPavel Březina if (subreq == NULL) {
b6d5f2a91fbce15c7ef4d382fa6b52407adb26ddPavel Březina ret = ENOMEM;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek goto immediately;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek }
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek tevent_req_set_callback(subreq, sss_dp_get_domains_process, req);
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek return req;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozekimmediately:
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek if (ret == EOK) {
99bac83188601c2b07e0b141aac7dc7d882b464aSumit Bose set_time_of_last_request(rctx);
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek tevent_req_done(req);
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek } else {
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek tevent_req_error(req, ret);
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek }
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek tevent_req_post(req, rctx->ev);
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek return req;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek}
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
749963195393efa3a4f9b168dd02fbcc68976ba3Sumit Bosestatic void sss_resp_update_certmaps(struct resp_ctx *rctx)
749963195393efa3a4f9b168dd02fbcc68976ba3Sumit Bose{
749963195393efa3a4f9b168dd02fbcc68976ba3Sumit Bose int ret;
749963195393efa3a4f9b168dd02fbcc68976ba3Sumit Bose struct certmap_info **certmaps;
749963195393efa3a4f9b168dd02fbcc68976ba3Sumit Bose bool user_name_hint;
749963195393efa3a4f9b168dd02fbcc68976ba3Sumit Bose struct sss_domain_info *dom;
749963195393efa3a4f9b168dd02fbcc68976ba3Sumit Bose
749963195393efa3a4f9b168dd02fbcc68976ba3Sumit Bose for (dom = rctx->domains; dom != NULL; dom = dom->next) {
749963195393efa3a4f9b168dd02fbcc68976ba3Sumit Bose ret = sysdb_get_certmap(dom, dom->sysdb, &certmaps, &user_name_hint);
749963195393efa3a4f9b168dd02fbcc68976ba3Sumit Bose if (ret == EOK) {
749963195393efa3a4f9b168dd02fbcc68976ba3Sumit Bose dom->user_name_hint = user_name_hint;
749963195393efa3a4f9b168dd02fbcc68976ba3Sumit Bose talloc_free(dom->certmaps);
749963195393efa3a4f9b168dd02fbcc68976ba3Sumit Bose dom->certmaps = certmaps;
749963195393efa3a4f9b168dd02fbcc68976ba3Sumit Bose } else {
749963195393efa3a4f9b168dd02fbcc68976ba3Sumit Bose DEBUG(SSSDBG_OP_FAILURE,
749963195393efa3a4f9b168dd02fbcc68976ba3Sumit Bose "sysdb_get_certmap failed for domain [%s].\n", dom->name);
749963195393efa3a4f9b168dd02fbcc68976ba3Sumit Bose }
749963195393efa3a4f9b168dd02fbcc68976ba3Sumit Bose }
749963195393efa3a4f9b168dd02fbcc68976ba3Sumit Bose}
749963195393efa3a4f9b168dd02fbcc68976ba3Sumit Bose
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozekstatic void
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozeksss_dp_get_domains_process(struct tevent_req *subreq)
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek{
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek errno_t ret;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek struct tevent_req);
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek struct sss_dp_get_domains_state *state = tevent_req_data(req,
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek struct sss_dp_get_domains_state);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny dbus_uint16_t dp_err;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny dbus_uint32_t dp_ret;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny char *err_msg;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek ret = get_next_domain_recv(req, subreq, &dp_err, &dp_ret, &err_msg);
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek talloc_zfree(subreq);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny if (ret != EOK) {
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny goto fail;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny }
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek ret = process_subdomains(state->dom, state->rctx->cdb);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "process_subdomains failed, "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "trying next domain.\n");
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny goto fail;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny }
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek /* Advance to the next domain */
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek state->dom = get_next_domain(state->dom, 0);
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek /* Skip local domains */
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek while(state->dom != NULL && !NEED_CHECK_PROVIDER(state->dom->provider)) {
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek state->dom = get_next_domain(state->dom, 0);
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek }
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek if (state->dom == NULL) {
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek /* All domains were local */
99bac83188601c2b07e0b141aac7dc7d882b464aSumit Bose set_time_of_last_request(state->rctx);
66c8e92eb5a4985bb7f64c349a53b08030a000cfFabiano Fidêncio ret = sss_resp_populate_cr_domains(state->rctx);
66c8e92eb5a4985bb7f64c349a53b08030a000cfFabiano Fidêncio if (ret != EOK) {
66c8e92eb5a4985bb7f64c349a53b08030a000cfFabiano Fidêncio DEBUG(SSSDBG_CRIT_FAILURE,
66c8e92eb5a4985bb7f64c349a53b08030a000cfFabiano Fidêncio "sss_resp_populate_cr_domains() failed [%d]: [%s]\n",
66c8e92eb5a4985bb7f64c349a53b08030a000cfFabiano Fidêncio ret, sss_strerror(ret));
66c8e92eb5a4985bb7f64c349a53b08030a000cfFabiano Fidêncio goto fail;
66c8e92eb5a4985bb7f64c349a53b08030a000cfFabiano Fidêncio }
749963195393efa3a4f9b168dd02fbcc68976ba3Sumit Bose
749963195393efa3a4f9b168dd02fbcc68976ba3Sumit Bose sss_resp_update_certmaps(state->rctx);
749963195393efa3a4f9b168dd02fbcc68976ba3Sumit Bose
bdbf4f169e4d5d00b0616df19f7a55debb407f78Pavel Březina tevent_req_done(req);
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek return;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny }
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
ef2455b63380ecd17bea94270ceaabe15dcf6456Jakub Hrozek subreq = get_subdomains_send(req, state->rctx, state->dom, state->hint);
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek if (subreq == NULL) {
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek ret = ENOMEM;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek goto fail;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek }
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek tevent_req_set_callback(subreq, sss_dp_get_domains_process, req);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny return;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zelenyfail:
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny tevent_req_error(req, ret);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny return;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny}
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozekstatic errno_t
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židekprocess_subdomains(struct sss_domain_info *domain, struct confdb_ctx *confdb)
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny{
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny int ret;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce if (domain->realm == NULL ||
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce domain->flat_name == NULL ||
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce domain->domain_id == NULL) {
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce ret = sysdb_master_domain_update(domain);
aac3ca699a09090072ae4d68bdda8dec990ae393Sumit Bose if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_FUNC_DATA, "sysdb_master_domain_get_info " \
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "failed.\n");
aac3ca699a09090072ae4d68bdda8dec990ae393Sumit Bose goto done;
aac3ca699a09090072ae4d68bdda8dec990ae393Sumit Bose }
aac3ca699a09090072ae4d68bdda8dec990ae393Sumit Bose }
aac3ca699a09090072ae4d68bdda8dec990ae393Sumit Bose
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce /* Retrieve all subdomains of this domain from sysdb
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce * and create their struct sss_domain_info representations
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce */
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek ret = sysdb_update_subdomains(domain, confdb);
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_FUNC_DATA, "sysdb_update_subdomains failed.\n");
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce goto done;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce }
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny errno = 0;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny ret = gettimeofday(&domain->subdomains_last_checked, NULL);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny if (ret == -1) {
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny ret = errno;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny goto done;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny }
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny ret = EOK;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zelenydone:
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Failed to update sub-domains "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "of domain [%s].\n", domain->name);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny }
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny return ret;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny}
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zelenyerrno_t sss_dp_get_domains_recv(struct tevent_req *req)
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny{
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny TEVENT_REQ_RETURN_ON_ERROR(req);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny return EOK;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny}
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
99bac83188601c2b07e0b141aac7dc7d882b464aSumit Bosestatic void set_time_of_last_request(struct resp_ctx *rctx)
99bac83188601c2b07e0b141aac7dc7d882b464aSumit Bose{
99bac83188601c2b07e0b141aac7dc7d882b464aSumit Bose int ret;
99bac83188601c2b07e0b141aac7dc7d882b464aSumit Bose
99bac83188601c2b07e0b141aac7dc7d882b464aSumit Bose errno = 0;
99bac83188601c2b07e0b141aac7dc7d882b464aSumit Bose ret = gettimeofday(&rctx->get_domains_last_call, NULL);
99bac83188601c2b07e0b141aac7dc7d882b464aSumit Bose if (ret == -1) {
99bac83188601c2b07e0b141aac7dc7d882b464aSumit Bose ret = errno;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "gettimeofday failed [%d][%s].\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
99bac83188601c2b07e0b141aac7dc7d882b464aSumit Bose }
99bac83188601c2b07e0b141aac7dc7d882b464aSumit Bose}
99bac83188601c2b07e0b141aac7dc7d882b464aSumit Bose
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zelenystatic errno_t check_last_request(struct resp_ctx *rctx, const char *hint)
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny{
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny struct sss_domain_info *dom;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny time_t now = time(NULL);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny time_t diff;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce diff = now - rctx->get_domains_last_call.tv_sec;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny if (diff >= rctx->domains_timeout) {
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny /* Timeout, expired, fetch domains again */
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny return EAGAIN;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny }
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny if (hint != NULL) {
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek for (dom = rctx->domains; dom;
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek dom = get_next_domain(dom, SSS_GND_DESCEND)) {
4f118e3e6a25762f40a43e6dbefb09f44adbef32Simo Sorce if (!IS_SUBDOMAIN(dom)) {
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce diff = now - dom->subdomains_last_checked.tv_sec;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce /* not a subdomain */
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce continue;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce }
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce if (strcasecmp(dom->name, hint) == 0) {
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce if (diff >= rctx->domains_timeout) {
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce /* Timeout, expired, fetch domains again */
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce return EAGAIN;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny }
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny }
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny }
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny }
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny return EOK;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny}
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozekstruct get_domains_state {
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek struct resp_ctx *rctx;
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek struct sss_nc_ctx *optional_ncache;
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek};
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bosestatic void get_domains_at_startup_done(struct tevent_req *req)
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose{
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose int ret;
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek struct get_domains_state *state;
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek state = tevent_req_callback_data(req, struct get_domains_state);
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose ret = sss_dp_get_domains_recv(req);
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose talloc_free(req);
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose if (ret != EOK) {
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE, "sss_dp_get_domains request failed.\n");
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose }
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek if (state->optional_ncache != NULL) {
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek ret = sss_ncache_reset_repopulate_permanent(state->rctx,
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek state->optional_ncache);
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek if (ret != EOK) {
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE, "sss_dp_get_domains request failed.\n");
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek }
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek }
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek
0c5b97812f20b57b93c10496fed34ea221fbcca8Sumit Bose if (!NEED_CHECK_PROVIDER(state->rctx->domains->provider)) {
0c5b97812f20b57b93c10496fed34ea221fbcca8Sumit Bose ret = sysdb_master_domain_update(state->rctx->domains);
0c5b97812f20b57b93c10496fed34ea221fbcca8Sumit Bose if (ret != EOK) {
0c5b97812f20b57b93c10496fed34ea221fbcca8Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_master_domain_update failed, "
0c5b97812f20b57b93c10496fed34ea221fbcca8Sumit Bose "ignored.\n");
0c5b97812f20b57b93c10496fed34ea221fbcca8Sumit Bose }
0c5b97812f20b57b93c10496fed34ea221fbcca8Sumit Bose }
0c5b97812f20b57b93c10496fed34ea221fbcca8Sumit Bose
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek talloc_free(state);
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose return;
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose}
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bosestatic void get_domains_at_startup(struct tevent_context *ev,
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose struct tevent_immediate *imm,
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose void *pvt)
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose{
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose struct tevent_req *req;
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek struct get_domains_state *state;
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek state = talloc_get_type(pvt, struct get_domains_state);
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek req = sss_dp_get_domains_send(state, state->rctx, true, NULL);
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose if (req == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "sss_dp_get_domains_send failed.\n");
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek talloc_free(state);
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose return;
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose }
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek tevent_req_set_callback(req, get_domains_at_startup_done, state);
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose return;
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose}
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Boseerrno_t schedule_get_domains_task(TALLOC_CTX *mem_ctx,
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose struct tevent_context *ev,
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek struct resp_ctx *rctx,
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek struct sss_nc_ctx *optional_ncache)
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose{
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose struct tevent_immediate *imm;
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek struct get_domains_state *state;
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek state = talloc(mem_ctx, struct get_domains_state);
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek if (state == NULL) {
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek return ENOMEM;
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek }
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek state->rctx = rctx;
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek state->optional_ncache = optional_ncache;
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose imm = tevent_create_immediate(mem_ctx);
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose if (imm == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "tevent_create_immediate failed.\n");
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek talloc_free(state);
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose return ENOMEM;
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose }
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek tevent_schedule_immediate(imm, ev, get_domains_at_startup, state);
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose return EOK;
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose}
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozekstruct sss_parse_inp_state {
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek struct resp_ctx *rctx;
2b5704cd96a085b99d3b0d4f80f4414adc134750Pavel Březina const char *default_domain;
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek const char *rawinp;
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek char *name;
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek char *domname;
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina errno_t error;
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek};
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozekstatic void sss_parse_inp_done(struct tevent_req *subreq);
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozekstruct tevent_req *
2b5704cd96a085b99d3b0d4f80f4414adc134750Pavel Březinasss_parse_inp_send(TALLOC_CTX *mem_ctx,
2b5704cd96a085b99d3b0d4f80f4414adc134750Pavel Březina struct resp_ctx *rctx,
2b5704cd96a085b99d3b0d4f80f4414adc134750Pavel Březina const char *default_domain,
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek const char *rawinp)
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek{
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek errno_t ret;
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek struct tevent_req *req;
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek struct tevent_req *subreq;
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek struct sss_parse_inp_state *state;
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek req = tevent_req_create(mem_ctx, &state, struct sss_parse_inp_state);
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek if (req == NULL) {
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek return NULL;
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek }
2b5704cd96a085b99d3b0d4f80f4414adc134750Pavel Březina
2b5704cd96a085b99d3b0d4f80f4414adc134750Pavel Březina if (rawinp == NULL) {
2b5704cd96a085b99d3b0d4f80f4414adc134750Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Empty input!\n");
2b5704cd96a085b99d3b0d4f80f4414adc134750Pavel Březina ret = EINVAL;
2b5704cd96a085b99d3b0d4f80f4414adc134750Pavel Březina goto done;
2b5704cd96a085b99d3b0d4f80f4414adc134750Pavel Březina }
2b5704cd96a085b99d3b0d4f80f4414adc134750Pavel Březina
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek state->rctx = rctx;
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek
2b5704cd96a085b99d3b0d4f80f4414adc134750Pavel Březina state->rawinp = talloc_strdup(state, rawinp);
2b5704cd96a085b99d3b0d4f80f4414adc134750Pavel Březina if (state->rawinp == NULL) {
2b5704cd96a085b99d3b0d4f80f4414adc134750Pavel Březina ret = ENOMEM;
2b5704cd96a085b99d3b0d4f80f4414adc134750Pavel Březina goto done;
2b5704cd96a085b99d3b0d4f80f4414adc134750Pavel Březina }
2b5704cd96a085b99d3b0d4f80f4414adc134750Pavel Březina
2b5704cd96a085b99d3b0d4f80f4414adc134750Pavel Březina
2b5704cd96a085b99d3b0d4f80f4414adc134750Pavel Březina state->default_domain = talloc_strdup(state, default_domain);
2b5704cd96a085b99d3b0d4f80f4414adc134750Pavel Březina if (default_domain != NULL && state->default_domain == NULL) {
2b5704cd96a085b99d3b0d4f80f4414adc134750Pavel Březina ret = ENOMEM;
2b5704cd96a085b99d3b0d4f80f4414adc134750Pavel Březina goto done;
2b5704cd96a085b99d3b0d4f80f4414adc134750Pavel Březina }
2b5704cd96a085b99d3b0d4f80f4414adc134750Pavel Březina
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek /* If the subdomains haven't been checked yet, we need to always
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek * attach to the post-startup subdomain request and only then parse
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek * the input. Otherwise, we might not be able to parse input with a
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek * flat domain name specifier */
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek if (rctx->get_domains_last_call.tv_sec > 0) {
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek ret = sss_parse_name_for_domains(state, rctx->domains,
2b5704cd96a085b99d3b0d4f80f4414adc134750Pavel Březina default_domain, rawinp,
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek &state->domname, &state->name);
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek if (ret == EOK) {
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek /* Was able to use cached domains */
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek goto done;
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek } else if (ret != EAGAIN) {
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "Invalid name received [%s]\n", rawinp);
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek ret = ERR_INPUT_PARSE;
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek goto done;
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek }
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek }
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek /* EAGAIN - check the DP for subdomains */
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek DEBUG(SSSDBG_FUNC_DATA, "Requesting info for [%s] from [%s]\n",
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek state->name, state->domname ? state->domname : "<ALL>");
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek /* We explicitly use force=false here. This request should decide itself
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek * if it's time to re-use the cached subdomain list or refresh. If the
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek * caller needs to specify the 'force' parameter, they should use the
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek * sss_dp_get_domains_send() request itself
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek */
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek subreq = sss_dp_get_domains_send(state, rctx, false, state->domname);
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek if (subreq == NULL) {
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek ret = ENOMEM;
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek goto done;
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek }
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek tevent_req_set_callback(subreq, sss_parse_inp_done, req);
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek return req;
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozekdone:
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek if (ret == EOK) {
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek tevent_req_done(req);
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek } else {
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek tevent_req_error(req, ret);
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek }
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek tevent_req_post(req, rctx->ev);
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek return req;
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek}
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozekstatic void sss_parse_inp_done(struct tevent_req *subreq)
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek{
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek errno_t ret;
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek struct tevent_req);
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek struct sss_parse_inp_state *state = tevent_req_data(req,
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek struct sss_parse_inp_state);
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek ret = sss_dp_get_domains_recv(subreq);
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek talloc_free(subreq);
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek if (ret != EOK) {
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek tevent_req_error(req, ret);
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek return;
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek }
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina state->error = ERR_OK;
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek ret = sss_parse_name_for_domains(state, state->rctx->domains,
2b5704cd96a085b99d3b0d4f80f4414adc134750Pavel Březina state->default_domain,
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek state->rawinp,
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek &state->domname, &state->name);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina if (ret == EAGAIN && state->domname != NULL && state->name == NULL) {
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina DEBUG(SSSDBG_OP_FAILURE,
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina "Unknown domain in [%s]\n", state->rawinp);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina state->error = ERR_DOMAIN_NOT_FOUND;
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina } else if (ret != EOK) {
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek "Invalid name received [%s]\n", state->rawinp);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina state->error = ERR_INPUT_PARSE;
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina }
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina if (state->error != ERR_OK) {
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina tevent_req_error(req, state->error);
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek return;
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek }
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek /* Was able to parse the name now */
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek tevent_req_done(req);
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek}
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozekerrno_t sss_parse_inp_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek char **_name, char **_domname)
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek{
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek struct sss_parse_inp_state *state = tevent_req_data(req,
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek struct sss_parse_inp_state);
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina if (state->error != ERR_DOMAIN_NOT_FOUND) {
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina TEVENT_REQ_RETURN_ON_ERROR(req);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina }
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek if (_name) {
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek *_name = talloc_steal(mem_ctx, state->name);
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek }
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek if (_domname) {
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek *_domname = talloc_steal(mem_ctx, state->domname);
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek }
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina return state->error;
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek}
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek
677a31351c80453d9ce006481364399a96312052René Genz/* ========== Get domain of an account ================= */
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozekstruct sss_dp_get_account_domain_info {
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek struct sss_domain_info *dom;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek enum sss_dp_acct_type type;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek uint32_t opt_id;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek};
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozekstatic DBusMessage *sss_dp_get_account_domain_msg(void *pvt);
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozekstruct tevent_req *sss_dp_get_account_domain_send(TALLOC_CTX *mem_ctx,
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek struct resp_ctx *rctx,
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek struct sss_domain_info *dom,
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek enum sss_dp_acct_type type,
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek uint32_t opt_id)
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek{
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek struct tevent_req *req;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek struct sss_dp_get_account_domain_info *info;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek struct sss_dp_req_state *state;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek char *key;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek errno_t ret;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek req = tevent_req_create(mem_ctx, &state, struct sss_dp_req_state);
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek if (!req) {
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek return NULL;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek }
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek info = talloc_zero(state, struct sss_dp_get_account_domain_info);
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek if (info == NULL) {
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek ret = ENOMEM;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek goto immediately;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek }
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek info->type = type;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek info->opt_id = opt_id;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek info->dom = dom;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek key = talloc_asprintf(state, "%d: %"SPRIuid"@%s", type, opt_id, dom->name);
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek if (key == NULL) {
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek ret = ENOMEM;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek goto immediately;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek }
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek ret = sss_dp_issue_request(state, rctx, key, dom,
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek sss_dp_get_account_domain_msg,
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek info, req);
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek talloc_free(key);
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek if (ret != EOK) {
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek "Could not issue DP request [%d]: %s\n",
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek ret, sss_strerror(ret));
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek goto immediately;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek }
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek return req;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozekimmediately:
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek if (ret == EOK) {
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek tevent_req_done(req);
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek } else {
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek tevent_req_error(req, ret);
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek }
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek tevent_req_post(req, rctx->ev);
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek return req;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek}
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozekstatic DBusMessage *
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozeksss_dp_get_account_domain_msg(void *pvt)
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek{
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek DBusMessage *msg;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek dbus_bool_t dbret;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek struct sss_dp_get_account_domain_info *info;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek uint32_t entry_type;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek char *filter;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek info = talloc_get_type(pvt, struct sss_dp_get_account_domain_info);
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek switch (info->type) {
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek case SSS_DP_USER:
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek entry_type = BE_REQ_USER;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek break;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek case SSS_DP_GROUP:
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek entry_type = BE_REQ_GROUP;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek break;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek case SSS_DP_USER_AND_GROUP:
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek entry_type = BE_REQ_USER_AND_GROUP;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek break;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek default:
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek "Unsupported lookup type %X for this request\n", info->type);
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek return NULL;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek }
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek filter = talloc_asprintf(info, "idnumber=%u", info->opt_id);
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek if (!filter) {
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "Out of memory?!\n");
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek return NULL;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek }
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek msg = dbus_message_new_method_call(NULL,
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek DP_PATH,
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek IFACE_DP,
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek IFACE_DP_GETACCOUNTDOMAIN);
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek if (msg == NULL) {
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek talloc_free(filter);
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "Out of memory?!\n");
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek return NULL;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek }
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek /* create the message */
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek DEBUG(SSSDBG_TRACE_FUNC,
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek "Creating request for [%s][%#x][%s][%s:-]\n",
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek info->dom->name, entry_type, be_req2str(entry_type), filter);
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek dbret = dbus_message_append_args(msg,
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek DBUS_TYPE_UINT32, &entry_type,
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek DBUS_TYPE_STRING, &filter,
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek DBUS_TYPE_INVALID);
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek talloc_free(filter);
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek if (!dbret) {
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "Failed to build message\n");
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek dbus_message_unref(msg);
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek return NULL;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek }
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek return msg;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek}
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozekerrno_t sss_dp_get_account_domain_recv(TALLOC_CTX *mem_ctx,
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek struct tevent_req *req,
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek char **_domain)
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek{
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek errno_t ret;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek dbus_uint16_t err_maj;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek dbus_uint32_t err_min;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek char *msg;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek ret = sss_dp_req_recv(mem_ctx, req, &err_maj, &err_min, &msg);
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek if (ret != EOK) {
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek "Could not get account info [%d]: %s\n",
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek ret, sss_strerror(ret));
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek return ret;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek }
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek if (err_maj != DP_ERR_OK) {
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek "Data Provider Error: %u, %u\n",
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek (unsigned int)err_maj, (unsigned int)err_min);
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek talloc_free(msg);
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek return err_min ? err_min : EIO;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek }
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek *_domain = msg;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek return EOK;
95fd82a4d7b50e64fed6906bc5345f271e8247d9Jakub Hrozek}