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