summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJan Zeleny <jzeleny@redhat.com>2012-05-23 04:21:35 -0400
committerStephen Gallagher <sgallagh@redhat.com>2012-05-31 15:46:27 -0400
commit64ddff90c7fcc02ccb06824ac93af7d5f361a88f (patch)
tree70f12aa095d575826844f26278c2056ce8df0cf5 /src
parent3111c28041b732b98a7fb39ef6232257d086d670 (diff)
downloadsssd-64ddff90c7fcc02ccb06824ac93af7d5f361a88f.tar.gz
sssd-64ddff90c7fcc02ccb06824ac93af7d5f361a88f.tar.bz2
sssd-64ddff90c7fcc02ccb06824ac93af7d5f361a88f.zip
Add support for filtering atributes
This patch adds support for filtering attributes when constructing attribute list from a map for LDAP query.
Diffstat (limited to 'src')
-rw-r--r--src/providers/ipa/ipa_hosts.c5
-rw-r--r--src/providers/ipa/ipa_id.c3
-rw-r--r--src/providers/ipa/ipa_netgroups.c2
-rw-r--r--src/providers/ipa/ipa_selinux_maps.c3
-rw-r--r--src/providers/ipa/ipa_subdomains_id.c6
-rw-r--r--src/providers/ldap/ldap_common.c3
-rw-r--r--src/providers/ldap/ldap_id.c12
-rw-r--r--src/providers/ldap/ldap_id_enum.c8
-rw-r--r--src/providers/ldap/ldap_id_netgroup.c4
-rw-r--r--src/providers/ldap/ldap_id_services.c3
-rw-r--r--src/providers/ldap/sdap.c20
-rw-r--r--src/providers/ldap/sdap.h1
-rw-r--r--src/providers/ldap/sdap_async_autofs.c6
-rw-r--r--src/providers/ldap/sdap_async_groups.c10
-rw-r--r--src/providers/ldap/sdap_async_initgroups.c20
-rw-r--r--src/providers/ldap/sdap_async_services.c3
-rw-r--r--src/providers/ldap/sdap_sudo.c2
17 files changed, 70 insertions, 41 deletions
diff --git a/src/providers/ipa/ipa_hosts.c b/src/providers/ipa/ipa_hosts.c
index 09a5acaf..792af410 100644
--- a/src/providers/ipa/ipa_hosts.c
+++ b/src/providers/ipa/ipa_hosts.c
@@ -103,7 +103,7 @@ ipa_host_info_send(TALLOC_CTX *mem_ctx,
state->hostgroup_map = hostgroup_map;
ret = build_attrs_from_map(state, host_map, IPA_OPTS_HOST,
- &state->attrs, NULL);
+ NULL, &state->attrs, NULL);
if (ret != EOK) {
goto immediate;
}
@@ -214,7 +214,8 @@ ipa_host_info_done(struct tevent_req *subreq)
if (state->hostgroup_map) {
talloc_free(state->attrs);
ret = build_attrs_from_map(state, state->hostgroup_map,
- IPA_OPTS_HOSTGROUP, &state->attrs, NULL);
+ IPA_OPTS_HOSTGROUP, NULL,
+ &state->attrs, NULL);
if (ret != EOK) {
tevent_req_error(req, ret);
return;
diff --git a/src/providers/ipa/ipa_id.c b/src/providers/ipa/ipa_id.c
index 1f434799..5f528632 100644
--- a/src/providers/ipa/ipa_id.c
+++ b/src/providers/ipa/ipa_id.c
@@ -212,7 +212,8 @@ struct tevent_req *ipa_netgroup_get_send(TALLOC_CTX *memctx,
talloc_zfree(clean_name);
ret = build_attrs_from_map(state, ctx->opts->netgroup_map,
- IPA_OPTS_NETGROUP, &state->attrs, NULL);
+ IPA_OPTS_NETGROUP, NULL,
+ &state->attrs, NULL);
if (ret != EOK) goto fail;
ret = ipa_netgroup_get_retry(req);
diff --git a/src/providers/ipa/ipa_netgroups.c b/src/providers/ipa/ipa_netgroups.c
index 881eeb86..7d9a433e 100644
--- a/src/providers/ipa/ipa_netgroups.c
+++ b/src/providers/ipa/ipa_netgroups.c
@@ -528,7 +528,7 @@ static int ipa_netgr_fetch_hosts(struct ipa_get_netgroups_state *state,
return ENOMEM;
ret = build_attrs_from_map(state, state->ipa_opts->host_map,
- IPA_OPTS_HOST, &attrs, NULL);
+ IPA_OPTS_HOST, NULL, &attrs, NULL);
if (ret != EOK) {
talloc_free(filter);
return ret;
diff --git a/src/providers/ipa/ipa_selinux_maps.c b/src/providers/ipa/ipa_selinux_maps.c
index 28923cee..b0a2c8f7 100644
--- a/src/providers/ipa/ipa_selinux_maps.c
+++ b/src/providers/ipa/ipa_selinux_maps.c
@@ -77,7 +77,8 @@ struct tevent_req *ipa_selinux_get_maps_send(TALLOC_CTX *mem_ctx,
state->maps = NULL;
ret = build_attrs_from_map(state, ipa_opts->selinuxuser_map,
- IPA_OPTS_SELINUX_USERMAP, &state->attrs, NULL);
+ IPA_OPTS_SELINUX_USERMAP, NULL,
+ &state->attrs, NULL);
if (ret != EOK) goto fail;
state->cur_filter = NULL;
diff --git a/src/providers/ipa/ipa_subdomains_id.c b/src/providers/ipa/ipa_subdomains_id.c
index 39f076cd..eed8170c 100644
--- a/src/providers/ipa/ipa_subdomains_id.c
+++ b/src/providers/ipa/ipa_subdomains_id.c
@@ -89,11 +89,13 @@ struct tevent_req *ipa_get_subdomain_account_info_send(TALLOC_CTX *memctx,
switch (state->entry_type) {
case BE_REQ_USER:
ret = build_attrs_from_map(state, ctx->opts->user_map,
- SDAP_OPTS_USER, &state->attrs, NULL);
+ SDAP_OPTS_USER, NULL,
+ &state->attrs, NULL);
break;
case BE_REQ_GROUP:
ret = build_attrs_from_map(state, ctx->opts->group_map,
- SDAP_OPTS_GROUP, &state->attrs, NULL);
+ SDAP_OPTS_GROUP, NULL,
+ &state->attrs, NULL);
break;
default:
ret = EINVAL;
diff --git a/src/providers/ldap/ldap_common.c b/src/providers/ldap/ldap_common.c
index dd782815..22cd7d9a 100644
--- a/src/providers/ldap/ldap_common.c
+++ b/src/providers/ldap/ldap_common.c
@@ -1303,7 +1303,8 @@ errno_t list_missing_attrs(TALLOC_CTX *mem_ctx,
return ENOMEM;
}
- ret = build_attrs_from_map(tmp_ctx, map, map_size, &expected_attrs, &attr_count);
+ ret = build_attrs_from_map(tmp_ctx, map, map_size, NULL,
+ &expected_attrs, &attr_count);
if (ret != EOK) {
goto done;
}
diff --git a/src/providers/ldap/ldap_id.c b/src/providers/ldap/ldap_id.c
index bdd640a9..889fbddc 100644
--- a/src/providers/ldap/ldap_id.c
+++ b/src/providers/ldap/ldap_id.c
@@ -151,8 +151,8 @@ struct tevent_req *users_get_send(TALLOC_CTX *memctx,
}
/* TODO: handle attrs_type */
- ret = build_attrs_from_map(state, ctx->opts->user_map,
- SDAP_OPTS_USER, &state->attrs, NULL);
+ ret = build_attrs_from_map(state, ctx->opts->user_map, SDAP_OPTS_USER,
+ NULL, &state->attrs, NULL);
if (ret != EOK) goto fail;
ret = users_get_retry(req);
@@ -439,8 +439,8 @@ struct tevent_req *groups_get_send(TALLOC_CTX *memctx,
}
/* TODO: handle attrs_type */
- ret = build_attrs_from_map(state, ctx->opts->group_map,
- SDAP_OPTS_GROUP, &state->attrs, NULL);
+ ret = build_attrs_from_map(state, ctx->opts->group_map, SDAP_OPTS_GROUP,
+ NULL, &state->attrs, NULL);
if (ret != EOK) goto fail;
ret = groups_get_retry(req);
@@ -631,8 +631,8 @@ static struct tevent_req *groups_by_user_send(TALLOC_CTX *memctx,
state->name = name;
- ret = build_attrs_from_map(state, ctx->opts->group_map,
- SDAP_OPTS_GROUP, &state->attrs, NULL);
+ ret = build_attrs_from_map(state, ctx->opts->group_map, SDAP_OPTS_GROUP,
+ NULL, &state->attrs, NULL);
if (ret != EOK) goto fail;
ret = groups_by_user_retry(req);
diff --git a/src/providers/ldap/ldap_id_enum.c b/src/providers/ldap/ldap_id_enum.c
index 107ab23f..53fc99fb 100644
--- a/src/providers/ldap/ldap_id_enum.c
+++ b/src/providers/ldap/ldap_id_enum.c
@@ -557,8 +557,8 @@ static struct tevent_req *enum_users_send(TALLOC_CTX *memctx,
}
/* TODO: handle attrs_type */
- ret = build_attrs_from_map(state, ctx->opts->user_map,
- SDAP_OPTS_USER, &state->attrs, NULL);
+ ret = build_attrs_from_map(state, ctx->opts->user_map, SDAP_OPTS_USER,
+ NULL, &state->attrs, NULL);
if (ret != EOK) goto fail;
/* TODO: restrict the enumerations to using a single
@@ -716,8 +716,8 @@ static struct tevent_req *enum_groups_send(TALLOC_CTX *memctx,
}
/* TODO: handle attrs_type */
- ret = build_attrs_from_map(state, ctx->opts->group_map,
- SDAP_OPTS_GROUP, &state->attrs, NULL);
+ ret = build_attrs_from_map(state, ctx->opts->group_map, SDAP_OPTS_GROUP,
+ NULL, &state->attrs, NULL);
if (ret != EOK) goto fail;
/* TODO: restrict the enumerations to using a single
diff --git a/src/providers/ldap/ldap_id_netgroup.c b/src/providers/ldap/ldap_id_netgroup.c
index 7fe7543f..58a9a346 100644
--- a/src/providers/ldap/ldap_id_netgroup.c
+++ b/src/providers/ldap/ldap_id_netgroup.c
@@ -98,8 +98,8 @@ struct tevent_req *ldap_netgroup_get_send(TALLOC_CTX *memctx,
}
talloc_zfree(clean_name);
- ret = build_attrs_from_map(state, ctx->opts->netgroup_map,
- SDAP_OPTS_NETGROUP, &state->attrs, NULL);
+ ret = build_attrs_from_map(state, ctx->opts->netgroup_map, SDAP_OPTS_NETGROUP,
+ NULL, &state->attrs, NULL);
if (ret != EOK) goto fail;
ret = ldap_netgroup_get_retry(req);
diff --git a/src/providers/ldap/ldap_id_services.c b/src/providers/ldap/ldap_id_services.c
index 16d696af..b0291351 100644
--- a/src/providers/ldap/ldap_id_services.c
+++ b/src/providers/ldap/ldap_id_services.c
@@ -135,7 +135,8 @@ services_get_send(TALLOC_CTX *mem_ctx,
state->filter));
ret = build_attrs_from_map(state, id_ctx->opts->service_map,
- SDAP_OPTS_SERVICES, &state->attrs, NULL);
+ SDAP_OPTS_SERVICES, NULL,
+ &state->attrs, NULL);
if (ret != EOK) goto error;
ret = services_get_retry(req);
diff --git a/src/providers/ldap/sdap.c b/src/providers/ldap/sdap.c
index 01ba418a..cb02f4a5 100644
--- a/src/providers/ldap/sdap.c
+++ b/src/providers/ldap/sdap.c
@@ -1019,10 +1019,28 @@ void sdap_steal_server_opts(struct sdap_id_ctx *id_ctx,
id_ctx->srv_opts = talloc_move(id_ctx, srv_opts);
}
+static bool attr_is_filtered(const char *attr, const char **filter)
+{
+ int i;
+
+ if (filter) {
+ i = 0;
+ while (filter[i]) {
+ if (filter[i] == attr ||
+ strcasecmp(filter[i], attr) == 0) {
+ return true;
+ }
+ i++;
+ }
+ }
+
+ return false;
+}
int build_attrs_from_map(TALLOC_CTX *memctx,
struct sdap_attr_map *map,
size_t size,
+ const char **filter,
const char ***_attrs,
size_t *attr_count)
{
@@ -1045,7 +1063,7 @@ int build_attrs_from_map(TALLOC_CTX *memctx,
/* add the others */
for (i = j = 1; i < size; i++) {
- if (map[i].name) {
+ if (map[i].name && !attr_is_filtered(map[i].name, filter)) {
attrs[j] = map[i].name;
j++;
}
diff --git a/src/providers/ldap/sdap.h b/src/providers/ldap/sdap.h
index 61f899f3..90558221 100644
--- a/src/providers/ldap/sdap.h
+++ b/src/providers/ldap/sdap.h
@@ -454,6 +454,7 @@ bool sdap_check_sup_list(struct sup_list *l, const char *val);
int build_attrs_from_map(TALLOC_CTX *memctx,
struct sdap_attr_map *map,
size_t size,
+ const char **filter,
const char ***_attrs,
size_t *attr_count);
diff --git a/src/providers/ldap/sdap_async_autofs.c b/src/providers/ldap/sdap_async_autofs.c
index d8a2d0ee..9c8337d3 100644
--- a/src/providers/ldap/sdap_async_autofs.c
+++ b/src/providers/ldap/sdap_async_autofs.c
@@ -242,7 +242,8 @@ automntmaps_process_members_send(TALLOC_CTX *mem_ctx,
}
ret = build_attrs_from_map(state, opts->autofs_entry_map,
- SDAP_OPTS_AUTOFS_ENTRY, &state->attrs, NULL);
+ SDAP_OPTS_AUTOFS_ENTRY, NULL,
+ &state->attrs, NULL);
if (ret != EOK) {
DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to build attributes from map\n"));
ret = ENOMEM;
@@ -674,7 +675,8 @@ sdap_autofs_setautomntent_send(TALLOC_CTX *memctx,
talloc_free(clean_mapname);
ret = build_attrs_from_map(state, state->opts->autofs_mobject_map,
- SDAP_OPTS_AUTOFS_MAP, &state->attrs, NULL);
+ SDAP_OPTS_AUTOFS_MAP, NULL,
+ &state->attrs, NULL);
if (ret != EOK) {
DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to build attributes from map\n"));
ret = ENOMEM;
diff --git a/src/providers/ldap/sdap_async_groups.c b/src/providers/ldap/sdap_async_groups.c
index 637a2527..2a079228 100644
--- a/src/providers/ldap/sdap_async_groups.c
+++ b/src/providers/ldap/sdap_async_groups.c
@@ -728,7 +728,7 @@ struct tevent_req *sdap_process_group_send(TALLOC_CTX *memctx,
if (!req) return NULL;
ret = build_attrs_from_map(grp_state, opts->user_map, SDAP_OPTS_USER,
- &attrs, NULL);
+ NULL, &attrs, NULL);
if (ret) {
goto done;
}
@@ -2484,8 +2484,8 @@ sdap_nested_group_process_deref_call(struct tevent_req *req)
/* Pull down the whole group map, but only pull down username
* and originalDN for users. */
- ret = build_attrs_from_map(state, state->opts->group_map,
- SDAP_OPTS_GROUP, &sdap_attrs, &attr_count);
+ ret = build_attrs_from_map(state, state->opts->group_map, SDAP_OPTS_GROUP,
+ NULL, &sdap_attrs, &attr_count);
if (ret != EOK) goto fail;
sdap_attrs = talloc_realloc(NULL, sdap_attrs, const char *,
@@ -2687,8 +2687,8 @@ static errno_t sdap_nested_group_lookup_group(struct tevent_req *req)
return EOK;
}
- ret = build_attrs_from_map(state, state->opts->group_map,
- SDAP_OPTS_GROUP, &sdap_attrs, NULL);
+ ret = build_attrs_from_map(state, state->opts->group_map, SDAP_OPTS_GROUP,
+ NULL, &sdap_attrs, NULL);
if (ret != EOK) {
return ret;
}
diff --git a/src/providers/ldap/sdap_async_initgroups.c b/src/providers/ldap/sdap_async_initgroups.c
index 86117600..1911b1bb 100644
--- a/src/providers/ldap/sdap_async_initgroups.c
+++ b/src/providers/ldap/sdap_async_initgroups.c
@@ -353,8 +353,8 @@ struct tevent_req *sdap_initgr_rfc2307_send(TALLOC_CTX *memctx,
return NULL;
}
- ret = build_attrs_from_map(state, opts->group_map,
- SDAP_OPTS_GROUP, &state->attrs, NULL);
+ ret = build_attrs_from_map(state, opts->group_map, SDAP_OPTS_GROUP,
+ NULL, &state->attrs, NULL);
if (ret != EOK) {
talloc_free(req);
return NULL;
@@ -843,8 +843,8 @@ static errno_t sdap_initgr_nested_deref_search(struct tevent_req *req)
maps[0].num_attrs = SDAP_OPTS_GROUP;
maps[1].map = NULL;
- ret = build_attrs_from_map(state, state->opts->group_map,
- SDAP_OPTS_GROUP, &sdap_attrs, NULL);
+ ret = build_attrs_from_map(state, state->opts->group_map, SDAP_OPTS_GROUP,
+ NULL, &sdap_attrs, NULL);
if (ret != EOK) goto fail;
timeout = dp_opt_get_int(state->opts->basic, SDAP_SEARCH_TIMEOUT);
@@ -1495,8 +1495,8 @@ static struct tevent_req *sdap_initgr_rfc2307bis_send(
return NULL;
}
- ret = build_attrs_from_map(state, opts->group_map,
- SDAP_OPTS_GROUP, &state->attrs, NULL);
+ ret = build_attrs_from_map(state, opts->group_map, SDAP_OPTS_GROUP,
+ NULL, &state->attrs, NULL);
if (ret != EOK) goto done;
ret = sss_filter_sanitize(state, orig_dn, &clean_orig_dn);
@@ -2168,8 +2168,8 @@ static errno_t rfc2307bis_nested_groups_step(struct tevent_req *req)
goto done;
}
- ret = build_attrs_from_map(state, state->opts->group_map,
- SDAP_OPTS_GROUP, &state->attrs, NULL);
+ ret = build_attrs_from_map(state, state->opts->group_map, SDAP_OPTS_GROUP,
+ NULL, &state->attrs, NULL);
if (ret != EOK) {
goto done;
}
@@ -2504,8 +2504,8 @@ struct tevent_req *sdap_get_initgr_send(TALLOC_CTX *memctx,
return NULL;
}
- ret = build_attrs_from_map(state, state->opts->user_map,
- SDAP_OPTS_USER, &state->user_attrs, NULL);
+ ret = build_attrs_from_map(state, state->opts->user_map, SDAP_OPTS_USER,
+ NULL, &state->user_attrs, NULL);
if (ret) {
talloc_zfree(req);
return NULL;
diff --git a/src/providers/ldap/sdap_async_services.c b/src/providers/ldap/sdap_async_services.c
index 895ea7e7..a59db6c6 100644
--- a/src/providers/ldap/sdap_async_services.c
+++ b/src/providers/ldap/sdap_async_services.c
@@ -572,7 +572,8 @@ enum_services_send(TALLOC_CTX *memctx,
/* TODO: handle attrs_type */
ret = build_attrs_from_map(state, id_ctx->opts->service_map,
- SDAP_OPTS_SERVICES, &state->attrs, NULL);
+ SDAP_OPTS_SERVICES, NULL,
+ &state->attrs, NULL);
if (ret != EOK) goto fail;
subreq = sdap_get_services_send(state, state->ev,
diff --git a/src/providers/ldap/sdap_sudo.c b/src/providers/ldap/sdap_sudo.c
index 23fd062c..75d30430 100644
--- a/src/providers/ldap/sdap_sudo.c
+++ b/src/providers/ldap/sdap_sudo.c
@@ -456,7 +456,7 @@ struct tevent_req * sdap_sudo_load_sudoers_send(TALLOC_CTX *mem_ctx,
/* create attrs from map */
ret = build_attrs_from_map(state, opts->sudorule_map, SDAP_OPTS_SUDO,
- &state->attrs, NULL);
+ NULL, &state->attrs, NULL);
if (ret != EOK) {
goto fail;
}