1 /* 2 * Copyright (c) 1989 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that the above copyright notice and this paragraph are 7 * duplicated in all such forms and that any documentation, 8 * advertising materials, and other materials related to such 9 * distribution and use acknowledge that the software was developed 10 * by the University of California, Berkeley. The name of the 11 * University may not be used to endorse or promote products derived 12 * from this software without specific prior written permission. 13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16 */ 17 18 #ifndef lint 19 static char sccsid[] = "@(#)make_keypair.c 1.4 (Berkeley) 08/21/89"; 20 #endif /* not lint */ 21 22 #include <sys/types.h> 23 #include <krb.h> 24 #include <stdio.h> 25 #include <netdb.h> 26 #include <netinet/in.h> 27 #include <sys/file.h> 28 #include "pathnames.h" 29 #include "register_proto.h" 30 31 main(argc, argv) 32 char **argv; 33 { 34 char namebuf[255]; 35 int fd; 36 struct hostent *hp; 37 char *addr; 38 int i; 39 struct sockaddr_in sin; 40 41 if(argc != 2) { 42 usage(argv[0]); 43 exit(1); 44 } 45 46 hp = gethostbyname(argv[1]); 47 for (i = 0; addr = hp->h_addr_list[i]; i++) { 48 addr = hp->h_addr_list[i]; 49 bcopy(addr, &sin.sin_addr, hp->h_length); 50 51 printf("Making key for host %s (%s)\n", 52 argv[1], inet_ntoa(sin.sin_addr)); 53 make_key(sin.sin_addr); 54 } 55 printf("==========\n"); 56 printf("One copy of the each key should be put in %s on the\n", 57 SERVER_KEYDIR); 58 printf("Kerberos server machine (mode 600, owner root).\n"); 59 printf("Another copy of each key should be put on the named\n"); 60 printf("client as %sXXX.XXX.XXX.XXX (same modes as above),\n", 61 CLIENT_KEYFILE); 62 printf("where the X's refer to digits of the host's inet address.\n"); 63 fflush(stdout); 64 } 65 66 make_key(addr) 67 struct in_addr addr; 68 { 69 struct keyfile_data kfile; 70 char namebuf[255]; 71 int fd; 72 73 sprintf(namebuf, ".%s%s", 74 CLIENT_KEYFILE, 75 inet_ntoa(addr)); 76 fd = open(namebuf, O_WRONLY|O_CREAT, 0600); 77 if (fd < 0) { 78 perror("open"); 79 exit(1); 80 } 81 random_key(kfile.kf_key); 82 printf("writing to file -> %s ...", namebuf); 83 if (write(fd, &kfile, sizeof(kfile)) != sizeof(kfile)) { 84 fprintf(stderr, "error writing file %s\n", namebuf); 85 } 86 printf("done.\n"); 87 close(fd); 88 } 89 usage(name) 90 char *name; 91 { 92 fprintf(stderr, "usage: %s host\n", name); 93 } 94