]> git.sur5r.net Git - openldap/blob - clients/tools/ldapsearch.c
6a3a90d51156ed221279ebad588a0d38314ad6b6
[openldap] / clients / tools / ldapsearch.c
1 /*
2  * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
3  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
4  */
5 #include "portable.h"
6
7 #include <stdio.h>
8
9 #include <ac/stdlib.h>
10
11 #include <ac/ctype.h>
12 #include <ac/signal.h>
13 #include <ac/string.h>
14 #include <ac/unistd.h>
15
16 #include <ldap.h>
17
18 #include "ldif.h"
19 #include "ldap_defaults.h"
20
21 #define DEFSEP          "="
22
23 static void
24 usage( char *s )
25 {
26         fprintf( stderr,
27 "usage: %s [options] filter [attributes...]\nwhere:\n"
28 "       filter\tRFC-1558 compliant LDAP search filter\n"
29 "       attributes\twhitespace-separated list of attributes to retrieve\n"
30 "\t\t1.1                -- no attributes\n"
31 "\t\t*            -- all user attributes\n"
32 "\t\t+            -- all operational attributes\n"
33 "\t\tempty list -- all non-operational attributes\n"
34 "options:\n"
35 "       -n\t\tshow what would be done but don't actually search\n"
36 "       -v\t\trun in verbose mode (diagnostics to standard output)\n"
37 "       -t\t\twrite binary values to files in TMPDIR\n"
38 "       -tt\t\twrite all values to files in TMPDIR\n"
39 "       -T path\twrite files to directory specified by path (default: \"/tmp\")\n"
40 "       -V prefix\tURL prefix for files (default: \"file://tmp/\"\n"
41 "       -u\t\tinclude User Friendly entry names in the output\n"
42 "       -A\t\tretrieve attribute names only (no values)\n"
43 "       -B\t\tdo not suppress printing of binary values\n"
44 "       -F sep\tprint `sep' instead of `=' between attribute names and values\n"
45 "       -L\t\tprint entries in LDIF format (implies -B)\n"
46 "       -LL\t\tprint entries in LDIF format without comments\n"
47 "       -LLL\t\tprint entries in LDIF format without comments and version\n"
48 "       -M\t\tenable Manage DSA IT control (-MM to make critical)\n"
49 "       -R\t\tdo not automatically follow referrals\n"
50 "       -S attr\tsort the results by attribute `attr'\n"
51 "       -d level\tset LDAP debugging level to `level'\n"
52 "       -f file\tperform sequence of searches listed in `file'\n"
53 "       -b basedn\tbase dn for search\n"
54 "       -s scope\tone of base, one, or sub (search scope)\n"
55 "       -a deref\tone of never, always, search, or find (alias dereferencing)\n"
56 "       -l limit\ttime limit (in seconds) for search\n"
57 "       -z limit\tsize limit (in entries) for search\n"
58 "       -D binddn\tbind dn\n"
59 "       -w passwd\tbind passwd (for simple authentication)\n"
60 "       -W\t\tprompt for bind passwd\n"
61 #ifdef HAVE_KERBEROS
62 "       -k\t\tuse Kerberos instead of Simple Password authentication\n"
63 #endif
64 "       -h host\tldap server\n"
65 "       -p port\tport on ldap server\n"
66 "       -P version\tprocotol version (2 or 3)\n"
67 ,               s );
68
69         exit( EXIT_FAILURE );
70 }
71
72 static void print_entry LDAP_P((
73         LDAP    *ld,
74         LDAPMessage     *entry,
75         int             attrsonly));
76
77 static int write_ldif LDAP_P((
78         int type,
79         char *name,
80         char *value,
81         ber_len_t vallen ));
82
83 static int dosearch LDAP_P((
84         LDAP    *ld,
85         char    *base,
86         int             scope,
87         char    **attrs,
88         int             attrsonly,
89         char    *filtpatt,
90         char    *value));
91
92 #define TMPDIR "/tmp"
93 #define URLPRE "file:/tmp/"
94
95 static char *tmpdir = NULL;
96 static char *urlpre = NULL;
97
98 static char     *binddn = NULL;
99 static char     *passwd = NULL;
100 static char     *base = NULL;
101 static char     *ldaphost = NULL;
102 static int      ldapport = 0;
103 static char     *sep = DEFSEP;
104 static char     *sortattr = NULL;
105 static int      skipsortattr = 0;
106 static int      verbose, not, includeufn, binary, vals2tmp, ldif;
107
108 int
109 main( int argc, char **argv )
110 {
111         char            *infile, *filtpattern, **attrs, line[ BUFSIZ ];
112         FILE            *fp;
113         int                     rc, i, first, scope, deref, attrsonly, manageDSAit;
114         int                     referrals, timelimit, sizelimit, debug;
115         int             authmethod, version, want_bindpw;
116         LDAP            *ld;
117
118         infile = NULL;
119         debug = verbose = binary = not = vals2tmp =
120                 attrsonly = manageDSAit = ldif = want_bindpw = 0;
121
122         deref = referrals = sizelimit = timelimit = version = -1;
123
124         scope = LDAP_SCOPE_SUBTREE;
125         authmethod = LDAP_AUTH_SIMPLE;
126
127         while (( i = getopt( argc, argv,
128                 "WKknuvtMRABLD:s:f:h:b:d:P:p:F:a:w:l:z:S:T:V:")) != EOF )
129         {
130         switch( i ) {
131         case 'n':       /* do Not do any searches */
132                 ++not;
133                 break;
134         case 'v':       /* verbose mode */
135                 ++verbose;
136                 break;
137         case 'd':
138                 debug |= atoi( optarg );
139                 break;
140         case 'k':       /* use kerberos bind */
141 #ifdef HAVE_KERBEROS
142                 authmethod = LDAP_AUTH_KRBV4;
143 #else
144                 fprintf (stderr, "%s was not compiled with Kerberos support\n", argv[0]);
145 #endif
146                 break;
147         case 'K':       /* use kerberos bind, 1st part only */
148 #ifdef HAVE_KERBEROS
149                 authmethod = LDAP_AUTH_KRBV41;
150 #else
151                 fprintf (stderr, "%s was not compiled with Kerberos support\n", argv[0]);
152 #endif
153                 break;
154         case 'u':       /* include UFN */
155                 ++includeufn;
156                 break;
157         case 't':       /* write attribute values to /tmp files */
158                 ++vals2tmp;
159                 break;
160         case 'M':
161                 /* enable Manage DSA IT */
162                 manageDSAit++;
163                 break;
164         case 'R':       /* don't automatically chase referrals */
165                 referrals = (int) LDAP_OPT_OFF;
166                 break;
167         case 'A':       /* retrieve attribute names only -- no values */
168                 ++attrsonly;
169                 break;
170         case 'L':       /* print entries in LDIF format */
171                 ++ldif;
172                 /* fall through -- always allow binary when outputting LDIF */
173         case 'B':       /* allow binary values to be printed */
174                 ++binary;
175                 break;
176         case 's':       /* search scope */
177                 if ( strcasecmp( optarg, "base" ) == 0 ) {
178                 scope = LDAP_SCOPE_BASE;
179                 } else if ( strcasecmp( optarg, "one" ) == 0 ) {
180                 scope = LDAP_SCOPE_ONELEVEL;
181                 } else if ( strcasecmp( optarg, "sub" ) == 0 ) {
182                 scope = LDAP_SCOPE_SUBTREE;
183                 } else {
184                 fprintf( stderr, "scope should be base, one, or sub\n" );
185                 usage( argv[ 0 ] );
186                 }
187                 break;
188
189         case 'a':       /* set alias deref option */
190                 if ( strcasecmp( optarg, "never" ) == 0 ) {
191                 deref = LDAP_DEREF_NEVER;
192                 } else if ( strcasecmp( optarg, "search" ) == 0 ) {
193                 deref = LDAP_DEREF_SEARCHING;
194                 } else if ( strcasecmp( optarg, "find" ) == 0 ) {
195                 deref = LDAP_DEREF_FINDING;
196                 } else if ( strcasecmp( optarg, "always" ) == 0 ) {
197                 deref = LDAP_DEREF_ALWAYS;
198                 } else {
199                 fprintf( stderr, "alias deref should be never, search, find, or always\n" );
200                 usage( argv[ 0 ] );
201                 }
202                 break;
203                 
204         case 'T':       /* field separator */
205                 if( tmpdir ) free( tmpdir );
206                 tmpdir = strdup( optarg );
207                 break;
208         case 'V':       /* field separator */
209                 if( urlpre ) free( urlpre );
210                 urlpre = strdup( optarg );
211                 break;
212         case 'F':       /* field separator */
213                 sep = strdup( optarg );
214                 break;
215         case 'f':       /* input file */
216                 infile = strdup( optarg );
217                 break;
218         case 'h':       /* ldap host */
219                 ldaphost = strdup( optarg );
220                 break;
221         case 'b':       /* searchbase */
222                 base = strdup( optarg );
223                 break;
224         case 'D':       /* bind DN */
225                 binddn = strdup( optarg );
226                 break;
227         case 'p':       /* ldap port */
228                 ldapport = atoi( optarg );
229                 break;
230         case 'w':       /* bind password */
231                 passwd = strdup( optarg );
232                 {
233                         char* p;
234
235                         for( p = optarg; *p == '\0'; p++ ) {
236                                 *p = '*';
237                         }
238                 }
239                 break;
240         case 'l':       /* time limit */
241                 timelimit = atoi( optarg );
242                 break;
243         case 'z':       /* size limit */
244                 sizelimit = atoi( optarg );
245                 break;
246         case 'S':       /* sort attribute */
247                 sortattr = strdup( optarg );
248                 break;
249         case 'W':
250                 want_bindpw++;
251                 break;
252         case 'P':
253                 switch( atoi( optarg ) )
254                 {
255                 case 2:
256                         version = LDAP_VERSION2;
257                         break;
258                 case 3:
259                         version = LDAP_VERSION3;
260                         break;
261                 default:
262                         fprintf( stderr, "protocol version should be 2 or 3\n" );
263                         usage( argv[0] );
264                 }
265                 break;
266         default:
267                 usage( argv[0] );
268         }
269         }
270
271         if ( argc - optind < 1 ) {
272                 usage( argv[ 0 ] );
273         }
274
275         filtpattern = strdup( argv[ optind ] );
276
277         if ( argv[ optind + 1 ] == NULL ) {
278                 attrs = NULL;
279         } else if ( sortattr == NULL || *sortattr == '\0' ) {
280                 attrs = &argv[ optind + 1 ];
281         } else {
282                 for ( i = optind + 1; i < argc; i++ ) {
283                         if ( strcasecmp( argv[ i ], sortattr ) == 0 ) {
284                                 break;
285                         }
286                 }
287                 if ( i == argc ) {
288                         skipsortattr = 1;
289                         argv[ optind ] = sortattr;
290                 } else {
291                         optind++;
292                 }
293                 attrs = &argv[ optind ];
294         }
295
296         if ( infile != NULL ) {
297                 if ( infile[0] == '-' && infile[1] == '\0' ) {
298                         fp = stdin;
299                 } else if (( fp = fopen( infile, "r" )) == NULL ) {
300                         perror( infile );
301                         return EXIT_FAILURE;
302                 }
303         }
304
305         if( tmpdir == NULL
306                 && (tmpdir = getenv("TMPDIR")) == NULL
307                 && (tmpdir = getenv("TMP")) == NULL
308                 && (tmpdir = getenv("TEMP")) == NULL )
309         {
310                 tmpdir = "/tmp";
311         }
312
313         if( urlpre == NULL ) {
314                 urlpre = malloc( sizeof("file:///") + strlen(tmpdir) );
315
316                 if( urlpre == NULL ) {
317                         perror( "malloc" );
318                         return EXIT_FAILURE;
319                 }
320
321                 sprintf( urlpre, "file:///%s/",
322                         tmpdir[0] == '/' ? &tmpdir[1] : tmpdir );
323
324                 /* urlpre should be URLized.... */
325         }
326
327         if ( debug ) {
328                 if( ber_set_option( NULL, LBER_OPT_DEBUG_LEVEL, &debug ) != LBER_OPT_SUCCESS ) {
329                         fprintf( stderr, "Could not set LBER_OPT_DEBUG_LEVEL %d\n", debug );
330                 }
331                 if( ldap_set_option( NULL, LDAP_OPT_DEBUG_LEVEL, &debug ) != LDAP_OPT_SUCCESS ) {
332                         fprintf( stderr, "Could not set LDAP_OPT_DEBUG_LEVEL %d\n", debug );
333                 }
334                 ldif_debug = debug;
335         }
336
337 #ifdef SIGPIPE
338         (void) SIGNAL( SIGPIPE, SIG_IGN );
339 #endif
340
341         if ( verbose ) {
342                 fprintf( stderr, "ldap_init( %s, %d )\n",
343                         (ldaphost != NULL) ? ldaphost : "<DEFAULT>",
344                         ldapport );
345         }
346
347         if (( ld = ldap_init( ldaphost, ldapport )) == NULL ) {
348                 perror( "ldap_init" );
349                 return( EXIT_FAILURE );
350         }
351
352         if (deref != -1 &&
353                 ldap_set_option( ld, LDAP_OPT_DEREF, (void *) &deref ) != LDAP_OPT_SUCCESS )
354         {
355                 fprintf( stderr, "Could not set LDAP_OPT_DEREF %d\n", deref );
356         }
357         if (timelimit != -1 &&
358                 ldap_set_option( ld, LDAP_OPT_TIMELIMIT, (void *) &timelimit ) != LDAP_OPT_SUCCESS )
359         {
360                 fprintf( stderr, "Could not set LDAP_OPT_TIMELIMIT %d\n", timelimit );
361         }
362         if (sizelimit != -1 &&
363                 ldap_set_option( ld, LDAP_OPT_SIZELIMIT, (void *) &sizelimit ) != LDAP_OPT_SUCCESS )
364         {
365                 fprintf( stderr, "Could not set LDAP_OPT_SIZELIMIT %d\n", sizelimit );
366         }
367         if (referrals != -1 &&
368                 ldap_set_option( ld, LDAP_OPT_REFERRALS,
369                                  (referrals ? LDAP_OPT_ON : LDAP_OPT_OFF) ) != LDAP_OPT_SUCCESS )
370         {
371                 fprintf( stderr, "Could not set LDAP_OPT_REFERRALS %s\n",
372                         referrals ? "on" : "off" );
373         }
374
375         if (version != -1 &&
376                 ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &version ) != LDAP_OPT_SUCCESS )
377         {
378                 fprintf( stderr, "Could not set LDAP_OPT_PROTOCOL_VERSION %d\n", version );
379         }
380
381         if (want_bindpw) {
382                 passwd = getpass("Enter LDAP Password: ");
383         }
384
385         if ( ldap_bind_s( ld, binddn, passwd, authmethod ) != LDAP_SUCCESS ) {
386                 ldap_perror( ld, "ldap_bind" );
387                 return( EXIT_FAILURE );
388         }
389
390         if ( manageDSAit ) {
391                 int err;
392                 LDAPControl c;
393                 LDAPControl *ctrls[2];
394                 ctrls[0] = &c;
395                 ctrls[1] = NULL;
396
397                 c.ldctl_oid = LDAP_CONTROL_MANAGEDSAIT;
398                 c.ldctl_value.bv_val = NULL;
399                 c.ldctl_value.bv_len = 0;
400                 c.ldctl_iscritical = manageDSAit > 1;
401
402                 err = ldap_set_option( ld, LDAP_OPT_SERVER_CONTROLS, &ctrls );
403
404                 if( err != LDAP_OPT_SUCCESS ) {
405                         fprintf( stderr, "Could not set Manage DSA IT Control\n" );
406                         if( c.ldctl_iscritical ) {
407                                 exit( EXIT_FAILURE );
408                         }
409                 }
410         }
411
412         if ( verbose ) {
413                 fprintf( stderr, "filter%s: %s\nreturning: ",
414                         infile != NULL ? " pattern" : "",
415                         filtpattern );
416
417                 if ( attrs == NULL ) {
418                         fprintf( stderr, "ALL" );
419                 } else {
420                         for ( i = 0; attrs[ i ] != NULL; ++i ) {
421                                 fprintf( stderr, "%s ", attrs[ i ] );
422                         }
423                 }
424                 fprintf( stderr, "\n" );
425         }
426
427         if ( ldif ) {
428                 if (ldif < 3 ) {
429                         printf( "version: 1\n\n");
430                 }
431
432                 if (ldif < 2 ) {
433                         printf( "#\n# filter%s: %s\n# returning: ",
434                                 infile != NULL ? " pattern" : "",
435                                 filtpattern );
436
437                         if ( attrs == NULL ) {
438                                 printf( "ALL" );
439                         } else {
440                                 for ( i = 0; attrs[ i ] != NULL; ++i ) {
441                                         printf( "%s ", attrs[ i ] );
442                                 }
443                         }
444                         printf( "\n#\n\n" );
445                 }
446         }
447
448         if ( infile == NULL ) {
449                 rc = dosearch( ld, base, scope, attrs, attrsonly, NULL, filtpattern );
450
451         } else {
452                 rc = 0;
453                 first = 1;
454                 while ( rc == 0 && fgets( line, sizeof( line ), fp ) != NULL ) {
455                         line[ strlen( line ) - 1 ] = '\0';
456                         if ( !first ) {
457                                 putchar( '\n' );
458                         } else {
459                                 first = 0;
460                         }
461                         rc = dosearch( ld, base, scope, attrs, attrsonly,
462                                 filtpattern, line );
463                 }
464                 if ( fp != stdin ) {
465                         fclose( fp );
466                 }
467         }
468
469         ldap_unbind( ld );
470         return( rc );
471 }
472
473
474 static int dosearch(
475         LDAP    *ld,
476         char    *base,
477         int             scope,
478         char    **attrs,
479         int             attrsonly,
480         char    *filtpatt,
481         char    *value)
482 {
483         char            filter[ BUFSIZ ];
484         int                     rc, first, matches;
485         LDAPMessage             *res, *e;
486
487         if( filtpatt != NULL ) {
488                 sprintf( filter, filtpatt, value );
489
490                 if ( verbose ) {
491                         fprintf( stderr, "filter is: (%s)\n", filter );
492                 }
493
494                 if( ldif == 1 ) {
495                         printf( "#\n# filter: %s\n#\n", filter );
496                 }
497
498         } else {
499                 sprintf( filter, "%s", value );
500         }
501
502         if ( not ) {
503                 return( LDAP_SUCCESS );
504         }
505
506         if ( ldap_search( ld, base, scope, filter, attrs, attrsonly ) == -1 ) {
507                 int ld_errno;
508                 ldap_perror( ld, "ldap_search" );
509
510                 ldap_get_option(ld, LDAP_OPT_ERROR_NUMBER, &ld_errno);
511                 return( ld_errno );
512         }
513
514         matches = 0;
515         first = 1;
516         res = NULL;
517         while ( (rc = ldap_result( ld, LDAP_RES_ANY, sortattr ? 1 : 0, NULL, &res ))
518                 == LDAP_RES_SEARCH_ENTRY ) {
519         matches++;
520         e = ldap_first_entry( ld, res );
521         if ( !first ) {
522                 putchar( '\n' );
523         } else {
524                 first = 0;
525         }
526         print_entry( ld, e, attrsonly );
527         ldap_msgfree( res );
528         res = NULL;
529         }
530         if ( rc == -1 ) {
531         ldap_perror( ld, "ldap_result" );
532         return( rc );
533         }
534         if (( rc = ldap_result2error( ld, res, 0 )) != LDAP_SUCCESS ) {
535                 ldap_perror( ld, "ldap_search" );
536         }
537         if ( sortattr != NULL ) {
538                 (void) ldap_sort_entries( ld, &res,
539                         ( *sortattr == '\0' ) ? NULL : sortattr, strcasecmp );
540                 matches = 0;
541                 first = 1;
542                 for ( e = ldap_first_entry( ld, res ); e != NULL;
543                         e = ldap_next_entry( ld, e ) ) {
544                 matches++;
545                 if ( !first ) {
546                         putchar( '\n' );
547                 } else {
548                         first = 0;
549                 }
550                 print_entry( ld, e, attrsonly );
551                 }
552         }
553
554         if ( verbose ) {
555                 printf( "%d matches\n", matches );
556         }
557
558         ldap_msgfree( res );
559         return( rc );
560 }
561
562
563 void print_entry(
564         LDAP    *ld,
565         LDAPMessage     *entry,
566         int             attrsonly)
567 {
568         char            *a, *dn, *ufn;
569         char    tmpfname[ 256 ];
570         char    url[ 256 ];
571         int                     i;
572         BerElement              *ber = NULL;
573         struct berval   **bvals;
574         FILE            *tmpfp;
575
576         dn = ldap_get_dn( ld, entry );
577         ufn = NULL;
578
579         if ( ldif == 1 ) {
580                 ufn = ldap_dn2ufn( dn );
581                 write_ldif( LDIF_PUT_COMMENT, NULL, ufn, strlen( ufn ));
582         }
583         if ( ldif ) {
584                 write_ldif( LDIF_PUT_VALUE, "dn", dn, strlen( dn ));
585         } else {
586                 printf( "%s\n", dn );
587         }
588
589         if ( includeufn ) {
590                 if( ufn == NULL ) {
591                         ufn = ldap_dn2ufn( dn );
592                 }
593                 if ( ldif ) {
594                         write_ldif( LDIF_PUT_VALUE, "ufn", ufn, strlen( ufn ));
595                 } else {
596                         printf( "%s\n", ufn );
597                 }
598         }
599
600         if( ufn != NULL ) ldap_memfree( ufn );
601         ldap_memfree( dn );
602
603         for ( a = ldap_first_attribute( ld, entry, &ber ); a != NULL;
604                 a = ldap_next_attribute( ld, entry, ber ) )
605         {
606                 if ( skipsortattr && strcasecmp( a, sortattr ) == 0 ) {
607                         continue;
608                 }
609
610                 if ( attrsonly ) {
611                         if ( ldif ) {
612                                 write_ldif( LDIF_PUT_NOVALUE, a, NULL, 0 );
613                         } else {
614                                 printf( "%s\n", a );
615                         }
616
617                 } else if (( bvals = ldap_get_values_len( ld, entry, a )) != NULL ) {
618                         for ( i = 0; bvals[i] != NULL; i++ ) {
619                                 if ( vals2tmp > 1 || ( vals2tmp
620                                         && ldif_is_not_printable( bvals[i]->bv_val, bvals[i]->bv_len ) ))
621                                 {
622                                         /* write value to file */
623                                         sprintf( tmpfname, "%s" LDAP_DIRSEP "ldapsearch-%s-XXXXXX",
624                                                 tmpdir, a );
625                                         tmpfp = NULL;
626
627                                         if ( mktemp( tmpfname ) == NULL ) {
628                                                 perror( tmpfname );
629                                                 continue;
630                                         }
631
632                                         if (( tmpfp = fopen( tmpfname, "w")) == NULL ) {
633                                                 perror( tmpfname );
634                                                 continue;
635                                         }
636
637                                         if ( fwrite( bvals[ i ]->bv_val,
638                                                 bvals[ i ]->bv_len, 1, tmpfp ) == 0 )
639                                         {
640                                                 perror( tmpfname );
641                                                 fclose( tmpfp );
642                                                 continue;
643                                         }
644
645                                         fclose( tmpfp );
646
647                                         sprintf( url, "%s%s", urlpre,
648                                                 &tmpfname[strlen(tmpdir) + sizeof(LDAP_DIRSEP) - 1] );
649
650                                         if ( ldif ) {
651                                                 write_ldif( LDIF_PUT_URL, a, url, strlen( url ));
652                                         } else {
653                                                 printf( "%s%s%s\n", a, sep, url );
654                                         }
655
656
657                                 } else {
658                                         if ( ldif ) {
659                                                 write_ldif( LDIF_PUT_VALUE, a,
660                                                         bvals[ i ]->bv_val, bvals[ i ]->bv_len );
661
662                                         } else {
663                                                 int notprint = !binary && !vals2tmp
664                                                         && ldif_is_not_printable( bvals[i]->bv_val,
665                                                                 bvals[i]->bv_len ); 
666                                                 printf( "%s%s", a, sep );
667                                                 puts( notprint ? "NOT PRINTABLE" : bvals[ i ]->bv_val );
668                                                 puts( "\n" );
669                                         }
670                                 }
671                         }
672                         ber_bvecfree( bvals );
673                 }
674         }
675
676         if( ber != NULL ) {
677                 ber_free( ber, 0 );
678         }
679 }
680
681
682 int
683 write_ldif( int type, char *name, char *value, ber_len_t vallen )
684 {
685         char    *ldif;
686
687         if (( ldif = ldif_put( type, name, value, vallen )) == NULL ) {
688                 return( -1 );
689         }
690
691         fputs( ldif, stdout );
692         ber_memfree( ldif );
693
694         return( 0 );
695 }