]> git.sur5r.net Git - openldap/blob - include/ldap_pvt.h
ITS#6013 fix contextCSN check
[openldap] / include / ldap_pvt.h
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  * 
4  * Copyright 1998-2009 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 #include <lber_pvt.h>                           /* get Sockbuf_Buf */
25
26 LDAP_BEGIN_DECL
27
28 #define LDAP_PROTO_TCP 1 /* ldap://  */
29 #define LDAP_PROTO_UDP 2 /* reserved */
30 #define LDAP_PROTO_IPC 3 /* ldapi:// */
31 #define LDAP_PROTO_EXT 4 /* user-defined socket/sockbuf */
32
33 LDAP_F ( int )
34 ldap_pvt_url_scheme2proto LDAP_P((
35         const char * ));
36 LDAP_F ( int )
37 ldap_pvt_url_scheme2tls LDAP_P((
38         const char * ));
39
40 LDAP_F ( int )
41 ldap_pvt_url_scheme_port LDAP_P((
42         const char *, int ));
43
44 struct ldap_url_desc; /* avoid pulling in <ldap.h> */
45
46 #define LDAP_PVT_URL_PARSE_NONE                 (0x00U)
47 #define LDAP_PVT_URL_PARSE_NOEMPTY_HOST         (0x01U)
48 #define LDAP_PVT_URL_PARSE_DEF_PORT             (0x02U)
49 #define LDAP_PVT_URL_PARSE_NOEMPTY_DN           (0x04U)
50 #define LDAP_PVT_URL_PARSE_NODEF_SCOPE          (0x08U)
51 #define LDAP_PVT_URL_PARSE_HISTORIC             (LDAP_PVT_URL_PARSE_NODEF_SCOPE | \
52                                                  LDAP_PVT_URL_PARSE_NOEMPTY_HOST | \
53                                                  LDAP_PVT_URL_PARSE_DEF_PORT)
54
55 LDAP_F( int )
56 ldap_url_parse_ext LDAP_P((
57         LDAP_CONST char *url,
58         struct ldap_url_desc **ludpp,
59         unsigned flags ));
60
61 LDAP_F (int) ldap_url_parselist LDAP_P((        /* deprecated, use ldap_url_parselist_ext() */
62         struct ldap_url_desc **ludlist,
63         const char *url ));
64
65 LDAP_F (int) ldap_url_parselist_ext LDAP_P((
66         struct ldap_url_desc **ludlist,
67         const char *url,
68         const char *sep,
69         unsigned flags ));
70
71 LDAP_F (char *) ldap_url_list2urls LDAP_P((
72         struct ldap_url_desc *ludlist ));
73
74 LDAP_F (void) ldap_free_urllist LDAP_P((
75         struct ldap_url_desc *ludlist ));
76
77 LDAP_F (int) ldap_pvt_scope2bv LDAP_P ((
78         int scope, struct berval *bv ));
79
80 LDAP_F (LDAP_CONST char *) ldap_pvt_scope2str LDAP_P ((
81         int scope ));
82
83 LDAP_F (int) ldap_pvt_bv2scope LDAP_P ((
84         struct berval *bv ));
85
86 LDAP_F (int) ldap_pvt_str2scope LDAP_P ((
87         LDAP_CONST char * ));
88
89 LDAP_F( char * )
90 ldap_pvt_ctime LDAP_P((
91         const time_t *tp,
92         char *buf ));
93
94 LDAP_F( char *) ldap_pvt_get_fqdn LDAP_P(( char * ));
95
96 struct hostent; /* avoid pulling in <netdb.h> */
97
98 LDAP_F( int )
99 ldap_pvt_gethostbyname_a LDAP_P((
100         const char *name,
101         struct hostent *resbuf,
102         char **buf,
103         struct hostent **result,
104         int *herrno_ptr ));
105
106 LDAP_F( int )
107 ldap_pvt_gethostbyaddr_a LDAP_P((
108         const char *addr,
109         int len,
110         int type,
111         struct hostent *resbuf,
112         char **buf,
113         struct hostent **result,
114         int *herrno_ptr ));
115
116 struct sockaddr;
117
118 LDAP_F( int )
119 ldap_pvt_get_hname LDAP_P((
120         const struct sockaddr * sa,
121         int salen,
122         char *name,
123         int namelen,
124         char **herr ));
125
126
127 /* charray.c */
128
129 LDAP_F( int )
130 ldap_charray_add LDAP_P((
131     char        ***a,
132     const char *s ));
133
134 LDAP_F( int )
135 ldap_charray_merge LDAP_P((
136     char        ***a,
137     char        **s ));
138
139 LDAP_F( void )
140 ldap_charray_free LDAP_P(( char **a ));
141
142 LDAP_F( int )
143 ldap_charray_inlist LDAP_P((
144     char        **a,
145     const char *s ));
146
147 LDAP_F( char ** )
148 ldap_charray_dup LDAP_P(( char **a ));
149
150 LDAP_F( char ** )
151 ldap_str2charray LDAP_P((
152         const char *str,
153         const char *brkstr ));
154
155 LDAP_F( char * )
156 ldap_charray2str LDAP_P((
157         char **array, const char* sep ));
158
159 /* getdn.c */
160
161 #ifdef LDAP_AVA_NULL    /* in ldap.h */
162 LDAP_F( void ) ldap_rdnfree_x LDAP_P(( LDAPRDN rdn, void *ctx ));
163 LDAP_F( void ) ldap_dnfree_x LDAP_P(( LDAPDN dn, void *ctx ));
164
165 LDAP_F( int ) ldap_bv2dn_x LDAP_P(( 
166         struct berval *bv, LDAPDN *dn, unsigned flags, void *ctx ));
167 LDAP_F( int ) ldap_dn2bv_x LDAP_P(( 
168         LDAPDN dn, struct berval *bv, unsigned flags, void *ctx ));
169 LDAP_F( int ) ldap_bv2rdn_x LDAP_P(( 
170         struct berval *, LDAPRDN *, char **, unsigned flags, void *ctx ));
171 LDAP_F( int ) ldap_rdn2bv_x LDAP_P(( 
172         LDAPRDN rdn, struct berval *bv, unsigned flags, void *ctx ));
173 #endif /* LDAP_AVA_NULL */
174
175 /* url.c */
176 LDAP_F (void) ldap_pvt_hex_unescape LDAP_P(( char *s ));
177
178 /*
179  * these macros assume 'x' is an ASCII x
180  * and assume the "C" locale
181  */
182 #define LDAP_ASCII(c)           (!((c) & 0x80))
183 #define LDAP_SPACE(c)           ((c) == ' ' || (c) == '\t' || (c) == '\n')
184 #define LDAP_DIGIT(c)           ((c) >= '0' && (c) <= '9')
185 #define LDAP_LOWER(c)           ((c) >= 'a' && (c) <= 'z')
186 #define LDAP_UPPER(c)           ((c) >= 'A' && (c) <= 'Z')
187 #define LDAP_ALPHA(c)           (LDAP_LOWER(c) || LDAP_UPPER(c))
188 #define LDAP_ALNUM(c)           (LDAP_ALPHA(c) || LDAP_DIGIT(c))
189
190 #define LDAP_LDH(c)                     (LDAP_ALNUM(c) || (c) == '-')
191
192 #define LDAP_HEXLOWER(c)        ((c) >= 'a' && (c) <= 'f')
193 #define LDAP_HEXUPPER(c)        ((c) >= 'A' && (c) <= 'F')
194 #define LDAP_HEX(c)                     (LDAP_DIGIT(c) || \
195                                                                 LDAP_HEXLOWER(c) || LDAP_HEXUPPER(c))
196
197 /* controls.c */
198 struct ldapcontrol;
199 LDAP_F (int)
200 ldap_pvt_put_control LDAP_P((
201         const struct ldapcontrol *c,
202         BerElement *ber ));
203 LDAP_F (int) ldap_pvt_get_controls LDAP_P((
204         BerElement *be,
205         struct ldapcontrol ***ctrlsp));
206
207 #ifdef HAVE_CYRUS_SASL
208 /* cyrus.c */
209 struct sasl_security_properties; /* avoid pulling in <sasl.h> */
210 LDAP_F (int) ldap_pvt_sasl_secprops LDAP_P((
211         const char *in,
212         struct sasl_security_properties *secprops ));
213 LDAP_F (void) ldap_pvt_sasl_secprops_unparse LDAP_P((
214         struct sasl_security_properties *secprops,
215         struct berval *out ));
216
217 LDAP_F (void *) ldap_pvt_sasl_mutex_new LDAP_P((void));
218 LDAP_F (int) ldap_pvt_sasl_mutex_lock LDAP_P((void *mutex));
219 LDAP_F (int) ldap_pvt_sasl_mutex_unlock LDAP_P((void *mutex));
220 LDAP_F (void) ldap_pvt_sasl_mutex_dispose LDAP_P((void *mutex));
221 #endif /* HAVE_CYRUS_SASL */
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
227 /*
228  * SASL encryption support for LBER Sockbufs
229  */
230
231 struct sb_sasl_generic_data;
232
233 struct sb_sasl_generic_ops {
234         void (*init)(struct sb_sasl_generic_data *p,
235                      ber_len_t *min_send,
236                      ber_len_t *max_send,
237                      ber_len_t *max_recv);
238         ber_int_t (*encode)(struct sb_sasl_generic_data *p,
239                             unsigned char *buf,
240                             ber_len_t len,
241                             Sockbuf_Buf *dst);
242         ber_int_t (*decode)(struct sb_sasl_generic_data *p,
243                             const Sockbuf_Buf *src,
244                             Sockbuf_Buf *dst);
245         void (*reset_buf)(struct sb_sasl_generic_data *p,
246                           Sockbuf_Buf *buf);
247         void (*fini)(struct sb_sasl_generic_data *p);
248 };
249
250 struct sb_sasl_generic_install {
251         const struct sb_sasl_generic_ops        *ops;
252         void                                    *ops_private;
253 };
254
255 struct sb_sasl_generic_data {
256         const struct sb_sasl_generic_ops        *ops;
257         void                                    *ops_private;
258         Sockbuf_IO_Desc                         *sbiod;
259         ber_len_t                               min_send;
260         ber_len_t                               max_send;
261         ber_len_t                               max_recv;
262         Sockbuf_Buf                             sec_buf_in;
263         Sockbuf_Buf                             buf_in;
264         Sockbuf_Buf                             buf_out;
265 };
266  
267 #ifndef LDAP_PVT_SASL_LOCAL_SSF
268 #define LDAP_PVT_SASL_LOCAL_SSF 71      /* SSF for Unix Domain Sockets */
269 #endif /* ! LDAP_PVT_SASL_LOCAL_SSF */
270
271 struct ldap;
272 struct ldapmsg;
273
274 /* abandon */
275 LDAP_F ( int ) ldap_pvt_discard LDAP_P((
276         struct ldap *ld, ber_int_t msgid ));
277
278 /* messages.c */
279 LDAP_F( BerElement * )
280 ldap_get_message_ber LDAP_P((
281         struct ldapmsg * ));
282
283 /* open */
284 LDAP_F (int) ldap_open_internal_connection LDAP_P((
285         struct ldap **ldp, ber_socket_t *fdp ));
286 LDAP_F (int) ldap_init_fd LDAP_P((
287         ber_socket_t fd, int proto, LDAP_CONST char *url, struct ldap **ldp ));
288
289 /* sasl.c */
290 LDAP_F (int) ldap_pvt_sasl_generic_install LDAP_P(( Sockbuf *sb,
291         struct sb_sasl_generic_install *install_arg ));
292 LDAP_F (void) ldap_pvt_sasl_generic_remove LDAP_P(( Sockbuf *sb ));
293
294 /* search.c */
295 LDAP_F( int ) ldap_pvt_put_filter LDAP_P((
296         BerElement *ber,
297         const char *str ));
298
299 LDAP_F( char * )
300 ldap_pvt_find_wildcard LDAP_P(( const char *s ));
301
302 LDAP_F( ber_slen_t )
303 ldap_pvt_filter_value_unescape LDAP_P(( char *filter ));
304
305 LDAP_F( ber_len_t )
306 ldap_bv2escaped_filter_value_len LDAP_P(( struct berval *in ));
307
308 LDAP_F( int )
309 ldap_bv2escaped_filter_value_x LDAP_P(( struct berval *in, struct berval *out,
310         int inplace, void *ctx ));
311
312 LDAP_F (int) ldap_pvt_search LDAP_P((
313         struct ldap *ld,
314         LDAP_CONST char *base,
315         int scope,
316         LDAP_CONST char *filter,
317         char **attrs,
318         int attrsonly,
319         struct ldapcontrol **sctrls,
320         struct ldapcontrol **cctrls,
321         struct timeval *timeout,
322         int sizelimit,
323         int deref,
324         int *msgidp ));
325
326 LDAP_F(int) ldap_pvt_search_s LDAP_P((
327         struct ldap *ld,
328         LDAP_CONST char *base,
329         int scope,
330         LDAP_CONST char *filter,
331         char **attrs,
332         int attrsonly,
333         struct ldapcontrol **sctrls,
334         struct ldapcontrol **cctrls,
335         struct timeval *timeout,
336         int sizelimit,
337         int deref,
338         struct ldapmsg **res ));
339
340 /* string.c */
341 LDAP_F( char * )
342 ldap_pvt_str2upper LDAP_P(( char *str ));
343
344 LDAP_F( char * )
345 ldap_pvt_str2lower LDAP_P(( char *str ));
346
347 LDAP_F( struct berval * )
348 ldap_pvt_str2upperbv LDAP_P(( char *str, struct berval *bv ));
349
350 LDAP_F( struct berval * )
351 ldap_pvt_str2lowerbv LDAP_P(( char *str, struct berval *bv ));
352
353 /* tls.c */
354 LDAP_F (int) ldap_pvt_tls_config LDAP_P(( struct ldap *ld,
355         int option, const char *arg ));
356 LDAP_F (int) ldap_pvt_tls_get_option LDAP_P(( struct ldap *ld,
357         int option, void *arg ));
358 LDAP_F (int) ldap_pvt_tls_set_option LDAP_P(( struct ldap *ld,
359         int option, void *arg ));
360
361 LDAP_F (void) ldap_pvt_tls_destroy LDAP_P(( void ));
362 LDAP_F (int) ldap_pvt_tls_init LDAP_P(( void ));
363 LDAP_F (int) ldap_pvt_tls_init_def_ctx LDAP_P(( int is_server ));
364 LDAP_F (int) ldap_pvt_tls_accept LDAP_P(( Sockbuf *sb, void *ctx_arg ));
365 LDAP_F (int) ldap_pvt_tls_inplace LDAP_P(( Sockbuf *sb ));
366 LDAP_F (void *) ldap_pvt_tls_sb_ctx LDAP_P(( Sockbuf *sb ));
367 LDAP_F (void) ldap_pvt_tls_ctx_free LDAP_P(( void * ));
368
369 typedef int LDAPDN_rewrite_dummy LDAP_P (( void *dn, unsigned flags ));
370
371 typedef int (LDAP_TLS_CONNECT_CB) LDAP_P (( struct ldap *ld, void *ssl,
372         void *ctx, void *arg ));
373
374 LDAP_F (int) ldap_pvt_tls_get_my_dn LDAP_P(( void *ctx, struct berval *dn,
375         LDAPDN_rewrite_dummy *func, unsigned flags ));
376 LDAP_F (int) ldap_pvt_tls_get_peer_dn LDAP_P(( void *ctx, struct berval *dn,
377         LDAPDN_rewrite_dummy *func, unsigned flags ));
378 LDAP_F (int) ldap_pvt_tls_get_strength LDAP_P(( void *ctx ));
379
380 LDAP_END_DECL
381
382 /*
383  * Multiple precision stuff
384  * 
385  * May use OpenSSL's BIGNUM if built with TLS,
386  * or GNU's multiple precision library. But if
387  * long long is available, that's big enough
388  * and much more efficient.
389  *
390  * If none is available, unsigned long data is used.
391  */
392
393 LDAP_BEGIN_DECL
394
395 #ifdef USE_MP_BIGNUM
396 /*
397  * Use OpenSSL's BIGNUM
398  */
399 #include <openssl/crypto.h>
400 #include <openssl/bn.h>
401
402 typedef BIGNUM* ldap_pvt_mp_t;
403 #define LDAP_PVT_MP_INIT        (NULL)
404
405 #define ldap_pvt_mp_init(mp) \
406         do { (mp) = BN_new(); } while (0)
407
408 /* FIXME: we rely on mpr being initialized */
409 #define ldap_pvt_mp_init_set(mpr,mpv) \
410         do { ldap_pvt_mp_init((mpr)); BN_add((mpr), (mpr), (mpv)); } while (0)
411
412 #define ldap_pvt_mp_add(mpr,mpv) \
413         BN_add((mpr), (mpr), (mpv))
414
415 #define ldap_pvt_mp_add_ulong(mp,v) \
416         BN_add_word((mp), (v))
417
418 #define ldap_pvt_mp_clear(mp) \
419         do { BN_free((mp)); (mp) = 0; } while (0)
420
421 #elif defined(USE_MP_GMP)
422 /*
423  * Use GNU's multiple precision library
424  */
425 #include <gmp.h>
426
427 typedef mpz_t           ldap_pvt_mp_t;
428 #define LDAP_PVT_MP_INIT        { 0 }
429
430 #define ldap_pvt_mp_init(mp) \
431         mpz_init((mp))
432
433 #define ldap_pvt_mp_init_set(mpr,mpv) \
434         mpz_init_set((mpr), (mpv))
435
436 #define ldap_pvt_mp_add(mpr,mpv) \
437         mpz_add((mpr), (mpr), (mpv))
438
439 #define ldap_pvt_mp_add_ulong(mp,v)     \
440         mpz_add_ui((mp), (mp), (v))
441
442 #define ldap_pvt_mp_clear(mp) \
443         mpz_clear((mp))
444
445 #else
446 /*
447  * Use unsigned long long
448  */
449
450 #ifdef USE_MP_LONG_LONG
451 typedef unsigned long long      ldap_pvt_mp_t;
452 #define LDAP_PVT_MP_INIT        (0LL)
453 #elif defined(USE_MP_LONG)
454 typedef unsigned long           ldap_pvt_mp_t;
455 #define LDAP_PVT_MP_INIT        (0L)
456 #elif defined(HAVE_LONG_LONG)
457 typedef unsigned long long      ldap_pvt_mp_t;
458 #define LDAP_PVT_MP_INIT        (0LL)
459 #else
460 typedef unsigned long           ldap_pvt_mp_t;
461 #define LDAP_PVT_MP_INIT        (0L)
462 #endif
463
464 #define ldap_pvt_mp_init(mp) \
465         do { (mp) = 0; } while (0)
466
467 #define ldap_pvt_mp_init_set(mpr,mpv) \
468         do { (mpr) = (mpv); } while (0)
469
470 #define ldap_pvt_mp_add(mpr,mpv) \
471         do { (mpr) += (mpv); } while (0)
472
473 #define ldap_pvt_mp_add_ulong(mp,v) \
474         do { (mp) += (v); } while (0)
475
476 #define ldap_pvt_mp_clear(mp) \
477         do { (mp) = 0; } while (0)
478
479 #endif /* MP */
480
481 #include "ldap_pvt_uc.h"
482
483 LDAP_END_DECL
484
485 LDAP_BEGIN_DECL
486
487 #include <limits.h>                             /* get CHAR_BIT */
488
489 /* Buffer space for sign, decimal digits and \0. Note: log10(2) < 146/485. */
490 #define LDAP_PVT_INTTYPE_CHARS(type) (((sizeof(type)*CHAR_BIT-1)*146)/485 + 3)
491
492 LDAP_END_DECL
493
494 #endif /* _LDAP_PVT_H */