diff options
-rw-r--r-- | src/db/sysdb.c | 155 | ||||
-rw-r--r-- | src/db/sysdb.h | 57 | ||||
-rw-r--r-- | src/db/sysdb_ops.c | 501 | ||||
-rw-r--r-- | src/db/sysdb_search.c | 18 | ||||
-rw-r--r-- | src/providers/ipa/ipa_access.c | 2 | ||||
-rw-r--r-- | src/providers/ipa/ipa_hbac_common.c | 4 | ||||
-rw-r--r-- | src/providers/krb5/krb5_auth.c | 7 | ||||
-rw-r--r-- | src/providers/ldap/ldap_auth.c | 3 | ||||
-rw-r--r-- | src/providers/ldap/ldap_id.c | 12 | ||||
-rw-r--r-- | src/providers/ldap/ldap_id_cleanup.c | 4 | ||||
-rw-r--r-- | src/providers/ldap/sdap_access.c | 3 | ||||
-rw-r--r-- | src/providers/ldap/sdap_async_accounts.c | 18 | ||||
-rw-r--r-- | src/providers/proxy/proxy_auth.c | 3 | ||||
-rw-r--r-- | src/providers/proxy/proxy_id.c | 18 | ||||
-rw-r--r-- | src/responder/pam/pam_LOCAL_domain.c | 9 | ||||
-rw-r--r-- | src/responder/pam/pamsrv_cmd.c | 5 | ||||
-rw-r--r-- | src/tests/auth-tests.c | 2 | ||||
-rw-r--r-- | src/tests/sysdb-tests.c | 41 | ||||
-rw-r--r-- | src/tools/sss_cache.c | 8 | ||||
-rw-r--r-- | src/tools/sss_sync_ops.c | 14 |
20 files changed, 429 insertions, 455 deletions
diff --git a/src/db/sysdb.c b/src/db/sysdb.c index dd7ce7ec..3174f3d1 100644 --- a/src/db/sysdb.c +++ b/src/db/sysdb.c @@ -64,7 +64,7 @@ static errno_t sysdb_ldb_connect(TALLOC_CTX *mem_ctx, const char *filename, return EOK; } -errno_t sysdb_dn_sanitize(void *mem_ctx, const char *input, +errno_t sysdb_dn_sanitize(TALLOC_CTX *mem_ctx, const char *input, char **sanitized) { struct ldb_val val; @@ -89,7 +89,8 @@ errno_t sysdb_dn_sanitize(void *mem_ctx, const char *input, return ret; } -struct ldb_dn *sysdb_custom_subtree_dn(struct sysdb_ctx *sysdb, void *memctx, +struct ldb_dn *sysdb_custom_subtree_dn(struct sysdb_ctx *sysdb, + TALLOC_CTX *mem_ctx, const char *domain, const char *subtree_name) { @@ -98,7 +99,7 @@ struct ldb_dn *sysdb_custom_subtree_dn(struct sysdb_ctx *sysdb, void *memctx, struct ldb_dn *dn = NULL; TALLOC_CTX *tmp_ctx; - tmp_ctx = talloc_new(memctx); + tmp_ctx = talloc_new(NULL); if (!tmp_ctx) return NULL; ret = sysdb_dn_sanitize(tmp_ctx, subtree_name, &clean_subtree); @@ -110,13 +111,13 @@ struct ldb_dn *sysdb_custom_subtree_dn(struct sysdb_ctx *sysdb, void *memctx, dn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, SYSDB_TMPL_CUSTOM_SUBTREE, clean_subtree, domain); if (dn) { - talloc_steal(memctx, dn); + talloc_steal(mem_ctx, dn); } talloc_free(tmp_ctx); return dn; } -struct ldb_dn *sysdb_custom_dn(struct sysdb_ctx *sysdb, void *memctx, +struct ldb_dn *sysdb_custom_dn(struct sysdb_ctx *sysdb, TALLOC_CTX *mem_ctx, const char *domain, const char *object_name, const char *subtree_name) { @@ -141,7 +142,7 @@ struct ldb_dn *sysdb_custom_dn(struct sysdb_ctx *sysdb, void *memctx, goto done; } - dn = ldb_dn_new_fmt(memctx, sysdb->ldb, SYSDB_TMPL_CUSTOM, clean_name, + dn = ldb_dn_new_fmt(mem_ctx, sysdb->ldb, SYSDB_TMPL_CUSTOM, clean_name, clean_subtree, domain); done: @@ -149,7 +150,7 @@ done: return dn; } -struct ldb_dn *sysdb_user_dn(struct sysdb_ctx *sysdb, void *memctx, +struct ldb_dn *sysdb_user_dn(struct sysdb_ctx *sysdb, TALLOC_CTX *mem_ctx, const char *domain, const char *name) { errno_t ret; @@ -161,14 +162,14 @@ struct ldb_dn *sysdb_user_dn(struct sysdb_ctx *sysdb, void *memctx, return NULL; } - dn = ldb_dn_new_fmt(memctx, sysdb->ldb, SYSDB_TMPL_USER, + dn = ldb_dn_new_fmt(mem_ctx, sysdb->ldb, SYSDB_TMPL_USER, clean_name, domain); talloc_free(clean_name); return dn; } -struct ldb_dn *sysdb_group_dn(struct sysdb_ctx *sysdb, void *memctx, +struct ldb_dn *sysdb_group_dn(struct sysdb_ctx *sysdb, TALLOC_CTX *mem_ctx, const char *domain, const char *name) { errno_t ret; @@ -180,14 +181,14 @@ struct ldb_dn *sysdb_group_dn(struct sysdb_ctx *sysdb, void *memctx, return NULL; } - dn = ldb_dn_new_fmt(memctx, sysdb->ldb, SYSDB_TMPL_GROUP, + dn = ldb_dn_new_fmt(mem_ctx, sysdb->ldb, SYSDB_TMPL_GROUP, clean_name, domain); talloc_free(clean_name); return dn; } -struct ldb_dn *sysdb_netgroup_dn(struct sysdb_ctx *sysdb, void *memctx, +struct ldb_dn *sysdb_netgroup_dn(struct sysdb_ctx *sysdb, TALLOC_CTX *mem_ctx, const char *domain, const char *name) { errno_t ret; @@ -199,37 +200,37 @@ struct ldb_dn *sysdb_netgroup_dn(struct sysdb_ctx *sysdb, void *memctx, return NULL; } - dn = ldb_dn_new_fmt(memctx, sysdb->ldb, SYSDB_TMPL_NETGROUP, + dn = ldb_dn_new_fmt(mem_ctx, sysdb->ldb, SYSDB_TMPL_NETGROUP, clean_name, domain); talloc_free(clean_name); return dn; } -struct ldb_dn *sysdb_netgroup_base_dn(struct sysdb_ctx *sysdb, void *memctx, +struct ldb_dn *sysdb_netgroup_base_dn(struct sysdb_ctx *sysdb, TALLOC_CTX *mem_ctx, const char *domain) { - return ldb_dn_new_fmt(memctx, sysdb->ldb, SYSDB_TMPL_NETGROUP_BASE, domain); + return ldb_dn_new_fmt(mem_ctx, sysdb->ldb, SYSDB_TMPL_NETGROUP_BASE, domain); } -errno_t sysdb_get_rdn(struct sysdb_ctx *sysdb, void *memctx, +errno_t sysdb_get_rdn(struct sysdb_ctx *sysdb, TALLOC_CTX *mem_ctx, const char *_dn, char **_name, char **_val) { errno_t ret; struct ldb_dn *dn; const char *attr_name = NULL; const struct ldb_val *val; - TALLOC_CTX *tmpctx; + TALLOC_CTX *tmp_ctx; - /* We have to create a tmpctx here because - * ldb_dn_new_fmt() fails if memctx is NULL + /* We have to create a tmp_ctx here because + * ldb_dn_new_fmt() fails if mem_ctx is NULL */ - tmpctx = talloc_new(NULL); - if (!tmpctx) { + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { return ENOMEM; } - dn = ldb_dn_new_fmt(tmpctx, sysdb->ldb, "%s", _dn); + dn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, "%s", _dn); if (dn == NULL) { ret = ENOMEM; goto done; @@ -242,7 +243,7 @@ errno_t sysdb_get_rdn(struct sysdb_ctx *sysdb, void *memctx, goto done; } - *_name = talloc_strdup(memctx, attr_name); + *_name = talloc_strdup(mem_ctx, attr_name); if (!*_name) { ret = ENOMEM; goto done; @@ -256,7 +257,7 @@ errno_t sysdb_get_rdn(struct sysdb_ctx *sysdb, void *memctx, goto done; } - *_val = talloc_strndup(memctx, (char *) val->data, val->length); + *_val = talloc_strndup(mem_ctx, (char *) val->data, val->length); if (!*_val) { ret = ENOMEM; if (_name) talloc_free(*_name); @@ -266,20 +267,20 @@ errno_t sysdb_get_rdn(struct sysdb_ctx *sysdb, void *memctx, ret = EOK; done: - talloc_zfree(tmpctx); + talloc_zfree(tmp_ctx); return ret; } -errno_t sysdb_group_dn_name(struct sysdb_ctx *sysdb, void *memctx, +errno_t sysdb_group_dn_name(struct sysdb_ctx *sysdb, TALLOC_CTX *mem_ctx, const char *_dn, char **_name) { - return sysdb_get_rdn(sysdb, memctx, _dn, NULL, _name); + return sysdb_get_rdn(sysdb, mem_ctx, _dn, NULL, _name); } -struct ldb_dn *sysdb_domain_dn(struct sysdb_ctx *sysdb, void *memctx, +struct ldb_dn *sysdb_domain_dn(struct sysdb_ctx *sysdb, TALLOC_CTX *mem_ctx, const char *domain) { - return ldb_dn_new_fmt(memctx, sysdb->ldb, SYSDB_DOM_BASE, domain); + return ldb_dn_new_fmt(mem_ctx, sysdb->ldb, SYSDB_DOM_BASE, domain); } struct ldb_context *sysdb_ctx_get_ldb(struct sysdb_ctx *sysdb) @@ -292,9 +293,9 @@ struct sss_domain_info *sysdb_ctx_get_domain(struct sysdb_ctx *sysdb) return sysdb->domain; } -struct sysdb_attrs *sysdb_new_attrs(TALLOC_CTX *memctx) +struct sysdb_attrs *sysdb_new_attrs(TALLOC_CTX *mem_ctx) { - return talloc_zero(memctx, struct sysdb_attrs); + return talloc_zero(mem_ctx, struct sysdb_attrs); } static int sysdb_attrs_get_el_int(struct sysdb_attrs *attrs, const char *name, @@ -667,7 +668,7 @@ int sysdb_attrs_users_from_ldb_vals(struct sysdb_attrs *attrs, return EOK; } -static char *build_dom_dn_str_escape(TALLOC_CTX *memctx, const char *template, +static char *build_dom_dn_str_escape(TALLOC_CTX *mem_ctx, const char *template, const char *domain, const char *name) { char *ret; @@ -681,12 +682,12 @@ static char *build_dom_dn_str_escape(TALLOC_CTX *memctx, const char *template, v.data = discard_const_p(uint8_t, name); v.length = strlen(name); - tmp = ldb_dn_escape_value(memctx, v); + tmp = ldb_dn_escape_value(mem_ctx, v); if (!tmp) { return NULL; } - ret = talloc_asprintf(memctx, template, tmp, domain); + ret = talloc_asprintf(mem_ctx, template, tmp, domain); talloc_zfree(tmp); if (!ret) { return NULL; @@ -695,7 +696,7 @@ static char *build_dom_dn_str_escape(TALLOC_CTX *memctx, const char *template, return ret; } - ret = talloc_asprintf(memctx, template, name, domain); + ret = talloc_asprintf(mem_ctx, template, name, domain); if (!ret) { return NULL; } @@ -703,16 +704,16 @@ static char *build_dom_dn_str_escape(TALLOC_CTX *memctx, const char *template, return ret; } -char *sysdb_user_strdn(TALLOC_CTX *memctx, +char *sysdb_user_strdn(TALLOC_CTX *mem_ctx, const char *domain, const char *name) { - return build_dom_dn_str_escape(memctx, SYSDB_TMPL_USER, domain, name); + return build_dom_dn_str_escape(mem_ctx, SYSDB_TMPL_USER, domain, name); } -char *sysdb_group_strdn(TALLOC_CTX *memctx, +char *sysdb_group_strdn(TALLOC_CTX *mem_ctx, const char *domain, const char *name) { - return build_dom_dn_str_escape(memctx, SYSDB_TMPL_GROUP, domain, name); + return build_dom_dn_str_escape(mem_ctx, SYSDB_TMPL_GROUP, domain, name); } /* TODO: make a more complete and precise mapping */ @@ -827,8 +828,7 @@ static int finish_upgrade(int result, struct ldb_context *ldb, * finally stop indexing memberUid * upgrade version to 0.2 */ -static int sysdb_upgrade_01(TALLOC_CTX *mem_ctx, - struct ldb_context *ldb, +static int sysdb_upgrade_01(struct ldb_context *ldb, const char **ver) { struct ldb_message_element *el; @@ -842,14 +842,21 @@ static int sysdb_upgrade_01(TALLOC_CTX *mem_ctx, const char *mdn; char *domain; int ret, i, j; + TALLOC_CTX *tmp_ctx; + + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { + ret = ENOMEM; + goto done; + } - basedn = ldb_dn_new(mem_ctx, ldb, SYSDB_BASE); + basedn = ldb_dn_new(tmp_ctx, ldb, SYSDB_BASE); if (!basedn) { ret = EIO; goto done; } - ret = ldb_search(ldb, mem_ctx, &res, + ret = ldb_search(ldb, tmp_ctx, &res, basedn, LDB_SCOPE_SUBTREE, attrs, filter); if (ret != LDB_SUCCESS) { @@ -872,7 +879,7 @@ static int sysdb_upgrade_01(TALLOC_CTX *mem_ctx, } /* create modification message */ - msg = ldb_msg_new(mem_ctx); + msg = ldb_msg_new(tmp_ctx); if (!msg) { ret = ENOMEM; goto done; @@ -893,14 +900,14 @@ static int sysdb_upgrade_01(TALLOC_CTX *mem_ctx, /* get domain name component value */ val = ldb_dn_get_component_val(res->msgs[i]->dn, 2); - domain = talloc_strndup(mem_ctx, (const char *)val->data, val->length); + domain = talloc_strndup(tmp_ctx, (const char *)val->data, val->length); if (!domain) { ret = ENOMEM; goto done; } for (j = 0; j < el->num_values; j++) { - mem_dn = ldb_dn_new_fmt(mem_ctx, ldb, SYSDB_TMPL_USER, + mem_dn = ldb_dn_new_fmt(tmp_ctx, ldb, SYSDB_TMPL_USER, (const char *)el->values[j].data, domain); if (!mem_dn) { ret = ENOMEM; @@ -932,12 +939,12 @@ static int sysdb_upgrade_01(TALLOC_CTX *mem_ctx, } /* conversion done, upgrade version number */ - msg = ldb_msg_new(mem_ctx); + msg = ldb_msg_new(tmp_ctx); if (!msg) { ret = ENOMEM; goto done; } - msg->dn = ldb_dn_new(mem_ctx, ldb, SYSDB_BASE); + msg->dn = ldb_dn_new(tmp_ctx, ldb, SYSDB_BASE); if (!msg->dn) { ret = ENOMEM; goto done; @@ -963,11 +970,12 @@ static int sysdb_upgrade_01(TALLOC_CTX *mem_ctx, ret = EOK; done: - return finish_upgrade(ret, ldb, SYSDB_VERSION_0_2, ver); + ret = finish_upgrade(ret, ldb, SYSDB_VERSION_0_2, ver); + talloc_free(tmp_ctx); + return ret; } -static int sysdb_check_upgrade_02(TALLOC_CTX *mem_ctx, - struct sss_domain_info *domains, +static int sysdb_check_upgrade_02(struct sss_domain_info *domains, const char *db_path) { TALLOC_CTX *tmp_ctx = NULL; @@ -984,12 +992,12 @@ static int sysdb_check_upgrade_02(TALLOC_CTX *mem_ctx, bool ctx_trans = false; int ret; - tmp_ctx = talloc_new(mem_ctx); + tmp_ctx = talloc_new(NULL); if (!tmp_ctx) { return ENOMEM; } - ret = sysdb_get_db_file(mem_ctx, + ret = sysdb_get_db_file(tmp_ctx, "local", "UPGRADE", db_path, &ldb_file); if (ret != EOK) { @@ -1045,7 +1053,7 @@ static int sysdb_check_upgrade_02(TALLOC_CTX *mem_ctx, if (strcmp(version, SYSDB_VERSION_0_1) == 0) { /* convert database */ - ret = sysdb_upgrade_01(tmp_ctx, ldb, &version); + ret = sysdb_upgrade_01(ldb, &version); if (ret != EOK) goto exit; } @@ -1302,7 +1310,7 @@ static int sysdb_upgrade_03(struct sysdb_ctx *sysdb, const char **ver) int ret; struct ldb_message *msg; - tmp_ctx = talloc_new(sysdb); + tmp_ctx = talloc_new(NULL); if (!tmp_ctx) { return ENOMEM; } @@ -1382,7 +1390,7 @@ static int sysdb_upgrade_04(struct sysdb_ctx *sysdb, const char **ver) int ret; struct ldb_message *msg; - tmp_ctx = talloc_new(sysdb); + tmp_ctx = talloc_new(NULL); if (!tmp_ctx) { return ENOMEM; } @@ -1485,7 +1493,7 @@ static int sysdb_upgrade_05(struct sysdb_ctx *sysdb, const char **ver) int ret; struct ldb_message *msg; - tmp_ctx = talloc_new(sysdb); + tmp_ctx = talloc_new(NULL); if (!tmp_ctx) { return ENOMEM; } @@ -1583,7 +1591,7 @@ static int sysdb_upgrade_06(struct sysdb_ctx *sysdb, const char **ver) int ret; struct ldb_message *msg; - tmp_ctx = talloc_new(sysdb); + tmp_ctx = talloc_new(NULL); if (!tmp_ctx) { return ENOMEM; } @@ -1706,7 +1714,7 @@ static int sysdb_domain_init_internal(TALLOC_CTX *mem_ctx, goto done; } - tmp_ctx = talloc_new(sysdb); + tmp_ctx = talloc_new(NULL); if (!tmp_ctx) { ret = ENOMEM; goto done; @@ -1969,8 +1977,7 @@ int sysdb_init(TALLOC_CTX *mem_ctx, if (allow_upgrade) { /* check if we have an old sssd.ldb to upgrade */ - ret = sysdb_check_upgrade_02(ctx_list, domains, - ctx_list->db_path); + ret = sysdb_check_upgrade_02(domains, ctx_list->db_path); if (ret != EOK) { talloc_zfree(ctx_list); return ret; @@ -2130,7 +2137,7 @@ int sysdb_attrs_replace_name(struct sysdb_attrs *attrs, const char *oldname, * attributes. Multi-valued attributes will return * only the first entry */ -errno_t sysdb_attrs_to_list(TALLOC_CTX *memctx, +errno_t sysdb_attrs_to_list(TALLOC_CTX *mem_ctx, struct sysdb_attrs **attrs, int attr_count, const char *attr_name, @@ -2149,7 +2156,7 @@ errno_t sysdb_attrs_to_list(TALLOC_CTX *memctx, * have the attribute, but it will save us the trouble * of continuously resizing the array. */ - list = talloc_array(memctx, char *, attr_count+1); + list = talloc_array(mem_ctx, char *, attr_count+1); if (!list) { return ENOMEM; } @@ -2186,7 +2193,7 @@ errno_t sysdb_attrs_to_list(TALLOC_CTX *memctx, * reclaim unused memory */ if (list_idx < attr_count) { - tmp_list = talloc_realloc(memctx, list, char *, list_idx+1); + tmp_list = talloc_realloc(mem_ctx, list, char *, list_idx+1); if (!tmp_list) { talloc_zfree(list); return ENOMEM; @@ -2207,16 +2214,16 @@ errno_t sysdb_has_enumerated(struct sysdb_ctx *sysdb, struct ldb_result *res; const char *attributes[2] = {SYSDB_HAS_ENUMERATED, NULL}; - TALLOC_CTX *tmpctx; + TALLOC_CTX *tmp_ctx; - tmpctx = talloc_new(NULL); - if (!tmpctx) { + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { ret = ENOMEM; goto done; } - base_dn = ldb_dn_new_fmt(tmpctx, sysdb->ldb, + base_dn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, SYSDB_DOM_BASE, sysdb->domain->name); if (!base_dn) { @@ -2224,7 +2231,7 @@ errno_t sysdb_has_enumerated(struct sysdb_ctx *sysdb, goto done; } - lret = ldb_search(sysdb->ldb, tmpctx, &res, base_dn, + lret = ldb_search(sysdb->ldb, tmp_ctx, &res, base_dn, LDB_SCOPE_BASE, attributes, NULL); if (lret != LDB_SUCCESS) { ret = sysdb_error_to_errno(lret); @@ -2257,7 +2264,7 @@ errno_t sysdb_has_enumerated(struct sysdb_ctx *sysdb, ret = EOK; done: - talloc_free(tmpctx); + talloc_free(tmp_ctx); return ret; } @@ -2349,10 +2356,10 @@ errno_t sysdb_attrs_primary_name(struct sysdb_ctx *sysdb, struct ldb_message_element *sysdb_name_el; struct ldb_message_element *orig_dn_el; size_t i; - TALLOC_CTX *tmpctx = NULL; + TALLOC_CTX *tmp_ctx = NULL; - tmpctx = talloc_new(NULL); - if (!tmpctx) { + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { return ENOMEM; } @@ -2382,7 +2389,7 @@ errno_t sysdb_attrs_primary_name(struct sysdb_ctx *sysdb, ret = EINVAL; goto done; } else if (orig_dn_el->num_values == 1) { - ret = sysdb_get_rdn(sysdb, tmpctx, + ret = sysdb_get_rdn(sysdb, tmp_ctx, (const char *) orig_dn_el->values[0].data, &rdn_attr, &rdn_val); @@ -2438,7 +2445,7 @@ done: DEBUG(1, ("Could not determine primary name: [%d][%s]\n", ret, strerror(ret))); } - talloc_free(tmpctx); + talloc_free(tmp_ctx); return ret; } diff --git a/src/db/sysdb.h b/src/db/sysdb.h index da078ea9..ab6d797d 100644 --- a/src/db/sysdb.h +++ b/src/db/sysdb.h @@ -377,8 +377,7 @@ int sysdb_delete_entry(struct sysdb_ctx *sysdb, bool ignore_not_found); -int sysdb_delete_recursive(TALLOC_CTX *mem_ctx, - struct sysdb_ctx *sysdb, +int sysdb_delete_recursive(struct sysdb_ctx *sysdb, struct ldb_dn *dn, bool ignore_not_found); @@ -426,22 +425,19 @@ int sysdb_search_netgroup_by_name(TALLOC_CTX *mem_ctx, struct ldb_message **msg); /* Replace entry attrs */ -int sysdb_set_entry_attr(TALLOC_CTX *mem_ctx, - struct sysdb_ctx *sysdb, +int sysdb_set_entry_attr(struct sysdb_ctx *sysdb, struct ldb_dn *entry_dn, struct sysdb_attrs *attrs, int mod_op); /* Replace user attrs */ -int sysdb_set_user_attr(TALLOC_CTX *mem_ctx, - struct sysdb_ctx *sysdb, +int sysdb_set_user_attr(struct sysdb_ctx *sysdb, const char *name, struct sysdb_attrs *attrs, int mod_op); /* Replace group attrs */ -int sysdb_set_group_attr(TALLOC_CTX *mem_ctx, - struct sysdb_ctx *sysdb, +int sysdb_set_group_attr(struct sysdb_ctx *sysdb, const char *name, struct sysdb_attrs *attrs, int mod_op); @@ -453,13 +449,11 @@ int sysdb_set_netgroup_attr(struct sysdb_ctx *sysdb, int mod_op); /* Allocate a new id */ -int sysdb_get_new_id(TALLOC_CTX *mem_ctx, - struct sysdb_ctx *sysdb, +int sysdb_get_new_id(struct sysdb_ctx *sysdb, uint32_t *id); /* Add user (only basic attrs and w/o checks) */ -int sysdb_add_basic_user(TALLOC_CTX *mem_ctx, - struct sysdb_ctx *sysdb, +int sysdb_add_basic_user(struct sysdb_ctx *sysdb, const char *name, uid_t uid, gid_t gid, const char *gecos, @@ -467,8 +461,7 @@ int sysdb_add_basic_user(TALLOC_CTX *mem_ctx, const char *shell); /* Add user (all checks) */ -int sysdb_add_user(TALLOC_CTX *mem_ctx, - struct sysdb_ctx *sysdb, +int sysdb_add_user(struct sysdb_ctx *sysdb, const char *name, uid_t uid, gid_t gid, const char *gecos, @@ -482,13 +475,11 @@ int sysdb_add_fake_user(struct sysdb_ctx *sysdb, const char *original_dn); /* Add group (only basic attrs and w/o checks) */ -int sysdb_add_basic_group(TALLOC_CTX *mem_ctx, - struct sysdb_ctx *sysdb, +int sysdb_add_basic_group(struct sysdb_ctx *sysdb, const char *name, gid_t gid); /* Add group (all checks) */ -int sysdb_add_group(TALLOC_CTX *mem_ctx, - struct sysdb_ctx *sysdb, +int sysdb_add_group(struct sysdb_ctx *sysdb, const char *name, gid_t gid, struct sysdb_attrs *attrs, int cache_timeout); @@ -509,14 +500,12 @@ int sysdb_add_netgroup(struct sysdb_ctx *sysdb, int cache_timeout); /* mod_op must be either LDB_FLAG_MOD_ADD or LDB_FLAG_MOD_DELETE */ -int sysdb_mod_group_member(TALLOC_CTX *mem_ctx, - struct sysdb_ctx *sysdb, +int sysdb_mod_group_member(struct sysdb_ctx *sysdb, struct ldb_dn *member_dn, struct ldb_dn *group_dn, int mod_op); -int sysdb_store_user(TALLOC_CTX *mem_ctx, - struct sysdb_ctx *sysdb, +int sysdb_store_user(struct sysdb_ctx *sysdb, const char *name, const char *pwd, uid_t uid, gid_t gid, @@ -527,8 +516,7 @@ int sysdb_store_user(TALLOC_CTX *mem_ctx, char **remove_attrs, uint64_t cache_timeout); -int sysdb_store_group(TALLOC_CTX *mem_ctx, - struct sysdb_ctx *sysdb, +int sysdb_store_group(struct sysdb_ctx *sysdb, const char *name, gid_t gid, struct sysdb_attrs *attrs, @@ -592,18 +580,15 @@ errno_t sysdb_mod_netgroup_member(struct sysdb_ctx *sysdb, * If you are not in a transaction pass NULL in handle and provide sysdb, * in this case a transaction will be automatically started and the * function will be completely wrapped in it's own sysdb transaction */ -int sysdb_cache_password(TALLOC_CTX *mem_ctx, - struct sysdb_ctx *sysdb, +int sysdb_cache_password(struct sysdb_ctx *sysdb, const char *username, const char *password); -errno_t check_failed_login_attempts(TALLOC_CTX *mem_ctx, - struct confdb_ctx *cdb, +errno_t check_failed_login_attempts(struct confdb_ctx *cdb, struct ldb_message *ldb_msg, uint32_t *failed_login_attempts, time_t *delayed_until); -int sysdb_cache_auth(TALLOC_CTX *mem_ctx, - struct sysdb_ctx *sysdb, +int sysdb_cache_auth(struct sysdb_ctx *sysdb, const char *name, const uint8_t *authtok, size_t authtok_size, @@ -612,8 +597,7 @@ int sysdb_cache_auth(TALLOC_CTX *mem_ctx, time_t *_expire_date, time_t *_delayed_until); -int sysdb_store_custom(TALLOC_CTX *mem_ctx, - struct sysdb_ctx *sysdb, +int sysdb_store_custom(struct sysdb_ctx *sysdb, const char *object_name, const char *subtree_name, struct sysdb_attrs *attrs); @@ -634,8 +618,7 @@ int sysdb_search_custom_by_name(TALLOC_CTX *mem_ctx, size_t *_count, struct ldb_message ***_msgs); -int sysdb_delete_custom(TALLOC_CTX *mem_ctx, - struct sysdb_ctx *sysdb, +int sysdb_delete_custom(struct sysdb_ctx *sysdb, const char *object_name, const char *subtree_name); @@ -655,8 +638,7 @@ int sysdb_search_users(TALLOC_CTX *mem_ctx, size_t *msgs_count, struct ldb_message ***msgs); -int sysdb_delete_user(TALLOC_CTX *mem_ctx, - struct sysdb_ctx *sysdb, +int sysdb_delete_user(struct sysdb_ctx *sysdb, const char *name, uid_t uid); int sysdb_search_groups(TALLOC_CTX *mem_ctx, @@ -666,8 +648,7 @@ int sysdb_search_groups(TALLOC_CTX *mem_ctx, size_t *msgs_count, struct ldb_message ***msgs); -int sysdb_delete_group(TALLOC_CTX *mem_ctx, - struct sysdb_ctx *sysdb, +int sysdb_delete_group(struct sysdb_ctx *sysdb, const char *name, gid_t gid); int sysdb_search_netgroups(TALLOC_CTX *mem_ctx, diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c index 37554807..ee58342e 100644 --- a/src/db/sysdb_ops.c +++ b/src/db/sysdb_ops.c @@ -101,8 +101,7 @@ int sysdb_delete_entry(struct sysdb_ctx *sysdb, /* =Remove-Subentries-From-Sysdb=========================================== */ -int sysdb_delete_recursive(TALLOC_CTX *mem_ctx, - struct sysdb_ctx *sysdb, +int sysdb_delete_recursive(struct sysdb_ctx *sysdb, struct ldb_dn *dn, bool ignore_not_found) { @@ -111,14 +110,20 @@ int sysdb_delete_recursive(TALLOC_CTX *mem_ctx, size_t msgs_count; int ret; int i; + TALLOC_CTX *tmp_ctx; + + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { + return ENOMEM; + } ret = ldb_transaction_start(sysdb->ldb); if (ret) { ret = sysdb_error_to_errno(ret); - return ret; + goto done; } - ret = sysdb_search_entry(mem_ctx, sysdb, dn, + ret = sysdb_search_entry(tmp_ctx, sysdb, dn, LDB_SCOPE_SUBTREE, "(distinguishedName=*)", no_attrs, &msgs_count, &msgs); if (ret) { @@ -153,6 +158,7 @@ done: } else { ldb_transaction_cancel(sysdb->ldb); } + talloc_free(tmp_ctx); return ret; } @@ -197,25 +203,25 @@ int sysdb_search_user_by_name(TALLOC_CTX *mem_ctx, const char **attrs, struct ldb_message **msg) { - TALLOC_CTX *tmpctx; + TALLOC_CTX *tmp_ctx; const char *def_attrs[] = { SYSDB_NAME, SYSDB_UIDNUM, NULL }; struct ldb_message **msgs = NULL; struct ldb_dn *basedn; size_t msgs_count = 0; int ret; - tmpctx = talloc_new(mem_ctx); - if (!tmpctx) { + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { return ENOMEM; } - basedn = sysdb_user_dn(sysdb, tmpctx, sysdb->domain->name, name); + basedn = sysdb_user_dn(sysdb, tmp_ctx, sysdb->domain->name, name); if (!basedn) { ret = ENOMEM; goto done; } - ret = sysdb_search_entry(tmpctx, sysdb, basedn, LDB_SCOPE_BASE, NULL, + ret = sysdb_search_entry(tmp_ctx, sysdb, basedn, LDB_SCOPE_BASE, NULL, attrs?attrs:def_attrs, &msgs_count, &msgs); if (ret) { goto done; @@ -227,7 +233,7 @@ done: if (ret) { DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret))); } - talloc_zfree(tmpctx); + talloc_zfree(tmp_ctx); return ret; } @@ -237,7 +243,7 @@ int sysdb_search_user_by_uid(TALLOC_CTX *mem_ctx, const char **attrs, struct ldb_message **msg) { - TALLOC_CTX *tmpctx; + TALLOC_CTX *tmp_ctx; const char *def_attrs[] = { SYSDB_NAME, SYSDB_UIDNUM, NULL }; struct ldb_message **msgs = NULL; struct ldb_dn *basedn; @@ -245,19 +251,19 @@ int sysdb_search_user_by_uid(TALLOC_CTX *mem_ctx, char *filter; int ret; - tmpctx = talloc_new(mem_ctx); - if (!tmpctx) { + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { return ENOMEM; } - basedn = ldb_dn_new_fmt(tmpctx, sysdb->ldb, + basedn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, SYSDB_TMPL_USER_BASE, sysdb->domain->name); if (!basedn) { ret = ENOMEM; goto done; } - filter = talloc_asprintf(tmpctx, SYSDB_PWUID_FILTER, (unsigned long)uid); + filter = talloc_asprintf(tmp_ctx, SYSDB_PWUID_FILTER, (unsigned long)uid); if (!filter) { ret = ENOMEM; goto done; @@ -267,7 +273,7 @@ int sysdb_search_user_by_uid(TALLOC_CTX *mem_ctx, * There is a bug in LDB that makes ONELEVEL searches extremely * slow (it ignores indexing) */ - ret = sysdb_search_entry(tmpctx, sysdb, basedn, LDB_SCOPE_SUBTREE, filter, + ret = sysdb_search_entry(tmp_ctx, sysdb, basedn, LDB_SCOPE_SUBTREE, filter, attrs?attrs:def_attrs, &msgs_count, &msgs); if (ret) { goto done; @@ -280,7 +286,7 @@ done: DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret))); } - talloc_zfree(tmpctx); + talloc_zfree(tmp_ctx); return ret; } @@ -293,25 +299,25 @@ int sysdb_search_group_by_name(TALLOC_CTX *mem_ctx, const char **attrs, struct ldb_message **msg) { - TALLOC_CTX *tmpctx; + TALLOC_CTX *tmp_ctx; static const char *def_attrs[] = { SYSDB_NAME, SYSDB_GIDNUM, NULL }; struct ldb_message **msgs = NULL; struct ldb_dn *basedn; size_t msgs_count = 0; int ret; - tmpctx = talloc_new(mem_ctx); - if (!tmpctx) { + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { return ENOMEM; } - basedn = sysdb_group_dn(sysdb, tmpctx, sysdb->domain->name, name); + basedn = sysdb_group_dn(sysdb, tmp_ctx, sysdb->domain->name, name); if (!basedn) { ret = ENOMEM; goto done; } - ret = sysdb_search_entry(tmpctx, sysdb, basedn, LDB_SCOPE_BASE, NULL, + ret = sysdb_search_entry(tmp_ctx, sysdb, basedn, LDB_SCOPE_BASE, NULL, attrs?attrs:def_attrs, &msgs_count, &msgs); if (ret) { goto done; @@ -323,7 +329,7 @@ done: if (ret) { DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret))); } - talloc_zfree(tmpctx); + talloc_zfree(tmp_ctx); return ret; } @@ -333,7 +339,7 @@ int sysdb_search_group_by_gid(TALLOC_CTX *mem_ctx, const char **attrs, struct ldb_message **msg) { - TALLOC_CTX *tmpctx; + TALLOC_CTX *tmp_ctx; const char *def_attrs[] = { SYSDB_NAME, SYSDB_UIDNUM, NULL }; struct ldb_message **msgs = NULL; struct ldb_dn *basedn; @@ -341,19 +347,19 @@ int sysdb_search_group_by_gid(TALLOC_CTX *mem_ctx, char *filter; int ret; - tmpctx = talloc_new(mem_ctx); - if (!tmpctx) { + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { return ENOMEM; } - basedn = ldb_dn_new_fmt(tmpctx, sysdb->ldb, + basedn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, SYSDB_TMPL_GROUP_BASE, sysdb->domain->name); if (!basedn) { ret = ENOMEM; goto done; } - filter = talloc_asprintf(tmpctx, SYSDB_GRGID_FILTER, (unsigned long)gid); + filter = talloc_asprintf(tmp_ctx, SYSDB_GRGID_FILTER, (unsigned long)gid); if (!filter) { ret = ENOMEM; goto done; @@ -363,7 +369,7 @@ int sysdb_search_group_by_gid(TALLOC_CTX *mem_ctx, * There is a bug in LDB that makes ONELEVEL searches extremely * slow (it ignores indexing) */ - ret = sysdb_search_entry(tmpctx, sysdb, basedn, LDB_SCOPE_SUBTREE, filter, + ret = sysdb_search_entry(tmp_ctx, sysdb, basedn, LDB_SCOPE_SUBTREE, filter, attrs?attrs:def_attrs, &msgs_count, &msgs); if (ret) { goto done; @@ -376,7 +382,7 @@ done: DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret))); } - talloc_zfree(tmpctx); + talloc_zfree(tmp_ctx); return ret; } @@ -389,25 +395,25 @@ int sysdb_search_netgroup_by_name(TALLOC_CTX *mem_ctx, const char **attrs, struct ldb_message **msg) { - TALLOC_CTX *tmpctx; + TALLOC_CTX *tmp_ctx; static const char *def_attrs[] = { SYSDB_NAME, NULL }; struct ldb_message **msgs = NULL; struct ldb_dn *basedn; size_t msgs_count = 0; int ret; - tmpctx = talloc_new(mem_ctx); - if (!tmpctx) { + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { return ENOMEM; } - basedn = sysdb_netgroup_dn(sysdb, tmpctx, sysdb->domain->name, name); + basedn = sysdb_netgroup_dn(sysdb, tmp_ctx, sysdb->domain->name, name); if (!basedn) { ret = ENOMEM; goto done; } - ret = sysdb_search_entry(tmpctx, sysdb, basedn, LDB_SCOPE_BASE, NULL, + ret = sysdb_search_entry(tmp_ctx, sysdb, basedn, LDB_SCOPE_BASE, NULL, attrs?attrs:def_attrs, &msgs_count, &msgs); if (ret) { goto done; @@ -419,26 +425,31 @@ done: if (ret) { DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret))); } - talloc_zfree(tmpctx); + talloc_zfree(tmp_ctx); return ret; } /* =Replace-Attributes-On-Entry=========================================== */ -int sysdb_set_entry_attr(TALLOC_CTX *mem_ctx, - struct sysdb_ctx *sysdb, +int sysdb_set_entry_attr(struct sysdb_ctx *sysdb, struct ldb_dn *entry_dn, struct sysdb_attrs *attrs, int mod_op) { struct ldb_message *msg; int i, ret; + TALLOC_CTX *tmp_ctx; + + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { + return ENOMEM; + } if (!entry_dn || attrs->num == 0) { return EINVAL; } - msg = ldb_msg_new(mem_ctx); + msg = ldb_msg_new(tmp_ctx); if (!msg) { return ENOMEM; } @@ -472,39 +483,49 @@ fail: /* =Replace-Attributes-On-User============================================ */ -int sysdb_set_user_attr(TALLOC_CTX *mem_ctx, - struct sysdb_ctx *sysdb, +int sysdb_set_user_attr(struct sysdb_ctx *sysdb, const char *name, struct sysdb_attrs *attrs, int mod_op) { struct ldb_dn *dn; + TALLOC_CTX *tmp_ctx; + + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { + return ENOMEM; + } - dn = sysdb_user_dn(sysdb, mem_ctx, sysdb->domain->name, name); + dn = sysdb_user_dn(sysdb, tmp_ctx, sysdb->domain->name, name); if (!dn) { return ENOMEM; } - return sysdb_set_entry_attr(mem_ctx, sysdb, dn, attrs, mod_op); + return sysdb_set_entry_attr(sysdb, dn, attrs, mod_op); } /* =Replace-Attributes-On-Group=========================================== */ -int sysdb_set_group_attr(TALLOC_CTX *mem_ctx, - struct sysdb_ctx *sysdb, +int sysdb_set_group_attr(struct sysdb_ctx *sysdb, const char *name, struct sysdb_attrs *attrs, int mod_op) { struct ldb_dn *dn; + TALLOC_CTX *tmp_ctx; + + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { + return ENOMEM; + } - dn = sysdb_group_dn(sysdb, mem_ctx, sysdb->domain->name, name); + dn = sysdb_group_dn(sysdb, tmp_ctx, sysdb->domain->name, name); if (!dn) { return ENOMEM; } - return sysdb_set_entry_attr(mem_ctx, sysdb, dn, attrs, mod_op); + return sysdb_set_entry_attr(sysdb, dn, attrs, mod_op); } /* =Replace-Attributes-On-Netgroup=========================================== */ @@ -529,7 +550,7 @@ int sysdb_set_netgroup_attr(struct sysdb_ctx *sysdb, goto done; } - ret = sysdb_set_entry_attr(tmp_ctx, sysdb, dn, attrs, mod_op); + ret = sysdb_set_entry_attr(sysdb, dn, attrs, mod_op); done: talloc_free(tmp_ctx); @@ -538,11 +559,10 @@ done: /* =Get-New-ID============================================================ */ -int sysdb_get_new_id(TALLOC_CTX *mem_ctx, - struct sysdb_ctx *sysdb, +int sysdb_get_new_id(struct sysdb_ctx *sysdb, uint32_t *_id) { - TALLOC_CTX *tmpctx; + TALLOC_CTX *tmp_ctx; const char *attrs_1[] = { SYSDB_NEXTID, NULL }; const char *attrs_2[] = { SYSDB_UIDNUM, SYSDB_GIDNUM, NULL }; struct ldb_dn *base_dn; @@ -557,25 +577,25 @@ int sysdb_get_new_id(TALLOC_CTX *mem_ctx, struct sss_domain_info *domain = sysdb->domain; - tmpctx = talloc_new(mem_ctx); - if (!tmpctx) { + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { return ENOMEM; } - base_dn = sysdb_domain_dn(sysdb, tmpctx, domain->name); + base_dn = sysdb_domain_dn(sysdb, tmp_ctx, domain->name); if (!base_dn) { - talloc_zfree(tmpctx); + talloc_zfree(tmp_ctx); return ENOMEM; } ret = ldb_transaction_start(sysdb->ldb); if (ret) { - talloc_zfree(tmpctx); + talloc_zfree(tmp_ctx); ret = sysdb_error_to_errno(ret); return ret; } - ret = sysdb_search_entry(tmpctx, sysdb, base_dn, LDB_SCOPE_BASE, + ret = sysdb_search_entry(tmp_ctx, sysdb, base_dn, LDB_SCOPE_BASE, SYSDB_NEXTID_FILTER, attrs_1, &count, &msgs); switch (ret) { case EOK: @@ -612,7 +632,7 @@ int sysdb_get_new_id(TALLOC_CTX *mem_ctx, /* verify the id is actually really free. * search all entries with id >= new_id and < max_id */ if (domain->id_max) { - filter = talloc_asprintf(tmpctx, + filter = talloc_asprintf(tmp_ctx, "(|(&(%s>=%u)(%s<=%u))(&(%s>=%u)(%s<=%u)))", SYSDB_UIDNUM, new_id, SYSDB_UIDNUM, domain->id_max, @@ -620,7 +640,7 @@ int sysdb_get_new_id(TALLOC_CTX *mem_ctx, SYSDB_GIDNUM, domain->id_max); } else { - filter = talloc_asprintf(tmpctx, + filter = talloc_asprintf(tmp_ctx, "(|(%s>=%u)(%s>=%u))", SYSDB_UIDNUM, new_id, SYSDB_GIDNUM, new_id); @@ -631,7 +651,7 @@ int sysdb_get_new_id(TALLOC_CTX *mem_ctx, goto done; } - ret = sysdb_search_entry(tmpctx, sysdb, base_dn, LDB_SCOPE_SUBTREE, + ret = sysdb_search_entry(tmp_ctx, sysdb, base_dn, LDB_SCOPE_SUBTREE, filter, attrs_2, &count, &msgs); switch (ret) { /* if anything was found, find the maximum and increment past it */ @@ -669,7 +689,7 @@ int sysdb_get_new_id(TALLOC_CTX *mem_ctx, count = 0; /* finally store the new next id */ - msg = ldb_msg_new(tmpctx); + msg = ldb_msg_new(tmp_ctx); if (!msg) { DEBUG(6, ("Error: Out of memory\n")); ret = ENOMEM; @@ -698,15 +718,14 @@ done: if (ret) { DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret))); } - talloc_zfree(tmpctx); + talloc_zfree(tmp_ctx); return ret; } /* =Add-Basic-User-NO-CHECKS============================================== */ -int sysdb_add_basic_user(TALLOC_CTX *mem_ctx, - struct sysdb_ctx *sysdb, +int sysdb_add_basic_user(struct sysdb_ctx *sysdb, const char *name, uid_t uid, gid_t gid, const char *gecos, @@ -715,8 +734,14 @@ int sysdb_add_basic_user(TALLOC_CTX *mem_ctx, { struct ldb_message *msg; int ret; + TALLOC_CTX *tmp_ctx; + + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { + return ENOMEM; + } - msg = ldb_msg_new(mem_ctx); + msg = ldb_msg_new(tmp_ctx); if (!msg) { return ENOMEM; } @@ -779,8 +804,7 @@ done: /* =Add-User-Function===================================================== */ -int sysdb_add_user(TALLOC_CTX *mem_ctx, - struct sysdb_ctx *sysdb, +int sysdb_add_user(struct sysdb_ctx *sysdb, const char *name, uid_t uid, gid_t gid, const char *gecos, @@ -789,7 +813,7 @@ int sysdb_add_user(TALLOC_CTX *mem_ctx, struct sysdb_attrs *attrs, int cache_timeout) { - TALLOC_CTX *tmpctx; + TALLOC_CTX *tmp_ctx; struct ldb_message *msg; struct sysdb_attrs *id_attrs; uint32_t id; @@ -820,15 +844,15 @@ int sysdb_add_user(TALLOC_CTX *mem_ctx, return ERANGE; } - tmpctx = talloc_new(mem_ctx); - if (!tmpctx) { + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { return ENOMEM; } ret = ldb_transaction_start(sysdb->ldb); if (ret) { ret = sysdb_error_to_errno(ret); - talloc_free(tmpctx); + talloc_free(tmp_ctx); return ret; } @@ -838,7 +862,7 @@ int sysdb_add_user(TALLOC_CTX *mem_ctx, * Don't worry about users, if we try to add a user with the same * name the operation will fail */ - ret = sysdb_search_group_by_name(tmpctx, sysdb, + ret = sysdb_search_group_by_name(tmp_ctx, sysdb, name, NULL, &msg); if (ret != ENOENT) { if (ret == EOK) ret = EEXIST; @@ -848,7 +872,7 @@ int sysdb_add_user(TALLOC_CTX *mem_ctx, /* check no other user with the same uid exist */ if (uid != 0) { - ret = sysdb_search_user_by_uid(tmpctx, sysdb, + ret = sysdb_search_user_by_uid(tmp_ctx, sysdb, uid, NULL, &msg); if (ret != ENOENT) { if (ret == EOK) ret = EEXIST; @@ -857,16 +881,14 @@ int sysdb_add_user(TALLOC_CTX *mem_ctx, } /* try to add the user */ - ret = sysdb_add_basic_user(tmpctx, sysdb, - name, uid, gid, - gecos, homedir, shell); + ret = sysdb_add_basic_user(sysdb, name, uid, gid, gecos, homedir, shell); if (ret) goto done; if (uid == 0) { - ret = sysdb_get_new_id(tmpctx, sysdb, &id); + ret = sysdb_get_new_id(sysdb, &id); if (ret) goto done; - id_attrs = sysdb_new_attrs(tmpctx); + id_attrs = sysdb_new_attrs(tmp_ctx); if (!id_attrs) { ret = ENOMEM; goto done; @@ -879,13 +901,12 @@ int sysdb_add_user(TALLOC_CTX *mem_ctx, if (ret) goto done; } - ret = sysdb_set_user_attr(tmpctx, sysdb, - name, id_attrs, SYSDB_MOD_REP); + ret = sysdb_set_user_attr(sysdb, name, id_attrs, SYSDB_MOD_REP); goto done; } if (!attrs) { - attrs = sysdb_new_attrs(tmpctx); + attrs = sysdb_new_attrs(tmp_ctx); if (!attrs) { ret = ENOMEM; goto done; @@ -902,8 +923,7 @@ int sysdb_add_user(TALLOC_CTX *mem_ctx, (now + cache_timeout) : 0)); if (ret) goto done; - ret = sysdb_set_user_attr(tmpctx, sysdb, - name, attrs, SYSDB_MOD_REP); + ret = sysdb_set_user_attr(sysdb, name, attrs, SYSDB_MOD_REP); done: if (ret == EOK) { @@ -913,7 +933,7 @@ done: DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret))); ldb_transaction_cancel(sysdb->ldb); } - talloc_zfree(tmpctx); + talloc_zfree(tmp_ctx); return ret; } @@ -921,17 +941,17 @@ int sysdb_add_fake_user(struct sysdb_ctx *sysdb, const char *name, const char *original_dn) { - TALLOC_CTX *tmpctx; + TALLOC_CTX *tmp_ctx; struct ldb_message *msg; time_t now; int ret; - tmpctx = talloc_new(NULL); - if (!tmpctx) { + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { return ENOMEM; } - msg = ldb_msg_new(tmpctx); + msg = ldb_msg_new(tmp_ctx); if (!msg) { ERROR_OUT(ret, ENOMEM, done); } @@ -981,20 +1001,25 @@ done: if (ret != EOK) { DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret))); } - talloc_zfree(tmpctx); + talloc_zfree(tmp_ctx); return ret; } /* =Add-Basic-Group-NO-CHECKS============================================= */ -int sysdb_add_basic_group(TALLOC_CTX *mem_ctx, - struct sysdb_ctx *sysdb, +int sysdb_add_basic_group(struct sysdb_ctx *sysdb, const char *name, gid_t gid) { struct ldb_message *msg; int ret; + TALLOC_CTX *tmp_ctx; + + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { + return ENOMEM; + } - msg = ldb_msg_new(mem_ctx); + msg = ldb_msg_new(tmp_ctx); if (!msg) { return ENOMEM; } @@ -1033,13 +1058,12 @@ done: /* =Add-Group-Function==================================================== */ -int sysdb_add_group(TALLOC_CTX *mem_ctx, - struct sysdb_ctx *sysdb, +int sysdb_add_group(struct sysdb_ctx *sysdb, const char *name, gid_t gid, struct sysdb_attrs *attrs, int cache_timeout) { - TALLOC_CTX *tmpctx; + TALLOC_CTX *tmp_ctx; struct ldb_message *msg; uint32_t id; time_t now; @@ -1055,15 +1079,15 @@ int sysdb_add_group(TALLOC_CTX *mem_ctx, return ERANGE; } - tmpctx = talloc_new(mem_ctx); - if (!tmpctx) { + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { return ENOMEM; } ret = ldb_transaction_start(sysdb->ldb); if (ret) { ret = sysdb_error_to_errno(ret); - talloc_free(tmpctx); + talloc_free(tmp_ctx); return ret; } @@ -1073,7 +1097,7 @@ int sysdb_add_group(TALLOC_CTX *mem_ctx, * Don't worry about users, if we try to add a user with the same * name the operation will fail */ - ret = sysdb_search_user_by_name(tmpctx, sysdb, + ret = sysdb_search_user_by_name(tmp_ctx, sysdb, name, NULL, &msg); if (ret != ENOENT) { if (ret == EOK) ret = EEXIST; @@ -1083,7 +1107,7 @@ int sysdb_add_group(TALLOC_CTX *mem_ctx, /* check no other groups with the same gid exist */ if (gid != 0) { - ret = sysdb_search_group_by_gid(tmpctx, sysdb, + ret = sysdb_search_group_by_gid(tmp_ctx, sysdb, gid, NULL, &msg); if (ret != ENOENT) { if (ret == EOK) ret = EEXIST; @@ -1092,11 +1116,11 @@ int sysdb_add_group(TALLOC_CTX *mem_ctx, } /* try to add the group */ - ret = sysdb_add_basic_group(tmpctx, sysdb, name, gid); + ret = sysdb_add_basic_group(sysdb, name, gid); if (ret) goto done; if (!attrs) { - attrs = sysdb_new_attrs(tmpctx); + attrs = sysdb_new_attrs(tmp_ctx); if (!attrs) { ret = ENOMEM; goto done; @@ -1113,7 +1137,7 @@ int sysdb_add_group(TALLOC_CTX *mem_ctx, } if (posix && gid == 0) { - ret = sysdb_get_new_id(tmpctx, sysdb, &id); + ret = sysdb_get_new_id(sysdb, &id); if (ret) goto done; ret = sysdb_attrs_add_uint32(attrs, SYSDB_GIDNUM, id); @@ -1130,8 +1154,7 @@ int sysdb_add_group(TALLOC_CTX *mem_ctx, (now + cache_timeout) : 0)); if (ret) goto done; - ret = sysdb_set_group_attr(tmpctx, sysdb, - name, attrs, SYSDB_MOD_REP); + ret = sysdb_set_group_attr(sysdb, name, attrs, SYSDB_MOD_REP); done: if (ret == EOK) { @@ -1141,7 +1164,7 @@ done: DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret))); ldb_transaction_cancel(sysdb->ldb); } - talloc_zfree(tmpctx); + talloc_zfree(tmp_ctx); return ret; } @@ -1151,21 +1174,21 @@ int sysdb_add_incomplete_group(struct sysdb_ctx *sysdb, const char *original_dn, bool posix) { - TALLOC_CTX *tmpctx; + TALLOC_CTX *tmp_ctx; time_t now; int ret; struct sysdb_attrs *attrs; - tmpctx = talloc_new(NULL); - if (!tmpctx) { + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { return ENOMEM; } /* try to add the group */ - ret = sysdb_add_basic_group(tmpctx, sysdb, name, gid); + ret = sysdb_add_basic_group(sysdb, name, gid); if (ret) goto done; - attrs = sysdb_new_attrs(tmpctx); + attrs = sysdb_new_attrs(tmp_ctx); if (!attrs) { ret = ENOMEM; goto done; @@ -1188,22 +1211,20 @@ int sysdb_add_incomplete_group(struct sysdb_ctx *sysdb, if (ret) goto done; } - ret = sysdb_set_group_attr(tmpctx, sysdb, - name, attrs, SYSDB_MOD_REP); + ret = sysdb_set_group_attr(sysdb, name, attrs, SYSDB_MOD_REP); done: if (ret != EOK) { DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret))); } - talloc_zfree(tmpctx); + talloc_zfree(tmp_ctx); return ret; } /* =Add-Or-Remove-Group-Memeber=========================================== */ /* mod_op must be either SYSDB_MOD_ADD or SYSDB_MOD_DEL */ -int sysdb_mod_group_member(TALLOC_CTX *mem_ctx, - struct sysdb_ctx *sysdb, +int sysdb_mod_group_member(struct sysdb_ctx *sysdb, struct ldb_dn *member_dn, struct ldb_dn *group_dn, int mod_op) @@ -1212,7 +1233,7 @@ int sysdb_mod_group_member(TALLOC_CTX *mem_ctx, const char *dn; int ret; - msg = ldb_msg_new(mem_ctx); + msg = ldb_msg_new(NULL); if (!msg) { ERROR_OUT(ret, ENOMEM, fail); } @@ -1360,8 +1381,7 @@ done: /* if one of the basic attributes is empty ("") as opposed to NULL, * this will just remove it */ -int sysdb_store_user(TALLOC_CTX *mem_ctx, - struct sysdb_ctx *sysdb, +int sysdb_store_user(struct sysdb_ctx *sysdb, const char *name, const char *pwd, uid_t uid, gid_t gid, @@ -1372,20 +1392,20 @@ int sysdb_store_user(TALLOC_CTX *mem_ctx, char **remove_attrs, uint64_t cache_timeout) { - TALLOC_CTX *tmpctx; + TALLOC_CTX *tmp_ctx; struct ldb_message *msg; time_t now; int ret; errno_t sret = EOK; bool in_transaction = false; - tmpctx = talloc_new(mem_ctx); - if (!tmpctx) { + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { return ENOMEM; } if (!attrs) { - attrs = sysdb_new_attrs(tmpctx); + attrs = sysdb_new_attrs(tmp_ctx); if (!attrs) { ret = ENOMEM; goto done; @@ -1402,7 +1422,7 @@ int sysdb_store_user(TALLOC_CTX *mem_ctx, in_transaction = true; - ret = sysdb_search_user_by_name(tmpctx, sysdb, + ret = sysdb_search_user_by_name(tmp_ctx, sysdb, name, NULL, &msg); if (ret && ret != ENOENT) { goto done; @@ -1410,7 +1430,7 @@ int sysdb_store_user(TALLOC_CTX *mem_ctx, if (ret == ENOENT) { /* users doesn't exist, turn into adding a user */ - ret = sysdb_add_user(tmpctx, sysdb, name, uid, gid, + ret = sysdb_add_user(sysdb, name, uid, gid, gecos, homedir, shell, attrs, cache_timeout); goto done; } @@ -1456,8 +1476,7 @@ int sysdb_store_user(TALLOC_CTX *mem_ctx, (now + cache_timeout) : 0)); if (ret) goto done; - ret = sysdb_set_user_attr(tmpctx, sysdb, - name, attrs, SYSDB_MOD_REP); + ret = sysdb_set_user_attr(sysdb, name, attrs, SYSDB_MOD_REP); if (ret != EOK) goto done; if (remove_attrs) { @@ -1488,7 +1507,7 @@ done: if (ret) { DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret))); } - talloc_zfree(tmpctx); + talloc_zfree(tmp_ctx); return ret; } @@ -1496,14 +1515,13 @@ done: /* this function does not check that all user members are actually present */ -int sysdb_store_group(TALLOC_CTX *mem_ctx, - struct sysdb_ctx *sysdb, +int sysdb_store_group(struct sysdb_ctx *sysdb, const char *name, gid_t gid, struct sysdb_attrs *attrs, uint64_t cache_timeout) { - TALLOC_CTX *tmpctx; + TALLOC_CTX *tmp_ctx; static const char *src_attrs[] = { SYSDB_NAME, SYSDB_GIDNUM, SYSDB_ORIG_MODSTAMP, NULL }; struct ldb_message *msg; @@ -1511,12 +1529,12 @@ int sysdb_store_group(TALLOC_CTX *mem_ctx, time_t now; int ret; - tmpctx = talloc_new(mem_ctx); - if (!tmpctx) { + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { return ENOMEM; } - ret = sysdb_search_group_by_name(tmpctx, sysdb, + ret = sysdb_search_group_by_name(tmp_ctx, sysdb, name, src_attrs, &msg); if (ret && ret != ENOENT) { goto done; @@ -1526,7 +1544,7 @@ int sysdb_store_group(TALLOC_CTX *mem_ctx, } if (!attrs) { - attrs = sysdb_new_attrs(tmpctx); + attrs = sysdb_new_attrs(tmp_ctx); if (!attrs) { ret = ENOMEM; goto done; @@ -1538,8 +1556,7 @@ int sysdb_store_group(TALLOC_CTX *mem_ctx, if (new_group) { /* group doesn't exist, turn into adding a group */ - ret = sysdb_add_group(tmpctx, sysdb, - name, gid, attrs, cache_timeout); + ret = sysdb_add_group(sysdb, name, gid, attrs, cache_timeout); goto done; } @@ -1559,14 +1576,13 @@ int sysdb_store_group(TALLOC_CTX *mem_ctx, (now + cache_timeout) : 0)); if (ret) goto done; - ret = sysdb_set_group_attr(tmpctx, sysdb, - name, attrs, SYSDB_MOD_REP); + ret = sysdb_set_group_attr(sysdb, name, attrs, SYSDB_MOD_REP); done: if (ret) { DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret))); } - talloc_zfree(tmpctx); + talloc_zfree(tmp_ctx); return ret; } @@ -1610,9 +1626,7 @@ int sysdb_add_group_member(struct sysdb_ctx *sysdb, goto done; } - ret = sysdb_mod_group_member(tmp_ctx, sysdb, - member_dn, group_dn, - SYSDB_MOD_ADD); + ret = sysdb_mod_group_member(sysdb, member_dn, group_dn, SYSDB_MOD_ADD); done: talloc_free(tmp_ctx); @@ -1657,9 +1671,7 @@ int sysdb_remove_group_member(struct sysdb_ctx *sysdb, ret = EINVAL; goto done; } - ret = sysdb_mod_group_member(tmp_ctx, sysdb, - member_dn, group_dn, - SYSDB_MOD_DEL); + ret = sysdb_mod_group_member(sysdb, member_dn, group_dn, SYSDB_MOD_DEL); done: talloc_free(tmp_ctx); return ret; @@ -1668,35 +1680,34 @@ done: /* =Password-Caching====================================================== */ -int sysdb_cache_password(TALLOC_CTX *mem_ctx, - struct sysdb_ctx *sysdb, +int sysdb_cache_password(struct sysdb_ctx *sysdb, const char *username, const char *password) { - TALLOC_CTX *tmpctx; + TALLOC_CTX *tmp_ctx; struct sysdb_attrs *attrs; char *hash = NULL; char *salt; int ret; - tmpctx = talloc_new(mem_ctx); - if (!tmpctx) { + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { return ENOMEM; } - ret = s3crypt_gen_salt(tmpctx, &salt); + ret = s3crypt_gen_salt(tmp_ctx, &salt); if (ret) { DEBUG(4, ("Failed to generate random salt.\n")); goto fail; } - ret = s3crypt_sha512(tmpctx, password, salt, &hash); + ret = s3crypt_sha512(tmp_ctx, password, salt, &hash); if (ret) { DEBUG(4, ("Failed to create password hash.\n")); goto fail; } - attrs = sysdb_new_attrs(tmpctx); + attrs = sysdb_new_attrs(tmp_ctx); if (!attrs) { ERROR_OUT(ret, ENOMEM, fail); } @@ -1713,19 +1724,18 @@ int sysdb_cache_password(TALLOC_CTX *mem_ctx, if (ret) goto fail; - ret = sysdb_set_user_attr(tmpctx, sysdb, - username, attrs, SYSDB_MOD_REP); + ret = sysdb_set_user_attr(sysdb, username, attrs, SYSDB_MOD_REP); if (ret) { goto fail; } - talloc_zfree(tmpctx); + talloc_zfree(tmp_ctx); return EOK; fail: if (ret) { DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret))); } - talloc_zfree(tmpctx); + talloc_zfree(tmp_ctx); return ret; } @@ -1771,7 +1781,7 @@ int sysdb_search_custom_by_name(TALLOC_CTX *mem_ctx, size_t *_count, struct ldb_message ***_msgs) { - TALLOC_CTX *tmpctx; + TALLOC_CTX *tmp_ctx; struct ldb_dn *basedn; struct ldb_message **msgs; size_t count; @@ -1781,12 +1791,12 @@ int sysdb_search_custom_by_name(TALLOC_CTX *mem_ctx, return EINVAL; } - tmpctx = talloc_new(mem_ctx); - if (!tmpctx) { + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { return ENOMEM; } - basedn = sysdb_custom_dn(sysdb, tmpctx, + basedn = sysdb_custom_dn(sysdb, tmp_ctx, sysdb->domain->name, object_name, subtree_name); if (basedn == NULL) { DEBUG(1, ("sysdb_custom_dn failed.\n")); @@ -1799,7 +1809,7 @@ int sysdb_search_custom_by_name(TALLOC_CTX *mem_ctx, goto done; } - ret = sysdb_search_entry(tmpctx, sysdb, basedn, + ret = sysdb_search_entry(tmp_ctx, sysdb, basedn, LDB_SCOPE_BASE, NULL, attrs, &count, &msgs); if (ret) { goto done; @@ -1815,20 +1825,19 @@ int sysdb_search_custom_by_name(TALLOC_CTX *mem_ctx, *_msgs = talloc_move(mem_ctx, &msgs); done: - talloc_zfree(tmpctx); + talloc_zfree(tmp_ctx); return ret; } /* =Custom Store (replaces-existing-data)================== */ -int sysdb_store_custom(TALLOC_CTX *mem_ctx, - struct sysdb_ctx *sysdb, +int sysdb_store_custom(struct sysdb_ctx *sysdb, const char *object_name, const char *subtree_name, struct sysdb_attrs *attrs) { - TALLOC_CTX *tmpctx; + TALLOC_CTX *tmp_ctx; const char *search_attrs[] = { "*", NULL }; size_t resp_count = 0; struct ldb_message **resp; @@ -1847,13 +1856,13 @@ int sysdb_store_custom(TALLOC_CTX *mem_ctx, return sysdb_error_to_errno(ret); } - tmpctx = talloc_new(mem_ctx); - if (!tmpctx) { + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { ret = ENOMEM; goto done; } - ret = sysdb_search_custom_by_name(tmpctx, sysdb, + ret = sysdb_search_custom_by_name(tmp_ctx, sysdb, object_name, subtree_name, search_attrs, &resp_count, &resp); if (ret != EOK && ret != ENOENT) { @@ -1864,13 +1873,13 @@ int sysdb_store_custom(TALLOC_CTX *mem_ctx, add_object = true; } - msg = ldb_msg_new(tmpctx); + msg = ldb_msg_new(tmp_ctx); if (msg == NULL) { ret = ENOMEM; goto done; } - msg->dn = sysdb_custom_dn(sysdb, tmpctx, + msg->dn = sysdb_custom_dn(sysdb, tmp_ctx, sysdb->domain->name, object_name, subtree_name); if (!msg->dn) { DEBUG(1, ("sysdb_custom_dn failed.\n")); @@ -1918,18 +1927,17 @@ done: ret = ldb_transaction_commit(sysdb->ldb); ret = sysdb_error_to_errno(ret); } - talloc_zfree(tmpctx); + talloc_zfree(tmp_ctx); return ret; } /* = Custom Delete======================================= */ -int sysdb_delete_custom(TALLOC_CTX *mem_ctx, - struct sysdb_ctx *sysdb, +int sysdb_delete_custom(struct sysdb_ctx *sysdb, const char *object_name, const char *subtree_name) { - TALLOC_CTX *tmpctx; + TALLOC_CTX *tmp_ctx; struct ldb_dn *dn; int ret; @@ -1937,12 +1945,12 @@ int sysdb_delete_custom(TALLOC_CTX *mem_ctx, return EINVAL; } - tmpctx = talloc_new(mem_ctx); - if (!tmpctx) { + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { return ENOMEM; } - dn = sysdb_custom_dn(sysdb, tmpctx, sysdb->domain->name, object_name, subtree_name); + dn = sysdb_custom_dn(sysdb, tmp_ctx, sysdb->domain->name, object_name, subtree_name); if (dn == NULL) { DEBUG(1, ("sysdb_custom_dn failed.\n")); ret = ENOMEM; @@ -1965,7 +1973,7 @@ int sysdb_delete_custom(TALLOC_CTX *mem_ctx, } done: - talloc_zfree(tmpctx); + talloc_zfree(tmp_ctx); return ret; } @@ -1980,19 +1988,19 @@ int sysdb_asq_search(TALLOC_CTX *mem_ctx, size_t *msgs_count, struct ldb_message ***msgs) { - TALLOC_CTX *tmpctx; + TALLOC_CTX *tmp_ctx; struct ldb_request *ldb_req; struct ldb_control **ctrl; struct ldb_asq_control *asq_control; struct ldb_result *res; int ret; - tmpctx = talloc_new(mem_ctx); - if (!tmpctx) { + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { return ENOMEM; } - ctrl = talloc_array(tmpctx, struct ldb_control *, 2); + ctrl = talloc_array(tmp_ctx, struct ldb_control *, 2); if (ctrl == NULL) { ret = ENOMEM; goto fail; @@ -2023,12 +2031,12 @@ int sysdb_asq_search(TALLOC_CTX *mem_ctx, asq_control->src_attr_len = strlen(asq_control->source_attribute); ctrl[0]->data = asq_control; - res = talloc_zero(tmpctx, struct ldb_result); + res = talloc_zero(tmp_ctx, struct ldb_result); if (!res) { return ENOMEM; } - ret = ldb_build_search_req(&ldb_req, sysdb->ldb, tmpctx, + ret = ldb_build_search_req(&ldb_req, sysdb->ldb, tmp_ctx, base_dn, LDB_SCOPE_BASE, expression, attrs, ctrl, res, ldb_search_default_callback, NULL); @@ -2049,12 +2057,12 @@ int sysdb_asq_search(TALLOC_CTX *mem_ctx, *msgs_count = res->count; *msgs = talloc_move(mem_ctx, &res->msgs); - talloc_zfree(tmpctx); + talloc_zfree(tmp_ctx); return EOK; fail: DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret))); - talloc_zfree(tmpctx); + talloc_zfree(tmp_ctx); return ret; } @@ -2067,17 +2075,17 @@ int sysdb_search_users(TALLOC_CTX *mem_ctx, size_t *msgs_count, struct ldb_message ***msgs) { - TALLOC_CTX *tmpctx; + TALLOC_CTX *tmp_ctx; struct ldb_dn *basedn; char *filter; int ret; - tmpctx = talloc_new(mem_ctx); - if (!tmpctx) { + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { return ENOMEM; } - basedn = ldb_dn_new_fmt(tmpctx, sysdb->ldb, + basedn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, SYSDB_TMPL_USER_BASE, sysdb->domain->name); if (!basedn) { DEBUG(2, ("Failed to build base dn\n")); @@ -2085,7 +2093,7 @@ int sysdb_search_users(TALLOC_CTX *mem_ctx, goto fail; } - filter = talloc_asprintf(tmpctx, "(&(%s)%s)", SYSDB_UC, sub_filter); + filter = talloc_asprintf(tmp_ctx, "(&(%s)%s)", SYSDB_UC, sub_filter); if (!filter) { DEBUG(2, ("Failed to build filter\n")); ret = ENOMEM; @@ -2101,35 +2109,34 @@ int sysdb_search_users(TALLOC_CTX *mem_ctx, goto fail; } - talloc_zfree(tmpctx); + talloc_zfree(tmp_ctx); return EOK; fail: DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret))); - talloc_zfree(tmpctx); + talloc_zfree(tmp_ctx); return ret; } /* =Delete-User-by-Name-OR-uid============================================ */ -int sysdb_delete_user(TALLOC_CTX *mem_ctx, - struct sysdb_ctx *sysdb, +int sysdb_delete_user(struct sysdb_ctx *sysdb, const char *name, uid_t uid) { - TALLOC_CTX *tmpctx; + TALLOC_CTX *tmp_ctx; struct ldb_message *msg; int ret; - tmpctx = talloc_new(mem_ctx); - if (!tmpctx) { + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { return ENOMEM; } if (name) { - ret = sysdb_search_user_by_name(tmpctx, sysdb, + ret = sysdb_search_user_by_name(tmp_ctx, sysdb, name, NULL, &msg); } else { - ret = sysdb_search_user_by_uid(tmpctx, sysdb, + ret = sysdb_search_user_by_uid(tmp_ctx, sysdb, uid, NULL, &msg); } if (ret) { @@ -2160,12 +2167,12 @@ int sysdb_delete_user(TALLOC_CTX *mem_ctx, goto fail; } - talloc_zfree(tmpctx); + talloc_zfree(tmp_ctx); return EOK; fail: DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret))); - talloc_zfree(tmpctx); + talloc_zfree(tmp_ctx); return ret; } @@ -2179,17 +2186,17 @@ int sysdb_search_groups(TALLOC_CTX *mem_ctx, size_t *msgs_count, struct ldb_message ***msgs) { - TALLOC_CTX *tmpctx; + TALLOC_CTX *tmp_ctx; struct ldb_dn *basedn; char *filter; int ret; - tmpctx = talloc_new(mem_ctx); - if (!tmpctx) { + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { return ENOMEM; } - basedn = ldb_dn_new_fmt(tmpctx, sysdb->ldb, + basedn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, SYSDB_TMPL_GROUP_BASE, sysdb->domain->name); if (!basedn) { DEBUG(2, ("Failed to build base dn\n")); @@ -2197,7 +2204,7 @@ int sysdb_search_groups(TALLOC_CTX *mem_ctx, goto fail; } - filter = talloc_asprintf(tmpctx, "(&(%s)%s)", SYSDB_GC, sub_filter); + filter = talloc_asprintf(tmp_ctx, "(&(%s)%s)", SYSDB_GC, sub_filter); if (!filter) { DEBUG(2, ("Failed to build filter\n")); ret = ENOMEM; @@ -2213,35 +2220,34 @@ int sysdb_search_groups(TALLOC_CTX *mem_ctx, goto fail; } - talloc_zfree(tmpctx); + talloc_zfree(tmp_ctx); return EOK; fail: DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret))); - talloc_zfree(tmpctx); + talloc_zfree(tmp_ctx); return ret; } /* =Delete-Group-by-Name-OR-gid=========================================== */ -int sysdb_delete_group(TALLOC_CTX *mem_ctx, - struct sysdb_ctx *sysdb, +int sysdb_delete_group(struct sysdb_ctx *sysdb, const char *name, gid_t gid) { - TALLOC_CTX *tmpctx; + TALLOC_CTX *tmp_ctx; struct ldb_message *msg; int ret; - tmpctx = talloc_new(mem_ctx); - if (!tmpctx) { + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { return ENOMEM; } if (name) { - ret = sysdb_search_group_by_name(tmpctx, sysdb, + ret = sysdb_search_group_by_name(tmp_ctx, sysdb, name, NULL, &msg); } else { - ret = sysdb_search_group_by_gid(tmpctx, sysdb, + ret = sysdb_search_group_by_gid(tmp_ctx, sysdb, gid, NULL, &msg); } if (ret) { @@ -2272,12 +2278,12 @@ int sysdb_delete_group(TALLOC_CTX *mem_ctx, goto fail; } - talloc_zfree(tmpctx); + talloc_zfree(tmp_ctx); return EOK; fail: DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret))); - talloc_zfree(tmpctx); + talloc_zfree(tmp_ctx); return ret; } @@ -2290,17 +2296,17 @@ int sysdb_search_netgroups(TALLOC_CTX *mem_ctx, size_t *msgs_count, struct ldb_message ***msgs) { - TALLOC_CTX *tmpctx; + TALLOC_CTX *tmp_ctx; struct ldb_dn *basedn; char *filter; int ret; - tmpctx = talloc_new(mem_ctx); - if (!tmpctx) { + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { return ENOMEM; } - basedn = ldb_dn_new_fmt(tmpctx, sysdb->ldb, + basedn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, SYSDB_TMPL_NETGROUP_BASE, sysdb->domain->name); if (!basedn) { DEBUG(2, ("Failed to build base dn\n")); @@ -2308,7 +2314,7 @@ int sysdb_search_netgroups(TALLOC_CTX *mem_ctx, goto fail; } - filter = talloc_asprintf(tmpctx, "(&(%s)%s)", SYSDB_NC, sub_filter); + filter = talloc_asprintf(tmp_ctx, "(&(%s)%s)", SYSDB_NC, sub_filter); if (!filter) { DEBUG(2, ("Failed to build filter\n")); ret = ENOMEM; @@ -2324,12 +2330,12 @@ int sysdb_search_netgroups(TALLOC_CTX *mem_ctx, goto fail; } - talloc_zfree(tmpctx); + talloc_zfree(tmp_ctx); return EOK; fail: DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret))); - talloc_zfree(tmpctx); + talloc_zfree(tmp_ctx); return ret; } @@ -2376,8 +2382,7 @@ done: /* ========= Authentication against cached password ============ */ -errno_t check_failed_login_attempts(TALLOC_CTX *mem_ctx, - struct confdb_ctx *cdb, +errno_t check_failed_login_attempts(struct confdb_ctx *cdb, struct ldb_message *ldb_msg, uint32_t *failed_login_attempts, time_t *delayed_until) @@ -2387,13 +2392,19 @@ errno_t check_failed_login_attempts(TALLOC_CTX *mem_ctx, int failed_login_delay; time_t last_failed_login; time_t end; + TALLOC_CTX *tmp_ctx; + + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { + return ENOMEM; + } *delayed_until = -1; *failed_login_attempts = ldb_msg_find_attr_as_uint(ldb_msg, SYSDB_FAILED_LOGIN_ATTEMPTS, 0); last_failed_login = (time_t) ldb_msg_find_attr_as_int64(ldb_msg, SYSDB_LAST_FAILED_LOGIN, 0); - ret = confdb_get_int(cdb, mem_ctx, CONFDB_PAM_CONF_ENTRY, + ret = confdb_get_int(cdb, tmp_ctx, CONFDB_PAM_CONF_ENTRY, CONFDB_PAM_FAILED_LOGIN_ATTEMPTS, CONFDB_DEFAULT_PAM_FAILED_LOGIN_ATTEMPTS, &allowed_failed_login_attempts); @@ -2402,7 +2413,7 @@ errno_t check_failed_login_attempts(TALLOC_CTX *mem_ctx, "attempts.\n")); return EIO; } - ret = confdb_get_int(cdb, mem_ctx, CONFDB_PAM_CONF_ENTRY, + ret = confdb_get_int(cdb, tmp_ctx, CONFDB_PAM_CONF_ENTRY, CONFDB_PAM_FAILED_LOGIN_DELAY, CONFDB_DEFAULT_PAM_FAILED_LOGIN_DELAY, &failed_login_delay); @@ -2437,8 +2448,7 @@ errno_t check_failed_login_attempts(TALLOC_CTX *mem_ctx, return EOK; } -int sysdb_cache_auth(TALLOC_CTX *mem_ctx, - struct sysdb_ctx *sysdb, +int sysdb_cache_auth(struct sysdb_ctx *sysdb, const char *name, const uint8_t *authtok, size_t authtok_size, @@ -2447,7 +2457,7 @@ int sysdb_cache_auth(TALLOC_CTX *mem_ctx, time_t *_expire_date, time_t *_delayed_until) { - TALLOC_CTX *tmpctx; + TALLOC_CTX *tmp_ctx; const char *attrs[] = { SYSDB_NAME, SYSDB_CACHEDPWD, SYSDB_DISABLED, SYSDB_LAST_LOGIN, SYSDB_LAST_ONLINE_AUTH, "lastCachedPasswordChange", @@ -2487,19 +2497,19 @@ int sysdb_cache_auth(TALLOC_CTX *mem_ctx, return EINVAL; } - tmpctx = talloc_new(mem_ctx); - if (!tmpctx) { + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { return ENOMEM; } ret = ldb_transaction_start(sysdb->ldb); if (ret) { - talloc_zfree(tmpctx); + talloc_zfree(tmp_ctx); ret = sysdb_error_to_errno(ret); return ret; } - ret = sysdb_search_user_by_name(tmpctx, sysdb, + ret = sysdb_search_user_by_name(tmp_ctx, sysdb, name, attrs, &ldb_msg); if (ret != EOK) { DEBUG(1, ("sysdb_search_user_by_name failed [%d][%s].\n", @@ -2512,7 +2522,7 @@ int sysdb_cache_auth(TALLOC_CTX *mem_ctx, SYSDB_LAST_ONLINE_AUTH, 0); - ret = confdb_get_int(cdb, tmpctx, CONFDB_PAM_CONF_ENTRY, + ret = confdb_get_int(cdb, tmp_ctx, CONFDB_PAM_CONF_ENTRY, CONFDB_PAM_CRED_TIMEOUT, 0, &cred_expiration); if (ret != EOK) { DEBUG(1, ("Failed to read expiration time of offline credentials.\n")); @@ -2533,8 +2543,7 @@ int sysdb_cache_auth(TALLOC_CTX *mem_ctx, expire_date = 0; } - ret = check_failed_login_attempts(tmpctx, cdb, ldb_msg, - &failed_login_attempts, + ret = check_failed_login_attempts(cdb, ldb_msg, &failed_login_attempts, &delayed_until); if (ret != EOK) { DEBUG(1, ("Failed to check login attempts\n")); @@ -2543,7 +2552,7 @@ int sysdb_cache_auth(TALLOC_CTX *mem_ctx, /* TODO: verify user account (disabled, expired ...) */ - password = talloc_strndup(tmpctx, (const char *)authtok, authtok_size); + password = talloc_strndup(tmp_ctx, (const char *)authtok, authtok_size); if (password == NULL) { DEBUG(1, ("talloc_strndup failed.\n")); ret = ENOMEM; @@ -2557,14 +2566,14 @@ int sysdb_cache_auth(TALLOC_CTX *mem_ctx, goto done; } - ret = s3crypt_sha512(tmpctx, password, userhash, &comphash); + ret = s3crypt_sha512(tmp_ctx, password, userhash, &comphash); if (ret) { DEBUG(4, ("Failed to create password hash.\n")); ret = EFAULT; goto done; } - update_attrs = sysdb_new_attrs(tmpctx); + update_attrs = sysdb_new_attrs(tmp_ctx); if (update_attrs == NULL) { DEBUG(1, ("sysdb_new_attrs failed.\n")); ret = ENOMEM; @@ -2621,9 +2630,7 @@ int sysdb_cache_auth(TALLOC_CTX *mem_ctx, } } - ret = sysdb_set_user_attr(tmpctx, sysdb, - name, update_attrs, - LDB_FLAG_MOD_REPLACE); + ret = sysdb_set_user_attr(sysdb, name, update_attrs, LDB_FLAG_MOD_REPLACE); if (ret) { DEBUG(1, ("Failed to update Login attempt information!\n")); } diff --git a/src/db/sysdb_search.c b/src/db/sysdb_search.c index 85ef8aef..8f382520 100644 --- a/src/db/sysdb_search.c +++ b/src/db/sysdb_search.c @@ -39,7 +39,7 @@ int sysdb_getpwnam(TALLOC_CTX *mem_ctx, char *sanitized_name; int ret; - tmpctx = talloc_new(mem_ctx); + tmpctx = talloc_new(NULL); if (!tmpctx) { return ENOMEM; } @@ -83,7 +83,7 @@ int sysdb_getpwuid(TALLOC_CTX *mem_ctx, struct ldb_result *res; int ret; - tmpctx = talloc_new(mem_ctx); + tmpctx = talloc_new(NULL); if (!tmpctx) { return ENOMEM; } @@ -119,7 +119,7 @@ int sysdb_enumpwent(TALLOC_CTX *mem_ctx, struct ldb_result *res; int ret; - tmpctx = talloc_new(mem_ctx); + tmpctx = talloc_new(NULL); if (!tmpctx) { return ENOMEM; } @@ -202,7 +202,7 @@ int sysdb_getgrnam(TALLOC_CTX *mem_ctx, struct ldb_result *res; int ret; - tmpctx = talloc_new(mem_ctx); + tmpctx = talloc_new(NULL); if (!tmpctx) { return ENOMEM; } @@ -259,7 +259,7 @@ int sysdb_getgrgid(TALLOC_CTX *mem_ctx, struct ldb_result *res; int ret; - tmpctx = talloc_new(mem_ctx); + tmpctx = talloc_new(NULL); if (!tmpctx) { return ENOMEM; } @@ -308,7 +308,7 @@ int sysdb_enumgrent(TALLOC_CTX *mem_ctx, struct ldb_result *res; int ret; - tmpctx = talloc_new(mem_ctx); + tmpctx = talloc_new(NULL); if (!tmpctx) { return ENOMEM; } @@ -360,7 +360,7 @@ int sysdb_initgroups(TALLOC_CTX *mem_ctx, static const char *attrs[] = SYSDB_INITGR_ATTRS; int ret; - tmpctx = talloc_new(mem_ctx); + tmpctx = talloc_new(NULL); if (!tmpctx) { return ENOMEM; } @@ -457,7 +457,7 @@ int sysdb_get_user_attr(TALLOC_CTX *mem_ctx, char *sanitized_name; int ret; - tmpctx = talloc_new(mem_ctx); + tmpctx = talloc_new(NULL); if (!tmpctx) { return ENOMEM; } @@ -811,7 +811,7 @@ int sysdb_get_netgroup_attr(TALLOC_CTX *mem_ctx, char *sanitized_netgroup; int ret; - tmpctx = talloc_new(mem_ctx); + tmpctx = talloc_new(NULL); if (!tmpctx) { return ENOMEM; } diff --git a/src/providers/ipa/ipa_access.c b/src/providers/ipa/ipa_access.c index 74136d31..a74d6a97 100644 --- a/src/providers/ipa/ipa_access.c +++ b/src/providers/ipa/ipa_access.c @@ -454,7 +454,7 @@ static void hbac_sysdb_save(struct tevent_req *req) return; } - ret = sysdb_delete_recursive(tmp_ctx, sysdb, base_dn, true); + ret = sysdb_delete_recursive(sysdb, base_dn, true); talloc_free(tmp_ctx); if (ret != EOK) { DEBUG(1, ("sysdb_delete_recursive failed.\n")); diff --git a/src/providers/ipa/ipa_hbac_common.c b/src/providers/ipa/ipa_hbac_common.c index 36c67e49..08cb0254 100644 --- a/src/providers/ipa/ipa_hbac_common.c +++ b/src/providers/ipa/ipa_hbac_common.c @@ -50,7 +50,7 @@ ipa_hbac_save_list(struct sysdb_ctx *sysdb, bool delete_subdir, goto done; } - ret = sysdb_delete_recursive(tmp_ctx, sysdb, base_dn, true); + ret = sysdb_delete_recursive(sysdb, base_dn, true); if (ret != EOK) { DEBUG(1, ("sysdb_delete_recursive failed.\n")); goto done; @@ -77,7 +77,7 @@ ipa_hbac_save_list(struct sysdb_ctx *sysdb, bool delete_subdir, } DEBUG(9, ("Object name: [%s].\n", object_name)); - ret = sysdb_store_custom(tmp_ctx, sysdb, object_name, subdir, list[c]); + ret = sysdb_store_custom(sysdb, object_name, subdir, list[c]); if (ret != EOK) { DEBUG(1, ("sysdb_store_custom failed.\n")); goto done; diff --git a/src/providers/krb5/krb5_auth.c b/src/providers/krb5/krb5_auth.c index c8dc8652..d7406860 100644 --- a/src/providers/krb5/krb5_auth.c +++ b/src/providers/krb5/krb5_auth.c @@ -193,7 +193,7 @@ static int krb5_mod_ccname(TALLOC_CTX *mem_ctx, goto done; } - ret = sysdb_set_user_attr(tmpctx, sysdb, name, attrs, mod_op); + ret = sysdb_set_user_attr(sysdb, name, attrs, mod_op); if (ret != EOK) { DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret))); sysdb_transaction_cancel(sysdb); @@ -1083,8 +1083,7 @@ static void krb5_save_ccname_done(struct tevent_req *req) talloc_set_destructor((TALLOC_CTX *)password, password_destructor); - ret = sysdb_cache_password(state, state->be_ctx->sysdb, pd->user, - password); + ret = sysdb_cache_password(state->be_ctx->sysdb, pd->user, password); if (ret) { DEBUG(2, ("Failed to cache password, offline auth may not work." " (%d)[%s]!?\n", ret, strerror(ret))); @@ -1112,7 +1111,7 @@ static void krb5_pam_handler_cache_auth_step(struct tevent_req *req) struct krb5_ctx *krb5_ctx = state->kr->krb5_ctx; int ret; - ret = sysdb_cache_auth(state, state->be_ctx->sysdb, pd->user, pd->authtok, + ret = sysdb_cache_auth(state->be_ctx->sysdb, pd->user, pd->authtok, pd->authtok_size, state->be_ctx->cdb, true, NULL, NULL); if (ret != EOK) { diff --git a/src/providers/ldap/ldap_auth.c b/src/providers/ldap/ldap_auth.c index efc9f527..ad4549e7 100644 --- a/src/providers/ldap/ldap_auth.c +++ b/src/providers/ldap/ldap_auth.c @@ -1098,8 +1098,7 @@ static void sdap_pam_auth_done(struct tevent_req *req) } talloc_set_destructor((TALLOC_CTX *)password, password_destructor); - ret = sysdb_cache_password(state, - state->breq->be_ctx->sysdb, + ret = sysdb_cache_password(state->breq->be_ctx->sysdb, state->username, password); /* password caching failures are not fatal errors */ diff --git a/src/providers/ldap/ldap_id.c b/src/providers/ldap/ldap_id.c index 9525224b..2d8aefff 100644 --- a/src/providers/ldap/ldap_id.c +++ b/src/providers/ldap/ldap_id.c @@ -227,7 +227,7 @@ static void users_get_done(struct tevent_req *subreq) tevent_req_error(req, ret); return; case BE_FILTER_NAME: - ret = sysdb_delete_user(state, state->sysdb, state->name, 0); + ret = sysdb_delete_user(state->sysdb, state->name, 0); if (ret != EOK && ret != ENOENT) { tevent_req_error(req, ret); return; @@ -241,7 +241,7 @@ static void users_get_done(struct tevent_req *subreq) return; } - ret = sysdb_delete_user(state, state->sysdb, NULL, uid); + ret = sysdb_delete_user(state->sysdb, NULL, uid); if (ret != EOK && ret != ENOENT) { tevent_req_error(req, ret); return; @@ -470,7 +470,7 @@ static void groups_get_done(struct tevent_req *subreq) tevent_req_error(req, ret); return; case BE_FILTER_NAME: - ret = sysdb_delete_group(state, state->sysdb, state->name, 0); + ret = sysdb_delete_group(state->sysdb, state->name, 0); if (ret != EOK && ret != ENOENT) { tevent_req_error(req, ret); return; @@ -484,7 +484,7 @@ static void groups_get_done(struct tevent_req *subreq) return; } - ret = sysdb_delete_group(state, state->sysdb, NULL, gid); + ret = sysdb_delete_group(state->sysdb, NULL, gid); if (ret != EOK && ret != ENOENT) { tevent_req_error(req, ret); return; @@ -652,9 +652,7 @@ static void groups_by_user_done(struct tevent_req *subreq) } if (ret == ENOENT) { - ret = sysdb_delete_user(state, - state->ctx->be->sysdb, - state->name, 0); + ret = sysdb_delete_user(state->ctx->be->sysdb, state->name, 0); if (ret != EOK && ret != ENOENT) { tevent_req_error(req, ret); return; diff --git a/src/providers/ldap/ldap_id_cleanup.c b/src/providers/ldap/ldap_id_cleanup.c index fc659271..9c50ee48 100644 --- a/src/providers/ldap/ldap_id_cleanup.c +++ b/src/providers/ldap/ldap_id_cleanup.c @@ -336,7 +336,7 @@ static int cleanup_users(TALLOC_CTX *memctx, struct sdap_id_ctx *ctx) /* If not logged in or cannot check the table, delete him */ DEBUG(9, ("About to delete user %s\n", name)); - ret = sysdb_delete_user(tmpctx, sysdb, name, 0); + ret = sysdb_delete_user(sysdb, name, 0); if (ret) { goto done; } @@ -465,7 +465,7 @@ static int cleanup_groups(TALLOC_CTX *memctx, } DEBUG(8, ("About to delete group %s\n", name)); - ret = sysdb_delete_group(tmpctx, sysdb, name, 0); + ret = sysdb_delete_group(sysdb, name, 0); if (ret) { DEBUG(2, ("Group delete returned %d (%s)\n", ret, strerror(ret))); diff --git a/src/providers/ldap/sdap_access.c b/src/providers/ldap/sdap_access.c index 0ac0f639..9f10a146 100644 --- a/src/providers/ldap/sdap_access.c +++ b/src/providers/ldap/sdap_access.c @@ -1058,8 +1058,7 @@ static void sdap_access_filter_get_access_done(struct tevent_req *subreq) goto done; } - ret = sysdb_set_user_attr(attrs, - state->be_ctx->sysdb, + ret = sysdb_set_user_attr(state->be_ctx->sysdb, state->username, attrs, SYSDB_MOD_REP); if (ret != EOK) { diff --git a/src/providers/ldap/sdap_async_accounts.c b/src/providers/ldap/sdap_async_accounts.c index a6907a34..47653245 100644 --- a/src/providers/ldap/sdap_async_accounts.c +++ b/src/providers/ldap/sdap_async_accounts.c @@ -298,8 +298,7 @@ static int sdap_save_user(TALLOC_CTX *memctx, DEBUG(6, ("Storing info for user %s\n", name)); - ret = sysdb_store_user(user_attrs, ctx, - name, pwd, uid, gid, gecos, homedir, shell, + ret = sysdb_store_user(ctx, name, pwd, uid, gid, gecos, homedir, shell, user_attrs, missing, cache_timeout); if (ret) goto fail; @@ -664,8 +663,7 @@ done: /* FIXME: support storing additional attributes */ static errno_t -sdap_store_group_with_gid(TALLOC_CTX *mem_ctx, - struct sysdb_ctx *ctx, +sdap_store_group_with_gid(struct sysdb_ctx *ctx, const char *name, gid_t gid, struct sysdb_attrs *group_attrs, @@ -684,9 +682,7 @@ sdap_store_group_with_gid(TALLOC_CTX *mem_ctx, } } - ret = sysdb_store_group(mem_ctx, ctx, - name, gid, group_attrs, - cache_timeout); + ret = sysdb_store_group(ctx, name, gid, group_attrs, cache_timeout); if (ret) { DEBUG(2, ("Could not store group %s\n", name)); return ret; @@ -856,8 +852,7 @@ static int sdap_save_group(TALLOC_CTX *memctx, DEBUG(6, ("Storing info for group %s\n", name)); - ret = sdap_store_group_with_gid(group_attrs, ctx, - name, gid, group_attrs, + ret = sdap_store_group_with_gid(ctx, name, gid, group_attrs, dp_opt_get_int(opts->basic, SDAP_ENTRY_CACHE_TIMEOUT), posix_group); @@ -928,7 +923,7 @@ static int sdap_save_grpmem(TALLOC_CTX *memctx, DEBUG(6, ("Storing members for group %s\n", name)); - ret = sysdb_store_group(memctx, ctx, name, 0, group_attrs, + ret = sysdb_store_group(ctx, name, 0, group_attrs, dp_opt_get_int(opts->basic, SDAP_ENTRY_CACHE_TIMEOUT)); if (ret) goto fail; @@ -2052,8 +2047,7 @@ static errno_t sdap_nested_group_populate_users(struct sysdb_ctx *sysdb, ret = sysdb_attrs_add_string(attrs, SYSDB_NAME, username); if (ret) goto done; - ret = sysdb_set_user_attr(tmp_ctx, sysdb, - sysdb_name, attrs, SYSDB_MOD_REP); + ret = sysdb_set_user_attr(sysdb, sysdb_name, attrs, SYSDB_MOD_REP); if (ret != EOK) goto done; } diff --git a/src/providers/proxy/proxy_auth.c b/src/providers/proxy/proxy_auth.c index 57eb483c..f92c6471 100644 --- a/src/providers/proxy/proxy_auth.c +++ b/src/providers/proxy/proxy_auth.c @@ -759,8 +759,7 @@ static void proxy_child_done(struct tevent_req *req) } talloc_set_destructor((TALLOC_CTX *)password, password_destructor); - ret = sysdb_cache_password(client_ctx, - client_ctx->be_req->be_ctx->sysdb, + ret = sysdb_cache_password(client_ctx->be_req->be_ctx->sysdb, pd->user, password); /* password caching failures are not fatal errors */ diff --git a/src/providers/proxy/proxy_id.c b/src/providers/proxy/proxy_id.c index b4dcac7c..041e25f2 100644 --- a/src/providers/proxy/proxy_id.c +++ b/src/providers/proxy/proxy_id.c @@ -97,7 +97,7 @@ static int get_pw_name(TALLOC_CTX *mem_ctx, break; } - ret = sysdb_store_user(tmpctx, sysdb, + ret = sysdb_store_user(sysdb, pwd->pw_name, pwd->pw_passwd, pwd->pw_uid, @@ -212,7 +212,7 @@ static int get_pw_uid(TALLOC_CTX *mem_ctx, break; } - ret = sysdb_store_user(tmpctx, sysdb, + ret = sysdb_store_user(sysdb, pwd->pw_name, pwd->pw_passwd, pwd->pw_uid, @@ -241,7 +241,7 @@ static int get_pw_uid(TALLOC_CTX *mem_ctx, DEBUG(7, ("User %d does not exist (or is invalid) on remote server," " deleting!\n", uid)); - ret = sysdb_delete_user(tmpctx, sysdb, NULL, uid); + ret = sysdb_delete_user(sysdb, NULL, uid); if (ret) { goto done; } @@ -352,7 +352,7 @@ again: goto again; /* skip */ } - ret = sysdb_store_user(tmpctx, sysdb, + ret = sysdb_store_user(sysdb, pwd->pw_name, pwd->pw_passwd, pwd->pw_uid, @@ -515,7 +515,7 @@ again: members = NULL; } - ret = sysdb_store_group(tmpctx, sysdb, + ret = sysdb_store_group(sysdb, grp->gr_name, grp->gr_gid, members, @@ -666,7 +666,7 @@ again: members = NULL; } - ret = sysdb_store_group(tmpctx, sysdb, + ret = sysdb_store_group(sysdb, grp->gr_name, grp->gr_gid, members, @@ -691,7 +691,7 @@ again: DEBUG(7, ("Group %d does not exist (or is invalid) on remote server," " deleting!\n", gid)); - ret = sysdb_delete_group(tmpctx, sysdb, NULL, gid); + ret = sysdb_delete_group(sysdb, NULL, gid); if (ret) { goto done; } @@ -821,7 +821,7 @@ again: members = NULL; } - ret = sysdb_store_group(tmpctx, sysdb, + ret = sysdb_store_group(sysdb, grp->gr_name, grp->gr_gid, members, @@ -928,7 +928,7 @@ static int get_initgr(TALLOC_CTX *mem_ctx, break; } - ret = sysdb_store_user(tmpctx, sysdb, + ret = sysdb_store_user(sysdb, pwd->pw_name, pwd->pw_passwd, pwd->pw_uid, diff --git a/src/responder/pam/pam_LOCAL_domain.c b/src/responder/pam/pam_LOCAL_domain.c index d636fd33..66f3a885 100644 --- a/src/responder/pam/pam_LOCAL_domain.c +++ b/src/responder/pam/pam_LOCAL_domain.c @@ -86,8 +86,7 @@ static void do_successful_login(struct LOCAL_request *lreq) NEQ_CHECK_OR_JUMP(ret, EOK, ("sysdb_attrs_add_long failed.\n"), lreq->error, ret, done); - ret = sysdb_set_user_attr(lreq, lreq->dbctx, - lreq->preq->pd->user, + ret = sysdb_set_user_attr(lreq->dbctx, lreq->preq->pd->user, lreq->mod_attrs, SYSDB_MOD_REP); NEQ_CHECK_OR_JUMP(ret, EOK, ("sysdb_set_user_attr failed.\n"), lreq->error, ret, done); @@ -127,8 +126,7 @@ static void do_failed_login(struct LOCAL_request *lreq) NEQ_CHECK_OR_JUMP(ret, EOK, ("sysdb_attrs_add_long failed.\n"), lreq->error, ret, done); - ret = sysdb_set_user_attr(lreq, lreq->dbctx, - lreq->preq->pd->user, + ret = sysdb_set_user_attr(lreq->dbctx, lreq->preq->pd->user, lreq->mod_attrs, SYSDB_MOD_REP); NEQ_CHECK_OR_JUMP(ret, EOK, ("sysdb_set_user_attr failed.\n"), lreq->error, ret, done); @@ -200,8 +198,7 @@ static void do_pam_chauthtok(struct LOCAL_request *lreq) NEQ_CHECK_OR_JUMP(ret, EOK, ("sysdb_attrs_add_long failed.\n"), lreq->error, ret, done); - ret = sysdb_set_user_attr(lreq, lreq->dbctx, - lreq->preq->pd->user, + ret = sysdb_set_user_attr(lreq->dbctx, lreq->preq->pd->user, lreq->mod_attrs, SYSDB_MOD_REP); NEQ_CHECK_OR_JUMP(ret, EOK, ("sysdb_set_user_attr failed.\n"), lreq->error, ret, done); diff --git a/src/responder/pam/pamsrv_cmd.c b/src/responder/pam/pamsrv_cmd.c index 48228e97..1d2a2a58 100644 --- a/src/responder/pam/pamsrv_cmd.c +++ b/src/responder/pam/pamsrv_cmd.c @@ -310,8 +310,7 @@ static errno_t set_last_login(struct pam_auth_req *preq) goto fail; } - ret = sysdb_set_user_attr(preq, dbctx, preq->pd->user, attrs, - SYSDB_MOD_REP); + ret = sysdb_set_user_attr(dbctx, preq->pd->user, attrs, SYSDB_MOD_REP); if (ret != EOK) { DEBUG(2, ("set_last_login failed.\n")); preq->pd->pam_status = PAM_SYSTEM_ERR; @@ -484,7 +483,7 @@ static void pam_reply(struct pam_auth_req *preq) goto done; } - ret = sysdb_cache_auth(preq, sysdb, pd->user, + ret = sysdb_cache_auth(sysdb, pd->user, pd->authtok, pd->authtok_size, pctx->rctx->cdb, false, &exp_date, &delay_until); diff --git a/src/tests/auth-tests.c b/src/tests/auth-tests.c index abdc874a..02646627 100644 --- a/src/tests/auth-tests.c +++ b/src/tests/auth-tests.c @@ -195,7 +195,7 @@ static void do_failed_login_test(uint32_t failed_login_attempts, (long long) last_failed_login); fail_unless(ret == EOK, "ldb_msg_add_string failed"); - ret = check_failed_login_attempts(test_ctx, test_ctx->confdb, ldb_msg, + ret = check_failed_login_attempts(test_ctx->confdb, ldb_msg, &returned_failed_login_attempts, &delayed_until); fail_unless(ret == expected_result, diff --git a/src/tests/sysdb-tests.c b/src/tests/sysdb-tests.c index 57edeece..4c2021cf 100644 --- a/src/tests/sysdb-tests.c +++ b/src/tests/sysdb-tests.c @@ -190,7 +190,7 @@ static int test_add_user(struct test_data *data) homedir = talloc_asprintf(data, "/home/testuser%d", data->uid); gecos = talloc_asprintf(data, "Test User %d", data->uid); - ret = sysdb_add_user(data, data->ctx->sysdb, data->username, + ret = sysdb_add_user(data->ctx->sysdb, data->username, data->uid, 0, gecos, homedir, "/bin/bash", NULL, 0); return ret; @@ -205,7 +205,7 @@ static int test_store_user(struct test_data *data) homedir = talloc_asprintf(data, "/home/testuser%d", data->uid); gecos = talloc_asprintf(data, "Test User %d", data->uid); - ret = sysdb_store_user(data, data->ctx->sysdb, data->username, "x", + ret = sysdb_store_user(data->ctx->sysdb, data->username, "x", data->uid, 0, gecos, homedir, data->shell ? data->shell : "/bin/bash", NULL, NULL, -1); @@ -228,7 +228,7 @@ static int test_remove_user_by_uid(struct test_data *data) { int ret; - ret = sysdb_delete_user(data, data->ctx->sysdb, NULL, data->uid); + ret = sysdb_delete_user(data->ctx->sysdb, NULL, data->uid); return ret; } @@ -236,7 +236,7 @@ static int test_remove_nonexistent_group(struct test_data *data) { int ret; - ret = sysdb_delete_group(data, data->ctx->sysdb, NULL, data->uid); + ret = sysdb_delete_group(data->ctx->sysdb, NULL, data->uid); return ret; } @@ -244,7 +244,7 @@ static int test_remove_nonexistent_user(struct test_data *data) { int ret; - ret = sysdb_delete_user(data, data->ctx->sysdb, NULL, data->uid); + ret = sysdb_delete_user(data->ctx->sysdb, NULL, data->uid); return ret; } @@ -252,7 +252,7 @@ static int test_add_group(struct test_data *data) { int ret; - ret = sysdb_add_group(data, data->ctx->sysdb, data->groupname, + ret = sysdb_add_group(data->ctx->sysdb, data->groupname, data->gid, NULL, 0); return ret; } @@ -270,7 +270,7 @@ static int test_store_group(struct test_data *data) { int ret; - ret = sysdb_store_group(data, data->ctx->sysdb, data->groupname, + ret = sysdb_store_group(data->ctx->sysdb, data->groupname, data->gid, NULL, -1); return ret; } @@ -291,7 +291,7 @@ static int test_remove_group_by_gid(struct test_data *data) { int ret; - ret = sysdb_delete_group(data, data->ctx->sysdb, NULL, data->gid); + ret = sysdb_delete_group(data->ctx->sysdb, NULL, data->gid); if (ret == ENOENT) { ret = EOK; } @@ -302,7 +302,7 @@ static int test_set_user_attr(struct test_data *data) { int ret; - ret = sysdb_set_user_attr(data, data->ctx->sysdb, data->username, + ret = sysdb_set_user_attr(data->ctx->sysdb, data->username, data->attrs, SYSDB_MOD_REP); return ret; } @@ -349,7 +349,7 @@ static int test_store_custom(struct test_data *data) return ENOMEM; } - ret = sysdb_store_custom(data, data->ctx->sysdb, object_name, + ret = sysdb_store_custom(data->ctx->sysdb, object_name, CUSTOM_TEST_CONTAINER, data->attrs); return ret; } @@ -358,7 +358,7 @@ static int test_delete_custom(struct test_data *data) { int ret; - ret = sysdb_delete_custom(data, data->ctx->sysdb, + ret = sysdb_delete_custom(data->ctx->sysdb, CUSTOM_TEST_OBJECT, CUSTOM_TEST_CONTAINER); return ret; } @@ -391,7 +391,7 @@ static int test_delete_recursive(struct test_data *data) return ENOMEM; } - ret = sysdb_delete_recursive(data, data->ctx->sysdb, dn, false); + ret = sysdb_delete_recursive(data->ctx->sysdb, dn, false); fail_unless(ret == EOK, "sysdb_delete_recursive returned [%d]", ret); return ret; } @@ -419,7 +419,7 @@ static int test_memberof_store_group(struct test_data *data) } } - ret = sysdb_store_group(data, data->ctx->sysdb, data->groupname, + ret = sysdb_store_group(data->ctx->sysdb, data->groupname, data->gid, attrs, -1); return ret; } @@ -1451,7 +1451,7 @@ START_TEST (test_sysdb_cache_password) data->ev = test_ctx->ev; data->username = talloc_asprintf(data, "testuser%d", _i); - ret = sysdb_cache_password(data, test_ctx->sysdb, + ret = sysdb_cache_password(test_ctx->sysdb, data->username, data->username); fail_unless(ret == EOK, "sysdb_cache_password request failed [%d].", ret); @@ -1490,7 +1490,7 @@ static void cached_authentication_without_expiration(const char *username, return; } - ret = sysdb_cache_auth(data, test_ctx->sysdb, data->username, + ret = sysdb_cache_auth(test_ctx->sysdb, data->username, (const uint8_t *)password, strlen(password), test_ctx->confdb, false, &expire_date, &delayed_until); @@ -1546,11 +1546,11 @@ static void cached_authentication_with_expiration(const char *username, data->attrs = sysdb_new_attrs(data); ret = sysdb_attrs_add_time_t(data->attrs, SYSDB_LAST_ONLINE_AUTH, now); - ret = sysdb_set_user_attr(data, data->ctx->sysdb, data->username, + ret = sysdb_set_user_attr(data->ctx->sysdb, data->username, data->attrs, SYSDB_MOD_REP); fail_unless(ret == EOK, "Could not modify user %s", data->username); - ret = sysdb_cache_auth(data, test_ctx->sysdb, data->username, + ret = sysdb_cache_auth(test_ctx->sysdb, data->username, (const uint8_t *) password, strlen(password), test_ctx->confdb, false, &expire_date, &delayed_until); @@ -2727,8 +2727,7 @@ START_TEST(test_odd_characters) /* ===== Users ===== */ /* Add */ - ret = sysdb_add_basic_user(test_ctx, - test_ctx->sysdb, + ret = sysdb_add_basic_user(test_ctx->sysdb, odd_username, 10000, 10000, "","",""); @@ -2771,13 +2770,13 @@ START_TEST(test_odd_characters) talloc_free(res); /* Delete User */ - ret = sysdb_delete_user(test_ctx, test_ctx->sysdb, odd_username, 10000); + ret = sysdb_delete_user(test_ctx->sysdb, odd_username, 10000); fail_unless(ret == EOK, "sysdb_delete_user error [%d][%s]", ret, strerror(ret)); /* Delete Group */ - ret = sysdb_delete_group(test_ctx, test_ctx->sysdb, odd_groupname, 20000); + ret = sysdb_delete_group(test_ctx->sysdb, odd_groupname, 20000); fail_unless(ret == EOK, "sysdb_delete_group error [%d][%s]", ret, strerror(ret)); diff --git a/src/tools/sss_cache.c b/src/tools/sss_cache.c index 67fe2df5..37b60c89 100644 --- a/src/tools/sss_cache.c +++ b/src/tools/sss_cache.c @@ -157,12 +157,12 @@ errno_t invalidate_entry(TALLOC_CTX *ctx, struct sysdb_ctx *sysdb, if (ret == EOK) { switch (entry_type) { case TYPE_USER: - ret = sysdb_set_user_attr(ctx, sysdb, name, - sys_attrs, SYSDB_MOD_REP); + ret = sysdb_set_user_attr(sysdb, name, sys_attrs, + SYSDB_MOD_REP); break; case TYPE_GROUP: - ret = sysdb_set_group_attr(ctx, sysdb, name, - sys_attrs, SYSDB_MOD_REP); + ret = sysdb_set_group_attr(sysdb, name, sys_attrs, + SYSDB_MOD_REP); break; case TYPE_NETGROUP: ret = sysdb_set_netgroup_attr(sysdb, name, diff --git a/src/tools/sss_sync_ops.c b/src/tools/sss_sync_ops.c index d3cbb9d9..49c6c58e 100644 --- a/src/tools/sss_sync_ops.c +++ b/src/tools/sss_sync_ops.c @@ -80,8 +80,7 @@ static int mod_groups_member(TALLOC_CTX *mem_ctx, goto done; } - ret = sysdb_mod_group_member(tmpctx, sysdb, - member_dn, parent_dn, optype); + ret = sysdb_mod_group_member(sysdb, member_dn, parent_dn, optype); if (ret) { goto done; } @@ -223,8 +222,7 @@ int usermod(TALLOC_CTX *mem_ctx, } if (attrs->num != 0) { - ret = sysdb_set_user_attr(mem_ctx, sysdb, data->name, - attrs, SYSDB_MOD_REP); + ret = sysdb_set_user_attr(sysdb, data->name, attrs, SYSDB_MOD_REP); if (ret) { return ret; } @@ -279,8 +277,7 @@ int groupmod(TALLOC_CTX *mem_ctx, return ret; } - ret = sysdb_set_group_attr(mem_ctx, sysdb, data->name, - attrs, SYSDB_MOD_REP); + ret = sysdb_set_group_attr(sysdb, data->name, attrs, SYSDB_MOD_REP); if (ret) { return ret; } @@ -474,7 +471,7 @@ int useradd(TALLOC_CTX *mem_ctx, { int ret; - ret = sysdb_add_user(mem_ctx, sysdb, data->name, data->uid, data->gid, + ret = sysdb_add_user(sysdb, data->name, data->uid, data->gid, data->gecos, data->home, data->shell, NULL, 0); if (ret) { goto done; @@ -540,8 +537,7 @@ int groupadd(TALLOC_CTX *mem_ctx, { int ret; - ret = sysdb_add_group(mem_ctx, sysdb, data->name, - data->gid, NULL, 0); + ret = sysdb_add_group(sysdb, data->name, data->gid, NULL, 0); if (ret == EOK) { flush_nscd_cache(mem_ctx, NSCD_DB_GROUP); } |