Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/auth/passdb-cache.c @ 9415:2a48aa6e2bce HEAD
Added signature for changeset 609fe4268f40
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 05 Oct 2009 19:52:13 -0400 |
parents | 8a23ab43132a |
children | 00cd9aacd03c |
rev | line source |
---|---|
8590
b9faf4db2a9f
Updated copyright notices to include year 2009.
Timo Sirainen <tss@iki.fi>
parents:
7891
diff
changeset
|
1 /* Copyright (c) 2004-2009 Dovecot authors, see the included COPYING file */ |
2798
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 #include "common.h" |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
4 #include "password-scheme.h" |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 #include "passdb.h" |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 #include "passdb-cache.h" |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 #include <stdlib.h> |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 struct auth_cache *passdb_cache = NULL; |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
11 |
7277
e0debdcd2e10
auth_debug: Hide passwords from "cache hit" log lines if
Timo Sirainen <tss@iki.fi>
parents:
7275
diff
changeset
|
12 static void |
e0debdcd2e10
auth_debug: Hide passwords from "cache hit" log lines if
Timo Sirainen <tss@iki.fi>
parents:
7275
diff
changeset
|
13 passdb_cache_log_hit(struct auth_request *request, const char *value) |
e0debdcd2e10
auth_debug: Hide passwords from "cache hit" log lines if
Timo Sirainen <tss@iki.fi>
parents:
7275
diff
changeset
|
14 { |
e0debdcd2e10
auth_debug: Hide passwords from "cache hit" log lines if
Timo Sirainen <tss@iki.fi>
parents:
7275
diff
changeset
|
15 const char *p; |
e0debdcd2e10
auth_debug: Hide passwords from "cache hit" log lines if
Timo Sirainen <tss@iki.fi>
parents:
7275
diff
changeset
|
16 |
e0debdcd2e10
auth_debug: Hide passwords from "cache hit" log lines if
Timo Sirainen <tss@iki.fi>
parents:
7275
diff
changeset
|
17 if (!request->auth->verbose_debug_passwords && |
e0debdcd2e10
auth_debug: Hide passwords from "cache hit" log lines if
Timo Sirainen <tss@iki.fi>
parents:
7275
diff
changeset
|
18 *value != '\0' && *value != '\t') { |
e0debdcd2e10
auth_debug: Hide passwords from "cache hit" log lines if
Timo Sirainen <tss@iki.fi>
parents:
7275
diff
changeset
|
19 /* hide the password */ |
e0debdcd2e10
auth_debug: Hide passwords from "cache hit" log lines if
Timo Sirainen <tss@iki.fi>
parents:
7275
diff
changeset
|
20 p = strchr(value, '\t'); |
e0debdcd2e10
auth_debug: Hide passwords from "cache hit" log lines if
Timo Sirainen <tss@iki.fi>
parents:
7275
diff
changeset
|
21 value = t_strconcat("<hidden>", p, NULL); |
e0debdcd2e10
auth_debug: Hide passwords from "cache hit" log lines if
Timo Sirainen <tss@iki.fi>
parents:
7275
diff
changeset
|
22 } |
e0debdcd2e10
auth_debug: Hide passwords from "cache hit" log lines if
Timo Sirainen <tss@iki.fi>
parents:
7275
diff
changeset
|
23 auth_request_log_debug(request, "cache", "hit: %s", value); |
e0debdcd2e10
auth_debug: Hide passwords from "cache hit" log lines if
Timo Sirainen <tss@iki.fi>
parents:
7275
diff
changeset
|
24 } |
e0debdcd2e10
auth_debug: Hide passwords from "cache hit" log lines if
Timo Sirainen <tss@iki.fi>
parents:
7275
diff
changeset
|
25 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3728
diff
changeset
|
26 bool passdb_cache_verify_plain(struct auth_request *request, const char *key, |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3728
diff
changeset
|
27 const char *password, |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3728
diff
changeset
|
28 enum passdb_result *result_r, int use_expired) |
2798
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
29 { |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
30 const char *value, *cached_pw, *scheme, *const *list; |
4658
3b49b9ec87dc
auth_cache: Try to handle changing passwords automatically: If password
Timo Sirainen <tss@iki.fi>
parents:
3918
diff
changeset
|
31 struct auth_cache_node *node; |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3728
diff
changeset
|
32 int ret; |
9110
8a23ab43132a
auth_cache_negative_ttl is now also used for password mismatches.
Timo Sirainen <tss@iki.fi>
parents:
8764
diff
changeset
|
33 bool expired, neg_expired; |
2798
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
34 |
3728
64ed35c97678
Don't crash if cache key isn't set but cache is enabled.
Timo Sirainen <tss@iki.fi>
parents:
3655
diff
changeset
|
35 if (passdb_cache == NULL || key == NULL) |
2798
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
36 return FALSE; |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
37 |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
38 /* value = password \t ... */ |
9110
8a23ab43132a
auth_cache_negative_ttl is now also used for password mismatches.
Timo Sirainen <tss@iki.fi>
parents:
8764
diff
changeset
|
39 value = auth_cache_lookup(passdb_cache, request, key, &node, |
8a23ab43132a
auth_cache_negative_ttl is now also used for password mismatches.
Timo Sirainen <tss@iki.fi>
parents:
8764
diff
changeset
|
40 &expired, &neg_expired); |
5259 | 41 if (value == NULL || (expired && !use_expired)) { |
42 auth_request_log_debug(request, "cache", | |
43 value == NULL ? "miss" : "expired"); | |
2798
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
44 return FALSE; |
5259 | 45 } |
7277
e0debdcd2e10
auth_debug: Hide passwords from "cache hit" log lines if
Timo Sirainen <tss@iki.fi>
parents:
7275
diff
changeset
|
46 passdb_cache_log_hit(request, value); |
2798
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
47 |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
48 if (*value == '\0') { |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
49 /* negative cache entry */ |
3646
f50496e14ac8
Added some more verbosity to cache lookups.
Timo Sirainen <tss@iki.fi>
parents:
3431
diff
changeset
|
50 auth_request_log_info(request, "cache", "User unknown"); |
2798
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
51 *result_r = PASSDB_RESULT_USER_UNKNOWN; |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
52 return TRUE; |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
53 } |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
54 |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
55 list = t_strsplit(value, "\t"); |
3431
27fb8c9202e2
Auth cache wasn't working if password wasn't given (ie. didn't work for
Timo Sirainen <tss@iki.fi>
parents:
3274
diff
changeset
|
56 |
2798
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
57 cached_pw = list[0]; |
3431
27fb8c9202e2
Auth cache wasn't working if password wasn't given (ie. didn't work for
Timo Sirainen <tss@iki.fi>
parents:
3274
diff
changeset
|
58 if (*cached_pw == '\0') { |
27fb8c9202e2
Auth cache wasn't working if password wasn't given (ie. didn't work for
Timo Sirainen <tss@iki.fi>
parents:
3274
diff
changeset
|
59 /* NULL password */ |
3646
f50496e14ac8
Added some more verbosity to cache lookups.
Timo Sirainen <tss@iki.fi>
parents:
3431
diff
changeset
|
60 auth_request_log_info(request, "cache", "NULL password access"); |
5128
365ff0cfd03f
If last login was valid and the current one wasn't, we returned "not found
Timo Sirainen <tss@iki.fi>
parents:
4658
diff
changeset
|
61 ret = 1; |
365ff0cfd03f
If last login was valid and the current one wasn't, we returned "not found
Timo Sirainen <tss@iki.fi>
parents:
4658
diff
changeset
|
62 } else { |
365ff0cfd03f
If last login was valid and the current one wasn't, we returned "not found
Timo Sirainen <tss@iki.fi>
parents:
4658
diff
changeset
|
63 scheme = password_get_scheme(&cached_pw); |
365ff0cfd03f
If last login was valid and the current one wasn't, we returned "not found
Timo Sirainen <tss@iki.fi>
parents:
4658
diff
changeset
|
64 i_assert(scheme != NULL); |
3161
6a3254e3c3de
Moved cache handling from sql/ldap-specific code to generic auth-request
Timo Sirainen <tss@iki.fi>
parents:
3158
diff
changeset
|
65 |
5128
365ff0cfd03f
If last login was valid and the current one wasn't, we returned "not found
Timo Sirainen <tss@iki.fi>
parents:
4658
diff
changeset
|
66 ret = auth_request_password_verify(request, password, cached_pw, |
365ff0cfd03f
If last login was valid and the current one wasn't, we returned "not found
Timo Sirainen <tss@iki.fi>
parents:
4658
diff
changeset
|
67 scheme, "cache"); |
2798
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
68 |
9110
8a23ab43132a
auth_cache_negative_ttl is now also used for password mismatches.
Timo Sirainen <tss@iki.fi>
parents:
8764
diff
changeset
|
69 if (ret == 0 && (node->last_success || neg_expired)) { |
8a23ab43132a
auth_cache_negative_ttl is now also used for password mismatches.
Timo Sirainen <tss@iki.fi>
parents:
8764
diff
changeset
|
70 /* a) the last authentication was successful. assume |
8a23ab43132a
auth_cache_negative_ttl is now also used for password mismatches.
Timo Sirainen <tss@iki.fi>
parents:
8764
diff
changeset
|
71 that the password was changed and cache is expired. |
8a23ab43132a
auth_cache_negative_ttl is now also used for password mismatches.
Timo Sirainen <tss@iki.fi>
parents:
8764
diff
changeset
|
72 b) negative TTL reached, use it for password |
8a23ab43132a
auth_cache_negative_ttl is now also used for password mismatches.
Timo Sirainen <tss@iki.fi>
parents:
8764
diff
changeset
|
73 mismatches too. */ |
5128
365ff0cfd03f
If last login was valid and the current one wasn't, we returned "not found
Timo Sirainen <tss@iki.fi>
parents:
4658
diff
changeset
|
74 node->last_success = FALSE; |
365ff0cfd03f
If last login was valid and the current one wasn't, we returned "not found
Timo Sirainen <tss@iki.fi>
parents:
4658
diff
changeset
|
75 return FALSE; |
365ff0cfd03f
If last login was valid and the current one wasn't, we returned "not found
Timo Sirainen <tss@iki.fi>
parents:
4658
diff
changeset
|
76 } |
4658
3b49b9ec87dc
auth_cache: Try to handle changing passwords automatically: If password
Timo Sirainen <tss@iki.fi>
parents:
3918
diff
changeset
|
77 } |
3b49b9ec87dc
auth_cache: Try to handle changing passwords automatically: If password
Timo Sirainen <tss@iki.fi>
parents:
3918
diff
changeset
|
78 node->last_success = ret > 0; |
3b49b9ec87dc
auth_cache: Try to handle changing passwords automatically: If password
Timo Sirainen <tss@iki.fi>
parents:
3918
diff
changeset
|
79 |
5128
365ff0cfd03f
If last login was valid and the current one wasn't, we returned "not found
Timo Sirainen <tss@iki.fi>
parents:
4658
diff
changeset
|
80 /* save the extra_fields only after we know we're using the |
365ff0cfd03f
If last login was valid and the current one wasn't, we returned "not found
Timo Sirainen <tss@iki.fi>
parents:
4658
diff
changeset
|
81 cached data */ |
5153
83f361144a8a
Added auth_request_set_fields() and used it instead of duplicating the code
Timo Sirainen <tss@iki.fi>
parents:
5134
diff
changeset
|
82 auth_request_set_fields(request, list + 1, NULL); |
5128
365ff0cfd03f
If last login was valid and the current one wasn't, we returned "not found
Timo Sirainen <tss@iki.fi>
parents:
4658
diff
changeset
|
83 |
2798
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
84 *result_r = ret > 0 ? PASSDB_RESULT_OK : |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
85 PASSDB_RESULT_PASSWORD_MISMATCH; |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
86 return TRUE; |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
87 } |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
88 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3728
diff
changeset
|
89 bool passdb_cache_lookup_credentials(struct auth_request *request, |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3728
diff
changeset
|
90 const char *key, const char **password_r, |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3728
diff
changeset
|
91 const char **scheme_r, |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3728
diff
changeset
|
92 enum passdb_result *result_r, |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3728
diff
changeset
|
93 bool use_expired) |
2798
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
94 { |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
95 const char *value, *const *list; |
4658
3b49b9ec87dc
auth_cache: Try to handle changing passwords automatically: If password
Timo Sirainen <tss@iki.fi>
parents:
3918
diff
changeset
|
96 struct auth_cache_node *node; |
9110
8a23ab43132a
auth_cache_negative_ttl is now also used for password mismatches.
Timo Sirainen <tss@iki.fi>
parents:
8764
diff
changeset
|
97 bool expired, neg_expired; |
2798
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
98 |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
99 if (passdb_cache == NULL) |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
100 return FALSE; |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
101 |
9110
8a23ab43132a
auth_cache_negative_ttl is now also used for password mismatches.
Timo Sirainen <tss@iki.fi>
parents:
8764
diff
changeset
|
102 value = auth_cache_lookup(passdb_cache, request, key, &node, |
8a23ab43132a
auth_cache_negative_ttl is now also used for password mismatches.
Timo Sirainen <tss@iki.fi>
parents:
8764
diff
changeset
|
103 &expired, &neg_expired); |
5259 | 104 if (value == NULL || (expired && !use_expired)) { |
105 auth_request_log_debug(request, "cache", | |
106 value == NULL ? "miss" : "expired"); | |
2798
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
107 return FALSE; |
5259 | 108 } |
7277
e0debdcd2e10
auth_debug: Hide passwords from "cache hit" log lines if
Timo Sirainen <tss@iki.fi>
parents:
7275
diff
changeset
|
109 passdb_cache_log_hit(request, value); |
2798
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
110 |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
111 if (*value == '\0') { |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
112 /* negative cache entry */ |
3655
62fc6883faeb
Fixes and cleanups to credentials handling. Also fixed auth caching to work
Timo Sirainen <tss@iki.fi>
parents:
3646
diff
changeset
|
113 *result_r = PASSDB_RESULT_USER_UNKNOWN; |
62fc6883faeb
Fixes and cleanups to credentials handling. Also fixed auth caching to work
Timo Sirainen <tss@iki.fi>
parents:
3646
diff
changeset
|
114 *password_r = NULL; |
2798
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
115 *scheme_r = NULL; |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
116 return TRUE; |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
117 } |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
118 |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
119 list = t_strsplit(value, "\t"); |
5153
83f361144a8a
Added auth_request_set_fields() and used it instead of duplicating the code
Timo Sirainen <tss@iki.fi>
parents:
5134
diff
changeset
|
120 auth_request_set_fields(request, list + 1, NULL); |
2798
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
121 |
3655
62fc6883faeb
Fixes and cleanups to credentials handling. Also fixed auth caching to work
Timo Sirainen <tss@iki.fi>
parents:
3646
diff
changeset
|
122 *result_r = PASSDB_RESULT_OK; |
8763
992cfb5ebdb0
auth cache: Don't crash if trying to lookup credentials for NULL password.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
123 *password_r = *list[0] == '\0' ? NULL : list[0]; |
3655
62fc6883faeb
Fixes and cleanups to credentials handling. Also fixed auth caching to work
Timo Sirainen <tss@iki.fi>
parents:
3646
diff
changeset
|
124 *scheme_r = password_get_scheme(password_r); |
7891
9cd7caa922d6
Code cleanup: Don't mix up '\0' and NULL.
Timo Sirainen <tss@iki.fi>
parents:
7277
diff
changeset
|
125 i_assert(*scheme_r != NULL || *password_r == NULL); |
2798
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
126 return TRUE; |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
127 } |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
128 |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
129 void passdb_cache_init(void) |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
130 { |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
131 const char *env; |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
132 size_t max_size; |
6174
6c48466c23fa
Added auth_cache_negative_ttl setting.
Timo Sirainen <tss@iki.fi>
parents:
5259
diff
changeset
|
133 unsigned int cache_ttl, neg_cache_ttl; |
2798
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
134 |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
135 env = getenv("CACHE_SIZE"); |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
136 if (env == NULL) |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
137 return; |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
138 |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
139 max_size = (size_t)strtoul(env, NULL, 10) * 1024; |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
140 if (max_size == 0) |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
141 return; |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
142 |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
143 env = getenv("CACHE_TTL"); |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
144 if (env == NULL) |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
145 return; |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
146 |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
147 cache_ttl = (unsigned int)strtoul(env, NULL, 10); |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
148 if (cache_ttl == 0) |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
149 return; |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
150 |
6174
6c48466c23fa
Added auth_cache_negative_ttl setting.
Timo Sirainen <tss@iki.fi>
parents:
5259
diff
changeset
|
151 env = getenv("CACHE_NEGATIVE_TTL"); |
6c48466c23fa
Added auth_cache_negative_ttl setting.
Timo Sirainen <tss@iki.fi>
parents:
5259
diff
changeset
|
152 neg_cache_ttl = env == NULL ? 0 : (unsigned int)strtoul(env, NULL, 10); |
6c48466c23fa
Added auth_cache_negative_ttl setting.
Timo Sirainen <tss@iki.fi>
parents:
5259
diff
changeset
|
153 passdb_cache = auth_cache_new(max_size, cache_ttl, neg_cache_ttl); |
2798
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
154 } |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
155 |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
156 void passdb_cache_deinit(void) |
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
157 { |
2811
253fae0aa95f
Don't try to free cache if it doesn't exist.
Timo Sirainen <tss@iki.fi>
parents:
2798
diff
changeset
|
158 if (passdb_cache != NULL) |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
159 auth_cache_free(&passdb_cache); |
2798
54b29901a793
Added simple LRU cache for auth requests. Currently only for sql passdb.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
160 } |