summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolker Lendecke <vlendec@samba.org>2005-04-18 16:07:49 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 10:56:39 -0500
commitf74f7c933db6c981661ce5fc8666b87ad7ef41cc (patch)
treed2ccc2abd99a7f16905c8d32bda842b49b1405d4
parentb39c949ae05ee990bd8daa588e92c768185761b5 (diff)
downloadsamba-f74f7c933db6c981661ce5fc8666b87ad7ef41cc.tar.gz
samba-f74f7c933db6c981661ce5fc8666b87ad7ef41cc.tar.bz2
samba-f74f7c933db6c981661ce5fc8666b87ad7ef41cc.zip
r6367: Slim down pdb_interface.c a bit. next_entry and search_end are function
pointers now. Yes, Jeremy, this is about re-inventing C++... :-) Volker (This used to be commit a831e54738c7854e68c696e9cbb132c012ff223c)
-rw-r--r--source3/include/passdb.h13
-rw-r--r--source3/passdb/pdb_interface.c245
-rw-r--r--source3/passdb/pdb_ldap.c18
3 files changed, 72 insertions, 204 deletions
diff --git a/source3/include/passdb.h b/source3/include/passdb.h
index 0c816271b0..9a3dd9c8d3 100644
--- a/source3/include/passdb.h
+++ b/source3/include/passdb.h
@@ -254,6 +254,9 @@ struct pdb_search {
ssize_t cache_size;
BOOL search_ended;
void *private;
+ BOOL (*next_entry)(struct pdb_search *search,
+ struct samr_displayentry *entry);
+ void (*search_end)(struct pdb_search *search);
};
/*****************************************************************
@@ -378,11 +381,6 @@ typedef struct pdb_context
BOOL (*pdb_search_aliases)(struct pdb_context *context,
struct pdb_search *search,
const DOM_SID *sid);
- BOOL (*pdb_search_next_entry)(struct pdb_context *context,
- struct pdb_search *search,
- struct samr_displayentry *entry);
- void (*pdb_search_end)(struct pdb_context *context,
- struct pdb_search *search);
void (*free_fn)(struct pdb_context **);
@@ -496,11 +494,6 @@ typedef struct pdb_methods
BOOL (*search_aliases)(struct pdb_methods *methods,
struct pdb_search *search,
const DOM_SID *sid);
- BOOL (*search_next_entry)(struct pdb_methods *methods,
- struct pdb_search *search,
- struct samr_displayentry *entry);
- void (*search_end)(struct pdb_methods *methods,
- struct pdb_search *search);
void *private_data; /* Private data of some kind */
diff --git a/source3/passdb/pdb_interface.c b/source3/passdb/pdb_interface.c
index edcd1c9222..c6880b1d50 100644
--- a/source3/passdb/pdb_interface.c
+++ b/source3/passdb/pdb_interface.c
@@ -702,31 +702,6 @@ static BOOL context_search_aliases(struct pdb_context *context,
search, sid);
}
-static BOOL context_search_next_entry(struct pdb_context *context,
- struct pdb_search *search,
- struct samr_displayentry *entry)
-{
- if ((!context) || (!context->pdb_methods)) {
- DEBUG(0, ("invalid pdb_context specified!\n"));
- return False;
- }
-
- return context->pdb_methods->search_next_entry(context->pdb_methods,
- search, entry);
-}
-
-static void context_search_end(struct pdb_context *context,
- struct pdb_search *search)
-{
- if ((!context) || (!context->pdb_methods)) {
- DEBUG(0, ("invalid pdb_context specified!\n"));
- return;
- }
-
- context->pdb_methods->search_end(context->pdb_methods, search);
- return;
-}
-
/******************************************************************
Free and cleanup a pdb context, any associated data and anything
that the attached modules might have associated.
@@ -860,8 +835,6 @@ static NTSTATUS make_pdb_context(struct pdb_context **context)
(*context)->pdb_search_users = context_search_users;
(*context)->pdb_search_groups = context_search_groups;
(*context)->pdb_search_aliases = context_search_aliases;
- (*context)->pdb_search_next_entry = context_search_next_entry;
- (*context)->pdb_search_end = context_search_end;
(*context)->free_fn = free_pdb_context;
@@ -1600,6 +1573,10 @@ static struct pdb_search *pdb_search_init(enum pdb_search_type type)
result->cache_size = 0;
result->search_ended = False;
+ /* Segfault appropriately if not initialized */
+ result->next_entry = NULL;
+ result->search_end = NULL;
+
return result;
}
@@ -1634,38 +1611,8 @@ struct user_search {
uint16 acct_flags;
};
-static BOOL pdb_default_search_users(struct pdb_methods *methods,
- struct pdb_search *search,
- uint16 acct_flags)
-{
- struct user_search *state;
-
- if (user_search_in_progress) {
- DEBUG(1, ("user search in progress\n"));
- return False;
- }
-
- if (!pdb_setsampwent(False, acct_flags)) {
- DEBUG(5, ("Could not start search\n"));
- return False;
- }
-
- user_search_in_progress = True;
-
- state = TALLOC_P(search->mem_ctx, struct user_search);
- if (state == NULL) {
- DEBUG(0, ("talloc failed\n"));
- return False;
- }
-
- state->acct_flags = acct_flags;
-
- search->private = state;
- return True;
-}
-
-static BOOL pdb_search_next_entry_users(struct pdb_search *s,
- struct samr_displayentry *entry)
+static BOOL next_entry_users(struct pdb_search *s,
+ struct samr_displayentry *entry)
{
struct user_search *state = s->private;
SAM_ACCOUNT *user = NULL;
@@ -1698,41 +1645,51 @@ static BOOL pdb_search_next_entry_users(struct pdb_search *s,
return True;
}
-static void pdb_search_end_users(struct pdb_search *search)
+static void search_end_users(struct pdb_search *search)
{
pdb_endsampwent();
user_search_in_progress = False;
}
-struct group_search {
- GROUP_MAP *groups;
- int num_groups, current_group;
-};
-
-static BOOL pdb_default_search_groups(struct pdb_methods *methods,
- struct pdb_search *search)
+static BOOL pdb_default_search_users(struct pdb_methods *methods,
+ struct pdb_search *search,
+ uint16 acct_flags)
{
- struct group_search *state;
+ struct user_search *state;
- state = TALLOC_P(search->mem_ctx, struct group_search);
- if (state == NULL) {
- DEBUG(0, ("talloc failed\n"));
+ if (user_search_in_progress) {
+ DEBUG(1, ("user search in progress\n"));
return False;
}
- if (!pdb_enum_group_mapping(SID_NAME_DOM_GRP, &state->groups,
- &state->num_groups, True)) {
- DEBUG(0, ("Could not enum groups\n"));
+ if (!pdb_setsampwent(False, acct_flags)) {
+ DEBUG(5, ("Could not start search\n"));
return False;
}
- state->current_group = 0;
+ user_search_in_progress = True;
+
+ state = TALLOC_P(search->mem_ctx, struct user_search);
+ if (state == NULL) {
+ DEBUG(0, ("talloc failed\n"));
+ return False;
+ }
+
+ state->acct_flags = acct_flags;
+
search->private = state;
+ search->next_entry = next_entry_users;
+ search->search_end = search_end_users;
return True;
}
-static BOOL pdb_search_next_entry_group(struct pdb_search *s,
- struct samr_displayentry *entry)
+struct group_search {
+ GROUP_MAP *groups;
+ int num_groups, current_group;
+};
+
+static BOOL next_entry_groups(struct pdb_search *s,
+ struct samr_displayentry *entry)
{
struct group_search *state = s->private;
uint32 rid;
@@ -1750,135 +1707,55 @@ static BOOL pdb_search_next_entry_group(struct pdb_search *s,
return True;
}
-static void pdb_search_end_groups(struct pdb_search *search)
+static void search_end_groups(struct pdb_search *search)
{
struct group_search *state = search->private;
SAFE_FREE(state->groups);
}
-struct alias_search {
- GROUP_MAP *aliases;
- int num_aliases, current_alias;
-};
-
-static BOOL pdb_default_search_aliases(struct pdb_methods *methods,
- struct pdb_search *search,
- const DOM_SID *sid)
+static BOOL pdb_search_grouptype(struct pdb_search *search,
+ enum SID_NAME_USE type)
{
- struct alias_search *state;
- enum SID_NAME_USE type = SID_NAME_UNKNOWN;
-
- if (sid_equal(sid, get_global_sam_sid()))
- type = SID_NAME_ALIAS;
-
- if (sid_equal(sid, &global_sid_Builtin))
- type = SID_NAME_WKN_GRP;
-
- if (type == SID_NAME_UNKNOWN) {
- DEBUG(3, ("unknown domain sid: %s\n", sid_string_static(sid)));
- return False;
- }
+ struct group_search *state;
- state = TALLOC_P(search->mem_ctx, struct alias_search);
+ state = TALLOC_P(search->mem_ctx, struct group_search);
if (state == NULL) {
DEBUG(0, ("talloc failed\n"));
return False;
}
- if (!pdb_enum_group_mapping(type, &state->aliases,
- &state->num_aliases, False)) {
- DEBUG(0, ("Could not enum aliases\n"));
+ if (!pdb_enum_group_mapping(type, &state->groups, &state->num_groups,
+ True)) {
+ DEBUG(0, ("Could not enum groups\n"));
return False;
}
- state->current_alias = 0;
+ state->current_group = 0;
search->private = state;
+ search->next_entry = next_entry_groups;
+ search->search_end = search_end_groups;
return True;
}
-static BOOL pdb_search_next_entry_alias(struct pdb_search *s,
- struct samr_displayentry *entry)
-{
- struct alias_search *state = s->private;
- uint32 rid;
- GROUP_MAP *map = &state->aliases[state->current_alias];
-
- if (state->current_alias == state->num_aliases)
- return False;
-
- sid_peek_rid(&map->sid, &rid);
-
- fill_displayentry(s->mem_ctx, rid, 0, map->nt_name, NULL, map->comment,
- entry);
-
- state->current_alias += 1;
- return True;
-}
-
-static void pdb_search_end_aliases(struct pdb_search *search)
-{
- struct alias_search *state = search->private;
- SAFE_FREE(state->aliases);
-}
-
-static BOOL pdb_default_search_next_entry(struct pdb_methods *pdb_methods,
- struct pdb_search *search,
- struct samr_displayentry *entry)
-{
- BOOL result = False;
- switch (search->type) {
- case PDB_USER_SEARCH:
- result = pdb_search_next_entry_users(search, entry);
- break;
- case PDB_GROUP_SEARCH:
- result = pdb_search_next_entry_group(search, entry);
- break;
- case PDB_ALIAS_SEARCH:
- result = pdb_search_next_entry_alias(search, entry);
- break;
- default:
- DEBUG(0, ("unknown search type: %d\n", search->type));
- break;
- }
- return result;
-}
-
-static BOOL pdb_search_next_entry(struct pdb_search *search,
- struct samr_displayentry *entry)
+static BOOL pdb_default_search_groups(struct pdb_methods *methods,
+ struct pdb_search *search)
{
- struct pdb_context *pdb_context = pdb_get_static_context(False);
-
- if (pdb_context == NULL) return False;
-
- return pdb_context->pdb_search_next_entry(pdb_context, search, entry);
+ return pdb_search_grouptype(search, SID_NAME_DOM_GRP);
}
-static void pdb_default_search_end(struct pdb_methods *pdb_methods,
- struct pdb_search *search)
+static BOOL pdb_default_search_aliases(struct pdb_methods *methods,
+ struct pdb_search *search,
+ const DOM_SID *sid)
{
- switch (search->type) {
- case PDB_USER_SEARCH:
- pdb_search_end_users(search);
- break;
- case PDB_GROUP_SEARCH:
- pdb_search_end_groups(search);
- break;
- case PDB_ALIAS_SEARCH:
- pdb_search_end_aliases(search);
- break;
- default:
- DEBUG(0, ("unknown search type: %d\n", search->type));
- break;
- }
-}
-static void pdb_search_end(struct pdb_search *search)
-{
- struct pdb_context *pdb_context = pdb_get_static_context(False);
+ if (sid_equal(sid, get_global_sam_sid()))
+ return pdb_search_grouptype(search, SID_NAME_ALIAS);
- if (pdb_context == NULL) return;
+ if (sid_equal(sid, &global_sid_Builtin))
+ return pdb_search_grouptype(search, SID_NAME_WKN_GRP);
- pdb_context->pdb_search_end(pdb_context, search);
+ DEBUG(3, ("unknown domain sid: %s\n", sid_string_static(sid)));
+ return False;
}
static struct samr_displayentry *pdb_search_getentry(struct pdb_search *search,
@@ -1893,8 +1770,8 @@ static struct samr_displayentry *pdb_search_getentry(struct pdb_search *search,
while (idx >= search->num_entries) {
struct samr_displayentry entry;
- if (!pdb_search_next_entry(search, &entry)) {
- pdb_search_end(search);
+ if (!search->next_entry(search, &entry)) {
+ search->search_end(search);
search->search_ended = True;
break;
}
@@ -1987,7 +1864,7 @@ void pdb_search_destroy(struct pdb_search *search)
return;
if (!search->search_ended)
- pdb_search_end(search);
+ search->search_end(search);
talloc_destroy(search->mem_ctx);
}
@@ -2034,8 +1911,6 @@ NTSTATUS make_pdb_methods(TALLOC_CTX *mem_ctx, PDB_METHODS **methods)
(*methods)->search_users = pdb_default_search_users;
(*methods)->search_groups = pdb_default_search_groups;
(*methods)->search_aliases = pdb_default_search_aliases;
- (*methods)->search_next_entry = pdb_default_search_next_entry;
- (*methods)->search_end = pdb_default_search_end;
return NT_STATUS_OK;
}
diff --git a/source3/passdb/pdb_ldap.c b/source3/passdb/pdb_ldap.c
index 752eb878b1..04929314f0 100644
--- a/source3/passdb/pdb_ldap.c
+++ b/source3/passdb/pdb_ldap.c
@@ -3463,8 +3463,7 @@ static BOOL ldapsam_search_nextpage(struct pdb_search *search)
return True;
}
-static BOOL ldapsam_search_next_entry(struct pdb_methods *methods,
- struct pdb_search *search,
+static BOOL ldapsam_search_next_entry(struct pdb_search *search,
struct samr_displayentry *entry)
{
struct ldap_search_state *state = search->private;
@@ -3501,8 +3500,7 @@ static BOOL ldapsam_search_next_entry(struct pdb_methods *methods,
return True;
}
-static void ldapsam_search_end(struct pdb_methods *methods,
- struct pdb_search *search)
+static void ldapsam_search_end(struct pdb_search *search)
{
struct ldap_search_state *state = search->private;
int rc;
@@ -3656,6 +3654,8 @@ static BOOL ldapsam_search_users(struct pdb_methods *methods,
}
search->private = state;
+ search->next_entry = ldapsam_search_next_entry;
+ search->search_end = ldapsam_search_end;
return ldapsam_search_firstpage(search);
}
@@ -3761,6 +3761,8 @@ static BOOL ldapsam_search_grouptype(struct pdb_methods *methods,
}
search->private = state;
+ search->next_entry = ldapsam_search_next_entry;
+ search->search_end = ldapsam_search_end;
return ldapsam_search_firstpage(search);
}
@@ -3845,11 +3847,6 @@ static NTSTATUS pdb_init_ldapsam_common(PDB_CONTEXT *pdb_context, PDB_METHODS **
(*pdb_method)->enum_group_members = ldapsam_enum_group_members;
(*pdb_method)->enum_group_memberships = ldapsam_enum_group_memberships;
(*pdb_method)->lookup_rids = ldapsam_lookup_rids;
- (*pdb_method)->search_users = ldapsam_search_users;
- (*pdb_method)->search_groups = ldapsam_search_groups;
- (*pdb_method)->search_aliases = ldapsam_search_aliases;
- (*pdb_method)->search_next_entry = ldapsam_search_next_entry;
- (*pdb_method)->search_end = ldapsam_search_end;
/* TODO: Setup private data and free */
@@ -3941,6 +3938,9 @@ NTSTATUS pdb_init_ldapsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, co
(*pdb_method)->del_aliasmem = ldapsam_del_aliasmem;
(*pdb_method)->enum_aliasmem = ldapsam_enum_aliasmem;
(*pdb_method)->enum_alias_memberships = ldapsam_alias_memberships;
+ (*pdb_method)->search_users = ldapsam_search_users;
+ (*pdb_method)->search_groups = ldapsam_search_groups;
+ (*pdb_method)->search_aliases = ldapsam_search_aliases;
ldap_state = (*pdb_method)->private_data;
ldap_state->schema_ver = SCHEMAVER_SAMBASAMACCOUNT;