From 4cf846768003c75fae69dff6ec952efa5d47fceb Mon Sep 17 00:00:00 2001 From: John Kohl Date: Wed, 7 Feb 1990 17:46:52 +0000 Subject: [PATCH] #ifdef-out some of the varargs com_err stuff add some of the functions (incl. argument parsing) git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@310 dc483132-0cff-0310-8789-dd5450dbe970 --- src/kdc/main.c | 210 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 162 insertions(+), 48 deletions(-) diff --git a/src/kdc/main.c b/src/kdc/main.c index 71c10cb73..fdb10906d 100644 --- a/src/kdc/main.c +++ b/src/kdc/main.c @@ -19,20 +19,28 @@ static char rcsid_main_c[] = #include #include +#ifdef notdef #include /* XXX ansi? */ +#endif +#include +#include + #include #include +#include #include #include #include #include #include +#include + #include "kdc_util.h" #include "extern.h" -char *dbm_db_name = DEFAULT_DBM_FILE; - +#ifdef notdef +/* need to sort out varargs stuff */ static void kdc_com_err_proc(whoami, code, format, va_alist) char *whoami; @@ -62,6 +70,7 @@ va_dcl return; } +#endif void setup_com_err() @@ -70,71 +79,120 @@ setup_com_err() initialize_kdb5_error_table(); initialize_isod_error_table(); +#ifdef notdef (void) set_com_err_hook(kdc_com_err_proc); +#endif return; } -void -setup_signal_handlers() +sigtype +request_exit() { + signal_requests_exit = 1; return; } +void +setup_signal_handlers() +{ + signal(SIGINT, request_exit); + signal(SIGHUP, request_exit); + signal(SIGTERM, request_exit); -/* - outline: - - process args & setup - - initialize database access (fetch master key, open DB) - - initialize network - - loop: - listen for packet - - determine packet type, dispatch to handling routine - (AS or TGS (or V4?)) - - reflect response - - exit on signal - - clean up secrets, close db - - shut down network + return; +} - exit - */ +void +usage(name) +char *name; +{ + fprintf(stderr, "usage: %s [-d dbpathname] [-r dbrealmname] [-m] [-k masterkeytype] [-M masterkeyname]\n", name); + return; +} -main(argc, argv) +void +process_args(argc, argv) int argc; char **argv; { + int c; + krb5_boolean manual = FALSE; + int keytypedone = 0; + char *db_realm = 0; + char *mkey_name = 0; + char *mkey_fullname; + char lrealm[BUFSIZ]; krb5_error_code retval; - process_args(argc, argv); /* includes reading master key */ - - setup_com_err(); + extern int optind; + extern char *optarg; + + while (c = getopt(argc, argv, "r:d:mM:k:")) { + switch(c) { + case 'r': /* realm name for db */ + db_realm = optarg; + break; + case 'd': /* pathname for db */ + dbm_db_name = optarg; + break; + case 'm': /* manual type-in of master key */ + manual = TRUE; + break; + case 'M': /* master key name in DB */ + mkey_name = optarg; + break; + case 'k': /* keytype for master key */ + master_keyblock.keytype = atoi(optarg); + keytypedone++; + break; + case '?': + default: + usage(argv[0]); + exit(1); + } + } + if (!db_realm) { + /* no realm specified, use default realm */ + if (retval = krb5_get_default_realm(sizeof(lrealm), lrealm)) { + com_err(argv[0], retval, + "while attempting to retrieve default realm"); + exit(1); + } + db_realm = lrealm; + } + if (!mkey_name) + mkey_name = KRB5_KDB_M_NAME; - setup_signal_handlers(); + if (!keytypedone) + master_keyblock.keytype = KEYTYPE_DES; - openlog(argv[0], LOG_CONS|LOG_NDELAY, LOG_LOCAL0); /* XXX */ - syslog(LOG_INFO, "commencing operation"); + /* assemble & parse the master key name */ - if (retval = init_db(dbm_db_name, master_princ, master_keyblock)) { - com_err(argv[0], retval, "cannot initialize database"); + /* +2 for @ and null term */ + if (!(mkey_fullname = malloc(strlen(mkey_name) + strlen(db_realm) + 2))) { + com_err(argv[0], ENOMEM, + "while allocating storage for master key name"); exit(1); } - setup_network(); /* XXX */ - listen_and_process(); /* XXX */ - closedown_network(); /* XXX */ + (void) strcpy(mkey_fullname, mkey_name); + (void) strcat(mkey_fullname, "@"); + (void) strcat(mkey_fullname, db_realm); - closedown_db(); - exit(0); + if (retval = krb5_parse_name(mkey_fullname, &master_princ)) { + com_err(argv[0], retval, + ": parse of \"%s\" failed", mkey_fullname); + exit(1); + } + + if (retval = krb5_db_fetch_mkey(master_princ, &master_encblock, manual, + &master_keyblock)) { + com_err(argv[0], retval, "while fetching master key"); + } + return; } + krb5_error_code init_db(dbname, masterkeyname, masterkeyblock) char *dbname; @@ -163,6 +221,7 @@ krb5_keyblock *masterkeyblock; if (retval = (*master_encblock.crypto_entry-> process_key)(&master_encblock, masterkeyblock)) { master_encblock.crypto_entry = 0; + (void) krb5_db_fini(); return(retval); } @@ -175,13 +234,68 @@ 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)); + retval = (*master_encblock.crypto_entry->finish_key)(&master_encblock); + + bzero((char *)&master_encblock, sizeof(master_encblock)); /* close database */ - if (retval = krb5_db_fini()) - return(retval); + if (retval) { + (void) krb5_db_fini(); + return retval; + } else + return (krb5_db_fini()); +} - return 0; +/* + outline: + + process args & setup + + initialize database access (fetch master key, open DB) + + initialize network + + loop: + listen for packet + + determine packet type, dispatch to handling routine + (AS or TGS (or V4?)) + + reflect response + + exit on signal + + clean up secrets, close db + + shut down network + + exit + */ + +main(argc, argv) +int argc; +char **argv; +{ + krb5_error_code retval; + + setup_com_err(); + + process_args(argc, argv); /* includes reading master key */ + + 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); } + -- 2.26.2