summaryrefslogtreecommitdiff
path: root/source3/utils
diff options
context:
space:
mode:
authorVolker Lendecke <vlendec@samba.org>2005-04-10 15:26:37 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 10:56:34 -0500
commit9f4c0afa0a3e359dfe9ac5dd8df0849b450a3fe1 (patch)
tree9ecaa05413c0bbd5c6f5372cee6bcfb0cf7894c4 /source3/utils
parent1875e46d05c21f4ca0e1163ecfd41b470dbce09a (diff)
downloadsamba-9f4c0afa0a3e359dfe9ac5dd8df0849b450a3fe1.tar.gz
samba-9f4c0afa0a3e359dfe9ac5dd8df0849b450a3fe1.tar.bz2
samba-9f4c0afa0a3e359dfe9ac5dd8df0849b450a3fe1.zip
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)
Diffstat (limited to 'source3/utils')
-rw-r--r--source3/utils/net.c72
1 files changed, 24 insertions, 48 deletions
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<num_entries; i++)
+ *max_rid = MAX(*max_rid, entries[i].rid);
+ pdb_search_destroy(search);
+ return True;
+}
- if (!sid_peek_check_rid(get_global_sam_sid(), &map[i].sid,
- &rid)) {
- DEBUG(3, ("skipping map for group '%s', SID %s\n",
- map[i].nt_name,
- sid_string_static(&map[i].sid)));
- continue;
- }
- DEBUG(1,("%d is group '%s'\n", rid, map[i].nt_name));
+static uint32 get_maxrid(void)
+{
+ uint32 max_rid = 0;
- if (rid > 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;
}