Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/auth/passdb-sql.c @ 9008:fc4f65a4ca60 HEAD
virtual: Don't show mailboxes as \Noselect.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 01 May 2009 14:56:52 -0400 |
parents | b9faf4db2a9f |
children | 00cd9aacd03c |
rev | line source |
---|---|
8590
b9faf4db2a9f
Updated copyright notices to include year 2009.
Timo Sirainen <tss@iki.fi>
parents:
8217
diff
changeset
|
1 /* Copyright (c) 2004-2009 Dovecot authors, see the included COPYING file */ |
2754
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
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:
3422
diff
changeset
|
3 #include "common.h" |
8217
c47b78e843aa
Separate "unknown passdb/userdb X" and "support for X not compiled in" error messages.
Timo Sirainen <tss@iki.fi>
parents:
7965
diff
changeset
|
4 #include "passdb.h" |
2754
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 #ifdef PASSDB_SQL |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 #include "str.h" |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 #include "strescape.h" |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 #include "var-expand.h" |
4782
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
11 #include "safe-memset.h" |
2754
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
12 #include "password-scheme.h" |
3161
6a3254e3c3de
Moved cache handling from sql/ldap-specific code to generic auth-request
Timo Sirainen <tss@iki.fi>
parents:
3158
diff
changeset
|
13 #include "auth-cache.h" |
2754
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
14 #include "db-sql.h" |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
15 |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 #include <stdlib.h> |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 #include <string.h> |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 |
3657
0c10475d9968
Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents:
3655
diff
changeset
|
19 struct sql_passdb_module { |
0c10475d9968
Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents:
3655
diff
changeset
|
20 struct passdb_module module; |
0c10475d9968
Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents:
3655
diff
changeset
|
21 |
0c10475d9968
Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents:
3655
diff
changeset
|
22 struct sql_connection *conn; |
0c10475d9968
Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents:
3655
diff
changeset
|
23 }; |
3161
6a3254e3c3de
Moved cache handling from sql/ldap-specific code to generic auth-request
Timo Sirainen <tss@iki.fi>
parents:
3158
diff
changeset
|
24 |
2754
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
25 struct passdb_sql_request { |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
26 struct auth_request *auth_request; |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
27 union { |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
28 verify_plain_callback_t *verify_plain; |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
29 lookup_credentials_callback_t *lookup_credentials; |
4782
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
30 set_credentials_callback_t *set_credentials; |
2754
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
31 } callback; |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
32 }; |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
33 |
3161
6a3254e3c3de
Moved cache handling from sql/ldap-specific code to generic auth-request
Timo Sirainen <tss@iki.fi>
parents:
3158
diff
changeset
|
34 static void sql_query_save_results(struct sql_result *result, |
6a3254e3c3de
Moved cache handling from sql/ldap-specific code to generic auth-request
Timo Sirainen <tss@iki.fi>
parents:
3158
diff
changeset
|
35 struct passdb_sql_request *sql_request) |
2765
428bba43a387
Authentication OK and FAIL replies can now contain extra fields from passdb.
Timo Sirainen <tss@iki.fi>
parents:
2754
diff
changeset
|
36 { |
3158
8849f2e380d1
userdb can now return extra parameters to master. Removed special handling
Timo Sirainen <tss@iki.fi>
parents:
3143
diff
changeset
|
37 struct auth_request *auth_request = sql_request->auth_request; |
3657
0c10475d9968
Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents:
3655
diff
changeset
|
38 struct passdb_module *_module = auth_request->passdb->passdb; |
0c10475d9968
Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents:
3655
diff
changeset
|
39 struct sql_passdb_module *module = (struct sql_passdb_module *)_module; |
2765
428bba43a387
Authentication OK and FAIL replies can now contain extra fields from passdb.
Timo Sirainen <tss@iki.fi>
parents:
2754
diff
changeset
|
40 unsigned int i, fields_count; |
428bba43a387
Authentication OK and FAIL replies can now contain extra fields from passdb.
Timo Sirainen <tss@iki.fi>
parents:
2754
diff
changeset
|
41 const char *name, *value; |
2798
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
2769
diff
changeset
|
42 |
3161
6a3254e3c3de
Moved cache handling from sql/ldap-specific code to generic auth-request
Timo Sirainen <tss@iki.fi>
parents:
3158
diff
changeset
|
43 fields_count = sql_result_get_fields_count(result); |
2765
428bba43a387
Authentication OK and FAIL replies can now contain extra fields from passdb.
Timo Sirainen <tss@iki.fi>
parents:
2754
diff
changeset
|
44 for (i = 0; i < fields_count; i++) { |
428bba43a387
Authentication OK and FAIL replies can now contain extra fields from passdb.
Timo Sirainen <tss@iki.fi>
parents:
2754
diff
changeset
|
45 name = sql_result_get_field_name(result, i); |
428bba43a387
Authentication OK and FAIL replies can now contain extra fields from passdb.
Timo Sirainen <tss@iki.fi>
parents:
2754
diff
changeset
|
46 value = sql_result_get_field_value(result, i); |
428bba43a387
Authentication OK and FAIL replies can now contain extra fields from passdb.
Timo Sirainen <tss@iki.fi>
parents:
2754
diff
changeset
|
47 |
4017
e2d267e6f930
Check that we don't pass around key=value pairs with empty keys.
Timo Sirainen <tss@iki.fi>
parents:
3918
diff
changeset
|
48 if (*name != '\0' && value != NULL) { |
3272
36db3285f4a7
Try to keep scheme always included in auth_request->passdb_password.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
49 auth_request_set_field(auth_request, name, value, |
3657
0c10475d9968
Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents:
3655
diff
changeset
|
50 module->conn->set.default_pass_scheme); |
3272
36db3285f4a7
Try to keep scheme always included in auth_request->passdb_password.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
51 } |
2765
428bba43a387
Authentication OK and FAIL replies can now contain extra fields from passdb.
Timo Sirainen <tss@iki.fi>
parents:
2754
diff
changeset
|
52 } |
428bba43a387
Authentication OK and FAIL replies can now contain extra fields from passdb.
Timo Sirainen <tss@iki.fi>
parents:
2754
diff
changeset
|
53 } |
428bba43a387
Authentication OK and FAIL replies can now contain extra fields from passdb.
Timo Sirainen <tss@iki.fi>
parents:
2754
diff
changeset
|
54 |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4782
diff
changeset
|
55 static void sql_query_callback(struct sql_result *result, |
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4782
diff
changeset
|
56 struct passdb_sql_request *sql_request) |
2754
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
57 { |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
58 struct auth_request *auth_request = sql_request->auth_request; |
3058
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
3036
diff
changeset
|
59 enum passdb_result passdb_result; |
2754
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
60 const char *user, *password, *scheme; |
3161
6a3254e3c3de
Moved cache handling from sql/ldap-specific code to generic auth-request
Timo Sirainen <tss@iki.fi>
parents:
3158
diff
changeset
|
61 int ret; |
2754
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
62 |
3161
6a3254e3c3de
Moved cache handling from sql/ldap-specific code to generic auth-request
Timo Sirainen <tss@iki.fi>
parents:
3158
diff
changeset
|
63 passdb_result = PASSDB_RESULT_INTERNAL_FAILURE; |
2754
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
64 user = auth_request->user; |
5475
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
65 password = NULL; |
2754
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
66 |
5475
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
67 ret = sql_result_next_row(result); |
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
68 if (ret < 0) { |
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
69 auth_request_log_error(auth_request, "sql", |
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
70 "Password query failed: %s", |
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
71 sql_result_get_error(result)); |
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
72 } else if (ret == 0) { |
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
73 auth_request_log_info(auth_request, "sql", "unknown user"); |
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
74 passdb_result = PASSDB_RESULT_USER_UNKNOWN; |
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
75 } else { |
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
76 sql_query_save_results(result, sql_request); |
2754
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
77 |
5475
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
78 /* Note that we really want to check if the password field is |
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
79 found. Just checking if password is set isn't enough, |
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
80 because with proxies we might want to return NULL as |
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
81 password. */ |
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
82 if (sql_result_find_field(result, "password") < 0) { |
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
83 auth_request_log_error(auth_request, "sql", |
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
84 "Password query must return a field named " |
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
85 "'password'"); |
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
86 } else if (sql_result_next_row(result) > 0) { |
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
87 auth_request_log_error(auth_request, "sql", |
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
88 "Password query returned multiple matches"); |
5619
121af23cfc65
Empty password doesn't anymore allow user to log in with any password,
Timo Sirainen <tss@iki.fi>
parents:
5593
diff
changeset
|
89 } else if (auth_request->passdb_password == NULL && |
121af23cfc65
Empty password doesn't anymore allow user to log in with any password,
Timo Sirainen <tss@iki.fi>
parents:
5593
diff
changeset
|
90 !auth_request->no_password) { |
121af23cfc65
Empty password doesn't anymore allow user to log in with any password,
Timo Sirainen <tss@iki.fi>
parents:
5593
diff
changeset
|
91 auth_request_log_info(auth_request, "sql", |
7965
72a560a00def
"Empty password returned without no_password" message -> "nopassword".
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
92 "Empty password returned without nopassword"); |
5619
121af23cfc65
Empty password doesn't anymore allow user to log in with any password,
Timo Sirainen <tss@iki.fi>
parents:
5593
diff
changeset
|
93 passdb_result = PASSDB_RESULT_PASSWORD_MISMATCH; |
5475
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
94 } else { |
4731
bd702f6cac23
Non-plaintext authentication didn't work with sql as passdb. Cleaned up the
Timo Sirainen <tss@iki.fi>
parents:
4295
diff
changeset
|
95 /* passdb_password may change on the way, |
bd702f6cac23
Non-plaintext authentication didn't work with sql as passdb. Cleaned up the
Timo Sirainen <tss@iki.fi>
parents:
4295
diff
changeset
|
96 so we'll need to strdup. */ |
bd702f6cac23
Non-plaintext authentication didn't work with sql as passdb. Cleaned up the
Timo Sirainen <tss@iki.fi>
parents:
4295
diff
changeset
|
97 password = t_strdup(auth_request->passdb_password); |
3161
6a3254e3c3de
Moved cache handling from sql/ldap-specific code to generic auth-request
Timo Sirainen <tss@iki.fi>
parents:
3158
diff
changeset
|
98 passdb_result = PASSDB_RESULT_OK; |
2754
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
99 } |
5475
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
100 } |
2754
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
101 |
5475
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
102 scheme = password_get_scheme(&password); |
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
103 /* auth_request_set_field() sets scheme */ |
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
104 i_assert(password == NULL || scheme != NULL); |
2754
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
105 |
5593
f8dc0bdb06a7
Removed enum passdb_credentials. Use scheme strings directly instead. This
Timo Sirainen <tss@iki.fi>
parents:
5475
diff
changeset
|
106 if (auth_request->credentials_scheme != NULL) { |
5475
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
107 passdb_handle_credentials(passdb_result, password, scheme, |
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
108 sql_request->callback.lookup_credentials, |
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
109 auth_request); |
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
110 auth_request_unref(&auth_request); |
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
111 return; |
2754
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
112 } |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
113 |
5475
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
114 /* verify plain */ |
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
115 if (password == NULL) { |
3058
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
3036
diff
changeset
|
116 sql_request->callback.verify_plain(passdb_result, auth_request); |
5475
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
117 auth_request_unref(&auth_request); |
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
118 return; |
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
119 } |
2754
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
120 |
5475
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
121 ret = auth_request_password_verify(auth_request, |
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
122 auth_request->mech_password, |
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
123 password, scheme, "sql"); |
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
124 |
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
125 sql_request->callback.verify_plain(ret > 0 ? PASSDB_RESULT_OK : |
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
126 PASSDB_RESULT_PASSWORD_MISMATCH, |
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
127 auth_request); |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3694
diff
changeset
|
128 auth_request_unref(&auth_request); |
2754
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
129 } |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
130 |
4295
4fc637010202
Escape SQL strings using sql_escape_string(). Fixes the problems with
Timo Sirainen <tss@iki.fi>
parents:
4017
diff
changeset
|
131 static const char * |
4fc637010202
Escape SQL strings using sql_escape_string(). Fixes the problems with
Timo Sirainen <tss@iki.fi>
parents:
4017
diff
changeset
|
132 passdb_sql_escape(const char *str, const struct auth_request *auth_request) |
4fc637010202
Escape SQL strings using sql_escape_string(). Fixes the problems with
Timo Sirainen <tss@iki.fi>
parents:
4017
diff
changeset
|
133 { |
4fc637010202
Escape SQL strings using sql_escape_string(). Fixes the problems with
Timo Sirainen <tss@iki.fi>
parents:
4017
diff
changeset
|
134 struct passdb_module *_module = auth_request->passdb->passdb; |
4fc637010202
Escape SQL strings using sql_escape_string(). Fixes the problems with
Timo Sirainen <tss@iki.fi>
parents:
4017
diff
changeset
|
135 struct sql_passdb_module *module = (struct sql_passdb_module *)_module; |
4fc637010202
Escape SQL strings using sql_escape_string(). Fixes the problems with
Timo Sirainen <tss@iki.fi>
parents:
4017
diff
changeset
|
136 |
4fc637010202
Escape SQL strings using sql_escape_string(). Fixes the problems with
Timo Sirainen <tss@iki.fi>
parents:
4017
diff
changeset
|
137 return sql_escape_string(module->conn->db, str); |
4fc637010202
Escape SQL strings using sql_escape_string(). Fixes the problems with
Timo Sirainen <tss@iki.fi>
parents:
4017
diff
changeset
|
138 } |
4fc637010202
Escape SQL strings using sql_escape_string(). Fixes the problems with
Timo Sirainen <tss@iki.fi>
parents:
4017
diff
changeset
|
139 |
2754
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
140 static void sql_lookup_pass(struct passdb_sql_request *sql_request) |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
141 { |
3657
0c10475d9968
Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents:
3655
diff
changeset
|
142 struct passdb_module *_module = |
0c10475d9968
Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents:
3655
diff
changeset
|
143 sql_request->auth_request->passdb->passdb; |
0c10475d9968
Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents:
3655
diff
changeset
|
144 struct sql_passdb_module *module = (struct sql_passdb_module *)_module; |
2754
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
145 string_t *query; |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
146 |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
147 query = t_str_new(512); |
3657
0c10475d9968
Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents:
3655
diff
changeset
|
148 var_expand(query, module->conn->set.password_query, |
2754
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
149 auth_request_get_var_expand_table(sql_request->auth_request, |
4295
4fc637010202
Escape SQL strings using sql_escape_string(). Fixes the problems with
Timo Sirainen <tss@iki.fi>
parents:
4017
diff
changeset
|
150 passdb_sql_escape)); |
2754
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
151 |
3069 | 152 auth_request_log_debug(sql_request->auth_request, "sql", |
153 "query: %s", str_c(query)); | |
3036
fcecff14e470
Added authentication debugging logging.
Timo Sirainen <tss@iki.fi>
parents:
2942
diff
changeset
|
154 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3694
diff
changeset
|
155 auth_request_ref(sql_request->auth_request); |
3657
0c10475d9968
Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents:
3655
diff
changeset
|
156 sql_query(module->conn->db, str_c(query), |
2754
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
157 sql_query_callback, sql_request); |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
158 } |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
159 |
3161
6a3254e3c3de
Moved cache handling from sql/ldap-specific code to generic auth-request
Timo Sirainen <tss@iki.fi>
parents:
3158
diff
changeset
|
160 static void sql_verify_plain(struct auth_request *request, |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6213
diff
changeset
|
161 const char *password ATTR_UNUSED, |
2754
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
162 verify_plain_callback_t *callback) |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
163 { |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
164 struct passdb_sql_request *sql_request; |
2798
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
2769
diff
changeset
|
165 |
3161
6a3254e3c3de
Moved cache handling from sql/ldap-specific code to generic auth-request
Timo Sirainen <tss@iki.fi>
parents:
3158
diff
changeset
|
166 sql_request = p_new(request->pool, struct passdb_sql_request, 1); |
2754
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
167 sql_request->auth_request = request; |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
168 sql_request->callback.verify_plain = callback; |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
169 |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
170 sql_lookup_pass(sql_request); |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
171 } |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
172 |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
173 static void sql_lookup_credentials(struct auth_request *request, |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
174 lookup_credentials_callback_t *callback) |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
175 { |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
176 struct passdb_sql_request *sql_request; |
2798
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
2769
diff
changeset
|
177 |
3161
6a3254e3c3de
Moved cache handling from sql/ldap-specific code to generic auth-request
Timo Sirainen <tss@iki.fi>
parents:
3158
diff
changeset
|
178 sql_request = p_new(request->pool, struct passdb_sql_request, 1); |
2754
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
179 sql_request->auth_request = request; |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
180 sql_request->callback.lookup_credentials = callback; |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
181 |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
182 sql_lookup_pass(sql_request); |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
183 } |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
184 |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4782
diff
changeset
|
185 static void sql_set_credentials_callback(const char *error, |
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4782
diff
changeset
|
186 struct passdb_sql_request *sql_request) |
4782
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
187 { |
6213
e33a87152c41
Changed set_credentials() callback to take a bool success instead of
Timo Sirainen <tss@iki.fi>
parents:
5619
diff
changeset
|
188 if (error != NULL) { |
4782
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
189 auth_request_log_error(sql_request->auth_request, "sql", |
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
190 "Set credentials query failed: %s", |
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
191 error); |
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
192 } |
6213
e33a87152c41
Changed set_credentials() callback to take a bool success instead of
Timo Sirainen <tss@iki.fi>
parents:
5619
diff
changeset
|
193 |
e33a87152c41
Changed set_credentials() callback to take a bool success instead of
Timo Sirainen <tss@iki.fi>
parents:
5619
diff
changeset
|
194 sql_request->callback. |
e33a87152c41
Changed set_credentials() callback to take a bool success instead of
Timo Sirainen <tss@iki.fi>
parents:
5619
diff
changeset
|
195 set_credentials(error == NULL, sql_request->auth_request); |
4782
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
196 i_free(sql_request); |
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
197 } |
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
198 |
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
199 static int sql_set_credentials(struct auth_request *request, |
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
200 const char *new_credentials, |
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
201 set_credentials_callback_t *callback) |
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
202 { |
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
203 struct sql_passdb_module *module = |
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
204 (struct sql_passdb_module *) request->passdb->passdb; |
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
205 struct sql_transaction_context *transaction; |
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
206 struct passdb_sql_request *sql_request; |
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
207 string_t *query; |
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
208 |
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
209 request->mech_password = p_strdup(request->pool, new_credentials); |
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
210 |
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
211 query = t_str_new(512); |
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
212 var_expand(query, module->conn->set.update_query, |
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
213 auth_request_get_var_expand_table(request, |
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
214 passdb_sql_escape)); |
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
215 |
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
216 sql_request = i_new(struct passdb_sql_request, 1); |
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
217 sql_request->auth_request = request; |
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
218 sql_request->callback.set_credentials = callback; |
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
219 |
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
220 transaction = sql_transaction_begin(module->conn->db); |
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
221 sql_update(transaction, str_c(query)); |
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
222 sql_transaction_commit(&transaction, |
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
223 sql_set_credentials_callback, sql_request); |
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
224 return 0; |
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
225 } |
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
226 |
3657
0c10475d9968
Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents:
3655
diff
changeset
|
227 static struct passdb_module * |
0c10475d9968
Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents:
3655
diff
changeset
|
228 passdb_sql_preinit(struct auth_passdb *auth_passdb, const char *args) |
2754
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
229 { |
3657
0c10475d9968
Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents:
3655
diff
changeset
|
230 struct sql_passdb_module *module; |
0c10475d9968
Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents:
3655
diff
changeset
|
231 struct sql_connection *conn; |
3161
6a3254e3c3de
Moved cache handling from sql/ldap-specific code to generic auth-request
Timo Sirainen <tss@iki.fi>
parents:
3158
diff
changeset
|
232 |
3657
0c10475d9968
Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents:
3655
diff
changeset
|
233 module = p_new(auth_passdb->auth->pool, struct sql_passdb_module, 1); |
0c10475d9968
Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents:
3655
diff
changeset
|
234 module->conn = conn = db_sql_init(args); |
0c10475d9968
Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents:
3655
diff
changeset
|
235 |
0c10475d9968
Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents:
3655
diff
changeset
|
236 module->module.cache_key = |
3694
12d00d9ceb6e
cache_key was set wrong for sql/ldap passdbs, so auth_cache was completely
Timo Sirainen <tss@iki.fi>
parents:
3669
diff
changeset
|
237 auth_cache_parse_key(auth_passdb->auth->pool, |
12d00d9ceb6e
cache_key was set wrong for sql/ldap passdbs, so auth_cache was completely
Timo Sirainen <tss@iki.fi>
parents:
3669
diff
changeset
|
238 conn->set.password_query); |
3657
0c10475d9968
Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents:
3655
diff
changeset
|
239 module->module.default_pass_scheme = conn->set.default_pass_scheme; |
0c10475d9968
Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents:
3655
diff
changeset
|
240 return &module->module; |
2754
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
241 } |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
242 |
3657
0c10475d9968
Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents:
3655
diff
changeset
|
243 static void passdb_sql_init(struct passdb_module *_module, |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6213
diff
changeset
|
244 const char *args ATTR_UNUSED) |
2754
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
245 { |
3657
0c10475d9968
Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents:
3655
diff
changeset
|
246 struct sql_passdb_module *module = |
0c10475d9968
Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents:
3655
diff
changeset
|
247 (struct sql_passdb_module *)_module; |
3166
e6a487d80288
Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents:
3161
diff
changeset
|
248 enum sql_db_flags flags; |
e6a487d80288
Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents:
3161
diff
changeset
|
249 |
3657
0c10475d9968
Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents:
3655
diff
changeset
|
250 flags = sql_get_flags(module->conn->db); |
0c10475d9968
Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents:
3655
diff
changeset
|
251 module->module.blocking = (flags & SQL_DB_FLAG_BLOCKING) != 0; |
3422
28be9a80908e
Don't connect to SQL database in main dovecot-auth process if we're using
Timo Sirainen <tss@iki.fi>
parents:
3310
diff
changeset
|
252 |
3657
0c10475d9968
Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents:
3655
diff
changeset
|
253 if (!module->module.blocking || worker) |
0c10475d9968
Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents:
3655
diff
changeset
|
254 sql_connect(module->conn->db); |
2754
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
255 } |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
256 |
3657
0c10475d9968
Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents:
3655
diff
changeset
|
257 static void passdb_sql_deinit(struct passdb_module *_module) |
2754
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
258 { |
3657
0c10475d9968
Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents:
3655
diff
changeset
|
259 struct sql_passdb_module *module = |
0c10475d9968
Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents:
3655
diff
changeset
|
260 (struct sql_passdb_module *)_module; |
0c10475d9968
Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents:
3655
diff
changeset
|
261 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3694
diff
changeset
|
262 db_sql_unref(&module->conn); |
2754
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
263 } |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
264 |
3657
0c10475d9968
Separated passdb_module's interface and the actual data struct. Now it's
Timo Sirainen <tss@iki.fi>
parents:
3655
diff
changeset
|
265 struct passdb_module_interface passdb_sql = { |
2942
c7d426f8cb58
Added name variable for userdb_module and passdb_module and changed their
Timo Sirainen <tss@iki.fi>
parents:
2841
diff
changeset
|
266 "sql", |
c7d426f8cb58
Added name variable for userdb_module and passdb_module and changed their
Timo Sirainen <tss@iki.fi>
parents:
2841
diff
changeset
|
267 |
2754
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
268 passdb_sql_preinit, |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
269 passdb_sql_init, |
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
270 passdb_sql_deinit, |
3161
6a3254e3c3de
Moved cache handling from sql/ldap-specific code to generic auth-request
Timo Sirainen <tss@iki.fi>
parents:
3158
diff
changeset
|
271 |
2754
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
272 sql_verify_plain, |
4782
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
273 sql_lookup_credentials, |
2c1cc5bbc260
Added auth_request_set_credentials() to modify credentials in passdb and
Timo Sirainen <tss@iki.fi>
parents:
4731
diff
changeset
|
274 sql_set_credentials |
2754
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
275 }; |
8217
c47b78e843aa
Separate "unknown passdb/userdb X" and "support for X not compiled in" error messages.
Timo Sirainen <tss@iki.fi>
parents:
7965
diff
changeset
|
276 #else |
c47b78e843aa
Separate "unknown passdb/userdb X" and "support for X not compiled in" error messages.
Timo Sirainen <tss@iki.fi>
parents:
7965
diff
changeset
|
277 struct passdb_module_interface passdb_sql = { |
c47b78e843aa
Separate "unknown passdb/userdb X" and "support for X not compiled in" error messages.
Timo Sirainen <tss@iki.fi>
parents:
7965
diff
changeset
|
278 MEMBER(name) "sql" |
c47b78e843aa
Separate "unknown passdb/userdb X" and "support for X not compiled in" error messages.
Timo Sirainen <tss@iki.fi>
parents:
7965
diff
changeset
|
279 }; |
2754
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
280 #endif |