diff options
author | Volker Lendecke <vlendec@samba.org> | 2006-08-08 13:54:43 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 11:38:35 -0500 |
commit | 21da07ba1fdbef9d8fadfb9bf9fa23afc0a665d1 (patch) | |
tree | a865f0c7630a42d0c565a73da8b483a18210a0d2 /source3/lib | |
parent | 72c605b4fc518b498688ec032004fded0d2250d7 (diff) | |
download | samba-21da07ba1fdbef9d8fadfb9bf9fa23afc0a665d1.tar.gz samba-21da07ba1fdbef9d8fadfb9bf9fa23afc0a665d1.tar.bz2 samba-21da07ba1fdbef9d8fadfb9bf9fa23afc0a665d1.zip |
r17457: Add a test to do some operations on group mapping.
Volker
(This used to be commit 68db058fdf508d5b4d38731ece21f5d92feca00c)
Diffstat (limited to 'source3/lib')
-rw-r--r-- | source3/lib/tdb_multikey.c | 59 |
1 files changed, 57 insertions, 2 deletions
diff --git a/source3/lib/tdb_multikey.c b/source3/lib/tdb_multikey.c index 77e63c5aaa..e8febd6f7b 100644 --- a/source3/lib/tdb_multikey.c +++ b/source3/lib/tdb_multikey.c @@ -34,7 +34,7 @@ static struct { enum TDB_ERROR t; NTSTATUS n; } tdb_to_ntstatus_map[] = { { 0, NT_STATUS_OK }, }; -static NTSTATUS map_ntstatus_from_tdb(struct tdb_context *t) +NTSTATUS map_ntstatus_from_tdb(struct tdb_context *t) { enum TDB_ERROR err = tdb_error(t); int i = 0; @@ -474,7 +474,7 @@ NTSTATUS tdb_update_keyed(struct tdb_context *tdb, const char *primary_key, if ((primary_key == NULL) || (strlen(primary_key) != PRIMARY_KEY_LENGTH) || - (strncmp(primary_key, "KEYPRIM/", 7) != 0)) { + (strncmp(primary_key, "KEYPRIM/", 8) != 0)) { return NT_STATUS_INVALID_PARAMETER; } @@ -528,3 +528,58 @@ NTSTATUS tdb_update_keyed(struct tdb_context *tdb, const char *primary_key, return status; } + +static int iterator_destructor(void *p) +{ + struct tdb_keyed_iterator *i = (struct tdb_keyed_iterator *)p; + SAFE_FREE(i->key.dptr); + return 0; +} + +struct tdb_keyed_iterator *tdb_enum_keyed(TALLOC_CTX *mem_ctx, + struct tdb_context *tdb) +{ + struct tdb_keyed_iterator *result = TALLOC_P( + mem_ctx, struct tdb_keyed_iterator); + + if (result == NULL) { + DEBUG(0, ("talloc failed\n")); + return result; + } + + result->tdb = tdb; + result->key = tdb_firstkey(tdb); + talloc_set_destructor(result, iterator_destructor); + return result; +} + +BOOL tdb_next_keyed(struct tdb_keyed_iterator *it, TDB_DATA *data) +{ + if (it->key.dptr == NULL) { + return False; + } + + while (True) { + TDB_DATA tmp; + + if ((it->key.dsize == PRIMARY_KEY_LENGTH+1) && + (strncmp(it->key.dptr, "KEYPRIM/", 8) == 0)) { + + *data = tdb_fetch(it->tdb, it->key); + + tmp = tdb_nextkey(it->tdb, it->key); + SAFE_FREE(it->key.dptr); + it->key = tmp; + + return (data->dptr != NULL); + } + + tmp = tdb_nextkey(it->tdb, it->key); + SAFE_FREE(it->key.dptr); + it->key = tmp; + + if (it->key.dptr == NULL) { + return False; + } + } +} |