f799084b320209cdd71a29e74fff1be054c1d342Christian Maeder Async LDAP Helper routines - retrieving groups
f799084b320209cdd71a29e74fff1be054c1d342Christian Maeder Copyright (C) Simo Sorce <ssorce@redhat.com> - 2009
f799084b320209cdd71a29e74fff1be054c1d342Christian Maeder Copyright (C) 2010, Ralf Haferkamp <rhafer@suse.de>, Novell Inc.
f799084b320209cdd71a29e74fff1be054c1d342Christian Maeder Copyright (C) Jan Zeleny <jzeleny@redhat.com> - 2011
f799084b320209cdd71a29e74fff1be054c1d342Christian Maeder This program is free software; you can redistribute it and/or modify
f799084b320209cdd71a29e74fff1be054c1d342Christian Maeder it under the terms of the GNU General Public License as published by
f799084b320209cdd71a29e74fff1be054c1d342Christian Maeder the Free Software Foundation; either version 3 of the License, or
f799084b320209cdd71a29e74fff1be054c1d342Christian Maeder (at your option) any later version.
f799084b320209cdd71a29e74fff1be054c1d342Christian Maeder This program is distributed in the hope that it will be useful,
f799084b320209cdd71a29e74fff1be054c1d342Christian Maeder but WITHOUT ANY WARRANTY; without even the implied warranty of
3ab1e7a18f3fc3eb004464bc54b7df4483f1f060Christian Maeder MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f799084b320209cdd71a29e74fff1be054c1d342Christian Maeder GNU General Public License for more details.
f799084b320209cdd71a29e74fff1be054c1d342Christian Maeder You should have received a copy of the GNU General Public License
f799084b320209cdd71a29e74fff1be054c1d342Christian Maeder along with this program. If not, see <http://www.gnu.org/licenses/>.
264b794970b6f2bd437f14233f367f1067565728Jian Chun Wang#include "providers/ldap/sdap_async_private.h"
57d9ffd4f0d821632c5dd116a5301c3305599b19Christian Maeder/* ==Group-Parsing Routines=============================================== */
264b794970b6f2bd437f14233f367f1067565728Jian Chun Wangstatic int sdap_find_entry_by_origDN(TALLOC_CTX *memctx,
264b794970b6f2bd437f14233f367f1067565728Jian Chun Wang const char *attrs[] = {SYSDB_OBJECTCLASS, NULL};
264b794970b6f2bd437f14233f367f1067565728Jian Chun Wang ret = sss_filter_sanitize(tmpctx, orig_dn, &sanitized_dn);
03a6bbff551286168d0b15dc53476c2ede4e60d0Christian Maeder filter = talloc_asprintf(tmpctx, "%s=%s", SYSDB_ORIG_DN, sanitized_dn);
f799084b320209cdd71a29e74fff1be054c1d342Christian Maeder DEBUG(SSSDBG_TRACE_ALL, "Searching cache for [%s].\n", sanitized_dn);
0015e1756b734b34d4b550318c078f9a0c585611Christian Maeder *_localdn = talloc_strdup(memctx, ldb_dn_get_linearized(msgs[0]->dn));
0015e1756b734b34d4b550318c078f9a0c585611Christian Maeder objectclass = ldb_msg_find_attr_as_string(msgs[0], SYSDB_OBJECTCLASS,
0015e1756b734b34d4b550318c078f9a0c585611Christian Maeder DEBUG(SSSDBG_OP_FAILURE, "An antry without a %s?\n",
0015e1756b734b34d4b550318c078f9a0c585611Christian Maeder *_is_group = strcmp(SYSDB_GROUP_CLASS, objectclass) == 0;
0015e1756b734b34d4b550318c078f9a0c585611Christian Maedersdap_get_members_with_primary_gid(TALLOC_CTX *mem_ctx,
0015e1756b734b34d4b550318c078f9a0c585611Christian Maeder static const char *search_attrs[] = { SYSDB_NAME, NULL };
0015e1756b734b34d4b550318c078f9a0c585611Christian Maeder /* Don't search if the group is non-posix */
479da8506f391abe070ced2fb93c9759a280fa68Christian Maeder filter = talloc_asprintf(mem_ctx, "(%s=%llu)", SYSDB_GIDNUM,
c4a8059d0469a85bb58c28ac66729ac19d743d3cChristian Maeder (unsigned long long) gid);
d06598e0c310f65ab552ca55626c2f7694ffd5e3Christian Maeder ret = sysdb_search_users(mem_ctx, domain, filter,
50ed946595d60c06f773e73bb22b21f5cf1199caChristian Maeder localdn = talloc_array(mem_ctx, char *, count);
d06598e0c310f65ab552ca55626c2f7694ffd5e3Christian Maeder for (i=0; i < count; i++) {
d06598e0c310f65ab552ca55626c2f7694ffd5e3Christian Maedersdap_dn_by_primary_gid(TALLOC_CTX *mem_ctx, struct sysdb_attrs *ldap_attrs,
d06598e0c310f65ab552ca55626c2f7694ffd5e3Christian Maeder opts->group_map[SDAP_AT_GROUP_GID].sys_name,
f799084b320209cdd71a29e74fff1be054c1d342Christian Maeder /* Non-posix AD group. Skip. */
abcb1baa565c878598d732d0aa7724f474c9265cChristian Maeder ret = sdap_get_members_with_primary_gid(mem_ctx, domain, gid,
f799084b320209cdd71a29e74fff1be054c1d342Christian Maederstatic bool has_member(struct ldb_message_element *member_el,
f799084b320209cdd71a29e74fff1be054c1d342Christian Maeder /* This is bad complexity, but the this loop should only be invoked in
f799084b320209cdd71a29e74fff1be054c1d342Christian Maeder * the very rare scenario of AD POSIX group that is primary group of
f799084b320209cdd71a29e74fff1be054c1d342Christian Maeder * some users but has user member attributes at the same time
f799084b320209cdd71a29e74fff1be054c1d342Christian Maeder if (ldb_msg_find_val(member_el, &val) != NULL) {
f799084b320209cdd71a29e74fff1be054c1d342Christian Maeder return false;
f799084b320209cdd71a29e74fff1be054c1d342Christian Maederstatic void link_pgroup_members(struct sysdb_attrs *group_attrs,
d06598e0c310f65ab552ca55626c2f7694ffd5e3Christian Maeder for (i=0; i < nuserdns; i++) {
479da8506f391abe070ced2fb93c9759a280fa68Christian Maeder "Member %s already included, skipping\n", userdns[i]);
f799084b320209cdd71a29e74fff1be054c1d342Christian Maeder member_el->values[member_el->num_values + j].data = (uint8_t *) \
d06598e0c310f65ab552ca55626c2f7694ffd5e3Christian Maeder member_el->values[member_el->num_values + j].length = \
f799084b320209cdd71a29e74fff1be054c1d342Christian Maederstatic int sdap_fill_memberships(struct sdap_options *opts,
2344f16936f5b31c9530d0cafb3838e9df3f3644Christian Maeder ret = sysdb_attrs_get_el(group_attrs, SYSDB_MEMBER, &el);
f799084b320209cdd71a29e74fff1be054c1d342Christian Maeder DEBUG(SSSDBG_MINOR_FAILURE, "sysdb_attrs_get_el failed\n");
f799084b320209cdd71a29e74fff1be054c1d342Christian Maeder /* Just allocate both big enough to contain all members for now */
f799084b320209cdd71a29e74fff1be054c1d342Christian Maeder el->values = talloc_realloc(group_attrs, el->values, struct ldb_val,
abcb1baa565c878598d732d0aa7724f474c9265cChristian Maeder DEBUG(SSSDBG_MINOR_FAILURE, "No memory to allocate group attrs\n");
690e4ab8f298d9cff3803316cda70ad9b98e9c43Christian Maeder for (i = 0; i < num_values; i++) {
f799084b320209cdd71a29e74fff1be054c1d342Christian Maeder sdom = sdap_domain_get_by_dn(opts, (char *)values[i].data);
NULL);
goto done;
goto done;
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,
return ret;
false, &memberel);
return ENOMEM;
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,
if (!tmpctx) {
goto done;
goto done;
&sid_str);
goto done;
sid_str);
if (subdomain) {
goto done;
posix_group = true;
&need_filter);
goto done;
if (need_filter) {
posix_group = false;
gid = 0;
goto done;
if (posix_group) {
sid_str);
if (use_id_mapping) {
posix_group = true;
goto done;
goto done;
goto done;
if (ret) {
goto done;
posix_group = true;
goto done;
goto done;
&gid);
goto done;
if (posix_group) {
goto done;
goto done;
goto done;
if (ret) {
goto done;
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;
static errno_t
return EINVAL;
return EINVAL;
return EOK;
static errno_t
const char *group_name,
const char *group_sid,
char ***_userdns,
size_t i, n;
return ENOMEM;
goto done;
nuserdns++;
goto done;
done:
return ret;
NULL};
return EOK;
&group_name);
goto fail;
goto fail;
goto fail;
goto fail;
if (!group_attrs) {
goto fail;
if (ret) {
goto fail;
if (ret) {
goto fail;
return EOK;
fail:
return ret;
int num_groups,
bool populate_members,
bool save_orig_member,
char **_usn_value)
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;
return ENOMEM;
return ENOMEM;
return EOK;
static struct tevent_req *
bool enumeration)
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,
unsigned num_users)
return ENOMEM;
if (!subreq) {
return ENOMEM;
return EOK;
&strdn,
&is_group);
i, member_dn);
return ret;
return ret;
return ret;
const char *username)
return ENOMEM;
return EOK;
char *member_name)
goto done;
if (!filter) {
goto done;
goto done;
goto done;
return ENOMEM;
done:
return ret;
return ENOMEM;
return ENOMEM;
goto done;
i, member_name);
i, member_name);
goto done;
goto done;
done:
return ret;
if (ret) {
goto next;
goto next;
if (ret) {
goto next;
goto next;
next:
if (ret) {
if (!subreq) {
&el);
return EOK;
const char **attrs,
const char *filter,
int timeout,
bool no_members)
goto done;
goto done;
goto done;
req);
return req;
done:
return req;
return ENOMEM;
case SDAP_LOOKUP_SINGLE:
case SDAP_LOOKUP_WILDCARD:
need_paging = true;
case SDAP_LOOKUP_ENUMERATE:
need_paging = true;
if (!subreq) {
return ENOMEM;
return EOK;
if (ret) {
count == 0) {
next_base = true;
if (count > 0) {
struct sysdb_attrs *,
if (next_base) {
* for RFC2307bis/FreeIPA/ActiveDirectory
if (!subreq) {
if (!subreq) {
req);
if (ret) {
if (!subreq) {
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;
struct tevent_req);
struct sdap_get_groups_state);
goto fail;
goto fail;
in_transaction = true;
goto fail;
goto fail;
goto fail;
in_transaction = false;
goto fail;
fail:
if (in_transaction) {
struct tevent_req);
struct sdap_get_groups_state);
int num_users,
return EINVAL;
if (num_users == 0) {
return EOK;
goto done;
if (ret) {
goto done;
in_transaction = true;
for (i = 0; i < num_users; i++) {
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;