浏览代码

Fix for ticket 510
Avoid creating an attribute just to determine the syntax for a type, look up the syntax directly by type

Ludwig Krispenz 13 年之前
父节点
当前提交
49b7b66895
共有 3 个文件被更改,包括 22 次插入12 次删除
  1. 18 0
      ldap/servers/slapd/attrsyntax.c
  2. 3 12
      ldap/servers/slapd/dn.c
  3. 1 0
      ldap/servers/slapd/slapi-plugin.h

+ 18 - 0
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

+ 3 - 12
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;

+ 1 - 0
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.