From: John Kohl Date: Tue, 6 Feb 1990 16:29:56 +0000 (+0000) Subject: add lots of stuff X-Git-Tag: krb5-1.0-alpha2~1093 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=fc9bcae06e2992c11e54e9497abd1a9be235af5e;p=krb5.git add lots of stuff git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@291 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/kdc/main.c b/src/kdc/main.c index b652e2b39..71c10cb73 100644 --- a/src/kdc/main.c +++ b/src/kdc/main.c @@ -17,9 +17,76 @@ static char rcsid_main_c[] = #include +#include +#include +#include /* XXX ansi? */ +#include + +#include +#include +#include +#include +#include +#include +#include "kdc_util.h" +#include "extern.h" + +char *dbm_db_name = DEFAULT_DBM_FILE; + +static void +kdc_com_err_proc(whoami, code, format, va_alist) +char *whoami; +long code; +char *format; +va_dcl +{ + /* XXX need some way to do this better... */ + + if (whoami) { + fputs(whoami, stderr); + fputs(": ", stderr); + } + if (code) { + fputs(error_message(code), stderr); + fputs(" ", stderr); + } + if (format) { + fprintf (stderr, format, va_alist); + } + putc('\n', stderr); + /* should do this only on a tty in raw mode */ + putc('\r', stderr); + fflush(stderr); + + syslog(LOG_ERR, format, va_alist); + + return; +} + +void +setup_com_err() +{ + initialize_krb5_error_table(); + initialize_kdb5_error_table(); + initialize_isod_error_table(); + + (void) set_com_err_hook(kdc_com_err_proc); + return; +} + +void +setup_signal_handlers() +{ + + return; +} + + /* outline: + process args & setup + initialize database access (fetch master key, open DB) initialize network @@ -34,13 +101,40 @@ static char rcsid_main_c[] = exit on signal - clean up secrets + clean up secrets, close db shut down network exit */ +main(argc, argv) +int argc; +char **argv; +{ + krb5_error_code retval; + + process_args(argc, argv); /* includes reading master key */ + + setup_com_err(); + + setup_signal_handlers(); + + openlog(argv[0], LOG_CONS|LOG_NDELAY, LOG_LOCAL0); /* XXX */ + syslog(LOG_INFO, "commencing operation"); + + if (retval = init_db(dbm_db_name, master_princ, master_keyblock)) { + com_err(argv[0], retval, "cannot initialize database"); + exit(1); + } + setup_network(); /* XXX */ + listen_and_process(); /* XXX */ + closedown_network(); /* XXX */ + + closedown_db(); + exit(0); +} + krb5_error_code init_db(dbname, masterkeyname, masterkeyblock) char *dbname; @@ -48,7 +142,6 @@ krb5_principal masterkeyname; krb5_keyblock *masterkeyblock; { krb5_error_code retval; - krb5_db_entry master_entry; /* set db name if appropriate */ if (dbname && (retval = krb5_db_set_name(dbname))) @@ -58,19 +151,37 @@ krb5_keyblock *masterkeyblock; if (retval = krb5_db_init()) return(retval); - master_encblock.crypto_entry = &krb5_des_cs_entry; + master_encblock.crypto_entry = &krb5_des_cs_entry; /* XXX */ - if (retval = krb5_db_verify_master_key(masterkeyname, masterkeyblock)) { + if (retval = krb5_db_verify_master_key(masterkeyname, masterkeyblock, + &master_encblock)) { master_encblock.crypto_entry = 0; return(retval); } /* do any necessary key pre-processing */ if (retval = (*master_encblock.crypto_entry-> - process_key)(&eblock, masterkeyblock)) { + process_key)(&master_encblock, masterkeyblock)) { master_encblock.crypto_entry = 0; return(retval); } return 0; } + +krb5_error_code +closedown_db() +{ + krb5_error_code retval; + + /* clean up master key stuff */ + if (retval = (*master_encblock.crypto_entry->finish_key)(&master_encblock)) + return retval; + bzero(&master_encblock, sizeof(master_encblock)); + + /* close database */ + if (retval = krb5_db_fini()) + return(retval); + + return 0; +}