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) );
229 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
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 );
264 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
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 lber_debug = 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 ] );
350 printf( "%sldap_open( %s, %d )\n", cldapflg ? "c" : "",
351 host == NULL ? "(null)" : host, port );
354 #ifdef LDAP_CONNECTIONLESS
355 ld = cldap_open( host, port );
356 #endif /* LDAP_CONNECTIONLESS */
358 ld = ldap_open( host, port );
362 perror( "ldap_open" );
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 lber_debug = 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 */
548 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
550 #else /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
551 if ( !cldapflg && bound )
552 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
557 case 'r': /* result or remove */
558 switch ( command3 ) {
559 case 's': /* result */
560 getline( line, sizeof(line), stdin,
561 "msgid (-1=>any)? " );
562 if ( line[0] == '\0' )
566 getline( line, sizeof(line), stdin,
567 "all (0=>any, 1=>all)? " );
568 if ( line[0] == '\0' )
572 if (( msgtype = ldap_result( ld, id, all,
573 &timeout, &res )) < 1 ) {
574 ldap_perror( ld, "ldap_result" );
577 printf( "\nresult: msgtype %d msgid %d\n",
578 msgtype, res->lm_msgid );
579 handle_result( ld, res );
583 case 'm': /* remove */
584 getline( dn, sizeof(dn), stdin, "dn? " );
585 strcat( dn, dnsuffix );
586 if ( (id = ldap_delete( ld, dn )) == -1 )
587 ldap_perror( ld, "ldap_delete" );
589 printf( "Remove initiated with id %d\n",
594 printf( "Possibilities: [rem]ove, [res]ult\n" );
599 case 's': /* search */
600 getline( dn, sizeof(dn), stdin, "searchbase? " );
601 strcat( dn, dnsuffix );
602 getline( line, sizeof(line), stdin,
603 "scope (0=Base, 1=One Level, 2=Subtree)? " );
604 scope = atoi( line );
605 getline( filter, sizeof(filter), stdin,
606 "search filter (e.g. sn=jones)? " );
607 types = get_list( "attrs to return? " );
608 getline( line, sizeof(line), stdin,
609 "attrsonly (0=attrs&values, 1=attrs only)? " );
610 attrsonly = atoi( line );
613 #ifdef LDAP_CONNECTIONLESS
614 getline( line, sizeof(line), stdin,
615 "Requestor DN (for logging)? " );
616 if ( cldap_search_s( ld, dn, scope, filter, types,
617 attrsonly, &res, line ) != 0 ) {
618 ldap_perror( ld, "cldap_search_s" );
620 printf( "\nresult: msgid %d\n",
622 handle_result( ld, res );
625 #endif /* LDAP_CONNECTIONLESS */
627 if (( id = ldap_search( ld, dn, scope, filter,
628 types, attrsonly )) == -1 ) {
629 ldap_perror( ld, "ldap_search" );
631 printf( "Search initiated with id %d\n", id );
637 case 't': /* set timeout value */
638 getline( line, sizeof(line), stdin, "timeout? " );
639 timeout.tv_sec = atoi( line );
642 case 'U': /* set ufn search prefix */
643 getline( line, sizeof(line), stdin, "ufn prefix? " );
644 ldap_ufn_setprefix( ld, line );
647 case 'u': /* user friendly search w/optional timeout */
648 getline( dn, sizeof(dn), stdin, "ufn? " );
649 strcat( dn, dnsuffix );
650 types = get_list( "attrs to return? " );
651 getline( line, sizeof(line), stdin,
652 "attrsonly (0=attrs&values, 1=attrs only)? " );
653 attrsonly = atoi( line );
655 if ( command2 == 't' ) {
656 id = ldap_ufn_search_c( ld, dn, types,
657 attrsonly, &res, ldap_ufn_timeout,
660 id = ldap_ufn_search_s( ld, dn, types,
664 ldap_perror( ld, "ldap_ufn_search" );
666 printf( "\nresult: err %d\n", id );
667 handle_result( ld, res );
673 case 'l': /* URL search */
674 getline( line, sizeof(line), stdin,
675 "attrsonly (0=attrs&values, 1=attrs only)? " );
676 attrsonly = atoi( line );
677 getline( line, sizeof(line), stdin, "LDAP URL? " );
678 if (( id = ldap_url_search( ld, line, attrsonly ))
680 ldap_perror( ld, "ldap_url_search" );
682 printf( "URL search initiated with id %d\n", id );
686 case 'p': /* parse LDAP URL */
687 getline( line, sizeof(line), stdin, "LDAP URL? " );
688 if (( i = ldap_url_parse( line, &ludp )) != 0 ) {
689 fprintf( stderr, "ldap_url_parse: error %d\n", i );
691 printf( "\t host: " );
692 if ( ludp->lud_host == NULL ) {
693 printf( "DEFAULT\n" );
695 printf( "<%s>\n", ludp->lud_host );
697 printf( "\t port: " );
698 if ( ludp->lud_port == 0 ) {
699 printf( "DEFAULT\n" );
701 printf( "%d\n", ludp->lud_port );
703 printf( "\t dn: <%s>\n", ludp->lud_dn );
704 printf( "\t attrs:" );
705 if ( ludp->lud_attrs == NULL ) {
708 for ( i = 0; ludp->lud_attrs[ i ] != NULL; ++i ) {
709 printf( " <%s>", ludp->lud_attrs[ i ] );
712 printf( "\n\t scope: %s\n", ludp->lud_scope == LDAP_SCOPE_ONELEVEL ?
713 "ONE" : ludp->lud_scope == LDAP_SCOPE_BASE ? "BASE" :
714 ludp->lud_scope == LDAP_SCOPE_SUBTREE ? "SUB" : "**invalid**" );
715 printf( "\tfilter: <%s>\n", ludp->lud_filter );
716 ldap_free_urldesc( ludp );
720 case 'n': /* set dn suffix, for convenience */
721 getline( line, sizeof(line), stdin, "DN suffix? " );
722 strcpy( dnsuffix, line );
725 case 'e': /* enable cache */
727 printf( NOCACHEERRMSG );
728 #else /* LDAP_NOCACHE */
729 getline( line, sizeof(line), stdin, "Cache timeout (secs)? " );
731 getline( line, sizeof(line), stdin, "Maximum memory to use (bytes)? " );
732 if ( ldap_enable_cache( ld, i, atoi( line )) == 0 ) {
733 printf( "local cache is on\n" );
735 printf( "ldap_enable_cache failed\n" );
737 #endif /* LDAP_NOCACHE */
740 case 'x': /* uncache entry */
742 printf( NOCACHEERRMSG );
743 #else /* LDAP_NOCACHE */
744 getline( line, sizeof(line), stdin, "DN? " );
745 ldap_uncache_entry( ld, line );
746 #endif /* LDAP_NOCACHE */
749 case 'X': /* uncache request */
751 printf( NOCACHEERRMSG );
752 #else /* LDAP_NOCACHE */
753 getline( line, sizeof(line), stdin, "request msgid? " );
754 ldap_uncache_request( ld, atoi( line ));
755 #endif /* LDAP_NOCACHE */
758 case 'o': /* set ldap options */
759 getline( line, sizeof(line), stdin, "alias deref (0=never, 1=searching, 2=finding, 3=always)?" );
760 ld->ld_deref = atoi( line );
761 getline( line, sizeof(line), stdin, "timelimit?" );
762 ld->ld_timelimit = atoi( line );
763 getline( line, sizeof(line), stdin, "sizelimit?" );
764 ld->ld_sizelimit = atoi( line );
766 LDAP_BOOL_ZERO(&ld->ld_options);
768 #ifdef STR_TRANSLATION
769 getline( line, sizeof(line), stdin,
770 "Automatic translation of T.61 strings (0=no, 1=yes)?" );
771 if ( atoi( line ) == 0 ) {
772 ld->ld_lberoptions &= ~LBER_TRANSLATE_STRINGS;
774 ld->ld_lberoptions |= LBER_TRANSLATE_STRINGS;
775 #ifdef LDAP_CHARSET_8859
776 getline( line, sizeof(line), stdin,
777 "Translate to/from ISO-8859 (0=no, 1=yes?" );
778 if ( atoi( line ) != 0 ) {
779 ldap_set_string_translators( ld,
783 #endif /* LDAP_CHARSET_8859 */
785 #endif /* STR_TRANSLATION */
787 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
788 getline( line, sizeof(line), stdin,
789 "Use DN & DNS to determine where to send requests (0=no, 1=yes)?" );
790 if ( atoi( line ) != 0 ) {
791 LDAP_BOOL_SET(&ld->ld_options, LDAP_BOOL_DNS);
793 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
795 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
796 getline( line, sizeof(line), stdin,
797 "Recognize and chase referrals (0=no, 1=yes)?" );
798 if ( atoi( line ) != 0 ) {
799 LDAP_BOOL_SET(&ld->ld_options, LDAP_BOOL_REFERRALS);
800 getline( line, sizeof(line), stdin,
801 "Prompt for bind credentials when chasing referrals (0=no, 1=yes)?" );
802 if ( atoi( line ) != 0 ) {
803 ldap_set_rebind_proc( ld, bind_prompt );
806 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
809 case 'O': /* set cache options */
811 printf( NOCACHEERRMSG );
812 #else /* LDAP_NOCACHE */
813 getline( line, sizeof(line), stdin, "cache errors (0=smart, 1=never, 2=always)?" );
814 switch( atoi( line )) {
816 ldap_set_cache_options( ld, 0 );
819 ldap_set_cache_options( ld,
820 LDAP_CACHE_OPT_CACHENOERRS );
823 ldap_set_cache_options( ld,
824 LDAP_CACHE_OPT_CACHEALLERRS );
827 printf( "not a valid cache option\n" );
829 #endif /* LDAP_NOCACHE */
833 printf( "Commands: [ad]d [ab]andon [b]ind\n" );
834 printf( " [B]ind async [c]ompare [l]URL search\n" );
835 printf( " [modi]fy [modr]dn [rem]ove\n" );
836 printf( " [res]ult [s]earch [q]uit/unbind\n\n" );
837 printf( " [u]fn search [ut]fn search with timeout\n" );
838 printf( " [d]ebug [e]nable cache set ms[g]id\n" );
839 printf( " d[n]suffix [t]imeout [v]ersion\n" );
840 printf( " [U]fn prefix [x]uncache entry [X]uncache request\n" );
841 printf( " [?]help [o]ptions [O]cache options\n" );
842 printf( " [E]xplode dn [p]arse LDAP URL\n" );
846 printf( "Invalid command. Type ? for help.\n" );
850 (void) memset( line, '\0', sizeof(line) );
857 handle_result( LDAP *ld, LDAPMessage *lm )
859 switch ( lm->lm_msgtype ) {
860 case LDAP_RES_COMPARE:
861 printf( "Compare result\n" );
862 print_ldap_result( ld, lm, "compare" );
865 case LDAP_RES_SEARCH_RESULT:
866 printf( "Search result\n" );
867 print_ldap_result( ld, lm, "search" );
870 case LDAP_RES_SEARCH_ENTRY:
871 printf( "Search entry\n" );
872 print_search_entry( ld, lm );
876 printf( "Add result\n" );
877 print_ldap_result( ld, lm, "add" );
880 case LDAP_RES_DELETE:
881 printf( "Delete result\n" );
882 print_ldap_result( ld, lm, "delete" );
885 case LDAP_RES_MODRDN:
886 printf( "ModRDN result\n" );
887 print_ldap_result( ld, lm, "modrdn" );
891 printf( "Bind result\n" );
892 print_ldap_result( ld, lm, "bind" );
896 printf( "Unknown result type 0x%x\n", lm->lm_msgtype );
897 print_ldap_result( ld, lm, "unknown" );
902 print_ldap_result( LDAP *ld, LDAPMessage *lm, char *s )
904 ldap_result2error( ld, lm, 1 );
905 ldap_perror( ld, s );
907 if ( ld->ld_error != NULL && *ld->ld_error != '\0' )
908 fprintf( stderr, "Additional info: %s\n", ld->ld_error );
909 if ( NAME_ERROR( ld->ld_errno ) && ld->ld_matched != NULL )
910 fprintf( stderr, "Matched DN: %s\n", ld->ld_matched );
915 print_search_entry( LDAP *ld, LDAPMessage *res )
919 struct berval **vals;
923 for ( e = ldap_first_entry( ld, res ); e != NULLMSG;
924 e = ldap_next_entry( ld, e ) ) {
925 if ( e->lm_msgtype == LDAP_RES_SEARCH_RESULT )
928 dn = ldap_get_dn( ld, e );
929 printf( "\tDN: %s\n", dn );
931 ufn = ldap_dn2ufn( dn );
932 printf( "\tUFN: %s\n", ufn );
937 for ( a = ldap_first_attribute( ld, e, &ber ); a != NULL;
938 a = ldap_next_attribute( ld, e, ber ) ) {
939 printf( "\t\tATTR: %s\n", a );
940 if ( (vals = ldap_get_values_len( ld, e, a ))
942 printf( "\t\t\t(no values)\n" );
944 for ( i = 0; vals[i] != NULL; i++ ) {
948 for ( j = 0; (unsigned long) 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 lber_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 );
970 if ( res->lm_msgtype == LDAP_RES_SEARCH_RESULT
971 || res->lm_chain != NULLMSG )
972 print_ldap_result( ld, res, "search" );