sdap_async_services.c revision 64ddff90c7fcc02ccb06824ac93af7d5f361a88f
c28749e97052f09388969427adf7df641cdcdc22kais/*
c28749e97052f09388969427adf7df641cdcdc22kais SSSD
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais Authors:
968d6dde54d2efa62910a3cf36438325d0b69031krishna Stephen Gallagher <sgallagh@redhat.com>
968d6dde54d2efa62910a3cf36438325d0b69031krishna
c28749e97052f09388969427adf7df641cdcdc22kais Copyright (C) 2012 Red Hat
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais This program is free software; you can redistribute it and/or modify
c28749e97052f09388969427adf7df641cdcdc22kais it under the terms of the GNU General Public License as published by
c28749e97052f09388969427adf7df641cdcdc22kais the Free Software Foundation; either version 3 of the License, or
c28749e97052f09388969427adf7df641cdcdc22kais (at your option) any later version.
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais This program is distributed in the hope that it will be useful,
c28749e97052f09388969427adf7df641cdcdc22kais but WITHOUT ANY WARRANTY; without even the implied warranty of
c28749e97052f09388969427adf7df641cdcdc22kais MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c28749e97052f09388969427adf7df641cdcdc22kais GNU General Public License for more details.
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais You should have received a copy of the GNU General Public License
c28749e97052f09388969427adf7df641cdcdc22kais along with this program. If not, see <http://www.gnu.org/licenses/>.
c28749e97052f09388969427adf7df641cdcdc22kais*/
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri
c28749e97052f09388969427adf7df641cdcdc22kais#include "util/util.h"
c28749e97052f09388969427adf7df641cdcdc22kais#include "db/sysdb.h"
c28749e97052f09388969427adf7df641cdcdc22kais#include "db/sysdb_services.h"
c28749e97052f09388969427adf7df641cdcdc22kais#include "providers/ldap/sdap_async_private.h"
c28749e97052f09388969427adf7df641cdcdc22kais#include "providers/ldap/ldap_common.h"
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kaisstruct sdap_get_services_state {
c28749e97052f09388969427adf7df641cdcdc22kais struct tevent_context *ev;
c28749e97052f09388969427adf7df641cdcdc22kais struct sdap_options *opts;
c28749e97052f09388969427adf7df641cdcdc22kais struct sdap_handle *sh;
c28749e97052f09388969427adf7df641cdcdc22kais struct sss_domain_info *dom;
c28749e97052f09388969427adf7df641cdcdc22kais struct sysdb_ctx *sysdb;
c28749e97052f09388969427adf7df641cdcdc22kais const char **attrs;
c28749e97052f09388969427adf7df641cdcdc22kais const char *base_filter;
c28749e97052f09388969427adf7df641cdcdc22kais char *filter;
c28749e97052f09388969427adf7df641cdcdc22kais int timeout;
c28749e97052f09388969427adf7df641cdcdc22kais bool enumeration;
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais char *higher_usn;
c28749e97052f09388969427adf7df641cdcdc22kais struct sysdb_attrs **services;
c28749e97052f09388969427adf7df641cdcdc22kais size_t count;
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais size_t base_iter;
c28749e97052f09388969427adf7df641cdcdc22kais struct sdap_search_base **search_bases;
c28749e97052f09388969427adf7df641cdcdc22kais};
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kaisstatic errno_t
c28749e97052f09388969427adf7df641cdcdc22kaissdap_get_services_next_base(struct tevent_req *req);
c28749e97052f09388969427adf7df641cdcdc22kaisstatic void
c28749e97052f09388969427adf7df641cdcdc22kaissdap_get_services_process(struct tevent_req *subreq);
c28749e97052f09388969427adf7df641cdcdc22kaisstatic errno_t
c28749e97052f09388969427adf7df641cdcdc22kaissdap_save_services(TALLOC_CTX *memctx,
c28749e97052f09388969427adf7df641cdcdc22kais struct sysdb_ctx *sysdb,
c28749e97052f09388969427adf7df641cdcdc22kais struct sss_domain_info *dom,
2bd70d4be73561631df9cb3d9eb4c65fa94fa665krishna struct sdap_options *opts,
c28749e97052f09388969427adf7df641cdcdc22kais struct sysdb_attrs **services,
2bd70d4be73561631df9cb3d9eb4c65fa94fa665krishna size_t num_services,
2bd70d4be73561631df9cb3d9eb4c65fa94fa665krishna char **_usn_value);
c28749e97052f09388969427adf7df641cdcdc22kaisstatic errno_t
2bd70d4be73561631df9cb3d9eb4c65fa94fa665krishnasdap_save_service(TALLOC_CTX *mem_ctx,
2bd70d4be73561631df9cb3d9eb4c65fa94fa665krishna struct sysdb_ctx *sysdb,
c28749e97052f09388969427adf7df641cdcdc22kais struct sdap_options *opts,
2bd70d4be73561631df9cb3d9eb4c65fa94fa665krishna struct sss_domain_info *dom,
2bd70d4be73561631df9cb3d9eb4c65fa94fa665krishna struct sysdb_attrs *attrs,
c28749e97052f09388969427adf7df641cdcdc22kais char **_usn_value,
2bd70d4be73561631df9cb3d9eb4c65fa94fa665krishna time_t now);
2bd70d4be73561631df9cb3d9eb4c65fa94fa665krishna
2bd70d4be73561631df9cb3d9eb4c65fa94fa665krishnastruct tevent_req *
2bd70d4be73561631df9cb3d9eb4c65fa94fa665krishnasdap_get_services_send(TALLOC_CTX *memctx,
2bd70d4be73561631df9cb3d9eb4c65fa94fa665krishna struct tevent_context *ev,
2bd70d4be73561631df9cb3d9eb4c65fa94fa665krishna struct sss_domain_info *dom,
2bd70d4be73561631df9cb3d9eb4c65fa94fa665krishna struct sysdb_ctx *sysdb,
c28749e97052f09388969427adf7df641cdcdc22kais struct sdap_options *opts,
c28749e97052f09388969427adf7df641cdcdc22kais struct sdap_search_base **search_bases,
c28749e97052f09388969427adf7df641cdcdc22kais struct sdap_handle *sh,
c28749e97052f09388969427adf7df641cdcdc22kais const char **attrs,
c28749e97052f09388969427adf7df641cdcdc22kais const char *filter,
c28749e97052f09388969427adf7df641cdcdc22kais int timeout,
c28749e97052f09388969427adf7df641cdcdc22kais bool enumeration)
c28749e97052f09388969427adf7df641cdcdc22kais{
c28749e97052f09388969427adf7df641cdcdc22kais errno_t ret;
c28749e97052f09388969427adf7df641cdcdc22kais struct tevent_req *req;
c28749e97052f09388969427adf7df641cdcdc22kais struct sdap_get_services_state *state;
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais req = tevent_req_create(memctx, &state, struct sdap_get_services_state);
c28749e97052f09388969427adf7df641cdcdc22kais if (!req) return NULL;
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais state->ev = ev;
c28749e97052f09388969427adf7df641cdcdc22kais state->opts = opts;
c28749e97052f09388969427adf7df641cdcdc22kais state->dom = dom;
c28749e97052f09388969427adf7df641cdcdc22kais state->sh = sh;
c28749e97052f09388969427adf7df641cdcdc22kais state->sysdb = sysdb;
c28749e97052f09388969427adf7df641cdcdc22kais state->attrs = attrs;
c28749e97052f09388969427adf7df641cdcdc22kais state->higher_usn = NULL;
c28749e97052f09388969427adf7df641cdcdc22kais state->services = NULL;
c28749e97052f09388969427adf7df641cdcdc22kais state->count = 0;
c28749e97052f09388969427adf7df641cdcdc22kais state->timeout = timeout;
c28749e97052f09388969427adf7df641cdcdc22kais state->base_filter = filter;
c28749e97052f09388969427adf7df641cdcdc22kais state->base_iter = 0;
c28749e97052f09388969427adf7df641cdcdc22kais state->search_bases = search_bases;
c28749e97052f09388969427adf7df641cdcdc22kais state->enumeration = enumeration;
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais if (!state->search_bases) {
c28749e97052f09388969427adf7df641cdcdc22kais DEBUG(SSSDBG_CRIT_FAILURE,
c28749e97052f09388969427adf7df641cdcdc22kais ("Services lookup request without a search base\n"));
c28749e97052f09388969427adf7df641cdcdc22kais ret = EINVAL;
c28749e97052f09388969427adf7df641cdcdc22kais goto done;
c28749e97052f09388969427adf7df641cdcdc22kais }
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais ret = sdap_get_services_next_base(req);
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kaisdone:
c28749e97052f09388969427adf7df641cdcdc22kais if (ret != EOK) {
c28749e97052f09388969427adf7df641cdcdc22kais tevent_req_error(req, ret);
c28749e97052f09388969427adf7df641cdcdc22kais tevent_req_post(req, state->ev);
c28749e97052f09388969427adf7df641cdcdc22kais }
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais return req;
c28749e97052f09388969427adf7df641cdcdc22kais}
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kaisstatic errno_t
c28749e97052f09388969427adf7df641cdcdc22kaissdap_get_services_next_base(struct tevent_req *req)
c28749e97052f09388969427adf7df641cdcdc22kais{
c28749e97052f09388969427adf7df641cdcdc22kais struct tevent_req *subreq;
c28749e97052f09388969427adf7df641cdcdc22kais struct sdap_get_services_state *state;
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais state = tevent_req_data(req, struct sdap_get_services_state);
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais talloc_zfree(state->filter);
c28749e97052f09388969427adf7df641cdcdc22kais state->filter = sdap_get_id_specific_filter(state,
c28749e97052f09388969427adf7df641cdcdc22kais state->base_filter,
c28749e97052f09388969427adf7df641cdcdc22kais state->search_bases[state->base_iter]->filter);
c28749e97052f09388969427adf7df641cdcdc22kais if (!state->filter) {
c28749e97052f09388969427adf7df641cdcdc22kais return ENOMEM;
c28749e97052f09388969427adf7df641cdcdc22kais }
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais DEBUG(SSSDBG_TRACE_FUNC,
c28749e97052f09388969427adf7df641cdcdc22kais ("Searching for services with base [%s]\n",
c28749e97052f09388969427adf7df641cdcdc22kais state->search_bases[state->base_iter]->basedn));
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais subreq = sdap_get_generic_send(
c28749e97052f09388969427adf7df641cdcdc22kais state, state->ev, state->opts, state->sh,
c28749e97052f09388969427adf7df641cdcdc22kais state->search_bases[state->base_iter]->basedn,
c28749e97052f09388969427adf7df641cdcdc22kais state->search_bases[state->base_iter]->scope,
c28749e97052f09388969427adf7df641cdcdc22kais state->filter, state->attrs,
c28749e97052f09388969427adf7df641cdcdc22kais state->opts->service_map, SDAP_OPTS_SERVICES,
c28749e97052f09388969427adf7df641cdcdc22kais state->timeout,
c28749e97052f09388969427adf7df641cdcdc22kais state->enumeration); /* If we're enumerating, we need paging */
c28749e97052f09388969427adf7df641cdcdc22kais if (!subreq) {
c28749e97052f09388969427adf7df641cdcdc22kais return ENOMEM;
c28749e97052f09388969427adf7df641cdcdc22kais }
c28749e97052f09388969427adf7df641cdcdc22kais tevent_req_set_callback(subreq, sdap_get_services_process, req);
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais return EOK;
efe05f9ecde56550699213909fd4152ef8ef6438krishna}
efe05f9ecde56550699213909fd4152ef8ef6438krishna
efe05f9ecde56550699213909fd4152ef8ef6438krishnastatic void
efe05f9ecde56550699213909fd4152ef8ef6438krishnasdap_get_services_process(struct tevent_req *subreq)
efe05f9ecde56550699213909fd4152ef8ef6438krishna{
efe05f9ecde56550699213909fd4152ef8ef6438krishna struct tevent_req *req =
c28749e97052f09388969427adf7df641cdcdc22kais tevent_req_callback_data(subreq, struct tevent_req);
c28749e97052f09388969427adf7df641cdcdc22kais struct sdap_get_services_state *state =
c28749e97052f09388969427adf7df641cdcdc22kais tevent_req_data(req, struct sdap_get_services_state);
c28749e97052f09388969427adf7df641cdcdc22kais int ret;
c28749e97052f09388969427adf7df641cdcdc22kais size_t count, i;
c28749e97052f09388969427adf7df641cdcdc22kais struct sysdb_attrs **services;
c28749e97052f09388969427adf7df641cdcdc22kais bool next_base = false;
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais ret = sdap_get_generic_recv(subreq, state,
c28749e97052f09388969427adf7df641cdcdc22kais &count, &services);
c28749e97052f09388969427adf7df641cdcdc22kais talloc_zfree(subreq);
c28749e97052f09388969427adf7df641cdcdc22kais if (ret) {
c28749e97052f09388969427adf7df641cdcdc22kais tevent_req_error(req, ret);
c28749e97052f09388969427adf7df641cdcdc22kais return;
c28749e97052f09388969427adf7df641cdcdc22kais }
efe05f9ecde56550699213909fd4152ef8ef6438krishna
c28749e97052f09388969427adf7df641cdcdc22kais DEBUG(SSSDBG_TRACE_FUNC,
c28749e97052f09388969427adf7df641cdcdc22kais ("Search for services, returned %d results.\n",
c28749e97052f09388969427adf7df641cdcdc22kais count));
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais if (state->enumeration || count == 0) {
c28749e97052f09388969427adf7df641cdcdc22kais /* No services found in this search or enumerating */
c28749e97052f09388969427adf7df641cdcdc22kais next_base = true;
c28749e97052f09388969427adf7df641cdcdc22kais }
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais /* Add this batch of sevices to the list */
c28749e97052f09388969427adf7df641cdcdc22kais if (count > 0) {
c28749e97052f09388969427adf7df641cdcdc22kais state->services =
c28749e97052f09388969427adf7df641cdcdc22kais talloc_realloc(state,
c28749e97052f09388969427adf7df641cdcdc22kais state->services,
c28749e97052f09388969427adf7df641cdcdc22kais struct sysdb_attrs *,
c28749e97052f09388969427adf7df641cdcdc22kais state->count + count + 1);
c28749e97052f09388969427adf7df641cdcdc22kais if (!state->services) {
c28749e97052f09388969427adf7df641cdcdc22kais tevent_req_error(req, ENOMEM);
c28749e97052f09388969427adf7df641cdcdc22kais return;
c28749e97052f09388969427adf7df641cdcdc22kais }
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais /* Copy the new services into the list
c28749e97052f09388969427adf7df641cdcdc22kais */
c28749e97052f09388969427adf7df641cdcdc22kais for (i = 0; i < count; i++) {
c28749e97052f09388969427adf7df641cdcdc22kais state->services[state->count + i] =
c28749e97052f09388969427adf7df641cdcdc22kais talloc_steal(state->services, services[i]);
efe05f9ecde56550699213909fd4152ef8ef6438krishna }
efe05f9ecde56550699213909fd4152ef8ef6438krishna
c28749e97052f09388969427adf7df641cdcdc22kais state->count += count;
efe05f9ecde56550699213909fd4152ef8ef6438krishna state->services[state->count] = NULL;
efe05f9ecde56550699213909fd4152ef8ef6438krishna }
efe05f9ecde56550699213909fd4152ef8ef6438krishna
efe05f9ecde56550699213909fd4152ef8ef6438krishna if (next_base) {
efe05f9ecde56550699213909fd4152ef8ef6438krishna state->base_iter++;
efe05f9ecde56550699213909fd4152ef8ef6438krishna if (state->search_bases[state->base_iter]) {
efe05f9ecde56550699213909fd4152ef8ef6438krishna /* There are more search bases to try */
efe05f9ecde56550699213909fd4152ef8ef6438krishna ret = sdap_get_services_next_base(req);
efe05f9ecde56550699213909fd4152ef8ef6438krishna if (ret != EOK) {
efe05f9ecde56550699213909fd4152ef8ef6438krishna tevent_req_error(req, ret);
efe05f9ecde56550699213909fd4152ef8ef6438krishna }
efe05f9ecde56550699213909fd4152ef8ef6438krishna return;
efe05f9ecde56550699213909fd4152ef8ef6438krishna }
efe05f9ecde56550699213909fd4152ef8ef6438krishna }
efe05f9ecde56550699213909fd4152ef8ef6438krishna
efe05f9ecde56550699213909fd4152ef8ef6438krishna /* No more search bases
c28749e97052f09388969427adf7df641cdcdc22kais * Return ENOENT if no services were found
efe05f9ecde56550699213909fd4152ef8ef6438krishna */
efe05f9ecde56550699213909fd4152ef8ef6438krishna if (state->count == 0) {
efe05f9ecde56550699213909fd4152ef8ef6438krishna tevent_req_error(req, ENOENT);
efe05f9ecde56550699213909fd4152ef8ef6438krishna return;
c28749e97052f09388969427adf7df641cdcdc22kais }
c28749e97052f09388969427adf7df641cdcdc22kais
efe05f9ecde56550699213909fd4152ef8ef6438krishna ret = sdap_save_services(state, state->sysdb,
efe05f9ecde56550699213909fd4152ef8ef6438krishna state->dom, state->opts,
efe05f9ecde56550699213909fd4152ef8ef6438krishna state->services, state->count,
efe05f9ecde56550699213909fd4152ef8ef6438krishna &state->higher_usn);
efe05f9ecde56550699213909fd4152ef8ef6438krishna if (ret) {
efe05f9ecde56550699213909fd4152ef8ef6438krishna DEBUG(SSSDBG_MINOR_FAILURE,
efe05f9ecde56550699213909fd4152ef8ef6438krishna ("Failed to store services.\n"));
efe05f9ecde56550699213909fd4152ef8ef6438krishna tevent_req_error(req, ret);
efe05f9ecde56550699213909fd4152ef8ef6438krishna return;
efe05f9ecde56550699213909fd4152ef8ef6438krishna }
efe05f9ecde56550699213909fd4152ef8ef6438krishna
efe05f9ecde56550699213909fd4152ef8ef6438krishna DEBUG(SSSDBG_TRACE_INTERNAL,
efe05f9ecde56550699213909fd4152ef8ef6438krishna ("Saving %d services - Done\n", state->count));
efe05f9ecde56550699213909fd4152ef8ef6438krishna
efe05f9ecde56550699213909fd4152ef8ef6438krishna tevent_req_done(req);
efe05f9ecde56550699213909fd4152ef8ef6438krishna}
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kaisstatic errno_t
efe05f9ecde56550699213909fd4152ef8ef6438krishnasdap_save_services(TALLOC_CTX *mem_ctx,
efe05f9ecde56550699213909fd4152ef8ef6438krishna struct sysdb_ctx *sysdb,
efe05f9ecde56550699213909fd4152ef8ef6438krishna struct sss_domain_info *dom,
51dd2c77f06e5663c28bd4f7a760cae4cf159e79vk struct sdap_options *opts,
51dd2c77f06e5663c28bd4f7a760cae4cf159e79vk struct sysdb_attrs **services,
efe05f9ecde56550699213909fd4152ef8ef6438krishna size_t num_services,
efe05f9ecde56550699213909fd4152ef8ef6438krishna char **_usn_value)
c28749e97052f09388969427adf7df641cdcdc22kais{
efe05f9ecde56550699213909fd4152ef8ef6438krishna errno_t ret, sret;
efe05f9ecde56550699213909fd4152ef8ef6438krishna time_t now;
efe05f9ecde56550699213909fd4152ef8ef6438krishna size_t i;
efe05f9ecde56550699213909fd4152ef8ef6438krishna bool in_transaction = false;
c28749e97052f09388969427adf7df641cdcdc22kais char *higher_usn = NULL;
51dd2c77f06e5663c28bd4f7a760cae4cf159e79vk char *usn_value;
c28749e97052f09388969427adf7df641cdcdc22kais TALLOC_CTX *tmp_ctx;
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais if (num_services == 0) {
c28749e97052f09388969427adf7df641cdcdc22kais /* Nothing to do */
c28749e97052f09388969427adf7df641cdcdc22kais return ENOENT;
51dd2c77f06e5663c28bd4f7a760cae4cf159e79vk }
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais tmp_ctx = talloc_new(NULL);
c28749e97052f09388969427adf7df641cdcdc22kais if (!tmp_ctx) {
c28749e97052f09388969427adf7df641cdcdc22kais return ENOMEM;
c28749e97052f09388969427adf7df641cdcdc22kais }
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais ret = sysdb_transaction_start(sysdb);
c28749e97052f09388969427adf7df641cdcdc22kais if (ret != EOK) goto done;
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais in_transaction = true;
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais now = time(NULL);
c28749e97052f09388969427adf7df641cdcdc22kais for (i = 0; i < num_services; i++) {
c28749e97052f09388969427adf7df641cdcdc22kais usn_value = NULL;
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais ret = sdap_save_service(tmp_ctx, sysdb, opts, dom,
c28749e97052f09388969427adf7df641cdcdc22kais services[i],
c28749e97052f09388969427adf7df641cdcdc22kais &usn_value, now);
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais /* Do not fail completely on errors.
c28749e97052f09388969427adf7df641cdcdc22kais * Just report the failure to save and go on */
c28749e97052f09388969427adf7df641cdcdc22kais if (ret) {
c28749e97052f09388969427adf7df641cdcdc22kais DEBUG(SSSDBG_MINOR_FAILURE,
c28749e97052f09388969427adf7df641cdcdc22kais ("Failed to store service %d. Ignoring.\n", i));
c28749e97052f09388969427adf7df641cdcdc22kais } else {
c28749e97052f09388969427adf7df641cdcdc22kais DEBUG(SSSDBG_TRACE_INTERNAL,
c28749e97052f09388969427adf7df641cdcdc22kais ("Service [%lu/%lu] processed!\n", i, num_services));
c28749e97052f09388969427adf7df641cdcdc22kais }
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais if (usn_value) {
c28749e97052f09388969427adf7df641cdcdc22kais if (higher_usn) {
c28749e97052f09388969427adf7df641cdcdc22kais if ((strlen(usn_value) > strlen(higher_usn)) ||
c28749e97052f09388969427adf7df641cdcdc22kais (strcmp(usn_value, higher_usn) > 0)) {
c28749e97052f09388969427adf7df641cdcdc22kais talloc_zfree(higher_usn);
c28749e97052f09388969427adf7df641cdcdc22kais higher_usn = usn_value;
c28749e97052f09388969427adf7df641cdcdc22kais } else {
c28749e97052f09388969427adf7df641cdcdc22kais talloc_zfree(usn_value);
c28749e97052f09388969427adf7df641cdcdc22kais }
c28749e97052f09388969427adf7df641cdcdc22kais } else {
c28749e97052f09388969427adf7df641cdcdc22kais higher_usn = usn_value;
c28749e97052f09388969427adf7df641cdcdc22kais }
c28749e97052f09388969427adf7df641cdcdc22kais }
c28749e97052f09388969427adf7df641cdcdc22kais }
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais ret = sysdb_transaction_commit(sysdb);
c28749e97052f09388969427adf7df641cdcdc22kais if (ret != EOK) {
c28749e97052f09388969427adf7df641cdcdc22kais DEBUG(SSSDBG_CRIT_FAILURE,
c28749e97052f09388969427adf7df641cdcdc22kais ("Failed to commit transaction!\n"));
c28749e97052f09388969427adf7df641cdcdc22kais goto done;
c28749e97052f09388969427adf7df641cdcdc22kais }
c28749e97052f09388969427adf7df641cdcdc22kais in_transaction = false;
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais if (_usn_value) {
c28749e97052f09388969427adf7df641cdcdc22kais *_usn_value = talloc_steal(mem_ctx, higher_usn);
c28749e97052f09388969427adf7df641cdcdc22kais }
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kaisdone:
c28749e97052f09388969427adf7df641cdcdc22kais if (in_transaction) {
c28749e97052f09388969427adf7df641cdcdc22kais sret = sysdb_transaction_cancel(sysdb);
c28749e97052f09388969427adf7df641cdcdc22kais if (sret != EOK) {
c28749e97052f09388969427adf7df641cdcdc22kais DEBUG(SSSDBG_CRIT_FAILURE,
c28749e97052f09388969427adf7df641cdcdc22kais ("Failed to cancel transaction!\n"));
c28749e97052f09388969427adf7df641cdcdc22kais }
c28749e97052f09388969427adf7df641cdcdc22kais }
c28749e97052f09388969427adf7df641cdcdc22kais talloc_free(tmp_ctx);
c28749e97052f09388969427adf7df641cdcdc22kais return ret;
c28749e97052f09388969427adf7df641cdcdc22kais}
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kaisstatic errno_t
c28749e97052f09388969427adf7df641cdcdc22kaissdap_save_service(TALLOC_CTX *mem_ctx,
c28749e97052f09388969427adf7df641cdcdc22kais struct sysdb_ctx *sysdb,
c28749e97052f09388969427adf7df641cdcdc22kais struct sdap_options *opts,
c28749e97052f09388969427adf7df641cdcdc22kais struct sss_domain_info *dom,
c28749e97052f09388969427adf7df641cdcdc22kais struct sysdb_attrs *attrs,
c28749e97052f09388969427adf7df641cdcdc22kais char **_usn_value,
c28749e97052f09388969427adf7df641cdcdc22kais time_t now)
c28749e97052f09388969427adf7df641cdcdc22kais{
c28749e97052f09388969427adf7df641cdcdc22kais errno_t ret;
c28749e97052f09388969427adf7df641cdcdc22kais TALLOC_CTX *tmp_ctx = NULL;
c28749e97052f09388969427adf7df641cdcdc22kais struct sysdb_attrs *svc_attrs;
c28749e97052f09388969427adf7df641cdcdc22kais struct ldb_message_element *el;
51dd2c77f06e5663c28bd4f7a760cae4cf159e79vk char *usn_value = NULL;
c28749e97052f09388969427adf7df641cdcdc22kais const char *name = NULL;
c28749e97052f09388969427adf7df641cdcdc22kais const char **aliases;
c28749e97052f09388969427adf7df641cdcdc22kais const char **protocols;
c28749e97052f09388969427adf7df641cdcdc22kais const char **cased_protocols;
c28749e97052f09388969427adf7df641cdcdc22kais const char **store_protocols;
c28749e97052f09388969427adf7df641cdcdc22kais char **missing;
c28749e97052f09388969427adf7df641cdcdc22kais uint16_t port;
c28749e97052f09388969427adf7df641cdcdc22kais uint64_t cache_timeout;
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais DEBUG(SSSDBG_TRACE_ALL, ("Saving service\n"));
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais tmp_ctx = talloc_new(NULL);
c28749e97052f09388969427adf7df641cdcdc22kais if (!tmp_ctx) {
c28749e97052f09388969427adf7df641cdcdc22kais ret = ENOMEM;
c28749e97052f09388969427adf7df641cdcdc22kais goto done;
c28749e97052f09388969427adf7df641cdcdc22kais }
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais svc_attrs = sysdb_new_attrs(tmp_ctx);
c28749e97052f09388969427adf7df641cdcdc22kais if (!svc_attrs) {
c28749e97052f09388969427adf7df641cdcdc22kais ret = ENOMEM;
c28749e97052f09388969427adf7df641cdcdc22kais goto done;
c28749e97052f09388969427adf7df641cdcdc22kais }
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais /* Identify the primary name of this services */
c28749e97052f09388969427adf7df641cdcdc22kais ret = sysdb_attrs_primary_name(
c28749e97052f09388969427adf7df641cdcdc22kais sysdb, attrs,
c28749e97052f09388969427adf7df641cdcdc22kais opts->service_map[SDAP_AT_SERVICE_NAME].name,
c28749e97052f09388969427adf7df641cdcdc22kais &name);
c28749e97052f09388969427adf7df641cdcdc22kais if (ret != EOK) {
c28749e97052f09388969427adf7df641cdcdc22kais DEBUG(SSSDBG_MINOR_FAILURE,
c28749e97052f09388969427adf7df641cdcdc22kais ("Could not determine the primary name of the service\n"));
c28749e97052f09388969427adf7df641cdcdc22kais goto done;
c28749e97052f09388969427adf7df641cdcdc22kais }
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais DEBUG(SSSDBG_TRACE_INTERNAL, ("Primary name: [%s]\n", name));
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais /* Handle any available aliases */
c28749e97052f09388969427adf7df641cdcdc22kais ret = sysdb_attrs_get_aliases(tmp_ctx, attrs, name,
c28749e97052f09388969427adf7df641cdcdc22kais !dom->case_sensitive,
c28749e97052f09388969427adf7df641cdcdc22kais &aliases);
c28749e97052f09388969427adf7df641cdcdc22kais if (ret != EOK) {
c28749e97052f09388969427adf7df641cdcdc22kais DEBUG(SSSDBG_MINOR_FAILURE,
c28749e97052f09388969427adf7df641cdcdc22kais ("Failed to identify service aliases\n"));
c28749e97052f09388969427adf7df641cdcdc22kais goto done;
c28749e97052f09388969427adf7df641cdcdc22kais }
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais /* Get the port number */
c28749e97052f09388969427adf7df641cdcdc22kais ret = sysdb_attrs_get_uint16_t(attrs, SYSDB_SVC_PORT, &port);
c28749e97052f09388969427adf7df641cdcdc22kais if (ret != EOK) {
c28749e97052f09388969427adf7df641cdcdc22kais DEBUG(SSSDBG_MINOR_FAILURE,
c28749e97052f09388969427adf7df641cdcdc22kais ("Failed to identify service port: [%s]\n",
51dd2c77f06e5663c28bd4f7a760cae4cf159e79vk strerror(ret)));
51dd2c77f06e5663c28bd4f7a760cae4cf159e79vk goto done;
51dd2c77f06e5663c28bd4f7a760cae4cf159e79vk }
51dd2c77f06e5663c28bd4f7a760cae4cf159e79vk
51dd2c77f06e5663c28bd4f7a760cae4cf159e79vk /* Get the protocols this service offers on that port */
c28749e97052f09388969427adf7df641cdcdc22kais ret = sysdb_attrs_get_string_array(attrs, SYSDB_SVC_PROTO,
c28749e97052f09388969427adf7df641cdcdc22kais tmp_ctx, &protocols);
c28749e97052f09388969427adf7df641cdcdc22kais if (ret != EOK) {
c28749e97052f09388969427adf7df641cdcdc22kais DEBUG(SSSDBG_MINOR_FAILURE,
c28749e97052f09388969427adf7df641cdcdc22kais ("Failed to identify service protocols: [%s]\n",
c28749e97052f09388969427adf7df641cdcdc22kais strerror(ret)));
c28749e97052f09388969427adf7df641cdcdc22kais goto done;
c28749e97052f09388969427adf7df641cdcdc22kais }
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais if (dom->case_sensitive == false) {
c28749e97052f09388969427adf7df641cdcdc22kais /* Don't perform the extra mallocs if not necessary */
c28749e97052f09388969427adf7df641cdcdc22kais ret = sss_get_cased_name_list(tmp_ctx, protocols,
c28749e97052f09388969427adf7df641cdcdc22kais dom->case_sensitive, &cased_protocols);
c28749e97052f09388969427adf7df641cdcdc22kais if (ret != EOK) {
c28749e97052f09388969427adf7df641cdcdc22kais DEBUG(SSSDBG_MINOR_FAILURE,
c28749e97052f09388969427adf7df641cdcdc22kais ("Failed to get case_sensitive protocols names: [%s]\n",
c28749e97052f09388969427adf7df641cdcdc22kais strerror(ret)));
c28749e97052f09388969427adf7df641cdcdc22kais goto done;
c28749e97052f09388969427adf7df641cdcdc22kais }
c28749e97052f09388969427adf7df641cdcdc22kais }
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais store_protocols = dom->case_sensitive ? protocols : cased_protocols;
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais /* Get the USN value, if available */
c28749e97052f09388969427adf7df641cdcdc22kais ret = sysdb_attrs_get_el(attrs,
c28749e97052f09388969427adf7df641cdcdc22kais opts->service_map[SDAP_AT_SERVICE_USN].sys_name, &el);
c28749e97052f09388969427adf7df641cdcdc22kais if (ret && ret != ENOENT) {
c28749e97052f09388969427adf7df641cdcdc22kais DEBUG(SSSDBG_MINOR_FAILURE,
c28749e97052f09388969427adf7df641cdcdc22kais ("Failed to retrieve USN value: [%s]\n",
c28749e97052f09388969427adf7df641cdcdc22kais strerror(ret)));
c28749e97052f09388969427adf7df641cdcdc22kais goto done;
c28749e97052f09388969427adf7df641cdcdc22kais }
c28749e97052f09388969427adf7df641cdcdc22kais if (ret == ENOENT || el->num_values == 0) {
c28749e97052f09388969427adf7df641cdcdc22kais DEBUG(SSSDBG_TRACE_LIBS,
c28749e97052f09388969427adf7df641cdcdc22kais ("Original USN value is not available for [%s].\n",
c28749e97052f09388969427adf7df641cdcdc22kais name));
c28749e97052f09388969427adf7df641cdcdc22kais } else {
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri ret = sysdb_attrs_add_string(svc_attrs,
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri opts->service_map[SDAP_AT_SERVICE_USN].sys_name,
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri (const char*)el->values[0].data);
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri if (ret) {
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri DEBUG(SSSDBG_MINOR_FAILURE,
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri ("Failed to add USN value: [%s]\n",
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri strerror(ret)));
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri goto done;
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri }
c28749e97052f09388969427adf7df641cdcdc22kais usn_value = talloc_strdup(tmp_ctx, (const char*)el->values[0].data);
c28749e97052f09388969427adf7df641cdcdc22kais if (!usn_value) {
c28749e97052f09388969427adf7df641cdcdc22kais ret = ENOMEM;
c28749e97052f09388969427adf7df641cdcdc22kais goto done;
c28749e97052f09388969427adf7df641cdcdc22kais }
c28749e97052f09388969427adf7df641cdcdc22kais }
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais /* Make sure to remove any extra attributes from the sysdb
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri * that have been removed from LDAP
c28749e97052f09388969427adf7df641cdcdc22kais */
c28749e97052f09388969427adf7df641cdcdc22kais ret = list_missing_attrs(svc_attrs, opts->service_map, SDAP_OPTS_SERVICES,
c28749e97052f09388969427adf7df641cdcdc22kais attrs, &missing);
c28749e97052f09388969427adf7df641cdcdc22kais if (ret != EOK) {
c28749e97052f09388969427adf7df641cdcdc22kais DEBUG(SSSDBG_MINOR_FAILURE,
c28749e97052f09388969427adf7df641cdcdc22kais ("Failed to identify removed attributes: [%s]\n",
c28749e97052f09388969427adf7df641cdcdc22kais strerror(ret)));
c28749e97052f09388969427adf7df641cdcdc22kais goto done;
c28749e97052f09388969427adf7df641cdcdc22kais }
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais cache_timeout = dom->service_timeout;
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais ret = sysdb_store_service(sysdb, name, port, aliases, store_protocols,
c28749e97052f09388969427adf7df641cdcdc22kais svc_attrs, missing, cache_timeout, now);
c28749e97052f09388969427adf7df641cdcdc22kais if (ret != EOK) {
c28749e97052f09388969427adf7df641cdcdc22kais DEBUG(SSSDBG_MINOR_FAILURE,
c28749e97052f09388969427adf7df641cdcdc22kais ("Failed to store service in the sysdb: [%s]\n",
c28749e97052f09388969427adf7df641cdcdc22kais strerror(ret)));
51dd2c77f06e5663c28bd4f7a760cae4cf159e79vk goto done;
51dd2c77f06e5663c28bd4f7a760cae4cf159e79vk }
51dd2c77f06e5663c28bd4f7a760cae4cf159e79vk
51dd2c77f06e5663c28bd4f7a760cae4cf159e79vk *_usn_value = talloc_steal(mem_ctx, usn_value);
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kaisdone:
c28749e97052f09388969427adf7df641cdcdc22kais talloc_free(tmp_ctx);
c28749e97052f09388969427adf7df641cdcdc22kais return ret;
c28749e97052f09388969427adf7df641cdcdc22kais}
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kaiserrno_t
c28749e97052f09388969427adf7df641cdcdc22kaissdap_get_services_recv(TALLOC_CTX *mem_ctx,
c28749e97052f09388969427adf7df641cdcdc22kais struct tevent_req *req,
c28749e97052f09388969427adf7df641cdcdc22kais char **usn_value)
c28749e97052f09388969427adf7df641cdcdc22kais{
c28749e97052f09388969427adf7df641cdcdc22kais struct sdap_get_services_state *state =
c28749e97052f09388969427adf7df641cdcdc22kais tevent_req_data(req, struct sdap_get_services_state);
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais TEVENT_REQ_RETURN_ON_ERROR(req);
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais if (usn_value) {
c28749e97052f09388969427adf7df641cdcdc22kais *usn_value = talloc_steal(mem_ctx, state->higher_usn);
c28749e97052f09388969427adf7df641cdcdc22kais }
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais return EOK;
c28749e97052f09388969427adf7df641cdcdc22kais}
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri
c28749e97052f09388969427adf7df641cdcdc22kais
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri/* Enumeration routines */
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduristruct enum_services_state {
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri struct tevent_context *ev;
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri struct sdap_id_ctx *id_ctx;
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri struct sdap_id_op *op;
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri struct sss_domain_info *domain;
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri struct sysdb_ctx *sysdb;
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri char *filter;
c28749e97052f09388969427adf7df641cdcdc22kais const char **attrs;
c28749e97052f09388969427adf7df641cdcdc22kais};
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduristatic void
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yendurienum_services_op_done(struct tevent_req *subreq);
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kaisstruct tevent_req *
c28749e97052f09388969427adf7df641cdcdc22kaisenum_services_send(TALLOC_CTX *memctx,
c28749e97052f09388969427adf7df641cdcdc22kais struct tevent_context *ev,
c28749e97052f09388969427adf7df641cdcdc22kais struct sdap_id_ctx *id_ctx,
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri struct sdap_id_op *op,
c28749e97052f09388969427adf7df641cdcdc22kais bool purge)
c28749e97052f09388969427adf7df641cdcdc22kais{
c28749e97052f09388969427adf7df641cdcdc22kais errno_t ret;
c28749e97052f09388969427adf7df641cdcdc22kais struct tevent_req *req;
c28749e97052f09388969427adf7df641cdcdc22kais struct tevent_req *subreq;
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri struct enum_services_state *state;
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais req = tevent_req_create(memctx, &state, struct enum_services_state);
c28749e97052f09388969427adf7df641cdcdc22kais if (!req) return NULL;
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais state->ev = ev;
c28749e97052f09388969427adf7df641cdcdc22kais state->id_ctx = id_ctx;
c28749e97052f09388969427adf7df641cdcdc22kais state->domain = id_ctx->be->domain;
c28749e97052f09388969427adf7df641cdcdc22kais state->sysdb = id_ctx->be->sysdb;
c28749e97052f09388969427adf7df641cdcdc22kais state->op = op;
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri
c28749e97052f09388969427adf7df641cdcdc22kais if (id_ctx->srv_opts && id_ctx->srv_opts->max_service_value && !purge) {
c28749e97052f09388969427adf7df641cdcdc22kais state->filter = talloc_asprintf(
c28749e97052f09388969427adf7df641cdcdc22kais state,
c28749e97052f09388969427adf7df641cdcdc22kais "(&(objectclass=%s)(%s=*)(%s=*)(%s=*)(%s>=%s)(!(%s=%s)))",
c28749e97052f09388969427adf7df641cdcdc22kais id_ctx->opts->service_map[SDAP_OC_SERVICE].name,
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri id_ctx->opts->service_map[SDAP_AT_SERVICE_NAME].name,
c28749e97052f09388969427adf7df641cdcdc22kais id_ctx->opts->service_map[SDAP_AT_SERVICE_PORT].name,
c28749e97052f09388969427adf7df641cdcdc22kais id_ctx->opts->service_map[SDAP_AT_SERVICE_PROTOCOL].name,
c28749e97052f09388969427adf7df641cdcdc22kais id_ctx->opts->service_map[SDAP_AT_SERVICE_USN].name,
c28749e97052f09388969427adf7df641cdcdc22kais id_ctx->srv_opts->max_service_value,
c28749e97052f09388969427adf7df641cdcdc22kais id_ctx->opts->service_map[SDAP_AT_SERVICE_USN].name,
c28749e97052f09388969427adf7df641cdcdc22kais id_ctx->srv_opts->max_service_value);
c28749e97052f09388969427adf7df641cdcdc22kais } else {
c28749e97052f09388969427adf7df641cdcdc22kais state->filter = talloc_asprintf(
c28749e97052f09388969427adf7df641cdcdc22kais state,
51dd2c77f06e5663c28bd4f7a760cae4cf159e79vk "(&(objectclass=%s)(%s=*)(%s=*)(%s=*))",
c28749e97052f09388969427adf7df641cdcdc22kais id_ctx->opts->service_map[SDAP_OC_SERVICE].name,
c28749e97052f09388969427adf7df641cdcdc22kais id_ctx->opts->service_map[SDAP_AT_SERVICE_NAME].name,
c28749e97052f09388969427adf7df641cdcdc22kais id_ctx->opts->service_map[SDAP_AT_SERVICE_PORT].name,
c28749e97052f09388969427adf7df641cdcdc22kais id_ctx->opts->service_map[SDAP_AT_SERVICE_PROTOCOL].name);
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri }
c28749e97052f09388969427adf7df641cdcdc22kais if (!state->filter) {
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri DEBUG(SSSDBG_MINOR_FAILURE, ("Failed to build base filter\n"));
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri ret = ENOMEM;
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri goto fail;
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri }
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri /* TODO: handle attrs_type */
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri ret = build_attrs_from_map(state, id_ctx->opts->service_map,
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri SDAP_OPTS_SERVICES, NULL,
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri &state->attrs, NULL);
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri if (ret != EOK) goto fail;
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri subreq = sdap_get_services_send(state, state->ev,
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri state->domain, state->sysdb,
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri state->id_ctx->opts,
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri state->id_ctx->opts->service_search_bases,
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri sdap_id_op_handle(state->op),
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri state->attrs, state->filter,
c28749e97052f09388969427adf7df641cdcdc22kais dp_opt_get_int(state->id_ctx->opts->basic,
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri SDAP_SEARCH_TIMEOUT),
c28749e97052f09388969427adf7df641cdcdc22kais true);
c28749e97052f09388969427adf7df641cdcdc22kais if (!subreq) {
c28749e97052f09388969427adf7df641cdcdc22kais ret = ENOMEM;
c28749e97052f09388969427adf7df641cdcdc22kais goto fail;
c28749e97052f09388969427adf7df641cdcdc22kais }
c28749e97052f09388969427adf7df641cdcdc22kais tevent_req_set_callback(subreq, enum_services_op_done, req);
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais return req;
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kaisfail:
c28749e97052f09388969427adf7df641cdcdc22kais tevent_req_error(req, ret);
c28749e97052f09388969427adf7df641cdcdc22kais tevent_req_post(req, ev);
c28749e97052f09388969427adf7df641cdcdc22kais return req;
c28749e97052f09388969427adf7df641cdcdc22kais}
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kaisstatic void
c28749e97052f09388969427adf7df641cdcdc22kaisenum_services_op_done(struct tevent_req *subreq)
c28749e97052f09388969427adf7df641cdcdc22kais{
c28749e97052f09388969427adf7df641cdcdc22kais struct tevent_req *req =
c28749e97052f09388969427adf7df641cdcdc22kais tevent_req_callback_data(subreq, struct tevent_req);
c28749e97052f09388969427adf7df641cdcdc22kais struct enum_services_state *state =
c28749e97052f09388969427adf7df641cdcdc22kais tevent_req_data(req, struct enum_services_state);
c28749e97052f09388969427adf7df641cdcdc22kais char *usn_value;
c28749e97052f09388969427adf7df641cdcdc22kais char *endptr = NULL;
c28749e97052f09388969427adf7df641cdcdc22kais unsigned usn_number;
c28749e97052f09388969427adf7df641cdcdc22kais int ret;
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais ret = sdap_get_services_recv(state, subreq, &usn_value);
c28749e97052f09388969427adf7df641cdcdc22kais talloc_zfree(subreq);
c28749e97052f09388969427adf7df641cdcdc22kais if (ret != EOK) {
c28749e97052f09388969427adf7df641cdcdc22kais tevent_req_error(req, ret);
c28749e97052f09388969427adf7df641cdcdc22kais return;
c28749e97052f09388969427adf7df641cdcdc22kais }
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais if (usn_value) {
c28749e97052f09388969427adf7df641cdcdc22kais talloc_zfree(state->id_ctx->srv_opts->max_service_value);
c28749e97052f09388969427adf7df641cdcdc22kais state->id_ctx->srv_opts->max_service_value =
c28749e97052f09388969427adf7df641cdcdc22kais talloc_steal(state->id_ctx, usn_value);
51dd2c77f06e5663c28bd4f7a760cae4cf159e79vk
c28749e97052f09388969427adf7df641cdcdc22kais usn_number = strtoul(usn_value, &endptr, 10);
c28749e97052f09388969427adf7df641cdcdc22kais if ((endptr == NULL || (*endptr == '\0' && endptr != usn_value))
c28749e97052f09388969427adf7df641cdcdc22kais && (usn_number > state->id_ctx->srv_opts->last_usn)) {
c28749e97052f09388969427adf7df641cdcdc22kais state->id_ctx->srv_opts->last_usn = usn_number;
c28749e97052f09388969427adf7df641cdcdc22kais }
c28749e97052f09388969427adf7df641cdcdc22kais }
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais DEBUG(SSSDBG_FUNC_DATA, ("Services higher USN value: [%s]\n",
c28749e97052f09388969427adf7df641cdcdc22kais state->id_ctx->srv_opts->max_service_value));
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais tevent_req_done(req);
c28749e97052f09388969427adf7df641cdcdc22kais}
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kaiserrno_t
c28749e97052f09388969427adf7df641cdcdc22kaisenum_services_recv(struct tevent_req *req)
c28749e97052f09388969427adf7df641cdcdc22kais{
c28749e97052f09388969427adf7df641cdcdc22kais TEVENT_REQ_RETURN_ON_ERROR(req);
c28749e97052f09388969427adf7df641cdcdc22kais
c28749e97052f09388969427adf7df641cdcdc22kais return EOK;
c28749e97052f09388969427adf7df641cdcdc22kais}
c28749e97052f09388969427adf7df641cdcdc22kais