]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/at.c
Sync with HEAD
[openldap] / servers / slapd / at.c
index 44ec64c2e0499b4ddfea3fa46d0c428e0bb8014e..2b7d1cd08ba875e5eb325a4be53d48e3f5144f4d 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2005 The OpenLDAP Foundation.
+ * Copyright 1998-2006 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -247,6 +247,10 @@ at_destroy( void )
        if ( slap_schema.si_at_undefined ) {
                ad_destroy(slap_schema.si_at_undefined->sat_ad);
        }
+
+       if ( slap_schema.si_at_proxied ) {
+               ad_destroy(slap_schema.si_at_proxied->sat_ad);
+       }
 }
 
 int
@@ -341,14 +345,13 @@ at_insert(
     const char         **err )
 {
        struct aindexrec        *air;
-       char                    **names;
+       char                    **names = NULL;
 
 
        if ( sat->sat_oid ) {
                air = (struct aindexrec *)
                        ch_calloc( 1, sizeof(struct aindexrec) );
-               air->air_name.bv_val = sat->sat_oid;
-               air->air_name.bv_len = strlen(sat->sat_oid);
+               ber_str2bv( sat->sat_oid, 0, 0, &air->air_name );
                air->air_at = sat;
                if ( avl_insert( &attr_index, (caddr_t) air,
                                 attr_index_cmp, avl_dup_error ) )
@@ -375,8 +378,7 @@ at_insert(
                while ( *names ) {
                        air = (struct aindexrec *)
                                ch_calloc( 1, sizeof(struct aindexrec) );
-                       air->air_name.bv_val = *names;
-                       air->air_name.bv_len = strlen(*names);
+                       ber_str2bv( *names, 0, 0, &air->air_name );
                        air->air_at = sat;
                        if ( avl_insert( &attr_index, (caddr_t) air,
                                         attr_index_cmp, avl_dup_error ) )
@@ -392,6 +394,29 @@ at_insert(
 
                                ldap_memfree(air);
 
+                               while ( names > sat->sat_names ) {
+                                       struct aindexrec        tmpair;
+
+                                       names--;
+                                       ber_str2bv( *names, 0, 0, &tmpair.air_name );
+                                       tmpair.air_at = sat;
+                                       air = (struct aindexrec *)avl_delete( &attr_index,
+                                               (caddr_t)&tmpair, attr_index_cmp );
+                                       assert( air != NULL );
+                                       ldap_memfree( air );
+                               }
+
+                               if ( sat->sat_oid ) {
+                                       struct aindexrec        tmpair;
+
+                                       ber_str2bv( sat->sat_oid, 0, 0, &tmpair.air_name );
+                                       tmpair.air_at = sat;
+                                       air = (struct aindexrec *)avl_delete( &attr_index,
+                                               (caddr_t)&tmpair, attr_index_cmp );
+                                       assert( air != NULL );
+                                       ldap_memfree( air );
+                               }
+
                                return rc;
                        }
                        /* FIX: temporal consistency check */
@@ -400,6 +425,18 @@ at_insert(
                }
        }
 
+       if ( sat->sat_oid ) {
+               slap_ad_undef_promote( sat->sat_oid, sat );
+       }
+
+       names = sat->sat_names;
+       if ( names ) {
+               while ( *names ) {
+                       slap_ad_undef_promote( *names, sat );
+                       names++;
+               }
+       }
+
        LDAP_STAILQ_INSERT_TAIL( &attr_list, sat, sat_next );
 
        return 0;
@@ -412,16 +449,17 @@ at_add(
        AttributeType           **rsat,
        const char              **err )
 {
-       AttributeType   *sat;
-       MatchingRule    *mr;
-       Syntax          *syn;
+       AttributeType   *sat = NULL;
+       MatchingRule    *mr = NULL;
+       Syntax          *syn = NULL;
        int             i;
-       int             code;
-       char    *cname;
-       char    *oid;
-       char    *oidm = NULL;
+       int             code = LDAP_SUCCESS;
+       char            *cname = NULL;
+       char            *oidm = NULL;
 
        if ( !OID_LEADCHAR( at->at_oid[0] )) {
+               char    *oid;
+
                /* Expand OID macros */
                oid = oidm_find( at->at_oid );
                if ( !oid ) {
@@ -435,11 +473,14 @@ at_add(
        }
 
        if ( at->at_syntax_oid && !OID_LEADCHAR( at->at_syntax_oid[0] )) {
+               char    *oid;
+
                /* Expand OID macros */
                oid = oidm_find( at->at_syntax_oid );
                if ( !oid ) {
                        *err = at->at_syntax_oid;
-                       return SLAP_SCHERR_OIDM;
+                       code = SLAP_SCHERR_OIDM;
+                       goto error_return;
                }
                if ( oid != at->at_syntax_oid ) {
                        ldap_memfree( at->at_syntax_oid );
@@ -453,7 +494,8 @@ at_add(
                for( i=0; at->at_names[i]; i++ ) {
                        if( !slap_valid_descr( at->at_names[i] ) ) {
                                *err = at->at_names[i];
-                               return SLAP_SCHERR_BAD_DESCR;
+                               code = SLAP_SCHERR_BAD_DESCR;
+                               goto error_return;
                        }
                }
 
@@ -464,25 +506,29 @@ at_add(
 
        } else {
                *err = "";
-               return SLAP_SCHERR_ATTR_INCOMPLETE;
+               code = SLAP_SCHERR_ATTR_INCOMPLETE;
+               goto error_return;
        }
 
        *err = cname;
 
        if ( !at->at_usage && at->at_no_user_mod ) {
                /* user attribute must be modifable */
-               return SLAP_SCHERR_ATTR_BAD_USAGE;
+               code = SLAP_SCHERR_ATTR_BAD_USAGE;
+               goto error_return;
        }
 
        if ( at->at_collective ) {
                if( at->at_usage ) {
                        /* collective attributes cannot be operational */
-                       return SLAP_SCHERR_ATTR_BAD_USAGE;
+                       code = SLAP_SCHERR_ATTR_BAD_USAGE;
+                       goto error_return;
                }
 
                if( at->at_single_value ) {
                        /* collective attributes cannot be single-valued */
-                       return SLAP_SCHERR_ATTR_BAD_USAGE;
+                       code = SLAP_SCHERR_ATTR_BAD_USAGE;
+                       goto error_return;
                }
        }
 
@@ -743,6 +789,7 @@ error_return:;
 }
 
 #ifdef LDAP_DEBUG
+#ifdef SLAPD_UNUSED
 static int
 at_index_printnode( void *v_air, void *ignore )
 {
@@ -760,6 +807,7 @@ at_index_print( void )
        (void) avl_apply( attr_index, at_index_printnode, 0, -1, AVL_INORDER );
 }
 #endif
+#endif
 
 void
 at_unparse( BerVarray *res, AttributeType *start, AttributeType *end, int sys )