sdap_async_services.c revision 64ddff90c7fcc02ccb06824ac93af7d5f361a88f
968d6dde54d2efa62910a3cf36438325d0b69031krishna Stephen Gallagher <sgallagh@redhat.com>
c28749e97052f09388969427adf7df641cdcdc22kais Copyright (C) 2012 Red Hat
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 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 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 const char **attrs;
c28749e97052f09388969427adf7df641cdcdc22kais const char *base_filter;
c28749e97052f09388969427adf7df641cdcdc22kaisstatic void
c28749e97052f09388969427adf7df641cdcdc22kais const char **attrs,
c28749e97052f09388969427adf7df641cdcdc22kais const char *filter,
c28749e97052f09388969427adf7df641cdcdc22kais req = tevent_req_create(memctx, &state, struct sdap_get_services_state);
c28749e97052f09388969427adf7df641cdcdc22kais ("Services lookup request without a search base\n"));
c28749e97052f09388969427adf7df641cdcdc22kais state = tevent_req_data(req, struct sdap_get_services_state);
c28749e97052f09388969427adf7df641cdcdc22kais ("Searching for services with base [%s]\n",
c28749e97052f09388969427adf7df641cdcdc22kais state->enumeration); /* If we're enumerating, we need paging */
c28749e97052f09388969427adf7df641cdcdc22kais tevent_req_set_callback(subreq, sdap_get_services_process, req);
c28749e97052f09388969427adf7df641cdcdc22kais bool next_base = false;
c28749e97052f09388969427adf7df641cdcdc22kais ("Search for services, returned %d results.\n",
c28749e97052f09388969427adf7df641cdcdc22kais /* No services found in this search or enumerating */
c28749e97052f09388969427adf7df641cdcdc22kais /* Add this batch of sevices to the list */
c28749e97052f09388969427adf7df641cdcdc22kais /* Copy the new services into the list
c28749e97052f09388969427adf7df641cdcdc22kais for (i = 0; i < count; i++) {
efe05f9ecde56550699213909fd4152ef8ef6438krishna /* There are more search bases to try */
efe05f9ecde56550699213909fd4152ef8ef6438krishna /* No more search bases
c28749e97052f09388969427adf7df641cdcdc22kais * Return ENOENT if no services were found
efe05f9ecde56550699213909fd4152ef8ef6438krishna ("Failed to store services.\n"));
c28749e97052f09388969427adf7df641cdcdc22kais /* Nothing to do */
c28749e97052f09388969427adf7df641cdcdc22kais for (i = 0; i < num_services; i++) {
c28749e97052f09388969427adf7df641cdcdc22kais /* Do not fail completely on errors.
c28749e97052f09388969427adf7df641cdcdc22kais * Just report the failure to save and go on */
c28749e97052f09388969427adf7df641cdcdc22kais ("Failed to store service %d. Ignoring.\n", i));
c28749e97052f09388969427adf7df641cdcdc22kais ("Failed to commit transaction!\n"));
c28749e97052f09388969427adf7df641cdcdc22kais ("Failed to cancel transaction!\n"));
c28749e97052f09388969427adf7df641cdcdc22kais const char **aliases;
c28749e97052f09388969427adf7df641cdcdc22kais const char **protocols;
c28749e97052f09388969427adf7df641cdcdc22kais const char **cased_protocols;
c28749e97052f09388969427adf7df641cdcdc22kais const char **store_protocols;
c28749e97052f09388969427adf7df641cdcdc22kais /* Identify the primary name of this services */
c28749e97052f09388969427adf7df641cdcdc22kais ("Could not determine the primary name of the service\n"));
c28749e97052f09388969427adf7df641cdcdc22kais DEBUG(SSSDBG_TRACE_INTERNAL, ("Primary name: [%s]\n", name));
c28749e97052f09388969427adf7df641cdcdc22kais /* Handle any available aliases */
c28749e97052f09388969427adf7df641cdcdc22kais ("Failed to identify service aliases\n"));
c28749e97052f09388969427adf7df641cdcdc22kais /* Get the port number */
c28749e97052f09388969427adf7df641cdcdc22kais ret = sysdb_attrs_get_uint16_t(attrs, SYSDB_SVC_PORT, &port);
c28749e97052f09388969427adf7df641cdcdc22kais ("Failed to identify service port: [%s]\n",
51dd2c77f06e5663c28bd4f7a760cae4cf159e79vk /* Get the protocols this service offers on that port */
c28749e97052f09388969427adf7df641cdcdc22kais ret = sysdb_attrs_get_string_array(attrs, SYSDB_SVC_PROTO,
c28749e97052f09388969427adf7df641cdcdc22kais ("Failed to identify service protocols: [%s]\n",
c28749e97052f09388969427adf7df641cdcdc22kais /* Don't perform the extra mallocs if not necessary */
c28749e97052f09388969427adf7df641cdcdc22kais ("Failed to get case_sensitive protocols names: [%s]\n",
c28749e97052f09388969427adf7df641cdcdc22kais store_protocols = dom->case_sensitive ? protocols : cased_protocols;
c28749e97052f09388969427adf7df641cdcdc22kais /* Get the USN value, if available */
c28749e97052f09388969427adf7df641cdcdc22kais ("Failed to retrieve USN value: [%s]\n",
c28749e97052f09388969427adf7df641cdcdc22kais ("Original USN value is not available for [%s].\n",
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri opts->service_map[SDAP_AT_SERVICE_USN].sys_name,
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri ("Failed to add USN value: [%s]\n",
c28749e97052f09388969427adf7df641cdcdc22kais usn_value = talloc_strdup(tmp_ctx, (const char*)el->values[0].data);
c28749e97052f09388969427adf7df641cdcdc22kais /* Make sure to remove any extra attributes from the sysdb
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri * that have been removed from LDAP
c28749e97052f09388969427adf7df641cdcdc22kais ret = list_missing_attrs(svc_attrs, opts->service_map, SDAP_OPTS_SERVICES,
c28749e97052f09388969427adf7df641cdcdc22kais ("Failed to identify removed attributes: [%s]\n",
c28749e97052f09388969427adf7df641cdcdc22kais ret = sysdb_store_service(sysdb, name, port, aliases, store_protocols,
c28749e97052f09388969427adf7df641cdcdc22kais ("Failed to store service in the sysdb: [%s]\n",
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri/* Enumeration routines */
c28749e97052f09388969427adf7df641cdcdc22kais const char **attrs;
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yendurienum_services_op_done(struct tevent_req *subreq);
c28749e97052f09388969427adf7df641cdcdc22kais req = tevent_req_create(memctx, &state, struct enum_services_state);
c28749e97052f09388969427adf7df641cdcdc22kais if (id_ctx->srv_opts && id_ctx->srv_opts->max_service_value && !purge) {
c28749e97052f09388969427adf7df641cdcdc22kais "(&(objectclass=%s)(%s=*)(%s=*)(%s=*)(%s>=%s)(!(%s=%s)))",
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri id_ctx->opts->service_map[SDAP_AT_SERVICE_NAME].name,
c28749e97052f09388969427adf7df641cdcdc22kais id_ctx->opts->service_map[SDAP_AT_SERVICE_PROTOCOL].name,
51dd2c77f06e5663c28bd4f7a760cae4cf159e79vk "(&(objectclass=%s)(%s=*)(%s=*)(%s=*))",
c28749e97052f09388969427adf7df641cdcdc22kais id_ctx->opts->service_map[SDAP_AT_SERVICE_PROTOCOL].name);
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri DEBUG(SSSDBG_MINOR_FAILURE, ("Failed to build base filter\n"));
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri /* TODO: handle attrs_type */
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri ret = build_attrs_from_map(state, id_ctx->opts->service_map,
51144063f3afc862c6cb3f54fd4341724f765075Krishna Yenduri subreq = sdap_get_services_send(state, state->ev,
c28749e97052f09388969427adf7df641cdcdc22kais tevent_req_set_callback(subreq, enum_services_op_done, req);
c28749e97052f09388969427adf7df641cdcdc22kaisstatic void
c28749e97052f09388969427adf7df641cdcdc22kais ret = sdap_get_services_recv(state, subreq, &usn_value);
c28749e97052f09388969427adf7df641cdcdc22kais talloc_zfree(state->id_ctx->srv_opts->max_service_value);
c28749e97052f09388969427adf7df641cdcdc22kais if ((endptr == NULL || (*endptr == '\0' && endptr != usn_value))
c28749e97052f09388969427adf7df641cdcdc22kais DEBUG(SSSDBG_FUNC_DATA, ("Services higher USN value: [%s]\n",