]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/modify.c
ITS#2368 - fix deleting key from range IDL
[openldap] / servers / slapd / modify.c
index c3a2763d965dbe4c21cb710d8a7d592ecd5fc654..1d3c7b325ff97b4b7e77bd46dcfd3a418d15838b 100644 (file)
 #include <ac/string.h>
 #include <ac/time.h>
 
-#include "lutil.h"
-
 #include "ldap_pvt.h"
 #include "slap.h"
 #ifdef LDAP_SLAPI
 #include "slapi.h"
 #endif
+#include "lutil.h"
+
 
 int
 do_modify(
@@ -276,7 +276,6 @@ do_modify(
                }
 #endif
        }
-#endif
 
        if ( StatslogTest( LDAP_DEBUG_STATS ) ) {
                char abuf[BUFSIZ/2], *ptr = abuf;
@@ -304,6 +303,7 @@ do_modify(
                                op->o_connid, op->o_opid, abuf, 0, 0 );
                }
        }
+#endif /* LDAP_DEBUG */
 
        manageDSAit = get_manageDSAit( op );
 
@@ -562,7 +562,7 @@ int slap_mods_check(
                /*
                 * check values
                 */
-               if( ml->sml_bvalues != NULL ) {
+               if( ml->sml_values != NULL ) {
                        ber_len_t nvals;
                        slap_syntax_validate_func *validate =
                                ad->ad_type->sat_syntax->ssyn_validate;
@@ -583,14 +583,14 @@ int slap_mods_check(
                         * check that each value is valid per syntax
                         *      and pretty if appropriate
                         */
-                       for( nvals = 0; ml->sml_bvalues[nvals].bv_val; nvals++ ) {
+                       for( nvals = 0; ml->sml_values[nvals].bv_val; nvals++ ) {
                                struct berval pval;
                                if( pretty ) {
                                        rc = pretty( ad->ad_type->sat_syntax,
-                                               &ml->sml_bvalues[nvals], &pval );
+                                               &ml->sml_values[nvals], &pval );
                                } else {
                                        rc = validate( ad->ad_type->sat_syntax,
-                                               &ml->sml_bvalues[nvals] );
+                                               &ml->sml_values[nvals] );
                                }
 
                                if( rc != 0 ) {
@@ -602,8 +602,8 @@ int slap_mods_check(
                                }
 
                                if( pretty ) {
-                                       ber_memfree( ml->sml_bvalues[nvals].bv_val );
-                                       ml->sml_bvalues[nvals] = pval;
+                                       ber_memfree( ml->sml_values[nvals].bv_val );
+                                       ml->sml_values[nvals] = pval;
                                }
                        }
 
@@ -611,15 +611,48 @@ int slap_mods_check(
                         * a rough single value check... an additional check is needed
                         * to catch add of single value to existing single valued attribute
                         */
-                       if( ( ml->sml_op == LDAP_MOD_ADD || ml->sml_op == LDAP_MOD_REPLACE )
+                       if ((ml->sml_op == LDAP_MOD_ADD || ml->sml_op == LDAP_MOD_REPLACE)
                                && nvals > 1 && is_at_single_value( ad->ad_type ))
                        {
                                snprintf( textbuf, textlen,
-                                       "%s: multiple value provided",
+                                       "%s: multiple values provided",
                                        ml->sml_type.bv_val );
                                *text = textbuf;
                                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) );
+                               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] );
+                                       if( rc ) {
+#ifdef NEW_LOGGING
+                                               LDAP_LOG( OPERATION, DETAIL1,
+                                                       "str2entry:  NULL (ssyn_normalize %d)\n",
+                                                       rc, 0, 0 );
+#else
+                                               Debug( LDAP_DEBUG_ANY,
+                                                       "<= str2entry NULL (ssyn_normalize %d)\n",
+                                                       rc, 0, 0 );
+#endif
+                                               snprintf( textbuf, textlen,
+                                                       "%s: value #%ld normalization failed",
+                                                       ml->sml_type.bv_val, (long) nvals );
+                                               *text = textbuf;
+                                               return rc;
+                                       }
+                               }
+                               ml->sml_nvalues[nvals].bv_val = NULL;
+                               ml->sml_nvalues[nvals].bv_len = 0;
+                       }
+#endif
                }
        }
 
@@ -635,6 +668,9 @@ 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;
@@ -663,8 +699,14 @@ 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
                }
        }
 
@@ -682,13 +724,20 @@ int slap_mods_opattrs(
                        mod->sml_op = mop;
                        mod->sml_type.bv_val = NULL;
                        mod->sml_desc = slap_schema.si_ad_structuralObjectClass;
-#ifdef SLAP_NVALUES
-                       mod->sml_nvalues = NULL;
-#endif
-                       mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
+                       mod->sml_values =
+                               (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
                        ber_dupbv( &mod->sml_values[0], &tmpval );
+                       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;
                }
@@ -703,13 +752,15 @@ int slap_mods_opattrs(
                        mod->sml_op = mop;
                        mod->sml_type.bv_val = NULL;
                        mod->sml_desc = slap_schema.si_ad_entryUUID;
-#ifdef SLAP_NVALUES
-                       mod->sml_nvalues = NULL;
-#endif
-                       mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
+                       mod->sml_values =
+                               (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
                        ber_dupbv( &mod->sml_values[0], &tmpval );
+                       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;
 
@@ -717,13 +768,19 @@ int slap_mods_opattrs(
                        mod->sml_op = mop;
                        mod->sml_type.bv_val = NULL;
                        mod->sml_desc = slap_schema.si_ad_creatorsName;
-#ifdef SLAP_NVALUES
-                       mod->sml_nvalues = NULL;
-#endif
                        mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
                        ber_dupbv( &mod->sml_values[0], &name );
+                       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;
 
@@ -731,13 +788,14 @@ int slap_mods_opattrs(
                        mod->sml_op = mop;
                        mod->sml_type.bv_val = NULL;
                        mod->sml_desc = slap_schema.si_ad_createTimestamp;
-#ifdef SLAP_NVALUES
-                       mod->sml_nvalues = NULL;
-#endif
                        mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
                        ber_dupbv( &mod->sml_values[0], &timestamp );
+                       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;
                }
@@ -748,13 +806,14 @@ int slap_mods_opattrs(
                mod->sml_op = mop;
                mod->sml_type.bv_val = NULL;
                mod->sml_desc = slap_schema.si_ad_entryCSN;
-#ifdef SLAP_NVALUES
-               mod->sml_nvalues = NULL;
-#endif
                mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
                ber_dupbv( &mod->sml_values[0], &csn );
+               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;
 
@@ -762,13 +821,19 @@ int slap_mods_opattrs(
                mod->sml_op = mop;
                mod->sml_type.bv_val = NULL;
                mod->sml_desc = slap_schema.si_ad_modifiersName;
-#ifdef SLAP_NVALUES
-               mod->sml_nvalues = NULL;
-#endif
                mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
                ber_dupbv( &mod->sml_values[0], &name );
+               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;
 
@@ -776,13 +841,14 @@ int slap_mods_opattrs(
                mod->sml_op = mop;
                mod->sml_type.bv_val = NULL;
                mod->sml_desc = slap_schema.si_ad_modifyTimestamp;
-#ifdef SLAP_NVALUES
-               mod->sml_nvalues = NULL;
-#endif
                mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
                ber_dupbv( &mod->sml_values[0], &timestamp );
+               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;
        }