Mercurial > dovecot > core-2.2
annotate src/auth/auth-settings.c @ 9057:c1b201243d52 HEAD
auth: Fixed listening in extra master/client sockets.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 09 Apr 2009 20:13:41 -0400 |
parents | 99659fef12b2 |
children | 6324a79d3ee1 |
rev | line source |
---|---|
9047
99659fef12b2
Updated missing copyright years to 2009.
Timo Sirainen <tss@iki.fi>
parents:
9045
diff
changeset
|
1 /* Copyright (c) 2005-2009 Dovecot authors, see the included COPYING file */ |
9002 | 2 |
3 #include "lib.h" | |
4 #include "array.h" | |
5 #include "hostpid.h" | |
6 #include "settings-parser.h" | |
7 #include "auth-settings.h" | |
8 | |
9 #include <stddef.h> | |
10 | |
11 extern struct setting_parser_info auth_socket_setting_parser_info; | |
12 extern struct setting_parser_info auth_setting_parser_info; | |
13 extern struct setting_parser_info auth_root_setting_parser_info; | |
14 | |
9045
0145ecc95752
settings_parser_info.check_func() now gets pool parameter if it wants to change settings.
Timo Sirainen <tss@iki.fi>
parents:
9011
diff
changeset
|
15 static bool auth_settings_check(void *_set, pool_t pool, const char **error_r); |
9011
c37f7113b1ee
doveconf now checks that all settings are ok by calling check functions.
Timo Sirainen <tss@iki.fi>
parents:
9002
diff
changeset
|
16 |
9002 | 17 #undef DEF |
18 #define DEF(type, name) \ | |
19 { type, #name, offsetof(struct auth_socket_unix_settings, name), NULL } | |
20 | |
21 static struct setting_define auth_socket_client_setting_defines[] = { | |
22 DEF(SET_STR, path), | |
23 DEF(SET_UINT, mode), | |
24 DEF(SET_STR, user), | |
25 DEF(SET_STR, group), | |
26 | |
27 SETTING_DEFINE_LIST_END | |
28 }; | |
29 | |
30 static struct auth_socket_unix_settings auth_socket_client_default_settings = { | |
31 MEMBER(path) "auth-client", | |
32 MEMBER(mode) 0660, | |
33 MEMBER(user) "", | |
34 MEMBER(group) "" | |
35 }; | |
36 | |
37 struct setting_parser_info auth_socket_client_setting_parser_info = { | |
38 MEMBER(defines) auth_socket_client_setting_defines, | |
39 MEMBER(defaults) &auth_socket_client_default_settings, | |
40 | |
41 MEMBER(parent) &auth_socket_setting_parser_info, | |
42 MEMBER(dynamic_parsers) NULL, | |
43 | |
44 MEMBER(parent_offset) (size_t)-1, | |
45 MEMBER(type_offset) (size_t)-1, | |
46 MEMBER(struct_size) sizeof(struct auth_socket_unix_settings) | |
47 }; | |
48 | |
49 #undef DEF | |
50 #define DEF(type, name) \ | |
51 { type, #name, offsetof(struct auth_socket_unix_settings, name), NULL } | |
52 | |
53 static struct setting_define auth_socket_master_setting_defines[] = { | |
54 DEF(SET_STR, path), | |
55 DEF(SET_UINT, mode), | |
56 DEF(SET_STR, user), | |
57 DEF(SET_STR, group), | |
58 | |
59 SETTING_DEFINE_LIST_END | |
60 }; | |
61 | |
62 static struct auth_socket_unix_settings auth_socket_master_default_settings = { | |
63 MEMBER(path) "auth-master", | |
64 MEMBER(mode) 0660, | |
65 MEMBER(user) "", | |
66 MEMBER(group) "" | |
67 }; | |
68 | |
69 struct setting_parser_info auth_socket_master_setting_parser_info = { | |
70 MEMBER(defines) auth_socket_master_setting_defines, | |
71 MEMBER(defaults) &auth_socket_master_default_settings, | |
72 | |
73 MEMBER(parent) &auth_socket_setting_parser_info, | |
74 MEMBER(dynamic_parsers) NULL, | |
75 | |
76 MEMBER(parent_offset) (size_t)-1, | |
77 MEMBER(type_offset) (size_t)-1, | |
78 MEMBER(struct_size) sizeof(struct auth_socket_unix_settings) | |
79 }; | |
80 | |
81 #undef DEF | |
82 #undef DEFLIST | |
83 #define DEF(type, name) \ | |
84 { type, #name, offsetof(struct auth_socket_settings, name), NULL } | |
85 #define DEFLIST(field, name, defines) \ | |
86 { SET_DEFLIST, name, offsetof(struct auth_socket_settings, field), defines } | |
87 | |
88 static struct setting_define auth_socket_setting_defines[] = { | |
9057
c1b201243d52
auth: Fixed listening in extra master/client sockets.
Timo Sirainen <tss@iki.fi>
parents:
9047
diff
changeset
|
89 DEF(SET_ENUM, type), |
9002 | 90 |
91 DEFLIST(clients, "client", &auth_socket_client_setting_parser_info), | |
92 DEFLIST(masters, "master", &auth_socket_master_setting_parser_info), | |
93 | |
94 SETTING_DEFINE_LIST_END | |
95 }; | |
96 | |
97 static struct auth_socket_settings auth_socket_default_settings = { | |
9057
c1b201243d52
auth: Fixed listening in extra master/client sockets.
Timo Sirainen <tss@iki.fi>
parents:
9047
diff
changeset
|
98 MEMBER(type) "listen:connect" |
9002 | 99 }; |
100 | |
101 struct setting_parser_info auth_socket_setting_parser_info = { | |
102 MEMBER(defines) auth_socket_setting_defines, | |
103 MEMBER(defaults) &auth_socket_default_settings, | |
104 | |
105 MEMBER(parent) &auth_setting_parser_info, | |
106 MEMBER(dynamic_parsers) NULL, | |
107 | |
108 MEMBER(parent_offset) (size_t)-1, | |
109 MEMBER(type_offset) offsetof(struct auth_socket_settings, type), | |
110 MEMBER(struct_size) sizeof(struct auth_socket_settings) | |
111 }; | |
112 | |
113 #undef DEF | |
114 #define DEF(type, name) \ | |
115 { type, #name, offsetof(struct auth_passdb_settings, name), NULL } | |
116 | |
117 static struct setting_define auth_passdb_setting_defines[] = { | |
118 DEF(SET_STR, driver), | |
119 DEF(SET_STR, args), | |
120 DEF(SET_BOOL, deny), | |
121 | |
122 SETTING_DEFINE_LIST_END | |
123 }; | |
124 | |
125 struct setting_parser_info auth_passdb_setting_parser_info = { | |
126 MEMBER(defines) auth_passdb_setting_defines, | |
127 MEMBER(defaults) NULL, | |
128 | |
129 MEMBER(parent) &auth_setting_parser_info, | |
130 MEMBER(dynamic_parsers) NULL, | |
131 | |
132 MEMBER(parent_offset) (size_t)-1, | |
133 MEMBER(type_offset) offsetof(struct auth_passdb_settings, driver), | |
134 MEMBER(struct_size) sizeof(struct auth_passdb_settings) | |
135 }; | |
136 | |
137 #undef DEF | |
138 #define DEF(type, name) \ | |
139 { type, #name, offsetof(struct auth_userdb_settings, name), NULL } | |
140 | |
141 static struct setting_define auth_userdb_setting_defines[] = { | |
142 DEF(SET_STR, driver), | |
143 DEF(SET_STR, args), | |
144 | |
145 SETTING_DEFINE_LIST_END | |
146 }; | |
147 | |
148 struct setting_parser_info auth_userdb_setting_parser_info = { | |
149 MEMBER(defines) auth_userdb_setting_defines, | |
150 MEMBER(defaults) NULL, | |
151 | |
152 MEMBER(parent) &auth_setting_parser_info, | |
153 MEMBER(dynamic_parsers) NULL, | |
154 | |
155 MEMBER(parent_offset) (size_t)-1, | |
156 MEMBER(type_offset) offsetof(struct auth_userdb_settings, driver), | |
157 MEMBER(struct_size) sizeof(struct auth_userdb_settings) | |
158 }; | |
159 | |
160 #undef DEF | |
161 #undef DEFLIST | |
162 #define DEF(type, name) \ | |
163 { type, #name, offsetof(struct auth_settings, name), NULL } | |
164 #define DEFLIST(field, name, defines) \ | |
165 { SET_DEFLIST, name, offsetof(struct auth_settings, field), defines } | |
166 | |
167 static struct setting_define auth_setting_defines[] = { | |
168 DEF(SET_STR, name), | |
169 DEF(SET_STR, mechanisms), | |
170 DEF(SET_STR, realms), | |
171 DEF(SET_STR, default_realm), | |
172 DEF(SET_UINT, cache_size), | |
173 DEF(SET_UINT, cache_ttl), | |
174 DEF(SET_UINT, cache_negative_ttl), | |
175 DEF(SET_STR, username_chars), | |
176 DEF(SET_STR, username_translation), | |
177 DEF(SET_STR, username_format), | |
178 DEF(SET_STR, master_user_separator), | |
179 DEF(SET_STR, anonymous_username), | |
180 DEF(SET_STR, krb5_keytab), | |
181 DEF(SET_STR, gssapi_hostname), | |
182 DEF(SET_STR, winbind_helper_path), | |
183 DEF(SET_UINT, failure_delay), | |
184 | |
185 DEF(SET_BOOL, verbose), | |
186 DEF(SET_BOOL, debug), | |
187 DEF(SET_BOOL, debug_passwords), | |
188 DEF(SET_BOOL, ssl_require_client_cert), | |
189 DEF(SET_BOOL, ssl_username_from_cert), | |
190 DEF(SET_BOOL, use_winbind), | |
191 | |
192 DEF(SET_UINT, worker_max_count), | |
193 | |
194 DEFLIST(sockets, "socket", &auth_socket_setting_parser_info), | |
195 DEFLIST(passdbs, "passdb", &auth_passdb_setting_parser_info), | |
196 DEFLIST(userdbs, "userdb", &auth_userdb_setting_parser_info), | |
197 | |
198 SETTING_DEFINE_LIST_END | |
199 }; | |
200 | |
201 static struct auth_settings auth_default_settings = { | |
202 MEMBER(name) NULL, | |
203 MEMBER(root) NULL, | |
204 | |
205 MEMBER(mechanisms) "plain", | |
206 MEMBER(realms) "", | |
207 MEMBER(default_realm) "", | |
208 MEMBER(cache_size) 0, | |
209 MEMBER(cache_ttl) 3600, | |
210 MEMBER(cache_negative_ttl) 0, | |
211 MEMBER(username_chars) "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.-_@", | |
212 MEMBER(username_translation) "", | |
213 MEMBER(username_format) "", | |
214 MEMBER(master_user_separator) "", | |
215 MEMBER(anonymous_username) "anonymous", | |
216 MEMBER(krb5_keytab) "", | |
217 MEMBER(gssapi_hostname) "", | |
218 MEMBER(winbind_helper_path) "/usr/bin/ntlm_auth", | |
219 MEMBER(failure_delay) 2, | |
220 | |
221 MEMBER(verbose) FALSE, | |
222 MEMBER(debug) FALSE, | |
223 MEMBER(debug_passwords) FALSE, | |
224 MEMBER(ssl_require_client_cert) FALSE, | |
225 MEMBER(ssl_username_from_cert) FALSE, | |
226 MEMBER(use_winbind) FALSE, | |
227 | |
228 MEMBER(worker_max_count) 30, | |
229 | |
230 MEMBER(sockets) ARRAY_INIT, | |
231 MEMBER(passdbs) ARRAY_INIT, | |
232 MEMBER(userdbs) ARRAY_INIT | |
233 }; | |
234 | |
235 struct setting_parser_info auth_setting_parser_info = { | |
236 MEMBER(defines) auth_setting_defines, | |
237 MEMBER(defaults) &auth_default_settings, | |
238 | |
239 MEMBER(parent) &auth_root_setting_parser_info, | |
240 MEMBER(dynamic_parsers) NULL, | |
241 | |
242 MEMBER(parent_offset) offsetof(struct auth_settings, root), | |
243 MEMBER(type_offset) offsetof(struct auth_settings, name), | |
9011
c37f7113b1ee
doveconf now checks that all settings are ok by calling check functions.
Timo Sirainen <tss@iki.fi>
parents:
9002
diff
changeset
|
244 MEMBER(struct_size) sizeof(struct auth_settings), |
c37f7113b1ee
doveconf now checks that all settings are ok by calling check functions.
Timo Sirainen <tss@iki.fi>
parents:
9002
diff
changeset
|
245 MEMBER(check_func) auth_settings_check |
9002 | 246 }; |
247 | |
248 #undef DEF | |
249 #undef DEFLIST | |
250 #define DEF(type, name) \ | |
251 { type, #name, offsetof(struct auth_root_settings, name), NULL } | |
252 #define DEFLIST(field, name, defines) \ | |
253 { SET_DEFLIST, name, offsetof(struct auth_root_settings, field), defines } | |
254 | |
255 static struct setting_define auth_root_setting_defines[] = { | |
256 DEF(SET_STR, base_dir), | |
257 DEFLIST(auths, "auth", &auth_setting_parser_info), | |
258 | |
259 SETTING_DEFINE_LIST_END | |
260 }; | |
261 | |
262 static struct auth_root_settings auth_root_default_settings = { | |
263 MEMBER(base_dir) PKG_RUNDIR, | |
264 MEMBER(auths) ARRAY_INIT | |
265 }; | |
266 | |
267 struct setting_parser_info auth_root_setting_parser_info = { | |
268 MEMBER(defines) auth_root_setting_defines, | |
269 MEMBER(defaults) &auth_root_default_settings, | |
270 | |
271 MEMBER(parent) NULL, | |
272 MEMBER(dynamic_parsers) NULL, | |
273 | |
274 MEMBER(parent_offset) (size_t)-1, | |
275 MEMBER(type_offset) (size_t)-1, | |
276 MEMBER(struct_size) sizeof(struct auth_root_settings) | |
277 }; | |
278 | |
279 static pool_t settings_pool = NULL; | |
280 | |
281 static void fix_base_path(struct auth_settings *set, const char **str) | |
282 { | |
283 if (*str != NULL && **str != '\0' && **str != '/') { | |
284 *str = p_strconcat(settings_pool, | |
285 set->root->base_dir, "/", *str, NULL); | |
286 } | |
287 } | |
288 | |
9011
c37f7113b1ee
doveconf now checks that all settings are ok by calling check functions.
Timo Sirainen <tss@iki.fi>
parents:
9002
diff
changeset
|
289 /* <settings checks> */ |
9045
0145ecc95752
settings_parser_info.check_func() now gets pool parameter if it wants to change settings.
Timo Sirainen <tss@iki.fi>
parents:
9011
diff
changeset
|
290 static bool auth_settings_check(void *_set ATTR_UNUSED, pool_t pool ATTR_UNUSED, |
9011
c37f7113b1ee
doveconf now checks that all settings are ok by calling check functions.
Timo Sirainen <tss@iki.fi>
parents:
9002
diff
changeset
|
291 const char **error_r ATTR_UNUSED) |
9002 | 292 { |
9011
c37f7113b1ee
doveconf now checks that all settings are ok by calling check functions.
Timo Sirainen <tss@iki.fi>
parents:
9002
diff
changeset
|
293 #ifndef CONFIG_BINARY |
c37f7113b1ee
doveconf now checks that all settings are ok by calling check functions.
Timo Sirainen <tss@iki.fi>
parents:
9002
diff
changeset
|
294 struct auth_settings *set = _set; |
9002 | 295 struct auth_socket_unix_settings *const *u; |
296 struct auth_socket_settings *const *sockets; | |
297 unsigned int i, j, count, count2; | |
298 | |
299 if (!array_is_created(&set->sockets)) | |
9011
c37f7113b1ee
doveconf now checks that all settings are ok by calling check functions.
Timo Sirainen <tss@iki.fi>
parents:
9002
diff
changeset
|
300 return TRUE; |
9002 | 301 |
302 sockets = array_get(&set->sockets, &count); | |
303 for (i = 0; i < count; i++) { | |
304 if (array_is_created(&sockets[i]->masters)) { | |
305 u = array_get(&sockets[i]->masters, &count2); | |
306 for (j = 0; j < count2; j++) | |
307 fix_base_path(set, &u[j]->path); | |
308 } | |
309 if (array_is_created(&sockets[i]->clients)) { | |
310 u = array_get(&sockets[i]->clients, &count2); | |
311 for (j = 0; j < count2; j++) | |
312 fix_base_path(set, &u[j]->path); | |
313 } | |
314 } | |
9011
c37f7113b1ee
doveconf now checks that all settings are ok by calling check functions.
Timo Sirainen <tss@iki.fi>
parents:
9002
diff
changeset
|
315 #endif |
c37f7113b1ee
doveconf now checks that all settings are ok by calling check functions.
Timo Sirainen <tss@iki.fi>
parents:
9002
diff
changeset
|
316 return TRUE; |
9002 | 317 } |
9011
c37f7113b1ee
doveconf now checks that all settings are ok by calling check functions.
Timo Sirainen <tss@iki.fi>
parents:
9002
diff
changeset
|
318 /* </settings checks> */ |
9002 | 319 |
320 struct auth_settings *auth_settings_read(const char *name) | |
321 { | |
322 struct setting_parser_context *parser; | |
323 struct auth_root_settings *set; | |
324 struct auth_settings *const *auths; | |
9011
c37f7113b1ee
doveconf now checks that all settings are ok by calling check functions.
Timo Sirainen <tss@iki.fi>
parents:
9002
diff
changeset
|
325 const char *error; |
9002 | 326 unsigned int i, count; |
327 | |
328 if (settings_pool == NULL) | |
329 settings_pool = pool_alloconly_create("auth settings", 1024); | |
330 else | |
331 p_clear(settings_pool); | |
332 | |
333 parser = settings_parser_init(settings_pool, | |
334 &auth_root_setting_parser_info, | |
335 SETTINGS_PARSER_FLAG_IGNORE_UNKNOWN_KEYS); | |
336 | |
337 auth_default_settings.gssapi_hostname = my_hostname; | |
338 | |
339 if (settings_parse_environ(parser) < 0) { | |
340 i_fatal("Error reading configuration: %s", | |
341 settings_parser_get_error(parser)); | |
342 } | |
343 | |
9045
0145ecc95752
settings_parser_info.check_func() now gets pool parameter if it wants to change settings.
Timo Sirainen <tss@iki.fi>
parents:
9011
diff
changeset
|
344 if (settings_parser_check(parser, settings_pool, &error) < 0) |
9011
c37f7113b1ee
doveconf now checks that all settings are ok by calling check functions.
Timo Sirainen <tss@iki.fi>
parents:
9002
diff
changeset
|
345 i_fatal("Invalid settings: %s", error); |
c37f7113b1ee
doveconf now checks that all settings are ok by calling check functions.
Timo Sirainen <tss@iki.fi>
parents:
9002
diff
changeset
|
346 |
9002 | 347 set = settings_parser_get(parser); |
348 settings_parser_deinit(&parser); | |
349 | |
350 if (array_is_created(&set->auths)) { | |
351 auths = array_get(&set->auths, &count); | |
352 for (i = 0; i < count; i++) { | |
9011
c37f7113b1ee
doveconf now checks that all settings are ok by calling check functions.
Timo Sirainen <tss@iki.fi>
parents:
9002
diff
changeset
|
353 if (strcmp(auths[i]->name, name) == 0) |
9002 | 354 return auths[i]; |
355 } | |
356 } | |
357 i_fatal("Error reading configuration: No auth section: %s", name); | |
358 return NULL; | |
359 } |