]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/at.c
Fix log_age_parse days parsing
[openldap] / servers / slapd / at.c
index 59bdb98142a23cf8882be565ef94941c41e9198a..9453cabf02383cb3fb9acc1738a5ec89c69972b8 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
@@ -345,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 ) )
@@ -379,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 ) )
@@ -396,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 */
@@ -428,16 +449,22 @@ 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 ( !at->at_oid ) {
+               *err = "";
+               return SLAP_SCHERR_ATTR_INCOMPLETE;
+       }
 
        if ( !OID_LEADCHAR( at->at_oid[0] )) {
+               char    *oid;
+
                /* Expand OID macros */
                oid = oidm_find( at->at_oid );
                if ( !oid ) {
@@ -451,11 +478,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 );
@@ -469,36 +499,37 @@ 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;
                        }
                }
 
                cname = at->at_names[0];
 
-       } else if ( at->at_oid ) {
+       } else {
                cname = at->at_oid;
 
-       } else {
-               *err = "";
-               return SLAP_SCHERR_ATTR_INCOMPLETE;
        }
 
        *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;
                }
        }
 
@@ -759,6 +790,7 @@ error_return:;
 }
 
 #ifdef LDAP_DEBUG
+#ifdef SLAPD_UNUSED
 static int
 at_index_printnode( void *v_air, void *ignore )
 {
@@ -776,6 +808,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 )