2 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
3 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
10 #include <ac/stdlib.h>
13 #include <ac/socket.h>
14 #include <ac/string.h>
16 #include <ac/unistd.h>
20 #ifdef HAVE_SYS_FILE_H
29 /* including the "internal" defs is legit and nec. since this test routine has
30 * a-priori knowledge of libldap internal workings.
31 * hodges@stanford.edu 5-Feb-96
37 static char *getline LDAP_P(( char *line, int len, FILE *fp, char *prompt ));
39 static char **get_list LDAP_P(( char *prompt ));
40 static int file_read LDAP_P(( char *path, struct berval *bv ));
41 static LDAPMod **get_modlist LDAP_P(( char *prompt1, char *prompt2, char *prompt3 ));
42 static void handle_result LDAP_P(( LDAP *ld, LDAPMessage *lm ));
43 static void print_ldap_result LDAP_P(( LDAP *ld, LDAPMessage *lm, char *s ));
44 static void print_search_entry LDAP_P(( LDAP *ld, LDAPMessage *res ));
45 static void free_list LDAP_P(( char **list ));
47 #define NOCACHEERRMSG "don't compile with -DLDAP_NOCACHE if you desire local caching"
49 static char *dnsuffix;
53 getline( char *line, int len, FILE *fp, char *prompt )
57 if ( fgets( line, len, fp ) == NULL )
60 line[ strlen( line ) - 1 ] = '\0';
67 get_list( char *prompt )
76 getline( buf, sizeof(buf), stdin, prompt );
81 if ( result == (char **) 0 )
82 result = (char **) malloc( sizeof(char *) );
84 result = (char **) realloc( result,
85 sizeof(char *) * (num + 1) );
87 result[num++] = (char *) strdup( buf );
89 if ( result == (char **) 0 )
91 result = (char **) realloc( result, sizeof(char *) * (num + 1) );
99 free_list( char **list )
103 if ( list != NULL ) {
104 for ( i = 0; list[ i ] != NULL; ++i ) {
107 free( (char *)list );
113 file_read( char *path, struct berval *bv )
119 if (( fp = fopen( path, "r" )) == NULL ) {
124 if ( fseek( fp, 0L, SEEK_END ) != 0 ) {
130 bv->bv_len = ftell( fp );
132 if (( bv->bv_val = (char *)malloc( bv->bv_len )) == NULL ) {
138 if ( fseek( fp, 0L, SEEK_SET ) != 0 ) {
144 rlen = fread( bv->bv_val, 1, bv->bv_len, fp );
148 if ( (ber_len_t) rlen != bv->bv_len ) {
154 return( bv->bv_len );
159 get_modlist( char *prompt1, char *prompt2, char *prompt3 )
161 static char buf[256];
165 struct berval **bvals;
171 getline( buf, sizeof(buf), stdin, prompt1 );
172 tmp.mod_op = atoi( buf );
174 if ( tmp.mod_op == -1 || buf[0] == '\0' )
178 getline( buf, sizeof(buf), stdin, prompt2 );
179 if ( buf[0] == '\0' )
181 tmp.mod_type = strdup( buf );
183 tmp.mod_values = get_list( prompt3 );
185 if ( tmp.mod_values != NULL ) {
188 for ( i = 0; tmp.mod_values[i] != NULL; ++i )
190 bvals = (struct berval **)calloc( i + 1,
191 sizeof( struct berval *));
192 for ( i = 0; tmp.mod_values[i] != NULL; ++i ) {
193 bvals[i] = (struct berval *)malloc(
194 sizeof( struct berval ));
195 if ( strncmp( tmp.mod_values[i], "{FILE}",
197 if ( file_read( tmp.mod_values[i] + 6,
202 bvals[i]->bv_val = tmp.mod_values[i];
204 strlen( tmp.mod_values[i] );
207 tmp.mod_bvalues = bvals;
208 tmp.mod_op |= LDAP_MOD_BVALUES;
211 if ( result == NULL )
212 result = (LDAPMod **) malloc( sizeof(LDAPMod *) );
214 result = (LDAPMod **) realloc( result,
215 sizeof(LDAPMod *) * (num + 1) );
217 result[num] = (LDAPMod *) malloc( sizeof(LDAPMod) );
218 *(result[num]) = tmp; /* struct copy */
221 if ( result == NULL )
223 result = (LDAPMod **) realloc( result, sizeof(LDAPMod *) * (num + 1) );
231 bind_prompt( LDAP *ld, char **dnp, char **passwdp, int *authmethodp,
234 static char dn[256], passwd[256];
238 getline( dn, sizeof(dn), stdin,
239 "re-bind method (0->simple, 1->krbv41, 2->krbv42, 3->krbv41&2)? " );
240 if (( *authmethodp = atoi( dn )) == 3 ) {
241 *authmethodp = LDAP_AUTH_KRBV4;
243 *authmethodp |= 0x80;
245 #else /* HAVE_KERBEROS */
246 *authmethodp = LDAP_AUTH_SIMPLE;
247 #endif /* HAVE_KERBEROS */
249 getline( dn, sizeof(dn), stdin, "re-bind dn? " );
250 strcat( dn, dnsuffix );
253 if ( *authmethodp == LDAP_AUTH_SIMPLE && dn[0] != '\0' ) {
254 getline( passwd, sizeof(passwd), stdin,
255 "re-bind password? " );
262 return( LDAP_SUCCESS );
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 ] );
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" );
366 if ( copyfname != NULL ) {
367 if ( (ld->ld_sb.sb_fd = open( copyfname, O_WRONLY | O_CREAT,
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 */
416 getline( line, sizeof(line), stdin,
417 "method (0->simple, 1->krbv41, 2->krbv42)? " );
418 method = atoi( line ) | 0x80;
419 #else /* HAVE_KERBEROS */
420 method = LDAP_AUTH_SIMPLE;
421 #endif /* HAVE_KERBEROS */
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 */
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 /* HAVE_KERBEROS */
450 method = LDAP_AUTH_SIMPLE;
451 #endif /* HAVE_KERBEROS */
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 */
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 #ifdef STR_TRANSLATION
767 getline( line, sizeof(line), stdin,
768 "Automatic translation of T.61 strings (0=no, 1=yes)?" );
769 if ( atoi( line ) == 0 ) {
770 ld->ld_lberoptions &= ~LBER_TRANSLATE_STRINGS;
772 ld->ld_lberoptions |= LBER_TRANSLATE_STRINGS;
773 #ifdef LDAP_CHARSET_8859
774 getline( line, sizeof(line), stdin,
775 "Translate to/from ISO-8859 (0=no, 1=yes?" );
776 if ( atoi( line ) != 0 ) {
777 ldap_set_string_translators( ld,
781 #endif /* LDAP_CHARSET_8859 */
783 #endif /* STR_TRANSLATION */
785 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
786 getline( line, sizeof(line), stdin,
787 "Use DN & DNS to determine where to send requests (0=no, 1=yes)?" );
788 if ( atoi( line ) != 0 ) {
789 LDAP_BOOL_SET(&ld->ld_options, LDAP_BOOL_DNS);
791 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
793 getline( line, sizeof(line), stdin,
794 "Recognize and chase referrals (0=no, 1=yes)?" );
795 if ( atoi( line ) != 0 ) {
796 LDAP_BOOL_SET(&ld->ld_options, LDAP_BOOL_REFERRALS);
797 getline( line, sizeof(line), stdin,
798 "Prompt for bind credentials when chasing referrals (0=no, 1=yes)?" );
799 if ( atoi( line ) != 0 ) {
800 ldap_set_rebind_proc( ld, bind_prompt );
805 case 'O': /* set cache options */
807 printf( NOCACHEERRMSG );
808 #else /* LDAP_NOCACHE */
809 getline( line, sizeof(line), stdin, "cache errors (0=smart, 1=never, 2=always)?" );
810 switch( atoi( line )) {
812 ldap_set_cache_options( ld, 0 );
815 ldap_set_cache_options( ld,
816 LDAP_CACHE_OPT_CACHENOERRS );
819 ldap_set_cache_options( ld,
820 LDAP_CACHE_OPT_CACHEALLERRS );
823 printf( "not a valid cache option\n" );
825 #endif /* LDAP_NOCACHE */
829 printf( "Commands: [ad]d [ab]andon [b]ind\n" );
830 printf( " [B]ind async [c]ompare [l]URL search\n" );
831 printf( " [modi]fy [modr]dn [rem]ove\n" );
832 printf( " [res]ult [s]earch [q]uit/unbind\n\n" );
833 printf( " [u]fn search [ut]fn search with timeout\n" );
834 printf( " [d]ebug [e]nable cache set ms[g]id\n" );
835 printf( " d[n]suffix [t]imeout [v]ersion\n" );
836 printf( " [U]fn prefix [x]uncache entry [X]uncache request\n" );
837 printf( " [?]help [o]ptions [O]cache options\n" );
838 printf( " [E]xplode dn [p]arse LDAP URL\n" );
842 printf( "Invalid command. Type ? for help.\n" );
846 (void) memset( line, '\0', sizeof(line) );
853 handle_result( LDAP *ld, LDAPMessage *lm )
855 switch ( lm->lm_msgtype ) {
856 case LDAP_RES_COMPARE:
857 printf( "Compare result\n" );
858 print_ldap_result( ld, lm, "compare" );
861 case LDAP_RES_SEARCH_RESULT:
862 printf( "Search result\n" );
863 print_ldap_result( ld, lm, "search" );
866 case LDAP_RES_SEARCH_ENTRY:
867 printf( "Search entry\n" );
868 print_search_entry( ld, lm );
872 printf( "Add result\n" );
873 print_ldap_result( ld, lm, "add" );
876 case LDAP_RES_DELETE:
877 printf( "Delete result\n" );
878 print_ldap_result( ld, lm, "delete" );
881 case LDAP_RES_MODRDN:
882 printf( "ModRDN result\n" );
883 print_ldap_result( ld, lm, "modrdn" );
887 printf( "Bind result\n" );
888 print_ldap_result( ld, lm, "bind" );
892 printf( "Unknown result type 0x%x\n", lm->lm_msgtype );
893 print_ldap_result( ld, lm, "unknown" );
898 print_ldap_result( LDAP *ld, LDAPMessage *lm, char *s )
900 ldap_result2error( ld, lm, 1 );
901 ldap_perror( ld, s );
903 if ( ld->ld_error != NULL && *ld->ld_error != '\0' )
904 fprintf( stderr, "Additional info: %s\n", ld->ld_error );
905 if ( LDAP_NAME_ERROR( ld->ld_errno ) && ld->ld_matched != NULL )
906 fprintf( stderr, "Matched DN: %s\n", ld->ld_matched );
911 print_search_entry( LDAP *ld, LDAPMessage *res )
915 for ( e = ldap_first_entry( ld, res ); e != NULL;
916 e = ldap_next_entry( ld, e ) )
918 BerElement *ber = NULL;
921 if ( e->lm_msgtype == LDAP_RES_SEARCH_RESULT )
924 dn = ldap_get_dn( ld, e );
925 printf( "\tDN: %s\n", dn );
927 ufn = ldap_dn2ufn( dn );
928 printf( "\tUFN: %s\n", ufn );
933 for ( a = ldap_first_attribute( ld, e, &ber ); a != NULL;
934 a = ldap_next_attribute( ld, e, ber ) )
936 struct berval **vals;
938 printf( "\t\tATTR: %s\n", a );
939 if ( (vals = ldap_get_values_len( ld, e, a ))
941 printf( "\t\t\t(no values)\n" );
944 for ( i = 0; vals[i] != NULL; i++ ) {
948 for ( j = 0; (ber_len_t) j < vals[i]->bv_len; j++ )
949 if ( !isascii( vals[i]->bv_val[j] ) ) {
955 printf( "\t\t\tlength (%ld) (not ascii)\n", vals[i]->bv_len );
956 #ifdef BPRINT_NONASCII
957 ber_bprint( vals[i]->bv_val,
959 #endif /* BPRINT_NONASCII */
962 printf( "\t\t\tlength (%ld) %s\n",
963 vals[i]->bv_len, vals[i]->bv_val );
965 ber_bvecfree( vals );
974 if ( res->lm_msgtype == LDAP_RES_SEARCH_RESULT
975 || res->lm_chain != NULL )
976 print_ldap_result( ld, res, "search" );