xref: /netbsd/external/bsd/openldap/dist/include/lber.h (revision cf1d77f7)
1 /*	$NetBSD: lber.h,v 1.3 2021/08/14 16:14:55 christos Exp $	*/
2 
3 /* $OpenLDAP$ */
4 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5  *
6  * Copyright 1998-2021 The OpenLDAP Foundation.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted only as authorized by the OpenLDAP
11  * Public License.
12  *
13  * A copy of this license is available in file LICENSE in the
14  * top-level directory of the distribution or, alternatively, at
15  * <http://www.OpenLDAP.org/license.html>.
16  */
17 /* Portions Copyright (c) 1990 Regents of the University of Michigan.
18  * All rights reserved.
19  *
20  * Redistribution and use in source and binary forms are permitted
21  * provided that this notice is preserved and that due credit is given
22  * to the University of Michigan at Ann Arbor. The name of the University
23  * may not be used to endorse or promote products derived from this
24  * software without specific prior written permission. This software
25  * is provided ``as is'' without express or implied warranty.
26  */
27 
28 #ifndef _LBER_H
29 #define _LBER_H
30 
31 #include <lber_types.h>
32 #include <string.h>
33 
34 LDAP_BEGIN_DECL
35 
36 /*
37  * ber_tag_t represents the identifier octets at the beginning of BER
38  * elements.  OpenLDAP treats them as mere big-endian unsigned integers.
39  *
40  * Actually the BER identifier octets look like this:
41  *
42  *	Bits of 1st octet:
43  *	______
44  *	8 7 | CLASS
45  *	0 0 = UNIVERSAL
46  *	0 1 = APPLICATION
47  *	1 0 = CONTEXT-SPECIFIC
48  *	1 1 = PRIVATE
49  *		_____
50  *		| 6 | DATA-TYPE
51  *		  0 = PRIMITIVE
52  *		  1 = CONSTRUCTED
53  *			___________
54  *			| 5 ... 1 | TAG-NUMBER
55  *
56  *  For ASN.1 tag numbers >= 0x1F, TAG-NUMBER above is 0x1F and the next
57  *  BER octets contain the actual ASN.1 tag number:  Big-endian, base
58  *  128, 8.bit = 1 in all but the last octet, minimum number of octets.
59  */
60 
61 /* BER classes and mask (in 1st identifier octet) */
62 #define LBER_CLASS_UNIVERSAL	((ber_tag_t) 0x00U)
63 #define LBER_CLASS_APPLICATION	((ber_tag_t) 0x40U)
64 #define LBER_CLASS_CONTEXT		((ber_tag_t) 0x80U)
65 #define LBER_CLASS_PRIVATE		((ber_tag_t) 0xc0U)
66 #define LBER_CLASS_MASK			((ber_tag_t) 0xc0U)
67 
68 /* BER encoding type and mask (in 1st identifier octet) */
69 #define LBER_PRIMITIVE			((ber_tag_t) 0x00U)
70 #define LBER_CONSTRUCTED		((ber_tag_t) 0x20U)
71 #define LBER_ENCODING_MASK		((ber_tag_t) 0x20U)
72 
73 #define LBER_BIG_TAG_MASK		((ber_tag_t) 0x1fU)
74 #define LBER_MORE_TAG_MASK		((ber_tag_t) 0x80U)
75 
76 /*
77  * LBER_ERROR and LBER_DEFAULT are values that can never appear
78  * as valid BER tags, so it is safe to use them to report errors.
79  * Valid tags have (tag & (ber_tag_t) 0xFF) != 0xFF.
80  */
81 #define LBER_ERROR			((ber_tag_t) -1)
82 #define LBER_DEFAULT		((ber_tag_t) -1)
83 
84 /* general BER types we know about */
85 #define LBER_BOOLEAN		((ber_tag_t) 0x01UL)
86 #define LBER_INTEGER		((ber_tag_t) 0x02UL)
87 #define LBER_BITSTRING		((ber_tag_t) 0x03UL)
88 #define LBER_OCTETSTRING	((ber_tag_t) 0x04UL)
89 #define LBER_NULL			((ber_tag_t) 0x05UL)
90 #define LBER_ENUMERATED		((ber_tag_t) 0x0aUL)
91 #define LBER_SEQUENCE		((ber_tag_t) 0x30UL)	/* constructed */
92 #define LBER_SET			((ber_tag_t) 0x31UL)	/* constructed */
93 
94 /* LBER BerElement options */
95 #define LBER_USE_DER		0x01
96 
97 /* get/set options for BerElement */
98 #define LBER_OPT_BER_OPTIONS			0x01
99 #define LBER_OPT_BER_DEBUG				0x02
100 #define LBER_OPT_BER_REMAINING_BYTES	0x03
101 #define LBER_OPT_BER_TOTAL_BYTES		0x04
102 #define LBER_OPT_BER_BYTES_TO_WRITE		0x05
103 #define LBER_OPT_BER_MEMCTX				0x06
104 
105 #define LBER_OPT_DEBUG_LEVEL	LBER_OPT_BER_DEBUG
106 #define LBER_OPT_REMAINING_BYTES	LBER_OPT_BER_REMAINING_BYTES
107 #define LBER_OPT_TOTAL_BYTES		LBER_OPT_BER_TOTAL_BYTES
108 #define LBER_OPT_BYTES_TO_WRITE		LBER_OPT_BER_BYTES_TO_WRITE
109 
110 #define LBER_OPT_LOG_PRINT_FN	0x8001
111 #define LBER_OPT_MEMORY_FNS		0x8002
112 #define LBER_OPT_ERROR_FN		0x8003
113 #define LBER_OPT_LOG_PRINT_FILE		0x8004
114 
115 /* get/set Memory Debug options */
116 #define LBER_OPT_MEMORY_INUSE		0x8005	/* for memory debugging */
117 #define LBER_OPT_LOG_PROC           0x8006  /* for external logging function */
118 
119 typedef int* (*BER_ERRNO_FN) LDAP_P(( void ));
120 
121 typedef void (*BER_LOG_PRINT_FN) LDAP_P(( LDAP_CONST char *buf ));
122 
123 typedef void* (BER_MEMALLOC_FN)	LDAP_P(( ber_len_t size, void *ctx ));
124 typedef void* (BER_MEMCALLOC_FN)	LDAP_P(( ber_len_t n, ber_len_t size, void *ctx ));
125 typedef void* (BER_MEMREALLOC_FN)	LDAP_P(( void *p, ber_len_t size, void *ctx ));
126 typedef void  (BER_MEMFREE_FN)		LDAP_P(( void *p, void *ctx ));
127 
128 typedef struct lber_memory_fns {
129 	BER_MEMALLOC_FN	*bmf_malloc;
130 	BER_MEMCALLOC_FN *bmf_calloc;
131 	BER_MEMREALLOC_FN *bmf_realloc;
132 	BER_MEMFREE_FN *bmf_free;
133 } BerMemoryFunctions;
134 
135 /* LBER Sockbuf_IO options */
136 #define LBER_SB_OPT_GET_FD		1
137 #define LBER_SB_OPT_SET_FD		2
138 #define LBER_SB_OPT_HAS_IO		3
139 #define LBER_SB_OPT_SET_NONBLOCK	4
140 #define LBER_SB_OPT_GET_SSL		7
141 #define LBER_SB_OPT_DATA_READY		8
142 #define LBER_SB_OPT_SET_READAHEAD	9
143 #define LBER_SB_OPT_DRAIN		10
144 #define LBER_SB_OPT_NEEDS_READ		11
145 #define LBER_SB_OPT_NEEDS_WRITE		12
146 #define LBER_SB_OPT_GET_MAX_INCOMING	13
147 #define LBER_SB_OPT_SET_MAX_INCOMING	14
148 
149 /* Only meaningful ifdef LDAP_PF_LOCAL_SENDMSG */
150 #define LBER_SB_OPT_UNGET_BUF	15
151 
152 /* Largest option used by the library */
153 #define LBER_SB_OPT_OPT_MAX		15
154 
155 /* LBER IO operations stacking levels */
156 #define LBER_SBIOD_LEVEL_PROVIDER	10
157 #define LBER_SBIOD_LEVEL_TRANSPORT	20
158 #define LBER_SBIOD_LEVEL_APPLICATION	30
159 
160 /* get/set options for Sockbuf */
161 #define LBER_OPT_SOCKBUF_DESC		0x1000
162 #define LBER_OPT_SOCKBUF_OPTIONS	0x1001
163 #define LBER_OPT_SOCKBUF_DEBUG		0x1002
164 
165 /* on/off values */
166 LBER_V( char ) ber_pvt_opt_on;
167 #define LBER_OPT_ON		((void *) &ber_pvt_opt_on)
168 #define LBER_OPT_OFF	((void *) 0)
169 
170 #define LBER_OPT_SUCCESS	(0)
171 #define LBER_OPT_ERROR		(-1)
172 
173 typedef struct berelement BerElement;
174 typedef struct sockbuf Sockbuf;
175 
176 typedef struct sockbuf_io Sockbuf_IO;
177 
178 /* Structure for LBER IO operation descriptor */
179 typedef struct sockbuf_io_desc {
180 	int			sbiod_level;
181 	Sockbuf			*sbiod_sb;
182 	Sockbuf_IO		*sbiod_io;
183 	void 			*sbiod_pvt;
184 	struct sockbuf_io_desc	*sbiod_next;
185 } Sockbuf_IO_Desc;
186 
187 /* Structure for LBER IO operation functions */
188 struct sockbuf_io {
189 	int (*sbi_setup)( Sockbuf_IO_Desc *sbiod, void *arg );
190 	int (*sbi_remove)( Sockbuf_IO_Desc *sbiod );
191 	int (*sbi_ctrl)( Sockbuf_IO_Desc *sbiod, int opt, void *arg);
192 
193 	ber_slen_t (*sbi_read)( Sockbuf_IO_Desc *sbiod, void *buf,
194 		ber_len_t len );
195 	ber_slen_t (*sbi_write)( Sockbuf_IO_Desc *sbiod, void *buf,
196 		ber_len_t len );
197 
198 	int (*sbi_close)( Sockbuf_IO_Desc *sbiod );
199 };
200 
201 /* Helper macros for LBER IO functions */
202 #define LBER_SBIOD_READ_NEXT( sbiod, buf, len ) \
203 	( (sbiod)->sbiod_next->sbiod_io->sbi_read( (sbiod)->sbiod_next, \
204 		buf, len ) )
205 #define LBER_SBIOD_WRITE_NEXT( sbiod, buf, len ) \
206 	( (sbiod)->sbiod_next->sbiod_io->sbi_write( (sbiod)->sbiod_next, \
207 		buf, len ) )
208 #define LBER_SBIOD_CTRL_NEXT( sbiod, opt, arg ) \
209 	( (sbiod)->sbiod_next ? \
210 		( (sbiod)->sbiod_next->sbiod_io->sbi_ctrl( \
211 		(sbiod)->sbiod_next, opt, arg ) ) : 0 )
212 
213 /* structure for returning a sequence of octet strings + length */
214 typedef struct berval {
215 	ber_len_t	bv_len;
216 	char		*bv_val;
217 } BerValue;
218 
219 typedef BerValue *BerVarray;	/* To distinguish from a single bv */
220 
221 /* this should be moved to lber-int.h */
222 
223 /*
224  * in bprint.c:
225  */
226 LBER_F( void )
227 ber_error_print LDAP_P((
228 	LDAP_CONST char *data ));
229 
230 LBER_F( void )
231 ber_bprint LDAP_P((
232 	LDAP_CONST char *data, ber_len_t len ));
233 
234 LBER_F( void )
235 ber_dump LDAP_P((
236 	BerElement *ber, int inout ));
237 
238 /*
239  * in decode.c:
240  */
241 typedef int (*BERDecodeCallback) LDAP_P((
242 	BerElement *ber,
243 	void *data,
244 	int mode ));
245 
246 LBER_F( ber_tag_t )
247 ber_get_tag LDAP_P((
248 	BerElement *ber ));
249 
250 LBER_F( ber_tag_t )
251 ber_skip_tag LDAP_P((
252 	BerElement *ber,
253 	ber_len_t *len ));
254 
255 LBER_F( ber_tag_t )
256 ber_peek_tag LDAP_P((
257 	BerElement *ber,
258 	ber_len_t *len ));
259 
260 LBER_F( ber_tag_t )
261 ber_skip_raw LDAP_P((
262 	BerElement *ber,
263 	struct berval *bv ));
264 
265 LBER_F( ber_tag_t )
266 ber_skip_element LDAP_P((
267 	BerElement *ber,
268 	struct berval *bv ));
269 
270 LBER_F( ber_tag_t )
271 ber_peek_element LDAP_P((
272 	LDAP_CONST BerElement *ber,
273 	struct berval *bv ));
274 
275 LBER_F( ber_tag_t )
276 ber_get_int LDAP_P((
277 	BerElement *ber,
278 	ber_int_t *num ));
279 
280 LBER_F( ber_tag_t )
281 ber_get_enum LDAP_P((
282 	BerElement *ber,
283 	ber_int_t *num ));
284 
285 LBER_F( int )
286 ber_decode_int LDAP_P((
287 	const struct berval *bv,
288 	ber_int_t *num ));
289 
290 LBER_F( ber_tag_t )
291 ber_get_stringb LDAP_P((
292 	BerElement *ber,
293 	char *buf,
294 	ber_len_t *len ));
295 
296 #define	LBER_BV_ALLOC	0x01	/* allocate/copy result, otherwise in-place */
297 #define	LBER_BV_NOTERM	0x02	/* omit NUL-terminator if parsing in-place */
298 #define	LBER_BV_STRING	0x04	/* fail if berval contains embedded \0 */
299 /* LBER_BV_STRING currently accepts a terminating \0 in the berval, because
300  * Active Directory sends that in at least the diagonsticMessage field.
301  */
302 
303 LBER_F( ber_tag_t )
304 ber_get_stringbv LDAP_P((
305 	BerElement *ber,
306 	struct berval *bv,
307 	int options ));
308 
309 LBER_F( ber_tag_t )
310 ber_get_stringa LDAP_P((
311 	BerElement *ber,
312 	char **buf ));
313 
314 LBER_F( ber_tag_t )
315 ber_get_stringal LDAP_P((
316 	BerElement *ber,
317 	struct berval **bv ));
318 
319 LBER_F( ber_tag_t )
320 ber_get_bitstringa LDAP_P((
321 	BerElement *ber,
322 	char **buf,
323 	ber_len_t *len ));
324 
325 LBER_F( ber_tag_t )
326 ber_get_null LDAP_P((
327 	BerElement *ber ));
328 
329 LBER_F( ber_tag_t )
330 ber_get_boolean LDAP_P((
331 	BerElement *ber,
332 	ber_int_t *boolval ));
333 
334 LBER_F( ber_tag_t )
335 ber_first_element LDAP_P((
336 	BerElement *ber,
337 	ber_len_t *len,
338 	char **last ));
339 
340 LBER_F( ber_tag_t )
341 ber_next_element LDAP_P((
342 	BerElement *ber,
343 	ber_len_t *len,
344 	LDAP_CONST char *last ));
345 
346 LBER_F( ber_tag_t )
347 ber_scanf LDAP_P((
348 	BerElement *ber,
349 	LDAP_CONST char *fmt,
350 	... ));
351 
352 LBER_F( int )
353 ber_decode_oid LDAP_P((
354 	struct berval *in,
355 	struct berval *out ));
356 
357 /*
358  * in encode.c
359  */
360 LBER_F( int )
361 ber_encode_oid LDAP_P((
362 	struct berval *in,
363 	struct berval *out ));
364 
365 typedef int (*BEREncodeCallback) LDAP_P((
366 	BerElement *ber,
367 	void *data ));
368 
369 LBER_F( int )
370 ber_put_enum LDAP_P((
371 	BerElement *ber,
372 	ber_int_t num,
373 	ber_tag_t tag ));
374 
375 LBER_F( int )
376 ber_put_int LDAP_P((
377 	BerElement *ber,
378 	ber_int_t num,
379 	ber_tag_t tag ));
380 
381 LBER_F( int )
382 ber_put_ostring LDAP_P((
383 	BerElement *ber,
384 	LDAP_CONST char *str,
385 	ber_len_t len,
386 	ber_tag_t tag ));
387 
388 LBER_F( int )
389 ber_put_berval LDAP_P((
390 	BerElement *ber,
391 	struct berval *bv,
392 	ber_tag_t tag ));
393 
394 LBER_F( int )
395 ber_put_string LDAP_P((
396 	BerElement *ber,
397 	LDAP_CONST char *str,
398 	ber_tag_t tag ));
399 
400 LBER_F( int )
401 ber_put_bitstring LDAP_P((
402 	BerElement *ber,
403 	LDAP_CONST char *str,
404 	ber_len_t bitlen,
405 	ber_tag_t tag ));
406 
407 LBER_F( int )
408 ber_put_null LDAP_P((
409 	BerElement *ber,
410 	ber_tag_t tag ));
411 
412 LBER_F( int )
413 ber_put_boolean LDAP_P((
414 	BerElement *ber,
415 	ber_int_t boolval,
416 	ber_tag_t tag ));
417 
418 LBER_F( int )
419 ber_start_seq LDAP_P((
420 	BerElement *ber,
421 	ber_tag_t tag ));
422 
423 LBER_F( int )
424 ber_start_set LDAP_P((
425 	BerElement *ber,
426 	ber_tag_t tag ));
427 
428 LBER_F( int )
429 ber_put_seq LDAP_P((
430 	BerElement *ber ));
431 
432 LBER_F( int )
433 ber_put_set LDAP_P((
434 	BerElement *ber ));
435 
436 LBER_F( int )
437 ber_printf LDAP_P((
438 	BerElement *ber,
439 	LDAP_CONST char *fmt,
440 	... ));
441 
442 
443 /*
444  * in io.c:
445  */
446 
447 LBER_F( ber_slen_t )
448 ber_skip_data LDAP_P((
449 	BerElement *ber,
450 	ber_len_t len ));
451 
452 LBER_F( ber_slen_t )
453 ber_read LDAP_P((
454 	BerElement *ber,
455 	char *buf,
456 	ber_len_t len ));
457 
458 LBER_F( ber_slen_t )
459 ber_write LDAP_P((
460 	BerElement *ber,
461 	LDAP_CONST char *buf,
462 	ber_len_t len,
463 	int zero ));	/* nonzero is unsupported from OpenLDAP 2.4.18 */
464 
465 LBER_F( void )
466 ber_free LDAP_P((
467 	BerElement *ber,
468 	int freebuf ));
469 
470 LBER_F( void )
471 ber_free_buf LDAP_P(( BerElement *ber ));
472 
473 LBER_F( int )
474 ber_flush2 LDAP_P((
475 	Sockbuf *sb,
476 	BerElement *ber,
477 	int freeit ));
478 #define LBER_FLUSH_FREE_NEVER		(0x0)	/* traditional behavior */
479 #define LBER_FLUSH_FREE_ON_SUCCESS	(0x1)	/* traditional behavior */
480 #define LBER_FLUSH_FREE_ON_ERROR	(0x2)
481 #define LBER_FLUSH_FREE_ALWAYS		(LBER_FLUSH_FREE_ON_SUCCESS|LBER_FLUSH_FREE_ON_ERROR)
482 
483 LBER_F( int )
484 ber_flush LDAP_P((
485 	Sockbuf *sb,
486 	BerElement *ber,
487 	int freeit )); /* DEPRECATED */
488 
489 LBER_F( BerElement * )
490 ber_alloc LDAP_P(( void )); /* DEPRECATED */
491 
492 LBER_F( BerElement * )
493 der_alloc LDAP_P(( void )); /* DEPRECATED */
494 
495 LBER_F( BerElement * )
496 ber_alloc_t LDAP_P((
497 	int beroptions ));
498 
499 LBER_F( BerElement * )
500 ber_dup LDAP_P((
501 	BerElement *ber ));
502 
503 LBER_F( ber_tag_t )
504 ber_get_next LDAP_P((
505 	Sockbuf *sb,
506 	ber_len_t *len,
507 	BerElement *ber ));
508 
509 LBER_F( void )
510 ber_init2 LDAP_P((
511 	BerElement *ber,
512 	struct berval *bv,
513 	int options ));
514 
515 LBER_F( void )
516 ber_init_w_nullc LDAP_P((	/* DEPRECATED */
517 	BerElement *ber,
518 	int options ));
519 
520 LBER_F( void )
521 ber_reset LDAP_P((
522 	BerElement *ber,
523 	int was_writing ));
524 
525 LBER_F( BerElement * )
526 ber_init LDAP_P((
527 	struct berval *bv ));
528 
529 LBER_F( int )
530 ber_flatten LDAP_P((
531 	BerElement *ber,
532 	struct berval **bvPtr ));
533 
534 LBER_F( int )
535 ber_flatten2 LDAP_P((
536 	BerElement *ber,
537 	struct berval *bv,
538 	int alloc ));
539 
540 LBER_F( int )
541 ber_remaining LDAP_P((
542 	BerElement *ber ));
543 
544 /*
545  * LBER ber accessor functions
546  */
547 
548 LBER_F( int )
549 ber_get_option LDAP_P((
550 	void *item,
551 	int option,
552 	void *outvalue));
553 
554 LBER_F( int )
555 ber_set_option LDAP_P((
556 	void *item,
557 	int option,
558 	LDAP_CONST void *invalue));
559 
560 /*
561  * LBER sockbuf.c
562  */
563 
564 LBER_F( Sockbuf *  )
565 ber_sockbuf_alloc LDAP_P((
566 	void ));
567 
568 LBER_F( void )
569 ber_sockbuf_free LDAP_P((
570 	Sockbuf *sb ));
571 
572 LBER_F( int )
573 ber_sockbuf_add_io LDAP_P((
574 	Sockbuf *sb,
575 	Sockbuf_IO *sbio,
576 	int layer,
577 	void *arg ));
578 
579 LBER_F( int )
580 ber_sockbuf_remove_io LDAP_P((
581 	Sockbuf *sb,
582 	Sockbuf_IO *sbio,
583 	int layer ));
584 
585 LBER_F( int )
586 ber_sockbuf_ctrl LDAP_P((
587 	Sockbuf *sb,
588 	int opt,
589 	void *arg ));
590 
591 LBER_V( Sockbuf_IO ) ber_sockbuf_io_tcp;
592 LBER_V( Sockbuf_IO ) ber_sockbuf_io_readahead;
593 LBER_V( Sockbuf_IO ) ber_sockbuf_io_fd;
594 LBER_V( Sockbuf_IO ) ber_sockbuf_io_debug;
595 LBER_V( Sockbuf_IO ) ber_sockbuf_io_udp;
596 
597 /*
598  * LBER memory.c
599  */
600 LBER_F( void * )
601 ber_memalloc LDAP_P((
602 	ber_len_t s ));
603 
604 LBER_F( void * )
605 ber_memrealloc LDAP_P((
606 	void* p,
607 	ber_len_t s ));
608 
609 LBER_F( void * )
610 ber_memcalloc LDAP_P((
611 	ber_len_t n,
612 	ber_len_t s ));
613 
614 LBER_F( void )
615 ber_memfree LDAP_P((
616 	void* p ));
617 
618 LBER_F( void )
619 ber_memvfree LDAP_P((
620 	void** vector ));
621 
622 LBER_F( void )
623 ber_bvfree LDAP_P((
624 	struct berval *bv ));
625 
626 LBER_F( void )
627 ber_bvecfree LDAP_P((
628 	struct berval **bv ));
629 
630 LBER_F( int )
631 ber_bvecadd LDAP_P((
632 	struct berval ***bvec,
633 	struct berval *bv ));
634 
635 LBER_F( struct berval * )
636 ber_dupbv LDAP_P((
637 	struct berval *dst, struct berval *src ));
638 
639 LBER_F( struct berval * )
640 ber_bvdup LDAP_P((
641 	struct berval *src ));
642 
643 LBER_F( struct berval * )
644 ber_mem2bv LDAP_P((
645 	LDAP_CONST char *, ber_len_t len, int duplicate, struct berval *bv));
646 
647 LBER_F( struct berval * )
648 ber_str2bv LDAP_P((
649 	LDAP_CONST char *, ber_len_t len, int duplicate, struct berval *bv));
650 
651 #define	ber_bvstr(a)	((ber_str2bv)((a), 0, 0, NULL))
652 #define	ber_bvstrdup(a)	((ber_str2bv)((a), 0, 1, NULL))
653 
654 LBER_F( char * )
655 ber_strdup LDAP_P((
656 	LDAP_CONST char * ));
657 
658 LBER_F( ber_len_t )
659 ber_strnlen LDAP_P((
660 	LDAP_CONST char *s, ber_len_t len ));
661 
662 LBER_F( char * )
663 ber_strndup LDAP_P((
664 	LDAP_CONST char *s, ber_len_t l ));
665 
666 LBER_F( struct berval * )
667 ber_bvreplace LDAP_P((
668 	struct berval *dst, LDAP_CONST struct berval *src ));
669 
670 LBER_F( void )
671 ber_bvarray_free LDAP_P(( BerVarray p ));
672 
673 LBER_F( int )
674 ber_bvarray_add LDAP_P(( BerVarray *p, BerValue *bv ));
675 
676 #define ber_bvcmp(v1,v2) \
677 	((v1)->bv_len < (v2)->bv_len \
678 		? -1 : ((v1)->bv_len > (v2)->bv_len \
679 			? 1 : memcmp((v1)->bv_val, (v2)->bv_val, (v1)->bv_len) ))
680 
681 /*
682  * error.c
683  */
684 LBER_F( int * ) ber_errno_addr LDAP_P((void));
685 #define ber_errno (*(ber_errno_addr)())
686 
687 #define LBER_ERROR_NONE		0
688 #define LBER_ERROR_PARAM	0x1
689 #define LBER_ERROR_MEMORY	0x2
690 
691 LDAP_END_DECL
692 
693 #endif /* _LBER_H */
694