]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/modify.c
#include <ac/string.h> to get strcasecmp().
[openldap] / servers / slapd / modify.c
index d28b85e3c27f1e23bbb47d82c2b3496ae3ea5194..1405ca9c7201c0d5aca34333748160195efa7ff7 100644 (file)
@@ -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;
@@ -154,7 +150,8 @@ do_modify(
                default: {
 #ifdef NEW_LOGGING
                                LDAP_LOG( OPERATION, ERR, 
-                                       "do_modify: invalid modify operation (%ld)\n", (long)mop, 0, 0 );
+                                       "do_modify: invalid modify operation (%ld)\n",
+                                       (long)mop, 0, 0 );
 #else
                                Debug( LDAP_DEBUG_ANY,
                                        "do_modify: invalid modify operation (%ld)\n",
@@ -181,7 +178,8 @@ 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",
@@ -300,15 +298,21 @@ do_modify(
         * appropriate one, or send a referral to our "referral server"
         * if we don't hold it.
         */
-       if ( (op->o_bd = select_backend( &op->o_req_ndn, manageDSAit, 0 )) == NULL ) {
+       op->o_bd = select_backend( &op->o_req_ndn, manageDSAit, 0 );
+       if ( op->o_bd == NULL ) {
                rs->sr_ref = referral_rewrite( default_referral,
                        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;
        }
 
@@ -324,16 +328,14 @@ do_modify(
        }
 
 #if defined( LDAP_SLAPI )
-       slapi_x_backend_set_pb( pb, be );
-       slapi_x_connection_set_pb( pb, conn );
-       slapi_x_operation_set_pb( pb, op );
+       slapi_x_pblock_set_operation( pb, op );
        slapi_pblock_set( pb, SLAPI_MODIFY_TARGET, (void *)dn.bv_val );
        slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)manageDSAit );
        modv = slapi_x_modifications2ldapmods( &modlist );
        slapi_pblock_set( pb, SLAPI_MODIFY_MODS, (void *)modv );
 
-       rs->sr_err = doPluginFNs( be, SLAPI_PLUGIN_PRE_MODIFY_FN, pb );
-       if ( rs->sr_err != 0 ) {
+       rs->sr_err = doPluginFNs( op->o_bd, SLAPI_PLUGIN_PRE_MODIFY_FN, pb );
+       if ( rs->sr_err < 0 ) {
                /*
                 * A preoperation plugin failure will abort the
                 * entire operation.
@@ -345,10 +347,11 @@ do_modify(
                Debug(LDAP_DEBUG_TRACE, "do_modify: modify preoperation plugin failed.\n",
                                0, 0, 0);
 #endif
-               if ( slapi_pblock_get( pb, SLAPI_RESULT_CODE, (void *)&rs->sr_err ) != 0) {
+               if ( ( slapi_pblock_get( op->o_pb, SLAPI_RESULT_CODE, (void *)&rs->sr_err ) != 0 )  ||
+                    rs->sr_err == LDAP_SUCCESS ) {
                        rs->sr_err = LDAP_OTHER;
                }
-               ldap_mods_free( modv, 1 );
+               slapi_x_free_ldapmods( modv );
                modv = NULL;
                goto cleanup;
        }
@@ -363,6 +366,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 ) */
 
        /*
@@ -374,10 +391,16 @@ do_modify(
        if ( op->o_bd->be_modify ) {
                /* do the update here */
                int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
-#ifndef SLAPD_MULTIMASTER
+
                /* Multimaster slapd does not have to check for replicator dn
                 * because it accepts each modify request
                 */
+#if defined(LDAP_SYNCREPL) && !defined(SLAPD_MULTIMASTER)
+               if ( !op->o_bd->syncinfo &&
+                               ( !op->o_bd->be_update_ndn.bv_len || repl_user ))
+#elif defined(LDAP_SYNCREPL) && defined(SLAPD_MULTIMASTER)
+               if ( !op->o_bd->syncinfo )  /* LDAP_SYNCREPL overrides MM */
+#elif !defined(LDAP_SYNCREPL) && !defined(SLAPD_MULTIMASTER)
                if ( !op->o_bd->be_update_ndn.bv_len || repl_user )
 #endif
                {
@@ -386,7 +409,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 );
@@ -409,7 +432,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
@@ -419,18 +442,34 @@ do_modify(
                                replog( op );
                        }
 
-#ifndef SLAPD_MULTIMASTER
+#if defined(LDAP_SYNCREPL) || !defined(SLAPD_MULTIMASTER)
                /* send a referral */
                } 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 );
+                       BerVarray defref = NULL;
+#ifdef LDAP_SYNCREPL
+                       if ( op->o_bd->syncinfo ) {
+                               defref = op->o_bd->syncinfo->master_bv;
+                       } else
+#endif
+                       {
+                               defref = op->o_bd->be_update_refs
+                                               ? op->o_bd->be_update_refs : default_referral;
+                       }
+                       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 {
@@ -439,7 +478,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 );
@@ -451,8 +490,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 );
@@ -468,7 +507,8 @@ int slap_mods_check(
        int update,
        const char **text,
        char *textbuf,
-       size_t textlen )
+       size_t textlen,
+       void *ctx )
 {
        int rc;
 
@@ -569,7 +609,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] );
@@ -584,7 +624,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;
                                }
                        }
@@ -603,17 +643,18 @@ 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,
@@ -631,10 +672,12 @@ int slap_mods_check(
                                                return rc;
                                        }
                                }
+
                                ml->sml_nvalues[nvals].bv_val = NULL;
                                ml->sml_nvalues[nvals].bv_len = 0;
+
+                       } else {
                        }
-#endif
                }
        }
 
@@ -649,9 +692,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;
@@ -680,14 +721,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
                }
        }
 
@@ -711,14 +748,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;
                }
@@ -739,9 +774,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;
 
@@ -754,14 +787,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;
 
@@ -774,9 +805,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;
                }
@@ -792,9 +821,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;
 
@@ -807,14 +834,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;
 
@@ -827,9 +852,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;
        }