};
struct pdb_search {
- TALLOC_CTX *mem_ctx;
enum pdb_search_type type;
struct samr_displayentry *cache;
uint32 num_entries;
bool pdb_rid_algorithm(void);
bool pdb_new_rid(uint32 *rid);
bool initialize_password_db(bool reload, struct event_context *event_ctx);
-struct pdb_search *pdb_search_init(enum pdb_search_type type);
-struct pdb_search *pdb_search_users(uint32 acct_flags);
-struct pdb_search *pdb_search_groups(void);
-struct pdb_search *pdb_search_aliases(const DOM_SID *sid);
+struct pdb_search *pdb_search_init(TALLOC_CTX *mem_ctx,
+ enum pdb_search_type type);
+struct pdb_search *pdb_search_users(TALLOC_CTX *mem_ctx, uint32 acct_flags);
+struct pdb_search *pdb_search_groups(TALLOC_CTX *mem_ctx);
+struct pdb_search *pdb_search_aliases(TALLOC_CTX *mem_ctx, const DOM_SID *sid);
uint32 pdb_search_entries(struct pdb_search *search,
uint32 start_idx, uint32 max_entries,
struct samr_displayentry **result);
-void pdb_search_destroy(struct pdb_search *search);
bool pdb_get_trusteddom_pw(const char *domain, char** pwd, DOM_SID *sid,
time_t *pass_last_set_time);
bool pdb_set_trusteddom_pw(const char* domain, const char* pwd,
}
#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;
result->next_entry = NULL;
result->search_end = NULL;
+ talloc_set_destructor(result, pdb_search_destructor);
+
return result;
}
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;
{
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;
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);
}
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;
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
*******************************************************************/
!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) {
(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;
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;
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;
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;
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)) {
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;
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);
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;
* enumerate stuff, so just cache 2 entries.
*/
- static struct disp_info builtin_dispinfo;
- static struct disp_info domain_dispinfo;
+ static struct disp_info *builtin_dispinfo;
+ static struct disp_info *domain_dispinfo;
/* There are two cases to consider here:
1) The SID is a domain SID and we look for an equality match, or
/*
* Necessary only once, but it does not really hurt.
*/
- sid_copy(&builtin_dispinfo.sid, &global_sid_Builtin);
+ if (builtin_dispinfo == NULL) {
+ builtin_dispinfo = talloc_zero(
+ talloc_autofree_context(), struct disp_info);
+ if (builtin_dispinfo == NULL) {
+ return NULL;
+ }
+ }
+ sid_copy(&builtin_dispinfo->sid, &global_sid_Builtin);
- return &builtin_dispinfo;
+ return builtin_dispinfo;
}
if (sid_check_is_domain(psid) || sid_check_is_in_our_domain(psid)) {
/*
* Necessary only once, but it does not really hurt.
*/
- sid_copy(&domain_dispinfo.sid, get_global_sam_sid());
+ if (domain_dispinfo == NULL) {
+ domain_dispinfo = talloc_zero(
+ talloc_autofree_context(), struct disp_info);
+ if (domain_dispinfo == NULL) {
+ return NULL;
+ }
+ }
+ sid_copy(&domain_dispinfo->sid, get_global_sam_sid());
- return &domain_dispinfo;
+ return domain_dispinfo;
}
return NULL;
become_root();
- if (disp_info->users) {
- DEBUG(10,("free_samr_cache: deleting users cache\n"));
- pdb_search_destroy(disp_info->users);
- disp_info->users = NULL;
- }
- if (disp_info->machines) {
- DEBUG(10,("free_samr_cache: deleting machines cache\n"));
- pdb_search_destroy(disp_info->machines);
- disp_info->machines = NULL;
- }
- if (disp_info->groups) {
- DEBUG(10,("free_samr_cache: deleting groups cache\n"));
- pdb_search_destroy(disp_info->groups);
- disp_info->groups = NULL;
- }
- if (disp_info->aliases) {
- DEBUG(10,("free_samr_cache: deleting aliases cache\n"));
- pdb_search_destroy(disp_info->aliases);
- disp_info->aliases = NULL;
- }
- if (disp_info->enum_users) {
- DEBUG(10,("free_samr_cache: deleting enum_users cache\n"));
- pdb_search_destroy(disp_info->enum_users);
- disp_info->enum_users = NULL;
- }
- disp_info->enum_acb_mask = 0;
+ TALLOC_FREE(disp_info->users);
+ TALLOC_FREE(disp_info->machines);
+ TALLOC_FREE(disp_info->groups);
+ TALLOC_FREE(disp_info->aliases);
+ TALLOC_FREE(disp_info->enum_users);
unbecome_root();
}
}
if (info->users == NULL) {
- info->users = pdb_search_users(acct_flags);
+ info->users = pdb_search_users(info, acct_flags);
if (info->users == NULL) {
return 0;
}
}
if (info->groups == NULL) {
- info->groups = pdb_search_groups();
+ info->groups = pdb_search_groups(info);
if (info->groups == NULL) {
return 0;
}
struct samr_displayentry *entry;
if (info->aliases == NULL) {
- info->aliases = pdb_search_aliases(&info->sid);
+ info->aliases = pdb_search_aliases(info, &info->sid);
if (info->aliases == NULL) {
return 0;
}
if ((info->disp_info->enum_users != NULL) &&
(info->disp_info->enum_acb_mask != r->in.acct_flags)) {
- pdb_search_destroy(info->disp_info->enum_users);
- info->disp_info->enum_users = NULL;
+ TALLOC_FREE(info->disp_info->enum_users);
}
if (info->disp_info->enum_users == NULL) {
- info->disp_info->enum_users = pdb_search_users(r->in.acct_flags);
+ info->disp_info->enum_users = pdb_search_users(
+ info->disp_info, r->in.acct_flags);
info->disp_info->enum_acb_mask = r->in.acct_flags;
}
become_root();
if (info->disp_info->groups == NULL) {
- info->disp_info->groups = pdb_search_groups();
+ info->disp_info->groups = pdb_search_groups(info->disp_info);
if (info->disp_info->groups == NULL) {
unbecome_root();
become_root();
if (info->disp_info->aliases == NULL) {
- info->disp_info->aliases = pdb_search_aliases(&info->sid);
+ info->disp_info->aliases = pdb_search_aliases(
+ info->disp_info, &info->sid);
if (info->disp_info->aliases == NULL) {
unbecome_root();
return NT_STATUS_ACCESS_DENIED;
case 0x1:
case 0x4:
if (info->disp_info->users == NULL) {
- info->disp_info->users = pdb_search_users(ACB_NORMAL);
+ info->disp_info->users = pdb_search_users(
+ info->disp_info, ACB_NORMAL);
if (info->disp_info->users == NULL) {
unbecome_root();
return NT_STATUS_ACCESS_DENIED;
break;
case 0x2:
if (info->disp_info->machines == NULL) {
- info->disp_info->machines =
- pdb_search_users(ACB_WSTRUST|ACB_SVRTRUST);
+ info->disp_info->machines = pdb_search_users(
+ info->disp_info, ACB_WSTRUST|ACB_SVRTRUST);
if (info->disp_info->machines == NULL) {
unbecome_root();
return NT_STATUS_ACCESS_DENIED;
case 0x3:
case 0x5:
if (info->disp_info->groups == NULL) {
- info->disp_info->groups = pdb_search_groups();
+ info->disp_info->groups = pdb_search_groups(
+ info->disp_info);
if (info->disp_info->groups == NULL) {
unbecome_root();
return NT_STATUS_ACCESS_DENIED;
switch (r->in.level) {
case 1:
if (info->disp_info->users == NULL) {
- info->disp_info->users = pdb_search_users(ACB_NORMAL);
+ info->disp_info->users = pdb_search_users(
+ info->disp_info, ACB_NORMAL);
if (info->disp_info->users == NULL) {
unbecome_root();
return NT_STATUS_ACCESS_DENIED;
break;
case 2:
if (info->disp_info->machines == NULL) {
- info->disp_info->machines =
- pdb_search_users(ACB_WSTRUST|ACB_SVRTRUST);
+ info->disp_info->machines = pdb_search_users(
+ info->disp_info, ACB_WSTRUST|ACB_SVRTRUST);
if (info->disp_info->machines == NULL) {
unbecome_root();
return NT_STATUS_ACCESS_DENIED;
break;
case 3:
if (info->disp_info->groups == NULL) {
- info->disp_info->groups = pdb_search_groups();
+ info->disp_info->groups = pdb_search_groups(
+ info->disp_info);
if (info->disp_info->groups == NULL) {
unbecome_root();
return NT_STATUS_ACCESS_DENIED;
num_entries = pdb_search_entries(search, 0, 0xffffffff, &entries);
for (i=0; i<num_entries; i++)
*max_rid = MAX(*max_rid, entries[i].rid);
- pdb_search_destroy(search);
+ TALLOC_FREE(search);
return true;
}
{
uint32 max_rid = 0;
- if (!search_maxrid(pdb_search_users(0), "users", &max_rid))
+ if (!search_maxrid(pdb_search_users(talloc_tos(), 0), "users", &max_rid))
return 0;
- if (!search_maxrid(pdb_search_groups(), "groups", &max_rid))
+ if (!search_maxrid(pdb_search_groups(talloc_tos()), "groups", &max_rid))
return 0;
- if (!search_maxrid(pdb_search_aliases(get_global_sam_sid()),
+ if (!search_maxrid(pdb_search_aliases(talloc_tos(),
+ get_global_sam_sid()),
"aliases", &max_rid))
return 0;
}
}
- pdb_search_destroy(search);
+ TALLOC_FREE(search);
return 0;
}
static int net_sam_list_users(struct net_context *c, int argc,
const char **argv)
{
- return net_sam_do_list(c, argc, argv, pdb_search_users(ACB_NORMAL),
+ return net_sam_do_list(c, argc, argv,
+ pdb_search_users(talloc_tos(), ACB_NORMAL),
"users");
}
static int net_sam_list_groups(struct net_context *c, int argc,
const char **argv)
{
- return net_sam_do_list(c, argc, argv, pdb_search_groups(), "groups");
+ return net_sam_do_list(c, argc, argv, pdb_search_groups(talloc_tos()),
+ "groups");
}
static int net_sam_list_localgroups(struct net_context *c, int argc,
const char **argv)
{
return net_sam_do_list(c, argc, argv,
- pdb_search_aliases(get_global_sam_sid()),
+ pdb_search_aliases(talloc_tos(),
+ get_global_sam_sid()),
"localgroups");
}
const char **argv)
{
return net_sam_do_list(c, argc, argv,
- pdb_search_aliases(&global_sid_Builtin),
+ pdb_search_aliases(talloc_tos(),
+ &global_sid_Builtin),
"builtin");
}
const char **argv)
{
return net_sam_do_list(c, argc, argv,
- pdb_search_users(ACB_WSTRUST),
+ pdb_search_users(talloc_tos(), ACB_WSTRUST),
"workstations");
}
DEBUG(3, ("export_database: username=\"%s\"\n", username ? username : "(NULL)"));
- u_search = pdb_search_init(PDB_USER_SEARCH);
+ u_search = pdb_search_init(talloc_tos(), PDB_USER_SEARCH);
if (u_search == NULL) {
DEBUG(0, ("pdb_search_init failed\n"));
return 1;
if (!in->search_users(in, u_search, 0)) {
DEBUG(0, ("Could not start searching users\n"));
- pdb_search_destroy(u_search);
+ TALLOC_FREE(u_search);
return 1;
}
fprintf(stderr, "export_database: Memory allocation "
"failure!\n");
TALLOC_FREE( user );
- pdb_search_destroy(u_search);
+ TALLOC_FREE(u_search);
return 1;
}
TALLOC_FREE( user );
}
- pdb_search_destroy(u_search);
+ TALLOC_FREE(u_search);
return 0;
}
struct pdb_search *u_search;
struct samr_displayentry userentry;
- u_search = pdb_search_init(PDB_USER_SEARCH);
+ u_search = pdb_search_init(talloc_tos(), PDB_USER_SEARCH);
if (u_search == NULL) {
DEBUG(0, ("pdb_search_init failed\n"));
return 1;
if (!in->search_users(in, u_search, 0)) {
DEBUG(0, ("Could not start searching users\n"));
- pdb_search_destroy(u_search);
+ TALLOC_FREE(u_search);
return 1;
}
print_sam_info (sam_pwent, verbosity, smbpwdstyle);
TALLOC_FREE(sam_pwent);
}
- pdb_search_destroy(u_search);
+ TALLOC_FREE(u_search);
return 0;
}
struct pdb_search *u_search;
struct samr_displayentry userentry;
- u_search = pdb_search_init(PDB_USER_SEARCH);
+ u_search = pdb_search_init(talloc_tos(), PDB_USER_SEARCH);
if (u_search == NULL) {
DEBUG(0, ("pdb_search_init failed\n"));
return 1;
if (!in->search_users(in, u_search, 0)) {
DEBUG(0, ("Could not start searching users\n"));
- pdb_search_destroy(u_search);
+ TALLOC_FREE(u_search);
return 1;
}
}
TALLOC_FREE(sam_pwent);
}
- pdb_search_destroy(u_search);
+ TALLOC_FREE(u_search);
return 0;
}
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
if (sidtype == SID_NAME_ALIAS) {
- search = pdb_search_aliases(&domain->sid);
+ search = pdb_search_aliases(talloc_tos(), &domain->sid);
} else {
- search = pdb_search_groups();
+ search = pdb_search_groups(talloc_tos());
}
if (search == NULL) goto done;
result = NT_STATUS_OK;
done:
- pdb_search_destroy(search);
+ TALLOC_FREE(search);
return result;
}
uint32 *num_entries,
WINBIND_USERINFO **info)
{
- struct pdb_search *ps = pdb_search_users(ACB_NORMAL);
+ struct pdb_search *ps = pdb_search_users(talloc_tos(), ACB_NORMAL);
struct samr_displayentry *entries = NULL;
uint32 i;
*info = TALLOC_ZERO_ARRAY(mem_ctx, WINBIND_USERINFO, *num_entries);
if (!(*info)) {
- pdb_search_destroy(ps);
+ TALLOC_FREE(ps);
return NT_STATUS_NO_MEMORY;
}
DOMAIN_GROUP_RID_USERS);
}
- pdb_search_destroy(ps);
+ TALLOC_FREE(ps);
return NT_STATUS_OK;
}