diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2003-05-06 22:10:12 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2003-05-06 22:10:12 +0000 |
commit | 237f3ca12c2499b607c061f095929774144ec0f9 (patch) | |
tree | f5b53886bbc0ff78c0d89463bd55b24922148b67 /usr.bin | |
parent | 12e8b31474927177f0c8e63e2d6d8d6eac721265 (diff) |
use POSIX regex
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/rdist/Makefile | 5 | ||||
-rw-r--r-- | usr.bin/rdist/client.c | 5 | ||||
-rw-r--r-- | usr.bin/rdist/defs.h | 4 | ||||
-rw-r--r-- | usr.bin/rdist/docmd.c | 34 | ||||
-rw-r--r-- | usr.bin/rdist/gram.y | 24 | ||||
-rw-r--r-- | usr.bin/rdist/rdist.c | 9 | ||||
-rw-r--r-- | usr.bin/rdistd/Makefile | 5 |
7 files changed, 56 insertions, 30 deletions
diff --git a/usr.bin/rdist/Makefile b/usr.bin/rdist/Makefile index 56f2ec2982b..8731f61ac6b 100644 --- a/usr.bin/rdist/Makefile +++ b/usr.bin/rdist/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.12 2002/05/09 19:13:02 millert Exp $ +# $OpenBSD: Makefile,v 1.13 2003/05/06 22:10:11 millert Exp $ PROG= rdist @@ -7,9 +7,6 @@ SRCS= gram.y child.c client.c common.c distopt.c docmd.c expand.c \ isexec.c lookup.c message.c rdist.c CLEANFILES+=gram.c y.tab.h -LDADD= -lcompat -DPADD= ${LIBCOMPAT} - .include <bsd.prog.mk> .if ${ELF_TOOLCHAIN} == "yes" diff --git a/usr.bin/rdist/client.c b/usr.bin/rdist/client.c index fd9f6ba13b5..0d50be51ed7 100644 --- a/usr.bin/rdist/client.c +++ b/usr.bin/rdist/client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: client.c,v 1.16 2003/04/19 17:22:29 millert Exp $ */ +/* $OpenBSD: client.c,v 1.17 2003/05/06 22:10:11 millert Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -39,7 +39,7 @@ static char RCSid[] = "$From: client.c,v 6.80 1996/02/28 20:34:27 mcooper Exp $"; #else static char RCSid[] = -"$OpenBSD: client.c,v 1.16 2003/04/19 17:22:29 millert Exp $"; +"$OpenBSD: client.c,v 1.17 2003/05/06 22:10:11 millert Exp $"; #endif static char sccsid[] = "@(#)client.c"; @@ -219,6 +219,7 @@ static void addcmdspecialfile(starget, rname, destdir) if (isokay) { new = (struct namelist *) xmalloc(sizeof(struct namelist)); new->n_name = xstrdup(rfile); + new->n_regex = NULL; new->n_next = updfilelist; updfilelist = new; } diff --git a/usr.bin/rdist/defs.h b/usr.bin/rdist/defs.h index 17cdd722b32..c5dabb5d2cb 100644 --- a/usr.bin/rdist/defs.h +++ b/usr.bin/rdist/defs.h @@ -1,4 +1,4 @@ -/* $OpenBSD: defs.h,v 1.11 2001/08/23 14:17:08 aaron Exp $ */ +/* $OpenBSD: defs.h,v 1.12 2003/05/06 22:10:11 millert Exp $ */ #ifndef __DEFS_H__ #define __DEFS_H__ @@ -52,6 +52,7 @@ #include <errno.h> #include <pwd.h> #include <grp.h> +#include <regex.h> #include <syslog.h> #include <setjmp.h> #include <sys/types.h> @@ -257,6 +258,7 @@ */ struct namelist { /* for making lists of strings */ char *n_name; + regex_t *n_regex; struct namelist *n_next; }; diff --git a/usr.bin/rdist/docmd.c b/usr.bin/rdist/docmd.c index fdbe5801630..5772c5bb36b 100644 --- a/usr.bin/rdist/docmd.c +++ b/usr.bin/rdist/docmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: docmd.c,v 1.13 2003/04/19 17:22:29 millert Exp $ */ +/* $OpenBSD: docmd.c,v 1.14 2003/05/06 22:10:11 millert Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -39,7 +39,7 @@ static char RCSid[] = "$From: docmd.c,v 6.86 1996/01/30 02:29:43 mcooper Exp $"; #else static char RCSid[] = -"$OpenBSD: docmd.c,v 1.13 2003/04/19 17:22:29 millert Exp $"; +"$OpenBSD: docmd.c,v 1.14 2003/05/06 22:10:11 millert Exp $"; #endif static char sccsid[] = "@(#)docmd.c 5.1 (Berkeley) 6/6/85"; @@ -836,15 +836,31 @@ extern int except(file) } if (sc->sc_type == PATTERN) { for (nl = sc->sc_args; nl != NULL; nl = nl->n_next) { - char *cp, *re_comp(); - - if ((cp = re_comp(nl->n_name)) != NULL) { + char ebuf[BUFSIZ]; + int ecode = 0; + + /* allocate and compile n_regex as needed */ + if (nl->n_regex == NULL) { + nl->n_regex = (regex_t *) + xmalloc(sizeof(regex_t)); + ecode = regcomp(nl->n_regex, nl->n_name, + REG_NOSUB); + } + if (ecode == 0) { + ecode = regexec(nl->n_regex, file, 0, + NULL, 0); + } + switch (ecode) { + case REG_NOMATCH: + break; + case 0: + return(1); /* match! */ + default: + regerror(ecode, nl->n_regex, ebuf, + sizeof(ebuf)); error("Regex error \"%s\" for \"%s\".", - cp, nl->n_name); - return(0); + ebuf, nl->n_name); } - if (re_exec(file) > 0) - return(1); } } } diff --git a/usr.bin/rdist/gram.y b/usr.bin/rdist/gram.y index 6109f75e68a..463fc0351d1 100644 --- a/usr.bin/rdist/gram.y +++ b/usr.bin/rdist/gram.y @@ -1,5 +1,5 @@ %{ -/* $OpenBSD: gram.y,v 1.5 2002/05/30 07:36:44 deraadt Exp $ */ +/* $OpenBSD: gram.y,v 1.6 2003/05/06 22:10:11 millert Exp $ */ /* * Copyright (c) 1993 Michael A. Cooper @@ -41,7 +41,7 @@ static char RCSid[] = "$From: gram.y,v 6.29 1994/04/11 23:59:15 mcooper Exp mcooper $"; #else static char RCSid[] = -"$OpenBSD: gram.y,v 1.5 2002/05/30 07:36:44 deraadt Exp $"; +"$OpenBSD: gram.y,v 1.6 2003/05/06 22:10:11 millert Exp $"; #endif static char *sccsid = "@(#)gram.y 5.2 (Berkeley) 85/06/21"; @@ -196,11 +196,20 @@ cmd: INSTALL options opt_namelist ';' = { } | PATTERN namelist ';' = { struct namelist *nl; - char *cp, *re_comp(); - - for (nl = $2; nl != NULL; nl = nl->n_next) - if ((cp = re_comp(nl->n_name)) != NULL) - yyerror(cp); + char ebuf[BUFSIZ]; + regex_t reg; + int ecode; + + for (nl = $2; nl != NULL; nl = nl->n_next) { + /* check for a valid regex */ + ecode = regcomp(®, nl->n_name, REG_NOSUB); + if (ecode) { + regerror(ecode, ®, ebuf, + sizeof(ebuf)); + yyerror(ebuf); + } + regfree(®); + } $1->sc_args = expand($2, E_VARS); $$ = $1; } @@ -539,6 +548,7 @@ makenl(name) nl = ALLOC(namelist); nl->n_name = name; + nl->n_regex = NULL; nl->n_next = NULL; return(nl); diff --git a/usr.bin/rdist/rdist.c b/usr.bin/rdist/rdist.c index d25c4ea6209..7662a57f54e 100644 --- a/usr.bin/rdist/rdist.c +++ b/usr.bin/rdist/rdist.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rdist.c,v 1.14 2003/04/05 20:31:58 deraadt Exp $ */ +/* $OpenBSD: rdist.c,v 1.15 2003/05/06 22:10:11 millert Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -39,7 +39,7 @@ static char RCSid[] = "$From: rdist.c,v 6.65 1995/12/12 00:20:39 mcooper Exp $"; #else static char RCSid[] = -"$OpenBSD: rdist.c,v 1.14 2003/04/05 20:31:58 deraadt Exp $"; +"$OpenBSD: rdist.c,v 1.15 2003/05/06 22:10:11 millert Exp $"; #endif static char sccsid[] = "@(#)main.c 5.1 (Berkeley) 6/6/85"; @@ -90,6 +90,7 @@ static void addhostlist(name, hostlist) new = (struct namelist *) xmalloc(sizeof(struct namelist)); new->n_name = xstrdup(name); + new->n_regex = NULL; new->n_next = NULL; if (*hostlist) { @@ -401,7 +402,7 @@ docmdargs(nargs, args) struct namelist *files, *hosts; struct subcmd *cmds; char *dest; - static struct namelist tnl = { NULL, NULL }; + static struct namelist tnl; int i; if (nargs < 2) @@ -423,6 +424,8 @@ docmdargs(nargs, args) if ((dest = strchr(cp, ':')) != NULL) *dest++ = '\0'; tnl.n_name = cp; + tnl.n_regex = NULL; + tnl.n_next = NULL; hosts = expand(&tnl, E_ALL); if (nerrs) exit(1); diff --git a/usr.bin/rdistd/Makefile b/usr.bin/rdistd/Makefile index 7d9c0cf7d62..7dcca7df29d 100644 --- a/usr.bin/rdistd/Makefile +++ b/usr.bin/rdistd/Makefile @@ -1,11 +1,8 @@ -# $OpenBSD: Makefile,v 1.3 1997/04/27 13:03:11 downsj Exp $ +# $OpenBSD: Makefile,v 1.4 2003/05/06 22:10:11 millert Exp $ PROG= rdistd SRCS= common.c filesys-os.c filesys.c message.c rdistd.c server.c .PATH: ${.CURDIR}/../rdist CFLAGS+=-I${.CURDIR}/../rdist -DOS_H=\"os-openbsd.h\" -LDADD= -lcompat -DPADD= ${LIBCOMPAT} - .include <bsd.prog.mk> |