2 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
3 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #include <ac/socket.h>
13 #include <ac/string.h>
15 #include <ac/unistd.h>
19 #ifdef HAVE_SYS_FILE_H
28 /* including the "internal" defs is legit and nec. since this test routine has
29 * a-priori knowledge of libldap internal workings.
30 * hodges@stanford.edu 5-Feb-96
36 static char *getline LDAP_P(( char *line, int len, FILE *fp, char *prompt ));
38 static char **get_list LDAP_P(( char *prompt ));
39 static int file_read LDAP_P(( char *path, struct berval *bv ));
40 static LDAPMod **get_modlist LDAP_P(( char *prompt1, char *prompt2, char *prompt3 ));
41 static void handle_result LDAP_P(( LDAP *ld, LDAPMessage *lm ));
42 static void print_ldap_result LDAP_P(( LDAP *ld, LDAPMessage *lm, char *s ));
43 static void print_search_entry LDAP_P(( LDAP *ld, LDAPMessage *res ));
44 static void free_list LDAP_P(( char **list ));
46 #define NOCACHEERRMSG "don't compile with -DLDAP_NOCACHE if you desire local caching"
48 static char *dnsuffix;
52 getline( char *line, int len, FILE *fp, char *prompt )
56 if ( fgets( line, len, fp ) == NULL )
59 line[ strlen( line ) - 1 ] = '\0';
66 get_list( char *prompt )
75 getline( buf, sizeof(buf), stdin, prompt );
80 if ( result == (char **) 0 )
81 result = (char **) malloc( sizeof(char *) );
83 result = (char **) realloc( result,
84 sizeof(char *) * (num + 1) );
86 result[num++] = (char *) strdup( buf );
88 if ( result == (char **) 0 )
90 result = (char **) realloc( result, sizeof(char *) * (num + 1) );
98 free_list( char **list )
102 if ( list != NULL ) {
103 for ( i = 0; list[ i ] != NULL; ++i ) {
106 free( (char *)list );
112 file_read( char *path, struct berval *bv )
118 if (( fp = fopen( path, "r" )) == NULL ) {
123 if ( fseek( fp, 0L, SEEK_END ) != 0 ) {
129 bv->bv_len = ftell( fp );
131 if (( bv->bv_val = (char *)malloc( bv->bv_len )) == NULL ) {
137 if ( fseek( fp, 0L, SEEK_SET ) != 0 ) {
143 rlen = fread( bv->bv_val, 1, bv->bv_len, fp );
147 if ( (unsigned long) rlen != bv->bv_len ) {
153 return( bv->bv_len );
158 get_modlist( char *prompt1, char *prompt2, char *prompt3 )
160 static char buf[256];
164 struct berval **bvals;
170 getline( buf, sizeof(buf), stdin, prompt1 );
171 tmp.mod_op = atoi( buf );
173 if ( tmp.mod_op == -1 || buf[0] == '\0' )
177 getline( buf, sizeof(buf), stdin, prompt2 );
178 if ( buf[0] == '\0' )
180 tmp.mod_type = strdup( buf );
182 tmp.mod_values = get_list( prompt3 );
184 if ( tmp.mod_values != NULL ) {
187 for ( i = 0; tmp.mod_values[i] != NULL; ++i )
189 bvals = (struct berval **)calloc( i + 1,
190 sizeof( struct berval *));
191 for ( i = 0; tmp.mod_values[i] != NULL; ++i ) {
192 bvals[i] = (struct berval *)malloc(
193 sizeof( struct berval ));
194 if ( strncmp( tmp.mod_values[i], "{FILE}",
196 if ( file_read( tmp.mod_values[i] + 6,
201 bvals[i]->bv_val = tmp.mod_values[i];
203 strlen( tmp.mod_values[i] );
206 tmp.mod_bvalues = bvals;
207 tmp.mod_op |= LDAP_MOD_BVALUES;
210 if ( result == NULL )
211 result = (LDAPMod **) malloc( sizeof(LDAPMod *) );
213 result = (LDAPMod **) realloc( result,
214 sizeof(LDAPMod *) * (num + 1) );
216 result[num] = (LDAPMod *) malloc( sizeof(LDAPMod) );
217 *(result[num]) = tmp; /* struct copy */
220 if ( result == NULL )
222 result = (LDAPMod **) realloc( result, sizeof(LDAPMod *) * (num + 1) );
230 bind_prompt( LDAP *ld, char **dnp, char **passwdp, int *authmethodp,
233 static char dn[256], passwd[256];
237 getline( dn, sizeof(dn), stdin,
238 "re-bind method (0->simple, 1->krbv41, 2->krbv42, 3->krbv41&2)? " );
239 if (( *authmethodp = atoi( dn )) == 3 ) {
240 *authmethodp = LDAP_AUTH_KRBV4;
242 *authmethodp |= 0x80;
244 #else /* HAVE_KERBEROS */
245 *authmethodp = LDAP_AUTH_SIMPLE;
246 #endif /* HAVE_KERBEROS */
248 getline( dn, sizeof(dn), stdin, "re-bind dn? " );
249 strcat( dn, dnsuffix );
252 if ( *authmethodp == LDAP_AUTH_SIMPLE && dn[0] != '\0' ) {
253 getline( passwd, sizeof(passwd), stdin,
254 "re-bind password? " );
261 return( LDAP_SUCCESS );
266 main( int argc, char **argv )
269 int i, c, port, cldapflg, errflg, method, id, msgtype;
270 char line[256], command1, command2, command3;
271 char passwd[64], dn[256], rdn[64], attr[64], value[256];
272 char filter[256], *host, **types;
274 char *usage = "usage: %s [-u] [-h host] [-d level] [-s dnsuffix] [-p port] [-t file] [-T file]\n";
275 int bound, all, scope, attrsonly;
277 LDAPMod **mods, **attrs;
278 struct timeval timeout;
279 char *copyfname = NULL;
286 cldapflg = errflg = 0;
288 while (( c = getopt( argc, argv, "uh:d:s:p:t:T:" )) != -1 ) {
291 #ifdef LDAP_CONNECTIONLESS
293 #else /* LDAP_CONNECTIONLESS */
294 printf( "Compile with -DLDAP_CONNECTIONLESS for UDP support\n" );
295 #endif /* LDAP_CONNECTIONLESS */
300 ldap_debug = atoi( optarg );
302 if ( ldap_debug & LDAP_DEBUG_PACKETS ) {
303 lber_debug = ldap_debug;
307 printf( "Compile with -DLDAP_DEBUG for debugging\n" );
320 port = atoi( optarg );
323 case 't': /* copy ber's to given file */
324 copyfname = strdup( optarg );
325 copyoptions = LBER_TO_FILE;
328 case 'T': /* only output ber's to given file */
329 copyfname = strdup( optarg );
330 copyoptions = (LBER_TO_FILE | LBER_TO_FILE_ONLY);
338 if ( host == NULL && optind == argc - 1 ) {
339 host = argv[ optind ];
343 if ( errflg || optind < argc - 1 ) {
344 fprintf( stderr, usage, argv[ 0 ] );
348 printf( "%sldap_open( %s, %d )\n", cldapflg ? "c" : "",
349 host == NULL ? "(null)" : host, port );
352 #ifdef LDAP_CONNECTIONLESS
353 ld = cldap_open( host, port );
354 #endif /* LDAP_CONNECTIONLESS */
356 ld = ldap_open( host, port );
360 perror( "ldap_open" );
364 if ( copyfname != NULL ) {
365 if ( (ld->ld_sb.sb_fd = open( copyfname, O_WRONLY | O_CREAT,
370 ld->ld_sb.sb_options = copyoptions;
377 (void) memset( line, '\0', sizeof(line) );
378 while ( getline( line, sizeof(line), stdin, "\ncommand? " ) != NULL ) {
383 switch ( command1 ) {
384 case 'a': /* add or abandon */
385 switch ( command2 ) {
387 getline( dn, sizeof(dn), stdin, "dn? " );
388 strcat( dn, dnsuffix );
389 if ( (attrs = get_modlist( NULL, "attr? ",
390 "value? " )) == NULL )
392 if ( (id = ldap_add( ld, dn, attrs )) == -1 )
393 ldap_perror( ld, "ldap_add" );
395 printf( "Add initiated with id %d\n",
399 case 'b': /* abandon */
400 getline( line, sizeof(line), stdin, "msgid? " );
402 if ( ldap_abandon( ld, id ) != 0 )
403 ldap_perror( ld, "ldap_abandon" );
405 printf( "Abandon successful\n" );
408 printf( "Possibilities: [ad]d, [ab]ort\n" );
412 case 'b': /* asynch bind */
414 getline( line, sizeof(line), stdin,
415 "method (0->simple, 1->krbv41, 2->krbv42)? " );
416 method = atoi( line ) | 0x80;
417 #else /* HAVE_KERBEROS */
418 method = LDAP_AUTH_SIMPLE;
419 #endif /* HAVE_KERBEROS */
420 getline( dn, sizeof(dn), stdin, "dn? " );
421 strcat( dn, dnsuffix );
423 if ( method == LDAP_AUTH_SIMPLE && dn[0] != '\0' )
424 getline( passwd, sizeof(passwd), stdin,
429 if ( ldap_bind( ld, dn, passwd, method ) == -1 ) {
430 fprintf( stderr, "ldap_bind failed\n" );
431 ldap_perror( ld, "ldap_bind" );
433 printf( "Bind initiated\n" );
438 case 'B': /* synch bind */
440 getline( line, sizeof(line), stdin,
441 "method 0->simple 1->krbv41 2->krbv42 3->krb? " );
442 method = atoi( line );
444 method = LDAP_AUTH_KRBV4;
446 method = method | 0x80;
447 #else /* HAVE_KERBEROS */
448 method = LDAP_AUTH_SIMPLE;
449 #endif /* HAVE_KERBEROS */
450 getline( dn, sizeof(dn), stdin, "dn? " );
451 strcat( dn, dnsuffix );
454 getline( passwd, sizeof(passwd), stdin,
459 if ( ldap_bind_s( ld, dn, passwd, method ) !=
461 fprintf( stderr, "ldap_bind_s failed\n" );
462 ldap_perror( ld, "ldap_bind_s" );
464 printf( "Bind successful\n" );
469 case 'c': /* compare */
470 getline( dn, sizeof(dn), stdin, "dn? " );
471 strcat( dn, dnsuffix );
472 getline( attr, sizeof(attr), stdin, "attr? " );
473 getline( value, sizeof(value), stdin, "value? " );
475 if ( (id = ldap_compare( ld, dn, attr, value )) == -1 )
476 ldap_perror( ld, "ldap_compare" );
478 printf( "Compare initiated with id %d\n", id );
481 case 'd': /* turn on debugging */
483 getline( line, sizeof(line), stdin, "debug level? " );
484 ldap_debug = atoi( line );
486 if ( ldap_debug & LDAP_DEBUG_PACKETS ) {
487 lber_debug = ldap_debug;
491 printf( "Compile with -DLDAP_DEBUG for debugging\n" );
495 case 'E': /* explode a dn */
496 getline( line, sizeof(line), stdin, "dn? " );
497 exdn = ldap_explode_dn( line, 0 );
498 for ( i = 0; exdn != NULL && exdn[i] != NULL; i++ ) {
499 printf( "\t%s\n", exdn[i] );
503 case 'g': /* set next msgid */
504 getline( line, sizeof(line), stdin, "msgid? " );
505 ld->ld_msgid = atoi( line );
508 case 'v': /* set version number */
509 getline( line, sizeof(line), stdin, "version? " );
510 ld->ld_version = atoi( line );
513 case 'm': /* modify or modifyrdn */
514 if ( strncmp( line, "modify", 4 ) == 0 ) {
515 getline( dn, sizeof(dn), stdin, "dn? " );
516 strcat( dn, dnsuffix );
517 if ( (mods = get_modlist(
518 "mod (0=>add, 1=>delete, 2=>replace -1=>done)? ",
519 "attribute type? ", "attribute value? " ))
522 if ( (id = ldap_modify( ld, dn, mods )) == -1 )
523 ldap_perror( ld, "ldap_modify" );
525 printf( "Modify initiated with id %d\n",
527 } else if ( strncmp( line, "modrdn", 4 ) == 0 ) {
528 getline( dn, sizeof(dn), stdin, "dn? " );
529 strcat( dn, dnsuffix );
530 getline( rdn, sizeof(rdn), stdin, "newrdn? " );
531 if ( (id = ldap_modrdn( ld, dn, rdn )) == -1 )
532 ldap_perror( ld, "ldap_modrdn" );
534 printf( "Modrdn initiated with id %d\n",
537 printf( "Possibilities: [modi]fy, [modr]dn\n" );
542 #ifdef LDAP_CONNECTIONLESS
545 #endif /* LDAP_CONNECTIONLESS */
553 case 'r': /* result or remove */
554 switch ( command3 ) {
555 case 's': /* result */
556 getline( line, sizeof(line), stdin,
557 "msgid (-1=>any)? " );
558 if ( line[0] == '\0' )
562 getline( line, sizeof(line), stdin,
563 "all (0=>any, 1=>all)? " );
564 if ( line[0] == '\0' )
568 if (( msgtype = ldap_result( ld, id, all,
569 &timeout, &res )) < 1 ) {
570 ldap_perror( ld, "ldap_result" );
573 printf( "\nresult: msgtype %d msgid %d\n",
574 msgtype, res->lm_msgid );
575 handle_result( ld, res );
579 case 'm': /* remove */
580 getline( dn, sizeof(dn), stdin, "dn? " );
581 strcat( dn, dnsuffix );
582 if ( (id = ldap_delete( ld, dn )) == -1 )
583 ldap_perror( ld, "ldap_delete" );
585 printf( "Remove initiated with id %d\n",
590 printf( "Possibilities: [rem]ove, [res]ult\n" );
595 case 's': /* search */
596 getline( dn, sizeof(dn), stdin, "searchbase? " );
597 strcat( dn, dnsuffix );
598 getline( line, sizeof(line), stdin,
599 "scope (0=Base, 1=One Level, 2=Subtree)? " );
600 scope = atoi( line );
601 getline( filter, sizeof(filter), stdin,
602 "search filter (e.g. sn=jones)? " );
603 types = get_list( "attrs to return? " );
604 getline( line, sizeof(line), stdin,
605 "attrsonly (0=attrs&values, 1=attrs only)? " );
606 attrsonly = atoi( line );
609 #ifdef LDAP_CONNECTIONLESS
610 getline( line, sizeof(line), stdin,
611 "Requestor DN (for logging)? " );
612 if ( cldap_search_s( ld, dn, scope, filter, types,
613 attrsonly, &res, line ) != 0 ) {
614 ldap_perror( ld, "cldap_search_s" );
616 printf( "\nresult: msgid %d\n",
618 handle_result( ld, res );
621 #endif /* LDAP_CONNECTIONLESS */
623 if (( id = ldap_search( ld, dn, scope, filter,
624 types, attrsonly )) == -1 ) {
625 ldap_perror( ld, "ldap_search" );
627 printf( "Search initiated with id %d\n", id );
633 case 't': /* set timeout value */
634 getline( line, sizeof(line), stdin, "timeout? " );
635 timeout.tv_sec = atoi( line );
638 case 'U': /* set ufn search prefix */
639 getline( line, sizeof(line), stdin, "ufn prefix? " );
640 ldap_ufn_setprefix( ld, line );
643 case 'u': /* user friendly search w/optional timeout */
644 getline( dn, sizeof(dn), stdin, "ufn? " );
645 strcat( dn, dnsuffix );
646 types = get_list( "attrs to return? " );
647 getline( line, sizeof(line), stdin,
648 "attrsonly (0=attrs&values, 1=attrs only)? " );
649 attrsonly = atoi( line );
651 if ( command2 == 't' ) {
652 id = ldap_ufn_search_c( ld, dn, types,
653 attrsonly, &res, ldap_ufn_timeout,
656 id = ldap_ufn_search_s( ld, dn, types,
660 ldap_perror( ld, "ldap_ufn_search" );
662 printf( "\nresult: err %d\n", id );
663 handle_result( ld, res );
669 case 'l': /* URL search */
670 getline( line, sizeof(line), stdin,
671 "attrsonly (0=attrs&values, 1=attrs only)? " );
672 attrsonly = atoi( line );
673 getline( line, sizeof(line), stdin, "LDAP URL? " );
674 if (( id = ldap_url_search( ld, line, attrsonly ))
676 ldap_perror( ld, "ldap_url_search" );
678 printf( "URL search initiated with id %d\n", id );
682 case 'p': /* parse LDAP URL */
683 getline( line, sizeof(line), stdin, "LDAP URL? " );
684 if (( i = ldap_url_parse( line, &ludp )) != 0 ) {
685 fprintf( stderr, "ldap_url_parse: error %d\n", i );
687 printf( "\t host: " );
688 if ( ludp->lud_host == NULL ) {
689 printf( "DEFAULT\n" );
691 printf( "<%s>\n", ludp->lud_host );
693 printf( "\t port: " );
694 if ( ludp->lud_port == 0 ) {
695 printf( "DEFAULT\n" );
697 printf( "%d\n", ludp->lud_port );
699 printf( "\t dn: <%s>\n", ludp->lud_dn );
700 printf( "\t attrs:" );
701 if ( ludp->lud_attrs == NULL ) {
704 for ( i = 0; ludp->lud_attrs[ i ] != NULL; ++i ) {
705 printf( " <%s>", ludp->lud_attrs[ i ] );
708 printf( "\n\t scope: %s\n", ludp->lud_scope == LDAP_SCOPE_ONELEVEL ?
709 "ONE" : ludp->lud_scope == LDAP_SCOPE_BASE ? "BASE" :
710 ludp->lud_scope == LDAP_SCOPE_SUBTREE ? "SUB" : "**invalid**" );
711 printf( "\tfilter: <%s>\n", ludp->lud_filter );
712 ldap_free_urldesc( ludp );
716 case 'n': /* set dn suffix, for convenience */
717 getline( line, sizeof(line), stdin, "DN suffix? " );
718 strcpy( dnsuffix, line );
721 case 'e': /* enable cache */
723 printf( NOCACHEERRMSG );
724 #else /* LDAP_NOCACHE */
725 getline( line, sizeof(line), stdin, "Cache timeout (secs)? " );
727 getline( line, sizeof(line), stdin, "Maximum memory to use (bytes)? " );
728 if ( ldap_enable_cache( ld, i, atoi( line )) == 0 ) {
729 printf( "local cache is on\n" );
731 printf( "ldap_enable_cache failed\n" );
733 #endif /* LDAP_NOCACHE */
736 case 'x': /* uncache entry */
738 printf( NOCACHEERRMSG );
739 #else /* LDAP_NOCACHE */
740 getline( line, sizeof(line), stdin, "DN? " );
741 ldap_uncache_entry( ld, line );
742 #endif /* LDAP_NOCACHE */
745 case 'X': /* uncache request */
747 printf( NOCACHEERRMSG );
748 #else /* LDAP_NOCACHE */
749 getline( line, sizeof(line), stdin, "request msgid? " );
750 ldap_uncache_request( ld, atoi( line ));
751 #endif /* LDAP_NOCACHE */
754 case 'o': /* set ldap options */
755 getline( line, sizeof(line), stdin, "alias deref (0=never, 1=searching, 2=finding, 3=always)?" );
756 ld->ld_deref = atoi( line );
757 getline( line, sizeof(line), stdin, "timelimit?" );
758 ld->ld_timelimit = atoi( line );
759 getline( line, sizeof(line), stdin, "sizelimit?" );
760 ld->ld_sizelimit = atoi( line );
762 LDAP_BOOL_ZERO(&ld->ld_options);
764 #ifdef STR_TRANSLATION
765 getline( line, sizeof(line), stdin,
766 "Automatic translation of T.61 strings (0=no, 1=yes)?" );
767 if ( atoi( line ) == 0 ) {
768 ld->ld_lberoptions &= ~LBER_TRANSLATE_STRINGS;
770 ld->ld_lberoptions |= LBER_TRANSLATE_STRINGS;
771 #ifdef LDAP_CHARSET_8859
772 getline( line, sizeof(line), stdin,
773 "Translate to/from ISO-8859 (0=no, 1=yes?" );
774 if ( atoi( line ) != 0 ) {
775 ldap_set_string_translators( ld,
779 #endif /* LDAP_CHARSET_8859 */
781 #endif /* STR_TRANSLATION */
783 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
784 getline( line, sizeof(line), stdin,
785 "Use DN & DNS to determine where to send requests (0=no, 1=yes)?" );
786 if ( atoi( line ) != 0 ) {
787 LDAP_BOOL_SET(&ld->ld_options, LDAP_BOOL_DNS);
789 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
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 );
803 case 'O': /* set cache options */
805 printf( NOCACHEERRMSG );
806 #else /* LDAP_NOCACHE */
807 getline( line, sizeof(line), stdin, "cache errors (0=smart, 1=never, 2=always)?" );
808 switch( atoi( line )) {
810 ldap_set_cache_options( ld, 0 );
813 ldap_set_cache_options( ld,
814 LDAP_CACHE_OPT_CACHENOERRS );
817 ldap_set_cache_options( ld,
818 LDAP_CACHE_OPT_CACHEALLERRS );
821 printf( "not a valid cache option\n" );
823 #endif /* LDAP_NOCACHE */
827 printf( "Commands: [ad]d [ab]andon [b]ind\n" );
828 printf( " [B]ind async [c]ompare [l]URL search\n" );
829 printf( " [modi]fy [modr]dn [rem]ove\n" );
830 printf( " [res]ult [s]earch [q]uit/unbind\n\n" );
831 printf( " [u]fn search [ut]fn search with timeout\n" );
832 printf( " [d]ebug [e]nable cache set ms[g]id\n" );
833 printf( " d[n]suffix [t]imeout [v]ersion\n" );
834 printf( " [U]fn prefix [x]uncache entry [X]uncache request\n" );
835 printf( " [?]help [o]ptions [O]cache options\n" );
836 printf( " [E]xplode dn [p]arse LDAP URL\n" );
840 printf( "Invalid command. Type ? for help.\n" );
844 (void) memset( line, '\0', sizeof(line) );
851 handle_result( LDAP *ld, LDAPMessage *lm )
853 switch ( lm->lm_msgtype ) {
854 case LDAP_RES_COMPARE:
855 printf( "Compare result\n" );
856 print_ldap_result( ld, lm, "compare" );
859 case LDAP_RES_SEARCH_RESULT:
860 printf( "Search result\n" );
861 print_ldap_result( ld, lm, "search" );
864 case LDAP_RES_SEARCH_ENTRY:
865 printf( "Search entry\n" );
866 print_search_entry( ld, lm );
870 printf( "Add result\n" );
871 print_ldap_result( ld, lm, "add" );
874 case LDAP_RES_DELETE:
875 printf( "Delete result\n" );
876 print_ldap_result( ld, lm, "delete" );
879 case LDAP_RES_MODRDN:
880 printf( "ModRDN result\n" );
881 print_ldap_result( ld, lm, "modrdn" );
885 printf( "Bind result\n" );
886 print_ldap_result( ld, lm, "bind" );
890 printf( "Unknown result type 0x%x\n", lm->lm_msgtype );
891 print_ldap_result( ld, lm, "unknown" );
896 print_ldap_result( LDAP *ld, LDAPMessage *lm, char *s )
898 ldap_result2error( ld, lm, 1 );
899 ldap_perror( ld, s );
901 if ( ld->ld_error != NULL && *ld->ld_error != '\0' )
902 fprintf( stderr, "Additional info: %s\n", ld->ld_error );
903 if ( LDAP_NAME_ERROR( ld->ld_errno ) && ld->ld_matched != NULL )
904 fprintf( stderr, "Matched DN: %s\n", ld->ld_matched );
909 print_search_entry( LDAP *ld, LDAPMessage *res )
913 for ( e = ldap_first_entry( ld, res ); e != NULLMSG;
914 e = ldap_next_entry( ld, e ) )
916 BerElement *ber = NULL;
919 if ( e->lm_msgtype == LDAP_RES_SEARCH_RESULT )
922 dn = ldap_get_dn( ld, e );
923 printf( "\tDN: %s\n", dn );
925 ufn = ldap_dn2ufn( dn );
926 printf( "\tUFN: %s\n", ufn );
931 for ( a = ldap_first_attribute( ld, e, &ber ); a != NULL;
932 a = ldap_next_attribute( ld, e, ber ) )
934 struct berval **vals;
936 printf( "\t\tATTR: %s\n", a );
937 if ( (vals = ldap_get_values_len( ld, e, a ))
939 printf( "\t\t\t(no values)\n" );
942 for ( i = 0; vals[i] != NULL; i++ ) {
946 for ( j = 0; (unsigned long) j < vals[i]->bv_len; j++ )
947 if ( !isascii( vals[i]->bv_val[j] ) ) {
953 printf( "\t\t\tlength (%ld) (not ascii)\n", vals[i]->bv_len );
954 #ifdef BPRINT_NONASCII
955 lber_bprint( vals[i]->bv_val,
957 #endif /* BPRINT_NONASCII */
960 printf( "\t\t\tlength (%ld) %s\n",
961 vals[i]->bv_len, vals[i]->bv_val );
963 ber_bvecfree( vals );
972 if ( res->lm_msgtype == LDAP_RES_SEARCH_RESULT
973 || res->lm_chain != NULLMSG )
974 print_ldap_result( ld, res, "search" );