10 #include <ac/unistd.h>
14 #ifdef HAVE_SYS_FILE_H
23 /* including the "internal" defs is legit and nec. since this test routine has
24 * a-priori knowledge of libldap internal workings.
25 * hodges@stanford.edu 5-Feb-96
31 static char *getline LDAP_P(( char *line, int len, FILE *fp, char *prompt ));
33 static char **get_list LDAP_P(( char *prompt ));
34 static int file_read LDAP_P(( char *path, struct berval *bv ));
35 static LDAPMod **get_modlist LDAP_P(( char *prompt1, char *prompt2, char *prompt3 ));
36 static void handle_result LDAP_P(( LDAP *ld, LDAPMessage *lm ));
37 static void print_ldap_result LDAP_P(( LDAP *ld, LDAPMessage *lm, char *s ));
38 static void print_search_entry LDAP_P(( LDAP *ld, LDAPMessage *res ));
39 static void free_list LDAP_P(( char **list ));
41 #define NOCACHEERRMSG "don't compile with -DLDAP_NOCACHE if you desire local caching"
43 static char *dnsuffix;
47 getline( char *line, int len, FILE *fp, char *prompt )
51 if ( fgets( line, len, fp ) == NULL )
54 line[ strlen( line ) - 1 ] = '\0';
61 get_list( char *prompt )
70 getline( buf, sizeof(buf), stdin, prompt );
75 if ( result == (char **) 0 )
76 result = (char **) malloc( sizeof(char *) );
78 result = (char **) realloc( result,
79 sizeof(char *) * (num + 1) );
81 result[num++] = (char *) ldap_strdup( buf );
83 if ( result == (char **) 0 )
85 result = (char **) realloc( result, sizeof(char *) * (num + 1) );
93 free_list( char **list )
98 for ( i = 0; list[ i ] != NULL; ++i ) {
101 free( (char *)list );
107 file_read( char *path, struct berval *bv )
113 if (( fp = fopen( path, "r" )) == NULL ) {
118 if ( fseek( fp, 0L, SEEK_END ) != 0 ) {
124 bv->bv_len = ftell( fp );
126 if (( bv->bv_val = (char *)malloc( bv->bv_len )) == NULL ) {
132 if ( fseek( fp, 0L, SEEK_SET ) != 0 ) {
138 rlen = fread( bv->bv_val, 1, bv->bv_len, fp );
142 if ( (unsigned long) rlen != bv->bv_len ) {
148 return( bv->bv_len );
153 get_modlist( char *prompt1, char *prompt2, char *prompt3 )
155 static char buf[256];
159 struct berval **bvals;
165 getline( buf, sizeof(buf), stdin, prompt1 );
166 tmp.mod_op = atoi( buf );
168 if ( tmp.mod_op == -1 || buf[0] == '\0' )
172 getline( buf, sizeof(buf), stdin, prompt2 );
173 if ( buf[0] == '\0' )
175 tmp.mod_type = ldap_strdup( buf );
177 tmp.mod_values = get_list( prompt3 );
179 if ( tmp.mod_values != NULL ) {
182 for ( i = 0; tmp.mod_values[i] != NULL; ++i )
184 bvals = (struct berval **)calloc( i + 1,
185 sizeof( struct berval *));
186 for ( i = 0; tmp.mod_values[i] != NULL; ++i ) {
187 bvals[i] = (struct berval *)malloc(
188 sizeof( struct berval ));
189 if ( strncmp( tmp.mod_values[i], "{FILE}",
191 if ( file_read( tmp.mod_values[i] + 6,
196 bvals[i]->bv_val = tmp.mod_values[i];
198 strlen( tmp.mod_values[i] );
201 tmp.mod_bvalues = bvals;
202 tmp.mod_op |= LDAP_MOD_BVALUES;
205 if ( result == NULL )
206 result = (LDAPMod **) malloc( sizeof(LDAPMod *) );
208 result = (LDAPMod **) realloc( result,
209 sizeof(LDAPMod *) * (num + 1) );
211 result[num] = (LDAPMod *) malloc( sizeof(LDAPMod) );
212 *(result[num]) = tmp; /* struct copy */
215 if ( result == NULL )
217 result = (LDAPMod **) realloc( result, sizeof(LDAPMod *) * (num + 1) );
224 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
226 bind_prompt( LDAP *ld, char **dnp, char **passwdp, int *authmethodp,
229 static char dn[256], passwd[256];
233 getline( dn, sizeof(dn), stdin,
234 "re-bind method (0->simple, 1->krbv41, 2->krbv42, 3->krbv41&2)? " );
235 if (( *authmethodp = atoi( dn )) == 3 ) {
236 *authmethodp = LDAP_AUTH_KRBV4;
238 *authmethodp |= 0x80;
240 #else /* HAVE_KERBEROS */
241 *authmethodp = LDAP_AUTH_SIMPLE;
242 #endif /* HAVE_KERBEROS */
244 getline( dn, sizeof(dn), stdin, "re-bind dn? " );
245 strcat( dn, dnsuffix );
248 if ( *authmethodp == LDAP_AUTH_SIMPLE && dn[0] != '\0' ) {
249 getline( passwd, sizeof(passwd), stdin,
250 "re-bind password? " );
257 return( LDAP_SUCCESS );
259 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
263 main( int argc, char **argv )
266 int i, c, port, cldapflg, errflg, method, id, msgtype;
267 char line[256], command1, command2, command3;
268 char passwd[64], dn[256], rdn[64], attr[64], value[256];
269 char filter[256], *host, **types;
271 char *usage = "usage: %s [-u] [-h host] [-d level] [-s dnsuffix] [-p port] [-t file] [-T file]\n";
272 int bound, all, scope, attrsonly;
274 LDAPMod **mods, **attrs;
275 struct timeval timeout;
276 char *copyfname = NULL;
283 cldapflg = errflg = 0;
285 while (( c = getopt( argc, argv, "uh:d:s:p:t:T:" )) != -1 ) {
288 #ifdef LDAP_CONNECTIONLESS
290 #else /* LDAP_CONNECTIONLESS */
291 printf( "Compile with -DLDAP_CONNECTIONLESS for UDP support\n" );
292 #endif /* LDAP_CONNECTIONLESS */
297 ldap_debug = atoi( optarg );
298 if ( ldap_debug & LDAP_DEBUG_PACKETS ) {
299 lber_debug = ldap_debug;
302 printf( "Compile with -DLDAP_DEBUG for debugging\n" );
315 port = atoi( optarg );
318 case 't': /* copy ber's to given file */
319 copyfname = ldap_strdup( optarg );
320 copyoptions = LBER_TO_FILE;
323 case 'T': /* only output ber's to given file */
324 copyfname = ldap_strdup( optarg );
325 copyoptions = (LBER_TO_FILE | LBER_TO_FILE_ONLY);
333 if ( host == NULL && optind == argc - 1 ) {
334 host = argv[ optind ];
338 if ( errflg || optind < argc - 1 ) {
339 fprintf( stderr, usage, argv[ 0 ] );
343 printf( "%sldap_open( %s, %d )\n", cldapflg ? "c" : "",
344 host == NULL ? "(null)" : host, port );
347 #ifdef LDAP_CONNECTIONLESS
348 ld = cldap_open( host, port );
349 #endif /* LDAP_CONNECTIONLESS */
351 ld = ldap_open( host, port );
355 perror( "ldap_open" );
359 if ( copyfname != NULL ) {
360 if ( (ld->ld_sb.sb_fd = open( copyfname, O_WRONLY | O_CREAT,
365 ld->ld_sb.sb_options = copyoptions;
372 (void) memset( line, '\0', sizeof(line) );
373 while ( getline( line, sizeof(line), stdin, "\ncommand? " ) != NULL ) {
378 switch ( command1 ) {
379 case 'a': /* add or abandon */
380 switch ( command2 ) {
382 getline( dn, sizeof(dn), stdin, "dn? " );
383 strcat( dn, dnsuffix );
384 if ( (attrs = get_modlist( NULL, "attr? ",
385 "value? " )) == NULL )
387 if ( (id = ldap_add( ld, dn, attrs )) == -1 )
388 ldap_perror( ld, "ldap_add" );
390 printf( "Add initiated with id %d\n",
394 case 'b': /* abandon */
395 getline( line, sizeof(line), stdin, "msgid? " );
397 if ( ldap_abandon( ld, id ) != 0 )
398 ldap_perror( ld, "ldap_abandon" );
400 printf( "Abandon successful\n" );
403 printf( "Possibilities: [ad]d, [ab]ort\n" );
407 case 'b': /* asynch bind */
409 getline( line, sizeof(line), stdin,
410 "method (0->simple, 1->krbv41, 2->krbv42)? " );
411 method = atoi( line ) | 0x80;
412 #else /* HAVE_KERBEROS */
413 method = LDAP_AUTH_SIMPLE;
414 #endif /* HAVE_KERBEROS */
415 getline( dn, sizeof(dn), stdin, "dn? " );
416 strcat( dn, dnsuffix );
418 if ( method == LDAP_AUTH_SIMPLE && dn[0] != '\0' )
419 getline( passwd, sizeof(passwd), stdin,
424 if ( ldap_bind( ld, dn, passwd, method ) == -1 ) {
425 fprintf( stderr, "ldap_bind failed\n" );
426 ldap_perror( ld, "ldap_bind" );
428 printf( "Bind initiated\n" );
433 case 'B': /* synch bind */
435 getline( line, sizeof(line), stdin,
436 "method 0->simple 1->krbv41 2->krbv42 3->krb? " );
437 method = atoi( line );
439 method = LDAP_AUTH_KRBV4;
441 method = method | 0x80;
442 #else /* HAVE_KERBEROS */
443 method = LDAP_AUTH_SIMPLE;
444 #endif /* HAVE_KERBEROS */
445 getline( dn, sizeof(dn), stdin, "dn? " );
446 strcat( dn, dnsuffix );
449 getline( passwd, sizeof(passwd), stdin,
454 if ( ldap_bind_s( ld, dn, passwd, method ) !=
456 fprintf( stderr, "ldap_bind_s failed\n" );
457 ldap_perror( ld, "ldap_bind_s" );
459 printf( "Bind successful\n" );
464 case 'c': /* compare */
465 getline( dn, sizeof(dn), stdin, "dn? " );
466 strcat( dn, dnsuffix );
467 getline( attr, sizeof(attr), stdin, "attr? " );
468 getline( value, sizeof(value), stdin, "value? " );
470 if ( (id = ldap_compare( ld, dn, attr, value )) == -1 )
471 ldap_perror( ld, "ldap_compare" );
473 printf( "Compare initiated with id %d\n", id );
476 case 'd': /* turn on debugging */
478 getline( line, sizeof(line), stdin, "debug level? " );
479 ldap_debug = atoi( line );
480 if ( ldap_debug & LDAP_DEBUG_PACKETS ) {
481 lber_debug = ldap_debug;
484 printf( "Compile with -DLDAP_DEBUG for debugging\n" );
488 case 'E': /* explode a dn */
489 getline( line, sizeof(line), stdin, "dn? " );
490 exdn = ldap_explode_dn( line, 0 );
491 for ( i = 0; exdn != NULL && exdn[i] != NULL; i++ ) {
492 printf( "\t%s\n", exdn[i] );
496 case 'g': /* set next msgid */
497 getline( line, sizeof(line), stdin, "msgid? " );
498 ld->ld_msgid = atoi( line );
501 case 'v': /* set version number */
502 getline( line, sizeof(line), stdin, "version? " );
503 ld->ld_version = atoi( line );
506 case 'm': /* modify or modifyrdn */
507 if ( strncmp( line, "modify", 4 ) == 0 ) {
508 getline( dn, sizeof(dn), stdin, "dn? " );
509 strcat( dn, dnsuffix );
510 if ( (mods = get_modlist(
511 "mod (0=>add, 1=>delete, 2=>replace -1=>done)? ",
512 "attribute type? ", "attribute value? " ))
515 if ( (id = ldap_modify( ld, dn, mods )) == -1 )
516 ldap_perror( ld, "ldap_modify" );
518 printf( "Modify initiated with id %d\n",
520 } else if ( strncmp( line, "modrdn", 4 ) == 0 ) {
521 getline( dn, sizeof(dn), stdin, "dn? " );
522 strcat( dn, dnsuffix );
523 getline( rdn, sizeof(rdn), stdin, "newrdn? " );
524 if ( (id = ldap_modrdn( ld, dn, rdn )) == -1 )
525 ldap_perror( ld, "ldap_modrdn" );
527 printf( "Modrdn initiated with id %d\n",
530 printf( "Possibilities: [modi]fy, [modr]dn\n" );
535 #ifdef LDAP_CONNECTIONLESS
538 #endif /* LDAP_CONNECTIONLESS */
539 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
541 #else /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
542 if ( !cldapflg && bound )
543 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
548 case 'r': /* result or remove */
549 switch ( command3 ) {
550 case 's': /* result */
551 getline( line, sizeof(line), stdin,
552 "msgid (-1=>any)? " );
553 if ( line[0] == '\0' )
557 getline( line, sizeof(line), stdin,
558 "all (0=>any, 1=>all)? " );
559 if ( line[0] == '\0' )
563 if (( msgtype = ldap_result( ld, id, all,
564 &timeout, &res )) < 1 ) {
565 ldap_perror( ld, "ldap_result" );
568 printf( "\nresult: msgtype %d msgid %d\n",
569 msgtype, res->lm_msgid );
570 handle_result( ld, res );
574 case 'm': /* remove */
575 getline( dn, sizeof(dn), stdin, "dn? " );
576 strcat( dn, dnsuffix );
577 if ( (id = ldap_delete( ld, dn )) == -1 )
578 ldap_perror( ld, "ldap_delete" );
580 printf( "Remove initiated with id %d\n",
585 printf( "Possibilities: [rem]ove, [res]ult\n" );
590 case 's': /* search */
591 getline( dn, sizeof(dn), stdin, "searchbase? " );
592 strcat( dn, dnsuffix );
593 getline( line, sizeof(line), stdin,
594 "scope (0=Base, 1=One Level, 2=Subtree)? " );
595 scope = atoi( line );
596 getline( filter, sizeof(filter), stdin,
597 "search filter (e.g. sn=jones)? " );
598 types = get_list( "attrs to return? " );
599 getline( line, sizeof(line), stdin,
600 "attrsonly (0=attrs&values, 1=attrs only)? " );
601 attrsonly = atoi( line );
604 #ifdef LDAP_CONNECTIONLESS
605 getline( line, sizeof(line), stdin,
606 "Requestor DN (for logging)? " );
607 if ( cldap_search_s( ld, dn, scope, filter, types,
608 attrsonly, &res, line ) != 0 ) {
609 ldap_perror( ld, "cldap_search_s" );
611 printf( "\nresult: msgid %d\n",
613 handle_result( ld, res );
616 #endif /* LDAP_CONNECTIONLESS */
618 if (( id = ldap_search( ld, dn, scope, filter,
619 types, attrsonly )) == -1 ) {
620 ldap_perror( ld, "ldap_search" );
622 printf( "Search initiated with id %d\n", id );
628 case 't': /* set timeout value */
629 getline( line, sizeof(line), stdin, "timeout? " );
630 timeout.tv_sec = atoi( line );
633 case 'U': /* set ufn search prefix */
634 getline( line, sizeof(line), stdin, "ufn prefix? " );
635 ldap_ufn_setprefix( ld, line );
638 case 'u': /* user friendly search w/optional timeout */
639 getline( dn, sizeof(dn), stdin, "ufn? " );
640 strcat( dn, dnsuffix );
641 types = get_list( "attrs to return? " );
642 getline( line, sizeof(line), stdin,
643 "attrsonly (0=attrs&values, 1=attrs only)? " );
644 attrsonly = atoi( line );
646 if ( command2 == 't' ) {
647 id = ldap_ufn_search_c( ld, dn, types,
648 attrsonly, &res, ldap_ufn_timeout,
651 id = ldap_ufn_search_s( ld, dn, types,
655 ldap_perror( ld, "ldap_ufn_search" );
657 printf( "\nresult: err %d\n", id );
658 handle_result( ld, res );
664 case 'l': /* URL search */
665 getline( line, sizeof(line), stdin,
666 "attrsonly (0=attrs&values, 1=attrs only)? " );
667 attrsonly = atoi( line );
668 getline( line, sizeof(line), stdin, "LDAP URL? " );
669 if (( id = ldap_url_search( ld, line, attrsonly ))
671 ldap_perror( ld, "ldap_url_search" );
673 printf( "URL search initiated with id %d\n", id );
677 case 'p': /* parse LDAP URL */
678 getline( line, sizeof(line), stdin, "LDAP URL? " );
679 if (( i = ldap_url_parse( line, &ludp )) != 0 ) {
680 fprintf( stderr, "ldap_url_parse: error %d\n", i );
682 printf( "\t host: " );
683 if ( ludp->lud_host == NULL ) {
684 printf( "DEFAULT\n" );
686 printf( "<%s>\n", ludp->lud_host );
688 printf( "\t port: " );
689 if ( ludp->lud_port == 0 ) {
690 printf( "DEFAULT\n" );
692 printf( "%d\n", ludp->lud_port );
694 printf( "\t dn: <%s>\n", ludp->lud_dn );
695 printf( "\t attrs:" );
696 if ( ludp->lud_attrs == NULL ) {
699 for ( i = 0; ludp->lud_attrs[ i ] != NULL; ++i ) {
700 printf( " <%s>", ludp->lud_attrs[ i ] );
703 printf( "\n\t scope: %s\n", ludp->lud_scope == LDAP_SCOPE_ONELEVEL ?
704 "ONE" : ludp->lud_scope == LDAP_SCOPE_BASE ? "BASE" :
705 ludp->lud_scope == LDAP_SCOPE_SUBTREE ? "SUB" : "**invalid**" );
706 printf( "\tfilter: <%s>\n", ludp->lud_filter );
707 ldap_free_urldesc( ludp );
711 case 'n': /* set dn suffix, for convenience */
712 getline( line, sizeof(line), stdin, "DN suffix? " );
713 strcpy( dnsuffix, line );
716 case 'e': /* enable cache */
718 printf( NOCACHEERRMSG );
719 #else /* LDAP_NOCACHE */
720 getline( line, sizeof(line), stdin, "Cache timeout (secs)? " );
722 getline( line, sizeof(line), stdin, "Maximum memory to use (bytes)? " );
723 if ( ldap_enable_cache( ld, i, atoi( line )) == 0 ) {
724 printf( "local cache is on\n" );
726 printf( "ldap_enable_cache failed\n" );
728 #endif /* LDAP_NOCACHE */
731 case 'x': /* uncache entry */
733 printf( NOCACHEERRMSG );
734 #else /* LDAP_NOCACHE */
735 getline( line, sizeof(line), stdin, "DN? " );
736 ldap_uncache_entry( ld, line );
737 #endif /* LDAP_NOCACHE */
740 case 'X': /* uncache request */
742 printf( NOCACHEERRMSG );
743 #else /* LDAP_NOCACHE */
744 getline( line, sizeof(line), stdin, "request msgid? " );
745 ldap_uncache_request( ld, atoi( line ));
746 #endif /* LDAP_NOCACHE */
749 case 'o': /* set ldap options */
750 getline( line, sizeof(line), stdin, "alias deref (0=never, 1=searching, 2=finding, 3=always)?" );
751 ld->ld_deref = atoi( line );
752 getline( line, sizeof(line), stdin, "timelimit?" );
753 ld->ld_timelimit = atoi( line );
754 getline( line, sizeof(line), stdin, "sizelimit?" );
755 ld->ld_sizelimit = atoi( line );
757 LDAP_BOOL_ZERO(&ld->ld_options);
759 #ifdef STR_TRANSLATION
760 getline( line, sizeof(line), stdin,
761 "Automatic translation of T.61 strings (0=no, 1=yes)?" );
762 if ( atoi( line ) == 0 ) {
763 ld->ld_lberoptions &= ~LBER_TRANSLATE_STRINGS;
765 ld->ld_lberoptions |= LBER_TRANSLATE_STRINGS;
766 #ifdef LDAP_CHARSET_8859
767 getline( line, sizeof(line), stdin,
768 "Translate to/from ISO-8859 (0=no, 1=yes?" );
769 if ( atoi( line ) != 0 ) {
770 ldap_set_string_translators( ld,
774 #endif /* LDAP_CHARSET_8859 */
776 #endif /* STR_TRANSLATION */
778 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
779 getline( line, sizeof(line), stdin,
780 "Use DN & DNS to determine where to send requests (0=no, 1=yes)?" );
781 if ( atoi( line ) != 0 ) {
782 LDAP_BOOL_SET(&ld->ld_options, LDAP_BOOL_DNS);
784 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
786 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
787 getline( line, sizeof(line), stdin,
788 "Recognize and chase referrals (0=no, 1=yes)?" );
789 if ( atoi( line ) != 0 ) {
790 LDAP_BOOL_SET(&ld->ld_options, LDAP_BOOL_REFERRALS);
791 getline( line, sizeof(line), stdin,
792 "Prompt for bind credentials when chasing referrals (0=no, 1=yes)?" );
793 if ( atoi( line ) != 0 ) {
794 ldap_set_rebind_proc( ld, bind_prompt );
797 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
800 case 'O': /* set cache options */
802 printf( NOCACHEERRMSG );
803 #else /* LDAP_NOCACHE */
804 getline( line, sizeof(line), stdin, "cache errors (0=smart, 1=never, 2=always)?" );
805 switch( atoi( line )) {
807 ldap_set_cache_options( ld, 0 );
810 ldap_set_cache_options( ld,
811 LDAP_CACHE_OPT_CACHENOERRS );
814 ldap_set_cache_options( ld,
815 LDAP_CACHE_OPT_CACHEALLERRS );
818 printf( "not a valid cache option\n" );
820 #endif /* LDAP_NOCACHE */
824 printf( "Commands: [ad]d [ab]andon [b]ind\n" );
825 printf( " [B]ind async [c]ompare [l]URL search\n" );
826 printf( " [modi]fy [modr]dn [rem]ove\n" );
827 printf( " [res]ult [s]earch [q]uit/unbind\n\n" );
828 printf( " [u]fn search [ut]fn search with timeout\n" );
829 printf( " [d]ebug [e]nable cache set ms[g]id\n" );
830 printf( " d[n]suffix [t]imeout [v]ersion\n" );
831 printf( " [U]fn prefix [x]uncache entry [X]uncache request\n" );
832 printf( " [?]help [o]ptions [O]cache options\n" );
833 printf( " [E]xplode dn [p]arse LDAP URL\n" );
837 printf( "Invalid command. Type ? for help.\n" );
841 (void) memset( line, '\0', sizeof(line) );
848 handle_result( LDAP *ld, LDAPMessage *lm )
850 switch ( lm->lm_msgtype ) {
851 case LDAP_RES_COMPARE:
852 printf( "Compare result\n" );
853 print_ldap_result( ld, lm, "compare" );
856 case LDAP_RES_SEARCH_RESULT:
857 printf( "Search result\n" );
858 print_ldap_result( ld, lm, "search" );
861 case LDAP_RES_SEARCH_ENTRY:
862 printf( "Search entry\n" );
863 print_search_entry( ld, lm );
867 printf( "Add result\n" );
868 print_ldap_result( ld, lm, "add" );
871 case LDAP_RES_DELETE:
872 printf( "Delete result\n" );
873 print_ldap_result( ld, lm, "delete" );
876 case LDAP_RES_MODRDN:
877 printf( "ModRDN result\n" );
878 print_ldap_result( ld, lm, "modrdn" );
882 printf( "Bind result\n" );
883 print_ldap_result( ld, lm, "bind" );
887 printf( "Unknown result type 0x%x\n", lm->lm_msgtype );
888 print_ldap_result( ld, lm, "unknown" );
893 print_ldap_result( LDAP *ld, LDAPMessage *lm, char *s )
895 ldap_result2error( ld, lm, 1 );
896 ldap_perror( ld, s );
898 if ( ld->ld_error != NULL && *ld->ld_error != '\0' )
899 fprintf( stderr, "Additional info: %s\n", ld->ld_error );
900 if ( NAME_ERROR( ld->ld_errno ) && ld->ld_matched != NULL )
901 fprintf( stderr, "Matched DN: %s\n", ld->ld_matched );
906 print_search_entry( LDAP *ld, LDAPMessage *res )
910 struct berval **vals;
914 for ( e = ldap_first_entry( ld, res ); e != NULLMSG;
915 e = ldap_next_entry( ld, e ) ) {
916 if ( e->lm_msgtype == LDAP_RES_SEARCH_RESULT )
919 dn = ldap_get_dn( ld, e );
920 printf( "\tDN: %s\n", dn );
922 ufn = ldap_dn2ufn( dn );
923 printf( "\tUFN: %s\n", ufn );
928 for ( a = ldap_first_attribute( ld, e, &ber ); a != NULL;
929 a = ldap_next_attribute( ld, e, ber ) ) {
930 printf( "\t\tATTR: %s\n", a );
931 if ( (vals = ldap_get_values_len( ld, e, a ))
933 printf( "\t\t\t(no values)\n" );
935 for ( i = 0; vals[i] != NULL; i++ ) {
939 for ( j = 0; (unsigned long) j < vals[i]->bv_len; j++ )
940 if ( !isascii( vals[i]->bv_val[j] ) ) {
946 printf( "\t\t\tlength (%ld) (not ascii)\n", vals[i]->bv_len );
947 #ifdef BPRINT_NONASCII
948 lber_bprint( vals[i]->bv_val,
950 #endif /* BPRINT_NONASCII */
953 printf( "\t\t\tlength (%ld) %s\n",
954 vals[i]->bv_len, vals[i]->bv_val );
956 ber_bvecfree( vals );
961 if ( res->lm_msgtype == LDAP_RES_SEARCH_RESULT
962 || res->lm_chain != NULLMSG )
963 print_ldap_result( ld, res, "search" );