]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-meta/modify.c
Preliminary ldapAdd support
[openldap] / servers / slapd / back-meta / modify.c
index 556fd98b380b81307cd10eb546f4cbe3ad75958b..e09b9c35666347c744093e4da5a41ad4b6ca7f9c 100644 (file)
@@ -47,22 +47,15 @@ meta_back_modify( Operation *op, SlapReply *rs )
        dncookie        dc;
 
        lc = meta_back_getconn( op, rs, META_OP_REQUIRE_SINGLE,
-                       &op->o_req_ndn, &candidate );
-       if ( !lc ) {
-               rc = -1;
-               goto cleanup;
+                       &op->o_req_ndn, &candidate, LDAP_BACK_SENDERR );
+       if ( !lc || !meta_back_dobind( lc, op, LDAP_BACK_SENDERR ) ) {
+               return rs->sr_err;
        }
        
-       if ( !meta_back_dobind( lc, op ) ) {
-               rs->sr_err = LDAP_UNAVAILABLE;
-
-       } else if ( !meta_back_is_valid( lc, candidate ) ) {
+       if ( !meta_back_is_valid( lc, candidate ) ) {
                rs->sr_err = LDAP_OTHER;
-       }
-
-       if ( rs->sr_err != LDAP_SUCCESS ) {
-               rc = -1;
-               goto cleanup;
+               send_ldap_result( op, rs );
+               return rs->sr_err;
        }
 
        /*
@@ -97,17 +90,25 @@ meta_back_modify( Operation *op, SlapReply *rs )
        dc.ctx = "modifyAttrDN";
        isupdate = be_shadow_update( op );
        for ( i = 0, ml = op->orm_modlist; ml; ml = ml->sml_next ) {
-               int j;
+               int     j, is_oc = 0;
 
                if ( !isupdate && ml->sml_desc->ad_type->sat_no_user_mod  ) {
                        continue;
                }
 
-               ldap_back_map( &li->targets[ candidate ]->mt_rwmap.rwm_at,
-                               &ml->sml_desc->ad_cname, &mapped,
-                               BACKLDAP_MAP );
-               if ( BER_BVISNULL( &mapped ) || mapped.bv_val[0] == '\0' ) {
-                       continue;
+               if ( ml->sml_desc == slap_schema.si_ad_objectClass 
+                               || ml->sml_desc == slap_schema.si_ad_structuralObjectClass )
+               {
+                       is_oc = 1;
+                       mapped = ml->sml_desc->ad_cname;
+
+               } else {
+                       ldap_back_map( &li->targets[ candidate ]->mt_rwmap.rwm_at,
+                                       &ml->sml_desc->ad_cname, &mapped,
+                                       BACKLDAP_MAP );
+                       if ( BER_BVISNULL( &mapped ) || BER_BVISEMPTY( &mapped ) ) {
+                               continue;
+                       }
                }
 
                modv[ i ] = &mods[ i ];
@@ -119,22 +120,52 @@ meta_back_modify( Operation *op, SlapReply *rs )
                 * to allow their use in ACLs at the back-ldap
                 * level.
                 */
-               if ( strcmp( ml->sml_desc->ad_type->sat_syntax->ssyn_oid,
-                                       SLAPD_DN_SYNTAX ) == 0 )
-               {
-                       ( void )ldap_dnattr_rewrite( &dc, ml->sml_values );
-               }
-
                if ( ml->sml_values != NULL ) {
-                       for ( j = 0; ml->sml_values[ j ].bv_val; j++ )
-                               ;
-                       mods[ i ].mod_bvalues =
-                               (struct berval **)ch_malloc( ( j + 1 ) *
-                               sizeof(struct berval *) );
-                       for ( j = 0; ml->sml_values[ j ].bv_val; j++ ) {
-                               mods[ i ].mod_bvalues[ j ] = &ml->sml_values[ j ];
+                       if ( is_oc ) {
+                               for ( j = 0; !BER_BVISNULL( &ml->sml_values[ j ] ); j++ )
+                                       ;
+                               mods[ i ].mod_bvalues =
+                                       (struct berval **)ch_malloc( ( j + 1 ) *
+                                       sizeof( struct berval * ) );
+                               for ( j = 0; !BER_BVISNULL( &ml->sml_values[ j ] ); ) {
+                                       struct ldapmapping      *mapping;
+
+                                       ldap_back_mapping( &li->targets[ candidate ]->mt_rwmap.rwm_oc,
+                                                       &ml->sml_values[ j ], &mapping, BACKLDAP_MAP );
+
+                                       if ( mapping == NULL ) {
+                                               if ( li->targets[ candidate ]->mt_rwmap.rwm_oc.drop_missing ) {
+                                                       continue;
+                                               }
+                                               mods[ i ].mod_bvalues[ j ] = &ml->sml_values[ j ];
+
+                                       } else {
+                                               mods[ i ].mod_bvalues[ j ] = &mapping->dst;
+                                       }
+                                       j++;
+                               }
+                               mods[ i ].mod_bvalues[ j ] = NULL;
+
+                       } else {
+                               if ( ml->sml_desc->ad_type->sat_syntax ==
+                                               slap_schema.si_syn_distinguishedName )
+                               {
+                                       ( void )ldap_dnattr_rewrite( &dc, ml->sml_values );
+                                       if ( ml->sml_values == NULL ) {
+                                               continue;
+                                       }
+                               }
+
+                               for ( j = 0; !BER_BVISNULL( &ml->sml_values[ j ] ); j++ )
+                                       ;
+                               mods[ i ].mod_bvalues =
+                                       (struct berval **)ch_malloc( ( j + 1 ) *
+                                       sizeof( struct berval * ) );
+                               for ( j = 0; !BER_BVISNULL( &ml->sml_values[ j ] ); j++ ) {
+                                       mods[ i ].mod_bvalues[ j ] = &ml->sml_values[ j ];
+                               }
+                               mods[ i ].mod_bvalues[ j ] = NULL;
                        }
-                       mods[ i ].mod_bvalues[ j ] = NULL;
 
                } else {
                        mods[ i ].mod_bvalues = NULL;
@@ -144,8 +175,8 @@ meta_back_modify( Operation *op, SlapReply *rs )
        }
        modv[ i ] = 0;
 
-       rc = ldap_modify_ext_s( lc->mc_conns[ candidate ].msc_ld, mdn.bv_val,
-                       modv, NULL, NULL ) != LDAP_SUCCESS;
+       rs->sr_err = ldap_modify_ext_s( lc->mc_conns[ candidate ].msc_ld, mdn.bv_val,
+                       modv, op->o_ctrls, NULL );
 
 cleanup:;
        if ( mdn.bv_val != op->o_req_dn.bv_val ) {
@@ -159,14 +190,13 @@ cleanup:;
        }
        free( mods );
        free( modv );
-       
-       if ( rc == 0 ) {
-               return meta_back_op_result( lc, op, rs ) == LDAP_SUCCESS
-                       ? 0 : 1;
-       } /* else */
 
+       if ( rc != -1 ) {
+               return meta_back_op_result( lc, op, rs );
+       }
+       
        send_ldap_result( op, rs );
 
-       return rc;
+       return rs->sr_err;
 }