1 /* $OpenLDAP: pkg/ldap/tests/progs/slapd-tester.c,v 1.46.2.8 2008/02/11 23:26:50 kurt Exp $ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2008 The OpenLDAP Foundation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
11 * A copy of this license is available in file LICENSE in the
12 * top-level directory of the distribution or, alternatively, at
13 * <http://www.OpenLDAP.org/license.html>.
16 * This work was initially developed by Kurt Spanier for inclusion
17 * in OpenLDAP Software.
24 #include "ac/stdlib.h"
27 #include "ac/dirent.h"
29 #include "ac/socket.h"
30 #include "ac/string.h"
31 #include "ac/unistd.h"
35 #include "ldap_defaults.h"
41 #include "slapd-common.h"
43 #define SEARCHCMD "slapd-search"
44 #define READCMD "slapd-read"
45 #define ADDCMD "slapd-addel"
46 #define MODRDNCMD "slapd-modrdn"
47 #define MODIFYCMD "slapd-modify"
48 #define BINDCMD "slapd-bind"
52 #define OUTERLOOPS "1"
55 #define TSEARCHFILE "do_search.0"
56 #define TREADFILE "do_read.0"
57 #define TADDFILE "do_add."
58 #define TMODRDNFILE "do_modrdn.0"
59 #define TMODIFYFILE "do_modify.0"
60 #define TBINDFILE "do_bind.0"
62 static char *get_file_name( char *dirname
, char *filename
);
63 static int get_search_filters( char *filename
, char *filters
[], char *attrs
[], char *bases
[], LDAPURLDesc
*luds
[] );
64 static int get_read_entries( char *filename
, char *entries
[], char *filters
[] );
65 static void fork_child( char *prog
, char **args
);
66 static void wait4kids( int nkidval
);
68 static int maxkids
= 20;
72 static HANDLE
*children
;
73 static char argbuf
[BUFSIZ
];
74 #define ArgDup(x) strdup(strcat(strcat(strcpy(argbuf,"\""),x),"\""))
76 #define ArgDup(x) strdup(x)
80 usage( char *name
, char opt
)
83 fprintf( stderr
, "%s: unable to handle option \'%c\'\n\n",
89 "-H <uri> | ([-h <host>] -p <port>) "
95 "[-l {<loops>|<type>=<loops>[,...]}] "
105 exit( EXIT_FAILURE
);
109 main( int argc
, char **argv
)
113 char *host
= "localhost";
115 char *manager
= NULL
;
117 char *dirname
= NULL
;
118 char *progdir
= NULL
;
120 char *outerloops
= OUTERLOOPS
;
121 char *retries
= RETRIES
;
133 char *sreqs
[MAXREQS
];
134 char *sattrs
[MAXREQS
];
135 char *sbase
[MAXREQS
];
136 LDAPURLDesc
*slud
[MAXREQS
];
138 char *sargs
[MAXARGS
];
141 char scmd
[MAXPATHLEN
];
142 /* static so that its address can be used in initializer below. */
143 static char sloops
[LDAP_PVT_INTTYPE_CHARS(unsigned long)];
146 char *rreqs
[MAXREQS
];
148 char *rargs
[MAXARGS
];
149 char *rflts
[MAXREQS
];
152 char rcmd
[MAXPATHLEN
];
153 static char rloops
[LDAP_PVT_INTTYPE_CHARS(unsigned long)];
155 char *afiles
[MAXREQS
];
157 char *aargs
[MAXARGS
];
159 char acmd
[MAXPATHLEN
];
160 static char aloops
[LDAP_PVT_INTTYPE_CHARS(unsigned long)];
163 char *nreqs
[MAXREQS
];
165 char *nargs
[MAXARGS
];
167 char ncmd
[MAXPATHLEN
];
168 static char nloops
[LDAP_PVT_INTTYPE_CHARS(unsigned long)];
171 char *mreqs
[MAXREQS
];
174 char *margs
[MAXARGS
];
176 char mcmd
[MAXPATHLEN
];
177 static char mloops
[LDAP_PVT_INTTYPE_CHARS(unsigned long)];
180 char *breqs
[MAXREQS
];
181 char *bcreds
[MAXREQS
];
182 char *battrs
[MAXREQS
];
184 char *bargs
[MAXARGS
];
186 char bcmd
[MAXPATHLEN
];
187 static char bloops
[LDAP_PVT_INTTYPE_CHARS(unsigned long)];
188 char **bargs_extra
= NULL
;
190 char *friendlyOpt
= NULL
;
192 char *pw_file
= NULL
;
194 /* extra action to do after bind... */
195 typedef struct extra_t
{
197 struct extra_t
*next
;
200 extra_t
*extra
= NULL
;
203 tester_init( "slapd-tester", TESTER_TESTER
);
212 while ( ( i
= getopt( argc
, argv
, "AB:CD:d:FH:h:Ii:j:L:l:NP:p:r:t:Ww:y:" ) ) != EOF
)
221 **b
= ldap_str2charray( optarg
, "," );
224 for ( epp
= &extra
; *epp
; epp
= &(*epp
)->next
)
227 for ( p
= b
; p
[0]; p
++ ) {
228 *epp
= calloc( 1, sizeof( extra_t
) );
229 (*epp
)->action
= p
[0];
241 case 'D': /* slapd manager */
242 manager
= ArgDup( optarg
);
245 case 'd': /* data directory */
246 dirname
= strdup( optarg
);
253 case 'H': /* slapd uri */
254 uri
= strdup( optarg
);
257 case 'h': /* slapd host */
258 host
= strdup( optarg
);
269 case 'j': /* the number of parallel clients */
270 if ( lutil_atoi( &maxkids
, optarg
) != 0 ) {
271 usage( argv
[0], 'j' );
275 case 'l': /* the number of loops per client */
276 if ( !isdigit( (unsigned char) optarg
[0] ) ) {
278 **l
= ldap_str2charray( optarg
, "," );
280 for ( p
= l
; p
[0]; p
++) {
285 { BER_BVC( "add=" ), aloops
},
286 { BER_BVC( "bind=" ), bloops
},
287 { BER_BVC( "modify=" ), mloops
},
288 { BER_BVC( "modrdn=" ), nloops
},
289 { BER_BVC( "read=" ), rloops
},
290 { BER_BVC( "search=" ), sloops
},
295 for ( c
= 0; types
[c
].type
.bv_val
; c
++ ) {
296 if ( strncasecmp( p
[0], types
[c
].type
.bv_val
, types
[c
].type
.bv_len
) == 0 ) {
301 if ( types
[c
].type
.bv_val
== NULL
) {
302 usage( argv
[0], 'l' );
305 if ( lutil_atoi( &n
, &p
[0][types
[c
].type
.bv_len
] ) != 0 ) {
306 usage( argv
[0], 'l' );
309 snprintf( types
[c
].buf
, sizeof( aloops
), "%d", n
);
312 ldap_charray_free( l
);
314 } else if ( lutil_atoi( &loops
, optarg
) != 0 ) {
315 usage( argv
[0], 'l' );
319 case 'L': /* the number of outerloops per client */
320 outerloops
= strdup( optarg
);
327 case 'P': /* prog directory */
328 progdir
= strdup( optarg
);
331 case 'p': /* the servers port number */
332 port
= strdup( optarg
);
335 case 'r': /* the number of retries in case of error */
336 retries
= strdup( optarg
);
339 case 't': /* the delay in seconds between each retry */
340 delay
= strdup( optarg
);
343 case 'w': /* the managers passwd */
344 passwd
= ArgDup( optarg
);
345 memset( optarg
, '*', strlen( optarg
) );
357 usage( argv
[0], '\0' );
362 if (( dirname
== NULL
) || ( port
== NULL
&& uri
== NULL
) ||
363 ( manager
== NULL
) || ( passwd
== NULL
) || ( progdir
== NULL
))
365 usage( argv
[0], '\0' );
369 children
= malloc( maxkids
* sizeof(HANDLE
) );
371 /* get the file list */
372 if ( ( datadir
= opendir( dirname
)) == NULL
) {
373 fprintf( stderr
, "%s: couldn't open data directory \"%s\".\n",
375 exit( EXIT_FAILURE
);
378 /* look for search, read, modrdn, and add/delete files */
379 for ( file
= readdir( datadir
); file
; file
= readdir( datadir
)) {
381 if ( !strcasecmp( file
->d_name
, TSEARCHFILE
)) {
382 sfile
= get_file_name( dirname
, file
->d_name
);
384 } else if ( !strcasecmp( file
->d_name
, TREADFILE
)) {
385 rfile
= get_file_name( dirname
, file
->d_name
);
387 } else if ( !strcasecmp( file
->d_name
, TMODRDNFILE
)) {
388 nfile
= get_file_name( dirname
, file
->d_name
);
390 } else if ( !strcasecmp( file
->d_name
, TMODIFYFILE
)) {
391 mfile
= get_file_name( dirname
, file
->d_name
);
393 } else if ( !strncasecmp( file
->d_name
, TADDFILE
, strlen( TADDFILE
))
394 && ( anum
< MAXREQS
)) {
395 afiles
[anum
++] = get_file_name( dirname
, file
->d_name
);
397 } else if ( !strcasecmp( file
->d_name
, TBINDFILE
)) {
398 bfile
= get_file_name( dirname
, file
->d_name
);
406 passwd
= getpassphrase( _("Enter LDAP Password: ") );
408 } else if ( pw_file
) {
411 if ( lutil_get_filed_password( pw_file
, &pw
) ) {
412 exit( EXIT_FAILURE
);
418 if ( !sfile
&& !rfile
&& !nfile
&& !mfile
&& !bfile
&& !anum
) {
419 fprintf( stderr
, "no data files found.\n" );
420 exit( EXIT_FAILURE
);
423 /* look for search requests */
425 snum
= get_search_filters( sfile
, sreqs
, sattrs
, sbase
, slud
);
428 "unable to parse file \"%s\" line %d\n",
429 sfile
, -2*(snum
+ 1));
430 exit( EXIT_FAILURE
);
434 /* look for read requests */
436 rnum
= get_read_entries( rfile
, rreqs
, rflts
);
439 "unable to parse file \"%s\" line %d\n",
440 rfile
, -2*(rnum
+ 1) );
441 exit( EXIT_FAILURE
);
445 /* look for modrdn requests */
447 nnum
= get_read_entries( nfile
, nreqs
, NULL
);
450 "unable to parse file \"%s\" line %d\n",
451 nfile
, -2*(nnum
+ 1) );
452 exit( EXIT_FAILURE
);
456 /* look for modify requests */
458 mnum
= get_search_filters( mfile
, mreqs
, NULL
, mdn
, NULL
);
461 "unable to parse file \"%s\" line %d\n",
462 mfile
, -2*(mnum
+ 1) );
463 exit( EXIT_FAILURE
);
467 /* look for bind requests */
469 bnum
= get_search_filters( bfile
, bcreds
, battrs
, breqs
, NULL
);
472 "unable to parse file \"%s\" line %d\n",
473 bfile
, -2*(bnum
+ 1) );
474 exit( EXIT_FAILURE
);
478 /* setup friendly option */
480 switch ( friendly
) {
489 /* NOTE: right now we don't need it more than twice */
495 if ( sloops
[0] == '\0' ) snprintf( sloops
, sizeof( sloops
), "%d", 10 * loops
);
496 if ( rloops
[0] == '\0' ) snprintf( rloops
, sizeof( rloops
), "%d", 20 * loops
);
497 if ( aloops
[0] == '\0' ) snprintf( aloops
, sizeof( aloops
), "%d", loops
);
498 if ( nloops
[0] == '\0' ) snprintf( nloops
, sizeof( nloops
), "%d", loops
);
499 if ( mloops
[0] == '\0' ) snprintf( mloops
, sizeof( mloops
), "%d", loops
);
500 if ( bloops
[0] == '\0' ) snprintf( bloops
, sizeof( bloops
), "%d", 20 * loops
);
503 * generate the search clients
507 snprintf( scmd
, sizeof scmd
, "%s" LDAP_DIRSEP SEARCHCMD
,
509 sargs
[sanum
++] = scmd
;
511 sargs
[sanum
++] = "-H";
512 sargs
[sanum
++] = uri
;
514 sargs
[sanum
++] = "-h";
515 sargs
[sanum
++] = host
;
516 sargs
[sanum
++] = "-p";
517 sargs
[sanum
++] = port
;
519 sargs
[sanum
++] = "-D";
520 sargs
[sanum
++] = manager
;
521 sargs
[sanum
++] = "-w";
522 sargs
[sanum
++] = passwd
;
523 sargs
[sanum
++] = "-l";
524 sargs
[sanum
++] = sloops
;
525 sargs
[sanum
++] = "-L";
526 sargs
[sanum
++] = outerloops
;
527 sargs
[sanum
++] = "-r";
528 sargs
[sanum
++] = retries
;
529 sargs
[sanum
++] = "-t";
530 sargs
[sanum
++] = delay
;
532 sargs
[sanum
++] = friendlyOpt
;
535 sargs
[sanum
++] = "-C";
538 sargs
[sanum
++] = "-A";
541 sargs
[sanum
++] = "-N";
544 sargs
[sanum
++] = "-i";
545 sargs
[sanum
++] = ignore
;
547 sargs
[sanum
++] = "-b";
548 sargs
[sanum
++] = NULL
; /* will hold the search base */
549 sargs
[sanum
++] = "-s";
550 sargs
[sanum
++] = NULL
; /* will hold the search scope */
551 sargs
[sanum
++] = "-f";
552 sargs
[sanum
++] = NULL
; /* will hold the search request */
554 sargs
[sanum
++] = NULL
;
555 sargs
[sanum
++] = NULL
; /* might hold the "attr" request */
561 * generate the read clients
565 snprintf( rcmd
, sizeof rcmd
, "%s" LDAP_DIRSEP READCMD
,
567 rargs
[ranum
++] = rcmd
;
569 rargs
[ranum
++] = "-H";
570 rargs
[ranum
++] = uri
;
572 rargs
[ranum
++] = "-h";
573 rargs
[ranum
++] = host
;
574 rargs
[ranum
++] = "-p";
575 rargs
[ranum
++] = port
;
577 rargs
[ranum
++] = "-D";
578 rargs
[ranum
++] = manager
;
579 rargs
[ranum
++] = "-w";
580 rargs
[ranum
++] = passwd
;
581 rargs
[ranum
++] = "-l";
582 rargs
[ranum
++] = rloops
;
583 rargs
[ranum
++] = "-L";
584 rargs
[ranum
++] = outerloops
;
585 rargs
[ranum
++] = "-r";
586 rargs
[ranum
++] = retries
;
587 rargs
[ranum
++] = "-t";
588 rargs
[ranum
++] = delay
;
590 rargs
[ranum
++] = friendlyOpt
;
593 rargs
[ranum
++] = "-C";
596 rargs
[ranum
++] = "-A";
599 rargs
[ranum
++] = "-i";
600 rargs
[ranum
++] = ignore
;
602 rargs
[ranum
++] = "-e";
603 rargs
[ranum
++] = NULL
; /* will hold the read entry */
605 rargs
[ranum
++] = NULL
;
606 rargs
[ranum
++] = NULL
; /* might hold the filter arg */
612 * generate the modrdn clients
616 snprintf( ncmd
, sizeof ncmd
, "%s" LDAP_DIRSEP MODRDNCMD
,
618 nargs
[nanum
++] = ncmd
;
620 nargs
[nanum
++] = "-H";
621 nargs
[nanum
++] = uri
;
623 nargs
[nanum
++] = "-h";
624 nargs
[nanum
++] = host
;
625 nargs
[nanum
++] = "-p";
626 nargs
[nanum
++] = port
;
628 nargs
[nanum
++] = "-D";
629 nargs
[nanum
++] = manager
;
630 nargs
[nanum
++] = "-w";
631 nargs
[nanum
++] = passwd
;
632 nargs
[nanum
++] = "-l";
633 nargs
[nanum
++] = nloops
;
634 nargs
[nanum
++] = "-L";
635 nargs
[nanum
++] = outerloops
;
636 nargs
[nanum
++] = "-r";
637 nargs
[nanum
++] = retries
;
638 nargs
[nanum
++] = "-t";
639 nargs
[nanum
++] = delay
;
641 nargs
[nanum
++] = friendlyOpt
;
644 nargs
[nanum
++] = "-C";
647 nargs
[nanum
++] = "-i";
648 nargs
[nanum
++] = ignore
;
650 nargs
[nanum
++] = "-e";
651 nargs
[nanum
++] = NULL
; /* will hold the modrdn entry */
655 * generate the modify clients
659 snprintf( mcmd
, sizeof mcmd
, "%s" LDAP_DIRSEP MODIFYCMD
,
661 margs
[manum
++] = mcmd
;
663 margs
[manum
++] = "-H";
664 margs
[manum
++] = uri
;
666 margs
[manum
++] = "-h";
667 margs
[manum
++] = host
;
668 margs
[manum
++] = "-p";
669 margs
[manum
++] = port
;
671 margs
[manum
++] = "-D";
672 margs
[manum
++] = manager
;
673 margs
[manum
++] = "-w";
674 margs
[manum
++] = passwd
;
675 margs
[manum
++] = "-l";
676 margs
[manum
++] = mloops
;
677 margs
[manum
++] = "-L";
678 margs
[manum
++] = outerloops
;
679 margs
[manum
++] = "-r";
680 margs
[manum
++] = retries
;
681 margs
[manum
++] = "-t";
682 margs
[manum
++] = delay
;
684 margs
[manum
++] = friendlyOpt
;
687 margs
[manum
++] = "-C";
690 margs
[manum
++] = "-i";
691 margs
[manum
++] = ignore
;
693 margs
[manum
++] = "-e";
694 margs
[manum
++] = NULL
; /* will hold the modify entry */
695 margs
[manum
++] = "-a";;
696 margs
[manum
++] = NULL
; /* will hold the ava */
700 * generate the add/delete clients
704 snprintf( acmd
, sizeof acmd
, "%s" LDAP_DIRSEP ADDCMD
,
706 aargs
[aanum
++] = acmd
;
708 aargs
[aanum
++] = "-H";
709 aargs
[aanum
++] = uri
;
711 aargs
[aanum
++] = "-h";
712 aargs
[aanum
++] = host
;
713 aargs
[aanum
++] = "-p";
714 aargs
[aanum
++] = port
;
716 aargs
[aanum
++] = "-D";
717 aargs
[aanum
++] = manager
;
718 aargs
[aanum
++] = "-w";
719 aargs
[aanum
++] = passwd
;
720 aargs
[aanum
++] = "-l";
721 aargs
[aanum
++] = aloops
;
722 aargs
[aanum
++] = "-L";
723 aargs
[aanum
++] = outerloops
;
724 aargs
[aanum
++] = "-r";
725 aargs
[aanum
++] = retries
;
726 aargs
[aanum
++] = "-t";
727 aargs
[aanum
++] = delay
;
729 aargs
[aanum
++] = friendlyOpt
;
732 aargs
[aanum
++] = "-C";
735 aargs
[aanum
++] = "-i";
736 aargs
[aanum
++] = ignore
;
738 aargs
[aanum
++] = "-f";
739 aargs
[aanum
++] = NULL
; /* will hold the add data file */
743 * generate the bind clients
747 snprintf( bcmd
, sizeof bcmd
, "%s" LDAP_DIRSEP BINDCMD
,
749 bargs
[banum
++] = bcmd
;
751 bargs
[banum
++] = "-I"; /* init on each bind */
754 bargs
[banum
++] = "-H";
755 bargs
[banum
++] = uri
;
757 bargs
[banum
++] = "-h";
758 bargs
[banum
++] = host
;
759 bargs
[banum
++] = "-p";
760 bargs
[banum
++] = port
;
762 bargs
[banum
++] = "-l";
763 bargs
[banum
++] = bloops
;
764 bargs
[banum
++] = "-L";
765 bargs
[banum
++] = outerloops
;
767 bargs
[banum
++] = "-r";
768 bargs
[banum
++] = retries
;
769 bargs
[banum
++] = "-t";
770 bargs
[banum
++] = delay
;
773 bargs
[banum
++] = friendlyOpt
;
776 bargs
[banum
++] = "-C";
779 bargs
[banum
++] = "-i";
780 bargs
[banum
++] = ignore
;
783 bargs
[banum
++] = "-B";
784 bargs_extra
= &bargs
[banum
++];
786 bargs
[banum
++] = "-D";
787 bargs
[banum
++] = NULL
;
788 bargs
[banum
++] = "-w";
789 bargs
[banum
++] = NULL
;
792 #define DOREQ(n,j) ((n) && ((maxkids > (n)) ? ((j) < maxkids ) : ((j) < (n))))
794 for ( j
= 0; j
< MAXREQS
; j
++ ) {
796 if ( DOREQ( snum
, j
) ) {
798 int x
= sanum
- sextra_args
;
801 if ( sbase
[jj
] != NULL
) {
802 sargs
[sanum
- 7] = sbase
[jj
];
805 sargs
[sanum
- 7] = slud
[jj
]->lud_dn
;
809 if ( slud
[jj
] != NULL
) {
810 sargs
[sanum
- 5] = (char *)ldap_pvt_scope2str( slud
[jj
]->lud_scope
);
813 sargs
[sanum
- 5] = "sub";
817 if ( sreqs
[jj
] != NULL
) {
818 sargs
[sanum
- 3] = sreqs
[jj
];
820 } else if ( slud
[jj
]->lud_filter
!= NULL
) {
821 sargs
[sanum
- 3] = slud
[jj
]->lud_filter
;
824 sargs
[sanum
- 3] = "(objectClass=*)";
831 if ( sattrs
[jj
] != NULL
) {
833 sargs
[x
++] = sattrs
[jj
];
837 if ( slud
[jj
] != NULL
&& slud
[jj
]->lud_attrs
!= NULL
) {
840 for ( i
= 0; slud
[jj
]->lud_attrs
[ i
] != NULL
&& x
+ i
< MAXARGS
- 1; i
++ ) {
841 sargs
[x
+ i
] = slud
[jj
]->lud_attrs
[ i
];
846 fork_child( scmd
, sargs
);
850 if ( DOREQ( rnum
, j
) ) {
852 int x
= ranum
- rextra_args
;
854 rargs
[ranum
- 3] = rreqs
[jj
];
855 if ( rflts
[jj
] != NULL
) {
857 rargs
[x
++] = rflts
[jj
];
860 fork_child( rcmd
, rargs
);
865 nargs
[nanum
- 1] = nreqs
[j
];
866 fork_child( ncmd
, nargs
);
871 margs
[manum
- 3] = mdn
[j
];
872 margs
[manum
- 1] = mreqs
[j
];
873 fork_child( mcmd
, margs
);
878 aargs
[aanum
- 1] = afiles
[j
];
879 fork_child( acmd
, aargs
);
883 if ( DOREQ( bnum
, j
) ) {
887 int n
= ((double)nextra
)*rand()/(RAND_MAX
+ 1.0);
890 for ( e
= extra
; n
-- > 0; e
= e
->next
)
892 *bargs_extra
= e
->action
;
895 if ( battrs
[jj
] != NULL
) {
896 bargs
[banum
- 3] = manager
? manager
: "";
897 bargs
[banum
- 1] = passwd
? passwd
: "";
899 bargs
[banum
+ 0] = "-b";
900 bargs
[banum
+ 1] = breqs
[jj
];
901 bargs
[banum
+ 2] = "-f";
902 bargs
[banum
+ 3] = bcreds
[jj
];
903 bargs
[banum
+ 4] = "-a";
904 bargs
[banum
+ 5] = battrs
[jj
];
905 bargs
[banum
+ 6] = NULL
;
908 bargs
[banum
- 3] = breqs
[jj
];
909 bargs
[banum
- 1] = bcreds
[jj
];
913 fork_child( bcmd
, bargs
);
920 exit( EXIT_SUCCESS
);
924 get_file_name( char *dirname
, char *filename
)
926 char buf
[MAXPATHLEN
];
928 snprintf( buf
, sizeof buf
, "%s" LDAP_DIRSEP
"%s",
930 return( strdup( buf
));
935 get_search_filters( char *filename
, char *filters
[], char *attrs
[], char *bases
[], LDAPURLDesc
*luds
[] )
940 if ( (fp
= fopen( filename
, "r" )) != NULL
) {
943 while (( filter
< MAXREQS
) && ( fgets( line
, BUFSIZ
, fp
))) {
947 if (( nl
= strchr( line
, '\r' )) || ( nl
= strchr( line
, '\n' )))
950 if ( luds
) luds
[filter
] = NULL
;
952 if ( luds
&& strncmp( line
, "ldap:///", STRLENOF( "ldap:///" ) ) == 0 ) {
956 bases
[filter
] = NULL
;
957 if ( ldap_url_parse( line
, &lud
) != LDAP_URL_SUCCESS
) {
958 filter
= -filter
- 1;
962 if ( lud
->lud_dn
== NULL
|| lud
->lud_exts
!= NULL
) {
963 filter
= -filter
- 1;
964 ldap_free_urldesc( lud
);
971 bases
[filter
] = ArgDup( line
);
973 fgets( line
, BUFSIZ
, fp
);
974 if (( nl
= strchr( line
, '\r' )) || ( nl
= strchr( line
, '\n' )))
977 filters
[filter
] = ArgDup( line
);
979 if ( filters
[filter
][0] == '+') {
980 char *sep
= strchr( filters
[filter
], ':' );
982 attrs
[ filter
] = &filters
[ filter
][ 1 ];
985 /* NOTE: don't free this! */
986 filters
[ filter
] = &sep
[ 1 ];
990 attrs
[ filter
] = NULL
;
1004 get_read_entries( char *filename
, char *entries
[], char *filters
[] )
1009 if ( (fp
= fopen( filename
, "r" )) != NULL
) {
1012 while (( entry
< MAXREQS
) && ( fgets( line
, BUFSIZ
, fp
))) {
1015 if (( nl
= strchr( line
, '\r' )) || ( nl
= strchr( line
, '\n' )))
1017 if ( filters
!= NULL
&& line
[0] == '+' ) {
1020 if ( ldap_url_parse( &line
[1], &lud
) != LDAP_URL_SUCCESS
) {
1025 if ( lud
->lud_dn
== NULL
|| lud
->lud_dn
[ 0 ] == '\0' ) {
1026 ldap_free_urldesc( lud
);
1031 entries
[entry
] = ArgDup( lud
->lud_dn
);
1033 if ( lud
->lud_filter
) {
1034 filters
[entry
] = ArgDup( lud
->lud_filter
);
1037 filters
[entry
] = ArgDup( "(objectClass=*)" );
1039 ldap_free_urldesc( lud
);
1042 entries
[entry
] = ArgDup( line
);
1054 #ifndef HAVE_WINSOCK
1056 fork_child( char *prog
, char **args
)
1058 /* note: obscures global pid var; intended */
1061 wait4kids( maxkids
);
1063 switch ( pid
= fork() ) {
1066 /* The __LIBASCII execvp only handles ASCII "prog",
1067 * we still need to translate the arg vec ourselves.
1069 { char *arg2
[MAXREQS
];
1072 for (i
=0; args
[i
]; i
++) {
1073 arg2
[i
] = ArgDup(args
[i
]);
1079 execvp( prog
, args
);
1080 tester_perror( "execvp", NULL
);
1082 for (i
=0; args
[i
]; i
++);
1083 fprintf(stderr
,"%d args\n", i
);
1084 for (i
=0; args
[i
]; i
++)
1085 fprintf(stderr
,"%d %s\n", i
, args
[i
]);
1088 exit( EXIT_FAILURE
);
1091 case -1: /* trouble */
1092 tester_perror( "fork", NULL
);
1095 default: /* parent */
1102 wait4kids( int nkidval
)
1106 while ( nkids
>= nkidval
) {
1109 if ( WIFSTOPPED(status
) ) {
1111 "stopping: child stopped with signal %d\n",
1112 (int) WSTOPSIG(status
) );
1114 } else if ( WIFSIGNALED(status
) ) {
1116 "stopping: child terminated with signal %d%s\n",
1117 (int) WTERMSIG(status
),
1119 WCOREDUMP(status
) ? ", core dumped" : ""
1124 exit( WEXITSTATUS(status
) );
1126 } else if ( WEXITSTATUS(status
) != 0 ) {
1128 "stopping: child exited with status %d\n",
1129 (int) WEXITSTATUS(status
) );
1130 exit( WEXITSTATUS(status
) );
1140 wait4kids( int nkidval
)
1144 while ( nkids
>= nkidval
) {
1145 rc
= WaitForMultipleObjects( nkids
, children
, FALSE
, INFINITE
);
1146 for ( i
=rc
- WAIT_OBJECT_0
; i
<nkids
-1; i
++)
1147 children
[i
] = children
[i
+1];
1153 fork_child( char *prog
, char **args
)
1157 wait4kids( maxkids
);
1159 rc
= _spawnvp( _P_NOWAIT
, prog
, args
);
1162 tester_perror( "_spawnvp", NULL
);
1164 children
[nkids
++] = (HANDLE
)rc
;