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