796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher/*
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher SSSD
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher Authors:
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher Stephen Gallagher <sgallagh@redhat.com>
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher Copyright (C) 2012 Red Hat
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher This program is free software; you can redistribute it and/or modify
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher it under the terms of the GNU General Public License as published by
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher the Free Software Foundation; either version 3 of the License, or
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher (at your option) any later version.
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher This program is distributed in the hope that it will be useful,
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher but WITHOUT ANY WARRANTY; without even the implied warranty of
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher GNU General Public License for more details.
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher You should have received a copy of the GNU General Public License
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher along with this program. If not, see <http://www.gnu.org/licenses/>.
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher*/
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher#include <errno.h>
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher#include "util/util.h"
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher#include "util/strtonum.h"
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher#include "db/sysdb.h"
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher#include "db/sysdb_services.h"
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher#include "providers/ldap/ldap_common.h"
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher#include "providers/ldap/sdap_async.h"
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagherstruct sdap_services_get_state {
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher struct tevent_context *ev;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher struct sdap_id_ctx *id_ctx;
749cfb5d3270b5daf389d51a0dbd3fd2aec6e05dJakub Hrozek struct sdap_domain *sdom;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher struct sdap_id_op *op;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher struct sysdb_ctx *sysdb;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher struct sss_domain_info *domain;
9aa117a93e315f790a1922d9ac7bd484878b621eJakub Hrozek struct sdap_id_conn_ctx *conn;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher const char *name;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher const char *protocol;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher char *filter;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher const char **attrs;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher int filter_type;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher int dp_error;
ca344fdecdf127c80ad1074047aeba21e1165313Jakub Hrozek int sdap_ret;
ca344fdecdf127c80ad1074047aeba21e1165313Jakub Hrozek bool noexist_delete;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher};
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagherstatic errno_t
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagherservices_get_retry(struct tevent_req *req);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagherstatic void
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagherservices_get_connect_done(struct tevent_req *subreq);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagherstatic void
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagherservices_get_done(struct tevent_req *subreq);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagherstruct tevent_req *
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagherservices_get_send(TALLOC_CTX *mem_ctx,
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher struct tevent_context *ev,
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher struct sdap_id_ctx *id_ctx,
749cfb5d3270b5daf389d51a0dbd3fd2aec6e05dJakub Hrozek struct sdap_domain *sdom,
9aa117a93e315f790a1922d9ac7bd484878b621eJakub Hrozek struct sdap_id_conn_ctx *conn,
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher const char *name,
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher const char *protocol,
ca344fdecdf127c80ad1074047aeba21e1165313Jakub Hrozek int filter_type,
ca344fdecdf127c80ad1074047aeba21e1165313Jakub Hrozek bool noexist_delete)
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher{
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher errno_t ret;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher struct tevent_req *req;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher struct sdap_services_get_state *state;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher const char *attr_name;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher char *clean_name;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher char *clean_protocol = NULL;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher req = tevent_req_create(mem_ctx, &state, struct sdap_services_get_state);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher if (!req) return NULL;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher state->ev = ev;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher state->id_ctx = id_ctx;
749cfb5d3270b5daf389d51a0dbd3fd2aec6e05dJakub Hrozek state->sdom = sdom;
9aa117a93e315f790a1922d9ac7bd484878b621eJakub Hrozek state->conn = conn;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher state->dp_error = DP_ERR_FATAL;
749cfb5d3270b5daf389d51a0dbd3fd2aec6e05dJakub Hrozek state->domain = sdom->dom;
749cfb5d3270b5daf389d51a0dbd3fd2aec6e05dJakub Hrozek state->sysdb = sdom->dom->sysdb;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher state->name = name;
61ab73554e03a2eea4ef51bc5ef02676632eaf6aJakub Hrozek state->protocol = protocol;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher state->filter_type = filter_type;
ca344fdecdf127c80ad1074047aeba21e1165313Jakub Hrozek state->noexist_delete = noexist_delete;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
9aa117a93e315f790a1922d9ac7bd484878b621eJakub Hrozek state->op = sdap_id_op_create(state, state->conn->conn_cache);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher if (!state->op) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "sdap_id_op_create failed\n");
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher ret = ENOMEM;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher goto error;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher }
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher switch(filter_type) {
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher case BE_FILTER_NAME:
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher attr_name = id_ctx->opts->service_map[SDAP_AT_SERVICE_NAME].name;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher break;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher case BE_FILTER_IDNUM:
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher attr_name = id_ctx->opts->service_map[SDAP_AT_SERVICE_PORT].name;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher break;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher default:
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher ret = EINVAL;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher goto error;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher }
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher ret = sss_filter_sanitize(state, name, &clean_name);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher if (ret != EOK) goto error;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
f9d363f9feb7d057d66ba98337e0f8a6fdbca5abLukas Slebodnik if (protocol != NULL) {
e4ba22c165be4b0ccd0e1b9fc92f2f1e35f78a82Petr Cech ret = sss_filter_sanitize(state, protocol, &clean_protocol);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher if (ret != EOK) goto error;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher }
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher if (clean_protocol) {
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher state->filter = talloc_asprintf(
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher state, "(&(%s=%s)(%s=%s)(objectclass=%s))",
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher attr_name, clean_name,
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher id_ctx->opts->service_map[SDAP_AT_SERVICE_PROTOCOL].name,
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher clean_protocol,
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher id_ctx->opts->service_map[SDAP_OC_SERVICE].name);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher } else {
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher state->filter =
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher talloc_asprintf(state, "(&(%s=%s)(objectclass=%s))",
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher attr_name, clean_name,
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher id_ctx->opts->service_map[SDAP_OC_SERVICE].name);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher }
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher talloc_zfree(clean_name);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher talloc_zfree(clean_protocol);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher if (!state->filter) {
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher DEBUG(SSSDBG_MINOR_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Failed to build the base filter\n");
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher ret = ENOMEM;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher goto error;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher }
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher DEBUG(SSSDBG_TRACE_LIBS,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Preparing to search for services with filter [%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov state->filter);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher ret = build_attrs_from_map(state, id_ctx->opts->service_map,
64ddff90c7fcc02ccb06824ac93af7d5f361a88fJan Zeleny SDAP_OPTS_SERVICES, NULL,
64ddff90c7fcc02ccb06824ac93af7d5f361a88fJan Zeleny &state->attrs, NULL);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher if (ret != EOK) goto error;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher ret = services_get_retry(req);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher if (ret != EOK) goto error;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher return req;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallaghererror:
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher tevent_req_error(req, ret);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher tevent_req_post(req, ev);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher return req;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher}
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagherstatic errno_t
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagherservices_get_retry(struct tevent_req *req)
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher{
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher errno_t ret;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher struct sdap_services_get_state *state =
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher tevent_req_data(req, struct sdap_services_get_state);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher struct tevent_req *subreq;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher subreq = sdap_id_op_connect_send(state->op, state, &ret);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher if (!subreq) {
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher return ret;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher }
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher tevent_req_set_callback(subreq, services_get_connect_done, req);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher return EOK;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher}
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagherstatic void
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagherservices_get_connect_done(struct tevent_req *subreq)
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher{
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher errno_t ret;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher struct tevent_req *req =
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher tevent_req_callback_data(subreq, struct tevent_req);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher struct sdap_services_get_state *state =
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher tevent_req_data(req, struct sdap_services_get_state);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher int dp_error = DP_ERR_FATAL;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher ret = sdap_id_op_connect_recv(subreq, &dp_error);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher talloc_zfree(subreq);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher if (ret != EOK) {
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher state->dp_error = dp_error;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher tevent_req_error(req, ret);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher return;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher }
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher subreq = sdap_get_services_send(state, state->ev,
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher state->domain, state->sysdb,
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher state->id_ctx->opts,
749cfb5d3270b5daf389d51a0dbd3fd2aec6e05dJakub Hrozek state->sdom->service_search_bases,
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher sdap_id_op_handle(state->op),
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher state->attrs, state->filter,
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher dp_opt_get_int(state->id_ctx->opts->basic,
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher SDAP_SEARCH_TIMEOUT),
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher false);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher if (!subreq) {
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher tevent_req_error(req, ENOMEM);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher return;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher }
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher tevent_req_set_callback(subreq, services_get_done, req);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher}
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagherstatic void
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagherservices_get_done(struct tevent_req *subreq)
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher{
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher errno_t ret;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher uint16_t port;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher struct tevent_req *req =
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher tevent_req_callback_data(subreq, struct tevent_req);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher struct sdap_services_get_state *state =
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher tevent_req_data(req, struct sdap_services_get_state);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher int dp_error = DP_ERR_FATAL;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher ret = sdap_get_services_recv(NULL, subreq, NULL);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher talloc_zfree(subreq);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher /* Check whether we need to try again with another
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher * failover server.
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher */
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher ret = sdap_id_op_done(state->op, ret, &dp_error);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher if (dp_error == DP_ERR_OK && ret != EOK) {
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher /* retry */
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher ret = services_get_retry(req);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher if (ret != EOK) {
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher tevent_req_error(req, ret);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher return;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher }
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher /* Return to the mainloop to retry */
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher return;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher }
ca344fdecdf127c80ad1074047aeba21e1165313Jakub Hrozek state->sdap_ret = ret;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher /* An error occurred. */
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher if (ret && ret != ENOENT) {
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher state->dp_error = dp_error;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher tevent_req_error(req, ret);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher return;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher }
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
ca344fdecdf127c80ad1074047aeba21e1165313Jakub Hrozek if (ret == ENOENT && state->noexist_delete == true) {
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher /* Ensure that this entry is removed from the sysdb */
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher switch(state->filter_type) {
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher case BE_FILTER_NAME:
4fcc50e133f90cd4c5931a3ac48c84cb628b16fcMichal Zidek ret = sysdb_svc_delete(state->domain, state->name,
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher 0, state->protocol);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher if (ret != EOK) {
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher tevent_req_error(req, ret);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher return;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher }
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher break;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher case BE_FILTER_IDNUM:
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher port = strtouint16(state->name, NULL, 10);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher if (errno) {
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher tevent_req_error(req, errno);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher return;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher }
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
4fcc50e133f90cd4c5931a3ac48c84cb628b16fcMichal Zidek ret = sysdb_svc_delete(state->domain, NULL, port,
4fcc50e133f90cd4c5931a3ac48c84cb628b16fcMichal Zidek state->protocol);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher if (ret != EOK) {
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher tevent_req_error(req, ret);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher return;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher }
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher break;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher default:
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher tevent_req_error(req, EINVAL);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher return;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher }
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher }
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher state->dp_error = DP_ERR_OK;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher tevent_req_done(req);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher}
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallaghererrno_t
ca344fdecdf127c80ad1074047aeba21e1165313Jakub Hrozekservices_get_recv(struct tevent_req *req, int *dp_error_out, int *sdap_ret)
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher{
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher struct sdap_services_get_state *state =
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher tevent_req_data(req, struct sdap_services_get_state);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher if (dp_error_out) {
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher *dp_error_out = state->dp_error;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher }
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
ca344fdecdf127c80ad1074047aeba21e1165313Jakub Hrozek if (sdap_ret) {
ca344fdecdf127c80ad1074047aeba21e1165313Jakub Hrozek *sdap_ret = state->sdap_ret;
ca344fdecdf127c80ad1074047aeba21e1165313Jakub Hrozek }
ca344fdecdf127c80ad1074047aeba21e1165313Jakub Hrozek
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher TEVENT_REQ_RETURN_ON_ERROR(req);
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher return EOK;
796463906a54e259bd5b582ce84af4297a58eafcStephen Gallagher}