From 04c2de7cdc0bd1db49d9dfc15c2de01221f8c080 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Thu, 13 Feb 2003 08:02:40 +0000 Subject: [PATCH] Added support for "-H" arg with LDAP uri / ldap_initialize --- tests/progs/slapd-addel.c | 24 +++++++++++++------ tests/progs/slapd-read.c | 23 ++++++++++++------ tests/progs/slapd-search.c | 23 ++++++++++++------ tests/progs/slapd-tester.c | 48 +++++++++++++++++++++++++++----------- 4 files changed, 83 insertions(+), 35 deletions(-) diff --git a/tests/progs/slapd-addel.c b/tests/progs/slapd-addel.c index 881fb1d17a..2d7a16f948 100644 --- a/tests/progs/slapd-addel.c +++ b/tests/progs/slapd-addel.c @@ -24,7 +24,7 @@ static char * get_add_entry( char *filename, LDAPMod ***mods ); static void -do_addel( char *host, int port, char *manager, char *passwd, +do_addel( char *uri, char *host, int port, char *manager, char *passwd, char *dn, LDAPMod **attrs, int maxloop ); static void @@ -40,6 +40,7 @@ main( int argc, char **argv ) { int i; char *host = "localhost"; + char *uri = NULL; int port = -1; char *manager = NULL; char *passwd = NULL; @@ -48,8 +49,11 @@ main( int argc, char **argv ) int loops = LOOPS; LDAPMod **attrs = NULL; - while ( (i = getopt( argc, argv, "h:p:D:w:f:l:" )) != EOF ) { + while ( (i = getopt( argc, argv, "H:h:p:D:w:f:l:" )) != EOF ) { switch( i ) { + case 'H': /* the server's URI */ + uri = strdup( optarg ); + break; case 'h': /* the servers host */ host = strdup( optarg ); break; @@ -80,7 +84,7 @@ main( int argc, char **argv ) } } - if (( filename == NULL ) || ( port == -1 ) || + if (( filename == NULL ) || ( port == -1 && uri == NULL ) || ( manager == NULL ) || ( passwd == NULL )) usage( argv[0] ); @@ -101,7 +105,7 @@ main( int argc, char **argv ) } - do_addel( host, port, manager, passwd, entry, attrs, loops ); + do_addel( uri, host, port, manager, passwd, entry, attrs, loops ); exit( EXIT_SUCCESS ); } @@ -223,6 +227,7 @@ get_add_entry( char *filename, LDAPMod ***mods ) static void do_addel( + char *uri, char *host, int port, char *manager, @@ -232,11 +237,16 @@ do_addel( int maxloop ) { - LDAP *ld; + LDAP *ld = NULL; int i; pid_t pid = getpid(); - if (( ld = ldap_init( host, port )) == NULL ) { + if ( uri ) { + ldap_initialize( &ld, uri ); + } else { + ld = ldap_init( host, port ); + } + if ( ld == NULL ) { perror( "ldap_init" ); exit( EXIT_FAILURE ); } @@ -268,7 +278,7 @@ do_addel( } /* wait a second for the add to really complete */ - sleep( 1 ); + /* sleep( 1 ); */ /* now delete the entry again */ if ( ldap_delete_s( ld, entry ) != LDAP_SUCCESS ) { diff --git a/tests/progs/slapd-read.c b/tests/progs/slapd-read.c index c3c27dea70..7acb5fb8f4 100644 --- a/tests/progs/slapd-read.c +++ b/tests/progs/slapd-read.c @@ -21,7 +21,7 @@ #define LOOPS 100 static void -do_read( char *host, int port, char *entry, int maxloop ); +do_read( char *uri, char *host, int port, char *entry, int maxloop ); static void usage( char *name ) @@ -35,13 +35,17 @@ int main( int argc, char **argv ) { int i; + char *uri = NULL; char *host = "localhost"; int port = -1; char *entry = NULL; int loops = LOOPS; - while ( (i = getopt( argc, argv, "h:p:e:l:" )) != EOF ) { + while ( (i = getopt( argc, argv, "H:h:p:e:l:" )) != EOF ) { switch( i ) { + case 'H': /* the server uri */ + uri = strdup( optarg ); + break; case 'h': /* the servers host */ host = strdup( optarg ); break; @@ -64,7 +68,7 @@ main( int argc, char **argv ) } } - if (( entry == NULL ) || ( port == -1 )) + if (( entry == NULL ) || ( port == -1 && uri == NULL )) usage( argv[0] ); if ( *entry == '\0' ) { @@ -75,20 +79,25 @@ main( int argc, char **argv ) } - do_read( host, port, entry, ( 20 * loops )); + do_read( uri, host, port, entry, ( 20 * loops )); exit( EXIT_SUCCESS ); } static void -do_read( char *host, int port, char *entry, int maxloop ) +do_read( char *uri, char *host, int port, char *entry, int maxloop ) { - LDAP *ld; + LDAP *ld = NULL; int i; char *attrs[] = { "1.1", NULL }; pid_t pid = getpid(); - if (( ld = ldap_init( host, port )) == NULL ) { + if ( uri ) { + ldap_initialize( &ld, uri ); + } else { + ld = ldap_init( host, port ); + } + if ( ld == NULL ) { perror( "ldap_init" ); exit( EXIT_FAILURE ); } diff --git a/tests/progs/slapd-search.c b/tests/progs/slapd-search.c index 2febfdd395..5830a01cae 100644 --- a/tests/progs/slapd-search.c +++ b/tests/progs/slapd-search.c @@ -22,7 +22,7 @@ #define LOOPS 100 static void -do_search( char *host, int port, char *sbase, char *filter, int maxloop ); +do_search( char *uri, char *host, int port, char *sbase, char *filter, int maxloop ); static void usage( char *name ) @@ -36,14 +36,18 @@ int main( int argc, char **argv ) { int i; + char *uri = NULL; char *host = "localhost"; int port = -1; char *sbase = NULL; char *filter = NULL; int loops = LOOPS; - while ( (i = getopt( argc, argv, "h:p:b:f:l:" )) != EOF ) { + while ( (i = getopt( argc, argv, "H:h:p:b:f:l:" )) != EOF ) { switch( i ) { + case 'H': /* the server uri */ + uri = strdup( optarg ); + break; case 'h': /* the servers host */ host = strdup( optarg ); break; @@ -70,7 +74,7 @@ main( int argc, char **argv ) } } - if (( sbase == NULL ) || ( filter == NULL ) || ( port == -1 )) + if (( sbase == NULL ) || ( filter == NULL ) || ( port == -1 && uri == NULL )) usage( argv[0] ); if ( *filter == '\0' ) { @@ -81,20 +85,25 @@ main( int argc, char **argv ) } - do_search( host, port, sbase, filter, ( 10 * loops )); + do_search( uri, host, port, sbase, filter, ( 10 * loops )); exit( EXIT_SUCCESS ); } static void -do_search( char *host, int port, char *sbase, char *filter, int maxloop ) +do_search( char *uri, char *host, int port, char *sbase, char *filter, int maxloop ) { - LDAP *ld; + LDAP *ld = NULL; int i; char *attrs[] = { "cn", "sn", NULL }; pid_t pid = getpid(); - if (( ld = ldap_init( host, port )) == NULL ) { + if ( uri ) { + ldap_initialize( &ld, uri ); + } else { + ld = ldap_init( host, port ); + } + if ( ld == NULL ) { perror( "ldap_init" ); exit( EXIT_FAILURE ); } diff --git a/tests/progs/slapd-tester.c b/tests/progs/slapd-tester.c index c33ce60061..f14c92ea0b 100644 --- a/tests/progs/slapd-tester.c +++ b/tests/progs/slapd-tester.c @@ -60,6 +60,7 @@ int main( int argc, char **argv ) { int i, j; + char *uri = NULL; char *host = "localhost"; char *port = NULL; char *manager = NULL; @@ -88,8 +89,12 @@ main( int argc, char **argv ) int aanum; char acmd[MAXPATHLEN]; - while ( (i = getopt( argc, argv, "h:p:D:w:b:d:j:l:P:" )) != EOF ) { + while ( (i = getopt( argc, argv, "H:h:p:D:w:b:d:j:l:P:" )) != EOF ) { switch( i ) { + case 'H': /* slapd uri */ + uri = strdup( optarg ); + break; + case 'h': /* slapd host */ host = strdup( optarg ); break; @@ -132,7 +137,7 @@ main( int argc, char **argv ) } } - if (( dirname == NULL ) || ( sbase == NULL ) || ( port == NULL ) || + if (( dirname == NULL ) || ( sbase == NULL ) || ( port == NULL && uri == NULL ) || ( manager == NULL ) || ( passwd == NULL ) || ( progdir == NULL )) usage( argv[0] ); @@ -184,10 +189,15 @@ main( int argc, char **argv ) snprintf( scmd, sizeof scmd, "%s" LDAP_DIRSEP SEARCHCMD, progdir ); sargs[sanum++] = scmd; - sargs[sanum++] = "-h"; - sargs[sanum++] = host; - sargs[sanum++] = "-p"; - sargs[sanum++] = port; + if ( uri ) { + sargs[sanum++] = "-H"; + sargs[sanum++] = uri; + } else { + sargs[sanum++] = "-h"; + sargs[sanum++] = host; + sargs[sanum++] = "-p"; + sargs[sanum++] = port; + } sargs[sanum++] = "-b"; sargs[sanum++] = sbase; sargs[sanum++] = "-l"; @@ -204,10 +214,15 @@ main( int argc, char **argv ) snprintf( rcmd, sizeof rcmd, "%s" LDAP_DIRSEP READCMD, progdir ); rargs[ranum++] = rcmd; - rargs[ranum++] = "-h"; - rargs[ranum++] = host; - rargs[ranum++] = "-p"; - rargs[ranum++] = port; + if ( uri ) { + rargs[ranum++] = "-H"; + rargs[ranum++] = uri; + } else { + rargs[ranum++] = "-h"; + rargs[ranum++] = host; + rargs[ranum++] = "-p"; + rargs[ranum++] = port; + } rargs[ranum++] = "-l"; rargs[ranum++] = loops; rargs[ranum++] = "-e"; @@ -222,10 +237,15 @@ main( int argc, char **argv ) snprintf( acmd, sizeof acmd, "%s" LDAP_DIRSEP ADDCMD, progdir ); aargs[aanum++] = acmd; - aargs[aanum++] = "-h"; - aargs[aanum++] = host; - aargs[aanum++] = "-p"; - aargs[aanum++] = port; + if ( uri ) { + aargs[aanum++] = "-H"; + aargs[aanum++] = uri; + } else { + aargs[aanum++] = "-h"; + aargs[aanum++] = host; + aargs[aanum++] = "-p"; + aargs[aanum++] = port; + } aargs[aanum++] = "-D"; aargs[aanum++] = manager; aargs[aanum++] = "-w"; -- 2.39.5