xref: /onnv-gate/usr/src/lib/libldap4/include/lber.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
3*0Sstevel@tonic-gate  * Use is subject to license terms.
4*0Sstevel@tonic-gate  */
5*0Sstevel@tonic-gate 
6*0Sstevel@tonic-gate /*
7*0Sstevel@tonic-gate  * Copyright (c) 1990 Regents of the University of Michigan.
8*0Sstevel@tonic-gate  * All rights reserved.
9*0Sstevel@tonic-gate  *
10*0Sstevel@tonic-gate  * Redistribution and use in source and binary forms are permitted
11*0Sstevel@tonic-gate  * provided that this notice is preserved and that due credit is given
12*0Sstevel@tonic-gate  * to the University of Michigan at Ann Arbor. The name of the University
13*0Sstevel@tonic-gate  * may not be used to endorse or promote products derived from this
14*0Sstevel@tonic-gate  * software without specific prior written permission. This software
15*0Sstevel@tonic-gate  * is provided ``as is'' without express or implied warranty.
16*0Sstevel@tonic-gate  */
17*0Sstevel@tonic-gate 
18*0Sstevel@tonic-gate #ifndef _LBER_H
19*0Sstevel@tonic-gate #define	_LBER_H
20*0Sstevel@tonic-gate 
21*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
22*0Sstevel@tonic-gate 
23*0Sstevel@tonic-gate #ifdef __cplusplus
24*0Sstevel@tonic-gate extern "C" {
25*0Sstevel@tonic-gate #endif
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #if !defined(NEEDPROTOS) && defined(__STDC__)
28*0Sstevel@tonic-gate #define	NEEDPROTOS	1
29*0Sstevel@tonic-gate #endif
30*0Sstevel@tonic-gate 
31*0Sstevel@tonic-gate /* BER classes and mask */
32*0Sstevel@tonic-gate #define	LBER_CLASS_UNIVERSAL	0x00
33*0Sstevel@tonic-gate #define	LBER_CLASS_APPLICATION	0x40
34*0Sstevel@tonic-gate #define	LBER_CLASS_CONTEXT	0x80
35*0Sstevel@tonic-gate #define	LBER_CLASS_PRIVATE	0xc0
36*0Sstevel@tonic-gate #define	LBER_CLASS_MASK		0xc0
37*0Sstevel@tonic-gate 
38*0Sstevel@tonic-gate /* BER encoding type and mask */
39*0Sstevel@tonic-gate #define	LBER_PRIMITIVE		0x00
40*0Sstevel@tonic-gate #define	LBER_CONSTRUCTED	0x20
41*0Sstevel@tonic-gate #define	LBER_ENCODING_MASK	0x20
42*0Sstevel@tonic-gate 
43*0Sstevel@tonic-gate #define	LBER_BIG_TAG_MASK	0x1f
44*0Sstevel@tonic-gate #define	LBER_MORE_TAG_MASK	0x80
45*0Sstevel@tonic-gate 
46*0Sstevel@tonic-gate /*
47*0Sstevel@tonic-gate  * Note that LBER_ERROR and LBER_DEFAULT are values that can never appear
48*0Sstevel@tonic-gate  * as valid BER tags, and so it is safe to use them to report errors.  In
49*0Sstevel@tonic-gate  * fact, any tag for which the following is true is invalid:
50*0Sstevel@tonic-gate  *     (( tag & 0x00000080 ) != 0 ) && (( tag & 0xFFFFFF00 ) != 0 )
51*0Sstevel@tonic-gate  */
52*0Sstevel@tonic-gate #define	LBER_ERROR		0xffffffff
53*0Sstevel@tonic-gate #define	LBER_DEFAULT		0xffffffff
54*0Sstevel@tonic-gate 
55*0Sstevel@tonic-gate /* general BER types we know about */
56*0Sstevel@tonic-gate #define	LBER_BOOLEAN		0x01
57*0Sstevel@tonic-gate #define	LBER_INTEGER		0x02
58*0Sstevel@tonic-gate #define	LBER_BITSTRING		0x03
59*0Sstevel@tonic-gate #define	LBER_OCTETSTRING	0x04
60*0Sstevel@tonic-gate #define	LBER_NULL		0x05
61*0Sstevel@tonic-gate #define	LBER_ENUMERATED		0x0a
62*0Sstevel@tonic-gate #define	LBER_SEQUENCE		0x30	/* constructed */
63*0Sstevel@tonic-gate #define	LBER_SET		0x31	/* constructed */
64*0Sstevel@tonic-gate 
65*0Sstevel@tonic-gate #define	OLD_LBER_SEQUENCE	0x10	/* w/o constructed bit - broken */
66*0Sstevel@tonic-gate #define	OLD_LBER_SET		0x11	/* w/o constructed bit - broken */
67*0Sstevel@tonic-gate 
68*0Sstevel@tonic-gate #ifdef NEEDPROTOS
69*0Sstevel@tonic-gate typedef int (*BERTranslateProc)(char **bufp, unsigned int *buflenp,
70*0Sstevel@tonic-gate 	int free_input);
71*0Sstevel@tonic-gate #else /* NEEDPROTOS */
72*0Sstevel@tonic-gate typedef int (*BERTranslateProc)();
73*0Sstevel@tonic-gate #endif /* NEEDPROTOS */
74*0Sstevel@tonic-gate 
75*0Sstevel@tonic-gate typedef struct berelement BerElement; /* Opaque BerElement structure */
76*0Sstevel@tonic-gate #define	NULLBER ((BerElement *) 0)
77*0Sstevel@tonic-gate 
78*0Sstevel@tonic-gate #ifdef LDAP_SSL
79*0Sstevel@tonic-gate #include <security/ssl.h>
80*0Sstevel@tonic-gate #endif /* LDAP_SSL */
81*0Sstevel@tonic-gate 
82*0Sstevel@tonic-gate /*
83*0Sstevel@tonic-gate  * Structure Sockbuf which used to be defined in this header file, is
84*0Sstevel@tonic-gate  * removed since the c-api draft does not define the structure and it
85*0Sstevel@tonic-gate  * is only used internal to the library
86*0Sstevel@tonic-gate  */
87*0Sstevel@tonic-gate 
88*0Sstevel@tonic-gate typedef struct seqorset {
89*0Sstevel@tonic-gate 	BerElement	*sos_ber;
90*0Sstevel@tonic-gate 	unsigned int	sos_clen;
91*0Sstevel@tonic-gate 	unsigned int	sos_tag;
92*0Sstevel@tonic-gate 	char		*sos_first;
93*0Sstevel@tonic-gate 	char		*sos_ptr;
94*0Sstevel@tonic-gate 	struct seqorset	*sos_next;
95*0Sstevel@tonic-gate } Seqorset;
96*0Sstevel@tonic-gate #define	NULLSEQORSET	((Seqorset *) 0)
97*0Sstevel@tonic-gate 
98*0Sstevel@tonic-gate typedef unsigned int	ber_len_t;   /* for BER len */
99*0Sstevel@tonic-gate typedef unsigned int	ber_tag_t;   /* for BER tags */
100*0Sstevel@tonic-gate typedef int		ber_int_t;   /* for BER ints, enums, and Booleans */
101*0Sstevel@tonic-gate typedef unsigned int	ber_uint_t; /* unsigned equivalent of ber_int_t */
102*0Sstevel@tonic-gate typedef int		ber_slen_t; /* signed equivalent of ber_len_t */
103*0Sstevel@tonic-gate 
104*0Sstevel@tonic-gate /* structure for returning a sequence of octet strings + length */
105*0Sstevel@tonic-gate typedef struct berval {
106*0Sstevel@tonic-gate 	ber_len_t	bv_len;
107*0Sstevel@tonic-gate 	char		*bv_val;
108*0Sstevel@tonic-gate } BerValue;
109*0Sstevel@tonic-gate 
110*0Sstevel@tonic-gate #ifndef NEEDPROTOS
111*0Sstevel@tonic-gate extern BerElement *ber_alloc();
112*0Sstevel@tonic-gate extern BerElement *der_alloc();
113*0Sstevel@tonic-gate extern BerElement *ber_alloc_t();
114*0Sstevel@tonic-gate extern BerElement *ber_dup();
115*0Sstevel@tonic-gate extern BerElement *ber_init();
116*0Sstevel@tonic-gate extern int lber_debug;
117*0Sstevel@tonic-gate extern void ber_bvfree();
118*0Sstevel@tonic-gate extern void ber_bvecfree();
119*0Sstevel@tonic-gate extern struct berval *ber_bvdup();
120*0Sstevel@tonic-gate extern void ber_dump();
121*0Sstevel@tonic-gate extern void ber_sos_dump();
122*0Sstevel@tonic-gate extern void lber_bprint();
123*0Sstevel@tonic-gate extern void ber_reset();
124*0Sstevel@tonic-gate extern void ber_zero_init();
125*0Sstevel@tonic-gate #else /* NEEDPROTOS */
126*0Sstevel@tonic-gate 
127*0Sstevel@tonic-gate /*
128*0Sstevel@tonic-gate  * in bprint.c:
129*0Sstevel@tonic-gate  */
130*0Sstevel@tonic-gate void lber_bprint(char *data, int len);
131*0Sstevel@tonic-gate 
132*0Sstevel@tonic-gate /*
133*0Sstevel@tonic-gate  * in decode.c:
134*0Sstevel@tonic-gate  */
135*0Sstevel@tonic-gate ber_tag_t ber_get_tag(BerElement *ber);
136*0Sstevel@tonic-gate ber_tag_t ber_skip_tag(BerElement *ber, ber_len_t *len);
137*0Sstevel@tonic-gate ber_tag_t ber_peek_tag(BerElement *ber, ber_len_t *len);
138*0Sstevel@tonic-gate unsigned int ber_get_int(BerElement *ber, int *num);
139*0Sstevel@tonic-gate unsigned int ber_get_stringb(BerElement *ber, char *buf,
140*0Sstevel@tonic-gate 	ber_len_t *len);
141*0Sstevel@tonic-gate unsigned int ber_get_stringa(BerElement *ber, char **buf);
142*0Sstevel@tonic-gate unsigned int ber_get_stringal(BerElement *ber, struct berval **bv);
143*0Sstevel@tonic-gate unsigned int ber_get_bitstringa(BerElement *ber, char **buf,
144*0Sstevel@tonic-gate 	ber_len_t *len);
145*0Sstevel@tonic-gate unsigned int ber_get_null(BerElement *ber);
146*0Sstevel@tonic-gate unsigned int ber_get_boolean(BerElement *ber, int *boolval);
147*0Sstevel@tonic-gate ber_tag_t ber_first_element(BerElement *ber, ber_len_t *len,
148*0Sstevel@tonic-gate 	char **last);
149*0Sstevel@tonic-gate ber_tag_t ber_next_element(BerElement *ber, ber_len_t *len,
150*0Sstevel@tonic-gate 	char *last);
151*0Sstevel@tonic-gate #if defined(MACOS) || defined(BC31) || defined(_WIN32) || defined(__sun)
152*0Sstevel@tonic-gate ber_tag_t ber_scanf(BerElement *ber, char *fmt, ...);
153*0Sstevel@tonic-gate #else
154*0Sstevel@tonic-gate ber_tag_t ber_scanf();
155*0Sstevel@tonic-gate #endif
156*0Sstevel@tonic-gate void ber_bvfree(struct berval *bv);
157*0Sstevel@tonic-gate void ber_bvecfree(struct berval **bv);
158*0Sstevel@tonic-gate struct berval *ber_bvdup(struct berval *bv);
159*0Sstevel@tonic-gate #ifdef STR_TRANSLATION
160*0Sstevel@tonic-gate void ber_set_string_translators(BerElement *ber,
161*0Sstevel@tonic-gate 	BERTranslateProc encode_proc, BERTranslateProc decode_proc);
162*0Sstevel@tonic-gate #endif /* STR_TRANSLATION */
163*0Sstevel@tonic-gate int ber_flatten(BerElement *ber, struct berval **bvPtr);
164*0Sstevel@tonic-gate 
165*0Sstevel@tonic-gate /*
166*0Sstevel@tonic-gate  * in encode.c
167*0Sstevel@tonic-gate  */
168*0Sstevel@tonic-gate int ber_put_enum(BerElement *ber, int num, ber_tag_t tag);
169*0Sstevel@tonic-gate int ber_put_int(BerElement *ber, int num, ber_tag_t tag);
170*0Sstevel@tonic-gate int ber_put_ostring(BerElement *ber, char *str, ber_len_t len, ber_tag_t tag);
171*0Sstevel@tonic-gate int ber_put_string(BerElement *ber, char *str, ber_tag_t tag);
172*0Sstevel@tonic-gate int ber_put_bitstring(BerElement *ber, char *str,
173*0Sstevel@tonic-gate 	unsigned int bitlen, ber_tag_t tag);
174*0Sstevel@tonic-gate int ber_put_null(BerElement *ber, ber_tag_t tag);
175*0Sstevel@tonic-gate int ber_put_boolean(BerElement *ber, int boolval, ber_tag_t tag);
176*0Sstevel@tonic-gate int ber_start_seq(BerElement *ber, ber_tag_t tag);
177*0Sstevel@tonic-gate int ber_start_set(BerElement *ber, ber_tag_t tag);
178*0Sstevel@tonic-gate int ber_put_seq(BerElement *ber);
179*0Sstevel@tonic-gate int ber_put_set(BerElement *ber);
180*0Sstevel@tonic-gate #if defined(MACOS) || defined(BC31) || defined(_WIN32) || defined(__sun)
181*0Sstevel@tonic-gate int ber_printf(BerElement *ber, char *fmt, ...);
182*0Sstevel@tonic-gate #else
183*0Sstevel@tonic-gate int ber_printf();
184*0Sstevel@tonic-gate #endif
185*0Sstevel@tonic-gate 
186*0Sstevel@tonic-gate /*
187*0Sstevel@tonic-gate  * in io.c:
188*0Sstevel@tonic-gate  *
189*0Sstevel@tonic-gate  * ber_flush() and ber_get_next() functions are obsolete and removed
190*0Sstevel@tonic-gate  * from this library/header file
191*0Sstevel@tonic-gate  */
192*0Sstevel@tonic-gate int ber_read(BerElement *ber, char *buf, ber_len_t len);
193*0Sstevel@tonic-gate int ber_write(BerElement *ber, char *buf, ber_len_t len, int nosos);
194*0Sstevel@tonic-gate void ber_free(BerElement *ber, int freebuf);
195*0Sstevel@tonic-gate BerElement *ber_alloc(void);
196*0Sstevel@tonic-gate BerElement *der_alloc(void);
197*0Sstevel@tonic-gate BerElement *ber_alloc_t(int options);
198*0Sstevel@tonic-gate BerElement *ber_dup(BerElement *ber);
199*0Sstevel@tonic-gate BerElement *ber_init(struct berval *bv);
200*0Sstevel@tonic-gate void ber_dump(BerElement *ber, int inout);
201*0Sstevel@tonic-gate void ber_sos_dump(Seqorset *sos);
202*0Sstevel@tonic-gate void ber_zero_init(BerElement *ber, int options);
203*0Sstevel@tonic-gate void ber_reset(BerElement *ber, int was_writing);
204*0Sstevel@tonic-gate 
205*0Sstevel@tonic-gate #ifdef NEEDGETOPT
206*0Sstevel@tonic-gate /*
207*0Sstevel@tonic-gate  * in getopt.c
208*0Sstevel@tonic-gate  */
209*0Sstevel@tonic-gate int getopt(int nargc, char **nargv, char *ostr);
210*0Sstevel@tonic-gate #endif /* NEEDGETOPT */
211*0Sstevel@tonic-gate #endif /* NEEDPROTOS */
212*0Sstevel@tonic-gate 
213*0Sstevel@tonic-gate #define	LBER_HTONL(l) htonl(l)
214*0Sstevel@tonic-gate #define	LBER_NTOHL(l) ntohl(l)
215*0Sstevel@tonic-gate 
216*0Sstevel@tonic-gate /*
217*0Sstevel@tonic-gate  * SAFEMEMCPY is an overlap-safe copy from s to d of n bytes
218*0Sstevel@tonic-gate  */
219*0Sstevel@tonic-gate #ifdef sunos4
220*0Sstevel@tonic-gate #define	SAFEMEMCPY(d, s, n)	bcopy(s, d, n)
221*0Sstevel@tonic-gate #else /* sunos4 */
222*0Sstevel@tonic-gate #define	SAFEMEMCPY(d, s, n)	memmove(d, s, n)
223*0Sstevel@tonic-gate #endif /* sunos4 */
224*0Sstevel@tonic-gate 
225*0Sstevel@tonic-gate #ifdef SUN
226*0Sstevel@tonic-gate 
227*0Sstevel@tonic-gate /* I18N support */
228*0Sstevel@tonic-gate #include <locale.h>
229*0Sstevel@tonic-gate #include <nl_types.h>
230*0Sstevel@tonic-gate 
231*0Sstevel@tonic-gate extern	nl_catd	slapdcat;		/* for I18N support */
232*0Sstevel@tonic-gate extern void i18n_catopen(char *);
233*0Sstevel@tonic-gate 
234*0Sstevel@tonic-gate #endif
235*0Sstevel@tonic-gate 
236*0Sstevel@tonic-gate #ifdef __cplusplus
237*0Sstevel@tonic-gate }
238*0Sstevel@tonic-gate #endif
239*0Sstevel@tonic-gate 
240*0Sstevel@tonic-gate #endif /* _LBER_H */
241