3 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
11 #include <ac/stdlib.h>
14 #include <ac/socket.h>
15 #include <ac/string.h>
17 #include <ac/unistd.h>
21 #ifdef HAVE_SYS_FILE_H
30 /* including the "internal" defs is legit and nec. since this test routine has
31 * a-priori knowledge of libldap internal workings.
32 * hodges@stanford.edu 5-Feb-96
38 static char *getline LDAP_P(( char *line, int len, FILE *fp, char *prompt ));
40 static char **get_list LDAP_P(( char *prompt ));
41 static int file_read LDAP_P(( char *path, struct berval *bv ));
42 static LDAPMod **get_modlist LDAP_P(( char *prompt1, char *prompt2, char *prompt3 ));
43 static void handle_result LDAP_P(( LDAP *ld, LDAPMessage *lm ));
44 static void print_ldap_result LDAP_P(( LDAP *ld, LDAPMessage *lm, char *s ));
45 static void print_search_entry LDAP_P(( LDAP *ld, LDAPMessage *res ));
46 static void free_list LDAP_P(( char **list ));
48 #define NOCACHEERRMSG "don't compile with -DLDAP_NOCACHE if you desire local caching"
50 static char *dnsuffix;
54 getline( char *line, int len, FILE *fp, char *prompt )
58 if ( fgets( line, len, fp ) == NULL )
61 line[ strlen( line ) - 1 ] = '\0';
68 get_list( char *prompt )
77 getline( buf, sizeof(buf), stdin, prompt );
82 if ( result == (char **) 0 )
83 result = (char **) malloc( sizeof(char *) );
85 result = (char **) realloc( result,
86 sizeof(char *) * (num + 1) );
88 result[num++] = (char *) strdup( buf );
90 if ( result == (char **) 0 )
92 result = (char **) realloc( result, sizeof(char *) * (num + 1) );
100 free_list( char **list )
104 if ( list != NULL ) {
105 for ( i = 0; list[ i ] != NULL; ++i ) {
108 free( (char *)list );
114 file_read( char *path, struct berval *bv )
120 if (( fp = fopen( path, "r" )) == NULL ) {
125 if ( fseek( fp, 0L, SEEK_END ) != 0 ) {
131 bv->bv_len = ftell( fp );
133 if (( bv->bv_val = (char *)malloc( bv->bv_len )) == NULL ) {
139 if ( fseek( fp, 0L, SEEK_SET ) != 0 ) {
145 rlen = fread( bv->bv_val, 1, bv->bv_len, fp );
149 if ( (ber_len_t) rlen != bv->bv_len ) {
155 return( bv->bv_len );
160 get_modlist( char *prompt1, char *prompt2, char *prompt3 )
162 static char buf[256];
166 struct berval **bvals;
172 getline( buf, sizeof(buf), stdin, prompt1 );
173 tmp.mod_op = atoi( buf );
175 if ( tmp.mod_op == -1 || buf[0] == '\0' )
179 getline( buf, sizeof(buf), stdin, prompt2 );
180 if ( buf[0] == '\0' )
182 tmp.mod_type = strdup( buf );
184 tmp.mod_values = get_list( prompt3 );
186 if ( tmp.mod_values != NULL ) {
189 for ( i = 0; tmp.mod_values[i] != NULL; ++i )
191 bvals = (struct berval **)calloc( i + 1,
192 sizeof( struct berval *));
193 for ( i = 0; tmp.mod_values[i] != NULL; ++i ) {
194 bvals[i] = (struct berval *)malloc(
195 sizeof( struct berval ));
196 if ( strncmp( tmp.mod_values[i], "{FILE}",
198 if ( file_read( tmp.mod_values[i] + 6,
203 bvals[i]->bv_val = tmp.mod_values[i];
205 strlen( tmp.mod_values[i] );
208 tmp.mod_bvalues = bvals;
209 tmp.mod_op |= LDAP_MOD_BVALUES;
212 if ( result == NULL )
213 result = (LDAPMod **) malloc( sizeof(LDAPMod *) );
215 result = (LDAPMod **) realloc( result,
216 sizeof(LDAPMod *) * (num + 1) );
218 result[num] = (LDAPMod *) malloc( sizeof(LDAPMod) );
219 *(result[num]) = tmp; /* struct copy */
222 if ( result == NULL )
224 result = (LDAPMod **) realloc( result, sizeof(LDAPMod *) * (num + 1) );
232 bind_prompt( LDAP *ld, char **dnp, char **passwdp, int *authmethodp,
235 static char dn[256], passwd[256];
239 getline( dn, sizeof(dn), stdin,
240 "re-bind method (0->simple, 1->krbv41, 2->krbv42, 3->krbv41&2)? " );
241 if (( *authmethodp = atoi( dn )) == 3 ) {
242 *authmethodp = LDAP_AUTH_KRBV4;
244 *authmethodp |= 0x80;
246 #else /* HAVE_KERBEROS */
247 *authmethodp = LDAP_AUTH_SIMPLE;
248 #endif /* HAVE_KERBEROS */
250 getline( dn, sizeof(dn), stdin, "re-bind dn? " );
251 strcat( dn, dnsuffix );
254 if ( *authmethodp == LDAP_AUTH_SIMPLE && dn[0] != '\0' ) {
255 getline( passwd, sizeof(passwd), stdin,
256 "re-bind password? " );
263 return( LDAP_SUCCESS );
268 main( int argc, char **argv )
271 int i, c, port, cldapflg, errflg, method, id, msgtype;
272 char line[256], command1, command2, command3;
273 char passwd[64], dn[256], rdn[64], attr[64], value[256];
274 char filter[256], *host, **types;
276 char *usage = "usage: %s [-u] [-h host] [-d level] [-s dnsuffix] [-p port] [-t file] [-T file]\n";
277 int bound, all, scope, attrsonly;
279 LDAPMod **mods, **attrs;
280 struct timeval timeout;
281 char *copyfname = NULL;
288 cldapflg = errflg = 0;
290 while (( c = getopt( argc, argv, "uh:d:s:p:t:T:" )) != -1 ) {
293 #ifdef LDAP_CONNECTIONLESS
295 #else /* LDAP_CONNECTIONLESS */
296 printf( "Compile with -DLDAP_CONNECTIONLESS for UDP support\n" );
297 #endif /* LDAP_CONNECTIONLESS */
302 ldap_debug = atoi( optarg );
304 if ( ldap_debug & LDAP_DEBUG_PACKETS ) {
305 ber_set_option( NULL, LBER_OPT_DEBUG_LEVEL, &ldap_debug );
309 printf( "Compile with -DLDAP_DEBUG for debugging\n" );
322 port = atoi( optarg );
325 case 't': /* copy ber's to given file */
326 copyfname = strdup( optarg );
327 copyoptions = LBER_TO_FILE;
330 case 'T': /* only output ber's to given file */
331 copyfname = strdup( optarg );
332 copyoptions = (LBER_TO_FILE | LBER_TO_FILE_ONLY);
340 if ( host == NULL && optind == argc - 1 ) {
341 host = argv[ optind ];
345 if ( errflg || optind < argc - 1 ) {
346 fprintf( stderr, usage, argv[ 0 ] );
347 exit( EXIT_FAILURE );
350 printf( "%s( %s, %d )\n",
351 cldapflg ? "cldap_open" : "ldap_init",
352 host == NULL ? "(null)" : host, port );
355 #ifdef LDAP_CONNECTIONLESS
356 ld = cldap_open( host, port );
357 #endif /* LDAP_CONNECTIONLESS */
359 ld = ldap_init( host, port );
363 perror( cldapflg ? "cldap_open" : "ldap_init" );
364 exit( EXIT_FAILURE );
367 if ( copyfname != NULL ) {
368 if ( (ld->ld_sb.sb_fd = open( copyfname, O_WRONLY | O_CREAT,
371 exit ( EXIT_FAILURE );
373 ld->ld_sb.sb_options = copyoptions;
380 (void) memset( line, '\0', sizeof(line) );
381 while ( getline( line, sizeof(line), stdin, "\ncommand? " ) != NULL ) {
386 switch ( command1 ) {
387 case 'a': /* add or abandon */
388 switch ( command2 ) {
390 getline( dn, sizeof(dn), stdin, "dn? " );
391 strcat( dn, dnsuffix );
392 if ( (attrs = get_modlist( NULL, "attr? ",
393 "value? " )) == NULL )
395 if ( (id = ldap_add( ld, dn, attrs )) == -1 )
396 ldap_perror( ld, "ldap_add" );
398 printf( "Add initiated with id %d\n",
402 case 'b': /* abandon */
403 getline( line, sizeof(line), stdin, "msgid? " );
405 if ( ldap_abandon( ld, id ) != 0 )
406 ldap_perror( ld, "ldap_abandon" );
408 printf( "Abandon successful\n" );
411 printf( "Possibilities: [ad]d, [ab]ort\n" );
415 case 'b': /* asynch bind */
417 getline( line, sizeof(line), stdin,
418 "method (0->simple, 1->krbv41, 2->krbv42)? " );
419 method = atoi( line ) | 0x80;
420 #else /* HAVE_KERBEROS */
421 method = LDAP_AUTH_SIMPLE;
422 #endif /* HAVE_KERBEROS */
423 getline( dn, sizeof(dn), stdin, "dn? " );
424 strcat( dn, dnsuffix );
426 if ( method == LDAP_AUTH_SIMPLE && dn[0] != '\0' )
427 getline( passwd, sizeof(passwd), stdin,
432 if ( ldap_bind( ld, dn, passwd, method ) == -1 ) {
433 fprintf( stderr, "ldap_bind failed\n" );
434 ldap_perror( ld, "ldap_bind" );
436 printf( "Bind initiated\n" );
441 case 'B': /* synch bind */
443 getline( line, sizeof(line), stdin,
444 "method 0->simple 1->krbv41 2->krbv42 3->krb? " );
445 method = atoi( line );
447 method = LDAP_AUTH_KRBV4;
449 method = method | 0x80;
450 #else /* HAVE_KERBEROS */
451 method = LDAP_AUTH_SIMPLE;
452 #endif /* HAVE_KERBEROS */
453 getline( dn, sizeof(dn), stdin, "dn? " );
454 strcat( dn, dnsuffix );
457 getline( passwd, sizeof(passwd), stdin,
462 if ( ldap_bind_s( ld, dn, passwd, method ) !=
464 fprintf( stderr, "ldap_bind_s failed\n" );
465 ldap_perror( ld, "ldap_bind_s" );
467 printf( "Bind successful\n" );
472 case 'c': /* compare */
473 getline( dn, sizeof(dn), stdin, "dn? " );
474 strcat( dn, dnsuffix );
475 getline( attr, sizeof(attr), stdin, "attr? " );
476 getline( value, sizeof(value), stdin, "value? " );
478 if ( (id = ldap_compare( ld, dn, attr, value )) == -1 )
479 ldap_perror( ld, "ldap_compare" );
481 printf( "Compare initiated with id %d\n", id );
484 case 'd': /* turn on debugging */
486 getline( line, sizeof(line), stdin, "debug level? " );
487 ldap_debug = atoi( line );
489 if ( ldap_debug & LDAP_DEBUG_PACKETS ) {
490 ber_set_option( NULL, LBER_OPT_DEBUG_LEVEL, &ldap_debug );
494 printf( "Compile with -DLDAP_DEBUG for debugging\n" );
498 case 'E': /* explode a dn */
499 getline( line, sizeof(line), stdin, "dn? " );
500 exdn = ldap_explode_dn( line, 0 );
501 for ( i = 0; exdn != NULL && exdn[i] != NULL; i++ ) {
502 printf( "\t%s\n", exdn[i] );
506 case 'g': /* set next msgid */
507 getline( line, sizeof(line), stdin, "msgid? " );
508 ld->ld_msgid = atoi( line );
511 case 'v': /* set version number */
512 getline( line, sizeof(line), stdin, "version? " );
513 ld->ld_version = atoi( line );
516 case 'm': /* modify or modifyrdn */
517 if ( strncmp( line, "modify", 4 ) == 0 ) {
518 getline( dn, sizeof(dn), stdin, "dn? " );
519 strcat( dn, dnsuffix );
520 if ( (mods = get_modlist(
521 "mod (0=>add, 1=>delete, 2=>replace -1=>done)? ",
522 "attribute type? ", "attribute value? " ))
525 if ( (id = ldap_modify( ld, dn, mods )) == -1 )
526 ldap_perror( ld, "ldap_modify" );
528 printf( "Modify initiated with id %d\n",
530 } else if ( strncmp( line, "modrdn", 4 ) == 0 ) {
531 getline( dn, sizeof(dn), stdin, "dn? " );
532 strcat( dn, dnsuffix );
533 getline( rdn, sizeof(rdn), stdin, "newrdn? " );
534 if ( (id = ldap_modrdn( ld, dn, rdn )) == -1 )
535 ldap_perror( ld, "ldap_modrdn" );
537 printf( "Modrdn initiated with id %d\n",
540 printf( "Possibilities: [modi]fy, [modr]dn\n" );
545 #ifdef LDAP_CONNECTIONLESS
548 #endif /* LDAP_CONNECTIONLESS */
553 exit( EXIT_SUCCESS );
556 case 'r': /* result or remove */
557 switch ( command3 ) {
558 case 's': /* result */
559 getline( line, sizeof(line), stdin,
560 "msgid (-1=>any)? " );
561 if ( line[0] == '\0' )
565 getline( line, sizeof(line), stdin,
566 "all (0=>any, 1=>all)? " );
567 if ( line[0] == '\0' )
571 if (( msgtype = ldap_result( ld, id, all,
572 &timeout, &res )) < 1 ) {
573 ldap_perror( ld, "ldap_result" );
576 printf( "\nresult: msgtype %d msgid %d\n",
577 msgtype, res->lm_msgid );
578 handle_result( ld, res );
582 case 'm': /* remove */
583 getline( dn, sizeof(dn), stdin, "dn? " );
584 strcat( dn, dnsuffix );
585 if ( (id = ldap_delete( ld, dn )) == -1 )
586 ldap_perror( ld, "ldap_delete" );
588 printf( "Remove initiated with id %d\n",
593 printf( "Possibilities: [rem]ove, [res]ult\n" );
598 case 's': /* search */
599 getline( dn, sizeof(dn), stdin, "searchbase? " );
600 strcat( dn, dnsuffix );
601 getline( line, sizeof(line), stdin,
602 "scope (0=Base, 1=One Level, 2=Subtree)? " );
603 scope = atoi( line );
604 getline( filter, sizeof(filter), stdin,
605 "search filter (e.g. sn=jones)? " );
606 types = get_list( "attrs to return? " );
607 getline( line, sizeof(line), stdin,
608 "attrsonly (0=attrs&values, 1=attrs only)? " );
609 attrsonly = atoi( line );
612 #ifdef LDAP_CONNECTIONLESS
613 getline( line, sizeof(line), stdin,
614 "Requestor DN (for logging)? " );
615 if ( cldap_search_s( ld, dn, scope, filter, types,
616 attrsonly, &res, line ) != 0 ) {
617 ldap_perror( ld, "cldap_search_s" );
619 printf( "\nresult: msgid %d\n",
621 handle_result( ld, res );
624 #endif /* LDAP_CONNECTIONLESS */
626 if (( id = ldap_search( ld, dn, scope, filter,
627 types, attrsonly )) == -1 ) {
628 ldap_perror( ld, "ldap_search" );
630 printf( "Search initiated with id %d\n", id );
636 case 't': /* set timeout value */
637 getline( line, sizeof(line), stdin, "timeout? " );
638 timeout.tv_sec = atoi( line );
641 case 'U': /* set ufn search prefix */
642 getline( line, sizeof(line), stdin, "ufn prefix? " );
643 ldap_ufn_setprefix( ld, line );
646 case 'u': /* user friendly search w/optional timeout */
647 getline( dn, sizeof(dn), stdin, "ufn? " );
648 strcat( dn, dnsuffix );
649 types = get_list( "attrs to return? " );
650 getline( line, sizeof(line), stdin,
651 "attrsonly (0=attrs&values, 1=attrs only)? " );
652 attrsonly = atoi( line );
654 if ( command2 == 't' ) {
655 id = ldap_ufn_search_c( ld, dn, types,
656 attrsonly, &res, ldap_ufn_timeout,
659 id = ldap_ufn_search_s( ld, dn, types,
663 ldap_perror( ld, "ldap_ufn_search" );
665 printf( "\nresult: err %d\n", id );
666 handle_result( ld, res );
672 case 'l': /* URL search */
673 getline( line, sizeof(line), stdin,
674 "attrsonly (0=attrs&values, 1=attrs only)? " );
675 attrsonly = atoi( line );
676 getline( line, sizeof(line), stdin, "LDAP URL? " );
677 if (( id = ldap_url_search( ld, line, attrsonly ))
679 ldap_perror( ld, "ldap_url_search" );
681 printf( "URL search initiated with id %d\n", id );
685 case 'p': /* parse LDAP URL */
686 getline( line, sizeof(line), stdin, "LDAP URL? " );
687 if (( i = ldap_url_parse( line, &ludp )) != 0 ) {
688 fprintf( stderr, "ldap_url_parse: error %d\n", i );
690 printf( "\t host: " );
691 if ( ludp->lud_host == NULL ) {
692 printf( "DEFAULT\n" );
694 printf( "<%s>\n", ludp->lud_host );
696 printf( "\t port: " );
697 if ( ludp->lud_port == 0 ) {
698 printf( "DEFAULT\n" );
700 printf( "%d\n", ludp->lud_port );
702 printf( "\t dn: <%s>\n", ludp->lud_dn );
703 printf( "\t attrs:" );
704 if ( ludp->lud_attrs == NULL ) {
707 for ( i = 0; ludp->lud_attrs[ i ] != NULL; ++i ) {
708 printf( " <%s>", ludp->lud_attrs[ i ] );
711 printf( "\n\t scope: %s\n", ludp->lud_scope == LDAP_SCOPE_ONELEVEL ?
712 "ONE" : ludp->lud_scope == LDAP_SCOPE_BASE ? "BASE" :
713 ludp->lud_scope == LDAP_SCOPE_SUBTREE ? "SUB" : "**invalid**" );
714 printf( "\tfilter: <%s>\n", ludp->lud_filter );
715 ldap_free_urldesc( ludp );
719 case 'n': /* set dn suffix, for convenience */
720 getline( line, sizeof(line), stdin, "DN suffix? " );
721 strcpy( dnsuffix, line );
724 case 'e': /* enable cache */
726 printf( NOCACHEERRMSG );
727 #else /* LDAP_NOCACHE */
728 getline( line, sizeof(line), stdin, "Cache timeout (secs)? " );
730 getline( line, sizeof(line), stdin, "Maximum memory to use (bytes)? " );
731 if ( ldap_enable_cache( ld, i, atoi( line )) == 0 ) {
732 printf( "local cache is on\n" );
734 printf( "ldap_enable_cache failed\n" );
736 #endif /* LDAP_NOCACHE */
739 case 'x': /* uncache entry */
741 printf( NOCACHEERRMSG );
742 #else /* LDAP_NOCACHE */
743 getline( line, sizeof(line), stdin, "DN? " );
744 ldap_uncache_entry( ld, line );
745 #endif /* LDAP_NOCACHE */
748 case 'X': /* uncache request */
750 printf( NOCACHEERRMSG );
751 #else /* LDAP_NOCACHE */
752 getline( line, sizeof(line), stdin, "request msgid? " );
753 ldap_uncache_request( ld, atoi( line ));
754 #endif /* LDAP_NOCACHE */
757 case 'o': /* set ldap options */
758 getline( line, sizeof(line), stdin, "alias deref (0=never, 1=searching, 2=finding, 3=always)?" );
759 ld->ld_deref = atoi( line );
760 getline( line, sizeof(line), stdin, "timelimit?" );
761 ld->ld_timelimit = atoi( line );
762 getline( line, sizeof(line), stdin, "sizelimit?" );
763 ld->ld_sizelimit = atoi( line );
765 LDAP_BOOL_ZERO(&ld->ld_options);
767 #ifdef STR_TRANSLATION
768 getline( line, sizeof(line), stdin,
769 "Automatic translation of T.61 strings (0=no, 1=yes)?" );
770 if ( atoi( line ) == 0 ) {
771 ld->ld_lberoptions &= ~LBER_TRANSLATE_STRINGS;
773 ld->ld_lberoptions |= LBER_TRANSLATE_STRINGS;
774 #ifdef LDAP_CHARSET_8859
775 getline( line, sizeof(line), stdin,
776 "Translate to/from ISO-8859 (0=no, 1=yes?" );
777 if ( atoi( line ) != 0 ) {
778 ldap_set_string_translators( ld,
782 #endif /* LDAP_CHARSET_8859 */
784 #endif /* STR_TRANSLATION */
786 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
787 getline( line, sizeof(line), stdin,
788 "Use DN & DNS to determine where to send requests (0=no, 1=yes)?" );
789 if ( atoi( line ) != 0 ) {
790 LDAP_BOOL_SET(&ld->ld_options, LDAP_BOOL_DNS);
792 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
794 getline( line, sizeof(line), stdin,
795 "Recognize and chase referrals (0=no, 1=yes)?" );
796 if ( atoi( line ) != 0 ) {
797 LDAP_BOOL_SET(&ld->ld_options, LDAP_BOOL_REFERRALS);
798 getline( line, sizeof(line), stdin,
799 "Prompt for bind credentials when chasing referrals (0=no, 1=yes)?" );
800 if ( atoi( line ) != 0 ) {
801 ldap_set_rebind_proc( ld, bind_prompt );
806 case 'O': /* set cache options */
808 printf( NOCACHEERRMSG );
809 #else /* LDAP_NOCACHE */
810 getline( line, sizeof(line), stdin, "cache errors (0=smart, 1=never, 2=always)?" );
811 switch( atoi( line )) {
813 ldap_set_cache_options( ld, 0 );
816 ldap_set_cache_options( ld,
817 LDAP_CACHE_OPT_CACHENOERRS );
820 ldap_set_cache_options( ld,
821 LDAP_CACHE_OPT_CACHEALLERRS );
824 printf( "not a valid cache option\n" );
826 #endif /* LDAP_NOCACHE */
830 printf( "Commands: [ad]d [ab]andon [b]ind\n" );
831 printf( " [B]ind async [c]ompare [l]URL search\n" );
832 printf( " [modi]fy [modr]dn [rem]ove\n" );
833 printf( " [res]ult [s]earch [q]uit/unbind\n\n" );
834 printf( " [u]fn search [ut]fn search with timeout\n" );
835 printf( " [d]ebug [e]nable cache set ms[g]id\n" );
836 printf( " d[n]suffix [t]imeout [v]ersion\n" );
837 printf( " [U]fn prefix [x]uncache entry [X]uncache request\n" );
838 printf( " [?]help [o]ptions [O]cache options\n" );
839 printf( " [E]xplode dn [p]arse LDAP URL\n" );
843 printf( "Invalid command. Type ? for help.\n" );
847 (void) memset( line, '\0', sizeof(line) );
854 handle_result( LDAP *ld, LDAPMessage *lm )
856 switch ( lm->lm_msgtype ) {
857 case LDAP_RES_COMPARE:
858 printf( "Compare result\n" );
859 print_ldap_result( ld, lm, "compare" );
862 case LDAP_RES_SEARCH_RESULT:
863 printf( "Search result\n" );
864 print_ldap_result( ld, lm, "search" );
867 case LDAP_RES_SEARCH_ENTRY:
868 printf( "Search entry\n" );
869 print_search_entry( ld, lm );
873 printf( "Add result\n" );
874 print_ldap_result( ld, lm, "add" );
877 case LDAP_RES_DELETE:
878 printf( "Delete result\n" );
879 print_ldap_result( ld, lm, "delete" );
882 case LDAP_RES_MODRDN:
883 printf( "ModRDN result\n" );
884 print_ldap_result( ld, lm, "modrdn" );
888 printf( "Bind result\n" );
889 print_ldap_result( ld, lm, "bind" );
893 printf( "Unknown result type 0x%lx\n",
894 (unsigned long) lm->lm_msgtype );
895 print_ldap_result( ld, lm, "unknown" );
900 print_ldap_result( LDAP *ld, LDAPMessage *lm, char *s )
902 ldap_result2error( ld, lm, 1 );
903 ldap_perror( ld, s );
905 if ( ld->ld_error != NULL && *ld->ld_error != '\0' )
906 fprintf( stderr, "Additional info: %s\n", ld->ld_error );
907 if ( LDAP_NAME_ERROR( ld->ld_errno ) && ld->ld_matched != NULL )
908 fprintf( stderr, "Matched DN: %s\n", ld->ld_matched );
913 print_search_entry( LDAP *ld, LDAPMessage *res )
917 for ( e = ldap_first_entry( ld, res ); e != NULL;
918 e = ldap_next_entry( ld, e ) )
920 BerElement *ber = NULL;
923 if ( e->lm_msgtype == LDAP_RES_SEARCH_RESULT )
926 dn = ldap_get_dn( ld, e );
927 printf( "\tDN: %s\n", dn );
929 ufn = ldap_dn2ufn( dn );
930 printf( "\tUFN: %s\n", ufn );
935 for ( a = ldap_first_attribute( ld, e, &ber ); a != NULL;
936 a = ldap_next_attribute( ld, e, ber ) )
938 struct berval **vals;
940 printf( "\t\tATTR: %s\n", a );
941 if ( (vals = ldap_get_values_len( ld, e, a ))
943 printf( "\t\t\t(no values)\n" );
946 for ( i = 0; vals[i] != NULL; i++ ) {
950 for ( j = 0; (ber_len_t) j < vals[i]->bv_len; j++ )
951 if ( !isascii( vals[i]->bv_val[j] ) ) {
957 printf( "\t\t\tlength (%ld) (not ascii)\n", vals[i]->bv_len );
958 #ifdef BPRINT_NONASCII
959 ber_bprint( vals[i]->bv_val,
961 #endif /* BPRINT_NONASCII */
964 printf( "\t\t\tlength (%ld) %s\n",
965 vals[i]->bv_len, vals[i]->bv_val );
967 ber_bvecfree( vals );
976 if ( res->lm_msgtype == LDAP_RES_SEARCH_RESULT
977 || res->lm_chain != NULL )
978 print_ldap_result( ld, res, "search" );