mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-12-21 15:19:34 -05:00
Added support for "-H" arg with LDAP uri / ldap_initialize
This commit is contained in:
parent
262d021ecf
commit
04c2de7cdc
4 changed files with 83 additions and 35 deletions
|
|
@ -24,7 +24,7 @@ static char *
|
||||||
get_add_entry( char *filename, LDAPMod ***mods );
|
get_add_entry( char *filename, LDAPMod ***mods );
|
||||||
|
|
||||||
static void
|
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 );
|
char *dn, LDAPMod **attrs, int maxloop );
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -40,6 +40,7 @@ main( int argc, char **argv )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char *host = "localhost";
|
char *host = "localhost";
|
||||||
|
char *uri = NULL;
|
||||||
int port = -1;
|
int port = -1;
|
||||||
char *manager = NULL;
|
char *manager = NULL;
|
||||||
char *passwd = NULL;
|
char *passwd = NULL;
|
||||||
|
|
@ -48,8 +49,11 @@ main( int argc, char **argv )
|
||||||
int loops = LOOPS;
|
int loops = LOOPS;
|
||||||
LDAPMod **attrs = NULL;
|
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 ) {
|
switch( i ) {
|
||||||
|
case 'H': /* the server's URI */
|
||||||
|
uri = strdup( optarg );
|
||||||
|
break;
|
||||||
case 'h': /* the servers host */
|
case 'h': /* the servers host */
|
||||||
host = strdup( optarg );
|
host = strdup( optarg );
|
||||||
break;
|
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 ))
|
( manager == NULL ) || ( passwd == NULL ))
|
||||||
usage( argv[0] );
|
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 );
|
exit( EXIT_SUCCESS );
|
||||||
}
|
}
|
||||||
|
|
@ -223,6 +227,7 @@ get_add_entry( char *filename, LDAPMod ***mods )
|
||||||
|
|
||||||
static void
|
static void
|
||||||
do_addel(
|
do_addel(
|
||||||
|
char *uri,
|
||||||
char *host,
|
char *host,
|
||||||
int port,
|
int port,
|
||||||
char *manager,
|
char *manager,
|
||||||
|
|
@ -232,11 +237,16 @@ do_addel(
|
||||||
int maxloop
|
int maxloop
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
LDAP *ld;
|
LDAP *ld = NULL;
|
||||||
int i;
|
int i;
|
||||||
pid_t pid = getpid();
|
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" );
|
perror( "ldap_init" );
|
||||||
exit( EXIT_FAILURE );
|
exit( EXIT_FAILURE );
|
||||||
}
|
}
|
||||||
|
|
@ -268,7 +278,7 @@ do_addel(
|
||||||
}
|
}
|
||||||
|
|
||||||
/* wait a second for the add to really complete */
|
/* wait a second for the add to really complete */
|
||||||
sleep( 1 );
|
/* sleep( 1 ); */
|
||||||
|
|
||||||
/* now delete the entry again */
|
/* now delete the entry again */
|
||||||
if ( ldap_delete_s( ld, entry ) != LDAP_SUCCESS ) {
|
if ( ldap_delete_s( ld, entry ) != LDAP_SUCCESS ) {
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
#define LOOPS 100
|
#define LOOPS 100
|
||||||
|
|
||||||
static void
|
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
|
static void
|
||||||
usage( char *name )
|
usage( char *name )
|
||||||
|
|
@ -35,13 +35,17 @@ int
|
||||||
main( int argc, char **argv )
|
main( int argc, char **argv )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
char *uri = NULL;
|
||||||
char *host = "localhost";
|
char *host = "localhost";
|
||||||
int port = -1;
|
int port = -1;
|
||||||
char *entry = NULL;
|
char *entry = NULL;
|
||||||
int loops = LOOPS;
|
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 ) {
|
switch( i ) {
|
||||||
|
case 'H': /* the server uri */
|
||||||
|
uri = strdup( optarg );
|
||||||
|
break;
|
||||||
case 'h': /* the servers host */
|
case 'h': /* the servers host */
|
||||||
host = strdup( optarg );
|
host = strdup( optarg );
|
||||||
break;
|
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] );
|
usage( argv[0] );
|
||||||
|
|
||||||
if ( *entry == '\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 );
|
exit( EXIT_SUCCESS );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
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;
|
int i;
|
||||||
char *attrs[] = { "1.1", NULL };
|
char *attrs[] = { "1.1", NULL };
|
||||||
pid_t pid = getpid();
|
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" );
|
perror( "ldap_init" );
|
||||||
exit( EXIT_FAILURE );
|
exit( EXIT_FAILURE );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@
|
||||||
#define LOOPS 100
|
#define LOOPS 100
|
||||||
|
|
||||||
static void
|
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
|
static void
|
||||||
usage( char *name )
|
usage( char *name )
|
||||||
|
|
@ -36,14 +36,18 @@ int
|
||||||
main( int argc, char **argv )
|
main( int argc, char **argv )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
char *uri = NULL;
|
||||||
char *host = "localhost";
|
char *host = "localhost";
|
||||||
int port = -1;
|
int port = -1;
|
||||||
char *sbase = NULL;
|
char *sbase = NULL;
|
||||||
char *filter = NULL;
|
char *filter = NULL;
|
||||||
int loops = LOOPS;
|
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 ) {
|
switch( i ) {
|
||||||
|
case 'H': /* the server uri */
|
||||||
|
uri = strdup( optarg );
|
||||||
|
break;
|
||||||
case 'h': /* the servers host */
|
case 'h': /* the servers host */
|
||||||
host = strdup( optarg );
|
host = strdup( optarg );
|
||||||
break;
|
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] );
|
usage( argv[0] );
|
||||||
|
|
||||||
if ( *filter == '\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 );
|
exit( EXIT_SUCCESS );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
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;
|
int i;
|
||||||
char *attrs[] = { "cn", "sn", NULL };
|
char *attrs[] = { "cn", "sn", NULL };
|
||||||
pid_t pid = getpid();
|
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" );
|
perror( "ldap_init" );
|
||||||
exit( EXIT_FAILURE );
|
exit( EXIT_FAILURE );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,7 @@ int
|
||||||
main( int argc, char **argv )
|
main( int argc, char **argv )
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
|
char *uri = NULL;
|
||||||
char *host = "localhost";
|
char *host = "localhost";
|
||||||
char *port = NULL;
|
char *port = NULL;
|
||||||
char *manager = NULL;
|
char *manager = NULL;
|
||||||
|
|
@ -88,8 +89,12 @@ main( int argc, char **argv )
|
||||||
int aanum;
|
int aanum;
|
||||||
char acmd[MAXPATHLEN];
|
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 ) {
|
switch( i ) {
|
||||||
|
case 'H': /* slapd uri */
|
||||||
|
uri = strdup( optarg );
|
||||||
|
break;
|
||||||
|
|
||||||
case 'h': /* slapd host */
|
case 'h': /* slapd host */
|
||||||
host = strdup( optarg );
|
host = strdup( optarg );
|
||||||
break;
|
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 ))
|
( manager == NULL ) || ( passwd == NULL ) || ( progdir == NULL ))
|
||||||
usage( argv[0] );
|
usage( argv[0] );
|
||||||
|
|
||||||
|
|
@ -184,10 +189,15 @@ main( int argc, char **argv )
|
||||||
snprintf( scmd, sizeof scmd, "%s" LDAP_DIRSEP SEARCHCMD,
|
snprintf( scmd, sizeof scmd, "%s" LDAP_DIRSEP SEARCHCMD,
|
||||||
progdir );
|
progdir );
|
||||||
sargs[sanum++] = scmd;
|
sargs[sanum++] = scmd;
|
||||||
|
if ( uri ) {
|
||||||
|
sargs[sanum++] = "-H";
|
||||||
|
sargs[sanum++] = uri;
|
||||||
|
} else {
|
||||||
sargs[sanum++] = "-h";
|
sargs[sanum++] = "-h";
|
||||||
sargs[sanum++] = host;
|
sargs[sanum++] = host;
|
||||||
sargs[sanum++] = "-p";
|
sargs[sanum++] = "-p";
|
||||||
sargs[sanum++] = port;
|
sargs[sanum++] = port;
|
||||||
|
}
|
||||||
sargs[sanum++] = "-b";
|
sargs[sanum++] = "-b";
|
||||||
sargs[sanum++] = sbase;
|
sargs[sanum++] = sbase;
|
||||||
sargs[sanum++] = "-l";
|
sargs[sanum++] = "-l";
|
||||||
|
|
@ -204,10 +214,15 @@ main( int argc, char **argv )
|
||||||
snprintf( rcmd, sizeof rcmd, "%s" LDAP_DIRSEP READCMD,
|
snprintf( rcmd, sizeof rcmd, "%s" LDAP_DIRSEP READCMD,
|
||||||
progdir );
|
progdir );
|
||||||
rargs[ranum++] = rcmd;
|
rargs[ranum++] = rcmd;
|
||||||
|
if ( uri ) {
|
||||||
|
rargs[ranum++] = "-H";
|
||||||
|
rargs[ranum++] = uri;
|
||||||
|
} else {
|
||||||
rargs[ranum++] = "-h";
|
rargs[ranum++] = "-h";
|
||||||
rargs[ranum++] = host;
|
rargs[ranum++] = host;
|
||||||
rargs[ranum++] = "-p";
|
rargs[ranum++] = "-p";
|
||||||
rargs[ranum++] = port;
|
rargs[ranum++] = port;
|
||||||
|
}
|
||||||
rargs[ranum++] = "-l";
|
rargs[ranum++] = "-l";
|
||||||
rargs[ranum++] = loops;
|
rargs[ranum++] = loops;
|
||||||
rargs[ranum++] = "-e";
|
rargs[ranum++] = "-e";
|
||||||
|
|
@ -222,10 +237,15 @@ main( int argc, char **argv )
|
||||||
snprintf( acmd, sizeof acmd, "%s" LDAP_DIRSEP ADDCMD,
|
snprintf( acmd, sizeof acmd, "%s" LDAP_DIRSEP ADDCMD,
|
||||||
progdir );
|
progdir );
|
||||||
aargs[aanum++] = acmd;
|
aargs[aanum++] = acmd;
|
||||||
|
if ( uri ) {
|
||||||
|
aargs[aanum++] = "-H";
|
||||||
|
aargs[aanum++] = uri;
|
||||||
|
} else {
|
||||||
aargs[aanum++] = "-h";
|
aargs[aanum++] = "-h";
|
||||||
aargs[aanum++] = host;
|
aargs[aanum++] = host;
|
||||||
aargs[aanum++] = "-p";
|
aargs[aanum++] = "-p";
|
||||||
aargs[aanum++] = port;
|
aargs[aanum++] = port;
|
||||||
|
}
|
||||||
aargs[aanum++] = "-D";
|
aargs[aanum++] = "-D";
|
||||||
aargs[aanum++] = manager;
|
aargs[aanum++] = manager;
|
||||||
aargs[aanum++] = "-w";
|
aargs[aanum++] = "-w";
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue