+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
}
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;
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;
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:
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;
#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
(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,