From df7f9db8ac49e45a8fe582b3209d98cd1b961b73 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Mon, 13 Aug 2007 16:20:24 +0000 Subject: [PATCH] use URI to configure client; enable attrlist in slapd-search --- tests/progs/slapd-addel.c | 18 ++-- tests/progs/slapd-bind.c | 30 +++---- tests/progs/slapd-common.c | 10 +-- tests/progs/slapd-modify.c | 18 ++-- tests/progs/slapd-modrdn.c | 18 ++-- tests/progs/slapd-read.c | 61 ++++++++----- tests/progs/slapd-search.c | 100 ++++++++++++++------- tests/progs/slapd-tester.c | 180 ++++++++++++++++++++++++++----------- 8 files changed, 282 insertions(+), 153 deletions(-) diff --git a/tests/progs/slapd-addel.c b/tests/progs/slapd-addel.c index a51e5aca0b..99499039d7 100644 --- a/tests/progs/slapd-addel.c +++ b/tests/progs/slapd-addel.c @@ -21,17 +21,17 @@ #include -#include +#include "ac/stdlib.h" -#include -#include -#include -#include -#include -#include +#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 -#include +#include "ldap.h" +#include "lutil.h" #include "slapd-common.h" diff --git a/tests/progs/slapd-bind.c b/tests/progs/slapd-bind.c index 21642137a0..4f1b1f2d5c 100644 --- a/tests/progs/slapd-bind.c +++ b/tests/progs/slapd-bind.c @@ -21,21 +21,21 @@ #include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include +#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 "ldap.h" +#include "lutil.h" +#include "lber_pvt.h" +#include "ldap_pvt.h" #include "slapd-common.h" diff --git a/tests/progs/slapd-common.c b/tests/progs/slapd-common.c index 7a4df27bfc..72bfebae11 100644 --- a/tests/progs/slapd-common.c +++ b/tests/progs/slapd-common.c @@ -21,12 +21,12 @@ #include -#include -#include -#include -#include +#include "ac/stdlib.h" +#include "ac/unistd.h" +#include "ac/string.h" +#include "ac/errno.h" -#include +#include "ldap.h" #include "ldap_pvt.h" #include "slapd-common.h" diff --git a/tests/progs/slapd-modify.c b/tests/progs/slapd-modify.c index ae639572db..4c20b1f5fc 100644 --- a/tests/progs/slapd-modify.c +++ b/tests/progs/slapd-modify.c @@ -17,17 +17,17 @@ #include -#include +#include "ac/stdlib.h" -#include -#include -#include -#include -#include -#include +#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 -#include +#include "ldap.h" +#include "lutil.h" #include "slapd-common.h" diff --git a/tests/progs/slapd-modrdn.c b/tests/progs/slapd-modrdn.c index d2646e4c24..b25c284910 100644 --- a/tests/progs/slapd-modrdn.c +++ b/tests/progs/slapd-modrdn.c @@ -21,17 +21,17 @@ #include -#include +#include "ac/stdlib.h" -#include -#include -#include -#include -#include -#include +#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 -#include +#include "ldap.h" +#include "lutil.h" #include "slapd-common.h" diff --git a/tests/progs/slapd-read.c b/tests/progs/slapd-read.c index dd5e692d07..e4e389ec0d 100644 --- a/tests/progs/slapd-read.c +++ b/tests/progs/slapd-read.c @@ -21,17 +21,19 @@ #include -#include +#include "ac/stdlib.h" -#include -#include -#include -#include -#include -#include +#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 -#include +#include "ldap.h" +#include "lutil.h" + +#include "ldap_pvt.h" #include "slapd-common.h" @@ -40,12 +42,13 @@ static void do_read( char *uri, char *manager, struct berval *passwd, - char *entry, LDAP **ld, int noattrs, int nobind, int maxloop, + char *entry, LDAP **ld, + char **attrs, int noattrs, int nobind, int maxloop, int maxretries, int delay, int force, int chaserefs ); static void do_random( char *uri, char *manager, struct berval *passwd, - char *sbase, char *filter, int noattrs, int nobind, + char *sbase, char *filter, char **attrs, int noattrs, int nobind, int innerloop, int maxretries, int delay, int force, int chaserefs ); static void @@ -66,7 +69,10 @@ usage( char *name ) "[-l ] " "[-L ] " "[-r ] " - "[-t ]\n", + "[-t ] " + "[-T ] " + "[] " + "\n", name ); exit( EXIT_FAILURE ); } @@ -88,6 +94,8 @@ main( int argc, char **argv ) int delay = 0; int force = 0; int chaserefs = 0; + char *srchattrs[] = { "1.1", NULL }; + char **attrs = srchattrs; int noattrs = 0; int nobind = 0; @@ -96,7 +104,7 @@ main( int argc, char **argv ) /* by default, tolerate referrals and no such object */ tester_ignore_str2errlist( "REFERRAL,NO_SUCH_OBJECT" ); - while ( (i = getopt( argc, argv, "ACD:e:Ff:H:h:i:L:l:p:r:t:w:" )) != EOF ) { + while ( (i = getopt( argc, argv, "ACD:e:Ff:H:h:i:L:l:p:r:t:T:w:" )) != EOF ) { switch ( i ) { case 'A': noattrs++; @@ -174,6 +182,13 @@ main( int argc, char **argv ) } break; + case 'T': + attrs = ldap_str2charray( optarg, "," ); + if ( attrs == NULL ) { + usage( argv[0] ); + } + break; + default: usage( argv[0] ); break; @@ -189,17 +204,22 @@ main( int argc, char **argv ) exit( EXIT_FAILURE ); } + if ( argv[optind] != NULL ) { + attrs = &argv[optind]; + } + uri = tester_uri( uri, host, port ); for ( i = 0; i < outerloops; i++ ) { if ( filter != NULL ) { - do_random( uri, manager, &passwd, entry, filter, + do_random( uri, manager, &passwd, entry, filter, attrs, noattrs, nobind, loops, retries, delay, force, chaserefs ); } else { - do_read( uri, manager, &passwd, entry, NULL, noattrs, nobind, - loops, retries, delay, force, chaserefs ); + do_read( uri, manager, &passwd, entry, NULL, attrs, + noattrs, nobind, loops, retries, delay, force, + chaserefs ); } } @@ -208,7 +228,7 @@ main( int argc, char **argv ) static void do_random( char *uri, char *manager, struct berval *passwd, - char *sbase, char *filter, int noattrs, int nobind, + char *sbase, char *filter, char **srchattrs, int noattrs, int nobind, int innerloop, int maxretries, int delay, int force, int chaserefs ) { LDAP *ld = NULL; @@ -288,8 +308,8 @@ do_random( char *uri, char *manager, struct berval *passwd, int r = ((double)nvalues)*rand()/(RAND_MAX + 1.0); do_read( uri, manager, passwd, values[ r ], &ld, - noattrs, nobind, 1, maxretries, delay, force, - chaserefs ); + srchattrs, noattrs, nobind, 1, maxretries, + delay, force, chaserefs ); } free( values ); break; @@ -308,12 +328,11 @@ do_random( char *uri, char *manager, struct berval *passwd, static void do_read( char *uri, char *manager, struct berval *passwd, char *entry, - LDAP **ldp, int noattrs, int nobind, int maxloop, + LDAP **ldp, char **attrs, int noattrs, int nobind, int maxloop, int maxretries, int delay, int force, int chaserefs ) { LDAP *ld = ldp ? *ldp : NULL; int i = 0, do_retry = maxretries; - char *attrs[] = { "1.1", NULL }; int rc = LDAP_SUCCESS; int version = LDAP_VERSION3; diff --git a/tests/progs/slapd-search.c b/tests/progs/slapd-search.c index afda1768b5..0428fef2b4 100644 --- a/tests/progs/slapd-search.c +++ b/tests/progs/slapd-search.c @@ -21,17 +21,18 @@ #include -#include +#include "ac/stdlib.h" -#include -#include -#include -#include -#include -#include +#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 -#include +#include "ldap.h" +#include "lutil.h" +#include "ldap_pvt.h" #include "slapd-common.h" @@ -40,23 +41,30 @@ static void do_search( char *uri, char *manager, struct berval *passwd, - char *sbase, char *filter, LDAP **ldp, int noattrs, int nobind, + char *sbase, int scope, char *filter, LDAP **ldp, + char **attrs, int noattrs, int nobind, int innerloop, int maxretries, int delay, int force, int chaserefs ); static void do_random( char *uri, char *manager, struct berval *passwd, - char *sbase, char *filter, char *attr, int noattrs, int nobind, + char *sbase, int scope, char *filter, char *attr, + char **attrs, int noattrs, int nobind, int innerloop, int maxretries, int delay, int force, int chaserefs ); static void -usage( char *name ) +usage( char *name, char o ) { + if ( o != '\0' ) { + fprintf( stderr, "unknown/incorrect option \"%c\"\n", o ); + } + fprintf( stderr, "usage: %s " "-H | ([-h ] -p ) " "-D " "-w " "-b " + "-s " "-f " "[-a ] " "[-A] " @@ -67,7 +75,9 @@ usage( char *name ) "[-l ] " "[-L ] " "[-r ] " - "[-t ]\n", + "[-t ] " + "[] " + "\n", name ); exit( EXIT_FAILURE ); } @@ -82,8 +92,11 @@ main( int argc, char **argv ) char *manager = NULL; struct berval passwd = { 0, NULL }; char *sbase = NULL; + int scope = LDAP_SCOPE_SUBTREE; char *filter = NULL; char *attr = NULL; + char *srchattrs[] = { "cn", "sn", NULL }; + char **attrs = srchattrs; int loops = LOOPS; int outerloops = 1; int retries = RETRIES; @@ -98,7 +111,7 @@ main( int argc, char **argv ) /* by default, tolerate referrals and no such object */ tester_ignore_str2errlist( "REFERRAL,NO_SUCH_OBJECT" ); - while ( ( i = getopt( argc, argv, "Aa:b:CD:f:FH:h:i:l:L:Np:r:t:w:" ) ) != EOF ) + while ( ( i = getopt( argc, argv, "Aa:b:CD:f:FH:h:i:l:L:Np:r:s:t:T:w:" ) ) != EOF ) { switch ( i ) { case 'A': @@ -127,7 +140,7 @@ main( int argc, char **argv ) case 'p': /* the servers port */ if ( lutil_atoi( &port, optarg ) != 0 ) { - usage( argv[0] ); + usage( argv[0], i ); } break; @@ -159,36 +172,50 @@ main( int argc, char **argv ) case 'l': /* number of loops */ if ( lutil_atoi( &loops, optarg ) != 0 ) { - usage( argv[0] ); + usage( argv[0], i ); } break; case 'L': /* number of loops */ if ( lutil_atoi( &outerloops, optarg ) != 0 ) { - usage( argv[0] ); + usage( argv[0], i ); } break; case 'r': /* number of retries */ if ( lutil_atoi( &retries, optarg ) != 0 ) { - usage( argv[0] ); + usage( argv[0], i ); } break; case 't': /* delay in seconds */ if ( lutil_atoi( &delay, optarg ) != 0 ) { - usage( argv[0] ); + usage( argv[0], i ); + } + break; + + case 'T': + attrs = ldap_str2charray( optarg, "," ); + if ( attrs == NULL ) { + usage( argv[0], i ); + } + break; + + case 's': + scope = ldap_pvt_str2scope( optarg ); + if ( scope == -1 ) { + usage( argv[0], i ); } break; default: - usage( argv[0] ); + usage( argv[0], i ); break; } } if (( sbase == NULL ) || ( filter == NULL ) || ( port == -1 && uri == NULL )) - usage( argv[0] ); + usage( argv[0], '\0' ); if ( *filter == '\0' ) { @@ -198,16 +225,24 @@ main( int argc, char **argv ) } + if ( argv[optind] != NULL ) { + attrs = &argv[optind]; + } + uri = tester_uri( uri, host, port ); for ( i = 0; i < outerloops; i++ ) { if ( attr != NULL ) { - do_random( uri, manager, &passwd, sbase, filter, attr, - noattrs, nobind, loops, retries, delay, force, chaserefs ); + do_random( uri, manager, &passwd, + sbase, scope, filter, attr, + attrs, noattrs, nobind, + loops, retries, delay, force, chaserefs ); } else { - do_search( uri, manager, &passwd, sbase, filter, NULL, - noattrs, nobind, loops, retries, delay, force, chaserefs ); + do_search( uri, manager, &passwd, + sbase, scope, filter, NULL, + attrs, noattrs, nobind, + loops, retries, delay, force, chaserefs ); } } @@ -217,7 +252,8 @@ main( int argc, char **argv ) static void do_random( char *uri, char *manager, struct berval *passwd, - char *sbase, char *filter, char *attr, int noattrs, int nobind, + char *sbase, int scope, char *filter, char *attr, + char **srchattrs, int noattrs, int nobind, int innerloop, int maxretries, int delay, int force, int chaserefs ) { LDAP *ld = NULL; @@ -315,8 +351,10 @@ do_random( char *uri, char *manager, struct berval *passwd, snprintf( buf, sizeof( buf ), "(%s=%s)", attr, values[ r ] ); - do_search( uri, manager, passwd, sbase, buf, &ld, noattrs, nobind, - 1, maxretries, delay, force, chaserefs ); + do_search( uri, manager, passwd, + sbase, scope, buf, &ld, + srchattrs, noattrs, nobind, + 1, maxretries, delay, force, chaserefs ); } break; @@ -334,12 +372,12 @@ do_random( char *uri, char *manager, struct berval *passwd, static void do_search( char *uri, char *manager, struct berval *passwd, - char *sbase, char *filter, LDAP **ldp, int noattrs, int nobind, + char *sbase, int scope, char *filter, LDAP **ldp, + char **attrs, int noattrs, int nobind, int innerloop, int maxretries, int delay, int force, int chaserefs ) { LDAP *ld = ldp ? *ldp : NULL; int i = 0, do_retry = maxretries; - char *attrs[] = { "cn", "sn", NULL }; int rc = LDAP_SUCCESS; int version = LDAP_VERSION3; char buf[ BUFSIZ ]; @@ -392,7 +430,7 @@ retry:; for ( ; i < innerloop; i++ ) { LDAPMessage *res = NULL; - rc = ldap_search_ext_s( ld, sbase, LDAP_SCOPE_SUBTREE, + rc = ldap_search_ext_s( ld, sbase, scope, filter, attrs, noattrs, NULL, NULL, NULL, LDAP_NO_LIMIT, &res ); if ( res != NULL ) { diff --git a/tests/progs/slapd-tester.c b/tests/progs/slapd-tester.c index 6cbc13fd10..43b8e0e1ed 100644 --- a/tests/progs/slapd-tester.c +++ b/tests/progs/slapd-tester.c @@ -21,15 +21,15 @@ #include -#include +#include "ac/stdlib.h" -#include -#include -#include -#include -#include -#include -#include +#include "ac/ctype.h" +#include "ac/dirent.h" +#include "ac/param.h" +#include "ac/socket.h" +#include "ac/string.h" +#include "ac/unistd.h" +#include "ac/wait.h" #include "ldap_defaults.h" @@ -60,7 +60,7 @@ #define TBINDFILE "do_bind.0" static char *get_file_name( char *dirname, char *filename ); -static int get_search_filters( char *filename, char *filters[], char *attrs[], char *bases[] ); +static int get_search_filters( char *filename, char *filters[], char *attrs[], char *bases[], LDAPURLDesc *luds[] ); static int get_read_entries( char *filename, char *entries[], char *filters[] ); static void fork_child( char *prog, char **args ); static void wait4kids( int nkidval ); @@ -133,9 +133,11 @@ main( int argc, char **argv ) char *sreqs[MAXREQS]; char *sattrs[MAXREQS]; char *sbase[MAXREQS]; + LDAPURLDesc *slud[MAXREQS]; int snum = 0; char *sargs[MAXARGS]; int sanum; + int sextra_args = 0; char scmd[MAXPATHLEN]; /* static so that its address can be used in initializer below. */ static char sloops[] = "18446744073709551615UL"; @@ -146,6 +148,7 @@ main( int argc, char **argv ) char *rargs[MAXARGS]; char *rflts[MAXREQS]; int ranum; + int rextra_args = 0; char rcmd[MAXPATHLEN]; static char rloops[] = "18446744073709551615UL"; /* addel */ @@ -414,7 +417,7 @@ main( int argc, char **argv ) /* look for search requests */ if ( sfile ) { - snum = get_search_filters( sfile, sreqs, sattrs, sbase ); + snum = get_search_filters( sfile, sreqs, sattrs, sbase, slud ); } /* look for read requests */ @@ -429,12 +432,12 @@ main( int argc, char **argv ) /* look for modify requests */ if ( mfile ) { - mnum = get_search_filters( mfile, mreqs, NULL, mdn ); + mnum = get_search_filters( mfile, mreqs, NULL, mdn, NULL ); } /* look for bind requests */ if ( bfile ) { - bnum = get_search_filters( bfile, bcreds, battrs, breqs ); + bnum = get_search_filters( bfile, bcreds, battrs, breqs, NULL ); } /* setup friendly option */ @@ -508,13 +511,16 @@ main( int argc, char **argv ) } sargs[sanum++] = "-b"; sargs[sanum++] = NULL; /* will hold the search base */ + sargs[sanum++] = "-s"; + sargs[sanum++] = NULL; /* will hold the search scope */ sargs[sanum++] = "-f"; sargs[sanum++] = NULL; /* will hold the search request */ sargs[sanum++] = NULL; - sargs[sanum] = NULL; /* might hold the "attr" request */ + sargs[sanum++] = NULL; /* might hold the "attr" request */ + sextra_args += 2; - sargs[sanum + 1] = NULL; + sargs[sanum] = NULL; /* * generate the read clients @@ -562,9 +568,10 @@ main( int argc, char **argv ) rargs[ranum++] = NULL; /* will hold the read entry */ rargs[ranum++] = NULL; - rargs[ranum] = NULL; /* might hold the filter arg */ + rargs[ranum++] = NULL; /* might hold the filter arg */ + rextra_args += 2; - rargs[ranum + 1] = NULL; + rargs[ranum] = NULL; /* * generate the modrdn clients @@ -607,7 +614,7 @@ main( int argc, char **argv ) } nargs[nanum++] = "-e"; nargs[nanum++] = NULL; /* will hold the modrdn entry */ - nargs[nanum++] = NULL; + nargs[nanum] = NULL; /* * generate the modify clients @@ -652,7 +659,7 @@ main( int argc, char **argv ) margs[manum++] = NULL; /* will hold the modify entry */ margs[manum++] = "-a";; margs[manum++] = NULL; /* will hold the ava */ - margs[manum++] = NULL; + margs[manum] = NULL; /* * generate the add/delete clients @@ -695,7 +702,7 @@ main( int argc, char **argv ) } aargs[aanum++] = "-f"; aargs[aanum++] = NULL; /* will hold the add data file */ - aargs[aanum++] = NULL; + aargs[aanum] = NULL; /* * generate the bind clients @@ -745,56 +752,99 @@ main( int argc, char **argv ) bargs[banum++] = NULL; bargs[banum++] = "-w"; bargs[banum++] = NULL; - bargs[banum++] = NULL; + bargs[banum] = NULL; #define DOREQ(n,j) ((n) && ((maxkids > (n)) ? ((j) < maxkids ) : ((j) < (n)))) for ( j = 0; j < MAXREQS; j++ ) { + /* search */ if ( DOREQ( snum, j ) ) { int jj = j % snum; + int x = sanum - sextra_args; - sargs[sanum - 2] = sreqs[jj]; - sargs[sanum - 4] = sbase[jj]; - if ( sattrs[jj] != NULL ) { - sargs[sanum - 1] = "-a"; - sargs[sanum] = sattrs[jj]; + /* base */ + if ( sbase[jj] != NULL ) { + sargs[sanum - 7] = sbase[jj]; + + } else { + sargs[sanum - 7] = slud[jj]->lud_dn; + } + + /* scope */ + if ( slud[jj] != NULL ) { + sargs[sanum - 5] = (char *)ldap_pvt_scope2str( slud[jj]->lud_scope ); + + } else { + sargs[sanum - 5] = "sub"; + } + + /* filter */ + if ( sreqs[jj] != NULL ) { + sargs[sanum - 3] = sreqs[jj]; + + } else if ( slud[jj]->lud_filter != NULL ) { + sargs[sanum - 3] = slud[jj]->lud_filter; } else { - sargs[sanum - 1] = NULL; + sargs[sanum - 3] = "(objectClass=*)"; + } + + /* extras */ + sargs[x] = NULL; + + /* attr */ + if ( sattrs[jj] != NULL ) { + sargs[x++] = "-a"; + sargs[x++] = sattrs[jj]; + } + + /* attrs */ + if ( slud[jj] != NULL && slud[jj]->lud_attrs != NULL ) { + int i; + + for ( i = 0; slud[jj]->lud_attrs[ i ] != NULL && x + i < MAXARGS - 1; i++ ) { + sargs[x + i] = slud[jj]->lud_attrs[ i ]; + } + sargs[x + i] = NULL; } + fork_child( scmd, sargs ); } + /* read */ if ( DOREQ( rnum, j ) ) { int jj = j % rnum; + int x = ranum - rextra_args; - rargs[ranum - 2] = rreqs[jj]; + rargs[ranum - 3] = rreqs[jj]; if ( rflts[jj] != NULL ) { - rargs[ranum - 1] = "-f"; - rargs[ranum] = rflts[jj]; - - } else { - rargs[ranum - 1] = NULL; + rargs[x++] = "-f"; + rargs[x++] = rflts[jj]; } + rargs[x] = NULL; fork_child( rcmd, rargs ); } + /* rename */ if ( j < nnum ) { - nargs[nanum - 2] = nreqs[j]; + nargs[nanum - 1] = nreqs[j]; fork_child( ncmd, nargs ); } + /* modify */ if ( j < mnum ) { - margs[manum - 4] = mdn[j]; - margs[manum - 2] = mreqs[j]; + margs[manum - 3] = mdn[j]; + margs[manum - 1] = mreqs[j]; fork_child( mcmd, margs ); } + /* add/delete */ if ( j < anum ) { - aargs[aanum - 2] = afiles[j]; + aargs[aanum - 1] = afiles[j]; fork_child( acmd, aargs ); } + /* bind */ if ( DOREQ( bnum, j ) ) { int jj = j % bnum; @@ -808,23 +858,24 @@ main( int argc, char **argv ) } if ( battrs[jj] != NULL ) { - bargs[banum - 4] = manager ? manager : ""; - bargs[banum - 2] = passwd ? passwd : ""; - - bargs[banum - 1] = "-b"; - bargs[banum] = breqs[jj]; - bargs[banum + 1] = "-f"; - bargs[banum + 2] = bcreds[jj]; - bargs[banum + 3] = "-a"; - bargs[banum + 4] = battrs[jj]; + bargs[banum - 3] = manager ? manager : ""; + bargs[banum - 1] = passwd ? passwd : ""; + + bargs[banum - 2] = "-b"; + bargs[banum - 1] = breqs[jj]; + bargs[banum + 0] = "-f"; + bargs[banum + 1] = bcreds[jj]; + bargs[banum + 2] = "-a"; + bargs[banum + 3] = battrs[jj]; + } else { - bargs[banum - 4] = breqs[jj]; - bargs[banum - 2] = bcreds[jj]; - bargs[banum - 1] = NULL; + bargs[banum - 3] = breqs[jj]; + bargs[banum - 1] = bcreds[jj]; + bargs[banum] = NULL; } fork_child( bcmd, bargs ); - bargs[banum - 1] = NULL; + bargs[banum] = NULL; } } @@ -845,7 +896,7 @@ get_file_name( char *dirname, char *filename ) static int -get_search_filters( char *filename, char *filters[], char *attrs[], char *bases[] ) +get_search_filters( char *filename, char *filters[], char *attrs[], char *bases[], LDAPURLDesc *luds[] ) { FILE *fp; int filter = 0; @@ -854,11 +905,32 @@ get_search_filters( char *filename, char *filters[], char *attrs[], char *bases[ char line[BUFSIZ]; while (( filter < MAXREQS ) && ( fgets( line, BUFSIZ, fp ))) { - char *nl; + char *nl; + int got_URL = 0; if (( nl = strchr( line, '\r' )) || ( nl = strchr( line, '\n' ))) *nl = '\0'; - bases[filter] = ArgDup( line ); + + if ( luds ) luds[filter] = NULL; + + if ( luds && strncmp( line, "ldap:///", STRLENOF( "ldap:///" ) ) == 0 ) { + LDAPURLDesc *lud; + + got_URL = 1; + bases[filter] = NULL; + if ( ldap_url_parse( line, &lud ) != LDAP_URL_SUCCESS ) { + return 1; + } + + if ( lud->lud_dn == NULL || lud->lud_exts != NULL ) { + return 1; + } + + luds[filter] = lud; + + } else { + bases[filter] = ArgDup( line ); + } fgets( line, BUFSIZ, fp ); if (( nl = strchr( line, '\r' )) || ( nl = strchr( line, '\n' ))) *nl = '\0'; @@ -868,15 +940,15 @@ get_search_filters( char *filename, char *filters[], char *attrs[], char *bases[ if ( filters[filter][0] == '+') { char *sep = strchr( filters[filter], ':' ); + attrs[ filter ] = &filters[ filter ][ 1 ]; if ( sep != NULL ) { - attrs[ filter ] = &filters[ filter ][ 1 ]; sep[ 0 ] = '\0'; /* NOTE: don't free this! */ filters[ filter ] = &sep[ 1 ]; } } else { - attrs[ filter] = NULL; + attrs[ filter ] = NULL; } } filter++; -- 2.39.5