sdap_async_initgroups.c revision 3ff729e6c8a371e7a52914772816c39ca73c50a9
/*
SSSD
Async LDAP Helper routines - initgroups operation
Copyright (C) Simo Sorce <ssorce@redhat.com> - 2009
Copyright (C) 2010, Ralf Haferkamp <rhafer@suse.de>, Novell Inc.
Copyright (C) Jan Zeleny <jzeleny@redhat.com> - 2011
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "providers/ldap/sdap_async_private.h"
#include "providers/ldap/ldap_common.h"
/* ==Save-fake-group-list=====================================*/
struct sdap_options *opts,
char **groupnames,
struct sysdb_attrs **ldap_groups,
int ldap_groups_count)
{
struct ldb_message *msg;
const char *name;
const char *original_dn;
char **missing;
int ret;
bool in_transaction = false;
bool posix;
/* There are no groups in LDAP but we should add user to groups ?? */
if (ldap_groups_count == 0) return EOK;
if (!missing) {
goto fail;
}
mi = 0;
goto fail;
}
in_transaction = true;
for (i=0; groupnames[i]; i++) {
continue;
i, groupnames[i]));
mi++;
continue;
goto fail;
}
}
/* All groups are cached, nothing to do */
if (mi == 0) {
goto done;
}
for (i=0; missing[i]; i++) {
/* The group is not in sysdb, need to add a fake entry */
&name);
goto fail;
}
posix = true;
&gid);
gid = 0;
posix = false;
} else if (ret) {
goto fail;
}
&original_dn);
if (ret) {
original_dn = NULL;
}
goto fail;
}
break;
}
}
if (ai == ldap_groups_count) {
goto fail;
}
}
done:
goto fail;
}
in_transaction = false;
fail:
if (in_transaction) {
}
return ret;
}
struct sdap_options *opts,
const char *name,
enum sysdb_member_type type,
char **sysdb_grouplist,
struct sysdb_attrs **ldap_groups,
int ldap_groups_count)
{
char **ldap_grouplist = NULL;
char **add_groups;
char **del_groups;
bool in_transaction = false;
if (ldap_groups_count == 0) {
/* No groups for this user in LDAP.
* We need to ensure that there are no groups
* in the sysdb either.
*/
} else {
goto done;
}
}
/* Find the differences between the sysdb and LDAP lists
* Groups in the sysdb only must be removed.
*/
goto done;
}
in_transaction = true;
/* Add fake entries for any groups the user should be added as
* member of but that are not cached in sysdb
*/
if (add_groups && add_groups[0]) {
goto done;
}
}
(const char *const *) add_groups,
(const char *const *) del_groups);
goto done;
}
goto done;
}
in_transaction = false;
done:
if (in_transaction) {
}
}
return ret;
}
/* ==Initgr-call-(groups-a-user-is-member-of)-RFC2307===================== */
struct sdap_initgr_rfc2307_state {
struct tevent_context *ev;
struct sdap_options *opts;
struct sdap_handle *sh;
const char **attrs;
const char *name;
const char *base_filter;
const char *orig_dn;
char *filter;
int timeout;
struct sysdb_attrs **ldap_groups;
struct sdap_search_base **search_bases;
};
struct tevent_context *ev,
struct sdap_options *opts,
struct sdap_handle *sh,
const char *name)
{
struct tevent_req *req;
struct sdap_initgr_rfc2307_state *state;
char *clean_name;
state->ldap_groups_count = 0;
if (!state->search_bases) {
("Initgroups lookup request without a group search base\n"));
goto done;
}
return NULL;
}
return NULL;
}
return NULL;
}
"(&(%s=%s)(objectclass=%s)(%s=*)(&(%s=*)(!(%s=0))))",
if (!state->base_filter) {
return NULL;
}
done:
}
return req;
}
{
struct tevent_req *subreq;
struct sdap_initgr_rfc2307_state *state;
return ENOMEM;
}
("Searching for groups with base [%s]\n",
true);
if (!subreq) {
return ENOMEM;
}
return EOK;
}
{
struct tevent_req *req;
struct sdap_initgr_rfc2307_state *state;
struct sysdb_attrs **ldap_groups;
char **sysdb_grouplist = NULL;
struct ldb_message *msg;
struct ldb_message_element *groups;
const char *attrs[2];
int ret;
int i;
if (ret) {
return;
}
/* Add this batch of groups to the list */
if (count > 0) {
state->ldap_groups =
struct sysdb_attrs *,
if (!state->ldap_groups) {
return;
}
/* Copy the new groups into the list.
*/
for (i = 0; i < count; i++) {
}
}
/* Check for additional search bases, and iterate
* through again.
*/
}
return;
}
/* Search for all groups for which this user is a member */
attrs[0] = SYSDB_MEMBEROF;
return;
}
/* No groups for this user in sysdb currently */
} else {
if (!sysdb_grouplist) {
return;
}
/* Get a list of the groups by groupname only */
for (i=0; i < groups->num_values; i++) {
&sysdb_grouplist[i]);
return;
}
}
}
/* There are no nested groups here so we can just update the
* memberships */
return;
}
}
{
return EOK;
}
static errno_t
struct sdap_options *opts,
struct sysdb_attrs **groups,
unsigned long count)
{
char **groupnamelist = NULL;
bool in_transaction = false;
if (count > 0) {
goto done;
}
}
goto done;
}
in_transaction = true;
goto done;
}
goto done;
}
in_transaction = false;
done:
if (in_transaction) {
}
}
return ret;
}
struct membership_diff {
struct membership_diff *prev;
struct membership_diff *next;
const char *name;
char **add;
char **del;
};
static errno_t
char **ldap_parent_names, char **sysdb_parent_names,
struct membership_diff **_mdiff)
{
struct membership_diff *mdiff;
char **add_groups;
char **del_groups;
if (!tmp_ctx) {
goto done;
}
if (!mdiff) {
goto done;
}
goto done;
}
/* Find the differences between the sysdb and ldap lists
* Groups in ldap only must be added to the sysdb;
* groups in the sysdb only must be removed.
*/
goto done;
}
done:
return ret;
}
/* ==Initgr-call-(groups-a-user-is-member-of)-nested-groups=============== */
struct sdap_initgr_nested_state {
struct tevent_context *ev;
struct sdap_options *opts;
struct sss_domain_info *dom;
struct sdap_handle *sh;
struct sysdb_attrs *user;
const char *username;
const char *orig_dn;
const char **grp_attrs;
struct ldb_message_element *memberof;
char *filter;
char **group_dns;
int cur;
struct sysdb_attrs **groups;
int groups_cur;
};
struct tevent_context *ev,
struct sdap_options *opts,
struct sss_domain_info *dom,
struct sdap_handle *sh,
struct sysdb_attrs *user,
const char **grp_attrs)
{
struct tevent_req *req;
struct sdap_initgr_nested_state *state;
int deref_threshold;
goto immediate;
}
/* We can't find any groups for this user, so we'll
* have to assume there aren't any. Just return
* success here.
*/
goto immediate;
}
goto immediate;
}
state->groups_cur = 0;
} else {
}
return req;
} else {
}
return req;
}
{
int i;
struct tevent_req *subreq;
struct sdap_initgr_nested_state *state;
return ENOMEM;
}
return ENOMEM;
}
}
return ENOMEM;
}
false);
if (!subreq) {
return ENOMEM;
}
return EAGAIN;
}
{
struct tevent_req *subreq;
struct sdap_attr_map_info *maps;
const int num_maps = 1;
const char **sdap_attrs;
int timeout;
struct sdap_initgr_nested_state *state;
if (!subreq) {
goto fail;
}
return EAGAIN;
fail:
return ret;
}
{
struct tevent_req *req;
struct sdap_initgr_nested_state *state;
size_t i;
struct sdap_deref_attrs **deref_result;
&deref_result);
return;
/* Nothing could be dereferenced. Done. */
return;
}
for (i=0; i < num_results; i++) {
deref_result[i]->attrs);
}
}
{
struct tevent_req *req;
struct sdap_initgr_nested_state *state;
struct sysdb_attrs **groups;
int ret;
if (ret) {
return;
}
if (count == 1) {
groups[0]);
state->groups_cur++;
} else {
}
/* note that state->memberof->num_values is the count of original
* memberOf which might not be only groups, but permissions, etc.
* Use state->groups_cur for group index cap */
false);
if (!subreq) {
return;
}
} else {
}
}
static errno_t
static errno_t
static errno_t
{
struct sdap_initgr_nested_state *state;
bool in_transaction = false;
goto fail;
}
in_transaction = true;
/* save the groups if they are not already */
goto fail;
}
/* save the group memberships */
goto fail;
}
/* save the user memberships */
goto fail;
}
goto fail;
}
in_transaction = false;
return;
fail:
if (in_transaction) {
}
}
return;
}
static errno_t
{
state->groups_cur);
}
static errno_t
struct sdap_options *opts,
struct sss_domain_info *dom,
struct sysdb_attrs *group,
struct sysdb_attrs **all_groups,
int groups_count,
struct membership_diff **mdiff);
struct sysdb_attrs *attrs,
struct sysdb_attrs **groups,
int ngroups,
struct sysdb_attrs ***_direct_parents,
int *_ndirect);
static errno_t
{
int i, tret;
struct membership_diff *miter;
bool in_transaction = false;
/* Compute the diffs first in order to keep the transaction as small
* as possible
*/
for (i=0; i < state->groups_cur; i++) {
&miter);
if (ret) {
goto done;
}
}
goto done;
}
in_transaction = true;
goto done;
}
}
goto done;
}
in_transaction = false;
done:
if (in_transaction) {
}
}
return ret;
}
static errno_t
{
int tret;
const char *orig_dn;
char **sysdb_parent_name_list = NULL;
char **ldap_parent_name_list = NULL;
int nparents;
struct sysdb_attrs **ldap_parentlist;
struct ldb_message_element *el;
int i, mi;
char **add_groups;
char **del_groups;
bool in_transaction = false;
if (!tmp_ctx) {
goto done;
}
/* Get direct LDAP parents */
goto done;
}
if (!ldap_parentlist) {
goto done;
}
nparents = 0;
for (i=0; i < state->groups_cur ; i++) {
if (ret) {
goto done;
}
continue;
}
nparents++;
}
}
if (nparents == 0) {
} else {
goto done;
}
}
if (ret) {
goto done;
}
goto done;
}
goto done;
}
in_transaction = true;
(const char *const *) add_groups,
(const char *const *) del_groups);
goto done;
}
goto done;
}
in_transaction = false;
done:
if (in_transaction) {
}
}
return ret;
}
static errno_t
struct sdap_options *opts,
struct sss_domain_info *dom,
struct sysdb_attrs *group,
struct sysdb_attrs **all_groups,
int groups_count,
struct membership_diff **_mdiff)
{
struct membership_diff *mdiff;
const char *group_name;
struct sysdb_attrs **ldap_parentlist;
int parents_count;
char **ldap_parent_names_list = NULL;
char **sysdb_parents_names_list = NULL;
if (!tmp_ctx) {
goto done;
}
/* Get direct sysdb parents */
&group_name);
goto done;
}
if (ret) {
goto done;
}
/* For each group, filter only parents from full set */
goto done;
}
if (parents_count > 0) {
goto done;
}
}
goto done;
}
done:
return ret;
}
struct sysdb_attrs *attrs,
struct sysdb_attrs **groups,
int ngroups,
struct sysdb_attrs ***_direct_parents,
int *_ndirect)
{
struct ldb_message_element *member;
int i, mi;
int ret;
const char *orig_dn;
int ndirect;
struct sysdb_attrs **direct_groups;
ngroups + 1);
if (!direct_groups) {
goto done;
}
ndirect = 0;
goto done;
}
/* FIXME - Filter only parents from full set to avoid searching
* through all members of huge groups. That requires asking for memberOf
* with the group LDAP search
*/
/* Filter only direct parents from the list of all groups */
for (i=0; i < ngroups; i++) {
if (ret) {
continue;
}
continue;
}
ndirect++;
}
}
done:
return ret;
}
{
return EOK;
}
/* ==Initgr-call-(groups-a-user-is-member-of)-RFC2307-BIS================= */
struct sdap_initgr_rfc2307bis_state {
struct tevent_context *ev;
struct sdap_options *opts;
struct sss_domain_info *dom;
struct sdap_handle *sh;
const char *name;
const char *base_filter;
char *filter;
const char **attrs;
const char *orig_dn;
int timeout;
struct sdap_search_base **search_bases;
struct sysdb_attrs **direct_groups;
};
struct sdap_nested_group {
struct sysdb_attrs *group;
struct sysdb_attrs **ldap_parents;
};
struct sdap_initgr_rfc2307bis_state *state);
struct tevent_req *rfc2307bis_nested_groups_send(
static struct tevent_req *sdap_initgr_rfc2307bis_send(
struct tevent_context *ev,
struct sdap_options *opts,
struct sss_domain_info *dom,
struct sdap_handle *sh,
const char *name,
const char *orig_dn)
{
struct tevent_req *req;
struct sdap_initgr_rfc2307bis_state *state;
char *clean_orig_dn;
state->num_direct_parents = 0;
if (!state->search_bases) {
("Initgroups lookup request without a group search base\n"));
goto done;
}
return NULL;
}
state->base_filter =
if (!state->base_filter) {
goto done;
}
done:
}
return req;
}
{
struct tevent_req *subreq;
struct sdap_initgr_rfc2307bis_state *state;
return ENOMEM;
}
("Searching for parent groups for user [%s] with base [%s]\n",
true);
if (!subreq) {
return ENOMEM;
}
return EOK;
}
{
struct tevent_req *req;
struct sdap_initgr_rfc2307bis_state *state;
struct sysdb_attrs **ldap_groups;
size_t i;
int ret;
&count,
&ldap_groups);
if (ret) {
return;
}
/* Add this batch of groups to the list */
if (count > 0) {
struct sysdb_attrs *,
if (!state->direct_groups) {
return;
}
/* Copy the new groups into the list.
*/
for (i = 0; i < count; i++) {
}
}
/* Check for additional search bases, and iterate
* through again.
*/
}
return;
}
if (state->num_direct_parents == 0) {
/* Start a transaction to look up the groups in the sysdb
* and update them with LDAP data
*/
} else {
}
return;
}
state->group_hash, 0);
if (!subreq) {
return;
}
}
static errno_t
static errno_t
{
struct tevent_req *req =
struct sdap_initgr_rfc2307bis_state *state =
bool in_transaction = false;
return;
}
goto fail;
}
in_transaction = true;
/* save the groups if they are not cached */
goto fail;
}
/* save the group membership */
goto fail;
}
/* save the user memberships */
goto fail;
}
goto fail;
}
in_transaction = false;
return;
fail:
if (in_transaction) {
}
}
return;
}
{
return EOK;
}
struct rfc2307bis_group_memberships_state {
struct sdap_options *opts;
struct sss_domain_info *dom;
struct membership_diff *memberships;
int ret;
};
static errno_t
{
unsigned long count;
int hret, i;
struct sdap_nested_group *gr;
if (hret != HASH_SUCCESS) {
goto done;
}
if (!groups) {
goto done;
}
for (i = 0; i < count; i++) {
struct sdap_nested_group);
}
goto done;
}
done:
return ret;
}
static errno_t
{
int hret;
struct membership_diff *iter;
bool in_transaction = false;
struct rfc2307bis_group_memberships_state);
if (!membership_state) {
goto done;
}
if (hret != HASH_SUCCESS) {
goto done;
}
goto done;
}
in_transaction = true;
goto done;
}
}
goto done;
}
in_transaction = false;
done:
if (in_transaction) {
}
}
return ret;
}
static bool
{
user_data, struct rfc2307bis_group_memberships_state);
struct sdap_nested_group *group;
char *group_name;
char **sysdb_parents_names_list;
char **ldap_parents_names_list = NULL;
struct membership_diff *mdiff;
if (!tmp_ctx) {
goto done;
}
if (ret) {
goto done;
}
if (group->parents_count > 0) {
goto done;
}
}
goto done;
}
done:
}
struct sdap_initgr_rfc2307bis_state *state)
{
char **ldap_grouplist;
char **sysdb_parent_name_list;
char **add_groups;
char **del_groups;
bool in_transaction = false;
if(!tmp_ctx) {
return ENOMEM;
}
goto error;
}
in_transaction = true;
if (ret) {
goto error;
}
if (state->num_direct_parents == 0) {
}
else {
goto error;
}
}
/* Find the differences between the sysdb and ldap lists
* Groups in ldap only must be added to the sysdb;
* groups in the sysdb only must be removed.
*/
goto error;
}
(const char *const *)add_groups,
(const char *const *)del_groups);
goto error;
}
goto error;
}
in_transaction = false;
return EOK;
if (in_transaction) {
}
}
return ret;
}
struct sdap_rfc2307bis_nested_ctx {
struct tevent_context *ev;
struct sdap_options *opts;
struct sss_domain_info *dom;
struct sdap_handle *sh;
int timeout;
const char *base_filter;
char *filter;
const char *orig_dn;
const char **attrs;
struct sysdb_attrs **groups;
struct sysdb_attrs **ldap_parents;
const char *primary_name;
struct sysdb_handle *handle;
struct sdap_search_base **search_bases;
};
struct tevent_req *rfc2307bis_nested_groups_send(
{
struct tevent_req *req;
struct sdap_rfc2307bis_nested_ctx *state;
struct sdap_rfc2307bis_nested_ctx);
if ((num_groups == 0) ||
/* No parent groups to process or too deep*/
return req;
}
state->group_iter = 0;
if (!state->search_bases) {
("Initgroups nested lookup request "
"without a group search base\n"));
goto done;
}
done:
/* All parent groups were already processed */
}
/* EAGAIN means a lookup is in progress */
return req;
}
{
char *clean_orig_dn;
struct sdap_rfc2307bis_nested_ctx *state =
if (!tmp_ctx) {
goto done;
}
&state->primary_name);
goto done;
}
goto done;
}
goto done;
}
/* Get any parent groups for this group */
goto done;
}
goto done;
}
goto done;
}
state, "(&(%s=%s)(objectclass=%s)(%s=*))",
if (!state->base_filter) {
goto done;
}
/* Still processing parent groups */
done:
return ret;
}
{
struct tevent_req *subreq;
struct sdap_rfc2307bis_nested_ctx *state;
return ENOMEM;
}
("Searching for parent groups of group [%s] with base [%s]\n",
true);
if (!subreq) {
return ENOMEM;
}
req);
return EOK;
}
{
struct tevent_req *req =
struct sdap_rfc2307bis_nested_ctx *state =
size_t i;
struct sysdb_attrs **ldap_groups;
struct sdap_nested_group *ngr;
int hret;
&count,
&ldap_groups);
if (ret) {
return;
}
/* Add this batch of groups to the list */
if (count > 0) {
struct sysdb_attrs *,
if (!state->ldap_parents) {
return;
}
/* Copy the new groups into the list.
* They're allocated on 'state' so we need to move them
* onto ldap_parents so that the data won't disappear when
* we finish this nesting level.
*/
for (i = 0; i < count; i++) {
}
}
/* Check for additional search bases, and iterate
* through again.
*/
}
return;
}
/* Reset the base iterator for future lookups */
if (!ngr) {
return;
}
return;
}
if (hret != HASH_SUCCESS) {
return;
}
if (state->parents_count == 0) {
/* No parent groups for this group in LDAP
* Move on to the next group
*/
state->group_iter++;
/* Looking up parent groups.. */
return;
return;
}
/* EOK means this group has already been processed
* in another nesting level */
state->group_iter++;
}
/* All groups processed. Done. */
}
return;
}
/* Otherwise, recurse into the groups */
if (!subreq) {
return;
}
}
{
return EOK;
}
{
struct tevent_req *req =
struct sdap_rfc2307bis_nested_ctx *state =
return;
}
state->group_iter++;
/* Looking up parent groups.. */
return;
return;
}
/* EOK means this group has already been processed
* in another nesting level */
state->group_iter++;
}
/* All groups processed. Done. */
return;
}
}
/* ==Initgr-call-(groups-a-user-is-member-of)============================= */
struct sdap_get_initgr_state {
struct tevent_context *ev;
struct sdap_options *opts;
struct sss_domain_info *dom;
struct sdap_handle *sh;
struct sdap_id_ctx *id_ctx;
const char *name;
const char **grp_attrs;
const char **user_attrs;
const char *user_base_filter;
char *filter;
int timeout;
struct sysdb_attrs *orig_user;
struct sdap_search_base **user_search_bases;
};
struct tevent_context *ev,
struct sdap_handle *sh,
struct sdap_id_ctx *id_ctx,
const char *name,
const char **grp_attrs)
{
struct tevent_req *req;
struct sdap_get_initgr_state *state;
int ret;
char *clean_name;
state->user_base_iter = 0;
if (!state->user_search_bases) {
("Initgroups lookup request without a user search base\n"));
goto done;
}
return NULL;
}
if (!state->user_base_filter) {
return NULL;
}
if (ret) {
return NULL;
}
done:
}
return req;
}
{
struct tevent_req *subreq;
struct sdap_get_initgr_state *state;
return ENOMEM;
}
("Searching for users with base [%s]\n",
false);
if (!subreq) {
return ENOMEM;
}
return EOK;
}
static struct tevent_req *sdap_initgr_rfc2307bis_send(
struct tevent_context *ev,
struct sdap_options *opts,
struct sss_domain_info *dom,
struct sdap_handle *sh,
const char *name,
const char *orig_dn);
{
struct tevent_req);
struct sdap_get_initgr_state);
struct sysdb_attrs **usr_attrs;
int ret;
const char *orig_dn;
const char *cname;
if (ret) {
return;
}
if (count == 0) {
/* No users found in this search */
state->user_base_iter++;
/* There are more search bases to try */
}
return;
}
return;
} else if (count != 1) {
return;
}
if (ret) {
return;
}
true, NULL, 0);
if (ret) {
return;
}
if (ret) {
return;
}
return;
}
case SDAP_SCHEMA_RFC2307:
return;
}
cname);
if (!subreq) {
return;
}
break;
case SDAP_SCHEMA_RFC2307BIS:
&orig_dn);
return;
}
if (!subreq) {
return;
}
break;
case SDAP_SCHEMA_IPA_V1:
case SDAP_SCHEMA_AD:
* We need an AD specific call that is able to unroll
* nested groups by doing extensive recursive searches */
if (!subreq) {
return;
}
return;
default:
return;
}
}
{
struct tevent_req);
struct sdap_get_initgr_state);
int ret;
char *gid;
case SDAP_SCHEMA_RFC2307:
break;
case SDAP_SCHEMA_RFC2307BIS:
break;
case SDAP_SCHEMA_IPA_V1:
case SDAP_SCHEMA_AD:
break;
default:
break;
}
if (ret) {
return;
}
/* We also need to update the user's primary group, since
* the user may not be an explicit member of that group
*/
return;
}
return;
}
if (!subreq) {
return;
}
}
{
struct tevent_req *req =
return;
}
}
{
return EOK;
}