home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / kerberosIV / kstash / kstash.c next >
Encoding:
C/C++ Source or Header  |  1990-06-25  |  2.1 KB  |  98 lines

  1. /*
  2.  * $Source: /usr/src/kerberosIV/kstash/RCS/kstash.c,v $
  3.  * $Author: kfall $
  4.  *
  5.  * Copyright 1985, 1986, 1987, 1988 by the Massachusetts Institute
  6.  * of Technology 
  7.  *
  8.  * For copying and distribution information, please see the file
  9.  * <mit-copyright.h>.
  10.  *
  11.  * Description.
  12.  */
  13.  
  14. #ifndef    lint
  15. static char rcsid_kstash_c[] =
  16. "$Header: /usr/src/kerberosIV/kstash/RCS/kstash.c,v 4.1 90/06/25 21:33:13 kfall Exp $";
  17. #endif    lint
  18.  
  19. #include <mit-copyright.h>
  20.  
  21. #include <stdio.h>
  22. #include <sys/types.h>
  23. #include <sys/socket.h>
  24. #include <netinet/in.h>
  25. #include <netdb.h>
  26. #include <signal.h>
  27. #include <sgtty.h>
  28. #include <sys/ioctl.h>
  29. #include <sys/time.h>
  30. #include <sys/file.h>
  31.  
  32. #include <des.h>
  33. #include <krb.h>
  34. #include <klog.h>
  35. #include <prot.h>
  36. #include <krb_db.h>
  37. #include <kdc.h>
  38.  
  39. extern int errno;
  40.  
  41. /* change this later, but krblib_dbm needs it for now */
  42. char   *progname;
  43.  
  44. static C_Block master_key;
  45. static Key_schedule master_key_schedule;
  46. static Principal s_name_data;    /* for services requested */
  47. static unsigned char master_key_version;
  48. int     debug;
  49. static int more;
  50. static int kfile;
  51. static void clear_secrets();
  52.  
  53. main(argc, argv)
  54.     int     argc;
  55.     char  **argv;
  56. {
  57.     long    n;
  58.     if (n = kerb_init()) {
  59.     fprintf(stderr, "Kerberos db and cache init failed = %d\n", n);
  60.     exit(1);
  61.     }
  62.  
  63.     if (kdb_get_master_key (TRUE, master_key, master_key_schedule) != 0) {
  64.       fprintf (stderr, "%s: Couldn't read master key.\n", argv[0]);
  65.       fflush (stderr);
  66.       clear_secrets();
  67.       exit (-1);
  68.     }
  69.  
  70.     if (kdb_verify_master_key (master_key, master_key_schedule, stderr) < 0) {
  71.       clear_secrets();
  72.       exit (-1);
  73.     }
  74.  
  75.     kfile = open(MKEYFILE, O_TRUNC | O_RDWR | O_CREAT, 0600);
  76.     if (kfile < 0) {
  77.     clear_secrets();
  78.     fprintf(stderr, "\n\07\07%s: Unable to open master key file\n",
  79.         argv[0]);
  80.     exit(1);
  81.     }
  82.     if (write(kfile, (char *) master_key, 8) < 0) {
  83.     clear_secrets();
  84.     fprintf(stderr, "\n%s: Write I/O error on master key file\n",
  85.         argv[0]);
  86.     exit(1);
  87.     }
  88.     (void) close(kfile);
  89.     clear_secrets();
  90. }
  91.  
  92. static void 
  93. clear_secrets()
  94. {
  95.     bzero(master_key_schedule, sizeof(master_key_schedule));
  96.     bzero(master_key, sizeof(master_key));
  97. }
  98.