From f2abddceac41ef9e6cc56995b1fce562a5846ff8 Mon Sep 17 00:00:00 2001 From: Philippe Charnier Date: Tue, 29 Jul 1997 06:54:16 +0000 Subject: [PATCH] Add usage(), use err(3). Rewrote man page in mdoc format. --- usr.bin/newkey/generic.c | 5 +++ usr.bin/newkey/newkey.8 | 65 ++++++++++++++++++------------------- usr.bin/newkey/newkey.c | 70 +++++++++++++++++++--------------------- usr.bin/newkey/update.c | 8 +++-- 4 files changed, 76 insertions(+), 72 deletions(-) diff --git a/usr.bin/newkey/generic.c b/usr.bin/newkey/generic.c index 4d1518531962..2c3ec1e8cbe1 100644 --- a/usr.bin/newkey/generic.c +++ b/usr.bin/newkey/generic.c @@ -28,14 +28,19 @@ * Mountain View, California 94043 */ #if !defined(lint) && defined(SCCSIDS) +#if 0 static char sccsid[] = "@(#)generic.c 1.2 91/03/11 Copyr 1986 Sun Micro"; #endif +static const char rcsid[] = + "$Id$"; +#endif /* * Copyright (C) 1986, Sun Microsystems, Inc. */ #include +#include #include #include #include diff --git a/usr.bin/newkey/newkey.8 b/usr.bin/newkey/newkey.8 index 80297517296e..c32fe9eb6ced 100644 --- a/usr.bin/newkey/newkey.8 +++ b/usr.bin/newkey/newkey.8 @@ -1,54 +1,53 @@ .\" @(#)newkey.8 1.3 91/03/11 TIRPC 1.0; from 1.12 90/02/03 SMI; -.TH NEWKEY 8 "12 October 1987" -.SH NAME -newkey \- create a new key in the publickey database -.SH SYNOPSIS -.B "newkey \-h" -.I hostname -.br -.B "newkey \-u" -.I username -.SH DESCRIPTION -.IX "newkey command" "" "\fLnewkey\fP command" -.LP -.B newkey +.Dd October 12, 1987 +.Dt NEWKEY 8 +.Os +.Sh NAME +.Nm newkey +.Nd create a new key in the publickey database +.Sh SYNOPSIS +.Nm newkey +.Fl h Ar hostname +.Nm newkey +.Fl u Ar username +.Sh DESCRIPTION +.Nm Newkey is normally run by the network administrator on the Network Interface Service (\s-1NIS\s0) master machine in order to establish public keys for users and super-users on the network. These keys are needed for using secure -.SM RPC +RPC or secure -.SM NFS\s0. -.LP -.B newkey +NFS\s0. +.Pp +.Nm Newkey will prompt for the login password of the given username and then create a new public/secret key pair in -.B /etc/publickey +.Pa /etc/publickey encrypted with the login password of the given user. -.LP +.Pp Use of this program is not required: users may create their own keys using -.BR chkey (1). -.SH OPTIONS -.TP 12 -.BI \-h " hostname" +.Xr chkey 1 . +.Sh OPTIONS +.Bl -tag -width indent +.It Fl h Ar hostname Create a new public key for the super-user at the given hostname. Prompts for the root password of the given hostname. -.TP -.BI \-u " username" +.It Fl u Ar username Create a new public key for the given username. Prompts for the -.SM NIS +NIS password of the given username. -.SH "SEE ALSO" -.BR chkey (1), -.BR keylogin (1), -.BR publickey (5), -.BR keyserv (8C) -.SH NOTES -.LP +.El +.Sh SEE ALSO +.Xr chkey 1 , +.Xr keylogin 1 , +.Xr publickey 5 , +.Xr keyserv 8 +.Sh NOTES The Network Information Service (\s-1NIS\s0) was formerly known as Sun Yellow Pages diff --git a/usr.bin/newkey/newkey.c b/usr.bin/newkey/newkey.c index 489324dcfc0a..dcf14ecab28e 100644 --- a/usr.bin/newkey/newkey.c +++ b/usr.bin/newkey/newkey.c @@ -28,8 +28,12 @@ * Mountain View, California 94043 */ #if !defined(lint) && defined(SCCSIDS) +#if 0 static char sccsid[] = "@(#)newkey.c 1.8 91/03/11 Copyr 1986 Sun Micro"; #endif +static const char rcsid[] = + "$Id$"; +#endif /* * Copyright (C) 1986, Sun Microsystems, Inc. @@ -38,6 +42,7 @@ static char sccsid[] = "@(#)newkey.c 1.8 91/03/11 Copyr 1986 Sun Micro"; /* * Administrative tool to add a new user to the publickey database */ +#include #include #include #include @@ -49,6 +54,7 @@ static char sccsid[] = "@(#)newkey.c 1.8 91/03/11 Copyr 1986 Sun Micro"; #endif /* YP */ #include #include +#include #include #ifdef YP @@ -66,9 +72,6 @@ static char sccsid[] = "@(#)newkey.c 1.8 91/03/11 Copyr 1986 Sun Micro"; #define ERR_KEY 6 #endif -extern char *getpass(); -extern char *malloc(); - #ifdef YP static char *basename(); static char SHELL[] = "/bin/sh"; @@ -80,6 +83,9 @@ static char PKFILE[] = "/etc/publickey"; static char *err_string(); #endif /* YP */ +static void usage __P((void)); + +int main(argc, argv) int argc; char *argv[]; @@ -98,37 +104,25 @@ main(argc, argv) if (argc != 3 || !(strcmp(argv[1], "-u") == 0 || strcmp(argv[1], "-h") == 0)) { - (void)fprintf(stderr, "usage: %s [-u username]\n", - argv[0]); - (void)fprintf(stderr, "usage: %s [-h hostname]\n", - argv[0]); - exit(1); - } - if (geteuid() != 0) { - (void)fprintf(stderr, "must be superuser to run %s\n", argv[0]); - exit(1); + usage(); } + if (geteuid() != 0) + errx(1, "must be superuser"); #ifdef YP - if (chdir(YPDBPATH) < 0) { - (void)fprintf(stderr, "cannot chdir to "); - perror(YPDBPATH); - } + if (chdir(YPDBPATH) < 0) + warn("cannot chdir to %s", YPDBPATH); #endif /* YP */ if (strcmp(argv[1], "-u") == 0) { pw = getpwnam(argv[2]); - if (pw == NULL) { - (void)fprintf(stderr, "unknown user: %s\n", argv[2]); - exit(1); - } + if (pw == NULL) + errx(1, "unknown user: %s", argv[2]); (void)user2netname(name, (int)pw->pw_uid, (char *)NULL); } else { #ifdef undef h = gethostbyname(argv[2]); - if (h == NULL) { - (void)fprintf(stderr, "unknown host: %s\n", argv[1]); - exit(1); - } + if (h == NULL) + errx(1, "unknown host: %s", argv[1]); (void)host2netname(name, h->h_name, (char *)NULL); #else (void)host2netname(name, argv[2], (char *)NULL); @@ -147,31 +141,35 @@ main(argc, argv) memcpy(crypt2, crypt1, HEXKEYBYTES + KEYCHECKSUMSIZE + 1); xdecrypt(crypt2, getpass("Retype password:")); if (memcmp(crypt2, crypt2 + HEXKEYBYTES, KEYCHECKSUMSIZE) != 0 || - memcmp(crypt2, secret, HEXKEYBYTES) != 0) { - (void)fprintf(stderr, "Password incorrect.\n"); - exit(1); - } + memcmp(crypt2, secret, HEXKEYBYTES) != 0) + errx(1, "password incorrect"); #ifdef YP (void)printf("Please wait for the database to get updated...\n"); #endif - if (status = setpublicmap(name, public, crypt1)) { + if ((status = setpublicmap(name, public, crypt1))) { #ifdef YP - (void)fprintf(stderr, - "%s: unable to update NIS database (%u): %s\n", - argv[0], status, yperr_string(status)); + errx(1, "unable to update NIS database (%u): %s", + status, yperr_string(status)); #else - (void)fprintf(stderr, - "%s: unable to update publickey database (%u): %s\n", - argv[0], status, err_string(status)); + errx(1, "unable to update publickey database (%u): %s", + status, err_string(status)); #endif - exit(1); } (void)printf("Your new key has been successfully stored away.\n"); exit(0); /* NOTREACHED */ } +static void +usage() +{ + (void)fprintf(stderr, "%s\n%s\n", + "usage: newkey [-u username]", + " newkey [-h hostname]"); + exit(1); +} + /* * Set the entry in the public key file */ diff --git a/usr.bin/newkey/update.c b/usr.bin/newkey/update.c index e6bc9a694490..c6b663d84bb5 100644 --- a/usr.bin/newkey/update.c +++ b/usr.bin/newkey/update.c @@ -28,8 +28,12 @@ * Mountain View, California 94043 */ #ifndef lint +#if 0 static char sccsid[] = "@(#)update.c 1.2 91/03/11 Copyr 1986 Sun Micro"; #endif +static const char rcsid[] = + "$Id$"; +#endif /* * Copyright (C) 1986, 1989, Sun Microsystems, Inc. @@ -49,6 +53,7 @@ static char sccsid[] = "@(#)update.c 1.2 91/03/11 Copyr 1986 Sun Micro"; #endif /* YP */ #include #include +#include #include #ifdef YP @@ -60,9 +65,6 @@ static char sccsid[] = "@(#)update.c 1.2 91/03/11 Copyr 1986 Sun Micro"; #define YPOP_STORE 4 /* add, or change */ #endif -extern char *getpass(); -extern char *malloc(); - #ifdef YP static char *basename(); static char SHELL[] = "/bin/sh";