ipa_netgroups.c revision 57170bd05e64559a604c1907c59728e8d9e83cd4
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi Async IPA Helper routines for netgroups
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi Jan Zeleny <jzeleny@redhat.com>
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi Copyright (C) 2011 Red Hat
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi This program is free software; you can redistribute it and/or modify
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi it under the terms of the GNU General Public License as published by
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi the Free Software Foundation; either version 3 of the License, or
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi (at your option) any later version.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi This program is distributed in the hope that it will be useful,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi but WITHOUT ANY WARRANTY; without even the implied warranty of
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi GNU General Public License for more details.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi You should have received a copy of the GNU General Public License
a5ba96715d4ef264c43d4f187251de491ba198c0KATOH Yasufumi along with this program. If not, see <http://www.gnu.org/licenses/>.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi#include "providers/ldap/sdap_async_private.h"
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi const char **attrs;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi /* Entities which have been already asked for
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi * and are scheduled for inspection */
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumistatic errno_t ipa_save_netgroup(TALLOC_CTX *mem_ctx,
dc421f3aac1f0e516c763dd156629a8ed2a7b4caKATOH Yasufumi opts->netgroup_map[IPA_AT_NETGROUP_NAME].sys_name,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi DEBUG(SSSDBG_TRACE_INTERNAL, ("Storing netgroup %s\n", name));
dc421f3aac1f0e516c763dd156629a8ed2a7b4caKATOH Yasufumi ret = sysdb_attrs_get_el(attrs, SYSDB_ORIG_DN, &el);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi DEBUG(7, ("Original DN is not available for [%s].\n", name));
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi DEBUG(7, ("Adding original DN [%s] to attributes of [%s].\n",
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi ret = sysdb_attrs_add_string(netgroup_attrs, SYSDB_ORIG_DN,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi ret = sysdb_attrs_get_el(attrs, SYSDB_NETGROUP_TRIPLE, &el);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi DEBUG(7, ("No netgroup triples for netgroup [%s].\n", name));
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi opts->netgroup_map[IPA_AT_NETGROUP_MEMBER].sys_name,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi DEBUG(7, ("No original members for netgroup [%s]\n", name));
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi DEBUG(7, ("Adding original members to netgroup [%s]\n", name));
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi opts->netgroup_map[IPA_AT_NETGROUP_MEMBER].sys_name,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi ret = sysdb_attrs_get_el(attrs, SYSDB_NETGROUP_MEMBER, &el);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi DEBUG(7, ("No members for netgroup [%s]\n", name));
348cb247dbb92940b5684c12b43579bccba85dabKATOH Yasufumi DEBUG(7, ("Adding members to netgroup [%s]\n", name));
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi ret = sysdb_attrs_add_string(netgroup_attrs, SYSDB_NETGROUP_MEMBER,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi DEBUG(6, ("Storing info for netgroup %s\n", name));
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi ret = sysdb_add_netgroup(ctx, name, NULL, netgroup_attrs,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi DEBUG(2, ("Failed to save netgroup %s\n", name));
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumistatic errno_t ipa_netgr_next_base(struct tevent_req *req);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumistatic void ipa_get_netgroups_process(struct tevent_req *subreq);
4724cf84f941156273d52918704c6e584455f6b4KATOH Yasufumistatic int ipa_netgr_process_all(struct ipa_get_netgroups_state *state);
4724cf84f941156273d52918704c6e584455f6b4KATOH Yasufumistruct tevent_req *ipa_get_netgroups_send(TALLOC_CTX *memctx,
4724cf84f941156273d52918704c6e584455f6b4KATOH Yasufumi const char **attrs,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi req = tevent_req_create(memctx, &state, struct ipa_get_netgroups_state);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi ret = sss_hash_create(state, 32, &state->new_netgroups);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi ret = sss_hash_create(state, 32, &state->new_users);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi ret = sss_hash_create(state, 32, &state->new_hosts);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumistatic errno_t ipa_netgr_next_base(struct tevent_req *req)
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumi state = tevent_req_data(req, struct ipa_get_netgroups_state);
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumi netgr_bases = state->ipa_opts->id->netgroup_search_bases;
dc421f3aac1f0e516c763dd156629a8ed2a7b4caKATOH Yasufumi netgr_bases[state->netgr_base_iter]->filter);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi ("Searching for netgroups with base [%s]\n",
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi netgr_bases[state->netgr_base_iter]->basedn));
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi state->opts->netgroup_map, IPA_OPTS_NETGROUP,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi tevent_req_set_callback(subreq, ipa_get_netgroups_process, req);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumistatic int ipa_netgr_fetch_netgroups(struct ipa_get_netgroups_state *state,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumistatic int ipa_netgr_fetch_users(struct ipa_get_netgroups_state *state,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumistatic int ipa_netgr_fetch_hosts(struct ipa_get_netgroups_state *state,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumistatic void ipa_netgr_members_process(struct tevent_req *subreq);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumistatic void ipa_get_netgroups_process(struct tevent_req *subreq)
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi struct tevent_req *req = tevent_req_callback_data(subreq,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi struct ipa_get_netgroups_state *state = tevent_req_data(req,
const char *orig_dn;
char *dn;
char *filter;
bool fetch_members = false;
if (ret) {
goto done;
if (netgroups_count == 0) {
goto done;
goto done;
for (i = 0; i < netgroups_count; i++) {
&ng_found);
&user_found);
&host_found);
goto done;
goto done;
goto done;
dn);
goto done;
fetch_members = true;
if (!fetch_members) {
goto done;
done:
char *filter;
const char *base_filter;
return ENOENT;
return ENOMEM;
return ENOMEM;
return EOK;
char *filter;
const char *base_filter;
return ENOENT;
return ENOMEM;
return ENOMEM;
return EOK;
const char **attrs;
char *filter;
const char *base_filter;
int ret;
return ENOENT;
return ENOMEM;
return ret;
return ENOMEM;
return EOK;
struct tevent_req);
struct ipa_get_netgroups_state);
int ret, i;
const char *orig_dn;
char *orig_dn_lower;
struct tevent_req *);
bool next_batch_scheduled = false;
if (ret) {
goto fail;
goto fail;
next_batch_scheduled = true;
goto fail;
for (i = 0; i < count; i++) {
goto fail;
goto fail;
goto fail;
if (next_batch_scheduled) {
if (next_call) {
fail:
struct sysdb_attrs);
struct extract_state {
const char *group;
const char **entries;
int entries_count;
int i, ret;
const char *member_type,
const char ***_ret_array,
int *_ret_count)
int process_count = 0;
int ret_count = 0;
int ret, i;
goto done;
goto done;
goto done;
goto done;
goto done;
goto done;
ret_count++;
for (i = 0; i < process_count; i++) {
goto done;
done:
return ret;
int i, j, k, ret;
const char **members;
const char *member_name;
int uids_count = 0;
int hosts_count = 0;
const char *domain;
char *triple;
return ENOMEM;
goto done;
goto done;
for (j = 0; members[j]; j++) {
goto done;
goto done;
goto done;
goto done;
goto done;
goto done;
goto done;
goto done;
hosts_count++;
&domain);
goto done;
if (uids_count == 0) {
if (hosts_count == 0) {
for (j = 0; j < uids_count; j++) {
for (k = 0; k < hosts_count; k++) {
domain);
goto done;
goto done;
goto done;
done:
return ret;
struct ipa_get_netgroups_state);
if (reply_count) {
if (reply) {
return EOK;