From 9f4c0afa0a3e359dfe9ac5dd8df0849b450a3fe1 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 10 Apr 2005 15:26:37 +0000 Subject: r6277: This implements a new caching API for enumerating the pdb elements. It is modeled after query_displayinfo and should hide the differences between users, groups and aliases while allowing a cache analog load_sampw_entries: struct pdb_search *pdb_search_users(uint16 acct_flags); struct pdb_search *pdb_search_groups(void); struct pdb_search *pdb_search_aliases(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); Why this API? Eventually we will need to apply the work gd has started on enumerating users with paged ldap searches to groups and aliases. Before doing that I want to clean up the search routines we have. The sample application (more to follow) is 'net maxrid'. Volker (This used to be commit 8b4f67a1e9d459145cde10b1064781d58d62b805) --- source3/utils/net.c | 72 ++++++++++++++++++----------------------------------- 1 file changed, 24 insertions(+), 48 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/net.c b/source3/utils/net.c index ef992b1014..61c366710c 100644 --- a/source3/utils/net.c +++ b/source3/utils/net.c @@ -632,62 +632,38 @@ static int net_afs(int argc, const char **argv) #endif /* WITH_FAKE_KASERVER */ -static uint32 get_maxrid(void) +static BOOL search_maxrid(struct pdb_search *search, const char *type, + uint32 *max_rid) { - SAM_ACCOUNT *pwd = NULL; - uint32 max_rid = 0; - GROUP_MAP *map = NULL; - int num_entries = 0; - int i; - - if (!pdb_setsampwent(False, 0)) { - DEBUG(0, ("get_maxrid: Unable to open passdb.\n")); - return 0; - } + struct samr_displayentry *entries; + uint32 i, num_entries; - for (; (NT_STATUS_IS_OK(pdb_init_sam(&pwd))) - && pdb_getsampwent(pwd) == True; pwd=NULL) { - uint32 rid; - - if (!sid_peek_rid(pdb_get_user_sid(pwd), &rid)) { - DEBUG(0, ("can't get RID for user '%s'\n", - pdb_get_username(pwd))); - pdb_free_sam(&pwd); - continue; - } - - if (rid > max_rid) - max_rid = rid; - - DEBUG(1,("%d is user '%s'\n", rid, pdb_get_username(pwd))); - pdb_free_sam(&pwd); + if (search == NULL) { + d_printf("get_maxrid: Could not search %s\n", type); + return False; } - pdb_endsampwent(); - pdb_free_sam(&pwd); - - if (!pdb_enum_group_mapping(SID_NAME_UNKNOWN, &map, &num_entries, - ENUM_ONLY_MAPPED)) - return max_rid; - - for (i = 0; i < num_entries; i++) { - uint32 rid; + num_entries = pdb_search_entries(search, 0, 0xffffffff, &entries); + for (i=0; i max_rid) - max_rid = rid; - } + if (!search_maxrid(pdb_search_users(0), "users", &max_rid)) + return 0; - SAFE_FREE(map); + if (!search_maxrid(pdb_search_groups(), "groups", &max_rid)) + return 0; + if (!search_maxrid(pdb_search_aliases(get_global_sam_sid()), + "aliases", &max_rid)) + return 0; + return max_rid; } -- cgit