From 4ec9a782dc8b5d480daa8aa735b6a6fbe9d56ddf Mon Sep 17 00:00:00 2001 From: Tom Yu Date: Fri, 23 Aug 2002 18:03:56 +0000 Subject: [PATCH] * kdb_db2.h: Add prototype and rename for krb5_db2_db_iterate_ext(). * kdb_db2.c (krb5_db2_db_iterate_ext): New function; allow optional backwards or recursive (if btree) traversal of the database. * Makefile.in (LIBMINOR): Bump due to addition of krb5_db_iterate_ext(). git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@14755 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/kdb/ChangeLog | 12 ++++++++++++ src/lib/kdb/Makefile.in | 2 +- src/lib/kdb/kdb_db2.c | 38 ++++++++++++++++++++++++++++++++++---- src/lib/kdb/kdb_db2.h | 6 ++++++ 4 files changed, 53 insertions(+), 5 deletions(-) diff --git a/src/lib/kdb/ChangeLog b/src/lib/kdb/ChangeLog index a790596ad..2363ce5f7 100644 --- a/src/lib/kdb/ChangeLog +++ b/src/lib/kdb/ChangeLog @@ -1,3 +1,15 @@ +2002-08-23 Tom Yu + + * kdb_db2.h: Add prototype and rename for + krb5_db2_db_iterate_ext(). + + * kdb_db2.c (krb5_db2_db_iterate_ext): New function; allow + optional backwards or recursive (if btree) traversal of the + database. + + * Makefile.in (LIBMINOR): Bump due to addition of + krb5_db_iterate_ext(). + 2002-08-15 Tom Yu * keytab.c (krb5_ktkdb_get_entry): For consistency, check for diff --git a/src/lib/kdb/Makefile.in b/src/lib/kdb/Makefile.in index 854ddefac..21c65ca40 100644 --- a/src/lib/kdb/Makefile.in +++ b/src/lib/kdb/Makefile.in @@ -9,7 +9,7 @@ PROG_RPATH=$(KRB5_LIBDIR) LIB=kdb5 LIBMAJOR=3 -LIBMINOR=1 +LIBMINOR=2 RELDIR=kdb # Depends on libk5crypto and libkrb5 SHLIB_EXPDEPS = \ diff --git a/src/lib/kdb/kdb_db2.c b/src/lib/kdb/kdb_db2.c index 9c6e4fcef..c9c6e1f74 100644 --- a/src/lib/kdb/kdb_db2.c +++ b/src/lib/kdb/kdb_db2.c @@ -1119,10 +1119,11 @@ cleanup: } krb5_error_code -krb5_db2_db_iterate (context, func, func_arg) +krb5_db2_db_iterate_ext(context, func, func_arg, backwards, recursive) krb5_context context; krb5_error_code (*func) (krb5_pointer, krb5_db_entry *); krb5_pointer func_arg; + int backwards, recursive; { krb5_db2_context *db_ctx; DB *db; @@ -1131,17 +1132,31 @@ krb5_db2_db_iterate (context, func, func_arg) krb5_db_entry entries; krb5_error_code retval; int dbret; - + void *cookie; + + cookie = NULL; if (!k5db2_inited(context)) return KRB5_KDB_DBNOTINITED; db_ctx = (krb5_db2_context *) context->db_context; retval = krb5_db2_db_lock(context, KRB5_LOCKMODE_SHARED); + if (retval) return retval; db = db_ctx->db; - dbret = (*db->seq)(db, &key, &contents, R_FIRST); + if (recursive && db->type != DB_BTREE) { + (void)krb5_db2_db_unlock(context); + return KRB5_KDB_UK_RERROR; /* Not optimal, but close enough. */ + } + + if (!recursive) { + dbret = (*db->seq)(db, &key, &contents, + backwards ? R_LAST : R_FIRST); + } else { + dbret = bt_rseq(db, &key, &contents, &cookie, + backwards ? R_LAST : R_FIRST); + } while (dbret == 0) { contdata.data = contents.data; contdata.length = contents.size; @@ -1152,7 +1167,13 @@ krb5_db2_db_iterate (context, func, func_arg) krb5_dbe_free_contents(context, &entries); if (retval) break; - dbret = (*db->seq)(db, &key, &contents, R_NEXT); + if (!recursive) { + dbret = (*db->seq)(db, &key, &contents, + backwards ? R_PREV : R_NEXT); + } else { + dbret = bt_rseq(db, &key, &contents, &cookie, + backwards ? R_PREV : R_NEXT); + } } switch (dbret) { case 1: @@ -1166,6 +1187,15 @@ krb5_db2_db_iterate (context, func, func_arg) return retval; } +krb5_error_code +krb5_db2_db_iterate(context, func, func_arg) + krb5_context context; + krb5_error_code (*func) (krb5_pointer, krb5_db_entry *); + krb5_pointer func_arg; +{ + return krb5_db2_db_iterate_ext(context, func, func_arg, 0, 0); +} + krb5_boolean krb5_db2_db_set_lockmode(context, mode) krb5_context context; diff --git a/src/lib/kdb/kdb_db2.h b/src/lib/kdb/kdb_db2.h index 2d4d8e947..80f949596 100644 --- a/src/lib/kdb/kdb_db2.h +++ b/src/lib/kdb/kdb_db2.h @@ -41,6 +41,7 @@ #define krb5_db2_db_free_principal krb5_db_free_principal #define krb5_db2_db_put_principal krb5_db_put_principal #define krb5_db2_db_delete_principal krb5_db_delete_principal +#define krb5_db2_db_iterate_ext krb5_db_iterate_ext #define krb5_db2_db_iterate krb5_db_iterate #define krb5_db2_db_lock krb5_db_lock #define krb5_db2_db_unlock krb5_db_unlock @@ -104,6 +105,11 @@ krb5_error_code krb5_db2_db_put_principal (krb5_context, krb5_db_entry *, int * ); +krb5_error_code krb5_db2_db_iterate_ext + (krb5_context, + krb5_error_code (*) (krb5_pointer, + krb5_db_entry *), + krb5_pointer, int, int ); krb5_error_code krb5_db2_db_iterate (krb5_context, krb5_error_code (*) (krb5_pointer, -- 2.26.2