From a2a7378815725e6d8f54f97ab4f17f33a110fec7 Mon Sep 17 00:00:00 2001 From: Petr Písař Date: Nov 05 2019 11:48:53 +0000 Subject: Report detailed LDAP failures --- diff --git a/quota-4.05-warnquota-Free-LDAP-error-message.patch b/quota-4.05-warnquota-Free-LDAP-error-message.patch new file mode 100644 index 0000000..af8a680 --- /dev/null +++ b/quota-4.05-warnquota-Free-LDAP-error-message.patch @@ -0,0 +1,36 @@ +From a543b200cdd1e798383cc1070e51ad13ff424543 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= +Date: Tue, 5 Nov 2019 12:11:14 +0100 +Subject: [PATCH] warnquota: Free LDAP error message +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +ldap_get_option(3) documents that a pointer set by +LDAP_OPT_DIAGNOSTIC_MESSAGE must be freed with ldap_memfree(3). + +Signed-off-by: Petr Písař +--- + warnquota.c | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +diff --git a/warnquota.c b/warnquota.c +index d54b4c1..f6b42d5 100644 +--- a/warnquota.c ++++ b/warnquota.c +@@ -190,8 +190,11 @@ static void print_ldap_error(int err, char *prefix) + sstrncat(outbuf, ": %s\n", LDAP_ERR_BUF_SIZE); + errstr(outbuf, ldap_err2string(err)); + ldap_get_option(ldapconn, LDAP_OPT_DIAGNOSTIC_MESSAGE, (void *)&msg); +- if (msg && strcmp(msg, "")) ++ if (msg) { ++ if (strcmp(msg, "")) + errstr(_("Additional error info: %s\n"), msg); ++ ldap_memfree(msg); ++ } + } + + static int setup_ldap(struct configparams *config) +-- +2.21.0 + diff --git a/quota-4.05-warnquota-Print-also-additional-error-info-for-LDAP-.patch b/quota-4.05-warnquota-Print-also-additional-error-info-for-LDAP-.patch new file mode 100644 index 0000000..4742fc2 --- /dev/null +++ b/quota-4.05-warnquota-Print-also-additional-error-info-for-LDAP-.patch @@ -0,0 +1,82 @@ +From 52ead0d37dcbce59338dcb765527712c9ee656e1 Mon Sep 17 00:00:00 2001 +From: Jan Kara +Date: Thu, 12 Sep 2019 10:06:38 +0200 +Subject: [PATCH] warnquota: Print also additional error info for LDAP errors +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +LDAP library provides additional error information in some cases. Print +it make debugging LDAP setup easier. + +Signed-off-by: Jan Kara +Signed-off-by: Petr Písař +--- + warnquota.c | 26 +++++++++++++++++++++----- + 1 file changed, 21 insertions(+), 5 deletions(-) + +diff --git a/warnquota.c b/warnquota.c +index 24d7410..d54b4c1 100644 +--- a/warnquota.c ++++ b/warnquota.c +@@ -178,6 +178,22 @@ static void wc_exit(int ex_stat) + } + + #ifdef USE_LDAP_MAIL_LOOKUP ++ ++#define LDAP_ERR_BUF_SIZE 1024 ++ ++static void print_ldap_error(int err, char *prefix) ++{ ++ char *msg = NULL; ++ char outbuf[LDAP_ERR_BUF_SIZE]; ++ ++ sstrncpy(outbuf, prefix, LDAP_ERR_BUF_SIZE); ++ sstrncat(outbuf, ": %s\n", LDAP_ERR_BUF_SIZE); ++ errstr(outbuf, ldap_err2string(err)); ++ ldap_get_option(ldapconn, LDAP_OPT_DIAGNOSTIC_MESSAGE, (void *)&msg); ++ if (msg && strcmp(msg, "")) ++ errstr(_("Additional error info: %s\n"), msg); ++} ++ + static int setup_ldap(struct configparams *config) + { + int ret; +@@ -187,7 +203,7 @@ static int setup_ldap(struct configparams *config) + ret = ldap_initialize(&ldapconn, config->ldap_uri); + + if (ret != LDAP_SUCCESS) { +- errstr(_("ldap_initialize() failed: %s\n"), ldap_err2string(ret)); ++ print_ldap_error(ret, _("ldap_initialize() failed")); + return -1; + } + +@@ -196,13 +212,13 @@ static int setup_ldap(struct configparams *config) + ldap_set_option(ldapconn, LDAP_OPT_X_TLS_REQUIRE_CERT, &(config->ldap_tls)); + ret = ldap_start_tls_s(ldapconn, NULL, NULL); + if (ret != LDAP_SUCCESS) { +- errstr(_("ldap_start_tls_s() failed: %s\n"), ldap_err2string(ret)); +- return -1; ++ print_ldap_error(ret, _("ldap_start_tls_s() failed")); ++ return -1; + } + } + ret = ldap_sasl_bind_s(ldapconn, config->ldap_binddn, LDAP_SASL_SIMPLE, &cred, NULL, NULL, NULL); + if (ret != LDAP_SUCCESS) { +- errstr(_("ldap_sasl_bind_s() failed: %s\n"), ldap_err2string(ret)); ++ print_ldap_error(ret, _("ldap_sasl_bind_s() failed")); + return -1; + } + return 0; +@@ -428,7 +444,7 @@ static char *lookup_user(struct configparams *config, char *user) + + if (ret != LDAP_SUCCESS) { + errstr(_("Error with %s.\n"), user); +- errstr(_("ldap_search_ext_s() failed: %s\n"), ldap_err2string(ret)); ++ print_ldap_error(ret, _("ldap_search_ext_s() failed")); + return NULL; + } + +-- +2.21.0 + diff --git a/quota.spec b/quota.spec index 995728a..bff5844 100644 --- a/quota.spec +++ b/quota.spec @@ -88,6 +88,11 @@ Patch12: quota-4.05-warnquota-Fix-help-text.patch # Fix checking for the LDAP failures in the warnquota tool, # in upstream after 4.05 Patch13: quota-4.05-warnquota-Properly-detect-LDAP-errors.patch +# 1/2 Report detailed LDAP failures, in upstream after 4.05 +Patch14: quota-4.05-warnquota-Print-also-additional-error-info-for-LDAP-.patch +# 2/2 Report detailed LDAP failures, proposed to the upstream, +# +Patch15: quota-4.05-warnquota-Free-LDAP-error-message.patch BuildRequires: autoconf BuildRequires: automake BuildRequires: bash @@ -221,6 +226,8 @@ Linux/UNIX environment. %patch11 -p1 %patch12 -p1 %patch13 -p1 +%patch14 -p1 +%patch15 -p1 # Regenerate build scripts autoreconf -f -i @@ -374,6 +381,7 @@ make check - Optimize out useless checking of file systems with hidden quota files - Fix warnquota --help output - Fix checking for the LDAP failures in the warnquota tool +- Report detailed LDAP failures * Fri Jul 26 2019 Fedora Release Engineering - 1:4.05-5 - Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild