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