sdap_async_users.c revision fb83de0699b16e7d8eca803305e2112795807b4c
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny Async LDAP Helper routines - retrieving users
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny Copyright (C) Simo Sorce <ssorce@redhat.com> - 2009
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny Copyright (C) 2010, Ralf Haferkamp <rhafer@suse.de>, Novell Inc.
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny Copyright (C) Jan Zeleny <jzeleny@redhat.com> - 2011
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny This program is free software; you can redistribute it and/or modify
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny it under the terms of the GNU General Public License as published by
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny the Free Software Foundation; either version 3 of the License, or
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny (at your option) any later version.
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny This program is distributed in the hope that it will be useful,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny but WITHOUT ANY WARRANTY; without even the implied warranty of
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny GNU General Public License for more details.
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny You should have received a copy of the GNU General Public License
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny along with this program. If not, see <http://www.gnu.org/licenses/>.
208b9f9bea519392428d99803edac1739ffdd444Pavel Březinastatic void make_realm_upper_case(const char *upn)
208b9f9bea519392428d99803edac1739ffdd444Pavel Březina DEBUG(SSSDBG_TRACE_ALL, "No realm delimiter found in upn [%s].\n", upn);
208b9f9bea519392428d99803edac1739ffdd444Pavel Březina while(*(++c) != '\0') {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny/* ==Save-User-Entry====================================================== */
a79c0a639c4ab26eacbc29f9f42bc95421e33f6eJakub Hrozeksdap_get_idmap_primary_gid(struct sdap_options *opts,
a79c0a639c4ab26eacbc29f9f42bc95421e33f6eJakub Hrozek opts->user_map[SDAP_AT_USER_PRIMARY_GROUP].sys_name,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "no primary group ID provided\n");
a79c0a639c4ab26eacbc29f9f42bc95421e33f6eJakub Hrozek /* The primary group ID is just the RID part of the objectSID
a79c0a639c4ab26eacbc29f9f42bc95421e33f6eJakub Hrozek * of the group. Generate the GID by adding this to the domain
a79c0a639c4ab26eacbc29f9f42bc95421e33f6eJakub Hrozek * SID value.
a79c0a639c4ab26eacbc29f9f42bc95421e33f6eJakub Hrozek /* First, get the domain SID if we didn't do so above */
a79c0a639c4ab26eacbc29f9f42bc95421e33f6eJakub Hrozek ret = sdap_idmap_get_dom_sid_from_object(tmpctx, sid_str,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Could not parse domain SID from [%s]\n", sid_str);
a79c0a639c4ab26eacbc29f9f42bc95421e33f6eJakub Hrozek /* Add the RID to the end */
a79c0a639c4ab26eacbc29f9f42bc95421e33f6eJakub Hrozek group_sid_str = talloc_asprintf(tmpctx, "%s-%lu", dom_sid_str,
a79c0a639c4ab26eacbc29f9f42bc95421e33f6eJakub Hrozek (unsigned long) primary_gid);
a79c0a639c4ab26eacbc29f9f42bc95421e33f6eJakub Hrozek /* Convert the SID into a UNIX group ID */
a79c0a639c4ab26eacbc29f9f42bc95421e33f6eJakub Hrozek ret = sdap_idmap_sid_to_unix(opts->idmap_ctx, group_sid_str, &gid);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny/* FIXME: support storing additional attributes */
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny const char *pwd;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny const char *gecos;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny const char *shell;
022ebf54037982211da729b99213bab7458ae827Pavel Březina /* Always store SID string if available */
022ebf54037982211da729b99213bab7458ae827Pavel Březina ret = sdap_attrs_get_sid_str(tmpctx, opts->idmap_ctx, attrs,
022ebf54037982211da729b99213bab7458ae827Pavel Březina opts->user_map[SDAP_AT_USER_OBJECTSID].sys_name,
022ebf54037982211da729b99213bab7458ae827Pavel Březina ret = sysdb_attrs_add_string(user_attrs, SYSDB_SID_STR, sid_str);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Could not add SID string: [%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_ALL, "objectSID: not available for user\n");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Could not identify objectSID: [%s]\n",
933326b4180b72636af84643d4811f6ad645fbe8Sumit Bose /* Always store UUID if available */
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bose ret = sysdb_handle_original_uuid(opts->user_map[SDAP_AT_USER_UUID].def_name,
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bose DEBUG((ret == ENOENT) ? SSSDBG_TRACE_ALL : SSSDBG_MINOR_FAILURE,
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bose "Failed to retrieve UUID [%d][%s].\n", ret, sss_strerror(ret));
022ebf54037982211da729b99213bab7458ae827Pavel Březina /* If this object has a SID available, we will determine the correct
022ebf54037982211da729b99213bab7458ae827Pavel Březina * domain by its SID. */
9ca0071db0e226e4e65b2a80fdeddd5048ca8990Pavel Reichl subdomain = find_domain_by_sid(get_domains_head(dom), sid_str);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "SID %s does not belong to any known "
bfd59d1a2d0d45125e5164ef12c425690d519f61Jakub Hrozek ret = sdap_get_user_primary_name(memctx, opts, attrs, dom, &user_name);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Failed to get user name\n");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Processing user %s\n", user_name);
ec2102d767bd658668d59db0954013c9c20c15ddPavel Březina opts->user_map[SDAP_AT_USER_FULLNAME].sys_name, &fullname);
ec2102d767bd658668d59db0954013c9c20c15ddPavel Březina ret = sysdb_attrs_add_string(user_attrs, SYSDB_FULLNAME, fullname);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny opts->user_map[SDAP_AT_USER_GECOS].sys_name, &el);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny /* Fall back to the user's full name */
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny opts->user_map[SDAP_AT_USER_FULLNAME].sys_name, &el);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (el->num_values > 0) gecos = (const char *)el->values[0].data;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny opts->user_map[SDAP_AT_USER_HOME].sys_name, &el);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny opts->user_map[SDAP_AT_USER_SHELL].sys_name, &el);
b56b06e199f15a8a840b36bc7cb8010e39ae761dSumit Bose use_id_mapping = sdap_idmap_domain_has_algorithmic_mapping(opts->idmap_ctx,
8538f3d5109c548049c344fa042684d9d40f04d6Stephen Gallagher /* Retrieve or map the UID as appropriate */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "SID not available, cannot map a " \
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Mapping user [%s] objectSID [%s] to unix ID\n", user_name, sid_str);
8538f3d5109c548049c344fa042684d9d40f04d6Stephen Gallagher /* Convert the SID into a UNIX user ID */
8be5e4497e5008f7807178acdfcbf97365ec4e73Stephen Gallagher ret = sdap_idmap_sid_to_unix(opts->idmap_ctx, sid_str, &uid);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Skipping built-in object.\n");
3f2fa4c9290afdb393c760419a0ff686045a1ab3Stephen Gallagher /* Store the UID in the ldap_attrs so it doesn't get
3f2fa4c9290afdb393c760419a0ff686045a1ab3Stephen Gallagher * treated as a missing attribute from LDAP and removed.
f9f74a587c8e96dcf90214c760022684afc8bef7Jakub Hrozek ret = sdap_replace_id(attrs, SYSDB_UIDNUM, uid);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Cannot set the id-mapped UID\n");
8538f3d5109c548049c344fa042684d9d40f04d6Stephen Gallagher opts->user_map[SDAP_AT_USER_UID].sys_name,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "no uid provided for [%s] in domain [%s].\n",
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny /* check that the uid is valid for this domain */
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (OUT_OF_ID_RANGE(uid, dom->id_min, dom->id_max)) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "User [%s] filtered out! (uid out of range)\n",
8cdb9b9824d3fcc2448544d67544496f55b8d393Sumit Bose ret = sdap_get_idmap_primary_gid(opts, attrs, sid_str, dom_sid_str,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Cannot get the GID for [%s] in domain [%s].\n",
d27d7f2c270b69d0805633c4bedcf6d806acd5cdJakub Hrozek /* For subdomain users, only create the private group as
8cdb9b9824d3fcc2448544d67544496f55b8d393Sumit Bose * the subdomain is an MPG domain.
8cdb9b9824d3fcc2448544d67544496f55b8d393Sumit Bose * But we have to save the GID of the original primary group
8cdb9b9824d3fcc2448544d67544496f55b8d393Sumit Bose * becasuse otherwise this information might be lost because
8cdb9b9824d3fcc2448544d67544496f55b8d393Sumit Bose * typically (Unix and AD) the user is not listed in his primary
8cdb9b9824d3fcc2448544d67544496f55b8d393Sumit Bose * group as a member.
8cdb9b9824d3fcc2448544d67544496f55b8d393Sumit Bose ret = sysdb_attrs_add_uint32(user_attrs, SYSDB_PRIMARY_GROUP_GIDNUM,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "sysdb_attrs_add_uint32 failed.\n");
3f2fa4c9290afdb393c760419a0ff686045a1ab3Stephen Gallagher /* Store the GID in the ldap_attrs so it doesn't get
a79c0a639c4ab26eacbc29f9f42bc95421e33f6eJakub Hrozek * treated as a missing attribute from LDAP and removed.
3f2fa4c9290afdb393c760419a0ff686045a1ab3Stephen Gallagher ret = sysdb_attrs_add_uint32(attrs, SYSDB_GIDNUM, gid);
532eb49e129bedf57cdbd0a66f39ad228b8f2482Stephen Gallagher opts->user_map[SDAP_AT_USER_GID].sys_name,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "no gid provided for [%s] in domain [%s].\n",
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny /* check that the gid is valid for this domain */
d27d7f2c270b69d0805633c4bedcf6d806acd5cdJakub Hrozek OUT_OF_ID_RANGE(gid, dom->id_min, dom->id_max)) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "User [%s] filtered out! (primary gid out of range)\n",
8455d5ab61184e0d126fc074a9ce6e98391eb909Jakub Hrozek ret = sysdb_attrs_get_el(attrs, SYSDB_ORIG_DN, &el);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "originalDN is not available for [%s].\n", user_name);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_INTERNAL, "Adding originalDN [%s] to attributes "
8455d5ab61184e0d126fc074a9ce6e98391eb909Jakub Hrozek ret = sysdb_attrs_add_string(user_attrs, SYSDB_ORIG_DN, orig_dn);
13308d6c9e30ca6835c38fbdedcb47dfc343d8b3Jakub Hrozek ret = sysdb_attrs_get_el(attrs, SYSDB_MEMBEROF, &el);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Original memberOf is not available for [%s].\n", user_name);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Adding original memberOf attributes to [%s].\n", user_name);
13308d6c9e30ca6835c38fbdedcb47dfc343d8b3Jakub Hrozek ret = sysdb_attrs_add_string(user_attrs, SYSDB_ORIG_MEMBEROF,
70a33bdf7db34fe4d1ba194cf9ea28c758719b4bJakub Hrozek opts->user_map[SDAP_AT_USER_MODSTAMP].sys_name,
70a33bdf7db34fe4d1ba194cf9ea28c758719b4bJakub Hrozek "original mod-Timestamp",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Original USN value is not available for [%s].\n", user_name);
70a33bdf7db34fe4d1ba194cf9ea28c758719b4bJakub Hrozek usn_value = talloc_strdup(tmpctx, (const char*)el->values[0].data);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny opts->user_map[SDAP_AT_USER_PRINC].sys_name, &el);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "User principal is not available for [%s].\n", user_name);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny upn = talloc_strdup(user_attrs, (const char*) el->values[0].data);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (dp_opt_get_bool(opts->basic, SDAP_FORCE_UPPER_CASE_REALM)) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Adding user principal [%s] to attributes of [%s].\n",
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny ret = sysdb_attrs_add_string(user_attrs, SYSDB_UPN, upn);
4dd38025efda88f123eac672f87d3cda12f050c8Jakub Hrozek for (i = SDAP_FIRST_EXTRA_USER_AT; i < opts->user_map_cnt; i++) {
70a33bdf7db34fe4d1ba194cf9ea28c758719b4bJakub Hrozek ret = sdap_attrs_add_list(attrs, opts->user_map[i].sys_name,
bfd59d1a2d0d45125e5164ef12c425690d519f61Jakub Hrozek ret = sdap_save_all_names(user_name, attrs, dom, user_attrs);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to save user names\n");
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny /* Make sure that any attributes we requested from LDAP that we
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny * did not receive are also removed from the sysdb
4dd38025efda88f123eac672f87d3cda12f050c8Jakub Hrozek ret = list_missing_attrs(user_attrs, opts->user_map, opts->user_map_cnt,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Storing info for user %s\n", user_name);
d115f40c7a3999e3cbe705a2ff9cf0fd493f80fbMichal Zidek ret = sysdb_store_user(dom, user_name, pwd, uid, gid,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Failed to save user [%s]\n",
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny/* ==Generic-Function-to-save-multiple-users============================= */
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny /* Nothing to do if there are no users */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to start transaction\n");
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny for (i = 0; i < num_users; i++) {
dca741129d221558a4325479aefc617240f1ab08Lukas Slebodnik ret = sdap_save_user(tmpctx, opts, dom, users[i], &usn_value, now);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny /* Do not fail completely on errors.
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny * Just report the failure to save and go on */
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Failed to store user %d. Ignoring.\n", i);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_TRACE_ALL, "User %d processed!\n", i);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to commit transaction!\n");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to cancel transaction\n");
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny/* ==Search-Users-with-filter============================================= */
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny const char **attrs;
5b83443dd252a3897feda134f224f6b09f283372Jakub Hrozekstatic errno_t sdap_search_user_next_base(struct tevent_req *req);
fb83de0699b16e7d8eca803305e2112795807b4cJakub Hrozekstatic void sdap_search_user_copy_batch(struct sdap_search_user_state *state,
5b83443dd252a3897feda134f224f6b09f283372Jakub Hrozekstatic void sdap_search_user_process(struct tevent_req *subreq);
5b83443dd252a3897feda134f224f6b09f283372Jakub Hrozekstruct tevent_req *sdap_search_user_send(TALLOC_CTX *memctx,
5b83443dd252a3897feda134f224f6b09f283372Jakub Hrozek const char **attrs,
5b83443dd252a3897feda134f224f6b09f283372Jakub Hrozek req = tevent_req_create(memctx, &state, struct sdap_search_user_state);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "User lookup request without a search base\n");
5b83443dd252a3897feda134f224f6b09f283372Jakub Hrozekstatic errno_t sdap_search_user_next_base(struct tevent_req *req)
5b83443dd252a3897feda134f224f6b09f283372Jakub Hrozek state = tevent_req_data(req, struct sdap_search_user_state);
a0e406e5219068aec1a531e2b09ee30309b266cfStephen Gallagher state->filter = sdap_get_id_specific_filter(state,
a0e406e5219068aec1a531e2b09ee30309b266cfStephen Gallagher state->search_bases[state->base_iter]->filter);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Searching for users with base [%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov state->search_bases[state->base_iter]->basedn);
1f2fc55ecf7b5e170b2c0752304d1a2ecebc5259Jakub Hrozek /* Only requests that can return multiple entries should require
1f2fc55ecf7b5e170b2c0752304d1a2ecebc5259Jakub Hrozek * the paging control
b9e74a747b8f1012bba3575f3e4289ef4877d64aJakub Hrozek sizelimit = dp_opt_get_int(state->opts->basic, SDAP_WILDCARD_LIMIT);
a0e406e5219068aec1a531e2b09ee30309b266cfStephen Gallagher state->search_bases[state->base_iter]->basedn,
a0e406e5219068aec1a531e2b09ee30309b266cfStephen Gallagher state->search_bases[state->base_iter]->scope,
4dd38025efda88f123eac672f87d3cda12f050c8Jakub Hrozek state->opts->user_map, state->opts->user_map_cnt,
5b83443dd252a3897feda134f224f6b09f283372Jakub Hrozek tevent_req_set_callback(subreq, sdap_search_user_process, req);
5b83443dd252a3897feda134f224f6b09f283372Jakub Hrozekstatic void sdap_search_user_process(struct tevent_req *subreq)
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct tevent_req *req = tevent_req_callback_data(subreq,
5b83443dd252a3897feda134f224f6b09f283372Jakub Hrozek struct sdap_search_user_state *state = tevent_req_data(req,
5b2ca5cc0e22dd184e3eba84af2c00d7065c59c7Jakub Hrozek ret = sdap_get_and_parse_generic_recv(subreq, state,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Search for users, returned %zu results.\n", count);
1f2fc55ecf7b5e170b2c0752304d1a2ecebc5259Jakub Hrozek if (state->lookup_type == SDAP_LOOKUP_WILDCARD || \
1f2fc55ecf7b5e170b2c0752304d1a2ecebc5259Jakub Hrozek state->lookup_type == SDAP_LOOKUP_ENUMERATE || \
1f2fc55ecf7b5e170b2c0752304d1a2ecebc5259Jakub Hrozek /* No users found in this search or looking up multiple entries */
f26b61dfe246c750a42f1f9fb28f9df5981bc841Stephen Gallagher /* Add this batch of users to the list */
fb83de0699b16e7d8eca803305e2112795807b4cJakub Hrozek sdap_search_user_copy_batch(state, users, count);
a0e406e5219068aec1a531e2b09ee30309b266cfStephen Gallagher if (state->search_bases[state->base_iter]) {
a0e406e5219068aec1a531e2b09ee30309b266cfStephen Gallagher /* There are more search bases to try */
f26b61dfe246c750a42f1f9fb28f9df5981bc841Stephen Gallagher /* No more search bases
f26b61dfe246c750a42f1f9fb28f9df5981bc841Stephen Gallagher * Return ENOENT if no users were found
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_ALL, "Retrieved total %zu users\n", state->count);
fb83de0699b16e7d8eca803305e2112795807b4cJakub Hrozekstatic void sdap_search_user_copy_batch(struct sdap_search_user_state *state,
fb83de0699b16e7d8eca803305e2112795807b4cJakub Hrozek /* Always copy all objects for wildcard lookups. */
fb83de0699b16e7d8eca803305e2112795807b4cJakub Hrozek filter = state->lookup_type == SDAP_LOOKUP_SINGLE ? true : false;
fb83de0699b16e7d8eca803305e2112795807b4cJakub Hrozek copied = sdap_steal_objects_in_dom(state->opts,
5b83443dd252a3897feda134f224f6b09f283372Jakub Hrozekint sdap_search_user_recv(TALLOC_CTX *memctx, struct tevent_req *req,
5b83443dd252a3897feda134f224f6b09f283372Jakub Hrozek char **higher_usn, struct sysdb_attrs ***users,
5b83443dd252a3897feda134f224f6b09f283372Jakub Hrozek struct sdap_search_user_state *state = tevent_req_data(req,
5b83443dd252a3897feda134f224f6b09f283372Jakub Hrozek *higher_usn = talloc_steal(memctx, state->higher_usn);
5b83443dd252a3897feda134f224f6b09f283372Jakub Hrozek/* ==Search-And-Save-Users-with-filter============================================= */
5b83443dd252a3897feda134f224f6b09f283372Jakub Hrozekstatic void sdap_get_users_done(struct tevent_req *subreq);
5b83443dd252a3897feda134f224f6b09f283372Jakub Hrozekstruct tevent_req *sdap_get_users_send(TALLOC_CTX *memctx,
5b83443dd252a3897feda134f224f6b09f283372Jakub Hrozek const char **attrs,
5b83443dd252a3897feda134f224f6b09f283372Jakub Hrozek req = tevent_req_create(memctx, &state, struct sdap_get_users_state);
5b83443dd252a3897feda134f224f6b09f283372Jakub Hrozek subreq = sdap_search_user_send(state, ev, dom, opts, search_bases,
5b83443dd252a3897feda134f224f6b09f283372Jakub Hrozek tevent_req_set_callback(subreq, sdap_get_users_done, req);
5b83443dd252a3897feda134f224f6b09f283372Jakub Hrozekstatic void sdap_get_users_done(struct tevent_req *subreq)
5b83443dd252a3897feda134f224f6b09f283372Jakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
5b83443dd252a3897feda134f224f6b09f283372Jakub Hrozek struct sdap_get_users_state *state = tevent_req_data(req,
5b83443dd252a3897feda134f224f6b09f283372Jakub Hrozek ret = sdap_search_user_recv(state, subreq, &state->higher_usn,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Failed to retrieve users\n");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Failed to store users.\n");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_ALL, "Saving %zu Users - Done\n", state->count);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct sdap_get_users_state *state = tevent_req_data(req,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny *usn_value = talloc_steal(mem_ctx, state->higher_usn);
fae99bfe4bfc8b4a12e9c2a0ad01b3684c22f934Simo Sorce/* ==Fetch-Fallback-local-user============================================ */
fae99bfe4bfc8b4a12e9c2a0ad01b3684c22f934Simo Sorceerrno_t sdap_fallback_local_user(TALLOC_CTX *memctx,
fae99bfe4bfc8b4a12e9c2a0ad01b3684c22f934Simo Sorce ua = talloc_array(memctx, struct sysdb_attrs *, 2);
fae99bfe4bfc8b4a12e9c2a0ad01b3684c22f934Simo Sorce ret = sysdb_attrs_add_string(user, SYSDB_NAME, pwd->pw_name);
fae99bfe4bfc8b4a12e9c2a0ad01b3684c22f934Simo Sorce ret = sysdb_attrs_add_string(user, SYSDB_PWD, pwd->pw_passwd);
fae99bfe4bfc8b4a12e9c2a0ad01b3684c22f934Simo Sorce ret = sysdb_attrs_add_long(user, SYSDB_UIDNUM, (long)pwd->pw_uid);
fae99bfe4bfc8b4a12e9c2a0ad01b3684c22f934Simo Sorce ret = sysdb_attrs_add_long(user, SYSDB_GIDNUM, (long)pwd->pw_gid);
fae99bfe4bfc8b4a12e9c2a0ad01b3684c22f934Simo Sorce ret = sysdb_attrs_add_string(user, SYSDB_GECOS, pwd->pw_gecos);
fae99bfe4bfc8b4a12e9c2a0ad01b3684c22f934Simo Sorce ret = sysdb_attrs_add_string(user, SYSDB_HOMEDIR, pwd->pw_dir);