3 * Copyright 1998-2000 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, LDAP_CONST char *url, int request, ber_int_t msgid)
234 static char dn[256], passwd[256];
237 printf("rebind for request=%d msgid=%ld url=%s\n",
238 request, (long) msgid, url );
240 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
241 getline( dn, sizeof(dn), stdin,
242 "re-bind method (0->simple, 1->krbv41, 2->krbv42, 3->krbv41&2)? " );
243 if (( authmethod = atoi( dn )) == 3 ) {
244 authmethod = LDAP_AUTH_KRBV4;
248 #else /* LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND */
249 authmethod = LDAP_AUTH_SIMPLE;
250 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND */
252 getline( dn, sizeof(dn), stdin, "re-bind dn? " );
253 strcat( dn, dnsuffix );
255 if ( authmethod == LDAP_AUTH_SIMPLE && dn[0] != '\0' ) {
256 getline( passwd, sizeof(passwd), stdin,
257 "re-bind password? " );
262 return ldap_bind_s( ld, dn, passwd, authmethod);
267 main( int argc, char **argv )
270 int i, c, port, cldapflg, errflg, method, id, msgtype;
271 char line[256], command1, command2, command3;
272 char passwd[64], dn[256], rdn[64], attr[64], value[256];
273 char filter[256], *host, **types;
275 char *usage = "usage: %s [-u] [-h host] [-d level] [-s dnsuffix] [-p port] [-t file] [-T file]\n";
276 int bound, all, scope, attrsonly;
278 LDAPMod **mods, **attrs;
279 struct timeval timeout;
280 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 );
303 if ( ldap_debug & LDAP_DEBUG_PACKETS ) {
304 ber_set_option( NULL, LBER_OPT_DEBUG_LEVEL, &ldap_debug );
308 printf( "Compile with -DLDAP_DEBUG for debugging\n" );
321 port = atoi( optarg );
324 case 't': /* copy ber's to given file */
325 copyfname = strdup( optarg );
326 /* copyoptions = LBER_TO_FILE; */
329 case 'T': /* only output ber's to given file */
330 copyfname = strdup( optarg );
331 /* copyoptions = (LBER_TO_FILE | LBER_TO_FILE_ONLY); */
339 if ( host == NULL && optind == argc - 1 ) {
340 host = argv[ optind ];
344 if ( errflg || optind < argc - 1 ) {
345 fprintf( stderr, usage, argv[ 0 ] );
346 exit( EXIT_FAILURE );
349 printf( "%s( %s, %d )\n",
350 cldapflg ? "cldap_open" : "ldap_init",
351 host == NULL ? "(null)" : host, port );
354 #ifdef LDAP_CONNECTIONLESS
355 ld = cldap_open( host, port );
356 #endif /* LDAP_CONNECTIONLESS */
358 ld = ldap_init( host, port );
362 perror( cldapflg ? "cldap_open" : "ldap_init" );
363 exit( EXIT_FAILURE );
366 if ( copyfname != NULL ) {
367 if ( ( ld->ld_sb->sb_fd = open( copyfname, O_WRONLY | O_CREAT,
370 exit ( EXIT_FAILURE );
372 ld->ld_sb->sb_options = copyoptions;
379 (void) memset( line, '\0', sizeof(line) );
380 while ( getline( line, sizeof(line), stdin, "\ncommand? " ) != NULL ) {
385 switch ( command1 ) {
386 case 'a': /* add or abandon */
387 switch ( command2 ) {
389 getline( dn, sizeof(dn), stdin, "dn? " );
390 strcat( dn, dnsuffix );
391 if ( (attrs = get_modlist( NULL, "attr? ",
392 "value? " )) == NULL )
394 if ( (id = ldap_add( ld, dn, attrs )) == -1 )
395 ldap_perror( ld, "ldap_add" );
397 printf( "Add initiated with id %d\n",
401 case 'b': /* abandon */
402 getline( line, sizeof(line), stdin, "msgid? " );
404 if ( ldap_abandon( ld, id ) != 0 )
405 ldap_perror( ld, "ldap_abandon" );
407 printf( "Abandon successful\n" );
410 printf( "Possibilities: [ad]d, [ab]ort\n" );
414 case 'b': /* asynch bind */
415 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
416 getline( line, sizeof(line), stdin,
417 "method (0->simple, 1->krbv41, 2->krbv42)? " );
418 method = atoi( line ) | 0x80;
419 #else /* LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND */
420 method = LDAP_AUTH_SIMPLE;
421 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND */
422 getline( dn, sizeof(dn), stdin, "dn? " );
423 strcat( dn, dnsuffix );
425 if ( method == LDAP_AUTH_SIMPLE && dn[0] != '\0' )
426 getline( passwd, sizeof(passwd), stdin,
431 if ( ldap_bind( ld, dn, passwd, method ) == -1 ) {
432 fprintf( stderr, "ldap_bind failed\n" );
433 ldap_perror( ld, "ldap_bind" );
435 printf( "Bind initiated\n" );
440 case 'B': /* synch bind */
441 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
442 getline( line, sizeof(line), stdin,
443 "method 0->simple 1->krbv41 2->krbv42 3->krb? " );
444 method = atoi( line );
446 method = LDAP_AUTH_KRBV4;
448 method = method | 0x80;
449 #else /* LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND */
450 method = LDAP_AUTH_SIMPLE;
451 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND */
452 getline( dn, sizeof(dn), stdin, "dn? " );
453 strcat( dn, dnsuffix );
456 getline( passwd, sizeof(passwd), stdin,
461 if ( ldap_bind_s( ld, dn, passwd, method ) !=
463 fprintf( stderr, "ldap_bind_s failed\n" );
464 ldap_perror( ld, "ldap_bind_s" );
466 printf( "Bind successful\n" );
471 case 'c': /* compare */
472 getline( dn, sizeof(dn), stdin, "dn? " );
473 strcat( dn, dnsuffix );
474 getline( attr, sizeof(attr), stdin, "attr? " );
475 getline( value, sizeof(value), stdin, "value? " );
477 if ( (id = ldap_compare( ld, dn, attr, value )) == -1 )
478 ldap_perror( ld, "ldap_compare" );
480 printf( "Compare initiated with id %d\n", id );
483 case 'd': /* turn on debugging */
485 getline( line, sizeof(line), stdin, "debug level? " );
486 ldap_debug = atoi( line );
488 if ( ldap_debug & LDAP_DEBUG_PACKETS ) {
489 ber_set_option( NULL, LBER_OPT_DEBUG_LEVEL, &ldap_debug );
493 printf( "Compile with -DLDAP_DEBUG for debugging\n" );
497 case 'E': /* explode a dn */
498 getline( line, sizeof(line), stdin, "dn? " );
499 exdn = ldap_explode_dn( line, 0 );
500 for ( i = 0; exdn != NULL && exdn[i] != NULL; i++ ) {
501 printf( "\t%s\n", exdn[i] );
505 case 'g': /* set next msgid */
506 getline( line, sizeof(line), stdin, "msgid? " );
507 ld->ld_msgid = atoi( line );
510 case 'v': /* set version number */
511 getline( line, sizeof(line), stdin, "version? " );
512 ld->ld_version = atoi( line );
515 case 'm': /* modify or modifyrdn */
516 if ( strncmp( line, "modify", 4 ) == 0 ) {
517 getline( dn, sizeof(dn), stdin, "dn? " );
518 strcat( dn, dnsuffix );
519 if ( (mods = get_modlist(
520 "mod (0=>add, 1=>delete, 2=>replace -1=>done)? ",
521 "attribute type? ", "attribute value? " ))
524 if ( (id = ldap_modify( ld, dn, mods )) == -1 )
525 ldap_perror( ld, "ldap_modify" );
527 printf( "Modify initiated with id %d\n",
529 } else if ( strncmp( line, "modrdn", 4 ) == 0 ) {
530 getline( dn, sizeof(dn), stdin, "dn? " );
531 strcat( dn, dnsuffix );
532 getline( rdn, sizeof(rdn), stdin, "newrdn? " );
533 if ( (id = ldap_modrdn( ld, dn, rdn )) == -1 )
534 ldap_perror( ld, "ldap_modrdn" );
536 printf( "Modrdn initiated with id %d\n",
539 printf( "Possibilities: [modi]fy, [modr]dn\n" );
544 #ifdef LDAP_CONNECTIONLESS
547 #endif /* LDAP_CONNECTIONLESS */
552 exit( EXIT_SUCCESS );
555 case 'r': /* result or remove */
556 switch ( command3 ) {
557 case 's': /* result */
558 getline( line, sizeof(line), stdin,
559 "msgid (-1=>any)? " );
560 if ( line[0] == '\0' )
564 getline( line, sizeof(line), stdin,
565 "all (0=>any, 1=>all)? " );
566 if ( line[0] == '\0' )
570 if (( msgtype = ldap_result( ld, id, all,
571 &timeout, &res )) < 1 ) {
572 ldap_perror( ld, "ldap_result" );
575 printf( "\nresult: msgtype %d msgid %d\n",
576 msgtype, res->lm_msgid );
577 handle_result( ld, res );
581 case 'm': /* remove */
582 getline( dn, sizeof(dn), stdin, "dn? " );
583 strcat( dn, dnsuffix );
584 if ( (id = ldap_delete( ld, dn )) == -1 )
585 ldap_perror( ld, "ldap_delete" );
587 printf( "Remove initiated with id %d\n",
592 printf( "Possibilities: [rem]ove, [res]ult\n" );
597 case 's': /* search */
598 getline( dn, sizeof(dn), stdin, "searchbase? " );
599 strcat( dn, dnsuffix );
600 getline( line, sizeof(line), stdin,
601 "scope (0=Base, 1=One Level, 2=Subtree)? " );
602 scope = atoi( line );
603 getline( filter, sizeof(filter), stdin,
604 "search filter (e.g. sn=jones)? " );
605 types = get_list( "attrs to return? " );
606 getline( line, sizeof(line), stdin,
607 "attrsonly (0=attrs&values, 1=attrs only)? " );
608 attrsonly = atoi( line );
611 #ifdef LDAP_CONNECTIONLESS
612 getline( line, sizeof(line), stdin,
613 "Requestor DN (for logging)? " );
614 if ( cldap_search_s( ld, dn, scope, filter, types,
615 attrsonly, &res, line ) != 0 ) {
616 ldap_perror( ld, "cldap_search_s" );
618 printf( "\nresult: msgid %d\n",
620 handle_result( ld, res );
623 #endif /* LDAP_CONNECTIONLESS */
625 if (( id = ldap_search( ld, dn, scope, filter,
626 types, attrsonly )) == -1 ) {
627 ldap_perror( ld, "ldap_search" );
629 printf( "Search initiated with id %d\n", id );
635 case 't': /* set timeout value */
636 getline( line, sizeof(line), stdin, "timeout? " );
637 timeout.tv_sec = atoi( line );
640 case 'U': /* set ufn search prefix */
641 getline( line, sizeof(line), stdin, "ufn prefix? " );
642 ldap_ufn_setprefix( ld, line );
645 case 'u': /* user friendly search w/optional timeout */
646 getline( dn, sizeof(dn), stdin, "ufn? " );
647 strcat( dn, dnsuffix );
648 types = get_list( "attrs to return? " );
649 getline( line, sizeof(line), stdin,
650 "attrsonly (0=attrs&values, 1=attrs only)? " );
651 attrsonly = atoi( line );
653 if ( command2 == 't' ) {
654 id = ldap_ufn_search_c( ld, dn, types,
655 attrsonly, &res, ldap_ufn_timeout,
658 id = ldap_ufn_search_s( ld, dn, types,
662 ldap_perror( ld, "ldap_ufn_search" );
664 printf( "\nresult: err %d\n", id );
665 handle_result( ld, res );
671 case 'l': /* URL search */
672 getline( line, sizeof(line), stdin,
673 "attrsonly (0=attrs&values, 1=attrs only)? " );
674 attrsonly = atoi( line );
675 getline( line, sizeof(line), stdin, "LDAP URL? " );
676 if (( id = ldap_url_search( ld, line, attrsonly ))
678 ldap_perror( ld, "ldap_url_search" );
680 printf( "URL search initiated with id %d\n", id );
684 case 'p': /* parse LDAP URL */
685 getline( line, sizeof(line), stdin, "LDAP URL? " );
686 if (( i = ldap_url_parse( line, &ludp )) != 0 ) {
687 fprintf( stderr, "ldap_url_parse: error %d\n", i );
689 printf( "\t host: " );
690 if ( ludp->lud_host == NULL ) {
691 printf( "DEFAULT\n" );
693 printf( "<%s>\n", ludp->lud_host );
695 printf( "\t port: " );
696 if ( ludp->lud_port == 0 ) {
697 printf( "DEFAULT\n" );
699 printf( "%d\n", ludp->lud_port );
701 printf( "\t dn: <%s>\n", ludp->lud_dn );
702 printf( "\t attrs:" );
703 if ( ludp->lud_attrs == NULL ) {
706 for ( i = 0; ludp->lud_attrs[ i ] != NULL; ++i ) {
707 printf( " <%s>", ludp->lud_attrs[ i ] );
710 printf( "\n\t scope: %s\n", ludp->lud_scope == LDAP_SCOPE_ONELEVEL ?
711 "ONE" : ludp->lud_scope == LDAP_SCOPE_BASE ? "BASE" :
712 ludp->lud_scope == LDAP_SCOPE_SUBTREE ? "SUB" : "**invalid**" );
713 printf( "\tfilter: <%s>\n", ludp->lud_filter );
714 ldap_free_urldesc( ludp );
718 case 'n': /* set dn suffix, for convenience */
719 getline( line, sizeof(line), stdin, "DN suffix? " );
720 strcpy( dnsuffix, line );
723 case 'e': /* enable cache */
725 printf( NOCACHEERRMSG );
726 #else /* LDAP_NOCACHE */
727 getline( line, sizeof(line), stdin, "Cache timeout (secs)? " );
729 getline( line, sizeof(line), stdin, "Maximum memory to use (bytes)? " );
730 if ( ldap_enable_cache( ld, i, atoi( line )) == 0 ) {
731 printf( "local cache is on\n" );
733 printf( "ldap_enable_cache failed\n" );
735 #endif /* LDAP_NOCACHE */
738 case 'x': /* uncache entry */
740 printf( NOCACHEERRMSG );
741 #else /* LDAP_NOCACHE */
742 getline( line, sizeof(line), stdin, "DN? " );
743 ldap_uncache_entry( ld, line );
744 #endif /* LDAP_NOCACHE */
747 case 'X': /* uncache request */
749 printf( NOCACHEERRMSG );
750 #else /* LDAP_NOCACHE */
751 getline( line, sizeof(line), stdin, "request msgid? " );
752 ldap_uncache_request( ld, atoi( line ));
753 #endif /* LDAP_NOCACHE */
756 case 'o': /* set ldap options */
757 getline( line, sizeof(line), stdin, "alias deref (0=never, 1=searching, 2=finding, 3=always)?" );
758 ld->ld_deref = atoi( line );
759 getline( line, sizeof(line), stdin, "timelimit?" );
760 ld->ld_timelimit = atoi( line );
761 getline( line, sizeof(line), stdin, "sizelimit?" );
762 ld->ld_sizelimit = atoi( line );
764 LDAP_BOOL_ZERO(&ld->ld_options);
766 getline( line, sizeof(line), stdin,
767 "Recognize and chase referrals (0=no, 1=yes)?" );
768 if ( atoi( line ) != 0 ) {
769 LDAP_BOOL_SET(&ld->ld_options, LDAP_BOOL_REFERRALS);
770 getline( line, sizeof(line), stdin,
771 "Prompt for bind credentials when chasing referrals (0=no, 1=yes)?" );
772 if ( atoi( line ) != 0 ) {
773 ldap_set_rebind_proc( ld, bind_prompt );
778 case 'O': /* set cache options */
780 printf( NOCACHEERRMSG );
781 #else /* LDAP_NOCACHE */
782 getline( line, sizeof(line), stdin, "cache errors (0=smart, 1=never, 2=always)?" );
783 switch( atoi( line )) {
785 ldap_set_cache_options( ld, 0 );
788 ldap_set_cache_options( ld,
789 LDAP_CACHE_OPT_CACHENOERRS );
792 ldap_set_cache_options( ld,
793 LDAP_CACHE_OPT_CACHEALLERRS );
796 printf( "not a valid cache option\n" );
798 #endif /* LDAP_NOCACHE */
802 printf( "Commands: [ad]d [ab]andon [b]ind\n" );
803 printf( " [B]ind async [c]ompare [l]URL search\n" );
804 printf( " [modi]fy [modr]dn [rem]ove\n" );
805 printf( " [res]ult [s]earch [q]uit/unbind\n\n" );
806 printf( " [u]fn search [ut]fn search with timeout\n" );
807 printf( " [d]ebug [e]nable cache set ms[g]id\n" );
808 printf( " d[n]suffix [t]imeout [v]ersion\n" );
809 printf( " [U]fn prefix [x]uncache entry [X]uncache request\n" );
810 printf( " [?]help [o]ptions [O]cache options\n" );
811 printf( " [E]xplode dn [p]arse LDAP URL\n" );
815 printf( "Invalid command. Type ? for help.\n" );
819 (void) memset( line, '\0', sizeof(line) );
826 handle_result( LDAP *ld, LDAPMessage *lm )
828 switch ( lm->lm_msgtype ) {
829 case LDAP_RES_COMPARE:
830 printf( "Compare result\n" );
831 print_ldap_result( ld, lm, "compare" );
834 case LDAP_RES_SEARCH_RESULT:
835 printf( "Search result\n" );
836 print_ldap_result( ld, lm, "search" );
839 case LDAP_RES_SEARCH_ENTRY:
840 printf( "Search entry\n" );
841 print_search_entry( ld, lm );
845 printf( "Add result\n" );
846 print_ldap_result( ld, lm, "add" );
849 case LDAP_RES_DELETE:
850 printf( "Delete result\n" );
851 print_ldap_result( ld, lm, "delete" );
854 case LDAP_RES_MODRDN:
855 printf( "ModRDN result\n" );
856 print_ldap_result( ld, lm, "modrdn" );
860 printf( "Bind result\n" );
861 print_ldap_result( ld, lm, "bind" );
865 printf( "Unknown result type 0x%lx\n",
866 (unsigned long) lm->lm_msgtype );
867 print_ldap_result( ld, lm, "unknown" );
872 print_ldap_result( LDAP *ld, LDAPMessage *lm, char *s )
874 ldap_result2error( ld, lm, 1 );
875 ldap_perror( ld, s );
877 if ( ld->ld_error != NULL && *ld->ld_error != '\0' )
878 fprintf( stderr, "Additional info: %s\n", ld->ld_error );
879 if ( LDAP_NAME_ERROR( ld->ld_errno ) && ld->ld_matched != NULL )
880 fprintf( stderr, "Matched DN: %s\n", ld->ld_matched );
885 print_search_entry( LDAP *ld, LDAPMessage *res )
889 for ( e = ldap_first_entry( ld, res ); e != NULL;
890 e = ldap_next_entry( ld, e ) )
892 BerElement *ber = NULL;
895 if ( e->lm_msgtype == LDAP_RES_SEARCH_RESULT )
898 dn = ldap_get_dn( ld, e );
899 printf( "\tDN: %s\n", dn );
901 ufn = ldap_dn2ufn( dn );
902 printf( "\tUFN: %s\n", ufn );
907 for ( a = ldap_first_attribute( ld, e, &ber ); a != NULL;
908 a = ldap_next_attribute( ld, e, ber ) )
910 struct berval **vals;
912 printf( "\t\tATTR: %s\n", a );
913 if ( (vals = ldap_get_values_len( ld, e, a ))
915 printf( "\t\t\t(no values)\n" );
918 for ( i = 0; vals[i] != NULL; i++ ) {
922 for ( j = 0; (ber_len_t) j < vals[i]->bv_len; j++ )
923 if ( !isascii( vals[i]->bv_val[j] ) ) {
929 printf( "\t\t\tlength (%ld) (not ascii)\n", vals[i]->bv_len );
930 #ifdef BPRINT_NONASCII
931 ber_bprint( vals[i]->bv_val,
933 #endif /* BPRINT_NONASCII */
936 printf( "\t\t\tlength (%ld) %s\n",
937 vals[i]->bv_len, vals[i]->bv_val );
939 ber_bvecfree( vals );
948 if ( res->lm_msgtype == LDAP_RES_SEARCH_RESULT
949 || res->lm_chain != NULL )
950 print_ldap_result( ld, res, "search" );