Warning: That file was not part of the compilation database. It may have many parsing errors.

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

Warning: That file was not part of the compilation database. It may have many parsing errors.