]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/add.c
Fix ITS#3424
[openldap] / servers / slapd / add.c
index 9b4734ed9cdc5c3a61e5ba9698400432ed4a7729..4b392247836ca4f5a5e3a283bef7c81b42a7ec23 100644 (file)
@@ -30,7 +30,6 @@
 #include <ac/time.h>
 #include <ac/socket.h>
 
-#include "ldap_pvt.h"
 #include "slap.h"
 
 #ifdef LDAP_SLAPI
@@ -47,20 +46,15 @@ do_add( Operation *op, SlapReply *rs )
 {
        BerElement      *ber = op->o_ber;
        char            *last;
-       struct berval dn = BER_BVNULL;
+       struct berval   dn = BER_BVNULL;
        ber_len_t       len;
        ber_tag_t       tag;
        Entry           *e;
        Modifications   *modlist = NULL;
        Modifications   **modtail = &modlist;
        Modifications   tmp;
-       int     manageDSAit;
 
-#ifdef NEW_LOGGING
-       LDAP_LOG( OPERATION, ENTRY, "do_add: conn %d enter\n", op->o_connid,0,0 );
-#else
        Debug( LDAP_DEBUG_TRACE, "do_add\n", 0, 0, 0 );
-#endif
        /*
         * Parse the add request.  It looks like this:
         *
@@ -75,12 +69,7 @@ do_add( Operation *op, SlapReply *rs )
 
        /* get the name */
        if ( ber_scanf( ber, "{m", /*}*/ &dn ) == LBER_ERROR ) {
-#ifdef NEW_LOGGING
-               LDAP_LOG( OPERATION, ERR, 
-                       "do_add: conn %d ber_scanf failed\n", op->o_connid,0,0 );
-#else
                Debug( LDAP_DEBUG_ANY, "do_add: ber_scanf failed\n", 0, 0, 0 );
-#endif
                send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" );
                return SLAPD_DISCONNECT;
        }
@@ -91,12 +80,7 @@ do_add( Operation *op, SlapReply *rs )
                op->o_tmpmemctx );
 
        if( rs->sr_err != LDAP_SUCCESS ) {
-#ifdef NEW_LOGGING
-               LDAP_LOG( OPERATION, ERR, 
-                       "do_add: conn %d invalid dn (%s)\n", op->o_connid, dn.bv_val, 0 );
-#else
                Debug( LDAP_DEBUG_ANY, "do_add: invalid dn (%s)\n", dn.bv_val, 0, 0 );
-#endif
                send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX, "invalid DN" );
                goto done;
        }
@@ -104,12 +88,7 @@ do_add( Operation *op, SlapReply *rs )
        ber_dupbv( &e->e_name, &op->o_req_dn );
        ber_dupbv( &e->e_nname, &op->o_req_ndn );
 
-#ifdef NEW_LOGGING
-       LDAP_LOG( OPERATION, ARGS, 
-               "do_add: conn %d  dn (%s)\n", op->o_connid, e->e_dn, 0 );
-#else
        Debug( LDAP_DEBUG_ARGS, "do_add: dn (%s)\n", e->e_dn, 0, 0 );
-#endif
 
        /* get the attrs */
        for ( tag = ber_first_element( ber, &len, &last ); tag != LBER_DEFAULT;
@@ -123,26 +102,15 @@ do_add( Operation *op, SlapReply *rs )
                rtag = ber_scanf( ber, "{m{W}}", &tmp.sml_type, &tmp.sml_values );
 
                if ( rtag == LBER_ERROR ) {
-#ifdef NEW_LOGGING
-                       LDAP_LOG( OPERATION, ERR, 
-                                  "do_add: conn %d      decoding error \n", op->o_connid, 0, 0 );
-#else
                        Debug( LDAP_DEBUG_ANY, "do_add: decoding error\n", 0, 0, 0 );
-#endif
                        send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" );
                        rs->sr_err = SLAPD_DISCONNECT;
                        goto done;
                }
 
                if ( tmp.sml_values == NULL ) {
-#ifdef NEW_LOGGING
-                       LDAP_LOG( OPERATION, INFO, 
-                               "do_add: conn %d         no values for type %s\n",
-                               op->o_connid, tmp.sml_type.bv_val, 0 );
-#else
                        Debug( LDAP_DEBUG_ANY, "no values for type %s\n",
                                tmp.sml_type.bv_val, 0, 0 );
-#endif
                        send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
                                "no values for attribute type" );
                        goto done;
@@ -161,24 +129,14 @@ do_add( Operation *op, SlapReply *rs )
        }
 
        if ( ber_scanf( ber, /*{*/ "}") == LBER_ERROR ) {
-#ifdef NEW_LOGGING
-               LDAP_LOG( OPERATION, ERR, 
-                       "do_add: conn %d ber_scanf failed\n", op->o_connid, 0, 0 );
-#else
                Debug( LDAP_DEBUG_ANY, "do_add: ber_scanf failed\n", 0, 0, 0 );
-#endif
                send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" );
                rs->sr_err = SLAPD_DISCONNECT;
                goto done;
        }
 
        if( get_ctrls( op, rs, 1 ) != LDAP_SUCCESS ) {
-#ifdef NEW_LOGGING
-               LDAP_LOG( OPERATION, INFO, 
-                       "do_add: conn %d get_ctrls failed\n", op->o_connid, 0, 0 );
-#else
                Debug( LDAP_DEBUG_ANY, "do_add: get_ctrls failed\n", 0, 0, 0 );
-#endif
                goto done;
        } 
 
