summaryrefslogtreecommitdiff
path: root/kerberosIV/kstash
diff options
context:
space:
mode:
authorArtur Grabowski <art@cvs.openbsd.org>1997-12-17 11:26:53 +0000
committerArtur Grabowski <art@cvs.openbsd.org>1997-12-17 11:26:53 +0000
commit5153e9f1e09cfad14b3dc139258314330261d520 (patch)
tree7dbb67f01f78b3239086f95f5a0291b55eddecb0 /kerberosIV/kstash
parent2e9a156b058ee8b38cef763f7e8d87bc994a55c6 (diff)
another upgrade.
Diffstat (limited to 'kerberosIV/kstash')
-rw-r--r--kerberosIV/kstash/kstash.c59
1 files changed, 25 insertions, 34 deletions
diff --git a/kerberosIV/kstash/kstash.c b/kerberosIV/kstash/kstash.c
index 492619ac23d..9863709f33b 100644
--- a/kerberosIV/kstash/kstash.c
+++ b/kerberosIV/kstash/kstash.c
@@ -1,8 +1,8 @@
-/* $Id: kstash.c,v 1.1 1995/12/14 06:52:41 tholo Exp $ */
+/* $KTH: kstash.c,v 1.10 1997/03/30 17:35:37 assar Exp $ */
/*-
* Copyright 1987, 1988 by the Student Information Processing Board
- * of the Massachusetts Institute of Technology
+ * of the Massachusetts Institute of Technology
*
* Permission to use, copy, modify, and distribute this software
* and its documentation for any purpose and without fee is
@@ -17,57 +17,48 @@
* provided "as is" without express or implied warranty.
*/
-#include <adm_locl.h>
+#include "adm_locl.h"
/* change this later, but krblib_dbm needs it for now */
-char *progname;
static des_cblock master_key;
static des_key_schedule master_key_schedule;
-static int kfile;
static void
clear_secrets(void)
{
- bzero(master_key_schedule, sizeof(master_key_schedule));
- bzero(master_key, sizeof(master_key));
+ memset(master_key_schedule, 0, sizeof(master_key_schedule));
+ memset(master_key, 0, sizeof(master_key));
}
+static char progname[] = "kstash";
+
int
main(int argc, char **argv)
{
long n;
- if ((n = kerb_init())) {
- fprintf(stderr, "Kerberos db and cache init failed = %ld\n", n);
- exit(1);
- }
+ int ret = 0;
+
+ if (atexit(clear_secrets))
+ errx(1, "Out of resources\n");
- if (kdb_get_master_key (TRUE, &master_key, master_key_schedule) != 0) {
- fprintf (stderr, "%s: Couldn't read master key.\n", argv[0]);
- fflush (stderr);
- clear_secrets();
- exit (-1);
+ if ((n = kerb_init()))
+ errx(1, "Kerberos db and cache init failed = %ld\n", n);
+
+ if (kdb_get_master_key (KDB_GET_PROMPT, &master_key,
+ master_key_schedule) != 0) {
+ errx(1, "Couldn't read master key.");
}
if (kdb_verify_master_key (&master_key, master_key_schedule, stderr) < 0) {
- clear_secrets();
- exit (-1);
+ return 1;
}
- kfile = open(MKEYFILE, O_TRUNC | O_RDWR | O_CREAT, 0600);
- if (kfile < 0) {
- clear_secrets();
- fprintf(stderr, "\n\07\07%s: Unable to open master key file\n",
- argv[0]);
- exit(1);
- }
- if (write(kfile, (char *) master_key, 8) < 0) {
- clear_secrets();
- fprintf(stderr, "\n%s: Write I/O error on master key file\n",
- argv[0]);
- exit(1);
- }
- (void) close(kfile);
- clear_secrets();
- exit(0);
+ ret = kdb_kstash(&master_key, MKEYFILE);
+ if(ret < 0)
+ warn("writing master key");
+ else
+ fprintf(stderr, "Wrote master key to %s\n", MKEYFILE);
+
+ return ret;
}