svn rev #24142: trunk/src/kadmin/dbutil/

ghudson@MIT.EDU ghudson at MIT.EDU
Mon Jun 21 16:29:12 EDT 2010


http://src.mit.edu/fisheye/changelog/krb5/?cs=24142
Commit By: ghudson
Log Message:
Eliminate a bunch of duplicated code in kdb5_stash() by using
util_context.



Changed Files:
U   trunk/src/kadmin/dbutil/kdb5_stash.c
Modified: trunk/src/kadmin/dbutil/kdb5_stash.c
===================================================================
--- trunk/src/kadmin/dbutil/kdb5_stash.c	2010-06-21 19:56:29 UTC (rev 24141)
+++ trunk/src/kadmin/dbutil/kdb5_stash.c	2010-06-21 20:29:12 UTC (rev 24142)
@@ -78,28 +78,11 @@
     int optchar;
     krb5_error_code retval;
     char *dbname = (char *) NULL;
-    char *realm = 0;
     char *mkey_name = 0;
-    char *mkey_fullname;
     char *keyfile = 0;
-    krb5_context context;
     krb5_kvno mkey_kvno;
 
-    retval = kadm5_init_krb5_context(&context);
-    if( retval )
-    {
-        com_err(progname, retval, "while initializing krb5_context");
-        exit(1);
-    }
-
-    if ((retval = krb5_set_default_realm(context,
-                                         util_context->default_realm))) {
-        com_err(progname, retval, "while setting default realm name");
-        exit(1);
-    }
-
     dbname = global_params.dbname;
-    realm = global_params.realm;
     mkey_name = global_params.mkey_name;
     keyfile = global_params.stash_file;
 
@@ -127,22 +110,6 @@
         exit_status++; return;
     }
 
-    /* assemble & parse the master key name */
-    retval = krb5_db_setup_mkey_name(context, mkey_name, realm,
-                                     &mkey_fullname, &master_princ);
-    if (retval) {
-        com_err(progname, retval, "while setting up master key name");
-        exit_status++; return;
-    }
-
-    retval = krb5_db_open(context, db5util_db_args,
-                          KRB5_KDB_OPEN_RW | KRB5_KDB_SRV_TYPE_ADMIN);
-    if (retval) {
-        com_err(progname, retval, "while initializing the database '%s'",
-                dbname);
-        exit_status++; return;
-    }
-
     if (global_params.mask & KADM5_CONFIG_KVNO)
         mkey_kvno = global_params.kvno; /* user specified */
     else
@@ -150,44 +117,39 @@
 
     if (!valid_master_key) {
         /* TRUE here means read the keyboard, but only once */
-        retval = krb5_db_fetch_mkey(context, master_princ,
+        retval = krb5_db_fetch_mkey(util_context, master_princ,
                                     master_keyblock.enctype,
                                     TRUE, FALSE, (char *) NULL,
                                     &mkey_kvno,
                                     NULL, &master_keyblock);
         if (retval) {
             com_err(progname, retval, "while reading master key");
-            (void) krb5_db_fini(context);
             exit_status++; return;
         }
 
-        retval = krb5_db_fetch_mkey_list(context, master_princ,
+        retval = krb5_db_fetch_mkey_list(util_context, master_princ,
                                          &master_keyblock, mkey_kvno,
                                          &master_keylist);
         if (retval) {
             com_err(progname, retval, "while getting master key list");
-            (void) krb5_db_fini(context);
             exit_status++; return;
         }
     } else {
         printf("Using existing stashed keys to update stash file.\n");
     }
 
-    retval = krb5_db_store_master_key_list(context, keyfile, master_princ,
+    retval = krb5_db_store_master_key_list(util_context, keyfile, master_princ,
                                            master_keylist, NULL);
     if (retval) {
         com_err(progname, errno, "while storing key");
-        (void) krb5_db_fini(context);
         exit_status++; return;
     }
 
-    retval = krb5_db_fini(context);
     if (retval) {
         com_err(progname, retval, "closing database '%s'", dbname);
         exit_status++; return;
     }
 
-    krb5_free_context(context);
     exit_status = 0;
     return;
 }




More information about the cvs-krb5 mailing list