[Dovecot] [PATCH] Substitution of dots to ", dc=" in variable expansions

Andrey Panin pazke at donpac.ru
Mon Jul 24 16:27:53 EEST 2006


On 205, 07 24, 2006 at 03:41:00PM +0300, Antonio Kanouras wrote:
> Hi list,
> 
> my ldap directory uses DNs like this:
> 
>   uid=solist,ou=People,dc=solistland,dc=net,ou=Virtuals
> 
> but I only could use something like
> 
>   uid=solist,ou=People,dc=solistland.net,ou=Virtuals
> 
> with dovecot, which obviously isn't what the dcObject object class was
> meant to present.
> 
> I've written a small function for var-expand.c which introduces a new
> modifier for string variable expansions, %D (arbitrarily chosen), which
> substitutes dots to ",dc=". You might want to include that in dovecot's
> code base, after bringing it up to dovecot standards of course. :-)
> 
> Example of use:
> 
>   base = ou=People,dc=%Dd,ou=Virtuals
> 
> Warning: I'm a beginner in C and could only understand so much of
> dovecot's code, so this patch is a hack at best. That said, I tested it
> with more than 10k logins and can say it works for me. :-D

You do not need all this RET_SIZE nightmare, dovecot string API will resize
string when necessary. Can you test an attached simplified patch ?

-- 
Andrey Panin		| Linux and UNIX system administrator
pazke at donpac.ru		| PGP key: wwwkeys.pgp.net
-------------- next part --------------
diff -urdpNX /usr/share/dontdiff dovecot-1.0.beta8.vanilla/src/lib/var-expand.c dovecot-1.0.beta8/src/lib/var-expand.c
--- dovecot-1.0.beta8.vanilla/src/lib/var-expand.c	2006-04-13 06:00:06.000000000 +0400
+++ dovecot-1.0.beta8/src/lib/var-expand.c	2006-07-24 17:25:12.956083944 +0400
@@ -87,6 +87,21 @@ static const char *m_str_md5(const char 
 	return binary_to_hex(digest, sizeof(digest));
 }
 
+static const char *m_str_ldap_dn(const char *str, struct var_expand_context *ctx __attr_unused__)
+{
+	string_t *ret = t_str_new(256);
+
+	while (*str) {
+		if (*str == '.')
+			str_append(ret, ",dc=");
+		else
+			str_append_c(ret, *str);
+		str++;
+	}
+
+	return str_free_without_data(&ret);
+}
+
 #define MAX_MODIFIER_COUNT 10
 static const struct var_expand_modifier modifiers[] = {
 	{ 'L', m_str_lcase },
@@ -96,6 +111,7 @@ static const struct var_expand_modifier 
 	{ 'R', m_str_reverse },
 	{ 'H', m_str_hash },
 	{ 'M', m_str_md5 },
+	{ 'D', m_str_ldap_dn },
 	{ '\0', NULL }
 };
 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://dovecot.org/pipermail/dovecot/attachments/20060724/24f0f9ef/attachment.pgp 


More information about the dovecot mailing list