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