sdap_async_users.c revision 8be5e4497e5008f7807178acdfcbf97365ec4e73
/*
SSSD
Async LDAP Helper routines - retrieving users
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"
#include "providers/ldap/sdap_idmap.h"
/* ==Save-User-Entry====================================================== */
/* FIXME: support storing additional attributes */
struct sdap_options *opts,
struct sss_domain_info *dom,
struct sysdb_attrs *attrs,
bool is_initgr,
char **_usn_value,
{
struct ldb_message_element *el;
int ret;
const char *pwd;
const char *gecos;
const char *homedir;
const char *shell;
struct sysdb_attrs *user_attrs;
size_t i;
int cache_timeout;
char *sid_str;
char *dom_sid_str = NULL;
char *group_sid_str;
if (!tmpctx) {
goto fail;
}
if (user_attrs == NULL) {
goto fail;
}
&name);
goto fail;
}
if (!gecos) {
/* Fall back to the user's full name */
}
/* Retrieve or map the UID as appropriate */
if (use_id_mapping) {
("Mapping user [%s] objectSID to unix ID\n", name));
&sid_str);
/* Add string representation to the cache for easier
* debugging
*/
/* Convert the SID into a UNIX user ID */
/* Store the UID in the ldap_attrs so it doesn't get
* treated as a missing attribute from LDAP and removed.
*/
} else {
&uid);
goto fail;
}
}
/* check that the uid is valid for this domain */
name));
goto fail;
}
if (use_id_mapping) {
&primary_gid);
("no primary group ID provided for [%s] in domain [%s].\n",
goto fail;
}
/* The primary group ID is just the RID part of the objectSID
* of the group. Generate the GID by adding this to the domain
* SID value.
*/
/* First, get the domain SID if we didn't do so above */
if (!dom_sid_str) {
&dom_sid_str);
("Could not parse domain SID from [%s]\n", sid_str));
goto fail;
}
}
/* Add the RID to the end */
(unsigned long)primary_gid);
if (!group_sid_str) {
goto fail;
}
/* Convert the SID into a UNIX group ID */
/* Store the GID in the ldap_attrs so it doesn't get
* treated as a missing attribute from LDAP and removed.
*/
} else {
&gid);
goto fail;
}
}
/* check that the gid is valid for this domain */
name));
goto fail;
}
"original DN",
name, user_attrs);
goto fail;
}
if (ret) {
goto fail;
}
if (el->num_values == 0) {
name));
} else {
name));
for (i = 0; i < el->num_values; i++) {
if (ret) {
goto fail;
}
}
}
"original mod-Timestamp",
name, user_attrs);
goto fail;
}
if (ret) {
goto fail;
}
if (el->num_values == 0) {
name));
} else {
if (ret) {
goto fail;
}
if (!usn_value) {
goto fail;
}
}
if (ret) {
goto fail;
}
if (el->num_values == 0) {
} else {
if (!upn) {
goto fail;
}
}
if (ret) {
goto fail;
}
}
for (i = SDAP_FIRST_EXTRA_USER_AT; i < SDAP_OPTS_USER; i++) {
if (ret) {
goto fail;
}
}
if (is_initgr) {
if (ret) {
goto fail;
}
}
goto fail;
}
/* Make sure that any attributes we requested from LDAP that we
* did not receive are also removed from the sysdb
*/
goto fail;
}
if (_usn_value) {
}
return EOK;
fail:
return ret;
}
/* ==Generic-Function-to-save-multiple-users============================= */
struct sss_domain_info *dom,
struct sdap_options *opts,
struct sysdb_attrs **users,
int num_users,
char **_usn_value)
{
char *higher_usn = NULL;
char *usn_value;
int ret;
int i;
if (num_users == 0) {
/* Nothing to do if there are no users */
return EOK;
}
if (!tmpctx) {
return ENOMEM;
}
if (ret) {
goto done;
}
for (i = 0; i < num_users; i++) {
users[i], false,
/* Do not fail completely on errors.
* Just report the failure to save and go on */
if (ret) {
} else {
}
opts, true);
if (ret) {
}
if (usn_value) {
if (higher_usn) {
} else {
}
} else {
}
}
}
if (ret) {
goto done;
}
if (_usn_value) {
}
done:
return ret;
}
/* ==Search-Users-with-filter============================================= */
struct sdap_get_users_state {
struct tevent_context *ev;
struct sdap_options *opts;
struct sdap_handle *sh;
struct sss_domain_info *dom;
const char **attrs;
const char *base_filter;
char *filter;
int timeout;
bool enumeration;
char *higher_usn;
struct sysdb_attrs **users;
struct sdap_search_base **search_bases;
};
struct tevent_context *ev,
struct sss_domain_info *dom,
struct sdap_options *opts,
struct sdap_search_base **search_bases,
struct sdap_handle *sh,
const char **attrs,
const char *filter,
int timeout,
bool enumeration)
{
struct tevent_req *req;
struct sdap_get_users_state *state;
if (!state->search_bases) {
("User lookup request without a search base\n"));
goto done;
}
done:
}
return req;
}
{
struct tevent_req *subreq;
struct sdap_get_users_state *state;
return ENOMEM;
}
("Searching for users with base [%s]\n",
if (!subreq) {
return ENOMEM;
}
return EOK;
}
{
struct tevent_req);
struct sdap_get_users_state);
int ret;
struct sysdb_attrs **users;
bool next_base = false;
if (ret) {
return;
}
/* No users found in this search or enumerating */
next_base = true;
}
/* Add this batch of users to the list */
if (count > 0) {
struct sysdb_attrs *,
return;
}
/* Copy the new users into the list
* They're already allocated on 'state'
*/
for (i = 0; i < count; i++) {
}
}
if (next_base) {
/* There are more search bases to try */
}
return;
}
}
/* No more search bases
* Return ENOENT if no users were found
*/
return;
}
&state->higher_usn);
if (ret) {
return;
}
}
{
struct sdap_get_users_state);
if (usn_value) {
}
return EOK;
}