sdap_async_services.c revision a3c8390d19593b1e5277d95bfb4ab206d4785150
/*
SSSD
Authors:
Stephen Gallagher <sgallagh@redhat.com>
Copyright (C) 2012 Red Hat
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "db/sysdb_services.h"
#include "providers/ldap/sdap_async_private.h"
#include "providers/ldap/ldap_common.h"
struct sdap_get_services_state {
struct tevent_context *ev;
struct sdap_options *opts;
struct sdap_handle *sh;
struct sss_domain_info *dom;
const char **attrs;
const char *base_filter;
char *filter;
int timeout;
bool enumeration;
char *higher_usn;
struct sysdb_attrs **services;
struct sdap_search_base **search_bases;
};
static errno_t
static void
static errno_t
struct sss_domain_info *dom,
struct sdap_options *opts,
struct sysdb_attrs **services,
char **_usn_value);
static errno_t
struct sdap_options *opts,
struct sss_domain_info *dom,
struct sysdb_attrs *attrs,
char **_usn_value,
struct tevent_req *
struct tevent_context *ev,
struct sss_domain_info *dom,
struct sdap_options *opts,
struct sdap_search_base **search_bases,
struct sdap_handle *sh,
const char **attrs,
const char *filter,
int timeout,
bool enumeration)
{
struct tevent_req *req;
struct sdap_get_services_state *state;
if (!state->search_bases) {
"Services lookup request without a search base\n");
goto done;
}
done:
}
return req;
}
static errno_t
{
struct tevent_req *subreq;
struct sdap_get_services_state *state;
return ENOMEM;
}
"Searching for services with base [%s]\n",
if (!subreq) {
return ENOMEM;
}
return EOK;
}
static void
{
struct tevent_req *req =
struct sdap_get_services_state *state =
int ret;
struct sysdb_attrs **services;
bool next_base = false;
if (ret) {
return;
}
"Search for services, returned %zu results.\n",
count);
/* No services found in this search or enumerating */
next_base = true;
}
/* Add this batch of sevices to the list */
if (count > 0) {
struct sysdb_attrs *,
return;
}
/* Copy the new services into the list
*/
for (i = 0; i < count; i++) {
}
}
if (next_base) {
/* There are more search bases to try */
}
return;
}
}
/* No more search bases
* Return ENOENT if no services were found
*/
return;
}
&state->higher_usn);
if (ret) {
"Failed to store services.\n");
return;
}
}
static errno_t
struct sss_domain_info *dom,
struct sdap_options *opts,
struct sysdb_attrs **services,
char **_usn_value)
{
size_t i;
bool in_transaction = false;
char *higher_usn = NULL;
char *usn_value;
if (num_services == 0) {
/* Nothing to do */
return ENOENT;
}
if (!tmp_ctx) {
return ENOMEM;
}
goto done;
}
in_transaction = true;
for (i = 0; i < num_services; i++) {
services[i],
/* Do not fail completely on errors.
* Just report the failure to save and go on */
if (ret) {
"Failed to store service %zu. Ignoring.\n", i);
} else {
"Service [%zu/%zu] processed!\n", i, num_services);
}
if (usn_value) {
if (higher_usn) {
} else {
}
} else {
}
}
}
"Failed to commit transaction!\n");
goto done;
}
in_transaction = false;
if (_usn_value) {
}
done:
if (in_transaction) {
"Failed to cancel transaction!\n");
}
}
return ret;
}
static errno_t
struct sdap_options *opts,
struct sss_domain_info *dom,
struct sysdb_attrs *attrs,
char **_usn_value,
{
struct sysdb_attrs *svc_attrs;
struct ldb_message_element *el;
const char **aliases;
const char **protocols;
const char **cased_protocols;
const char **store_protocols;
char **missing;
if (!tmp_ctx) {
goto done;
}
if (!svc_attrs) {
goto done;
}
/* Identify the primary name of this services */
&name);
"Could not determine the primary name of the service\n");
goto done;
}
/* Handle any available aliases */
&aliases);
"Failed to identify service aliases\n");
goto done;
}
/* Get the port number */
"Failed to identify service port: [%s]\n",
goto done;
}
/* Get the protocols this service offers on that port */
"Failed to identify service protocols: [%s]\n",
goto done;
}
if (dom->case_sensitive == false) {
/* Don't perform the extra mallocs if not necessary */
"Failed to get case_sensitive protocols names: [%s]\n",
goto done;
}
}
/* Get the USN value, if available */
"Failed to retrieve USN value: [%s]\n",
goto done;
}
"Original USN value is not available for [%s].\n",
name);
} else {
if (ret) {
"Failed to add USN value: [%s]\n",
goto done;
}
if (!usn_value) {
goto done;
}
}
/* Make sure to remove any extra attributes from the sysdb
* that have been removed from LDAP
*/
"Failed to identify removed attributes: [%s]\n",
goto done;
}
"Failed to store service in the sysdb: [%s]\n",
goto done;
}
done:
return ret;
}
struct tevent_req *req,
char **usn_value)
{
struct sdap_get_services_state *state =
if (usn_value) {
}
return EOK;
}
/* Enumeration routines */
struct enum_services_state {
struct tevent_context *ev;
struct sdap_id_ctx *id_ctx;
struct sdap_id_op *op;
struct sss_domain_info *domain;
char *filter;
const char **attrs;
};
static void
struct tevent_req *
struct tevent_context *ev,
struct sdap_id_ctx *id_ctx,
struct sdap_id_op *op,
bool purge)
{
struct tevent_req *req;
struct tevent_req *subreq;
struct enum_services_state *state;
"(&(objectclass=%s)(%s=*)(%s=*)(%s=*)(%s>=%s)(!(%s=%s)))",
} else {
"(&(objectclass=%s)(%s=*)(%s=*)(%s=*))",
}
goto fail;
}
/* TODO: handle attrs_type */
true);
if (!subreq) {
goto fail;
}
return req;
fail:
return req;
}
static void
{
struct tevent_req *req =
struct enum_services_state *state =
char *usn_value;
unsigned usn_number;
int ret;
return;
}
if (usn_value) {
}
}
}
{
return EOK;
}