* kdb_db2.h: Add prototype and rename for
authorTom Yu <tlyu@mit.edu>
Fri, 23 Aug 2002 18:03:56 +0000 (18:03 +0000)
committerTom Yu <tlyu@mit.edu>
Fri, 23 Aug 2002 18:03:56 +0000 (18:03 +0000)
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
src/lib/kdb/Makefile.in
src/lib/kdb/kdb_db2.c
src/lib/kdb/kdb_db2.h

index a790596ad1e9118ab6c64b5ca6e2c13e0f7ef38c..2363ce5f7456f069a60350d7ef72e803018d0d3c 100644 (file)
@@ -1,3 +1,15 @@
+2002-08-23  Tom Yu  <tlyu@mit.edu>
+
+       * 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  <tlyu@mit.edu>
 
        * keytab.c (krb5_ktkdb_get_entry): For consistency, check for
index 854ddefac8494b5ab21e01211a4d9a13c6412d12..21c65ca40e5fd134cf6a8fea64f2a43899d88990 100644 (file)
@@ -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 = \
index 9c6e4fcef8356ba1eb84b6d84e00286cbaa3c044..c9c6e1f7450dc710903933714c97e258102f094e 100644 (file)
@@ -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;
index 2d4d8e94785e198097405b2979d4b5270c49a886..80f9495964208a091ab21b4ac138dc1c835e0f32 100644 (file)
@@ -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,