1 /* ldapsearch -- a tool for searching LDAP directories */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2009 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, _(" -E [!]<ext>[=<extparam>] search extensions (! indicates criticality)\n"));
127 fprintf( stderr, _(" [!]domainScope (domain scope)\n"));
128 fprintf( stderr, _(" !dontUseCopy (Don't Use Copy)\n"));
129 fprintf( stderr, _(" [!]mv=<filter> (RFC 3876 matched values filter)\n"));
130 fprintf( stderr, _(" [!]pr=<size>[/prompt|noprompt] (RFC 2696 paged results/prompt)\n"));
131 fprintf( stderr, _(" [!]sss=[-]<attr[:OID]>[/[-]<attr[:OID]>...]\n"));
132 fprintf( stderr, _(" (RFC 2891 server side sorting)\n"));
133 fprintf( stderr, _(" [!]subentries[=true|false] (RFC 3672 subentries)\n"));
134 fprintf( stderr, _(" [!]sync=ro[/<cookie>] (RFC 4533 LDAP Sync refreshOnly)\n"));
135 fprintf( stderr, _(" rp[/<cookie>][/<slimit>] (refreshAndPersist)\n"));
136 fprintf( stderr, _(" [!]vlv=<before>/<after>(/<offset>/<count>|:<value>)\n"));
137 fprintf( stderr, _(" (ldapv3-vlv-09 virtual list views)\n"));
138 #ifdef LDAP_CONTROL_X_DEREF
139 fprintf( stderr, _(" [!]deref=derefAttr:attr[,...][;derefAttr:attr[,...][;...]]\n"));
141 fprintf( stderr, _(" [!]<oid>=:<value> (generic control; no response handling)\n"));
142 fprintf( stderr, _(" -F prefix URL prefix for files (default: %s)\n"), def_urlpre);
143 fprintf( stderr, _(" -l limit time limit (in seconds, or \"none\" or \"max\") for search\n"));
144 fprintf( stderr, _(" -L print responses in LDIFv1 format\n"));
145 fprintf( stderr, _(" -LL print responses in LDIF format without comments\n"));
146 fprintf( stderr, _(" -LLL print responses in LDIF format without comments\n"));
147 fprintf( stderr, _(" and version\n"));
148 fprintf( stderr, _(" -s scope one of base, one, sub or children (search scope)\n"));
149 fprintf( stderr, _(" -S attr sort the results by attribute `attr'\n"));
150 fprintf( stderr, _(" -t write binary values to files in temporary directory\n"));
151 fprintf( stderr, _(" -tt write all values to files in temporary directory\n"));
152 fprintf( stderr, _(" -T path write files to directory specified by path (default: %s)\n"), def_tmpdir);
153 fprintf( stderr, _(" -u include User Friendly entry names in the output\n"));
154 fprintf( stderr, _(" -z limit size limit (in entries, or \"none\" or \"max\") for search\n"));
156 exit( EXIT_FAILURE );
159 static void print_entry LDAP_P((
164 static void print_reference(
166 LDAPMessage *reference );
168 static void print_extended(
170 LDAPMessage *extended );
172 static void print_partial(
174 LDAPMessage *partial );
176 static int print_result(
181 static int dosearch LDAP_P((
189 LDAPControl **sctrls,
190 LDAPControl **cctrls,
191 struct timeval *timeout,
194 static char *tmpdir = NULL;
195 static char *urlpre = NULL;
196 static char *base = NULL;
197 static char *sortattr = NULL;
198 static int includeufn, vals2tmp = 0;
200 static int subentries = 0, valuesReturnFilter = 0;
201 static char *vrFilter = NULL;
203 #ifdef LDAP_CONTROL_DONTUSECOPY
204 static int dontUseCopy = 0;
207 static int domainScope = 0;
210 static LDAPSortKey **sss_keys = NULL;
213 static LDAPVLVInfo vlvInfo;
214 static struct berval vlvValue;
216 static int ldapsync = 0;
217 static struct berval sync_cookie = { 0, NULL };
218 static int sync_slimit = -1;
220 /* cookie and morePagedResults moved to common.c */
221 static int pagedResults = 0;
222 static int pagePrompt = 1;
223 static ber_int_t pageSize = 0;
224 static ber_int_t entriesLeft = 0;
225 static int npagedresponses;
226 static int npagedentries;
227 static int npagedreferences;
228 static int npagedextended;
229 static int npagedpartial;
231 static LDAPControl *c = NULL;
232 static int nctrls = 0;
233 static int save_nctrls = 0;
235 #ifdef LDAP_CONTROL_X_DEREF
236 static int derefcrit;
237 static LDAPDerefSpec *ds;
238 static struct berval derefval;
247 tmpc = realloc( c, sizeof( LDAPControl ) * nctrls );
248 if ( tmpc == NULL ) {
251 _("unable to make room for control; out of memory?\n"));
264 if (*LDAP_DIRSEP != '/') {
265 for (p = url; *p; p++) {
266 if (*p == *LDAP_DIRSEP)
273 parse_vlv(char *cvalue)
279 if ( sscanf( keyp, "%d/%d", &num1, &num2 ) != 2 ) {
281 _("VLV control value \"%s\" invalid\n"),
285 vlvInfo.ldvlv_before_count = num1;
286 vlvInfo.ldvlv_after_count = num2;
287 keyp = strchr( keyp, '/' ) + 1;
288 key2 = strchr( keyp, '/' );
291 if ( sscanf( keyp, "%d/%d", &num1, &num2 ) != 2 ) {
293 _("VLV control value \"%s\" invalid\n"),
297 vlvInfo.ldvlv_offset = num1;
298 vlvInfo.ldvlv_count = num2;
299 vlvInfo.ldvlv_attrvalue = NULL;
301 key2 = strchr( keyp, ':' );
304 _("VLV control value \"%s\" invalid\n"),
308 ber_str2bv( key2+1, 0, 0, &vlvValue );
309 vlvInfo.ldvlv_attrvalue = &vlvValue;
314 const char options[] = "a:Ab:cE:F:l:Ls:S:tT:uz:"
315 "Cd:D:e:f:h:H:IMnNO:o:p:P:QR:U:vVw:WxX:y:Y:Z";
318 handle_private_option( int i )
323 case 'a': /* set alias deref option */
324 if ( strcasecmp( optarg, "never" ) == 0 ) {
325 deref = LDAP_DEREF_NEVER;
326 } else if ( strncasecmp( optarg, "search", sizeof("search")-1 ) == 0 ) {
327 deref = LDAP_DEREF_SEARCHING;
328 } else if ( strncasecmp( optarg, "find", sizeof("find")-1 ) == 0 ) {
329 deref = LDAP_DEREF_FINDING;
330 } else if ( strcasecmp( optarg, "always" ) == 0 ) {
331 deref = LDAP_DEREF_ALWAYS;
334 _("alias deref should be never, search, find, or always\n") );
338 case 'A': /* retrieve attribute names only -- no values */
341 case 'b': /* search base */
342 base = ber_strdup( optarg );
344 case 'E': /* search extensions */
345 if( protocol == LDAP_VERSION2 ) {
346 fprintf( stderr, _("%s: -E incompatible with LDAPv%d\n"),
348 exit( EXIT_FAILURE );
351 /* should be extended to support comma separated list of
352 * [!]key[=value] parameters, e.g. -E !foo,bar=567
357 while ( optarg[0] == '!' ) {
362 control = ber_strdup( optarg );
363 if ( (cvalue = strchr( control, '=' )) != NULL ) {
367 if ( strcasecmp( control, "mv" ) == 0 ) {
368 /* ValuesReturnFilter control */
369 if( valuesReturnFilter ) {
371 _("ValuesReturnFilter previously specified\n"));
372 exit( EXIT_FAILURE );
374 valuesReturnFilter= 1 + crit;
376 if ( cvalue == NULL ) {
378 _("missing filter in ValuesReturnFilter control\n"));
379 exit( EXIT_FAILURE );
383 protocol = LDAP_VERSION3;
385 } else if ( strcasecmp( control, "pr" ) == 0 ) {
387 /* PagedResults control */
388 if ( pagedResults != 0 ) {
390 _("PagedResultsControl previously specified\n") );
391 exit( EXIT_FAILURE );
395 _("PagedResultsControl incompatible with VLV\n") );
396 exit( EXIT_FAILURE );
399 if( cvalue != NULL ) {
402 promptp = strchr( cvalue, '/' );
403 if ( promptp != NULL ) {
405 if ( strcasecmp( promptp, "prompt" ) == 0 ) {
407 } else if ( strcasecmp( promptp, "noprompt" ) == 0) {
411 _("Invalid value for PagedResultsControl,"
412 " %s/%s.\n"), cvalue, promptp );
413 exit( EXIT_FAILURE );
416 num = sscanf( cvalue, "%d", &tmp );
419 _("Invalid value for PagedResultsControl, %s.\n"),
421 exit( EXIT_FAILURE );
424 fprintf(stderr, _("Invalid value for PagedResultsControl.\n"));
425 exit( EXIT_FAILURE );
427 pageSize = (ber_int_t) tmp;
428 pagedResults = 1 + crit;
430 #ifdef LDAP_CONTROL_DONTUSECOPY
431 } else if ( strcasecmp( control, "dontUseCopy" ) == 0 ) {
434 _("dontUseCopy control previously specified\n"));
435 exit( EXIT_FAILURE );
437 if( cvalue != NULL ) {
439 _("dontUseCopy: no control value expected\n") );
444 _("dontUseCopy: critical flag required\n") );
448 dontUseCopy = 1 + crit;
450 } else if ( strcasecmp( control, "domainScope" ) == 0 ) {
453 _("domainScope control previously specified\n"));
454 exit( EXIT_FAILURE );
456 if( cvalue != NULL ) {
458 _("domainScope: no control value expected\n") );
462 domainScope = 1 + crit;
464 } else if ( strcasecmp( control, "sss" ) == 0 ) {
468 _("server side sorting control previously specified\n"));
469 exit( EXIT_FAILURE );
471 if( cvalue == NULL ) {
473 _("missing specification of sss control\n") );
474 exit( EXIT_FAILURE );
477 while ( ( keyp = strchr(keyp, '/') ) != NULL ) {
480 if ( ldap_create_sort_keylist( &sss_keys, cvalue )) {
482 _("server side sorting control value \"%s\" invalid\n"),
484 exit( EXIT_FAILURE );
489 } else if ( strcasecmp( control, "subentries" ) == 0 ) {
492 _("subentries control previously specified\n"));
493 exit( EXIT_FAILURE );
495 if( cvalue == NULL || strcasecmp( cvalue, "true") == 0 ) {
497 } else if ( strcasecmp( cvalue, "false") == 0 ) {
501 _("subentries control value \"%s\" invalid\n"),
503 exit( EXIT_FAILURE );
505 if( crit ) subentries *= -1;
507 } else if ( strcasecmp( control, "sync" ) == 0 ) {
511 fprintf( stderr, _("sync control previously specified\n") );
512 exit( EXIT_FAILURE );
514 if ( cvalue == NULL ) {
515 fprintf( stderr, _("missing specification of sync control\n"));
516 exit( EXIT_FAILURE );
518 if ( strncasecmp( cvalue, "ro", 2 ) == 0 ) {
519 ldapsync = LDAP_SYNC_REFRESH_ONLY;
520 cookiep = strchr( cvalue, '/' );
521 if ( cookiep != NULL ) {
523 if ( *cookiep != '\0' ) {
524 ber_str2bv( cookiep, 0, 0, &sync_cookie );
527 } else if ( strncasecmp( cvalue, "rp", 2 ) == 0 ) {
528 ldapsync = LDAP_SYNC_REFRESH_AND_PERSIST;
529 cookiep = strchr( cvalue, '/' );
530 if ( cookiep != NULL ) {
534 slimitp = strchr( cvalue, '/' );
535 if ( slimitp != NULL ) {
538 if ( cookiep != NULL && *cookiep != '\0' )
539 ber_str2bv( cookiep, 0, 0, &sync_cookie );
540 if ( slimitp != NULL && *slimitp != '\0' ) {
541 ival = strtol( slimitp, &next, 10 );
542 if ( next == NULL || next[0] != '\0' ) {
543 fprintf( stderr, _("Unable to parse sync control value \"%s\"\n"), slimitp );
544 exit( EXIT_FAILURE );
549 fprintf( stderr, _("sync control value \"%s\" invalid\n"),
551 exit( EXIT_FAILURE );
553 if ( crit ) ldapsync *= -1;
555 } else if ( strcasecmp( control, "vlv" ) == 0 ) {
558 _("virtual list view control previously specified\n"));
559 exit( EXIT_FAILURE );
561 if ( pagedResults != 0 ) {
563 _("PagedResultsControl incompatible with VLV\n") );
564 exit( EXIT_FAILURE );
566 if( cvalue == NULL ) {
568 _("missing specification of vlv control\n") );
569 exit( EXIT_FAILURE );
571 if ( parse_vlv( cvalue ))
572 exit( EXIT_FAILURE );
576 #ifdef LDAP_CONTROL_X_DEREF
577 } else if ( strcasecmp( control, "deref" ) == 0 ) {
581 /* cvalue is something like
583 * derefAttr:attr[,attr[...]][;derefAttr:attr[,attr[...]]]"
586 specs = ldap_str2charray( cvalue, ";" );
587 if ( specs == NULL ) {
588 fprintf( stderr, _("deref specs \"%s\" invalid\n"),
590 exit( EXIT_FAILURE );
592 for ( ispecs = 0; specs[ ispecs ] != NULL; ispecs++ )
595 ds = ldap_memcalloc( ispecs + 1, sizeof( LDAPDerefSpec ) );
598 exit( EXIT_FAILURE );
601 for ( ispecs = 0; specs[ ispecs ] != NULL; ispecs++ ) {
604 ptr = strchr( specs[ ispecs ], ':' );
606 fprintf( stderr, _("deref specs \"%s\" invalid\n"),
608 exit( EXIT_FAILURE );
611 ds[ ispecs ].derefAttr = specs[ ispecs ];
613 ds[ ispecs ].attributes = ldap_str2charray( ptr, "," );
616 derefcrit = 1 + crit;
618 ldap_memfree( specs );
619 #endif /* LDAP_CONTROL_X_DEREF */
621 } else if ( tool_is_oid( control ) ) {
624 for ( i = 0; c[ i ].ldctl_oid != NULL; i++ ) {
625 if ( strcmp( control, c[ i ].ldctl_oid ) == 0 ) {
626 fprintf( stderr, "%s control previously specified\n", control );
627 exit( EXIT_FAILURE );
633 exit( EXIT_FAILURE );
637 c[ nctrls - 1 ].ldctl_oid = control;
640 if ( cvalue == NULL ) {
641 c[ nctrls - 1 ].ldctl_value.bv_val = NULL;
642 c[ nctrls - 1 ].ldctl_value.bv_len = 0;
644 } else if ( cvalue[ 0 ] == ':' ) {
652 * to use ldif_parse_line2() */
654 ldif_parse_line2( &cvalue[ -2 ], &type,
659 c[ nctrls - 1 ].ldctl_value = value;
662 ber_dupbv( &c[ nctrls - 1 ].ldctl_value, &value );
667 c[ nctrls - 1 ].ldctl_iscritical = crit;
670 fprintf( stderr, _("Invalid search extension name: %s\n"),
675 case 'F': /* uri prefix */
676 if( urlpre ) free( urlpre );
677 urlpre = strdup( optarg );
679 case 'l': /* time limit */
680 if ( strcasecmp( optarg, "none" ) == 0 ) {
683 } else if ( strcasecmp( optarg, "max" ) == 0 ) {
684 timelimit = LDAP_MAXINT;
687 ival = strtol( optarg, &next, 10 );
688 if ( next == NULL || next[0] != '\0' ) {
690 _("Unable to parse time limit \"%s\"\n"), optarg );
691 exit( EXIT_FAILURE );
695 if( timelimit < 0 || timelimit > LDAP_MAXINT ) {
696 fprintf( stderr, _("%s: invalid timelimit (%d) specified\n"),
698 exit( EXIT_FAILURE );
701 case 'L': /* print entries in LDIF format */
704 case 's': /* search scope */
705 if ( strncasecmp( optarg, "base", sizeof("base")-1 ) == 0 ) {
706 scope = LDAP_SCOPE_BASE;
707 } else if ( strncasecmp( optarg, "one", sizeof("one")-1 ) == 0 ) {
708 scope = LDAP_SCOPE_ONELEVEL;
709 } else if (( strcasecmp( optarg, "subordinate" ) == 0 )
710 || ( strcasecmp( optarg, "children" ) == 0 ))
712 scope = LDAP_SCOPE_SUBORDINATE;
713 } else if ( strncasecmp( optarg, "sub", sizeof("sub")-1 ) == 0 ) {
714 scope = LDAP_SCOPE_SUBTREE;
716 fprintf( stderr, _("scope should be base, one, or sub\n") );
720 case 'S': /* sort attribute */
721 sortattr = strdup( optarg );
723 case 't': /* write attribute values to TMPDIR files */
726 case 'T': /* tmpdir */
727 if( tmpdir ) free( tmpdir );
728 tmpdir = strdup( optarg );
730 case 'u': /* include UFN */
733 case 'z': /* size limit */
734 if ( strcasecmp( optarg, "none" ) == 0 ) {
737 } else if ( strcasecmp( optarg, "max" ) == 0 ) {
738 sizelimit = LDAP_MAXINT;
741 ival = strtol( optarg, &next, 10 );
742 if ( next == NULL || next[0] != '\0' ) {
744 _("Unable to parse size limit \"%s\"\n"), optarg );
745 exit( EXIT_FAILURE );
749 if( sizelimit < 0 || sizelimit > LDAP_MAXINT ) {
750 fprintf( stderr, _("%s: invalid sizelimit (%d) specified\n"),
752 exit( EXIT_FAILURE );
763 private_conn_setup( LDAP *ld )
766 ldap_set_option( ld, LDAP_OPT_DEREF, (void *) &deref )
767 != LDAP_OPT_SUCCESS )
769 fprintf( stderr, _("Could not set LDAP_OPT_DEREF %d\n"), deref );
770 exit( EXIT_FAILURE );
773 ldap_set_option( ld, LDAP_OPT_TIMELIMIT, (void *) &timelimit )
774 != LDAP_OPT_SUCCESS )
777 _("Could not set LDAP_OPT_TIMELIMIT %d\n"), timelimit );
778 exit( EXIT_FAILURE );
781 ldap_set_option( ld, LDAP_OPT_SIZELIMIT, (void *) &sizelimit )
782 != LDAP_OPT_SUCCESS )
785 _("Could not set LDAP_OPT_SIZELIMIT %d\n"), sizelimit );
786 exit( EXIT_FAILURE );
791 main( int argc, char **argv )
793 char *filtpattern, **attrs = NULL, line[BUFSIZ];
795 int rc, rc1, i, first;
797 BerElement *seber = NULL, *vrber = NULL;
799 BerElement *syncber = NULL;
800 struct berval *syncbvalp = NULL;
803 tool_init( TOOL_SEARCH );
805 npagedresponses = npagedentries = npagedreferences =
806 npagedextended = npagedpartial = 0;
808 prog = lutil_progname( "ldapsearch", argc, argv );
810 if((def_tmpdir = getenv("TMPDIR")) == NULL &&
811 (def_tmpdir = getenv("TMP")) == NULL &&
812 (def_tmpdir = getenv("TEMP")) == NULL )
814 def_tmpdir = LDAP_TMPDIR;
818 def_tmpdir = LDAP_TMPDIR;
820 def_urlpre = malloc( sizeof("file:////") + strlen(def_tmpdir) );
822 if( def_urlpre == NULL ) {
827 sprintf( def_urlpre, "file:///%s/",
828 def_tmpdir[0] == *LDAP_DIRSEP ? &def_tmpdir[1] : def_tmpdir );
830 urlize( def_urlpre );
832 tool_args( argc, argv );
836 _("VLV control requires server side sort control\n" ));
840 if (( argc - optind < 1 ) ||
841 ( *argv[optind] != '(' /*')'*/ &&
842 ( strchr( argv[optind], '=' ) == NULL ) ) )
844 filtpattern = "(objectclass=*)";
846 filtpattern = argv[optind++];
849 if ( argv[optind] != NULL ) {
850 attrs = &argv[optind];
853 if ( infile != NULL ) {
856 if ( infile[0] == '-' && infile[1] == '\0' ) {
858 } else if (( fp = fopen( infile, "r" )) == NULL ) {
863 for( i=0 ; filtpattern[i] ; i++ ) {
864 if( filtpattern[i] == '%' ) {
866 fprintf( stderr, _("Bad filter pattern \"%s\"\n"),
873 if( filtpattern[i+1] != 's' ) {
874 fprintf( stderr, _("Bad filter pattern \"%s\"\n"),
882 if ( tmpdir == NULL ) {
885 if ( urlpre == NULL )
889 if( urlpre == NULL ) {
890 urlpre = malloc( sizeof("file:////") + strlen(tmpdir) );
892 if( urlpre == NULL ) {
897 sprintf( urlpre, "file:///%s/",
898 tmpdir[0] == *LDAP_DIRSEP ? &tmpdir[1] : tmpdir );
906 ld = tool_conn_setup( 0, &private_conn_setup );
908 if ( pw_file || want_bindpw ) {
910 rc = lutil_get_filed_password( pw_file, &passwd );
911 if( rc ) return EXIT_FAILURE;
913 passwd.bv_val = getpassphrase( _("Enter LDAP Password: ") );
914 passwd.bv_len = passwd.bv_val ? strlen( passwd.bv_val ) : 0;
921 save_nctrls = nctrls;
924 #ifdef LDAP_CONTROL_DONTUSECOPY
927 #ifdef LDAP_CONTROL_X_DEREF
935 || valuesReturnFilter
939 #ifdef LDAP_CONTROL_DONTUSECOPY
945 c[i].ldctl_oid = LDAP_CONTROL_DONTUSECOPY;
946 c[i].ldctl_value.bv_val = NULL;
947 c[i].ldctl_value.bv_len = 0;
948 c[i].ldctl_iscritical = dontUseCopy == 2;
958 c[i].ldctl_oid = LDAP_CONTROL_X_DOMAIN_SCOPE;
959 c[i].ldctl_value.bv_val = NULL;
960 c[i].ldctl_value.bv_len = 0;
961 c[i].ldctl_iscritical = domainScope > 1;
970 if (( seber = ber_alloc_t(LBER_USE_DER)) == NULL ) {
974 err = ber_printf( seber, "b", abs(subentries) == 1 ? 0 : 1 );
976 ber_free( seber, 1 );
977 fprintf( stderr, _("Subentries control encoding error!\n") );
981 if ( ber_flatten2( seber, &c[i].ldctl_value, 0 ) == -1 ) {
985 c[i].ldctl_oid = LDAP_CONTROL_SUBENTRIES;
986 c[i].ldctl_iscritical = subentries < 1;
995 if (( syncber = ber_alloc_t(LBER_USE_DER)) == NULL ) {
999 if ( sync_cookie.bv_len == 0 ) {
1000 err = ber_printf( syncber, "{e}", abs(ldapsync) );
1002 err = ber_printf( syncber, "{eO}", abs(ldapsync),
1007 ber_free( syncber, 1 );
1008 fprintf( stderr, _("ldap sync control encoding error!\n") );
1009 return EXIT_FAILURE;
1012 if ( ber_flatten( syncber, &syncbvalp ) == -1 ) {
1013 return EXIT_FAILURE;
1016 c[i].ldctl_oid = LDAP_CONTROL_SYNC;
1017 c[i].ldctl_value = (*syncbvalp);
1018 c[i].ldctl_iscritical = ldapsync < 0;
1022 if ( valuesReturnFilter ) {
1024 return EXIT_FAILURE;
1027 if (( vrber = ber_alloc_t(LBER_USE_DER)) == NULL ) {
1028 return EXIT_FAILURE;
1031 if ( ( err = ldap_put_vrFilter( vrber, vrFilter ) ) == -1 ) {
1032 ber_free( vrber, 1 );
1033 fprintf( stderr, _("Bad ValuesReturnFilter: %s\n"), vrFilter );
1034 return EXIT_FAILURE;
1037 if ( ber_flatten2( vrber, &c[i].ldctl_value, 0 ) == -1 ) {
1038 return EXIT_FAILURE;
1041 c[i].ldctl_oid = LDAP_CONTROL_VALUESRETURNFILTER;
1042 c[i].ldctl_iscritical = valuesReturnFilter > 1;
1046 if ( pagedResults ) {
1048 return EXIT_FAILURE;
1051 if ( ldap_create_page_control_value( ld,
1052 pageSize, &pr_cookie, &c[i].ldctl_value ) )
1054 return EXIT_FAILURE;
1057 if ( pr_cookie.bv_val != NULL ) {
1058 ber_memfree( pr_cookie.bv_val );
1059 pr_cookie.bv_val = NULL;
1060 pr_cookie.bv_len = 0;
1063 c[i].ldctl_oid = LDAP_CONTROL_PAGEDRESULTS;
1064 c[i].ldctl_iscritical = pagedResults > 1;
1070 return EXIT_FAILURE;
1073 if ( ldap_create_sort_control_value( ld,
1074 sss_keys, &c[i].ldctl_value ) )
1076 return EXIT_FAILURE;
1079 c[i].ldctl_oid = LDAP_CONTROL_SORTREQUEST;
1080 c[i].ldctl_iscritical = sss > 1;
1086 return EXIT_FAILURE;
1089 if ( ldap_create_vlv_control_value( ld,
1090 &vlvInfo, &c[i].ldctl_value ) )
1092 return EXIT_FAILURE;
1095 c[i].ldctl_oid = LDAP_CONTROL_VLVREQUEST;
1096 c[i].ldctl_iscritical = sss > 1;
1099 #ifdef LDAP_CONTROL_X_DEREF
1101 if ( derefval.bv_val == NULL ) {
1104 assert( ds != NULL );
1106 if ( ldap_create_deref_control_value( ld, ds, &derefval ) != LDAP_SUCCESS ) {
1107 return EXIT_FAILURE;
1110 for ( i = 0; ds[ i ].derefAttr != NULL; i++ ) {
1111 ldap_memfree( ds[ i ].derefAttr );
1112 ldap_charray_free( ds[ i ].attributes );
1119 exit( EXIT_FAILURE );
1122 c[ i ].ldctl_iscritical = derefcrit > 1;
1123 c[ i ].ldctl_oid = LDAP_CONTROL_X_DEREF;
1124 c[ i ].ldctl_value = derefval;
1127 #endif /* LDAP_CONTROL_X_DEREF */
1130 tool_server_controls( ld, c, i );
1132 if ( seber ) ber_free( seber, 1 );
1133 if ( vrber ) ber_free( vrber, 1 );
1135 /* step back to the original number of controls, so that
1136 * those set while parsing args are preserved */
1137 nctrls = save_nctrls;
1140 fprintf( stderr, _("filter%s: %s\nrequesting: "),
1141 infile != NULL ? _(" pattern") : "",
1144 if ( attrs == NULL ) {
1145 fprintf( stderr, _("All userApplication attributes") );
1147 for ( i = 0; attrs[ i ] != NULL; ++i ) {
1148 fprintf( stderr, "%s ", attrs[ i ] );
1151 fprintf( stderr, "\n" );
1155 printf( _("# extended LDIF\n") );
1156 } else if ( ldif < 3 ) {
1157 printf( _("version: %d\n\n"), 1 );
1161 char *realbase = base;
1163 if ( realbase == NULL ) {
1164 ldap_get_option( ld, LDAP_OPT_DEFBASE, (void **)(char *)&realbase );
1168 printf(_("# LDAPv%d\n"), protocol);
1169 printf(_("# base <%s>%s with scope %s\n"),
1170 realbase ? realbase : "",
1171 ( realbase == NULL || realbase != base ) ? " (default)" : "",
1172 ((scope == LDAP_SCOPE_BASE) ? "baseObject"
1173 : ((scope == LDAP_SCOPE_ONELEVEL) ? "oneLevel"
1174 : ((scope == LDAP_SCOPE_SUBORDINATE) ? "children"
1176 printf(_("# filter%s: %s\n"), infile != NULL ? _(" pattern") : "",
1178 printf(_("# requesting: "));
1180 if ( attrs == NULL ) {
1183 for ( i = 0; attrs[ i ] != NULL; ++i ) {
1184 printf( "%s ", attrs[ i ] );
1188 if ( manageDSAit ) {
1189 printf(_("\n# with manageDSAit %scontrol"),
1190 manageDSAit > 1 ? _("critical ") : "" );
1193 printf(_("\n# with noop %scontrol"),
1194 noop > 1 ? _("critical ") : "" );
1197 printf(_("\n# with subentries %scontrol: %s"),
1198 subentries < 0 ? _("critical ") : "",
1199 abs(subentries) == 1 ? "false" : "true" );
1201 if ( valuesReturnFilter ) {
1202 printf(_("\n# with valuesReturnFilter %scontrol: %s"),
1203 valuesReturnFilter > 1 ? _("critical ") : "", vrFilter );
1205 if ( pagedResults ) {
1206 printf(_("\n# with pagedResults %scontrol: size=%d"),
1207 (pagedResults > 1) ? _("critical ") : "",
1211 printf(_("\n# with server side sorting %scontrol"),
1212 sss > 1 ? _("critical ") : "" );
1215 printf(_("\n# with virtual list view %scontrol: %d/%d"),
1216 vlv > 1 ? _("critical ") : "",
1217 vlvInfo.ldvlv_before_count, vlvInfo.ldvlv_after_count);
1218 if ( vlvInfo.ldvlv_attrvalue )
1219 printf(":%s", vlvInfo.ldvlv_attrvalue->bv_val );
1221 printf("/%d/%d", vlvInfo.ldvlv_offset, vlvInfo.ldvlv_count );
1223 #ifdef LDAP_CONTROL_X_DEREF
1225 printf(_("\n# with dereference %scontrol"),
1226 derefcrit > 1 ? _("critical ") : "" );
1230 printf( _("\n#\n\n") );
1232 if ( realbase && realbase != base ) {
1233 ldap_memfree( realbase );
1237 if ( infile == NULL ) {
1238 rc = dosearch( ld, base, scope, NULL, filtpattern,
1239 attrs, attrsonly, NULL, NULL, NULL, -1 );
1244 while ( fgets( line, sizeof( line ), fp ) != NULL ) {
1245 line[ strlen( line ) - 1 ] = '\0';
1251 rc1 = dosearch( ld, base, scope, filtpattern, line,
1252 attrs, attrsonly, NULL, NULL, NULL, -1 );
1260 if ( fp != stdin ) {
1265 if (( rc == LDAP_SUCCESS ) && pageSize && pr_morePagedResults ) {
1267 int i, moreEntries, tmpSize;
1269 /* Loop to get the next pages when
1270 * enter is pressed on the terminal.
1272 if ( pagePrompt != 0 ) {
1273 if ( entriesLeft > 0 ) {
1274 printf( _("Estimate entries: %d\n"), entriesLeft );
1276 printf( _("Press [size] Enter for the next {%d|size} entries.\n"),
1279 moreEntries = getchar();
1280 while ( moreEntries != EOF && moreEntries != '\n' ) {
1281 if ( i < (int)sizeof(buf) - 1 ) {
1282 buf[i] = moreEntries;
1285 moreEntries = getchar();
1289 if ( i > 0 && isdigit( (unsigned char)buf[0] ) ) {
1290 int num = sscanf( buf, "%d", &tmpSize );
1293 _("Invalid value for PagedResultsControl, %s.\n"), buf);
1294 return EXIT_FAILURE;
1297 pageSize = (ber_int_t)tmpSize;
1304 if (( rc == LDAP_SUCCESS ) && vlv ) {
1306 int i, moreEntries, tmpSize;
1308 /* Loop to get the next window when
1309 * enter is pressed on the terminal.
1311 printf( _("Press [before/after(/offset/count|:value)] Enter for the next window.\n"));
1313 moreEntries = getchar();
1314 while ( moreEntries != EOF && moreEntries != '\n' ) {
1315 if ( i < (int)sizeof(buf) - 1 ) {
1316 buf[i] = moreEntries;
1319 moreEntries = getchar();
1323 i = parse_vlv( strdup( buf ));
1325 return EXIT_FAILURE;
1327 vlvInfo.ldvlv_attrvalue = NULL;
1328 vlvInfo.ldvlv_count = vlvCount;
1329 vlvInfo.ldvlv_offset += vlvInfo.ldvlv_after_count;
1332 if ( vlvInfo.ldvlv_context )
1333 ber_bvfree( vlvInfo.ldvlv_context );
1334 vlvInfo.ldvlv_context = vlvContext;
1341 if ( base != NULL ) {
1342 ber_memfree( base );
1344 if ( control != NULL ) {
1345 ber_memfree( control );
1347 if ( sss_keys != NULL ) {
1348 ldap_free_sort_keylist( sss_keys );
1350 if ( derefval.bv_val != NULL ) {
1351 ldap_memfree( derefval.bv_val );
1355 for ( ; save_nctrls-- > 0; ) {
1356 ber_memfree( c[ save_nctrls ].ldctl_value.bv_val );
1366 static int dosearch(
1374 LDAPControl **sctrls,
1375 LDAPControl **cctrls,
1376 struct timeval *timeout,
1386 LDAPMessage *res, *msg;
1388 char *retoid = NULL;
1389 struct berval *retdata = NULL;
1390 int nresponses_psearch = -1;
1391 int cancel_msgid = -1;
1393 if( filtpatt != NULL ) {
1394 size_t max_fsize = strlen( filtpatt ) + strlen( value ) + 1, outlen;
1395 filter = malloc( max_fsize );
1396 if( filter == NULL ) {
1398 return EXIT_FAILURE;
1401 outlen = snprintf( filter, max_fsize, filtpatt, value );
1402 if( outlen >= max_fsize ) {
1403 fprintf( stderr, "Bad filter pattern: \"%s\"\n", filtpatt );
1405 return EXIT_FAILURE;
1409 fprintf( stderr, _("filter: %s\n"), filter );
1413 printf( _("#\n# filter: %s\n#\n"), filter );
1421 if ( filtpatt != NULL ) {
1424 return LDAP_SUCCESS;
1427 rc = ldap_search_ext( ld, base, scope, filter, attrs, attrsonly,
1428 sctrls, cctrls, timeout, sizelimit, &msgid );
1430 if ( filtpatt != NULL ) {
1434 if( rc != LDAP_SUCCESS ) {
1435 fprintf( stderr, _("%s: ldap_search_ext: %s (%d)\n"),
1436 prog, ldap_err2string( rc ), rc );
1440 nresponses = nentries = nreferences = nextended = npartial = 0;
1444 while ((rc = ldap_result( ld, LDAP_RES_ANY,
1445 sortattr ? LDAP_MSG_ALL : LDAP_MSG_ONE,
1448 rc = tool_check_abandon( ld, msgid );
1454 (void) ldap_sort_entries( ld, &res,
1455 ( *sortattr == '\0' ) ? NULL : sortattr, strcasecmp );
1458 for ( msg = ldap_first_message( ld, res );
1460 msg = ldap_next_message( ld, msg ) )
1462 if ( nresponses++ ) putchar('\n');
1463 if ( nresponses_psearch >= 0 )
1464 nresponses_psearch++;
1466 switch( ldap_msgtype( msg ) ) {
1467 case LDAP_RES_SEARCH_ENTRY:
1469 print_entry( ld, msg, attrsonly );
1472 case LDAP_RES_SEARCH_REFERENCE:
1474 print_reference( ld, msg );
1477 case LDAP_RES_EXTENDED:
1479 print_extended( ld, msg );
1481 if ( ldap_msgid( msg ) == 0 ) {
1482 /* unsolicited extended operation */
1486 if ( cancel_msgid != -1 &&
1487 cancel_msgid == ldap_msgid( msg ) ) {
1488 printf(_("Cancelled \n"));
1489 printf(_("cancel_msgid = %d\n"), cancel_msgid);
1494 case LDAP_RES_SEARCH_RESULT:
1495 /* pagedResults stuff is dealt with
1496 * in tool_print_ctrls(), called by
1497 * print_results(). */
1498 rc = print_result( ld, msg, 1 );
1499 if ( ldapsync == LDAP_SYNC_REFRESH_AND_PERSIST ) {
1505 case LDAP_RES_INTERMEDIATE:
1507 ldap_parse_intermediate( ld, msg,
1508 &retoid, &retdata, NULL, 0 );
1510 nresponses_psearch = 0;
1512 if ( strcmp( retoid, LDAP_SYNC_INFO ) == 0 ) {
1513 printf(_("SyncInfo Received\n"));
1514 ldap_memfree( retoid );
1515 ber_bvfree( retdata );
1519 print_partial( ld, msg );
1520 ldap_memfree( retoid );
1521 ber_bvfree( retdata );
1525 if ( ldapsync && sync_slimit != -1 &&
1526 nresponses_psearch >= sync_slimit ) {
1527 BerElement *msgidber = NULL;
1528 struct berval *msgidvalp = NULL;
1529 msgidber = ber_alloc_t(LBER_USE_DER);
1530 ber_printf(msgidber, "{i}", msgid);
1531 ber_flatten(msgidber, &msgidvalp);
1532 ldap_extended_operation(ld, LDAP_EXOP_CANCEL,
1533 msgidvalp, NULL, NULL, &cancel_msgid);
1534 nresponses_psearch = -1;
1538 ldap_msgfree( res );
1543 tool_perror( "ldap_result", rc, NULL, NULL, NULL, NULL );
1547 ldap_msgfree( res );
1549 if ( pagedResults ) {
1550 npagedresponses += nresponses;
1551 npagedentries += nentries;
1552 npagedextended += nextended;
1553 npagedpartial += npartial;
1554 npagedreferences += nreferences;
1555 if ( ( pr_morePagedResults == 0 ) && ( ldif < 2 ) ) {
1556 printf( _("\n# numResponses: %d\n"), npagedresponses );
1557 if( npagedentries ) {
1558 printf( _("# numEntries: %d\n"), npagedentries );
1560 if( npagedextended ) {
1561 printf( _("# numExtended: %d\n"), npagedextended );
1563 if( npagedpartial ) {
1564 printf( _("# numPartial: %d\n"), npagedpartial );
1566 if( npagedreferences ) {
1567 printf( _("# numReferences: %d\n"), npagedreferences );
1570 } else if ( ldif < 2 ) {
1571 printf( _("\n# numResponses: %d\n"), nresponses );
1572 if( nentries ) printf( _("# numEntries: %d\n"), nentries );
1573 if( nextended ) printf( _("# numExtended: %d\n"), nextended );
1574 if( npartial ) printf( _("# numPartial: %d\n"), npartial );
1575 if( nreferences ) printf( _("# numReferences: %d\n"), nreferences );
1581 /* This is the proposed new way of doing things.
1582 * It is more efficient, but the API is non-standard.
1591 char tmpfname[ 256 ];
1594 BerElement *ber = NULL;
1595 struct berval bv, *bvals, **bvp = &bvals;
1596 LDAPControl **ctrls = NULL;
1599 rc = ldap_get_dn_ber( ld, entry, &ber, &bv );
1602 ufn = ldap_dn2ufn( bv.bv_val );
1603 tool_write_ldif( LDIF_PUT_COMMENT, NULL, ufn, ufn ? strlen( ufn ) : 0 );
1605 tool_write_ldif( LDIF_PUT_VALUE, "dn", bv.bv_val, bv.bv_len );
1607 rc = ldap_get_entry_controls( ld, entry, &ctrls );
1608 if( rc != LDAP_SUCCESS ) {
1609 fprintf(stderr, _("print_entry: %d\n"), rc );
1610 tool_perror( "ldap_get_entry_controls", rc, NULL, NULL, NULL, NULL );
1611 exit( EXIT_FAILURE );
1615 tool_print_ctrls( ld, ctrls );
1616 ldap_controls_free( ctrls );
1621 ufn = ldap_dn2ufn( bv.bv_val );
1623 tool_write_ldif( LDIF_PUT_VALUE, "ufn", ufn, ufn ? strlen( ufn ) : 0 );
1626 if( ufn != NULL ) ldap_memfree( ufn );
1628 if ( attrsonly ) bvp = NULL;
1630 for ( rc = ldap_get_attribute_ber( ld, entry, ber, &bv, bvp );
1632 rc = ldap_get_attribute_ber( ld, entry, ber, &bv, bvp ) )
1634 if (bv.bv_val == NULL) break;
1637 tool_write_ldif( LDIF_PUT_NOVALUE, bv.bv_val, NULL, 0 );
1639 } else if ( bvals ) {
1640 for ( i = 0; bvals[i].bv_val != NULL; i++ ) {
1641 if ( vals2tmp > 1 || ( vals2tmp &&
1642 ldif_is_not_printable( bvals[i].bv_val, bvals[i].bv_len )))
1645 /* write value to file */
1646 snprintf( tmpfname, sizeof tmpfname,
1647 "%s" LDAP_DIRSEP "ldapsearch-%s-XXXXXX",
1648 tmpdir, bv.bv_val );
1651 tmpfd = mkstemp( tmpfname );
1658 if (( tmpfp = fdopen( tmpfd, "w")) == NULL ) {
1663 if ( fwrite( bvals[ i ].bv_val,
1664 bvals[ i ].bv_len, 1, tmpfp ) == 0 )
1673 snprintf( url, sizeof url, "%s%s", urlpre,
1674 &tmpfname[strlen(tmpdir) + sizeof(LDAP_DIRSEP) - 1] );
1677 tool_write_ldif( LDIF_PUT_URL, bv.bv_val, url, strlen( url ));
1680 tool_write_ldif( LDIF_PUT_VALUE, bv.bv_val,
1681 bvals[ i ].bv_val, bvals[ i ].bv_len );
1684 ber_memfree( bvals );
1693 static void print_reference(
1695 LDAPMessage *reference )
1699 LDAPControl **ctrls;
1702 printf(_("# search reference\n"));
1705 rc = ldap_parse_reference( ld, reference, &refs, &ctrls, 0 );
1707 if( rc != LDAP_SUCCESS ) {
1708 tool_perror( "ldap_parse_reference", rc, NULL, NULL, NULL, NULL );
1709 exit( EXIT_FAILURE );
1714 for( i=0; refs[i] != NULL; i++ ) {
1715 tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
1716 "ref", refs[i], strlen(refs[i]) );
1718 ber_memvfree( (void **) refs );
1722 tool_print_ctrls( ld, ctrls );
1723 ldap_controls_free( ctrls );
1727 static void print_extended(
1729 LDAPMessage *extended )
1732 char *retoid = NULL;
1733 struct berval *retdata = NULL;
1736 printf(_("# extended result response\n"));
1739 rc = ldap_parse_extended_result( ld, extended,
1740 &retoid, &retdata, 0 );
1742 if( rc != LDAP_SUCCESS ) {
1743 tool_perror( "ldap_parse_extended_result", rc, NULL, NULL, NULL, NULL );
1744 exit( EXIT_FAILURE );
1748 tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
1749 "extended", retoid, retoid ? strlen(retoid) : 0 );
1751 ber_memfree( retoid );
1755 tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_BINARY,
1756 "data", retdata->bv_val, retdata->bv_len );
1758 ber_bvfree( retdata );
1761 print_result( ld, extended, 0 );
1764 static void print_partial(
1766 LDAPMessage *partial )
1769 char *retoid = NULL;
1770 struct berval *retdata = NULL;
1771 LDAPControl **ctrls = NULL;
1774 printf(_("# extended partial response\n"));
1777 rc = ldap_parse_intermediate( ld, partial,
1778 &retoid, &retdata, &ctrls, 0 );
1780 if( rc != LDAP_SUCCESS ) {
1781 tool_perror( "ldap_parse_intermediate", rc, NULL, NULL, NULL, NULL );
1782 exit( EXIT_FAILURE );
1786 tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
1787 "partial", retoid, retoid ? strlen(retoid) : 0 );
1790 ber_memfree( retoid );
1794 tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_BINARY,
1795 "data", retdata->bv_val, retdata->bv_len );
1798 ber_bvfree( retdata );
1802 tool_print_ctrls( ld, ctrls );
1803 ldap_controls_free( ctrls );
1807 static int print_result(
1809 LDAPMessage *result, int search )
1813 char *matcheddn = NULL;
1816 LDAPControl **ctrls = NULL;
1820 printf(_("# search result\n"));
1823 printf("%s: %d\n", _("search"), ldap_msgid(result) );
1827 rc = ldap_parse_result( ld, result,
1828 &err, &matcheddn, &text, &refs, &ctrls, 0 );
1830 if( rc != LDAP_SUCCESS ) {
1831 tool_perror( "ldap_parse_result", rc, NULL, NULL, NULL, NULL );
1832 exit( EXIT_FAILURE );
1837 printf( _("result: %d %s\n"), err, ldap_err2string(err) );
1839 } else if ( err != LDAP_SUCCESS ) {
1840 fprintf( stderr, "%s (%d)\n", ldap_err2string(err), err );
1846 tool_write_ldif( LDIF_PUT_VALUE,
1847 "matchedDN", matcheddn, strlen(matcheddn) );
1849 fprintf( stderr, _("Matched DN: %s\n"), matcheddn );
1853 ber_memfree( matcheddn );
1859 if ( err == LDAP_PARTIAL_RESULTS ) {
1862 for ( line = text; line != NULL; ) {
1863 char *next = strchr( line, '\n' );
1865 tool_write_ldif( LDIF_PUT_TEXT,
1867 next ? (size_t) (next - line) : strlen( line ));
1869 line = next ? next + 1 : NULL;
1873 tool_write_ldif( LDIF_PUT_TEXT, "text",
1874 text, strlen(text) );
1877 fprintf( stderr, _("Additional information: %s\n"), text );
1881 ber_memfree( text );
1886 for( i=0; refs[i] != NULL; i++ ) {
1888 tool_write_ldif( LDIF_PUT_VALUE, "ref", refs[i], strlen(refs[i]) );
1890 fprintf( stderr, _("Referral: %s\n"), refs[i] );
1894 ber_memvfree( (void **) refs );
1897 pr_morePagedResults = 0;
1900 tool_print_ctrls( ld, ctrls );
1901 ldap_controls_free( ctrls );