use-posix-regex-20031010
authorGarrett Wollman <wollman@khavrinen.lcs.mit.edu>
Fri, 10 Oct 2003 15:08:31 +0000 (15:08 +0000)
committerJim Rees <rees@umich.edu>
Fri, 10 Oct 2003 15:08:31 +0000 (15:08 +0000)
use posix regex if available instead of re_comp
eliminates need for -lcompat on the BSDs, so remove it from XLIBS

acinclude.m4
src/cf/osconf.m4
src/vlserver/vlprocs.c
src/volser/vos.c

index 321ecfa..58dcb8b 100644 (file)
@@ -806,7 +806,7 @@ AC_CHECK_HEADERS(netinet/in.h netdb.h sys/fcntl.h sys/mnttab.h sys/mntent.h)
 AC_CHECK_HEADERS(mntent.h sys/vfs.h sys/param.h sys/fs_types.h sys/fstyp.h)
 AC_CHECK_HEADERS(sys/mount.h strings.h termios.h signal.h)
 AC_CHECK_HEADERS(windows.h malloc.h winsock2.h direct.h io.h)
-AC_CHECK_HEADERS(security/pam_modules.h siad.h usersec.h ucontext.h)
+AC_CHECK_HEADERS(security/pam_modules.h siad.h usersec.h ucontext.h regex.h)
 
 if test "$ac_cv_header_security_pam_modules_h" = "yes"; then
        HAVE_PAM="yes"
@@ -817,6 +817,19 @@ AC_SUBST(HAVE_PAM)
 
 AC_CHECK_FUNCS(utimes random srandom getdtablesize snprintf strlcat strlcpy re_comp re_exec)
 AC_CHECK_FUNCS(setprogname getprogname sigaction mkstemp vsnprintf strerror)
+
+AC_CHECK_FUNCS(regcomp regexec regerror)
+AC_MSG_CHECKING([for POSIX regex library])
+if test "$ac_cv_header_regex_h" = "yes" && \
+       test "$ac_cv_func_regcomp" = "yes" && \
+       test "$ac_cv_func_regexec" = "yes" && \
+       test "$ac_cv_func_regerror" = "yes"; then
+    AC_DEFINE(HAVE_POSIX_REGEX, 1, [define if you have POSIX regex library])
+    AC_MSG_RESULT(yes)
+else
+    AC_MSG_RESULT(no)
+fi
+       
 AC_CHECK_TYPE(ssize_t, int)
 AC_SIZEOF_TYPE(long)
 
index af3e476..4e25b64 100644 (file)
@@ -181,29 +181,14 @@ case $AFS_SYSNAME in
                SHLIB_LINKER="ld -b"
                ;;
 
-       i386_fbsd_4*)
+       *fbsd_*)
                LEX="flex -l"
                MT_CFLAGS='-DAFS_PTHREAD_ENV -pthread -D_REENTRANT ${XCFLAGS}'
                MT_LIBS="-pthread"
-               #MT_CFLAGS='-DAFS_PTHREAD_ENV -D_THREAD_SAFE -I/usr/local/include/pthread/linuxthreads ${XCFLAGS}'
-               #MT_LIBS="-L/usr/local/lib -llthread -llgcc_r"
                PAM_CFLAGS="-O2 -pipe -fPIC"
                SHLIB_LDFLAGS="-shared -Xlinker -x"
                TXLIBS="-lncurses"
                XCFLAGS="-O2 -pipe"
-               XLIBS="${LIB_AFSDB} -lcompat"
-               YACC="byacc"
-               ;;
-
-       *fbsd_5*)
-               LEX="flex -l"
-               MT_CFLAGS='-DAFS_PTHREAD_ENV -pthread -D_REENTRANT ${XCFLAGS}'
-               MT_LIBS="-pthread"
-               PAM_CFLAGS="-O2 -pipe -fPIC"
-               SHLIB_LDFLAGS="-shared -Xlinker -x"
-               TXLIBS="-lncurses"
-               XCFLAGS="-O2 -pipe"
-               XLIBS="${LIB_AFSDB} -lcompat"
                YACC="byacc"
                ;;
 
@@ -215,7 +200,6 @@ case $AFS_SYSNAME in
                SHLIB_LDFLAGS="-shared -Xlinker -x"
                TXLIBS="/usr/lib/libcurses.so"
                XCFLAGS="-O2 -pipe"
-               XLIBS="${LIB_AFSDB} -lcompat"
                YACC="yacc"
                ;;
 
