10 #include <ac/unistd.h>
14 #ifdef HAVE_SYS_FILE_H
26 /* including the "internal" defs is legit and nec. since this test routine has
27 * a-priori knowledge of libldap internal workings.
28 * hodges@stanford.edu 5-Feb-96
32 #if !defined( PCNFS ) && !defined( WINSOCK ) && !defined( MACOS )
34 #endif /* !PCNFS && !WINSOCK && !MACOS */
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"
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 *) 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 );
108 file_read( char *path, struct berval *bv )
114 if (( fp = fopen( path, "r" )) == NULL ) {
119 if ( fseek( fp, 0L, SEEK_END ) != 0 ) {
125 bv->bv_len = ftell( fp );
127 if (( bv->bv_val = (char *)malloc( bv->bv_len )) == NULL ) {
133 if ( fseek( fp, 0L, SEEK_SET ) != 0 ) {
139 rlen = fread( bv->bv_val, 1, bv->bv_len, fp );
143 if ( (unsigned long) rlen != bv->bv_len ) {
149 return( bv->bv_len );
151 #endif /* MOD_USE_BVALS */
155 get_modlist( char *prompt1, char *prompt2, char *prompt3 )
157 static char buf[256];
162 struct berval **bvals;
163 #endif /* MOD_USE_BVALS */
169 getline( buf, sizeof(buf), stdin, prompt1 );
170 tmp.mod_op = atoi( buf );
172 if ( tmp.mod_op == -1 || buf[0] == '\0' )
176 getline( buf, sizeof(buf), stdin, prompt2 );
177 if ( buf[0] == '\0' )
179 tmp.mod_type = strdup( buf );
181 tmp.mod_values = get_list( prompt3 );
183 if ( tmp.mod_values != NULL ) {
186 for ( i = 0; tmp.mod_values[i] != NULL; ++i )
188 bvals = (struct berval **)calloc( i + 1,
189 sizeof( struct berval *));
190 for ( i = 0; tmp.mod_values[i] != NULL; ++i ) {
191 bvals[i] = (struct berval *)malloc(
192 sizeof( struct berval ));
193 if ( strncmp( tmp.mod_values[i], "{FILE}",
195 if ( file_read( tmp.mod_values[i] + 6,
200 bvals[i]->bv_val = tmp.mod_values[i];
202 strlen( tmp.mod_values[i] );
205 tmp.mod_bvalues = bvals;
206 tmp.mod_op |= LDAP_MOD_BVALUES;
208 #endif /* MOD_USE_BVALS */
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_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_REFERRALS */
273 int argc, char **argv )
276 int i, c, port, cldapflg, errflg, method, id, msgtype;
277 char line[256], command1, command2, command3;
278 char passwd[64], dn[256], rdn[64], attr[64], value[256];
279 char filter[256], *host, **types;
281 char *usage = "usage: %s [-u] [-h host] [-d level] [-s dnsuffix] [-p port] [-t file] [-T file]\n";
282 int bound, all, scope, attrsonly;
284 LDAPMod **mods, **attrs;
285 struct timeval timeout;
286 char *copyfname = NULL;
294 if (( argv = get_list( "cmd line arg?" )) == NULL ) {
297 for ( argc = 0; argv[ argc ] != NULL; ++argc ) {
305 cldapflg = errflg = 0;
307 while (( c = getopt( argc, argv, "uh:d:s:p:t:T:" )) != -1 ) {
310 #ifdef LDAP_CONNECTIONLESS
312 #else /* LDAP_CONNECTIONLESS */
313 printf( "Compile with -DLDAP_CONNECTIONLESS for UDP support\n" );
314 #endif /* LDAP_CONNECTIONLESS */
319 ldap_debug = atoi( optarg );
320 if ( ldap_debug & LDAP_DEBUG_PACKETS ) {
321 lber_debug = ldap_debug;
324 printf( "Compile with -DLDAP_DEBUG for debugging\n" );
337 port = atoi( optarg );
340 #if !defined(MACOS) && !defined(DOS)
341 case 't': /* copy ber's to given file */
342 copyfname = strdup( optarg );
343 copyoptions = LBER_TO_FILE;
346 case 'T': /* only output ber's to given file */
347 copyfname = strdup( optarg );
348 copyoptions = (LBER_TO_FILE | LBER_TO_FILE_ONLY);
357 if ( host == NULL && optind == argc - 1 ) {
358 host = argv[ optind ];
362 if ( errflg || optind < argc - 1 ) {
363 fprintf( stderr, usage, argv[ 0 ] );
367 printf( "%sldap_open( %s, %d )\n", cldapflg ? "c" : "",
368 host == NULL ? "(null)" : host, port );
371 #ifdef LDAP_CONNECTIONLESS
372 ld = cldap_open( host, port );
373 #endif /* LDAP_CONNECTIONLESS */
375 ld = ldap_open( host, port );
379 perror( "ldap_open" );
383 #if !defined(MACOS) && !defined(DOS)
384 if ( copyfname != NULL ) {
385 if ( (ld->ld_sb.sb_fd = open( copyfname, O_WRONLY | O_CREAT,
390 ld->ld_sb.sb_options = copyoptions;
398 (void) memset( line, '\0', sizeof(line) );
399 while ( getline( line, sizeof(line), stdin, "\ncommand? " ) != NULL ) {
404 switch ( command1 ) {
405 case 'a': /* add or abandon */
406 switch ( command2 ) {
408 getline( dn, sizeof(dn), stdin, "dn? " );
409 strcat( dn, dnsuffix );
410 if ( (attrs = get_modlist( NULL, "attr? ",
411 "value? " )) == NULL )
413 if ( (id = ldap_add( ld, dn, attrs )) == -1 )
414 ldap_perror( ld, "ldap_add" );
416 printf( "Add initiated with id %d\n",
420 case 'b': /* abandon */
421 getline( line, sizeof(line), stdin, "msgid? " );
423 if ( ldap_abandon( ld, id ) != 0 )
424 ldap_perror( ld, "ldap_abandon" );
426 printf( "Abandon successful\n" );
429 printf( "Possibilities: [ad]d, [ab]ort\n" );
433 case 'b': /* asynch bind */
435 getline( line, sizeof(line), stdin,
436 "method (0->simple, 1->krbv41, 2->krbv42)? " );
437 method = atoi( line ) | 0x80;
438 #else /* HAVE_KERBEROS */
439 method = LDAP_AUTH_SIMPLE;
440 #endif /* HAVE_KERBEROS */
441 getline( dn, sizeof(dn), stdin, "dn? " );
442 strcat( dn, dnsuffix );
444 if ( method == LDAP_AUTH_SIMPLE && dn[0] != '\0' )
445 getline( passwd, sizeof(passwd), stdin,
450 if ( ldap_bind( ld, dn, passwd, method ) == -1 ) {
451 fprintf( stderr, "ldap_bind failed\n" );
452 ldap_perror( ld, "ldap_bind" );
454 printf( "Bind initiated\n" );
459 case 'B': /* synch bind */
461 getline( line, sizeof(line), stdin,
462 "method 0->simple 1->krbv41 2->krbv42 3->krb? " );
463 method = atoi( line );
465 method = LDAP_AUTH_KRBV4;
467 method = method | 0x80;
468 #else /* HAVE_KERBEROS */
469 method = LDAP_AUTH_SIMPLE;
470 #endif /* HAVE_KERBEROS */
471 getline( dn, sizeof(dn), stdin, "dn? " );
472 strcat( dn, dnsuffix );
475 getline( passwd, sizeof(passwd), stdin,
480 if ( ldap_bind_s( ld, dn, passwd, method ) !=
482 fprintf( stderr, "ldap_bind_s failed\n" );
483 ldap_perror( ld, "ldap_bind_s" );
485 printf( "Bind successful\n" );
490 case 'c': /* compare */
491 getline( dn, sizeof(dn), stdin, "dn? " );
492 strcat( dn, dnsuffix );
493 getline( attr, sizeof(attr), stdin, "attr? " );
494 getline( value, sizeof(value), stdin, "value? " );
496 if ( (id = ldap_compare( ld, dn, attr, value )) == -1 )
497 ldap_perror( ld, "ldap_compare" );
499 printf( "Compare initiated with id %d\n", id );
502 case 'd': /* turn on debugging */
504 getline( line, sizeof(line), stdin, "debug level? " );
505 ldap_debug = atoi( line );
506 if ( ldap_debug & LDAP_DEBUG_PACKETS ) {
507 lber_debug = ldap_debug;
510 printf( "Compile with -DLDAP_DEBUG for debugging\n" );
514 case 'E': /* explode a dn */
515 getline( line, sizeof(line), stdin, "dn? " );
516 exdn = ldap_explode_dn( line, 0 );
517 for ( i = 0; exdn != NULL && exdn[i] != NULL; i++ ) {
518 printf( "\t%s\n", exdn[i] );
522 case 'g': /* set next msgid */
523 getline( line, sizeof(line), stdin, "msgid? " );
524 ld->ld_msgid = atoi( line );
527 case 'v': /* set version number */
528 getline( line, sizeof(line), stdin, "version? " );
529 ld->ld_version = atoi( line );
532 case 'm': /* modify or modifyrdn */
533 if ( strncmp( line, "modify", 4 ) == 0 ) {
534 getline( dn, sizeof(dn), stdin, "dn? " );
535 strcat( dn, dnsuffix );
536 if ( (mods = get_modlist(
537 "mod (0=>add, 1=>delete, 2=>replace -1=>done)? ",
538 "attribute type? ", "attribute value? " ))
541 if ( (id = ldap_modify( ld, dn, mods )) == -1 )
542 ldap_perror( ld, "ldap_modify" );
544 printf( "Modify initiated with id %d\n",
546 } else if ( strncmp( line, "modrdn", 4 ) == 0 ) {
547 getline( dn, sizeof(dn), stdin, "dn? " );
548 strcat( dn, dnsuffix );
549 getline( rdn, sizeof(rdn), stdin, "newrdn? " );
550 if ( (id = ldap_modrdn( ld, dn, rdn )) == -1 )
551 ldap_perror( ld, "ldap_modrdn" );
553 printf( "Modrdn initiated with id %d\n",
556 printf( "Possibilities: [modi]fy, [modr]dn\n" );
561 #ifdef LDAP_CONNECTIONLESS
564 #endif /* LDAP_CONNECTIONLESS */
565 #ifdef LDAP_REFERRALS
567 #else /* LDAP_REFERRALS */
568 if ( !cldapflg && bound )
569 #endif /* LDAP_REFERRALS */
574 case 'r': /* result or remove */
575 switch ( command3 ) {
576 case 's': /* result */
577 getline( line, sizeof(line), stdin,
578 "msgid (-1=>any)? " );
579 if ( line[0] == '\0' )
583 getline( line, sizeof(line), stdin,
584 "all (0=>any, 1=>all)? " );
585 if ( line[0] == '\0' )
589 if (( msgtype = ldap_result( ld, id, all,
590 &timeout, &res )) < 1 ) {
591 ldap_perror( ld, "ldap_result" );
594 printf( "\nresult: msgtype %d msgid %d\n",
595 msgtype, res->lm_msgid );
596 handle_result( ld, res );
600 case 'm': /* remove */
601 getline( dn, sizeof(dn), stdin, "dn? " );
602 strcat( dn, dnsuffix );
603 if ( (id = ldap_delete( ld, dn )) == -1 )
604 ldap_perror( ld, "ldap_delete" );
606 printf( "Remove initiated with id %d\n",
611 printf( "Possibilities: [rem]ove, [res]ult\n" );
616 case 's': /* search */
617 getline( dn, sizeof(dn), stdin, "searchbase? " );
618 strcat( dn, dnsuffix );
619 getline( line, sizeof(line), stdin,
620 "scope (0=Base, 1=One Level, 2=Subtree)? " );
621 scope = atoi( line );
622 getline( filter, sizeof(filter), stdin,
623 "search filter (e.g. sn=jones)? " );
624 types = get_list( "attrs to return? " );
625 getline( line, sizeof(line), stdin,
626 "attrsonly (0=attrs&values, 1=attrs only)? " );
627 attrsonly = atoi( line );
630 #ifdef LDAP_CONNECTIONLESS
631 getline( line, sizeof(line), stdin,
632 "Requestor DN (for logging)? " );
633 if ( cldap_search_s( ld, dn, scope, filter, types,
634 attrsonly, &res, line ) != 0 ) {
635 ldap_perror( ld, "cldap_search_s" );
637 printf( "\nresult: msgid %d\n",
639 handle_result( ld, res );
642 #endif /* LDAP_CONNECTIONLESS */
644 if (( id = ldap_search( ld, dn, scope, filter,
645 types, attrsonly )) == -1 ) {
646 ldap_perror( ld, "ldap_search" );
648 printf( "Search initiated with id %d\n", id );
654 case 't': /* set timeout value */
655 getline( line, sizeof(line), stdin, "timeout? " );
656 timeout.tv_sec = atoi( line );
659 case 'U': /* set ufn search prefix */
660 getline( line, sizeof(line), stdin, "ufn prefix? " );
661 ldap_ufn_setprefix( ld, line );
664 case 'u': /* user friendly search w/optional timeout */
665 getline( dn, sizeof(dn), stdin, "ufn? " );
666 strcat( dn, dnsuffix );
667 types = get_list( "attrs to return? " );
668 getline( line, sizeof(line), stdin,
669 "attrsonly (0=attrs&values, 1=attrs only)? " );
670 attrsonly = atoi( line );
672 if ( command2 == 't' ) {
673 id = ldap_ufn_search_c( ld, dn, types,
674 attrsonly, &res, ldap_ufn_timeout,
677 id = ldap_ufn_search_s( ld, dn, types,
681 ldap_perror( ld, "ldap_ufn_search" );
683 printf( "\nresult: err %d\n", id );
684 handle_result( ld, res );
690 case 'l': /* URL search */
691 getline( line, sizeof(line), stdin,
692 "attrsonly (0=attrs&values, 1=attrs only)? " );
693 attrsonly = atoi( line );
694 getline( line, sizeof(line), stdin, "LDAP URL? " );
695 if (( id = ldap_url_search( ld, line, attrsonly ))
697 ldap_perror( ld, "ldap_url_search" );
699 printf( "URL search initiated with id %d\n", id );
703 case 'p': /* parse LDAP URL */
704 getline( line, sizeof(line), stdin, "LDAP URL? " );
705 if (( i = ldap_url_parse( line, &ludp )) != 0 ) {
706 fprintf( stderr, "ldap_url_parse: error %d\n", i );
708 printf( "\t host: " );
709 if ( ludp->lud_host == NULL ) {
710 printf( "DEFAULT\n" );
712 printf( "<%s>\n", ludp->lud_host );
714 printf( "\t port: " );
715 if ( ludp->lud_port == 0 ) {
716 printf( "DEFAULT\n" );
718 printf( "%d\n", ludp->lud_port );
720 printf( "\t dn: <%s>\n", ludp->lud_dn );
721 printf( "\t attrs:" );
722 if ( ludp->lud_attrs == NULL ) {
725 for ( i = 0; ludp->lud_attrs[ i ] != NULL; ++i ) {
726 printf( " <%s>", ludp->lud_attrs[ i ] );
729 printf( "\n\t scope: %s\n", ludp->lud_scope == LDAP_SCOPE_ONELEVEL ?
730 "ONE" : ludp->lud_scope == LDAP_SCOPE_BASE ? "BASE" :
731 ludp->lud_scope == LDAP_SCOPE_SUBTREE ? "SUB" : "**invalid**" );
732 printf( "\tfilter: <%s>\n", ludp->lud_filter );
733 ldap_free_urldesc( ludp );
737 case 'n': /* set dn suffix, for convenience */
738 getline( line, sizeof(line), stdin, "DN suffix? " );
739 strcpy( dnsuffix, line );
742 case 'e': /* enable cache */
744 printf( NOCACHEERRMSG );
745 #else /* LDAP_NOCACHE */
746 getline( line, sizeof(line), stdin, "Cache timeout (secs)? " );
748 getline( line, sizeof(line), stdin, "Maximum memory to use (bytes)? " );
749 if ( ldap_enable_cache( ld, i, atoi( line )) == 0 ) {
750 printf( "local cache is on\n" );
752 printf( "ldap_enable_cache failed\n" );
754 #endif /* LDAP_NOCACHE */
757 case 'x': /* uncache entry */
759 printf( NOCACHEERRMSG );
760 #else /* LDAP_NOCACHE */
761 getline( line, sizeof(line), stdin, "DN? " );
762 ldap_uncache_entry( ld, line );
763 #endif /* LDAP_NOCACHE */
766 case 'X': /* uncache request */
768 printf( NOCACHEERRMSG );
769 #else /* LDAP_NOCACHE */
770 getline( line, sizeof(line), stdin, "request msgid? " );
771 ldap_uncache_request( ld, atoi( line ));
772 #endif /* LDAP_NOCACHE */
775 case 'o': /* set ldap options */
776 getline( line, sizeof(line), stdin, "alias deref (0=never, 1=searching, 2=finding, 3=always)?" );
777 ld->ld_deref = atoi( line );
778 getline( line, sizeof(line), stdin, "timelimit?" );
779 ld->ld_timelimit = atoi( line );
780 getline( line, sizeof(line), stdin, "sizelimit?" );
781 ld->ld_sizelimit = atoi( line );
785 #ifdef STR_TRANSLATION
786 getline( line, sizeof(line), stdin,
787 "Automatic translation of T.61 strings (0=no, 1=yes)?" );
788 if ( atoi( line ) == 0 ) {
789 ld->ld_lberoptions &= ~LBER_TRANSLATE_STRINGS;
791 ld->ld_lberoptions |= LBER_TRANSLATE_STRINGS;
792 #ifdef LDAP_CHARSET_8859
793 getline( line, sizeof(line), stdin,
794 "Translate to/from ISO-8859 (0=no, 1=yes?" );
795 if ( atoi( line ) != 0 ) {
796 ldap_set_string_translators( ld,
800 #endif /* LDAP_CHARSET_8859 */
802 #endif /* STR_TRANSLATION */
805 getline( line, sizeof(line), stdin,
806 "Use DN & DNS to determine where to send requests (0=no, 1=yes)?" );
807 if ( atoi( line ) != 0 ) {
808 ld->ld_options |= LDAP_OPT_DNS;
810 #endif /* LDAP_DNS */
812 #ifdef LDAP_REFERRALS
813 getline( line, sizeof(line), stdin,
814 "Recognize and chase referrals (0=no, 1=yes)?" );
815 if ( atoi( line ) != 0 ) {
816 ld->ld_options |= LDAP_OPT_REFERRALS;
817 getline( line, sizeof(line), stdin,
818 "Prompt for bind credentials when chasing referrals (0=no, 1=yes)?" );
819 if ( atoi( line ) != 0 ) {
820 ldap_set_rebind_proc( ld, bind_prompt );
823 #endif /* LDAP_REFERRALS */
826 case 'O': /* set cache options */
828 printf( NOCACHEERRMSG );
829 #else /* LDAP_NOCACHE */
830 getline( line, sizeof(line), stdin, "cache errors (0=smart, 1=never, 2=always)?" );
831 switch( atoi( line )) {
833 ldap_set_cache_options( ld, 0 );
836 ldap_set_cache_options( ld,
837 LDAP_CACHE_OPT_CACHENOERRS );
840 ldap_set_cache_options( ld,
841 LDAP_CACHE_OPT_CACHEALLERRS );
844 printf( "not a valid cache option\n" );
846 #endif /* LDAP_NOCACHE */
850 printf( "Commands: [ad]d [ab]andon [b]ind\n" );
851 printf( " [B]ind async [c]ompare [l]URL search\n" );
852 printf( " [modi]fy [modr]dn [rem]ove\n" );
853 printf( " [res]ult [s]earch [q]uit/unbind\n\n" );
854 printf( " [u]fn search [ut]fn search with timeout\n" );
855 printf( " [d]ebug [e]nable cache set ms[g]id\n" );
856 printf( " d[n]suffix [t]imeout [v]ersion\n" );
857 printf( " [U]fn prefix [x]uncache entry [X]uncache request\n" );
858 printf( " [?]help [o]ptions [O]cache options\n" );
859 printf( " [E]xplode dn [p]arse LDAP URL\n" );
863 printf( "Invalid command. Type ? for help.\n" );
867 (void) memset( line, '\0', sizeof(line) );
874 handle_result( LDAP *ld, LDAPMessage *lm )
876 switch ( lm->lm_msgtype ) {
877 case LDAP_RES_COMPARE:
878 printf( "Compare result\n" );
879 print_ldap_result( ld, lm, "compare" );
882 case LDAP_RES_SEARCH_RESULT:
883 printf( "Search result\n" );
884 print_ldap_result( ld, lm, "search" );
887 case LDAP_RES_SEARCH_ENTRY:
888 printf( "Search entry\n" );
889 print_search_entry( ld, lm );
893 printf( "Add result\n" );
894 print_ldap_result( ld, lm, "add" );
897 case LDAP_RES_DELETE:
898 printf( "Delete result\n" );
899 print_ldap_result( ld, lm, "delete" );
902 case LDAP_RES_MODRDN:
903 printf( "ModRDN result\n" );
904 print_ldap_result( ld, lm, "modrdn" );
908 printf( "Bind result\n" );
909 print_ldap_result( ld, lm, "bind" );
913 printf( "Unknown result type 0x%x\n", lm->lm_msgtype );
914 print_ldap_result( ld, lm, "unknown" );
919 print_ldap_result( LDAP *ld, LDAPMessage *lm, char *s )
921 ldap_result2error( ld, lm, 1 );
922 ldap_perror( ld, s );
924 if ( ld->ld_error != NULL && *ld->ld_error != '\0' )
925 fprintf( stderr, "Additional info: %s\n", ld->ld_error );
926 if ( NAME_ERROR( ld->ld_errno ) && ld->ld_matched != NULL )
927 fprintf( stderr, "Matched DN: %s\n", ld->ld_matched );
932 print_search_entry( LDAP *ld, LDAPMessage *res )
936 struct berval **vals;
940 for ( e = ldap_first_entry( ld, res ); e != NULLMSG;
941 e = ldap_next_entry( ld, e ) ) {
942 if ( e->lm_msgtype == LDAP_RES_SEARCH_RESULT )
945 dn = ldap_get_dn( ld, e );
946 printf( "\tDN: %s\n", dn );
948 ufn = ldap_dn2ufn( dn );
949 printf( "\tUFN: %s\n", ufn );
958 for ( a = ldap_first_attribute( ld, e, &ber ); a != NULL;
959 a = ldap_next_attribute( ld, e, ber ) ) {
960 printf( "\t\tATTR: %s\n", a );
961 if ( (vals = ldap_get_values_len( ld, e, a ))
963 printf( "\t\t\t(no values)\n" );
965 for ( i = 0; vals[i] != NULL; i++ ) {
969 for ( j = 0; (unsigned long) j < vals[i]->bv_len; j++ )
970 if ( !isascii( vals[i]->bv_val[j] ) ) {
976 printf( "\t\t\tlength (%ld) (not ascii)\n", vals[i]->bv_len );
977 #ifdef BPRINT_NONASCII
978 lber_bprint( vals[i]->bv_val,
980 #endif /* BPRINT_NONASCII */
983 printf( "\t\t\tlength (%ld) %s\n",
984 vals[i]->bv_len, vals[i]->bv_val );
986 ber_bvecfree( vals );
991 if ( res->lm_msgtype == LDAP_RES_SEARCH_RESULT
992 || res->lm_chain != NULLMSG )
993 print_ldap_result( ld, res, "search" );
999 ldap_perror( LDAP *ld, char *s )
1008 errs = ldap_err2string( ld->ld_errno );
1009 printf( "%s: %s\n", s, errs == NULL ? "unknown error" : errs );
1010 if ( ld->ld_error != NULL && *ld->ld_error != '\0' ) {
1011 printf( "%s: additional info: %s\n", s, ld->ld_error );
1014 #endif /* WINSOCK */