[dovecot-cvs] dovecot/src/auth auth-cache.c, 1.21, 1.22 auth-request.c, 1.76, 1.77 auth-request.h, 1.30, 1.31 userdb-ldap.c, 1.43, 1.44 userdb-passwd-file.c, 1.23, 1.24 userdb-passwd.c, 1.19, 1.20 userdb-sql.c, 1.18, 1.19 userdb-vpopmail.c, 1.22, 1.23 userdb.h, 1.26, 1.27
tss-movial at dovecot.org
tss-movial at dovecot.org
Thu Dec 21 16:01:20 UTC 2006
Update of /var/lib/cvs/dovecot/src/auth
In directory talvi:/tmp/cvs-serv29514/src/auth
Modified Files:
auth-cache.c auth-request.c auth-request.h userdb-ldap.c
userdb-passwd-file.c userdb-passwd.c userdb-sql.c
userdb-vpopmail.c userdb.h
Log Message:
Authentication cache caches now also userdb data. Code by Tommi Saviranta.
Index: auth-cache.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth-cache.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- auth-cache.c 8 Nov 2006 19:13:32 -0000 1.21
+++ auth-cache.c 21 Dec 2006 16:01:15 -0000 1.22
@@ -159,7 +159,8 @@
/* %! is prepended automatically. it contains the passdb ID number. */
str = t_str_new(256);
- var_expand(str, t_strconcat("%!/", key, NULL),
+ var_expand(str, t_strconcat(request->userdb_lookup ? "U" : "P",
+ "%!/", key, NULL),
auth_request_get_var_expand_table(request,
auth_request_str_escape));
@@ -195,9 +196,10 @@
struct auth_cache_node *node;
size_t data_size, alloc_size, value_len = strlen(value);
- /* %! is prepended automatically. it contains the passdb ID number. */
+ /* %! is prepended automatically. it contains the db ID number. */
str = t_str_new(256);
- var_expand(str, t_strconcat("%!/", key, NULL),
+ var_expand(str, t_strconcat(request->userdb_lookup ? "U" : "P",
+ "%!/", key, NULL),
auth_request_get_var_expand_table(request,
auth_request_str_escape));
Index: auth-request.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth-request.c,v
retrieving revision 1.76
retrieving revision 1.77
diff -u -d -r1.76 -r1.77
--- auth-request.c 16 Dec 2006 13:37:32 -0000 1.76
+++ auth-request.c 21 Dec 2006 16:01:15 -0000 1.77
@@ -9,6 +9,7 @@
#include "str-sanitize.h"
#include "strescape.h"
#include "var-expand.h"
+#include "auth-cache.h"
#include "auth-request.h"
#include "auth-client-connection.h"
#include "auth-master-connection.h"
@@ -564,10 +565,52 @@
}
}
+static void auth_request_userdb_save_cache(struct auth_request *request,
+ struct auth_stream_reply *reply,
+ enum userdb_result result)
+{
+ struct userdb_module *userdb = request->userdb->userdb;
+ const char *str;
+
+ str = auth_stream_reply_export(reply);
+ auth_cache_insert(passdb_cache, request, userdb->cache_key, str,
+ result == PASSDB_RESULT_OK);
+}
+
+static bool auth_request_lookup_user_cache(struct auth_request *request,
+ const char *key,
+ struct auth_stream_reply **reply_r,
+ enum userdb_result *result_r,
+ bool use_expired)
+{
+ const char *value;
+ struct auth_cache_node *node;
+ bool expired;
+
+ value = auth_cache_lookup(passdb_cache, request, key, &node,
+ &expired);
+ if (value == NULL || (expired && !use_expired))
+ return FALSE;
+
+ if (*value == '\0') {
+ /* negative cache entry */
+ *result_r = PASSDB_RESULT_USER_UNKNOWN;
+ *reply_r = auth_stream_reply_init(request);
+ return TRUE;
+ }
+
+ *result_r = PASSDB_RESULT_OK;
+ *reply_r = auth_stream_reply_init(request);
+ auth_stream_reply_import(*reply_r, value);
+ return TRUE;
+}
+
void auth_request_userdb_callback(enum userdb_result result,
struct auth_stream_reply *reply,
struct auth_request *request)
{
+ struct userdb_module *userdb = request->userdb->userdb;
+
if (result != USERDB_RESULT_OK && request->userdb->next != NULL) {
/* try next userdb. */
if (result == USERDB_RESULT_INTERNAL_FAILURE)
@@ -591,6 +634,20 @@
"user not found from userdb");
}
+ if (result != PASSDB_RESULT_INTERNAL_FAILURE)
+ auth_request_userdb_save_cache(request, reply, result);
+ else {
+ /* lookup failed. if we're looking here only because the
+ request was expired in cache, fallback to using cached
+ expired record. */
+ const char *cache_key = userdb->cache_key;
+
+ if (auth_request_lookup_user_cache(request, cache_key, &reply,
+ &result, TRUE))
+ auth_request_log_info(request, "userdb",
+ "Fallbacking to expired data from cache");
+ }
+
request->private_callback.userdb(result, reply, request);
}
@@ -598,8 +655,24 @@
userdb_callback_t *callback)
{
struct userdb_module *userdb = request->userdb->userdb;
+ const char *cache_key;
request->private_callback.userdb = callback;
+ request->userdb_lookup = TRUE;
+
+ /* (for now) auth_cache is shared between passdb and userdb */
+ cache_key = passdb_cache == NULL ? NULL : userdb->cache_key;
+ if (cache_key != NULL) {
+ struct auth_stream_reply *reply;
+ enum userdb_result result;
+
+ if (auth_request_lookup_user_cache(request, cache_key, &reply,
+ &result, FALSE)) {
+ request->private_callback.userdb(result, reply,
+ request);
+ return;
+ }
+ }
if (userdb->blocking)
userdb_blocking_lookup(request);
@@ -994,8 +1067,13 @@
tab[8].value = escape_func(auth_request->mech_password,
auth_request);
}
- tab[9].value = auth_request->passdb == NULL ? "" :
- dec2str(auth_request->passdb->id);
+ if (auth_request->userdb_lookup) {
+ tab[9].value = auth_request->userdb == NULL ? "" :
+ dec2str(auth_request->userdb->num);
+ } else {
+ tab[9].value = auth_request->passdb == NULL ? "" :
+ dec2str(auth_request->passdb->id);
+ }
return tab;
}
Index: auth-request.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth-request.h,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- auth-request.h 9 Dec 2006 15:11:48 -0000 1.30
+++ auth-request.h 21 Dec 2006 16:01:15 -0000 1.31
@@ -81,6 +81,7 @@
unsigned int skip_password_check:1;
unsigned int proxy:1;
unsigned int cert_username:1;
+ unsigned int userdb_lookup:1;
/* ... mechanism specific data ... */
};
Index: userdb-ldap.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/userdb-ldap.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- userdb-ldap.c 9 Dec 2006 15:11:48 -0000 1.43
+++ userdb-ldap.c 21 Dec 2006 16:01:15 -0000 1.44
@@ -7,6 +7,7 @@
#include "hash.h"
#include "str.h"
#include "var-expand.h"
+#include "auth-cache.h"
#include "db-ldap.h"
#include "userdb.h"
@@ -224,6 +225,9 @@
db_ldap_set_attrs(conn, conn->set.user_attrs, &conn->user_attr_names,
conn->user_attr_map, default_attr_map, NULL);
+ module->module.cache_key =
+ auth_cache_parse_key(auth_userdb->auth->pool,
+ conn->set.user_filter);
return &module->module;
}
Index: userdb-passwd-file.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/userdb-passwd-file.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- userdb-passwd-file.c 9 Dec 2006 15:11:48 -0000 1.23
+++ userdb-passwd-file.c 21 Dec 2006 16:01:15 -0000 1.24
@@ -5,10 +5,13 @@
#ifdef USERDB_PASSWD_FILE
#include "str.h"
+#include "auth-cache.h"
#include "var-expand.h"
#include "userdb.h"
#include "db-passwd-file.h"
+#define PASSWD_FILE_CACHE_KEY "%u"
+
struct passwd_file_userdb_module {
struct userdb_module module;
@@ -78,6 +81,16 @@
module->auth = auth_userdb->auth;
module->pwf =
db_passwd_file_init(args, TRUE, module->auth->verbose_debug);
+
+ if (!module->pwf->vars)
+ module->module.cache_key = PASSWD_FILE_CACHE_KEY;
+ else {
+ module->module.cache_key =
+ auth_cache_parse_key(auth_userdb->auth->pool,
+ t_strconcat(PASSWD_FILE_CACHE_KEY,
+ module->pwf->path,
+ NULL));
+ }
return &module->module;
}
Index: userdb-passwd.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/userdb-passwd.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- userdb-passwd.c 9 Dec 2006 15:11:48 -0000 1.19
+++ userdb-passwd.c 21 Dec 2006 16:01:15 -0000 1.20
@@ -8,6 +8,8 @@
#include <pwd.h>
+#define USER_CACHE_KEY "%u"
+
static void passwd_lookup(struct auth_request *auth_request,
userdb_callback_t *callback)
{
@@ -39,10 +41,19 @@
callback(USERDB_RESULT_OK, reply, auth_request);
}
+static void passwd_passwd_init(struct userdb_module *module,
+ const char *args __attr_unused__)
+{
+ module->cache_key = USER_CACHE_KEY;
+}
+
struct userdb_module_interface userdb_passwd = {
"passwd",
- NULL, NULL, NULL,
+ NULL,
+ passwd_passwd_init,
+ NULL,
+
passwd_lookup
};
Index: userdb-sql.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/userdb-sql.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- userdb-sql.c 21 Dec 2006 15:57:30 -0000 1.18
+++ userdb-sql.c 21 Dec 2006 16:01:15 -0000 1.19
@@ -7,6 +7,7 @@
#include "str.h"
#include "strescape.h"
#include "var-expand.h"
+#include "auth-cache.h"
#include "db-sql.h"
#include "userdb.h"
@@ -147,6 +148,10 @@
module = p_new(auth_userdb->auth->pool, struct sql_userdb_module, 1);
module->conn = db_sql_init(args);
+
+ module->module.cache_key =
+ auth_cache_parse_key(auth_userdb->auth->pool,
+ module->conn->set.user_query);
return &module->module;
}
Index: userdb-vpopmail.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/userdb-vpopmail.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- userdb-vpopmail.c 9 Dec 2006 15:11:48 -0000 1.22
+++ userdb-vpopmail.c 21 Dec 2006 16:01:15 -0000 1.23
@@ -5,7 +5,6 @@
#include "common.h"
#if defined(PASSDB_VPOPMAIL) || defined(USERDB_VPOPMAIL)
-
#include "userdb.h"
#include "userdb-vpopmail.h"
@@ -38,7 +37,6 @@
}
#ifdef USERDB_VPOPMAIL
-
static void vpopmail_lookup(struct auth_request *auth_request,
userdb_callback_t *callback)
{
@@ -95,10 +93,27 @@
callback(USERDB_RESULT_OK, reply, auth_request);
}
+static struct userdb_module *
+vpopmail_preinit(struct auth_userdb *auth_userdb, const char *args)
+{
+ struct userdb_module *module;
+
+ module = p_new(auth_userdb->auth->pool, struct userdb_module, 1);
+
+ if (strncmp(args, "cache_key=", 10) == 0) {
+ module->cache_key = p_strconcat(auth_userdb->auth->pool,
+ args + 10, NULL);
+ }
+ return module;
+}
+
struct userdb_module_interface userdb_vpopmail = {
"vpopmail",
- NULL, NULL, NULL,
+ vpopmail_preinit,
+ NULL,
+ NULL,
+
vpopmail_lookup
};
Index: userdb.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/userdb.h,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- userdb.h 9 Dec 2006 15:11:48 -0000 1.26
+++ userdb.h 21 Dec 2006 16:01:15 -0000 1.27
@@ -17,6 +17,9 @@
struct auth_request *request);
struct userdb_module {
+ /* The caching key for this module, or NULL if caching isn't wanted. */
+ const char *cache_key;
+
/* If blocking is set to TRUE, use child processes to access
this userdb. */
bool blocking;
More information about the dovecot-cvs
mailing list