1 #include <sys/types.h>
2 #include <kerberos/krb.h>
3 #include <stdio.h>
4 #include <netdb.h>
5 #include <netinet/in.h>
6 #include <sys/file.h>
7 #include "register_proto.h"
8 
9 #define	KFILE	"update.key%s"
10 
11 main(argc, argv)
12 char	**argv;
13 {
14 	char		namebuf[255];
15 	int		fd;
16 	struct hostent	*hp;
17 	char		*addr;
18 	int		i;
19 	struct sockaddr_in	sin;
20 
21 	if(argc != 2) {
22 		usage(argv[0]);
23 		exit(1);
24 	}
25 
26 	hp = gethostbyname(argv[1]);
27 	for(i = 0; addr = hp->h_addr_list[i]; i++) {
28 		addr = hp->h_addr_list[i];
29 		bcopy(addr, &sin.sin_addr, hp->h_length);
30 
31 		printf("Making key for host %s (%s)\n",
32 			argv[1], inet_ntoa(sin.sin_addr));
33 		make_key(sin.sin_addr);
34 	}
35 	printf("==========\n");
36 	printf("One copy of the each key should be put in /kerberos on the\n");
37 	printf("Kerberos machine (mode 600, owner root).\n");
38 	printf("Another copy of each key should be put on the named\n");
39 	printf("client as /.update.keyXXX.XXX.XXX.XXX (same modes as above).\n");
40 	fflush(stdout);
41 }
42 
43 make_key(addr)
44 	struct in_addr	addr;
45 {
46 	struct keyfile_data	kfile;
47 	char		namebuf[255];
48 	int		fd;
49 
50 	sprintf(namebuf, KFILE, inet_ntoa(addr));
51 	fd = open(namebuf, O_WRONLY|O_CREAT, 0600);
52 	if(fd < 0) {
53 		perror("open");
54 		exit(1);
55 	}
56 	random_key(kfile.kf_key);
57 	if(write(fd, &kfile, sizeof(kfile)) != sizeof(kfile)) {
58 		fprintf(stderr, "error writing file %s\n", namebuf);
59 	}
60 	close(fd);
61 }
62 usage(name)
63 	char	*name;
64 {
65 	fprintf(stderr, "usage: %s host\n", name);
66 }
67