126242Swpaul/*
226242Swpaul * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
326242Swpaul * unrestricted use provided that this legend is included on all tape
426242Swpaul * media and as a part of the software program in whole or part.  Users
526242Swpaul * may copy or modify Sun RPC without charge, but are not authorized
626242Swpaul * to license or distribute it to anyone else except as part of a product or
726242Swpaul * program developed by the user or with the express written consent of
826242Swpaul * Sun Microsystems, Inc.
926242Swpaul *
1026242Swpaul * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
1126242Swpaul * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
1226242Swpaul * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
1326242Swpaul *
1426242Swpaul * Sun RPC is provided with no support and without any obligation on the
1526242Swpaul * part of Sun Microsystems, Inc. to assist in its use, correction,
1626242Swpaul * modification or enhancement.
1726242Swpaul *
1826242Swpaul * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
1926242Swpaul * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
2026242Swpaul * OR ANY PART THEREOF.
2126242Swpaul *
2226242Swpaul * In no event will Sun Microsystems, Inc. be liable for any lost revenue
2326242Swpaul * or profits or other special, indirect and consequential damages, even if
2426242Swpaul * Sun has been advised of the possibility of such damages.
2526242Swpaul *
2626242Swpaul * Sun Microsystems, Inc.
2726242Swpaul * 2550 Garcia Avenue
2826242Swpaul * Mountain View, California  94043
2926242Swpaul */
3026242Swpaul#if !defined(lint) && defined(SCCSIDS)
3126242Swpaulstatic char sccsid[] = "@(#)keylogin.c 1.4 91/03/11 Copyr 1986 Sun Micro";
3226242Swpaul#endif
3399112Sobrien#include <sys/cdefs.h>
3499112Sobrien__FBSDID("$FreeBSD$");
3526242Swpaul
3626242Swpaul/*
3726242Swpaul * Copyright (C) 1986, Sun Microsystems, Inc.
3826242Swpaul */
3926242Swpaul
4026242Swpaul/*
4126242Swpaul * Set secret key on local machine
4226242Swpaul */
4326242Swpaul#include <stdio.h>
4478718Sdd#include <stdlib.h>
4526242Swpaul#include <string.h>
4626242Swpaul#include <pwd.h>
4726242Swpaul#include <unistd.h>
4826242Swpaul#include <rpc/rpc.h>
4926242Swpaul#include <rpc/key_prot.h>
5026242Swpaul
51246990Scharnierextern int key_setnet(struct key_netstarg *);
52246990Scharnier
5326242Swpaulint
54246990Scharniermain(void)
5526242Swpaul{
5626242Swpaul	char fullname[MAXNETNAMELEN + 1];
5774462Salfred	struct key_netstarg netst;
5826242Swpaul
5926242Swpaul	if (!getnetname(fullname)) {
6026242Swpaul		fprintf(stderr, "netname lookup failed -- make sure the ");
6126242Swpaul		fprintf(stderr, "system domain name is set.\n");
6226242Swpaul		exit(1);
6326242Swpaul	}
6426242Swpaul
6526242Swpaul	if (! getsecretkey(fullname, (char *)&(netst.st_priv_key),
6626242Swpaul				getpass("Password:"))) {
6726242Swpaul		fprintf(stderr, "Can't find %s's secret key\n", fullname);
6826242Swpaul		exit(1);
6926242Swpaul	}
7026242Swpaul	if (netst.st_priv_key[0] == 0) {
7126242Swpaul		fprintf(stderr, "Password incorrect for %s\n", fullname);
7226242Swpaul		exit(1);
7326242Swpaul	}
7426242Swpaul
7526242Swpaul	netst.st_pub_key[0] = 0;
7626242Swpaul	netst.st_netname = strdup(fullname);
7726242Swpaul
7826242Swpaul	if (key_setnet(&netst) < 0) {
7926242Swpaul		fprintf(stderr, "Could not set %s's secret key\n", fullname);
8026242Swpaul		fprintf(stderr, "Maybe the keyserver is down?\n");
8126242Swpaul		exit(1);
8226242Swpaul	}
8326242Swpaul	exit(0);
8426242Swpaul	/* NOTREACHED */
8526242Swpaul}
86