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