fix some code in the db restart code
authorJohn Kohl <jtkohl@mit.edu>
Tue, 8 May 1990 17:51:04 +0000 (17:51 +0000)
committerJohn Kohl <jtkohl@mit.edu>
Tue, 8 May 1990 17:51:04 +0000 (17:51 +0000)
add list_db.

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@791 dc483132-0cff-0310-8789-dd5450dbe970

src/admin/edit/kdb5_edit.c

index a72908c4a6a4ea1c560335e956010d35929d2ce9..5970ecbb828dfff30db6458ec25b5f82969b0a32 100644 (file)
@@ -80,6 +80,7 @@ static char *progname;
 static char *cur_realm = 0;
 static char *mkey_name = 0;
 static krb5_boolean manual_mkey = FALSE;
+static krb5_boolean dbactive = FALSE;
 
 void
 quit()
@@ -370,13 +371,16 @@ krb5_pointer infop;
        com_err(argv[0], 0, "Usage: set_dbname dbpathname realmname");
        return;
     }
-    if ((retval = krb5_db_fini()) && retval != KRB5_KDB_DBNOTINITED) {
-       com_err(argv[0], retval, "while closing previous database");
-       return;
+    if (dbactive) {
+       if ((retval = krb5_db_fini()) && retval != KRB5_KDB_DBNOTINITED) {
+           com_err(argv[0], retval, "while closing previous database");
+           return;
+       }
+       (void) (*csentry->finish_key)(&master_encblock);
+       (void) (*csentry->finish_random_key)(&master_random);
+       krb5_free_principal(master_princ);
+       dbactive = FALSE;
     }
-    (void) (*csentry->finish_key)(&master_encblock);
-    (void) (*csentry->finish_random_key)(&master_random);
-    krb5_free_principal(master_princ);
     cur_realm = malloc(strlen(argv[2])+1);
     if (!cur_realm) {
        com_err(argv[0], 0, "Insufficient memory to proceed");
@@ -466,6 +470,7 @@ char *dbname;
     mblock.mkvno = master_entry.kvno;
 
     krb5_db_free_principal(&master_entry, nentries);
+    dbactive = TRUE;
     return 0;
 }
 
@@ -580,3 +585,30 @@ char *argv[];
        com_err(argv[0], retval, "while closing keytab");
     return;
 }
+
+krb5_error_code
+list_iterator(ptr, entry)
+krb5_pointer ptr;
+krb5_db_entry *entry;
+{
+    krb5_error_code retval;
+    char *comerrname = (char *)ptr;
+    char *name;
+
+    if (retval = krb5_unparse_name(entry->principal, &name)) {
+       com_err(comerrname, retval, "while unparsing principal");
+       return retval;
+    }
+    printf("entry: %s\n", name);
+    free(name);
+    return 0;
+}
+
+/*ARGSUSED*/
+void
+list_db(argc, argv)
+int argc;
+char *argv[];
+{
+    (void) krb5_db_iterate(list_iterator, argv[0]);
+}