dbd1c52
From ba59ab9edb79d9da7f983fd341c9c1523641d65d Mon Sep 17 00:00:00 2001
dbd1c52
From: "Scott A. Williams" <vwfoxguru@gmail.com>
dbd1c52
Date: Fri, 3 Mar 2023 18:35:27 -0800
dbd1c52
Subject: [PATCH 1/3] Port pcre calls to pcre2.
dbd1c52
dbd1c52
Signed-off-by: Scott A. Williams <vwfoxguru@gmail.com>
dbd1c52
---
dbd1c52
 README             |  2 +-
dbd1c52
 README.win32       |  2 +-
dbd1c52
 config.h.in        |  2 +-
dbd1c52
 configure          | 12 ++++++------
dbd1c52
 configure.ac       |  4 ++--
dbd1c52
 src/mod_auth_cas.c | 12 ++++++------
dbd1c52
 6 files changed, 17 insertions(+), 17 deletions(-)
dbd1c52
dbd1c52
diff --git a/README b/README
dbd1c52
index 5069de7..88f1a20 100644
dbd1c52
--- a/README
dbd1c52
+++ b/README
dbd1c52
@@ -49,7 +49,7 @@ The following development libraries and utilities must be installed:
dbd1c52
 * Apache Portable Runtime Utilities - 1.2.7 or higher
dbd1c52
 * Apache Web Server - 2.2.3 or higher
dbd1c52
 * libcurl - 7.18.2 or higher
dbd1c52
-* libpcre - 7.8 or higher
dbd1c52
+* libpcre2 - 10 or higher
dbd1c52
 
dbd1c52
 Download the distribution via git or tarball.  Because git does not
dbd1c52
 preserve timestamps, autoconf may determine it is necessary to bootstrap
dbd1c52
diff --git a/README.win32 b/README.win32
dbd1c52
index f7d41df..ce40fd7 100644
dbd1c52
--- a/README.win32
dbd1c52
+++ b/README.win32
dbd1c52
@@ -22,7 +22,7 @@ This has only been tested with:
dbd1c52
 NOTE:	As of mod_auth_cas 1.0.9, Win32 support has been dropped due
dbd1c52
 	to lack of development resources and low community interest.
dbd1c52
 	As a result, these instructions may be inaccurate.  As an
dbd1c52
-	explicit example, the additional curl and libpcre dependencies are
dbd1c52
+	explicit example, the additional curl and libpcre2 dependencies are
dbd1c52
 	not addressed in these instructions at all.
dbd1c52
 
dbd1c52
 ====================================================================
dbd1c52
diff --git a/config.h.in b/config.h.in
dbd1c52
index 0ffabb5..26fbd2c 100644
dbd1c52
--- a/config.h.in
dbd1c52
+++ b/config.h.in
dbd1c52
@@ -15,7 +15,7 @@
dbd1c52
 /* Define to 1 if you have a functional curl library. */
dbd1c52
 #undef HAVE_LIBCURL
dbd1c52
 
dbd1c52
-/* Define to 1 if you have the `pcre' library (-lpcre). */
dbd1c52
+/* Define to 1 if you have the `pcre2' library (-lpcre). */
dbd1c52
 #undef HAVE_LIBPCRE
dbd1c52
 
dbd1c52
 /* Define to 1 if you have the `ssl' library (-lssl). */
dbd1c52
diff --git a/configure b/configure
dbd1c52
index a7931aa..3bfd765 100755
dbd1c52
--- a/configure
dbd1c52
+++ b/configure
dbd1c52
@@ -14129,9 +14129,9 @@ _ACEOF
dbd1c52
   unset _libcurl_with
dbd1c52
 
dbd1c52
 
