X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fmodify.c;h=a04d49a61c1708f623768b596cedc9283bd18c73;hb=7c39a5e7269d4bde62555d7c36fc03a02cc9758b;hp=cdac8cae2db2b02f8faf7ab02201f9863d5d7d30;hpb=2fdbc553746c44df7ec15c88b73d608743bfa030;p=openldap diff --git a/servers/slapd/modify.c b/servers/slapd/modify.c index cdac8cae2d..a04d49a61c 100644 --- a/servers/slapd/modify.c +++ b/servers/slapd/modify.c @@ -103,9 +103,7 @@ do_modify( ber_int_t mop; Modifications tmp, *mod; -#ifdef SLAP_NVALUES tmp.sml_nvalues = NULL; -#endif if ( ber_scanf( op->o_ber, "{i{m[W]}}", &mop, &tmp.sml_type, &tmp.sml_values ) @@ -120,9 +118,7 @@ do_modify( mod->sml_op = mop; mod->sml_type = tmp.sml_type; mod->sml_values = tmp.sml_values; -#ifdef SLAP_NVALUES mod->sml_nvalues = NULL; -#endif mod->sml_desc = NULL; mod->sml_next = NULL; *modtail = mod; @@ -181,7 +177,7 @@ do_modify( goto cleanup; } - rs->sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn ); + rs->sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, op->o_tmpmemctx ); if( rs->sr_err != LDAP_SUCCESS ) { #ifdef NEW_LOGGING LDAP_LOG( OPERATION, INFO, "do_modify: conn %d invalid dn (%s)\n", @@ -305,10 +301,15 @@ do_modify( NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT ); if (!rs->sr_ref) rs->sr_ref = default_referral; - rs->sr_err = LDAP_REFERRAL; - send_ldap_result( op, rs ); + if (rs->sr_ref != NULL ) { + rs->sr_err = LDAP_REFERRAL; + send_ldap_result( op, rs ); - if (rs->sr_ref != default_referral) ber_bvarray_free( rs->sr_ref ); + if (rs->sr_ref != default_referral) ber_bvarray_free( rs->sr_ref ); + } else { + send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM, + "referral missing" ); + } goto cleanup; } @@ -331,7 +332,7 @@ do_modify( slapi_pblock_set( pb, SLAPI_MODIFY_MODS, (void *)modv ); rs->sr_err = doPluginFNs( op->o_bd, SLAPI_PLUGIN_PRE_MODIFY_FN, pb ); - if ( rs->sr_err != 0 ) { + if ( rs->sr_err < 0 ) { /* * A preoperation plugin failure will abort the * entire operation. @@ -346,7 +347,7 @@ do_modify( if ( slapi_pblock_get( pb, SLAPI_RESULT_CODE, (void *)&rs->sr_err ) != 0) { rs->sr_err = LDAP_OTHER; } - ldap_mods_free( modv, 1 ); + slapi_x_free_ldapmods( modv ); modv = NULL; goto cleanup; } @@ -361,6 +362,20 @@ do_modify( */ slapi_pblock_get( pb, SLAPI_MODIFY_MODS, (void **)&modv ); modlist = slapi_x_ldapmods2modifications( modv ); + + /* + * NB: it is valid for the plugin to return no modifications + * (for example, a plugin might store some attributes elsewhere + * and remove them from the modification list; if only those + * attribute types were included in the modification request, + * then slapi_x_ldapmods2modifications() above will return + * NULL). + */ + if ( modlist == NULL ) { + rs->sr_err = LDAP_SUCCESS; + send_ldap_result( op, rs ); + goto cleanup; + } #endif /* defined( LDAP_SLAPI ) */ /* @@ -384,7 +399,7 @@ do_modify( size_t textlen = sizeof textbuf; rs->sr_err = slap_mods_check( modlist, update, &rs->sr_text, - textbuf, textlen ); + textbuf, textlen, NULL ); if( rs->sr_err != LDAP_SUCCESS ) { send_ldap_result( op, rs ); @@ -407,7 +422,7 @@ do_modify( } } - op->oq_modify.rs_modlist = modlist; + op->orm_modlist = modlist; if ( (op->o_bd->be_modify)( op, rs ) == 0 #ifdef SLAPD_MULTIMASTER && !repl_user @@ -422,13 +437,21 @@ do_modify( } else { BerVarray defref = op->o_bd->be_update_refs ? op->o_bd->be_update_refs : default_referral; - rs->sr_ref = referral_rewrite( defref, - NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT ); - - if (!rs->sr_ref) rs->sr_ref = defref; - rs->sr_err = LDAP_REFERRAL; - send_ldap_result( op, rs ); - if (rs->sr_ref != defref) ber_bvarray_free( rs->sr_ref ); + if ( defref != NULL ) { + rs->sr_ref = referral_rewrite( defref, + NULL, &op->o_req_dn, + LDAP_SCOPE_DEFAULT ); + if (!rs->sr_ref) rs->sr_ref = defref; + rs->sr_err = LDAP_REFERRAL; + send_ldap_result( op, rs ); + if (rs->sr_ref != defref) { + ber_bvarray_free( rs->sr_ref ); + } + } else { + send_ldap_error( op, rs, + LDAP_UNWILLING_TO_PERFORM, + "referral missing" ); + } #endif } } else { @@ -437,7 +460,7 @@ do_modify( } #if defined( LDAP_SLAPI ) - if ( doPluginFNs( op->o_bd, SLAPI_PLUGIN_POST_MODIFY_FN, pb ) != 0 ) { + if ( doPluginFNs( op->o_bd, SLAPI_PLUGIN_POST_MODIFY_FN, pb ) < 0 ) { #ifdef NEW_LOGGING LDAP_LOG( OPERATION, INFO, "do_modify: modify postoperation plugins " "failed\n", 0, 0, 0 ); @@ -449,8 +472,8 @@ do_modify( #endif /* defined( LDAP_SLAPI ) */ cleanup: - free( op->o_req_dn.bv_val ); - free( op->o_req_ndn.bv_val ); + op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx ); + op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx ); if ( modlist != NULL ) slap_mods_free( modlist ); #if defined( LDAP_SLAPI ) if ( modv != NULL ) slapi_x_free_ldapmods( modv ); @@ -466,7 +489,8 @@ int slap_mods_check( int update, const char **text, char *textbuf, - size_t textlen ) + size_t textlen, + void *ctx ) { int rc; @@ -567,7 +591,7 @@ int slap_mods_check( struct berval pval; if( pretty ) { rc = pretty( ad->ad_type->sat_syntax, - &ml->sml_values[nvals], &pval ); + &ml->sml_values[nvals], &pval, ctx ); } else { rc = validate( ad->ad_type->sat_syntax, &ml->sml_values[nvals] ); @@ -582,7 +606,7 @@ int slap_mods_check( } if( pretty ) { - ber_memfree( ml->sml_values[nvals].bv_val ); + ber_memfree_x( ml->sml_values[nvals].bv_val, ctx ); ml->sml_values[nvals] = pval; } } @@ -601,17 +625,16 @@ int slap_mods_check( return LDAP_CONSTRAINT_VIOLATION; } -#ifdef SLAP_NVALUES if( nvals && ad->ad_type->sat_equality && ad->ad_type->sat_equality->smr_normalize ) { - ml->sml_nvalues = ch_malloc( (nvals+1)*sizeof(struct berval) ); + ml->sml_nvalues = ber_memalloc_x( (nvals+1)*sizeof(struct berval), ctx ); for( nvals = 0; ml->sml_values[nvals].bv_val; nvals++ ) { rc = ad->ad_type->sat_equality->smr_normalize( 0, ad->ad_type->sat_syntax, ad->ad_type->sat_equality, - &ml->sml_values[nvals], &ml->sml_nvalues[nvals] ); + &ml->sml_values[nvals], &ml->sml_nvalues[nvals], ctx ); if( rc ) { #ifdef NEW_LOGGING LDAP_LOG( OPERATION, DETAIL1, @@ -632,7 +655,6 @@ int slap_mods_check( ml->sml_nvalues[nvals].bv_val = NULL; ml->sml_nvalues[nvals].bv_len = 0; } -#endif } } @@ -647,9 +669,7 @@ int slap_mods_opattrs( char *textbuf, size_t textlen ) { struct berval name, timestamp, csn; -#ifdef SLAP_NVALUES struct berval nname; -#endif char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ]; char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ]; Modifications *mod; @@ -678,14 +698,10 @@ int slap_mods_opattrs( if( op->o_dn.bv_len == 0 ) { name.bv_val = SLAPD_ANONYMOUS; name.bv_len = sizeof(SLAPD_ANONYMOUS)-1; -#ifdef SLAP_NVALUES nname = name; -#endif } else { name = op->o_dn; -#ifdef SLAP_NVALUES nname = op->o_ndn; -#endif } } @@ -709,14 +725,12 @@ int slap_mods_opattrs( mod->sml_values[1].bv_len = 0; mod->sml_values[1].bv_val = NULL; assert( mod->sml_values[0].bv_val ); -#ifdef SLAP_NVALUES 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 ); -#endif *modtail = mod; modtail = &mod->sml_next; } @@ -737,9 +751,7 @@ int slap_mods_opattrs( mod->sml_values[1].bv_len = 0; mod->sml_values[1].bv_val = NULL; assert( mod->sml_values[0].bv_val ); -#ifdef SLAP_NVALUES mod->sml_nvalues = NULL; -#endif *modtail = mod; modtail = &mod->sml_next; @@ -752,14 +764,12 @@ int slap_mods_opattrs( mod->sml_values[1].bv_len = 0; mod->sml_values[1].bv_val = NULL; assert( mod->sml_values[0].bv_val ); -#ifdef SLAP_NVALUES 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 ); -#endif *modtail = mod; modtail = &mod->sml_next; @@ -772,9 +782,7 @@ int slap_mods_opattrs( mod->sml_values[1].bv_len = 0; mod->sml_values[1].bv_val = NULL; assert( mod->sml_values[0].bv_val ); -#ifdef SLAP_NVALUES mod->sml_nvalues = NULL; -#endif *modtail = mod; modtail = &mod->sml_next; } @@ -790,9 +798,7 @@ int slap_mods_opattrs( mod->sml_values[1].bv_len = 0; mod->sml_values[1].bv_val = NULL; assert( mod->sml_values[0].bv_val ); -#ifdef SLAP_NVALUES mod->sml_nvalues = NULL; -#endif *modtail = mod; modtail = &mod->sml_next; @@ -805,14 +811,12 @@ int slap_mods_opattrs( mod->sml_values[1].bv_len = 0; mod->sml_values[1].bv_val = NULL; assert( mod->sml_values[0].bv_val ); -#ifdef SLAP_NVALUES 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 ); -#endif *modtail = mod; modtail = &mod->sml_next; @@ -825,9 +829,7 @@ int slap_mods_opattrs( mod->sml_values[1].bv_len = 0; mod->sml_values[1].bv_val = NULL; assert( mod->sml_values[0].bv_val ); -#ifdef SLAP_NVALUES mod->sml_nvalues = NULL; -#endif *modtail = mod; modtail = &mod->sml_next; }