2 * Copyright (c) 1990 Regents of the University of Michigan.
5 * Redistribution and use in source and binary forms are permitted
6 * provided that this notice is preserved and that due credit is given
7 * to the University of Michigan at Ann Arbor. The name of the University
8 * may not be used to endorse or promote products derived from this
9 * software without specific prior written permission. This software
10 * is provided ``as is'' without express or implied warranty.
16 #include <ldap_cdefs.h>
20 /* BER classes and mask */
21 #define LBER_CLASS_UNIVERSAL 0x00
22 #define LBER_CLASS_APPLICATION 0x40
23 #define LBER_CLASS_CONTEXT 0x80
24 #define LBER_CLASS_PRIVATE 0xc0
25 #define LBER_CLASS_MASK 0xc0
27 /* BER encoding type and mask */
28 #define LBER_PRIMITIVE 0x00
29 #define LBER_CONSTRUCTED 0x20
30 #define LBER_ENCODING_MASK 0x20
32 #define LBER_BIG_TAG_MASK 0x1f
33 #define LBER_MORE_TAG_MASK 0x80
36 * Note that LBER_ERROR and LBER_DEFAULT are values that can never appear
37 * as valid BER tags, and so it is safe to use them to report errors. In
38 * fact, any tag for which the following is true is invalid:
39 * (( tag & 0x00000080 ) != 0 ) && (( tag & 0xFFFFFF00 ) != 0 )
41 #define LBER_ERROR 0xffffffffL
42 #define LBER_DEFAULT 0xffffffffL
44 /* general BER types we know about */
45 #define LBER_BOOLEAN 0x01L
46 #define LBER_INTEGER 0x02L
47 #define LBER_BITSTRING 0x03L
48 #define LBER_OCTETSTRING 0x04L
49 #define LBER_NULL 0x05L
50 #define LBER_ENUMERATED 0x0aL
51 #define LBER_SEQUENCE 0x30L /* constructed */
52 #define LBER_SET 0x31L /* constructed */
54 #define OLD_LBER_SEQUENCE 0x10L /* w/o constructed bit - broken */
55 #define OLD_LBER_SET 0x11L /* w/o constructed bit - broken */
57 typedef int (*BERTranslateProc) LDAP_P(( char **bufp,
58 unsigned long *buflenp,
61 typedef struct berelement {
65 struct seqorset *ber_sos;
66 unsigned long ber_tag;
67 unsigned long ber_len;
70 #define LBER_USE_DER 0x01
71 #define LBER_USE_INDEFINITE_LEN 0x02
72 #define LBER_TRANSLATE_STRINGS 0x04
74 BERTranslateProc ber_encode_translate_proc;
75 BERTranslateProc ber_decode_translate_proc;
77 #define NULLBER ((BerElement *) 0)
79 typedef struct sockbuf {
87 int sb_naddr; /* > 0 implies using CLDAP (UDP) */
88 void *sb_useaddr; /* pointer to sockaddr to use next */
89 void *sb_fromaddr; /* pointer to message source sockaddr */
90 void **sb_addrs; /* actually an array of pointers to
93 int sb_options; /* to support copying ber elements */
94 #define LBER_TO_FILE 0x01 /* to a file referenced by sb_fd */
95 #define LBER_TO_FILE_ONLY 0x02 /* only write to file, not network */
96 #define LBER_MAX_INCOMING_SIZE 0x04 /* impose limit on incoming stuff */
97 #define LBER_NO_READ_AHEAD 0x08 /* read only as much as requested */
101 #define READBUFSIZ 8192
103 typedef struct seqorset {
105 unsigned long sos_clen;
106 unsigned long sos_tag;
109 struct seqorset *sos_next;
111 #define NULLSEQORSET ((Seqorset *) 0)
113 /* structure for returning a sequence of octet strings + length */
115 unsigned long bv_len;
119 extern int lber_debug;
124 LDAP_F void lber_bprint LDAP_P(( char *data, int len ));
129 LDAP_F unsigned long ber_get_tag LDAP_P(( BerElement *ber ));
130 LDAP_F unsigned long ber_skip_tag LDAP_P(( BerElement *ber, unsigned long *len ));
131 LDAP_F unsigned long ber_peek_tag LDAP_P(( BerElement *ber, unsigned long *len ));
132 LDAP_F unsigned long ber_get_int LDAP_P(( BerElement *ber, long *num ));
133 LDAP_F unsigned long ber_get_stringb LDAP_P(( BerElement *ber, char *buf,
134 unsigned long *len ));
135 LDAP_F unsigned long ber_get_stringa LDAP_P(( BerElement *ber, char **buf ));
136 LDAP_F unsigned long ber_get_stringal LDAP_P(( BerElement *ber, struct berval **bv ));
137 LDAP_F unsigned long ber_get_bitstringa LDAP_P(( BerElement *ber, char **buf,
138 unsigned long *len ));
139 LDAP_F unsigned long ber_get_null LDAP_P(( BerElement *ber ));
140 LDAP_F unsigned long ber_get_boolean LDAP_P(( BerElement *ber, int *boolval ));
141 LDAP_F unsigned long ber_first_element LDAP_P(( BerElement *ber, unsigned long *len,
143 LDAP_F unsigned long ber_next_element LDAP_P(( BerElement *ber, unsigned long *len,
145 LDAP_F unsigned long ber_scanf LDAP_P(( BerElement *ber, char *fmt, ... ));
146 LDAP_F void ber_bvfree LDAP_P(( struct berval *bv ));
147 LDAP_F void ber_bvecfree LDAP_P(( struct berval **bv ));
148 LDAP_F struct berval *ber_bvdup LDAP_P(( struct berval *bv ));
149 LDAP_F void ber_set_string_translators LDAP_P(( BerElement *ber,
150 BERTranslateProc encode_proc, BERTranslateProc decode_proc ));
155 LDAP_F int ber_put_enum LDAP_P(( BerElement *ber, long num, unsigned long tag ));
156 LDAP_F int ber_put_int LDAP_P(( BerElement *ber, long num, unsigned long tag ));
157 LDAP_F int ber_put_ostring LDAP_P(( BerElement *ber, char *str, unsigned long len,
158 unsigned long tag ));
159 LDAP_F int ber_put_string LDAP_P(( BerElement *ber, char *str, unsigned long tag ));
160 LDAP_F int ber_put_bitstring LDAP_P(( BerElement *ber, char *str,
161 unsigned long bitlen, unsigned long tag ));
162 LDAP_F int ber_put_null LDAP_P(( BerElement *ber, unsigned long tag ));
163 LDAP_F int ber_put_boolean LDAP_P(( BerElement *ber, int boolval,
164 unsigned long tag ));
165 LDAP_F int ber_start_seq LDAP_P(( BerElement *ber, unsigned long tag ));
166 LDAP_F int ber_start_set LDAP_P(( BerElement *ber, unsigned long tag ));
167 LDAP_F int ber_put_seq LDAP_P(( BerElement *ber ));
168 LDAP_F int ber_put_set LDAP_P(( BerElement *ber ));
169 LDAP_F int ber_printf LDAP_P(( BerElement *ber, char *fmt, ... ));
174 LDAP_F long ber_read LDAP_P(( BerElement *ber, char *buf, unsigned long len ));
175 LDAP_F long ber_write LDAP_P(( BerElement *ber, char *buf, unsigned long len,
177 LDAP_F void ber_free LDAP_P(( BerElement *ber, int freebuf ));
178 LDAP_F int ber_flush LDAP_P(( Sockbuf *sb, BerElement *ber, int freeit ));
179 LDAP_F BerElement *ber_alloc LDAP_P(( void ));
180 LDAP_F BerElement *der_alloc LDAP_P(( void ));
181 LDAP_F BerElement *ber_alloc_t LDAP_P(( int options ));
182 LDAP_F BerElement *ber_dup LDAP_P(( BerElement *ber ));
183 LDAP_F void ber_dump LDAP_P(( BerElement *ber, int inout ));
184 LDAP_F void ber_sos_dump LDAP_P(( Seqorset *sos ));
185 LDAP_F unsigned long ber_get_next LDAP_P(( Sockbuf *sb, unsigned long *len,
187 LDAP_F void ber_init LDAP_P(( BerElement *ber, int options ));
188 LDAP_F void ber_reset LDAP_P(( BerElement *ber, int was_writing ));