dbd1c52
-# Checks for libpcre
dbd1c52
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for pcre_compile in -lpcre" >&5
dbd1c52
-$as_echo_n "checking for pcre_compile in -lpcre... " >&6; }
dbd1c52
+# Checks for libpcre2
dbd1c52
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for pcre2_compile in -lpcre" >&5
dbd1c52
+$as_echo_n "checking for pcre2_compile in -lpcre... " >&6; }
dbd1c52
 if ${ac_cv_lib_pcre_pcre_compile+:} false; then :
dbd1c52
   $as_echo_n "(cached) " >&6
dbd1c52
 else
dbd1c52
@@ -14146,11 +14146,11 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
dbd1c52
 #ifdef __cplusplus
dbd1c52
 extern "C"
dbd1c52
 #endif
dbd1c52
-char pcre_compile ();
dbd1c52
+char pcre2_compile ();
dbd1c52
 int
dbd1c52
 main ()
dbd1c52
 {
dbd1c52
-return pcre_compile ();
dbd1c52
+return pcre2_compile ();
dbd1c52
   ;
dbd1c52
   return 0;
dbd1c52
 }
dbd1c52
@@ -14174,7 +14174,7 @@ _ACEOF
dbd1c52
   LIBS="-lpcre $LIBS"
dbd1c52
 
dbd1c52
 else
dbd1c52
-  as_fn_error $? "libpcre required" "$LINENO" 5
dbd1c52
+  as_fn_error $? "libpcre2 required" "$LINENO" 5
dbd1c52
 fi
dbd1c52
 
dbd1c52
 