@@ -227,7 +211,6 @@ case $AFS_SYSNAME in
                SHLIB_LDFLAGS="-shared -Xlinker -x"
                TXLIBS="/usr/lib/libcurses.so"
                XCFLAGS="-O2 -pipe"
-               XLIBS="${LIB_AFSDB} -lcompat"
                YACC="bison -y"
                ;;
 
@@ -332,7 +315,6 @@ case $AFS_SYSNAME in
                SHLIB_LDFLAGS="-shared -Xlinker -x"
                TXLIBS="/usr/lib/libcurses.a"
                XCFLAGS="-O2"
-               XLIBS="${LIB_AFSDB} -lcompat"
                YACC="yacc"
                ;;
 
index c92910c..2e920e0 100644 (file)
@@ -38,6 +38,9 @@ RCSID
 #ifndef AFS_NT40_ENV
 #include <unistd.h>
 #endif
+#ifdef HAVE_POSIX_REGEX                /* use POSIX regexp library */
+#include <regex.h>
+#endif
 
 extern int smallMem;
 extern extent_mod;
@@ -1376,6 +1379,10 @@ SVL_ListAttributesN2(rxcall, attributes, name, startindex, nentries,
     int pollcount = 0;
     int namematchRWBK, namematchRO, thismatch, matchtype;
     char volumename[VL_MAXNAMELEN];
+#ifdef HAVE_POSIX_REGEX
+    regex_t re;
+    int need_regfree = 0;
+#endif
 
     COUNT_REQ(VLLISTATTRIBUTESN2);
     vldbentries->nbulkentries_val = 0;
@@ -1433,11 +1440,19 @@ SVL_ListAttributesN2(rxcall, attributes, name, startindex, nentries,
        findflag = ((attributes->Mask & VLLIST_FLAG) ? 1 : 0);
        if (name && (strcmp(name, ".*") != 0) && (strcmp(name, "") != 0)) {
            sprintf(volumename, "^%s$", name);
+#ifdef HAVE_POSIX_REGEX
+           if (regcomp(&re, volumename, REG_BASIC | REG_NOSUB) != 0) {
+               errorcode = VL_BADNAME;
+               goto done;
+           }
+           need_regfree = 1;
+#else
            t = (char *)re_comp(volumename);
            if (t) {
                errorcode = VL_BADNAME;
                goto done;
            }
+#endif
            findname = 1;
        }
 
@@ -1468,9 +1483,15 @@ SVL_ListAttributesN2(rxcall, attributes, name, startindex, nentries,
                    if (tentry.flags & VLF_RWEXISTS) {
                        if (findname) {
                            sprintf(volumename, "%s", tentry.name);
+#ifdef HAVE_POSIX_REGEX
+                           if (regexec(&re, volumename, 0, NULL, 0) == 0) {
+                               thismatch = VLSF_RWVOL;
+                           }
+#else
                            if (re_exec(volumename)) {
                                thismatch = VLSF_RWVOL;
                            }
+#endif
                        } else {
                            thismatch = VLSF_RWVOL;
                        }
@@ -1480,9 +1501,15 @@ SVL_ListAttributesN2(rxcall, attributes, name, startindex, nentries,
                    if (!thismatch && (tentry.flags & VLF_BACKEXISTS)) {
                        if (findname) {
                            sprintf(volumename, "%s.backup", tentry.name);
+#ifdef HAVE_POSIX_REGEX
+                           if (regexec(&re, volumename, 0, NULL, 0) == 0) {
+                               thismatch = VLSF_BACKVOL;
+                           }
+#else
                            if (re_exec(volumename)) {
                                thismatch = VLSF_BACKVOL;
                            }
+#endif
                        } else {
                            thismatch = VLSF_BACKVOL;
                        }
@@ -1504,8 +1531,14 @@ SVL_ListAttributesN2(rxcall, attributes, name, startindex, nentries,
                            } else {
                                sprintf(volumename, "%s.readonly",
                                        tentry.name);
+#ifdef HAVE_POSIX_REGEX
+                           if (regexec(&re, volumename, 0, NULL, 0) == 0) {
+                               thismatch = VLSF_ROVOL;
+                           }
+#else
                                if (re_exec(volumename))
                                    thismatch = VLSF_ROVOL;
+#endif
                            }
                        } else {
                            thismatch = VLSF_ROVOL;
@@ -1566,6 +1599,11 @@ SVL_ListAttributesN2(rxcall, attributes, name, startindex, nentries,
     }
 
   done:
+#ifdef HAVE_POSIX_REGEX
+    if (need_regfree)
+       regfree(&re);
+#endif
+
     if (errorcode) {
        COUNT_ABO;
        ubik_AbortTrans(trans);
index 8a0fb3d..55093b4 100644 (file)
@@ -62,6 +62,10 @@ RCSID
 #endif
 #include "volser_prototypes.h"
 
+#ifdef HAVE_POSIX_REGEX
+#include <regex.h>
+#endif
+
 struct tqElem {
     afs_int32 volid;
     struct tqElem *next;
@@ -3928,6 +3932,20 @@ BackSys(as)
     if (seenprefix) {
        for (ti = as->parms[0].items; ti; ti = ti->next) {
            if (strncmp(ti->data, "^", 1) == 0) {
+#ifdef HAVE_POSIX_REGEX
+               regex_t re;
+               char errbuf[256];
+
+               code = regcomp(&re, ti->data, REG_BASIC | REG_NOSUB);
+               if (code != 0) {
+                   regerror(code, &re, errbuf, sizeof errbuf);
+                   fprintf(STDERR,
+                           "Unrecognizable -prefix regular expression: '%s': %s\n",
+                           ti->data, errbuf);
+                   exit(1);
+               }
+               regfree(&re);
+#else
                ccode = (char *)re_comp(ti->data);
                if (ccode) {
                    fprintf(STDERR,
@@ -3935,12 +3953,27 @@ BackSys(as)
                            ti->data, ccode);
                    exit(1);
                }
+#endif
            }
        }
     }
     if (seenxprefix) {
        for (ti = as->parms[4].items; ti; ti = ti->next) {
            if (strncmp(ti->data, "^", 1) == 0) {
+#ifdef HAVE_POSIX_REGEX
+               regex_t re;
+               char errbuf[256];
+
+               code = regcomp(&re, ti->data, REG_BASIC | REG_NOSUB);
+               if (code != 0) {
+                   regerror(code, &re, errbuf, sizeof errbuf);
+                   fprintf(STDERR,
+                           "Unrecognizable -xprefix regular expression: '%s': %s\n",
+                           ti->data, errbuf);
+                   exit(1);
+               }
+               regfree(&re);
+#else
                ccode = (char *)re_comp(ti->data);
                if (ccode) {
                    fprintf(STDERR,
@@ -3948,6 +3981,7 @@ BackSys(as)
                            ti->data, ccode);
                    exit(1);
                }
+#endif
            }
        }
     }
@@ -4012,6 +4046,22 @@ BackSys(as)
        if (seenprefix) {
            for (ti = as->parms[0].items; ti; ti = ti->next) {
                if (strncmp(ti->data, "^", 1) == 0) {
+#ifdef HAVE_POSIX_REGEX
+                   regex_t re;
+                   char errbuf[256];
+
+                   /* XXX -- should just do the compile once! */
+                   code = regcomp(&re, ti->data, REG_BASIC | REG_NOSUB);
+                   if (code != 0) {
+                       regerror(code, &re, errbuf, sizeof errbuf);
+                       fprintf(STDERR,
+                               "Error in -prefix regular expression: '%s': %s\n",
+                               ti->data, errbuf);
+                       exit(1);
+                   }
+                   match = (regexec(&re, vllist->name, 0, NULL, 0) == 0);
+                   regfree(&re);
+#else
                    ccode = (char *)re_comp(ti->data);
                    if (ccode) {
                        fprintf(STDERR,
@@ -4020,6 +4070,7 @@ BackSys(as)
                        exit(1);
                    }
                    match = (re_exec(vllist->name) == 1);
+#endif
                } else {
                    match =
                        (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
@@ -4040,6 +4091,23 @@ BackSys(as)
        if (match && seenxprefix) {
            for (ti = as->parms[4].items; ti; ti = ti->next) {
                if (strncmp(ti->data, "^", 1) == 0) {
+#ifdef HAVE_POSIX_REGEX
+                   regex_t re;
+                   char errbuf[256];
+
+                   /* XXX -- should just do the compile once! */
+                   code = regcomp(&re, ti->data, REG_BASIC | REG_NOSUB);
+                   if (code != 0) {
+                       regerror(code, &re, errbuf, sizeof errbuf);
+                       fprintf(STDERR,
+                               "Error in -xprefix regular expression: '%s': %s\n",
+                               ti->data, errbuf);
+                       exit(1);
+                   }
+                   if (regexec(&re, vllist->name, 0, NULL, 0) == 0)
+                           match = 0;
+                   regfree(&re);
+#else
                    ccode = (char *)re_comp(ti->data);
                    if (ccode) {
                        fprintf(STDERR,
@@ -4051,6 +4119,7 @@ BackSys(as)
                        match = 0;
                        break;
                    }
+#endif
                } else {
                    if (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
                        0) {