From 5067669d48daed75e155874929629b8a67f5c92a Mon Sep 17 00:00:00 2001 From: Paul Park Date: Thu, 17 Aug 1995 17:54:56 +0000 Subject: [PATCH] Add routines to open and close the database git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@6544 dc483132-0cff-0310-8789-dd5450dbe970 --- src/kadmin/v5server/kadm5_defs.h | 2 ++ src/kadmin/v5server/srv_key.c | 41 ++++++++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/kadmin/v5server/kadm5_defs.h b/src/kadmin/v5server/kadm5_defs.h index b2bfbf9cf..96200beec 100644 --- a/src/kadmin/v5server/kadm5_defs.h +++ b/src/kadmin/v5server/kadm5_defs.h @@ -150,6 +150,8 @@ krb5_error_code key_update_tl_attrs krb5_db_entry *, krb5_principal, krb5_boolean)); +krb5_error_code key_open_db KRB5_PROTOTYPE((krb5_context)); +krb5_error_code key_close_db KRB5_PROTOTYPE((krb5_context)); /* srv_acl.c */ krb5_error_code acl_init diff --git a/src/kadmin/v5server/srv_key.c b/src/kadmin/v5server/srv_key.c index d38eed7c9..1450f6ce3 100644 --- a/src/kadmin/v5server/srv_key.c +++ b/src/kadmin/v5server/srv_key.c @@ -67,6 +67,7 @@ static const char *key_vmast_key_fmt = "%s: cannot verify master key (%s).\n"; static const char *key_key_pp_fmt = "%s: cannot preprocess key (%s).\n"; static const char *key_rkey_fmt = "%s: cannot initialize random key generator (%s).\n"; static const char *key_getm_fmt = "%s: cannot get master entry (%s).\n"; +static const char *key_nomem_fmt = "%s: cannot get memory for string %s.\n"; static int mprinc_init = 0; static krb5_principal master_principal; @@ -101,6 +102,8 @@ static krb5_key_salt_tuple default_ktent = { KEYTYPE_DES, KRB5_KDB_SALTTYPE_NORMAL }; +static char *key_db_name = (char *) NULL; + static int key_debug_level = 0; extern char *programname; @@ -418,10 +421,16 @@ key_init(kcontext, debug_level, enc_type, key_type, master_key_name, manual, ("- initializing for realm %s\n", master_realm)); /* Set database name if supplied */ - if (db_file && (kret = krb5_db_set_name(kcontext, db_file))) { - fprintf(stderr, key_bad_name_fmt, programname, db_file, - error_message(kret)); - goto leave; + if (db_file) { + if (!(key_db_name = strdup(db_file))) { + fprintf(stderr, key_nomem_fmt, programname, db_file); + goto leave; + } + if ((kret = krb5_db_set_name(kcontext, db_file))) { + fprintf(stderr, key_bad_name_fmt, programname, db_file, + error_message(kret)); + goto leave; + } } /* Initialize database */ @@ -573,8 +582,11 @@ key_init(kcontext, debug_level, enc_type, key_type, master_key_name, manual, key_free_key_data(madmin_keys, madmin_num_keys); madmin_key_init = 0; } + if (key_db_name) + free(key_db_name); } leave: + krb5_db_fini(kcontext); DPRINT(DEBUG_CALLS, key_debug_level, ("X key_init() = %d\n", kret)); return(kret); } @@ -624,6 +636,8 @@ key_finish(kcontext, debug_level) key_free_key_data(madmin_keys, madmin_num_keys); madmin_key_init = 0; } + if (key_db_name) + free(key_db_name); krb5_db_fini(kcontext); /* memset((char *) tgs_key.contents, 0, tgs_key.length); */ DPRINT(DEBUG_CALLS, key_debug_level, ("X key_finish()\n")); @@ -1333,3 +1347,22 @@ key_update_tl_attrs(kcontext, dbentp, mod_name, is_pwchg) return(kret); } + +krb5_error_code +key_open_db(kcontext) + krb5_context kcontext; +{ + krb5_error_code kret; + + if (!(key_db_name) || !(kret = krb5_db_set_name(kcontext, key_db_name))) { + kret = krb5_db_init(kcontext); + } + return(kret); +} + +krb5_error_code +key_close_db(kcontext) + krb5_context kcontext; +{ + return(krb5_db_fini(kcontext)); +} -- 2.26.2