dovecot-2.0: auth sql/ldap: Allow using global %variables in ite...

dovecot at dovecot.org dovecot at dovecot.org
Fri Nov 26 20:19:20 EET 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/8ca8de045df1
changeset: 12475:8ca8de045df1
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Nov 26 18:19:16 2010 +0000
description:
auth sql/ldap: Allow using global %variables in iterate_query/filter.
No per-query %variables are defined, but e.g. %{hostname} or %{env:*} can
be used.

diffstat:

 src/auth/userdb-ldap.c |  12 +++++++++++-
 src/auth/userdb-sql.c  |  10 +++++++++-
 2 files changed, 20 insertions(+), 2 deletions(-)

diffs (64 lines):

diff -r e9b90ff13910 -r 8ca8de045df1 src/auth/userdb-ldap.c
--- a/src/auth/userdb-ldap.c	Fri Nov 26 17:46:49 2010 +0000
+++ b/src/auth/userdb-ldap.c	Fri Nov 26 18:19:16 2010 +0000
@@ -188,12 +188,17 @@
 userdb_ldap_iterate_init(struct userdb_module *userdb,
 			 userdb_iter_callback_t *callback, void *context)
 {
+	static struct var_expand_table static_tab[] = {
+		/* nothing for now, but e.g. %{hostname} can be used */
+		{ '\0', NULL, NULL }
+	};
 	struct ldap_userdb_module *module =
 		(struct ldap_userdb_module *)userdb;
 	struct ldap_connection *conn = module->conn;
 	struct ldap_userdb_iterate_context *ctx;
 	struct userdb_iter_ldap_request *request;
 	const char **attr_names = (const char **)conn->iterate_attr_names;
+	string_t *str;
 
 	ctx = i_new(struct ldap_userdb_iterate_context, 1);
 	ctx->ctx.userdb = userdb;
@@ -205,7 +210,12 @@
 
 	request->request.request.auth_request = auth_request_new_dummy();
 	request->request.base = conn->set.base;
-	request->request.filter = conn->set.iterate_filter;
+
+	str = t_str_new(512);
+	var_expand(str, conn->set.iterate_filter, static_tab);
+	request->request.filter =
+		p_strdup(request->request.request.auth_request->pool,
+			 str_c(str));
 	request->request.attributes = conn->iterate_attr_names;
 
 	if (global_auth_settings->debug) {
diff -r e9b90ff13910 -r 8ca8de045df1 src/auth/userdb-sql.c
--- a/src/auth/userdb-sql.c	Fri Nov 26 17:46:49 2010 +0000
+++ b/src/auth/userdb-sql.c	Fri Nov 26 18:19:16 2010 +0000
@@ -143,16 +143,24 @@
 userdb_sql_iterate_init(struct userdb_module *userdb,
 			userdb_iter_callback_t *callback, void *context)
 {
+	static struct var_expand_table static_tab[] = {
+		/* nothing for now, but e.g. %{hostname} can be used */
+		{ '\0', NULL, NULL }
+	};
 	struct sql_userdb_module *module =
 		(struct sql_userdb_module *)userdb;
 	struct sql_userdb_iterate_context *ctx;
+	string_t *query;
+
+	query = t_str_new(512);
+	var_expand(query, module->conn->set.iterate_query, static_tab);
 
 	ctx = i_new(struct sql_userdb_iterate_context, 1);
 	ctx->ctx.userdb = userdb;
 	ctx->ctx.callback = callback;
 	ctx->ctx.context = context;
 
-	sql_query(module->conn->db, module->conn->set.iterate_query,
+	sql_query(module->conn->db, str_c(query),
 		  sql_iter_query_callback, ctx);
 	return &ctx->ctx;
 }


More information about the dovecot-cvs mailing list