sdap_async_groups.c revision 99c0cfdc5f065ba38f1ee91701d1d27f9e4fdb96
60be96a6bed14ee4d7625e3d73040a74ca26321eCodruta Girlea Async LDAP Helper routines - retrieving groups
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu Prodescu Copyright (C) Simo Sorce <ssorce@redhat.com> - 2009
cb1bcdcebd18280e73151a05cf9846b940674518Codruta Girlea Copyright (C) 2010, Ralf Haferkamp <rhafer@suse.de>, Novell Inc.
60be96a6bed14ee4d7625e3d73040a74ca26321eCodruta Girlea Copyright (C) Jan Zeleny <jzeleny@redhat.com> - 2011
60be96a6bed14ee4d7625e3d73040a74ca26321eCodruta Girlea This program is free software; you can redistribute it and/or modify
60be96a6bed14ee4d7625e3d73040a74ca26321eCodruta Girlea it under the terms of the GNU General Public License as published by
60be96a6bed14ee4d7625e3d73040a74ca26321eCodruta Girlea the Free Software Foundation; either version 3 of the License, or
60be96a6bed14ee4d7625e3d73040a74ca26321eCodruta Girlea (at your option) any later version.
60be96a6bed14ee4d7625e3d73040a74ca26321eCodruta Girlea This program is distributed in the hope that it will be useful,
60be96a6bed14ee4d7625e3d73040a74ca26321eCodruta Girlea but WITHOUT ANY WARRANTY; without even the implied warranty of
60be96a6bed14ee4d7625e3d73040a74ca26321eCodruta Girlea MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7857a35e3af533dfbd0f0e18638ebd211e6358a0Christian Maeder GNU General Public License for more details.
60be96a6bed14ee4d7625e3d73040a74ca26321eCodruta Girlea You should have received a copy of the GNU General Public License
cb1bcdcebd18280e73151a05cf9846b940674518Codruta Girlea along with this program. If not, see <http://www.gnu.org/licenses/>.
60be96a6bed14ee4d7625e3d73040a74ca26321eCodruta Girlea#include "providers/ldap/sdap_async_private.h"
60be96a6bed14ee4d7625e3d73040a74ca26321eCodruta Girlea/* ==Group-Parsing Routines=============================================== */
fd1c864a3dec70aa22ecb2bc85816ec8251c6decCodruta Girleastatic int sdap_find_entry_by_origDN(TALLOC_CTX *memctx,
cb1bcdcebd18280e73151a05cf9846b940674518Codruta Girlea ret = sss_filter_sanitize(tmpctx, orig_dn, &sanitized_dn);
cb5be4f31df88b8137ef3cabf4e8b0ddec52f351Christian Maeder filter = talloc_asprintf(tmpctx, "%s=%s", SYSDB_ORIG_DN, sanitized_dn);
2025793bdf95b956b34761af691fe9bde01f6d83Christian Maeder base_dn = sysdb_domain_dn(ctx, tmpctx, domain);
cb1bcdcebd18280e73151a05cf9846b940674518Codruta Girlea DEBUG(9, ("Searching cache for [%s].\n", sanitized_dn));
cb1bcdcebd18280e73151a05cf9846b940674518Codruta Girlea base_dn, LDB_SCOPE_SUBTREE, filter, no_attrs,
2025793bdf95b956b34761af691fe9bde01f6d83Christian Maeder *localdn = talloc_strdup(memctx, ldb_dn_get_linearized(msgs[0]->dn));
f588d2cfbdd1e6d4855df164fce25cf7db1a8e2dChristian Maedersdap_get_members_with_primary_gid(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb,
d6c6b2543c509ec7f6213e4cba675d96304a7fd6Christian Maeder static const char *search_attrs[] = { SYSDB_NAME, NULL };
f588d2cfbdd1e6d4855df164fce25cf7db1a8e2dChristian Maeder /* Don't search if the group is non-posix */
f588d2cfbdd1e6d4855df164fce25cf7db1a8e2dChristian Maeder filter = talloc_asprintf(mem_ctx, "(%s=%llu)", SYSDB_GIDNUM,
7857a35e3af533dfbd0f0e18638ebd211e6358a0Christian Maeder (unsigned long long) gid);
417437c97b9f3ef102275ebd1e3d015b52ef6201Christian Maeder ret = sysdb_search_users(mem_ctx, sysdb, filter,
9e4febfd2eb81ca73c9b6a6a3c40017e6fb99390Mihaela Turcu localdn = talloc_array(mem_ctx, char *, count);
9e4febfd2eb81ca73c9b6a6a3c40017e6fb99390Mihaela Turcu for (i=0; i < count; i++) {
9e4febfd2eb81ca73c9b6a6a3c40017e6fb99390Mihaela Turcusdap_dn_by_primary_gid(TALLOC_CTX *mem_ctx, struct sysdb_attrs *ldap_attrs,
9e4febfd2eb81ca73c9b6a6a3c40017e6fb99390Mihaela Turcu struct sysdb_ctx *sysdb, struct sdap_options *opts,
9e4febfd2eb81ca73c9b6a6a3c40017e6fb99390Mihaela Turcu /* Non-posix AD group. Skip. */
9e4febfd2eb81ca73c9b6a6a3c40017e6fb99390Mihaela Turcu ret = sdap_get_members_with_primary_gid(mem_ctx, sysdb, gid,
int num_values,
char **userdns,
int ret;
if (ret) {
goto done;
goto done;
for (i = 0; i < num_values; i++) {
goto done;
goto done;
for (i=0; i < nuserdns; i++) {
done:
return ret;
static errno_t
const char *name,
bool posix_group,
if (!posix_group) {
if (ret) {
return ret;
if (ret) {
return ret;
return ret;
static errno_t
bool populate_members,
bool store_original_member,
int hret;
return ret;
&memberel);
return ret;
if (store_original_member) {
if (ret) {
return ret;
if (populate_members) {
return ret;
return ret;
return ENOMEM;
return EFAULT;
return ENOMEM;
return EOK;
bool populate_members,
bool store_original_member,
char **_usn_value,
bool posix_group;
char *sid_str;
if (!tmpctx) {
goto done;
goto done;
&name);
goto done;
if (use_id_mapping) {
posix_group = true;
&sid_str);
goto done;
goto done;
goto done;
goto done;
if (ret) {
goto done;
posix_group = true;
goto done;
goto done;
&gid);
goto done;
if (posix_group) {
name));
goto done;
goto done;
goto done;
if (ret) {
goto done;
name));
if (ret) {
goto done;
if (!usn_value) {
goto done;
goto done;
goto done;
if (ret) {
goto done;
if (_usn_value) {
done:
if (ret) {
return ret;
const char *name;
int ret;
&name);
goto fail;
goto fail;
goto fail;
if (!group_attrs) {
goto fail;
if (ret) {
goto fail;
return EOK;
fail:
return ret;
int num_groups,
bool populate_members,
char **_usn_value)
char *usn_value;
bool twopass;
bool has_nesting = false;
int ret;
int nsaved_groups = 0;
bool in_transaction = false;
case SDAP_SCHEMA_RFC2307:
twopass = false;
case SDAP_SCHEMA_RFC2307BIS:
case SDAP_SCHEMA_IPA_V1:
case SDAP_SCHEMA_AD:
twopass = true;
has_nesting = true;
return EINVAL;
if (!tmpctx) {
return ENOMEM;
if (ret) {
goto done;
in_transaction = true;
if (!saved_groups) {
goto done;
for (i = 0; i < num_groups; i++) {
if (ret) {
if (usn_value) {
if (higher_usn) {
for (i = 0; i < nsaved_groups; i++) {
if (ret) {
if (ret) {
goto done;
in_transaction = false;
if (_usn_value) {
done:
if (in_transaction) {
return ret;
struct sdap_process_group_state {
char **queued_members;
int queue_len;
const char **attrs;
const char *filter;
bool enumeration;
return ENOMEM;
return ENOMEM;
return EOK;
bool enumeration)
const char **attrs;
char* filter;
int ret;
struct sdap_process_group_state);
if (ret) {
goto done;
if (!filter) {
return NULL;
&el);
if (ret) {
goto done;
goto done;
&ghostel);
if (ret) {
goto done;
&el);
goto done;
goto done;
goto done;
case SDAP_SCHEMA_RFC2307:
case SDAP_SCHEMA_IPA_V1:
case SDAP_SCHEMA_AD:
case SDAP_SCHEMA_RFC2307BIS:
done:
return req;
char *user_dn,
int num_users)
return ENOMEM;
if (!subreq) {
return ENOMEM;
return EOK;
char *member_dn;
char *strdn;
int ret;
&strdn);
i, member_dn));
return ret;
return ret;
return ret;
const char *username)
return ENOMEM;
return EOK;
int ret;
const char *filter;
const char *username;
const char *user_dn;
if (!filter) {
goto done;
goto done;
goto done;
return ENOMEM;
done:
return ret;
char *member_name;
char *userdn;
int ret;
return ENOMEM;
goto done;
i, member_name));
i, member_name));
goto done;
goto done;
done:
return ret;
int ret;
if (ret) {
goto next;
goto next;
if (ret) {
goto next;
next:
if (ret) {
if (!subreq) {
&el);
return EOK;
struct sdap_get_groups_state {
const char **attrs;
const char *base_filter;
char *filter;
int timeout;
bool enumeration;
char *higher_usn;
const char **attrs,
const char *filter,
int timeout,
bool enumeration)
if (!search_bases) {
goto done;
done:
return req;
return ENOMEM;
if (!subreq) {
return ENOMEM;
return EOK;
int ret;
bool next_base = false;
bool enable_deref = true;
if (ret) {
next_base = true;
if (count > 0) {
struct sysdb_attrs *,
for (i = 0; i < count; i++) {
if (next_base) {
* for RFC2307bis/FreeIPA/ActiveDirectory
enable_deref = true;
enable_deref = false;
if (enable_deref) {
enable_deref = false;
if (!subreq) {
if (!subreq) {
req);
if (ret) {
if (!subreq) {
int ret;
if (ret) {
if (ret) {
int num_users,
struct sdap_get_groups_state);
size_t i;
goto done;
goto done;
if (!tmp_ctx) {
goto done;
&ghosts);
goto done;
goto done;
for (i = 0; i < count; i++) {
&orig_dn_el);
goto done;
goto done;
done:
struct sdap_get_groups_state);
if (usn_value) {
return EOK;
int hret;
unsigned long user_count;
unsigned long group_count;
bool in_transaction = false;
struct tevent_req);
struct sdap_get_groups_state);
goto fail;
goto fail;
if (user_count) {
if (!users) {
goto fail;
for (i = 0; i < user_count; i++) {
goto fail;
if (!groups) {
goto fail;
for (i = 0; i < group_count; i++) {
goto fail;
in_transaction = true;
goto fail;
goto fail;
goto fail;
in_transaction = false;
fail:
if (in_transaction) {
int num_users,
const char *username;
char *clean_orig_dn;
const char *original_dn;
char *filter;
const char *sysdb_name;
bool in_transaction = false;
return EINVAL;
if (num_users == 0) {
return EOK;
goto done;
if (ret) {
goto done;
in_transaction = true;
for (i = 0; i < num_users; i++) {
&username);
goto done;
goto done;
if (!filter) {
goto done;
goto done;
if (!attrs) {
goto done;
goto done;
if (ret) {
goto done;
in_transaction = false;
done:
if (in_transaction) {
return ret;
static errno_t
struct sdap_nested_get_user_state {
static struct tevent_req *
const char *user_dn,
const char *search_bases_filter)
const char **sdap_attrs;
const char *filter;
struct sdap_nested_get_user_state);
if (!req) {
return NULL;
goto immediate;
if (!sdap_attrs) {
goto immediate;
if (!filter) {
goto immediate;
if (!subreq) {
goto immediate;
return req;
if (ret) {
return req;
static errno_t
char *name;
const char *rdn_name;
const char *users_comp_name;
const char *acct_comp_name;
goto done;
goto done;
goto done;
goto done;
goto done;
goto done;
goto done;
goto done;
if (!reply) {
goto done;
if (!reply[0]) {
goto done;
goto done;
goto done;
goto done;
goto done;
done:
return ret;
struct sdap_nested_get_user_state);
static errno_t
struct sdap_nested_get_user_state);
if (_count) {
if (_replies) {
return EOK;
struct sdap_deref_ctx {
const char *orig_dn;
char **expired_users;
char **expired_groups;
char **missing_dns;
int deref_threshold;
struct sdap_nested_group_ctx {
char *member_dn;
bool enable_deref;
int hret;
const char *groupname;
if (!req) {
return NULL;
goto immediate;
&groupname);
goto immediate;
goto immediate;
goto immediate;
&gid);
goto immediate;
goto immediate;
} else if (ret) {
goto immediate;
goto immediate;
goto immediate;
goto immediate;
return req;
return req;
char *member_dn,
switch(mtype) {
case SYSDB_MEMBER_GROUP:
missing++;
case SYSDB_MEMBER_USER:
missing++;
goto done;
missing++;
if (missing == 0) {
goto done;
return EAGAIN;
done:
return ret;
switch(mtype) {
case SYSDB_MEMBER_GROUP:
case SYSDB_MEMBER_USER:
goto error;
return EAGAIN;
goto error;
return EAGAIN;
return ret;
static errno_t
bool has_key = false;
return EOK;
return ENOMEM;
if (has_key) {
} while (has_key);
return ENOENT;
static errno_t
char *dn,
char *member_dn;
NULL };
char *filter;
goto fail;
if (!filter) {
goto fail;
goto fail;
goto fail;
if (!user_uid) {
goto fail;
goto done;
goto done;
goto fail;
goto fail;
goto done;
goto done;
done:
return ret;
fail:
return ret;
static errno_t
const char **sdap_attrs;
int ret;
int timeout;
if (!sdap_attrs) {
goto fail;
if (!subreq) {
goto fail;
return EOK;
fail:
return ret;
return EAGAIN;
return EAGAIN;
return EAGAIN;
done:
return ret;
&search_bases_filter)) {
return ret;
return EOK;
if (!subreq) {
return EIO;
return EOK;
const char **sdap_attrs;
char *filter;
&search_bases_filter)) {
return ret;
return EOK;
return ret;
if (!filter) {
return ENOMEM;
if (!subreq) {
return EIO;
return EOK;
int hret;
if (!tmp_ctx) {
goto done;
goto skip;
goto done;
goto done;
skip:
done:
if (!tmp_ctx) {
goto done;
goto skip;
goto done;
if (!subreq) {
goto done;
skip:
done:
int hret;
if (!tmp_ctx) {
goto done;
goto done;
goto done;
goto done;
done:
static errno_t
static errno_t
int hret;
const char *orig_dn;
const char *tmp_name;
size_t i;
return ret;
orig_dn) == 0) break;
struct ldb_val,
return ENOMEM;
return ENOMEM;
NULL)) {
&tmp_name);
} else if (ret) {
return EIO;
NULL)) {
req);
return EAGAIN;
return EOK;
return EOK;