add lots of stuff
authorJohn Kohl <jtkohl@mit.edu>
Tue, 6 Feb 1990 16:29:56 +0000 (16:29 +0000)
committerJohn Kohl <jtkohl@mit.edu>
Tue, 6 Feb 1990 16:29:56 +0000 (16:29 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@291 dc483132-0cff-0310-8789-dd5450dbe970

src/kdc/main.c

index b652e2b39d3141fb30e44ec3c4b43ec29b5be6f5..71c10cb73ab9143a7dd1c64042e48b8a85fbe204 100644 (file)
@@ -17,9 +17,76 @@ static char rcsid_main_c[] =
 
 #include <krb5/copyright.h>
 
+#include <stdio.h>
+#include <syslog.h>
+#include <varargs.h>                   /* XXX ansi? */
+#include <com_err.h>
+
+#include <krb5/krb5.h>
+#include <krb5/kdb.h>
+#include <krb5/kdb_dbm.h>
+#include <krb5/krb5_err.h>
+#include <krb5/isode_err.h>
+#include <krb5/kdb5_err.h>
+#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;
+}