summaryrefslogtreecommitdiffstats
path: root/usr.bin/newkey/newkey.c
diff options
context:
space:
mode:
authorcharnier <charnier@FreeBSD.org>1997-07-29 06:54:16 +0000
committercharnier <charnier@FreeBSD.org>1997-07-29 06:54:16 +0000
commit7711e701aa1f4f9d39e5cb307997bfa18a733136 (patch)
treeaa6e652d97672aab7685f3a8895f647b750a6401 /usr.bin/newkey/newkey.c
parente97a8f1bb5fbb72a7aba41985727d01d65f488c2 (diff)
downloadFreeBSD-src-7711e701aa1f4f9d39e5cb307997bfa18a733136.zip
FreeBSD-src-7711e701aa1f4f9d39e5cb307997bfa18a733136.tar.gz
Add usage(), use err(3).
Rewrote man page in mdoc format.
Diffstat (limited to 'usr.bin/newkey/newkey.c')
-rw-r--r--usr.bin/newkey/newkey.c70
1 files changed, 34 insertions, 36 deletions
diff --git a/usr.bin/newkey/newkey.c b/usr.bin/newkey/newkey.c
index 489324d..dcf14ec 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 <err.h>
#include <stdio.h>
#include <rpc/rpc.h>
#include <rpc/key_prot.h>
@@ -49,6 +54,7 @@ static char sccsid[] = "@(#)newkey.c 1.8 91/03/11 Copyr 1986 Sun Micro";
#endif /* YP */
#include <pwd.h>
#include <string.h>
+#include <unistd.h>
#include <sys/resource.h>
#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
*/
OpenPOWER on IntegriCloud