10 #include <ac/unistd.h>
11 extern char *strdup (const char *);
15 #ifdef HAVE_SYS_FILE_H
24 /* including the "internal" defs is legit and nec. since this test routine has
25 * a-priori knowledge of libldap internal workings.
26 * hodges@stanford.edu 5-Feb-96
32 static char *getline LDAP_P(( char *line, int len, FILE *fp, char *prompt ));
34 static char **get_list LDAP_P(( char *prompt ));
35 static int file_read LDAP_P(( char *path, struct berval *bv ));
36 static LDAPMod **get_modlist LDAP_P(( char *prompt1, char *prompt2, char *prompt3 ));
37 static void handle_result LDAP_P(( LDAP *ld, LDAPMessage *lm ));
38 static void print_ldap_result LDAP_P(( LDAP *ld, LDAPMessage *lm, char *s ));
39 static void print_search_entry LDAP_P(( LDAP *ld, LDAPMessage *res ));
40 static void free_list LDAP_P(( char **list ));
42 #define NOCACHEERRMSG "don't compile with -DLDAP_NOCACHE if you desire local caching"
44 static char *dnsuffix;
48 getline( char *line, int len, FILE *fp, char *prompt )
52 if ( fgets( line, len, fp ) == NULL )
55 line[ strlen( line ) - 1 ] = '\0';
62 get_list( char *prompt )
71 getline( buf, sizeof(buf), stdin, prompt );
76 if ( result == (char **) 0 )
77 result = (char **) malloc( sizeof(char *) );
79 result = (char **) realloc( result,
80 sizeof(char *) * (num + 1) );
82 result[num++] = (char *) strdup( buf );
84 if ( result == (char **) 0 )
86 result = (char **) realloc( result, sizeof(char *) * (num + 1) );
94 free_list( char **list )
99 for ( i = 0; list[ i ] != NULL; ++i ) {
102 free( (char *)list );
108 file_read( char *path, struct berval *bv )
114 if (( fp = fopen( path, "r" )) == NULL ) {
119 if ( fseek( fp, 0L, SEEK_END ) != 0 ) {
125 bv->bv_len = ftell( fp );
127 if (( bv->bv_val = (char *)malloc( bv->bv_len )) == NULL ) {
133 if ( fseek( fp, 0L, SEEK_SET ) != 0 ) {
139 rlen = fread( bv->bv_val, 1, bv->bv_len, fp );
143 if ( (unsigned long) rlen != bv->bv_len ) {
149 return( bv->bv_len );
154 get_modlist( char *prompt1, char *prompt2, char *prompt3 )
156 static char buf[256];
160 struct berval **bvals;
166 getline( buf, sizeof(buf), stdin, prompt1 );
167 tmp.mod_op = atoi( buf );
169 if ( tmp.mod_op == -1 || buf[0] == '\0' )
173 getline( buf, sizeof(buf), stdin, prompt2 );
174 if ( buf[0] == '\0' )
176 tmp.mod_type = strdup( buf );
178 tmp.mod_values = get_list( prompt3 );
180 if ( tmp.mod_values != NULL ) {
183 for ( i = 0; tmp.mod_values[i] != NULL; ++i )
185 bvals = (struct berval **)calloc( i + 1,
186 sizeof( struct berval *));
187 for ( i = 0; tmp.mod_values[i] != NULL; ++i ) {
188 bvals[i] = (struct berval *)malloc(
189 sizeof( struct berval ));
190 if ( strncmp( tmp.mod_values[i], "{FILE}",
192 if ( file_read( tmp.mod_values[i] + 6,
197 bvals[i]->bv_val = tmp.mod_values[i];
199 strlen( tmp.mod_values[i] );
202 tmp.mod_bvalues = bvals;
203 tmp.mod_op |= LDAP_MOD_BVALUES;
206 if ( result == NULL )
207 result = (LDAPMod **) malloc( sizeof(LDAPMod *) );
209 result = (LDAPMod **) realloc( result,
210 sizeof(LDAPMod *) * (num + 1) );
212 result[num] = (LDAPMod *) malloc( sizeof(LDAPMod) );
213 *(result[num]) = tmp; /* struct copy */
216 if ( result == NULL )
218 result = (LDAPMod **) realloc( result, sizeof(LDAPMod *) * (num + 1) );
225 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
227 bind_prompt( LDAP *ld, char **dnp, char **passwdp, int *authmethodp,
230 static char dn[256], passwd[256];
234 getline( dn, sizeof(dn), stdin,
235 "re-bind method (0->simple, 1->krbv41, 2->krbv42, 3->krbv41&2)? " );
236 if (( *authmethodp = atoi( dn )) == 3 ) {
237 *authmethodp = LDAP_AUTH_KRBV4;
239 *authmethodp |= 0x80;
241 #else /* HAVE_KERBEROS */
242 *authmethodp = LDAP_AUTH_SIMPLE;
243 #endif /* HAVE_KERBEROS */
245 getline( dn, sizeof(dn), stdin, "re-bind dn? " );
246 strcat( dn, dnsuffix );
249 if ( *authmethodp == LDAP_AUTH_SIMPLE && dn[0] != '\0' ) {
250 getline( passwd, sizeof(passwd), stdin,
251 "re-bind password? " );
258 return( LDAP_SUCCESS );
260 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
264 main( int argc, char **argv )
267 int i, c, port, cldapflg, errflg, method, id, msgtype;
268 char line[256], command1, command2, command3;
269 char passwd[64], dn[256], rdn[64], attr[64], value[256];
270 char filter[256], *host, **types;
272 char *usage = "usage: %s [-u] [-h host] [-d level] [-s dnsuffix] [-p port] [-t file] [-T file]\n";
273 int bound, all, scope, attrsonly;
275 LDAPMod **mods, **attrs;
276 struct timeval timeout;
277 char *copyfname = NULL;
287 cldapflg = errflg = 0;
289 while (( c = getopt( argc, argv, "uh:d:s:p:t:T:" )) != -1 ) {
292 #ifdef LDAP_CONNECTIONLESS
294 #else /* LDAP_CONNECTIONLESS */
295 printf( "Compile with -DLDAP_CONNECTIONLESS for UDP support\n" );
296 #endif /* LDAP_CONNECTIONLESS */
301 ldap_debug = atoi( optarg );
302 if ( ldap_debug & LDAP_DEBUG_PACKETS ) {
303 lber_debug = ldap_debug;
306 printf( "Compile with -DLDAP_DEBUG for debugging\n" );
319 port = atoi( optarg );
322 case 't': /* copy ber's to given file */
323 copyfname = strdup( optarg );
324 copyoptions = LBER_TO_FILE;
327 case 'T': /* only output ber's to given file */
328 copyfname = strdup( optarg );
329 copyoptions = (LBER_TO_FILE | LBER_TO_FILE_ONLY);
337 if ( host == NULL && optind == argc - 1 ) {
338 host = argv[ optind ];
342 if ( errflg || optind < argc - 1 ) {
343 fprintf( stderr, usage, argv[ 0 ] );
347 printf( "%sldap_open( %s, %d )\n", cldapflg ? "c" : "",
348 host == NULL ? "(null)" : host, port );
351 #ifdef LDAP_CONNECTIONLESS
352 ld = cldap_open( host, port );
353 #endif /* LDAP_CONNECTIONLESS */
355 ld = ldap_open( host, port );
359 perror( "ldap_open" );
363 if ( copyfname != NULL ) {
364 if ( (ld->ld_sb.sb_fd = open( copyfname, O_WRONLY | O_CREAT,
369 ld->ld_sb.sb_options = copyoptions;
376 (void) memset( line, '\0', sizeof(line) );
377 while ( getline( line, sizeof(line), stdin, "\ncommand? " ) != NULL ) {
382 switch ( command1 ) {
383 case 'a': /* add or abandon */
384 switch ( command2 ) {
386 getline( dn, sizeof(dn), stdin, "dn? " );
387 strcat( dn, dnsuffix );
388 if ( (attrs = get_modlist( NULL, "attr? ",
389 "value? " )) == NULL )
391 if ( (id = ldap_add( ld, dn, attrs )) == -1 )
392 ldap_perror( ld, "ldap_add" );
394 printf( "Add initiated with id %d\n",
398 case 'b': /* abandon */
399 getline( line, sizeof(line), stdin, "msgid? " );
401 if ( ldap_abandon( ld, id ) != 0 )
402 ldap_perror( ld, "ldap_abandon" );
404 printf( "Abandon successful\n" );
407 printf( "Possibilities: [ad]d, [ab]ort\n" );
411 case 'b': /* asynch bind */
413 getline( line, sizeof(line), stdin,
414 "method (0->simple, 1->krbv41, 2->krbv42)? " );
415 method = atoi( line ) | 0x80;
416 #else /* HAVE_KERBEROS */
417 method = LDAP_AUTH_SIMPLE;
418 #endif /* HAVE_KERBEROS */
419 getline( dn, sizeof(dn), stdin, "dn? " );
420 strcat( dn, dnsuffix );
422 if ( method == LDAP_AUTH_SIMPLE && dn[0] != '\0' )
423 getline( passwd, sizeof(passwd), stdin,
428 if ( ldap_bind( ld, dn, passwd, method ) == -1 ) {
429 fprintf( stderr, "ldap_bind failed\n" );
430 ldap_perror( ld, "ldap_bind" );
432 printf( "Bind initiated\n" );
437 case 'B': /* synch bind */
439 getline( line, sizeof(line), stdin,
440 "method 0->simple 1->krbv41 2->krbv42 3->krb? " );
441 method = atoi( line );
443 method = LDAP_AUTH_KRBV4;
445 method = method | 0x80;
446 #else /* HAVE_KERBEROS */
447 method = LDAP_AUTH_SIMPLE;
448 #endif /* HAVE_KERBEROS */
449 getline( dn, sizeof(dn), stdin, "dn? " );
450 strcat( dn, dnsuffix );
453 getline( passwd, sizeof(passwd), stdin,
458 if ( ldap_bind_s( ld, dn, passwd, method ) !=
460 fprintf( stderr, "ldap_bind_s failed\n" );
461 ldap_perror( ld, "ldap_bind_s" );
463 printf( "Bind successful\n" );
468 case 'c': /* compare */
469 getline( dn, sizeof(dn), stdin, "dn? " );
470 strcat( dn, dnsuffix );
471 getline( attr, sizeof(attr), stdin, "attr? " );
472 getline( value, sizeof(value), stdin, "value? " );
474 if ( (id = ldap_compare( ld, dn, attr, value )) == -1 )
475 ldap_perror( ld, "ldap_compare" );
477 printf( "Compare initiated with id %d\n", id );
480 case 'd': /* turn on debugging */
482 getline( line, sizeof(line), stdin, "debug level? " );
483 ldap_debug = atoi( line );
484 if ( ldap_debug & LDAP_DEBUG_PACKETS ) {
485 lber_debug = ldap_debug;
488 printf( "Compile with -DLDAP_DEBUG for debugging\n" );
492 case 'E': /* explode a dn */
493 getline( line, sizeof(line), stdin, "dn? " );
494 exdn = ldap_explode_dn( line, 0 );
495 for ( i = 0; exdn != NULL && exdn[i] != NULL; i++ ) {
496 printf( "\t%s\n", exdn[i] );
500 case 'g': /* set next msgid */
501 getline( line, sizeof(line), stdin, "msgid? " );
502 ld->ld_msgid = atoi( line );
505 case 'v': /* set version number */
506 getline( line, sizeof(line), stdin, "version? " );
507 ld->ld_version = atoi( line );
510 case 'm': /* modify or modifyrdn */
511 if ( strncmp( line, "modify", 4 ) == 0 ) {
512 getline( dn, sizeof(dn), stdin, "dn? " );
513 strcat( dn, dnsuffix );
514 if ( (mods = get_modlist(
515 "mod (0=>add, 1=>delete, 2=>replace -1=>done)? ",
516 "attribute type? ", "attribute value? " ))
519 if ( (id = ldap_modify( ld, dn, mods )) == -1 )
520 ldap_perror( ld, "ldap_modify" );
522 printf( "Modify initiated with id %d\n",
524 } else if ( strncmp( line, "modrdn", 4 ) == 0 ) {
525 getline( dn, sizeof(dn), stdin, "dn? " );
526 strcat( dn, dnsuffix );
527 getline( rdn, sizeof(rdn), stdin, "newrdn? " );
528 if ( (id = ldap_modrdn( ld, dn, rdn )) == -1 )
529 ldap_perror( ld, "ldap_modrdn" );
531 printf( "Modrdn initiated with id %d\n",
534 printf( "Possibilities: [modi]fy, [modr]dn\n" );
539 #ifdef LDAP_CONNECTIONLESS
542 #endif /* LDAP_CONNECTIONLESS */
543 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
545 #else /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
546 if ( !cldapflg && bound )
547 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
552 case 'r': /* result or remove */
553 switch ( command3 ) {
554 case 's': /* result */
555 getline( line, sizeof(line), stdin,
556 "msgid (-1=>any)? " );
557 if ( line[0] == '\0' )
561 getline( line, sizeof(line), stdin,
562 "all (0=>any, 1=>all)? " );
563 if ( line[0] == '\0' )
567 if (( msgtype = ldap_result( ld, id, all,
568 &timeout, &res )) < 1 ) {
569 ldap_perror( ld, "ldap_result" );
572 printf( "\nresult: msgtype %d msgid %d\n",
573 msgtype, res->lm_msgid );
574 handle_result( ld, res );
578 case 'm': /* remove */
579 getline( dn, sizeof(dn), stdin, "dn? " );
580 strcat( dn, dnsuffix );
581 if ( (id = ldap_delete( ld, dn )) == -1 )
582 ldap_perror( ld, "ldap_delete" );
584 printf( "Remove initiated with id %d\n",
589 printf( "Possibilities: [rem]ove, [res]ult\n" );
594 case 's': /* search */
595 getline( dn, sizeof(dn), stdin, "searchbase? " );
596 strcat( dn, dnsuffix );
597 getline( line, sizeof(line), stdin,
598 "scope (0=Base, 1=One Level, 2=Subtree)? " );
599 scope = atoi( line );
600 getline( filter, sizeof(filter), stdin,
601 "search filter (e.g. sn=jones)? " );
602 types = get_list( "attrs to return? " );
603 getline( line, sizeof(line), stdin,
604 "attrsonly (0=attrs&values, 1=attrs only)? " );
605 attrsonly = atoi( line );
608 #ifdef LDAP_CONNECTIONLESS
609 getline( line, sizeof(line), stdin,
610 "Requestor DN (for logging)? " );
611 if ( cldap_search_s( ld, dn, scope, filter, types,
612 attrsonly, &res, line ) != 0 ) {
613 ldap_perror( ld, "cldap_search_s" );
615 printf( "\nresult: msgid %d\n",
617 handle_result( ld, res );
620 #endif /* LDAP_CONNECTIONLESS */
622 if (( id = ldap_search( ld, dn, scope, filter,
623 types, attrsonly )) == -1 ) {
624 ldap_perror( ld, "ldap_search" );
626 printf( "Search initiated with id %d\n", id );
632 case 't': /* set timeout value */
633 getline( line, sizeof(line), stdin, "timeout? " );
634 timeout.tv_sec = atoi( line );
637 case 'U': /* set ufn search prefix */
638 getline( line, sizeof(line), stdin, "ufn prefix? " );
639 ldap_ufn_setprefix( ld, line );
642 case 'u': /* user friendly search w/optional timeout */
643 getline( dn, sizeof(dn), stdin, "ufn? " );
644 strcat( dn, dnsuffix );
645 types = get_list( "attrs to return? " );
646 getline( line, sizeof(line), stdin,
647 "attrsonly (0=attrs&values, 1=attrs only)? " );
648 attrsonly = atoi( line );
650 if ( command2 == 't' ) {
651 id = ldap_ufn_search_c( ld, dn, types,
652 attrsonly, &res, ldap_ufn_timeout,
655 id = ldap_ufn_search_s( ld, dn, types,
659 ldap_perror( ld, "ldap_ufn_search" );
661 printf( "\nresult: err %d\n", id );
662 handle_result( ld, res );
668 case 'l': /* URL search */
669 getline( line, sizeof(line), stdin,
670 "attrsonly (0=attrs&values, 1=attrs only)? " );
671 attrsonly = atoi( line );
672 getline( line, sizeof(line), stdin, "LDAP URL? " );
673 if (( id = ldap_url_search( ld, line, attrsonly ))
675 ldap_perror( ld, "ldap_url_search" );
677 printf( "URL search initiated with id %d\n", id );
681 case 'p': /* parse LDAP URL */
682 getline( line, sizeof(line), stdin, "LDAP URL? " );
683 if (( i = ldap_url_parse( line, &ludp )) != 0 ) {
684 fprintf( stderr, "ldap_url_parse: error %d\n", i );
686 printf( "\t host: " );
687 if ( ludp->lud_host == NULL ) {
688 printf( "DEFAULT\n" );
690 printf( "<%s>\n", ludp->lud_host );
692 printf( "\t port: " );
693 if ( ludp->lud_port == 0 ) {
694 printf( "DEFAULT\n" );
696 printf( "%d\n", ludp->lud_port );
698 printf( "\t dn: <%s>\n", ludp->lud_dn );
699 printf( "\t attrs:" );
700 if ( ludp->lud_attrs == NULL ) {
703 for ( i = 0; ludp->lud_attrs[ i ] != NULL; ++i ) {
704 printf( " <%s>", ludp->lud_attrs[ i ] );
707 printf( "\n\t scope: %s\n", ludp->lud_scope == LDAP_SCOPE_ONELEVEL ?
708 "ONE" : ludp->lud_scope == LDAP_SCOPE_BASE ? "BASE" :
709 ludp->lud_scope == LDAP_SCOPE_SUBTREE ? "SUB" : "**invalid**" );
710 printf( "\tfilter: <%s>\n", ludp->lud_filter );
711 ldap_free_urldesc( ludp );
715 case 'n': /* set dn suffix, for convenience */
716 getline( line, sizeof(line), stdin, "DN suffix? " );
717 strcpy( dnsuffix, line );
720 case 'e': /* enable cache */
722 printf( NOCACHEERRMSG );
723 #else /* LDAP_NOCACHE */
724 getline( line, sizeof(line), stdin, "Cache timeout (secs)? " );
726 getline( line, sizeof(line), stdin, "Maximum memory to use (bytes)? " );
727 if ( ldap_enable_cache( ld, i, atoi( line )) == 0 ) {
728 printf( "local cache is on\n" );
730 printf( "ldap_enable_cache failed\n" );
732 #endif /* LDAP_NOCACHE */
735 case 'x': /* uncache entry */
737 printf( NOCACHEERRMSG );
738 #else /* LDAP_NOCACHE */
739 getline( line, sizeof(line), stdin, "DN? " );
740 ldap_uncache_entry( ld, line );
741 #endif /* LDAP_NOCACHE */
744 case 'X': /* uncache request */
746 printf( NOCACHEERRMSG );
747 #else /* LDAP_NOCACHE */
748 getline( line, sizeof(line), stdin, "request msgid? " );
749 ldap_uncache_request( ld, atoi( line ));
750 #endif /* LDAP_NOCACHE */
753 case 'o': /* set ldap options */
754 getline( line, sizeof(line), stdin, "alias deref (0=never, 1=searching, 2=finding, 3=always)?" );
755 ld->ld_deref = atoi( line );
756 getline( line, sizeof(line), stdin, "timelimit?" );
757 ld->ld_timelimit = atoi( line );
758 getline( line, sizeof(line), stdin, "sizelimit?" );
759 ld->ld_sizelimit = atoi( line );
761 LDAP_BOOL_ZERO(&ld->ld_options);
763 #ifdef STR_TRANSLATION
764 getline( line, sizeof(line), stdin,
765 "Automatic translation of T.61 strings (0=no, 1=yes)?" );
766 if ( atoi( line ) == 0 ) {
767 ld->ld_lberoptions &= ~LBER_TRANSLATE_STRINGS;
769 ld->ld_lberoptions |= LBER_TRANSLATE_STRINGS;
770 #ifdef LDAP_CHARSET_8859
771 getline( line, sizeof(line), stdin,
772 "Translate to/from ISO-8859 (0=no, 1=yes?" );
773 if ( atoi( line ) != 0 ) {
774 ldap_set_string_translators( ld,
778 #endif /* LDAP_CHARSET_8859 */
780 #endif /* STR_TRANSLATION */
782 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
783 getline( line, sizeof(line), stdin,
784 "Use DN & DNS to determine where to send requests (0=no, 1=yes)?" );
785 if ( atoi( line ) != 0 ) {
786 LDAP_BOOL_SET(&ld->ld_options, LDAP_BOOL_DNS);
788 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
790 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
791 getline( line, sizeof(line), stdin,
792 "Recognize and chase referrals (0=no, 1=yes)?" );
793 if ( atoi( line ) != 0 ) {
794 LDAP_BOOL_SET(&ld->ld_options, LDAP_BOOL_REFERRALS);
795 getline( line, sizeof(line), stdin,
796 "Prompt for bind credentials when chasing referrals (0=no, 1=yes)?" );
797 if ( atoi( line ) != 0 ) {
798 ldap_set_rebind_proc( ld, bind_prompt );
801 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
804 case 'O': /* set cache options */
806 printf( NOCACHEERRMSG );
807 #else /* LDAP_NOCACHE */
808 getline( line, sizeof(line), stdin, "cache errors (0=smart, 1=never, 2=always)?" );
809 switch( atoi( line )) {
811 ldap_set_cache_options( ld, 0 );
814 ldap_set_cache_options( ld,
815 LDAP_CACHE_OPT_CACHENOERRS );
818 ldap_set_cache_options( ld,
819 LDAP_CACHE_OPT_CACHEALLERRS );
822 printf( "not a valid cache option\n" );
824 #endif /* LDAP_NOCACHE */
828 printf( "Commands: [ad]d [ab]andon [b]ind\n" );
829 printf( " [B]ind async [c]ompare [l]URL search\n" );
830 printf( " [modi]fy [modr]dn [rem]ove\n" );
831 printf( " [res]ult [s]earch [q]uit/unbind\n\n" );
832 printf( " [u]fn search [ut]fn search with timeout\n" );
833 printf( " [d]ebug [e]nable cache set ms[g]id\n" );
834 printf( " d[n]suffix [t]imeout [v]ersion\n" );
835 printf( " [U]fn prefix [x]uncache entry [X]uncache request\n" );
836 printf( " [?]help [o]ptions [O]cache options\n" );
837 printf( " [E]xplode dn [p]arse LDAP URL\n" );
841 printf( "Invalid command. Type ? for help.\n" );
845 (void) memset( line, '\0', sizeof(line) );
852 handle_result( LDAP *ld, LDAPMessage *lm )
854 switch ( lm->lm_msgtype ) {
855 case LDAP_RES_COMPARE:
856 printf( "Compare result\n" );
857 print_ldap_result( ld, lm, "compare" );
860 case LDAP_RES_SEARCH_RESULT:
861 printf( "Search result\n" );
862 print_ldap_result( ld, lm, "search" );
865 case LDAP_RES_SEARCH_ENTRY:
866 printf( "Search entry\n" );
867 print_search_entry( ld, lm );
871 printf( "Add result\n" );
872 print_ldap_result( ld, lm, "add" );
875 case LDAP_RES_DELETE:
876 printf( "Delete result\n" );
877 print_ldap_result( ld, lm, "delete" );
880 case LDAP_RES_MODRDN:
881 printf( "ModRDN result\n" );
882 print_ldap_result( ld, lm, "modrdn" );
886 printf( "Bind result\n" );
887 print_ldap_result( ld, lm, "bind" );
891 printf( "Unknown result type 0x%x\n", lm->lm_msgtype );
892 print_ldap_result( ld, lm, "unknown" );
897 print_ldap_result( LDAP *ld, LDAPMessage *lm, char *s )
899 ldap_result2error( ld, lm, 1 );
900 ldap_perror( ld, s );
902 if ( ld->ld_error != NULL && *ld->ld_error != '\0' )
903 fprintf( stderr, "Additional info: %s\n", ld->ld_error );
904 if ( NAME_ERROR( ld->ld_errno ) && ld->ld_matched != NULL )
905 fprintf( stderr, "Matched DN: %s\n", ld->ld_matched );
910 print_search_entry( LDAP *ld, LDAPMessage *res )
914 struct berval **vals;
918 for ( e = ldap_first_entry( ld, res ); e != NULLMSG;
919 e = ldap_next_entry( ld, e ) ) {
920 if ( e->lm_msgtype == LDAP_RES_SEARCH_RESULT )
923 dn = ldap_get_dn( ld, e );
924 printf( "\tDN: %s\n", dn );
926 ufn = ldap_dn2ufn( dn );
927 printf( "\tUFN: %s\n", ufn );
932 for ( a = ldap_first_attribute( ld, e, &ber ); a != NULL;
933 a = ldap_next_attribute( ld, e, ber ) ) {
934 printf( "\t\tATTR: %s\n", a );
935 if ( (vals = ldap_get_values_len( ld, e, a ))
937 printf( "\t\t\t(no values)\n" );
939 for ( i = 0; vals[i] != NULL; i++ ) {
943 for ( j = 0; (unsigned long) j < vals[i]->bv_len; j++ )
944 if ( !isascii( vals[i]->bv_val[j] ) ) {
950 printf( "\t\t\tlength (%ld) (not ascii)\n", vals[i]->bv_len );
951 #ifdef BPRINT_NONASCII
952 lber_bprint( vals[i]->bv_val,
954 #endif /* BPRINT_NONASCII */
957 printf( "\t\t\tlength (%ld) %s\n",
958 vals[i]->bv_len, vals[i]->bv_val );
960 ber_bvecfree( vals );
965 if ( res->lm_msgtype == LDAP_RES_SEARCH_RESULT
966 || res->lm_chain != NULLMSG )
967 print_ldap_result( ld, res, "search" );