]> git.sur5r.net Git - openldap/blobdiff - tests/progs/slapd-common.c
Merge remote branch 'origin/mdb.master'
[openldap] / tests / progs / slapd-common.c
index 3c98adb0151f3d41d58747cf3d1d135cb9a8f27d..f90e32a0acf3784dd92f443ee310b2087b8c2094 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-2012 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/unistd.h>
-#include <ac/string.h>
-#include <ac/errno.h>
+#include "ac/stdlib.h"
+#include "ac/unistd.h"
+#include "ac/string.h"
+#include "ac/errno.h"
 
-#include <ldap.h>
+#include "ldap.h"
 
 #include "ldap_pvt.h"
 #include "slapd-common.h"
 
+/* global vars */
+pid_t pid;
+
+/* static vars */
 static char progname[ BUFSIZ ];
 tester_t progtype;
 
-#define        TESTER_SERVER_LAST      (LDAP_OTHER + 1)
-#define TESTER_CLIENT_LAST     (- LDAP_REFERRAL_LIMIT_EXCEEDED + 1)
-static unsigned ignore_server[ TESTER_SERVER_LAST ];
-static unsigned ignore_client[ TESTER_CLIENT_LAST ];
+/*
+ * ignore_count[] is indexed by result code:
+ * negative for OpenLDAP client-side errors, positive for protocol codes.
+ */
+#define        TESTER_CLIENT_FIRST     LDAP_REFERRAL_LIMIT_EXCEEDED /* negative */
+#define        TESTER_SERVER_LAST      LDAP_OTHER
+static int ignore_base [ -TESTER_CLIENT_FIRST + TESTER_SERVER_LAST + 1 ];
+#define    ignore_count        (ignore_base - TESTER_CLIENT_FIRST)
 
-static struct {
-       char    *name;
+static const struct {
+       const char *name;
        int     err;
 } ignore_str2err[] = {
        { "OPERATIONS_ERROR",           LDAP_OPERATIONS_ERROR },
@@ -74,7 +82,8 @@ static struct {
        { "IS_LEAF",                    LDAP_IS_LEAF },
        { "ALIAS_DEREF_PROBLEM",        LDAP_ALIAS_DEREF_PROBLEM },
 
-       { "PROXY_AUTHZ_FAILURE",        LDAP_PROXY_AUTHZ_FAILURE },
+       /* obsolete */
+       { "PROXY_AUTHZ_FAILURE",        LDAP_X_PROXY_AUTHZ_FAILURE },
        { "INAPPROPRIATE_AUTH",         LDAP_INAPPROPRIATE_AUTH },
        { "INVALID_CREDENTIALS",        LDAP_INVALID_CREDENTIALS },
        { "INSUFFICIENT_ACCESS",        LDAP_INSUFFICIENT_ACCESS },
@@ -121,20 +130,13 @@ static struct {
 static int
 tester_ignore_str2err( const char *err )
 {
-       int             i;
-       unsigned        ignore = 1;
+       int             i, ignore = 1;
 
        if ( strcmp( err, "ALL" ) == 0 ) {
                for ( i = 0; ignore_str2err[ i ].name != NULL; i++ ) {
-                       int     err = ignore_str2err[ i ].err;
-
-                       if ( err > 0 ) {
-                               ignore_server[ err ] = 1;
-
-                       } else if ( err < 0 ) {
-                               ignore_client[ -err ] = 1;
-                       }
+                       ignore_count[ ignore_str2err[ i ].err ] = 1;
                }
+               ignore_count[ LDAP_SUCCESS ] = 0;
 
                return 0;
        }
@@ -142,17 +144,18 @@ tester_ignore_str2err( const char *err )
        if ( err[ 0 ] == '!' ) {
                ignore = 0;
                err++;
+
+       } else if ( err[ 0 ] == '*' ) {
+               ignore = -1;
+               err++;
        }
 
        for ( i = 0; ignore_str2err[ i ].name != NULL; i++ ) {
                if ( strcmp( err, ignore_str2err[ i ].name ) == 0 ) {
                        int     err = ignore_str2err[ i ].err;
 
-                       if ( err > 0 ) {
-                               ignore_server[ err ] = ignore;
-
-                       } else if ( err < 0 ) {
-                               ignore_client[ -err ] = ignore;
+                       if ( err != LDAP_SUCCESS ) {
+                               ignore_count[ err ] = ignore;
                        }
 
                        return err;
@@ -178,25 +181,15 @@ tester_ignore_str2errlist( const char *err )
        return 0;
 }
 
-unsigned
+int
 tester_ignore_err( int err )
 {
-       unsigned        rc = 1;
+       int rc = 1;
 
-       if ( err > 0 ) {
-               if ( err < TESTER_SERVER_LAST ) {
-                       rc = ignore_server[ err ];
-                       if ( rc ) {
-                               ignore_server[ err ]++;
-                       }
-               }
-
-       } else if ( err < 0 ) {
-               if ( -err < TESTER_CLIENT_LAST ) {
-                       rc = ignore_client[ -err ];
-                       if ( rc ) {
-                               ignore_client[ -err ]++;
-                       }
+       if ( err && TESTER_CLIENT_FIRST <= err && err <= TESTER_SERVER_LAST ) {
+               rc = ignore_count[ err ];
+               if ( rc != 0 ) {
+                       ignore_count[ err ] = rc + (rc > 0 ? 1 : -1);
                }
        }
 
@@ -207,7 +200,9 @@ tester_ignore_err( int err )
 void
 tester_init( const char *pname, tester_t ptype )
 {
-       snprintf( progname, sizeof( progname ), "%s PID=%d", pname, getpid() );
+       pid = getpid();
+       srand( pid );
+       snprintf( progname, sizeof( progname ), "%s PID=%d", pname, pid );
        progtype = ptype;
 }
 
@@ -234,7 +229,7 @@ tester_ldap_error( LDAP *ld, const char *fname, const char *msg )
 
        ldap_get_option( ld, LDAP_OPT_RESULT_CODE, (void *)&err );
        if ( err != LDAP_SUCCESS ) {
-               ldap_get_option( ld, LDAP_OPT_ERROR_STRING, (void *)&text );
+               ldap_get_option( ld, LDAP_OPT_DIAGNOSTIC_MESSAGE, (void *)&text );
        }
 
        fprintf( stderr, "%s: %s: %s (%d) %s %s\n",
@@ -303,4 +298,3 @@ tester_error( const char *msg )
 {
        fprintf( stderr, "%s: %s\n", progname, msg );
 }
-