]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/modify.c
Fixed slapd req_pwdexop bug
[openldap] / servers / slapd / modify.c
index 56d6c0bf4aaa23b1ae63ef334851ba9b0bc32a56..ca628ef5ff424a93f86a8b243407d6e93f351fc7 100644 (file)
@@ -140,7 +140,7 @@ do_modify(
                                        goto cleanup;
                                }
 
-                               if( mod->sml_values[1].bv_val ) {
+                               if ( !BER_BVISNULL( &mod->sml_values[ 1 ] ) ) {
                                        Debug( LDAP_DEBUG_ANY, "do_modify: modify/increment "
                                                "operation (%ld) requires single value\n",
                                                (long) mop, 0, 0 );
@@ -184,8 +184,8 @@ do_modify(
                goto cleanup;
        }
 
-       rs->sr_err = slap_mods_check( modlist, &rs->sr_text,
-               textbuf, textlen, NULL );
+       rs->sr_err = slap_mods_check( modlist,
+               &rs->sr_text, textbuf, textlen, NULL );
 
        if ( rs->sr_err != LDAP_SUCCESS ) {
                send_ldap_result( op, rs );
@@ -251,10 +251,10 @@ fe_op_modify( Operation *op, SlapReply *rs )
                if ( tmp->sml_values == NULL ) {
                        Debug( LDAP_DEBUG_ARGS, "%s\n",
                           "\t\tno values", NULL, NULL );
-               } else if ( tmp->sml_values[0].bv_val == NULL ) {
+               } else if ( BER_BVISNULL( &tmp->sml_values[ 0 ] ) ) {
                        Debug( LDAP_DEBUG_ARGS, "%s\n",
                           "\t\tzero values", NULL, NULL );
-               } else if ( tmp->sml_values[1].bv_val == NULL ) {
+               } else if ( BER_BVISNULL( &tmp->sml_values[ 1 ] ) ) {
                        Debug( LDAP_DEBUG_ARGS, "%s, length %ld\n",
                           "\t\tone value", (long) tmp->sml_values[0].bv_len, NULL );
                } else {
@@ -499,8 +499,9 @@ slap_mods_no_user_mod_check(
        for ( ; ml != NULL; ml = ml->sml_next ) {
                if ( !is_at_no_user_mod( ml->sml_desc->ad_type ) ) continue;
 
-               if( get_manageDIT( op )) {
+               if ( get_manageDIT( op ) ) {
                        if ( ml->sml_desc->ad_type->sat_flags & SLAP_AT_MANAGEABLE ) {
+                               ml->sml_flags |= SLAP_MOD_MANAGING;
                                continue;
                        }
 
@@ -844,7 +845,7 @@ int slap_mods_opattrs(
        assert( modtail != NULL );
        assert( *modtail == NULL );
 
-       if ( SLAP_LASTMOD( op->o_bd )) {
+       if ( SLAP_LASTMOD( op->o_bd ) ) {
                time_t now = slap_get_time();
 
                slap_get_csn( op, csnbuf, sizeof(csnbuf), &csn, manage_ctxcsn );
@@ -854,7 +855,7 @@ int slap_mods_opattrs(
 
                slap_timestamp( &now, &timestamp );
 
-               if( op->o_dn.bv_len == 0 ) {
+               if ( BER_BVISEMPTY( &op->o_dn ) ) {
                        BER_BVSTR( &name, SLAPD_ANONYMOUS );
                        nname = name;
                } else {
@@ -863,10 +864,20 @@ int slap_mods_opattrs(
                }
        }
 
-       if( op->o_tag == LDAP_REQ_ADD ) {
+       if ( op->o_tag == LDAP_REQ_ADD ) {
                struct berval tmpval;
 
-               {
+               mod = *modtail;
+               if ( get_manageDIT( op ) ) {
+                       for ( mod = mods; mod != *modtail; mod = mod->sml_next ) {
+                               if ( mod->sml_desc == slap_schema.si_ad_structuralObjectClass ) {
+                                       break;
+                               }
+                       }
+
+               }
+
+               if ( mod == *modtail ) {
                        int rc = mods_structural_class( mods, &tmpval,
                                text, textbuf, textlen );
                        if( rc != LDAP_SUCCESS ) return rc;
@@ -874,139 +885,190 @@ int slap_mods_opattrs(
                        mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
                        mod->sml_op = mop;
                        mod->sml_flags = SLAP_MOD_INTERNAL;
-                       mod->sml_type.bv_val = NULL;
+                       mod->sml_next = NULL;
+                       BER_BVZERO( &mod->sml_type );
                        mod->sml_desc = slap_schema.si_ad_structuralObjectClass;
                        mod->sml_values =
                                (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
                        ber_dupbv( &mod->sml_values[0], &tmpval );
-                       mod->sml_values[1].bv_len = 0;
-                       mod->sml_values[1].bv_val = NULL;
-                       assert( mod->sml_values[0].bv_val != NULL );
+                       BER_BVZERO( &mod->sml_values[1] );
+                       assert( !BER_BVISNULL( &mod->sml_values[0] ) );
                        mod->sml_nvalues =
                                (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
                        ber_dupbv( &mod->sml_nvalues[0], &tmpval );
-                       mod->sml_nvalues[1].bv_len = 0;
-                       mod->sml_nvalues[1].bv_val = NULL;
-                       assert( mod->sml_nvalues[0].bv_val != NULL );
+                       BER_BVZERO( &mod->sml_nvalues[1] );
+                       assert( !BER_BVISNULL( &mod->sml_nvalues[0] ) );
                        *modtail = mod;
                        modtail = &mod->sml_next;
                }
 
-               if ( SLAP_LASTMOD( op->o_bd )) {
-                       char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
+               if ( SLAP_LASTMOD( op->o_bd ) ) {
+                       mod = *modtail;
+                       if ( get_manageDIT( op ) ) {
+                               for ( mod = mods; mod != *modtail; mod = mod->sml_next ) {
+                                       if ( mod->sml_desc == slap_schema.si_ad_entryUUID ) {
+                                               break;
+                                       }
+                               }
+                       }
 
-                       tmpval.bv_len = lutil_uuidstr( uuidbuf, sizeof( uuidbuf ) );
-                       tmpval.bv_val = uuidbuf;
-               
-                       mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
-                       mod->sml_op = mop;
-                       mod->sml_flags = SLAP_MOD_INTERNAL;
-                       mod->sml_type.bv_val = NULL;
-                       mod->sml_desc = slap_schema.si_ad_entryUUID;
-                       mod->sml_values =
-                               (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
-                       ber_dupbv( &mod->sml_values[0], &tmpval );
-                       mod->sml_values[1].bv_len = 0;
-                       mod->sml_values[1].bv_val = NULL;
-                       assert( mod->sml_values[0].bv_val != NULL );
-                       mod->sml_nvalues =
-                               (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
-                       (*mod->sml_desc->ad_type->sat_equality->smr_normalize)(
-                                       SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
-                                       mod->sml_desc->ad_type->sat_syntax,
-                                       mod->sml_desc->ad_type->sat_equality,
-                                       mod->sml_values, mod->sml_nvalues, NULL );
-                       mod->sml_nvalues[1].bv_len = 0;
-                       mod->sml_nvalues[1].bv_val = NULL;
-                       *modtail = mod;
-                       modtail = &mod->sml_next;
+                       if ( mod == *modtail ) {
+                               char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
+
+                               tmpval.bv_len = lutil_uuidstr( uuidbuf, sizeof( uuidbuf ) );
+                               tmpval.bv_val = uuidbuf;
+                       
+                               mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
+                               mod->sml_op = mop;
+                               mod->sml_flags = SLAP_MOD_INTERNAL;
+                               mod->sml_next = NULL;
+                               BER_BVZERO( &mod->sml_type );
+                               mod->sml_desc = slap_schema.si_ad_entryUUID;
+                               mod->sml_values =
+                                       (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
+                               ber_dupbv( &mod->sml_values[0], &tmpval );
+                               BER_BVZERO( &mod->sml_values[1] );
+                               assert( !BER_BVISNULL( &mod->sml_values[0] ) );
+                               mod->sml_nvalues =
+                                       (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
+                               (*mod->sml_desc->ad_type->sat_equality->smr_normalize)(
+                                               SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
+                                               mod->sml_desc->ad_type->sat_syntax,
+                                               mod->sml_desc->ad_type->sat_equality,
+                                               mod->sml_values, mod->sml_nvalues, NULL );
+                               BER_BVZERO( &mod->sml_nvalues[1] );
+                               *modtail = mod;
+                               modtail = &mod->sml_next;
+                       }
 
+                       mod = *modtail;
+                       if ( get_manageDIT( op ) ) {
+                               for ( mod = mods; mod != *modtail; mod = mod->sml_next ) {
+                                       if ( mod->sml_desc == slap_schema.si_ad_creatorsName ) {
+                                               break;
+                                       }
+                               }
+                       }
+
+                       if ( mod == *modtail ) {
+                               mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
+                               mod->sml_op = mop;
+                               mod->sml_flags = SLAP_MOD_INTERNAL;
+                               mod->sml_next = NULL;
+                               BER_BVZERO( &mod->sml_type );
+                               mod->sml_desc = slap_schema.si_ad_creatorsName;
+                               mod->sml_values =
+                                       (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
+                               ber_dupbv( &mod->sml_values[0], &name );
+                               BER_BVZERO( &mod->sml_values[1] );
+                               assert( !BER_BVISNULL( &mod->sml_values[0] ) );
+                               mod->sml_nvalues =
+                                       (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
+                               ber_dupbv( &mod->sml_nvalues[0], &nname );
+                               BER_BVZERO( &mod->sml_nvalues[1] );
+                               assert( !BER_BVISNULL( &mod->sml_nvalues[0] ) );
+                               *modtail = mod;
+                               modtail = &mod->sml_next;
+                       }
+       
+                       mod = *modtail;
+                       if ( get_manageDIT( op ) ) {
+                               for ( mod = mods; mod != *modtail; mod = mod->sml_next ) {
+                                       if ( mod->sml_desc == slap_schema.si_ad_createTimestamp ) {
+                                               break;
+                                       }
+                               }
+                       }
+
+                       if ( mod == *modtail ) {
+                               mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
+                               mod->sml_op = mop;
+                               mod->sml_flags = SLAP_MOD_INTERNAL;
+                               mod->sml_next = NULL;
+                               BER_BVZERO( &mod->sml_type );
+                               mod->sml_desc = slap_schema.si_ad_createTimestamp;
+                               mod->sml_values =
+                                       (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
+                               ber_dupbv( &mod->sml_values[0], &timestamp );
+                               BER_BVZERO( &mod->sml_values[1] );
+                               assert( !BER_BVISNULL( &mod->sml_values[0] ) );
+                               mod->sml_nvalues = NULL;
+                               *modtail = mod;
+                               modtail = &mod->sml_next;
+                       }
+               }
+       }
+
+       if ( SLAP_LASTMOD( op->o_bd ) ) {
+               mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
+               mod->sml_op = mop;
+               mod->sml_flags = SLAP_MOD_INTERNAL;
+               mod->sml_next = NULL;
+               BER_BVZERO( &mod->sml_type );
+               mod->sml_desc = slap_schema.si_ad_entryCSN;
+               mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
+               ber_dupbv( &mod->sml_values[0], &csn );
+               BER_BVZERO( &mod->sml_values[1] );
+               assert( !BER_BVISNULL( &mod->sml_values[0] ) );
+               mod->sml_nvalues = NULL;
+               *modtail = mod;
+               modtail = &mod->sml_next;
+       
+               mod = *modtail;
+               if ( get_manageDIT( op ) ) {
+                       for ( mod = mods; mod != *modtail; mod = mod->sml_next ) {
+                               if ( mod->sml_desc == slap_schema.si_ad_modifiersName ) {
+                                       break;
+                               }
+                       }
+               }
+
+               if ( mod == *modtail ) {
                        mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
                        mod->sml_op = mop;
                        mod->sml_flags = SLAP_MOD_INTERNAL;
-                       mod->sml_type.bv_val = NULL;
-                       mod->sml_desc = slap_schema.si_ad_creatorsName;
-                       mod->sml_values =
-                               (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
+                       mod->sml_next = NULL;
+                       BER_BVZERO( &mod->sml_type );
+                       mod->sml_desc = slap_schema.si_ad_modifiersName;
+                       mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
                        ber_dupbv( &mod->sml_values[0], &name );
-                       mod->sml_values[1].bv_len = 0;
-                       mod->sml_values[1].bv_val = NULL;
-                       assert( mod->sml_values[0].bv_val != NULL );
+                       BER_BVZERO( &mod->sml_values[1] );
+                       assert( !BER_BVISNULL( &mod->sml_values[0] ) );
                        mod->sml_nvalues =
                                (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
                        ber_dupbv( &mod->sml_nvalues[0], &nname );
-                       mod->sml_nvalues[1].bv_len = 0;
-                       mod->sml_nvalues[1].bv_val = NULL;
-                       assert( mod->sml_nvalues[0].bv_val != NULL );
+                       BER_BVZERO( &mod->sml_nvalues[1] );
+                       assert( !BER_BVISNULL( &mod->sml_nvalues[0] ) );
                        *modtail = mod;
                        modtail = &mod->sml_next;
+               }
 
+               mod = *modtail;
+               if ( get_manageDIT( op ) ) {
+                       for ( mod = mods; mod != *modtail; mod = mod->sml_next ) {
+                               if ( mod->sml_desc == slap_schema.si_ad_modifyTimestamp ) {
+                                       break;
+                               }
+                       }
+               }
+
+               if ( mod == *modtail ) {
                        mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
                        mod->sml_op = mop;
                        mod->sml_flags = SLAP_MOD_INTERNAL;
-                       mod->sml_type.bv_val = NULL;
-                       mod->sml_desc = slap_schema.si_ad_createTimestamp;
-                       mod->sml_values =
-                               (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
+                       mod->sml_next = NULL;
+                       BER_BVZERO( &mod->sml_type );
+                       mod->sml_desc = slap_schema.si_ad_modifyTimestamp;
+                       mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
                        ber_dupbv( &mod->sml_values[0], &timestamp );
-                       mod->sml_values[1].bv_len = 0;
-                       mod->sml_values[1].bv_val = NULL;
-                       assert( mod->sml_values[0].bv_val != NULL );
+                       BER_BVZERO( &mod->sml_values[1] );
+                       assert( !BER_BVISNULL( &mod->sml_values[0] ) );
                        mod->sml_nvalues = NULL;
                        *modtail = mod;
                        modtail = &mod->sml_next;
                }
        }
 
-       if ( SLAP_LASTMOD( op->o_bd )) {
-               mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
-               mod->sml_op = mop;
-               mod->sml_flags = SLAP_MOD_INTERNAL;
-               mod->sml_type.bv_val = NULL;
-               mod->sml_desc = slap_schema.si_ad_entryCSN;
-               mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
-               ber_dupbv( &mod->sml_values[0], &csn );
-               mod->sml_values[1].bv_len = 0;
-               mod->sml_values[1].bv_val = NULL;
-               assert( mod->sml_values[0].bv_val != NULL );
-               mod->sml_nvalues = NULL;
-               *modtail = mod;
-               modtail = &mod->sml_next;
-
-               mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
-               mod->sml_op = mop;
-               mod->sml_flags = SLAP_MOD_INTERNAL;
-               mod->sml_type.bv_val = NULL;
-               mod->sml_desc = slap_schema.si_ad_modifiersName;
-               mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
-               ber_dupbv( &mod->sml_values[0], &name );
-               mod->sml_values[1].bv_len = 0;
-               mod->sml_values[1].bv_val = NULL;
-               assert( mod->sml_values[0].bv_val != NULL );
-               mod->sml_nvalues =
-                       (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
-               ber_dupbv( &mod->sml_nvalues[0], &nname );
-               mod->sml_nvalues[1].bv_len = 0;
-               mod->sml_nvalues[1].bv_val = NULL;
-               assert( mod->sml_nvalues[0].bv_val != NULL );
-               *modtail = mod;
-               modtail = &mod->sml_next;
-
-               mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
-               mod->sml_op = mop;
-               mod->sml_flags = SLAP_MOD_INTERNAL;
-               mod->sml_type.bv_val = NULL;
-               mod->sml_desc = slap_schema.si_ad_modifyTimestamp;
-               mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
-               ber_dupbv( &mod->sml_values[0], &timestamp );
-               mod->sml_values[1].bv_len = 0;
-               mod->sml_values[1].bv_val = NULL;
-               assert( mod->sml_values[0].bv_val != NULL );
-               mod->sml_nvalues = NULL;
-               *modtail = mod;
-               modtail = &mod->sml_next;
-       }
-
        *modtail = NULL;
        return LDAP_SUCCESS;
 }