From: Pierangelo Masarati Date: Thu, 12 Jan 2006 13:01:38 +0000 (+0000) Subject: rework tester common error logging and so X-Git-Tag: OPENLDAP_REL_ENG_2_4_BP~338 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=120916a9629fc1a5d26f17847eec9e0035912d5b;p=openldap rework tester common error logging and so --- diff --git a/tests/progs/Makefile.in b/tests/progs/Makefile.in index 9c3a350e32..3832f84c43 100644 --- a/tests/progs/Makefile.in +++ b/tests/progs/Makefile.in @@ -16,37 +16,41 @@ PROGRAMS = slapd-tester slapd-search slapd-read slapd-addel slapd-modrdn \ slapd-modify slapd-bind -SRCS = slapd-tester.c slapd-search.c slapd-read.c slapd-addel.c \ +SRCS = slapd-common.c \ + slapd-tester.c slapd-search.c slapd-read.c slapd-addel.c \ slapd-modrdn.c slapd-modify.c slapd-bind.c LDAP_INCDIR= ../../include LDAP_LIBDIR= ../../libraries XLIBS = $(LDAP_LIBLDAP_LA) $(LDAP_LIBLBER_LA) $(LDAP_LIBLUTIL_A) -XXLIBS = $(SECURITY_LIBS) $(LUTIL_LIBS) +XXLIBS = $(SECURITY_LIBS) $(LUTIL_LIBS) + +OBJS = slapd-common.o # build-tools: FORCE # $(MAKE) $(MFLAGS) load-tools # load-tools: $(PROGRAMS) -slapd-tester: slapd-tester.o $(XLIBS) - $(LTLINK) -o $@ slapd-tester.o $(LIBS) +slapd-tester: slapd-tester.o $(OBJS) $(XLIBS) + $(LTLINK) -o $@ slapd-tester.o $(OBJS) $(LIBS) + +slapd-search: slapd-search.o $(OBJS) $(XLIBS) + $(LTLINK) -o $@ slapd-search.o $(OBJS) $(LIBS) -slapd-search: slapd-search.o $(XLIBS) - $(LTLINK) -o $@ slapd-search.o $(LIBS) +slapd-read: slapd-read.o $(OBJS) $(XLIBS) + $(LTLINK) -o $@ slapd-read.o $(OBJS) $(LIBS) -slapd-read: slapd-read.o $(XLIBS) - $(LTLINK) -o $@ slapd-read.o $(LIBS) +slapd-addel: slapd-addel.o $(OBJS) $(XLIBS) + $(LTLINK) -o $@ slapd-addel.o $(OBJS) $(LIBS) -slapd-addel: slapd-addel.o $(XLIBS) - $(LTLINK) -o $@ slapd-addel.o $(LIBS) +slapd-modrdn: slapd-modrdn.o $(OBJS) $(XLIBS) + $(LTLINK) -o $@ slapd-modrdn.o $(OBJS) $(LIBS) -slapd-modrdn: slapd-modrdn.o $(XLIBS) - $(LTLINK) -o $@ slapd-modrdn.o $(LIBS) +slapd-modify: slapd-modify.o $(OBJS) $(XLIBS) + $(LTLINK) -o $@ slapd-modify.o $(OBJS) $(LIBS) -slapd-modify: slapd-modify.o $(XLIBS) - $(LTLINK) -o $@ slapd-modify.o $(LIBS) +slapd-bind: slapd-bind.o $(OBJS) $(XLIBS) + $(LTLINK) -o $@ slapd-bind.o $(OBJS) $(LIBS) -slapd-bind: slapd-bind.o $(XLIBS) - $(LTLINK) -o $@ slapd-bind.o $(LIBS) diff --git a/tests/progs/slapd-addel.c b/tests/progs/slapd-addel.c index 6c643dffac..dc94d83a05 100644 --- a/tests/progs/slapd-addel.c +++ b/tests/progs/slapd-addel.c @@ -30,10 +30,11 @@ #include #include -#define LDAP_DEPRECATED 1 #include #include +#include "slapd-common.h" + #define LOOPS 100 #define RETRIES 0 @@ -41,7 +42,7 @@ static char * get_add_entry( char *filename, LDAPMod ***mods ); static void -do_addel( char *uri, char *host, int port, char *manager, char *passwd, +do_addel( char *uri, char *manager, struct berval *passwd, char *dn, LDAPMod **attrs, int maxloop, int maxretries, int delay, int friendly ); @@ -70,7 +71,7 @@ main( int argc, char **argv ) char *uri = NULL; int port = -1; char *manager = NULL; - char *passwd = NULL; + struct berval passwd = { 0, NULL }; char *filename = NULL; char *entry = NULL; int loops = LOOPS; @@ -79,6 +80,8 @@ main( int argc, char **argv ) int friendly = 0; LDAPMod **attrs = NULL; + tester_init( "slapd-modify" ); + while ( (i = getopt( argc, argv, "FH:h:p:D:w:f:l:r:t:" )) != EOF ) { switch( i ) { case 'F': @@ -104,7 +107,8 @@ main( int argc, char **argv ) break; case 'w': /* the server managers password */ - passwd = strdup( optarg ); + passwd.bv_val = strdup( optarg ); + passwd.bv_len = strlen( optarg ); break; case 'f': /* file with entry search request */ @@ -136,7 +140,7 @@ main( int argc, char **argv ) } if (( filename == NULL ) || ( port == -1 && uri == NULL ) || - ( manager == NULL ) || ( passwd == NULL )) + ( manager == NULL ) || ( passwd.bv_val == NULL )) usage( argv[0] ); entry = get_add_entry( filename, &attrs ); @@ -156,7 +160,9 @@ main( int argc, char **argv ) } - do_addel( uri, host, port, manager, passwd, entry, attrs, + uri = tester_uri( uri, host, port ); + + do_addel( uri, manager, &passwd, entry, attrs, loops, retries, delay, friendly ); exit( EXIT_SUCCESS ); @@ -186,19 +192,19 @@ addmodifyop( LDAPMod ***pmodsp, int modop, char *attr, char *value, int vlen ) if ( pmods == NULL || pmods[ i ] == NULL ) { if (( pmods = (LDAPMod **)realloc( pmods, (i + 2) * sizeof( LDAPMod * ))) == NULL ) { - perror( "realloc" ); + tester_perror( "realloc" ); exit( EXIT_FAILURE ); } *pmodsp = pmods; pmods[ i + 1 ] = NULL; if (( pmods[ i ] = (LDAPMod *)calloc( 1, sizeof( LDAPMod ))) == NULL ) { - perror( "calloc" ); + tester_perror( "calloc" ); exit( EXIT_FAILURE ); } pmods[ i ]->mod_op = modop; if (( pmods[ i ]->mod_type = strdup( attr )) == NULL ) { - perror( "strdup" ); + tester_perror( "strdup" ); exit( EXIT_FAILURE ); } } @@ -213,20 +219,20 @@ addmodifyop( LDAPMod ***pmodsp, int modop, char *attr, char *value, int vlen ) if (( pmods[ i ]->mod_bvalues = (struct berval **)ber_memrealloc( pmods[ i ]->mod_bvalues, (j + 2) * sizeof( struct berval * ))) == NULL ) { - perror( "ber_realloc" ); + tester_perror( "ber_memrealloc" ); exit( EXIT_FAILURE ); } pmods[ i ]->mod_bvalues[ j + 1 ] = NULL; if (( bvp = (struct berval *)ber_memalloc( sizeof( struct berval ))) == NULL ) { - perror( "malloc" ); + tester_perror( "ber_memalloc" ); exit( EXIT_FAILURE ); } pmods[ i ]->mod_bvalues[ j ] = bvp; bvp->bv_len = vlen; if (( bvp->bv_val = (char *)malloc( vlen + 1 )) == NULL ) { - perror( "malloc" ); + tester_perror( "malloc" ); exit( EXIT_FAILURE ); } AC_MEMCPY( bvp->bv_val, value, vlen ); @@ -280,10 +286,8 @@ get_add_entry( char *filename, LDAPMod ***mods ) static void do_addel( char *uri, - char *host, - int port, char *manager, - char *passwd, + struct berval *passwd, char *entry, LDAPMod **attrs, int maxloop, @@ -296,32 +300,25 @@ do_addel( int i = 0, do_retry = maxretries; pid_t pid = getpid(); int rc = LDAP_SUCCESS; + int version = LDAP_VERSION3; retry:; - if ( uri ) { - ldap_initialize( &ld, uri ); - } else { - ld = ldap_init( host, port ); - } + ldap_initialize( &ld, uri ); if ( ld == NULL ) { - perror( "ldap_init" ); + tester_perror( "ldap_initialize" ); exit( EXIT_FAILURE ); } - { - int version = LDAP_VERSION3; - (void) ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, - &version ); - } + (void) ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &version ); if ( do_retry == maxretries ) { fprintf( stderr, "PID=%ld - Add/Delete(%d): entry=\"%s\".\n", (long) pid, maxloop, entry ); } - rc = ldap_bind_s( ld, manager, passwd, LDAP_AUTH_SIMPLE ); + rc = ldap_sasl_bind_s( ld, manager, LDAP_SASL_SIMPLE, passwd, NULL, NULL, NULL ); if ( rc != LDAP_SUCCESS ) { - ldap_perror( ld, "ldap_bind" ); + tester_ldap_error( ld, "ldap_sasl_bind_s" ); switch ( rc ) { case LDAP_BUSY: case LDAP_UNAVAILABLE: @@ -342,9 +339,9 @@ retry:; for ( ; i < maxloop; i++ ) { /* add the entry */ - rc = ldap_add_s( ld, entry, attrs ); + rc = ldap_add_ext_s( ld, entry, attrs, NULL, NULL ); if ( rc != LDAP_SUCCESS ) { - ldap_perror( ld, "ldap_add" ); + tester_ldap_error( ld, "ldap_add_ext_s" ); switch ( rc ) { case LDAP_ALREADY_EXISTS: /* NOTE: this likely means @@ -375,9 +372,9 @@ retry:; #endif /* now delete the entry again */ - rc = ldap_delete_s( ld, entry ); + rc = ldap_delete_ext_s( ld, entry, NULL, NULL ); if ( rc != LDAP_SUCCESS ) { - ldap_perror( ld, "ldap_delete" ); + tester_ldap_error( ld, "ldap_delete_ext_s" ); switch ( rc ) { case LDAP_NO_SUCH_OBJECT: /* NOTE: this likely means @@ -405,7 +402,7 @@ retry:; done:; fprintf( stderr, " PID=%ld - Add/Delete done (%d).\n", (long) pid, rc ); - ldap_unbind( ld ); + ldap_unbind_ext( ld, NULL, NULL ); } diff --git a/tests/progs/slapd-bind.c b/tests/progs/slapd-bind.c index 207c332591..63409c0be0 100644 --- a/tests/progs/slapd-bind.c +++ b/tests/progs/slapd-bind.c @@ -35,21 +35,9 @@ #include #include -#define LOOPS 100 - -static void -do_error( LDAP *ld, const char *func ) -{ - int err; - const char *text = "Success"; - - ldap_get_option( ld, LDAP_OPT_RESULT_CODE, (void *)&err ); - if ( err != LDAP_SUCCESS ) { - ldap_get_option( ld, LDAP_OPT_ERROR_STRING, (void *)&text ); - } +#include "slapd-common.h" - fprintf( stderr, "%s: (%d) %s\n", func, err, text == NULL ? "" : text ); -} +#define LOOPS 100 static int do_bind( char *uri, char *dn, struct berval *pass, int maxloop, int force ); @@ -78,8 +66,7 @@ int main( int argc, char **argv ) { int i; - char *uri = NULL, - uribuf[ BUFSIZ ]; + char *uri = NULL; char *host = "localhost"; char *dn = NULL; char *base = NULL; @@ -88,6 +75,8 @@ main( int argc, char **argv ) int loops = LOOPS; int force = 0; + tester_init( "slapd-bind" ); + while ( (i = getopt( argc, argv, "b:H:h:p:D:w:l:f:F" )) != EOF ) { switch( i ) { case 'b': /* base DN of a tree of user DNs */ @@ -141,10 +130,7 @@ main( int argc, char **argv ) usage( argv[0] ); } - if ( uri == NULL ) { - snprintf( uribuf, sizeof( uribuf ), "ldap://%s:%d", host, port ); - uri = uribuf; - } + uri = tester_uri( uri, host, port ); if ( base ) { do_base( uri, base, &pass, ( 20 * loops ), force ); @@ -169,7 +155,7 @@ do_bind( char *uri, char *dn, struct berval *pass, int maxloop, int force ) for ( i = 0; i < maxloop; i++ ) { ldap_initialize( &ld, uri ); if ( ld == NULL ) { - perror( "ldap_initialize" ); + tester_perror( "ldap_initialize" ); rc = -1; break; } @@ -182,7 +168,7 @@ do_bind( char *uri, char *dn, struct berval *pass, int maxloop, int force ) rc = ldap_sasl_bind_s( ld, dn, LDAP_SASL_SIMPLE, pass, NULL, NULL, NULL ); if ( rc != LDAP_SUCCESS ) { - do_error( ld, "ldap_bind" ); + tester_ldap_error( ld, "ldap_sasl_bind_s" ); } ldap_unbind_ext( ld, NULL, NULL ); if ( rc != LDAP_SUCCESS && !force ) { @@ -220,7 +206,7 @@ do_base( char *uri, char *base, struct berval *pass, int maxloop, int force ) ldap_initialize( &ld, uri ); if ( ld == NULL ) { - perror( "ldap_initialize" ); + tester_perror( "ldap_initialize" ); exit( EXIT_FAILURE ); } @@ -229,14 +215,14 @@ do_base( char *uri, char *base, struct berval *pass, int maxloop, int force ) rc = ldap_sasl_bind_s( ld, NULL, LDAP_SASL_SIMPLE, NULL, NULL, NULL, NULL ); if ( rc != LDAP_SUCCESS ) { - do_error( ld, "ldap_bind" ); + tester_ldap_error( ld, "ldap_sasl_bind_s" ); exit( EXIT_FAILURE ); } rc = ldap_search_ext( ld, base, LDAP_SCOPE_ONE, filter, attrs, 0, NULL, NULL, 0, 0, &msgid ); if ( rc != LDAP_SUCCESS ) { - do_error( ld, "ldap_search_ext" ); + tester_ldap_error( ld, "ldap_search_ext" ); exit( EXIT_FAILURE ); } diff --git a/tests/progs/slapd-common.c b/tests/progs/slapd-common.c new file mode 100644 index 0000000000..ec401084fa --- /dev/null +++ b/tests/progs/slapd-common.c @@ -0,0 +1,78 @@ +/* $OpenLDAP$ */ +/* This work is part of OpenLDAP Software . + * + * Copyright 1999-2006 The OpenLDAP Foundation. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted only as authorized by the OpenLDAP + * Public License. + * + * A copy of this license is available in file LICENSE in the + * top-level directory of the distribution or, alternatively, at + * . + */ +/* ACKNOWLEDGEMENTS: + * This work was initially developed by Howard Chu for inclusion + * in OpenLDAP Software. + */ + +#include "portable.h" + +#include + +#include +#include +#include +#include + +#include + +static char progname[ BUFSIZ ]; + +void +tester_init( const char *pname ) +{ + snprintf( progname, sizeof( progname ), "%s PID=%d", pname, getpid() ); +} + +char * +tester_uri( char *uri, char *host, int port ) +{ + static char uribuf[ BUFSIZ ]; + + if ( uri != NULL ) { + return uri; + } + + snprintf( uribuf, sizeof( uribuf ), "ldap://%s:%d", host, port ); + + return uribuf; +} + +void +tester_ldap_error( LDAP *ld, const char *fname ) +{ + int err; + const char *text = "Success"; + + ldap_get_option( ld, LDAP_OPT_RESULT_CODE, (void *)&err ); + if ( err != LDAP_SUCCESS ) { + ldap_get_option( ld, LDAP_OPT_ERROR_STRING, (void *)&text ); + } + + fprintf( stderr, "%s: %s: (%d) %s\n", + progname, fname, err, text == NULL ? "" : text ); +} + +void +tester_perror( const char *fname ) +{ + int save_errno = errno; + char buf[ BUFSIZ ]; + + fprintf( stderr, "%s: %s: (%d) %s\n", + progname, fname, save_errno, + AC_STRERROR_R( save_errno, buf, sizeof( buf ) ) ); +} + diff --git a/tests/progs/slapd-common.h b/tests/progs/slapd-common.h new file mode 100644 index 0000000000..156077f754 --- /dev/null +++ b/tests/progs/slapd-common.h @@ -0,0 +1,28 @@ +/* $OpenLDAP$ */ +/* This work is part of OpenLDAP Software . + * + * Copyright 1999-2006 The OpenLDAP Foundation. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted only as authorized by the OpenLDAP + * Public License. + * + * A copy of this license is available in file LICENSE in the + * top-level directory of the distribution or, alternatively, at + * . + */ +/* ACKNOWLEDGEMENTS: + * This work was initially developed by Howard Chu for inclusion + * in OpenLDAP Software. + */ + +#ifndef SLAPD_COMMON_H +#define SLAPD_COMMON_H + +extern void tester_init( const char *pname ); +extern char * tester_uri( char *uri, char *host, int port ); +extern void tester_perror( const char *fname ); +extern void tester_ldap_error( LDAP *ld, const char *fname ); + +#endif /* SLAPD_COMMON_H */ diff --git a/tests/progs/slapd-modify.c b/tests/progs/slapd-modify.c index 7d1aaf3311..510571c914 100644 --- a/tests/progs/slapd-modify.c +++ b/tests/progs/slapd-modify.c @@ -26,15 +26,16 @@ #include #include -#define LDAP_DEPRECATED 1 #include #include +#include "slapd-common.h" + #define LOOPS 100 #define RETRIES 0 static void -do_modify( char *uri, char *host, int port, char *manager, char *passwd, +do_modify( char *uri, char *manager, struct berval *passwd, char *entry, char *attr, char *value, int maxloop, int maxretries, int delay, int friendly ); @@ -64,7 +65,7 @@ main( int argc, char **argv ) char *host = "localhost"; int port = -1; char *manager = NULL; - char *passwd = NULL; + struct berval passwd = { 0, NULL }; char *entry = NULL; char *ava = NULL; char *value = NULL; @@ -73,6 +74,8 @@ main( int argc, char **argv ) int delay = 0; int friendly = 0; + tester_init( "slapd-modify" ); + while ( (i = getopt( argc, argv, "FH:h:p:D:w:e:a:l:r:t:" )) != EOF ) { switch( i ) { case 'F': @@ -98,7 +101,8 @@ main( int argc, char **argv ) break; case 'w': /* the server managers password */ - passwd = strdup( optarg ); + passwd.bv_val = strdup( optarg ); + passwd.bv_len = strlen( optarg ); break; case 'e': /* entry to modify */ @@ -158,15 +162,17 @@ main( int argc, char **argv ) while ( *value && isspace( (unsigned char) *value )) value++; - do_modify( uri, host, port, manager, passwd, entry, ava, value, + uri = tester_uri( uri, host, port ); + + do_modify( uri, manager, &passwd, entry, ava, value, loops, retries, delay, friendly ); exit( EXIT_SUCCESS ); } static void -do_modify( char *uri, char *host, int port, char *manager, - char *passwd, char *entry, char* attr, char* value, +do_modify( char *uri, char *manager, + struct berval *passwd, char *entry, char* attr, char* value, int maxloop, int maxretries, int delay, int friendly ) { LDAP *ld = NULL; @@ -189,13 +195,9 @@ do_modify( char *uri, char *host, int port, char *manager, mods[1] = NULL; retry:; - if ( uri ) { - ldap_initialize( &ld, uri ); - } else { - ld = ldap_init( host, port ); - } + ldap_initialize( &ld, uri ); if ( ld == NULL ) { - perror( "ldap_init" ); + tester_perror( "ldap_initialize" ); exit( EXIT_FAILURE ); } @@ -210,9 +212,9 @@ retry:; (long) pid, maxloop, entry ); } - rc = ldap_bind_s( ld, manager, passwd, LDAP_AUTH_SIMPLE ); + rc = ldap_sasl_bind_s( ld, manager, LDAP_SASL_SIMPLE, passwd, NULL, NULL, NULL ); if ( rc != LDAP_SUCCESS ) { - ldap_perror( ld, "ldap_bind" ); + tester_ldap_error( ld, "ldap_sasl_bind_s" ); switch ( rc ) { case LDAP_BUSY: case LDAP_UNAVAILABLE: @@ -232,9 +234,9 @@ retry:; for ( ; i < maxloop; i++ ) { mod.mod_op = LDAP_MOD_ADD; - rc = ldap_modify_s( ld, entry, mods ); + rc = ldap_modify_ext_s( ld, entry, mods, NULL, NULL ); if ( rc != LDAP_SUCCESS ) { - ldap_perror( ld, "ldap_modify" ); + tester_ldap_error( ld, "ldap_modify_ext_s" ); switch ( rc ) { case LDAP_TYPE_OR_VALUE_EXISTS: /* NOTE: this likely means @@ -259,9 +261,9 @@ retry:; } mod.mod_op = LDAP_MOD_DELETE; - rc = ldap_modify_s( ld, entry, mods ); + rc = ldap_modify_ext_s( ld, entry, mods, NULL, NULL ); if ( rc != LDAP_SUCCESS ) { - ldap_perror( ld, "ldap_modify" ); + tester_ldap_error( ld, "ldap_modify_ext_s" ); switch ( rc ) { case LDAP_NO_SUCH_ATTRIBUTE: /* NOTE: this likely means @@ -290,7 +292,7 @@ retry:; done:; fprintf( stderr, " PID=%ld - Modify done (%d).\n", (long) pid, rc ); - ldap_unbind( ld ); + ldap_unbind_ext( ld, NULL, NULL ); } diff --git a/tests/progs/slapd-modrdn.c b/tests/progs/slapd-modrdn.c index f15fd4e8ac..8695e172a4 100644 --- a/tests/progs/slapd-modrdn.c +++ b/tests/progs/slapd-modrdn.c @@ -30,15 +30,16 @@ #include #include -#define LDAP_DEPRECATED 1 #include #include +#include "slapd-common.h" + #define LOOPS 100 #define RETRIES 0 static void -do_modrdn( char *uri, char *host, int port, char *manager, char *passwd, +do_modrdn( char *uri, char *manager, struct berval *passwd, char *entry, int maxloop, int maxretries, int delay, int friendly ); @@ -67,13 +68,15 @@ main( int argc, char **argv ) char *host = "localhost"; int port = -1; char *manager = NULL; - char *passwd = NULL; + struct berval passwd = { 0, NULL }; char *entry = NULL; int loops = LOOPS; int retries = RETRIES; int delay = 0; int friendly = 0; + tester_init( "slapd-modrdn" ); + while ( (i = getopt( argc, argv, "FH:h:p:D:w:e:l:r:t:" )) != EOF ) { switch( i ) { case 'F': @@ -99,7 +102,8 @@ main( int argc, char **argv ) break; case 'w': /* the server managers password */ - passwd = strdup( optarg ); + passwd.bv_val = strdup( optarg ); + passwd.bv_len = strlen( optarg ); break; case 'e': /* entry to rename */ @@ -141,73 +145,64 @@ main( int argc, char **argv ) } - do_modrdn( uri, host, port, manager, passwd, entry, + uri = tester_uri( uri, host, port ); + + do_modrdn( uri, manager, &passwd, entry, loops, retries, delay, friendly ); exit( EXIT_SUCCESS ); } static void -do_modrdn( char *uri, char *host, int port, char *manager, - char *passwd, char *entry, int maxloop, int maxretries, int delay, +do_modrdn( char *uri, char *manager, + struct berval *passwd, char *entry, int maxloop, int maxretries, int delay, int friendly ) { LDAP *ld = NULL; int i = 0, do_retry = maxretries; pid_t pid; - char *DNs[2]; - char *rdns[2]; - int rc = LDAP_SUCCESS; - + char *DNs[2]; + char *rdns[2]; + int rc = LDAP_SUCCESS; + char *p1, *p2; + int version = LDAP_VERSION3; pid = getpid(); DNs[0] = entry; DNs[1] = strdup( entry ); /* reverse the RDN, make new DN */ - { - char *p1, *p2; - - p1 = strchr( entry, '=' ) + 1; - p2 = strchr( p1, ',' ); - - *p2 = '\0'; - rdns[1] = strdup( entry ); - *p2-- = ','; - - for (i = p1 - entry;p2 >= p1;) - DNs[1][i++] = *p2--; - - DNs[1][i] = '\0'; - rdns[0] = strdup( DNs[1] ); - DNs[1][i] = ','; - } + p1 = strchr( entry, '=' ) + 1; + p2 = strchr( p1, ',' ); + + *p2 = '\0'; + rdns[1] = strdup( entry ); + *p2-- = ','; + + for (i = p1 - entry;p2 >= p1;) + DNs[1][i++] = *p2--; + + DNs[1][i] = '\0'; + rdns[0] = strdup( DNs[1] ); + DNs[1][i] = ','; retry:; - if ( uri ) { - ldap_initialize( &ld, uri ); - } else { - ld = ldap_init( host, port ); - } + ldap_initialize( &ld, uri ); if ( ld == NULL ) { - perror( "ldap_init" ); + tester_perror( "ldap_initialize" ); exit( EXIT_FAILURE ); } - { - int version = LDAP_VERSION3; - (void) ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, - &version ); - } + (void) ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &version ); if ( do_retry == maxretries ) { fprintf( stderr, "PID=%ld - Modrdn(%d): entry=\"%s\".\n", (long) pid, maxloop, entry ); } - rc = ldap_bind_s( ld, manager, passwd, LDAP_AUTH_SIMPLE ); + rc = ldap_sasl_bind_s( ld, manager, LDAP_SASL_SIMPLE, passwd, NULL, NULL, NULL ); if ( rc != LDAP_SUCCESS ) { - ldap_perror( ld, "ldap_bind" ); + tester_ldap_error( ld, "ldap_sasl_bind_s" ); switch ( rc ) { case LDAP_BUSY: case LDAP_UNAVAILABLE: @@ -226,9 +221,9 @@ retry:; } for ( ; i < maxloop; i++ ) { - rc = ldap_modrdn2_s( ld, DNs[0], rdns[0], 0 ); + rc = ldap_rename_s( ld, DNs[0], rdns[0], NULL, 0, NULL, NULL ); if ( rc != LDAP_SUCCESS ) { - ldap_perror( ld, "ldap_modrdn" ); + tester_ldap_error( ld, "ldap_rename_s" ); switch ( rc ) { case LDAP_NO_SUCH_OBJECT: /* NOTE: this likely means @@ -251,9 +246,9 @@ retry:; goto done; } } - rc = ldap_modrdn2_s( ld, DNs[1], rdns[1], 1 ); + rc = ldap_rename_s( ld, DNs[1], rdns[1], NULL, 1, NULL, NULL ); if ( rc != LDAP_SUCCESS ) { - ldap_perror( ld, "ldap_modrdn" ); + tester_ldap_error( ld, "ldap_rename_s" ); switch ( rc ) { case LDAP_NO_SUCH_OBJECT: /* NOTE: this likely means @@ -281,7 +276,7 @@ retry:; done:; fprintf( stderr, " PID=%ld - Modrdn done (%d).\n", (long) pid, rc ); - ldap_unbind( ld ); + ldap_unbind_ext( ld, NULL, NULL ); } diff --git a/tests/progs/slapd-read.c b/tests/progs/slapd-read.c index 92efc6b6f1..6d5858d4e5 100644 --- a/tests/progs/slapd-read.c +++ b/tests/progs/slapd-read.c @@ -30,15 +30,16 @@ #include #include -#define LDAP_DEPRECATED 1 #include #include +#include "slapd-common.h" + #define LOOPS 100 #define RETRIES 0 static void -do_read( char *uri, char *host, int port, char *entry, int maxloop, +do_read( char *uri, char *entry, int maxloop, int maxretries, int delay ); static void @@ -67,6 +68,8 @@ main( int argc, char **argv ) int retries = RETRIES; int delay = 0; + tester_init( "slapd-read" ); + while ( (i = getopt( argc, argv, "H:h:p:e:l:r:t:" )) != EOF ) { switch( i ) { case 'H': /* the server uri */ @@ -120,13 +123,15 @@ main( int argc, char **argv ) exit( EXIT_FAILURE ); } - do_read( uri, host, port, entry, ( 20 * loops ), retries, delay ); + uri = tester_uri( uri, host, port ); + + do_read( uri, entry, ( 20 * loops ), retries, delay ); exit( EXIT_SUCCESS ); } static void -do_read( char *uri, char *host, int port, char *entry, int maxloop, +do_read( char *uri, char *entry, int maxloop, int maxretries, int delay ) { LDAP *ld = NULL; @@ -134,32 +139,26 @@ do_read( char *uri, char *host, int port, char *entry, int maxloop, char *attrs[] = { "1.1", NULL }; pid_t pid = getpid(); int rc = LDAP_SUCCESS; + int version = LDAP_VERSION3; + struct berval passwd = { 0, "" }; retry:; - if ( uri ) { - ldap_initialize( &ld, uri ); - } else { - ld = ldap_init( host, port ); - } + ldap_initialize( &ld, uri ); if ( ld == NULL ) { - perror( "ldap_init" ); + tester_perror( "ldap_initialize" ); exit( EXIT_FAILURE ); } - { - int version = LDAP_VERSION3; - (void) ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, - &version ); - } + (void) ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &version ); if ( do_retry == maxretries ) { fprintf( stderr, "PID=%ld - Read(%d): entry=\"%s\".\n", (long) pid, maxloop, entry ); } - rc = ldap_bind_s( ld, NULL, NULL, LDAP_AUTH_SIMPLE ); + rc = ldap_sasl_bind_s( ld, NULL, LDAP_SASL_SIMPLE, &passwd, NULL, NULL, NULL ); if ( rc != LDAP_SUCCESS ) { - ldap_perror( ld, "ldap_bind" ); + tester_ldap_error( ld, "ldap_sasl_bind_s" ); switch ( rc ) { case LDAP_BUSY: case LDAP_UNAVAILABLE: @@ -180,10 +179,10 @@ retry:; for ( ; i < maxloop; i++ ) { LDAPMessage *res; - rc = ldap_search_s( ld, entry, LDAP_SCOPE_BASE, - NULL, attrs, 1, &res ); + rc = ldap_search_ext_s( ld, entry, LDAP_SCOPE_BASE, + NULL, attrs, 1, NULL, NULL, NULL, LDAP_NO_LIMIT, &res ); if ( rc != LDAP_SUCCESS ) { - ldap_perror( ld, "ldap_read" ); + tester_ldap_error( ld, "ldap_search_ext_s" ); if ( rc == LDAP_BUSY && do_retry > 0 ) { do_retry--; goto retry; @@ -198,6 +197,6 @@ retry:; fprintf( stderr, " PID=%ld - Read done (%d).\n", (long) pid, rc ); - ldap_unbind( ld ); + ldap_unbind_ext( ld, NULL, NULL ); } diff --git a/tests/progs/slapd-search.c b/tests/progs/slapd-search.c index 27dcca6563..9d66783ef4 100644 --- a/tests/progs/slapd-search.c +++ b/tests/progs/slapd-search.c @@ -30,15 +30,16 @@ #include #include -#define LDAP_DEPRECATED 1 #include #include +#include "slapd-common.h" + #define LOOPS 100 #define RETRIES 0 static void -do_search( char *uri, char *host, int port, char *manager, char *passwd, +do_search( char *uri, char *manager, struct berval *passwd, char *sbase, char *filter, int maxloop, int maxretries, int delay ); static void @@ -66,13 +67,15 @@ main( int argc, char **argv ) char *host = "localhost"; int port = -1; char *manager = NULL; - char *passwd = NULL; + struct berval passwd = { 0, NULL }; char *sbase = NULL; char *filter = NULL; int loops = LOOPS; int retries = RETRIES; int delay = 0; + tester_init( "slapd-search" ); + while ( (i = getopt( argc, argv, "b:D:f:H:h:l:p:w:r:t:" )) != EOF ) { switch( i ) { case 'H': /* the server uri */ @@ -94,7 +97,8 @@ main( int argc, char **argv ) break; case 'w': /* the server managers password */ - passwd = strdup( optarg ); + passwd.bv_val = strdup( optarg ); + passwd.bv_len = strlen( optarg ); break; case 'b': /* file with search base */ @@ -140,14 +144,16 @@ main( int argc, char **argv ) } - do_search( uri, host, port, manager, passwd, sbase, filter, + uri = tester_uri( uri, host, port ); + + do_search( uri, manager, &passwd, sbase, filter, ( 10 * loops ), retries, delay ); exit( EXIT_SUCCESS ); } static void -do_search( char *uri, char *host, int port, char *manager, char *passwd, +do_search( char *uri, char *manager, struct berval *passwd, char *sbase, char *filter, int maxloop, int maxretries, int delay ) { LDAP *ld = NULL; @@ -155,32 +161,25 @@ do_search( char *uri, char *host, int port, char *manager, char *passwd, char *attrs[] = { "cn", "sn", NULL }; pid_t pid = getpid(); int rc = LDAP_SUCCESS; + int version = LDAP_VERSION3; retry:; - if ( uri ) { - ldap_initialize( &ld, uri ); - } else { - ld = ldap_init( host, port ); - } + ldap_initialize( &ld, uri ); if ( ld == NULL ) { - perror( "ldap_init" ); + tester_perror( "ldap_initialize" ); exit( EXIT_FAILURE ); } - { - int version = LDAP_VERSION3; - (void) ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, - &version ); - } + (void) ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &version ); if ( do_retry == maxretries ) { fprintf( stderr, "PID=%ld - Search(%d): base=\"%s\", filter=\"%s\".\n", (long) pid, maxloop, sbase, filter ); } - rc = ldap_bind_s( ld, manager, passwd, LDAP_AUTH_SIMPLE ); + rc = ldap_sasl_bind_s( ld, manager, LDAP_SASL_SIMPLE, passwd, NULL, NULL, NULL ); if ( rc != LDAP_SUCCESS ) { - ldap_perror( ld, "ldap_bind" ); + tester_ldap_error( ld, "ldap_sasl_bind_s" ); switch ( rc ) { case LDAP_BUSY: case LDAP_UNAVAILABLE: @@ -202,10 +201,10 @@ retry:; for ( ; i < maxloop; i++ ) { LDAPMessage *res; - rc = ldap_search_s( ld, sbase, LDAP_SCOPE_SUBTREE, - filter, attrs, 0, &res ); + rc = ldap_search_ext_s( ld, sbase, LDAP_SCOPE_SUBTREE, + filter, attrs, 0, NULL, NULL, NULL, LDAP_NO_LIMIT, &res ); if ( rc != LDAP_SUCCESS ) { - ldap_perror( ld, "ldap_search" ); + tester_ldap_error( ld, "ldap_search_ext_s" ); if ( rc == LDAP_BUSY && do_retry > 0 ) { ldap_unbind_ext( ld, NULL, NULL ); do_retry--; diff --git a/tests/progs/slapd-tester.c b/tests/progs/slapd-tester.c index e0e4fab7fa..565b55ccc2 100644 --- a/tests/progs/slapd-tester.c +++ b/tests/progs/slapd-tester.c @@ -35,6 +35,8 @@ #include "ldap_defaults.h" #include "lutil.h" +#include "ldap.h" +#include "slapd-common.h" #define SEARCHCMD "slapd-search" #define READCMD "slapd-read" @@ -152,6 +154,8 @@ main( int argc, char **argv ) int banum; char bcmd[MAXPATHLEN]; + tester_init( "slapd-tester" ); + while ( (i = getopt( argc, argv, "D:d:FH:h:j:l:P:p:r:t:w:" )) != EOF ) { switch( i ) { case 'D': /* slapd manager */ @@ -616,14 +620,12 @@ fork_child( char *prog, char **args ) args = arg2; } #endif execvp( prog, args ); - fprintf( stderr, "%s: ", prog ); - perror( "execv" ); + tester_perror( "execvp" ); exit( EXIT_FAILURE ); break; case -1: /* trouble */ - fprintf( stderr, "Could not fork to run %s\n", prog ); - perror( "fork" ); + tester_perror( "fork" ); break; default: /* parent */ @@ -693,8 +695,7 @@ fork_child( char *prog, char **args ) rc = _spawnvp( _P_NOWAIT, prog, args ); if ( rc == -1 ) { - fprintf( stderr, "%s: ", prog ); - perror("spawnvp"); + tester_perror( "_spawnvp" ); } else { children[nkids++] = (HANDLE)rc; }