ipa_netgroups.c revision 3e1c814a7ca3a0e4086e0822d6b4df23b8465bc8
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher Async IPA Helper routines for netgroups
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher Jan Zeleny <jzeleny@redhat.com>
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher Copyright (C) 2011 Red Hat
2cb6f28b3a12bb714bf14494d31eb6b6fff64b8bJakub Hrozek This program is free software; you can redistribute it and/or modify
2cb6f28b3a12bb714bf14494d31eb6b6fff64b8bJakub Hrozek it under the terms of the GNU General Public License as published by
7797e361155f7ce937085fd98e360469d7baf1b6Jakub Hrozek the Free Software Foundation; either version 3 of the License, or
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher (at your option) any later version.
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher This program is distributed in the hope that it will be useful,
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher but WITHOUT ANY WARRANTY; without even the implied warranty of
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7a14e8f66c0e932fe2954d792614a3b61d444bd1Jakub Hrozek GNU General Public License for more details.
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher You should have received a copy of the GNU General Public License
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher along with this program. If not, see <http://www.gnu.org/licenses/>.
65a9065538fd85e6ead925d344e6b421900eb8c2Jakub Hrozek const char **attrs;
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher /* Entities which have been already asked for
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher * and are scheduled for inspection */
65a9065538fd85e6ead925d344e6b421900eb8c2Jakub Hrozekstatic errno_t ipa_save_netgroup(TALLOC_CTX *mem_ctx,
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher opts->netgroup_map[IPA_AT_NETGROUP_NAME].sys_name,
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher DEBUG(SSSDBG_TRACE_INTERNAL, ("Storing netgroup %s\n", name));
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher ret = sysdb_attrs_get_el(attrs, SYSDB_ORIG_DN, &el);
b355dcb54194f498921743ca33304eac35d89718Stephen Gallagher DEBUG(7, ("Original DN is not available for [%s].\n", name));
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher DEBUG(7, ("Adding original DN [%s] to attributes of [%s].\n",
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher ret = sysdb_attrs_add_string(netgroup_attrs, SYSDB_ORIG_DN,
b355dcb54194f498921743ca33304eac35d89718Stephen Gallagher ret = sysdb_attrs_get_el(attrs, SYSDB_NETGROUP_TRIPLE, &el);
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher DEBUG(SSSDBG_TRACE_INTERNAL, ("No netgroup triples for netgroup [%s].\n", name));
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher ret = sysdb_attrs_get_el(netgroup_attrs, SYSDB_NETGROUP_TRIPLE, &el);
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher ret = sysdb_attrs_add_string(netgroup_attrs,
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher opts->netgroup_map[IPA_AT_NETGROUP_MEMBER].sys_name,
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher DEBUG(7, ("No original members for netgroup [%s]\n", name));
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher DEBUG(7, ("Adding original members to netgroup [%s]\n", name));
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher opts->netgroup_map[IPA_AT_NETGROUP_MEMBER].sys_name,
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher ret = sysdb_attrs_get_el(attrs, SYSDB_NETGROUP_MEMBER, &el);
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher DEBUG(7, ("No members for netgroup [%s]\n", name));
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher DEBUG(7, ("Adding members to netgroup [%s]\n", name));
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher ret = sysdb_attrs_add_string(netgroup_attrs, SYSDB_NETGROUP_MEMBER,
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher DEBUG(6, ("Storing info for netgroup %s\n", name));
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher ret = sysdb_add_netgroup(ctx, name, NULL, netgroup_attrs,
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher DEBUG(2, ("Failed to save netgroup %s\n", name));
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherstatic errno_t ipa_netgr_next_base(struct tevent_req *req);
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherstatic void ipa_get_netgroups_process(struct tevent_req *subreq);
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherstatic int ipa_netgr_process_all(struct ipa_get_netgroups_state *state);
b355dcb54194f498921743ca33304eac35d89718Stephen Gallagherstruct tevent_req *ipa_get_netgroups_send(TALLOC_CTX *memctx,
b355dcb54194f498921743ca33304eac35d89718Stephen Gallagher req = tevent_req_create(memctx, &state, struct ipa_get_netgroups_state);
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher if (!ipa_options->id->netgroup_search_bases) {
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher ("Netgroup lookup request without a search base\n"));
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher ret = sss_hash_create(state, 32, &state->new_netgroups);
2cb6f28b3a12bb714bf14494d31eb6b6fff64b8bJakub Hrozek ret = sss_hash_create(state, 32, &state->new_users);
b355dcb54194f498921743ca33304eac35d89718Stephen Gallagher ret = sss_hash_create(state, 32, &state->new_hosts);
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherstatic errno_t ipa_netgr_next_base(struct tevent_req *req)
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher state = tevent_req_data(req, struct ipa_get_netgroups_state);
dd3ba5c5b7d2a9d109963ae9e6c94fff34872221Stephen Gallagher netgr_bases = state->ipa_opts->id->netgroup_search_bases;
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher state->filter = sdap_get_id_specific_filter(
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher netgr_bases[state->netgr_base_iter]->filter);
dd3ba5c5b7d2a9d109963ae9e6c94fff34872221Stephen Gallagher ("Searching for netgroups with base [%s]\n",
dd3ba5c5b7d2a9d109963ae9e6c94fff34872221Stephen Gallagher netgr_bases[state->netgr_base_iter]->basedn));
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher netgr_bases[state->netgr_base_iter]->scope,
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher state->opts->netgroup_map, IPA_OPTS_NETGROUP,
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher tevent_req_set_callback(subreq, ipa_get_netgroups_process, req);
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherstatic int ipa_netgr_fetch_netgroups(struct ipa_get_netgroups_state *state,
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherstatic int ipa_netgr_fetch_users(struct ipa_get_netgroups_state *state,
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherstatic int ipa_netgr_fetch_hosts(struct ipa_get_netgroups_state *state,
dd3ba5c5b7d2a9d109963ae9e6c94fff34872221Stephen Gallagherstatic void ipa_netgr_members_process(struct tevent_req *subreq);
b355dcb54194f498921743ca33304eac35d89718Stephen Gallagherstatic void ipa_get_netgroups_process(struct tevent_req *subreq)
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher struct tevent_req *req = tevent_req_callback_data(subreq,
2cb6f28b3a12bb714bf14494d31eb6b6fff64b8bJakub Hrozek struct ipa_get_netgroups_state *state = tevent_req_data(req,
b355dcb54194f498921743ca33304eac35d89718Stephen Gallagher netgr_bases = state->ipa_opts->id->netgroup_search_bases;
dd3ba5c5b7d2a9d109963ae9e6c94fff34872221Stephen Gallagher ret = sdap_get_generic_recv(subreq, state, &netgroups_count, &netgroups);
2cb6f28b3a12bb714bf14494d31eb6b6fff64b8bJakub Hrozek DEBUG(6, ("Search for netgroups, returned %d results.\n", netgroups_count));
dd3ba5c5b7d2a9d109963ae9e6c94fff34872221Stephen Gallagher /* No netgroups found in this search */
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher if (netgr_bases[state->netgr_base_iter]) {
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher /* There are more search bases to try */
dd3ba5c5b7d2a9d109963ae9e6c94fff34872221Stephen Gallagher for (i = 0; i < netgroups_count; i++) {
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher ret = sysdb_attrs_get_el(netgroups[i], SYSDB_ORIG_NETGROUP_MEMBER,
dd3ba5c5b7d2a9d109963ae9e6c94fff34872221Stephen Gallagher ret = sysdb_attrs_get_el(netgroups[i], SYSDB_ORIG_MEMBER_USER,
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher ret = sysdb_attrs_get_el(netgroups[i], SYSDB_ORIG_MEMBER_HOST,
b355dcb54194f498921743ca33304eac35d89718Stephen Gallagher ret = sysdb_attrs_get_string(netgroups[i], SYSDB_ORIG_DN, &orig_dn);
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher ret = hash_enter(state->new_netgroups, &key, &value);
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher if (ng_found->num_values) state->entities_found |= ENTITY_NG;
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher if (user_found->num_values) state->entities_found |= ENTITY_USER;
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher if (host_found->num_values) state->entities_found |= ENTITY_HOST;
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher ret = sss_filter_sanitize(state, orig_dn, &dn);
2cb6f28b3a12bb714bf14494d31eb6b6fff64b8bJakub Hrozek /* Add this to the filter */
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher filter = talloc_asprintf_append(filter, "(%s=%s)",
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher state->opts->netgroup_map[IPA_AT_NETGROUP_MEMBER_OF].name,
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher state->filter = talloc_asprintf_append(filter, ")");
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher ret = ipa_netgr_fetch_netgroups(state, req);
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher } else if (state->entities_found & ENTITY_USER) {
524ceecc11f3d458eb3c1cf1489c3ff6ccb22226Jakub Hrozek } else if (state->entities_found & ENTITY_HOST) {
524ceecc11f3d458eb3c1cf1489c3ff6ccb22226Jakub Hrozekstatic int ipa_netgr_fetch_netgroups(struct ipa_get_netgroups_state *state,
524ceecc11f3d458eb3c1cf1489c3ff6ccb22226Jakub Hrozek bases = state->ipa_opts->id->netgroup_search_bases;
2cb6f28b3a12bb714bf14494d31eb6b6fff64b8bJakub Hrozek /* No more bases to try */
524ceecc11f3d458eb3c1cf1489c3ff6ccb22226Jakub Hrozek base_filter = bases[state->netgr_base_iter]->filter;
524ceecc11f3d458eb3c1cf1489c3ff6ccb22226Jakub Hrozek filter = talloc_asprintf(state, "(&%s%s(objectclass=%s))",
dd3ba5c5b7d2a9d109963ae9e6c94fff34872221Stephen Gallagher state->opts->netgroup_map[SDAP_OC_NETGROUP].name);
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher subreq = sdap_get_generic_send(state, state->ev, state->opts, state->sh,
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher filter, state->attrs, state->opts->netgroup_map,
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher tevent_req_set_callback(subreq, ipa_netgr_members_process, req);
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherstatic int ipa_netgr_fetch_users(struct ipa_get_netgroups_state *state,
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher const char *attrs[] = { state->opts->user_map[SDAP_AT_USER_NAME].name,
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher state->opts->user_map[SDAP_AT_USER_MEMBEROF].name,
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher bases = state->ipa_opts->id->user_search_bases;
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher if (bases[state->user_base_iter] == NULL) {
2cb6f28b3a12bb714bf14494d31eb6b6fff64b8bJakub Hrozek base_filter = bases[state->user_base_iter]->filter;
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher filter = talloc_asprintf(state, "(&%s%s(objectclass=%s))",
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher subreq = sdap_get_generic_send(state, state->ev, state->opts, state->sh,
2cb6f28b3a12bb714bf14494d31eb6b6fff64b8bJakub Hrozek tevent_req_set_callback(subreq, ipa_netgr_members_process, req);
2cb6f28b3a12bb714bf14494d31eb6b6fff64b8bJakub Hrozekstatic int ipa_netgr_fetch_hosts(struct ipa_get_netgroups_state *state,
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher bases = state->ipa_opts->host_search_bases;
b355dcb54194f498921743ca33304eac35d89718Stephen Gallagher if (bases[state->host_base_iter] == NULL) {
2cb6f28b3a12bb714bf14494d31eb6b6fff64b8bJakub Hrozek base_filter = bases[state->host_base_iter]->filter;
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher filter = talloc_asprintf(state, "(&%s%s(objectclass=%s))",
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher ret = build_attrs_from_map(state, state->opts->host_map,
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher subreq = sdap_get_generic_send(state, state->ev, state->opts, state->sh,
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher tevent_req_set_callback(subreq, ipa_netgr_members_process, req);
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherstatic void ipa_netgr_members_process(struct tevent_req *subreq)
dd3ba5c5b7d2a9d109963ae9e6c94fff34872221Stephen Gallagher struct tevent_req *req = tevent_req_callback_data(subreq,
dd3ba5c5b7d2a9d109963ae9e6c94fff34872221Stephen Gallagher struct ipa_get_netgroups_state *state = tevent_req_data(req,
dd3ba5c5b7d2a9d109963ae9e6c94fff34872221Stephen Gallagher int (* next_call)(struct ipa_get_netgroups_state *,
6463ed1dcdd45416468b3fa178bd856b5a9ed2c3Jakub Hrozek ret = sdap_get_generic_recv(subreq, state, &count, &entities);
6463ed1dcdd45416468b3fa178bd856b5a9ed2c3Jakub Hrozek DEBUG(SSSDBG_TRACE_INTERNAL, ("Found %u members in current search base\n", count));
2cb6f28b3a12bb714bf14494d31eb6b6fff64b8bJakub Hrozek /* While processing a batch of entities from one search base,
6463ed1dcdd45416468b3fa178bd856b5a9ed2c3Jakub Hrozek * schedule query for another search base if there is one
6463ed1dcdd45416468b3fa178bd856b5a9ed2c3Jakub Hrozek * If there is no other search base, another class of entities
6463ed1dcdd45416468b3fa178bd856b5a9ed2c3Jakub Hrozek * will be scheduled for lookup after processing of current
6463ed1dcdd45416468b3fa178bd856b5a9ed2c3Jakub Hrozek * batch. The order of lookup is: netgroups -> users -> hosts
6463ed1dcdd45416468b3fa178bd856b5a9ed2c3Jakub Hrozek /* We just received a batch of netgroups */
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher /* If there is a member netgroup, we always have to
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher * ask for both member users and hosts
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher * -> now schedule users
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher } else if (state->current_entity == ENTITY_USER) {
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher /* We just received a batch of users */
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher if (state->entities_found & ENTITY_HOST ||
2cb6f28b3a12bb714bf14494d31eb6b6fff64b8bJakub Hrozek } else if (state->current_entity == ENTITY_HOST) {
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher /* We just received a batch of hosts */
2cb6f28b3a12bb714bf14494d31eb6b6fff64b8bJakub Hrozek ("Invalid entity type given for processing: %d\n",
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher /* Next search base has been scheduled for inspection,
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher * don't try to look for other type of entities
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher /* Process all member entites and store them in the designated hash table */
2cb6f28b3a12bb714bf14494d31eb6b6fff64b8bJakub Hrozek for (i = 0; i < count; i++) {
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher ret = sysdb_attrs_get_string(entities[i], SYSDB_ORIG_DN, &orig_dn);
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher orig_dn_lower = talloc_strdup(table, orig_dn);
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher /* Transform the DN to lower case.
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher * this is important, as the member/memberof attributes
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher * have the value also in lower-case
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher /* The next search base is already scheduled to be searched */
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher /* There is another class of members that has to be retrieved
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher * - schedule the lookup
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher /* All members, that could have been fetched, were fetched */
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherstatic bool extract_netgroups(hash_entry_t *entry, void *pvt)
2cb6f28b3a12bb714bf14494d31eb6b6fff64b8bJakub Hrozek state = talloc_get_type(pvt, struct ipa_get_netgroups_state);
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher state->netgroups[state->netgroups_count] = talloc_get_type(entry->value.ptr,
2cb6f28b3a12bb714bf14494d31eb6b6fff64b8bJakub Hrozekstatic bool extract_entities(hash_entry_t *entry, void *pvt)
2cb6f28b3a12bb714bf14494d31eb6b6fff64b8bJakub Hrozek state = talloc_get_type(pvt, struct extract_state);
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher member = talloc_get_type(entry->value.ptr, struct sysdb_attrs);
2cb6f28b3a12bb714bf14494d31eb6b6fff64b8bJakub Hrozek ret = sysdb_attrs_get_el(member, SYSDB_MEMBEROF, &el);
2cb6f28b3a12bb714bf14494d31eb6b6fff64b8bJakub Hrozek ret = sysdb_attrs_get_el(member, SYSDB_NAME, &name_el);
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher if (ret != EOK || name_el == NULL || name_el->num_values == 0) {
65a9065538fd85e6ead925d344e6b421900eb8c2Jakub Hrozek if (strcmp((char *)el->values[i].data, state->group) == 0) {
65a9065538fd85e6ead925d344e6b421900eb8c2Jakub Hrozek state->entries = talloc_realloc(state, state->entries, const char *,
2cb6f28b3a12bb714bf14494d31eb6b6fff64b8bJakub Hrozek return false;
65a9065538fd85e6ead925d344e6b421900eb8c2Jakub Hrozek state->entries[state->entries_count] = (char *)name_el->values[0].data;
65a9065538fd85e6ead925d344e6b421900eb8c2Jakub Hrozek const char ***_ret_array,
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher state = talloc_zero(mem_ctx, struct extract_state);
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher ret = sysdb_attrs_get_el(netgroup, member_type, &el);
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher ret = hash_lookup(lookup_table, &key, &value);
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher if (ret != HASH_SUCCESS && ret != HASH_ERROR_KEY_NOT_FOUND) {
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher process = talloc_realloc(mem_ctx, process, const char *, process_count + 1);
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher process[process_count] = (char *)el->values[i].data;
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher ret_array = talloc_realloc(mem_ctx, ret_array, const char *, ret_count + 1);
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher member = talloc_get_type(value.ptr, struct sysdb_attrs);
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher ret = sysdb_attrs_get_string(member, SYSDB_NAME, &ret_array[ret_count]);
b355dcb54194f498921743ca33304eac35d89718Stephen Gallagher hash_iterate(lookup_table, extract_entities, state);
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher ret_array = talloc_realloc(mem_ctx, ret_array, const char *,
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher state->entries_count*sizeof(const char *));
2cb6f28b3a12bb714bf14494d31eb6b6fff64b8bJakub Hrozekstatic int ipa_netgr_process_all(struct ipa_get_netgroups_state *state)
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher int i, j, k, ret;
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher struct ldb_message_element *external_hosts;
486237ee009f1d84fc4c85665dce80ade76f7079Stephen Gallagher state->netgroups = talloc_zero_array(state, struct sysdb_attrs *,
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher extract_state = talloc_zero(state, struct extract_state);
2cb6f28b3a12bb714bf14494d31eb6b6fff64b8bJakub Hrozek hash_iterate(state->new_netgroups, extract_netgroups, state);
dd3ba5c5b7d2a9d109963ae9e6c94fff34872221Stephen Gallagher for (i = 0; i < state->netgroups_count; i++) {
dd3ba5c5b7d2a9d109963ae9e6c94fff34872221Stephen Gallagher /* load all its member netgroups, translate */
dd3ba5c5b7d2a9d109963ae9e6c94fff34872221Stephen Gallagher DEBUG(SSSDBG_TRACE_INTERNAL, ("Extracting netgroup members of netgroup %d\n", i));
dd3ba5c5b7d2a9d109963ae9e6c94fff34872221Stephen Gallagher ret = sysdb_attrs_get_string_array(state->netgroups[i],
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher for (j = 0; members[j]; j++) {
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher ret = hash_lookup(state->new_netgroups, &key, &value);
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher member = talloc_get_type(value.ptr, struct sysdb_attrs);
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher ret = sysdb_attrs_get_string(member, SYSDB_NAME, &member_name);
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher ret = sysdb_attrs_add_string(state->netgroups[i],
2cb6f28b3a12bb714bf14494d31eb6b6fff64b8bJakub Hrozek DEBUG(SSSDBG_TRACE_INTERNAL, ("Extracted %d netgroup members\n", j));
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher /* Load all UIDs */
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher DEBUG(SSSDBG_TRACE_ALL, ("Extracting user members of netgroup %d\n", i));
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher ret = extract_members(state, state->netgroups[i],
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher DEBUG(SSSDBG_TRACE_INTERNAL, ("Extracted %d user members\n", uids_count));
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher DEBUG(SSSDBG_TRACE_ALL, ("Extracting host members of netgroup %d\n", i));
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher ret = extract_members(state, state->netgroups[i],
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher DEBUG(SSSDBG_TRACE_INTERNAL, ("Extracted %d host members\n", hosts_count));
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher ret = sysdb_attrs_get_el(state->netgroups[i],
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher hosts = talloc_realloc(state, hosts, const char *,
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher hosts_count + external_hosts->num_values);
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher for (j = 0; j < external_hosts->num_values; j++) {
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher hosts[hosts_count] = talloc_strdup(hosts, (char *)external_hosts->values[j].data);
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher ret = sysdb_attrs_get_string(state->netgroups[i], SYSDB_NETGROUP_DOMAIN,
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher DEBUG(SSSDBG_TRACE_INTERNAL, ("Putting together triples of "
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher "netgroup %d\n", i));
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher for (j = 0; j < uids_count; j++) {
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher for (k = 0; k < hosts_count; k++) {
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher ret = sysdb_attrs_add_string(state->netgroups[i],
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher ret = ipa_save_netgroup(state, state->sysdb, state->dom,
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherint ipa_get_netgroups_recv(struct tevent_req *req,
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher struct ipa_get_netgroups_state *state = tevent_req_data(req,