]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/add.c
Per ITS#419, don't require SLAPD_RLOOKUPS when HAVE_TCPD
[openldap] / servers / slapd / add.c
index efb4e18d6d9b04a676c2534e87735f656d82e86a..9bc2133841a79b5b2a7e623f862457f1199106a3 100644 (file)
@@ -1,3 +1,8 @@
+/* $OpenLDAP$ */
+/*
+ * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
 /*
  * Copyright (c) 1995 Regents of the University of Michigan.
  * All rights reserved.
 #include <ac/time.h>
 #include <ac/socket.h>
 
+#include "ldap_pvt.h"
 #include "slap.h"
 
-static void    add_created_attrs(Operation *op, Entry *e);
+static int     add_created_attrs(Operation *op, Entry *e);
 
 int
 do_add( Connection *conn, Operation *op )
@@ -64,7 +70,7 @@ do_add( Connection *conn, Operation *op )
 
        ndn = ch_strdup( dn );
 
-       if ( dn_normalize_case( ndn ) == NULL ) {
+       if ( dn_normalize( ndn ) == NULL ) {
                Debug( LDAP_DEBUG_ANY, "do_add: invalid dn (%s)\n", dn, 0, 0 );
                send_ldap_result( conn, op, LDAP_INVALID_DN_SYNTAX, NULL,
                    "invalid DN", NULL, NULL );
@@ -79,8 +85,6 @@ do_add( Connection *conn, Operation *op )
        e->e_ndn = ndn;
        e->e_private = NULL;
 
-       dn = NULL;
-
        Debug( LDAP_DEBUG_ARGS, "    do_add: ndn (%s)\n", e->e_ndn, 0, 0 );
 
        /* get the attrs */
@@ -127,7 +131,7 @@ do_add( Connection *conn, Operation *op )
                return rc;
        } 
 
-       Statslog( LDAP_DEBUG_STATS, "conn=%d op=%d ADD dn=\"%s\"\n",
+       Statslog( LDAP_DEBUG_STATS, "conn=%ld op=%d ADD dn=\"%s\"\n",
            op->o_connid, op->o_opid, e->e_ndn, 0, 0 );
 
        /*
@@ -143,6 +147,23 @@ do_add( Connection *conn, Operation *op )
                return rc;
        }
 
+       /* make sure this backend recongizes critical controls */
+       rc = backend_check_controls( be, conn, op ) ;
+
+       if( rc != LDAP_SUCCESS ) {
+               send_ldap_result( conn, op, rc,
+                       NULL, NULL, NULL, NULL );
+       }
+
+       if ( global_readonly || be->be_readonly ) {
+               Debug( LDAP_DEBUG_ANY, "do_add: database is read-only\n",
+                      0, 0, 0 );
+               entry_free( e );
+               send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM,
+                                 NULL, "database is read-only", NULL, NULL );
+               return LDAP_UNWILLING_TO_PERFORM;
+       }
+
        /*
         * do the add if 1 && (2 || 3)
         * 1) there is an add function implemented in this backend;
@@ -151,23 +172,48 @@ do_add( Connection *conn, Operation *op )
         */
        if ( be->be_add ) {
                /* do the update here */
+#ifdef SLAPD_MULTIMASTER
+               if ( (be->be_lastmod == ON || (be->be_lastmod == UNDEFINED &&
+                       global_lastmod == ON)) && (be->be_update_ndn == NULL ||
+                       strcmp( be->be_update_ndn, op->o_ndn )) )
+#else
                if ( be->be_update_ndn == NULL ||
                        strcmp( be->be_update_ndn, op->o_ndn ) == 0 )
+#endif
                {
+#ifndef SLAPD_MULTIMASTER
                        if ( (be->be_lastmod == ON || (be->be_lastmod == UNDEFINED &&
-                               global_lastmod == ON)) && be->be_update_ndn == NULL ) {
-
-                               add_created_attrs( op, e );
+                               global_lastmod == ON)) && be->be_update_ndn == NULL )
+#endif
+                       {
+                               rc = add_created_attrs( op, e );
+
+                               if( rc != LDAP_SUCCESS ) {
+                                       entry_free( e );
+                                       send_ldap_result( conn, op, rc,
+                                               NULL, "no-user-modification attribute type",
+                                               NULL, NULL );
+                                       return rc;
+                               }
                        }
+
                        if ( (*be->be_add)( be, conn, op, e ) == 0 ) {
-                               replog( be, LDAP_REQ_ADD, e->e_dn, e, 0 );
+#ifdef SLAPD_MULTIMASTER
+                               if (be->be_update_ndn == NULL ||
+                                       strcmp( be->be_update_ndn, op->o_ndn ))
+#endif
+                               {
+                                       replog( be, op, e->e_dn, e );
+                               }
                                be_entry_release_w( be, e );
                        }
 
+#ifndef SLAPD_MULTIMASTER
                } else {
                        entry_free( e );
                        send_ldap_result( conn, op, rc = LDAP_REFERRAL, NULL, NULL,
                                be->be_update_refs ? be->be_update_refs : default_referral, NULL );
+#endif
                }
        } else {
            Debug( LDAP_DEBUG_ARGS, "    do_add: HHH\n", 0, 0, 0 );
@@ -179,14 +225,13 @@ do_add( Connection *conn, Operation *op )
        return rc;
 }
 
-static void
+static int
 add_created_attrs( Operation *op, Entry *e )
 {
        char            buf[22];
        struct berval   bv;
        struct berval   *bvals[2];
-       Attribute       **a, **next;
-       Attribute       *tmp;
+       Attribute       *a;
        struct tm       *ltm;
        time_t          currenttime;
 
@@ -195,15 +240,10 @@ add_created_attrs( Operation *op, Entry *e )
        bvals[0] = &bv;
        bvals[1] = NULL;
 
-       /* remove any attempts by the user to add these attrs */
-       for ( a = &e->e_attrs; *a != NULL; a = next ) {
-               if ( oc_check_no_usermod_attr( (*a)->a_type ) ) {
-                       tmp = *a;
-                       *a = (*a)->a_next;
-                       attr_free( tmp );
-                       next = a;
-               } else {
-                       next = &(*a)->a_next;
+       /* return error on any attempts by the user to add these attrs */
+       for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
+               if ( oc_check_no_usermod_attr( a->a_type ) ) {
+                       return LDAP_CONSTRAINT_VIOLATION;
                }
        }
 
@@ -215,19 +255,18 @@ add_created_attrs( Operation *op, Entry *e )
                bv.bv_len = strlen( bv.bv_val );
        }
        attr_merge( e, "creatorsname", bvals );
+       attr_merge( e, "modifiersname", bvals );
 
        currenttime = slap_get_time();
        ldap_pvt_thread_mutex_lock( &gmtime_mutex );
-#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
        ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
 
        bv.bv_val = buf;
        bv.bv_len = strlen( bv.bv_val );
        attr_merge( e, "createtimestamp", bvals );
+       attr_merge( e, "modifytimestamp", bvals );
+
+       return LDAP_SUCCESS;
 }