URL: https://github.com/SSSD/sssd/pull/5754 Author: alexey-tikhonov Title: #5754: Sources cleanup. Action: opened
PR body: """ Those are initial patches in the "cleanup" set. I expect to add more to this PR, but those already published are ready for review. Warning: this PR targets 2.6 upstream release, so it should be deferred until 2.5.3 is released. """ To pull the PR as Git branch: git remote add ghsssd https://github.com/SSSD/sssd git fetch ghsssd pull/5754/head:pr5754 git checkout pr5754
From 57b355494b9f516555ae7c6dea789f8ea0b699db Mon Sep 17 00:00:00 2001 From: Alexey Tikhonov <atikh...@redhat.com> Date: Wed, 18 Aug 2021 18:33:02 +0200 Subject: [PATCH 1/2] BUILD: get rid of PCRE support :relnote: This release removes pcre1 support. --- contrib/ci/sssd.supp | 12 ----- src/external/libpcre.m4 | 38 +++------------ src/util/sss_regexp.c | 105 +--------------------------------------- src/util/sss_regexp.h | 25 +++------- src/util/usertools.c | 19 -------- 5 files changed, 14 insertions(+), 185 deletions(-) diff --git a/contrib/ci/sssd.supp b/contrib/ci/sssd.supp index 0c61e08468..6d5a9f8aff 100644 --- a/contrib/ci/sssd.supp +++ b/contrib/ci/sssd.supp @@ -59,18 +59,6 @@ } # False positive - pcre_free is called in sss_names_ctx_destructor -{ - sssd-leak-sss_names - Memcheck:Leak - fun:malloc - fun:pcre_compile2 - fun:sss_regexp_pcre1_compile - fun:sss_regexp_new - fun:sss_names_init_from_args - ... -} - -# And the same, as above, for pcre2 { sssd-leak-sss_names_pcre2 Memcheck:Leak diff --git a/src/external/libpcre.m4 b/src/external/libpcre.m4 index f8a997ddf3..d4d50e8b02 100644 --- a/src/external/libpcre.m4 +++ b/src/external/libpcre.m4 @@ -6,11 +6,6 @@ PKG_CHECK_MODULES( [libpcre2-8], [ found_libpcre=yes - AC_DEFINE( - [HAVE_LIBPCRE2], - 1, - [Define if libpcre2 is present] - ) AC_DEFINE( [PCRE2_CODE_UNIT_WIDTH], 8, @@ -18,36 +13,17 @@ PKG_CHECK_MODULES( ) ], [ - PKG_CHECK_MODULES( - [PCRE], - [libpcre], - [ - found_libpcre=yes - PKG_CHECK_EXISTS( - libpcre >= 7, - [AC_MSG_NOTICE([PCRE version is 7 or higher])], - [ - AC_MSG_NOTICE([PCRE version is below 7]) - AC_DEFINE( - [HAVE_LIBPCRE_LESSER_THAN_7], - 1, - [Define if libpcre version is less than 7] - ) - ] - ) - ], - [found_libpcre=no] - ) + found_libpcre=no ] ) SSS_AC_EXPAND_LIB_DIR() AS_IF([test x"$found_libpcre" != xyes], - [AC_CHECK_HEADERS([pcre.h], - [AC_CHECK_LIB([pcre], - [pcre_compile], - [PCRE_LIBS="-L$sss_extra_libdir -lpcre"], - [AC_MSG_ERROR([No usable PCRE library found])], + [AC_CHECK_HEADERS([pcre2.h], + [AC_CHECK_LIB([libpcre2-8], + [pcre2_compile], + [PCRE_LIBS="-L$sss_extra_libdir -lpcre2-8"], + [AC_MSG_ERROR([No usable PCRE2 library found])], [-L$sss_extra_libdir])], - [AC_MSG_ERROR([pcre header files are not installed])])] + [AC_MSG_ERROR([pcre2 header files are not installed])])] ) diff --git a/src/util/sss_regexp.c b/src/util/sss_regexp.c index 1439c8c455..3fc1a7b8b3 100644 --- a/src/util/sss_regexp.c +++ b/src/util/sss_regexp.c @@ -32,7 +32,6 @@ #define EOK 0 #endif -#ifdef HAVE_LIBPCRE2 /* * sss_regexp with pcre2 */ @@ -124,102 +123,13 @@ static int sss_regexp_pcre2_get_named_substring(sss_regexp_t *self, return rc; } -#else /* !HAVE_LIBPCRE2 */ -/* - * sss_regexp with pcre - */ -struct _sss_regexp_t { - pcre *re; - int ovector[SSS_REGEXP_OVEC_SIZE]; - const char *matched_string; - const char *subject; -}; - -static int sss_regexp_pcre1_destroy(sss_regexp_t *self) -{ - if (self->re) { - pcre_free(self->re); - } - if (self->matched_string) { - pcre_free_substring(self->matched_string); - } - return 0; -} - -static int sss_regexp_pcre1_compile(sss_regexp_t *self, - const char *pattern, - int options) -{ - int errorcode; - const char *errormsg; - int erroroffset; - - self->re = pcre_compile2(pattern, - options, - &errorcode, - &errormsg, - &erroroffset, - NULL); - if (self->re == NULL) { - DEBUG(SSSDBG_CRIT_FAILURE, "Invalid Regular Expression pattern " - "at position %d. (Error: %d [%s])\n", erroroffset, errorcode, errormsg); - return errorcode; - } - return EOK; -} - -static int sss_regexp_pcre1_match(sss_regexp_t *self, - const char *subject, - int startoffset, - int options) -{ - if (!self->re) { - return SSS_REGEXP_ERROR_NOMATCH; - } - self->subject = subject; - return pcre_exec(self->re, - NULL, - subject, - strlen(subject), - startoffset, - options, - self->ovector, - SSS_REGEXP_OVEC_SIZE); -} - -static int sss_regexp_pcre1_get_named_substring(sss_regexp_t *self, - const char *name, - const char **value) -{ - int rc; - - if (self->matched_string) { - pcre_free_substring(self->matched_string); - self->matched_string = NULL; - } - rc = pcre_get_named_substring(self->re, - self->subject, - self->ovector, - SSS_REGEXP_OVEC_SIZE, - name, - &self->matched_string); - *value = self->matched_string; - return rc; -} - -#endif /* !HAVE_LIBPCRE2 */ - /* * sss_regexp talloc destructor */ static int sss_regexp_destroy(sss_regexp_t *self) { if (!self) return 0; -#ifdef HAVE_LIBPCRE2 return sss_regexp_pcre2_destroy(self); -#else - return sss_regexp_pcre1_destroy(self); -#endif } /* @@ -239,15 +149,9 @@ int sss_regexp_new(TALLOC_CTX *mem_ctx, } talloc_set_destructor(self, sss_regexp_destroy); -#ifdef HAVE_LIBPCRE2 ret = sss_regexp_pcre2_compile(self, pattern, options); -#else - ret = sss_regexp_pcre1_compile(self, - pattern, - options); -#endif if (ret != EOK) { talloc_free(self); self = NULL; @@ -266,11 +170,7 @@ int sss_regexp_match(sss_regexp_t *self, { if (!self || !self->re || !subject) return SSS_REGEXP_ERROR_NOMATCH; -#ifdef HAVE_LIBPCRE2 return sss_regexp_pcre2_match(self, subject, startoffset, options); -#else - return sss_regexp_pcre1_match(self, subject, startoffset, options); -#endif } @@ -285,9 +185,6 @@ int sss_regexp_get_named_substring(sss_regexp_t *self, *value = NULL; return SSS_REGEXP_ERROR_NOMATCH; } -#ifdef HAVE_LIBPCRE2 + return sss_regexp_pcre2_get_named_substring(self, name, value); -#else - return sss_regexp_pcre1_get_named_substring(self, name, value); -#endif } diff --git a/src/util/sss_regexp.h b/src/util/sss_regexp.h index 6ecc38fec6..2b29361b37 100644 --- a/src/util/sss_regexp.h +++ b/src/util/sss_regexp.h @@ -30,25 +30,12 @@ /* regexp class */ typedef struct _sss_regexp_t sss_regexp_t; -#ifdef HAVE_LIBPCRE2 -# include <pcre2.h> -# define SSS_REGEXP_ERROR_NOMATCH PCRE2_ERROR_NOMATCH -# define SSS_REGEXP_ERROR_NOMEMORY PCRE2_ERROR_NOMEMORY -# define SSS_REGEXP_NOTEMPTY PCRE2_NOTEMPTY -# define SSS_REGEXP_EXTENDED PCRE2_EXTENDED -# define SSS_REGEXP_DUPNAMES PCRE2_DUPNAMES -#else /* ! HAVE_LIBPCRE2 */ -# include <pcre.h> -# define SSS_REGEXP_ERROR_NOMATCH PCRE_ERROR_NOMATCH -# define SSS_REGEXP_ERROR_NOMEMORY PCRE_ERROR_NOMEMORY -# define SSS_REGEXP_NOTEMPTY PCRE_NOTEMPTY -# define SSS_REGEXP_EXTENDED PCRE_EXTENDED -# ifdef HAVE_LIBPCRE_LESSER_THAN_7 -# define SSS_REGEXP_DUPNAMES 0 -# else -# define SSS_REGEXP_DUPNAMES PCRE_DUPNAMES -# endif -#endif /* HAVE_LIBPCRE2 */ +#include <pcre2.h> +#define SSS_REGEXP_ERROR_NOMATCH PCRE2_ERROR_NOMATCH +#define SSS_REGEXP_ERROR_NOMEMORY PCRE2_ERROR_NOMEMORY +#define SSS_REGEXP_NOTEMPTY PCRE2_NOTEMPTY +#define SSS_REGEXP_EXTENDED PCRE2_EXTENDED +#define SSS_REGEXP_DUPNAMES PCRE2_DUPNAMES /* how to use sss_regexp: * diff --git a/src/util/usertools.c b/src/util/usertools.c index c2adc64fea..8c2ed4e2de 100644 --- a/src/util/usertools.c +++ b/src/util/usertools.c @@ -63,14 +63,6 @@ static errno_t get_id_provider_default_re(TALLOC_CTX *mem_ctx, const char *conf_path, char **re_pattern) { -#ifdef HAVE_LIBPCRE_LESSER_THAN_7 - DEBUG(SSSDBG_MINOR_FAILURE, - "The libpcre version on this system is too old. Only " - "the user@DOMAIN name fully qualified name format will " - "be supported\n"); - *re_pattern = NULL; - return EOK; -#else int ret; size_t c; char *id_provider = NULL; @@ -111,7 +103,6 @@ static errno_t get_id_provider_default_re(TALLOC_CTX *mem_ctx, done: talloc_free(id_provider); return ret; -#endif } static errno_t sss_fqnames_init(struct sss_names_ctx *nctx, const char *fq_fmt) @@ -236,16 +227,6 @@ int sss_names_init(TALLOC_CTX *mem_ctx, struct confdb_ctx *cdb, ret = ENOMEM; goto done; } -#ifdef HAVE_LIBPCRE_LESSER_THAN_7 - } else { - DEBUG(SSSDBG_OP_FAILURE, - "This binary was build with a version of libpcre that does " - "not support non-unique named subpatterns.\n"); - DEBUG(SSSDBG_OP_FAILURE, - "Please make sure that your pattern [%s] only contains " - "subpatterns with a unique name and uses " - "the Python syntax (?P<name>).\n", re_pattern); -#endif } if (conf_path != NULL) { From 21f3454d3903385e94a33eb9b95754a32d28e434 Mon Sep 17 00:00:00 2001 From: Alexey Tikhonov <atikh...@redhat.com> Date: Wed, 18 Aug 2021 19:53:44 +0200 Subject: [PATCH 2/2] UNICODE: drop support of glib2 for Unicode processing :relnote: This release drops support of `--with-unicode-lib` configure option. `libunistring` will be used unconditionally for Unicode processing. --- configure.ac | 12 ++------- contrib/sssd.spec.in | 1 - src/conf_macros.m4 | 20 --------------- src/external/glib.m4 | 11 --------- src/util/sss_tc_utf8.c | 34 +++----------------------- src/util/sss_utf8.c | 55 ------------------------------------------ 6 files changed, 6 insertions(+), 127 deletions(-) delete mode 100644 src/external/glib.m4 diff --git a/configure.ac b/configure.ac index c14a59eef1..60bcdfe832 100644 --- a/configure.ac +++ b/configure.ac @@ -238,16 +238,8 @@ AM_CONDITIONAL([BUILD_WITH_LIBSECRET], AM_CONDITIONAL([BUILD_WITH_LIBCURL], [test x"$have_curlopt_unix_sockpath" = xyes]) -WITH_UNICODE_LIB -AS_IF([test x$unicode_lib = xlibunistring], [ - m4_include([src/external/libunistring.m4]) - AC_DEFINE_UNQUOTED(HAVE_LIBUNISTRING, 1, [Using libunistring for unicode]) - UNICODE_LIBS=$UNISTRING_LIBS -], [ - m4_include([src/external/glib.m4]) - AC_DEFINE_UNQUOTED(HAVE_GLIB2, 1, [Using glib2 for unicode]) - UNICODE_LIBS=$GLIB2_LIBS -]) +m4_include([src/external/libunistring.m4]) +UNICODE_LIBS=$UNISTRING_LIBS AC_SUBST(UNICODE_LIBS) WITH_LIBNL diff --git a/contrib/sssd.spec.in b/contrib/sssd.spec.in index e2877b64b1..55ce2dd9aa 100644 --- a/contrib/sssd.spec.in +++ b/contrib/sssd.spec.in @@ -79,7 +79,6 @@ BuildRequires: findutils BuildRequires: gcc BuildRequires: gdm-pam-extensions-devel BuildRequires: gettext-devel -BuildRequires: glib2-devel # required for p11_child smartcard tests BuildRequires: gnutls-utils BuildRequires: jansson-devel diff --git a/src/conf_macros.m4 b/src/conf_macros.m4 index 0a1e6dd8fc..b77f8a3797 100644 --- a/src/conf_macros.m4 +++ b/src/conf_macros.m4 @@ -592,26 +592,6 @@ AC_ARG_ENABLE([all-experimental-features], [build_all_experimental_features=no]) -AC_DEFUN([WITH_UNICODE_LIB], - [ AC_ARG_WITH([unicode-lib], - [AC_HELP_STRING([--with-unicode-lib=<library>], - [Which library to use for Unicode processing (libunistring, glib2) [glib2]] - ) - ] - ) - unicode_lib="glib2" - if test x"$with_unicode_lib" != x; then - unicode_lib=$with_unicode_lib - fi - - if test x"$unicode_lib" != x"libunistring" -a x"$unicode_lib" != x"glib2"; then - AC_MSG_ERROR([Unsupported Unicode library]) - fi - - AM_CONDITIONAL([WITH_LIBUNISTRING], test x"$unicode_lib" = x"libunistring") - AM_CONDITIONAL([WITH_GLIB], test x"$unicode_lib" = x"glib2") - ]) - AC_DEFUN([WITH_APP_LIBS], [ AC_ARG_WITH([app-libs], [AC_HELP_STRING([--with-app-libs=<path>], diff --git a/src/external/glib.m4 b/src/external/glib.m4 deleted file mode 100644 index 3db25136b6..0000000000 --- a/src/external/glib.m4 +++ /dev/null @@ -1,11 +0,0 @@ -PKG_CHECK_MODULES([GLIB2],[glib-2.0]) - -if test x$has_glib2 != xno; then - SAFE_LIBS="$LIBS" - LIBS="$GLIB2_LIBS" - - AC_CHECK_FUNC([g_utf8_validate], - AC_DEFINE([HAVE_G_UTF8_VALIDATE], [1], - [Define if g_utf8_validate exists])) - LIBS="$SAFE_LIBS" -fi diff --git a/src/util/sss_tc_utf8.c b/src/util/sss_tc_utf8.c index 518a61a203..75d5c7136a 100644 --- a/src/util/sss_tc_utf8.c +++ b/src/util/sss_tc_utf8.c @@ -20,47 +20,21 @@ #include "config.h" -#ifdef HAVE_LIBUNISTRING #include <stdlib.h> #include <unistr.h> -#elif defined(HAVE_GLIB2) -#include <glib.h> -#endif +#include <unicase.h> #include <talloc.h> #include "util/util.h" -#ifdef HAVE_LIBUNISTRING -static void sss_utf8_free(char *ptr) -{ - free(ptr); -} -#elif defined(HAVE_GLIB2) -static void sss_utf8_free(char *ptr) -{ - g_free(ptr); -} -#else -#error No unicode library -#endif - /* Expects and returns NULL-terminated string; * result must be freed with sss_utf8_free() */ -#ifdef HAVE_LIBUNISTRING -static char *sss_utf8_tolower(const char *s) +static inline char *sss_utf8_tolower(const char *s) { size_t llen; - return u8_tolower((const uint8_t *)s, strlen(s) + 1, NULL, NULL, NULL, &llen); -} -#elif defined(HAVE_GLIB2) -static char *sss_utf8_tolower(const char *s) -{ - return g_utf8_strdown((const gchar *)s, -1); + return (char *)u8_tolower((const uint8_t *)s, strlen(s) + 1, NULL, NULL, NULL, &llen); } -#else -#error No unicode library -#endif char *sss_tc_utf8_str_tolower(TALLOC_CTX *mem_ctx, const char *s) { @@ -70,7 +44,7 @@ char *sss_tc_utf8_str_tolower(TALLOC_CTX *mem_ctx, const char *s) lower = sss_utf8_tolower(s); if (lower) { ret = talloc_strdup(mem_ctx, lower); - sss_utf8_free(lower); + free(lower); } return ret; diff --git a/src/util/sss_utf8.c b/src/util/sss_utf8.c index 57e2ea38e9..ac2c1ff7e1 100644 --- a/src/util/sss_utf8.c +++ b/src/util/sss_utf8.c @@ -25,17 +25,12 @@ #include <string.h> #include <errno.h> -#ifdef HAVE_LIBUNISTRING #include <stdlib.h> #include <unistr.h> #include <unicase.h> -#elif defined(HAVE_GLIB2) -#include <glib.h> -#endif #include "sss_utf8.h" -#ifdef HAVE_LIBUNISTRING bool sss_utf8_check(const uint8_t *s, size_t n) { if (u8_check(s, n) == NULL) { @@ -44,17 +39,6 @@ bool sss_utf8_check(const uint8_t *s, size_t n) return false; } -#elif defined(HAVE_GLIB2) -bool sss_utf8_check(const uint8_t *s, size_t n) -{ - return g_utf8_validate((const gchar *)s, n, NULL); -} - -#else -#error No unicode library -#endif - -#ifdef HAVE_LIBUNISTRING errno_t sss_utf8_case_eq(const uint8_t *s1, const uint8_t *s2) { @@ -87,45 +71,6 @@ errno_t sss_utf8_case_eq(const uint8_t *s1, const uint8_t *s2) return ENOMATCH; } -#elif defined(HAVE_GLIB2) -errno_t sss_utf8_case_eq(const uint8_t *s1, const uint8_t *s2) -{ - gchar *gs1; - gchar *gs2; - gssize n1, n2; - gint gret; - errno_t ret; - - n1 = g_utf8_strlen((const gchar *)s1, -1); - n2 = g_utf8_strlen((const gchar *)s2, -1); - - gs1 = g_utf8_casefold((const gchar *)s1, n1); - if (gs1 == NULL) { - return ENOMEM; - } - - gs2 = g_utf8_casefold((const gchar *)s2, n2); - if (gs2 == NULL) { - return ENOMEM; - } - - gret = g_utf8_collate(gs1, gs2); - if (gret == 0) { - ret = EOK; - } else { - ret = ENOMATCH; - } - - g_free(gs1); - g_free(gs2); - - return ret; -} - -#else -#error No unicode library -#endif - bool sss_string_equal(bool cs, const char *s1, const char *s2) { if (cs) {
_______________________________________________ sssd-devel mailing list -- sssd-devel@lists.fedorahosted.org To unsubscribe send an email to sssd-devel-le...@lists.fedorahosted.org Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/ List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedorahosted.org/archives/list/sssd-devel@lists.fedorahosted.org Do not reply to spam on the list, report it: https://pagure.io/fedora-infrastructure