Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/libs/ldap/liblber/lber-int.h
4394 views
1
/* $OpenLDAP$ */
2
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3
*
4
* Copyright 1998-2024 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 the 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_INT_H
27
#define _LBER_INT_H
28
29
#include "lber.h"
30
#define LDAP_INT_DEBUG
31
#include "ldap_log.h"
32
#include "lber_pvt.h"
33
#include "ldap_queue.h"
34
35
LDAP_BEGIN_DECL
36
37
typedef void (*BER_LOG_FN)(FILE *file,
38
const char *subsys, int level, const char *fmt, ... );
39
40
LBER_V (BER_ERRNO_FN) ber_int_errno_fn;
41
42
#ifdef LDAP_MEMORY_TRACE
43
# ifndef LDAP_MEMORY_DEBUG
44
# define LDAP_MEMORY_DEBUG 1
45
# endif
46
#endif
47
48
#ifdef LDAP_MEMORY_DEBUG
49
LBER_V (long) ber_int_meminuse;
50
#endif
51
#if defined(LDAP_MEMORY_DEBUG) && ((LDAP_MEMORY_DEBUG +0) & 2)
52
# define LDAP_MEMORY_DEBUG_ASSERT assert
53
#else
54
# define LDAP_MEMORY_DEBUG_ASSERT(expr) ((void) 0)
55
#endif
56
57
struct lber_options {
58
short lbo_valid;
59
unsigned short lbo_options;
60
int lbo_debug;
61
};
62
63
LBER_F( int ) ber_pvt_log_output(
64
const char *subsystem,
65
int level,
66
const char *fmt, ... );
67
68
#define LBER_UNINITIALIZED 0x0
69
#define LBER_INITIALIZED 0x1
70
#define LBER_VALID_BERELEMENT 0x2
71
#define LBER_VALID_SOCKBUF 0x3
72
73
LBER_V (struct lber_options) ber_int_options;
74
#define ber_int_debug ber_int_options.lbo_debug
75
76
/* Data encoded in ASN.1 BER format */
77
struct berelement {
78
struct lber_options ber_opts;
79
#define ber_valid ber_opts.lbo_valid
80
#define ber_options ber_opts.lbo_options
81
#define ber_debug ber_opts.lbo_debug
82
83
/*
84
* The members below, when not NULL/LBER_DEFAULT/etc, are:
85
* ber_buf Data buffer. Other pointers normally point into it.
86
* ber_rwptr Read/write cursor for Sockbuf I/O.
87
* ber_memctx Context passed to ber_memalloc() & co.
88
* When decoding data (reading it from the BerElement):
89
* ber_end End of BER data.
90
* ber_ptr Read cursor, except for 1st octet of tags.
91
* ber_tag 1st octet of next tag, saved from *ber_ptr when
92
* ber_ptr may be pointing at a tag and is >ber_buf.
93
* The octet *ber_ptr itself may get overwritten with
94
* a \0, to terminate the preceding element.
95
* When encoding data (writing it to the BerElement):
96
* ber_end End of allocated buffer - 1 (allowing a final \0).
97
* ber_ptr Last complete BER element (normally write cursor).
98
* ber_sos_ptr NULL or write cursor for incomplete sequence or set.
99
* ber_sos_inner offset(seq/set length octets) if ber_sos_ptr!=NULL.
100
* ber_tag Default tag for next ber_printf() element.
101
* ber_usertag Boolean set by ber_printf "!" if it sets ber_tag.
102
* ber_len Reused for ber_sos_inner.
103
* When output to a Sockbuf:
104
* ber_ptr End of encoded data to write.
105
* When input from a Sockbuf:
106
* See ber_get_next().
107
*/
108
109
/* Do not change the order of these 3 fields! see ber_get_next */
110
ber_tag_t ber_tag;
111
ber_len_t ber_len;
112
ber_tag_t ber_usertag;
113
114
char *ber_buf;
115
char *ber_ptr;
116
char *ber_end;
117
118
char *ber_sos_ptr;
119
# define ber_sos_inner ber_len /* reused for binary compat */
120
121
char *ber_rwptr;
122
void *ber_memctx;
123
};
124
#define LBER_VALID(ber) ((ber)->ber_valid==LBER_VALID_BERELEMENT)
125
126
#define ber_pvt_ber_remaining(ber) ((ber)->ber_end - (ber)->ber_ptr)
127
#define ber_pvt_ber_total(ber) ((ber)->ber_end - (ber)->ber_buf)
128
#define ber_pvt_ber_write(ber) ((ber)->ber_ptr - (ber)->ber_buf)
129
130
struct sockbuf {
131
struct lber_options sb_opts;
132
Sockbuf_IO_Desc *sb_iod; /* I/O functions */
133
#define sb_valid sb_opts.lbo_valid
134
#define sb_options sb_opts.lbo_options
135
#define sb_debug sb_opts.lbo_debug
136
ber_socket_t sb_fd;
137
ber_len_t sb_max_incoming;
138
unsigned int sb_trans_needs_read:1;
139
unsigned int sb_trans_needs_write:1;
140
#ifdef LDAP_PF_LOCAL_SENDMSG
141
char sb_ungetlen;
142
char sb_ungetbuf[8];
143
#endif
144
};
145
146
#define SOCKBUF_VALID( sb ) ( (sb)->sb_valid == LBER_VALID_SOCKBUF )
147
148
149
/*
150
* decode.c, encode.c
151
*/
152
153
/* Simplest OID max-DER-component to implement in both decode and encode */
154
#define LBER_OID_COMPONENT_MAX ((unsigned long)-1 - 128)
155
156
157
/*
158
* io.c
159
*/
160
LBER_F( int )
161
ber_realloc LDAP_P((
162
BerElement *ber,
163
ber_len_t len ));
164
165
LBER_F (char *) ber_start LDAP_P(( BerElement * ));
166
LBER_F (int) ber_len LDAP_P(( BerElement * ));
167
LBER_F (int) ber_ptrlen LDAP_P(( BerElement * ));
168
LBER_F (void) ber_rewind LDAP_P(( BerElement * ));
169
170
/*
171
* bprint.c
172
*/
173
#define ber_log_printf ber_pvt_log_printf
174
175
LBER_F( int )
176
ber_log_bprint LDAP_P((
177
int errlvl,
178
int loglvl,
179
const char *data,
180
ber_len_t len ));
181
182
LBER_F( int )
183
ber_log_dump LDAP_P((
184
int errlvl,
185
int loglvl,
186
BerElement *ber,
187
int inout ));
188
189
LBER_V (BER_LOG_FN) ber_int_log_proc;
190
LBER_V (FILE *) ber_pvt_err_file;
191
192
/* memory.c */
193
/* simple macros to realloc for now */
194
LBER_V (BerMemoryFunctions *) ber_int_memory_fns;
195
LBER_F (char *) ber_strndup( LDAP_CONST char *, ber_len_t );
196
LBER_F (char *) ber_strndup_x( LDAP_CONST char *, ber_len_t, void *ctx );
197
198
#define LBER_MALLOC(s) ber_memalloc((s))
199
#define LBER_CALLOC(n,s) ber_memcalloc((n),(s))
200
#define LBER_REALLOC(p,s) ber_memrealloc((p),(s))
201
#define LBER_FREE(p) ber_memfree((p))
202
#define LBER_VFREE(v) ber_memvfree((void**)(v))
203
#define LBER_STRDUP(s) ber_strdup((s))
204
#define LBER_STRNDUP(s,l) ber_strndup((s),(l))
205
206
/* sockbuf.c */
207
208
LBER_F( int )
209
ber_int_sb_init LDAP_P(( Sockbuf *sb ));
210
211
LBER_F( int )
212
ber_int_sb_close LDAP_P(( Sockbuf *sb ));
213
214
LBER_F( int )
215
ber_int_sb_destroy LDAP_P(( Sockbuf *sb ));
216
217
LBER_F( ber_slen_t )
218
ber_int_sb_read LDAP_P(( Sockbuf *sb, void *buf, ber_len_t len ));
219
220
LBER_F( ber_slen_t )
221
ber_int_sb_write LDAP_P(( Sockbuf *sb, void *buf, ber_len_t len ));
222
223
LDAP_END_DECL
224
225
#endif /* _LBER_INT_H */
226
227