aboutsummaryrefslogtreecommitdiffstats
path: root/testing/opensmtpd-extras/0004-Add-ldap-reconnection-logic-to-lookup-function-reord.patch
blob: d85a69402ab95a67157acdc69e5e981a91b5a9b1 (plain)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
From a29785e9177f5801317fcb3db297cbdafa4f3d93 Mon Sep 17 00:00:00 2001
From: "Paul B. Henson" <henson@acm.org>
Date: Sat, 26 May 2018 18:09:25 -0700
Subject: [PATCH] Add ldap reconnection logic to lookup function; reorder a
 bit to avoid implicit function declaration errors.

Patch-Source: https://github.com/OpenSMTPD/OpenSMTPD-extras/commit/a29785e9177f5801317fcb3db297cbdafa4f3d93
---
 extras/tables/table-ldap/table_ldap.c | 88 +++++++++++++++------------
 1 file changed, 49 insertions(+), 39 deletions(-)

diff --git a/extras/tables/table-ldap/table_ldap.c b/extras/tables/table-ldap/table_ldap.c
index 88c9ffd..090cfb4 100644
--- a/extras/tables/table-ldap/table_ldap.c
+++ b/extras/tables/table-ldap/table_ldap.c
@@ -74,45 +74,6 @@ table_ldap_update(void)
 	return 1;
 }
 
-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:
-		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;
-	}
-}
-
-static int
-table_ldap_lookup(int service, struct dict *params, const char *key, char *dst, size_t sz)
-{
-	switch(service) {
-	case K_ALIAS:
-	case K_DOMAIN:
-	case K_CREDENTIALS:
-	case K_USERINFO:
-	case K_MAILADDR:
-		return ldap_run_query(service, key, dst, sz);
-	default:
-		return -1;
-	}
-}
-
 static int
 table_ldap_fetch(int service, struct dict *params, char *dst, size_t sz)
 {
@@ -361,6 +322,31 @@ err:
 	return 0;
 }
 
+static int
+table_ldap_lookup(int service, struct dict *params, const char *key, char *dst, size_t sz)
+{
+	int ret;
+
+	switch(service) {
+	case K_ALIAS:
+	case K_DOMAIN:
+	case K_CREDENTIALS:
+	case K_USERINFO:
+	case K_MAILADDR:
+		if ((ret = ldap_run_query(service, key, dst, sz)) > 0) {
+			return ret;
+		}
+		log_debug("debug: table-ldap: reconnecting");
+		if (!(ret = ldap_open())) {
+			log_warnx("warn: table-ldap: failed to connect");
+			return ret;
+		}
+		return ldap_run_query(service, key, dst, sz);
+	default:
+		return -1;
+	}
+}
+
 static int
 ldap_query(const char *filter, char **attributes, char ***outp, size_t n)
 {
@@ -498,6 +484,30 @@ end:
 	return ret;
 }
 
+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:
+		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;
+	}
+}
+
 int
 main(int argc, char **argv)
 {
-- 
2.18.0