annotate src/auth/db-ldap.c @ 4749:2b899c97de29 HEAD

Don't call ldap_parse_sasl_bind_result() in ldap_bind()'s callback. We're not doing SASL authentication.
author Timo Sirainen <tss@iki.fi>
date Sat, 04 Nov 2006 22:09:57 +0200
parents 8f4eb963446c
children aadf124d273f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4426
b8089cf41c96 Check for sasl.h and sasl/sasl.h existence and use the one that's found. If
Timo Sirainen <tss@iki.fi>
parents: 4415
diff changeset
1 /* Copyright (C) 2003-2006 Timo Sirainen */
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
3474
9096b7957413 Removed direct config.h including. I'm not sure why it was done before,
Timo Sirainen <tss@iki.fi>
parents: 3306
diff changeset
3 #include "common.h"
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 #if defined(PASSDB_LDAP) || defined(USERDB_LDAP)
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6
1075
f1401fa7ab03 auth process fixes, LDAP seems to be working (with the kludge define or
Timo Sirainen <tss@iki.fi>
parents: 1062
diff changeset
7 #include "network.h"
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8 #include "ioloop.h"
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 #include "hash.h"
1189
2cb8e2136283 Escape special chars in username if needed.
Timo Sirainen <tss@iki.fi>
parents: 1182
diff changeset
10 #include "str.h"
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11 #include "settings.h"
3502
5e78500f1aee user_global_uid and user_global_gid settings weren't working. Also changed
Timo Sirainen <tss@iki.fi>
parents: 3474
diff changeset
12 #include "userdb.h"
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
13 #include "db-ldap.h"
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15 #include <stddef.h>
1610
6850142c4e25 New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents: 1330
diff changeset
16 #include <stdlib.h>
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17
4426
b8089cf41c96 Check for sasl.h and sasl/sasl.h existence and use the one that's found. If
Timo Sirainen <tss@iki.fi>
parents: 4415
diff changeset
18 #define HAVE_LDAP_SASL
4427
ffafc8583e06 Prefer sasl/sasl.h. Require SASL v2, otherwise disable it.
Timo Sirainen <tss@iki.fi>
parents: 4426
diff changeset
19 #ifdef HAVE_SASL_SASL_H
ffafc8583e06 Prefer sasl/sasl.h. Require SASL v2, otherwise disable it.
Timo Sirainen <tss@iki.fi>
parents: 4426
diff changeset
20 # include <sasl/sasl.h>
ffafc8583e06 Prefer sasl/sasl.h. Require SASL v2, otherwise disable it.
Timo Sirainen <tss@iki.fi>
parents: 4426
diff changeset
21 #elif defined (HAVE_SASL_H)
4426
b8089cf41c96 Check for sasl.h and sasl/sasl.h existence and use the one that's found. If
Timo Sirainen <tss@iki.fi>
parents: 4415
diff changeset
22 # include <sasl.h>
b8089cf41c96 Check for sasl.h and sasl/sasl.h existence and use the one that's found. If
Timo Sirainen <tss@iki.fi>
parents: 4415
diff changeset
23 #else
b8089cf41c96 Check for sasl.h and sasl/sasl.h existence and use the one that's found. If
Timo Sirainen <tss@iki.fi>
parents: 4415
diff changeset
24 # undef HAVE_LDAP_SASL
b8089cf41c96 Check for sasl.h and sasl/sasl.h existence and use the one that's found. If
Timo Sirainen <tss@iki.fi>
parents: 4415
diff changeset
25 #endif
4427
ffafc8583e06 Prefer sasl/sasl.h. Require SASL v2, otherwise disable it.
Timo Sirainen <tss@iki.fi>
parents: 4426
diff changeset
26 #if SASL_VERSION_MAJOR < 2
ffafc8583e06 Prefer sasl/sasl.h. Require SASL v2, otherwise disable it.
Timo Sirainen <tss@iki.fi>
parents: 4426
diff changeset
27 # undef HAVE_LDAP_SASL
ffafc8583e06 Prefer sasl/sasl.h. Require SASL v2, otherwise disable it.
Timo Sirainen <tss@iki.fi>
parents: 4426
diff changeset
28 #endif
4426
b8089cf41c96 Check for sasl.h and sasl/sasl.h existence and use the one that's found. If
Timo Sirainen <tss@iki.fi>
parents: 4415
diff changeset
29
1181
ac7dbb236b59 Rather than block for two seconds, we can just call ldap_result() again if
Timo Sirainen <tss@iki.fi>
parents: 1143
diff changeset
30 /* Older versions may require calling ldap_result() twice */
ac7dbb236b59 Rather than block for two seconds, we can just call ldap_result() again if
Timo Sirainen <tss@iki.fi>
parents: 1143
diff changeset
31 #if LDAP_VENDOR_VERSION <= 20112
1086
067130d609b7 Define OPENLDAP_ASYNC_WORKAROUND
Timo Sirainen <tss@iki.fi>
parents: 1075
diff changeset
32 # define OPENLDAP_ASYNC_WORKAROUND
067130d609b7 Define OPENLDAP_ASYNC_WORKAROUND
Timo Sirainen <tss@iki.fi>
parents: 1075
diff changeset
33 #endif
067130d609b7 Define OPENLDAP_ASYNC_WORKAROUND
Timo Sirainen <tss@iki.fi>
parents: 1075
diff changeset
34
2325
7613e0f68513 Fixed to compile with Solaris LDAP library
Timo Sirainen <tss@iki.fi>
parents: 1910
diff changeset
35 /* Solaris LDAP library doesn't have LDAP_OPT_SUCCESS */
7613e0f68513 Fixed to compile with Solaris LDAP library
Timo Sirainen <tss@iki.fi>
parents: 1910
diff changeset
36 #ifndef LDAP_OPT_SUCCESS
7613e0f68513 Fixed to compile with Solaris LDAP library
Timo Sirainen <tss@iki.fi>
parents: 1910
diff changeset
37 # define LDAP_OPT_SUCCESS LDAP_SUCCESS
7613e0f68513 Fixed to compile with Solaris LDAP library
Timo Sirainen <tss@iki.fi>
parents: 1910
diff changeset
38 #endif
7613e0f68513 Fixed to compile with Solaris LDAP library
Timo Sirainen <tss@iki.fi>
parents: 1910
diff changeset
39
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
40 #define DEF(type, name) \
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
41 { type, #name, offsetof(struct ldap_settings, name) }
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
42
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
43 static struct setting_def setting_defs[] = {
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
44 DEF(SET_STR, hosts),
1910
b9005f93be70 Patch by Quentin Garnier:
Timo Sirainen <tss@iki.fi>
parents: 1897
diff changeset
45 DEF(SET_STR, uris),
1075
f1401fa7ab03 auth process fixes, LDAP seems to be working (with the kludge define or
Timo Sirainen <tss@iki.fi>
parents: 1062
diff changeset
46 DEF(SET_STR, dn),
f1401fa7ab03 auth process fixes, LDAP seems to be working (with the kludge define or
Timo Sirainen <tss@iki.fi>
parents: 1062
diff changeset
47 DEF(SET_STR, dnpass),
3771
4b6d962485b9 Added authentication bind support. Patch by J.M. Maurer.
Timo Sirainen <tss@iki.fi>
parents: 3731
diff changeset
48 DEF(SET_BOOL, auth_bind),
3840
935f12d0d2fe Added fast authbinding and auth_bind_userdn setting. Patch by Geff
Timo Sirainen <tss@iki.fi>
parents: 3771
diff changeset
49 DEF(SET_STR, auth_bind_userdn),
4415
b91816cd1d16 Added TLS support for LDAP if the library supports it.
Timo Sirainen <tss@iki.fi>
parents: 4405
diff changeset
50 DEF(SET_BOOL, tls),
4319
31a28cd0b020 Added support for SASL binding. Patch by Geert Jansen
Timo Sirainen <tss@iki.fi>
parents: 4295
diff changeset
51 DEF(SET_BOOL, sasl_bind),
31a28cd0b020 Added support for SASL binding. Patch by Geert Jansen
Timo Sirainen <tss@iki.fi>
parents: 4295
diff changeset
52 DEF(SET_STR, sasl_mech),
31a28cd0b020 Added support for SASL binding. Patch by Geert Jansen
Timo Sirainen <tss@iki.fi>
parents: 4295
diff changeset
53 DEF(SET_STR, sasl_realm),
31a28cd0b020 Added support for SASL binding. Patch by Geert Jansen
Timo Sirainen <tss@iki.fi>
parents: 4295
diff changeset
54 DEF(SET_STR, sasl_authz_id),
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
55 DEF(SET_STR, deref),
1135
81930fff13cf passdb ldap added. fixes to userdb ldap.
Timo Sirainen <tss@iki.fi>
parents: 1086
diff changeset
56 DEF(SET_STR, scope),
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
57 DEF(SET_STR, base),
1282
e8894f2c776f Added ldap_version setting.
Timo Sirainen <tss@iki.fi>
parents: 1265
diff changeset
58 DEF(SET_INT, ldap_version),
1136
ad6343bd4479 Separate user and pass attrs/filters in config file
Timo Sirainen <tss@iki.fi>
parents: 1135
diff changeset
59 DEF(SET_STR, user_attrs),
ad6343bd4479 Separate user and pass attrs/filters in config file
Timo Sirainen <tss@iki.fi>
parents: 1135
diff changeset
60 DEF(SET_STR, user_filter),
ad6343bd4479 Separate user and pass attrs/filters in config file
Timo Sirainen <tss@iki.fi>
parents: 1135
diff changeset
61 DEF(SET_STR, pass_attrs),
1141
873634a5b472 Added user_global_uid and user_global_gid LDAP settings.
Timo Sirainen <tss@iki.fi>
parents: 1136
diff changeset
62 DEF(SET_STR, pass_filter),
1191
65e48854491d Added default_pass_scheme to LDAP. Support for more password schemes. Merged
Timo Sirainen <tss@iki.fi>
parents: 1189
diff changeset
63 DEF(SET_STR, default_pass_scheme),
3502
5e78500f1aee user_global_uid and user_global_gid settings weren't working. Also changed
Timo Sirainen <tss@iki.fi>
parents: 3474
diff changeset
64 DEF(SET_STR, user_global_uid),
3913
af15aab60ff1 Settings' default listing wasn't ended properly, which could have caused
Timo Sirainen <tss@iki.fi>
parents: 3908
diff changeset
65 DEF(SET_STR, user_global_gid),
af15aab60ff1 Settings' default listing wasn't ended properly, which could have caused
Timo Sirainen <tss@iki.fi>
parents: 3908
diff changeset
66
af15aab60ff1 Settings' default listing wasn't ended properly, which could have caused
Timo Sirainen <tss@iki.fi>
parents: 3908
diff changeset
67 { 0, NULL, 0 }
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
68 };
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
69
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
70 struct ldap_settings default_ldap_settings = {
1910
b9005f93be70 Patch by Quentin Garnier:
Timo Sirainen <tss@iki.fi>
parents: 1897
diff changeset
71 MEMBER(hosts) NULL,
b9005f93be70 Patch by Quentin Garnier:
Timo Sirainen <tss@iki.fi>
parents: 1897
diff changeset
72 MEMBER(uris) NULL,
1075
f1401fa7ab03 auth process fixes, LDAP seems to be working (with the kludge define or
Timo Sirainen <tss@iki.fi>
parents: 1062
diff changeset
73 MEMBER(dn) NULL,
f1401fa7ab03 auth process fixes, LDAP seems to be working (with the kludge define or
Timo Sirainen <tss@iki.fi>
parents: 1062
diff changeset
74 MEMBER(dnpass) NULL,
3771
4b6d962485b9 Added authentication bind support. Patch by J.M. Maurer.
Timo Sirainen <tss@iki.fi>
parents: 3731
diff changeset
75 MEMBER(auth_bind) FALSE,
3840
935f12d0d2fe Added fast authbinding and auth_bind_userdn setting. Patch by Geff
Timo Sirainen <tss@iki.fi>
parents: 3771
diff changeset
76 MEMBER(auth_bind_userdn) NULL,
4415
b91816cd1d16 Added TLS support for LDAP if the library supports it.
Timo Sirainen <tss@iki.fi>
parents: 4405
diff changeset
77 MEMBER(tls) FALSE,
4319
31a28cd0b020 Added support for SASL binding. Patch by Geert Jansen
Timo Sirainen <tss@iki.fi>
parents: 4295
diff changeset
78 MEMBER(sasl_bind) FALSE,
31a28cd0b020 Added support for SASL binding. Patch by Geert Jansen
Timo Sirainen <tss@iki.fi>
parents: 4295
diff changeset
79 MEMBER(sasl_mech) NULL,
31a28cd0b020 Added support for SASL binding. Patch by Geert Jansen
Timo Sirainen <tss@iki.fi>
parents: 4295
diff changeset
80 MEMBER(sasl_realm) NULL,
31a28cd0b020 Added support for SASL binding. Patch by Geert Jansen
Timo Sirainen <tss@iki.fi>
parents: 4295
diff changeset
81 MEMBER(sasl_authz_id) NULL,
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
82 MEMBER(deref) "never",
1135
81930fff13cf passdb ldap added. fixes to userdb ldap.
Timo Sirainen <tss@iki.fi>
parents: 1086
diff changeset
83 MEMBER(scope) "subtree",
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
84 MEMBER(base) NULL,
1282
e8894f2c776f Added ldap_version setting.
Timo Sirainen <tss@iki.fi>
parents: 1265
diff changeset
85 MEMBER(ldap_version) 2,
3094
d78e9a31b6d8 Move default filters/attrs to setting defaults rather than check it from
Timo Sirainen <tss@iki.fi>
parents: 2994
diff changeset
86 MEMBER(user_attrs) "uid,homeDirectory,,,uidNumber,gidNumber",
d78e9a31b6d8 Move default filters/attrs to setting defaults rather than check it from
Timo Sirainen <tss@iki.fi>
parents: 2994
diff changeset
87 MEMBER(user_filter) "(&(objectClass=posixAccount)(uid=%u))",
d78e9a31b6d8 Move default filters/attrs to setting defaults rather than check it from
Timo Sirainen <tss@iki.fi>
parents: 2994
diff changeset
88 MEMBER(pass_attrs) "uid,userPassword",
d78e9a31b6d8 Move default filters/attrs to setting defaults rather than check it from
Timo Sirainen <tss@iki.fi>
parents: 2994
diff changeset
89 MEMBER(pass_filter) "(&(objectClass=posixAccount)(uid=%u))",
1191
65e48854491d Added default_pass_scheme to LDAP. Support for more password schemes. Merged
Timo Sirainen <tss@iki.fi>
parents: 1189
diff changeset
90 MEMBER(default_pass_scheme) "crypt",
3502
5e78500f1aee user_global_uid and user_global_gid settings weren't working. Also changed
Timo Sirainen <tss@iki.fi>
parents: 3474
diff changeset
91 MEMBER(user_global_uid) "",
5e78500f1aee user_global_uid and user_global_gid settings weren't working. Also changed
Timo Sirainen <tss@iki.fi>
parents: 3474
diff changeset
92 MEMBER(user_global_gid) ""
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
93 };
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
94
1143
50f10a7a3bad Use the same LDAP connection for both userdb and passdb if config_path is
Timo Sirainen <tss@iki.fi>
parents: 1141
diff changeset
95 static struct ldap_connection *ldap_connections = NULL;
50f10a7a3bad Use the same LDAP connection for both userdb and passdb if config_path is
Timo Sirainen <tss@iki.fi>
parents: 1141
diff changeset
96
4741
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
97 static int db_ldap_bind(struct ldap_connection *conn);
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3840
diff changeset
98 static void ldap_conn_close(struct ldap_connection *conn, bool flush_requests);
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
99
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
100 static int deref2str(const char *str)
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
101 {
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
102 if (strcasecmp(str, "never") == 0)
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
103 return LDAP_DEREF_NEVER;
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
104 if (strcasecmp(str, "searching") == 0)
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
105 return LDAP_DEREF_SEARCHING;
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
106 if (strcasecmp(str, "finding") == 0)
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
107 return LDAP_DEREF_FINDING;
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
108 if (strcasecmp(str, "always") == 0)
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
109 return LDAP_DEREF_ALWAYS;
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
110
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
111 i_fatal("LDAP: Unknown deref option '%s'", str);
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
112 }
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
113
1135
81930fff13cf passdb ldap added. fixes to userdb ldap.
Timo Sirainen <tss@iki.fi>
parents: 1086
diff changeset
114 static int scope2str(const char *str)
81930fff13cf passdb ldap added. fixes to userdb ldap.
Timo Sirainen <tss@iki.fi>
parents: 1086
diff changeset
115 {
81930fff13cf passdb ldap added. fixes to userdb ldap.
Timo Sirainen <tss@iki.fi>
parents: 1086
diff changeset
116 if (strcasecmp(str, "base") == 0)
81930fff13cf passdb ldap added. fixes to userdb ldap.
Timo Sirainen <tss@iki.fi>
parents: 1086
diff changeset
117 return LDAP_SCOPE_BASE;
81930fff13cf passdb ldap added. fixes to userdb ldap.
Timo Sirainen <tss@iki.fi>
parents: 1086
diff changeset
118 if (strcasecmp(str, "onelevel") == 0)
81930fff13cf passdb ldap added. fixes to userdb ldap.
Timo Sirainen <tss@iki.fi>
parents: 1086
diff changeset
119 return LDAP_SCOPE_ONELEVEL;
81930fff13cf passdb ldap added. fixes to userdb ldap.
Timo Sirainen <tss@iki.fi>
parents: 1086
diff changeset
120 if (strcasecmp(str, "subtree") == 0)
81930fff13cf passdb ldap added. fixes to userdb ldap.
Timo Sirainen <tss@iki.fi>
parents: 1086
diff changeset
121 return LDAP_SCOPE_SUBTREE;
81930fff13cf passdb ldap added. fixes to userdb ldap.
Timo Sirainen <tss@iki.fi>
parents: 1086
diff changeset
122
81930fff13cf passdb ldap added. fixes to userdb ldap.
Timo Sirainen <tss@iki.fi>
parents: 1086
diff changeset
123 i_fatal("LDAP: Unknown scope option '%s'", str);
81930fff13cf passdb ldap added. fixes to userdb ldap.
Timo Sirainen <tss@iki.fi>
parents: 1086
diff changeset
124 }
81930fff13cf passdb ldap added. fixes to userdb ldap.
Timo Sirainen <tss@iki.fi>
parents: 1086
diff changeset
125
1210
8e6addbf12b3 minor ldap fixes
Timo Sirainen <tss@iki.fi>
parents: 1191
diff changeset
126 const char *ldap_get_error(struct ldap_connection *conn)
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
127 {
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
128 int ret, err;
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
129
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
130 ret = ldap_get_option(conn->ld, LDAP_OPT_ERROR_NUMBER, (void *) &err);
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
131 if (ret != LDAP_SUCCESS) {
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
132 i_error("LDAP: Can't get error number: %s",
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
133 ldap_err2string(ret));
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
134 return "??";
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
135 }
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
136
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
137 return ldap_err2string(err);
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
138 }
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
139
3771
4b6d962485b9 Added authentication bind support. Patch by J.M. Maurer.
Timo Sirainen <tss@iki.fi>
parents: 3731
diff changeset
140 void db_ldap_search(struct ldap_connection *conn, struct ldap_request *request,
4b6d962485b9 Added authentication bind support. Patch by J.M. Maurer.
Timo Sirainen <tss@iki.fi>
parents: 3731
diff changeset
141 int scope)
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
142 {
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
143 int msgid;
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
144
4742
62a5d2c10ecd Crashfixes
Timo Sirainen <tss@iki.fi>
parents: 4741
diff changeset
145 if (db_ldap_connect(conn) < 0) {
62a5d2c10ecd Crashfixes
Timo Sirainen <tss@iki.fi>
parents: 4741
diff changeset
146 request->callback(conn, request, NULL);
62a5d2c10ecd Crashfixes
Timo Sirainen <tss@iki.fi>
parents: 4741
diff changeset
147 return;
4741
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
148 }
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
149
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
150 if (conn->last_auth_bind) {
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
151 /* switch back to the default dn before doing the search
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
152 request. */
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
153 if (db_ldap_bind(conn) < 0) {
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
154 request->callback(conn, request, NULL);
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
155 return;
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
156 }
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
157 }
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
158
3771
4b6d962485b9 Added authentication bind support. Patch by J.M. Maurer.
Timo Sirainen <tss@iki.fi>
parents: 3731
diff changeset
159 msgid = ldap_search(conn->ld, request->base, scope,
3731
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
160 request->filter, request->attributes, 0);
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
161 if (msgid == -1) {
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
162 i_error("LDAP: ldap_search() failed (filter %s): %s",
3731
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
163 request->filter, ldap_get_error(conn));
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
164 request->callback(conn, request, NULL);
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
165 return;
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
166 }
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
167
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
168 hash_insert(conn->requests, POINTER_CAST(msgid), request);
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
169 }
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
170
3731
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
171 static void ldap_conn_retry_requests(struct ldap_connection *conn)
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
172 {
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
173 struct hash_table *old_requests;
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
174 struct hash_iterate_context *iter;
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
175 void *key, *value;
4741
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
176 bool have_binds = FALSE;
3731
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
177
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
178 i_assert(conn->connected);
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
179
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
180 if (hash_size(conn->requests) == 0)
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
181 return;
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
182
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
183 old_requests = conn->requests;
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
184 conn->requests = hash_create(default_pool, conn->pool, 0, NULL, NULL);
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
185
4741
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
186 conn->retrying = TRUE;
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
187 /* first retry all the search requests */
3731
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
188 iter = hash_iterate_init(old_requests);
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
189 while (hash_iterate(iter, &key, &value)) {
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
190 struct ldap_request *request = value;
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
191
4741
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
192 if (request->filter == NULL) {
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
193 /* bind request */
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
194 have_binds = TRUE;
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
195 } else {
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
196 i_assert(conn->connected);
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
197 db_ldap_search(conn, request, conn->set.ldap_scope);
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
198 }
3731
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
199 }
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
200 hash_iterate_deinit(iter);
4741
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
201
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
202 if (have_binds && conn->set.auth_bind) {
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
203 /* next retry all the bind requests. without auth binds the
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
204 only bind request can be the initial connection binding,
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
205 which we don't care to retry. */
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
206 iter = hash_iterate_init(old_requests);
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
207 while (hash_iterate(iter, &key, &value)) {
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
208 struct ldap_request *request = value;
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
209
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
210 if (request->filter == NULL)
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
211 request->callback(conn, request, NULL);
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
212 }
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
213 hash_iterate_deinit(iter);
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
214 }
3731
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
215 hash_destroy(old_requests);
4741
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
216
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
217 conn->retrying = FALSE;
3731
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
218 }
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
219
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
220 static void ldap_conn_reconnect(struct ldap_connection *conn)
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
221 {
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
222 ldap_conn_close(conn, FALSE);
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
223
4741
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
224 if (db_ldap_connect(conn) < 0) {
3731
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
225 /* failed to reconnect. fail all requests. */
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
226 ldap_conn_close(conn, TRUE);
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
227 }
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
228 }
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
229
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
230 static void ldap_input(void *context)
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
231 {
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
232 struct ldap_connection *conn = context;
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
233 struct ldap_request *request;
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
234 struct timeval timeout;
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
235 LDAPMessage *res;
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
236 int ret, msgid;
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
237
1210
8e6addbf12b3 minor ldap fixes
Timo Sirainen <tss@iki.fi>
parents: 1191
diff changeset
238 while (conn->ld != NULL) {
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
239 memset(&timeout, 0, sizeof(timeout));
1181
ac7dbb236b59 Rather than block for two seconds, we can just call ldap_result() again if
Timo Sirainen <tss@iki.fi>
parents: 1143
diff changeset
240 ret = ldap_result(conn->ld, LDAP_RES_ANY, 1, &timeout, &res);
1075
f1401fa7ab03 auth process fixes, LDAP seems to be working (with the kludge define or
Timo Sirainen <tss@iki.fi>
parents: 1062
diff changeset
241 #ifdef OPENLDAP_ASYNC_WORKAROUND
1181
ac7dbb236b59 Rather than block for two seconds, we can just call ldap_result() again if
Timo Sirainen <tss@iki.fi>
parents: 1143
diff changeset
242 if (ret == 0) {
ac7dbb236b59 Rather than block for two seconds, we can just call ldap_result() again if
Timo Sirainen <tss@iki.fi>
parents: 1143
diff changeset
243 /* try again, there may be another in buffer */
ac7dbb236b59 Rather than block for two seconds, we can just call ldap_result() again if
Timo Sirainen <tss@iki.fi>
parents: 1143
diff changeset
244 ret = ldap_result(conn->ld, LDAP_RES_ANY, 1,
ac7dbb236b59 Rather than block for two seconds, we can just call ldap_result() again if
Timo Sirainen <tss@iki.fi>
parents: 1143
diff changeset
245 &timeout, &res);
ac7dbb236b59 Rather than block for two seconds, we can just call ldap_result() again if
Timo Sirainen <tss@iki.fi>
parents: 1143
diff changeset
246 }
1075
f1401fa7ab03 auth process fixes, LDAP seems to be working (with the kludge define or
Timo Sirainen <tss@iki.fi>
parents: 1062
diff changeset
247 #endif
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
248 if (ret <= 0) {
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
249 if (ret < 0) {
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
250 i_error("LDAP: ldap_result() failed: %s",
1210
8e6addbf12b3 minor ldap fixes
Timo Sirainen <tss@iki.fi>
parents: 1191
diff changeset
251 ldap_get_error(conn));
3731
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
252 ldap_conn_reconnect(conn);
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
253 }
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
254 return;
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
255 }
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
256
1210
8e6addbf12b3 minor ldap fixes
Timo Sirainen <tss@iki.fi>
parents: 1191
diff changeset
257 msgid = ldap_msgid(res);
8e6addbf12b3 minor ldap fixes
Timo Sirainen <tss@iki.fi>
parents: 1191
diff changeset
258 request = hash_lookup(conn->requests, POINTER_CAST(msgid));
8e6addbf12b3 minor ldap fixes
Timo Sirainen <tss@iki.fi>
parents: 1191
diff changeset
259 if (request == NULL) {
8e6addbf12b3 minor ldap fixes
Timo Sirainen <tss@iki.fi>
parents: 1191
diff changeset
260 i_error("LDAP: Reply with unknown msgid %d",
8e6addbf12b3 minor ldap fixes
Timo Sirainen <tss@iki.fi>
parents: 1191
diff changeset
261 msgid);
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
262 } else {
1210
8e6addbf12b3 minor ldap fixes
Timo Sirainen <tss@iki.fi>
parents: 1191
diff changeset
263 hash_remove(conn->requests, POINTER_CAST(msgid));
8e6addbf12b3 minor ldap fixes
Timo Sirainen <tss@iki.fi>
parents: 1191
diff changeset
264 request->callback(conn, request, res);
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
265 }
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
266
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
267 ldap_msgfree(res);
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
268 }
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
269 }
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
270
4426
b8089cf41c96 Check for sasl.h and sasl/sasl.h existence and use the one that's found. If
Timo Sirainen <tss@iki.fi>
parents: 4415
diff changeset
271 #ifdef HAVE_LDAP_SASL
4405
fe17f63521ea Compiler warning fixes and some coding style cleanups.
Timo Sirainen <tss@iki.fi>
parents: 4319
diff changeset
272 static int
fe17f63521ea Compiler warning fixes and some coding style cleanups.
Timo Sirainen <tss@iki.fi>
parents: 4319
diff changeset
273 sasl_interact(LDAP *ld __attr_unused__, unsigned flags __attr_unused__,
fe17f63521ea Compiler warning fixes and some coding style cleanups.
Timo Sirainen <tss@iki.fi>
parents: 4319
diff changeset
274 void *defaults, void *interact)
4319
31a28cd0b020 Added support for SASL binding. Patch by Geert Jansen
Timo Sirainen <tss@iki.fi>
parents: 4295
diff changeset
275 {
4426
b8089cf41c96 Check for sasl.h and sasl/sasl.h existence and use the one that's found. If
Timo Sirainen <tss@iki.fi>
parents: 4415
diff changeset
276 struct ldap_sasl_bind_context *context = defaults;
4319
31a28cd0b020 Added support for SASL binding. Patch by Geert Jansen
Timo Sirainen <tss@iki.fi>
parents: 4295
diff changeset
277 sasl_interact_t *in;
4405
fe17f63521ea Compiler warning fixes and some coding style cleanups.
Timo Sirainen <tss@iki.fi>
parents: 4319
diff changeset
278 const char *str;
4319
31a28cd0b020 Added support for SASL binding. Patch by Geert Jansen
Timo Sirainen <tss@iki.fi>
parents: 4295
diff changeset
279
4405
fe17f63521ea Compiler warning fixes and some coding style cleanups.
Timo Sirainen <tss@iki.fi>
parents: 4319
diff changeset
280 for (in = interact; in->id != SASL_CB_LIST_END; in++) {
fe17f63521ea Compiler warning fixes and some coding style cleanups.
Timo Sirainen <tss@iki.fi>
parents: 4319
diff changeset
281 switch (in->id) {
4319
31a28cd0b020 Added support for SASL binding. Patch by Geert Jansen
Timo Sirainen <tss@iki.fi>
parents: 4295
diff changeset
282 case SASL_CB_GETREALM:
4405
fe17f63521ea Compiler warning fixes and some coding style cleanups.
Timo Sirainen <tss@iki.fi>
parents: 4319
diff changeset
283 str = context->realm;
4319
31a28cd0b020 Added support for SASL binding. Patch by Geert Jansen
Timo Sirainen <tss@iki.fi>
parents: 4295
diff changeset
284 break;
31a28cd0b020 Added support for SASL binding. Patch by Geert Jansen
Timo Sirainen <tss@iki.fi>
parents: 4295
diff changeset
285 case SASL_CB_AUTHNAME:
4405
fe17f63521ea Compiler warning fixes and some coding style cleanups.
Timo Sirainen <tss@iki.fi>
parents: 4319
diff changeset
286 str = context->authcid;
4319
31a28cd0b020 Added support for SASL binding. Patch by Geert Jansen
Timo Sirainen <tss@iki.fi>
parents: 4295
diff changeset
287 break;
31a28cd0b020 Added support for SASL binding. Patch by Geert Jansen
Timo Sirainen <tss@iki.fi>
parents: 4295
diff changeset
288 case SASL_CB_USER:
4405
fe17f63521ea Compiler warning fixes and some coding style cleanups.
Timo Sirainen <tss@iki.fi>
parents: 4319
diff changeset
289 str = context->authzid;
4319
31a28cd0b020 Added support for SASL binding. Patch by Geert Jansen
Timo Sirainen <tss@iki.fi>
parents: 4295
diff changeset
290 break;
31a28cd0b020 Added support for SASL binding. Patch by Geert Jansen
Timo Sirainen <tss@iki.fi>
parents: 4295
diff changeset
291 case SASL_CB_PASS:
4405
fe17f63521ea Compiler warning fixes and some coding style cleanups.
Timo Sirainen <tss@iki.fi>
parents: 4319
diff changeset
292 str = context->passwd;
fe17f63521ea Compiler warning fixes and some coding style cleanups.
Timo Sirainen <tss@iki.fi>
parents: 4319
diff changeset
293 break;
fe17f63521ea Compiler warning fixes and some coding style cleanups.
Timo Sirainen <tss@iki.fi>
parents: 4319
diff changeset
294 default:
fe17f63521ea Compiler warning fixes and some coding style cleanups.
Timo Sirainen <tss@iki.fi>
parents: 4319
diff changeset
295 str = NULL;
4319
31a28cd0b020 Added support for SASL binding. Patch by Geert Jansen
Timo Sirainen <tss@iki.fi>
parents: 4295
diff changeset
296 break;
31a28cd0b020 Added support for SASL binding. Patch by Geert Jansen
Timo Sirainen <tss@iki.fi>
parents: 4295
diff changeset
297 }
4405
fe17f63521ea Compiler warning fixes and some coding style cleanups.
Timo Sirainen <tss@iki.fi>
parents: 4319
diff changeset
298 if (str != NULL) {
fe17f63521ea Compiler warning fixes and some coding style cleanups.
Timo Sirainen <tss@iki.fi>
parents: 4319
diff changeset
299 in->len = strlen(str);
fe17f63521ea Compiler warning fixes and some coding style cleanups.
Timo Sirainen <tss@iki.fi>
parents: 4319
diff changeset
300 in->result = str;
4319
31a28cd0b020 Added support for SASL binding. Patch by Geert Jansen
Timo Sirainen <tss@iki.fi>
parents: 4295
diff changeset
301 }
31a28cd0b020 Added support for SASL binding. Patch by Geert Jansen
Timo Sirainen <tss@iki.fi>
parents: 4295
diff changeset
302
31a28cd0b020 Added support for SASL binding. Patch by Geert Jansen
Timo Sirainen <tss@iki.fi>
parents: 4295
diff changeset
303 }
31a28cd0b020 Added support for SASL binding. Patch by Geert Jansen
Timo Sirainen <tss@iki.fi>
parents: 4295
diff changeset
304 return LDAP_SUCCESS;
31a28cd0b020 Added support for SASL binding. Patch by Geert Jansen
Timo Sirainen <tss@iki.fi>
parents: 4295
diff changeset
305 }
4426
b8089cf41c96 Check for sasl.h and sasl/sasl.h existence and use the one that's found. If
Timo Sirainen <tss@iki.fi>
parents: 4415
diff changeset
306 #endif
4319
31a28cd0b020 Added support for SASL binding. Patch by Geert Jansen
Timo Sirainen <tss@iki.fi>
parents: 4295
diff changeset
307
4741
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
308 static int db_ldap_connect_finish(struct ldap_connection *conn, int ret)
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
309 {
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
310 if (ret == LDAP_SERVER_DOWN) {
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
311 i_error("LDAP: Can't connect to server: %s",
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
312 conn->set.uris != NULL ?
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
313 conn->set.uris : conn->set.hosts);
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
314 return -1;
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
315 }
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
316 if (ret != LDAP_SUCCESS) {
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
317 i_error("LDAP: binding failed (dn %s): %s",
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
318 conn->set.dn == NULL ? "(none)" : conn->set.dn,
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
319 ldap_get_error(conn));
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
320 return -1;
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
321 }
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
322
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
323 conn->connected = TRUE;
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
324
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
325 /* in case there are requests waiting, retry them */
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
326 ldap_conn_retry_requests(conn);
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
327 return 0;
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
328 }
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
329
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
330 static void db_ldap_bind_callback(struct ldap_connection *conn,
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
331 struct ldap_request *ldap_request,
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
332 LDAPMessage *res)
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
333 {
4741
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
334 int ret;
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
335
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
336 conn->connecting = FALSE;
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
337 i_free(ldap_request);
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
338
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
339 if (res == NULL) {
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
340 /* aborted */
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
341 return;
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
342 }
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
343
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
344 ret = ldap_result2error(conn->ld, res, FALSE);
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
345 (void)db_ldap_connect_finish(conn, ret);
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
346 }
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
347
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
348 static int db_ldap_bind(struct ldap_connection *conn)
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
349 {
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
350 struct ldap_request *ldap_request;
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
351 int msgid;
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
352
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
353 conn->connecting = TRUE;
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
354
4741
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
355 ldap_request = i_new(struct ldap_request, 1);
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
356 ldap_request->callback = db_ldap_bind_callback;
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
357 ldap_request->context = conn;
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
358
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
359 msgid = ldap_bind(conn->ld, conn->set.dn, conn->set.
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
360 dnpass, LDAP_AUTH_SIMPLE);
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
361 if (msgid == -1) {
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
362 i_error("ldap_bind(%s) failed: %s",
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
363 conn->set.dn, ldap_get_error(conn));
4742
62a5d2c10ecd Crashfixes
Timo Sirainen <tss@iki.fi>
parents: 4741
diff changeset
364 i_free(ldap_request);
4741
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
365 return -1;
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
366 }
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
367 hash_insert(conn->requests, POINTER_CAST(msgid), ldap_request);
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
368
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
369 /* we're binding back to the original DN, not doing an
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
370 authentication bind */
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
371 conn->last_auth_bind = FALSE;
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
372 return 0;
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
373 }
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
374
4742
62a5d2c10ecd Crashfixes
Timo Sirainen <tss@iki.fi>
parents: 4741
diff changeset
375 static void db_ldap_get_fd(struct ldap_connection *conn)
62a5d2c10ecd Crashfixes
Timo Sirainen <tss@iki.fi>
parents: 4741
diff changeset
376 {
62a5d2c10ecd Crashfixes
Timo Sirainen <tss@iki.fi>
parents: 4741
diff changeset
377 int ret;
62a5d2c10ecd Crashfixes
Timo Sirainen <tss@iki.fi>
parents: 4741
diff changeset
378
62a5d2c10ecd Crashfixes
Timo Sirainen <tss@iki.fi>
parents: 4741
diff changeset
379 /* get the connection's fd */
62a5d2c10ecd Crashfixes
Timo Sirainen <tss@iki.fi>
parents: 4741
diff changeset
380 ret = ldap_get_option(conn->ld, LDAP_OPT_DESC, (void *)&conn->fd);
62a5d2c10ecd Crashfixes
Timo Sirainen <tss@iki.fi>
parents: 4741
diff changeset
381 if (ret != LDAP_SUCCESS) {
62a5d2c10ecd Crashfixes
Timo Sirainen <tss@iki.fi>
parents: 4741
diff changeset
382 i_fatal("LDAP: Can't get connection fd: %s",
62a5d2c10ecd Crashfixes
Timo Sirainen <tss@iki.fi>
parents: 4741
diff changeset
383 ldap_err2string(ret));
62a5d2c10ecd Crashfixes
Timo Sirainen <tss@iki.fi>
parents: 4741
diff changeset
384 }
62a5d2c10ecd Crashfixes
Timo Sirainen <tss@iki.fi>
parents: 4741
diff changeset
385 i_assert(conn->fd != -1);
62a5d2c10ecd Crashfixes
Timo Sirainen <tss@iki.fi>
parents: 4741
diff changeset
386 net_set_nonblock(conn->fd, TRUE);
62a5d2c10ecd Crashfixes
Timo Sirainen <tss@iki.fi>
parents: 4741
diff changeset
387 }
62a5d2c10ecd Crashfixes
Timo Sirainen <tss@iki.fi>
parents: 4741
diff changeset
388
4741
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
389 int db_ldap_connect(struct ldap_connection *conn)
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
390 {
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
391 unsigned int ldap_version;
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
392 int ret;
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
393
4742
62a5d2c10ecd Crashfixes
Timo Sirainen <tss@iki.fi>
parents: 4741
diff changeset
394 if (conn->connected || conn->connecting)
4741
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
395 return 0;
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
396
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
397 if (conn->ld == NULL) {
1910
b9005f93be70 Patch by Quentin Garnier:
Timo Sirainen <tss@iki.fi>
parents: 1897
diff changeset
398 if (conn->set.uris != NULL) {
2325
7613e0f68513 Fixed to compile with Solaris LDAP library
Timo Sirainen <tss@iki.fi>
parents: 1910
diff changeset
399 #ifdef LDAP_HAVE_INITIALIZE
1910
b9005f93be70 Patch by Quentin Garnier:
Timo Sirainen <tss@iki.fi>
parents: 1897
diff changeset
400 if (ldap_initialize(&conn->ld, conn->set.uris) != LDAP_SUCCESS)
b9005f93be70 Patch by Quentin Garnier:
Timo Sirainen <tss@iki.fi>
parents: 1897
diff changeset
401 conn->ld = NULL;
2325
7613e0f68513 Fixed to compile with Solaris LDAP library
Timo Sirainen <tss@iki.fi>
parents: 1910
diff changeset
402 #else
7613e0f68513 Fixed to compile with Solaris LDAP library
Timo Sirainen <tss@iki.fi>
parents: 1910
diff changeset
403 i_fatal("LDAP: Your LDAP library doesn't support "
7613e0f68513 Fixed to compile with Solaris LDAP library
Timo Sirainen <tss@iki.fi>
parents: 1910
diff changeset
404 "'uris' setting, use 'hosts' instead.");
7613e0f68513 Fixed to compile with Solaris LDAP library
Timo Sirainen <tss@iki.fi>
parents: 1910
diff changeset
405 #endif
1910
b9005f93be70 Patch by Quentin Garnier:
Timo Sirainen <tss@iki.fi>
parents: 1897
diff changeset
406 } else
b9005f93be70 Patch by Quentin Garnier:
Timo Sirainen <tss@iki.fi>
parents: 1897
diff changeset
407 conn->ld = ldap_init(conn->set.hosts, LDAP_PORT);
b9005f93be70 Patch by Quentin Garnier:
Timo Sirainen <tss@iki.fi>
parents: 1897
diff changeset
408
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
409 if (conn->ld == NULL)
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
410 i_fatal("LDAP: ldap_init() failed with hosts: %s",
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
411 conn->set.hosts);
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
412
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
413 ret = ldap_set_option(conn->ld, LDAP_OPT_DEREF,
4741
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
414 (void *)&conn->set.ldap_deref);
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
415 if (ret != LDAP_SUCCESS) {
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
416 i_fatal("LDAP: Can't set deref option: %s",
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
417 ldap_err2string(ret));
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
418 }
1282
e8894f2c776f Added ldap_version setting.
Timo Sirainen <tss@iki.fi>
parents: 1265
diff changeset
419
4741
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
420 /* If SASL binds are used, the protocol version needs to be
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
421 at least 3 */
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
422 ldap_version = conn->set.sasl_bind &&
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
423 conn->set.ldap_version < 3 ? 3 :
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
424 conn->set.ldap_version;
1282
e8894f2c776f Added ldap_version setting.
Timo Sirainen <tss@iki.fi>
parents: 1265
diff changeset
425 ret = ldap_set_option(conn->ld, LDAP_OPT_PROTOCOL_VERSION,
4741
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
426 (void *)&ldap_version);
1282
e8894f2c776f Added ldap_version setting.
Timo Sirainen <tss@iki.fi>
parents: 1265
diff changeset
427 if (ret != LDAP_OPT_SUCCESS) {
e8894f2c776f Added ldap_version setting.
Timo Sirainen <tss@iki.fi>
parents: 1265
diff changeset
428 i_fatal("LDAP: Can't set protocol version %u: %s",
4741
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
429 ldap_version, ldap_err2string(ret));
1282
e8894f2c776f Added ldap_version setting.
Timo Sirainen <tss@iki.fi>
parents: 1265
diff changeset
430 }
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
431 }
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
432
4415
b91816cd1d16 Added TLS support for LDAP if the library supports it.
Timo Sirainen <tss@iki.fi>
parents: 4405
diff changeset
433 if (conn->set.tls) {
b91816cd1d16 Added TLS support for LDAP if the library supports it.
Timo Sirainen <tss@iki.fi>
parents: 4405
diff changeset
434 #ifdef LDAP_HAVE_START_TLS_S
b91816cd1d16 Added TLS support for LDAP if the library supports it.
Timo Sirainen <tss@iki.fi>
parents: 4405
diff changeset
435 ret = ldap_start_tls_s(conn->ld, NULL, NULL);
b91816cd1d16 Added TLS support for LDAP if the library supports it.
Timo Sirainen <tss@iki.fi>
parents: 4405
diff changeset
436 if (ret != LDAP_SUCCESS) {
b91816cd1d16 Added TLS support for LDAP if the library supports it.
Timo Sirainen <tss@iki.fi>
parents: 4405
diff changeset
437 i_error("LDAP: ldap_start_tls_s() failed: %s",
b91816cd1d16 Added TLS support for LDAP if the library supports it.
Timo Sirainen <tss@iki.fi>
parents: 4405
diff changeset
438 ldap_err2string(ret));
4741
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
439 return -1;
4415
b91816cd1d16 Added TLS support for LDAP if the library supports it.
Timo Sirainen <tss@iki.fi>
parents: 4405
diff changeset
440 }
b91816cd1d16 Added TLS support for LDAP if the library supports it.
Timo Sirainen <tss@iki.fi>
parents: 4405
diff changeset
441 #else
b91816cd1d16 Added TLS support for LDAP if the library supports it.
Timo Sirainen <tss@iki.fi>
parents: 4405
diff changeset
442 i_error("LDAP: Your LDAP library doesn't support TLS");
4741
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
443 return -1;
4415
b91816cd1d16 Added TLS support for LDAP if the library supports it.
Timo Sirainen <tss@iki.fi>
parents: 4405
diff changeset
444 #endif
b91816cd1d16 Added TLS support for LDAP if the library supports it.
Timo Sirainen <tss@iki.fi>
parents: 4405
diff changeset
445 }
b91816cd1d16 Added TLS support for LDAP if the library supports it.
Timo Sirainen <tss@iki.fi>
parents: 4405
diff changeset
446
4319
31a28cd0b020 Added support for SASL binding. Patch by Geert Jansen
Timo Sirainen <tss@iki.fi>
parents: 4295
diff changeset
447 if (conn->set.sasl_bind) {
4426
b8089cf41c96 Check for sasl.h and sasl/sasl.h existence and use the one that's found. If
Timo Sirainen <tss@iki.fi>
parents: 4415
diff changeset
448 #ifdef HAVE_LDAP_SASL
b8089cf41c96 Check for sasl.h and sasl/sasl.h existence and use the one that's found. If
Timo Sirainen <tss@iki.fi>
parents: 4415
diff changeset
449 struct ldap_sasl_bind_context context;
b8089cf41c96 Check for sasl.h and sasl/sasl.h existence and use the one that's found. If
Timo Sirainen <tss@iki.fi>
parents: 4415
diff changeset
450
b8089cf41c96 Check for sasl.h and sasl/sasl.h existence and use the one that's found. If
Timo Sirainen <tss@iki.fi>
parents: 4415
diff changeset
451 memset(&context, 0, sizeof(context));
4319
31a28cd0b020 Added support for SASL binding. Patch by Geert Jansen
Timo Sirainen <tss@iki.fi>
parents: 4295
diff changeset
452 context.authcid = conn->set.dn;
31a28cd0b020 Added support for SASL binding. Patch by Geert Jansen
Timo Sirainen <tss@iki.fi>
parents: 4295
diff changeset
453 context.passwd = conn->set.dnpass;
31a28cd0b020 Added support for SASL binding. Patch by Geert Jansen
Timo Sirainen <tss@iki.fi>
parents: 4295
diff changeset
454 context.realm = conn->set.sasl_realm;
31a28cd0b020 Added support for SASL binding. Patch by Geert Jansen
Timo Sirainen <tss@iki.fi>
parents: 4295
diff changeset
455 context.authzid = conn->set.sasl_authz_id;
31a28cd0b020 Added support for SASL binding. Patch by Geert Jansen
Timo Sirainen <tss@iki.fi>
parents: 4295
diff changeset
456
4743
8f4eb963446c Cleanup
Timo Sirainen <tss@iki.fi>
parents: 4742
diff changeset
457 /* There doesn't seem to be a way to do SASL binding
8f4eb963446c Cleanup
Timo Sirainen <tss@iki.fi>
parents: 4742
diff changeset
458 asynchronously.. */
4405
fe17f63521ea Compiler warning fixes and some coding style cleanups.
Timo Sirainen <tss@iki.fi>
parents: 4319
diff changeset
459 ret = ldap_sasl_interactive_bind_s(conn->ld, NULL,
fe17f63521ea Compiler warning fixes and some coding style cleanups.
Timo Sirainen <tss@iki.fi>
parents: 4319
diff changeset
460 conn->set.sasl_mech,
4319
31a28cd0b020 Added support for SASL binding. Patch by Geert Jansen
Timo Sirainen <tss@iki.fi>
parents: 4295
diff changeset
461 NULL, NULL, LDAP_SASL_QUIET,
31a28cd0b020 Added support for SASL binding. Patch by Geert Jansen
Timo Sirainen <tss@iki.fi>
parents: 4295
diff changeset
462 sasl_interact, &context);
4743
8f4eb963446c Cleanup
Timo Sirainen <tss@iki.fi>
parents: 4742
diff changeset
463 if (db_ldap_connect_finish(conn, ret) < 0)
8f4eb963446c Cleanup
Timo Sirainen <tss@iki.fi>
parents: 4742
diff changeset
464 return -1;
8f4eb963446c Cleanup
Timo Sirainen <tss@iki.fi>
parents: 4742
diff changeset
465 db_ldap_get_fd(conn);
4426
b8089cf41c96 Check for sasl.h and sasl/sasl.h existence and use the one that's found. If
Timo Sirainen <tss@iki.fi>
parents: 4415
diff changeset
466 #else
b8089cf41c96 Check for sasl.h and sasl/sasl.h existence and use the one that's found. If
Timo Sirainen <tss@iki.fi>
parents: 4415
diff changeset
467 i_fatal("LDAP: sasl_bind=yes but no SASL support compiled in");
b8089cf41c96 Check for sasl.h and sasl/sasl.h existence and use the one that's found. If
Timo Sirainen <tss@iki.fi>
parents: 4415
diff changeset
468 #endif
4319
31a28cd0b020 Added support for SASL binding. Patch by Geert Jansen
Timo Sirainen <tss@iki.fi>
parents: 4295
diff changeset
469 } else {
4741
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
470 if (db_ldap_bind(conn) < 0)
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
471 return -1;
4742
62a5d2c10ecd Crashfixes
Timo Sirainen <tss@iki.fi>
parents: 4741
diff changeset
472 db_ldap_get_fd(conn);
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
473 }
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
474
4741
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
475 conn->io = io_add(conn->fd, IO_READ, ldap_input, conn);
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
476 return 0;
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
477 }
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
478
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3840
diff changeset
479 static void ldap_conn_close(struct ldap_connection *conn, bool flush_requests)
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
480 {
1897
1e6ed8045f2b Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents: 1709
diff changeset
481 struct hash_iterate_context *iter;
1e6ed8045f2b Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents: 1709
diff changeset
482 void *key, *value;
1e6ed8045f2b Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents: 1709
diff changeset
483
3731
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
484 if (flush_requests) {
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
485 iter = hash_iterate_init(conn->requests);
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
486 while (hash_iterate(iter, &key, &value)) {
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
487 struct ldap_request *request = value;
1897
1e6ed8045f2b Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents: 1709
diff changeset
488
3731
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
489 request->callback(conn, request, NULL);
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
490 }
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
491 hash_iterate_deinit(iter);
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
492 hash_clear(conn->requests, FALSE);
1897
1e6ed8045f2b Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents: 1709
diff changeset
493 }
1210
8e6addbf12b3 minor ldap fixes
Timo Sirainen <tss@iki.fi>
parents: 1191
diff changeset
494
8e6addbf12b3 minor ldap fixes
Timo Sirainen <tss@iki.fi>
parents: 1191
diff changeset
495 conn->connected = FALSE;
8e6addbf12b3 minor ldap fixes
Timo Sirainen <tss@iki.fi>
parents: 1191
diff changeset
496
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
497 if (conn->io != NULL)
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
498 io_remove(&conn->io);
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
499
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
500 if (conn->ld != NULL) {
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
501 ldap_unbind(conn->ld);
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
502 conn->ld = NULL;
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
503 }
4741
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
504 conn->fd = -1;
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
505 }
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
506
3158
8849f2e380d1 userdb can now return extra parameters to master. Removed special handling
Timo Sirainen <tss@iki.fi>
parents: 3094
diff changeset
507 void db_ldap_set_attrs(struct ldap_connection *conn, const char *attrlist,
3306
aebed9a9edac If both userdb and passdb used LDAP the later one was overriding first one's
Timo Sirainen <tss@iki.fi>
parents: 3212
diff changeset
508 char ***attr_names_r, struct hash_table *attr_map,
4741
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
509 const char *const default_attr_map[],
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
510 const char *skip_attr)
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
511 {
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
512 const char *const *attr;
3158
8849f2e380d1 userdb can now return extra parameters to master. Removed special handling
Timo Sirainen <tss@iki.fi>
parents: 3094
diff changeset
513 char *name, *value, *p;
4741
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
514 unsigned int i, j, size;
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
515
3158
8849f2e380d1 userdb can now return extra parameters to master. Removed special handling
Timo Sirainen <tss@iki.fi>
parents: 3094
diff changeset
516 if (*attrlist == '\0')
8849f2e380d1 userdb can now return extra parameters to master. Removed special handling
Timo Sirainen <tss@iki.fi>
parents: 3094
diff changeset
517 return;
8849f2e380d1 userdb can now return extra parameters to master. Removed special handling
Timo Sirainen <tss@iki.fi>
parents: 3094
diff changeset
518
8849f2e380d1 userdb can now return extra parameters to master. Removed special handling
Timo Sirainen <tss@iki.fi>
parents: 3094
diff changeset
519 t_push();
8849f2e380d1 userdb can now return extra parameters to master. Removed special handling
Timo Sirainen <tss@iki.fi>
parents: 3094
diff changeset
520 attr = t_strsplit(attrlist, ",");
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
521
3212
eb840633c9bf LDAP crashfixes.
Timo Sirainen <tss@iki.fi>
parents: 3161
diff changeset
522 /* @UNSAFE */
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
523 for (size = 0; attr[size] != NULL; size++) ;
3306
aebed9a9edac If both userdb and passdb used LDAP the later one was overriding first one's
Timo Sirainen <tss@iki.fi>
parents: 3212
diff changeset
524 *attr_names_r = p_new(conn->pool, char *, size + 1);
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
525
4741
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
526 for (i = j = 0; i < size; i++) {
3158
8849f2e380d1 userdb can now return extra parameters to master. Removed special handling
Timo Sirainen <tss@iki.fi>
parents: 3094
diff changeset
527 p = strchr(attr[i], '=');
8849f2e380d1 userdb can now return extra parameters to master. Removed special handling
Timo Sirainen <tss@iki.fi>
parents: 3094
diff changeset
528 if (p == NULL) {
8849f2e380d1 userdb can now return extra parameters to master. Removed special handling
Timo Sirainen <tss@iki.fi>
parents: 3094
diff changeset
529 name = p_strdup(conn->pool, attr[i]);
8849f2e380d1 userdb can now return extra parameters to master. Removed special handling
Timo Sirainen <tss@iki.fi>
parents: 3094
diff changeset
530 value = *default_attr_map == NULL ? name :
8849f2e380d1 userdb can now return extra parameters to master. Removed special handling
Timo Sirainen <tss@iki.fi>
parents: 3094
diff changeset
531 p_strdup(conn->pool, *default_attr_map);
8849f2e380d1 userdb can now return extra parameters to master. Removed special handling
Timo Sirainen <tss@iki.fi>
parents: 3094
diff changeset
532 } else {
8849f2e380d1 userdb can now return extra parameters to master. Removed special handling
Timo Sirainen <tss@iki.fi>
parents: 3094
diff changeset
533 name = p_strdup_until(conn->pool, attr[i], p);
8849f2e380d1 userdb can now return extra parameters to master. Removed special handling
Timo Sirainen <tss@iki.fi>
parents: 3094
diff changeset
534 value = p_strdup(conn->pool, p + 1);
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
535 }
3158
8849f2e380d1 userdb can now return extra parameters to master. Removed special handling
Timo Sirainen <tss@iki.fi>
parents: 3094
diff changeset
536
4741
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
537 if (skip_attr != NULL && strcmp(skip_attr, value) == 0)
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
538 name = "";
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
539
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
540 if (*name != '\0') {
3306
aebed9a9edac If both userdb and passdb used LDAP the later one was overriding first one's
Timo Sirainen <tss@iki.fi>
parents: 3212
diff changeset
541 hash_insert(attr_map, name, value);
4741
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
542 (*attr_names_r)[j++] = name;
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
543 }
3158
8849f2e380d1 userdb can now return extra parameters to master. Removed special handling
Timo Sirainen <tss@iki.fi>
parents: 3094
diff changeset
544
8849f2e380d1 userdb can now return extra parameters to master. Removed special handling
Timo Sirainen <tss@iki.fi>
parents: 3094
diff changeset
545 if (*default_attr_map != NULL)
8849f2e380d1 userdb can now return extra parameters to master. Removed special handling
Timo Sirainen <tss@iki.fi>
parents: 3094
diff changeset
546 default_attr_map++;
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
547 }
3158
8849f2e380d1 userdb can now return extra parameters to master. Removed special handling
Timo Sirainen <tss@iki.fi>
parents: 3094
diff changeset
548 t_pop();
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
549 }
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
550
1330
7cde19dbe754 Moved auth_username_chars from db-pgsql to generic for all. Some other
Timo Sirainen <tss@iki.fi>
parents: 1282
diff changeset
551 #define IS_LDAP_ESCAPED_CHAR(c) \
7cde19dbe754 Moved auth_username_chars from db-pgsql to generic for all. Some other
Timo Sirainen <tss@iki.fi>
parents: 1282
diff changeset
552 ((c) == '*' || (c) == '(' || (c) == ')' || (c) == '\\')
7cde19dbe754 Moved auth_username_chars from db-pgsql to generic for all. Some other
Timo Sirainen <tss@iki.fi>
parents: 1282
diff changeset
553
4295
4fc637010202 Escape SQL strings using sql_escape_string(). Fixes the problems with
Timo Sirainen <tss@iki.fi>
parents: 4180
diff changeset
554 const char *ldap_escape(const char *str,
4fc637010202 Escape SQL strings using sql_escape_string(). Fixes the problems with
Timo Sirainen <tss@iki.fi>
parents: 4180
diff changeset
555 const struct auth_request *auth_request __attr_unused__)
1189
2cb8e2136283 Escape special chars in username if needed.
Timo Sirainen <tss@iki.fi>
parents: 1182
diff changeset
556 {
2cb8e2136283 Escape special chars in username if needed.
Timo Sirainen <tss@iki.fi>
parents: 1182
diff changeset
557 const char *p;
1330
7cde19dbe754 Moved auth_username_chars from db-pgsql to generic for all. Some other
Timo Sirainen <tss@iki.fi>
parents: 1282
diff changeset
558 string_t *ret;
1189
2cb8e2136283 Escape special chars in username if needed.
Timo Sirainen <tss@iki.fi>
parents: 1182
diff changeset
559
2cb8e2136283 Escape special chars in username if needed.
Timo Sirainen <tss@iki.fi>
parents: 1182
diff changeset
560 for (p = str; *p != '\0'; p++) {
1330
7cde19dbe754 Moved auth_username_chars from db-pgsql to generic for all. Some other
Timo Sirainen <tss@iki.fi>
parents: 1282
diff changeset
561 if (IS_LDAP_ESCAPED_CHAR(*p))
1189
2cb8e2136283 Escape special chars in username if needed.
Timo Sirainen <tss@iki.fi>
parents: 1182
diff changeset
562 break;
2cb8e2136283 Escape special chars in username if needed.
Timo Sirainen <tss@iki.fi>
parents: 1182
diff changeset
563 }
2cb8e2136283 Escape special chars in username if needed.
Timo Sirainen <tss@iki.fi>
parents: 1182
diff changeset
564
2cb8e2136283 Escape special chars in username if needed.
Timo Sirainen <tss@iki.fi>
parents: 1182
diff changeset
565 if (*p == '\0')
2cb8e2136283 Escape special chars in username if needed.
Timo Sirainen <tss@iki.fi>
parents: 1182
diff changeset
566 return str;
2cb8e2136283 Escape special chars in username if needed.
Timo Sirainen <tss@iki.fi>
parents: 1182
diff changeset
567
1330
7cde19dbe754 Moved auth_username_chars from db-pgsql to generic for all. Some other
Timo Sirainen <tss@iki.fi>
parents: 1282
diff changeset
568 ret = t_str_new((size_t) (p - str) + 64);
7cde19dbe754 Moved auth_username_chars from db-pgsql to generic for all. Some other
Timo Sirainen <tss@iki.fi>
parents: 1282
diff changeset
569 str_append_n(ret, str, (size_t) (p - str));
7cde19dbe754 Moved auth_username_chars from db-pgsql to generic for all. Some other
Timo Sirainen <tss@iki.fi>
parents: 1282
diff changeset
570
1189
2cb8e2136283 Escape special chars in username if needed.
Timo Sirainen <tss@iki.fi>
parents: 1182
diff changeset
571 for (; *p != '\0'; p++) {
1330
7cde19dbe754 Moved auth_username_chars from db-pgsql to generic for all. Some other
Timo Sirainen <tss@iki.fi>
parents: 1282
diff changeset
572 if (IS_LDAP_ESCAPED_CHAR(*p))
7cde19dbe754 Moved auth_username_chars from db-pgsql to generic for all. Some other
Timo Sirainen <tss@iki.fi>
parents: 1282
diff changeset
573 str_append_c(ret, '\\');
7cde19dbe754 Moved auth_username_chars from db-pgsql to generic for all. Some other
Timo Sirainen <tss@iki.fi>
parents: 1282
diff changeset
574 str_append_c(ret, *p);
1189
2cb8e2136283 Escape special chars in username if needed.
Timo Sirainen <tss@iki.fi>
parents: 1182
diff changeset
575 }
1330
7cde19dbe754 Moved auth_username_chars from db-pgsql to generic for all. Some other
Timo Sirainen <tss@iki.fi>
parents: 1282
diff changeset
576 return str_c(ret);
1189
2cb8e2136283 Escape special chars in username if needed.
Timo Sirainen <tss@iki.fi>
parents: 1182
diff changeset
577 }
2cb8e2136283 Escape special chars in username if needed.
Timo Sirainen <tss@iki.fi>
parents: 1182
diff changeset
578
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
579 static const char *parse_setting(const char *key, const char *value,
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
580 void *context)
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
581 {
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
582 struct ldap_connection *conn = context;
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
583
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
584 return parse_setting_from_defs(conn->pool, setting_defs,
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
585 &conn->set, key, value);
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
586 }
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
587
1143
50f10a7a3bad Use the same LDAP connection for both userdb and passdb if config_path is
Timo Sirainen <tss@iki.fi>
parents: 1141
diff changeset
588 static struct ldap_connection *ldap_conn_find(const char *config_path)
50f10a7a3bad Use the same LDAP connection for both userdb and passdb if config_path is
Timo Sirainen <tss@iki.fi>
parents: 1141
diff changeset
589 {
50f10a7a3bad Use the same LDAP connection for both userdb and passdb if config_path is
Timo Sirainen <tss@iki.fi>
parents: 1141
diff changeset
590 struct ldap_connection *conn;
50f10a7a3bad Use the same LDAP connection for both userdb and passdb if config_path is
Timo Sirainen <tss@iki.fi>
parents: 1141
diff changeset
591
50f10a7a3bad Use the same LDAP connection for both userdb and passdb if config_path is
Timo Sirainen <tss@iki.fi>
parents: 1141
diff changeset
592 for (conn = ldap_connections; conn != NULL; conn = conn->next) {
50f10a7a3bad Use the same LDAP connection for both userdb and passdb if config_path is
Timo Sirainen <tss@iki.fi>
parents: 1141
diff changeset
593 if (strcmp(conn->config_path, config_path) == 0)
50f10a7a3bad Use the same LDAP connection for both userdb and passdb if config_path is
Timo Sirainen <tss@iki.fi>
parents: 1141
diff changeset
594 return conn;
50f10a7a3bad Use the same LDAP connection for both userdb and passdb if config_path is
Timo Sirainen <tss@iki.fi>
parents: 1141
diff changeset
595 }
50f10a7a3bad Use the same LDAP connection for both userdb and passdb if config_path is
Timo Sirainen <tss@iki.fi>
parents: 1141
diff changeset
596
50f10a7a3bad Use the same LDAP connection for both userdb and passdb if config_path is
Timo Sirainen <tss@iki.fi>
parents: 1141
diff changeset
597 return NULL;
50f10a7a3bad Use the same LDAP connection for both userdb and passdb if config_path is
Timo Sirainen <tss@iki.fi>
parents: 1141
diff changeset
598 }
50f10a7a3bad Use the same LDAP connection for both userdb and passdb if config_path is
Timo Sirainen <tss@iki.fi>
parents: 1141
diff changeset
599
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
600 struct ldap_connection *db_ldap_init(const char *config_path)
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
601 {
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
602 struct ldap_connection *conn;
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
603 pool_t pool;
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
604
1143
50f10a7a3bad Use the same LDAP connection for both userdb and passdb if config_path is
Timo Sirainen <tss@iki.fi>
parents: 1141
diff changeset
605 /* see if it already exists */
50f10a7a3bad Use the same LDAP connection for both userdb and passdb if config_path is
Timo Sirainen <tss@iki.fi>
parents: 1141
diff changeset
606 conn = ldap_conn_find(config_path);
50f10a7a3bad Use the same LDAP connection for both userdb and passdb if config_path is
Timo Sirainen <tss@iki.fi>
parents: 1141
diff changeset
607 if (conn != NULL) {
50f10a7a3bad Use the same LDAP connection for both userdb and passdb if config_path is
Timo Sirainen <tss@iki.fi>
parents: 1141
diff changeset
608 conn->refcount++;
50f10a7a3bad Use the same LDAP connection for both userdb and passdb if config_path is
Timo Sirainen <tss@iki.fi>
parents: 1141
diff changeset
609 return conn;
50f10a7a3bad Use the same LDAP connection for both userdb and passdb if config_path is
Timo Sirainen <tss@iki.fi>
parents: 1141
diff changeset
610 }
50f10a7a3bad Use the same LDAP connection for both userdb and passdb if config_path is
Timo Sirainen <tss@iki.fi>
parents: 1141
diff changeset
611
3908
afe21b6d4b68 Give a clear error message if SQL/LDAP configuration file path was left
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
612 if (*config_path == '\0')
afe21b6d4b68 Give a clear error message if SQL/LDAP configuration file path was left
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
613 i_fatal("LDAP: Configuration file path not given");
afe21b6d4b68 Give a clear error message if SQL/LDAP configuration file path was left
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
614
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
615 pool = pool_alloconly_create("ldap_connection", 1024);
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
616 conn = p_new(pool, struct ldap_connection, 1);
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
617 conn->pool = pool;
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
618
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
619 conn->refcount = 1;
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
620 conn->requests = hash_create(default_pool, pool, 0, NULL, NULL);
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
621
4741
deccf9e1aebc LDAP code changes: If auth binds are used, bind back to the default dn
Timo Sirainen <tss@iki.fi>
parents: 4624
diff changeset
622 conn->fd = -1;
1143
50f10a7a3bad Use the same LDAP connection for both userdb and passdb if config_path is
Timo Sirainen <tss@iki.fi>
parents: 1141
diff changeset
623 conn->config_path = p_strdup(pool, config_path);
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
624 conn->set = default_ldap_settings;
1610
6850142c4e25 New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents: 1330
diff changeset
625 if (!settings_read(config_path, NULL, parse_setting, NULL, conn))
6850142c4e25 New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents: 1330
diff changeset
626 exit(FATAL_DEFAULT);
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
627
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
628 if (conn->set.base == NULL)
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
629 i_fatal("LDAP: No base given");
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
630
4006
0e8f0647504b Check that uris and hosts settings are correct.
Timo Sirainen <tss@iki.fi>
parents: 3913
diff changeset
631 if (conn->set.uris == NULL && conn->set.hosts == NULL)
0e8f0647504b Check that uris and hosts settings are correct.
Timo Sirainen <tss@iki.fi>
parents: 3913
diff changeset
632 i_fatal("LDAP: No uris or hosts set");
0e8f0647504b Check that uris and hosts settings are correct.
Timo Sirainen <tss@iki.fi>
parents: 3913
diff changeset
633 #ifndef LDAP_HAVE_INITIALIZE
4180
92b572fbb88a If LDAP library didn't have ldap_initialize() function, we always complained
Timo Sirainen <tss@iki.fi>
parents: 4006
diff changeset
634 if (conn->set.uris != NULL) {
4006
0e8f0647504b Check that uris and hosts settings are correct.
Timo Sirainen <tss@iki.fi>
parents: 3913
diff changeset
635 i_fatal("LDAP: Dovecot compiled without support for LDAP uris "
0e8f0647504b Check that uris and hosts settings are correct.
Timo Sirainen <tss@iki.fi>
parents: 3913
diff changeset
636 "(ldap_initialize not found)");
0e8f0647504b Check that uris and hosts settings are correct.
Timo Sirainen <tss@iki.fi>
parents: 3913
diff changeset
637 }
0e8f0647504b Check that uris and hosts settings are correct.
Timo Sirainen <tss@iki.fi>
parents: 3913
diff changeset
638 #endif
0e8f0647504b Check that uris and hosts settings are correct.
Timo Sirainen <tss@iki.fi>
parents: 3913
diff changeset
639
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
640 conn->set.ldap_deref = deref2str(conn->set.deref);
3502
5e78500f1aee user_global_uid and user_global_gid settings weren't working. Also changed
Timo Sirainen <tss@iki.fi>
parents: 3474
diff changeset
641 conn->set.ldap_scope = scope2str(conn->set.scope);
5e78500f1aee user_global_uid and user_global_gid settings weren't working. Also changed
Timo Sirainen <tss@iki.fi>
parents: 3474
diff changeset
642
5e78500f1aee user_global_uid and user_global_gid settings weren't working. Also changed
Timo Sirainen <tss@iki.fi>
parents: 3474
diff changeset
643 if (*conn->set.user_global_uid == '\0')
5e78500f1aee user_global_uid and user_global_gid settings weren't working. Also changed
Timo Sirainen <tss@iki.fi>
parents: 3474
diff changeset
644 conn->set.uid = (uid_t)-1;
5e78500f1aee user_global_uid and user_global_gid settings weren't working. Also changed
Timo Sirainen <tss@iki.fi>
parents: 3474
diff changeset
645 else {
5e78500f1aee user_global_uid and user_global_gid settings weren't working. Also changed
Timo Sirainen <tss@iki.fi>
parents: 3474
diff changeset
646 conn->set.uid =
5e78500f1aee user_global_uid and user_global_gid settings weren't working. Also changed
Timo Sirainen <tss@iki.fi>
parents: 3474
diff changeset
647 userdb_parse_uid(NULL, conn->set.user_global_uid);
5e78500f1aee user_global_uid and user_global_gid settings weren't working. Also changed
Timo Sirainen <tss@iki.fi>
parents: 3474
diff changeset
648 if (conn->set.uid == (uid_t)-1) {
5e78500f1aee user_global_uid and user_global_gid settings weren't working. Also changed
Timo Sirainen <tss@iki.fi>
parents: 3474
diff changeset
649 i_fatal("LDAP: Invalid user_global_uid: %s",
5e78500f1aee user_global_uid and user_global_gid settings weren't working. Also changed
Timo Sirainen <tss@iki.fi>
parents: 3474
diff changeset
650 conn->set.user_global_uid);
5e78500f1aee user_global_uid and user_global_gid settings weren't working. Also changed
Timo Sirainen <tss@iki.fi>
parents: 3474
diff changeset
651 }
5e78500f1aee user_global_uid and user_global_gid settings weren't working. Also changed
Timo Sirainen <tss@iki.fi>
parents: 3474
diff changeset
652 }
5e78500f1aee user_global_uid and user_global_gid settings weren't working. Also changed
Timo Sirainen <tss@iki.fi>
parents: 3474
diff changeset
653
5e78500f1aee user_global_uid and user_global_gid settings weren't working. Also changed
Timo Sirainen <tss@iki.fi>
parents: 3474
diff changeset
654 if (*conn->set.user_global_gid == '\0')
5e78500f1aee user_global_uid and user_global_gid settings weren't working. Also changed
Timo Sirainen <tss@iki.fi>
parents: 3474
diff changeset
655 conn->set.gid = (gid_t)-1;
5e78500f1aee user_global_uid and user_global_gid settings weren't working. Also changed
Timo Sirainen <tss@iki.fi>
parents: 3474
diff changeset
656 else {
5e78500f1aee user_global_uid and user_global_gid settings weren't working. Also changed
Timo Sirainen <tss@iki.fi>
parents: 3474
diff changeset
657 conn->set.gid =
5e78500f1aee user_global_uid and user_global_gid settings weren't working. Also changed
Timo Sirainen <tss@iki.fi>
parents: 3474
diff changeset
658 userdb_parse_gid(NULL, conn->set.user_global_gid);
5e78500f1aee user_global_uid and user_global_gid settings weren't working. Also changed
Timo Sirainen <tss@iki.fi>
parents: 3474
diff changeset
659 if (conn->set.gid == (gid_t)-1) {
5e78500f1aee user_global_uid and user_global_gid settings weren't working. Also changed
Timo Sirainen <tss@iki.fi>
parents: 3474
diff changeset
660 i_fatal("LDAP: Invalid user_global_gid: %s",
5e78500f1aee user_global_uid and user_global_gid settings weren't working. Also changed
Timo Sirainen <tss@iki.fi>
parents: 3474
diff changeset
661 conn->set.user_global_gid);
5e78500f1aee user_global_uid and user_global_gid settings weren't working. Also changed
Timo Sirainen <tss@iki.fi>
parents: 3474
diff changeset
662 }
5e78500f1aee user_global_uid and user_global_gid settings weren't working. Also changed
Timo Sirainen <tss@iki.fi>
parents: 3474
diff changeset
663 }
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
664
1143
50f10a7a3bad Use the same LDAP connection for both userdb and passdb if config_path is
Timo Sirainen <tss@iki.fi>
parents: 1141
diff changeset
665 conn->next = ldap_connections;
50f10a7a3bad Use the same LDAP connection for both userdb and passdb if config_path is
Timo Sirainen <tss@iki.fi>
parents: 1141
diff changeset
666 ldap_connections = conn;
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
667 return conn;
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
668 }
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
669
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
670 void db_ldap_unref(struct ldap_connection **_conn)
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
671 {
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
672 struct ldap_connection *conn = *_conn;
3657
0c10475d9968 Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents: 3502
diff changeset
673 struct ldap_connection **p;
0c10475d9968 Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents: 3502
diff changeset
674
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
675 *_conn = NULL;
3657
0c10475d9968 Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents: 3502
diff changeset
676 i_assert(conn->refcount >= 0);
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
677 if (--conn->refcount > 0)
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
678 return;
3657
0c10475d9968 Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents: 3502
diff changeset
679
0c10475d9968 Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents: 3502
diff changeset
680 for (p = &ldap_connections; *p != NULL; p = &(*p)->next) {
0c10475d9968 Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents: 3502
diff changeset
681 if (*p == conn) {
0c10475d9968 Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents: 3502
diff changeset
682 *p = conn->next;
0c10475d9968 Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents: 3502
diff changeset
683 break;
0c10475d9968 Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents: 3502
diff changeset
684 }
0c10475d9968 Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents: 3502
diff changeset
685 }
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
686
3731
0a7beabfe332 If LDAP lookup fails because connection gets closed, try retrying it again
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
687 ldap_conn_close(conn, TRUE);
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
688
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
689 hash_destroy(conn->requests);
3306
aebed9a9edac If both userdb and passdb used LDAP the later one was overriding first one's
Timo Sirainen <tss@iki.fi>
parents: 3212
diff changeset
690 if (conn->pass_attr_map != NULL)
aebed9a9edac If both userdb and passdb used LDAP the later one was overriding first one's
Timo Sirainen <tss@iki.fi>
parents: 3212
diff changeset
691 hash_destroy(conn->pass_attr_map);
aebed9a9edac If both userdb and passdb used LDAP the later one was overriding first one's
Timo Sirainen <tss@iki.fi>
parents: 3212
diff changeset
692 if (conn->user_attr_map != NULL)
aebed9a9edac If both userdb and passdb used LDAP the later one was overriding first one's
Timo Sirainen <tss@iki.fi>
parents: 3212
diff changeset
693 hash_destroy(conn->user_attr_map);
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
694 pool_unref(conn->pool);
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
695 }
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
696
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
697 #endif