]> git.sur5r.net Git - openldap/blob - include/ldap_pvt.h
happy new year
[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
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 /* abandon */
228 LDAP_F ( int ) ldap_pvt_discard LDAP_P((
229         struct ldap *ld, ber_int_t msgid ));
230
231 /* messages.c */
232 LDAP_F( BerElement * )
233 ldap_get_message_ber LDAP_P((
234         struct ldapmsg * ));
235
236 /* open */
237 LDAP_F (int) ldap_open_internal_connection LDAP_P((
238         struct ldap **ldp, ber_socket_t *fdp ));
239
240 /* search.c */
241 LDAP_F( int ) ldap_pvt_put_filter LDAP_P((
242         BerElement *ber,
243         const char *str ));
244
245 LDAP_F( char * )
246 ldap_pvt_find_wildcard LDAP_P(( const char *s ));
247
248 LDAP_F( ber_slen_t )
249 ldap_pvt_filter_value_unescape LDAP_P(( char *filter ));
250
251 LDAP_F( ber_len_t )
252 ldap_bv2escaped_filter_value_len LDAP_P(( struct berval *in ));
253
254 LDAP_F( int )
255 ldap_bv2escaped_filter_value_x LDAP_P(( struct berval *in, struct berval *out,
256         int inplace, void *ctx ));
257
258 /* string.c */
259 LDAP_F( char * )
260 ldap_pvt_str2upper LDAP_P(( char *str ));
261
262 LDAP_F( char * )
263 ldap_pvt_str2lower LDAP_P(( char *str ));
264
265 LDAP_F( struct berval * )
266 ldap_pvt_str2upperbv LDAP_P(( char *str, struct berval *bv ));
267
268 LDAP_F( struct berval * )
269 ldap_pvt_str2lowerbv LDAP_P(( char *str, struct berval *bv ));
270
271 /* tls.c */
272 LDAP_F (int) ldap_int_tls_config LDAP_P(( struct ldap *ld,
273         int option, const char *arg ));
274 LDAP_F (int) ldap_pvt_tls_get_option LDAP_P(( struct ldap *ld,
275         int option, void *arg ));
276 LDAP_F (int) ldap_pvt_tls_set_option LDAP_P(( struct ldap *ld,
277         int option, void *arg ));
278
279 LDAP_F (void) ldap_pvt_tls_destroy LDAP_P(( void ));
280 LDAP_F (int) ldap_pvt_tls_init LDAP_P(( void ));
281 LDAP_F (int) ldap_pvt_tls_init_def_ctx LDAP_P(( int is_server ));
282 LDAP_F (int) ldap_pvt_tls_accept LDAP_P(( Sockbuf *sb, void *ctx_arg ));
283 LDAP_F (int) ldap_pvt_tls_inplace LDAP_P(( Sockbuf *sb ));
284 LDAP_F (void *) ldap_pvt_tls_sb_ctx LDAP_P(( Sockbuf *sb ));
285
286 LDAP_F (int) ldap_pvt_tls_init_default_ctx LDAP_P(( void ));
287
288 typedef int LDAPDN_rewrite_dummy LDAP_P (( void *dn, unsigned flags ));
289
290 typedef int (LDAP_TLS_CONNECT_CB) LDAP_P (( struct ldap *ld, void *ssl,
291         void *ctx, void *arg ));
292
293 LDAP_F (int) ldap_pvt_tls_get_my_dn LDAP_P(( void *ctx, struct berval *dn,
294         LDAPDN_rewrite_dummy *func, unsigned flags ));
295 LDAP_F (int) ldap_pvt_tls_get_peer_dn LDAP_P(( void *ctx, struct berval *dn,
296         LDAPDN_rewrite_dummy *func, unsigned flags ));
297 LDAP_F (int) ldap_pvt_tls_get_strength LDAP_P(( void *ctx ));
298
299 LDAP_END_DECL
300
301 /*
302  * Multiple precision stuff
303  * 
304  * May use OpenSSL's BIGNUM if built with TLS,
305  * or GNU's multiple precision library. But if
306  * long long is available, that's big enough
307  * and much more efficient.
308  *
309  * If none is available, unsigned long data is used.
310  */
311
312 #if USE_MP_BIGNUM
313 /*
314  * Use OpenSSL's BIGNUM
315  */
316 #include <openssl/crypto.h>
317 #include <openssl/bn.h>
318
319 typedef BIGNUM* ldap_pvt_mp_t;
320 #define LDAP_PVT_MP_INIT        (NULL)
321
322 #define ldap_pvt_mp_init(mp) \
323         do { (mp) = BN_new(); } while (0)
324
325 /* FIXME: we rely on mpr being initialized */
326 #define ldap_pvt_mp_init_set(mpr,mpv) \
327         do { ldap_pvt_mp_init((mpr)); BN_add((mpr), (mpr), (mpv)); } while (0)
328
329 #define ldap_pvt_mp_add(mpr,mpv) \
330         BN_add((mpr), (mpr), (mpv))
331
332 #define ldap_pvt_mp_add_ulong(mp,v) \
333         BN_add_word((mp), (v))
334
335 #define ldap_pvt_mp_clear(mp) \
336         do { BN_free((mp)); (mp) = 0; } while (0)
337
338 #elif USE_MP_GMP
339 /*
340  * Use GNU's multiple precision library
341  */
342 #include <gmp.h>
343
344 typedef mpz_t           ldap_pvt_mp_t;
345 #define LDAP_PVT_MP_INIT        { 0 }
346
347 #define ldap_pvt_mp_init(mp) \
348         mpz_init((mp))
349
350 #define ldap_pvt_mp_init_set(mpr,mpv) \
351         mpz_init_set((mpr), (mpv))
352
353 #define ldap_pvt_mp_add(mpr,mpv) \
354         mpz_add((mpr), (mpr), (mpv))
355
356 #define ldap_pvt_mp_add_ulong(mp,v)     \
357         mpz_add_ui((mp), (mp), (v))
358
359 #define ldap_pvt_mp_clear(mp) \
360         mpz_clear((mp))
361
362 #else
363 /*
364  * Use unsigned long long
365  */
366
367 #if USE_MP_LONG_LONG
368 typedef unsigned long long      ldap_pvt_mp_t;
369 #define LDAP_PVT_MP_INIT        (0LL)
370 #elif USE_MP_LONG
371 typedef unsigned long           ldap_pvt_mp_t;
372 #define LDAP_PVT_MP_INIT        (0L)
373 #elif HAVE_LONG_LONG
374 typedef unsigned long long      ldap_pvt_mp_t;
375 #define LDAP_PVT_MP_INIT        (0LL)
376 #else
377 typedef unsigned long           ldap_pvt_mp_t;
378 #define LDAP_PVT_MP_INIT        (0L)
379 #endif
380
381 #define ldap_pvt_mp_init(mp) \
382         do { (mp) = 0; } while (0)
383
384 #define ldap_pvt_mp_init_set(mpr,mpv) \
385         do { (mpr) = (mpv); } while (0)
386
387 #define ldap_pvt_mp_add(mpr,mpv) \
388         do { (mpr) += (mpv); } while (0)
389
390 #define ldap_pvt_mp_add_ulong(mp,v) \
391         do { (mp) += (v); } while (0)
392
393 #define ldap_pvt_mp_clear(mp) \
394         do { (mp) = 0; } while (0)
395
396 #endif /* MP */
397
398 #include "ldap_pvt_uc.h"
399
400 #endif /* _LDAP_PVT_H */