summaryrefslogtreecommitdiff
path: root/src/db
diff options
context:
space:
mode:
Diffstat (limited to 'src/db')
-rw-r--r--src/db/sysdb.c155
-rw-r--r--src/db/sysdb.h57
-rw-r--r--src/db/sysdb_ops.c501
-rw-r--r--src/db/sysdb_search.c18
4 files changed, 363 insertions, 368 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;
}