1 /* ldapsearch -- a tool for searching LDAP directories */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2010 The OpenLDAP Foundation.
6 * Portions Copyright 1998-2003 Kurt D. Zeilenga.
7 * Portions Copyright 1998-2001 Net Boolean Incorporated.
8 * Portions Copyright 2001-2003 IBM Corporation.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted only as authorized by the OpenLDAP
15 * A copy of this license is available in the file LICENSE in the
16 * top-level directory of the distribution or, alternatively, at
17 * <http://www.OpenLDAP.org/license.html>.
19 /* Portions Copyright (c) 1992-1996 Regents of the University of Michigan.
20 * All rights reserved.
22 * Redistribution and use in source and binary forms are permitted
23 * provided that this notice is preserved and that due credit is given
24 * to the University of Michigan at Ann Arbor. The name of the
25 * University may not be used to endorse or promote products derived
26 * from this software without specific prior written permission. This
27 * software is provided ``as is'' without express or implied warranty.
30 * This work was originally developed by the University of Michigan
31 * (as part of U-MICH LDAP). Additional significant contributors
43 #include <ac/stdlib.h>
46 #include <ac/string.h>
47 #include <ac/unistd.h>
51 #include <ac/signal.h>
56 #ifdef HAVE_SYS_TYPES_H
57 #include <sys/types.h>
67 #include "lutil_ldap.h"
68 #include "ldap_defaults.h"
76 * NOTE: we use this deprecated function only because
77 * we want ldapsearch to provide some client-side sorting
81 typedef int (LDAP_SORT_AD_CMP_PROC) LDAP_P(( /* deprecated */
82 LDAP_CONST char *left,
83 LDAP_CONST char *right ));
85 LDAP_F( int ) /* deprecated */
86 ldap_sort_entries LDAP_P(( LDAP *ld,
88 LDAP_CONST char *attr,
89 LDAP_SORT_AD_CMP_PROC *cmp ));
92 static int scope = LDAP_SCOPE_SUBTREE;
93 static int deref = -1;
95 static int timelimit = -1;
96 static int sizelimit = -1;
100 static char *def_tmpdir;
101 static char *def_urlpre;
103 #if defined(__CYGWIN__) || defined(__MINGW32__)
104 /* Turn off commandline globbing, otherwise you cannot search for
113 fprintf( stderr, _("usage: %s [options] [filter [attributes...]]\nwhere:\n"), prog);
114 fprintf( stderr, _(" filter\tRFC 4515 compliant LDAP search filter\n"));
115 fprintf( stderr, _(" attributes\twhitespace-separated list of attribute descriptions\n"));
116 fprintf( stderr, _(" which may include:\n"));
117 fprintf( stderr, _(" 1.1 no attributes\n"));
118 fprintf( stderr, _(" * all user attributes\n"));
119 fprintf( stderr, _(" + all operational attributes\n"));
122 fprintf( stderr, _("Search options:\n"));
123 fprintf( stderr, _(" -a deref one of never (default), always, search, or find\n"));
124 fprintf( stderr, _(" -A retrieve attribute names only (no values)\n"));
125 fprintf( stderr, _(" -b basedn base dn for search\n"));
126 fprintf( stderr, _(" -c continuous operation mode (do not stop on errors)\n"));
127 fprintf( stderr, _(" -E [!]<ext>[=<extparam>] search extensions (! indicates criticality)\n"));
128 fprintf( stderr, _(" [!]domainScope (domain scope)\n"));
129 fprintf( stderr, _(" !dontUseCopy (Don't Use Copy)\n"));
130 fprintf( stderr, _(" [!]mv=<filter> (RFC 3876 matched values filter)\n"));
131 fprintf( stderr, _(" [!]pr=<size>[/prompt|noprompt] (RFC 2696 paged results/prompt)\n"));
132 fprintf( stderr, _(" [!]sss=[-]<attr[:OID]>[/[-]<attr[:OID]>...]\n"));
133 fprintf( stderr, _(" (RFC 2891 server side sorting)\n"));
134 fprintf( stderr, _(" [!]subentries[=true|false] (RFC 3672 subentries)\n"));
135 fprintf( stderr, _(" [!]sync=ro[/<cookie>] (RFC 4533 LDAP Sync refreshOnly)\n"));
136 fprintf( stderr, _(" rp[/<cookie>][/<slimit>] (refreshAndPersist)\n"));
137 fprintf( stderr, _(" [!]vlv=<before>/<after>(/<offset>/<count>|:<value>)\n"));
138 fprintf( stderr, _(" (ldapv3-vlv-09 virtual list views)\n"));
139 #ifdef LDAP_CONTROL_X_DEREF
140 fprintf( stderr, _(" [!]deref=derefAttr:attr[,...][;derefAttr:attr[,...][;...]]\n"));
142 fprintf( stderr, _(" [!]<oid>=:<value> (generic control; no response handling)\n"));
143 fprintf( stderr, _(" -f file read operations from `file'\n"));
144 fprintf( stderr, _(" -F prefix URL prefix for files (default: %s)\n"), def_urlpre);
145 fprintf( stderr, _(" -l limit time limit (in seconds, or \"none\" or \"max\") for search\n"));
146 fprintf( stderr, _(" -L print responses in LDIFv1 format\n"));
147 fprintf( stderr, _(" -LL print responses in LDIF format without comments\n"));
148 fprintf( stderr, _(" -LLL print responses in LDIF format without comments\n"));
149 fprintf( stderr, _(" and version\n"));
150 fprintf( stderr, _(" -M enable Manage DSA IT control (-MM to make critical)\n"));
151 fprintf( stderr, _(" -P version protocol version (default: 3)\n"));
152 fprintf( stderr, _(" -s scope one of base, one, sub or children (search scope)\n"));
153 fprintf( stderr, _(" -S attr sort the results by attribute `attr'\n"));
154 fprintf( stderr, _(" -t write binary values to files in temporary directory\n"));
155 fprintf( stderr, _(" -tt write all values to files in temporary directory\n"));
156 fprintf( stderr, _(" -T path write files to directory specified by path (default: %s)\n"), def_tmpdir);
157 fprintf( stderr, _(" -u include User Friendly entry names in the output\n"));
158 fprintf( stderr, _(" -z limit size limit (in entries, or \"none\" or \"max\") for search\n"));
160 exit( EXIT_FAILURE );
163 static void print_entry LDAP_P((
168 static void print_reference(
170 LDAPMessage *reference );
172 static void print_extended(
174 LDAPMessage *extended );
176 static void print_partial(
178 LDAPMessage *partial );
180 static int print_result(
185 static int dosearch LDAP_P((
193 LDAPControl **sctrls,
194 LDAPControl **cctrls,
195 struct timeval *timeout,
198 static char *tmpdir = NULL;
199 static char *urlpre = NULL;
200 static char *base = NULL;
201 static char *sortattr = NULL;
202 static int includeufn, vals2tmp = 0;
204 static int subentries = 0, valuesReturnFilter = 0;
205 static char *vrFilter = NULL;
207 #ifdef LDAP_CONTROL_DONTUSECOPY
208 static int dontUseCopy = 0;
211 static int domainScope = 0;
214 static LDAPSortKey **sss_keys = NULL;
217 static LDAPVLVInfo vlvInfo;
218 static struct berval vlvValue;
220 static int ldapsync = 0;
221 static struct berval sync_cookie = { 0, NULL };
222 static int sync_slimit = -1;
224 /* cookie and morePagedResults moved to common.c */
225 static int pagedResults = 0;
226 static int pagePrompt = 1;
227 static ber_int_t pageSize = 0;
228 static ber_int_t entriesLeft = 0;
229 static int npagedresponses;
230 static int npagedentries;
231 static int npagedreferences;
232 static int npagedextended;
233 static int npagedpartial;
235 static LDAPControl *c = NULL;
236 static int nctrls = 0;
237 static int save_nctrls = 0;
239 #ifdef LDAP_CONTROL_X_DEREF
240 static int derefcrit;
241 static LDAPDerefSpec *ds;
242 static struct berval derefval;
251 tmpc = realloc( c, sizeof( LDAPControl ) * nctrls );
252 if ( tmpc == NULL ) {
255 _("unable to make room for control; out of memory?\n"));
268 if (*LDAP_DIRSEP != '/') {
269 for (p = url; *p; p++) {
270 if (*p == *LDAP_DIRSEP)
277 parse_vlv(char *cvalue)
283 if ( sscanf( keyp, "%d/%d", &num1, &num2 ) != 2 ) {
285 _("VLV control value \"%s\" invalid\n"),
289 vlvInfo.ldvlv_before_count = num1;
290 vlvInfo.ldvlv_after_count = num2;
291 keyp = strchr( keyp, '/' ) + 1;
292 key2 = strchr( keyp, '/' );
295 if ( sscanf( keyp, "%d/%d", &num1, &num2 ) != 2 ) {
297 _("VLV control value \"%s\" invalid\n"),
301 vlvInfo.ldvlv_offset = num1;
302 vlvInfo.ldvlv_count = num2;
303 vlvInfo.ldvlv_attrvalue = NULL;
305 key2 = strchr( keyp, ':' );
308 _("VLV control value \"%s\" invalid\n"),
312 ber_str2bv( key2+1, 0, 0, &vlvValue );
313 vlvInfo.ldvlv_attrvalue = &vlvValue;
318 const char options[] = "a:Ab:cE:F:l:Ls:S:tT:uz:"
319 "Cd:D:e:f:h:H:IMnNO:o:p:P:QR:U:vVw:WxX:y:Y:Z";
322 handle_private_option( int i )
327 case 'a': /* set alias deref option */
328 if ( strcasecmp( optarg, "never" ) == 0 ) {
329 deref = LDAP_DEREF_NEVER;
330 } else if ( strncasecmp( optarg, "search", sizeof("search")-1 ) == 0 ) {
331 deref = LDAP_DEREF_SEARCHING;
332 } else if ( strncasecmp( optarg, "find", sizeof("find")-1 ) == 0 ) {
333 deref = LDAP_DEREF_FINDING;
334 } else if ( strcasecmp( optarg, "always" ) == 0 ) {
335 deref = LDAP_DEREF_ALWAYS;
338 _("alias deref should be never, search, find, or always\n") );
342 case 'A': /* retrieve attribute names only -- no values */
345 case 'b': /* search base */
346 base = ber_strdup( optarg );
348 case 'E': /* search extensions */
349 if( protocol == LDAP_VERSION2 ) {
350 fprintf( stderr, _("%s: -E incompatible with LDAPv%d\n"),
352 exit( EXIT_FAILURE );
355 /* should be extended to support comma separated list of
356 * [!]key[=value] parameters, e.g. -E !foo,bar=567
361 while ( optarg[0] == '!' ) {
366 control = ber_strdup( optarg );
367 if ( (cvalue = strchr( control, '=' )) != NULL ) {
371 if ( strcasecmp( control, "mv" ) == 0 ) {
372 /* ValuesReturnFilter control */
373 if( valuesReturnFilter ) {
375 _("ValuesReturnFilter previously specified\n"));
376 exit( EXIT_FAILURE );
378 valuesReturnFilter= 1 + crit;
380 if ( cvalue == NULL ) {
382 _("missing filter in ValuesReturnFilter control\n"));
383 exit( EXIT_FAILURE );
387 protocol = LDAP_VERSION3;
389 } else if ( strcasecmp( control, "pr" ) == 0 ) {
391 /* PagedResults control */
392 if ( pagedResults != 0 ) {
394 _("PagedResultsControl previously specified\n") );
395 exit( EXIT_FAILURE );
399 _("PagedResultsControl incompatible with VLV\n") );
400 exit( EXIT_FAILURE );
403 if( cvalue != NULL ) {
406 promptp = strchr( cvalue, '/' );
407 if ( promptp != NULL ) {
409 if ( strcasecmp( promptp, "prompt" ) == 0 ) {
411 } else if ( strcasecmp( promptp, "noprompt" ) == 0) {
415 _("Invalid value for PagedResultsControl,"
416 " %s/%s.\n"), cvalue, promptp );
417 exit( EXIT_FAILURE );
420 num = sscanf( cvalue, "%d", &tmp );
423 _("Invalid value for PagedResultsControl, %s.\n"),
425 exit( EXIT_FAILURE );
428 fprintf(stderr, _("Invalid value for PagedResultsControl.\n"));
429 exit( EXIT_FAILURE );
431 pageSize = (ber_int_t) tmp;
432 pagedResults = 1 + crit;
434 #ifdef LDAP_CONTROL_DONTUSECOPY
435 } else if ( strcasecmp( control, "dontUseCopy" ) == 0 ) {
438 _("dontUseCopy control previously specified\n"));
439 exit( EXIT_FAILURE );
441 if( cvalue != NULL ) {
443 _("dontUseCopy: no control value expected\n") );
448 _("dontUseCopy: critical flag required\n") );
452 dontUseCopy = 1 + crit;
454 } else if ( strcasecmp( control, "domainScope" ) == 0 ) {
457 _("domainScope control previously specified\n"));
458 exit( EXIT_FAILURE );
460 if( cvalue != NULL ) {
462 _("domainScope: no control value expected\n") );
466 domainScope = 1 + crit;
468 } else if ( strcasecmp( control, "sss" ) == 0 ) {
472 _("server side sorting control previously specified\n"));
473 exit( EXIT_FAILURE );
475 if( cvalue == NULL ) {
477 _("missing specification of sss control\n") );
478 exit( EXIT_FAILURE );
481 while ( ( keyp = strchr(keyp, '/') ) != NULL ) {
484 if ( ldap_create_sort_keylist( &sss_keys, cvalue )) {
486 _("server side sorting control value \"%s\" invalid\n"),
488 exit( EXIT_FAILURE );
493 } else if ( strcasecmp( control, "subentries" ) == 0 ) {
496 _("subentries control previously specified\n"));
497 exit( EXIT_FAILURE );
499 if( cvalue == NULL || strcasecmp( cvalue, "true") == 0 ) {
501 } else if ( strcasecmp( cvalue, "false") == 0 ) {
505 _("subentries control value \"%s\" invalid\n"),
507 exit( EXIT_FAILURE );
509 if( crit ) subentries *= -1;
511 } else if ( strcasecmp( control, "sync" ) == 0 ) {
515 fprintf( stderr, _("sync control previously specified\n") );
516 exit( EXIT_FAILURE );
518 if ( cvalue == NULL ) {
519 fprintf( stderr, _("missing specification of sync control\n"));
520 exit( EXIT_FAILURE );
522 if ( strncasecmp( cvalue, "ro", 2 ) == 0 ) {
523 ldapsync = LDAP_SYNC_REFRESH_ONLY;
524 cookiep = strchr( cvalue, '/' );
525 if ( cookiep != NULL ) {
527 if ( *cookiep != '\0' ) {
528 ber_str2bv( cookiep, 0, 0, &sync_cookie );
531 } else if ( strncasecmp( cvalue, "rp", 2 ) == 0 ) {
532 ldapsync = LDAP_SYNC_REFRESH_AND_PERSIST;
533 cookiep = strchr( cvalue, '/' );
534 if ( cookiep != NULL ) {
538 slimitp = strchr( cvalue, '/' );
539 if ( slimitp != NULL ) {
542 if ( cookiep != NULL && *cookiep != '\0' )
543 ber_str2bv( cookiep, 0, 0, &sync_cookie );
544 if ( slimitp != NULL && *slimitp != '\0' ) {
545 ival = strtol( slimitp, &next, 10 );
546 if ( next == NULL || next[0] != '\0' ) {
547 fprintf( stderr, _("Unable to parse sync control value \"%s\"\n"), slimitp );
548 exit( EXIT_FAILURE );
553 fprintf( stderr, _("sync control value \"%s\" invalid\n"),
555 exit( EXIT_FAILURE );
557 if ( crit ) ldapsync *= -1;
559 } else if ( strcasecmp( control, "vlv" ) == 0 ) {
562 _("virtual list view control previously specified\n"));
563 exit( EXIT_FAILURE );
565 if ( pagedResults != 0 ) {
567 _("PagedResultsControl incompatible with VLV\n") );
568 exit( EXIT_FAILURE );
570 if( cvalue == NULL ) {
572 _("missing specification of vlv control\n") );
573 exit( EXIT_FAILURE );
575 if ( parse_vlv( cvalue ))
576 exit( EXIT_FAILURE );
580 #ifdef LDAP_CONTROL_X_DEREF
581 } else if ( strcasecmp( control, "deref" ) == 0 ) {
585 /* cvalue is something like
587 * derefAttr:attr[,attr[...]][;derefAttr:attr[,attr[...]]]"
590 specs = ldap_str2charray( cvalue, ";" );
591 if ( specs == NULL ) {
592 fprintf( stderr, _("deref specs \"%s\" invalid\n"),
594 exit( EXIT_FAILURE );
596 for ( ispecs = 0; specs[ ispecs ] != NULL; ispecs++ )
599 ds = ldap_memcalloc( ispecs + 1, sizeof( LDAPDerefSpec ) );
602 exit( EXIT_FAILURE );
605 for ( ispecs = 0; specs[ ispecs ] != NULL; ispecs++ ) {
608 ptr = strchr( specs[ ispecs ], ':' );
610 fprintf( stderr, _("deref specs \"%s\" invalid\n"),
612 exit( EXIT_FAILURE );
615 ds[ ispecs ].derefAttr = specs[ ispecs ];
617 ds[ ispecs ].attributes = ldap_str2charray( ptr, "," );
620 derefcrit = 1 + crit;
622 ldap_memfree( specs );
623 #endif /* LDAP_CONTROL_X_DEREF */
625 } else if ( tool_is_oid( control ) ) {
628 for ( i = 0; c[ i ].ldctl_oid != NULL; i++ ) {
629 if ( strcmp( control, c[ i ].ldctl_oid ) == 0 ) {
630 fprintf( stderr, "%s control previously specified\n", control );
631 exit( EXIT_FAILURE );
637 exit( EXIT_FAILURE );
641 c[ nctrls - 1 ].ldctl_oid = control;
644 if ( cvalue == NULL ) {
645 c[ nctrls - 1 ].ldctl_value.bv_val = NULL;
646 c[ nctrls - 1 ].ldctl_value.bv_len = 0;
648 } else if ( cvalue[ 0 ] == ':' ) {
656 * to use ldif_parse_line2() */
658 ldif_parse_line2( &cvalue[ -2 ], &type,
663 c[ nctrls - 1 ].ldctl_value = value;
666 ber_dupbv( &c[ nctrls - 1 ].ldctl_value, &value );
671 c[ nctrls - 1 ].ldctl_iscritical = crit;
674 fprintf( stderr, _("Invalid search extension name: %s\n"),
679 case 'F': /* uri prefix */
680 if( urlpre ) free( urlpre );
681 urlpre = strdup( optarg );
683 case 'l': /* time limit */
684 if ( strcasecmp( optarg, "none" ) == 0 ) {
687 } else if ( strcasecmp( optarg, "max" ) == 0 ) {
688 timelimit = LDAP_MAXINT;
691 ival = strtol( optarg, &next, 10 );
692 if ( next == NULL || next[0] != '\0' ) {
694 _("Unable to parse time limit \"%s\"\n"), optarg );
695 exit( EXIT_FAILURE );
699 if( timelimit < 0 || timelimit > LDAP_MAXINT ) {
700 fprintf( stderr, _("%s: invalid timelimit (%d) specified\n"),
702 exit( EXIT_FAILURE );
705 case 'L': /* print entries in LDIF format */
708 case 's': /* search scope */
709 if ( strncasecmp( optarg, "base", sizeof("base")-1 ) == 0 ) {
710 scope = LDAP_SCOPE_BASE;
711 } else if ( strncasecmp( optarg, "one", sizeof("one")-1 ) == 0 ) {
712 scope = LDAP_SCOPE_ONELEVEL;
713 } else if (( strcasecmp( optarg, "subordinate" ) == 0 )
714 || ( strcasecmp( optarg, "children" ) == 0 ))
716 scope = LDAP_SCOPE_SUBORDINATE;
717 } else if ( strncasecmp( optarg, "sub", sizeof("sub")-1 ) == 0 ) {
718 scope = LDAP_SCOPE_SUBTREE;
720 fprintf( stderr, _("scope should be base, one, or sub\n") );
724 case 'S': /* sort attribute */
725 sortattr = strdup( optarg );
727 case 't': /* write attribute values to TMPDIR files */
730 case 'T': /* tmpdir */
731 if( tmpdir ) free( tmpdir );
732 tmpdir = strdup( optarg );
734 case 'u': /* include UFN */
737 case 'z': /* size limit */
738 if ( strcasecmp( optarg, "none" ) == 0 ) {
741 } else if ( strcasecmp( optarg, "max" ) == 0 ) {
742 sizelimit = LDAP_MAXINT;
745 ival = strtol( optarg, &next, 10 );
746 if ( next == NULL || next[0] != '\0' ) {
748 _("Unable to parse size limit \"%s\"\n"), optarg );
749 exit( EXIT_FAILURE );
753 if( sizelimit < 0 || sizelimit > LDAP_MAXINT ) {
754 fprintf( stderr, _("%s: invalid sizelimit (%d) specified\n"),
756 exit( EXIT_FAILURE );
767 private_conn_setup( LDAP *ld )
770 ldap_set_option( ld, LDAP_OPT_DEREF, (void *) &deref )
771 != LDAP_OPT_SUCCESS )
773 fprintf( stderr, _("Could not set LDAP_OPT_DEREF %d\n"), deref );
774 exit( EXIT_FAILURE );
777 ldap_set_option( ld, LDAP_OPT_TIMELIMIT, (void *) &timelimit )
778 != LDAP_OPT_SUCCESS )
781 _("Could not set LDAP_OPT_TIMELIMIT %d\n"), timelimit );
782 exit( EXIT_FAILURE );
785 ldap_set_option( ld, LDAP_OPT_SIZELIMIT, (void *) &sizelimit )
786 != LDAP_OPT_SUCCESS )
789 _("Could not set LDAP_OPT_SIZELIMIT %d\n"), sizelimit );
790 exit( EXIT_FAILURE );
795 main( int argc, char **argv )
797 char *filtpattern, **attrs = NULL, line[BUFSIZ];
799 int rc, rc1, i, first;
801 BerElement *seber = NULL, *vrber = NULL;
803 BerElement *syncber = NULL;
804 struct berval *syncbvalp = NULL;
807 tool_init( TOOL_SEARCH );
809 npagedresponses = npagedentries = npagedreferences =
810 npagedextended = npagedpartial = 0;
812 prog = lutil_progname( "ldapsearch", argc, argv );
814 if((def_tmpdir = getenv("TMPDIR")) == NULL &&
815 (def_tmpdir = getenv("TMP")) == NULL &&
816 (def_tmpdir = getenv("TEMP")) == NULL )
818 def_tmpdir = LDAP_TMPDIR;
822 def_tmpdir = LDAP_TMPDIR;
824 def_urlpre = malloc( sizeof("file:////") + strlen(def_tmpdir) );
826 if( def_urlpre == NULL ) {
831 sprintf( def_urlpre, "file:///%s/",
832 def_tmpdir[0] == *LDAP_DIRSEP ? &def_tmpdir[1] : def_tmpdir );
834 urlize( def_urlpre );
836 tool_args( argc, argv );
840 _("VLV control requires server side sort control\n" ));
844 if (( argc - optind < 1 ) ||
845 ( *argv[optind] != '(' /*')'*/ &&
846 ( strchr( argv[optind], '=' ) == NULL ) ) )
848 filtpattern = "(objectclass=*)";
850 filtpattern = argv[optind++];
853 if ( argv[optind] != NULL ) {
854 attrs = &argv[optind];
857 if ( infile != NULL ) {
860 if ( infile[0] == '-' && infile[1] == '\0' ) {
862 } else if (( fp = fopen( infile, "r" )) == NULL ) {
867 for( i=0 ; filtpattern[i] ; i++ ) {
868 if( filtpattern[i] == '%' ) {
870 fprintf( stderr, _("Bad filter pattern \"%s\"\n"),
877 if( filtpattern[i+1] != 's' ) {
878 fprintf( stderr, _("Bad filter pattern \"%s\"\n"),
886 if ( tmpdir == NULL ) {
889 if ( urlpre == NULL )
893 if( urlpre == NULL ) {
894 urlpre = malloc( sizeof("file:////") + strlen(tmpdir) );
896 if( urlpre == NULL ) {
901 sprintf( urlpre, "file:///%s/",
902 tmpdir[0] == *LDAP_DIRSEP ? &tmpdir[1] : tmpdir );
910 ld = tool_conn_setup( 0, &private_conn_setup );
915 save_nctrls = nctrls;
918 #ifdef LDAP_CONTROL_DONTUSECOPY
921 #ifdef LDAP_CONTROL_X_DEREF
929 || valuesReturnFilter
933 #ifdef LDAP_CONTROL_DONTUSECOPY
939 c[i].ldctl_oid = LDAP_CONTROL_DONTUSECOPY;
940 c[i].ldctl_value.bv_val = NULL;
941 c[i].ldctl_value.bv_len = 0;
942 c[i].ldctl_iscritical = dontUseCopy == 2;
952 c[i].ldctl_oid = LDAP_CONTROL_X_DOMAIN_SCOPE;
953 c[i].ldctl_value.bv_val = NULL;
954 c[i].ldctl_value.bv_len = 0;
955 c[i].ldctl_iscritical = domainScope > 1;
964 if (( seber = ber_alloc_t(LBER_USE_DER)) == NULL ) {
968 err = ber_printf( seber, "b", abs(subentries) == 1 ? 0 : 1 );
970 ber_free( seber, 1 );
971 fprintf( stderr, _("Subentries control encoding error!\n") );
975 if ( ber_flatten2( seber, &c[i].ldctl_value, 0 ) == -1 ) {
979 c[i].ldctl_oid = LDAP_CONTROL_SUBENTRIES;
980 c[i].ldctl_iscritical = subentries < 1;
989 if (( syncber = ber_alloc_t(LBER_USE_DER)) == NULL ) {
993 if ( sync_cookie.bv_len == 0 ) {
994 err = ber_printf( syncber, "{e}", abs(ldapsync) );
996 err = ber_printf( syncber, "{eO}", abs(ldapsync),
1001 ber_free( syncber, 1 );
1002 fprintf( stderr, _("ldap sync control encoding error!\n") );
1003 return EXIT_FAILURE;
1006 if ( ber_flatten( syncber, &syncbvalp ) == -1 ) {
1007 return EXIT_FAILURE;
1010 c[i].ldctl_oid = LDAP_CONTROL_SYNC;
1011 c[i].ldctl_value = (*syncbvalp);
1012 c[i].ldctl_iscritical = ldapsync < 0;
1016 if ( valuesReturnFilter ) {
1018 return EXIT_FAILURE;
1021 if (( vrber = ber_alloc_t(LBER_USE_DER)) == NULL ) {
1022 return EXIT_FAILURE;
1025 if ( ( err = ldap_put_vrFilter( vrber, vrFilter ) ) == -1 ) {
1026 ber_free( vrber, 1 );
1027 fprintf( stderr, _("Bad ValuesReturnFilter: %s\n"), vrFilter );
1028 return EXIT_FAILURE;
1031 if ( ber_flatten2( vrber, &c[i].ldctl_value, 0 ) == -1 ) {
1032 return EXIT_FAILURE;
1035 c[i].ldctl_oid = LDAP_CONTROL_VALUESRETURNFILTER;
1036 c[i].ldctl_iscritical = valuesReturnFilter > 1;
1040 if ( pagedResults ) {
1042 return EXIT_FAILURE;
1045 if ( ldap_create_page_control_value( ld,
1046 pageSize, &pr_cookie, &c[i].ldctl_value ) )
1048 return EXIT_FAILURE;
1051 if ( pr_cookie.bv_val != NULL ) {
1052 ber_memfree( pr_cookie.bv_val );
1053 pr_cookie.bv_val = NULL;
1054 pr_cookie.bv_len = 0;
1057 c[i].ldctl_oid = LDAP_CONTROL_PAGEDRESULTS;
1058 c[i].ldctl_iscritical = pagedResults > 1;
1064 return EXIT_FAILURE;
1067 if ( ldap_create_sort_control_value( ld,
1068 sss_keys, &c[i].ldctl_value ) )
1070 return EXIT_FAILURE;
1073 c[i].ldctl_oid = LDAP_CONTROL_SORTREQUEST;
1074 c[i].ldctl_iscritical = sss > 1;
1080 return EXIT_FAILURE;
1083 if ( ldap_create_vlv_control_value( ld,
1084 &vlvInfo, &c[i].ldctl_value ) )
1086 return EXIT_FAILURE;
1089 c[i].ldctl_oid = LDAP_CONTROL_VLVREQUEST;
1090 c[i].ldctl_iscritical = sss > 1;
1093 #ifdef LDAP_CONTROL_X_DEREF
1095 if ( derefval.bv_val == NULL ) {
1098 assert( ds != NULL );
1100 if ( ldap_create_deref_control_value( ld, ds, &derefval ) != LDAP_SUCCESS ) {
1101 return EXIT_FAILURE;
1104 for ( i = 0; ds[ i ].derefAttr != NULL; i++ ) {
1105 ldap_memfree( ds[ i ].derefAttr );
1106 ldap_charray_free( ds[ i ].attributes );
1113 exit( EXIT_FAILURE );
1116 c[ i ].ldctl_iscritical = derefcrit > 1;
1117 c[ i ].ldctl_oid = LDAP_CONTROL_X_DEREF;
1118 c[ i ].ldctl_value = derefval;
1121 #endif /* LDAP_CONTROL_X_DEREF */
1124 tool_server_controls( ld, c, i );
1126 if ( seber ) ber_free( seber, 1 );
1127 if ( vrber ) ber_free( vrber, 1 );
1129 /* step back to the original number of controls, so that
1130 * those set while parsing args are preserved */
1131 nctrls = save_nctrls;
1134 fprintf( stderr, _("filter%s: %s\nrequesting: "),
1135 infile != NULL ? _(" pattern") : "",
1138 if ( attrs == NULL ) {
1139 fprintf( stderr, _("All userApplication attributes") );
1141 for ( i = 0; attrs[ i ] != NULL; ++i ) {
1142 fprintf( stderr, "%s ", attrs[ i ] );
1145 fprintf( stderr, "\n" );
1149 printf( _("# extended LDIF\n") );
1150 } else if ( ldif < 3 ) {
1151 printf( _("version: %d\n\n"), 1 );
1155 char *realbase = base;
1157 if ( realbase == NULL ) {
1158 ldap_get_option( ld, LDAP_OPT_DEFBASE, (void **)(char *)&realbase );
1162 printf(_("# LDAPv%d\n"), protocol);
1163 printf(_("# base <%s>%s with scope %s\n"),
1164 realbase ? realbase : "",
1165 ( realbase == NULL || realbase != base ) ? " (default)" : "",
1166 ((scope == LDAP_SCOPE_BASE) ? "baseObject"
1167 : ((scope == LDAP_SCOPE_ONELEVEL) ? "oneLevel"
1168 : ((scope == LDAP_SCOPE_SUBORDINATE) ? "children"
1170 printf(_("# filter%s: %s\n"), infile != NULL ? _(" pattern") : "",
1172 printf(_("# requesting: "));
1174 if ( attrs == NULL ) {
1177 for ( i = 0; attrs[ i ] != NULL; ++i ) {
1178 printf( "%s ", attrs[ i ] );
1182 if ( manageDSAit ) {
1183 printf(_("\n# with manageDSAit %scontrol"),
1184 manageDSAit > 1 ? _("critical ") : "" );
1187 printf(_("\n# with noop %scontrol"),
1188 noop > 1 ? _("critical ") : "" );
1191 printf(_("\n# with subentries %scontrol: %s"),
1192 subentries < 0 ? _("critical ") : "",
1193 abs(subentries) == 1 ? "false" : "true" );
1195 if ( valuesReturnFilter ) {
1196 printf(_("\n# with valuesReturnFilter %scontrol: %s"),
1197 valuesReturnFilter > 1 ? _("critical ") : "", vrFilter );
1199 if ( pagedResults ) {
1200 printf(_("\n# with pagedResults %scontrol: size=%d"),
1201 (pagedResults > 1) ? _("critical ") : "",
1205 printf(_("\n# with server side sorting %scontrol"),
1206 sss > 1 ? _("critical ") : "" );
1209 printf(_("\n# with virtual list view %scontrol: %d/%d"),
1210 vlv > 1 ? _("critical ") : "",
1211 vlvInfo.ldvlv_before_count, vlvInfo.ldvlv_after_count);
1212 if ( vlvInfo.ldvlv_attrvalue )
1213 printf(":%s", vlvInfo.ldvlv_attrvalue->bv_val );
1215 printf("/%d/%d", vlvInfo.ldvlv_offset, vlvInfo.ldvlv_count );
1217 #ifdef LDAP_CONTROL_X_DEREF
1219 printf(_("\n# with dereference %scontrol"),
1220 derefcrit > 1 ? _("critical ") : "" );
1224 printf( _("\n#\n\n") );
1226 if ( realbase && realbase != base ) {
1227 ldap_memfree( realbase );
1231 if ( infile == NULL ) {
1232 rc = dosearch( ld, base, scope, NULL, filtpattern,
1233 attrs, attrsonly, NULL, NULL, NULL, -1 );
1238 while ( fgets( line, sizeof( line ), fp ) != NULL ) {
1239 line[ strlen( line ) - 1 ] = '\0';
1245 rc1 = dosearch( ld, base, scope, filtpattern, line,
1246 attrs, attrsonly, NULL, NULL, NULL, -1 );
1254 if ( fp != stdin ) {
1259 if (( rc == LDAP_SUCCESS ) && pageSize && pr_morePagedResults ) {
1261 int i, moreEntries, tmpSize;
1263 /* Loop to get the next pages when
1264 * enter is pressed on the terminal.
1266 if ( pagePrompt != 0 ) {
1267 if ( entriesLeft > 0 ) {
1268 printf( _("Estimate entries: %d\n"), entriesLeft );
1270 printf( _("Press [size] Enter for the next {%d|size} entries.\n"),
1273 moreEntries = getchar();
1274 while ( moreEntries != EOF && moreEntries != '\n' ) {
1275 if ( i < (int)sizeof(buf) - 1 ) {
1276 buf[i] = moreEntries;
1279 moreEntries = getchar();
1283 if ( i > 0 && isdigit( (unsigned char)buf[0] ) ) {
1284 int num = sscanf( buf, "%d", &tmpSize );
1287 _("Invalid value for PagedResultsControl, %s.\n"), buf);
1288 return EXIT_FAILURE;
1291 pageSize = (ber_int_t)tmpSize;
1298 if (( rc == LDAP_SUCCESS ) && vlv ) {
1302 /* Loop to get the next window when
1303 * enter is pressed on the terminal.
1305 printf( _("Press [before/after(/offset/count|:value)] Enter for the next window.\n"));
1307 moreEntries = getchar();
1308 while ( moreEntries != EOF && moreEntries != '\n' ) {
1309 if ( i < (int)sizeof(buf) - 1 ) {
1310 buf[i] = moreEntries;
1313 moreEntries = getchar();
1317 i = parse_vlv( strdup( buf ));
1319 return EXIT_FAILURE;
1321 vlvInfo.ldvlv_attrvalue = NULL;
1322 vlvInfo.ldvlv_count = vlvCount;
1323 vlvInfo.ldvlv_offset += vlvInfo.ldvlv_after_count;
1326 if ( vlvInfo.ldvlv_context )
1327 ber_bvfree( vlvInfo.ldvlv_context );
1328 vlvInfo.ldvlv_context = vlvContext;
1335 if ( base != NULL ) {
1336 ber_memfree( base );
1338 if ( control != NULL ) {
1339 ber_memfree( control );
1341 if ( sss_keys != NULL ) {
1342 ldap_free_sort_keylist( sss_keys );
1344 if ( derefval.bv_val != NULL ) {
1345 ldap_memfree( derefval.bv_val );
1347 if ( def_urlpre != NULL ) {
1348 ber_memfree( def_urlpre );
1352 for ( ; save_nctrls-- > 0; ) {
1353 ber_memfree( c[ save_nctrls ].ldctl_value.bv_val );
1363 static int dosearch(
1371 LDAPControl **sctrls,
1372 LDAPControl **cctrls,
1373 struct timeval *timeout,
1383 LDAPMessage *res, *msg;
1385 char *retoid = NULL;
1386 struct berval *retdata = NULL;
1387 int nresponses_psearch = -1;
1388 int cancel_msgid = -1;
1390 if( filtpatt != NULL ) {
1391 size_t max_fsize = strlen( filtpatt ) + strlen( value ) + 1, outlen;
1392 filter = malloc( max_fsize );
1393 if( filter == NULL ) {
1395 return EXIT_FAILURE;
1398 outlen = snprintf( filter, max_fsize, filtpatt, value );
1399 if( outlen >= max_fsize ) {
1400 fprintf( stderr, "Bad filter pattern: \"%s\"\n", filtpatt );
1402 return EXIT_FAILURE;
1406 fprintf( stderr, _("filter: %s\n"), filter );
1410 printf( _("#\n# filter: %s\n#\n"), filter );
1418 if ( filtpatt != NULL ) {
1421 return LDAP_SUCCESS;
1424 rc = ldap_search_ext( ld, base, scope, filter, attrs, attrsonly,
1425 sctrls, cctrls, timeout, sizelimit, &msgid );
1427 if ( filtpatt != NULL ) {
1431 if( rc != LDAP_SUCCESS ) {
1432 fprintf( stderr, _("%s: ldap_search_ext: %s (%d)\n"),
1433 prog, ldap_err2string( rc ), rc );
1437 nresponses = nentries = nreferences = nextended = npartial = 0;
1441 while ((rc = ldap_result( ld, LDAP_RES_ANY,
1442 sortattr ? LDAP_MSG_ALL : LDAP_MSG_ONE,
1445 rc = tool_check_abandon( ld, msgid );
1451 (void) ldap_sort_entries( ld, &res,
1452 ( *sortattr == '\0' ) ? NULL : sortattr, strcasecmp );
1455 for ( msg = ldap_first_message( ld, res );
1457 msg = ldap_next_message( ld, msg ) )
1459 if ( nresponses++ ) putchar('\n');
1460 if ( nresponses_psearch >= 0 )
1461 nresponses_psearch++;
1463 switch( ldap_msgtype( msg ) ) {
1464 case LDAP_RES_SEARCH_ENTRY:
1466 print_entry( ld, msg, attrsonly );
1469 case LDAP_RES_SEARCH_REFERENCE:
1471 print_reference( ld, msg );
1474 case LDAP_RES_EXTENDED:
1476 print_extended( ld, msg );
1478 if ( ldap_msgid( msg ) == 0 ) {
1479 /* unsolicited extended operation */
1483 if ( cancel_msgid != -1 &&
1484 cancel_msgid == ldap_msgid( msg ) ) {
1485 printf(_("Cancelled \n"));
1486 printf(_("cancel_msgid = %d\n"), cancel_msgid);
1491 case LDAP_RES_SEARCH_RESULT:
1492 /* pagedResults stuff is dealt with
1493 * in tool_print_ctrls(), called by
1494 * print_results(). */
1495 rc = print_result( ld, msg, 1 );
1496 if ( ldapsync == LDAP_SYNC_REFRESH_AND_PERSIST ) {
1502 case LDAP_RES_INTERMEDIATE:
1504 ldap_parse_intermediate( ld, msg,
1505 &retoid, &retdata, NULL, 0 );
1507 nresponses_psearch = 0;
1509 if ( strcmp( retoid, LDAP_SYNC_INFO ) == 0 ) {
1510 printf(_("SyncInfo Received\n"));
1511 ldap_memfree( retoid );
1512 ber_bvfree( retdata );
1516 print_partial( ld, msg );
1517 ldap_memfree( retoid );
1518 ber_bvfree( retdata );
1522 if ( ldapsync && sync_slimit != -1 &&
1523 nresponses_psearch >= sync_slimit ) {
1524 BerElement *msgidber = NULL;
1525 struct berval *msgidvalp = NULL;
1526 msgidber = ber_alloc_t(LBER_USE_DER);
1527 ber_printf(msgidber, "{i}", msgid);
1528 ber_flatten(msgidber, &msgidvalp);
1529 ldap_extended_operation(ld, LDAP_EXOP_CANCEL,
1530 msgidvalp, NULL, NULL, &cancel_msgid);
1531 nresponses_psearch = -1;
1535 ldap_msgfree( res );
1540 tool_perror( "ldap_result", rc, NULL, NULL, NULL, NULL );
1544 ldap_msgfree( res );
1546 if ( pagedResults ) {
1547 npagedresponses += nresponses;
1548 npagedentries += nentries;
1549 npagedextended += nextended;
1550 npagedpartial += npartial;
1551 npagedreferences += nreferences;
1552 if ( ( pr_morePagedResults == 0 ) && ( ldif < 2 ) ) {
1553 printf( _("\n# numResponses: %d\n"), npagedresponses );
1554 if( npagedentries ) {
1555 printf( _("# numEntries: %d\n"), npagedentries );
1557 if( npagedextended ) {
1558 printf( _("# numExtended: %d\n"), npagedextended );
1560 if( npagedpartial ) {
1561 printf( _("# numPartial: %d\n"), npagedpartial );
1563 if( npagedreferences ) {
1564 printf( _("# numReferences: %d\n"), npagedreferences );
1567 } else if ( ldif < 2 ) {
1568 printf( _("\n# numResponses: %d\n"), nresponses );
1569 if( nentries ) printf( _("# numEntries: %d\n"), nentries );
1570 if( nextended ) printf( _("# numExtended: %d\n"), nextended );
1571 if( npartial ) printf( _("# numPartial: %d\n"), npartial );
1572 if( nreferences ) printf( _("# numReferences: %d\n"), nreferences );
1578 /* This is the proposed new way of doing things.
1579 * It is more efficient, but the API is non-standard.
1588 char tmpfname[ 256 ];
1591 BerElement *ber = NULL;
1592 struct berval bv, *bvals, **bvp = &bvals;
1593 LDAPControl **ctrls = NULL;
1596 rc = ldap_get_dn_ber( ld, entry, &ber, &bv );
1599 ufn = ldap_dn2ufn( bv.bv_val );
1600 tool_write_ldif( LDIF_PUT_COMMENT, NULL, ufn, ufn ? strlen( ufn ) : 0 );
1602 tool_write_ldif( LDIF_PUT_VALUE, "dn", bv.bv_val, bv.bv_len );
1604 rc = ldap_get_entry_controls( ld, entry, &ctrls );
1605 if( rc != LDAP_SUCCESS ) {
1606 fprintf(stderr, _("print_entry: %d\n"), rc );
1607 tool_perror( "ldap_get_entry_controls", rc, NULL, NULL, NULL, NULL );
1608 exit( EXIT_FAILURE );
1612 tool_print_ctrls( ld, ctrls );
1613 ldap_controls_free( ctrls );
1618 ufn = ldap_dn2ufn( bv.bv_val );
1620 tool_write_ldif( LDIF_PUT_VALUE, "ufn", ufn, ufn ? strlen( ufn ) : 0 );
1623 if( ufn != NULL ) ldap_memfree( ufn );
1625 if ( attrsonly ) bvp = NULL;
1627 for ( rc = ldap_get_attribute_ber( ld, entry, ber, &bv, bvp );
1629 rc = ldap_get_attribute_ber( ld, entry, ber, &bv, bvp ) )
1631 if (bv.bv_val == NULL) break;
1634 tool_write_ldif( LDIF_PUT_NOVALUE, bv.bv_val, NULL, 0 );
1636 } else if ( bvals ) {
1637 for ( i = 0; bvals[i].bv_val != NULL; i++ ) {
1638 if ( vals2tmp > 1 || ( vals2tmp &&
1639 ldif_is_not_printable( bvals[i].bv_val, bvals[i].bv_len )))
1642 /* write value to file */
1643 snprintf( tmpfname, sizeof tmpfname,
1644 "%s" LDAP_DIRSEP "ldapsearch-%s-XXXXXX",
1645 tmpdir, bv.bv_val );
1648 tmpfd = mkstemp( tmpfname );
1655 if (( tmpfp = fdopen( tmpfd, "w")) == NULL ) {
1660 if ( fwrite( bvals[ i ].bv_val,
1661 bvals[ i ].bv_len, 1, tmpfp ) == 0 )
1670 snprintf( url, sizeof url, "%s%s", urlpre,
1671 &tmpfname[strlen(tmpdir) + sizeof(LDAP_DIRSEP) - 1] );
1674 tool_write_ldif( LDIF_PUT_URL, bv.bv_val, url, strlen( url ));
1677 tool_write_ldif( LDIF_PUT_VALUE, bv.bv_val,
1678 bvals[ i ].bv_val, bvals[ i ].bv_len );
1681 ber_memfree( bvals );
1690 static void print_reference(
1692 LDAPMessage *reference )
1696 LDAPControl **ctrls;
1699 printf(_("# search reference\n"));
1702 rc = ldap_parse_reference( ld, reference, &refs, &ctrls, 0 );
1704 if( rc != LDAP_SUCCESS ) {
1705 tool_perror( "ldap_parse_reference", rc, NULL, NULL, NULL, NULL );
1706 exit( EXIT_FAILURE );
1711 for( i=0; refs[i] != NULL; i++ ) {
1712 tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
1713 "ref", refs[i], strlen(refs[i]) );
1715 ber_memvfree( (void **) refs );
1719 tool_print_ctrls( ld, ctrls );
1720 ldap_controls_free( ctrls );
1724 static void print_extended(
1726 LDAPMessage *extended )
1729 char *retoid = NULL;
1730 struct berval *retdata = NULL;
1733 printf(_("# extended result response\n"));
1736 rc = ldap_parse_extended_result( ld, extended,
1737 &retoid, &retdata, 0 );
1739 if( rc != LDAP_SUCCESS ) {
1740 tool_perror( "ldap_parse_extended_result", rc, NULL, NULL, NULL, NULL );
1741 exit( EXIT_FAILURE );
1745 tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
1746 "extended", retoid, retoid ? strlen(retoid) : 0 );
1748 ber_memfree( retoid );
1752 tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_BINARY,
1753 "data", retdata->bv_val, retdata->bv_len );
1755 ber_bvfree( retdata );
1758 print_result( ld, extended, 0 );
1761 static void print_partial(
1763 LDAPMessage *partial )
1766 char *retoid = NULL;
1767 struct berval *retdata = NULL;
1768 LDAPControl **ctrls = NULL;
1771 printf(_("# extended partial response\n"));
1774 rc = ldap_parse_intermediate( ld, partial,
1775 &retoid, &retdata, &ctrls, 0 );
1777 if( rc != LDAP_SUCCESS ) {
1778 tool_perror( "ldap_parse_intermediate", rc, NULL, NULL, NULL, NULL );
1779 exit( EXIT_FAILURE );
1783 tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
1784 "partial", retoid, retoid ? strlen(retoid) : 0 );
1787 ber_memfree( retoid );
1791 tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_BINARY,
1792 "data", retdata->bv_val, retdata->bv_len );
1795 ber_bvfree( retdata );
1799 tool_print_ctrls( ld, ctrls );
1800 ldap_controls_free( ctrls );
1804 static int print_result(
1806 LDAPMessage *result, int search )
1810 char *matcheddn = NULL;
1813 LDAPControl **ctrls = NULL;
1817 printf(_("# search result\n"));
1820 printf("%s: %d\n", _("search"), ldap_msgid(result) );
1824 rc = ldap_parse_result( ld, result,
1825 &err, &matcheddn, &text, &refs, &ctrls, 0 );
1827 if( rc != LDAP_SUCCESS ) {
1828 tool_perror( "ldap_parse_result", rc, NULL, NULL, NULL, NULL );
1829 exit( EXIT_FAILURE );
1834 printf( _("result: %d %s\n"), err, ldap_err2string(err) );
1836 } else if ( err != LDAP_SUCCESS ) {
1837 fprintf( stderr, "%s (%d)\n", ldap_err2string(err), err );
1843 tool_write_ldif( LDIF_PUT_VALUE,
1844 "matchedDN", matcheddn, strlen(matcheddn) );
1846 fprintf( stderr, _("Matched DN: %s\n"), matcheddn );
1850 ber_memfree( matcheddn );
1856 if ( err == LDAP_PARTIAL_RESULTS ) {
1859 for ( line = text; line != NULL; ) {
1860 char *next = strchr( line, '\n' );
1862 tool_write_ldif( LDIF_PUT_TEXT,
1864 next ? (size_t) (next - line) : strlen( line ));
1866 line = next ? next + 1 : NULL;
1870 tool_write_ldif( LDIF_PUT_TEXT, "text",
1871 text, strlen(text) );
1874 fprintf( stderr, _("Additional information: %s\n"), text );
1878 ber_memfree( text );
1883 for( i=0; refs[i] != NULL; i++ ) {
1885 tool_write_ldif( LDIF_PUT_VALUE, "ref", refs[i], strlen(refs[i]) );
1887 fprintf( stderr, _("Referral: %s\n"), refs[i] );
1891 ber_memvfree( (void **) refs );
1894 pr_morePagedResults = 0;
1897 tool_print_ctrls( ld, ctrls );
1898 ldap_controls_free( ctrls );