]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/add.c
ITS#4310 seems to affect also back-ldbm
[openldap] / servers / slapd / add.c
index 250da6093a9fa81555c0a336a6ddb54d49f7b499..9056e412ae07eda7200489ff8a0ff7b6f64df903 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2005 The OpenLDAP Foundation.
+ * Copyright 1998-2006 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -47,6 +47,7 @@ do_add( Operation *op, SlapReply *rs )
        char            textbuf[ SLAP_TEXT_BUFLEN ];
        size_t          textlen = sizeof( textbuf );
        int             rc = 0;
+       int             freevals = 1;
 
        Debug( LDAP_DEBUG_TRACE, "do_add\n", 0, 0, 0 );
        /*
@@ -175,6 +176,8 @@ do_add( Operation *op, SlapReply *rs )
                goto done;
        }
 
+       freevals = 0;
+
        op->o_bd = frontendDB;
        rc = frontendDB->be_add( op, rs );
        if ( rc == 0 ) {
@@ -194,7 +197,8 @@ do_add( Operation *op, SlapReply *rs )
 
 done:;
        if ( modlist != NULL ) {
-               slap_mods_free( modlist, 0 );
+               /* in case of error, free the values as well */
+               slap_mods_free( modlist, freevals );
        }
 
        if ( op->ora_e != NULL ) {
@@ -210,10 +214,9 @@ int
 fe_op_add( Operation *op, SlapReply *rs )
 {
        int             manageDSAit;
-       Modifications   *modlist = op->ora_modlist;
-       Modifications   **modtail = &modlist;
+       Modifications   **modtail = &op->ora_modlist;
        int             rc = 0;
-       BackendDB *op_be;
+       BackendDB       *op_be;
        char            textbuf[ SLAP_TEXT_BUFLEN ];
        size_t          textlen = sizeof( textbuf );
 
@@ -264,7 +267,7 @@ fe_op_add( Operation *op, SlapReply *rs )
                goto done;
        }
 
-       rs->sr_err = slap_mods_obsolete_check( op, modlist,
+       rs->sr_err = slap_mods_obsolete_check( op, op->ora_modlist,
                &rs->sr_text, textbuf, textlen );
 
        if ( rs->sr_err != LDAP_SUCCESS ) {
@@ -283,7 +286,7 @@ fe_op_add( Operation *op, SlapReply *rs )
                int repl_user = be_isupdate( op );
 #ifndef SLAPD_MULTIMASTER
                if ( !SLAP_SHADOW(op->o_bd) || repl_user )
-#endif
+#endif /* ! SLAPD_MULTIMASTER */
                {
                        int             update = !BER_BVISEMPTY( &op->o_bd->be_update_ndn );
                        slap_callback   cb = { NULL, slap_replog_cb, NULL, NULL };
@@ -291,7 +294,7 @@ fe_op_add( Operation *op, SlapReply *rs )
                        op->o_bd = op_be;
 
                        if ( !update ) {
-                               rs->sr_err = slap_mods_no_user_mod_check( op, modlist,
+                               rs->sr_err = slap_mods_no_user_mod_check( op, op->ora_modlist,
                                        &rs->sr_text, textbuf, textlen );
 
                                if ( rs->sr_err != LDAP_SUCCESS ) {
@@ -302,7 +305,7 @@ fe_op_add( Operation *op, SlapReply *rs )
 
                        if ( !repl_user ) {
                                /* go to the last mod */
-                               for ( modtail = &modlist;
+                               for ( modtail = &op->ora_modlist;
                                                *modtail != NULL;
                                                modtail = &(*modtail)->sml_next )
                                {
@@ -313,7 +316,7 @@ fe_op_add( Operation *op, SlapReply *rs )
 
                                /* check for duplicate values */
                                rs->sr_err = slap_mods_no_repl_user_mod_check( op,
-                                       modlist, &rs->sr_text, textbuf, textlen );
+                                       op->ora_modlist, &rs->sr_text, textbuf, textlen );
                                if ( rs->sr_err != LDAP_SUCCESS ) {
                                        send_ldap_result( op, rs );
                                        goto done;
@@ -329,7 +332,7 @@ fe_op_add( Operation *op, SlapReply *rs )
 
 #ifdef SLAPD_MULTIMASTER
                        if ( !repl_user )
-#endif
+#endif /* SLAPD_MULTIMASTER */
                        {
                                cb.sc_next = op->o_callback;
                                op->o_callback = &cb;
@@ -466,6 +469,7 @@ slap_mods2entry(
                        snprintf( textbuf, textlen,
                                "attribute '%s' provided more than once",
                                mods->sml_desc->ad_cname.bv_val );
+                       *text = textbuf;
                        return LDAP_TYPE_OR_VALUE_EXISTS;
 #endif
                }
@@ -496,6 +500,7 @@ slap_mods2entry(
                                                snprintf( textbuf, textlen,
                                                        "%s: value #%d provided more than once",
                                                        mods->sml_desc->ad_cname.bv_val, j );
+                                               *text = textbuf;
                                                return LDAP_TYPE_OR_VALUE_EXISTS;
 
                                        } else if ( rc != LDAP_SUCCESS ) {
@@ -660,12 +665,12 @@ int slap_add_opattrs(
                } else {
                        csn = op->o_csn;
                }
-               ptr = strchr( csn.bv_val, '#' );
+               ptr = ber_bvchr( &csn, '#' );
                if ( ptr ) {
                        timestamp.bv_len = ptr - csn.bv_val;
-                       if ( timestamp.bv_len >= sizeof(timebuf) )
+                       if ( timestamp.bv_len >= sizeof(timebuf) )      /* ?!? */
                                timestamp.bv_len = sizeof(timebuf) - 1;
-                       strncpy( timebuf, csn.bv_val, timestamp.bv_len );
+                       AC_MEMCPY( timebuf, csn.bv_val, timestamp.bv_len );
                        timebuf[timestamp.bv_len] = '\0';
                } else {
                        time_t now = slap_get_time();
@@ -729,7 +734,6 @@ int slap_add_opattrs(
                        attr_merge_one( op->ora_e,
                                slap_schema.si_ad_modifyTimestamp, &timestamp, NULL );
                }
-
        }
        return LDAP_SUCCESS;
 }