@@ -188,8 +146,8 @@ do_add( Operation *op, SlapReply *rs )
                goto done;
        }
 
-       Statslog( LDAP_DEBUG_STATS, "conn=%lu op=%lu ADD dn=\"%s\"\n",
-           op->o_connid, op->o_opid, e->e_name.bv_val, 0, 0 );
+       Statslog( LDAP_DEBUG_STATS, "%s ADD dn=\"%s\"\n",
+           op->o_log_prefix, e->e_name.bv_val, 0, 0, 0 );
 
        if( e->e_nname.bv_len == 0 ) {
                /* protocolError may be a more appropriate error */
@@ -197,12 +155,45 @@ do_add( Operation *op, SlapReply *rs )
                        "root DSE already exists" );
                goto done;
 
-       } else if ( bvmatch( &e->e_nname, &global_schemandn ) ) {
+       } else if ( bvmatch( &e->e_nname, &frontendDB->be_schemandn ) ) {
                send_ldap_error( op, rs, LDAP_ALREADY_EXISTS,
                        "subschema subentry already exists" );
                goto done;
        }
 
+       /* temporary; remove if not invoking backend function */
+       op->ora_e = e;
+       op->ora_modlist = modlist;
+
+       op->o_bd = frontendDB;
+       rs->sr_err = frontendDB->be_add( op, rs );
+       if ( rs->sr_err == 0 ) {
+               e = NULL;
+       }
+
+done:;
+       slap_graduate_commit_csn( op );
+
+       if( modlist != NULL ) {
+               slap_mods_free( modlist );
+       }
+       if( e != NULL ) {
+               entry_free( e );
+       }
+       op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
+       op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
+
+       return rs->sr_err;
+}
+
+int
+fe_op_add( Operation *op, SlapReply *rs )
+{
+       int             manageDSAit;
+       Entry           *e = op->ora_e;
+       Modifications   *modlist = op->ora_modlist;
+       Modifications   **modtail = &modlist;
+
        manageDSAit = get_manageDSAit( op );
 
        /*
@@ -210,7 +201,7 @@ do_add( Operation *op, SlapReply *rs )
         * appropriate one, or send a referral to our "referral server"
         * if we don't hold it.
         */
-       op->o_bd = select_backend( &e->e_nname, manageDSAit, 0 );
+       op->o_bd = select_backend( &e->e_nname, manageDSAit, 1 );
        if ( op->o_bd == NULL ) {
                rs->sr_ref = referral_rewrite( default_referral,
                        NULL, &e->e_name, LDAP_SCOPE_DEFAULT );
@@ -241,7 +232,7 @@ do_add( Operation *op, SlapReply *rs )
        }
 
 #ifdef LDAP_SLAPI
-       if ( op->o_pb ) init_add_pblock( op, &dn, e, manageDSAit );
+       if ( op->o_pb ) init_add_pblock( op, &op->o_req_dn, e, manageDSAit );
 #endif /* LDAP_SLAPI */
 
        /*
@@ -279,7 +270,7 @@ do_add( Operation *op, SlapReply *rs )
                                        assert( (*modtail)->sml_desc != NULL );
                                }
                                rs->sr_err = slap_mods_opattrs( op, modlist, modtail,
-                                       &rs->sr_text, textbuf, textlen );
+                                       &rs->sr_text, textbuf, textlen, 1 );
                                if( rs->sr_err != LDAP_SUCCESS ) {
                                        send_ldap_result( op, rs );
                                        goto done;
@@ -319,6 +310,7 @@ do_add( Operation *op, SlapReply *rs )
                                be_entry_release_w( op, e );
                                e = NULL;
                        }
+                       op->ora_e = NULL;
 
 #ifndef SLAPD_MULTIMASTER
                } else {
@@ -368,12 +360,7 @@ do_add( Operation *op, SlapReply *rs )
                        }
                }
 #endif
-#ifdef NEW_LOGGING
-           LDAP_LOG( OPERATION, INFO, 
-                      "do_add: conn %d  no backend support\n", op->o_connid, 0, 0 );
-#else
            Debug( LDAP_DEBUG_ARGS, "    do_add: no backend support\n", 0, 0, 0 );
-#endif
            send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
                        "operation not supported within namingContext" );
        }
@@ -382,19 +369,7 @@ do_add( Operation *op, SlapReply *rs )
        if ( op->o_pb ) call_add_postop_plugins( op );
 #endif /* LDAP_SLAPI */
 
-done:
-
-       slap_graduate_commit_csn( op );
-
-       if( modlist != NULL ) {
-               slap_mods_free( modlist );
-       }
-       if( e != NULL ) {
-               entry_free( e );
-       }
-       op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
-       op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
-
+done:;
        return rs->sr_err;
 }
 
