diff options
author | Robert Peichaer <rpe@cvs.openbsd.org> | 2015-11-29 15:20:47 +0000 |
---|---|---|
committer | Robert Peichaer <rpe@cvs.openbsd.org> | 2015-11-29 15:20:47 +0000 |
commit | a9e9c53d59af81b700829cf2eee85f6a4127f9b9 (patch) | |
tree | 65428a908a349a6bc76b5d9b42ac20b353a9d1b5 /usr.sbin | |
parent | b41735379f440d8491abfcdcf68f49b899e36f01 (diff) |
Tedu stdethers and stdhosts from /usr/sbin, which are only used in Makefile.yp
for creating the hosts.byname, hosts.byaddr ethers.byname and ethers.byaddr YP
maps. Replace most of their functionality with sed/awk scripting directly in
Makefile.yp.
Suggested by and OK deraadt@
Feedback from @semarie
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/ypserv/Makefile | 5 | ||||
-rw-r--r-- | usr.sbin/ypserv/stdethers/Makefile | 7 | ||||
-rw-r--r-- | usr.sbin/ypserv/stdethers/stdethers.8 | 48 | ||||
-rw-r--r-- | usr.sbin/ypserv/stdethers/stdethers.c | 168 | ||||
-rw-r--r-- | usr.sbin/ypserv/stdhosts/Makefile | 6 | ||||
-rw-r--r-- | usr.sbin/ypserv/stdhosts/stdhosts.8 | 48 | ||||
-rw-r--r-- | usr.sbin/ypserv/stdhosts/stdhosts.c | 128 | ||||
-rw-r--r-- | usr.sbin/ypserv/ypinit/Makefile.yp | 24 | ||||
-rw-r--r-- | usr.sbin/ypserv/ypinit/Makefile.yp.8 | 10 |
9 files changed, 17 insertions, 427 deletions
diff --git a/usr.sbin/ypserv/Makefile b/usr.sbin/ypserv/Makefile index 43f4b44dccd..c2adca28f35 100644 --- a/usr.sbin/ypserv/Makefile +++ b/usr.sbin/ypserv/Makefile @@ -1,6 +1,5 @@ -# $OpenBSD: Makefile,v 1.7 2015/11/17 15:22:55 deraadt Exp $ +# $OpenBSD: Makefile,v 1.8 2015/11/29 15:20:46 rpe Exp $ -SUBDIR= makedbm mkalias mknetid revnetgroup stdethers stdhosts \ - ypinit ypserv yppush ypxfr +SUBDIR= makedbm mkalias mknetid revnetgroup ypinit ypserv yppush ypxfr .include <bsd.subdir.mk> diff --git a/usr.sbin/ypserv/stdethers/Makefile b/usr.sbin/ypserv/stdethers/Makefile deleted file mode 100644 index 923dfa8444b..00000000000 --- a/usr.sbin/ypserv/stdethers/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# $OpenBSD: Makefile,v 1.2 1996/05/30 09:53:11 deraadt Exp $ - -PROG= stdethers -MAN= stdethers.8 -CFLAGS+= -DNTOA_FIX - -.include <bsd.prog.mk> diff --git a/usr.sbin/ypserv/stdethers/stdethers.8 b/usr.sbin/ypserv/stdethers/stdethers.8 deleted file mode 100644 index 962d9a806b8..00000000000 --- a/usr.sbin/ypserv/stdethers/stdethers.8 +++ /dev/null @@ -1,48 +0,0 @@ -.\" $OpenBSD: stdethers.8,v 1.12 2013/07/16 11:13:34 schwarze Exp $ -.\" -.\" Copyright (c) 1995 Mats O Jansson <moj@stacken.kth.se> -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 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. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS -.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY -.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.Dd $Mdocdate: July 16 2013 $ -.Dt STDETHERS 8 -.Os -.Sh NAME -.Nm stdethers -.Nd YP filtering program -.Sh SYNOPSIS -.Nm stdethers -.Op Ar file -.Sh DESCRIPTION -.Nm -is used to get rid of unwanted information in -.Ar file , -or the standard input if no -.Ar file -argument is given. -This utility is used by YP when creating YP maps. -.Sh SEE ALSO -.Xr yp 8 , -.Xr ypserv 8 -.Sh AUTHORS -.An Mats O Jansson Aq Mt moj@stacken.kth.se diff --git a/usr.sbin/ypserv/stdethers/stdethers.c b/usr.sbin/ypserv/stdethers/stdethers.c deleted file mode 100644 index 6d0e26e7dc5..00000000000 --- a/usr.sbin/ypserv/stdethers/stdethers.c +++ /dev/null @@ -1,168 +0,0 @@ -/* $OpenBSD: stdethers.c,v 1.15 2009/10/27 23:59:58 deraadt Exp $ */ - -/* - * Copyright (c) 1995 Mats O Jansson <moj@stacken.kth.se> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include <sys/types.h> -#include <sys/socket.h> -#include <net/if.h> -#include <netinet/in.h> -#include <netinet/if_ether.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <ctype.h> - -#ifndef NTOA_FIX -#define NTOA(x) (char *)ether_ntoa(x) -#else -#define NTOA(x) (char *) working_ntoa((u_char *) x) - -/* As of 1995-12-02 NetBSD and OpenBSD has an SunOS 4 incompatible ether_ntoa. - The code in usr/lib/libc/net/ethers seems to do the correct thing - when asking YP but not when returning string from ether_ntoa. - */ - -static char * -working_ntoa(u_char *e) -{ - static char a[] = "xx:xx:xx:xx:xx:xx"; - - snprintf(a, sizeof a, "%x:%x:%x:%x:%x:%x", - e[0], e[1], e[2], e[3], e[4], e[5]); - return a; -} -#endif - -static int -read_line(FILE *fp, char *buf, int size) -{ - int done = 0; - - do { - while (fgets(buf, size, fp)) { - int len = strlen(buf); - - done += len; - if (len > 1 && buf[len-2] == '\\' && - buf[len-1] == '\n') { - int ch; - - buf += len - 2; - size -= len - 2; - *buf = '\n'; - buf[1] = '\0'; - - /* - * Skip leading white space on next line - */ - while ((ch = getc(fp)) != EOF && - isascii(ch) && isspace(ch)) - ; - (void) ungetc(ch, fp); - } else - return done; - } - } while (size > 0 && !feof(fp)); - return (done); -} - -static void -usage(void) -{ - fprintf(stderr, "usage: stdethers [file]\n"); - exit(1); -} - -int -main(int argc, char *argv[]) -{ - FILE *data_file; - char data_line[1024]; - int line_no = 0; - int len; - char *p, *k, *v; - struct ether_addr eth_addr; - char hostname[256]; - - if (argc > 2) - usage(); - - if (argc == 2) { - data_file = fopen(argv[1], "r"); - if (data_file == NULL) { - fprintf(stderr, "stdethers: can't open %s\n", - argv[1]); - exit(1); - } - } else - data_file = stdin; - - while (read_line(data_file, data_line, sizeof(data_line))) { - line_no++; - len = strlen(data_line); - - if (len > 0) { - if (data_line[0] == '#') - continue; - } - - /* - * Check if we have the whole line - */ - if (data_line[len-1] != '\n') { - if (argc == 2) - fprintf(stderr, - "line %d in \"%s\" is too long", - line_no, argv[1]); - else - fprintf(stderr, - "line %d in \"stdin\" is too long", - line_no); - } else - data_line[len-1] = '\0'; - - p = (char *) &data_line; - - k = p; /* save start of key */ - while (!isspace(*p)) /* find first "space" */ - p++; - while (isspace(*p)) /* move over "space" */ - p++; - - v = p; /* save start of value */ - while (*p != '\0') /* find end of string */ - p++; - - if (ether_line(data_line, ð_addr, hostname) == 0) - fprintf(stdout, "%s\t%s\n", NTOA(ð_addr), - hostname); - else - fprintf(stderr, "stdethers: ignoring line %d: \"%s\"\n", - line_no, data_line); - } - return(0); -} diff --git a/usr.sbin/ypserv/stdhosts/Makefile b/usr.sbin/ypserv/stdhosts/Makefile deleted file mode 100644 index e2c6a36345b..00000000000 --- a/usr.sbin/ypserv/stdhosts/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -# $OpenBSD: Makefile,v 1.2 1996/05/30 09:53:13 deraadt Exp $ - -PROG= stdhosts -MAN= stdhosts.8 - -.include <bsd.prog.mk> diff --git a/usr.sbin/ypserv/stdhosts/stdhosts.8 b/usr.sbin/ypserv/stdhosts/stdhosts.8 deleted file mode 100644 index f42c8f4e419..00000000000 --- a/usr.sbin/ypserv/stdhosts/stdhosts.8 +++ /dev/null @@ -1,48 +0,0 @@ -.\" $OpenBSD: stdhosts.8,v 1.13 2013/07/16 11:13:34 schwarze Exp $ -.\" -.\" Copyright (c) 1994 Mats O Jansson <moj@stacken.kth.se> -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 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. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS -.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY -.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.Dd $Mdocdate: July 16 2013 $ -.Dt STDHOSTS 8 -.Os -.Sh NAME -.Nm stdhosts -.Nd YP filtering program -.Sh SYNOPSIS -.Nm stdhosts -.Op Ar file -.Sh DESCRIPTION -.Nm -is used to get rid of unwanted information from -.Ar file , -or the standard input if no -.Ar file -argument is given. -This utility is used by YP when creating YP maps. -.Sh SEE ALSO -.Xr yp 8 , -.Xr ypserv 8 -.Sh AUTHORS -.An Mats O Jansson Aq Mt moj@stacken.kth.se diff --git a/usr.sbin/ypserv/stdhosts/stdhosts.c b/usr.sbin/ypserv/stdhosts/stdhosts.c deleted file mode 100644 index 71787d6a9f0..00000000000 --- a/usr.sbin/ypserv/stdhosts/stdhosts.c +++ /dev/null @@ -1,128 +0,0 @@ -/* $OpenBSD: stdhosts.c,v 1.16 2009/10/27 23:59:58 deraadt Exp $ */ - -/* - * Copyright (c) 1994 Mats O Jansson <moj@stacken.kth.se> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <ctype.h> -#include <err.h> - -static int -read_line(FILE *fp, char *buf, int size) -{ - int done = 0; - - do { - while (fgets(buf, size, fp)) { - int len = strlen(buf); - - done += len; - if (len > 1 && buf[len-2] == '\\' && - buf[len-1] == '\n') { - int ch; - - buf += len - 2; - size -= len - 2; - *buf = '\n'; - buf[1] = '\0'; - - /* - * Skip leading white space on next line - */ - while ((ch = getc(fp)) != EOF && - isascii(ch) && isspace(ch)) - ; - (void) ungetc(ch, fp); - } else - return done; - } - } while (size > 0 && !feof(fp)); - return done; -} - -int -main(int argc, char *argv[]) -{ - char data_line[1024], *p, *k, *v; - int line_no = 0, len; - struct in_addr host_addr; - FILE *data_file; - - if (argc > 2) { - fprintf(stderr, "usage: stdhosts [file]\n"); - exit(1); - } - - if (argc == 2) { - if ((data_file = fopen(argv[argc-1], "r")) == NULL) - err(1, "error opening %s", argv[argc-1]); - } else - data_file = stdin; - - while (read_line(data_file, data_line, sizeof(data_line))) { - line_no++; - len = strlen(data_line); - if (len > 0) { - if (data_line[0] == '#') - continue; - } - - /* - * Check if we have the whole line - */ - if (data_line[len-1] != '\n') { - if (argc == 2) - fprintf(stderr, - "line %d in \"%s\" is too long", - line_no, argv[1]); - else - fprintf(stderr, - "line %d in \"stdin\" is too long", line_no); - } else - data_line[len-1] = '\0'; - - p = (char *) &data_line; - k = p; /* save start of key */ - while (!isspace(*p)) /* find first "space" */ - p++; - while (isspace(*p)) /* replace space with <NUL> */ - *p++ = '\0'; - - v = p; /* save start of value */ - while (*p != '\0') /* find end of string */ - p++; - - if (inet_aton(k, &host_addr)) - printf("%s %s\n", inet_ntoa(host_addr), v); - } - return(0); -} diff --git a/usr.sbin/ypserv/ypinit/Makefile.yp b/usr.sbin/ypserv/ypinit/Makefile.yp index a46786c20f1..5215ccb045b 100644 --- a/usr.sbin/ypserv/ypinit/Makefile.yp +++ b/usr.sbin/ypserv/ypinit/Makefile.yp @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.yp,v 1.16 2010/01/20 23:20:28 schwarze Exp $ +# $OpenBSD: Makefile.yp,v 1.17 2015/11/29 15:20:46 rpe Exp $ # ---------------------------------------------------------------------- # User-configurable settings; see Makefile.yp(8) for details. @@ -46,8 +46,6 @@ REVNETGROUP=/usr/sbin/revnetgroup RM=/bin/rm SED=/usr/bin/sed SENDMAIL=/usr/sbin/sendmail -STDETHERS=/usr/sbin/stdethers -STDHOSTS=/usr/sbin/stdhosts TOUCH=/usr/bin/touch YPPUSH=/usr/sbin/yppush @@ -133,11 +131,13 @@ group.time: $(DIR)/group hosts.time: $(DIR)/hosts -@if [ -f $(DIR)/hosts ]; then \ - $(STDHOSTS) $(>) | $(SED) -e s/#.*$$// | \ - $(AWK) '{for (i = 2; i <= NF; i++) print $$i, $$0 }' | \ + $(SED) -E -e 's/[[:blank:]]*#.*$$//' -e '/^$$/d' $(>) | \ + $(AWK) 'BEGIN { OFS="\t" } \ + { if (length() > 1024) next; for (i=2; i <= NF; i++) print $$i,$$0 }' | \ $(MAKEDBM) $(USEDNS) - hosts.byname; \ - $(STDHOSTS) $(>) | \ - $(AWK) 'BEGIN { OFS="\t"; } { print $$1, $$0 }' | \ + $(SED) -E -e 's/[[:blank:]]*#.*$$//' -e '/^$$/d' $(>) | \ + $(AWK) 'BEGIN { OFS="\t" } \ + { if (length() > 1024) next; print $$1,$$0 }' | \ $(MAKEDBM) $(USEDNS) - hosts.byaddr; \ $(TOUCH) $(@); \ $(ECHO) "updated hosts"; \ @@ -154,11 +154,13 @@ hosts.time: $(DIR)/hosts ethers.time: $(DIR)/ethers -@if [ -f $(DIR)/ethers ]; then \ - $(STDETHERS) $(>) | $(SED) -e s/#.*$$// | \ - $(AWK) 'BEGIN { FS="\t"; OFS="\t"; } { print $$1, $$0 }' | \ + $(SED) -E -e 's/[[:blank:]]*#.*$$//' -e '/^$$/d' $(>) | \ + $(SED) -E -n '/^([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}[[:blank:]]/p' | \ + $(AWK) 'BEGIN { OFS="\t" } { if (length() > 1024) next; print $$1,$$0 }' | \ $(MAKEDBM) - ethers.byaddr; \ - $(STDETHERS) $(>) | \ - $(AWK) 'BEGIN { FS="\t"; OFS="\t"; } { print $$2, $$0 }' | \ + $(SED) -E -e 's/[[:blank:]]*#.*$$//' -e '/^$$/d' $(>) | \ + $(SED) -E -n '/^([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}[[:blank:]]/p' | \ + $(AWK) 'BEGIN { OFS="\t" } { if (length() > 1024) next; print $$2,$$0 }' | \ $(MAKEDBM) - ethers.byname; \ $(TOUCH) $(@); \ $(ECHO) "updated ethers"; \ diff --git a/usr.sbin/ypserv/ypinit/Makefile.yp.8 b/usr.sbin/ypserv/ypinit/Makefile.yp.8 index f0695ec91e5..a3d640206c9 100644 --- a/usr.sbin/ypserv/ypinit/Makefile.yp.8 +++ b/usr.sbin/ypserv/ypinit/Makefile.yp.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: Makefile.yp.8,v 1.6 2010/01/20 23:20:28 schwarze Exp $ +.\" $OpenBSD: Makefile.yp.8,v 1.7 2015/11/29 15:20:46 rpe Exp $ .\" .\" Copyright (c) 2008 Ingo Schwarze <schwarze@usta.de> .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: January 20 2010 $ +.Dd $Mdocdate: November 29 2015 $ .Dt MAKEFILE.YP 8 .Os .Sh NAME @@ -187,9 +187,6 @@ maps from .Xr hosts 5 for use by .Xr gethostbyname 3 . -Requires the -.Xr stdhosts 8 -utility. .Pp To get .Xr ypserv 8 @@ -206,9 +203,6 @@ maps from .Xr ethers 5 for use by .Xr ethers 3 . -Requires the -.Xr stdethers 8 -utility. .It Ic networks Generates the .Pa networks.byname |