]> git.sur5r.net Git - openldap/blob - include/ldap_pvt.h
handle errors
[openldap] / include / ldap_pvt.h
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  * 
4  * Copyright 1998-2006 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
16 /* ldap-pvt.h - Header for ldap_pvt_ functions.
17  * These are meant to be internal to OpenLDAP Software.
18  */
19
20 #ifndef _LDAP_PVT_H
21 #define _LDAP_PVT_H 1
22
23 #include <lber.h>                               /* get ber_slen_t */
24
25 LDAP_BEGIN_DECL
26
27 #define LDAP_PROTO_TCP 1 /* ldap://  */
28 #define LDAP_PROTO_UDP 2 /* reserved */
29 #define LDAP_PROTO_IPC 3 /* ldapi:// */
30
31 LDAP_F ( int )
32 ldap_pvt_url_scheme2proto LDAP_P((
33         const char * ));
34 LDAP_F ( int )
35 ldap_pvt_url_scheme2tls LDAP_P((
36         const char * ));
37
38 LDAP_F ( int )
39 ldap_pvt_url_scheme_port LDAP_P((
40         const char *, int ));
41
42 struct ldap_url_desc; /* avoid pulling in <ldap.h> */
43
44 #define LDAP_PVT_URL_PARSE_NONE                 (0x00U)
45 #define LDAP_PVT_URL_PARSE_NOEMPTY_HOST         (0x01U)
46 #define LDAP_PVT_URL_PARSE_DEF_PORT             (0x02U)
47 #define LDAP_PVT_URL_PARSE_NOEMPTY_DN           (0x04U)
48 #define LDAP_PVT_URL_PARSE_NODEF_SCOPE          (0x08U)
49 #define LDAP_PVT_URL_PARSE_HISTORIC             (LDAP_PVT_URL_PARSE_NODEF_SCOPE | LDAP_PVT_URL_PARSE_NOEMPTY_HOST | LDAP_PVT_URL_PARSE_DEF_PORT)
50 LDAP_F( int )
51 ldap_url_parse_ext LDAP_P((
52         LDAP_CONST char *url,
53         struct ldap_url_desc **ludpp,
54         unsigned flags ));
55
56 LDAP_F (int) ldap_url_parselist_ext LDAP_P((
57         struct ldap_url_desc **ludlist,
58         const char *url,
59         const char *sep,
60         unsigned flags ));
61
62 LDAP_F (char *) ldap_url_list2urls LDAP_P((
63         struct ldap_url_desc *ludlist ));
64
65 LDAP_F (void) ldap_free_urllist LDAP_P((
66         struct ldap_url_desc *ludlist ));
67
68 LDAP_F (int) ldap_pvt_scope2bv LDAP_P ((
69         int scope, struct berval *bv ));
70
71 LDAP_F (LDAP_CONST char *) ldap_pvt_scope2str LDAP_P ((
72         int scope ));
73
74 LDAP_F (int) ldap_pvt_bv2scope LDAP_P ((
75         struct berval *bv ));
76
77 LDAP_F (int) ldap_pvt_str2scope LDAP_P ((
78         LDAP_CONST char * ));
79
80 LDAP_F( char * )
81 ldap_pvt_ctime LDAP_P((
82         const time_t *tp,
83         char *buf ));
84
85 LDAP_F( char *) ldap_pvt_get_fqdn LDAP_P(( char * ));
86
87 struct hostent; /* avoid pulling in <netdb.h> */
88
89 LDAP_F( int )
90 ldap_pvt_gethostbyname_a LDAP_P((
91         const char *name,
92         struct hostent *resbuf,
93         char **buf,
94         struct hostent **result,
95         int *herrno_ptr ));
96
97 LDAP_F( int )
98 ldap_pvt_gethostbyaddr_a LDAP_P((
99         const char *addr,
100         int len,
101         int type,
102         struct hostent *resbuf,
103         char **buf,
104         struct hostent **result,
105         int *herrno_ptr ));
106
107 struct sockaddr;
108
109 LDAP_F( int )
110 ldap_pvt_get_hname LDAP_P((
111         const struct sockaddr * sa,
112         int salen,
113         char *name,
114         int namelen,
115         char **herr ));
116
117
118 /* charray.c */
119
120 LDAP_F( int )
121 ldap_charray_add LDAP_P((
122     char        ***a,
123     const char *s ));
124
125 LDAP_F( int )
126 ldap_charray_merge LDAP_P((
127     char        ***a,
128     char        **s ));
129
130 LDAP_F( void )
131 ldap_charray_free LDAP_P(( char **a ));
132
133 LDAP_F( int )
134 ldap_charray_inlist LDAP_P((
135     char        **a,
136     const char *s ));
137
138 LDAP_F( char ** )
139 ldap_charray_dup LDAP_P(( char **a ));
140
141 LDAP_F( char ** )
142 ldap_str2charray LDAP_P((
143         const char *str,
144         const char *brkstr ));
145
146 LDAP_F( char * )
147 ldap_charray2str LDAP_P((
148         char **array, const char* sep ));
149
150 /* getdn.c */
151
152 #ifdef LDAP_AVA_NULL    /* in ldap.h */
153 LDAP_F( void ) ldap_rdnfree_x LDAP_P(( LDAPRDN rdn, void *ctx ));
154 LDAP_F( void ) ldap_dnfree_x LDAP_P(( LDAPDN dn, void *ctx ));
155
156 LDAP_F( int ) ldap_bv2dn_x LDAP_P(( 
157         struct berval *bv, LDAPDN *dn, unsigned flags, void *ctx ));
158 LDAP_F( int ) ldap_dn2bv_x LDAP_P(( 
159         LDAPDN dn, struct berval *bv, unsigned flags, void *ctx ));
160 LDAP_F( int ) ldap_bv2rdn_x LDAP_P(( 
161         struct berval *, LDAPRDN *, char **, unsigned flags, void *ctx ));
162 LDAP_F( int ) ldap_rdn2bv_x LDAP_P(( 
163         LDAPRDN rdn, struct berval *bv, unsigned flags, void *ctx ));
164 #endif
165
166 /* url.c */
167 LDAP_F (void) ldap_pvt_hex_unescape LDAP_P(( char *s ));
168
169 /*
170  * these macros assume 'x' is an ASCII x
171  * and assume the "C" locale
172  */
173 #define LDAP_ASCII(c)           (!((c) & 0x80))
174 #define LDAP_SPACE(c)           ((c) == ' ' || (c) == '\t' || (c) == '\n')
175 #define LDAP_DIGIT(c)           ((c) >= '0' && (c) <= '9')
176 #define LDAP_LOWER(c)           ((c) >= 'a' && (c) <= 'z')
177 #define LDAP_UPPER(c)           ((c) >= 'A' && (c) <= 'Z')
178 #define LDAP_ALPHA(c)           (LDAP_LOWER(c) || LDAP_UPPER(c))
179 #define LDAP_ALNUM(c)           (LDAP_ALPHA(c) || LDAP_DIGIT(c))
180
181 #define LDAP_LDH(c)                     (LDAP_ALNUM(c) || (c) == '-')
182
183 #define LDAP_HEXLOWER(c)        ((c) >= 'a' && (c) <= 'f')
184 #define LDAP_HEXUPPER(c)        ((c) >= 'A' && (c) <= 'F')
185 #define LDAP_HEX(c)                     (LDAP_DIGIT(c) || \
186                                                                 LDAP_HEXLOWER(c) || LDAP_HEXUPPER(c))
187
188 /* controls.c */
189 struct ldapcontrol;
190 LDAP_F (struct ldapcontrol *) ldap_control_dup LDAP_P((
191         const struct ldapcontrol *ctrl ));
192
193 LDAP_F (struct ldapcontrol **) ldap_controls_dup LDAP_P((
194         struct ldapcontrol *const *ctrls ));
195
196 LDAP_F (int) ldap_pvt_get_controls LDAP_P((
197         BerElement *be,
198         struct ldapcontrol ***ctrlsp));
199
200 #ifdef HAVE_CYRUS_SASL
201 /* cyrus.c */
202 struct sasl_security_properties; /* avoid pulling in <sasl.h> */
203 LDAP_F (int) ldap_pvt_sasl_secprops LDAP_P((
204         const char *in,
205         struct sasl_security_properties *secprops ));
206 LDAP_F (void) ldap_pvt_sasl_secprops_unparse LDAP_P((
207         struct sasl_security_properties *secprops,
208         struct berval *out ));
209
210 LDAP_F (void *) ldap_pvt_sasl_mutex_new LDAP_P((void));
211 LDAP_F (int) ldap_pvt_sasl_mutex_lock LDAP_P((void *mutex));
212 LDAP_F (int) ldap_pvt_sasl_mutex_unlock LDAP_P((void *mutex));
213 LDAP_F (void) ldap_pvt_sasl_mutex_dispose LDAP_P((void *mutex));
214
215 struct sockbuf; /* avoid pulling in <lber.h> */
216 LDAP_F (int) ldap_pvt_sasl_install LDAP_P(( struct sockbuf *, void * ));
217 LDAP_F (void) ldap_pvt_sasl_remove LDAP_P(( struct sockbuf * ));
218 #endif /* HAVE_CYRUS_SASL */
219
220 #ifndef LDAP_PVT_SASL_LOCAL_SSF
221 #define LDAP_PVT_SASL_LOCAL_SSF 71      /* SSF for Unix Domain Sockets */
222 #endif
223
224 struct ldap;
225 struct ldapmsg;
226
227 LDAP_F (int) ldap_open_internal_connection LDAP_P((
228         struct ldap **ldp, ber_socket_t *fdp ));
229
230 /* messages.c */
231 LDAP_F( BerElement * )
232 ldap_get_message_ber LDAP_P((
233         struct ldapmsg * ));
234
235 /* search.c */
236 LDAP_F( int ) ldap_pvt_put_filter LDAP_P((
237         BerElement *ber,
238         const char *str ));
239
240 LDAP_F( char * )
241 ldap_pvt_find_wildcard LDAP_P(( const char *s ));
242
243 LDAP_F( ber_slen_t )
244 ldap_pvt_filter_value_unescape LDAP_P(( char *filter ));
245
246 LDAP_F( ber_len_t )
247 ldap_bv2escaped_filter_value_len LDAP_P(( struct berval *in ));
248
249 LDAP_F( int )
250 ldap_bv2escaped_filter_value_x LDAP_P(( struct berval *in, struct berval *out,
251         int inplace, void *ctx ));
252
253 /* string.c */
254 LDAP_F( char * )
255 ldap_pvt_str2upper LDAP_P(( char *str ));
256
257 LDAP_F( char * )
258 ldap_pvt_str2lower LDAP_P(( char *str ));
259
260 LDAP_F( struct berval * )
261 ldap_pvt_str2upperbv LDAP_P(( char *str, struct berval *bv ));
262
263 LDAP_F( struct berval * )
264 ldap_pvt_str2lowerbv LDAP_P(( char *str, struct berval *bv ));
265
266 /* tls.c */
267 LDAP_F (int) ldap_int_tls_config LDAP_P(( struct ldap *ld,
268         int option, const char *arg ));
269 LDAP_F (int) ldap_pvt_tls_get_option LDAP_P(( struct ldap *ld,
270         int option, void *arg ));
271 LDAP_F (int) ldap_pvt_tls_set_option LDAP_P(( struct ldap *ld,
272         int option, void *arg ));
273
274 LDAP_F (void) ldap_pvt_tls_destroy LDAP_P(( void ));
275 LDAP_F (int) ldap_pvt_tls_init LDAP_P(( void ));
276 LDAP_F (int) ldap_pvt_tls_init_def_ctx LDAP_P(( int is_server ));
277 LDAP_F (int) ldap_pvt_tls_accept LDAP_P(( Sockbuf *sb, void *ctx_arg ));
278 LDAP_F (int) ldap_pvt_tls_inplace LDAP_P(( Sockbuf *sb ));
279 LDAP_F (void *) ldap_pvt_tls_sb_ctx LDAP_P(( Sockbuf *sb ));
280
281 LDAP_F (int) ldap_pvt_tls_init_default_ctx LDAP_P(( void ));
282
283 typedef int LDAPDN_rewrite_dummy LDAP_P (( void *dn, unsigned flags ));
284
285 typedef int (LDAP_TLS_CONNECT_CB) LDAP_P (( struct ldap *ld, void *ssl,
286         void *ctx, void *arg ));
287
288 LDAP_F (int) ldap_pvt_tls_get_my_dn LDAP_P(( void *ctx, struct berval *dn,
289         LDAPDN_rewrite_dummy *func, unsigned flags ));
290 LDAP_F (int) ldap_pvt_tls_get_peer_dn LDAP_P(( void *ctx, struct berval *dn,
291         LDAPDN_rewrite_dummy *func, unsigned flags ));
292 LDAP_F (int) ldap_pvt_tls_get_strength LDAP_P(( void *ctx ));
293
294 LDAP_END_DECL
295
296 /*
297  * Multiple precision stuff
298  * 
299  * May use OpenSSL's BIGNUM if built with TLS,
300  * or GNU's multiple precision library. But if
301  * long long is available, that's big enough
302  * and much more efficient.
303  *
304  * If none is available, unsigned long data is used.
305  */
306
307 #if USE_MP_BIGNUM
308 /*
309  * Use OpenSSL's BIGNUM
310  */
311 #include <openssl/crypto.h>
312 #include <openssl/bn.h>
313
314 typedef BIGNUM* ldap_pvt_mp_t;
315 #define LDAP_PVT_MP_INIT        (NULL)
316
317 #define ldap_pvt_mp_init(mp) \
318         do { (mp) = BN_new(); } while (0)
319
320 /* FIXME: we rely on mpr being initialized */
321 #define ldap_pvt_mp_init_set(mpr,mpv) \
322         do { ldap_pvt_mp_init((mpr)); BN_add((mpr), (mpr), (mpv)); } while (0)
323
324 #define ldap_pvt_mp_add(mpr,mpv) \
325         BN_add((mpr), (mpr), (mpv))
326
327 #define ldap_pvt_mp_add_ulong(mp,v) \
328         BN_add_word((mp), (v))
329
330 #define ldap_pvt_mp_clear(mp) \
331         do { BN_free((mp)); (mp) = 0; } while (0)
332
333 #elif USE_MP_GMP
334 /*
335  * Use GNU's multiple precision library
336  */
337 #include <gmp.h>
338
339 typedef mpz_t           ldap_pvt_mp_t;
340 #define LDAP_PVT_MP_INIT        { 0 }
341
342 #define ldap_pvt_mp_init(mp) \
343         mpz_init((mp))
344
345 #define ldap_pvt_mp_init_set(mpr,mpv) \
346         mpz_init_set((mpr), (mpv))
347
348 #define ldap_pvt_mp_add(mpr,mpv) \
349         mpz_add((mpr), (mpr), (mpv))
350
351 #define ldap_pvt_mp_add_ulong(mp,v)     \
352         mpz_add_ui((mp), (mp), (v))
353
354 #define ldap_pvt_mp_clear(mp) \
355         mpz_clear((mp))
356
357 #else
358 /*
359  * Use unsigned long long
360  */
361
362 #if USE_MP_LONG_LONG
363 typedef unsigned long long      ldap_pvt_mp_t;
364 #define LDAP_PVT_MP_INIT        (0LL)
365 #elif USE_MP_LONG
366 typedef unsigned long           ldap_pvt_mp_t;
367 #define LDAP_PVT_MP_INIT        (0L)
368 #elif HAVE_LONG_LONG
369 typedef unsigned long long      ldap_pvt_mp_t;
370 #define LDAP_PVT_MP_INIT        (0LL)
371 #else
372 typedef unsigned long           ldap_pvt_mp_t;
373 #define LDAP_PVT_MP_INIT        (0L)
374 #endif
375
376 #define ldap_pvt_mp_init(mp) \
377         do { (mp) = 0; } while (0)
378
379 #define ldap_pvt_mp_init_set(mpr,mpv) \
380         do { (mpr) = (mpv); } while (0)
381
382 #define ldap_pvt_mp_add(mpr,mpv) \
383         do { (mpr) += (mpv); } while (0)
384
385 #define ldap_pvt_mp_add_ulong(mp,v) \
386         do { (mp) += (v); } while (0)
387
388 #define ldap_pvt_mp_clear(mp) \
389         do { (mp) = 0; } while (0)
390
391 #endif /* MP */
392
393 #include "ldap_pvt_uc.h"
394
395 #endif /* _LDAP_PVT_H */