aboutsummaryrefslogtreecommitdiffstats
path: root/testing/opensmtpd-extras/0003-table-ldap-reconnect.patch
blob: 985e766b9c181a4ced250e465f2a23a9b810bfe3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
From 04e4c521b34d1987af915ff97dcb0d87daf122b0 Mon Sep 17 00:00:00 2001
From: ID Fake <idfake@gmx.net>
Date: Thu, 27 Jul 2017 23:55:12 +0200
Subject: [PATCH] table-ldap reconnect

Patch-Source: https://github.com/OpenSMTPD/OpenSMTPD-extras/commit/04e4c521b34d1987af915ff97dcb0d87daf122b0
              https://github.com/OpenSMTPD/OpenSMTPD-extras/commit/07764840916e4d0ca0925dcc8722dd20d8347e95
---
 extras/tables/table-ldap/table_ldap.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/extras/tables/table-ldap/table_ldap.c b/extras/tables/table-ldap/table_ldap.c
index 5b54c86..5e9152f 100644
--- a/extras/tables/table-ldap/table_ldap.c
+++ b/extras/tables/table-ldap/table_ldap.c
@@ -77,13 +77,22 @@ table_ldap_update(void)
 static int
 table_ldap_check(int service, struct dict *params, const char *key)
 {
+	int ret;
+	
 	switch(service) {
 	case K_ALIAS:
 	case K_DOMAIN:
 	case K_CREDENTIALS:
 	case K_USERINFO:
 	case K_MAILADDR:
-		return ldap_run_query(service, key, NULL, 0);
+		if ((ret = ldap_run_query(service, key, NULL, 0)) >= 0) {
+			return ret;
+		}
+		log_debug("debug: table-ldap: reconnecting");
+		if (!(ret = ldap_open())) {
+			log_warnx("warn: table-ldap: failed to connect");
+		}
+		return ret;
 	default:
 		return -1;
 	}
@@ -306,6 +315,11 @@ ldap_open(void)
 {
 	struct aldap_message	*amsg = NULL;
 
+	if (aldap) {
+		aldap_close(aldap);
+		log_info("info: table-ldap: closed previous connection");
+	}
+
 	aldap = ldap_connect(url);
 	if (aldap == NULL) {
 		log_warnx("warn: ldap_connect error");
-- 
2.18.0