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