Link Here
|
1 |
diff -Naur new/lighttpd-1.4.23/src/http_auth.c old/lighttpd-1.4.23/src/http_auth.c |
|
|
2 |
--- src/http_auth.c 2009-06-11 14:05:06.000000000 +0400 |
3 |
+++ src/http_auth.c 2009-10-08 10:10:15.000000000 +0400 |
4 |
@@ -24,6 +24,7 @@ |
5 |
#include <errno.h> |
6 |
#include <unistd.h> |
7 |
#include <ctype.h> |
8 |
+#include <mysql/mysql.h> |
9 |
|
10 |
#include "server.h" |
11 |
#include "log.h" |
12 |
@@ -291,6 +292,117 @@ |
13 |
stream_close(&f); |
14 |
} else if (p->conf.auth_backend == AUTH_BACKEND_LDAP) { |
15 |
ret = 0; |
16 |
+ } else if (p->conf.auth_backend == AUTH_BACKEND_MYSQL) { |
17 |
+ MYSQL_RES *result; |
18 |
+ MYSQL_ROW row; |
19 |
+ int port = atoi(p->conf.auth_mysql_port->ptr); |
20 |
+ char q[255]; |
21 |
+ |
22 |
+ if (p->conf.auth_mysql_socket->ptr != NULL) |
23 |
+ if (0 == strcmp(p->conf.auth_mysql_socket->ptr, "")) p->conf.auth_mysql_socket->ptr = NULL; |
24 |
+ |
25 |
+ p->conf.mysql_conn = mysql_init(NULL); |
26 |
+ |
27 |
+ if (mysql_real_connect(p->conf.mysql_conn, p->conf.auth_mysql_host->ptr, p->conf.auth_mysql_user->ptr, p->conf.auth_mysql_pass->ptr, p->conf.auth_mysql_db->ptr, port, p->conf.auth_mysql_socket->ptr, 0)) |
28 |
+ { |
29 |
+//#define MY_HOSTING |
30 |
+ |
31 |
+#ifdef MY_HOSTING |
32 |
+ char my_full_realm[255]; |
33 |
+ char *my_realm = NULL; |
34 |
+ char *my_domain = NULL; |
35 |
+ |
36 |
+ char *uname; |
37 |
+ size_t unamelen; |
38 |
+ |
39 |
+ unamelen = strlen(username->ptr); |
40 |
+ uname = malloc(unamelen*2+1); |
41 |
+ |
42 |
+ mysql_real_escape_string(p->conf.mysql_conn, |
43 |
+ uname, username->ptr, |
44 |
+ (unsigned long)unamelen); |
45 |
+ |
46 |
+ strcpy(my_full_realm, realm->ptr); |
47 |
+ my_realm = strtok(my_full_realm, "@"); |
48 |
+ |
49 |
+ if (my_realm != NULL) |
50 |
+ my_domain = strtok(NULL, "@"); |
51 |
+ |
52 |
+ sprintf(q, "SELECT %s FROM %s, %s WHERE %s='%s' AND %s='%s' AND %s='%s' AND %s=%s", |
53 |
+ p->conf.auth_mysql_col_pass->ptr, |
54 |
+ |
55 |
+ p->conf.auth_mysql_users_table->ptr, |
56 |
+ p->conf.auth_mysql_domains_table->ptr, |
57 |
+ |
58 |
+ p->conf.auth_mysql_col_user->ptr, |
59 |
+ uname, |
60 |
+ |
61 |
+ p->conf.auth_mysql_col_realm->ptr, |
62 |
+ my_realm, |
63 |
+ |
64 |
+ p->conf.auth_mysql_col_domain->ptr, |
65 |
+ my_domain, |
66 |
+ |
67 |
+ p->conf.auth_mysql_domains_table_col_domain_id->ptr, |
68 |
+ p->conf.auth_mysql_users_table_col_domain_id->ptr |
69 |
+ ); |
70 |
+ |
71 |
+ free(uname); |
72 |
+#else |
73 |
+ // sanitize username & realm by taguchi@ff.iij4u.or.jp |
74 |
+ char *uname, *urealm; |
75 |
+ size_t unamelen, urealmlen; |
76 |
+ |
77 |
+ unamelen = strlen(username->ptr); |
78 |
+ urealmlen = strlen(realm->ptr); |
79 |
+ uname = malloc(unamelen*2+1); |
80 |
+ urealm = malloc(urealmlen*2+1); |
81 |
+ |
82 |
+ mysql_real_escape_string(p->conf.mysql_conn, |
83 |
+ uname, username->ptr, |
84 |
+ (unsigned long)unamelen); |
85 |
+ |
86 |
+ mysql_real_escape_string(p->conf.mysql_conn, |
87 |
+ urealm, realm->ptr, |
88 |
+ (unsigned long)unamelen); |
89 |
+ |
90 |
+ mysql_real_escape_string(p->conf.mysql_conn, |
91 |
+ urealm, realm->ptr, |
92 |
+ (unsigned long)urealmlen); |
93 |
+ |
94 |
+ sprintf(q, "SELECT %s FROM %s WHERE %s='%s' AND %s='%s'", |
95 |
+ p->conf.auth_mysql_col_pass->ptr, |
96 |
+ p->conf.auth_mysql_users_table->ptr, |
97 |
+ p->conf.auth_mysql_col_user->ptr, |
98 |
+ uname, |
99 |
+ p->conf.auth_mysql_col_realm->ptr, |
100 |
+ urealm |
101 |
+ ); |
102 |
+ |
103 |
+ free(uname); |
104 |
+ free(urealm); |
105 |
+#endif |
106 |
+ |
107 |
+ mysql_query(p->conf.mysql_conn, q); |
108 |
+ result = mysql_store_result(p->conf.mysql_conn); |
109 |
+ if (mysql_num_rows(result) == 1) |
110 |
+ { |
111 |
+ /* found */ |
112 |
+ row = mysql_fetch_row(result); |
113 |
+ buffer_copy_string_len(password, row[0], strlen(row[0])); |
114 |
+ |
115 |
+ ret = 0; |
116 |
+ } else |
117 |
+ { |
118 |
+ /* not found */ |
119 |
+ ret = -1; |
120 |
+ } |
121 |
+ |
122 |
+ mysql_free_result(result); |
123 |
+ mysql_close(p->conf.mysql_conn); |
124 |
+ |
125 |
+ p->conf.mysql_conn = NULL; |
126 |
+ } |
127 |
} else { |
128 |
return -1; |
129 |
} |
130 |
@@ -831,6 +943,60 @@ |
131 |
|
132 |
return 0; |
133 |
#endif |
134 |
+ } else if (p->conf.auth_backend == AUTH_BACKEND_MYSQL) { |
135 |
+ /* |
136 |
+ we check for md5 crypt() now |
137 |
+ request by Nicola Tiling <nti@w4w.net> |
138 |
+ */ |
139 |
+ if (password->ptr[0] == '$' && password->ptr[2] == '$') |
140 |
+ { |
141 |
+ char salt[32]; |
142 |
+ char *crypted; |
143 |
+ size_t salt_len = 0; |
144 |
+ char *dollar = NULL; |
145 |
+ |
146 |
+ if (NULL == (dollar = strchr(password->ptr + 3, '$'))) { |
147 |
+ fprintf(stderr, "%s.%d\n", __FILE__, __LINE__); |
148 |
+ return -1; |
149 |
+ } |
150 |
+ |
151 |
+ salt_len = dollar - password->ptr; |
152 |
+ |
153 |
+ if (salt_len > sizeof(salt) - 1) |
154 |
+ { |
155 |
+ fprintf(stderr, "%s.%d\n", __FILE__, __LINE__); |
156 |
+ return -1; |
157 |
+ } |
158 |
+ |
159 |
+ strncpy(salt, password->ptr, salt_len); |
160 |
+ |
161 |
+ salt[salt_len] = '\0'; |
162 |
+ |
163 |
+ crypted = crypt(pw, salt); |
164 |
+ |
165 |
+ if (0 == strcmp(password->ptr, crypted)) |
166 |
+ { |
167 |
+ return 0; |
168 |
+ } else { |
169 |
+ fprintf(stderr, "%s.%d\n", __FILE__, __LINE__); |
170 |
+ } |
171 |
+ } else |
172 |
+ /* plain md5 check now */ |
173 |
+ { |
174 |
+ li_MD5_CTX Md5Ctx; |
175 |
+ HASH HA1; |
176 |
+ char a1[256]; |
177 |
+ |
178 |
+ li_MD5_Init(&Md5Ctx); |
179 |
+ li_MD5_Update(&Md5Ctx, (unsigned char *)pw, strlen(pw)); |
180 |
+ li_MD5_Final(HA1, &Md5Ctx); |
181 |
+ |
182 |
+ CvtHex(HA1, a1); |
183 |
+ |
184 |
+ if (0 == strcmp(password->ptr, a1)) { |
185 |
+ return 0; |
186 |
+ } |
187 |
+ } |
188 |
} |
189 |
return -1; |
190 |
} |
191 |
diff -Naur new/lighttpd-1.4.23/src/http_auth.h old/lighttpd-1.4.23/src/http_auth.h |
192 |
--- src/http_auth.h 2009-03-31 02:16:59.000000000 +0400 |
193 |
+++ src/http_auth.h 2009-10-08 10:13:56.000000000 +0400 |
194 |
@@ -8,13 +8,15 @@ |
195 |
# define USE_LDAP |
196 |
# include <ldap.h> |
197 |
#endif |
198 |
+#include <mysql/mysql.h> |
199 |
|
200 |
typedef enum { |
201 |
AUTH_BACKEND_UNSET, |
202 |
AUTH_BACKEND_PLAIN, |
203 |
AUTH_BACKEND_LDAP, |
204 |
AUTH_BACKEND_HTPASSWD, |
205 |
- AUTH_BACKEND_HTDIGEST |
206 |
+ AUTH_BACKEND_HTDIGEST, |
207 |
+ AUTH_BACKEND_MYSQL |
208 |
} auth_backend_t; |
209 |
|
210 |
typedef struct { |
211 |
@@ -49,6 +51,22 @@ |
212 |
buffer *ldap_filter_pre; |
213 |
buffer *ldap_filter_post; |
214 |
#endif |
215 |
+ |
216 |
+ MYSQL *mysql_conn; |
217 |
+ buffer *auth_mysql_host; |
218 |
+ buffer *auth_mysql_user; |
219 |
+ buffer *auth_mysql_pass; |
220 |
+ buffer *auth_mysql_db; |
221 |
+ buffer *auth_mysql_port; |
222 |
+ buffer *auth_mysql_socket; |
223 |
+ buffer *auth_mysql_users_table; |
224 |
+ buffer *auth_mysql_col_user; |
225 |
+ buffer *auth_mysql_col_pass; |
226 |
+ buffer *auth_mysql_col_realm; |
227 |
+ buffer *auth_mysql_domains_table; |
228 |
+ buffer *auth_mysql_col_domain; |
229 |
+ buffer *auth_mysql_domains_table_col_domain_id; |
230 |
+ buffer *auth_mysql_users_table_col_domain_id; |
231 |
} mod_auth_plugin_config; |
232 |
|
233 |
typedef struct { |
234 |
diff -Naur new/lighttpd-1.4.23/src/Makefile.am old/lighttpd-1.4.23/src/Makefile.am |
235 |
--- src/Makefile.am.orig 2013-12-03 17:17:52.000000000 +0100 |
236 |
+++ src/Makefile.am 2014-01-21 20:48:24.645439249 +0100 |
237 |
@@ -243,7 +243,7 @@ |
238 |
lib_LTLIBRARIES += mod_auth.la |
239 |
mod_auth_la_SOURCES = mod_auth.c http_auth.c |
240 |
mod_auth_la_LDFLAGS = -module -export-dynamic -avoid-version |
241 |
-mod_auth_la_LIBADD = $(CRYPT_LIB) $(SSL_LIB) $(LDAP_LIB) $(LBER_LIB) $(common_libadd) |
242 |
+mod_auth_la_LIBADD = $(MYSQL_LIBS) $(CRYPT_LIB) $(SSL_LIB) $(LDAP_LIB) $(LBER_LIB) $(common_libadd) |
243 |
|
244 |
lib_LTLIBRARIES += mod_rewrite.la |
245 |
mod_rewrite_la_SOURCES = mod_rewrite.c |
246 |
diff -Naur lighttpd-1.4.23/src/Makefile.in old/lighttpd-1.4.23/src/Makefile.in |
247 |
--- src/Makefile.in.orig 2014-01-20 13:09:11.000000000 +0100 |
248 |
+++ src/Makefile.in 2014-01-21 20:48:37.115438375 +0100 |
249 |
@@ -852,7 +852,7 @@ |
250 |
mod_compress_la_LIBADD = $(Z_LIB) $(BZ_LIB) $(common_libadd) |
251 |
mod_auth_la_SOURCES = mod_auth.c http_auth.c |
252 |
mod_auth_la_LDFLAGS = -module -export-dynamic -avoid-version |
253 |
-mod_auth_la_LIBADD = $(CRYPT_LIB) $(SSL_LIB) $(LDAP_LIB) $(LBER_LIB) $(common_libadd) |
254 |
+mod_auth_la_LIBADD = $(MYSQL_LIBS) $(CRYPT_LIB) $(SSL_LIB) $(LDAP_LIB) $(LBER_LIB) $(common_libadd) |
255 |
mod_rewrite_la_SOURCES = mod_rewrite.c |
256 |
mod_rewrite_la_LDFLAGS = -module -export-dynamic -avoid-version |
257 |
mod_rewrite_la_LIBADD = $(PCRE_LIB) $(common_libadd) |
258 |
diff -Naur new/lighttpd-1.4.23/src/mod_auth.c old/lighttpd-1.4.23/src/mod_auth.c |
259 |
--- src/mod_auth.c 2009-04-11 16:08:19.000000000 +0400 |
260 |
+++ src/mod_auth.c 2009-10-08 10:24:13.000000000 +0400 |
261 |
@@ -6,6 +6,7 @@ |
262 |
#include <errno.h> |
263 |
#include <fcntl.h> |
264 |
#include <unistd.h> |
265 |
+#include <mysql/mysql.h> |
266 |
|
267 |
#include "plugin.h" |
268 |
#include "http_auth.h" |
269 |
@@ -83,6 +84,20 @@ |
270 |
if (s->ldap) ldap_unbind_s(s->ldap); |
271 |
#endif |
272 |
|
273 |
+ buffer_free(s->auth_mysql_host); |
274 |
+ buffer_free(s->auth_mysql_user); |
275 |
+ buffer_free(s->auth_mysql_pass); |
276 |
+ buffer_free(s->auth_mysql_db); |
277 |
+ buffer_free(s->auth_mysql_socket); |
278 |
+ buffer_free(s->auth_mysql_users_table); |
279 |
+ buffer_free(s->auth_mysql_col_user); |
280 |
+ buffer_free(s->auth_mysql_col_pass); |
281 |
+ buffer_free(s->auth_mysql_col_realm); |
282 |
+ buffer_free(s->auth_mysql_domains_table); |
283 |
+ buffer_free(s->auth_mysql_col_domain); |
284 |
+ buffer_free(s->auth_mysql_domains_table_col_domain_id); |
285 |
+ buffer_free(s->auth_mysql_users_table_col_domain_id); |
286 |
+ |
287 |
free(s); |
288 |
} |
289 |
free(p->config_storage); |
290 |
@@ -120,6 +135,21 @@ |
291 |
PATCH(ldap_filter_post); |
292 |
#endif |
293 |
|
294 |
+ PATCH(auth_mysql_host); |
295 |
+ PATCH(auth_mysql_user); |
296 |
+ PATCH(auth_mysql_pass); |
297 |
+ PATCH(auth_mysql_db); |
298 |
+ PATCH(auth_mysql_port); |
299 |
+ PATCH(auth_mysql_socket); |
300 |
+ PATCH(auth_mysql_users_table); |
301 |
+ PATCH(auth_mysql_col_user); |
302 |
+ PATCH(auth_mysql_col_pass); |
303 |
+ PATCH(auth_mysql_col_realm); |
304 |
+ PATCH(auth_mysql_domains_table); |
305 |
+ PATCH(auth_mysql_col_domain); |
306 |
+ PATCH(auth_mysql_domains_table_col_domain_id); |
307 |
+ PATCH(auth_mysql_users_table_col_domain_id); |
308 |
+ |
309 |
/* skip the first, the global context */ |
310 |
for (i = 1; i < srv->config_context->used; i++) { |
311 |
data_config *dc = (data_config *)srv->config_context->data[i]; |
312 |
@@ -169,6 +199,34 @@ |
313 |
PATCH(auth_ldap_bindpw); |
314 |
} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.ldap.allow-empty-pw"))) { |
315 |
PATCH(auth_ldap_allow_empty_pw); |
316 |
+ } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.mysql.host"))) { |
317 |
+ PATCH(auth_mysql_host); |
318 |
+ } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.mysql.user"))) { |
319 |
+ PATCH(auth_mysql_user); |
320 |
+ } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.mysql.pass"))) { |
321 |
+ PATCH(auth_mysql_pass); |
322 |
+ } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.mysql.db"))) { |
323 |
+ PATCH(auth_mysql_db); |
324 |
+ } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.mysql.port"))) { |
325 |
+ PATCH(auth_mysql_port); |
326 |
+ } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.mysql.socket"))) { |
327 |
+ PATCH(auth_mysql_user); |
328 |
+ } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.mysql.users_table"))) { |
329 |
+ PATCH(auth_mysql_users_table); |
330 |
+ } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.mysql.col_user"))) { |
331 |
+ PATCH(auth_mysql_col_user); |
332 |
+ } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.mysql.col_pass"))) { |
333 |
+ PATCH(auth_mysql_col_pass); |
334 |
+ } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.mysql.col_realm"))) { |
335 |
+ PATCH(auth_mysql_col_realm); |
336 |
+ } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.mysql.domains_table"))) { |
337 |
+ PATCH(auth_mysql_domains_table); |
338 |
+ } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.mysql.col_domain"))) { |
339 |
+ PATCH(auth_mysql_col_domain); |
340 |
+ } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.mysql.domains_table_col_domain_id"))) { |
341 |
+ PATCH(auth_mysql_domains_table_col_domain_id); |
342 |
+ } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.mysql.users_table_col_domain_id"))) { |
343 |
+ PATCH(auth_mysql_users_table_col_domain_id); |
344 |
} |
345 |
} |
346 |
} |
347 |
@@ -323,10 +381,24 @@ |
348 |
{ "auth.backend.ldap.starttls", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 8 */ |
349 |
{ "auth.backend.ldap.bind-dn", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 9 */ |
350 |
{ "auth.backend.ldap.bind-pw", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 10 */ |
351 |
- { "auth.backend.ldap.allow-empty-pw", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 11 */ |
352 |
+ { "auth.backend.ldap.allow-empty-pw", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, |
353 |
{ "auth.backend.htdigest.userfile", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 12 */ |
354 |
{ "auth.backend.htpasswd.userfile", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 13 */ |
355 |
{ "auth.debug", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION }, /* 14 */ |
356 |
+ { "auth.backend.mysql.host", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, |
357 |
+ { "auth.backend.mysql.user", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, |
358 |
+ { "auth.backend.mysql.pass", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, |
359 |
+ { "auth.backend.mysql.db", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, |
360 |
+ { "auth.backend.mysql.port", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, |
361 |
+ { "auth.backend.mysql.socket", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, |
362 |
+ { "auth.backend.mysql.users_table", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, |
363 |
+ { "auth.backend.mysql.col_user", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, |
364 |
+ { "auth.backend.mysql.col_pass", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, |
365 |
+ { "auth.backend.mysql.col_realm", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 23 */ |
366 |
+ { "auth.backend.mysql.domains_table", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, |
367 |
+ { "auth.backend.mysql.col_domain", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, |
368 |
+ { "auth.backend.mysql.domains_table_col_domain_id", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, |
369 |
+ { "auth.backend.mysql.users_table_col_domain_id", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 27 */ |
370 |
{ NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET } |
371 |
}; |
372 |
|
373 |
@@ -355,6 +427,22 @@ |
374 |
s->auth_debug = 0; |
375 |
|
376 |
s->auth_require = array_init(); |
377 |
+ s->mysql_conn = NULL; |
378 |
+ s->auth_mysql_host = buffer_init(); |
379 |
+ s->auth_mysql_user = buffer_init(); |
380 |
+ s->auth_mysql_pass = buffer_init(); |
381 |
+ s->auth_mysql_db = buffer_init(); |
382 |
+ s->auth_mysql_port = buffer_init(); |
383 |
+ s->auth_mysql_socket = buffer_init(); |
384 |
+ s->auth_mysql_users_table = buffer_init(); |
385 |
+ s->auth_mysql_col_user = buffer_init(); |
386 |
+ s->auth_mysql_col_pass = buffer_init(); |
387 |
+ s->auth_mysql_col_realm = buffer_init(); |
388 |
+ s->auth_mysql_domains_table = buffer_init(); |
389 |
+ s->auth_mysql_col_domain = buffer_init(); |
390 |
+ s->auth_mysql_domains_table_col_domain_id = buffer_init(); |
391 |
+ s->auth_mysql_users_table_col_domain_id = buffer_init(); |
392 |
+ |
393 |
|
394 |
#ifdef USE_LDAP |
395 |
s->ldap_filter_pre = buffer_init(); |
396 |
@@ -377,7 +465,20 @@ |
397 |
cv[12].destination = s->auth_htdigest_userfile; |
398 |
cv[13].destination = s->auth_htpasswd_userfile; |
399 |
cv[14].destination = &(s->auth_debug); |
400 |
- |
401 |
+ cv[15].destination = s->auth_mysql_host; |
402 |
+ cv[16].destination = s->auth_mysql_user; |
403 |
+ cv[17].destination = s->auth_mysql_pass; |
404 |
+ cv[18].destination = s->auth_mysql_db; |
405 |
+ cv[19].destination = s->auth_mysql_port; |
406 |
+ cv[20].destination = s->auth_mysql_socket; |
407 |
+ cv[21].destination = s->auth_mysql_users_table; |
408 |
+ cv[22].destination = s->auth_mysql_col_user; |
409 |
+ cv[23].destination = s->auth_mysql_col_pass; |
410 |
+ cv[24].destination = s->auth_mysql_col_realm; |
411 |
+ cv[25].destination = s->auth_mysql_domains_table; |
412 |
+ cv[26].destination = s->auth_mysql_col_domain; |
413 |
+ cv[27].destination = s->auth_mysql_domains_table_col_domain_id; |
414 |
+ cv[28].destination = s->auth_mysql_users_table_col_domain_id; |
415 |
p->config_storage[i] = s; |
416 |
ca = ((data_config *)srv->config_context->data[i])->value; |
417 |
|
418 |
@@ -394,6 +495,8 @@ |
419 |
s->auth_backend = AUTH_BACKEND_PLAIN; |
420 |
} else if (0 == strcmp(s->auth_backend_conf->ptr, "ldap")) { |
421 |
s->auth_backend = AUTH_BACKEND_LDAP; |
422 |
+ } else if (0 == strcmp(s->auth_backend_conf->ptr, "mysql")) { |
423 |
+ s->auth_backend = AUTH_BACKEND_MYSQL; |
424 |
} else { |
425 |
log_error_write(srv, __FILE__, __LINE__, "sb", "auth.backend not supported:", s->auth_backend_conf); |
426 |
|
427 |
@@ -534,6 +637,31 @@ |
428 |
return (ret); |
429 |
break; |
430 |
} |
431 |
+ case AUTH_BACKEND_MYSQL: { |
432 |
+ int port = atoi(s->auth_mysql_port->ptr); |
433 |
+ |
434 |
+ /* ignore if auth_mysql_socket is invalid */ |
435 |
+ if (p->conf.auth_mysql_socket == NULL) |
436 |
+ return HANDLER_GO_ON; |
437 |
+ if (p->conf.auth_mysql_socket->ptr != NULL) |
438 |
+ if (0 == strcmp(s->auth_mysql_socket->ptr, "")) s->auth_mysql_socket->ptr = NULL; |
439 |
+ |
440 |
+ s->mysql_conn = mysql_init(NULL); |
441 |
+ if (!mysql_real_connect(s->mysql_conn, s->auth_mysql_host->ptr, s->auth_mysql_user->ptr, s->auth_mysql_pass->ptr, s->auth_mysql_db->ptr, port, NULL, 0)) |
442 |
+ { |
443 |
+ log_error_write(srv, __FILE__, __LINE__, "sbsbsbsbss", |
444 |
+ "opening connection to mysql:", s->auth_mysql_host, |
445 |
+ "user:", s->auth_mysql_user, |
446 |
+ "pass:", s->auth_mysql_pass, |
447 |
+ "db:", s->auth_mysql_db, |
448 |
+ "failed:", strerror(errno)); |
449 |
+ |
450 |
+ return HANDLER_ERROR; |
451 |
+ } |
452 |
+ mysql_close(s->mysql_conn); |
453 |
+ |
454 |
+ break; |
455 |
+ } |
456 |
default: |
457 |
break; |
458 |
} |