From 508504ecfff98cd984e3ce7369097c1f422ee856 Mon Sep 17 00:00:00 2001 From: wollman Date: Tue, 21 Feb 1995 04:05:20 +0000 Subject: Use POSIX.2 regular expressions, get rid of libcompat. --- sbin/mount_portal/Makefile | 6 ++---- sbin/mount_portal/conf.c | 40 ++++++++++++++++++++++++---------------- 2 files changed, 26 insertions(+), 20 deletions(-) (limited to 'sbin/mount_portal') diff --git a/sbin/mount_portal/Makefile b/sbin/mount_portal/Makefile index 519d27f0..85eca12 100644 --- a/sbin/mount_portal/Makefile +++ b/sbin/mount_portal/Makefile @@ -1,4 +1,5 @@ -# @(#)Makefile 8.3 (Berkeley) 3/27/94 +# From: @(#)Makefile 8.3 (Berkeley) 3/27/94 +# $Id$ PROG= mount_portal SRCS= mount_portal.c activate.c conf.c getmntopts.c pt_conf.c \ @@ -9,7 +10,4 @@ MOUNT= ${.CURDIR}/../mount CFLAGS+= -I${.CURDIR}/../../sys -I${MOUNT} .PATH: ${MOUNT} -DPADD= $(LIBCOMPAT) -LDADD= -lcompat - .include diff --git a/sbin/mount_portal/conf.c b/sbin/mount_portal/conf.c index 18833b6..5b335a8 100644 --- a/sbin/mount_portal/conf.c +++ b/sbin/mount_portal/conf.c @@ -45,7 +45,7 @@ #include #include #include -#include +#include #include #include #include @@ -60,7 +60,8 @@ struct path { int p_lno; /* Line number of this record */ char *p_args; /* copy of arg string (malloc) */ char *p_key; /* Pathname to match (also p_argv[0]) */ - regexp *p_re; /* RE to match against pathname (malloc) */ + regex_t p_rx; /* RE to match against pathname () */ + int p_rxvalid; /* non-zero if valid regular expression */ int p_argc; /* number of elements in arg string */ char **p_argv; /* argv[] pointers into arg string (malloc) */ }; @@ -133,13 +134,6 @@ qelem *q0; } -void regerror(s) -const char *s; -{ - syslog(LOG_ERR, "%s:%s: regcomp %s: %s", - conf_file, curp->p_lno, curp->p_key, s); -} - static path *palloc(cline, lno) char *cline; int lno; @@ -202,11 +196,23 @@ int lno; p->p_key = p->p_argv[0]; if (strpbrk(p->p_key, RE_CHARS)) { + int val; + curp = p; /* XXX */ - p->p_re = regcomp(p->p_key); + val = regcomp(&p->p_rx, p->p_key, REG_EXTENDED | REG_NOSUB); + if (val) { + char errbuf[_POSIX2_LINE_MAX]; + regerror(val, &p->p_rx, errbuf, sizeof errbuf); + syslog(LOG_ERR, "%s:%s: regcomp %s: %s", + conf_file, curp->p_lno, curp->p_key, errbuf); + regfree(&p->p_rx); + p->p_rxvalid = 0; + } else { + p->p_rxvalid = 1; + } curp = 0; /* XXX */ } else { - p->p_re = 0; + p->p_rxvalid = 0; } p->p_lno = lno; @@ -220,8 +226,9 @@ static void pfree(p) path *p; { free(p->p_args); - if (p->p_re) - free((char *) p->p_re); + if (p->p_rxvalid) { + regfree(&p->p_rx); + } free((char *) p->p_argv); free((char *) p); } @@ -316,9 +323,10 @@ char *key; for (q = q0->q_forw; q != q0; q = q->q_forw) { path *p = (path *) q; - if (p->p_re) { - if (regexec(p->p_re, key)) - return (p->p_argv+1); + if (p->p_rxvalid) { + if (!regexec(&p->p_rx, key, 0, 0, 0)) { + return p->p_argv + 1; + } } else { if (strncmp(p->p_key, key, strlen(p->p_key)) == 0) return (p->p_argv+1); -- cgit v1.1