dbd1c52
diff --git a/configure.ac b/configure.ac
dbd1c52
index cd53219..f994f3b 100644
dbd1c52
--- a/configure.ac
dbd1c52
+++ b/configure.ac
dbd1c52
@@ -137,8 +137,8 @@ AC_CHECK_HEADERS([openssl/crypto.h openssl/x509.h openssl/pem.h openssl/ssl.h op
dbd1c52
 #### Check for libcurl
dbd1c52
 LIBCURL_CHECK_CONFIG([yes],[],[],[AC_MSG_ERROR([libcurl development files required])])
dbd1c52
 
dbd1c52
-# Checks for libpcre
dbd1c52
-AC_CHECK_LIB([pcre], [pcre_compile], [], [AC_MSG_ERROR([libpcre required])])
dbd1c52
+# Checks for libpcre2
dbd1c52
+AC_CHECK_LIB([pcre2], [pcre2_compile], [], [AC_MSG_ERROR([libpcre2 required])])
dbd1c52
 
dbd1c52
 # Checks for header files.
dbd1c52
 AC_CHECK_HEADERS([netdb.h stddef.h sys/socket.h unistd.h])
dbd1c52
diff --git a/src/mod_auth_cas.c b/src/mod_auth_cas.c
dbd1c52
index 9228e80..bbec877 100644
dbd1c52
--- a/src/mod_auth_cas.c
dbd1c52
+++ b/src/mod_auth_cas.c
dbd1c52
@@ -44,7 +44,7 @@
dbd1c52
 #include "util_md5.h"
dbd1c52
 #include "ap_config.h"
dbd1c52
 #include "ap_release.h"
dbd1c52
-#include "pcre.h"
dbd1c52
+#include "pcre2.h"
dbd1c52
 #include "apr_buckets.h"
dbd1c52
 #include "apr_file_info.h"
dbd1c52
 #include "apr_lib.h"
dbd1c52
@@ -2382,13 +2382,13 @@ int cas_match_attribute(const char *const attr_spec, const cas_saml_attr *const
dbd1c52
 			const cas_saml_attr_val *val;
dbd1c52
 			const char *errorptr;
dbd1c52
 			int erroffset;
dbd1c52
-			pcre *preg;
dbd1c52
+			pcre2_code *preg;
dbd1c52
 
dbd1c52
 			/* Skip the tilde */
dbd1c52
 			spec_c++;
dbd1c52
 
dbd1c52
 			/* Set up the regex */
dbd1c52
-			preg = pcre_compile(spec_c, 0, &errorptr, &erroffset, NULL);
dbd1c52
+			preg = pcre2_compile(spec_c, 0, &errorptr, &erroffset, NULL);
dbd1c52
 			if (NULL == preg) {
dbd1c52
 				ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "Pattern [%s] is not a valid regular expression", spec_c);
dbd1c52
 				continue;
dbd1c52
@@ -2399,13 +2399,13 @@ int cas_match_attribute(const char *const attr_spec, const cas_saml_attr *const
dbd1c52
 			for ( ; val; val = val->next) {
dbd1c52
 				/* PCRE-compare the attribute value. At this point, spec_c
dbd1c52
 				 * points to the NULL-terminated value pattern. */
dbd1c52
-				if (0 == pcre_exec(preg, NULL, val->value, (int)strlen(val->value), 0, 0, NULL, 0)) {
dbd1c52
-					pcre_free(preg);
dbd1c52
+				if (0 == pcre2_match(preg, NULL, val->value, (int)strlen(val->value), 0, 0, NULL, 0)) {
dbd1c52
+					pcre2_match_data_free(preg);
dbd1c52
 					return CAS_ATTR_MATCH;
dbd1c52
 				}
dbd1c52
 			}
dbd1c52
 
dbd1c52
-			pcre_free(preg);
dbd1c52
+			pcre2_match_data__free(preg);
dbd1c52
 		}
dbd1c52
 	}
dbd1c52
 	return CAS_ATTR_NO_MATCH;
dbd1c52
-- 
dbd1c52
2.39.2
dbd1c52
dbd1c52
dbd1c52
From 0f28901445b6103c1c0de669334c26ea381a4607 Mon Sep 17 00:00:00 2001
dbd1c52
From: "Scott A. Williams" <vwfoxguru@gmail.com>
dbd1c52
Date: Fri, 3 Mar 2023 19:46:30 -0800
dbd1c52
Subject: [PATCH 2/3] Adjust code and checks for PCRE2.
dbd1c52
dbd1c52
Signed-off-by: Scott A. Williams <vwfoxguru@gmail.com>
dbd1c52
---
dbd1c52
 config.h.in        |  2 +-
dbd1c52
 configure          |  8 ++++----
dbd1c52
 configure.ac       |  2 +-
dbd1c52
 src/mod_auth_cas.c | 18 +++++++++++-------
dbd1c52
 4 files changed, 17 insertions(+), 13 deletions(-)
dbd1c52
dbd1c52
diff --git a/config.h.in b/config.h.in
dbd1c52
index 26fbd2c..03f523c 100644
dbd1c52
--- a/config.h.in
dbd1c52
+++ b/config.h.in
dbd1c52
@@ -15,7 +15,7 @@
dbd1c52
 /* Define to 1 if you have a functional curl library. */
dbd1c52
 #undef HAVE_LIBCURL
dbd1c52
 
dbd1c52
-/* Define to 1 if you have the `pcre2' library (-lpcre). */
dbd1c52
+/* Define to 1 if you have the `pcre2' library (-lpcre2). */
dbd1c52
 #undef HAVE_LIBPCRE
dbd1c52
 
dbd1c52
 /* Define to 1 if you have the `ssl' library (-lssl). */
dbd1c52
diff --git a/configure b/configure
dbd1c52
index 3bfd765..26fb639 100755
dbd1c52
--- a/configure
dbd1c52
+++ b/configure
dbd1c52
@@ -14130,13 +14130,13 @@ _ACEOF
dbd1c52
 
dbd1c52
 
dbd1c52
 # Checks for libpcre2
dbd1c52
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for pcre2_compile in -lpcre" >&5
dbd1c52
-$as_echo_n "checking for pcre2_compile in -lpcre... " >&6; }
dbd1c52
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for pcre2_compile in -lpcre2" >&5
dbd1c52
+$as_echo_n "checking for pcre2_compile in -lpcre2... " >&6; }
dbd1c52
 if ${ac_cv_lib_pcre_pcre_compile+:} false; then :
dbd1c52
   $as_echo_n "(cached) " >&6
dbd1c52
 else
dbd1c52
   ac_check_lib_save_LIBS=$LIBS
dbd1c52
-LIBS="-lpcre  $LIBS"
dbd1c52
+LIBS="-lpcre2  $LIBS"
dbd1c52
 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
dbd1c52
 /* end confdefs.h.  */
dbd1c52
 
dbd1c52
@@ -14171,7 +14171,7 @@ if test "x$ac_cv_lib_pcre_pcre_compile" = xyes; then :
dbd1c52
 #define HAVE_LIBPCRE 1
dbd1c52
 _ACEOF
dbd1c52
 
dbd1c52
-  LIBS="-lpcre $LIBS"
dbd1c52
+  LIBS="-lpcre2 $LIBS"
dbd1c52
 
dbd1c52
 else
dbd1c52
   as_fn_error $? "libpcre2 required" "$LINENO" 5
dbd1c52
diff --git a/configure.ac b/configure.ac
dbd1c52
index f994f3b..de0d5e8 100644
dbd1c52
--- a/configure.ac
dbd1c52
+++ b/configure.ac
dbd1c52
@@ -138,7 +138,7 @@ AC_CHECK_HEADERS([openssl/crypto.h openssl/x509.h openssl/pem.h openssl/ssl.h op
dbd1c52
 LIBCURL_CHECK_CONFIG([yes],[],[],[AC_MSG_ERROR([libcurl development files required])])
dbd1c52
 
dbd1c52
 # Checks for libpcre2
dbd1c52
-AC_CHECK_LIB([pcre2], [pcre2_compile], [], [AC_MSG_ERROR([libpcre2 required])])
dbd1c52
+AC_CHECK_LIB([pcre2-8], [pcre2_compile_8], [], [AC_MSG_ERROR([libpcre2 required])])
dbd1c52
 
dbd1c52
 # Checks for header files.
dbd1c52
 AC_CHECK_HEADERS([netdb.h stddef.h sys/socket.h unistd.h])
dbd1c52
diff --git a/src/mod_auth_cas.c b/src/mod_auth_cas.c
dbd1c52
index bbec877..a3d7c3c 100644
dbd1c52
--- a/src/mod_auth_cas.c
dbd1c52
+++ b/src/mod_auth_cas.c
dbd1c52
@@ -44,6 +44,7 @@
dbd1c52
 #include "util_md5.h"
dbd1c52
 #include "ap_config.h"
dbd1c52
 #include "ap_release.h"
dbd1c52
+#define  PCRE2_CODE_UNIT_WIDTH 8
dbd1c52
 #include "pcre2.h"
dbd1c52
 #include "apr_buckets.h"
dbd1c52
 #include "apr_file_info.h"
dbd1c52
@@ -2380,32 +2381,35 @@ int cas_match_attribute(const char *const attr_spec, const cas_saml_attr *const
dbd1c52
 		 * name and the attr_spec is a tilde (denotes a PCRE match). */
dbd1c52
 		else if (!(*attr_c) && (*spec_c) == '~') {
dbd1c52
 			const cas_saml_attr_val *val;
dbd1c52
-			const char *errorptr;
dbd1c52
-			int erroffset;
dbd1c52
+			int errorptr;
dbd1c52
+			PCRE2_SIZE erroffset;
dbd1c52
 			pcre2_code *preg;
dbd1c52
+			uint32_t options = PCRE2_UTF;
dbd1c52
 
dbd1c52
 			/* Skip the tilde */
dbd1c52
 			spec_c++;
dbd1c52
 
dbd1c52
 			/* Set up the regex */
dbd1c52
-			preg = pcre2_compile(spec_c, 0, &errorptr, &erroffset, NULL);
dbd1c52
+			preg = pcre2_compile((PCRE2_SPTR)spec_c, PCRE2_ZERO_TERMINATED, options, &errorptr, &erroffset, NULL);
dbd1c52
 			if (NULL == preg) {
dbd1c52
 				ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "Pattern [%s] is not a valid regular expression", spec_c);
dbd1c52
 				continue;
dbd1c52
 			}
dbd1c52
-
dbd1c52
+			
dbd1c52
 			/* Compare the attribute values */
dbd1c52
+			pcre2_match_data *preg_match;
dbd1c52
+			preg_match = pcre2_match_data_create_from_pattern(preg, NULL);
dbd1c52
 			val = attr->values;
dbd1c52
 			for ( ; val; val = val->next) {
dbd1c52
 				/* PCRE-compare the attribute value. At this point, spec_c
dbd1c52
 				 * points to the NULL-terminated value pattern. */
dbd1c52
-				if (0 == pcre2_match(preg, NULL, val->value, (int)strlen(val->value), 0, 0, NULL, 0)) {
dbd1c52
-					pcre2_match_data_free(preg);
dbd1c52
+				if (0 == pcre2_match(preg, (PCRE2_SPTR)val->value, (int)strlen(val->value), 0, 0, preg_match, 0)) {
dbd1c52
+					pcre2_match_data_free(preg_match);
dbd1c52
 					return CAS_ATTR_MATCH;
dbd1c52
 				}
dbd1c52
 			}
dbd1c52
 
dbd1c52
-			pcre2_match_data__free(preg);
dbd1c52
+			pcre2_match_data_free(preg_match);
dbd1c52
 		}
dbd1c52
 	}
dbd1c52
 	return CAS_ATTR_NO_MATCH;
dbd1c52
-- 
dbd1c52
2.39.2
dbd1c52
dbd1c52
dbd1c52
From 6d1b7f5e100877bcd691f6e6c89d224a9270d239 Mon Sep 17 00:00:00 2001
dbd1c52
From: "Scott A. Williams" <vwfoxguru@gmail.com>
dbd1c52
Date: Fri, 3 Mar 2023 20:31:11 -0800
dbd1c52
Subject: [PATCH 3/3] Fix mixed declarations warning.
dbd1c52
dbd1c52
Signed-off-by: Scott A. Williams <vwfoxguru@gmail.com>
dbd1c52
---
dbd1c52
 src/mod_auth_cas.c | 2 +-
dbd1c52
 1 file changed, 1 insertion(+), 1 deletion(-)
dbd1c52
dbd1c52
diff --git a/src/mod_auth_cas.c b/src/mod_auth_cas.c
dbd1c52
index a3d7c3c..9775a2b 100644
dbd1c52
--- a/src/mod_auth_cas.c
dbd1c52
+++ b/src/mod_auth_cas.c
dbd1c52
@@ -2385,6 +2385,7 @@ int cas_match_attribute(const char *const attr_spec, const cas_saml_attr *const
dbd1c52
 			PCRE2_SIZE erroffset;
dbd1c52
 			pcre2_code *preg;
dbd1c52
 			uint32_t options = PCRE2_UTF;
dbd1c52
+                        pcre2_match_data *preg_match;
dbd1c52
 
dbd1c52
 			/* Skip the tilde */
dbd1c52
 			spec_c++;
dbd1c52
@@ -2397,7 +2398,6 @@ int cas_match_attribute(const char *const attr_spec, const cas_saml_attr *const
dbd1c52
 			}
dbd1c52
 			
dbd1c52
 			/* Compare the attribute values */
dbd1c52
-			pcre2_match_data *preg_match;
dbd1c52
 			preg_match = pcre2_match_data_create_from_pattern(preg, NULL);
dbd1c52
 			val = attr->values;
dbd1c52
 			for ( ; val; val = val->next) {
dbd1c52
-- 
dbd1c52
2.39.2
dbd1c52