@@ -447,24 +422,32 @@ slap_mods2entry(
 
                        /* should check for duplicates */
 
-                       AC_MEMCPY( &attr->a_vals[i], mods->sml_values,
-                               sizeof( struct berval ) * j );
-
-                       /* trim the mods array */
-                       ch_free( mods->sml_values );
-                       mods->sml_values = NULL;
+                       if ( dup ) {
+                               for ( j = 0; mods->sml_values[j].bv_val; j++ ) {
+                                       ber_dupbv( &attr->a_vals[i+j], &mods->sml_values[j] );
+                               }
+                               BER_BVZERO( &attr->a_vals[i+j] );       
+                       } else {
+                               AC_MEMCPY( &attr->a_vals[i], mods->sml_values,
+                                       sizeof( struct berval ) * j );
+                               ch_free( mods->sml_values );
+                               mods->sml_values = NULL;
+                       }
 
                        if( mods->sml_nvalues ) {
                                attr->a_nvals = ch_realloc( attr->a_nvals,
                                        sizeof( struct berval ) * (i+j) );
-
-                               AC_MEMCPY( &attr->a_nvals[i], mods->sml_nvalues,
-                                       sizeof( struct berval ) * j );
-
-                               /* trim the mods array */
-                               ch_free( mods->sml_nvalues );
-                               mods->sml_nvalues = NULL;
-
+                               if ( dup ) {
+                                       for ( j = 0; mods->sml_nvalues[j].bv_val; j++ ) {
+                                               ber_dupbv( &attr->a_nvals[i+j], &mods->sml_nvalues[j] );
+                                       }
+                                       BER_BVZERO( &attr->a_nvals[i+j] );      
+                               } else {
+                                       AC_MEMCPY( &attr->a_nvals[i], mods->sml_nvalues,
+                                               sizeof( struct berval ) * j );
+                                       ch_free( mods->sml_nvalues );
+                                       mods->sml_nvalues = NULL;
+                               }
                        } else {
                                attr->a_nvals = attr->a_vals;
                        }
@@ -550,8 +533,7 @@ slap_mods2entry(
                        for ( i = 0; mods->sml_values[i].bv_val; i++ ) {
                                ber_dupbv( &attr->a_vals[i], &mods->sml_values[i] );
                        }
-                       attr->a_vals[i].bv_len = 0;
-                       attr->a_vals[i].bv_val = NULL;
+                       BER_BVZERO( &attr->a_vals[i] );
                } else {
                        attr->a_vals = mods->sml_values;
                        mods->sml_values = NULL;
@@ -565,8 +547,7 @@ slap_mods2entry(
                                for ( i = 0; mods->sml_nvalues[i].bv_val; i++ ) {
                                        ber_dupbv( &attr->a_nvals[i], &mods->sml_nvalues[i] );
                                }
-                               attr->a_nvals[i].bv_len = 0;
-                               attr->a_nvals[i].bv_val = NULL;
+                               BER_BVZERO( &attr->a_nvals[i] );
                        } else {
                                attr->a_nvals = mods->sml_nvalues;
                                mods->sml_nvalues = NULL;
@@ -669,15 +650,9 @@ static int call_add_preop_plugins( Operation *op )
                 * 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 )
@@ -697,15 +672,9 @@ static void call_add_postop_plugins( Operation *op )
 
        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 */