+
+int
+slap_entry2mods(
+ Entry *e,
+ Modifications **mods,
+ const char **text
+)
+{
+ Modifications *modhead = NULL;
+ Modifications *mod;
+ Modifications **modtail = &modhead;
+ Attribute *a_new;
+ AttributeDescription *a_new_desc;
+ int i, count, rc;
+
+ a_new = e->e_attrs;
+
+ while ( a_new != NULL ) {
+ a_new_desc = a_new->a_desc;
+ mod = (Modifications *) malloc( sizeof( Modifications ));
+
+ if ( a_new_desc != slap_schema.si_ad_queryid )
+ mod->sml_op = LDAP_MOD_REPLACE;
+ else
+ mod->sml_op = LDAP_MOD_ADD;
+
+ ber_dupbv( &mod->sml_type, &a_new_desc->ad_cname );
+
+ for ( count = 0; a_new->a_vals[count].bv_val; count++ );
+
+ mod->sml_bvalues = (struct berval*) malloc(
+ (count+1) * sizeof( struct berval) );
+
+ /* see slap_mods_check() comments...
+ * if a_vals == a_nvals, there is no normalizer.
+ * in this case, mod->sml_nvalues must be left NULL.
+ */
+ if ( a_new->a_vals != a_new->a_nvals ) {
+ mod->sml_nvalues = (struct berval*) malloc(
+ (count+1) * sizeof( struct berval) );
+ } else {
+ mod->sml_nvalues = NULL;
+ }
+
+ for ( i = 0; i < count; i++ ) {
+ ber_dupbv(mod->sml_bvalues+i, a_new->a_vals+i);
+ if ( mod->sml_nvalues ) {
+ ber_dupbv( mod->sml_nvalues+i, a_new->a_vals+i );
+ }
+ }
+
+ mod->sml_bvalues[count].bv_val = 0;
+ mod->sml_bvalues[count].bv_len = 0;
+
+ if ( mod->sml_nvalues ) {
+ mod->sml_nvalues[count].bv_val = 0;
+ mod->sml_nvalues[count].bv_len = 0;
+ }
+
+ mod->sml_desc = a_new_desc;
+ mod->sml_next =NULL;
+ *modtail = mod;
+ modtail = &mod->sml_next;
+ a_new = a_new->a_next;
+ }
+
+ *mods = modhead;
+
+ return LDAP_SUCCESS;
+}
+
+#ifdef LDAP_SLAPI
+static void initAddPlugin( Operation *op,
+ struct berval *dn, Entry *e, int manageDSAit )
+{
+ slapi_x_pblock_set_operation( op->o_pb, op );
+ slapi_pblock_set( op->o_pb, SLAPI_ADD_TARGET, (void *)dn->bv_val );
+ slapi_pblock_set( op->o_pb, SLAPI_ADD_ENTRY, (void *)e );
+ slapi_pblock_set( op->o_pb, SLAPI_MANAGEDSAIT, (void *)manageDSAit );
+}
+
+static int doPreAddPluginFNs( Operation *op )
+{
+ int rc;
+
+ rc = doPluginFNs( op->o_bd, SLAPI_PLUGIN_PRE_ADD_FN, op->o_pb );
+ if ( rc < 0 ) {
+ /*
+ * A preoperation plugin failure will abort the
+ * entire operation.
+ */
+#ifdef NEW_LOGGING
+ LDAP_LOG( OPERATION, INFO, "do_add: add preoperation plugin failed\n",
+ 0, 0, 0);
+#else
+ Debug(LDAP_DEBUG_TRACE, "do_add: add preoperation plugin failed.\n",
+ 0, 0, 0);
+ if ( ( slapi_pblock_get( op->o_pb, SLAPI_RESULT_CODE, (void *)&rc ) != 0 ) ||
+ rc == LDAP_SUCCESS ) {
+ rc = LDAP_OTHER;
+ }
+#endif
+ } else {
+ rc = LDAP_SUCCESS;
+ }
+
+ return rc;
+}
+
+static void doPostAddPluginFNs( Operation *op )
+{
+ int rc;
+
+ rc = doPluginFNs( op->o_bd, SLAPI_PLUGIN_POST_ADD_FN, op->o_pb );
+ if ( rc < 0 ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG( OPERATION, INFO, "do_add: add postoperation plugin failed\n",
+ 0, 0, 0);
+#else
+ Debug(LDAP_DEBUG_TRACE, "do_add: add postoperation plugin failed.\n",
+ 0, 0, 0);
+#endif
+ }
+}
+#endif /* LDAP_SLAPI */