From 8619e9209bcfca43c5d0b3d4ce588396cf9516fc Mon Sep 17 00:00:00 2001 From: Yaakov Selkowitz Date: Tue, 11 Jul 2023 11:59:00 -0400 Subject: [PATCH] Update to pcre2 Classic pcre is unmaintained and being dropped from distributions. pcre2posix.h is missing idempotent guards, so handle that ourselves. Fixes: #3861 Signed-off-by: Yaakov Selkowitz --- configure.ac | 30 ++++++++++++++-------------- docsrc/assets/cyrus-build-devpkg.rst | 2 +- docsrc/assets/cyrus-build-reqpkg.rst | 2 +- docsrc/imap/developer/compiling.rst | 7 +++---- docsrc/imap/download/upgrade.rst | 2 +- imap/cyr_buildinfo.c | 6 +++--- lib/util.h | 12 ++++++----- ptclient/test3.c | 2 +- sieve/bc_eval.c | 4 ++-- sieve/comparator.h | 12 ++++++----- sieve/sieve.y | 4 ++-- 11 files changed, 43 insertions(+), 40 deletions(-) diff --git a/configure.ac b/configure.ac index 91cb1d829e..eb26b1be8e 100644 --- a/configure.ac +++ b/configure.ac @@ -675,8 +675,8 @@ AM_CONDITIONAL([SQUATTER], AC_ARG_ENABLE(sieve, [AS_HELP_STRING([--disable-sieve], [disable Sieve support])],,[enable_sieve="yes";]) -AC_ARG_ENABLE(pcre, - [AS_HELP_STRING([--disable-pcre], [disable PCRE library])],[cyrus_cv_pcre_utf8="$enableval"]) +AC_ARG_ENABLE(pcre2, + [AS_HELP_STRING([--disable-pcre2], [disable PCRE2 library])],[cyrus_cv_pcre2_utf8="$enableval"]) if test "$enable_sieve" != "no"; then AC_DEFINE(USE_SIEVE,[],[Build in Sieve support?]) @@ -702,25 +702,25 @@ fi AM_CONDITIONAL([SIEVE], [test "${enable_sieve}" != "no"]) -if test "$enable_pcre" != "no"; then - AC_CHECK_HEADER(pcreposix.h) - if test "$ac_cv_header_pcreposix_h" = "yes"; then - AC_MSG_CHECKING(for utf8 enabled pcre) - AC_CACHE_VAL(cyrus_cv_pcre_utf8, AC_TRY_CPP([#include -#ifndef REG_UTF8 +if test "$enable_pcre2" != "no"; then + AC_CHECK_HEADER(pcre2posix.h) + if test "$ac_cv_header_pcre2posix_h" = "yes"; then + AC_MSG_CHECKING(for utf8 enabled pcre2) + AC_CACHE_VAL(cyrus_cv_pcre2_utf8, AC_TRY_CPP([#include +#ifndef REG_UTF #include -#endif],cyrus_cv_pcre_utf8=yes,cyrus_cv_pcre_utf8=no)) - AC_MSG_RESULT($cyrus_cv_pcre_utf8) +#endif],cyrus_cv_pcre2_utf8=yes,cyrus_cv_pcre2_utf8=no)) + AC_MSG_RESULT($cyrus_cv_pcre2_utf8) else - cyrus_cv_pcre_utf8="no" + cyrus_cv_pcre2_utf8="no" fi fi LIB_REGEX= -if test "$cyrus_cv_pcre_utf8" = "yes"; then - LIB_REGEX="-lpcre -lpcreposix"; +if test "$cyrus_cv_pcre2_utf8" = "yes"; then + LIB_REGEX="-lpcre2-posix -lpcre2-8"; AC_DEFINE(ENABLE_REGEX, [], [Do we have a regex library?]) - AC_DEFINE(HAVE_PCREPOSIX_H, [], [Do we have usable pcre library?]) + AC_DEFINE(HAVE_PCRE2POSIX_H, [], [Do we have usable pcre2 library?]) else AC_CHECK_HEADERS(rxposix.h) if test "$ac_cv_header_rxposix_h" = "yes"; then @@ -2541,7 +2541,7 @@ External dependencies: openssl: $with_ssl zlib: $with_zlib jansson: $with_jansson - pcre: $cyrus_cv_pcre_utf8 + pcre2: $cyrus_cv_pcre2_utf8 clamav: $with_clamav ----------------------- caringo: $with_caringo diff --git a/docsrc/assets/cyrus-build-devpkg.rst b/docsrc/assets/cyrus-build-devpkg.rst index cf3eaef1b3..5c0156bb64 100644 --- a/docsrc/assets/cyrus-build-devpkg.rst +++ b/docsrc/assets/cyrus-build-devpkg.rst @@ -8,7 +8,7 @@ automated test facility. debhelper flex g++ git gperf groff heimdal-dev libbsd-resource-perl libclone-perl libconfig-inifiles-perl \ libcunit1-dev libdatetime-perl libbsd-dev libdigest-sha-perl libencode-imaputf7-perl \ libfile-chdir-perl libglib2.0-dev libical-dev libio-socket-inet6-perl \ libio-stringy-perl libldap2-dev libmysqlclient-dev \ - libnet-server-perl libnews-nntpclient-perl libpam0g-dev libpcre3-dev libsasl2-dev \ + libnet-server-perl libnews-nntpclient-perl libpam0g-dev libpcre2-dev libsasl2-dev \ libsqlite3-dev libssl-dev libtest-unit-perl libtool libunix-syslog-perl liburi-perl \ libxapian-dev libxml-generator-perl libxml-xpath-perl libxml2-dev libwrap0-dev libzephyr-dev lsb-base \ net-tools perl php-cli php-curl pkg-config po-debconf tcl-dev \ diff --git a/docsrc/assets/cyrus-build-reqpkg.rst b/docsrc/assets/cyrus-build-reqpkg.rst index a3a530cc39..1c8bb45951 100644 --- a/docsrc/assets/cyrus-build-reqpkg.rst +++ b/docsrc/assets/cyrus-build-reqpkg.rst @@ -2,6 +2,6 @@ sudo apt-get install git build-essential autoconf automake libtool \ pkg-config bison flex libssl-dev libjansson-dev libxml2-dev \ - libsqlite3-dev libical-dev libsasl2-dev libpcre3-dev uuid-dev \ + libsqlite3-dev libical-dev libsasl2-dev libpcre2-dev uuid-dev \ libicu-dev sudo apt-get -t jessie-backports install libxapian-dev diff --git a/docsrc/imap/developer/compiling.rst b/docsrc/imap/developer/compiling.rst index e0bc9b32eb..5d3bb7202a 100644 --- a/docsrc/imap/developer/compiling.rst +++ b/docsrc/imap/developer/compiling.rst @@ -186,9 +186,8 @@ Other to enable **ptloader** to interface with LDAP directly, for canonification of login usernames to mailbox names, and verification of login usernames, ACL subjects and group membership. Configure option: ``--with-ldap``." - `pcre`_, libpcre3-dev, pcre-devel, "yes", "PCRE 1 (8.x) - for utf-8/unicode - regular expression matching. Could be replaced by something else in the - future. See `issues/1731`_ for more information." + `pcre2`_, libpcre2-dev, pcre2-devel, "yes", "PCRE 2 (10.x) - for utf-8/unicode + regular expression matching." `perl(Term::ReadLine)`_,,, "no", "Perl library needed by **cyradm**." `libsrs2`_, *no package*, *no package*, "no", "It is used for implementing Sender Rewriting Scheme (SRS) functionality for messages @@ -210,7 +209,7 @@ Other .. _mariadb: http://mariadb.org .. _nghttp2: https://nghttp2.org/ .. _openldap: http://www.openldap.org/ -.. _pcre: http://www.pcre.org/ +.. _pcre2: https://www.pcre.org/ .. _perl(Term::ReadLine): https://metacpan.org/pod/Term::ReadLine .. _perl(ExtUtils::MakeMaker): http://search.cpan.org/dist/ExtUtils-MakeMaker/ .. _perl(Pod::POM::View::Restructured): https://metacpan.org/pod/Pod::POM::View::Restructured diff --git a/docsrc/imap/download/upgrade.rst b/docsrc/imap/download/upgrade.rst index 353a0114b8..09db9232b7 100644 --- a/docsrc/imap/download/upgrade.rst +++ b/docsrc/imap/download/upgrade.rst @@ -223,7 +223,7 @@ packages) for Debian is:: libcunit1-dev libdatetime-perl libdigest-sha-perl libencode-imaputf7-perl \ libfile-chdir-perl libglib2.0-dev libical-dev libio-socket-inet6-perl \ libio-stringy-perl libjansson-dev libldap2-dev libmysqlclient-dev \ - libnet-server-perl libnews-nntpclient-perl libpam0g-dev libpcre3-dev \ + libnet-server-perl libnews-nntpclient-perl libpam0g-dev libpcre2-dev \ libsasl2-dev libsqlite3-dev libssl-dev libtest-unit-perl libtool \ libunix-syslog-perl liburi-perl libxapian-dev libxml-generator-perl \ libxml-xpath-perl libxml2-dev libwrap0-dev libzephyr-dev lsb-base \ diff --git a/imap/cyr_buildinfo.c b/imap/cyr_buildinfo.c index 9027f42925..be5f34402d 100644 --- a/imap/cyr_buildinfo.c +++ b/imap/cyr_buildinfo.c @@ -193,10 +193,10 @@ static json_t *buildinfo() #else json_object_set_new(dependency, "jansson", json_false()); #endif -#if defined(ENABLE_REGEX) && defined(HAVE_PCREPOSIX_H) - json_object_set_new(dependency, "pcre", json_true()); +#if defined(ENABLE_REGEX) && defined(HAVE_PCRE2POSIX_H) + json_object_set_new(dependency, "pcre2", json_true()); #else - json_object_set_new(dependency, "pcre", json_false()); + json_object_set_new(dependency, "pcre2", json_false()); #endif #ifdef HAVE_CLAMAV json_object_set_new(dependency, "clamav", json_true()); diff --git a/lib/util.h b/lib/util.h index 7f7ab9f655..59339e2106 100644 --- a/lib/util.h +++ b/lib/util.h @@ -71,16 +71,18 @@ extern const char CYRUS_VERSION[]; #ifdef ENABLE_REGEX -# ifdef HAVE_PCREPOSIX_H -# include -# include -# else /* !HAVE_PCREPOSIX_H */ +# ifdef HAVE_PCRE2POSIX_H +# ifndef PCRE2POSIX_H_INCLUDED +# include +# define PCRE2POSIX_H_INCLUDED +# endif +# else /* !HAVE_PCRE2POSIX_H */ # ifdef HAVE_RXPOSIX_H # include # else /* !HAVE_RXPOSIX_H */ # include # endif /* HAVE_RXPOSIX_H */ -# endif /* HAVE_PCREPOSIX_H */ +# endif /* HAVE_PCRE2POSIX_H */ #endif /* ENABLE_REGEX */ #ifdef HAVE_LIBUUID diff --git a/ptclient/test3.c b/ptclient/test3.c index 0d61ff49d5..a45b706578 100644 --- a/ptclient/test3.c +++ b/ptclient/test3.c @@ -1,6 +1,6 @@ /* * test ptsmodule_standard_root_dn - * gcc -lz -lpcreposix -I.. -I ../lib ../lib/.libs/util.o ../lib/.libs/xmalloc.o ../lib/.libs/map_shared.o ../lib/.libs/retry.o ../lib/.libs/assert.o test3.c + * gcc -I.. -I ../lib ../lib/.libs/util.o ../lib/.libs/xmalloc.o ../lib/.libs/map_shared.o ../lib/.libs/retry.o ../lib/.libs/assert.o test3.c -lz -lpcre2-posix */ #include #include diff --git a/sieve/bc_eval.c b/sieve/bc_eval.c index 0049316463..2946cdbbaa 100644 --- a/sieve/bc_eval.c +++ b/sieve/bc_eval.c @@ -320,9 +320,9 @@ static int regcomp_flags(int comparator, int requires) { int cflags = REG_EXTENDED; -#ifdef HAVE_PCREPOSIX_H +#ifdef HAVE_PCRE2POSIX_H /* support UTF8 comparisons */ - cflags |= REG_UTF8; + cflags |= REG_UTF; #endif if (comparator == B_ASCIICASEMAP) { diff --git a/sieve/comparator.h b/sieve/comparator.h index b043bc296b..8eb40ab9bb 100644 --- a/sieve/comparator.h +++ b/sieve/comparator.h @@ -47,16 +47,18 @@ #include #ifdef ENABLE_REGEX -# ifdef HAVE_PCREPOSIX_H -# include -# include -# else /* !HAVE_PCREPOSIX_H */ +# ifdef HAVE_PCRE2POSIX_H +# ifndef PCRE2POSIX_H_INCLUDED +# include +# define PCRE2POSIX_H_INCLUDED +# endif +# else /* !HAVE_PCRE2POSIX_H */ # ifdef HAVE_RXPOSIX_H # include # else /* !HAVE_RXPOSIX_H */ # include # endif /* HAVE_RXPOSIX_H */ -# endif /* HAVE_PCREPOSIX_H */ +# endif /* HAVE_PCRE2POSIX_H */ #endif /* ENABLE_REGEX */ #include "sieve_interface.h" diff --git a/sieve/sieve.y b/sieve/sieve.y index c5d562a690..2dc70be8cc 100644 --- a/sieve/sieve.y +++ b/sieve/sieve.y @@ -2199,9 +2199,9 @@ static int verify_regexlist(sieve_script_t *sscript, regex_t reg; int cflags = REG_EXTENDED | REG_NOSUB; -#ifdef HAVE_PCREPOSIX_H +#ifdef HAVE_PCRE2POSIX_H /* support UTF8 comparisons */ - cflags |= REG_UTF8; + cflags |= REG_UTF; #endif if (collation == B_ASCIICASEMAP) {