1 /*- 2 * Copyright (c) 1988, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char copyright[] = 10 "@(#) Copyright (c) 1988, 1993\n\ 11 The Regents of the University of California. All rights reserved.\n"; 12 #endif /* not lint */ 13 14 #ifndef lint 15 static char sccsid[] = "@(#)make_keypair.c 8.1 (Berkeley) 06/01/93"; 16 #endif /* not lint */ 17 18 #include <sys/types.h> 19 #include <sys/file.h> 20 #include <netinet/in.h> 21 #include <stdio.h> 22 #include <netdb.h> 23 #include <kerberosIV/des.h> 24 #include <kerberosIV/krb.h> 25 #include "pathnames.h" 26 #include "register_proto.h" 27 28 extern void random_key(), herror(); 29 void make_key(), usage(); 30 31 main(argc, argv) 32 int argc; 33 char **argv; 34 { 35 struct hostent *hp; 36 char *addr; 37 int i; 38 struct sockaddr_in sin; 39 40 if (argc != 2) { 41 usage(argv[0]); 42 exit(1); 43 } 44 45 if ((hp = gethostbyname(argv[1])) == NULL) { 46 herror(argv[1]); 47 exit(1); 48 } 49 50 for (i = 0; addr = hp->h_addr_list[i]; i++) { 51 addr = hp->h_addr_list[i]; 52 bcopy(addr, &sin.sin_addr, hp->h_length); 53 54 printf("Making key for host %s (%s)\n", 55 argv[1], inet_ntoa(sin.sin_addr)); 56 make_key(sin.sin_addr); 57 } 58 printf("==========\n"); 59 printf("One copy of the each key should be put in %s on the\n", 60 SERVER_KEYDIR); 61 printf("Kerberos server machine (mode 600, owner root).\n"); 62 printf("Another copy of each key should be put on the named\n"); 63 printf("client as %sXXX.XXX.XXX.XXX (same modes as above),\n", 64 CLIENT_KEYFILE); 65 printf("where the X's refer to digits of the host's inet address.\n"); 66 (void)fflush(stdout); 67 exit(0); 68 } 69 70 void 71 make_key(addr) 72 struct in_addr addr; 73 { 74 struct keyfile_data kfile; 75 char namebuf[255]; 76 int fd; 77 78 (void)sprintf(namebuf, ".%s%s", 79 CLIENT_KEYFILE, 80 inet_ntoa(addr)); 81 fd = open(namebuf, O_WRONLY|O_CREAT, 0600); 82 if (fd < 0) { 83 perror("open"); 84 exit(1); 85 } 86 random_key(kfile.kf_key); 87 printf("writing to file -> %s ...", namebuf); 88 if (write(fd, &kfile, sizeof(kfile)) != sizeof(kfile)) { 89 fprintf(stderr, "error writing file %s\n", namebuf); 90 } 91 printf("done.\n"); 92 (void)close(fd); 93 return; 94 } 95 96 void 97 usage(name) 98 char *name; 99 { 100 fprintf(stderr, "usage: %s host\n", name); 101 } 102