diff options
Diffstat (limited to 'src/db/sysdb_ops.c')
-rw-r--r-- | src/db/sysdb_ops.c | 501 |
1 files changed, 254 insertions, 247 deletions
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")); } |