]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/at.c
fix dirsep's in DN (ITS#5172)
[openldap] / servers / slapd / at.c
index acdeff290bc7b28662e91ecc7738efadd25e1b9b..e70f10e969ba1eaaa5a1e59fec80366a3c6fdb82 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2006 The OpenLDAP Foundation.
+ * Copyright 1998-2007 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 #include "slap.h"
 
 
-int is_at_syntax(
-       AttributeType *at,
-       const char *oid )
+const char *
+at_syntax(
+       AttributeType   *at )
 {
-       for( ; at != NULL; at = at->sat_sup ) {
-               if( at->sat_syntax_oid ) {
-                       return ( strcmp( at->sat_syntax_oid, oid ) == 0 );
+       for ( ; at != NULL; at = at->sat_sup ) {
+               if ( at->sat_syntax_oid ) {
+                       return at->sat_syntax_oid;
                }
        }
 
+       assert( 0 );
+
+       return NULL;
+}
+
+int
+is_at_syntax(
+       AttributeType   *at,
+       const char      *oid )
+{
+       const char *syn_oid = at_syntax( at );
+
+       if ( syn_oid ) {
+               return strcmp( syn_oid, oid ) == 0;
+       }
+
        return 0;
 }
 
@@ -58,7 +74,7 @@ struct aindexrec {
 
 static Avlnode *attr_index = NULL;
 static Avlnode *attr_cache = NULL;
-static LDAP_STAILQ_HEAD(ATList, slap_attribute_type) attr_list
+static LDAP_STAILQ_HEAD(ATList, AttributeType) attr_list
        = LDAP_STAILQ_HEAD_INITIALIZER(attr_list);
 
 /* Last hardcoded attribute registered */
@@ -237,7 +253,7 @@ at_delete( AttributeType *at )
 {
        at->sat_flags |= SLAP_AT_DELETED;
 
-       LDAP_STAILQ_REMOVE(&attr_list,at,slap_attribute_type,sat_next);
+       LDAP_STAILQ_REMOVE(&attr_list, at, AttributeType, sat_next);
 
        at_delete_names( at );
 }
@@ -268,8 +284,14 @@ at_clean( AttributeType *a )
                }
        }
 
-       if ( a->sat_oidmacro ) ldap_memfree( a->sat_oidmacro );
-       if ( a->sat_subtypes ) ldap_memfree( a->sat_subtypes );
+       if ( a->sat_oidmacro ) {
+               ldap_memfree( a->sat_oidmacro );
+               a->sat_oidmacro = NULL;
+       }
+       if ( a->sat_subtypes ) {
+               ldap_memfree( a->sat_subtypes );
+               a->sat_subtypes = NULL;
+       }
 }
 
 static void
@@ -323,7 +345,7 @@ at_next( AttributeType **at )
 {
        assert( at != NULL );
 
-#if 1  /* pedantic check */
+#if 0  /* pedantic check: don't use this */
        {
                AttributeType *tmp = NULL;
 
@@ -433,9 +455,11 @@ at_insert(
                        /* replacing a deleted definition? */
                        if ( old_sat->sat_flags & SLAP_AT_DELETED ) {
                                AttributeType tmp;
+                               AttributeDescription *ad;
                                
                                /* Keep old oid, free new oid;
                                 * Keep old ads, free new ads;
+                                * Keep old ad_mutex, free new ad_mutex;
                                 * Keep new everything else, free old
                                 */
                                tmp = *old_sat;
@@ -444,8 +468,18 @@ at_insert(
                                tmp.sat_oid = sat->sat_oid;
                                old_sat->sat_ad = tmp.sat_ad;
                                tmp.sat_ad = sat->sat_ad;
+                               old_sat->sat_ad_mutex = tmp.sat_ad_mutex;
+                               tmp.sat_ad_mutex = sat->sat_ad_mutex;
                                *sat = tmp;
 
+                               /* Check for basic ad pointing at old cname */
+                               for ( ad = old_sat->sat_ad; ad; ad=ad->ad_next ) {
+                                       if ( ad->ad_cname.bv_val == sat->sat_cname.bv_val ) {
+                                               ad->ad_cname = old_sat->sat_cname;
+                                               break;
+                                       }
+                               }
+
                                at_clean( sat );
                                at_destroy_one( air );
 
@@ -720,9 +754,12 @@ at_add(
                        goto error_return;
                }
 
-               if( sat->sat_syntax != NULL && sat->sat_syntax != syn ) {
-                       code = SLAP_SCHERR_ATTR_BAD_SUP;
-                       goto error_return;
+               if ( sat->sat_syntax != NULL && sat->sat_syntax != syn ) {
+                       /* BEWARE: no loop detection! */
+                       if ( syn_is_sup( sat->sat_syntax, syn ) ) {
+                               code = SLAP_SCHERR_ATTR_BAD_SUP;
+                               goto error_return;
+                       }
                }
 
                sat->sat_syntax = syn;