]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/add.c
Apply ITS#12 fix from devel.
[openldap] / servers / slapd / add.c
index 027e40a8e4d2af935172366a8266aeb7a7bd41ca..0f497a0d73767a709692c7fba0849d3947c2e1e2 100644 (file)
  * is provided ``as is'' without express or implied warranty.
  */
 
+#include "portable.h"
+
 #include <stdio.h>
-#include <string.h>
-#include <time.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include "slap.h"
 
-extern Backend *select_backend();
-extern char    *dn_normalize();
+#include <ac/string.h>
+#include <ac/time.h>
+#include <ac/socket.h>
 
-extern char            *default_referral;
-extern time_t          currenttime;
-extern pthread_mutex_t currenttime_mutex;
-extern int             global_lastmod;
+#include "slap.h"
 
-static void    add_created_attrs();
+static void    add_created_attrs(Operation *op, Entry *e);
 
 void
-do_add( conn, op )
-    Connection *conn;
-    Operation  *op;
+do_add( Connection *conn, Operation *op )
 {
        BerElement      *ber = op->o_ber;
        char            *dn, *last;
@@ -52,8 +45,6 @@ do_add( conn, op )
         *      }
         */
 
-       e = (Entry *) ch_calloc( 1, sizeof(Entry) );
-
        /* get the name */
        if ( ber_scanf( ber, "{a", &dn ) == LBER_ERROR ) {
                Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
@@ -61,8 +52,13 @@ do_add( conn, op )
                    "decoding error" );
                return;
        }
+
+       e = (Entry *) ch_calloc( 1, sizeof(Entry) );
+       /* initialize reader/writer lock */
+       entry_rdwr_init(e);
+
        e->e_dn = dn;
-       dn = dn_normalize( strdup( dn ) );
+       dn = dn_normalize( ch_strdup( dn ) );
        Debug( LDAP_DEBUG_ARGS, "    do_add: dn (%s)\n", dn, 0, 0 );
 
        /* get the attrs */
@@ -117,21 +113,25 @@ do_add( conn, op )
         */
        if ( be->be_add != NULL ) {
                /* do the update here */
-               if ( be->be_updatedn == NULL || strcasecmp( be->be_updatedn,
-                   op->o_dn ) == 0 ) {
-                       if ( (be->be_lastmod == ON || be->be_lastmod == 0 &&
-                           global_lastmod == ON) && be->be_updatedn == NULL ) {
+               if ( be->be_updatedn == NULL ||
+                       strcasecmp( be->be_updatedn, op->o_dn ) == 0 ) {
+
+                       if ( (be->be_lastmod == ON || (be->be_lastmod == UNDEFINED &&
+                               global_lastmod == ON)) && be->be_updatedn == NULL ) {
+
                                add_created_attrs( op, e );
                        }
                        if ( (*be->be_add)( be, conn, op, e ) == 0 ) {
                                replog( be, LDAP_REQ_ADD, e->e_dn, e, 0 );
                        }
+
                } else {
                        entry_free( e );
                        send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS, NULL,
                            default_referral );
                }
        } else {
+           Debug( LDAP_DEBUG_ARGS, "    do_add: HHH\n", 0, 0, 0 );
                entry_free( e );
                send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
                    "Function not implemented" );
@@ -141,7 +141,7 @@ do_add( conn, op )
 static void
 add_created_attrs( Operation *op, Entry *e )
 {
-       char            buf[20];
+       char            buf[22];
        struct berval   bv;
        struct berval   *bvals[2];
        Attribute       **a, **next;
@@ -155,8 +155,10 @@ add_created_attrs( Operation *op, Entry *e )
 
        /* remove any attempts by the user to add these attrs */
        for ( a = &e->e_attrs; *a != NULL; a = next ) {
-               if ( strcasecmp( (*a)->a_type, "createtimestamp" ) == 0
-                   || strcasecmp( (*a)->a_type, "creatorsname" ) == 0 ) {
+               if ( strcasecmp( (*a)->a_type, "modifiersname" ) == 0 || 
+                       strcasecmp( (*a)->a_type, "modifytimestamp" ) == 0 ||
+                       strcasecmp( (*a)->a_type, "creatorsname" ) == 0 ||
+                       strcasecmp( (*a)->a_type, "createtimestamp" ) == 0 ) {
                        tmp = *a;
                        *a = (*a)->a_next;
                        attr_free( tmp );
@@ -176,8 +178,13 @@ add_created_attrs( Operation *op, Entry *e )
        attr_merge( e, "creatorsname", bvals );
 
        pthread_mutex_lock( &currenttime_mutex );
-        ltm = localtime( &currenttime );
-        strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
+#ifndef LDAP_LOCALTIME
+       ltm = gmtime( &currenttime );
+       strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm );
+#else
+       ltm = localtime( &currenttime );
+       strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
+#endif
        pthread_mutex_unlock( &currenttime_mutex );
 
        bv.bv_val = buf;