]> git.sur5r.net Git - openldap/blobdiff - tests/progs/slapd-bind.c
ITS#6003, #5916 fix ldap_back_entry_get_rw, no deref here
[openldap] / tests / progs / slapd-bind.c
index 0a892e0a9989584c6340db5fe01cdd37f936b240..1b597f27f04b1063528a535992e2ee259bb15943 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1999-2006 The OpenLDAP Foundation.
+ * Copyright 1999-2009 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 
 #include <stdio.h>
 
-#include <ac/stdlib.h>
-#include <ac/time.h>
+#include "ac/stdlib.h"
+#include "ac/time.h"
 
-#include <ac/ctype.h>
-#include <ac/param.h>
-#include <ac/socket.h>
-#include <ac/string.h>
-#include <ac/unistd.h>
-#include <ac/wait.h>
-#include <ac/time.h>
+#include "ac/ctype.h"
+#include "ac/param.h"
+#include "ac/socket.h"
+#include "ac/string.h"
+#include "ac/unistd.h"
+#include "ac/wait.h"
+#include "ac/time.h"
 
-#include <ldap.h>
-#include <lutil.h>
-#include <lber_pvt.h>
-#include <ldap_pvt.h>
+#include "ldap.h"
+#include "lutil.h"
+#include "lber_pvt.h"
+#include "ldap_pvt.h"
 
 #include "slapd-common.h"
 
@@ -98,7 +98,7 @@ main( int argc, char **argv )
        int             outerloops = 1;
        int             force = 0;
        int             chaserefs = 0;
-       int             noinit = 0;
+       int             noinit = 1;
        int             delay = 0;
 
        /* extra action to do after bind... */
@@ -120,8 +120,9 @@ main( int argc, char **argv )
        /* by default, tolerate invalid credentials */
        tester_ignore_str2errlist( "INVALID_CREDENTIALS" );
 
-       while ( (i = getopt( argc, argv, "a:b:B:H:h:i:p:D:w:l:L:f:FIt:" )) != EOF ) {
-               switch( i ) {
+       while ( ( i = getopt( argc, argv, "a:B:b:D:Ff:H:h:Ii:L:l:p:t:w:" ) ) != EOF )
+       {
+               switch ( i ) {
                case 'a':
                        pwattr = optarg;
                        break;
@@ -225,7 +226,7 @@ main( int argc, char **argv )
 
                case 'I':
                        /* reuse connection */
-                       noinit++;
+                       noinit = 0;
                        break;
 
                case 't':
@@ -248,13 +249,17 @@ main( int argc, char **argv )
        uri = tester_uri( uri, host, port );
 
        for ( i = 0; i < outerloops; i++ ) {
+               int rc;
+
                if ( base != NULL ) {
-                       do_base( uri, dn, &pass, base, filter, pwattr, loops,
+                       rc = do_base( uri, dn, &pass, base, filter, pwattr, loops,
                                force, chaserefs, noinit, delay, -1, NULL );
                } else {
-                       do_bind( uri, dn, &pass, loops,
+                       rc = do_bind( uri, dn, &pass, loops,
                                force, chaserefs, noinit, NULL, -1, NULL );
                }
+               if ( rc == LDAP_SERVER_DOWN )
+                       break;
        }
 
        exit( EXIT_SUCCESS );
@@ -338,12 +343,12 @@ do_bind( char *uri, char *dn, struct berval *pass, int maxloop,
 
                rc = ldap_sasl_bind_s( ld, dn, LDAP_SASL_SIMPLE, pass, NULL, NULL, NULL );
                if ( rc ) {
-                       unsigned first = tester_ignore_err( rc );
+                       int first = tester_ignore_err( rc );
 
                        /* if ignore.. */
                        if ( first ) {
                                /* only log if first occurrence */
-                               if ( force < 2 || first == 1 ) {
+                               if ( ( force < 2 && first > 0 ) || abs(first) == 1 ) {
                                        tester_ldap_error( ld, "ldap_sasl_bind_s", NULL );
                                }
                                rc = LDAP_SUCCESS;
@@ -393,7 +398,7 @@ do_bind( char *uri, char *dn, struct berval *pass, int maxloop,
        }
 
        if ( maxloop > 1 ) {
-               fprintf( stderr, " PID=%ld - Bind done (%d).\n", (long) pid, rc );
+               fprintf( stderr, "  PID=%ld - Bind done (%d).\n", (long) pid, rc );
        }
 
        if ( ldp && noinit ) {
@@ -569,7 +574,7 @@ novals:;
        end = GetTickCount();
        end -= beg;
 
-       fprintf( stderr, " PID=%ld - Bind done %d in %d.%03d seconds.\n",
+       fprintf( stderr, "  PID=%ld - Bind done %d in %d.%03d seconds.\n",
                (long) pid, i, end / 1000, end % 1000 );
 #else
        gettimeofday( &end, NULL );
@@ -580,7 +585,7 @@ novals:;
        }
        end.tv_sec -= beg.tv_sec;
 
-       fprintf( stderr, " PID=%ld - Bind done %d in %ld.%06ld seconds.\n",
+       fprintf( stderr, "  PID=%ld - Bind done %d in %ld.%06ld seconds.\n",
                (long) pid, i, (long) end.tv_sec, (long) end.tv_usec );
 #endif