dovecot-2.1: auth: LDAP fields can now access any returned LDAP ...

dovecot at dovecot.org dovecot at dovecot.org
Thu Feb 2 15:28:16 EET 2012


details:   http://hg.dovecot.org/dovecot-2.1/rev/ab58022f934f
changeset: 14054:ab58022f934f
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Feb 02 15:28:10 2012 +0200
description:
auth: LDAP fields can now access any returned LDAP attribtes with %{ldap:name}

diffstat:

 src/auth/db-ldap.c |  33 ++++++++++++++++++++++++++++++++-
 1 files changed, 32 insertions(+), 1 deletions(-)

diffs (55 lines):

diff -r ba86a60e3059 -r ab58022f934f src/auth/db-ldap.c
--- a/src/auth/db-ldap.c	Thu Feb 02 15:27:27 2012 +0200
+++ b/src/auth/db-ldap.c	Thu Feb 02 15:28:10 2012 +0200
@@ -1164,11 +1164,41 @@
 	return ctx;
 }
 
+static const char *db_ldap_field_expand(const char *data, void *context)
+{
+	struct db_ldap_result_iterate_context *ctx = context;
+	struct db_ldap_value *ldap_value;
+
+	ldap_value = hash_table_lookup(ctx->ldap_attrs, data);
+	if (ldap_value == NULL) {
+		/* ldap attribute wasn't requested */
+		if (ctx->debug)
+			str_printfa(ctx->debug, "; %s missing", data);
+		return "";
+	}
+	ldap_value->used = TRUE;
+
+	if (ldap_value->values[0] == NULL) {
+		/* no value for ldap attribute */
+		return "";
+	}
+	if (ldap_value->values[1] != NULL) {
+		auth_request_log_warning(ctx->auth_request, "ldap",
+			"Multiple values found for '%s', using value '%s'",
+			data, ldap_value->values[0]);
+	}
+	return ldap_value->values[0];
+}
+
 static const char *const *
 db_ldap_result_return_value(struct db_ldap_result_iterate_context *ctx,
 			    const struct ldap_field *field,
 			    struct db_ldap_value *ldap_value)
 {
+	static struct var_expand_func_table var_funcs_table[] = {
+		{ "ldap", db_ldap_field_expand },
+		{ NULL, NULL }
+	};
 	const char *const *values;
 
 	if (ldap_value != NULL)
@@ -1196,7 +1226,8 @@
 		}
 		ctx->var_table[0].value = values[0];
 		str_truncate(ctx->var, 0);
-		var_expand(ctx->var, field->value, ctx->var_table);
+		var_expand_with_funcs(ctx->var, field->value, ctx->var_table,
+				      var_funcs_table, ctx);
 		ctx->val_1_arr[0] = str_c(ctx->var);
 		values = ctx->val_1_arr;
 	}


More information about the dovecot-cvs mailing list