diff options
author | Jan Zeleny <jzeleny@redhat.com> | 2012-02-21 07:18:12 -0500 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2012-02-24 14:58:26 -0500 |
commit | 3ff729e6c8a371e7a52914772816c39ca73c50a9 (patch) | |
tree | 03d5c089a7b0c88dcbf79b3011f7a886d13bcfc2 | |
parent | 277a0187190fd417696590b303a5d7a204ed0555 (diff) | |
download | sssd-3ff729e6c8a371e7a52914772816c39ca73c50a9.tar.gz sssd-3ff729e6c8a371e7a52914772816c39ca73c50a9.tar.bz2 sssd-3ff729e6c8a371e7a52914772816c39ca73c50a9.zip |
Modifications to simplify list_missing_attrs
-rw-r--r-- | src/providers/ldap/ldap_common.c | 20 | ||||
-rw-r--r-- | src/providers/ldap/ldap_common.h | 1 | ||||
-rw-r--r-- | src/providers/ldap/sdap_async_groups.c | 2 | ||||
-rw-r--r-- | src/providers/ldap/sdap_async_initgroups.c | 2 | ||||
-rw-r--r-- | src/providers/ldap/sdap_async_netgroups.c | 16 | ||||
-rw-r--r-- | src/providers/ldap/sdap_async_private.h | 2 | ||||
-rw-r--r-- | src/providers/ldap/sdap_async_services.c | 9 | ||||
-rw-r--r-- | src/providers/ldap/sdap_async_users.c | 13 |
8 files changed, 21 insertions, 44 deletions
diff --git a/src/providers/ldap/ldap_common.c b/src/providers/ldap/ldap_common.c index 3b6a1b2b..ee2b56b6 100644 --- a/src/providers/ldap/ldap_common.c +++ b/src/providers/ldap/ldap_common.c @@ -1511,7 +1511,6 @@ errno_t get_sysdb_attr_name(TALLOC_CTX *mem_ctx, errno_t list_missing_attrs(TALLOC_CTX *mem_ctx, struct sdap_attr_map *map, size_t map_size, - const char **expected_attrs, struct sysdb_attrs *recvd_attrs, char ***missing_attrs) { @@ -1519,10 +1518,11 @@ errno_t list_missing_attrs(TALLOC_CTX *mem_ctx, size_t attr_count = 0; size_t i, j, k; char **missing = NULL; + const char **expected_attrs; char *sysdb_name; TALLOC_CTX *tmp_ctx; - if (!expected_attrs || !recvd_attrs || !missing_attrs) { + if (!recvd_attrs || !missing_attrs) { return EINVAL; } @@ -1531,6 +1531,11 @@ errno_t list_missing_attrs(TALLOC_CTX *mem_ctx, return ENOMEM; } + ret = build_attrs_from_map(tmp_ctx, map, map_size, &expected_attrs); + if (ret != EOK) { + goto done; + } + /* Count the expected attrs */ while(expected_attrs[attr_count]) attr_count++; @@ -1591,11 +1596,14 @@ errno_t list_missing_attrs(TALLOC_CTX *mem_ctx, } } - /* Terminate the list */ - missing[k] = NULL; - + if (k == 0) { + *missing = NULL; + } else { + /* Terminate the list */ + missing[k] = NULL; + *missing_attrs = talloc_steal(mem_ctx, missing); + } ret = EOK; - *missing_attrs = talloc_steal(mem_ctx, missing); done: talloc_free(tmp_ctx); diff --git a/src/providers/ldap/ldap_common.h b/src/providers/ldap/ldap_common.h index 7c472cf4..58054afe 100644 --- a/src/providers/ldap/ldap_common.h +++ b/src/providers/ldap/ldap_common.h @@ -186,7 +186,6 @@ errno_t get_sysdb_attr_name(TALLOC_CTX *mem_ctx, errno_t list_missing_attrs(TALLOC_CTX *mem_ctx, struct sdap_attr_map *map, size_t map_size, - const char **expected_attrs, struct sysdb_attrs *recvd_attrs, char ***missing_attrs); diff --git a/src/providers/ldap/sdap_async_groups.c b/src/providers/ldap/sdap_async_groups.c index d58ed468..aad2990c 100644 --- a/src/providers/ldap/sdap_async_groups.c +++ b/src/providers/ldap/sdap_async_groups.c @@ -1123,7 +1123,7 @@ next: } if (state->check_count == 0) { - ret = sdap_save_users(state, state->sysdb, state->attrs, + ret = sdap_save_users(state, state->sysdb, state->dom, state->opts, state->new_members, state->count, NULL); if (ret) { diff --git a/src/providers/ldap/sdap_async_initgroups.c b/src/providers/ldap/sdap_async_initgroups.c index 2f8e1ef6..1e2e6178 100644 --- a/src/providers/ldap/sdap_async_initgroups.c +++ b/src/providers/ldap/sdap_async_initgroups.c @@ -2548,7 +2548,7 @@ static void sdap_get_initgr_user(struct tevent_req *subreq) ret = sdap_save_user(state, state->sysdb, state->opts, state->dom, - state->orig_user, state->user_attrs, + state->orig_user, true, NULL, 0); if (ret) { sysdb_transaction_cancel(state->sysdb); diff --git a/src/providers/ldap/sdap_async_netgroups.c b/src/providers/ldap/sdap_async_netgroups.c index a5f30623..2262db51 100644 --- a/src/providers/ldap/sdap_async_netgroups.c +++ b/src/providers/ldap/sdap_async_netgroups.c @@ -49,7 +49,6 @@ static errno_t sdap_save_netgroup(TALLOC_CTX *memctx, const char *name = NULL; int ret; char *timestamp = NULL; - const char **ldap_attrs = NULL; char **missing = NULL; ret = sysdb_attrs_get_el(attrs, @@ -129,29 +128,16 @@ static errno_t sdap_save_netgroup(TALLOC_CTX *memctx, goto fail; } - ret = build_attrs_from_map(attrs, opts->netgroup_map, SDAP_OPTS_NETGROUP, - &ldap_attrs); - if (ret != EOK) { - DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to retrieve attributes from map\n")); - goto fail; - } - /* Make sure that any attributes we requested from LDAP that we * did not receive are also removed from the sysdb */ ret = list_missing_attrs(attrs, opts->netgroup_map, SDAP_OPTS_NETGROUP, - ldap_attrs, attrs, &missing); + attrs, &missing); if (ret != EOK) { DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to list missing attributes\n")); goto fail; } - /* Remove missing attributes */ - if (missing && !missing[0]) { - /* Nothing to remove */ - talloc_zfree(missing); - } - ret = sysdb_add_netgroup(ctx, name, NULL, netgroup_attrs, missing, dom->netgroup_timeout, now); if (ret) goto fail; diff --git a/src/providers/ldap/sdap_async_private.h b/src/providers/ldap/sdap_async_private.h index 4192a225..f6ed6800 100644 --- a/src/providers/ldap/sdap_async_private.h +++ b/src/providers/ldap/sdap_async_private.h @@ -94,14 +94,12 @@ int sdap_save_user(TALLOC_CTX *memctx, struct sdap_options *opts, struct sss_domain_info *dom, struct sysdb_attrs *attrs, - const char **ldap_attrs, bool is_initgr, char **_usn_value, time_t now); int sdap_save_users(TALLOC_CTX *memctx, struct sysdb_ctx *sysdb, - const char **attrs, struct sss_domain_info *dom, struct sdap_options *opts, struct sysdb_attrs **users, diff --git a/src/providers/ldap/sdap_async_services.c b/src/providers/ldap/sdap_async_services.c index 783861c7..ae96d888 100644 --- a/src/providers/ldap/sdap_async_services.c +++ b/src/providers/ldap/sdap_async_services.c @@ -53,7 +53,6 @@ sdap_get_services_process(struct tevent_req *subreq); static errno_t sdap_save_services(TALLOC_CTX *memctx, struct sysdb_ctx *sysdb, - const char **attrs, struct sss_domain_info *dom, struct sdap_options *opts, struct sysdb_attrs **services, @@ -65,7 +64,6 @@ sdap_save_service(TALLOC_CTX *mem_ctx, struct sdap_options *opts, struct sss_domain_info *dom, struct sysdb_attrs *attrs, - const char **ldap_attrs, char **_usn_value, time_t now); @@ -231,7 +229,6 @@ sdap_get_services_process(struct tevent_req *subreq) } ret = sdap_save_services(state, state->sysdb, - state->attrs, state->dom, state->opts, state->services, state->count, &state->higher_usn); @@ -251,7 +248,6 @@ sdap_get_services_process(struct tevent_req *subreq) static errno_t sdap_save_services(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb, - const char **attrs, struct sss_domain_info *dom, struct sdap_options *opts, struct sysdb_attrs **services, @@ -286,7 +282,7 @@ sdap_save_services(TALLOC_CTX *mem_ctx, usn_value = NULL; ret = sdap_save_service(tmp_ctx, sysdb, opts, dom, - services[i], attrs, + services[i], &usn_value, now); /* Do not fail completely on errors. @@ -344,7 +340,6 @@ sdap_save_service(TALLOC_CTX *mem_ctx, struct sdap_options *opts, struct sss_domain_info *dom, struct sysdb_attrs *attrs, - const char **ldap_attrs, char **_usn_value, time_t now) { @@ -451,7 +446,7 @@ sdap_save_service(TALLOC_CTX *mem_ctx, * that have been removed from LDAP */ ret = list_missing_attrs(svc_attrs, opts->service_map, SDAP_OPTS_SERVICES, - ldap_attrs, attrs, &missing); + attrs, &missing); if (ret != EOK) { DEBUG(SSSDBG_MINOR_FAILURE, ("Failed to identify removed attributes: [%s]\n", diff --git a/src/providers/ldap/sdap_async_users.c b/src/providers/ldap/sdap_async_users.c index 57540749..20067040 100644 --- a/src/providers/ldap/sdap_async_users.c +++ b/src/providers/ldap/sdap_async_users.c @@ -34,7 +34,6 @@ int sdap_save_user(TALLOC_CTX *memctx, struct sdap_options *opts, struct sss_domain_info *dom, struct sysdb_attrs *attrs, - const char **ldap_attrs, bool is_initgr, char **_usn_value, time_t now) @@ -256,17 +255,11 @@ int sdap_save_user(TALLOC_CTX *memctx, * did not receive are also removed from the sysdb */ ret = list_missing_attrs(user_attrs, opts->user_map, SDAP_OPTS_USER, - ldap_attrs, attrs, &missing); + attrs, &missing); if (ret != EOK) { goto fail; } - /* Remove missing attributes */ - if (missing && !missing[0]) { - /* Nothing to remove */ - talloc_zfree(missing); - } - DEBUG(6, ("Storing info for user %s\n", name)); ret = sysdb_store_user(ctx, name, pwd, uid, gid, gecos, homedir, shell, @@ -293,7 +286,6 @@ fail: int sdap_save_users(TALLOC_CTX *memctx, struct sysdb_ctx *sysdb, - const char **attrs, struct sss_domain_info *dom, struct sdap_options *opts, struct sysdb_attrs **users, @@ -327,7 +319,7 @@ int sdap_save_users(TALLOC_CTX *memctx, usn_value = NULL; ret = sdap_save_user(tmpctx, sysdb, opts, dom, - users[i], attrs, false, + users[i], false, &usn_value, now); /* Do not fail completely on errors. @@ -558,7 +550,6 @@ static void sdap_get_users_process(struct tevent_req *subreq) } ret = sdap_save_users(state, state->sysdb, - state->attrs, state->dom, state->opts, state->users, state->count, &state->higher_usn); |