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);
ed0cdfcacc44e4e13e1524e254efa744610a87c2Jakub Hrozekstatic errno_t sdap_set_non_posix_flag(struct sysdb_attrs *attrs,
ed0cdfcacc44e4e13e1524e254efa744610a87c2Jakub Hrozek const char *pkey)
4a9c1047354dbe5a4ed41e5951ae623e3772e113René Genz "Failed to add a zero ID to a non-POSIX object!\n");
ed0cdfcacc44e4e13e1524e254efa744610a87c2Jakub Hrozek ret = sysdb_attrs_add_bool(attrs, SYSDB_POSIX, false);
4a9c1047354dbe5a4ed41e5951ae623e3772e113René Genz "Error: Failed to mark objects as non-POSIX!\n");
cdb74b2cc6cc3fe52969712907c9eb4026c7a44fJakub Hrozekstatic int sdap_user_set_mpg(struct sysdb_attrs *user_attrs,
cdb74b2cc6cc3fe52969712907c9eb4026c7a44fJakub Hrozek if (*_gid == 0) {
cdb74b2cc6cc3fe52969712907c9eb4026c7a44fJakub Hrozek /* The original entry had no GID number. This is OK, we just won't add
cdb74b2cc6cc3fe52969712907c9eb4026c7a44fJakub Hrozek * the SYSDB_PRIMARY_GROUP_GIDNUM attribute
cdb74b2cc6cc3fe52969712907c9eb4026c7a44fJakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "sysdb_attrs_add_uint32 failed.\n");
cdb74b2cc6cc3fe52969712907c9eb4026c7a44fJakub Hrozek /* We won't really store gidNumber=0, but the zero value tells
cdb74b2cc6cc3fe52969712907c9eb4026c7a44fJakub Hrozek * the sysdb layer that no GID is set, which sysdb requires for
cdb74b2cc6cc3fe52969712907c9eb4026c7a44fJakub Hrozek * MPG-enabled domains
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny/* FIXME: support storing additional attributes */
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,
ed0cdfcacc44e4e13e1524e254efa744610a87c2Jakub Hrozek if (ret == ENOENT && dom->type == DOM_TYPE_APPLICATION) {
4a9c1047354dbe5a4ed41e5951ae623e3772e113René Genz "Marking object as non-POSIX and setting ID=0!\n");
ed0cdfcacc44e4e13e1524e254efa744610a87c2Jakub Hrozek "Cannot retrieve UID for [%s] in domain [%s].\n",
ed0cdfcacc44e4e13e1524e254efa744610a87c2Jakub Hrozek /* check that the uid is valid for this domain if the user is a POSIX one */
ed0cdfcacc44e4e13e1524e254efa744610a87c2Jakub Hrozek if (is_posix == true && OUT_OF_ID_RANGE(uid, dom->id_min, dom->id_max)) {
ed0cdfcacc44e4e13e1524e254efa744610a87c2Jakub Hrozek "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
4a9c1047354dbe5a4ed41e5951ae623e3772e113René Genz * because otherwise this information might be lost because
4a9c1047354dbe5a4ed41e5951ae623e3772e113René Genz * typically (UNIX and AD) the user is not listed in his primary
8cdb9b9824d3fcc2448544d67544496f55b8d393Sumit Bose * group as a member.
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);
cdb74b2cc6cc3fe52969712907c9eb4026c7a44fJakub Hrozek /* Likewise, if a domain is set to contain 'magic private groups', do
cdb74b2cc6cc3fe52969712907c9eb4026c7a44fJakub Hrozek * not process the real GID, but save it in the cache as originalGID
cdb74b2cc6cc3fe52969712907c9eb4026c7a44fJakub Hrozek * (if available)
cdb74b2cc6cc3fe52969712907c9eb4026c7a44fJakub Hrozek "Missing GID, won't save the %s attribute\n",
cdb74b2cc6cc3fe52969712907c9eb4026c7a44fJakub Hrozek /* Store the UID as GID (since we're in a MPG domain so that it doesn't
cdb74b2cc6cc3fe52969712907c9eb4026c7a44fJakub Hrozek * get treated as a missing attribute and removed
cdb74b2cc6cc3fe52969712907c9eb4026c7a44fJakub Hrozek ret = sdap_replace_id(attrs, SYSDB_GIDNUM, uid);
cdb74b2cc6cc3fe52969712907c9eb4026c7a44fJakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "Cannot set the id-mapped UID\n");
cdb74b2cc6cc3fe52969712907c9eb4026c7a44fJakub Hrozek "Cannot retrieve GID, won't save the %s attribute\n",
cdb74b2cc6cc3fe52969712907c9eb4026c7a44fJakub Hrozek "sdap_user_set_mpg failed [%d]: %s\n", ret, sss_strerror(ret));
532eb49e129bedf57cdbd0a66f39ad228b8f2482Stephen Gallagher opts->user_map[SDAP_AT_USER_GID].sys_name,
ed0cdfcacc44e4e13e1524e254efa744610a87c2Jakub Hrozek if (ret == ENOENT && dom->type == DOM_TYPE_APPLICATION) {
4a9c1047354dbe5a4ed41e5951ae623e3772e113René Genz "Marking object as non-POSIX and setting ID=0!\n");
ed0cdfcacc44e4e13e1524e254efa744610a87c2Jakub Hrozek "Cannot retrieve GID for [%s] in domain [%s].\n",
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny /* check that the gid is valid for this domain */
cdb74b2cc6cc3fe52969712907c9eb4026c7a44fJakub Hrozek if (is_posix == true && IS_SUBDOMAIN(dom) == false
cdb74b2cc6cc3fe52969712907c9eb4026c7a44fJakub 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);
0d5d490fb5ec685fd8ef7a75e612e6ec7ef6bde3Sumit Bose upn = talloc_strdup(tmpctx, (const char*) el->values[c].data);
15694ca762f61a414f0017c57ed97a8d57456b80Sumit Bose /* Check for IPA Kerberos enterprise principal strings
15694ca762f61a414f0017c57ed97a8d57456b80Sumit Bose * 'user\@my.realm@IPA.REALM' and use 'user@my.realm' */
15694ca762f61a414f0017c57ed97a8d57456b80Sumit Bose upn = talloc_asprintf(tmpctx, "%s%s", upn, p1 + 1);
15694ca762f61a414f0017c57ed97a8d57456b80Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_asprintf failed.\n");
0d5d490fb5ec685fd8ef7a75e612e6ec7ef6bde3Sumit Bose if (dp_opt_get_bool(opts->basic, SDAP_FORCE_UPPER_CASE_REALM)) {
0d5d490fb5ec685fd8ef7a75e612e6ec7ef6bde3Sumit Bose "Adding user principal [%s] to attributes of [%s].\n",
0d5d490fb5ec685fd8ef7a75e612e6ec7ef6bde3Sumit Bose 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,
7cc19286547260350afed9ef7176712f8fc66652Michal Zidek ret = sdap_save_all_names(user_name, attrs, dom,
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,
70c0648f021ded3d31313eb962e1ad140f242673Sumit Bose ret = sysdb_set_user_attr(dom, user_name, mapped_attrs, SYSDB_MOD_ADD);
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");
70c0648f021ded3d31313eb962e1ad140f242673Sumit Bose ret = sysdb_remove_mapped_data(dom, mapped_attrs);
70c0648f021ded3d31313eb962e1ad140f242673Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_remove_mapped_data failed, "
70c0648f021ded3d31313eb962e1ad140f242673Sumit Bose "some cached entries might contain invalid mapping data.\n");
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny for (i = 0; i < num_users; i++) {
70c0648f021ded3d31313eb962e1ad140f242673Sumit Bose ret = sdap_save_user(tmpctx, opts, dom, users[i], mapped_attrs,
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============================================= */
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);
92ec40e6aa25f75903ffdb166a8ec56b67bfd77dPavel Březina state->filter = sdap_combine_filters(state, state->base_filter,
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 */
835965da366e468c12015ac35979a8ded0824c66Fabiano Fidêncio DEBUG(SSSDBG_TRACE_INTERNAL, "Retrieved total %zu users\n", state->count);
f26b61dfe246c750a42f1f9fb28f9df5981bc841Stephen Gallagher /* No more search bases
f26b61dfe246c750a42f1f9fb28f9df5981bc841Stephen Gallagher * Return ENOENT if no users were found
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);
70c0648f021ded3d31313eb962e1ad140f242673Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_new_attrs failed.\n");
70c0648f021ded3d31313eb962e1ad140f242673Sumit Bose ret = sysdb_attrs_copy(mapped_attrs, state->mapped_attrs);
70c0648f021ded3d31313eb962e1ad140f242673Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_attrs_copy failed.\n");
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,
835965da366e468c12015ac35979a8ded0824c66Fabiano Fidêncio DEBUG(SSSDBG_OP_FAILURE, "Failed to retrieve users [%d][%s].\n",
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek PROBE(SDAP_SEARCH_USER_SAVE_BEGIN, state->filter);
630f3ff08c1d17c7900b9bde814922f775ca2703Jakub Hrozek PROBE(SDAP_SEARCH_USER_SAVE_END, state->filter);
1fedb90a1d67766da39783eb193f568e9e2d55b0Pavel Reichl DEBUG(SSSDBG_OP_FAILURE, "Failed to store users [%d][%s].\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);