147881Sbostic /*-
2*60962Sbostic * Copyright (c) 1988, 1993
3*60962Sbostic * The Regents of the University of California. All rights reserved.
438702Skfall *
547881Sbostic * %sccs.include.redist.c%
638702Skfall */
738702Skfall
838702Skfall #ifndef lint
9*60962Sbostic static char copyright[] =
10*60962Sbostic "@(#) Copyright (c) 1988, 1993\n\
11*60962Sbostic The Regents of the University of California. All rights reserved.\n";
1238702Skfall #endif /* not lint */
1338702Skfall
1447881Sbostic #ifndef lint
15*60962Sbostic static char sccsid[] = "@(#)make_keypair.c 8.1 (Berkeley) 06/01/93";
1647881Sbostic #endif /* not lint */
1747881Sbostic
1836342Skfall #include <sys/types.h>
1943959Skfall #include <sys/file.h>
2043959Skfall #include <netinet/in.h>
2136342Skfall #include <stdio.h>
2236342Skfall #include <netdb.h>
2343959Skfall #include <kerberosIV/des.h>
2443959Skfall #include <kerberosIV/krb.h>
2538699Skfall #include "pathnames.h"
2636342Skfall #include "register_proto.h"
2736342Skfall
2843959Skfall extern void random_key(), herror();
2943959Skfall void make_key(), usage();
3043959Skfall
main(argc,argv)3136342Skfall main(argc, argv)
3243959Skfall int argc;
3343959Skfall char **argv;
3436342Skfall {
3536342Skfall struct hostent *hp;
3636342Skfall char *addr;
3736342Skfall int i;
3836342Skfall struct sockaddr_in sin;
3936342Skfall
4043959Skfall if (argc != 2) {
4136342Skfall usage(argv[0]);
4236342Skfall exit(1);
4336342Skfall }
4436342Skfall
4543959Skfall if ((hp = gethostbyname(argv[1])) == NULL) {
4643959Skfall herror(argv[1]);
4743959Skfall exit(1);
4843959Skfall }
4943959Skfall
5038702Skfall for (i = 0; addr = hp->h_addr_list[i]; i++) {
5136342Skfall addr = hp->h_addr_list[i];
5236342Skfall bcopy(addr, &sin.sin_addr, hp->h_length);
5336342Skfall
5436342Skfall printf("Making key for host %s (%s)\n",
5536342Skfall argv[1], inet_ntoa(sin.sin_addr));
5636342Skfall make_key(sin.sin_addr);
5736342Skfall }
5836342Skfall printf("==========\n");
5938699Skfall printf("One copy of the each key should be put in %s on the\n",
6038699Skfall SERVER_KEYDIR);
6138699Skfall printf("Kerberos server machine (mode 600, owner root).\n");
6236342Skfall printf("Another copy of each key should be put on the named\n");
6338699Skfall printf("client as %sXXX.XXX.XXX.XXX (same modes as above),\n",
6438699Skfall CLIENT_KEYFILE);
6538699Skfall printf("where the X's refer to digits of the host's inet address.\n");
6643959Skfall (void)fflush(stdout);
6743959Skfall exit(0);
6836342Skfall }
6936342Skfall
7043959Skfall void
make_key(addr)7136342Skfall make_key(addr)
7236342Skfall struct in_addr addr;
7336342Skfall {
7436342Skfall struct keyfile_data kfile;
7536342Skfall char namebuf[255];
7636342Skfall int fd;
7736342Skfall
7843959Skfall (void)sprintf(namebuf, ".%s%s",
7938702Skfall CLIENT_KEYFILE,
8038702Skfall inet_ntoa(addr));
8136342Skfall fd = open(namebuf, O_WRONLY|O_CREAT, 0600);
8238702Skfall if (fd < 0) {
8336342Skfall perror("open");
8436342Skfall exit(1);
8536342Skfall }
8636342Skfall random_key(kfile.kf_key);
8738702Skfall printf("writing to file -> %s ...", namebuf);
8838702Skfall if (write(fd, &kfile, sizeof(kfile)) != sizeof(kfile)) {
8936342Skfall fprintf(stderr, "error writing file %s\n", namebuf);
9036342Skfall }
9138702Skfall printf("done.\n");
9243959Skfall (void)close(fd);
9343959Skfall return;
9436342Skfall }
9543959Skfall
9643959Skfall void
usage(name)9736342Skfall usage(name)
9836342Skfall char *name;
9936342Skfall {
10036342Skfall fprintf(stderr, "usage: %s host\n", name);
10136342Skfall }
102