summaryrefslogtreecommitdiff
path: root/source3/passdb
diff options
context:
space:
mode:
Diffstat (limited to 'source3/passdb')
-rw-r--r--source3/passdb/pdb_interface.c63
-rw-r--r--source3/passdb/pdb_ldap.c20
-rw-r--r--source3/passdb/pdb_smbpasswd.c9
-rw-r--r--source3/passdb/pdb_tdb.c11
4 files changed, 46 insertions, 57 deletions
diff --git a/source3/passdb/pdb_interface.c b/source3/passdb/pdb_interface.c
index e618b425e0..1909bd0da4 100644
--- a/source3/passdb/pdb_interface.c
+++ b/source3/passdb/pdb_interface.c
@@ -1709,24 +1709,25 @@ static NTSTATUS pdb_default_lookup_names(struct pdb_methods *methods,
}
#endif
-struct pdb_search *pdb_search_init(enum pdb_search_type type)
+static int pdb_search_destructor(struct pdb_search *search)
{
- TALLOC_CTX *mem_ctx;
- struct pdb_search *result;
-
- mem_ctx = talloc_init("pdb_search");
- if (mem_ctx == NULL) {
- DEBUG(0, ("talloc_init failed\n"));
- return NULL;
+ if (!search->search_ended) {
+ search->search_end(search);
}
+ return 0;
+}
- result = TALLOC_P(mem_ctx, struct pdb_search);
+struct pdb_search *pdb_search_init(TALLOC_CTX *mem_ctx,
+ enum pdb_search_type type)
+{
+ struct pdb_search *result;
+
+ result = talloc(mem_ctx, struct pdb_search);
if (result == NULL) {
DEBUG(0, ("talloc failed\n"));
return NULL;
}
- result->mem_ctx = mem_ctx;
result->type = type;
result->cache = NULL;
result->num_entries = 0;
@@ -1737,6 +1738,8 @@ struct pdb_search *pdb_search_init(enum pdb_search_type type)
result->next_entry = NULL;
result->search_end = NULL;
+ talloc_set_destructor(result, pdb_search_destructor);
+
return result;
}
@@ -1783,8 +1786,7 @@ static bool next_entry_groups(struct pdb_search *s,
sid_peek_rid(&map->sid, &rid);
- fill_displayentry(s->mem_ctx, rid, 0, map->nt_name, NULL, map->comment,
- entry);
+ fill_displayentry(s, rid, 0, map->nt_name, NULL, map->comment, entry);
state->current_group += 1;
return True;
@@ -1802,7 +1804,7 @@ static bool pdb_search_grouptype(struct pdb_search *search,
{
struct group_search *state;
- state = TALLOC_P(search->mem_ctx, struct group_search);
+ state = talloc(search, struct group_search);
if (state == NULL) {
DEBUG(0, ("talloc failed\n"));
return False;
@@ -1853,7 +1855,7 @@ static struct samr_displayentry *pdb_search_getentry(struct pdb_search *search,
break;
}
- ADD_TO_LARGE_ARRAY(search->mem_ctx, struct samr_displayentry,
+ ADD_TO_LARGE_ARRAY(search, struct samr_displayentry,
entry, &search->cache, &search->num_entries,
&search->cache_size);
}
@@ -1861,52 +1863,54 @@ static struct samr_displayentry *pdb_search_getentry(struct pdb_search *search,
return (search->num_entries > idx) ? &search->cache[idx] : NULL;
}
-struct pdb_search *pdb_search_users(uint32 acct_flags)
+struct pdb_search *pdb_search_users(TALLOC_CTX *mem_ctx, uint32 acct_flags)
{
struct pdb_methods *pdb = pdb_get_methods();
struct pdb_search *result;
- result = pdb_search_init(PDB_USER_SEARCH);
+ result = pdb_search_init(mem_ctx, PDB_USER_SEARCH);
if (result == NULL) {
return NULL;
}
if (!pdb->search_users(pdb, result, acct_flags)) {
- talloc_destroy(result->mem_ctx);
+ TALLOC_FREE(result);
return NULL;
}
return result;
}
-struct pdb_search *pdb_search_groups(void)
+struct pdb_search *pdb_search_groups(TALLOC_CTX *mem_ctx)
{
struct pdb_methods *pdb = pdb_get_methods();
struct pdb_search *result;
- result = pdb_search_init(PDB_GROUP_SEARCH);
+ result = pdb_search_init(mem_ctx, PDB_GROUP_SEARCH);
if (result == NULL) {
return NULL;
}
if (!pdb->search_groups(pdb, result)) {
- talloc_destroy(result->mem_ctx);
+ TALLOC_FREE(result);
return NULL;
}
return result;
}
-struct pdb_search *pdb_search_aliases(const DOM_SID *sid)
+struct pdb_search *pdb_search_aliases(TALLOC_CTX *mem_ctx, const DOM_SID *sid)
{
struct pdb_methods *pdb = pdb_get_methods();
struct pdb_search *result;
if (pdb == NULL) return NULL;
- result = pdb_search_init(PDB_ALIAS_SEARCH);
- if (result == NULL) return NULL;
+ result = pdb_search_init(mem_ctx, PDB_ALIAS_SEARCH);
+ if (result == NULL) {
+ return NULL;
+ }
if (!pdb->search_aliases(pdb, result, sid)) {
- talloc_destroy(result->mem_ctx);
+ TALLOC_FREE(result);
return NULL;
}
return result;
@@ -1935,17 +1939,6 @@ uint32 pdb_search_entries(struct pdb_search *search,
return search->num_entries - start_idx;
}
-void pdb_search_destroy(struct pdb_search *search)
-{
- if (search == NULL)
- return;
-
- if (!search->search_ended)
- search->search_end(search);
-
- talloc_destroy(search->mem_ctx);
-}
-
/*******************************************************************
trustdom methods
*******************************************************************/
diff --git a/source3/passdb/pdb_ldap.c b/source3/passdb/pdb_ldap.c
index 70a1c62bef..77b19e3de9 100644
--- a/source3/passdb/pdb_ldap.c
+++ b/source3/passdb/pdb_ldap.c
@@ -4349,7 +4349,8 @@ static bool ldapsam_search_next_entry(struct pdb_search *search,
!ldapsam_search_nextpage(search))
return False;
- result = state->ldap2displayentry(state, search->mem_ctx, state->connection->ldap_struct,
+ result = state->ldap2displayentry(state, search,
+ state->connection->ldap_struct,
state->current_entry, entry);
if (!result) {
@@ -4508,7 +4509,7 @@ static bool ldapsam_search_users(struct pdb_methods *methods,
(struct ldapsam_privates *)methods->private_data;
struct ldap_search_state *state;
- state = TALLOC_P(search->mem_ctx, struct ldap_search_state);
+ state = talloc(search, struct ldap_search_state);
if (state == NULL) {
DEBUG(0, ("talloc failed\n"));
return False;
@@ -4525,10 +4526,10 @@ static bool ldapsam_search_users(struct pdb_methods *methods,
state->base = lp_ldap_suffix();
state->acct_flags = acct_flags;
- state->base = talloc_strdup(search->mem_ctx, state->base);
+ state->base = talloc_strdup(search, state->base);
state->scope = LDAP_SCOPE_SUBTREE;
- state->filter = get_ldap_filter(search->mem_ctx, "*");
- state->attrs = talloc_attrs(search->mem_ctx, "uid", "sambaSid",
+ state->filter = get_ldap_filter(search, "*");
+ state->attrs = talloc_attrs(search, "uid", "sambaSid",
"displayName", "description",
"sambaAcctFlags", NULL);
state->attrsonly = 0;
@@ -4682,7 +4683,7 @@ static bool ldapsam_search_grouptype(struct pdb_methods *methods,
struct ldap_search_state *state;
fstring tmp;
- state = TALLOC_P(search->mem_ctx, struct ldap_search_state);
+ state = talloc(search, struct ldap_search_state);
if (state == NULL) {
DEBUG(0, ("talloc failed\n"));
return False;
@@ -4690,15 +4691,14 @@ static bool ldapsam_search_grouptype(struct pdb_methods *methods,
state->connection = ldap_state->smbldap_state;
- state->base = talloc_strdup(search->mem_ctx, lp_ldap_group_suffix());
+ state->base = talloc_strdup(search, lp_ldap_group_suffix());
state->connection = ldap_state->smbldap_state;
state->scope = LDAP_SCOPE_SUBTREE;
- state->filter = talloc_asprintf(search->mem_ctx,
- "(&(objectclass=%s)"
+ state->filter = talloc_asprintf(search, "(&(objectclass=%s)"
"(sambaGroupType=%d)(sambaSID=%s*))",
LDAP_OBJ_GROUPMAP,
type, sid_to_fstring(tmp, sid));
- state->attrs = talloc_attrs(search->mem_ctx, "cn", "sambaSid",
+ state->attrs = talloc_attrs(search, "cn", "sambaSid",
"displayName", "description",
"sambaGroupType", NULL);
state->attrsonly = 0;
diff --git a/source3/passdb/pdb_smbpasswd.c b/source3/passdb/pdb_smbpasswd.c
index b72e0f2cba..d663c7f0b2 100644
--- a/source3/passdb/pdb_smbpasswd.c
+++ b/source3/passdb/pdb_smbpasswd.c
@@ -1566,11 +1566,11 @@ static bool smbpasswd_search_next_entry(struct pdb_search *search,
entry->acct_flags = state->entries[state->current].acct_flags;
entry->account_name = talloc_strdup(
- search->mem_ctx, state->entries[state->current].account_name);
+ search, state->entries[state->current].account_name);
entry->fullname = talloc_strdup(
- search->mem_ctx, state->entries[state->current].fullname);
+ search, state->entries[state->current].fullname);
entry->description = talloc_strdup(
- search->mem_ctx, state->entries[state->current].description);
+ search, state->entries[state->current].description);
if ((entry->account_name == NULL) || (entry->fullname == NULL)
|| (entry->description == NULL)) {
@@ -1593,8 +1593,7 @@ static bool smbpasswd_search_users(struct pdb_methods *methods,
struct smb_passwd *pwd;
FILE *fp;
- search_state = TALLOC_ZERO_P(search->mem_ctx,
- struct smbpasswd_search_state);
+ search_state = talloc_zero(search, struct smbpasswd_search_state);
if (search_state == NULL) {
DEBUG(0, ("talloc failed\n"));
return false;
diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c
index 143a2e2390..3442561030 100644
--- a/source3/passdb/pdb_tdb.c
+++ b/source3/passdb/pdb_tdb.c
@@ -882,12 +882,9 @@ static bool tdbsam_search_next_entry(struct pdb_search *search,
entry->acct_flags = pdb_get_acct_ctrl(user);
entry->rid = rid;
- entry->account_name = talloc_strdup(
- search->mem_ctx, pdb_get_username(user));
- entry->fullname = talloc_strdup(
- search->mem_ctx, pdb_get_fullname(user));
- entry->description = talloc_strdup(
- search->mem_ctx, pdb_get_acct_desc(user));
+ entry->account_name = talloc_strdup(search, pdb_get_username(user));
+ entry->fullname = talloc_strdup(search, pdb_get_fullname(user));
+ entry->description = talloc_strdup(search, pdb_get_acct_desc(user));
TALLOC_FREE(user);
@@ -912,7 +909,7 @@ static bool tdbsam_search_users(struct pdb_methods *methods,
return false;
}
- state = TALLOC_ZERO_P(search->mem_ctx, struct tdbsam_search_state);
+ state = talloc_zero(search, struct tdbsam_search_state);
if (state == NULL) {
DEBUG(0, ("talloc failed\n"));
return false;