+
+int
+slap_entry2mods(
+ Entry *e,
+ Modifications **mods,
+ const char **text,
+ char *textbuf, size_t textlen )
+{
+ Modifications *modhead = NULL;
+ Modifications *mod;
+ Modifications **modtail = &modhead;
+ Attribute *a_new;
+ AttributeDescription *a_new_desc;
+ int i, count;
+
+ a_new = e->e_attrs;
+
+ while ( a_new != NULL ) {
+ a_new_desc = a_new->a_desc;
+ mod = (Modifications *) malloc( sizeof( Modifications ));
+
+ mod->sml_op = LDAP_MOD_REPLACE;
+
+ mod->sml_type = a_new_desc->ad_cname;
+
+ for ( count = 0; a_new->a_vals[count].bv_val; count++ ) /* EMPTY */;
+
+ mod->sml_values = (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_values+i, a_new->a_vals+i);
+ if ( mod->sml_nvalues ) {
+ ber_dupbv( mod->sml_nvalues+i, a_new->a_nvals+i );
+ }
+ }
+
+ mod->sml_values[count].bv_val = NULL;
+ mod->sml_values[count].bv_len = 0;
+
+ if ( mod->sml_nvalues ) {
+ mod->sml_nvalues[count].bv_val = NULL;
+ 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 init_add_pblock( Operation *op,
+ struct berval *dn, Entry *e, int manageDSAit )
+{
+ slapi_int_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 call_add_preop_plugins( Operation *op )
+{
+ int rc;
+
+ rc = slapi_int_call_plugins( 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);
+#endif
+
+ if (( slapi_pblock_get( op->o_pb, SLAPI_RESULT_CODE,
+ (void *)&rc ) != 0 ) || rc == LDAP_SUCCESS )
+ {
+ rc = LDAP_OTHER;
+ }
+ } else {
+ rc = LDAP_SUCCESS;
+ }
+
+ return rc;
+}
+
+static void call_add_postop_plugins( Operation *op )
+{
+ int rc;
+
+ rc = slapi_int_call_plugins( 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 */