summaryrefslogtreecommitdiffstats
path: root/usr.bin/ypcat/ypcat.c
diff options
context:
space:
mode:
authoraraujo <araujo@FreeBSD.org>2015-08-04 02:41:14 +0000
committeraraujo <araujo@FreeBSD.org>2015-08-04 02:41:14 +0000
commit99f1775e8a629b5abd8a6bd575f0dd0fddf9fc8b (patch)
tree3878311fd3cb2210a9adcba06438b6b3dd60226a /usr.bin/ypcat/ypcat.c
parenteae36d50f97ae8b70b1445940a354eb1394e0f4d (diff)
downloadFreeBSD-src-99f1775e8a629b5abd8a6bd575f0dd0fddf9fc8b.zip
FreeBSD-src-99f1775e8a629b5abd8a6bd575f0dd0fddf9fc8b.tar.gz
Remove the 3rd clause of BSD LICENSE.
Sync the code with the OpenBSD version. Small style(9) fix up. Differential Revision: D3212 Reviewed by: rodrigc, bapt Obtained from: OpenBSD Sponsored by: gandi.net
Diffstat (limited to 'usr.bin/ypcat/ypcat.c')
-rw-r--r--usr.bin/ypcat/ypcat.c77
1 files changed, 41 insertions, 36 deletions
diff --git a/usr.bin/ypcat/ypcat.c b/usr.bin/ypcat/ypcat.c
index d3a7f41..60acca0 100644
--- a/usr.bin/ypcat/ypcat.c
+++ b/usr.bin/ypcat/ypcat.c
@@ -1,5 +1,7 @@
+/* $OpenBSD: ypcat.c,v 1.16 2015/02/08 23:40:35 deraadt Exp $ */
+
/*
- * Copyright (c) 1992/3 Theo de Raadt <deraadt@fsa.ca>
+ * Copyright (c) 1992, 1993, 1996 Theo de Raadt <deraadt@theos.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -10,9 +12,6 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote
- * products derived from this software without specific prior written
- * permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
@@ -34,18 +33,20 @@ __FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/types.h>
#include <sys/socket.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <err.h>
#include <rpc/rpc.h>
#include <rpc/xdr.h>
-#include <rpcsvc/yp_prot.h>
+#include <rpcsvc/yp.h>
#include <rpcsvc/ypclnt.h>
-#include <ctype.h>
-#include <err.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
+void usage(void);
+int printit(u_long, char *, int, char *, int, void *);
static const struct ypalias {
char *alias, *name;
@@ -64,17 +65,18 @@ static const struct ypalias {
static int key;
-static void
+void
usage(void)
{
- fprintf(stderr, "%s\n%s\n",
- "usage: ypcat [-kt] [-d domainname] mapname",
- " ypcat -x");
+ fprintf(stderr,
+ "usage: ypcat [-kt] [-d domainname] mapname\n"
+ " ypcat -x\n");
exit(1);
}
-static int
-printit(unsigned long instatus, char *inkey, int inkeylen, char *inval, int invallen, void *dummy __unused)
+int
+printit(u_long instatus, char *inkey, int inkeylen, char *inval, int invallen,
+ void *indata)
{
if (instatus != YP_TRUE)
return (instatus);
@@ -87,31 +89,29 @@ printit(unsigned long instatus, char *inkey, int inkeylen, char *inval, int inva
int
main(int argc, char *argv[])
{
- char *domainname = NULL;
+ char *domain = NULL, *inmap;
struct ypall_callback ypcb;
- char *inmap;
- int notrans;
- int c, r;
+ extern char *optarg;
+ extern int optind;
+ int notrans, c, r;
u_int i;
notrans = key = 0;
-
while ((c = getopt(argc, argv, "xd:kt")) != -1)
switch (c) {
case 'x':
- for (i = 0; i<sizeof ypaliases/sizeof ypaliases[0]; i++)
+ for (i=0; i<sizeof ypaliases/sizeof ypaliases[0]; i++)
printf("Use \"%s\" for \"%s\"\n",
- ypaliases[i].alias,
- ypaliases[i].name);
+ ypaliases[i].alias, ypaliases[i].name);
exit(0);
case 'd':
- domainname = optarg;
+ domain = optarg;
break;
case 't':
- notrans++;
+ notrans = 1;
break;
case 'k':
- key++;
+ key = 1;
break;
default:
usage();
@@ -120,24 +120,29 @@ main(int argc, char *argv[])
if (optind + 1 != argc)
usage();
- if (!domainname)
- yp_get_default_domain(&domainname);
+ if (!domain)
+ yp_get_default_domain(&domain);
inmap = argv[optind];
- for (i = 0; (!notrans) && i<sizeof ypaliases/sizeof ypaliases[0]; i++)
- if (strcmp(inmap, ypaliases[i].alias) == 0)
- inmap = ypaliases[i].name;
+ if (!notrans) {
+ for (i=0; i<sizeof ypaliases/sizeof ypaliases[0]; i++)
+ if (strcmp(inmap, ypaliases[i].alias) == 0)
+ inmap = ypaliases[i].name;
+ }
ypcb.foreach = printit;
ypcb.data = NULL;
- r = yp_all(domainname, inmap, &ypcb);
+ r = yp_all(domain, inmap, &ypcb);
switch (r) {
case 0:
break;
case YPERR_YPBIND:
- errx(1, "not running ypbind");
+ errx(1, "ypcat: not running ypbind\n");
+ exit(1);
default:
- errx(1, "no such map %s. reason: %s", inmap, yperr_string(r));
+ errx(1, "No such map %s. Reason: %s\n",
+ inmap, yperr_string(r));
+ exit(1);
}
exit(0);
}
OpenPOWER on IntegriCloud