]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/slapadd.c
Plug mutex/rwlock leaks (destroy them)
[openldap] / servers / slapd / slapadd.c
index 4159d8ff42ef2258a9382913ec48a2d0e2db95dc..d88e1219713d78daf1dbf5842e512c8672b2c98d 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2009 The OpenLDAP Foundation.
+ * Copyright 1998-2010 The OpenLDAP Foundation.
  * Portions Copyright 1998-2003 Kurt D. Zeilenga.
  * Portions Copyright 2003 IBM Corporation.
  * All rights reserved.
@@ -40,8 +40,8 @@
 
 #include "slapcommon.h"
 
-static char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
-static char maxcsnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE * ( SLAP_SYNC_SID_MAX + 1 ) ];
+static char csnbuf[ LDAP_PVT_CSNSTR_BUFSIZE ];
+static char maxcsnbuf[ LDAP_PVT_CSNSTR_BUFSIZE * ( SLAP_SYNC_SID_MAX + 1 ) ];
 
 int
 slapadd( int argc, char **argv )
@@ -103,6 +103,14 @@ slapadd( int argc, char **argv )
 
        checkvals = (slapMode & SLAP_TOOL_QUICK) ? 0 : 1;
 
+       /* do not check values in quick mode */
+       if ( slapMode & SLAP_TOOL_QUICK ) {
+               if ( slapMode & SLAP_TOOL_VALUE_CHECK ) {
+                       fprintf( stderr, "%s: value-check incompatible with quick mode; disabled.\n", progname );
+                       slapMode &= ~SLAP_TOOL_VALUE_CHECK;
+               }
+       }
+
        lmax = 0;
        nextline = 0;
 
@@ -120,7 +128,7 @@ slapadd( int argc, char **argv )
        if ( update_ctxcsn ) {
                maxcsn[ 0 ].bv_val = maxcsnbuf;
                for ( sid = 1; sid <= SLAP_SYNC_SID_MAX; sid++ ) {
-                       maxcsn[ sid ].bv_val = maxcsn[ sid - 1 ].bv_val + LDAP_LUTIL_CSNSTR_BUFSIZE;
+                       maxcsn[ sid ].bv_val = maxcsn[ sid - 1 ].bv_val + LDAP_PVT_CSNSTR_BUFSIZE;
                        maxcsn[ sid ].bv_len = 0;
                }
        }
@@ -267,6 +275,34 @@ slapadd( int argc, char **argv )
                                }
                                textbuf[ 0 ] = '\0';
                        }
+
+                       if ( (slapMode & SLAP_TOOL_VALUE_CHECK) != 0) {
+                               Modifications *ml = NULL;
+
+                               if ( slap_entry2mods( e, &ml, &text, textbuf, textlen )
+                                       != LDAP_SUCCESS )
+                               {
+                                       fprintf( stderr, "%s: dn=\"%s\" (line=%d): (%d) %s\n",
+                                               progname, e->e_dn, lineno, rc, text );
+                                       rc = EXIT_FAILURE;
+                                       entry_free( e );
+                                       if( continuemode ) continue;
+                                       break;
+                               }
+                               textbuf[ 0 ] = '\0';
+
+                               rc = slap_mods_check( op, ml, &text, textbuf, textlen, NULL );
+                               slap_mods_free( ml, 1 );
+                               if ( rc != LDAP_SUCCESS ) {
+                                       fprintf( stderr, "%s: dn=\"%s\" (line=%d): (%d) %s\n",
+                                               progname, e->e_dn, lineno, rc, text );
+                                       rc = EXIT_FAILURE;
+                                       entry_free( e );
+                                       if( continuemode ) continue;
+                                       break;
+                               }
+                               textbuf[ 0 ] = '\0';
+                       }
                }
 
                if ( SLAP_LASTMOD(be) ) {
@@ -293,7 +329,7 @@ slapadd( int argc, char **argv )
                        nvals[1].bv_len = 0;
                        nvals[1].bv_val = NULL;
 
-                       csn.bv_len = lutil_csnstr( csnbuf, sizeof( csnbuf ), csnsid, 0 );
+                       csn.bv_len = ldap_pvt_csnstr( csnbuf, sizeof( csnbuf ), csnsid, 0 );
                        csn.bv_val = csnbuf;
 
                        timestamp.bv_val = timebuf;
@@ -438,10 +474,32 @@ slapadd( int argc, char **argv )
        }
 
        if ( rc == EXIT_SUCCESS && update_ctxcsn && !dryrun && sid != SLAP_SYNC_SID_MAX + 1 ) {
-               ctxcsn_id = be->be_dn2id_get( be, be->be_nsuffix );
+               struct berval ctxdn;
+               if ( SLAP_SYNC_SUBENTRY( be )) {
+                       build_new_dn( &ctxdn, &be->be_nsuffix[0],
+                               (struct berval *)&slap_ldapsync_cn_bv, NULL );
+               } else {
+                       ctxdn = be->be_nsuffix[0];
+               }
+               ctxcsn_id = be->be_dn2id_get( be, &ctxdn );
                if ( ctxcsn_id == NOID ) {
-                       fprintf( stderr, "%s: context entry is missing\n", progname );
-                       rc = EXIT_FAILURE;
+                       if ( SLAP_SYNC_SUBENTRY( be )) {
+                               ctxcsn_e = slap_create_context_csn_entry( be, NULL );
+                               for ( sid = 0; sid <= SLAP_SYNC_SID_MAX; sid++ ) {
+                                       if ( maxcsn[ sid ].bv_len ) {
+                                               attr_merge_one( ctxcsn_e, slap_schema.si_ad_contextCSN,
+                                                       &maxcsn[ sid ], NULL );
+                                       }
+                               }
+                               ctxcsn_id = be->be_entry_put( be, ctxcsn_e, &bvtext );
+                               if ( ctxcsn_id == NOID ) {
+                                       fprintf( stderr, "%s: couldn't create context entry\n", progname );
+                                       rc = EXIT_FAILURE;
+                               }
+                       } else {
+                               fprintf( stderr, "%s: context entry is missing\n", progname );
+                               rc = EXIT_FAILURE;
+                       }
                } else {
                        ctxcsn_e = be->be_entry_get( be, ctxcsn_id );
                        if ( ctxcsn_e != NULL ) {