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