#include "slap.h"
#include "slapi.h"
-#ifdef LDAP_SLAPI
-static LDAPMod **Modifications2LDAPMods (Modifications *modlist);
-static void FreeLDAPMods (LDAPMod **);
-#endif /* LDAP_SLAPI */
-
int
do_modify(
Connection *conn,
mod->sml_type = tmp.sml_type;
mod->sml_bvalues = tmp.sml_bvalues;
mod->sml_desc = NULL;
- mod->sml_next =NULL;
+ mod->sml_next = NULL;
*modtail = mod;
switch( mop ) {
suffix_alias( be, &ndn );
#if defined( LDAP_SLAPI )
- slapi_backend_set_pb( pb, be );
- slapi_connection_set_pb( pb, conn );
- slapi_operation_set_pb( pb, op );
+ slapi_x_backend_set_pb( pb, be );
+ slapi_x_connection_set_pb( pb, conn );
+ slapi_x_operation_set_pb( pb, op );
slapi_pblock_set( pb, SLAPI_MODIFY_TARGET, (void *)dn.bv_val );
slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)(1) );
- modv = Modifications2LDAPMods( modlist );
+ modv = slapi_x_modifications2ldapmods( &modlist );
slapi_pblock_set( pb, SLAPI_MODIFY_MODS, (void *)modv );
rc = doPluginFNs( be, SLAPI_PLUGIN_PRE_MODIFY_FN, pb );
- if ( rc != 0 && rc != LDAP_OTHER ) {
+ if ( rc != 0 ) {
/*
- * either there is no preOp (modify) plugins
- * or a plugin failed. Just log it
- *
- * FIXME: is this correct?
+ * A preoperation plugin failure will abort the
+ * entire operation.
*/
#ifdef NEW_LOGGING
- LDAP_LOG( OPERATION, INFO, "do_modify: modify preOps "
+ LDAP_LOG( OPERATION, INFO, "do_modify: modify preoperation plugin "
"failed\n", 0, 0, 0 );
#else
- Debug(LDAP_DEBUG_TRACE, "do_modify: modify preOps failed.\n",
+ Debug(LDAP_DEBUG_TRACE, "do_modify: modify preoperation plugin failed.\n",
0, 0, 0);
#endif
+ if ( slapi_pblock_get( pb, SLAPI_RESULT_CODE, (void *)&rc ) != 0) {
+ rc = LDAP_OTHER;
+ }
+ ldap_mods_free( modv, 1 );
+ modv = NULL;
+ goto cleanup;
}
+
+ /*
+ * It's possible that the preoperation plugin changed the
+ * modification array, so we need to convert it back to
+ * a Modification list.
+ *
+ * Calling slapi_x_modifications2ldapmods() destroyed modlist so
+ * we don't need to free it.
+ */
+ slapi_pblock_get( pb, SLAPI_MODIFY_MODS, (void **)&modv );
+ modlist = slapi_x_ldapmods2modifications( modv );
#endif /* defined( LDAP_SLAPI ) */
/*
}
#if defined( LDAP_SLAPI )
- rc = doPluginFNs( be, SLAPI_PLUGIN_POST_MODIFY_FN, pb );
- if ( rc != 0 && rc != LDAP_OTHER ) {
- /*
- * either there is no postOp (modify) plugins
- * or a plugin failed. Just log it
- *
- * FIXME: is this correct?
- */
+ if ( doPluginFNs( be, SLAPI_PLUGIN_POST_MODIFY_FN, pb ) != 0 ) {
#ifdef NEW_LOGGING
- LDAP_LOG( OPERATION, INFO, "do_modify: modify postOps "
+ LDAP_LOG( OPERATION, INFO, "do_modify: modify postoperation plugins "
"failed\n", 0, 0, 0 );
#else
- Debug(LDAP_DEBUG_TRACE, "do_modify: modify postOps "
+ Debug(LDAP_DEBUG_TRACE, "do_modify: modify postoperation plugins "
"failed.\n", 0, 0, 0);
#endif
}
cleanup:
free( pdn.bv_val );
free( ndn.bv_val );
- if ( modlist != NULL )
- slap_mods_free( modlist );
- if ( modv != NULL )
- FreeLDAPMods( modv );
+ if ( modlist != NULL ) slap_mods_free( modlist );
+#if defined( LDAP_SLAPI )
+ if ( modv != NULL ) slapi_x_free_ldapmods( modv );
+#endif
return rc;
}
return LDAP_SUCCESS;
}
-#ifdef LDAP_SLAPI
-/*
- * Synthesise an LDAPMod array from a Modifications list to pass
- * to SLAPI.
- */
-static LDAPMod **Modifications2LDAPMods(Modifications *modlist)
-{
- LDAPMod *mods, **modv;
- int i, j;
- Modifications *ml;
-
- /* based on back-ldap/modify.c */
- for( i = 0, ml = modlist; ml != NULL; i++, ml = ml->sml_next )
- ;
-
- mods = (LDAPMod *)ch_malloc( i * sizeof(LDAPMod) );
- if (mods == NULL) {
- return NULL;
- }
-
- modv = (LDAPMod **)ch_malloc( (i + 1) * sizeof(LDAPMod *) );
- if (modv == NULL) {
- ch_free(mods);
- return NULL;
- }
-
- for( i = 0, ml = modlist; ml != NULL; ml = ml->sml_next ) {
- if ( ml->sml_desc->ad_type->sat_no_user_mod ) {
- continue;
- }
- modv[i] = &mods[i];
- mods[i].mod_op = ml->sml_op | LDAP_MOD_BVALUES;
- mods[i].mod_type = ml->sml_desc->ad_cname.bv_val;
- if (ml->sml_bvalues != NULL) {
- for( j = 0; ml->sml_bvalues[j].bv_val != NULL; j++ )
- ;
- mods[i].mod_bvalues = (struct berval **)ch_malloc( (j + 1) *
- sizeof(struct berval *) );
- for( j = 0; ml->sml_bvalues[j].bv_val != NULL; j++ )
- mods[i].mod_bvalues[j] = &ml->sml_bvalues[j];
- } else {
- mods[i].mod_bvalues = NULL;
- }
- i++;
- }
- modv[i] = NULL;
-
- return modv;
-}
-
-/*
- * Free a contiguous block of LDAP modifications.
- */
-static void FreeLDAPMods(LDAPMod **modv)
-{
- int i;
- LDAPMod *mods;
-
- mods = modv[0];
-
- for( i = 0; modv[i] != NULL; i++ ) {
- ch_free( modv[i]->mod_bvalues );
- }
- ch_free( mods );
- ch_free( modv );
-}
-#endif /* LDAP_SLAPI */
-