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