dovecot: Having =key=value in pass_attrs or user_attrs allows re...

dovecot at dovecot.org dovecot at dovecot.org
Wed Jul 25 09:21:42 EEST 2007


details:   http://hg.dovecot.org/dovecot/rev/a744ae38a9e1
changeset: 6149:a744ae38a9e1
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Jul 25 09:21:35 2007 +0300
description:
Having =key=value in pass_attrs or user_attrs allows returning static
key=value pairs.

diffstat:

1 file changed, 34 insertions(+), 1 deletion(-)
src/auth/db-ldap.c |   35 ++++++++++++++++++++++++++++++++++-

diffs (102 lines):

diff -r 668a768fc8fd -r a744ae38a9e1 src/auth/db-ldap.c
--- a/src/auth/db-ldap.c	Wed Jul 25 09:11:43 2007 +0300
+++ b/src/auth/db-ldap.c	Wed Jul 25 09:21:35 2007 +0300
@@ -52,6 +52,7 @@ struct db_ldap_result_iterate_context {
 
 	char *attr, **vals;
 	const char *name, *value, *template, *val_1_arr[2];
+	const char *const *static_attrs;
 	BerElement *ber;
 
 	string_t *var, *debug;
@@ -622,6 +623,7 @@ void db_ldap_set_attrs(struct ldap_conne
 		       const char *skip_attr)
 {
 	const char *const *attr;
+	string_t *static_data;
 	char *name, *value, *p;
 	unsigned int i, j, size;
 
@@ -630,6 +632,7 @@ void db_ldap_set_attrs(struct ldap_conne
 
 	t_push();
 	attr = t_strsplit(attrlist, ",");
+	static_data = t_str_new(128);
 
 	/* @UNSAFE */
 	for (size = 0; attr[size] != NULL; size++) ;
@@ -639,9 +642,15 @@ void db_ldap_set_attrs(struct ldap_conne
 		p = strchr(attr[i], '=');
 		if (p == NULL)
 			name = value = p_strdup(conn->pool, attr[i]);
-		else {
+		else if (p != attr[i]) {
 			name = p_strdup_until(conn->pool, attr[i], p);
 			value = p_strdup(conn->pool, p + 1);
+		} else {
+			/* =<static key>=<static value> */
+			if (str_len(static_data) > 0)
+				str_append_c(static_data, ',');
+			str_append(static_data, p + 1);
+			continue;
 		}
 
 		if (*name != '\0' &&
@@ -650,6 +659,10 @@ void db_ldap_set_attrs(struct ldap_conne
 			(*attr_names_r)[j++] = name;
 		}
 	}
+	if (str_len(static_data) > 0) {
+		hash_insert(attr_map, "",
+			    p_strdup(conn->pool, str_c(static_data)));
+	}
 	t_pop();
 }
 
@@ -704,12 +717,17 @@ db_ldap_result_iterate_init(struct ldap_
 			    struct hash_table *attr_map)
 {
 	struct db_ldap_result_iterate_context *ctx;
+	const char *static_data;
 
 	ctx = t_new(struct db_ldap_result_iterate_context, 1);
 	ctx->conn = conn;
 	ctx->entry = entry;
 	ctx->auth_request = auth_request;
 	ctx->attr_map = attr_map;
+
+	static_data = hash_lookup(attr_map, "");
+	if (static_data != NULL)
+		ctx->static_attrs = t_strsplit(static_data, ",");
 
 	if (auth_request->auth->verbose_debug)
 		ctx->debug = t_str_new(256);
@@ -787,6 +805,8 @@ db_ldap_result_return_value(struct db_ld
 
 static bool db_ldap_result_int_next(struct db_ldap_result_iterate_context *ctx)
 {
+	const char *p;
+
 	while (ctx->attr != NULL) {
 		if (ctx->vals == NULL) {
 			/* a new attribute */
@@ -808,6 +828,19 @@ static bool db_ldap_result_int_next(stru
 						ctx->ber);
 	}
 
+	if (ctx->static_attrs != NULL && *ctx->static_attrs != NULL) {
+		p = strchr(*ctx->static_attrs, '=');
+		if (p == NULL) {
+			ctx->name = *ctx->static_attrs;
+			ctx->value = "";
+		} else {
+			ctx->name = t_strdup_until(*ctx->static_attrs, p);
+			ctx->value = p + 1;
+		}
+		ctx->static_attrs++;
+		return TRUE;
+	}
+
 	db_ldap_result_iterate_finish(ctx);
 	return FALSE;
 }


More information about the dovecot-cvs mailing list