From d866ac96b14cef65c5d116f5ec4b047025c3be98 Mon Sep 17 00:00:00 2001 From: Chris Toshok Date: Tue, 19 Feb 2002 00:06:39 +0000 Subject: escape commas in the dn, since they're used by ldap to specify the node's 2002-02-18 Chris Toshok * backend/pas/pas-backend-ldap.c (create_dn_from_ecard): escape commas in the dn, since they're used by ldap to specify the node's placement in the tree. (fixes bug 20089) (rfc2254_escape): just use sprintf and %02X instead. svn path=/trunk/; revision=15756 --- addressbook/backend/pas/pas-backend-ldap.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'addressbook/backend') diff --git a/addressbook/backend/pas/pas-backend-ldap.c b/addressbook/backend/pas/pas-backend-ldap.c index cfd6b0d1d5..3071fa7e45 100644 --- a/addressbook/backend/pas/pas-backend-ldap.c +++ b/addressbook/backend/pas/pas-backend-ldap.c @@ -586,11 +586,29 @@ create_dn_from_ecard (ECardSimple *card, const char *root_dn) { char *cn, *cn_part = NULL; char *dn; - gboolean need_comma = FALSE; cn = e_card_simple_get (card, E_CARD_SIMPLE_FIELD_FULL_NAME); if (cn) { - cn_part = g_strdup_printf ("cn=%s%s", cn, need_comma ? "," : ""); + if (strchr (cn, ',')) { + /* need to escape commas */ + char *new_cn = g_malloc0 (strlen (cn) * 3 + 1); + int i, j; + + for (i = 0, j = 0; i < strlen (cn); i ++) { + if (cn[i] == ',') { + sprintf (new_cn + j, "%%%02X", cn[i]); + j += 3; + } + else { + new_cn[j++] = cn[i]; + } + } + cn_part = g_strdup_printf ("cn=%s", new_cn); + g_free (new_cn); + } + else { + cn_part = g_strdup_printf ("cn=%s", cn); + } } else { cn_part = g_strdup (""); @@ -1766,7 +1784,6 @@ birthday_compare (ECardSimple *ecard1, ECardSimple *ecard2) } #define IS_RFC2254_CHAR(c) ((c) == '*' || (c) =='\\' || (c) == '(' || (c) == ')' || (c) == '\0') -static char hex[] = "0123456789abcdef"; static char * rfc2254_escape(char *str) { @@ -1789,9 +1806,8 @@ rfc2254_escape(char *str) int j = 0; for (i = 0; i < len; i ++) { if (IS_RFC2254_CHAR(str[i])) { - newstr[j++] = '\\'; - newstr[j++] = hex[(str[i]&0xf0) >> 4]; - newstr[j++] = hex[str[i]&0x0f]; + sprintf (newstr + j, "\\%02x", str[i]); + j+= 3; } else { newstr[j++] = str[i]; @@ -1799,7 +1815,6 @@ rfc2254_escape(char *str) } return newstr; } - } static ESExpResult * -- cgit v1.2.3