From 49b7b668953f576040f308081e1920a325f49971 Mon Sep 17 00:00:00 2001 From: Ludwig Krispenz Date: Fri, 16 Nov 2012 14:13:27 +0100 Subject: [PATCH] Fix for ticket 510 Avoid creating an attribute just to determine the syntax for a type, look up the syntax directly by type --- ldap/servers/slapd/attrsyntax.c | 18 ++++++++++++++++++ ldap/servers/slapd/dn.c | 15 +++------------ ldap/servers/slapd/slapi-plugin.h | 1 + 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/ldap/servers/slapd/attrsyntax.c b/ldap/servers/slapd/attrsyntax.c index f134fa4..59506a0 100644 --- a/ldap/servers/slapd/attrsyntax.c +++ b/ldap/servers/slapd/attrsyntax.c @@ -812,6 +812,24 @@ slapi_attr_is_dn_syntax_attr(Slapi_Attr *attr) return dn_syntax; } +int +slapi_attr_is_dn_syntax_type(char *type) +{ + const char *syntaxoid = NULL; + int dn_syntax = 0; /* not DN, by default */ + struct asyntaxinfo * asi; + + asi = attr_syntax_get_by_name(type); + + if (asi && asi->asi_plugin) { /* If not set, there is no way to get the info */ + if (syntaxoid = asi->asi_plugin->plg_syntax_oid) { + dn_syntax = ((0 == strcmp(syntaxoid, NAMEANDOPTIONALUID_SYNTAX_OID)) + || (0 == strcmp(syntaxoid, DN_SYNTAX_OID))); + } + } + return dn_syntax; +} + #ifdef ATTR_LDAP_DEBUG PRIntn diff --git a/ldap/servers/slapd/dn.c b/ldap/servers/slapd/dn.c index 0ca44e7..d643d33 100644 --- a/ldap/servers/slapd/dn.c +++ b/ldap/servers/slapd/dn.c @@ -608,7 +608,6 @@ slapi_dn_normalize_ext(char *src, size_t src_len, char **dest, size_t *dest_len) /* See if the type is defined to use * the Distinguished Name syntax. */ char savechar; - Slapi_Attr test_attr; /* We need typestart to be a string containing only * the type. We terminate the type and then reset @@ -616,9 +615,7 @@ slapi_dn_normalize_ext(char *src, size_t src_len, char **dest, size_t *dest_len) savechar = *d; *d = '\0'; - slapi_attr_init(&test_attr, typestart); - is_dn_syntax = slapi_attr_is_dn_syntax_attr(&test_attr); - attr_done(&test_attr); + is_dn_syntax = slapi_attr_is_dn_syntax_type(typestart); /* Reset the character we modified. */ *d = savechar; @@ -629,7 +626,6 @@ slapi_dn_normalize_ext(char *src, size_t src_len, char **dest, size_t *dest_len) /* See if the type is defined to use * the Distinguished Name syntax. */ char savechar; - Slapi_Attr test_attr; /* We need typestart to be a string containing only * the type. We terminate the type and then reset @@ -637,9 +633,7 @@ slapi_dn_normalize_ext(char *src, size_t src_len, char **dest, size_t *dest_len) savechar = *d; *d = '\0'; - slapi_attr_init(&test_attr, typestart); - is_dn_syntax = slapi_attr_is_dn_syntax_attr(&test_attr); - attr_done(&test_attr); + is_dn_syntax = slapi_attr_is_dn_syntax_type(typestart); /* Reset the character we modified. */ *d = savechar; @@ -650,7 +644,6 @@ slapi_dn_normalize_ext(char *src, size_t src_len, char **dest, size_t *dest_len) /* See if the type is defined to use * the Distinguished Name syntax. */ char savechar; - Slapi_Attr test_attr; /* We need typestart to be a string containing only * the type. We terminate the type and then reset @@ -658,9 +651,7 @@ slapi_dn_normalize_ext(char *src, size_t src_len, char **dest, size_t *dest_len) savechar = *d; *d = '\0'; - slapi_attr_init(&test_attr, typestart); - is_dn_syntax = slapi_attr_is_dn_syntax_attr(&test_attr); - attr_done(&test_attr); + is_dn_syntax = slapi_attr_is_dn_syntax_type(typestart); /* Reset the character we modified. */ *d = savechar; diff --git a/ldap/servers/slapd/slapi-plugin.h b/ldap/servers/slapd/slapi-plugin.h index 4883ad5..978b02c 100644 --- a/ldap/servers/slapd/slapi-plugin.h +++ b/ldap/servers/slapd/slapi-plugin.h @@ -3738,6 +3738,7 @@ int slapi_attr_get_syntax_oid_copy( const Slapi_Attr *a, char **oidp ); * \return \c 0 if the attribute does not use a DN syntax. */ int slapi_attr_is_dn_syntax_attr(Slapi_Attr *attr); +int slapi_attr_is_dn_syntax_type(char *type); /** * Get the flags associated with a particular attribute. -- 1.7.11.7