02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina/*
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina SSSD
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina Authors:
d98fdd80331e93cd698281341360a3ce3e30afbePavel Březina Pavel Březina <pbrezina@redhat.com>
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina Copyright (C) 2013 Red Hat
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina This program is free software; you can redistribute it and/or modify
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina it under the terms of the GNU General Public License as published by
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina the Free Software Foundation; either version 3 of the License, or
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina (at your option) any later version.
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina This program is distributed in the hope that it will be useful,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina but WITHOUT ANY WARRANTY; without even the implied warranty of
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina GNU General Public License for more details.
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina You should have received a copy of the GNU General Public License
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina along with this program. If not, see <http://www.gnu.org/licenses/>.
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina*/
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina#include <errno.h>
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina#include <string.h>
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina#include <tevent.h>
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina#include <talloc.h>
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina#include <ldb.h>
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina#include <dhash.h>
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina#include <stdint.h>
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina#include <time.h>
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina#include "util/util.h"
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek#include "util/probes.h"
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina#include "db/sysdb.h"
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina#include "providers/ldap/ldap_common.h"
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina#include "providers/ldap/sdap_async.h"
5cd4414fce1e0eb4133dfc6fc828bf25c8a959f9Lukas Slebodnik#include "providers/ldap/sdap_async_private.h"
8a8618717c99b7331125fa736b45d9155da797d3Jakub Hrozek#include "providers/ldap/sdap_idmap.h"
a6dd4a6c55773e81490dcafd61d4b9782705e9bfPavel Březina#include "providers/ipa/ipa_dn.h"
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
4c508463be960682cf94b4e5a39be2f8f49067c8Fabiano Fidêncio#define sdap_nested_group_sysdb_search_users(domain, dn) \
4c508463be960682cf94b4e5a39be2f8f49067c8Fabiano Fidêncio sdap_nested_group_sysdb_search((domain), (dn), true)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
4c508463be960682cf94b4e5a39be2f8f49067c8Fabiano Fidêncio#define sdap_nested_group_sysdb_search_groups(domain, dn) \
4c508463be960682cf94b4e5a39be2f8f49067c8Fabiano Fidêncio sdap_nested_group_sysdb_search((domain), (dn), false)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinaenum sdap_nested_group_dn_type {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina SDAP_NESTED_GROUP_DN_USER,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina SDAP_NESTED_GROUP_DN_GROUP,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina SDAP_NESTED_GROUP_DN_UNKNOWN
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina};
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastruct sdap_nested_group_member {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina enum sdap_nested_group_dn_type type;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina const char *dn;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina const char *user_filter;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina const char *group_filter;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina};
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
c6bda70d6131b5e8cd760ad690fae001d1765547Jakub Hrozek#ifndef EXTERNAL_MEMBERS_CHUNK
c6bda70d6131b5e8cd760ad690fae001d1765547Jakub Hrozek#define EXTERNAL_MEMBERS_CHUNK 16
c6bda70d6131b5e8cd760ad690fae001d1765547Jakub Hrozek#endif /* EXTERNAL_MEMBERS_CHUNK */
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozekstruct sdap_external_missing_member {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek const char **parent_group_dns;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek size_t parent_dn_idx;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek};
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastruct sdap_nested_group_ctx {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sss_domain_info *domain;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_options *opts;
749cfb5d3270b5daf389d51a0dbd3fd2aec6e05dJakub Hrozek struct sdap_search_base **user_search_bases;
749cfb5d3270b5daf389d51a0dbd3fd2aec6e05dJakub Hrozek struct sdap_search_base **group_search_bases;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_handle *sh;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina hash_table_t *users;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina hash_table_t *groups;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek hash_table_t *missing_external;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina bool try_deref;
4a9c1047354dbe5a4ed41e5951ae623e3772e113René Genz int deref_threshold;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina int max_nesting_level;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina};
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic struct tevent_req *
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinasdap_nested_group_process_send(TALLOC_CTX *mem_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_context *ev,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_ctx *group_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina int nesting_level,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sysdb_attrs *group);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic errno_t sdap_nested_group_process_recv(struct tevent_req *req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic struct tevent_req *
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinasdap_nested_group_single_send(TALLOC_CTX *mem_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_context *ev,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_ctx *group_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_member *members,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina int num_members,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina int num_groups_max,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina int nesting_level);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic errno_t sdap_nested_group_single_recv(struct tevent_req *req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic struct tevent_req *
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinasdap_nested_group_lookup_user_send(TALLOC_CTX *mem_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_context *ev,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_ctx *group_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_member *member);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic errno_t sdap_nested_group_lookup_user_recv(TALLOC_CTX *mem_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_req *req,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sysdb_attrs **_user);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic struct tevent_req *
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinasdap_nested_group_lookup_group_send(TALLOC_CTX *mem_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_context *ev,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_ctx *group_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_member *member);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic errno_t sdap_nested_group_lookup_group_recv(TALLOC_CTX *mem_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_req *req,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sysdb_attrs **_group);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic struct tevent_req *
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinasdap_nested_group_lookup_unknown_send(TALLOC_CTX *mem_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_context *ev,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_ctx *group_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_member *member);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic errno_t
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinasdap_nested_group_lookup_unknown_recv(TALLOC_CTX *mem_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_req *req,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sysdb_attrs **_entry,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina enum sdap_nested_group_dn_type *_type);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic struct tevent_req *
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinasdap_nested_group_deref_send(TALLOC_CTX *mem_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_context *ev,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_ctx *group_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct ldb_message_element *members,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina const char *group_dn,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina int nesting_level);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic errno_t sdap_nested_group_deref_recv(struct tevent_req *req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic errno_t
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinasdap_nested_group_extract_hash_table(TALLOC_CTX *mem_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina hash_table_t *table,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina unsigned long *_num_entries,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sysdb_attrs ***_entries)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sysdb_attrs **entries = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sysdb_attrs *entry = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina hash_value_t *values;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina unsigned long num_entries;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina unsigned int i;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina bool hret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina errno_t ret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina hret = hash_values(table, &num_entries, &values);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (hret != HASH_SUCCESS) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = EIO;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (num_entries > 0) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina entries = talloc_array(mem_ctx, struct sysdb_attrs *, num_entries);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (entries == NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = ENOMEM;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina for (i = 0; i < num_entries; i++) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina entry = talloc_get_type(values[i].ptr, struct sysdb_attrs);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina entries[i] = talloc_steal(entries, entry);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (_num_entries != NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina *_num_entries = num_entries;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (_entries != NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina *_entries = entries;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = EOK;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinadone:
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina talloc_free(values);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret != EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina talloc_free(entries);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return ret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozekstatic errno_t sdap_nested_group_hash_insert(hash_table_t *table,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek const char *entry_key,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek void *entry_value,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek bool overwrite,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek const char *table_name)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina hash_key_t key;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina hash_value_t value;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina int hret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_ALL, "Inserting [%s] into hash table [%s]\n",
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek entry_key, table_name);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina key.type = HASH_KEY_STRING;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek key.str = talloc_strdup(NULL, entry_key);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (key.str == NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return ENOMEM;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (overwrite == false && hash_has_key(table, &key)) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina talloc_free(key.str);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return EEXIST;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina value.type = HASH_VALUE_PTR;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek value.ptr = entry_value;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina hret = hash_enter(table, &key, &value);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (hret != HASH_SUCCESS) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina talloc_free(key.str);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return EIO;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina talloc_steal(table, key.str);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina talloc_steal(table, value.ptr);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return EOK;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozekstatic errno_t sdap_nested_group_hash_entry(hash_table_t *table,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct sysdb_attrs *entry,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek const char *table_name)
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek{
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek const char *name = NULL;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek errno_t ret;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ret = sysdb_attrs_get_string(entry, SYSDB_ORIG_DN, &name);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (ret != EOK) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek return ret;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek return sdap_nested_group_hash_insert(table, name, entry, false, table_name);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek}
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic errno_t
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinasdap_nested_group_hash_user(struct sdap_nested_group_ctx *group_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sysdb_attrs *user)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return sdap_nested_group_hash_entry(group_ctx->users, user, "users");
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic errno_t
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinasdap_nested_group_hash_group(struct sdap_nested_group_ctx *group_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sysdb_attrs *group)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_attr_map *map = group_ctx->opts->group_map;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina gid_t gid;
bad2fc8133d941e5a6c8d8016c9689e039265c61Lukas Slebodnik errno_t ret;
8280c5213094a72fcaa499dda2f8647246185d45Sumit Bose bool posix_group = true;
8a8618717c99b7331125fa736b45d9155da797d3Jakub Hrozek bool use_id_mapping;
72db1f3ce67b0634f2843088f1198b3b350b72abLukas Slebodnik bool can_find_gid;
bad2fc8133d941e5a6c8d8016c9689e039265c61Lukas Slebodnik bool need_filter;
8280c5213094a72fcaa499dda2f8647246185d45Sumit Bose
bad2fc8133d941e5a6c8d8016c9689e039265c61Lukas Slebodnik ret = sdap_check_ad_group_type(group_ctx->domain, group_ctx->opts,
bad2fc8133d941e5a6c8d8016c9689e039265c61Lukas Slebodnik group, "", &need_filter);
bad2fc8133d941e5a6c8d8016c9689e039265c61Lukas Slebodnik if (ret != EOK) {
bad2fc8133d941e5a6c8d8016c9689e039265c61Lukas Slebodnik return ret;
bad2fc8133d941e5a6c8d8016c9689e039265c61Lukas Slebodnik }
8280c5213094a72fcaa499dda2f8647246185d45Sumit Bose
bad2fc8133d941e5a6c8d8016c9689e039265c61Lukas Slebodnik if (need_filter) {
bad2fc8133d941e5a6c8d8016c9689e039265c61Lukas Slebodnik posix_group = false;
bad2fc8133d941e5a6c8d8016c9689e039265c61Lukas Slebodnik gid = 0;
8280c5213094a72fcaa499dda2f8647246185d45Sumit Bose }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
8a8618717c99b7331125fa736b45d9155da797d3Jakub Hrozek use_id_mapping = sdap_idmap_domain_has_algorithmic_mapping(
8a8618717c99b7331125fa736b45d9155da797d3Jakub Hrozek group_ctx->opts->idmap_ctx,
8a8618717c99b7331125fa736b45d9155da797d3Jakub Hrozek group_ctx->domain->name,
8a8618717c99b7331125fa736b45d9155da797d3Jakub Hrozek group_ctx->domain->domain_id);
8a8618717c99b7331125fa736b45d9155da797d3Jakub Hrozek
72db1f3ce67b0634f2843088f1198b3b350b72abLukas Slebodnik can_find_gid = posix_group && !use_id_mapping;
72db1f3ce67b0634f2843088f1198b3b350b72abLukas Slebodnik if (can_find_gid) {
e3c994b7b779e6d6d6d125ee28d30bd139590f49Jakub Hrozek ret = sysdb_attrs_get_uint32_t(group, map[SDAP_AT_GROUP_GID].sys_name,
e3c994b7b779e6d6d6d125ee28d30bd139590f49Jakub Hrozek &gid);
e3c994b7b779e6d6d6d125ee28d30bd139590f49Jakub Hrozek }
72db1f3ce67b0634f2843088f1198b3b350b72abLukas Slebodnik if (!can_find_gid || ret == ENOENT || (ret == EOK && gid == 0)) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina DEBUG(SSSDBG_TRACE_ALL,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "The group's gid was %s\n", ret == ENOENT ? "missing" : "zero");
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina DEBUG(SSSDBG_TRACE_INTERNAL,
4a9c1047354dbe5a4ed41e5951ae623e3772e113René Genz "Marking group as non-POSIX and setting GID=0!\n");
72db1f3ce67b0634f2843088f1198b3b350b72abLukas Slebodnik
8280c5213094a72fcaa499dda2f8647246185d45Sumit Bose if (ret == ENOENT || !posix_group) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = sysdb_attrs_add_uint32(group,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina map[SDAP_AT_GROUP_GID].sys_name, 0);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret != EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE,
4a9c1047354dbe5a4ed41e5951ae623e3772e113René Genz "Failed to add a GID to non-POSIX group!\n");
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return ret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = sysdb_attrs_add_bool(group, SYSDB_POSIX, false);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret != EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina DEBUG(SSSDBG_OP_FAILURE,
4a9c1047354dbe5a4ed41e5951ae623e3772e113René Genz "Error: Failed to mark group as non-POSIX!\n");
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return ret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina } else if (ret != EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return ret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return sdap_nested_group_hash_entry(group_ctx->groups, group, "groups");
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozekstatic errno_t sdap_nested_group_external_add(hash_table_t *table,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek const char *ext_member,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek const char *parent_group_dn)
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek{
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek hash_key_t key;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek hash_value_t value;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek int hret;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek int ret;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct sdap_external_missing_member *ext_mem;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek key.type = HASH_KEY_STRING;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek key.str = discard_const(ext_member);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek DEBUG(SSSDBG_TRACE_ALL,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek "Inserting external member [%s] into external members hash table\n",
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ext_member);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek hret = hash_lookup(table, &key, &value);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek switch (hret) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek case HASH_ERROR_KEY_NOT_FOUND:
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ext_mem = talloc_zero(table, struct sdap_external_missing_member);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (ext_mem == NULL) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek return ENOMEM;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ext_mem->parent_group_dns = talloc_zero_array(ext_mem,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek const char *,
c6bda70d6131b5e8cd760ad690fae001d1765547Jakub Hrozek EXTERNAL_MEMBERS_CHUNK);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (ext_mem->parent_group_dns == NULL) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek talloc_free(ext_mem);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek return ENOMEM;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ret = sdap_nested_group_hash_insert(table, ext_member, ext_mem,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek true, "missing external users");
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (ret != EOK) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek return ret;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek break;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek case HASH_SUCCESS:
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ext_mem = talloc_get_type(value.ptr,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct sdap_external_missing_member);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (ext_mem->parent_dn_idx == \
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek talloc_array_length(ext_mem->parent_group_dns)) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ext_mem->parent_group_dns = talloc_realloc(ext_mem,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ext_mem->parent_group_dns,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek const char *,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ext_mem->parent_dn_idx + \
c6bda70d6131b5e8cd760ad690fae001d1765547Jakub Hrozek EXTERNAL_MEMBERS_CHUNK);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (ext_mem->parent_group_dns == NULL) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek talloc_free(ext_mem);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek return ENOMEM;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek break;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek default:
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek return EIO;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ext_mem->parent_group_dns[ext_mem->parent_dn_idx] = \
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek talloc_strdup(ext_mem->parent_group_dns,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek parent_group_dn);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (ext_mem->parent_group_dns[ext_mem->parent_dn_idx] == NULL) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek return ENOMEM;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ext_mem->parent_dn_idx++;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek return EOK;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek}
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic errno_t sdap_nested_group_sysdb_search(struct sss_domain_info *domain,
4c508463be960682cf94b4e5a39be2f8f49067c8Fabiano Fidêncio const char *dn,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina bool user)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina static const char *attrs[] = {SYSDB_CACHE_EXPIRE,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina SYSDB_UIDNUM,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina NULL};
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct ldb_message **msgs = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina size_t count;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina time_t now = time(NULL);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina uint64_t expire;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina uid_t uid;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina errno_t ret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (user) {
4c508463be960682cf94b4e5a39be2f8f49067c8Fabiano Fidêncio ret = sysdb_search_users_by_orig_dn(NULL, domain, dn, attrs,
4c508463be960682cf94b4e5a39be2f8f49067c8Fabiano Fidêncio &count, &msgs);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina } else {
4c508463be960682cf94b4e5a39be2f8f49067c8Fabiano Fidêncio ret = sysdb_search_groups_by_orig_dn(NULL, domain, dn, attrs,
4c508463be960682cf94b4e5a39be2f8f49067c8Fabiano Fidêncio &count, &msgs);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret != EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (count != 1) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "More than one entry found?\n");
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = EFAULT;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* we found an object with this origDN in the sysdb,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina * check if it is valid */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (user) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina uid = ldb_msg_find_attr_as_uint64(msgs[0], SYSDB_UIDNUM, 0);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (uid == 0) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "User with no UID?\n");
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = EINVAL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina expire = ldb_msg_find_attr_as_uint64(msgs[0], SYSDB_CACHE_EXPIRE, 0);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (expire != 0 && expire <= now) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* needs refresh */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = EAGAIN;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* valid object */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = EOK;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinadone:
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina talloc_zfree(msgs);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return ret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic errno_t
05f6866b89f790e25510b7eeca88ded617294011Pavel Březinasdap_nested_group_check_cache(struct sdap_options *opts,
05f6866b89f790e25510b7eeca88ded617294011Pavel Březina struct sss_domain_info *domain,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina const char *member_dn,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina enum sdap_nested_group_dn_type *_type)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
05f6866b89f790e25510b7eeca88ded617294011Pavel Březina struct sdap_domain *sdap_domain = NULL;
05f6866b89f790e25510b7eeca88ded617294011Pavel Březina struct sss_domain_info *member_domain = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina errno_t ret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
05f6866b89f790e25510b7eeca88ded617294011Pavel Březina /* determine correct domain of this member */
05f6866b89f790e25510b7eeca88ded617294011Pavel Březina sdap_domain = sdap_domain_get_by_dn(opts, member_dn);
05f6866b89f790e25510b7eeca88ded617294011Pavel Březina member_domain = sdap_domain == NULL ? domain : sdap_domain->dom;
05f6866b89f790e25510b7eeca88ded617294011Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* search in users */
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek PROBE(SDAP_NESTED_GROUP_SYSDB_SEARCH_USERS_PRE);
4c508463be960682cf94b4e5a39be2f8f49067c8Fabiano Fidêncio ret = sdap_nested_group_sysdb_search_users(member_domain, member_dn);
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek PROBE(SDAP_NESTED_GROUP_SYSDB_SEARCH_USERS_POST);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret == EOK || ret == EAGAIN) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* user found */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina *_type = SDAP_NESTED_GROUP_DN_USER;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina } else if (ret != ENOENT) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* error */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* search in groups */
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek PROBE(SDAP_NESTED_GROUP_SYSDB_SEARCH_GROUPS_PRE);
4c508463be960682cf94b4e5a39be2f8f49067c8Fabiano Fidêncio ret = sdap_nested_group_sysdb_search_groups(member_domain, member_dn);
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek PROBE(SDAP_NESTED_GROUP_SYSDB_SEARCH_GROUPS_POST);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret == EOK || ret == EAGAIN) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* group found */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina *_type = SDAP_NESTED_GROUP_DN_GROUP;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina } else if (ret != ENOENT) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* error */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* not found in the sysdb */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = ENOENT;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinadone:
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return ret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozekstatic bool
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozeksdap_nested_member_is_ent(struct sdap_nested_group_ctx *group_ctx,
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozek const char *dn, char **filter, bool is_user)
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozek{
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozek struct sdap_domain *sditer = NULL;
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozek bool ret = false;
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozek struct sdap_search_base **search_bases;
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozek
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozek DLIST_FOR_EACH(sditer, group_ctx->opts->sdom) {
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozek search_bases = is_user ? sditer->user_search_bases : \
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozek sditer->group_search_bases;
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozek
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozek ret = sss_ldap_dn_in_search_bases(group_ctx, dn, search_bases,
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozek filter);
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozek if (ret == true) {
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozek break;
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozek }
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozek }
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozek
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozek return ret;
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozek}
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozek
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozekstatic inline bool
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozeksdap_nested_member_is_user(struct sdap_nested_group_ctx *group_ctx,
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozek const char *dn, char **filter)
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozek{
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozek return sdap_nested_member_is_ent(group_ctx, dn, filter, true);
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozek}
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozek
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozekstatic inline bool
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozeksdap_nested_member_is_group(struct sdap_nested_group_ctx *group_ctx,
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozek const char *dn, char **filter)
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozek{
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozek return sdap_nested_member_is_ent(group_ctx, dn, filter, false);
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozek}
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozek
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic errno_t
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinasdap_nested_group_split_members(TALLOC_CTX *mem_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_ctx *group_ctx,
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek int threshold,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina int nesting_level,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct ldb_message_element *members,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_member **_missing,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina int *_num_missing,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina int *_num_groups)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina TALLOC_CTX *tmp_ctx = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_member *missing = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina enum sdap_nested_group_dn_type type;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina char *dn = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina char *user_filter = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina char *group_filter = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina int num_missing = 0;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina int num_groups = 0;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina hash_key_t key;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina bool bret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina bool is_user;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina bool is_group;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina errno_t ret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina int i;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (members == NULL) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek *_missing = NULL;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek *_num_missing = 0;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek *_num_groups = 0;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek return EOK;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tmp_ctx = talloc_new(NULL);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (tmp_ctx == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new() failed\n");
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return ENOMEM;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina missing = talloc_zero_array(tmp_ctx, struct sdap_nested_group_member,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina members->num_values);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (missing == NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = ENOMEM;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* create list of missing members
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina * skip dn if:
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina * - is present in user or group hash table
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina * - is present in sysdb and not expired
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina * - it is a group and we have reached the maximal nesting level
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina * - it is not under user nor group search bases
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina *
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina * if dn is in sysdb but expired
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina * - we know what object type it is
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina *
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina * if dn is not in hash table or sysdb
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina * - try to determine type of object by search base that match dn
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina for (i = 0; i < members->num_values; i++) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina dn = (char*)members->values[i].data;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina type = SDAP_NESTED_GROUP_DN_UNKNOWN;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* check hash tables */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina key.type = HASH_KEY_STRING;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina key.str = dn;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina bret = hash_has_key(group_ctx->users, &key);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (bret) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina continue;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina bret = hash_has_key(group_ctx->groups, &key);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (bret) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina continue;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* check sysdb */
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek PROBE(SDAP_NESTED_GROUP_CHECK_CACHE_PRE);
05f6866b89f790e25510b7eeca88ded617294011Pavel Březina ret = sdap_nested_group_check_cache(group_ctx->opts, group_ctx->domain,
05f6866b89f790e25510b7eeca88ded617294011Pavel Březina dn, &type);
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek PROBE(SDAP_NESTED_GROUP_CHECK_CACHE_POST);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret == EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* found and valid */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_ALL, "[%s] found in cache, skipping\n", dn);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina continue;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina } else if (ret != EAGAIN && ret != ENOENT) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* error */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* try to determine type by dn */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (type == SDAP_NESTED_GROUP_DN_UNKNOWN) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* user */
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozek is_user = sdap_nested_member_is_user(group_ctx, dn,
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozek &user_filter);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozek is_group = sdap_nested_member_is_group(group_ctx, dn,
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozek &group_filter);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (is_user && is_group) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* search bases overlap */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_ALL, "[%s] is unknown object\n", dn);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina type = SDAP_NESTED_GROUP_DN_UNKNOWN;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina } else if (is_user) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_ALL, "[%s] is a user\n", dn);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina type = SDAP_NESTED_GROUP_DN_USER;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina } else if (is_group) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_ALL, "[%s] is a group\n", dn);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina type = SDAP_NESTED_GROUP_DN_GROUP;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina } else {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* dn is outside search bases */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_ALL, "[%s] is out of scope of configured "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "search bases, skipping\n", dn);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina continue;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* check nesting level */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (type == SDAP_NESTED_GROUP_DN_GROUP) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (nesting_level >= group_ctx->max_nesting_level) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_ALL, "[%s] is outside nesting limit "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "(level %d), skipping\n", dn, nesting_level);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina talloc_zfree(user_filter);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina talloc_zfree(group_filter);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina continue;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina missing[num_missing].dn = talloc_strdup(missing, dn);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (missing[num_missing].dn == NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = ENOMEM;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina missing[num_missing].type = type;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina missing[num_missing].user_filter = talloc_steal(missing, user_filter);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina missing[num_missing].group_filter = talloc_steal(missing, group_filter);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina num_missing++;
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek if (threshold > 0 && num_missing > threshold) {
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek if (_num_missing) {
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek *_num_missing = num_missing;
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek }
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek ret = ERR_DEREF_THRESHOLD;
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek goto done;
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (type != SDAP_NESTED_GROUP_DN_USER) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina num_groups++;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina missing = talloc_realloc(mem_ctx, missing,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_member, num_missing);
759fd29a597533a3f5489246c0d2b658d8bee417Pavel Reichl /* talloc_realloc behaves as talloc_free if 3rd parameter (count) is 0,
759fd29a597533a3f5489246c0d2b658d8bee417Pavel Reichl * so it's OK to return NULL then
759fd29a597533a3f5489246c0d2b658d8bee417Pavel Reichl */
759fd29a597533a3f5489246c0d2b658d8bee417Pavel Reichl if (missing == NULL && num_missing > 0) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = ENOMEM;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (_missing) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina *_missing = talloc_steal(mem_ctx, missing);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (_num_missing) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina *_num_missing = num_missing;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (_num_groups) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina *_num_groups = num_groups;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = EOK;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinadone:
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina talloc_free(tmp_ctx);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return ret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozekstatic errno_t
b5137d2fe9223f71740c2a9be35d7762f136c41aLukas Slebodniksdap_nested_group_add_ext_members(struct sdap_nested_group_ctx *group_ctx,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct sysdb_attrs *group,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct ldb_message_element *ext_members)
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek{
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek errno_t ret;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek const char *ext_member_attr;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek const char *orig_dn;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (ext_members == NULL) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek return EOK;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ret = sysdb_attrs_get_string(group, SYSDB_ORIG_DN, &orig_dn);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (ret != EOK) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "A group with no originalDN!?!\n");
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek return ret;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek for (size_t i = 0; i < ext_members->num_values; i++) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ext_member_attr = (const char *) ext_members->values[i].data;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ret = sdap_nested_group_external_add(group_ctx->missing_external,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ext_member_attr,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek orig_dn);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (ret != EOK) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek "Cannot add %s into external members [%d]: %s\n",
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ext_member_attr, ret, sss_strerror(ret));
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek return ret;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek return EOK;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek}
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozekstatic struct ldb_message_element *
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozeksdap_nested_group_ext_members(struct sdap_options *opts,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct sysdb_attrs *group)
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek{
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek errno_t ret;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct ldb_message_element *ext_members = NULL;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (opts->ext_ctx == NULL) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek return NULL;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ret = sysdb_attrs_get_el_ext(group,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek opts->group_map[SDAP_AT_GROUP_EXT_MEMBER].sys_name,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek false, &ext_members);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (ret != EOK && ret != ENOENT) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "Unable to retrieve external member list "
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek "[%d]: %s\n", ret, sss_strerror(ret));
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek return ext_members;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek}
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastruct sdap_nested_group_state {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_ctx *group_ctx;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina};
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic void sdap_nested_group_done(struct tevent_req *subreq);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
749cfb5d3270b5daf389d51a0dbd3fd2aec6e05dJakub Hrozekstruct tevent_req *
749cfb5d3270b5daf389d51a0dbd3fd2aec6e05dJakub Hrozeksdap_nested_group_send(TALLOC_CTX *mem_ctx,
749cfb5d3270b5daf389d51a0dbd3fd2aec6e05dJakub Hrozek struct tevent_context *ev,
749cfb5d3270b5daf389d51a0dbd3fd2aec6e05dJakub Hrozek struct sdap_domain *sdom,
749cfb5d3270b5daf389d51a0dbd3fd2aec6e05dJakub Hrozek struct sdap_options *opts,
749cfb5d3270b5daf389d51a0dbd3fd2aec6e05dJakub Hrozek struct sdap_handle *sh,
749cfb5d3270b5daf389d51a0dbd3fd2aec6e05dJakub Hrozek struct sysdb_attrs *group)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_state *state = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_req *req = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_req *subreq = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina errno_t ret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina int i;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek PROBE(SDAP_NESTED_GROUP_SEND);
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina req = tevent_req_create(mem_ctx, &state, struct sdap_nested_group_state);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (req == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "tevent_req_create() failed\n");
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* create main nested group context */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->group_ctx = talloc_zero(state, struct sdap_nested_group_ctx);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (state->group_ctx == NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = ENOMEM;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto immediately;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = sss_hash_create(state->group_ctx, 32, &state->group_ctx->users);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create hash table [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto immediately;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = sss_hash_create(state->group_ctx, 32, &state->group_ctx->groups);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create hash table [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto immediately;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ret = sss_hash_create(state->group_ctx, 32,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek &state->group_ctx->missing_external);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (ret != EOK) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create hash table [%d]: %s\n",
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ret, strerror(ret));
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek goto immediately;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->group_ctx->try_deref = true;
4a9c1047354dbe5a4ed41e5951ae623e3772e113René Genz state->group_ctx->deref_threshold = dp_opt_get_int(opts->basic,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina SDAP_DEREF_THRESHOLD);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->group_ctx->max_nesting_level = dp_opt_get_int(opts->basic,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina SDAP_NESTING_LEVEL);
749cfb5d3270b5daf389d51a0dbd3fd2aec6e05dJakub Hrozek state->group_ctx->domain = sdom->dom;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->group_ctx->opts = opts;
749cfb5d3270b5daf389d51a0dbd3fd2aec6e05dJakub Hrozek state->group_ctx->user_search_bases = sdom->user_search_bases;
749cfb5d3270b5daf389d51a0dbd3fd2aec6e05dJakub Hrozek state->group_ctx->group_search_bases = sdom->group_search_bases;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->group_ctx->sh = sh;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->group_ctx->try_deref = sdap_has_deref_support(sh, opts);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* disable deref if threshold <= 0 */
4a9c1047354dbe5a4ed41e5951ae623e3772e113René Genz if (state->group_ctx->deref_threshold <= 0) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->group_ctx->try_deref = false;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* if any search base contains filter, disable dereference. */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (state->group_ctx->try_deref) {
749cfb5d3270b5daf389d51a0dbd3fd2aec6e05dJakub Hrozek for (i = 0; opts->sdom->user_search_bases[i] != NULL; i++) {
749cfb5d3270b5daf389d51a0dbd3fd2aec6e05dJakub Hrozek if (opts->sdom->user_search_bases[i]->filter != NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "User search base contains filter, "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "dereference will be disabled\n");
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->group_ctx->try_deref = false;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina break;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (state->group_ctx->try_deref) {
749cfb5d3270b5daf389d51a0dbd3fd2aec6e05dJakub Hrozek for (i = 0; opts->sdom->group_search_bases[i] != NULL; i++) {
749cfb5d3270b5daf389d51a0dbd3fd2aec6e05dJakub Hrozek if (opts->sdom->group_search_bases[i]->filter != NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Group search base contains filter, "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "dereference will be disabled\n");
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->group_ctx->try_deref = false;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina break;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* insert initial group into hash table */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = sdap_nested_group_hash_group(state->group_ctx, group);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Unable to insert group into hash table "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "[%d]: %s\n", ret, strerror(ret));
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto immediately;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* resolve group */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina subreq = sdap_nested_group_process_send(state, ev, state->group_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina 0, group);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (subreq == NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = ENOMEM;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto immediately;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_set_callback(subreq, sdap_nested_group_done, req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return req;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinaimmediately:
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret == EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_done(req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina } else {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_error(req, ret);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_post(req, ev);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return req;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic void sdap_nested_group_done(struct tevent_req *subreq)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_req *req = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina errno_t ret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina req = tevent_req_callback_data(subreq, struct tevent_req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = sdap_nested_group_process_recv(subreq);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina talloc_zfree(subreq);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret != EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_error(req, ret);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_done(req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinaerrno_t sdap_nested_group_recv(TALLOC_CTX *mem_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_req *req,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina unsigned long *_num_users,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sysdb_attrs ***_users,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina unsigned long *_num_groups,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct sysdb_attrs ***_groups,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek hash_table_t **_missing_external)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_state *state = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sysdb_attrs **users = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sysdb_attrs **groups = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina unsigned long num_users;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina unsigned long num_groups;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina errno_t ret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state = tevent_req_data(req, struct sdap_nested_group_state);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek PROBE(SDAP_NESTED_GROUP_RECV);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina TEVENT_REQ_RETURN_ON_ERROR(req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = sdap_nested_group_extract_hash_table(state, state->group_ctx->users,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina &num_users, &users);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret != EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return ret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "%lu users found in the hash table\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov num_users);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = sdap_nested_group_extract_hash_table(state, state->group_ctx->groups,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina &num_groups, &groups);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret != EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return ret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "%lu groups found in the hash table\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov num_groups);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (_num_users != NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina *_num_users = num_users;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (_users != NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina *_users = talloc_steal(mem_ctx, users);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (_num_groups!= NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina *_num_groups = num_groups;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (_groups != NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina *_groups = talloc_steal(mem_ctx, groups);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (_missing_external) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek *_missing_external = talloc_steal(mem_ctx,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek state->group_ctx->missing_external);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return EOK;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastruct sdap_nested_group_process_state {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_context *ev;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_ctx *group_ctx;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_member *missing;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina int num_missing_total;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina int num_missing_groups;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct ldb_message_element *ext_members;
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek struct ldb_message_element *members;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina int nesting_level;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina char *group_dn;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina bool deref;
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek bool deref_shortcut;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina};
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic void sdap_nested_group_process_done(struct tevent_req *subreq);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic struct tevent_req *
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinasdap_nested_group_process_send(TALLOC_CTX *mem_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_context *ev,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_ctx *group_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina int nesting_level,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sysdb_attrs *group)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_process_state *state = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_attr_map *group_map = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_req *req = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_req *subreq = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina const char *orig_dn = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina errno_t ret;
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek int split_threshold;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina req = tevent_req_create(mem_ctx, &state,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_process_state);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (req == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "tevent_req_create() failed\n");
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->ev = ev;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->group_ctx = group_ctx;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->nesting_level = nesting_level;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina group_map = state->group_ctx->opts->group_map;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* get original dn */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = sysdb_attrs_get_string(group, SYSDB_ORIG_DN, &orig_dn);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Unable to retrieve original dn "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "[%d]: %s\n", ret, strerror(ret));
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto immediately;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->group_dn = talloc_strdup(state, orig_dn);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (state->group_dn == NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = ENOMEM;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto immediately;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_INTERNAL, "About to process group [%s]\n", orig_dn);
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek PROBE(SDAP_NESTED_GROUP_PROCESS_SEND, state->group_dn);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek /* get member list, both direct and external */
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek state->ext_members = sdap_nested_group_ext_members(state->group_ctx->opts,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek group);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
2efc26d6e54b68a079e8f11fa24d04867d432476Jakub Hrozek ret = sysdb_attrs_get_el_ext(group, group_map[SDAP_AT_GROUP_MEMBER].sys_name,
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek false, &state->members);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (ret == ENOENT && state->ext_members == NULL) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ret = EOK; /* no members, direct or external */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto immediately;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek } else if (ret != EOK && ret != ENOENT) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Unable to retrieve member list "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "[%d]: %s\n", ret, strerror(ret));
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto immediately;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek split_threshold = state->group_ctx->try_deref ? \
4a9c1047354dbe5a4ed41e5951ae623e3772e113René Genz state->group_ctx->deref_threshold : \
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek -1;
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* get members that need to be refreshed */
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek PROBE(SDAP_NESTED_GROUP_PROCESS_SPLIT_PRE);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = sdap_nested_group_split_members(state, state->group_ctx,
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek split_threshold,
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek state->nesting_level,
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek state->members,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina &state->missing,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina &state->num_missing_total,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina &state->num_missing_groups);
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek PROBE(SDAP_NESTED_GROUP_PROCESS_SPLIT_POST);
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek if (ret == ERR_DEREF_THRESHOLD) {
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek DEBUG(SSSDBG_TRACE_FUNC,
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek "More members were missing than the deref threshold\n");
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek state->deref_shortcut = true;
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek } else if (ret != EOK) {
2efc26d6e54b68a079e8f11fa24d04867d432476Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "Unable to split member list "
2efc26d6e54b68a079e8f11fa24d04867d432476Jakub Hrozek "[%d]: %s\n", ret, sss_strerror(ret));
2efc26d6e54b68a079e8f11fa24d04867d432476Jakub Hrozek goto immediately;
2efc26d6e54b68a079e8f11fa24d04867d432476Jakub Hrozek }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
b5137d2fe9223f71740c2a9be35d7762f136c41aLukas Slebodnik ret = sdap_nested_group_add_ext_members(state->group_ctx,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek group,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek state->ext_members);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (ret != EOK) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "Unable to split external member list "
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek "[%d]: %s\n", ret, sss_strerror(ret));
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek goto immediately;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (state->num_missing_total == 0
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek && hash_count(state->group_ctx->missing_external) == 0) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = EOK; /* we're done */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto immediately;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek /* If there are only indirect members of the group, it's still safe to
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek * proceed and let the direct lookup code just fall through.
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek */
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek DEBUG(SSSDBG_TRACE_INTERNAL,
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek "Looking up %d/%d members of group [%s]\n",
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek state->num_missing_total,
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek state->members ? state->members->num_values : 0,
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek orig_dn);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* process members */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (group_ctx->try_deref
4a9c1047354dbe5a4ed41e5951ae623e3772e113René Genz && state->num_missing_total > group_ctx->deref_threshold) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_INTERNAL, "Dereferencing members of group [%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov orig_dn);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->deref = true;
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek subreq = sdap_nested_group_deref_send(state, ev, group_ctx,
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek state->members, orig_dn,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->nesting_level);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina } else {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_INTERNAL, "Members of group [%s] will be "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "processed individually\n", orig_dn);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->deref = false;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina subreq = sdap_nested_group_single_send(state, ev, group_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->missing,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->num_missing_total,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->num_missing_groups,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->nesting_level);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (subreq == NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = ENOMEM;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto immediately;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_set_callback(subreq, sdap_nested_group_process_done, req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return req;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinaimmediately:
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret == EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_done(req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina } else {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_error(req, ret);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_post(req, ev);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return req;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic void sdap_nested_group_process_done(struct tevent_req *subreq)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_process_state *state = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_req *req = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina errno_t ret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina req = tevent_req_callback_data(subreq, struct tevent_req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state = tevent_req_data(req, struct sdap_nested_group_process_state);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (state->deref) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = sdap_nested_group_deref_recv(subreq);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina talloc_zfree(subreq);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret == ENOTSUP) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* dereference is not supported, try again without dereference */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->group_ctx->try_deref = false;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->deref = false;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_INTERNAL, "Members of group [%s] will be "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "processed individually\n", state->group_dn);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek if (state->deref_shortcut == true) {
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek /* If we previously short-cut dereference, we need to split the
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek * members again to get full list of missing member types
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek */
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek PROBE(SDAP_NESTED_GROUP_PROCESS_SPLIT_PRE);
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek ret = sdap_nested_group_split_members(state, state->group_ctx,
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek -1,
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek state->nesting_level,
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek state->members,
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek &state->missing,
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek &state->num_missing_total,
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek &state->num_missing_groups);
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek PROBE(SDAP_NESTED_GROUP_PROCESS_SPLIT_POST);
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek if (ret != EOK) {
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "Unable to split member list "
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek "[%d]: %s\n",
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek ret, sss_strerror(ret));
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek goto done;
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek }
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek }
beec1ee5799570f34a51ea57674c7291c15f7022Jakub Hrozek
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina subreq = sdap_nested_group_single_send(state,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->ev,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->group_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->missing,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->num_missing_total,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->num_missing_groups,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->nesting_level);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (subreq == NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = ENOMEM;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_set_callback(subreq, sdap_nested_group_process_done,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = EAGAIN;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina } else {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = sdap_nested_group_single_recv(subreq);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina talloc_zfree(subreq);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinadone:
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret == EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_done(req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina } else if (ret != EAGAIN) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_error(req, ret);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic errno_t sdap_nested_group_process_recv(struct tevent_req *req)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek#ifdef HAVE_SYSTEMTAP
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek struct sdap_nested_group_process_state *state = NULL;
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek state = tevent_req_data(req, struct sdap_nested_group_process_state);
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek PROBE(SDAP_NESTED_GROUP_PROCESS_RECV, state->group_dn);
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek#endif
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina TEVENT_REQ_RETURN_ON_ERROR(req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return EOK;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastruct sdap_nested_group_recurse_state {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_context *ev;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_ctx *group_ctx;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sysdb_attrs **groups;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina int num_groups;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina int index;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina int nesting_level;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina};
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic errno_t sdap_nested_group_recurse_step(struct tevent_req *req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic void sdap_nested_group_recurse_done(struct tevent_req *subreq);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic struct tevent_req *
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinasdap_nested_group_recurse_send(TALLOC_CTX *mem_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_context *ev,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_ctx *group_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sysdb_attrs **nested_groups,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina int num_groups,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina int nesting_level)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_recurse_state *state = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_req *req = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina errno_t ret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina req = tevent_req_create(mem_ctx, &state,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_recurse_state);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (req == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "tevent_req_create() failed\n");
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->ev = ev;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->group_ctx = group_ctx;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->groups = nested_groups;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->num_groups = num_groups;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->index = 0;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->nesting_level = nesting_level;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* process each group individually */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = sdap_nested_group_recurse_step(req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret != EAGAIN) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto immediately;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return req;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinaimmediately:
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret == EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_done(req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina } else {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_error(req, ret);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_post(req, ev);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return req;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic errno_t sdap_nested_group_recurse_step(struct tevent_req *req)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_recurse_state *state = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_req *subreq = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state = tevent_req_data(req, struct sdap_nested_group_recurse_state);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (state->index >= state->num_groups) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* we're done */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return EOK;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina subreq = sdap_nested_group_process_send(state, state->ev, state->group_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->nesting_level,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->groups[state->index]);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (subreq == NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return ENOMEM;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_set_callback(subreq, sdap_nested_group_recurse_done, req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->index++;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return EAGAIN;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic void sdap_nested_group_recurse_done(struct tevent_req *subreq)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_req *req = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina errno_t ret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina req = tevent_req_callback_data(subreq, struct tevent_req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = sdap_nested_group_process_recv(subreq);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina talloc_zfree(subreq);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret != EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = sdap_nested_group_recurse_step(req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinadone:
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret == EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_done(req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina } else if (ret != EAGAIN) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_error(req, ret);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic errno_t sdap_nested_group_recurse_recv(struct tevent_req *req)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina TEVENT_REQ_RETURN_ON_ERROR(req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return EOK;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastruct sdap_nested_group_single_state {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_context *ev;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_ctx *group_ctx;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_member *members;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina int nesting_level;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_member *current_member;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina int num_members;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina int member_index;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sysdb_attrs **nested_groups;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina int num_groups;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina};
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic errno_t sdap_nested_group_single_step(struct tevent_req *req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic void sdap_nested_group_single_step_done(struct tevent_req *subreq);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic void sdap_nested_group_single_done(struct tevent_req *subreq);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic struct tevent_req *
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinasdap_nested_group_single_send(TALLOC_CTX *mem_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_context *ev,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_ctx *group_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_member *members,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina int num_members,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina int num_groups_max,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina int nesting_level)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_single_state *state = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_req *req = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina errno_t ret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina req = tevent_req_create(mem_ctx, &state,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_single_state);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (req == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "tevent_req_create() failed\n");
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->ev = ev;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->group_ctx = group_ctx;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->members = members;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->nesting_level = nesting_level;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->current_member = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->num_members = num_members;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->member_index = 0;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->nested_groups = talloc_zero_array(state, struct sysdb_attrs *,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina num_groups_max);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (state->nested_groups == NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = ENOMEM;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto immediately;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->num_groups = 0; /* we will count exact number of the groups */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* process each member individually */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = sdap_nested_group_single_step(req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret != EAGAIN) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto immediately;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return req;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinaimmediately:
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret == EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_done(req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina } else {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_error(req, ret);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_post(req, ev);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return req;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic errno_t sdap_nested_group_single_step(struct tevent_req *req)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_single_state *state = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_req *subreq = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state = tevent_req_data(req, struct sdap_nested_group_single_state);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (state->member_index >= state->num_members) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* we're done */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return EOK;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->current_member = &state->members[state->member_index];
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->member_index++;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina switch (state->current_member->type) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina case SDAP_NESTED_GROUP_DN_USER:
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina subreq = sdap_nested_group_lookup_user_send(state, state->ev,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->group_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->current_member);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina break;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina case SDAP_NESTED_GROUP_DN_GROUP:
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina subreq = sdap_nested_group_lookup_group_send(state, state->ev,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->group_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->current_member);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina break;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina case SDAP_NESTED_GROUP_DN_UNKNOWN:
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina subreq = sdap_nested_group_lookup_unknown_send(state, state->ev,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->group_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->current_member);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina break;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (subreq == NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return ENOMEM;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_set_callback(subreq, sdap_nested_group_single_step_done, req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return EAGAIN;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic errno_t
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinasdap_nested_group_single_step_process(struct tevent_req *subreq)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_single_state *state = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_req *req = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sysdb_attrs *entry = NULL;
369626f19a9083be643c796691798e2debf2f07bLukas Slebodnik enum sdap_nested_group_dn_type type = SDAP_NESTED_GROUP_DN_UNKNOWN;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina const char *orig_dn = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina errno_t ret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina req = tevent_req_callback_data(subreq, struct tevent_req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state = tevent_req_data(req, struct sdap_nested_group_single_state);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* set correct type if possible */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (state->current_member->type == SDAP_NESTED_GROUP_DN_UNKNOWN) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = sdap_nested_group_lookup_unknown_recv(state, subreq,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina &entry, &type);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret != EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (entry != NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->current_member->type = type;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina switch (state->current_member->type) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina case SDAP_NESTED_GROUP_DN_USER:
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (entry == NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* type was not unknown, receive data */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = sdap_nested_group_lookup_user_recv(state, subreq, &entry);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret != EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (entry == NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* user not found, continue */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina break;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* save user in hash table */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = sdap_nested_group_hash_user(state->group_ctx, entry);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret == EEXIST) {
a47cb2e08e4004179d2a6b5f9a9340200270fbd0Pavel Březina /* the user is already present, skip it */
a47cb2e08e4004179d2a6b5f9a9340200270fbd0Pavel Březina talloc_zfree(entry);
a47cb2e08e4004179d2a6b5f9a9340200270fbd0Pavel Březina ret = EOK;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina } else if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Unable to save user in hash table "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "[%d]: %s\n", ret, strerror(ret));
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina break;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina case SDAP_NESTED_GROUP_DN_GROUP:
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (entry == NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* type was not unknown, receive data */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = sdap_nested_group_lookup_group_recv(state, subreq, &entry);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret != EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (entry == NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* group not found, continue */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina break;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina } else {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* the type was unknown so we had to pull the group,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina * but we don't want to process it if we have reached
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina * the nesting level */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (state->nesting_level >= state->group_ctx->max_nesting_level) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = sysdb_attrs_get_string(entry, SYSDB_ORIG_DN, &orig_dn);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret != EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina DEBUG(SSSDBG_MINOR_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "The entry has no originalDN\n");
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina orig_dn = "invalid";
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_ALL, "[%s] is outside nesting limit "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "(level %d), skipping\n", orig_dn, state->nesting_level);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina break;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* save group in hash table */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = sdap_nested_group_hash_group(state->group_ctx, entry);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret == EEXIST) {
a47cb2e08e4004179d2a6b5f9a9340200270fbd0Pavel Březina /* the group is already present, skip it */
a47cb2e08e4004179d2a6b5f9a9340200270fbd0Pavel Březina talloc_zfree(entry);
a47cb2e08e4004179d2a6b5f9a9340200270fbd0Pavel Březina ret = EOK;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina } else if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Unable to save group in hash table "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "[%d]: %s\n", ret, strerror(ret));
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* remember the group for later processing */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->nested_groups[state->num_groups] = entry;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->num_groups++;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina break;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina case SDAP_NESTED_GROUP_DN_UNKNOWN:
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* not found in users nor nested_groups, continue */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina break;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = EOK;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinadone:
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return ret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic void sdap_nested_group_single_step_done(struct tevent_req *subreq)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_single_state *state = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_req *req = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina errno_t ret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina req = tevent_req_callback_data(subreq, struct tevent_req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state = tevent_req_data(req, struct sdap_nested_group_single_state);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* process direct members */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = sdap_nested_group_single_step_process(subreq);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina talloc_zfree(subreq);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Error processing direct membership "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "[%d]: %s\n", ret, strerror(ret));
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = sdap_nested_group_single_step(req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret == EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* we have processed all direct members,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina * now recurse and process nested groups */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina subreq = sdap_nested_group_recurse_send(state, state->ev,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->group_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->nested_groups,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->num_groups,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->nesting_level + 1);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (subreq == NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = ENOMEM;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_set_callback(subreq, sdap_nested_group_single_done, req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina } else if (ret != EAGAIN) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* error */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* we're not done yet */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = EAGAIN;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinadone:
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret == EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* tevent_req_error() cannot cope with EOK */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "We should not get here with EOK\n");
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_error(req, EINVAL);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina } else if (ret != EAGAIN) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_error(req, ret);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic void sdap_nested_group_single_done(struct tevent_req *subreq)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_req *req = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina errno_t ret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina req = tevent_req_callback_data(subreq, struct tevent_req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* all nested groups are completed */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = sdap_nested_group_recurse_recv(subreq);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina talloc_zfree(subreq);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Error processing nested groups "
c683b8d730f4ec838244147d70a0275d53459aa5Pavel Reichl "[%d]: %s.\n", ret, strerror(ret));
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_error(req, ret);
0d47aef7577f8cf651255cf59df87b3847dbe1adPavel Reichl return;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_done(req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic errno_t sdap_nested_group_single_recv(struct tevent_req *req)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina TEVENT_REQ_RETURN_ON_ERROR(req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return EOK;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic errno_t sdap_nested_group_get_ipa_user(TALLOC_CTX *mem_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina const char *user_dn,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sysdb_ctx *sysdb,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sysdb_attrs **_user)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina TALLOC_CTX *tmp_ctx;
a6dd4a6c55773e81490dcafd61d4b9782705e9bfPavel Březina struct sysdb_attrs *user;
a6dd4a6c55773e81490dcafd61d4b9782705e9bfPavel Březina char *name;
a6dd4a6c55773e81490dcafd61d4b9782705e9bfPavel Březina errno_t ret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tmp_ctx = talloc_new(NULL);
a6dd4a6c55773e81490dcafd61d4b9782705e9bfPavel Březina if (tmp_ctx == NULL) {
a6dd4a6c55773e81490dcafd61d4b9782705e9bfPavel Březina return ENOMEM;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
a6dd4a6c55773e81490dcafd61d4b9782705e9bfPavel Březina ret = ipa_get_rdn(tmp_ctx, sysdb, user_dn, &name, "uid",
a6dd4a6c55773e81490dcafd61d4b9782705e9bfPavel Březina "cn", "users", "cn", "accounts");
a6dd4a6c55773e81490dcafd61d4b9782705e9bfPavel Březina if (ret != EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina user = sysdb_new_attrs(tmp_ctx);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (user == NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = ENOMEM;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = sysdb_attrs_add_string(user, SYSDB_NAME, name);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret != EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = sysdb_attrs_add_string(user, SYSDB_ORIG_DN, user_dn);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret != EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose ret = sysdb_attrs_add_string(user, SYSDB_OBJECTCATEGORY, SYSDB_USER_CLASS);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret != EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina *_user = talloc_steal(mem_ctx, user);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinadone:
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina talloc_free(tmp_ctx);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return ret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastruct sdap_nested_group_lookup_user_state {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sysdb_attrs *user;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina};
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic void sdap_nested_group_lookup_user_done(struct tevent_req *subreq);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic struct tevent_req *
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinasdap_nested_group_lookup_user_send(TALLOC_CTX *mem_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_context *ev,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_ctx *group_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_member *member)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_lookup_user_state *state = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_req *req = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_req *subreq = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina const char **attrs = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina const char *base_filter = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina const char *filter = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina errno_t ret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina req = tevent_req_create(mem_ctx, &state,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_lookup_user_state);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (req == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "tevent_req_create() failed\n");
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek PROBE(SDAP_NESTED_GROUP_LOOKUP_USER_SEND);
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (group_ctx->opts->schema_type == SDAP_SCHEMA_IPA_V1) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* if the schema is IPA, then just shortcut and guess the name */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = sdap_nested_group_get_ipa_user(state, member->dn,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina group_ctx->domain->sysdb,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina &state->user);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret == EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto immediately;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Couldn't parse out user information "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "based on DN %s, falling back to an LDAP lookup\n", member->dn);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* only pull down username and originalDN */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina attrs = talloc_array(state, const char *, 3);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (attrs == NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = ENOMEM;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto immediately;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina attrs[0] = "objectClass";
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina attrs[1] = group_ctx->opts->user_map[SDAP_AT_USER_NAME].name;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina attrs[2] = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* create filter */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina base_filter = talloc_asprintf(state, "(objectclass=%s)",
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina group_ctx->opts->user_map[SDAP_OC_USER].name);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (base_filter == NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = ENOMEM;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto immediately;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* use search base filter if needed */
92ec40e6aa25f75903ffdb166a8ec56b67bfd77dPavel Březina filter = sdap_combine_filters(state, base_filter, member->user_filter);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (filter == NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = ENOMEM;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto immediately;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* search */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina subreq = sdap_get_generic_send(state, ev, group_ctx->opts, group_ctx->sh,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina member->dn, LDAP_SCOPE_BASE, filter, attrs,
4dd38025efda88f123eac672f87d3cda12f050c8Jakub Hrozek group_ctx->opts->user_map,
4dd38025efda88f123eac672f87d3cda12f050c8Jakub Hrozek group_ctx->opts->user_map_cnt,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina dp_opt_get_int(group_ctx->opts->basic,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina SDAP_SEARCH_TIMEOUT),
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina false);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (subreq == NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = ENOMEM;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto immediately;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_set_callback(subreq, sdap_nested_group_lookup_user_done, req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return req;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinaimmediately:
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret == EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_done(req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina } else {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_error(req, ret);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_post(req, ev);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return req;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic void sdap_nested_group_lookup_user_done(struct tevent_req *subreq)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_lookup_user_state *state = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_req *req = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sysdb_attrs **user = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina size_t count = 0;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina errno_t ret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina req = tevent_req_callback_data(subreq, struct tevent_req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state = tevent_req_data(req, struct sdap_nested_group_lookup_user_state);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = sdap_get_generic_recv(subreq, state, &count, &user);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina talloc_zfree(subreq);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret == ENOENT) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina count = 0;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina } else if (ret != EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (count == 1) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->user = user[0];
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina } else if (count == 0) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* group not found */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->user = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina } else {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "BASE search returned more than one records\n");
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = EIO;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = EOK;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinadone:
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret != EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_error(req, ret);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_done(req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic errno_t sdap_nested_group_lookup_user_recv(TALLOC_CTX *mem_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_req *req,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sysdb_attrs **_user)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_lookup_user_state *state = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state = tevent_req_data(req, struct sdap_nested_group_lookup_user_state);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek PROBE(SDAP_NESTED_GROUP_LOOKUP_USER_RECV);
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina TEVENT_REQ_RETURN_ON_ERROR(req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (_user != NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina *_user = talloc_steal(mem_ctx, state->user);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return EOK;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastruct sdap_nested_group_lookup_group_state {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sysdb_attrs *group;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina};
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic void sdap_nested_group_lookup_group_done(struct tevent_req *subreq);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic struct tevent_req *
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinasdap_nested_group_lookup_group_send(TALLOC_CTX *mem_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_context *ev,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_ctx *group_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_member *member)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_lookup_group_state *state = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_req *req = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_req *subreq = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_attr_map *map = group_ctx->opts->group_map;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina const char **attrs = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina const char *base_filter = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina const char *filter = NULL;
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek char *oc_list;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina errno_t ret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek PROBE(SDAP_NESTED_GROUP_LOOKUP_GROUP_SEND);
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina req = tevent_req_create(mem_ctx, &state,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_lookup_group_state);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (req == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "tevent_req_create() failed\n");
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = build_attrs_from_map(state, group_ctx->opts->group_map,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina SDAP_OPTS_GROUP, NULL, &attrs, NULL);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret != EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto immediately;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* create filter */
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek oc_list = sdap_make_oc_list(state, map);
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek if (oc_list == NULL) {
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek DEBUG(SSSDBG_CRIT_FAILURE, "Failed to create objectClass list.\n");
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek ret = ENOMEM;
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek goto immediately;
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek }
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek base_filter = talloc_asprintf(attrs, "(&(%s)(%s=*))", oc_list,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina map[SDAP_AT_GROUP_NAME].name);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (base_filter == NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = ENOMEM;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto immediately;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* use search base filter if needed */
92ec40e6aa25f75903ffdb166a8ec56b67bfd77dPavel Březina filter = sdap_combine_filters(state, base_filter, member->group_filter);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (filter == NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = ENOMEM;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto immediately;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* search */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina subreq = sdap_get_generic_send(state, ev, group_ctx->opts, group_ctx->sh,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina member->dn, LDAP_SCOPE_BASE, filter, attrs,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina map, SDAP_OPTS_GROUP,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina dp_opt_get_int(group_ctx->opts->basic,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina SDAP_SEARCH_TIMEOUT),
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina false);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (subreq == NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = ENOMEM;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto immediately;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_set_callback(subreq, sdap_nested_group_lookup_group_done, req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return req;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinaimmediately:
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret == EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_done(req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina } else {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_error(req, ret);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_post(req, ev);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return req;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic void sdap_nested_group_lookup_group_done(struct tevent_req *subreq)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_lookup_group_state *state = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_req *req = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sysdb_attrs **group = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina size_t count = 0;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina errno_t ret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina req = tevent_req_callback_data(subreq, struct tevent_req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state = tevent_req_data(req, struct sdap_nested_group_lookup_group_state);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = sdap_get_generic_recv(subreq, state, &count, &group);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina talloc_zfree(subreq);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret == ENOENT) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina count = 0;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina } else if (ret != EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (count == 1) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->group = group[0];
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina } else if (count == 0) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* group not found */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->group = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina } else {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "BASE search returned more than one records\n");
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = EIO;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = EOK;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinadone:
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret != EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_error(req, ret);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_done(req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
24c3188e29df52d6df7070007e1c65d152b57fe9Jakub Hrozekstatic errno_t sdap_nested_group_lookup_group_recv(TALLOC_CTX *mem_ctx,
24c3188e29df52d6df7070007e1c65d152b57fe9Jakub Hrozek struct tevent_req *req,
24c3188e29df52d6df7070007e1c65d152b57fe9Jakub Hrozek struct sysdb_attrs **_group)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_lookup_group_state *state = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state = tevent_req_data(req, struct sdap_nested_group_lookup_group_state);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek PROBE(SDAP_NESTED_GROUP_LOOKUP_GROUP_RECV);
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina TEVENT_REQ_RETURN_ON_ERROR(req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (_group != NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina *_group = talloc_steal(mem_ctx, state->group);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return EOK;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastruct sdap_nested_group_lookup_unknown_state {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_context *ev;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_ctx *group_ctx;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_member *member;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina enum sdap_nested_group_dn_type type;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sysdb_attrs *entry;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina};
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic void
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinasdap_nested_group_lookup_unknown_user_done(struct tevent_req *subreq);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic void
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinasdap_nested_group_lookup_unknown_group_done(struct tevent_req *subreq);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic struct tevent_req *
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinasdap_nested_group_lookup_unknown_send(TALLOC_CTX *mem_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_context *ev,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_ctx *group_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_member *member)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_lookup_unknown_state *state = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_req *req = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_req *subreq = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina errno_t ret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina req = tevent_req_create(mem_ctx, &state,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_lookup_unknown_state);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (req == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "tevent_req_create() failed\n");
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek PROBE(SDAP_NESTED_GROUP_LOOKUP_UNKNOWN_SEND);
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->ev = ev;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->group_ctx = group_ctx;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->member = member;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* try users first */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina subreq = sdap_nested_group_lookup_user_send(state,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->ev,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->group_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->member);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (subreq == NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = ENOMEM;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto immediately;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_set_callback(subreq, sdap_nested_group_lookup_unknown_user_done,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return req;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinaimmediately:
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret == EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_done(req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina } else {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_error(req, ret);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_post(req, ev);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return req;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic void
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinasdap_nested_group_lookup_unknown_user_done(struct tevent_req *subreq)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_lookup_unknown_state *state = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_req *req = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sysdb_attrs *entry = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina errno_t ret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina req = tevent_req_callback_data(subreq, struct tevent_req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state = tevent_req_data(req, struct sdap_nested_group_lookup_unknown_state);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = sdap_nested_group_lookup_user_recv(state, subreq, &entry);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina talloc_zfree(subreq);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret != EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (entry != NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* found in users */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->entry = entry;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->type = SDAP_NESTED_GROUP_DN_USER;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = EOK;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* not found in users, try group */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina subreq = sdap_nested_group_lookup_group_send(state,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->ev,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->group_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->member);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (subreq == NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = ENOMEM;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_set_callback(subreq, sdap_nested_group_lookup_unknown_group_done,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = EAGAIN;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinadone:
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret == EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_done(req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina } else if (ret != EAGAIN) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_error(req, ret);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic void
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinasdap_nested_group_lookup_unknown_group_done(struct tevent_req *subreq)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_lookup_unknown_state *state = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_req *req = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sysdb_attrs *entry = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina errno_t ret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina req = tevent_req_callback_data(subreq, struct tevent_req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state = tevent_req_data(req, struct sdap_nested_group_lookup_unknown_state);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = sdap_nested_group_lookup_group_recv(state, subreq, &entry);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina talloc_zfree(subreq);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret != EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (entry == NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* not found, end request */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->entry = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->type = SDAP_NESTED_GROUP_DN_UNKNOWN;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina } else {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* found in groups */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->entry = entry;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->type = SDAP_NESTED_GROUP_DN_GROUP;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
24c3188e29df52d6df7070007e1c65d152b57fe9Jakub Hrozek ret = EOK;
24c3188e29df52d6df7070007e1c65d152b57fe9Jakub Hrozek
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinadone:
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret != EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_error(req, ret);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_done(req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic errno_t
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinasdap_nested_group_lookup_unknown_recv(TALLOC_CTX *mem_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_req *req,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sysdb_attrs **_entry,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina enum sdap_nested_group_dn_type *_type)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_lookup_unknown_state *state = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state = tevent_req_data(req, struct sdap_nested_group_lookup_unknown_state);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek PROBE(SDAP_NESTED_GROUP_LOOKUP_UNKNOWN_RECV);
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina TEVENT_REQ_RETURN_ON_ERROR(req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (_entry != NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina *_entry = talloc_steal(mem_ctx, state->entry);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (_type != NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina *_type = state->type;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return EOK;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastruct sdap_nested_group_deref_state {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_context *ev;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_ctx *group_ctx;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct ldb_message_element *members;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina int nesting_level;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sysdb_attrs **nested_groups;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina int num_groups;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina};
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic void sdap_nested_group_deref_direct_done(struct tevent_req *subreq);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic void sdap_nested_group_deref_done(struct tevent_req *subreq);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic struct tevent_req *
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinasdap_nested_group_deref_send(TALLOC_CTX *mem_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_context *ev,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_ctx *group_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct ldb_message_element *members,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina const char *group_dn,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina int nesting_level)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_deref_state *state = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_req *req = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_req *subreq = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_attr_map_info *maps = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina static const int num_maps = 2;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_options *opts = group_ctx->opts;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina const char **attrs = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina size_t num_attrs = 0;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina errno_t ret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina req = tevent_req_create(mem_ctx, &state,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_deref_state);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (req == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "tevent_req_create() failed\n");
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek PROBE(SDAP_NESTED_GROUP_DEREF_SEND);
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->ev = ev;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->group_ctx = group_ctx;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->members = members;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->nesting_level = nesting_level;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->num_groups = 0; /* we will count exact number of the groups */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina maps = talloc_array(state, struct sdap_attr_map_info, num_maps);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (maps == NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = ENOMEM;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto immediately;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina maps[0].map = opts->user_map;
4dd38025efda88f123eac672f87d3cda12f050c8Jakub Hrozek maps[0].num_attrs = opts->user_map_cnt;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina maps[1].map = opts->group_map;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina maps[1].num_attrs = SDAP_OPTS_GROUP;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* pull down the whole group map,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina * but only pull down username and originalDN for users */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = build_attrs_from_map(state, opts->group_map, SDAP_OPTS_GROUP,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina NULL, &attrs, &num_attrs);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret != EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto immediately;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina attrs = talloc_realloc(state, attrs, const char *, num_attrs + 2);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (attrs == NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = ENOMEM;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto immediately;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina attrs[num_attrs] = group_ctx->opts->user_map[SDAP_AT_USER_NAME].name;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina attrs[num_attrs + 1] = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* send request */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina subreq = sdap_deref_search_send(state, ev, opts, group_ctx->sh, group_dn,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina opts->group_map[SDAP_AT_GROUP_MEMBER].name,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina attrs, num_maps, maps,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina dp_opt_get_int(opts->basic,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina SDAP_SEARCH_TIMEOUT));
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (subreq == NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = ENOMEM;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto immediately;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_set_callback(subreq, sdap_nested_group_deref_direct_done, req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return req;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinaimmediately:
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret == EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_done(req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina } else {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_error(req, ret);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_post(req, ev);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return req;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic errno_t
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinasdap_nested_group_deref_direct_process(struct tevent_req *subreq)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_deref_state *state = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_req *req = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_options *opts = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_deref_attrs **entries = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct ldb_message_element *members = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina const char *orig_dn = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina const char *member_dn = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina size_t num_entries = 0;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina size_t i, j;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina bool member_found;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina errno_t ret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina req = tevent_req_callback_data(subreq, struct tevent_req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state = tevent_req_data(req, struct sdap_nested_group_deref_state);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina opts = state->group_ctx->opts;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina members = state->members;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = sdap_deref_search_recv(subreq, state, &num_entries, &entries);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret != EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_INTERNAL, "Received %zu dereference results, "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "about to process them\n", num_entries);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
fc0d76ac54c813c78380ab388f69c69c3620155dPavel Březina /*
fc0d76ac54c813c78380ab388f69c69c3620155dPavel Březina * We don't have any knowledge about possible number of groups when
fc0d76ac54c813c78380ab388f69c69c3620155dPavel Březina * dereferencing. We expect that every member is a group and we will
fc0d76ac54c813c78380ab388f69c69c3620155dPavel Březina * allocate enough space to hold it. We will shrink the memory later.
fc0d76ac54c813c78380ab388f69c69c3620155dPavel Březina */
fc0d76ac54c813c78380ab388f69c69c3620155dPavel Březina state->nested_groups = talloc_zero_array(state, struct sysdb_attrs *,
fc0d76ac54c813c78380ab388f69c69c3620155dPavel Březina num_entries);
fc0d76ac54c813c78380ab388f69c69c3620155dPavel Březina if (state->nested_groups == NULL) {
fc0d76ac54c813c78380ab388f69c69c3620155dPavel Březina ret = ENOMEM;
fc0d76ac54c813c78380ab388f69c69c3620155dPavel Březina goto done;
d9a000b54a23fd4a58481b864175b88a8a3f7949Pavel Březina }
d9a000b54a23fd4a58481b864175b88a8a3f7949Pavel Březina
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek PROBE(SDAP_NESTED_GROUP_DEREF_PROCESS_PRE);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina for (i = 0; i < num_entries; i++) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = sysdb_attrs_get_string(entries[i]->attrs,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina SYSDB_ORIG_DN, &orig_dn);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "The entry has no originalDN\n");
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* Ensure that all members returned from the deref request are included
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina * in the member processing. Sometimes we will get more results back
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina * from deref/asq than we got from the initial lookup, as is the case
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina * with Active Directory and its range retrieval mechanism.
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina member_found = false;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina for (j = 0; j < members->num_values; j++) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* FIXME: This is inefficient for very large sets of groups */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina member_dn = (const char *)members->values[j].data;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (strcasecmp(orig_dn, member_dn) == 0) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina member_found = true;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina break;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (!member_found) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* Append newly found member to member list.
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina * Changes in state->members will propagate into sysdb_attrs of
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina * the group. */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->members->values = talloc_realloc(members, members->values,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct ldb_val,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina members->num_values + 1);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (members->values == NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = ENOMEM;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina members->values[members->num_values].data =
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina (uint8_t *)talloc_strdup(members->values, orig_dn);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (members->values[members->num_values].data == NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = ENOMEM;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina members->values[members->num_values].length = strlen(orig_dn);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina members->num_values++;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (entries[i]->map == opts->user_map) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* we found a user */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* skip the user if it is not amongst configured search bases */
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozek if (!sdap_nested_member_is_user(state->group_ctx, orig_dn, NULL)) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina continue;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* save user in hash table */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = sdap_nested_group_hash_user(state->group_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina entries[i]->attrs);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret != EOK && ret != EEXIST) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Unable to save user in hash table "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "[%d]: %s\n", ret, strerror(ret));
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina } else if (entries[i]->map == opts->group_map) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* we found a group */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* skip the group if we have reached the nesting limit */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (state->nesting_level >= state->group_ctx->max_nesting_level) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_ALL, "[%s] is outside nesting limit "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "(level %d), skipping\n", orig_dn, state->nesting_level);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina continue;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* skip the group if it is not amongst configured search bases */
55206e06bcfa0322cd817d34457e330545d6b877Jakub Hrozek if (!sdap_nested_member_is_group(state->group_ctx, orig_dn, NULL)) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina continue;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* save group in hash table */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = sdap_nested_group_hash_group(state->group_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina entries[i]->attrs);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret == EEXIST) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina continue;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina } else if (ret != EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Unable to save group in hash table "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "[%d]: %s\n", ret, strerror(ret));
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* remember the group for later processing */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->nested_groups[state->num_groups] = entries[i]->attrs;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->num_groups++;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina } else {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* this should never happen, but if it does, do not loop forever */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina DEBUG(SSSDBG_MINOR_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Entry does not match any known map, skipping\n");
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina continue;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek PROBE(SDAP_NESTED_GROUP_DEREF_PROCESS_POST);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
d9a000b54a23fd4a58481b864175b88a8a3f7949Pavel Březina /* adjust size of nested groups array */
e6dee5182d07e3fdbcdfe5b1b3d36f1d26672223Pavel Březina if (state->num_groups > 0) {
e6dee5182d07e3fdbcdfe5b1b3d36f1d26672223Pavel Březina state->nested_groups = talloc_realloc(state, state->nested_groups,
e6dee5182d07e3fdbcdfe5b1b3d36f1d26672223Pavel Březina struct sysdb_attrs *,
e6dee5182d07e3fdbcdfe5b1b3d36f1d26672223Pavel Březina state->num_groups);
e6dee5182d07e3fdbcdfe5b1b3d36f1d26672223Pavel Březina if (state->nested_groups == NULL) {
e6dee5182d07e3fdbcdfe5b1b3d36f1d26672223Pavel Březina ret = ENOMEM;
e6dee5182d07e3fdbcdfe5b1b3d36f1d26672223Pavel Březina goto done;
e6dee5182d07e3fdbcdfe5b1b3d36f1d26672223Pavel Březina }
e6dee5182d07e3fdbcdfe5b1b3d36f1d26672223Pavel Březina } else {
e6dee5182d07e3fdbcdfe5b1b3d36f1d26672223Pavel Březina talloc_zfree(state->nested_groups);
d9a000b54a23fd4a58481b864175b88a8a3f7949Pavel Březina }
d9a000b54a23fd4a58481b864175b88a8a3f7949Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = EOK;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinadone:
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return ret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic void sdap_nested_group_deref_direct_done(struct tevent_req *subreq)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct sdap_nested_group_deref_state *state = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_req *req = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina errno_t ret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina req = tevent_req_callback_data(subreq, struct tevent_req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state = tevent_req_data(req, struct sdap_nested_group_deref_state);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* process direct members */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = sdap_nested_group_deref_direct_process(subreq);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina talloc_zfree(subreq);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Error processing direct membership "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "[%d]: %s\n", ret, strerror(ret));
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* we have processed all direct members,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina * now recurse and process nested groups */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina subreq = sdap_nested_group_recurse_send(state, state->ev,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->group_ctx,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->nested_groups,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->num_groups,
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina state->nesting_level + 1);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (subreq == NULL) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = ENOMEM;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina goto done;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_set_callback(subreq, sdap_nested_group_deref_done, req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = EAGAIN;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinadone:
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret == EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* tevent_req_error() cannot cope with EOK */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "We should not get here with EOK\n");
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_error(req, EINVAL);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina } else if (ret != EAGAIN) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_error(req, ret);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic void sdap_nested_group_deref_done(struct tevent_req *subreq)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina struct tevent_req *req = NULL;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina errno_t ret;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina req = tevent_req_callback_data(subreq, struct tevent_req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina /* process nested groups */
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina ret = sdap_nested_group_recurse_recv(subreq);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina talloc_zfree(subreq);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina if (ret == EOK) {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_done(req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina } else {
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina tevent_req_error(req, ret);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina }
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březinastatic errno_t sdap_nested_group_deref_recv(struct tevent_req *req)
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina{
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek PROBE(SDAP_NESTED_GROUP_DEREF_RECV);
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina TEVENT_REQ_RETURN_ON_ERROR(req);
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina return EOK;
02b2c042d0c2ace289583c8e5e4ead1eff481376Pavel Březina}
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozekstruct sdap_ext_member {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct sdap_external_missing_member *missing_mem;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek const char *ext_member_attr;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek enum sysdb_member_type member_type;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct sss_domain_info *dom;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct sysdb_attrs *attrs;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek};
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozekstruct sdap_nested_group_lookup_external_state {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct tevent_context *ev;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct sdap_ext_member_ctx *ext_ctx;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct sss_domain_info *group_dom;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek hash_table_t *missing_external;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek hash_entry_t *entries;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek unsigned long n_entries;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek unsigned long eniter;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct sdap_ext_member *ext_members;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ext_member_send_fn_t ext_member_resolve_send;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ext_member_recv_fn_t ext_member_resolve_recv;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek};
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozekstatic errno_t
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozeksdap_nested_group_lookup_external_step(struct tevent_req *req);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozekstatic void
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozeksdap_nested_group_lookup_external_done(struct tevent_req *subreq);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozekstatic errno_t
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozeksdap_nested_group_lookup_external_link(struct tevent_req *req);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozekstatic errno_t
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozeksdap_nested_group_lookup_external_link_member(
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct sdap_nested_group_lookup_external_state *state,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct sdap_ext_member *member);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozekstatic errno_t
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozeksdap_nested_group_memberof_dn_by_original_dn(
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek TALLOC_CTX *mem_ctx,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct sss_domain_info *group_dom,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek const char *original_dn,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek const char ***_parents);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozekstruct tevent_req *
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozeksdap_nested_group_lookup_external_send(TALLOC_CTX *mem_ctx,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct tevent_context *ev,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct sss_domain_info *group_dom,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct sdap_ext_member_ctx *ext_ctx,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek hash_table_t *missing_external)
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek{
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct sdap_nested_group_lookup_external_state *state = NULL;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct tevent_req *req = NULL;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek errno_t ret;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek req = tevent_req_create(mem_ctx, &state,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct sdap_nested_group_lookup_external_state);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (req == NULL) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "tevent_req_create() failed\n");
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek return NULL;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek state->ev = ev;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek state->group_dom = group_dom;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek state->ext_ctx = ext_ctx;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek state->missing_external = missing_external;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (state->ext_ctx->ext_member_resolve_send == NULL
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek || state->ext_ctx->ext_member_resolve_recv == NULL) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "Wrong private context\n");
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ret = EINVAL;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek goto immediately;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ret = hash_entries(state->missing_external,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek &state->n_entries, &state->entries);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (ret != HASH_SUCCESS) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "hash_entries returned %d\n", ret);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ret = EIO;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek goto immediately;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek state->eniter = 0;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek state->ext_members = talloc_zero_array(state,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct sdap_ext_member,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek state->n_entries);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (state->ext_members == NULL) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ret = ENOMEM;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek goto immediately;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ret = sdap_nested_group_lookup_external_step(req);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (ret != EAGAIN) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek goto immediately;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek return req;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozekimmediately:
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (ret == EOK) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek tevent_req_done(req);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek } else {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek tevent_req_error(req, ret);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek tevent_req_post(req, ev);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek return req;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek}
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozekstatic errno_t
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozeksdap_nested_group_lookup_external_step(struct tevent_req *req)
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek{
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct tevent_req *subreq = NULL;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct sdap_nested_group_lookup_external_state *state = NULL;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek state = tevent_req_data(req,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct sdap_nested_group_lookup_external_state);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek subreq = state->ext_ctx->ext_member_resolve_send(state,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek state->ev,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek state->entries[state->eniter].key.str,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek state->ext_ctx->pvt);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (subreq == NULL) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek return ENOMEM;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek DEBUG(SSSDBG_TRACE_FUNC, "Refreshing member %lu/%lu\n",
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek state->eniter, state->n_entries);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek tevent_req_set_callback(subreq,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek sdap_nested_group_lookup_external_done,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek req);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek return EAGAIN;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek}
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozekstatic void
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozeksdap_nested_group_lookup_external_done(struct tevent_req *subreq)
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek{
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek errno_t ret;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct tevent_req *req = NULL;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct sdap_nested_group_lookup_external_state *state = NULL;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek enum sysdb_member_type member_type;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct sysdb_attrs *member;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct sss_domain_info *member_dom;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek req = tevent_req_callback_data(subreq, struct tevent_req);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek state = tevent_req_data(req,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct sdap_nested_group_lookup_external_state);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ret = state->ext_ctx->ext_member_resolve_recv(state, subreq,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek &member_type,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek &member_dom,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek &member);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek talloc_free(subreq);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (ret == EOK) {
c6bda70d6131b5e8cd760ad690fae001d1765547Jakub Hrozek DEBUG(SSSDBG_TRACE_FUNC, "Refreshed member %lu\n", state->eniter);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek state->ext_members[state->eniter].missing_mem = \
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek state->entries[state->eniter].value.ptr;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek state->ext_members[state->eniter].dom = member_dom;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek state->ext_members[state->eniter].ext_member_attr = \
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek talloc_steal(state->ext_members,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek state->entries[state->eniter].key.str);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek state->ext_members[state->eniter].member_type = member_type;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek state->ext_members[state->eniter].attrs = \
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek talloc_steal(state->ext_members, member);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek state->eniter++;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (state->eniter >= state->n_entries) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek DEBUG(SSSDBG_TRACE_FUNC, "All external members processed\n");
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ret = sdap_nested_group_lookup_external_link(req);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (ret != EOK) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek tevent_req_error(req, ret);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek return;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek tevent_req_done(req);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek return;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ret = sdap_nested_group_lookup_external_step(req);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (ret != EOK && ret != EAGAIN) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek tevent_req_error(req, ret);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek return;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek return;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek}
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozekstatic errno_t
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozeksdap_nested_group_lookup_external_link(struct tevent_req *req)
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek{
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek errno_t ret, tret;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek bool in_transaction = false;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct sdap_nested_group_lookup_external_state *state = NULL;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek state = tevent_req_data(req,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct sdap_nested_group_lookup_external_state);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ret = sysdb_transaction_start(state->group_dom->sysdb);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (ret != EOK) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "Failed to start transaction\n");
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek goto fail;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek in_transaction = true;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek for (size_t i = 0; i < state->eniter; i++) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (state->ext_members[i].attrs == NULL) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE, "The member %s could not be resolved\n",
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek state->ext_members[i].ext_member_attr);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek continue;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ret = sdap_nested_group_lookup_external_link_member(state,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek &state->ext_members[i]);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (ret != EOK) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek goto fail;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ret = sysdb_transaction_commit(state->group_dom->sysdb);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (ret != EOK) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "Failed to commit transaction\n");
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek goto fail;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek in_transaction = false;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek return EOK;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozekfail:
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (in_transaction) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek tret = sysdb_transaction_cancel(state->group_dom->sysdb);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (tret != EOK) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "Failed to cancel transaction\n");
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek return EFAULT;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek}
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozekstatic errno_t
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozeksdap_nested_group_lookup_external_link_member(
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct sdap_nested_group_lookup_external_state *state,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct sdap_ext_member *member)
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek{
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek const char *name;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek int ret;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek const char **parents = NULL;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek size_t i;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek TALLOC_CTX *tmp_ctx;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek const char *orig_dn;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek tmp_ctx = talloc_new(state);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (tmp_ctx == NULL) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek return ENOMEM;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ret = sysdb_attrs_get_string(member->attrs, SYSDB_NAME, &name);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (ret != EOK) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "No name for a user\n");
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek goto done;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek /* This only works because the groups were saved in a previous
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek * transaction */
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek for (i=0; i < member->missing_mem->parent_dn_idx; i++) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek orig_dn = member->missing_mem->parent_group_dns[i];
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek DEBUG(SSSDBG_TRACE_INTERNAL,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek "Linking external members %s from domain %s to parents of %s\n",
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek name, member->dom->name, orig_dn);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ret = sdap_nested_group_memberof_dn_by_original_dn(tmp_ctx,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek state->group_dom,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek orig_dn,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek &parents);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (ret != EOK) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek "Cannot find parents of %s\n", orig_dn);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek continue;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek /* We don't have to remove the members here, since all members attributes
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek * are always written anew
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek */
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ret = sysdb_update_members_dn(member->dom, name, member->member_type,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek parents, NULL);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (ret != EOK) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "Cannot link %s@%s to its parents\n",
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek name, member->dom->name);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek goto done;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ret = EOK;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozekdone:
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek talloc_free(tmp_ctx);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek return ret;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek}
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozekstatic errno_t
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozeksdap_nested_group_memberof_dn_by_original_dn(
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek TALLOC_CTX *mem_ctx,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct sss_domain_info *group_dom,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek const char *original_dn,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek const char ***_parents)
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek{
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek errno_t ret;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek const char *attrs[] = { SYSDB_NAME,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek SYSDB_MEMBEROF,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek NULL };
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct ldb_message **msgs = NULL;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek size_t count;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek TALLOC_CTX *tmp_ctx;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct ldb_message_element *memberof;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek const char **parents;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek tmp_ctx = talloc_new(mem_ctx);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (tmp_ctx == NULL) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek return ENOMEM;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
4c508463be960682cf94b4e5a39be2f8f49067c8Fabiano Fidêncio ret = sysdb_search_groups_by_orig_dn(tmp_ctx, group_dom, original_dn,
4c508463be960682cf94b4e5a39be2f8f49067c8Fabiano Fidêncio attrs, &count, &msgs);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (ret != EOK) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek goto done;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (count != 1) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek "More than one entry found by originalDN?\n");
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek goto done;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek memberof = ldb_msg_find_element(msgs[0], SYSDB_MEMBEROF);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (memberof == NULL || memberof->num_values == 0) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek "The external group is not a member of any groups\n");
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ret = ENOENT;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek goto done;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek parents = talloc_zero_array(tmp_ctx,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek const char *,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek memberof->num_values + 1);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (parents == NULL) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ret = ENOMEM;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek goto done;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek for (size_t i = 0; i < memberof->num_values; i++) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek parents[i] = talloc_strdup(parents,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek (const char *) memberof->values[i].data);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek if (parents[i] == NULL) {
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ret = ENOMEM;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek goto done;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek }
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek *_parents = talloc_steal(mem_ctx, parents);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek ret = EOK;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozekdone:
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek talloc_free(tmp_ctx);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek return ret;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek}
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozekerrno_t
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozeksdap_nested_group_lookup_external_recv(TALLOC_CTX *mem_ctx,
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek struct tevent_req *req)
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek{
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek TEVENT_REQ_RETURN_ON_ERROR(req);
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek return EOK;
c32266e79f9d4bebd0c31eaa8d6fa26050e7fb3eJakub Hrozek}