f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny/*
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny SSSD
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny Async LDAP Helper routines - initgroups operation
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
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
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
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
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/>.
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny*/
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny#include "util/util.h"
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny#include "db/sysdb.h"
3ee411625aee19afda7477bb10b52c3da378b6fbPetr Čech#include "providers/ldap/sdap.h"
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny#include "providers/ldap/sdap_async_private.h"
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny#include "providers/ldap/ldap_common.h"
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher#include "providers/ldap/sdap_idmap.h"
fae99bfe4bfc8b4a12e9c2a0ad01b3684c22f934Simo Sorce#include "providers/ldap/sdap_users.h"
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny/* ==Save-fake-group-list=====================================*/
d81d8d3dc151ebc95cd0e3f3b14c1cdaa48980f1Sumit Boseerrno_t sdap_add_incomplete_groups(struct sysdb_ctx *sysdb,
d81d8d3dc151ebc95cd0e3f3b14c1cdaa48980f1Sumit Bose struct sss_domain_info *domain,
d81d8d3dc151ebc95cd0e3f3b14c1cdaa48980f1Sumit Bose struct sdap_options *opts,
c03214d427ea43e7bf8255ccc79faa905c89f7f6Jakub Hrozek char **sysdb_groupnames,
d81d8d3dc151ebc95cd0e3f3b14c1cdaa48980f1Sumit Bose struct sysdb_attrs **ldap_groups,
d81d8d3dc151ebc95cd0e3f3b14c1cdaa48980f1Sumit Bose int ldap_groups_count)
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny{
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny TALLOC_CTX *tmp_ctx;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct ldb_message *msg;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny int i, mi, ai;
bfd59d1a2d0d45125e5164ef12c425690d519f61Jakub Hrozek const char *groupname;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny const char *original_dn;
108db0e3b9e06e530364ef8228634f5e3f6bd3b5Jakub Hrozek const char *uuid = NULL;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny char **missing;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny gid_t gid;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny int ret;
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek errno_t sret;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny bool in_transaction = false;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny bool posix;
684d1b48b5582a1bf7812b8c3c663592dc6dfed9Pavel Březina time_t now;
75dd4b05e1dacc76dc9d5f16be31978f84a71dc5Sumit Bose char *sid_str = NULL;
b56b06e199f15a8a840b36bc7cb8010e39ae761dSumit Bose bool use_id_mapping;
b9fbeb75e7a4f50f98d979a70a710f9221892483Lukas Slebodnik bool need_filter;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
4a9c1047354dbe5a4ed41e5951ae623e3772e113René Genz /* There are no groups in LDAP but we should add user to groups?? */
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (ldap_groups_count == 0) return EOK;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny tmp_ctx = talloc_new(NULL);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (!tmp_ctx) return ENOMEM;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny missing = talloc_array(tmp_ctx, char *, ldap_groups_count+1);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (!missing) {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny ret = ENOMEM;
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek goto done;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny mi = 0;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
c03214d427ea43e7bf8255ccc79faa905c89f7f6Jakub Hrozek for (i=0; sysdb_groupnames[i]; i++) {
c03214d427ea43e7bf8255ccc79faa905c89f7f6Jakub Hrozek ret = sysdb_search_group_by_name(tmp_ctx, domain, sysdb_groupnames[i], NULL,
4c08db0fb0dda3d27b1184248ca5c800d7ce23f0Michal Zidek &msg);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (ret == EOK) {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny continue;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny } else if (ret == ENOENT) {
c03214d427ea43e7bf8255ccc79faa905c89f7f6Jakub Hrozek missing[mi] = talloc_strdup(missing, sysdb_groupnames[i]);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_TRACE_LIBS, "Group #%d [%s][%s] is not cached, " \
15b5d885e28afcd6c3c19f900eea2a8e00c3e6d3Sumit Bose "need to add a fake entry\n",
c03214d427ea43e7bf8255ccc79faa905c89f7f6Jakub Hrozek i, sysdb_groupnames[i], missing[mi]);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny mi++;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny continue;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny } else if (ret != ENOENT) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "search for group failed [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek goto done;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny missing[mi] = NULL;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny /* All groups are cached, nothing to do */
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (mi == 0) {
326f4fc3125e155ee2d484fe921aafddd6b5a49dPavel Březina ret = EOK;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny goto done;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
b56b06e199f15a8a840b36bc7cb8010e39ae761dSumit Bose use_id_mapping = sdap_idmap_domain_has_algorithmic_mapping(opts->idmap_ctx,
fdda4b659fa3be3027df91a2b053835186ec2c59Sumit Bose domain->name,
b56b06e199f15a8a840b36bc7cb8010e39ae761dSumit Bose domain->domain_id);
b56b06e199f15a8a840b36bc7cb8010e39ae761dSumit Bose
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek ret = sysdb_transaction_start(sysdb);
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek if (ret != EOK) {
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Cannot start sysdb transaction [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek goto done;
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek }
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek in_transaction = true;
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek
684d1b48b5582a1bf7812b8c3c663592dc6dfed9Pavel Březina now = time(NULL);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny for (i=0; missing[i]; i++) {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny /* The group is not in sysdb, need to add a fake entry */
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny for (ai=0; ai < ldap_groups_count; ai++) {
bfd59d1a2d0d45125e5164ef12c425690d519f61Jakub Hrozek ret = sdap_get_group_primary_name(tmp_ctx, opts, ldap_groups[ai],
bfd59d1a2d0d45125e5164ef12c425690d519f61Jakub Hrozek domain, &groupname);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (ret != EOK) {
bfd59d1a2d0d45125e5164ef12c425690d519f61Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "The group has no name attribute\n");
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek goto done;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
bfd59d1a2d0d45125e5164ef12c425690d519f61Jakub Hrozek if (strcmp(groupname, missing[i]) == 0) {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny posix = true;
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher
75dd4b05e1dacc76dc9d5f16be31978f84a71dc5Sumit Bose ret = sdap_attrs_get_sid_str(
75dd4b05e1dacc76dc9d5f16be31978f84a71dc5Sumit Bose tmp_ctx, opts->idmap_ctx, ldap_groups[ai],
75dd4b05e1dacc76dc9d5f16be31978f84a71dc5Sumit Bose opts->group_map[SDAP_AT_GROUP_OBJECTSID].sys_name,
75dd4b05e1dacc76dc9d5f16be31978f84a71dc5Sumit Bose &sid_str);
75dd4b05e1dacc76dc9d5f16be31978f84a71dc5Sumit Bose if (ret != EOK && ret != ENOENT) goto done;
75dd4b05e1dacc76dc9d5f16be31978f84a71dc5Sumit Bose
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher if (use_id_mapping) {
75dd4b05e1dacc76dc9d5f16be31978f84a71dc5Sumit Bose if (sid_str == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "No SID for group [%s] " \
75dd4b05e1dacc76dc9d5f16be31978f84a71dc5Sumit Bose "while id-mapping.\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov groupname);
75dd4b05e1dacc76dc9d5f16be31978f84a71dc5Sumit Bose ret = EINVAL;
75dd4b05e1dacc76dc9d5f16be31978f84a71dc5Sumit Bose goto done;
75dd4b05e1dacc76dc9d5f16be31978f84a71dc5Sumit Bose }
75dd4b05e1dacc76dc9d5f16be31978f84a71dc5Sumit Bose
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher DEBUG(SSSDBG_TRACE_LIBS,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Mapping group [%s] objectSID to unix ID\n", groupname);
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher DEBUG(SSSDBG_TRACE_INTERNAL,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Group [%s] has objectSID [%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov groupname, sid_str);
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher /* Convert the SID into a UNIX group ID */
8be5e4497e5008f7807178acdfcbf97365ec4e73Stephen Gallagher ret = sdap_idmap_sid_to_unix(opts->idmap_ctx, sid_str,
8be5e4497e5008f7807178acdfcbf97365ec4e73Stephen Gallagher &gid);
c20a339d54b39120b4051f690ca759e6d079f177Stephen Gallagher if (ret == EOK) {
c20a339d54b39120b4051f690ca759e6d079f177Stephen Gallagher DEBUG(SSSDBG_TRACE_INTERNAL,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Group [%s] has mapped gid [%lu]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov groupname, (unsigned long)gid);
c20a339d54b39120b4051f690ca759e6d079f177Stephen Gallagher } else {
c20a339d54b39120b4051f690ca759e6d079f177Stephen Gallagher posix = false;
c20a339d54b39120b4051f690ca759e6d079f177Stephen Gallagher gid = 0;
c20a339d54b39120b4051f690ca759e6d079f177Stephen Gallagher
c20a339d54b39120b4051f690ca759e6d079f177Stephen Gallagher DEBUG(SSSDBG_TRACE_INTERNAL,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Group [%s] cannot be mapped. "
c20a339d54b39120b4051f690ca759e6d079f177Stephen Gallagher "Treating as a non-POSIX group\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov groupname);
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher }
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher } else {
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher ret = sysdb_attrs_get_uint32_t(ldap_groups[ai],
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher SYSDB_GIDNUM,
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher &gid);
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher if (ret == ENOENT || (ret == EOK && gid == 0)) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_LIBS, "The group %s gid was %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov groupname, ret == ENOENT ? "missing" : "zero");
bfd59d1a2d0d45125e5164ef12c425690d519f61Jakub Hrozek DEBUG(SSSDBG_TRACE_FUNC,
4a9c1047354dbe5a4ed41e5951ae623e3772e113René Genz "Marking group %s as non-POSIX and setting GID=0!\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov groupname);
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher gid = 0;
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher posix = false;
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher } else if (ret) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "The GID attribute is malformed\n");
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek goto done;
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny ret = sysdb_attrs_get_string(ldap_groups[ai],
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny SYSDB_ORIG_DN,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny &original_dn);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (ret) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_FUNC_DATA,
108db0e3b9e06e530364ef8228634f5e3f6bd3b5Jakub Hrozek "The group has no original DN\n");
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny original_dn = NULL;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bose ret = sysdb_handle_original_uuid(
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bose opts->group_map[SDAP_AT_GROUP_UUID].def_name,
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bose ldap_groups[ai],
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bose opts->group_map[SDAP_AT_GROUP_UUID].sys_name,
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bose ldap_groups[ai], "uniqueIDstr");
56e88cd5f3501566778b138e4934ee8e7f3fa674Lukas Slebodnik if (ret != EOK) {
56e88cd5f3501566778b138e4934ee8e7f3fa674Lukas Slebodnik DEBUG((ret == ENOENT) ? SSSDBG_TRACE_ALL : SSSDBG_MINOR_FAILURE,
56e88cd5f3501566778b138e4934ee8e7f3fa674Lukas Slebodnik "Failed to retrieve UUID [%d][%s].\n",
56e88cd5f3501566778b138e4934ee8e7f3fa674Lukas Slebodnik ret, sss_strerror(ret));
56e88cd5f3501566778b138e4934ee8e7f3fa674Lukas Slebodnik }
56e88cd5f3501566778b138e4934ee8e7f3fa674Lukas Slebodnik
108db0e3b9e06e530364ef8228634f5e3f6bd3b5Jakub Hrozek ret = sysdb_attrs_get_string(ldap_groups[ai],
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bose "uniqueIDstr",
108db0e3b9e06e530364ef8228634f5e3f6bd3b5Jakub Hrozek &uuid);
108db0e3b9e06e530364ef8228634f5e3f6bd3b5Jakub Hrozek if (ret) {
108db0e3b9e06e530364ef8228634f5e3f6bd3b5Jakub Hrozek DEBUG(SSSDBG_FUNC_DATA,
108db0e3b9e06e530364ef8228634f5e3f6bd3b5Jakub Hrozek "The group has no UUID\n");
108db0e3b9e06e530364ef8228634f5e3f6bd3b5Jakub Hrozek uuid = NULL;
108db0e3b9e06e530364ef8228634f5e3f6bd3b5Jakub Hrozek }
108db0e3b9e06e530364ef8228634f5e3f6bd3b5Jakub Hrozek
b9fbeb75e7a4f50f98d979a70a710f9221892483Lukas Slebodnik ret = sdap_check_ad_group_type(domain, opts, ldap_groups[ai],
b9fbeb75e7a4f50f98d979a70a710f9221892483Lukas Slebodnik groupname, &need_filter);
b9fbeb75e7a4f50f98d979a70a710f9221892483Lukas Slebodnik if (ret != EOK) {
b9fbeb75e7a4f50f98d979a70a710f9221892483Lukas Slebodnik goto done;
b9fbeb75e7a4f50f98d979a70a710f9221892483Lukas Slebodnik }
b9fbeb75e7a4f50f98d979a70a710f9221892483Lukas Slebodnik
b9fbeb75e7a4f50f98d979a70a710f9221892483Lukas Slebodnik if (need_filter) {
b9fbeb75e7a4f50f98d979a70a710f9221892483Lukas Slebodnik posix = false;
b9fbeb75e7a4f50f98d979a70a710f9221892483Lukas Slebodnik gid = 0;
b9fbeb75e7a4f50f98d979a70a710f9221892483Lukas Slebodnik }
b9fbeb75e7a4f50f98d979a70a710f9221892483Lukas Slebodnik
bfd59d1a2d0d45125e5164ef12c425690d519f61Jakub Hrozek DEBUG(SSSDBG_TRACE_INTERNAL,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Adding fake group %s to sysdb\n", groupname);
d115f40c7a3999e3cbe705a2ff9cf0fd493f80fbMichal Zidek ret = sysdb_add_incomplete_group(domain, groupname, gid,
108db0e3b9e06e530364ef8228634f5e3f6bd3b5Jakub Hrozek original_dn, sid_str,
108db0e3b9e06e530364ef8228634f5e3f6bd3b5Jakub Hrozek uuid, posix, now);
a2e743cd23e8e2033340612c77a8dbb8ef48c1e1Fabiano Fidêncio if (ret == ERR_GID_DUPLICATED) {
a2e743cd23e8e2033340612c77a8dbb8ef48c1e1Fabiano Fidêncio /* In case o group id-collision, do:
a2e743cd23e8e2033340612c77a8dbb8ef48c1e1Fabiano Fidêncio * - Delete the group from sysdb
a2e743cd23e8e2033340612c77a8dbb8ef48c1e1Fabiano Fidêncio * - Add the new incomplete group
a2e743cd23e8e2033340612c77a8dbb8ef48c1e1Fabiano Fidêncio * - Notify the NSS responder that the entry has also to be
a2e743cd23e8e2033340612c77a8dbb8ef48c1e1Fabiano Fidêncio * removed from the memory cache
a2e743cd23e8e2033340612c77a8dbb8ef48c1e1Fabiano Fidêncio */
a2e743cd23e8e2033340612c77a8dbb8ef48c1e1Fabiano Fidêncio ret = sdap_handle_id_collision_for_incomplete_groups(
a2e743cd23e8e2033340612c77a8dbb8ef48c1e1Fabiano Fidêncio opts->dp, domain, groupname, gid,
a2e743cd23e8e2033340612c77a8dbb8ef48c1e1Fabiano Fidêncio original_dn, sid_str, uuid, posix,
a2e743cd23e8e2033340612c77a8dbb8ef48c1e1Fabiano Fidêncio now);
a2e743cd23e8e2033340612c77a8dbb8ef48c1e1Fabiano Fidêncio }
a2e743cd23e8e2033340612c77a8dbb8ef48c1e1Fabiano Fidêncio
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (ret != EOK) {
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek goto done;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny break;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (ai == ldap_groups_count) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Group %s not present in LDAP\n", missing[i]);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny ret = EINVAL;
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek goto done;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny ret = sysdb_transaction_commit(sysdb);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "sysdb_transaction_commit failed.\n");
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek goto done;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny in_transaction = false;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny ret = EOK;
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek
21d485184df986e1a123f70c689517386e51a5ceMichal Zidekdone:
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (in_transaction) {
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek sret = sysdb_transaction_cancel(sysdb);
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek if (sret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to cancel transaction\n");
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
e30d02c04efad31f97c35165a92105852c805d34Jakub Hrozek talloc_free(tmp_ctx);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny return ret;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny}
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
6199bd6b41e8b280e65db4b4bb17a1c5c0444aa9Stephen Gallagherint sdap_initgr_common_store(struct sysdb_ctx *sysdb,
b23539e420b9962ad3bfd8f305b9d5acf47e7efbSimo Sorce struct sss_domain_info *domain,
6199bd6b41e8b280e65db4b4bb17a1c5c0444aa9Stephen Gallagher struct sdap_options *opts,
6199bd6b41e8b280e65db4b4bb17a1c5c0444aa9Stephen Gallagher const char *name,
6199bd6b41e8b280e65db4b4bb17a1c5c0444aa9Stephen Gallagher enum sysdb_member_type type,
6199bd6b41e8b280e65db4b4bb17a1c5c0444aa9Stephen Gallagher char **sysdb_grouplist,
6199bd6b41e8b280e65db4b4bb17a1c5c0444aa9Stephen Gallagher struct sysdb_attrs **ldap_groups,
6199bd6b41e8b280e65db4b4bb17a1c5c0444aa9Stephen Gallagher int ldap_groups_count)
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny{
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny TALLOC_CTX *tmp_ctx;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny char **ldap_grouplist = NULL;
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek char **ldap_fqdnlist = NULL;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny char **add_groups;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny char **del_groups;
88ab259f993956b6cd0b1a07d3d88d105e368a8cJakub Hrozek int ret, tret;
88ab259f993956b6cd0b1a07d3d88d105e368a8cJakub Hrozek bool in_transaction = false;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny tmp_ctx = talloc_new(NULL);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (!tmp_ctx) return ENOMEM;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (ldap_groups_count == 0) {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny /* No groups for this user in LDAP.
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny * We need to ensure that there are no groups
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny * in the sysdb either.
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny */
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny ldap_grouplist = NULL;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny } else {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny ret = sysdb_attrs_primary_name_list(
3931c6612fae5ad32ad81a59f77d77c2d896ebe1Jakub Hrozek domain, tmp_ctx,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny ldap_groups, ldap_groups_count,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny opts->group_map[SDAP_AT_GROUP_NAME].name,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny &ldap_grouplist);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "sysdb_attrs_primary_name_list failed [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny goto done;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny /* Find the differences between the sysdb and LDAP lists
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny * Groups in the sysdb only must be removed.
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny */
64175969779e51c00a78397746d4fec7ce7033a4Jakub Hrozek if (ldap_grouplist != NULL) {
64175969779e51c00a78397746d4fec7ce7033a4Jakub Hrozek ldap_fqdnlist = sss_create_internal_fqname_list(
64175969779e51c00a78397746d4fec7ce7033a4Jakub Hrozek tmp_ctx,
64175969779e51c00a78397746d4fec7ce7033a4Jakub Hrozek (const char * const *) ldap_grouplist,
64175969779e51c00a78397746d4fec7ce7033a4Jakub Hrozek domain->name);
64175969779e51c00a78397746d4fec7ce7033a4Jakub Hrozek if (ldap_fqdnlist == NULL) {
64175969779e51c00a78397746d4fec7ce7033a4Jakub Hrozek ret = ENOMEM;
64175969779e51c00a78397746d4fec7ce7033a4Jakub Hrozek goto done;
64175969779e51c00a78397746d4fec7ce7033a4Jakub Hrozek }
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek }
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek ret = diff_string_lists(tmp_ctx, ldap_fqdnlist, sysdb_grouplist,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny &add_groups, &del_groups, NULL);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (ret != EOK) goto done;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
88ab259f993956b6cd0b1a07d3d88d105e368a8cJakub Hrozek ret = sysdb_transaction_start(sysdb);
88ab259f993956b6cd0b1a07d3d88d105e368a8cJakub Hrozek if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to start transaction\n");
88ab259f993956b6cd0b1a07d3d88d105e368a8cJakub Hrozek goto done;
88ab259f993956b6cd0b1a07d3d88d105e368a8cJakub Hrozek }
88ab259f993956b6cd0b1a07d3d88d105e368a8cJakub Hrozek in_transaction = true;
88ab259f993956b6cd0b1a07d3d88d105e368a8cJakub Hrozek
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny /* Add fake entries for any groups the user should be added as
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny * member of but that are not cached in sysdb
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny */
88ab259f993956b6cd0b1a07d3d88d105e368a8cJakub Hrozek if (add_groups && add_groups[0]) {
b23539e420b9962ad3bfd8f305b9d5acf47e7efbSimo Sorce ret = sdap_add_incomplete_groups(sysdb, domain, opts,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny add_groups, ldap_groups,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny ldap_groups_count);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Adding incomplete users failed\n");
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny goto done;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_TRACE_INTERNAL, "Updating memberships for %s\n", name);
d115f40c7a3999e3cbe705a2ff9cf0fd493f80fbMichal Zidek ret = sysdb_update_members(domain, name, type,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny (const char *const *) add_groups,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny (const char *const *) del_groups);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Membership update failed [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny goto done;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
88ab259f993956b6cd0b1a07d3d88d105e368a8cJakub Hrozek ret = sysdb_transaction_commit(sysdb);
88ab259f993956b6cd0b1a07d3d88d105e368a8cJakub Hrozek if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to commit transaction\n");
88ab259f993956b6cd0b1a07d3d88d105e368a8cJakub Hrozek goto done;
88ab259f993956b6cd0b1a07d3d88d105e368a8cJakub Hrozek }
88ab259f993956b6cd0b1a07d3d88d105e368a8cJakub Hrozek in_transaction = false;
88ab259f993956b6cd0b1a07d3d88d105e368a8cJakub Hrozek
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny ret = EOK;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zelenydone:
88ab259f993956b6cd0b1a07d3d88d105e368a8cJakub Hrozek if (in_transaction) {
88ab259f993956b6cd0b1a07d3d88d105e368a8cJakub Hrozek tret = sysdb_transaction_cancel(sysdb);
88ab259f993956b6cd0b1a07d3d88d105e368a8cJakub Hrozek if (tret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to cancel transaction\n");
88ab259f993956b6cd0b1a07d3d88d105e368a8cJakub Hrozek }
88ab259f993956b6cd0b1a07d3d88d105e368a8cJakub Hrozek }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny talloc_zfree(tmp_ctx);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny return ret;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny}
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny/* ==Initgr-call-(groups-a-user-is-member-of)-RFC2307===================== */
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zelenystruct sdap_initgr_rfc2307_state {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct tevent_context *ev;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct sysdb_ctx *sysdb;
2ce00e0d3896bb42db169d1e79553a81ca837a22Simo Sorce struct sss_domain_info *domain;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct sdap_options *opts;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct sdap_handle *sh;
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher const char **attrs;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny const char *name;
3e39806177e1cd383743ff596cb96df44a6ce8c9Jakub Hrozek char *base_filter;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher const char *orig_dn;
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher char *filter;
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher int timeout;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct sdap_op *op;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct sysdb_attrs **ldap_groups;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny size_t ldap_groups_count;
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher size_t base_iter;
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher struct sdap_search_base **search_bases;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny};
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagherstatic errno_t sdap_initgr_rfc2307_next_base(struct tevent_req *req);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zelenystatic void sdap_initgr_rfc2307_process(struct tevent_req *subreq);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zelenystruct tevent_req *sdap_initgr_rfc2307_send(TALLOC_CTX *memctx,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct tevent_context *ev,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct sdap_options *opts,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct sysdb_ctx *sysdb,
2ce00e0d3896bb42db169d1e79553a81ca837a22Simo Sorce struct sss_domain_info *domain,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct sdap_handle *sh,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny const char *name)
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny{
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher struct tevent_req *req;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct sdap_initgr_rfc2307_state *state;
6b81b6ada1010e65b447fc74453e236fb8791813Jan Zeleny const char **attr_filter;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny char *clean_name;
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek char *shortname;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny errno_t ret;
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek char *oc_list;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny req = tevent_req_create(memctx, &state, struct sdap_initgr_rfc2307_state);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (!req) return NULL;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state->ev = ev;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state->opts = opts;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state->sysdb = sysdb;
2ce00e0d3896bb42db169d1e79553a81ca837a22Simo Sorce state->domain = domain;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state->sh = sh;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state->op = NULL;
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher state->timeout = dp_opt_get_int(state->opts->basic, SDAP_SEARCH_TIMEOUT);
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher state->ldap_groups = NULL;
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher state->ldap_groups_count = 0;
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher state->base_iter = 0;
749cfb5d3270b5daf389d51a0dbd3fd2aec6e05dJakub Hrozek state->search_bases = opts->sdom->group_search_bases;
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher
169fa5bd3edd34aa0db35681832bd7406e423c1bStephen Gallagher if (!state->search_bases) {
169fa5bd3edd34aa0db35681832bd7406e423c1bStephen Gallagher DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Initgroups lookup request without a group search base\n");
169fa5bd3edd34aa0db35681832bd7406e423c1bStephen Gallagher ret = EINVAL;
169fa5bd3edd34aa0db35681832bd7406e423c1bStephen Gallagher goto done;
169fa5bd3edd34aa0db35681832bd7406e423c1bStephen Gallagher }
169fa5bd3edd34aa0db35681832bd7406e423c1bStephen Gallagher
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state->name = talloc_strdup(state, name);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (!state->name) {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny talloc_zfree(req);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny return NULL;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
6b81b6ada1010e65b447fc74453e236fb8791813Jan Zeleny attr_filter = talloc_array(state, const char *, 2);
6b81b6ada1010e65b447fc74453e236fb8791813Jan Zeleny if (!attr_filter) {
6b81b6ada1010e65b447fc74453e236fb8791813Jan Zeleny talloc_free(req);
6b81b6ada1010e65b447fc74453e236fb8791813Jan Zeleny return NULL;
6b81b6ada1010e65b447fc74453e236fb8791813Jan Zeleny }
6b81b6ada1010e65b447fc74453e236fb8791813Jan Zeleny
6b81b6ada1010e65b447fc74453e236fb8791813Jan Zeleny attr_filter[0] = opts->group_map[SDAP_AT_GROUP_MEMBER].name;
6b81b6ada1010e65b447fc74453e236fb8791813Jan Zeleny attr_filter[1] = NULL;
6b81b6ada1010e65b447fc74453e236fb8791813Jan Zeleny
64ddff90c7fcc02ccb06824ac93af7d5f361a88fJan Zeleny ret = build_attrs_from_map(state, opts->group_map, SDAP_OPTS_GROUP,
6b81b6ada1010e65b447fc74453e236fb8791813Jan Zeleny attr_filter, &state->attrs, NULL);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (ret != EOK) {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny talloc_free(req);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny return NULL;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek ret = sss_parse_internal_fqname(state, name,
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek &shortname, NULL);
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek if (ret != EOK) {
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "Cannot parse %s\n", name);
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek goto done;
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek }
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek ret = sss_filter_sanitize(state, shortname, &clean_name);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (ret != EOK) {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny talloc_free(req);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny return NULL;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek oc_list = sdap_make_oc_list(state, opts->group_map);
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek if (oc_list == NULL) {
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek DEBUG(SSSDBG_CRIT_FAILURE, "Failed to create objectClass list.\n");
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek ret = ENOMEM;
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek goto done;
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek }
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher state->base_filter = talloc_asprintf(state,
3e39806177e1cd383743ff596cb96df44a6ce8c9Jakub Hrozek "(&(%s=%s)(%s)(%s=*)",
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny opts->group_map[SDAP_AT_GROUP_MEMBER].name,
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek clean_name, oc_list,
3e39806177e1cd383743ff596cb96df44a6ce8c9Jakub Hrozek opts->group_map[SDAP_AT_GROUP_NAME].name);
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher if (!state->base_filter) {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny talloc_zfree(req);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny return NULL;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny talloc_zfree(clean_name);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
3e39806177e1cd383743ff596cb96df44a6ce8c9Jakub Hrozek switch (domain->type) {
3e39806177e1cd383743ff596cb96df44a6ce8c9Jakub Hrozek case DOM_TYPE_APPLICATION:
3e39806177e1cd383743ff596cb96df44a6ce8c9Jakub Hrozek state->base_filter = talloc_asprintf_append(state->base_filter, ")");
3e39806177e1cd383743ff596cb96df44a6ce8c9Jakub Hrozek break;
3e39806177e1cd383743ff596cb96df44a6ce8c9Jakub Hrozek case DOM_TYPE_POSIX:
3e39806177e1cd383743ff596cb96df44a6ce8c9Jakub Hrozek state->base_filter = talloc_asprintf_append(state->base_filter,
3e39806177e1cd383743ff596cb96df44a6ce8c9Jakub Hrozek "(&(%s=*)(!(%s=0))))",
3e39806177e1cd383743ff596cb96df44a6ce8c9Jakub Hrozek opts->group_map[SDAP_AT_GROUP_GID].name,
3e39806177e1cd383743ff596cb96df44a6ce8c9Jakub Hrozek opts->group_map[SDAP_AT_GROUP_GID].name);
3e39806177e1cd383743ff596cb96df44a6ce8c9Jakub Hrozek break;
3e39806177e1cd383743ff596cb96df44a6ce8c9Jakub Hrozek }
3e39806177e1cd383743ff596cb96df44a6ce8c9Jakub Hrozek if (!state->base_filter) {
3e39806177e1cd383743ff596cb96df44a6ce8c9Jakub Hrozek ret = ENOMEM;
3e39806177e1cd383743ff596cb96df44a6ce8c9Jakub Hrozek goto done;
3e39806177e1cd383743ff596cb96df44a6ce8c9Jakub Hrozek }
3e39806177e1cd383743ff596cb96df44a6ce8c9Jakub Hrozek
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher ret = sdap_initgr_rfc2307_next_base(req);
169fa5bd3edd34aa0db35681832bd7406e423c1bStephen Gallagher
169fa5bd3edd34aa0db35681832bd7406e423c1bStephen Gallagherdone:
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher if (ret != EOK) {
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher tevent_req_error(req, ret);
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher tevent_req_post(req, ev);
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher }
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher return req;
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher}
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagherstatic errno_t sdap_initgr_rfc2307_next_base(struct tevent_req *req)
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher{
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher struct tevent_req *subreq;
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher struct sdap_initgr_rfc2307_state *state;
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher state = tevent_req_data(req, struct sdap_initgr_rfc2307_state);
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher talloc_zfree(state->filter);
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher
92ec40e6aa25f75903ffdb166a8ec56b67bfd77dPavel Březina state->filter = sdap_combine_filters( state, state->base_filter,
92ec40e6aa25f75903ffdb166a8ec56b67bfd77dPavel Březina state->search_bases[state->base_iter]->filter);
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher if (!state->filter) {
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher return ENOMEM;
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher }
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher DEBUG(SSSDBG_TRACE_FUNC,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Searching for groups with base [%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov state->search_bases[state->base_iter]->basedn);
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher subreq = sdap_get_generic_send(
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher state, state->ev, state->opts, state->sh,
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher state->search_bases[state->base_iter]->basedn,
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher state->search_bases[state->base_iter]->scope,
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher state->filter, state->attrs,
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher state->opts->group_map, SDAP_OPTS_GROUP,
2f3ee3f49019f5b60adbe073070f31e6e2d7c7abStephen Gallagher state->timeout,
2f3ee3f49019f5b60adbe073070f31e6e2d7c7abStephen Gallagher true);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (!subreq) {
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher return ENOMEM;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny tevent_req_set_callback(subreq, sdap_initgr_rfc2307_process, req);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher return EOK;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny}
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zelenystatic void sdap_initgr_rfc2307_process(struct tevent_req *subreq)
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny{
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct tevent_req *req;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct sdap_initgr_rfc2307_state *state;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct sysdb_attrs **ldap_groups;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny char **sysdb_grouplist = NULL;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny size_t count;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny int ret;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny int i;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny req = tevent_req_callback_data(subreq, struct tevent_req);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state = tevent_req_data(req, struct sdap_initgr_rfc2307_state);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny ret = sdap_get_generic_recv(subreq, state, &count, &ldap_groups);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny talloc_zfree(subreq);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (ret) {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny tevent_req_error(req, ret);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny return;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher /* Add this batch of groups to the list */
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher if (count > 0) {
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher state->ldap_groups =
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher talloc_realloc(state,
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher state->ldap_groups,
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher struct sysdb_attrs *,
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher state->ldap_groups_count + count + 1);
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher if (!state->ldap_groups) {
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher tevent_req_error(req, ENOMEM);
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher return;
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher }
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher /* Copy the new groups into the list.
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher */
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher for (i = 0; i < count; i++) {
3a0522759a7e71b40cc88dba0f5c545b049cf9bfJakub Hrozek state->ldap_groups[state->ldap_groups_count + i] =
3a0522759a7e71b40cc88dba0f5c545b049cf9bfJakub Hrozek talloc_steal(state->ldap_groups, ldap_groups[i]);
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher }
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher state->ldap_groups_count += count;
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher state->ldap_groups[state->ldap_groups_count] = NULL;
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher }
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher state->base_iter++;
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher /* Check for additional search bases, and iterate
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher * through again.
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher */
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher if (state->search_bases[state->base_iter] != NULL) {
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher ret = sdap_initgr_rfc2307_next_base(req);
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher if (ret != EOK) {
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher tevent_req_error(req, ret);
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher }
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher return;
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher }
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny /* Search for all groups for which this user is a member */
2ce00e0d3896bb42db169d1e79553a81ca837a22Simo Sorce ret = get_sysdb_grouplist(state, state->sysdb, state->domain,
2ce00e0d3896bb42db169d1e79553a81ca837a22Simo Sorce state->name, &sysdb_grouplist);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (ret != EOK) {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny tevent_req_error(req, ret);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny return;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny /* There are no nested groups here so we can just update the
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny * memberships */
b23539e420b9962ad3bfd8f305b9d5acf47e7efbSimo Sorce ret = sdap_initgr_common_store(state->sysdb,
b23539e420b9962ad3bfd8f305b9d5acf47e7efbSimo Sorce state->domain,
b23539e420b9962ad3bfd8f305b9d5acf47e7efbSimo Sorce state->opts,
ac3a1f3da772cf101101c31675c63dc3549b21b5Jakub Hrozek state->name,
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher SYSDB_MEMBER_USER,
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher sysdb_grouplist,
38e1ee5d65ade946f1322efa96f69c05e041c57fStephen Gallagher state->ldap_groups,
88ab259f993956b6cd0b1a07d3d88d105e368a8cJakub Hrozek state->ldap_groups_count);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (ret != EOK) {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny tevent_req_error(req, ret);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny return;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny tevent_req_done(req);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny}
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zelenystatic int sdap_initgr_rfc2307_recv(struct tevent_req *req)
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny{
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny TEVENT_REQ_RETURN_ON_ERROR(req);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny return EOK;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny}
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek/* ==Common code for pure RFC2307bis and IPA/AD========================= */
49d3f0a487d55571b2bdc9d3f8280b304b964b9dSumit Boseerrno_t
c88e387d10104774852d54355fc17ad41761776aJakub Hrozeksdap_nested_groups_store(struct sysdb_ctx *sysdb,
b23539e420b9962ad3bfd8f305b9d5acf47e7efbSimo Sorce struct sss_domain_info *domain,
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek struct sdap_options *opts,
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek struct sysdb_attrs **groups,
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek unsigned long count)
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek{
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek errno_t ret, tret;
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek TALLOC_CTX *tmp_ctx;
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek char **groupnamelist = NULL;
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek bool in_transaction = false;
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek tmp_ctx = talloc_new(NULL);
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek if (!tmp_ctx) return ENOMEM;
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek if (count > 0) {
73ead5bb50130663668ded57822d9850b2dc2fffJakub Hrozek ret = sysdb_attrs_primary_fqdn_list(domain, tmp_ctx,
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek groups, count,
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek opts->group_map[SDAP_AT_GROUP_NAME].name,
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek &groupnamelist);
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "sysdb_attrs_primary_name_list failed [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek goto done;
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek }
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek }
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek ret = sysdb_transaction_start(sysdb);
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to start transaction\n");
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek goto done;
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek }
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek in_transaction = true;
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek
b23539e420b9962ad3bfd8f305b9d5acf47e7efbSimo Sorce ret = sdap_add_incomplete_groups(sysdb, domain, opts, groupnamelist,
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek groups, count);
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Could not add incomplete groups [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek goto done;
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek }
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek ret = sysdb_transaction_commit(sysdb);
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to commit transaction\n");
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek goto done;
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek }
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek in_transaction = false;
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek ret = EOK;
c88e387d10104774852d54355fc17ad41761776aJakub Hrozekdone:
f249521d2ebf23ccb03a93e070060f6e9d3db94cJakub Hrozek if (in_transaction) {
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek tret = sysdb_transaction_cancel(sysdb);
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek if (tret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to cancel transaction\n");
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek }
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek }
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek talloc_free(tmp_ctx);
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek return ret;
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek}
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek
c88e387d10104774852d54355fc17ad41761776aJakub Hrozekstruct membership_diff {
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek struct membership_diff *prev;
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek struct membership_diff *next;
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek const char *name;
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek char **add;
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek char **del;
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek};
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek
c88e387d10104774852d54355fc17ad41761776aJakub Hrozekstatic errno_t
c88e387d10104774852d54355fc17ad41761776aJakub Hrozekbuild_membership_diff(TALLOC_CTX *mem_ctx, const char *name,
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek char **ldap_parent_names, char **sysdb_parent_names,
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek struct membership_diff **_mdiff)
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek{
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek TALLOC_CTX *tmp_ctx;
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek struct membership_diff *mdiff;
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek errno_t ret;
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek char **add_groups;
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek char **del_groups;
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek tmp_ctx = talloc_new(NULL);
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek if (!tmp_ctx) {
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek ret = ENOMEM;
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek goto done;
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek }
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek mdiff = talloc_zero(tmp_ctx, struct membership_diff);
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek if (!mdiff) {
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek ret = ENOMEM;
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek goto done;
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek }
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek mdiff->name = talloc_strdup(mdiff, name);
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek if (!mdiff->name) {
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek ret = ENOMEM;
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek goto done;
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek }
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek /* Find the differences between the sysdb and ldap lists
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek * Groups in ldap only must be added to the sysdb;
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek * groups in the sysdb only must be removed.
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek */
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek ret = diff_string_lists(tmp_ctx,
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek ldap_parent_names, sysdb_parent_names,
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek &add_groups, &del_groups, NULL);
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek if (ret != EOK) {
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek goto done;
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek }
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek mdiff->add = talloc_steal(mdiff, add_groups);
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek mdiff->del = talloc_steal(mdiff, del_groups);
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek ret = EOK;
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek *_mdiff = talloc_steal(mem_ctx, mdiff);
c88e387d10104774852d54355fc17ad41761776aJakub Hrozekdone:
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek talloc_free(tmp_ctx);
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek return ret;
c88e387d10104774852d54355fc17ad41761776aJakub Hrozek}
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny/* ==Initgr-call-(groups-a-user-is-member-of)-nested-groups=============== */
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zelenystruct sdap_initgr_nested_state {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct tevent_context *ev;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct sysdb_ctx *sysdb;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct sdap_options *opts;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct sss_domain_info *dom;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct sdap_handle *sh;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct sysdb_attrs *user;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny const char *username;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek const char *orig_dn;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny const char **grp_attrs;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek struct ldb_message_element *memberof;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny char *filter;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny char **group_dns;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny int cur;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct sdap_op *op;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct sysdb_attrs **groups;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny int groups_cur;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny};
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozekstatic errno_t sdap_initgr_nested_deref_search(struct tevent_req *req);
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozekstatic errno_t sdap_initgr_nested_noderef_search(struct tevent_req *req);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zelenystatic void sdap_initgr_nested_search(struct tevent_req *subreq);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zelenystatic void sdap_initgr_nested_store(struct tevent_req *req);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zelenystatic struct tevent_req *sdap_initgr_nested_send(TALLOC_CTX *memctx,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct tevent_context *ev,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct sdap_options *opts,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct sysdb_ctx *sysdb,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct sss_domain_info *dom,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct sdap_handle *sh,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct sysdb_attrs *user,
ac67376a47ed52374641e7a4f6fd97712fe5171bJakub Hrozek const char **grp_attrs)
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny{
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek struct tevent_req *req;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct sdap_initgr_nested_state *state;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny errno_t ret;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek int deref_threshold;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny req = tevent_req_create(memctx, &state, struct sdap_initgr_nested_state);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (!req) return NULL;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state->ev = ev;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state->opts = opts;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state->sysdb = sysdb;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state->dom = dom;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state->sh = sh;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state->grp_attrs = grp_attrs;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state->user = user;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state->op = NULL;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
bfd59d1a2d0d45125e5164ef12c425690d519f61Jakub Hrozek ret = sdap_get_user_primary_name(memctx, opts, user, dom, &state->username);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "User entry had no username\n");
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek goto immediate;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek ret = sysdb_attrs_get_el(state->user, SYSDB_MEMBEROF, &state->memberof);
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek if (ret || !state->memberof || state->memberof->num_values == 0) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CONF_SETTINGS, "User entry lacks original memberof ?\n");
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny /* We can't find any groups for this user, so we'll
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny * have to assume there aren't any. Just return
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny * success here.
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny */
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek ret = EOK;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek goto immediate;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state->groups = talloc_zero_array(state, struct sysdb_attrs *,
b9941359b3181c42f415530d5ccad0f4664d85faLukas Slebodnik state->memberof->num_values + 1);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (!state->groups) {
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek ret = ENOMEM;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek goto immediate;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state->groups_cur = 0;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek deref_threshold = dp_opt_get_int(state->opts->basic,
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek SDAP_DEREF_THRESHOLD);
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek if (sdap_has_deref_support(state->sh, state->opts) &&
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek deref_threshold < state->memberof->num_values) {
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek ret = sysdb_attrs_get_string(user, SYSDB_ORIG_DN,
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek &state->orig_dn);
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek if (ret != EOK) goto immediate;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek ret = sdap_initgr_nested_deref_search(req);
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek if (ret != EAGAIN) goto immediate;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek } else {
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek ret = sdap_initgr_nested_noderef_search(req);
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek if (ret != EAGAIN) goto immediate;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek }
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek return req;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozekimmediate:
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek if (ret == EOK) {
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek tevent_req_done(req);
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek } else {
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek tevent_req_error(req, ret);
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek }
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek tevent_req_post(req, ev);
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek return req;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek}
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozekstatic errno_t sdap_initgr_nested_noderef_search(struct tevent_req *req)
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek{
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek int i;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek struct tevent_req *subreq;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek struct sdap_initgr_nested_state *state;
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek char *oc_list;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek state = tevent_req_data(req, struct sdap_initgr_nested_state);
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek state->group_dns = talloc_array(state, char *,
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek state->memberof->num_values + 1);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (!state->group_dns) {
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek return ENOMEM;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek for (i = 0; i < state->memberof->num_values; i++) {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state->group_dns[i] = talloc_strdup(state->group_dns,
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek (char *)state->memberof->values[i].data);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (!state->group_dns[i]) {
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek return ENOMEM;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state->group_dns[i] = NULL; /* terminate */
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state->cur = 0;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek oc_list = sdap_make_oc_list(state, state->opts->group_map);
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek if (oc_list == NULL) {
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek DEBUG(SSSDBG_CRIT_FAILURE, "Failed to create objectClass list.\n");
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek return ENOMEM;
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek }
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek state->filter = talloc_asprintf(state, "(&(%s)(%s=*))", oc_list,
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek state->opts->group_map[SDAP_AT_GROUP_NAME].name);
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek if (!state->filter) {
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek return ENOMEM;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek }
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny subreq = sdap_get_generic_send(state, state->ev, state->opts, state->sh,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state->group_dns[state->cur],
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny LDAP_SCOPE_BASE,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state->filter, state->grp_attrs,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state->opts->group_map, SDAP_OPTS_GROUP,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny dp_opt_get_int(state->opts->basic,
2f3ee3f49019f5b60adbe073070f31e6e2d7c7abStephen Gallagher SDAP_SEARCH_TIMEOUT),
2f3ee3f49019f5b60adbe073070f31e6e2d7c7abStephen Gallagher false);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (!subreq) {
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek return ENOMEM;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny tevent_req_set_callback(subreq, sdap_initgr_nested_search, req);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek return EAGAIN;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek}
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozekstatic void sdap_initgr_nested_deref_done(struct tevent_req *subreq);
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozekstatic errno_t sdap_initgr_nested_deref_search(struct tevent_req *req)
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek{
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek struct tevent_req *subreq;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek struct sdap_attr_map_info *maps;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek const int num_maps = 1;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek const char **sdap_attrs;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek errno_t ret;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek int timeout;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek struct sdap_initgr_nested_state *state;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek state = tevent_req_data(req, struct sdap_initgr_nested_state);
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek maps = talloc_array(state, struct sdap_attr_map_info, num_maps+1);
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek if (!maps) return ENOMEM;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek maps[0].map = state->opts->group_map;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek maps[0].num_attrs = SDAP_OPTS_GROUP;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek maps[1].map = NULL;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek
64ddff90c7fcc02ccb06824ac93af7d5f361a88fJan Zeleny ret = build_attrs_from_map(state, state->opts->group_map, SDAP_OPTS_GROUP,
64ddff90c7fcc02ccb06824ac93af7d5f361a88fJan Zeleny NULL, &sdap_attrs, NULL);
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek if (ret != EOK) goto fail;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek
f393e23f264a299868a12bec40a390a7ecd65d10Stephen Gallagher timeout = dp_opt_get_int(state->opts->basic, SDAP_SEARCH_TIMEOUT);
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek subreq = sdap_deref_search_send(state, state->ev, state->opts,
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek state->sh, state->orig_dn,
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek state->opts->user_map[SDAP_AT_USER_MEMBEROF].name,
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek sdap_attrs, num_maps, maps, timeout);
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek if (!subreq) {
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek ret = EIO;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek goto fail;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek }
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek talloc_steal(subreq, sdap_attrs);
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek talloc_steal(subreq, maps);
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek tevent_req_set_callback(subreq, sdap_initgr_nested_deref_done, req);
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek return EAGAIN;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozekfail:
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek talloc_free(sdap_attrs);
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek talloc_free(maps);
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek return ret;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek}
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozekstatic void sdap_initgr_nested_deref_done(struct tevent_req *subreq)
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek{
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek errno_t ret;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek struct tevent_req *req;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek struct sdap_initgr_nested_state *state;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek size_t num_results;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek size_t i;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek struct sdap_deref_attrs **deref_result;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek req = tevent_req_callback_data(subreq, struct tevent_req);
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek state = tevent_req_data(req, struct sdap_initgr_nested_state);
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek ret = sdap_deref_search_recv(subreq, state,
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek &num_results,
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek &deref_result);
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek talloc_zfree(subreq);
4709ff46db0dbe073aef061b796d2fd7adeaf18fJan Cholasta if (ret == ENOTSUP) {
4709ff46db0dbe073aef061b796d2fd7adeaf18fJan Cholasta ret = sdap_initgr_nested_noderef_search(req);
4709ff46db0dbe073aef061b796d2fd7adeaf18fJan Cholasta if (ret != EAGAIN) {
4709ff46db0dbe073aef061b796d2fd7adeaf18fJan Cholasta if (ret == EOK) {
4709ff46db0dbe073aef061b796d2fd7adeaf18fJan Cholasta tevent_req_done(req);
4709ff46db0dbe073aef061b796d2fd7adeaf18fJan Cholasta } else {
4709ff46db0dbe073aef061b796d2fd7adeaf18fJan Cholasta tevent_req_error(req, ret);
4709ff46db0dbe073aef061b796d2fd7adeaf18fJan Cholasta }
4709ff46db0dbe073aef061b796d2fd7adeaf18fJan Cholasta }
4709ff46db0dbe073aef061b796d2fd7adeaf18fJan Cholasta return;
4709ff46db0dbe073aef061b796d2fd7adeaf18fJan Cholasta } else if (ret != EOK && ret != ENOENT) {
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek tevent_req_error(req, ret);
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek return;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek } else if (ret == ENOENT || deref_result == NULL) {
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek /* Nothing could be dereferenced. Done. */
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek tevent_req_done(req);
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek return;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek }
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek for (i=0; i < num_results; i++) {
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek state->groups[i] = talloc_steal(state->groups,
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek deref_result[i]->attrs);
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek }
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek state->groups_cur = num_results;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek sdap_initgr_nested_store(req);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny}
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zelenystatic void sdap_initgr_nested_search(struct tevent_req *subreq)
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny{
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct tevent_req *req;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct sdap_initgr_nested_state *state;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct sysdb_attrs **groups;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny size_t count;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny int ret;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny req = tevent_req_callback_data(subreq, struct tevent_req);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state = tevent_req_data(req, struct sdap_initgr_nested_state);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny ret = sdap_get_generic_recv(subreq, state, &count, &groups);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny talloc_zfree(subreq);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (ret) {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny tevent_req_error(req, ret);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny return;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (count == 1) {
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek state->groups[state->groups_cur] = talloc_steal(state->groups,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek groups[0]);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state->groups_cur++;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny } else {
a75266b247510719f7879f876809a1b03c31a3deJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
a75266b247510719f7879f876809a1b03c31a3deJakub Hrozek "Search for group %s, returned %zu results. Skipping\n",
bc8c93ffe881271043492c938c626a9be948000ePavel Reichl state->group_dns[state->cur], count);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state->cur++;
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek /* note that state->memberof->num_values is the count of original
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek * memberOf which might not be only groups, but permissions, etc.
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek * Use state->groups_cur for group index cap */
f46b9fd64ef09aae23220c5adb2fe4d3e4adc553Jakub Hrozek if (state->cur < state->memberof->num_values) {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny subreq = sdap_get_generic_send(state, state->ev,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state->opts, state->sh,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state->group_dns[state->cur],
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny LDAP_SCOPE_BASE,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state->filter, state->grp_attrs,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state->opts->group_map,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny SDAP_OPTS_GROUP,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny dp_opt_get_int(state->opts->basic,
2f3ee3f49019f5b60adbe073070f31e6e2d7c7abStephen Gallagher SDAP_SEARCH_TIMEOUT),
2f3ee3f49019f5b60adbe073070f31e6e2d7c7abStephen Gallagher false);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (!subreq) {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny tevent_req_error(req, ENOMEM);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny return;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny tevent_req_set_callback(subreq, sdap_initgr_nested_search, req);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny } else {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny sdap_initgr_nested_store(req);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny}
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozekstatic errno_t
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozeksdap_initgr_store_groups(struct sdap_initgr_nested_state *state);
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozekstatic errno_t
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozeksdap_initgr_store_group_memberships(struct sdap_initgr_nested_state *state);
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozekstatic errno_t
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozeksdap_initgr_store_user_memberships(struct sdap_initgr_nested_state *state);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zelenystatic void sdap_initgr_nested_store(struct tevent_req *req)
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny{
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek errno_t ret;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct sdap_initgr_nested_state *state;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek bool in_transaction = false;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek errno_t tret;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek state = tevent_req_data(req, struct sdap_initgr_nested_state);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek ret = sysdb_transaction_start(state->sysdb);
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to start transaction\n");
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek goto fail;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek }
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek in_transaction = true;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek /* save the groups if they are not already */
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek ret = sdap_initgr_store_groups(state);
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Could not save groups [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek goto fail;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek /* save the group memberships */
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek ret = sdap_initgr_store_group_memberships(state);
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Could not save group memberships [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek goto fail;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek /* save the user memberships */
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek ret = sdap_initgr_store_user_memberships(state);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Could not save user memberships [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek goto fail;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek ret = sysdb_transaction_commit(state->sysdb);
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to commit transaction\n");
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek goto fail;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek }
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek in_transaction = false;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek tevent_req_done(req);
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek return;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozekfail:
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek if (in_transaction) {
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek tret = sysdb_transaction_cancel(state->sysdb);
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek if (tret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to cancel transaction\n");
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek tevent_req_error(req, ret);
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek return;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek}
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozekstatic errno_t
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozeksdap_initgr_store_groups(struct sdap_initgr_nested_state *state)
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek{
b23539e420b9962ad3bfd8f305b9d5acf47e7efbSimo Sorce return sdap_nested_groups_store(state->sysdb, state->dom,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek state->opts, state->groups,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek state->groups_cur);
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek}
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozekstatic errno_t
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozeksdap_initgr_nested_get_membership_diff(TALLOC_CTX *mem_ctx,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek struct sysdb_ctx *sysdb,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek struct sdap_options *opts,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek struct sss_domain_info *dom,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek struct sysdb_attrs *group,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek struct sysdb_attrs **all_groups,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek int groups_count,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek struct membership_diff **mdiff);
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozekstatic int sdap_initgr_nested_get_direct_parents(TALLOC_CTX *mem_ctx,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek struct sysdb_attrs *attrs,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek struct sysdb_attrs **groups,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek int ngroups,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek struct sysdb_attrs ***_direct_parents,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek int *_ndirect);
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozekstatic errno_t
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozeksdap_initgr_store_group_memberships(struct sdap_initgr_nested_state *state)
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek{
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek errno_t ret;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek int i, tret;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek TALLOC_CTX *tmp_ctx;
9f37bb2012faa136ef7c1f9fe93689ce2be85637Ondrej Kos struct membership_diff *miter = NULL;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek struct membership_diff *memberships = NULL;
f249521d2ebf23ccb03a93e070060f6e9d3db94cJakub Hrozek bool in_transaction = false;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek tmp_ctx = talloc_new(NULL);
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek if (!tmp_ctx) return ENOMEM;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek /* Compute the diffs first in order to keep the transaction as small
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek * as possible
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek */
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek for (i=0; i < state->groups_cur; i++) {
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek ret = sdap_initgr_nested_get_membership_diff(tmp_ctx, state->sysdb,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek state->opts, state->dom,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek state->groups[i],
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek state->groups,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek state->groups_cur,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek &miter);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (ret) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Could not compute memberships for group %d [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov i, ret, strerror(ret));
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny goto done;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek DLIST_ADD(memberships, miter);
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek ret = sysdb_transaction_start(state->sysdb);
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to start transaction\n");
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek goto done;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek }
f249521d2ebf23ccb03a93e070060f6e9d3db94cJakub Hrozek in_transaction = true;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek DLIST_FOR_EACH(miter, memberships) {
d115f40c7a3999e3cbe705a2ff9cf0fd493f80fbMichal Zidek ret = sysdb_update_members(state->dom, miter->name,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek SYSDB_MEMBER_GROUP,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek (const char *const *) miter->add,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek (const char *const *) miter->del);
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Failed to update memberships\n");
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek goto done;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek ret = sysdb_transaction_commit(state->sysdb);
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to commit transaction\n");
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek goto done;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek }
f249521d2ebf23ccb03a93e070060f6e9d3db94cJakub Hrozek in_transaction = false;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek ret = EOK;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozekdone:
f249521d2ebf23ccb03a93e070060f6e9d3db94cJakub Hrozek if (in_transaction) {
f249521d2ebf23ccb03a93e070060f6e9d3db94cJakub Hrozek tret = sysdb_transaction_cancel(state->sysdb);
f249521d2ebf23ccb03a93e070060f6e9d3db94cJakub Hrozek if (tret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to cancel transaction\n");
f249521d2ebf23ccb03a93e070060f6e9d3db94cJakub Hrozek }
f249521d2ebf23ccb03a93e070060f6e9d3db94cJakub Hrozek }
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek talloc_free(tmp_ctx);
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek return ret;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek}
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozekstatic errno_t
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozeksdap_initgr_store_user_memberships(struct sdap_initgr_nested_state *state)
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek{
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek errno_t ret;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek int tret;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek const char *orig_dn;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek char **sysdb_parent_name_list = NULL;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek char **ldap_parent_name_list = NULL;
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek char **ldap_fqdnlist = NULL;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek int nparents;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek struct sysdb_attrs **ldap_parentlist;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek struct ldb_message_element *el;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek int i, mi;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek char **add_groups;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek char **del_groups;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek TALLOC_CTX *tmp_ctx;
f249521d2ebf23ccb03a93e070060f6e9d3db94cJakub Hrozek bool in_transaction = false;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek tmp_ctx = talloc_new(NULL);
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek if (!tmp_ctx) {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny ret = ENOMEM;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny goto done;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek /* Get direct LDAP parents */
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek ret = sysdb_attrs_get_string(state->user, SYSDB_ORIG_DN, &orig_dn);
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "The user has no original DN\n");
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny goto done;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek ldap_parentlist = talloc_zero_array(tmp_ctx, struct sysdb_attrs *,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek state->groups_cur + 1);
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek if (!ldap_parentlist) {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny ret = ENOMEM;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny goto done;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek nparents = 0;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek for (i=0; i < state->groups_cur ; i++) {
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek ret = sysdb_attrs_get_el(state->groups[i], SYSDB_MEMBER, &el);
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek if (ret) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "A group with no members during initgroups?\n");
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny goto done;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek for (mi = 0; mi < el->num_values; mi++) {
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek if (strcasecmp((const char *) el->values[mi].data, orig_dn) != 0) {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny continue;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek ldap_parentlist[nparents] = state->groups[i];
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek nparents++;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek }
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_TRACE_LIBS,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "The user %s is a direct member of %d LDAP groups\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov state->username, nparents);
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek if (nparents == 0) {
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek ldap_parent_name_list = NULL;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny } else {
3931c6612fae5ad32ad81a59f77d77c2d896ebe1Jakub Hrozek ret = sysdb_attrs_primary_name_list(state->dom, tmp_ctx,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek ldap_parentlist,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek nparents,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek state->opts->group_map[SDAP_AT_GROUP_NAME].name,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek &ldap_parent_name_list);
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "sysdb_attrs_primary_name_list failed [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek goto done;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
64175969779e51c00a78397746d4fec7ce7033a4Jakub Hrozek if (ldap_parent_name_list) {
64175969779e51c00a78397746d4fec7ce7033a4Jakub Hrozek ldap_fqdnlist = sss_create_internal_fqname_list(
64175969779e51c00a78397746d4fec7ce7033a4Jakub Hrozek tmp_ctx,
64175969779e51c00a78397746d4fec7ce7033a4Jakub Hrozek (const char * const *) ldap_parent_name_list,
64175969779e51c00a78397746d4fec7ce7033a4Jakub Hrozek state->dom->name);
64175969779e51c00a78397746d4fec7ce7033a4Jakub Hrozek if (ldap_fqdnlist == NULL) {
64175969779e51c00a78397746d4fec7ce7033a4Jakub Hrozek ret = ENOMEM;
64175969779e51c00a78397746d4fec7ce7033a4Jakub Hrozek goto done;
64175969779e51c00a78397746d4fec7ce7033a4Jakub Hrozek }
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek }
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek
3dd4c3eca80e9223a65f3318821bd0fb5b45aeddSumit Bose ret = sysdb_get_direct_parents(tmp_ctx, state->dom, state->dom,
3dd4c3eca80e9223a65f3318821bd0fb5b45aeddSumit Bose SYSDB_MEMBER_USER,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek state->username, &sysdb_parent_name_list);
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek if (ret) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Could not get direct sysdb parents for %s: %d [%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov state->username, ret, strerror(ret));
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny goto done;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek ret = diff_string_lists(tmp_ctx,
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek ldap_fqdnlist, sysdb_parent_name_list,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek &add_groups, &del_groups, NULL);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (ret != EOK) {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny goto done;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek ret = sysdb_transaction_start(state->sysdb);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to start transaction\n");
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny goto done;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f249521d2ebf23ccb03a93e070060f6e9d3db94cJakub Hrozek in_transaction = true;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_TRACE_INTERNAL,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Updating memberships for %s\n", state->username);
d115f40c7a3999e3cbe705a2ff9cf0fd493f80fbMichal Zidek ret = sysdb_update_members(state->dom, state->username, SYSDB_MEMBER_USER,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek (const char *const *) add_groups,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek (const char *const *) del_groups);
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Could not update sysdb memberships for %s: %d [%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov state->username, ret, strerror(ret));
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek goto done;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek ret = sysdb_transaction_commit(state->sysdb);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (ret != EOK) {
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek goto done;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f249521d2ebf23ccb03a93e070060f6e9d3db94cJakub Hrozek in_transaction = false;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek ret = EOK;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozekdone:
f249521d2ebf23ccb03a93e070060f6e9d3db94cJakub Hrozek if (in_transaction) {
f249521d2ebf23ccb03a93e070060f6e9d3db94cJakub Hrozek tret = sysdb_transaction_cancel(state->sysdb);
f249521d2ebf23ccb03a93e070060f6e9d3db94cJakub Hrozek if (tret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to cancel transaction\n");
f249521d2ebf23ccb03a93e070060f6e9d3db94cJakub Hrozek }
f249521d2ebf23ccb03a93e070060f6e9d3db94cJakub Hrozek }
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek talloc_zfree(tmp_ctx);
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek return ret;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny}
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozekstatic errno_t
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozeksdap_initgr_nested_get_membership_diff(TALLOC_CTX *mem_ctx,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek struct sysdb_ctx *sysdb,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek struct sdap_options *opts,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek struct sss_domain_info *dom,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek struct sysdb_attrs *group,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek struct sysdb_attrs **all_groups,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek int groups_count,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek struct membership_diff **_mdiff)
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny{
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek errno_t ret;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek struct membership_diff *mdiff;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny const char *group_name;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek struct sysdb_attrs **ldap_parentlist;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek int parents_count;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek char **ldap_parent_names_list = NULL;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek char **sysdb_parents_names_list = NULL;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek TALLOC_CTX *tmp_ctx;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek tmp_ctx = talloc_new(NULL);
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek if (!tmp_ctx) {
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek ret = ENOMEM;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny goto done;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek /* Get direct sysdb parents */
bfd59d1a2d0d45125e5164ef12c425690d519f61Jakub Hrozek ret = sdap_get_group_primary_name(tmp_ctx, opts, group, dom, &group_name);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (ret != EOK) {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny goto done;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
3dd4c3eca80e9223a65f3318821bd0fb5b45aeddSumit Bose ret = sysdb_get_direct_parents(tmp_ctx, dom, dom, SYSDB_MEMBER_GROUP,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek group_name, &sysdb_parents_names_list);
fd61c807554d5a3ff74f065eb0438fe2524f4ba2Jakub Hrozek if (ret) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Could not get direct sysdb parents for %s: %d [%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov group_name, ret, strerror(ret));
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny goto done;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek /* For each group, filter only parents from full set */
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek ret = sdap_initgr_nested_get_direct_parents(tmp_ctx,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek group,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek all_groups,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek groups_count,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek &ldap_parentlist,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek &parents_count);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Cannot get parent groups for %s [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov group_name, ret, strerror(ret));
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny goto done;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_TRACE_LIBS,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "The group %s is a direct member of %d LDAP groups\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov group_name, parents_count);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek if (parents_count > 0) {
5bd3bef4a655fdfacd2f5df8a2343fe7bc68a771Sumit Bose ret = sysdb_attrs_primary_fqdn_list(dom, tmp_ctx,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek ldap_parentlist,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek parents_count,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek opts->group_map[SDAP_AT_GROUP_NAME].name,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek &ldap_parent_names_list);
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "sysdb_attrs_primary_name_list failed [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek goto done;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek }
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek }
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek ret = build_membership_diff(tmp_ctx, group_name, ldap_parent_names_list,
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek sysdb_parents_names_list, &mdiff);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Could not build membership diff for %s [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov group_name, ret, strerror(ret));
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny goto done;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny ret = EOK;
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek *_mdiff = talloc_steal(mem_ctx, mdiff);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zelenydone:
707ddc7de4d43a96a372880c50cb20b9672c9cdfJakub Hrozek talloc_free(tmp_ctx);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny return ret;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny}
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zelenystatic int sdap_initgr_nested_get_direct_parents(TALLOC_CTX *mem_ctx,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct sysdb_attrs *attrs,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct sysdb_attrs **groups,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny int ngroups,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct sysdb_attrs ***_direct_parents,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny int *_ndirect)
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny{
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny TALLOC_CTX *tmp_ctx;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct ldb_message_element *member;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny int i, mi;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny int ret;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny const char *orig_dn;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny int ndirect;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct sysdb_attrs **direct_groups;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny tmp_ctx = talloc_new(NULL);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (!tmp_ctx) return ENOMEM;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny direct_groups = talloc_zero_array(tmp_ctx, struct sysdb_attrs *,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny ngroups + 1);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (!direct_groups) {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny ret = ENOMEM;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny goto done;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny ndirect = 0;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny ret = sysdb_attrs_get_string(attrs, SYSDB_ORIG_DN, &orig_dn);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Missing originalDN\n");
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny goto done;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_TRACE_ALL,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Looking up direct parents for group [%s]\n", orig_dn);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny /* FIXME - Filter only parents from full set to avoid searching
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny * through all members of huge groups. That requires asking for memberOf
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny * with the group LDAP search
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny */
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny /* Filter only direct parents from the list of all groups */
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny for (i=0; i < ngroups; i++) {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny ret = sysdb_attrs_get_el(groups[i], SYSDB_MEMBER, &member);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (ret) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_TRACE_LIBS,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "A group with no members during initgroups?\n");
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny continue;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny for (mi = 0; mi < member->num_values; mi++) {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (strcasecmp((const char *) member->values[mi].data, orig_dn) != 0) {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny continue;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny direct_groups[ndirect] = groups[i];
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny ndirect++;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny direct_groups[ndirect] = NULL;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_TRACE_ALL,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "The group [%s] has %d direct parents\n", orig_dn, ndirect);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
d3bdb23bec3432591acb1135a108ee9bdd5f87e0Jakub Hrozek *_direct_parents = talloc_steal(mem_ctx, direct_groups);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny *_ndirect = ndirect;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny ret = EOK;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zelenydone:
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny talloc_zfree(tmp_ctx);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny return ret;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny}
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zelenystatic int sdap_initgr_nested_recv(struct tevent_req *req)
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny{
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny TEVENT_REQ_RETURN_ON_ERROR(req);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny return EOK;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny}
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny/* ==Initgr-call-(groups-a-user-is-member-of)-RFC2307-BIS================= */
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozekstruct sdap_initgr_rfc2307bis_state {
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek struct tevent_context *ev;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek struct sysdb_ctx *sysdb;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek struct sdap_options *opts;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek struct sss_domain_info *dom;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek struct sdap_handle *sh;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek const char *name;
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek char *base_filter;
fd21ca460115a5d51d0db6e5ac759b8aff51ab99Jakub Hrozek char *filter;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher const char **attrs;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher const char *orig_dn;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher int timeout;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher size_t base_iter;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher struct sdap_search_base **search_bases;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek struct sdap_op *op;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek hash_table_t *group_hash;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek size_t num_direct_parents;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek struct sysdb_attrs **direct_groups;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek};
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozekstruct sdap_nested_group {
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek struct sysdb_attrs *group;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek struct sysdb_attrs **ldap_parents;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek size_t parents_count;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek};
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagherstatic errno_t sdap_initgr_rfc2307bis_next_base(struct tevent_req *req);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zelenystatic void sdap_initgr_rfc2307bis_process(struct tevent_req *subreq);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zelenystatic void sdap_initgr_rfc2307bis_done(struct tevent_req *subreq);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zelenyerrno_t save_rfc2307bis_user_memberships(
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek struct sdap_initgr_rfc2307bis_state *state);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zelenystatic struct tevent_req *sdap_initgr_rfc2307bis_send(
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny TALLOC_CTX *memctx,
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct tevent_context *ev,
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct sdap_options *opts,
1b870ffa7910879f9310db453a31ab6f06392b9bJakub Hrozek struct sdap_domain *sdom,
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct sdap_handle *sh,
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny const char *name,
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny const char *orig_dn)
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny{
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny errno_t ret;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct tevent_req *req;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek struct sdap_initgr_rfc2307bis_state *state;
6b81b6ada1010e65b447fc74453e236fb8791813Jan Zeleny const char **attr_filter;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny char *clean_orig_dn;
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek bool use_id_mapping;
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek char *oc_list;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek req = tevent_req_create(memctx, &state, struct sdap_initgr_rfc2307bis_state);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (!req) return NULL;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state->ev = ev;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny state->opts = opts;
1b870ffa7910879f9310db453a31ab6f06392b9bJakub Hrozek state->sysdb = sdom->dom->sysdb;
1b870ffa7910879f9310db453a31ab6f06392b9bJakub Hrozek state->dom = sdom->dom;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state->sh = sh;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny state->op = NULL;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state->name = name;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher state->direct_groups = NULL;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher state->num_direct_parents = 0;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher state->timeout = dp_opt_get_int(state->opts->basic, SDAP_SEARCH_TIMEOUT);
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher state->base_iter = 0;
1b870ffa7910879f9310db453a31ab6f06392b9bJakub Hrozek state->search_bases = sdom->group_search_bases;
b4adc08bcc1cc225133146163989301b607c79b5Stephen Gallagher state->orig_dn = orig_dn;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
169fa5bd3edd34aa0db35681832bd7406e423c1bStephen Gallagher if (!state->search_bases) {
169fa5bd3edd34aa0db35681832bd7406e423c1bStephen Gallagher DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Initgroups lookup request without a group search base\n");
169fa5bd3edd34aa0db35681832bd7406e423c1bStephen Gallagher ret = EINVAL;
169fa5bd3edd34aa0db35681832bd7406e423c1bStephen Gallagher goto done;
169fa5bd3edd34aa0db35681832bd7406e423c1bStephen Gallagher }
169fa5bd3edd34aa0db35681832bd7406e423c1bStephen Gallagher
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek ret = sss_hash_create(state, 32, &state->group_hash);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek if (ret != EOK) {
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek talloc_free(req);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek return NULL;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek }
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek
6b81b6ada1010e65b447fc74453e236fb8791813Jan Zeleny attr_filter = talloc_array(state, const char *, 2);
6b81b6ada1010e65b447fc74453e236fb8791813Jan Zeleny if (!attr_filter) {
6b81b6ada1010e65b447fc74453e236fb8791813Jan Zeleny ret = ENOMEM;
6b81b6ada1010e65b447fc74453e236fb8791813Jan Zeleny goto done;
6b81b6ada1010e65b447fc74453e236fb8791813Jan Zeleny }
6b81b6ada1010e65b447fc74453e236fb8791813Jan Zeleny
6b81b6ada1010e65b447fc74453e236fb8791813Jan Zeleny attr_filter[0] = opts->group_map[SDAP_AT_GROUP_MEMBER].name;
6b81b6ada1010e65b447fc74453e236fb8791813Jan Zeleny attr_filter[1] = NULL;
6b81b6ada1010e65b447fc74453e236fb8791813Jan Zeleny
64ddff90c7fcc02ccb06824ac93af7d5f361a88fJan Zeleny ret = build_attrs_from_map(state, opts->group_map, SDAP_OPTS_GROUP,
6b81b6ada1010e65b447fc74453e236fb8791813Jan Zeleny attr_filter, &state->attrs, NULL);
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher if (ret != EOK) goto done;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny ret = sss_filter_sanitize(state, orig_dn, &clean_orig_dn);
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher if (ret != EOK) goto done;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher
1b870ffa7910879f9310db453a31ab6f06392b9bJakub Hrozek use_id_mapping = sdap_idmap_domain_has_algorithmic_mapping(
1b870ffa7910879f9310db453a31ab6f06392b9bJakub Hrozek opts->idmap_ctx,
fdda4b659fa3be3027df91a2b053835186ec2c59Sumit Bose sdom->dom->name,
1b870ffa7910879f9310db453a31ab6f06392b9bJakub Hrozek sdom->dom->domain_id);
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek oc_list = sdap_make_oc_list(state, opts->group_map);
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek if (oc_list == NULL) {
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek DEBUG(SSSDBG_CRIT_FAILURE, "Failed to create objectClass list.\n");
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek ret = ENOMEM;
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek goto done;
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek }
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher state->base_filter =
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek talloc_asprintf(state,
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek "(&(%s=%s)(%s)(%s=*)",
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher opts->group_map[SDAP_AT_GROUP_MEMBER].name,
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek clean_orig_dn, oc_list,
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher opts->group_map[SDAP_AT_GROUP_NAME].name);
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher if (!state->base_filter) {
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher ret = ENOMEM;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher goto done;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher }
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek if (use_id_mapping) {
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek /* When mapping IDs or looking for SIDs, we don't want to limit
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek * ourselves to groups with a GID value. But there must be a SID to map
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek * from.
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek */
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek state->base_filter = talloc_asprintf_append(state->base_filter,
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek "(%s=*))",
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek opts->group_map[SDAP_AT_GROUP_OBJECTSID].name);
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek } else {
981bf55532fbec91a106f82d7daf32094c76dfe0Pavel Reichl state->base_filter = talloc_asprintf_append(state->base_filter, ")");
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek }
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek if (!state->base_filter) {
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek talloc_zfree(req);
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek return NULL;
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek }
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher talloc_zfree(clean_orig_dn);
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher ret = sdap_initgr_rfc2307bis_next_base(req);
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagherdone:
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny if (ret != EOK) {
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher tevent_req_error(req, ret);
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher tevent_req_post(req, ev);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher return req;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher}
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagherstatic errno_t sdap_initgr_rfc2307bis_next_base(struct tevent_req *req)
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher{
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher struct tevent_req *subreq;
fd21ca460115a5d51d0db6e5ac759b8aff51ab99Jakub Hrozek struct sdap_initgr_rfc2307bis_state *state;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher
fd21ca460115a5d51d0db6e5ac759b8aff51ab99Jakub Hrozek state = tevent_req_data(req, struct sdap_initgr_rfc2307bis_state);
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher talloc_zfree(state->filter);
92ec40e6aa25f75903ffdb166a8ec56b67bfd77dPavel Březina state->filter = sdap_combine_filters(state, state->base_filter,
92ec40e6aa25f75903ffdb166a8ec56b67bfd77dPavel Březina state->search_bases[state->base_iter]->filter);
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher if (!state->filter) {
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher return ENOMEM;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher DEBUG(SSSDBG_TRACE_FUNC,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Searching for parent groups for user [%s] with base [%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov state->orig_dn, state->search_bases[state->base_iter]->basedn);
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher subreq = sdap_get_generic_send(
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher state, state->ev, state->opts, state->sh,
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher state->search_bases[state->base_iter]->basedn,
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher state->search_bases[state->base_iter]->scope,
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher state->filter, state->attrs,
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher state->opts->group_map, SDAP_OPTS_GROUP,
2f3ee3f49019f5b60adbe073070f31e6e2d7c7abStephen Gallagher state->timeout,
2f3ee3f49019f5b60adbe073070f31e6e2d7c7abStephen Gallagher true);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (!subreq) {
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher return ENOMEM;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny tevent_req_set_callback(subreq, sdap_initgr_rfc2307bis_process, req);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher return EOK;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny}
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zelenystatic void sdap_initgr_rfc2307bis_process(struct tevent_req *subreq)
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny{
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct tevent_req *req;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek struct sdap_initgr_rfc2307bis_state *state;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher struct sysdb_attrs **ldap_groups;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher size_t count;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher size_t i;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny int ret;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny req = tevent_req_callback_data(subreq, struct tevent_req);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek state = tevent_req_data(req, struct sdap_initgr_rfc2307bis_state);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny ret = sdap_get_generic_recv(subreq, state,
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher &count,
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher &ldap_groups);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny talloc_zfree(subreq);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (ret) {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny tevent_req_error(req, ret);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny return;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek DEBUG(SSSDBG_TRACE_LIBS,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Found %zu parent groups for user [%s]\n", count, state->name);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher /* Add this batch of groups to the list */
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher if (count > 0) {
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher state->direct_groups =
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher talloc_realloc(state,
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher state->direct_groups,
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher struct sysdb_attrs *,
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher state->num_direct_parents + count + 1);
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher if (!state->direct_groups) {
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher tevent_req_error(req, ENOMEM);
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher return;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher }
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher /* Copy the new groups into the list.
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher */
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher for (i = 0; i < count; i++) {
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher state->direct_groups[state->num_direct_parents + i] =
3a0522759a7e71b40cc88dba0f5c545b049cf9bfJakub Hrozek talloc_steal(state->direct_groups, ldap_groups[i]);
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher }
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher state->num_direct_parents += count;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher state->direct_groups[state->num_direct_parents] = NULL;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher }
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher state->base_iter++;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher /* Check for additional search bases, and iterate
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher * through again.
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher */
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher if (state->search_bases[state->base_iter] != NULL) {
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher ret = sdap_initgr_rfc2307bis_next_base(req);
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher if (ret != EOK) {
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher tevent_req_error(req, ret);
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher }
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher return;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher }
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek if (state->num_direct_parents == 0) {
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny /* Start a transaction to look up the groups in the sysdb
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny * and update them with LDAP data
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny */
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny ret = save_rfc2307bis_user_memberships(state);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny if (ret != EOK) {
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny tevent_req_error(req, ret);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny } else {
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny tevent_req_done(req);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny return;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny subreq = rfc2307bis_nested_groups_send(state, state->ev, state->opts,
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny state->sysdb, state->dom,
5b94e341a6ae347f49cfd18d574c9f37d0c2633eSumit Bose state->sh,
5b94e341a6ae347f49cfd18d574c9f37d0c2633eSumit Bose state->search_bases,
5b94e341a6ae347f49cfd18d574c9f37d0c2633eSumit Bose state->direct_groups,
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek state->num_direct_parents,
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek state->group_hash, 0);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny if (!subreq) {
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny tevent_req_error(req, EIO);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny return;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny tevent_req_set_callback(subreq, sdap_initgr_rfc2307bis_done, req);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny}
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozekstatic errno_t
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozeksave_rfc2307bis_groups(struct sdap_initgr_rfc2307bis_state *state);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozekstatic errno_t
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozeksave_rfc2307bis_group_memberships(struct sdap_initgr_rfc2307bis_state *state);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zelenystatic void sdap_initgr_rfc2307bis_done(struct tevent_req *subreq)
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny{
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny errno_t ret;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct tevent_req *req =
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny tevent_req_callback_data(subreq, struct tevent_req);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek struct sdap_initgr_rfc2307bis_state *state =
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek tevent_req_data(req, struct sdap_initgr_rfc2307bis_state);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek bool in_transaction = false;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek errno_t tret;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny ret = rfc2307bis_nested_groups_recv(subreq);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny talloc_zfree(subreq);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny if (ret != EOK) {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny tevent_req_error(req, ret);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny return;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek ret = sysdb_transaction_start(state->sysdb);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to start transaction\n");
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek goto fail;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek }
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek in_transaction = true;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek /* save the groups if they are not cached */
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek ret = save_rfc2307bis_groups(state);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE,
87f8bee53ee1b4ca87b602ff8536bc5fd5b5b595Lukas Slebodnik "Could not save groups memberships [%d]\n", ret);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek goto fail;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek }
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek /* save the group membership */
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek ret = save_rfc2307bis_group_memberships(state);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE,
87f8bee53ee1b4ca87b602ff8536bc5fd5b5b595Lukas Slebodnik "Could not save group memberships [%d]\n", ret);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek goto fail;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek }
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny /* save the user memberships */
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny ret = save_rfc2307bis_user_memberships(state);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE,
87f8bee53ee1b4ca87b602ff8536bc5fd5b5b595Lukas Slebodnik "Could not save user memberships [%d]\n", ret);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek goto fail;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek }
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek ret = sysdb_transaction_commit(state->sysdb);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to commit transaction\n");
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek goto fail;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek }
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek in_transaction = false;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek tevent_req_done(req);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek return;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozekfail:
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek if (in_transaction) {
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek tret = sysdb_transaction_cancel(state->sysdb);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek if (tret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to cancel transaction\n");
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek tevent_req_error(req, ret);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny return;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny}
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zelenystatic int sdap_initgr_rfc2307bis_recv(struct tevent_req *req)
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny{
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny TEVENT_REQ_RETURN_ON_ERROR(req);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny return EOK;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny}
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozekstruct rfc2307bis_group_memberships_state {
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek struct sysdb_ctx *sysdb;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek struct sdap_options *opts;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek struct sss_domain_info *dom;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek hash_table_t *group_hash;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek struct membership_diff *memberships;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek int ret;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek};
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozekstatic errno_t
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozeksave_rfc2307bis_groups(struct sdap_initgr_rfc2307bis_state *state)
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny{
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek struct sysdb_attrs **groups = NULL;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek unsigned long count;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek hash_value_t *values;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek int hret, i;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek errno_t ret;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek TALLOC_CTX *tmp_ctx;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek struct sdap_nested_group *gr;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek tmp_ctx = talloc_new(NULL);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek if (!tmp_ctx) return ENOMEM;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek hret = hash_values(state->group_hash, &count, &values);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek if (hret != HASH_SUCCESS) {
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek ret = EIO;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek goto done;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek groups = talloc_array(tmp_ctx, struct sysdb_attrs *, count);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek if (!groups) {
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek ret = ENOMEM;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek goto done;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek }
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek for (i = 0; i < count; i++) {
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek gr = talloc_get_type(values[i].ptr,
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek struct sdap_nested_group);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek groups[i] = gr->group;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek }
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek talloc_zfree(values);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek
b23539e420b9962ad3bfd8f305b9d5acf47e7efbSimo Sorce ret = sdap_nested_groups_store(state->sysdb, state->dom, state->opts,
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek groups, count);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Could not save groups [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek goto done;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek ret = EOK;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozekdone:
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek talloc_free(tmp_ctx);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek return ret;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek}
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozekstatic bool rfc2307bis_group_memberships_build(hash_entry_t *item, void *user_data);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozekstatic errno_t
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozeksave_rfc2307bis_group_memberships(struct sdap_initgr_rfc2307bis_state *state)
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek{
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek errno_t ret, tret;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek int hret;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek TALLOC_CTX *tmp_ctx;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek struct rfc2307bis_group_memberships_state *membership_state;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek struct membership_diff *iter;
fb5abb2a7abf63974d8db444c66f50a2dd74901fMichal Zidek struct membership_diff *iter_start;
fb5abb2a7abf63974d8db444c66f50a2dd74901fMichal Zidek struct membership_diff *iter_tmp;
f249521d2ebf23ccb03a93e070060f6e9d3db94cJakub Hrozek bool in_transaction = false;
fb5abb2a7abf63974d8db444c66f50a2dd74901fMichal Zidek int num_added;
fb5abb2a7abf63974d8db444c66f50a2dd74901fMichal Zidek int i;
fb5abb2a7abf63974d8db444c66f50a2dd74901fMichal Zidek int grp_count;
fb5abb2a7abf63974d8db444c66f50a2dd74901fMichal Zidek char **add = NULL;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek tmp_ctx = talloc_new(NULL);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek if (!tmp_ctx) return ENOMEM;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek membership_state = talloc_zero(tmp_ctx,
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek struct rfc2307bis_group_memberships_state);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek if (!membership_state) {
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny ret = ENOMEM;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek goto done;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek membership_state->sysdb = state->sysdb;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek membership_state->dom = state->dom;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek membership_state->opts = state->opts;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek membership_state->group_hash = state->group_hash;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek hret = hash_iterate(state->group_hash,
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek rfc2307bis_group_memberships_build,
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek membership_state);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek if (hret != HASH_SUCCESS) {
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek ret = membership_state->ret;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek goto done;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny }
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek ret = sysdb_transaction_start(state->sysdb);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to start transaction\n");
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek goto done;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny }
f249521d2ebf23ccb03a93e070060f6e9d3db94cJakub Hrozek in_transaction = true;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
fb5abb2a7abf63974d8db444c66f50a2dd74901fMichal Zidek iter_start = membership_state->memberships;
fb5abb2a7abf63974d8db444c66f50a2dd74901fMichal Zidek
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek DLIST_FOR_EACH(iter, membership_state->memberships) {
fb5abb2a7abf63974d8db444c66f50a2dd74901fMichal Zidek /* Create a copy of iter->add array but do not include groups outside
fb5abb2a7abf63974d8db444c66f50a2dd74901fMichal Zidek * nesting limit. This array must be NULL terminated.
fb5abb2a7abf63974d8db444c66f50a2dd74901fMichal Zidek */
fb5abb2a7abf63974d8db444c66f50a2dd74901fMichal Zidek for (grp_count = 0; iter->add[grp_count]; grp_count++);
1a54e022351a60fbfa619ef7ed6138fb892ad11aJakub Hrozek add = talloc_zero_array(tmp_ctx, char *, grp_count + 1);
1a54e022351a60fbfa619ef7ed6138fb892ad11aJakub Hrozek if (add == NULL) {
1a54e022351a60fbfa619ef7ed6138fb892ad11aJakub Hrozek ret = ENOMEM;
1a54e022351a60fbfa619ef7ed6138fb892ad11aJakub Hrozek goto done;
fb5abb2a7abf63974d8db444c66f50a2dd74901fMichal Zidek }
fb5abb2a7abf63974d8db444c66f50a2dd74901fMichal Zidek
fb5abb2a7abf63974d8db444c66f50a2dd74901fMichal Zidek num_added = 0;
fb5abb2a7abf63974d8db444c66f50a2dd74901fMichal Zidek for (i = 0; i < grp_count; i++) {
fb5abb2a7abf63974d8db444c66f50a2dd74901fMichal Zidek DLIST_FOR_EACH(iter_tmp, iter_start) {
fb5abb2a7abf63974d8db444c66f50a2dd74901fMichal Zidek if (!strcmp(iter_tmp->name,iter->add[i])) {
fb5abb2a7abf63974d8db444c66f50a2dd74901fMichal Zidek add[num_added] = iter->add[i];
fb5abb2a7abf63974d8db444c66f50a2dd74901fMichal Zidek num_added++;
fb5abb2a7abf63974d8db444c66f50a2dd74901fMichal Zidek break;
fb5abb2a7abf63974d8db444c66f50a2dd74901fMichal Zidek }
fb5abb2a7abf63974d8db444c66f50a2dd74901fMichal Zidek }
fb5abb2a7abf63974d8db444c66f50a2dd74901fMichal Zidek }
fb5abb2a7abf63974d8db444c66f50a2dd74901fMichal Zidek
fb5abb2a7abf63974d8db444c66f50a2dd74901fMichal Zidek if (num_added == 0) {
e3961dfa29324af5b6b9645fd7485c9035bdb18bJakub Hrozek add = NULL;
fb5abb2a7abf63974d8db444c66f50a2dd74901fMichal Zidek } else {
fb5abb2a7abf63974d8db444c66f50a2dd74901fMichal Zidek add[num_added] = NULL;
fb5abb2a7abf63974d8db444c66f50a2dd74901fMichal Zidek }
d115f40c7a3999e3cbe705a2ff9cf0fd493f80fbMichal Zidek ret = sysdb_update_members(state->dom, iter->name,
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek SYSDB_MEMBER_GROUP,
fb5abb2a7abf63974d8db444c66f50a2dd74901fMichal Zidek (const char *const *) add,
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek (const char *const *) iter->del);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Failed to update memberships\n");
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek goto done;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek }
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek }
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek ret = sysdb_transaction_commit(state->sysdb);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to commit transaction\n");
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek goto done;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek }
f249521d2ebf23ccb03a93e070060f6e9d3db94cJakub Hrozek in_transaction = false;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek ret = EOK;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozekdone:
f249521d2ebf23ccb03a93e070060f6e9d3db94cJakub Hrozek if (in_transaction) {
f249521d2ebf23ccb03a93e070060f6e9d3db94cJakub Hrozek tret = sysdb_transaction_cancel(state->sysdb);
f249521d2ebf23ccb03a93e070060f6e9d3db94cJakub Hrozek if (tret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to cancel transaction\n");
f249521d2ebf23ccb03a93e070060f6e9d3db94cJakub Hrozek }
f249521d2ebf23ccb03a93e070060f6e9d3db94cJakub Hrozek }
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek talloc_free(tmp_ctx);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek return ret;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek}
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozekstatic bool
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozekrfc2307bis_group_memberships_build(hash_entry_t *item, void *user_data)
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek{
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek struct rfc2307bis_group_memberships_state *mstate = talloc_get_type(
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek user_data, struct rfc2307bis_group_memberships_state);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek struct sdap_nested_group *group;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek char *group_name;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek TALLOC_CTX *tmp_ctx;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek errno_t ret;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek char **sysdb_parents_names_list;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek char **ldap_parents_names_list = NULL;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek struct membership_diff *mdiff;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek group_name = (char *) item->key.str;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek group = (struct sdap_nested_group *) item->value.ptr;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek tmp_ctx = talloc_new(NULL);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek if (!tmp_ctx) {
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny ret = ENOMEM;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek goto done;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
3dd4c3eca80e9223a65f3318821bd0fb5b45aeddSumit Bose ret = sysdb_get_direct_parents(tmp_ctx, mstate->dom, mstate->dom,
3dd4c3eca80e9223a65f3318821bd0fb5b45aeddSumit Bose SYSDB_MEMBER_GROUP,
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek group_name, &sysdb_parents_names_list);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek if (ret) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Could not get direct sysdb parents for %s: %d [%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov group_name, ret, strerror(ret));
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek goto done;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek if (group->parents_count > 0) {
6a89b38c032593ed705e679c23e6a4efce9f3defJakub Hrozek ret = sysdb_attrs_primary_fqdn_list(mstate->dom, tmp_ctx,
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek group->ldap_parents, group->parents_count,
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek mstate->opts->group_map[SDAP_AT_GROUP_NAME].name,
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek &ldap_parents_names_list);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek if (ret != EOK) {
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek goto done;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny }
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek ret = build_membership_diff(tmp_ctx, group_name, ldap_parents_names_list,
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek sysdb_parents_names_list, &mdiff);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Could not build membership diff for %s [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov group_name, ret, strerror(ret));
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek goto done;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek talloc_steal(mstate, mdiff);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek DLIST_ADD(mstate->memberships, mdiff);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek ret = EOK;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozekdone:
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek talloc_free(tmp_ctx);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek mstate->ret = ret;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek return ret == EOK ? true : false;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek}
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozekerrno_t save_rfc2307bis_user_memberships(
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek struct sdap_initgr_rfc2307bis_state *state)
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek{
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek errno_t ret, tret;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek char **ldap_grouplist;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek char **sysdb_parent_name_list;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek char **add_groups;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek char **del_groups;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek bool in_transaction = false;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek TALLOC_CTX *tmp_ctx = talloc_new(NULL);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek if(!tmp_ctx) {
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek return ENOMEM;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_TRACE_LIBS, "Save parent groups to sysdb\n");
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek ret = sysdb_transaction_start(state->sysdb);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to start transaction\n");
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek goto error;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek }
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek in_transaction = true;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek
3dd4c3eca80e9223a65f3318821bd0fb5b45aeddSumit Bose ret = sysdb_get_direct_parents(tmp_ctx, state->dom, state->dom,
3dd4c3eca80e9223a65f3318821bd0fb5b45aeddSumit Bose SYSDB_MEMBER_USER,
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek state->name, &sysdb_parent_name_list);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek if (ret) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Could not get direct sysdb parents for %s: %d [%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov state->name, ret, strerror(ret));
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek goto error;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek }
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek if (state->num_direct_parents == 0) {
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny ldap_grouplist = NULL;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny }
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny else {
73ead5bb50130663668ded57822d9850b2dc2fffJakub Hrozek ret = sysdb_attrs_primary_fqdn_list(
73ead5bb50130663668ded57822d9850b2dc2fffJakub Hrozek state->dom, tmp_ctx,
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek state->direct_groups, state->num_direct_parents,
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny state->opts->group_map[SDAP_AT_GROUP_NAME].name,
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny &ldap_grouplist);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny if (ret != EOK) {
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny goto error;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny /* Find the differences between the sysdb and ldap lists
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny * Groups in ldap only must be added to the sysdb;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny * groups in the sysdb only must be removed.
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny */
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny ret = diff_string_lists(tmp_ctx,
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek ldap_grouplist, sysdb_parent_name_list,
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny &add_groups, &del_groups, NULL);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (ret != EOK) {
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny goto error;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_TRACE_INTERNAL, "Updating memberships for %s\n", state->name);
d115f40c7a3999e3cbe705a2ff9cf0fd493f80fbMichal Zidek ret = sysdb_update_members(state->dom, state->name, SYSDB_MEMBER_USER,
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny (const char *const *)add_groups,
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny (const char *const *)del_groups);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny if (ret != EOK) {
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny goto error;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny ret = sysdb_transaction_commit(state->sysdb);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to commit transaction\n");
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny goto error;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f249521d2ebf23ccb03a93e070060f6e9d3db94cJakub Hrozek in_transaction = false;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
e30d02c04efad31f97c35165a92105852c805d34Jakub Hrozek talloc_free(tmp_ctx);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny return EOK;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zelenyerror:
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny if (in_transaction) {
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny tret = sysdb_transaction_cancel(state->sysdb);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny if (tret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to cancel transaction\n");
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny talloc_free(tmp_ctx);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny return ret;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny}
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zelenystruct sdap_rfc2307bis_nested_ctx {
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct tevent_context *ev;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct sdap_options *opts;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct sysdb_ctx *sysdb;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct sss_domain_info *dom;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct sdap_handle *sh;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher int timeout;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher const char *base_filter;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher char *filter;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher const char *orig_dn;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher const char **attrs;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct sysdb_attrs **groups;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny size_t num_groups;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny size_t nesting_level;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny size_t group_iter;
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek struct sdap_nested_group **processed_groups;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek hash_table_t *group_hash;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek const char *primary_name;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct sysdb_handle *handle;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher size_t base_iter;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher struct sdap_search_base **search_bases;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny};
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zelenystatic errno_t rfc2307bis_nested_groups_step(struct tevent_req *req);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zelenystruct tevent_req *rfc2307bis_nested_groups_send(
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny TALLOC_CTX *mem_ctx, struct tevent_context *ev,
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct sdap_options *opts, struct sysdb_ctx *sysdb,
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct sss_domain_info *dom, struct sdap_handle *sh,
5b94e341a6ae347f49cfd18d574c9f37d0c2633eSumit Bose struct sdap_search_base **search_bases,
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct sysdb_attrs **groups, size_t num_groups,
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek hash_table_t *group_hash, size_t nesting)
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny{
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny errno_t ret;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct tevent_req *req;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct sdap_rfc2307bis_nested_ctx *state;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek DEBUG(SSSDBG_TRACE_INTERNAL,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "About to process %zu groups in nesting level %zu\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov num_groups, nesting);
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny req = tevent_req_create(mem_ctx, &state,
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct sdap_rfc2307bis_nested_ctx);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (!req) return NULL;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny if ((num_groups == 0) ||
93493702980e23d5b0322d16681f4ba77d6dd999Lukas Slebodnik (nesting > dp_opt_get_int(opts->basic, SDAP_NESTING_LEVEL))) {
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny /* No parent groups to process or too deep*/
9356e8f50436724e985d9a8f5d4f2bc0f5b837bcJakub Hrozek ret = EOK;
9356e8f50436724e985d9a8f5d4f2bc0f5b837bcJakub Hrozek goto done;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny }
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state->ev = ev;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state->opts = opts;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state->sysdb = sysdb;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state->dom = dom;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state->sh = sh;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny state->groups = groups;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny state->num_groups = num_groups;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny state->group_iter = 0;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny state->nesting_level = nesting;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek state->group_hash = group_hash;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher state->filter = NULL;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher state->timeout = dp_opt_get_int(state->opts->basic,
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher SDAP_SEARCH_TIMEOUT);
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher state->base_iter = 0;
5b94e341a6ae347f49cfd18d574c9f37d0c2633eSumit Bose state->search_bases = search_bases;
169fa5bd3edd34aa0db35681832bd7406e423c1bStephen Gallagher if (!state->search_bases) {
169fa5bd3edd34aa0db35681832bd7406e423c1bStephen Gallagher DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Initgroups nested lookup request "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "without a group search base\n");
169fa5bd3edd34aa0db35681832bd7406e423c1bStephen Gallagher ret = EINVAL;
169fa5bd3edd34aa0db35681832bd7406e423c1bStephen Gallagher goto done;
169fa5bd3edd34aa0db35681832bd7406e423c1bStephen Gallagher }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek state->processed_groups = talloc_array(state,
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek struct sdap_nested_group *,
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek state->num_groups);
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek if (state->processed_groups == NULL) {
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek ret = ENOMEM;
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek goto done;
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek }
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek
9356e8f50436724e985d9a8f5d4f2bc0f5b837bcJakub Hrozek while (state->group_iter < state->num_groups) {
9356e8f50436724e985d9a8f5d4f2bc0f5b837bcJakub Hrozek ret = rfc2307bis_nested_groups_step(req);
9356e8f50436724e985d9a8f5d4f2bc0f5b837bcJakub Hrozek if (ret == EOK) {
9356e8f50436724e985d9a8f5d4f2bc0f5b837bcJakub Hrozek /* This group had already been looked up. Continue to
9356e8f50436724e985d9a8f5d4f2bc0f5b837bcJakub Hrozek * another group in the same level
9356e8f50436724e985d9a8f5d4f2bc0f5b837bcJakub Hrozek */
9356e8f50436724e985d9a8f5d4f2bc0f5b837bcJakub Hrozek state->group_iter++;
9356e8f50436724e985d9a8f5d4f2bc0f5b837bcJakub Hrozek continue;
9356e8f50436724e985d9a8f5d4f2bc0f5b837bcJakub Hrozek } else {
9356e8f50436724e985d9a8f5d4f2bc0f5b837bcJakub Hrozek goto done;
9356e8f50436724e985d9a8f5d4f2bc0f5b837bcJakub Hrozek }
9356e8f50436724e985d9a8f5d4f2bc0f5b837bcJakub Hrozek }
169fa5bd3edd34aa0db35681832bd7406e423c1bStephen Gallagher
67ef63cc88230e13a15cb9e5485340469c4bcc3ePavel Březina ret = EOK;
67ef63cc88230e13a15cb9e5485340469c4bcc3ePavel Březina
169fa5bd3edd34aa0db35681832bd7406e423c1bStephen Gallagherdone:
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek if (ret == EOK) {
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek /* All parent groups were already processed */
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek tevent_req_done(req);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek tevent_req_post(req, ev);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek } else if (ret != EAGAIN) {
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny tevent_req_error(req, ret);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny tevent_req_post(req, ev);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek /* EAGAIN means a lookup is in progress */
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny return req;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny}
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagherstatic errno_t rfc2307bis_nested_groups_next_base(struct tevent_req *req);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zelenystatic void rfc2307bis_nested_groups_process(struct tevent_req *subreq);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zelenystatic errno_t rfc2307bis_nested_groups_step(struct tevent_req *req)
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny{
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek errno_t ret;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny TALLOC_CTX *tmp_ctx = NULL;
6b81b6ada1010e65b447fc74453e236fb8791813Jan Zeleny const char **attr_filter;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny char *clean_orig_dn;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek hash_key_t key;
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek hash_value_t value;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct sdap_rfc2307bis_nested_ctx *state =
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny tevent_req_data(req, struct sdap_rfc2307bis_nested_ctx);
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek char *oc_list;
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose const char *class;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny tmp_ctx = talloc_new(state);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny if (!tmp_ctx) {
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny ret = ENOMEM;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher goto done;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny }
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose ret = sysdb_attrs_get_string(state->groups[state->group_iter],
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose SYSDB_OBJECTCATEGORY, &class);
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose if (ret == EOK) {
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose /* If there is a objectClass attribute the object is coming from the
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose * cache and the name attribute of the object already has the primary
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose * name.
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose * If the objectClass attribute is missing the object is coming from
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose * LDAP and we have to find the primary name first. */
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose ret = sysdb_attrs_get_string(state->groups[state->group_iter],
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose SYSDB_NAME, &state->primary_name);
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose } else {
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose ret = sdap_get_group_primary_name(state, state->opts,
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose state->groups[state->group_iter],
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose state->dom, &state->primary_name);
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (ret != EOK) {
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher goto done;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek key.type = HASH_KEY_STRING;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek key.str = talloc_strdup(state, state->primary_name);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek if (!key.str) {
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny ret = ENOMEM;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher goto done;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny }
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_LIBS, "Processing group [%s]\n", state->primary_name);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek ret = hash_lookup(state->group_hash, &key, &value);
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek if (ret == HASH_SUCCESS) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_INTERNAL, "Group [%s] was already processed, "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "taking a shortcut\n", state->primary_name);
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek state->processed_groups[state->group_iter] =
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek talloc_get_type(value.ptr, struct sdap_nested_group);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek talloc_free(key.str);
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher ret = EOK;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher goto done;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny }
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek /* Need to try to find parent groups for this group. */
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek state->processed_groups[state->group_iter] =
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek talloc_zero(state->processed_groups, struct sdap_nested_group);
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek if (!state->processed_groups[state->group_iter]) {
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek ret = ENOMEM;
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek goto done;
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek }
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek /* this steal doesn't change much now, but will be helpful later on
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek * if we steal the whole processed_group on the hash table */
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek state->processed_groups[state->group_iter]->group =
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek talloc_steal(state->processed_groups[state->group_iter],
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek state->groups[state->group_iter]);
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny /* Get any parent groups for this group */
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny ret = sysdb_attrs_get_string(state->groups[state->group_iter],
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny SYSDB_ORIG_DN,
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher &state->orig_dn);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny if (ret != EOK) {
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher goto done;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny }
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny
6b81b6ada1010e65b447fc74453e236fb8791813Jan Zeleny attr_filter = talloc_array(state, const char *, 2);
6b81b6ada1010e65b447fc74453e236fb8791813Jan Zeleny if (!attr_filter) {
6b81b6ada1010e65b447fc74453e236fb8791813Jan Zeleny ret = ENOMEM;
6b81b6ada1010e65b447fc74453e236fb8791813Jan Zeleny goto done;
6b81b6ada1010e65b447fc74453e236fb8791813Jan Zeleny }
6b81b6ada1010e65b447fc74453e236fb8791813Jan Zeleny
6b81b6ada1010e65b447fc74453e236fb8791813Jan Zeleny attr_filter[0] = state->opts->group_map[SDAP_AT_GROUP_MEMBER].name;
6b81b6ada1010e65b447fc74453e236fb8791813Jan Zeleny attr_filter[1] = NULL;
6b81b6ada1010e65b447fc74453e236fb8791813Jan Zeleny
64ddff90c7fcc02ccb06824ac93af7d5f361a88fJan Zeleny ret = build_attrs_from_map(state, state->opts->group_map, SDAP_OPTS_GROUP,
6b81b6ada1010e65b447fc74453e236fb8791813Jan Zeleny attr_filter, &state->attrs, NULL);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny if (ret != EOK) {
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher goto done;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny }
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher ret = sss_filter_sanitize(tmp_ctx, state->orig_dn, &clean_orig_dn);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny if (ret != EOK) {
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher goto done;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny }
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek oc_list = sdap_make_oc_list(state, state->opts->group_map);
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek if (oc_list == NULL) {
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek DEBUG(SSSDBG_CRIT_FAILURE, "Failed to create objectClass list.\n");
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek ret = ENOMEM;
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek goto done;
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek }
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher state->base_filter = talloc_asprintf(
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek state, "(&(%s=%s)(%s)(%s=*))",
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny state->opts->group_map[SDAP_AT_GROUP_MEMBER].name,
7ba70236daccb48432350147d0560b3302518ceeMichal Zidek clean_orig_dn, oc_list,
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny state->opts->group_map[SDAP_AT_GROUP_NAME].name);
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher if (!state->base_filter) {
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny ret = ENOMEM;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher goto done;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher ret = rfc2307bis_nested_groups_next_base(req);
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher if (ret != EOK) goto done;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher /* Still processing parent groups */
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher ret = EAGAIN;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagherdone:
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher talloc_free(tmp_ctx);
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher return ret;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher}
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagherstatic errno_t rfc2307bis_nested_groups_next_base(struct tevent_req *req)
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher{
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher struct tevent_req *subreq;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher struct sdap_rfc2307bis_nested_ctx *state;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher state = tevent_req_data(req, struct sdap_rfc2307bis_nested_ctx);
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher talloc_zfree(state->filter);
92ec40e6aa25f75903ffdb166a8ec56b67bfd77dPavel Březina state->filter = sdap_combine_filters(state, state->base_filter,
92ec40e6aa25f75903ffdb166a8ec56b67bfd77dPavel Březina state->search_bases[state->base_iter]->filter);
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher if (!state->filter) {
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher return ENOMEM;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher }
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher DEBUG(SSSDBG_TRACE_FUNC,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Searching for parent groups of group [%s] with base [%s]\n",
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher state->orig_dn,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov state->search_bases[state->base_iter]->basedn);
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher subreq = sdap_get_generic_send(
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher state, state->ev, state->opts, state->sh,
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher state->search_bases[state->base_iter]->basedn,
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher state->search_bases[state->base_iter]->scope,
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher state->filter, state->attrs,
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher state->opts->group_map, SDAP_OPTS_GROUP,
2f3ee3f49019f5b60adbe073070f31e6e2d7c7abStephen Gallagher state->timeout,
2f3ee3f49019f5b60adbe073070f31e6e2d7c7abStephen Gallagher true);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (!subreq) {
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher return ENOMEM;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny tevent_req_set_callback(subreq,
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny rfc2307bis_nested_groups_process,
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny req);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher return EOK;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny}
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
b53f1e74acee48c5f22f7532829e1934c68d4637Pavel Reichlstatic void
b53f1e74acee48c5f22f7532829e1934c68d4637Pavel Reichlrfc2307bis_nested_groups_iterate(struct tevent_req *req,
b53f1e74acee48c5f22f7532829e1934c68d4637Pavel Reichl struct sdap_rfc2307bis_nested_ctx *state)
b53f1e74acee48c5f22f7532829e1934c68d4637Pavel Reichl{
b53f1e74acee48c5f22f7532829e1934c68d4637Pavel Reichl errno_t ret;
b53f1e74acee48c5f22f7532829e1934c68d4637Pavel Reichl
b53f1e74acee48c5f22f7532829e1934c68d4637Pavel Reichl state->group_iter++;
b53f1e74acee48c5f22f7532829e1934c68d4637Pavel Reichl while (state->group_iter < state->num_groups) {
b53f1e74acee48c5f22f7532829e1934c68d4637Pavel Reichl ret = rfc2307bis_nested_groups_step(req);
b53f1e74acee48c5f22f7532829e1934c68d4637Pavel Reichl if (ret == EAGAIN) {
b53f1e74acee48c5f22f7532829e1934c68d4637Pavel Reichl /* Looking up parent groups.. */
b53f1e74acee48c5f22f7532829e1934c68d4637Pavel Reichl return;
b53f1e74acee48c5f22f7532829e1934c68d4637Pavel Reichl } else if (ret != EOK) {
b53f1e74acee48c5f22f7532829e1934c68d4637Pavel Reichl tevent_req_error(req, ret);
b53f1e74acee48c5f22f7532829e1934c68d4637Pavel Reichl return;
b53f1e74acee48c5f22f7532829e1934c68d4637Pavel Reichl }
b53f1e74acee48c5f22f7532829e1934c68d4637Pavel Reichl
b53f1e74acee48c5f22f7532829e1934c68d4637Pavel Reichl /* EOK means this group has already been processed
b53f1e74acee48c5f22f7532829e1934c68d4637Pavel Reichl * in another nesting level */
b53f1e74acee48c5f22f7532829e1934c68d4637Pavel Reichl state->group_iter++;
b53f1e74acee48c5f22f7532829e1934c68d4637Pavel Reichl }
b53f1e74acee48c5f22f7532829e1934c68d4637Pavel Reichl
b53f1e74acee48c5f22f7532829e1934c68d4637Pavel Reichl if (state->group_iter == state->num_groups) {
b53f1e74acee48c5f22f7532829e1934c68d4637Pavel Reichl /* All groups processed. Done. */
b53f1e74acee48c5f22f7532829e1934c68d4637Pavel Reichl tevent_req_done(req);
b53f1e74acee48c5f22f7532829e1934c68d4637Pavel Reichl }
b53f1e74acee48c5f22f7532829e1934c68d4637Pavel Reichl}
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zelenystatic void rfc2307bis_nested_groups_done(struct tevent_req *subreq);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zelenystatic void rfc2307bis_nested_groups_process(struct tevent_req *subreq)
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny{
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny errno_t ret;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct tevent_req *req =
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny tevent_req_callback_data(subreq, struct tevent_req);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct sdap_rfc2307bis_nested_ctx *state =
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny tevent_req_data(req, struct sdap_rfc2307bis_nested_ctx);
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher size_t count;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher size_t i;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher struct sysdb_attrs **ldap_groups;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek struct sdap_nested_group *ngr;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek hash_value_t value;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek hash_key_t key;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek int hret;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny ret = sdap_get_generic_recv(subreq, state,
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher &count,
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher &ldap_groups);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny talloc_zfree(subreq);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (ret) {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny tevent_req_error(req, ret);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny return;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek DEBUG(SSSDBG_TRACE_LIBS,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Found %zu parent groups of [%s]\n", count, state->orig_dn);
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek ngr = state->processed_groups[state->group_iter];
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher /* Add this batch of groups to the list */
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher if (count > 0) {
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek ngr->ldap_parents =
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek talloc_realloc(ngr,
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek ngr->ldap_parents,
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher struct sysdb_attrs *,
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek ngr->parents_count + count + 1);
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek if (!ngr->ldap_parents) {
21f666d6a88dfa9cd7e984c25464dd56fe170598Jakub Hrozek tevent_req_error(req, ENOMEM);
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher return;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher }
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher /* Copy the new groups into the list.
3a0522759a7e71b40cc88dba0f5c545b049cf9bfJakub Hrozek * They're allocated on 'state' so we need to move them
3a0522759a7e71b40cc88dba0f5c545b049cf9bfJakub Hrozek * onto ldap_parents so that the data won't disappear when
3a0522759a7e71b40cc88dba0f5c545b049cf9bfJakub Hrozek * we finish this nesting level.
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher */
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher for (i = 0; i < count; i++) {
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek ngr->ldap_parents[ngr->parents_count + i] =
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek talloc_steal(ngr->ldap_parents, ldap_groups[i]);
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher }
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek ngr->parents_count += count;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek ngr->ldap_parents[ngr->parents_count] = NULL;
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek DEBUG(SSSDBG_TRACE_INTERNAL,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Total of %zu direct parents after this iteration\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ngr->parents_count);
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher }
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher state->base_iter++;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher /* Check for additional search bases, and iterate
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher * through again.
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher */
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher if (state->search_bases[state->base_iter] != NULL) {
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher ret = rfc2307bis_nested_groups_next_base(req);
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher if (ret != EOK) {
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher tevent_req_error(req, ret);
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher }
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher return;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher }
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher /* Reset the base iterator for future lookups */
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher state->base_iter = 0;
9fcfe80902655f495b7258218fc8114aa5d2c023Stephen Gallagher
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek /* Save the group into the hash table */
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek key.type = HASH_KEY_STRING;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek key.str = talloc_strdup(state, state->primary_name);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek if (!key.str) {
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek tevent_req_error(req, ENOMEM);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek return;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek }
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek /* Steal the nested group entry on the group_hash context so it can
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek * outlive this request */
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek talloc_steal(state->group_hash, ngr);
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek value.type = HASH_VALUE_PTR;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek value.ptr = ngr;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek hret = hash_enter(state->group_hash, &key, &value);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek if (hret != HASH_SUCCESS) {
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek talloc_free(key.str);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek tevent_req_error(req, EIO);
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek return;
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek }
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek talloc_free(key.str);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek if (ngr->parents_count == 0) {
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek /* No parent groups for this group in LDAP
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek * Move on to the next group
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek */
b53f1e74acee48c5f22f7532829e1934c68d4637Pavel Reichl rfc2307bis_nested_groups_iterate(req, state);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny return;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny /* Otherwise, recurse into the groups */
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny subreq = rfc2307bis_nested_groups_send(
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny state, state->ev, state->opts, state->sysdb,
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny state->dom, state->sh,
5b94e341a6ae347f49cfd18d574c9f37d0c2633eSumit Bose state->search_bases,
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek ngr->ldap_parents,
1c386aa2c11d1bdbb3f42f722ec4599ce9f278c8Jakub Hrozek ngr->parents_count,
95470076a26745f65d087be7cdf79c0373df21caJakub Hrozek state->group_hash,
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny state->nesting_level+1);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (!subreq) {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny tevent_req_error(req, EIO);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny return;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny tevent_req_set_callback(subreq, rfc2307bis_nested_groups_done, req);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny}
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
49d3f0a487d55571b2bdc9d3f8280b304b964b9dSumit Boseerrno_t rfc2307bis_nested_groups_recv(struct tevent_req *req)
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny{
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny TEVENT_REQ_RETURN_ON_ERROR(req);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny return EOK;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny}
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zelenystatic void rfc2307bis_nested_groups_done(struct tevent_req *subreq)
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny{
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny errno_t ret;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct tevent_req *req =
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny tevent_req_callback_data(subreq, struct tevent_req);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct sdap_rfc2307bis_nested_ctx *state =
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny tevent_req_data(req, struct sdap_rfc2307bis_nested_ctx);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny ret = rfc2307bis_nested_groups_recv(subreq);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny talloc_zfree(subreq);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "rfc2307bis_nested failed [%d][%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny tevent_req_error(req, ret);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny return;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny }
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny
b53f1e74acee48c5f22f7532829e1934c68d4637Pavel Reichl rfc2307bis_nested_groups_iterate(req, state);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny}
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny/* ==Initgr-call-(groups-a-user-is-member-of)============================= */
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zelenystruct sdap_get_initgr_state {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct tevent_context *ev;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct sysdb_ctx *sysdb;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct sdap_options *opts;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct sss_domain_info *dom;
1b870ffa7910879f9310db453a31ab6f06392b9bJakub Hrozek struct sdap_domain *sdom;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct sdap_handle *sh;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct sdap_id_ctx *id_ctx;
9aa117a93e315f790a1922d9ac7bd484878b621eJakub Hrozek struct sdap_id_conn_ctx *conn;
9b29f86df7a29249ef8f485eedb8db515381c0deJakub Hrozek const char *filter_value;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny const char **grp_attrs;
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher const char **user_attrs;
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek char *user_base_filter;
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek char *shortname;
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher char *filter;
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher int timeout;
3e39806177e1cd383743ff596cb96df44a6ce8c9Jakub Hrozek bool non_posix;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct sysdb_attrs *orig_user;
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher size_t user_base_iter;
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher struct sdap_search_base **user_search_bases;
b56b06e199f15a8a840b36bc7cb8010e39ae761dSumit Bose
b56b06e199f15a8a840b36bc7cb8010e39ae761dSumit Bose bool use_id_mapping;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny};
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagherstatic errno_t sdap_get_initgr_next_base(struct tevent_req *req);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zelenystatic void sdap_get_initgr_user(struct tevent_req *subreq);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zelenystatic void sdap_get_initgr_done(struct tevent_req *subreq);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zelenystruct tevent_req *sdap_get_initgr_send(TALLOC_CTX *memctx,
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct tevent_context *ev,
749cfb5d3270b5daf389d51a0dbd3fd2aec6e05dJakub Hrozek struct sdap_domain *sdom,
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct sdap_handle *sh,
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct sdap_id_ctx *id_ctx,
9aa117a93e315f790a1922d9ac7bd484878b621eJakub Hrozek struct sdap_id_conn_ctx *conn,
9b29f86df7a29249ef8f485eedb8db515381c0deJakub Hrozek const char *filter_value,
9b29f86df7a29249ef8f485eedb8db515381c0deJakub Hrozek int filter_type,
25a387c2e90c74b27a26ea207503df8e4b6a1a76Sumit Bose const char *extra_value,
ac67376a47ed52374641e7a4f6fd97712fe5171bJakub Hrozek const char **grp_attrs)
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny{
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher struct tevent_req *req;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct sdap_get_initgr_state *state;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny int ret;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny char *clean_name;
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek bool use_id_mapping;
50a7a92f92e1584702bf25e61a50cb1c09c7e260Sumit Bose const char *search_attr = NULL;
50a7a92f92e1584702bf25e61a50cb1c09c7e260Sumit Bose char *ep_filter;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_TRACE_ALL, "Retrieving info for initgroups call\n");
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny req = tevent_req_create(memctx, &state, struct sdap_get_initgr_state);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny if (!req) return NULL;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state->ev = ev;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny state->opts = id_ctx->opts;
749cfb5d3270b5daf389d51a0dbd3fd2aec6e05dJakub Hrozek state->dom = sdom->dom;
749cfb5d3270b5daf389d51a0dbd3fd2aec6e05dJakub Hrozek state->sysdb = sdom->dom->sysdb;
1b870ffa7910879f9310db453a31ab6f06392b9bJakub Hrozek state->sdom = sdom;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny state->sh = sh;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny state->id_ctx = id_ctx;
9aa117a93e315f790a1922d9ac7bd484878b621eJakub Hrozek state->conn = conn;
9b29f86df7a29249ef8f485eedb8db515381c0deJakub Hrozek state->filter_value = filter_value;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny state->grp_attrs = grp_attrs;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny state->orig_user = NULL;
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher state->timeout = dp_opt_get_int(state->opts->basic, SDAP_SEARCH_TIMEOUT);
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher state->user_base_iter = 0;
749cfb5d3270b5daf389d51a0dbd3fd2aec6e05dJakub Hrozek state->user_search_bases = sdom->user_search_bases;
169fa5bd3edd34aa0db35681832bd7406e423c1bStephen Gallagher if (!state->user_search_bases) {
169fa5bd3edd34aa0db35681832bd7406e423c1bStephen Gallagher DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Initgroups lookup request without a user search base\n");
169fa5bd3edd34aa0db35681832bd7406e423c1bStephen Gallagher ret = EINVAL;
169fa5bd3edd34aa0db35681832bd7406e423c1bStephen Gallagher goto done;
169fa5bd3edd34aa0db35681832bd7406e423c1bStephen Gallagher }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
3e39806177e1cd383743ff596cb96df44a6ce8c9Jakub Hrozek if (state->dom->type == DOM_TYPE_APPLICATION) {
3e39806177e1cd383743ff596cb96df44a6ce8c9Jakub Hrozek state->non_posix = true;
3e39806177e1cd383743ff596cb96df44a6ce8c9Jakub Hrozek }
3e39806177e1cd383743ff596cb96df44a6ce8c9Jakub Hrozek
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek use_id_mapping = sdap_idmap_domain_has_algorithmic_mapping(
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek id_ctx->opts->idmap_ctx,
fdda4b659fa3be3027df91a2b053835186ec2c59Sumit Bose sdom->dom->name,
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek sdom->dom->domain_id);
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek switch (filter_type) {
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek case BE_FILTER_SECID:
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek search_attr = state->opts->user_map[SDAP_AT_USER_OBJECTSID].name;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek ret = sss_filter_sanitize(state, state->filter_value, &clean_name);
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek if (ret != EOK) {
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek talloc_zfree(req);
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek return NULL;
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek }
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek break;
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek case BE_FILTER_UUID:
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek search_attr = state->opts->user_map[SDAP_AT_USER_UUID].name;
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek ret = sss_filter_sanitize(state, state->filter_value, &clean_name);
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek if (ret != EOK) {
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek talloc_zfree(req);
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek return NULL;
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek }
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek break;
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek case BE_FILTER_NAME:
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek if (extra_value && strcmp(extra_value, EXTRA_NAME_IS_UPN) == 0) {
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek ret = sss_filter_sanitize(state, state->filter_value, &clean_name);
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek if (ret != EOK) {
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek talloc_zfree(req);
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek return NULL;
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek }
ba9ebfc49ab3bacb96213c8620411128c09f39daSumit Bose
50a7a92f92e1584702bf25e61a50cb1c09c7e260Sumit Bose ep_filter = get_enterprise_principal_string_filter(state,
50a7a92f92e1584702bf25e61a50cb1c09c7e260Sumit Bose state->opts->user_map[SDAP_AT_USER_PRINC].name,
50a7a92f92e1584702bf25e61a50cb1c09c7e260Sumit Bose clean_name, state->opts->basic);
ba9ebfc49ab3bacb96213c8620411128c09f39daSumit Bose state->user_base_filter =
ba9ebfc49ab3bacb96213c8620411128c09f39daSumit Bose talloc_asprintf(state,
50a7a92f92e1584702bf25e61a50cb1c09c7e260Sumit Bose "(&(|(%s=%s)(%s=%s)%s)(objectclass=%s)",
ba9ebfc49ab3bacb96213c8620411128c09f39daSumit Bose state->opts->user_map[SDAP_AT_USER_PRINC].name,
ba9ebfc49ab3bacb96213c8620411128c09f39daSumit Bose clean_name,
ba9ebfc49ab3bacb96213c8620411128c09f39daSumit Bose state->opts->user_map[SDAP_AT_USER_EMAIL].name,
ba9ebfc49ab3bacb96213c8620411128c09f39daSumit Bose clean_name,
50a7a92f92e1584702bf25e61a50cb1c09c7e260Sumit Bose ep_filter == NULL ? "" : ep_filter,
ba9ebfc49ab3bacb96213c8620411128c09f39daSumit Bose state->opts->user_map[SDAP_OC_USER].name);
ba9ebfc49ab3bacb96213c8620411128c09f39daSumit Bose if (state->user_base_filter == NULL) {
ba9ebfc49ab3bacb96213c8620411128c09f39daSumit Bose talloc_zfree(req);
ba9ebfc49ab3bacb96213c8620411128c09f39daSumit Bose return NULL;
ba9ebfc49ab3bacb96213c8620411128c09f39daSumit Bose }
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek } else {
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek search_attr = state->opts->user_map[SDAP_AT_USER_NAME].name;
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek ret = sss_parse_internal_fqname(state, filter_value,
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek &state->shortname, NULL);
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek if (ret != EOK) {
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "Cannot parse %s\n", filter_value);
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek goto done;
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek }
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek ret = sss_filter_sanitize(state, state->shortname, &clean_name);
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek if (ret != EOK) {
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek talloc_zfree(req);
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek return NULL;
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek }
0f9c28eb52d2b45c8a97f709308dc11377831b8cSumit Bose }
c88b63b2dd82f7111abc00d93fa8db2707487572Sumit Bose break;
c88b63b2dd82f7111abc00d93fa8db2707487572Sumit Bose default:
c88b63b2dd82f7111abc00d93fa8db2707487572Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "Unsupported filter type [%d].\n",
c88b63b2dd82f7111abc00d93fa8db2707487572Sumit Bose filter_type);
c88b63b2dd82f7111abc00d93fa8db2707487572Sumit Bose return NULL;
25a387c2e90c74b27a26ea207503df8e4b6a1a76Sumit Bose }
25a387c2e90c74b27a26ea207503df8e4b6a1a76Sumit Bose
ba9ebfc49ab3bacb96213c8620411128c09f39daSumit Bose if (search_attr == NULL && state->user_base_filter == NULL) {
ba9ebfc49ab3bacb96213c8620411128c09f39daSumit Bose DEBUG(SSSDBG_OP_FAILURE, "Missing search attribute name or filter.\n");
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny talloc_zfree(req);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny return NULL;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny }
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny
ba9ebfc49ab3bacb96213c8620411128c09f39daSumit Bose if (state->user_base_filter == NULL) {
ba9ebfc49ab3bacb96213c8620411128c09f39daSumit Bose state->user_base_filter =
ba9ebfc49ab3bacb96213c8620411128c09f39daSumit Bose talloc_asprintf(state, "(&(%s=%s)(objectclass=%s)",
ba9ebfc49ab3bacb96213c8620411128c09f39daSumit Bose search_attr, clean_name,
ba9ebfc49ab3bacb96213c8620411128c09f39daSumit Bose state->opts->user_map[SDAP_OC_USER].name);
ba9ebfc49ab3bacb96213c8620411128c09f39daSumit Bose if (!state->user_base_filter) {
ba9ebfc49ab3bacb96213c8620411128c09f39daSumit Bose talloc_zfree(req);
ba9ebfc49ab3bacb96213c8620411128c09f39daSumit Bose return NULL;
ba9ebfc49ab3bacb96213c8620411128c09f39daSumit Bose }
ba9ebfc49ab3bacb96213c8620411128c09f39daSumit Bose }
ba9ebfc49ab3bacb96213c8620411128c09f39daSumit Bose
3e39806177e1cd383743ff596cb96df44a6ce8c9Jakub Hrozek if (state->non_posix) {
3e39806177e1cd383743ff596cb96df44a6ce8c9Jakub Hrozek state->user_base_filter = talloc_asprintf_append(state->user_base_filter,
3e39806177e1cd383743ff596cb96df44a6ce8c9Jakub Hrozek ")");
3e39806177e1cd383743ff596cb96df44a6ce8c9Jakub Hrozek } else if (use_id_mapping) {
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek /* When mapping IDs or looking for SIDs, we don't want to limit
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek * ourselves to users with a UID value. But there must be a SID to map
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek * from.
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek */
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek state->user_base_filter = talloc_asprintf_append(state->user_base_filter,
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek "(%s=*))",
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek id_ctx->opts->user_map[SDAP_AT_USER_OBJECTSID].name);
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek } else {
3e39806177e1cd383743ff596cb96df44a6ce8c9Jakub Hrozek /* When not ID-mapping or looking up app users, make sure there
3e39806177e1cd383743ff596cb96df44a6ce8c9Jakub Hrozek * is a non-NULL UID */
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek state->user_base_filter = talloc_asprintf_append(state->user_base_filter,
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek "(&(%s=*)(!(%s=0))))",
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek id_ctx->opts->user_map[SDAP_AT_USER_UID].name,
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek id_ctx->opts->user_map[SDAP_AT_USER_UID].name);
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek }
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek if (!state->user_base_filter) {
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek talloc_zfree(req);
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek return NULL;
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek }
d3e1d88ce7de3216a862b9fe78dc5aa94dcbc14bJakub Hrozek
4dd38025efda88f123eac672f87d3cda12f050c8Jakub Hrozek ret = build_attrs_from_map(state,
4dd38025efda88f123eac672f87d3cda12f050c8Jakub Hrozek state->opts->user_map,
4dd38025efda88f123eac672f87d3cda12f050c8Jakub Hrozek state->opts->user_map_cnt,
64ddff90c7fcc02ccb06824ac93af7d5f361a88fJan Zeleny NULL, &state->user_attrs, NULL);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny if (ret) {
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny talloc_zfree(req);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny return NULL;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny }
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny
b56b06e199f15a8a840b36bc7cb8010e39ae761dSumit Bose state->use_id_mapping = sdap_idmap_domain_has_algorithmic_mapping(
b56b06e199f15a8a840b36bc7cb8010e39ae761dSumit Bose state->opts->idmap_ctx,
fdda4b659fa3be3027df91a2b053835186ec2c59Sumit Bose state->dom->name,
b56b06e199f15a8a840b36bc7cb8010e39ae761dSumit Bose state->dom->domain_id);
b56b06e199f15a8a840b36bc7cb8010e39ae761dSumit Bose
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher ret = sdap_get_initgr_next_base(req);
169fa5bd3edd34aa0db35681832bd7406e423c1bStephen Gallagher
169fa5bd3edd34aa0db35681832bd7406e423c1bStephen Gallagherdone:
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher if (ret != EOK) {
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher tevent_req_error(req, ret);
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher tevent_req_post(req, ev);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny return req;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny}
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagherstatic errno_t sdap_get_initgr_next_base(struct tevent_req *req)
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher{
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher struct tevent_req *subreq;
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher struct sdap_get_initgr_state *state;
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher state = tevent_req_data(req, struct sdap_get_initgr_state);
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher talloc_zfree(state->filter);
92ec40e6aa25f75903ffdb166a8ec56b67bfd77dPavel Březina state->filter = sdap_combine_filters(state, state->user_base_filter,
92ec40e6aa25f75903ffdb166a8ec56b67bfd77dPavel Březina state->user_search_bases[state->user_base_iter]->filter);
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher if (!state->filter) {
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher return ENOMEM;
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher }
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher DEBUG(SSSDBG_TRACE_FUNC,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Searching for users with base [%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov state->user_search_bases[state->user_base_iter]->basedn);
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher subreq = sdap_get_generic_send(
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher state, state->ev, state->opts, state->sh,
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher state->user_search_bases[state->user_base_iter]->basedn,
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher state->user_search_bases[state->user_base_iter]->scope,
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher state->filter, state->user_attrs,
4dd38025efda88f123eac672f87d3cda12f050c8Jakub Hrozek state->opts->user_map, state->opts->user_map_cnt,
2f3ee3f49019f5b60adbe073070f31e6e2d7c7abStephen Gallagher state->timeout,
2f3ee3f49019f5b60adbe073070f31e6e2d7c7abStephen Gallagher false);
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher if (!subreq) {
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher return ENOMEM;
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher }
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher tevent_req_set_callback(subreq, sdap_get_initgr_user, req);
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher return EOK;
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher}
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher
3ee411625aee19afda7477bb10b52c3da378b6fbPetr Čechstatic int sdap_search_initgr_user_in_batch(struct sdap_get_initgr_state *state,
3ee411625aee19afda7477bb10b52c3da378b6fbPetr Čech struct sysdb_attrs **users,
3ee411625aee19afda7477bb10b52c3da378b6fbPetr Čech size_t count)
3ee411625aee19afda7477bb10b52c3da378b6fbPetr Čech{
3ee411625aee19afda7477bb10b52c3da378b6fbPetr Čech int ret = EINVAL;
3ee411625aee19afda7477bb10b52c3da378b6fbPetr Čech
3ee411625aee19afda7477bb10b52c3da378b6fbPetr Čech for (size_t i = 0; i < count; i++) {
3ee411625aee19afda7477bb10b52c3da378b6fbPetr Čech if (sdap_object_in_domain(state->opts, users[i], state->dom) == false) {
3ee411625aee19afda7477bb10b52c3da378b6fbPetr Čech continue;
3ee411625aee19afda7477bb10b52c3da378b6fbPetr Čech }
3ee411625aee19afda7477bb10b52c3da378b6fbPetr Čech
3ee411625aee19afda7477bb10b52c3da378b6fbPetr Čech state->orig_user = talloc_steal(state, users[i]);
3ee411625aee19afda7477bb10b52c3da378b6fbPetr Čech ret = EOK;
3ee411625aee19afda7477bb10b52c3da378b6fbPetr Čech break;
3ee411625aee19afda7477bb10b52c3da378b6fbPetr Čech }
3ee411625aee19afda7477bb10b52c3da378b6fbPetr Čech
3ee411625aee19afda7477bb10b52c3da378b6fbPetr Čech return ret;
3ee411625aee19afda7477bb10b52c3da378b6fbPetr Čech}
3ee411625aee19afda7477bb10b52c3da378b6fbPetr Čech
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zelenystatic void sdap_get_initgr_user(struct tevent_req *subreq)
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny{
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct tevent_req *req = tevent_req_callback_data(subreq,
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct tevent_req);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct sdap_get_initgr_state *state = tevent_req_data(req,
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct sdap_get_initgr_state);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct sysdb_attrs **usr_attrs;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny size_t count;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny int ret;
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek errno_t sret;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny const char *orig_dn;
940e033c0c427d02a34347dbd2f4443fa625b111Jakub Hrozek const char *cname;
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek bool in_transaction = false;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_TRACE_ALL, "Receiving info for the user\n");
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny ret = sdap_get_generic_recv(subreq, state, &count, &usr_attrs);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny talloc_zfree(subreq);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny if (ret) {
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny tevent_req_error(req, ret);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny return;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher if (count == 0) {
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher /* No users found in this search */
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher state->user_base_iter++;
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher if (state->user_search_bases[state->user_base_iter]) {
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher /* There are more search bases to try */
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher ret = sdap_get_initgr_next_base(req);
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher if (ret != EOK) {
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher tevent_req_error(req, ret);
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher }
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher return;
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher }
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher
fae99bfe4bfc8b4a12e9c2a0ad01b3684c22f934Simo Sorce /* fallback to fetch a local user if required */
fae99bfe4bfc8b4a12e9c2a0ad01b3684c22f934Simo Sorce if ((state->opts->schema_type == SDAP_SCHEMA_RFC2307) &&
fae99bfe4bfc8b4a12e9c2a0ad01b3684c22f934Simo Sorce (dp_opt_get_bool(state->opts->basic,
fae99bfe4bfc8b4a12e9c2a0ad01b3684c22f934Simo Sorce SDAP_RFC2307_FALLBACK_TO_LOCAL_USERS) == true)) {
c4eb21582937362e09aa34e6a18b7f33815d4940Jakub Hrozek ret = sdap_fallback_local_user(state, state->shortname, -1, &usr_attrs);
aa8ec3758d885d6ae4088174369d30f8493ec898Michal Židek if (ret == EOK) {
aa8ec3758d885d6ae4088174369d30f8493ec898Michal Židek state->orig_user = usr_attrs[0];
aa8ec3758d885d6ae4088174369d30f8493ec898Michal Židek }
fae99bfe4bfc8b4a12e9c2a0ad01b3684c22f934Simo Sorce } else {
fae99bfe4bfc8b4a12e9c2a0ad01b3684c22f934Simo Sorce ret = ENOENT;
fae99bfe4bfc8b4a12e9c2a0ad01b3684c22f934Simo Sorce }
fae99bfe4bfc8b4a12e9c2a0ad01b3684c22f934Simo Sorce
fae99bfe4bfc8b4a12e9c2a0ad01b3684c22f934Simo Sorce if (ret != EOK) {
fae99bfe4bfc8b4a12e9c2a0ad01b3684c22f934Simo Sorce tevent_req_error(req, ret);
fae99bfe4bfc8b4a12e9c2a0ad01b3684c22f934Simo Sorce return;
fae99bfe4bfc8b4a12e9c2a0ad01b3684c22f934Simo Sorce }
5ff7a765434ed0b4d37564ade26d7761d06f81c3Sumit Bose } else if (count == 1) {
5ff7a765434ed0b4d37564ade26d7761d06f81c3Sumit Bose state->orig_user = usr_attrs[0];
14742d2cf50774ffd94b37a398238e4ce0e4a740Stephen Gallagher } else if (count != 1) {
0e65abe5cf2abf5d4b431cf6bd161b419f07901dLukas Slebodnik DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Expected one user entry and got %zu\n", count);
008e1ee835602023891ac45408483d87f41e4d5cSumit Bose
24d8c85fae253f988165c112af208198cf48eef6Jakub Hrozek /* When matching against a search base, it's sufficient to pick only
24d8c85fae253f988165c112af208198cf48eef6Jakub Hrozek * the first search base because all bases in a single domain would
24d8c85fae253f988165c112af208198cf48eef6Jakub Hrozek * have the same DC= components
24d8c85fae253f988165c112af208198cf48eef6Jakub Hrozek */
3ee411625aee19afda7477bb10b52c3da378b6fbPetr Čech ret = sdap_search_initgr_user_in_batch(state, usr_attrs, count);
008e1ee835602023891ac45408483d87f41e4d5cSumit Bose if (ret != EOK) {
5ff7a765434ed0b4d37564ade26d7761d06f81c3Sumit Bose DEBUG(SSSDBG_OP_FAILURE,
3ee411625aee19afda7477bb10b52c3da378b6fbPetr Čech "sdap_search_initgr_user_in_batch failed. "
3ee411625aee19afda7477bb10b52c3da378b6fbPetr Čech "No matching DN found.\n");
008e1ee835602023891ac45408483d87f41e4d5cSumit Bose tevent_req_error(req, EINVAL);
008e1ee835602023891ac45408483d87f41e4d5cSumit Bose return;
008e1ee835602023891ac45408483d87f41e4d5cSumit Bose }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny ret = sysdb_transaction_start(state->sysdb);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny if (ret) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to start transaction\n");
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek goto fail;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek in_transaction = true;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_TRACE_ALL, "Storing the user\n");
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
0bdef4fb23af3def3ca9608bb4dda46de1bd9dfbLukas Slebodnik ret = sdap_save_user(state, state->opts, state->dom, state->orig_user,
70c0648f021ded3d31313eb962e1ad140f242673Sumit Bose NULL, NULL, 0);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny if (ret) {
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek goto fail;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_TRACE_ALL, "Commit change\n");
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny ret = sysdb_transaction_commit(state->sysdb);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (ret) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to commit transaction\n");
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek goto fail;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek in_transaction = false;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
9b29f86df7a29249ef8f485eedb8db515381c0deJakub Hrozek ret = sysdb_get_real_name(state, state->dom, state->filter_value, &cname);
940e033c0c427d02a34347dbd2f4443fa625b111Jakub Hrozek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Cannot canonicalize username\n");
940e033c0c427d02a34347dbd2f4443fa625b111Jakub Hrozek tevent_req_error(req, ret);
940e033c0c427d02a34347dbd2f4443fa625b111Jakub Hrozek return;
940e033c0c427d02a34347dbd2f4443fa625b111Jakub Hrozek }
940e033c0c427d02a34347dbd2f4443fa625b111Jakub Hrozek
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_TRACE_ALL, "Process user's groups\n");
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny switch (state->opts->schema_type) {
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny case SDAP_SCHEMA_RFC2307:
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny subreq = sdap_initgr_rfc2307_send(state, state->ev, state->opts,
2ce00e0d3896bb42db169d1e79553a81ca837a22Simo Sorce state->sysdb, state->dom, state->sh,
940e033c0c427d02a34347dbd2f4443fa625b111Jakub Hrozek cname);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny if (!subreq) {
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny tevent_req_error(req, ENOMEM);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny return;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny }
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny tevent_req_set_callback(subreq, sdap_get_initgr_done, req);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny break;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny case SDAP_SCHEMA_RFC2307BIS:
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher case SDAP_SCHEMA_AD:
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny ret = sysdb_attrs_get_string(state->orig_user,
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny SYSDB_ORIG_DN,
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny &orig_dn);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (ret != EOK) {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny tevent_req_error(req, ret);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny return;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
5c2f2023696d1ff79c3c5d94b89e7ef9cd4159e9Jakub Hrozek if (state->opts->dc_functional_level >= DS_BEHAVIOR_WIN2003
69994add9cd4e57d40b3b7a0b1783ef2d0aa974cPavel Reichl && dp_opt_get_bool(state->opts->basic, SDAP_AD_USE_TOKENGROUPS)) {
d0e0e73e86f2afdb7f8fefbed70fda8d77b1c25aStephen Gallagher /* Take advantage of AD's tokenGroups mechanism to look up all
d0e0e73e86f2afdb7f8fefbed70fda8d77b1c25aStephen Gallagher * parent groups in a single request.
d0e0e73e86f2afdb7f8fefbed70fda8d77b1c25aStephen Gallagher */
29a61bce88147872b5086278d37b1e58726032d1Pavel Březina subreq = sdap_ad_tokengroups_initgroups_send(state, state->ev,
ed3e08e6ff267722c605141a0b57774efe4cb531Pavel Březina state->id_ctx,
008e1ee835602023891ac45408483d87f41e4d5cSumit Bose state->conn,
29a61bce88147872b5086278d37b1e58726032d1Pavel Březina state->opts,
29a61bce88147872b5086278d37b1e58726032d1Pavel Březina state->sysdb,
29a61bce88147872b5086278d37b1e58726032d1Pavel Březina state->dom,
29a61bce88147872b5086278d37b1e58726032d1Pavel Březina state->sh,
29a61bce88147872b5086278d37b1e58726032d1Pavel Březina cname, orig_dn,
ed3e08e6ff267722c605141a0b57774efe4cb531Pavel Březina state->timeout,
ed3e08e6ff267722c605141a0b57774efe4cb531Pavel Březina state->use_id_mapping);
d0e0e73e86f2afdb7f8fefbed70fda8d77b1c25aStephen Gallagher } else if (state->opts->support_matching_rule
d0e0e73e86f2afdb7f8fefbed70fda8d77b1c25aStephen Gallagher && dp_opt_get_bool(state->opts->basic,
d0e0e73e86f2afdb7f8fefbed70fda8d77b1c25aStephen Gallagher SDAP_AD_MATCHING_RULE_INITGROUPS)) {
d42d371c00c83ae44b9d1c3e88ecbe0e01b112e6Stephen Gallagher /* Take advantage of AD's extensibleMatch filter to look up
d42d371c00c83ae44b9d1c3e88ecbe0e01b112e6Stephen Gallagher * all parent groups in a single request.
d42d371c00c83ae44b9d1c3e88ecbe0e01b112e6Stephen Gallagher */
2ce00e0d3896bb42db169d1e79553a81ca837a22Simo Sorce subreq = sdap_get_ad_match_rule_initgroups_send(state, state->ev,
2ce00e0d3896bb42db169d1e79553a81ca837a22Simo Sorce state->opts,
2ce00e0d3896bb42db169d1e79553a81ca837a22Simo Sorce state->sysdb,
2ce00e0d3896bb42db169d1e79553a81ca837a22Simo Sorce state->dom,
2ce00e0d3896bb42db169d1e79553a81ca837a22Simo Sorce state->sh,
2ce00e0d3896bb42db169d1e79553a81ca837a22Simo Sorce cname, orig_dn,
2ce00e0d3896bb42db169d1e79553a81ca837a22Simo Sorce state->timeout);
d42d371c00c83ae44b9d1c3e88ecbe0e01b112e6Stephen Gallagher } else {
d42d371c00c83ae44b9d1c3e88ecbe0e01b112e6Stephen Gallagher subreq = sdap_initgr_rfc2307bis_send(
1b870ffa7910879f9310db453a31ab6f06392b9bJakub Hrozek state, state->ev, state->opts,
1b870ffa7910879f9310db453a31ab6f06392b9bJakub Hrozek state->sdom, state->sh,
d42d371c00c83ae44b9d1c3e88ecbe0e01b112e6Stephen Gallagher cname, orig_dn);
d42d371c00c83ae44b9d1c3e88ecbe0e01b112e6Stephen Gallagher }
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny if (!subreq) {
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny tevent_req_error(req, ENOMEM);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny return;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny }
d42d371c00c83ae44b9d1c3e88ecbe0e01b112e6Stephen Gallagher
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny talloc_steal(subreq, orig_dn);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny tevent_req_set_callback(subreq, sdap_get_initgr_done, req);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny break;
d42d371c00c83ae44b9d1c3e88ecbe0e01b112e6Stephen Gallagher
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny case SDAP_SCHEMA_IPA_V1:
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny subreq = sdap_initgr_nested_send(state, state->ev, state->opts,
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny state->sysdb, state->dom, state->sh,
ac67376a47ed52374641e7a4f6fd97712fe5171bJakub Hrozek state->orig_user, state->grp_attrs);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny if (!subreq) {
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny tevent_req_error(req, ENOMEM);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny return;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny tevent_req_set_callback(subreq, sdap_get_initgr_done, req);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny return;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny default:
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny tevent_req_error(req, EINVAL);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny return;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek return;
21d485184df986e1a123f70c689517386e51a5ceMichal Zidekfail:
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek if (in_transaction) {
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek sret = sysdb_transaction_cancel(state->sysdb);
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek if (sret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to cancel transaction\n");
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek }
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek }
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek tevent_req_error(req, ret);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny}
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bosestatic void sdap_ad_check_domain_local_groups_done(struct tevent_req *subreq);
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Boseerrno_t sdap_ad_check_domain_local_groups(struct tevent_req *req)
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose{
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose struct sdap_get_initgr_state *state = tevent_req_data(req,
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose struct sdap_get_initgr_state);
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose int ret;
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose struct sdap_domain *local_sdom;
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose const char *orig_name;
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose const char *sysdb_name;
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose struct ldb_result *res;
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose struct tevent_req *subreq;
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose struct sysdb_attrs **groups;
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose /* We only need to check for domain local groups in the AD case and if the
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose * user is not from our domain, i.e. if the user comes from a sub-domain.
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose */
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose if (state->opts->schema_type != SDAP_SCHEMA_AD
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose || !IS_SUBDOMAIN(state->dom)
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose || !dp_target_enabled(state->id_ctx->be->provider, "ad", DPT_ID)) {
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose return EOK;
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose }
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose local_sdom = sdap_domain_get(state->id_ctx->opts, state->dom->parent);
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose if (local_sdom == NULL || local_sdom->pvt == NULL) {
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "No ID ctx available for [%s].\n",
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose state->dom->parent->name);
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose return EINVAL;
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose }
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose ret = sysdb_attrs_get_string(state->orig_user, SYSDB_NAME, &orig_name);
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose if (ret != EOK) {
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "Missing name in user object.\n");
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose return ret;
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose }
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose sysdb_name = sss_create_internal_fqname(state, orig_name, state->dom->name);
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose if (sysdb_name == NULL) {
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sss_create_internal_fqname failed.\n");
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose return ENOMEM;
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose }
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose ret = sysdb_initgroups(state, state->dom, sysdb_name, &res);
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose if (ret != EOK) {
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "sysdb_initgroups failed for user [%s].\n",
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose sysdb_name);
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose return ret;
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose }
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose if (res->count == 0) {
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose "sysdb_initgroups returned no results for user [%s].\n",
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose sysdb_name);
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose return EINVAL;
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose }
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose /* The user object, the first entry in the res->msgs, is included as well
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose * to cover the case where the remote user is directly added to
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose * a domain local group. */
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose ret = sysdb_msg2attrs(state, res->count, res->msgs, &groups);
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose if (ret != EOK) {
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_msg2attrs failed.\n");
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose return ret;
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose }
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose subreq = sdap_ad_get_domain_local_groups_send(state, state->ev, local_sdom,
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose state->opts, state->sysdb, state->dom->parent,
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose groups, res->count);
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose if (subreq == NULL) {
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sdap_ad_get_domain_local_groups_send failed.\n");
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose return ENOMEM;
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose }
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose tevent_req_set_callback(subreq, sdap_ad_check_domain_local_groups_done,
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose req);
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose return EAGAIN;
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose}
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bosestatic void sdap_ad_check_domain_local_groups_done(struct tevent_req *subreq)
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose{
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose struct tevent_req *req = tevent_req_callback_data(subreq,
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose struct tevent_req);
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose int ret;
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose ret = sdap_ad_get_domain_local_groups_recv(subreq);
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose talloc_zfree(subreq);
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose if (ret != EOK) {
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose tevent_req_error(req, ret);
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose return;
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose }
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose tevent_req_done(req);
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose return;
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose}
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zelenystatic void sdap_get_initgr_pgid(struct tevent_req *req);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zelenystatic void sdap_get_initgr_done(struct tevent_req *subreq)
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny{
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct tevent_req *req = tevent_req_callback_data(subreq,
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct tevent_req);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct sdap_get_initgr_state *state = tevent_req_data(req,
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct sdap_get_initgr_state);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny int ret;
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher TALLOC_CTX *tmp_ctx;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny gid_t primary_gid;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny char *gid;
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher char *sid_str;
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher char *dom_sid_str;
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher char *group_sid_str;
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher struct sdap_options *opts = state->opts;
e182d98a391b5f6d3562e442748254cdbcef0b81Sumit Bose struct ldb_message *msg;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_TRACE_ALL, "Initgroups done\n");
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher tmp_ctx = talloc_new(NULL);
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher if (!tmp_ctx) {
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher tevent_req_error(req, ENOMEM);
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher return;
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher }
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny switch (state->opts->schema_type) {
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny case SDAP_SCHEMA_RFC2307:
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny ret = sdap_initgr_rfc2307_recv(subreq);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny break;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny case SDAP_SCHEMA_RFC2307BIS:
2394ec78b31c34f928843a56b9c395380347c418Stephen Gallagher case SDAP_SCHEMA_AD:
5c2f2023696d1ff79c3c5d94b89e7ef9cd4159e9Jakub Hrozek if (state->opts->dc_functional_level >= DS_BEHAVIOR_WIN2003
69994add9cd4e57d40b3b7a0b1783ef2d0aa974cPavel Reichl && dp_opt_get_bool(state->opts->basic, SDAP_AD_USE_TOKENGROUPS)) {
69994add9cd4e57d40b3b7a0b1783ef2d0aa974cPavel Reichl
29a61bce88147872b5086278d37b1e58726032d1Pavel Březina ret = sdap_ad_tokengroups_initgroups_recv(subreq);
d0e0e73e86f2afdb7f8fefbed70fda8d77b1c25aStephen Gallagher }
d0e0e73e86f2afdb7f8fefbed70fda8d77b1c25aStephen Gallagher else if (state->opts->support_matching_rule
d0e0e73e86f2afdb7f8fefbed70fda8d77b1c25aStephen Gallagher && dp_opt_get_bool(state->opts->basic,
d0e0e73e86f2afdb7f8fefbed70fda8d77b1c25aStephen Gallagher SDAP_AD_MATCHING_RULE_INITGROUPS)) {
d42d371c00c83ae44b9d1c3e88ecbe0e01b112e6Stephen Gallagher ret = sdap_get_ad_match_rule_initgroups_recv(subreq);
d42d371c00c83ae44b9d1c3e88ecbe0e01b112e6Stephen Gallagher } else {
d42d371c00c83ae44b9d1c3e88ecbe0e01b112e6Stephen Gallagher ret = sdap_initgr_rfc2307bis_recv(subreq);
d42d371c00c83ae44b9d1c3e88ecbe0e01b112e6Stephen Gallagher }
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny break;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny case SDAP_SCHEMA_IPA_V1:
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny ret = sdap_initgr_nested_recv(subreq);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny break;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny default:
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny ret = EINVAL;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny break;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny talloc_zfree(subreq);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny if (ret) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_TRACE_ALL, "Error in initgroups: [%d][%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
e182d98a391b5f6d3562e442748254cdbcef0b81Sumit Bose goto done;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny /* We also need to update the user's primary group, since
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny * the user may not be an explicit member of that group
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny */
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher
b56b06e199f15a8a840b36bc7cb8010e39ae761dSumit Bose if (state->use_id_mapping) {
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher DEBUG(SSSDBG_TRACE_LIBS,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Mapping primary group to unix ID\n");
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher /* The primary group ID is just the RID part of the objectSID
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher * of the group. Generate the GID by adding this to the domain
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher * SID value.
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher */
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher /* Get the user SID so we can extract the domain SID
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher * from it.
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher */
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher ret = sdap_attrs_get_sid_str(
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher tmp_ctx, opts->idmap_ctx, state->orig_user,
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher opts->user_map[SDAP_AT_USER_OBJECTSID].sys_name,
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher &sid_str);
e182d98a391b5f6d3562e442748254cdbcef0b81Sumit Bose if (ret != EOK) goto done;
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher /* Get the domain SID from the user SID */
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher ret = sdap_idmap_get_dom_sid_from_object(tmp_ctx, sid_str,
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher &dom_sid_str);
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher if (ret != EOK) {
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher DEBUG(SSSDBG_MINOR_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Could not parse domain SID from [%s]\n", sid_str);
e182d98a391b5f6d3562e442748254cdbcef0b81Sumit Bose goto done;
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher }
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher ret = sysdb_attrs_get_uint32_t(
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher state->orig_user,
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher opts->user_map[SDAP_AT_USER_PRIMARY_GROUP].sys_name,
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher &primary_gid);
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher if (ret != EOK) {
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher DEBUG(SSSDBG_MINOR_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "no primary group ID provided\n");
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher ret = EINVAL;
e182d98a391b5f6d3562e442748254cdbcef0b81Sumit Bose goto done;
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher }
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher /* Add the RID to the end */
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher group_sid_str = talloc_asprintf(tmp_ctx, "%s-%lu",
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher dom_sid_str,
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher (unsigned long)primary_gid);
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher if (!group_sid_str) {
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher ret = ENOMEM;
e182d98a391b5f6d3562e442748254cdbcef0b81Sumit Bose goto done;
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher }
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher /* Convert the SID into a UNIX group ID */
85089c1037f00c87a29f72647ece37a3b2b6481bSumit Bose ret = sdap_idmap_sid_to_unix(opts->idmap_ctx, group_sid_str,
85089c1037f00c87a29f72647ece37a3b2b6481bSumit Bose &primary_gid);
e182d98a391b5f6d3562e442748254cdbcef0b81Sumit Bose if (ret != EOK) goto done;
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher } else {
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher ret = sysdb_attrs_get_uint32_t(state->orig_user, SYSDB_GIDNUM,
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher &primary_gid);
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Could not find user's primary GID\n");
e182d98a391b5f6d3562e442748254cdbcef0b81Sumit Bose goto done;
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
e182d98a391b5f6d3562e442748254cdbcef0b81Sumit Bose ret = sysdb_search_group_by_gid(tmp_ctx, state->dom, primary_gid, NULL,
e182d98a391b5f6d3562e442748254cdbcef0b81Sumit Bose &msg);
e182d98a391b5f6d3562e442748254cdbcef0b81Sumit Bose if (ret == EOK) {
e182d98a391b5f6d3562e442748254cdbcef0b81Sumit Bose DEBUG(SSSDBG_TRACE_FUNC,
e182d98a391b5f6d3562e442748254cdbcef0b81Sumit Bose "Primary group already cached, nothing to do.\n");
e182d98a391b5f6d3562e442748254cdbcef0b81Sumit Bose } else {
e182d98a391b5f6d3562e442748254cdbcef0b81Sumit Bose gid = talloc_asprintf(state, "%lu", (unsigned long)primary_gid);
e182d98a391b5f6d3562e442748254cdbcef0b81Sumit Bose if (gid == NULL) {
e182d98a391b5f6d3562e442748254cdbcef0b81Sumit Bose ret = ENOMEM;
e182d98a391b5f6d3562e442748254cdbcef0b81Sumit Bose goto done;
e182d98a391b5f6d3562e442748254cdbcef0b81Sumit Bose }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
e182d98a391b5f6d3562e442748254cdbcef0b81Sumit Bose subreq = groups_get_send(req, state->ev, state->id_ctx,
e182d98a391b5f6d3562e442748254cdbcef0b81Sumit Bose state->id_ctx->opts->sdom, state->conn,
823d8292c4658b51821514adf21939e04b7423edLukas Slebodnik gid, BE_FILTER_IDNUM, false,
e182d98a391b5f6d3562e442748254cdbcef0b81Sumit Bose false);
e182d98a391b5f6d3562e442748254cdbcef0b81Sumit Bose if (!subreq) {
e182d98a391b5f6d3562e442748254cdbcef0b81Sumit Bose ret = ENOMEM;
e182d98a391b5f6d3562e442748254cdbcef0b81Sumit Bose goto done;
e182d98a391b5f6d3562e442748254cdbcef0b81Sumit Bose }
e182d98a391b5f6d3562e442748254cdbcef0b81Sumit Bose tevent_req_set_callback(subreq, sdap_get_initgr_pgid, req);
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose talloc_free(tmp_ctx);
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose return;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose ret = sdap_ad_check_domain_local_groups(req);
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose if (ret == EAGAIN) {
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose DEBUG(SSSDBG_TRACE_ALL,
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose "Checking for domain local group memberships.\n");
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose talloc_free(tmp_ctx);
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose return;
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose } else if (ret == EOK) {
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose DEBUG(SSSDBG_TRACE_ALL,
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose "No need to check for domain local group memberships.\n");
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose } else {
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose DEBUG(SSSDBG_OP_FAILURE,
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose "sdap_ad_check_domain_local_groups failed, "
4a9c1047354dbe5a4ed41e5951ae623e3772e113René Genz "memberships to domain local groups might be missing.\n");
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose /* do not let the request fail completely because we already have at
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose * least "some" groups */
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose ret = EOK;
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose }
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher
e182d98a391b5f6d3562e442748254cdbcef0b81Sumit Bosedone:
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher talloc_free(tmp_ctx);
e182d98a391b5f6d3562e442748254cdbcef0b81Sumit Bose if (ret == EOK) {
e182d98a391b5f6d3562e442748254cdbcef0b81Sumit Bose tevent_req_done(req);
e182d98a391b5f6d3562e442748254cdbcef0b81Sumit Bose } else {
e182d98a391b5f6d3562e442748254cdbcef0b81Sumit Bose tevent_req_error(req, ret);
e182d98a391b5f6d3562e442748254cdbcef0b81Sumit Bose }
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher return;
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny}
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zelenystatic void sdap_get_initgr_pgid(struct tevent_req *subreq)
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny{
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny struct tevent_req *req =
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny tevent_req_callback_data(subreq, struct tevent_req);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny errno_t ret;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
ca344fdecdf127c80ad1074047aeba21e1165313Jakub Hrozek ret = groups_get_recv(subreq, NULL, NULL);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny talloc_zfree(subreq);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (ret != EOK) {
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny tevent_req_error(req, ret);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny return;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny }
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose ret = sdap_ad_check_domain_local_groups(req);
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose if (ret == EAGAIN) {
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose DEBUG(SSSDBG_TRACE_ALL,
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose "Checking for domain local group memberships.\n");
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose return;
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose } else if (ret == EOK) {
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose DEBUG(SSSDBG_TRACE_ALL,
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose "No need to check for domain local group memberships.\n");
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose } else {
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose DEBUG(SSSDBG_OP_FAILURE,
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose "sdap_ad_check_domain_local_groups failed, "
4a9c1047354dbe5a4ed41e5951ae623e3772e113René Genz "memberships to domain local groups might be missing.\n");
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose /* do not let the request fail completely because we already have at
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose * least "some" groups */
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose }
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny tevent_req_done(req);
25699846bd1c9f8bb513b6271eb4366ab682fbd2Sumit Bose return;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny}
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zelenyint sdap_get_initgr_recv(struct tevent_req *req)
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny{
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny TEVENT_REQ_RETURN_ON_ERROR(req);
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny return EOK;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny}
9091fdea936f7d21584682b7f3d58f49b1e7b013Jan Zeleny
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březinastatic errno_t get_sysdb_grouplist_ex(TALLOC_CTX *mem_ctx,
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina struct sysdb_ctx *sysdb,
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina struct sss_domain_info *domain,
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina const char *name,
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina char ***grouplist,
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina bool get_dn)
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher{
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher errno_t ret;
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher const char *attrs[2];
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher struct ldb_message *msg;
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher TALLOC_CTX *tmp_ctx;
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher struct ldb_message_element *groups;
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher char **sysdb_grouplist = NULL;
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher unsigned int i;
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher attrs[0] = SYSDB_MEMBEROF;
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher attrs[1] = NULL;
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher tmp_ctx = talloc_new(NULL);
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher if (!tmp_ctx) return ENOMEM;
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher
4c08db0fb0dda3d27b1184248ca5c800d7ce23f0Michal Zidek ret = sysdb_search_user_by_name(tmp_ctx, domain, name,
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher attrs, &msg);
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher if (ret != EOK) {
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher DEBUG(SSSDBG_MINOR_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Error searching user [%s] by name: [%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov name, strerror(ret));
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher goto done;
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher }
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher groups = ldb_msg_find_element(msg, SYSDB_MEMBEROF);
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher if (!groups || groups->num_values == 0) {
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher /* No groups for this user in sysdb currently */
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher sysdb_grouplist = NULL;
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher } else {
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher sysdb_grouplist = talloc_array(tmp_ctx, char *, groups->num_values+1);
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher if (!sysdb_grouplist) {
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher ret = ENOMEM;
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher goto done;
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher }
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina if (get_dn) {
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina /* Get distinguish name */
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina for (i=0; i < groups->num_values; i++) {
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina sysdb_grouplist[i] = talloc_strdup(sysdb_grouplist,
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina (const char *)groups->values[i].data);
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina if (sysdb_grouplist[i] == NULL) {
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina ret = ENOMEM;
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina goto done;
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina }
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina }
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina } else {
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina /* Get a list of the groups by groupname only */
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina for (i=0; i < groups->num_values; i++) {
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina ret = sysdb_group_dn_name(sysdb,
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina sysdb_grouplist,
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina (const char *)groups->values[i].data,
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina &sysdb_grouplist[i]);
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina if (ret != EOK) {
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina DEBUG(SSSDBG_MINOR_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Could not determine group name from [%s]: [%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov (const char *)groups->values[i].data, strerror(ret));
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina goto done;
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina }
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher }
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher }
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher sysdb_grouplist[groups->num_values] = NULL;
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher }
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher *grouplist = talloc_steal(mem_ctx, sysdb_grouplist);
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagherdone:
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher talloc_free(tmp_ctx);
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher return ret;
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher}
1ed3a0d1d98ae410fcd716ec5c7202de2c082597Stephen Gallagher
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březinaerrno_t get_sysdb_grouplist(TALLOC_CTX *mem_ctx,
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina struct sysdb_ctx *sysdb,
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina struct sss_domain_info *domain,
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina const char *name,
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina char ***grouplist)
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina{
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina return get_sysdb_grouplist_ex(mem_ctx, sysdb, domain,
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina name, grouplist, false);
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina}
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březinaerrno_t get_sysdb_grouplist_dn(TALLOC_CTX *mem_ctx,
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina struct sysdb_ctx *sysdb,
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina struct sss_domain_info *domain,
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina const char *name,
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina char ***grouplist)
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina{
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina return get_sysdb_grouplist_ex(mem_ctx, sysdb, domain,
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina name, grouplist, true);
9cc66028cb6e497588a088ff2953e2ca7ed6ca6dPavel Březina}
a537df2ea99acb0181dc360ddf9a60b69c16faf0Fabiano Fidêncio
a537df2ea99acb0181dc360ddf9a60b69c16faf0Fabiano Fidêncioerrno_t
a537df2ea99acb0181dc360ddf9a60b69c16faf0Fabiano Fidênciosdap_handle_id_collision_for_incomplete_groups(struct data_provider *dp,
a537df2ea99acb0181dc360ddf9a60b69c16faf0Fabiano Fidêncio struct sss_domain_info *domain,
a537df2ea99acb0181dc360ddf9a60b69c16faf0Fabiano Fidêncio const char *name,
a537df2ea99acb0181dc360ddf9a60b69c16faf0Fabiano Fidêncio gid_t gid,
a537df2ea99acb0181dc360ddf9a60b69c16faf0Fabiano Fidêncio const char *original_dn,
a537df2ea99acb0181dc360ddf9a60b69c16faf0Fabiano Fidêncio const char *sid_str,
a537df2ea99acb0181dc360ddf9a60b69c16faf0Fabiano Fidêncio const char *uuid,
a537df2ea99acb0181dc360ddf9a60b69c16faf0Fabiano Fidêncio bool posix,
a537df2ea99acb0181dc360ddf9a60b69c16faf0Fabiano Fidêncio time_t now)
a537df2ea99acb0181dc360ddf9a60b69c16faf0Fabiano Fidêncio{
a537df2ea99acb0181dc360ddf9a60b69c16faf0Fabiano Fidêncio errno_t ret;
a537df2ea99acb0181dc360ddf9a60b69c16faf0Fabiano Fidêncio
a537df2ea99acb0181dc360ddf9a60b69c16faf0Fabiano Fidêncio ret = sysdb_delete_group(domain, NULL, gid);
a537df2ea99acb0181dc360ddf9a60b69c16faf0Fabiano Fidêncio if (ret != EOK) {
a537df2ea99acb0181dc360ddf9a60b69c16faf0Fabiano Fidêncio DEBUG(SSSDBG_MINOR_FAILURE,
a537df2ea99acb0181dc360ddf9a60b69c16faf0Fabiano Fidêncio "Due to an id collision, the new group with gid [\"%"PRIu32"\"] "
a537df2ea99acb0181dc360ddf9a60b69c16faf0Fabiano Fidêncio "will not be added as the old group (with the same gid) could "
a537df2ea99acb0181dc360ddf9a60b69c16faf0Fabiano Fidêncio "not be removed from the sysdb!",
a537df2ea99acb0181dc360ddf9a60b69c16faf0Fabiano Fidêncio gid);
a537df2ea99acb0181dc360ddf9a60b69c16faf0Fabiano Fidêncio return ret;
a537df2ea99acb0181dc360ddf9a60b69c16faf0Fabiano Fidêncio }
a537df2ea99acb0181dc360ddf9a60b69c16faf0Fabiano Fidêncio
a537df2ea99acb0181dc360ddf9a60b69c16faf0Fabiano Fidêncio ret = sysdb_add_incomplete_group(domain, name, gid, original_dn, sid_str,
a537df2ea99acb0181dc360ddf9a60b69c16faf0Fabiano Fidêncio uuid, posix, now);
a537df2ea99acb0181dc360ddf9a60b69c16faf0Fabiano Fidêncio if (ret != EOK) {
a537df2ea99acb0181dc360ddf9a60b69c16faf0Fabiano Fidêncio return ret;
a537df2ea99acb0181dc360ddf9a60b69c16faf0Fabiano Fidêncio }
a537df2ea99acb0181dc360ddf9a60b69c16faf0Fabiano Fidêncio
a537df2ea99acb0181dc360ddf9a60b69c16faf0Fabiano Fidêncio dp_sbus_invalidate_group_memcache(dp, gid);
a537df2ea99acb0181dc360ddf9a60b69c16faf0Fabiano Fidêncio
a537df2ea99acb0181dc360ddf9a60b69c16faf0Fabiano Fidêncio return EOK;
a537df2ea99acb0181dc360ddf9a60b69c16faf0Fabiano Fidêncio}