1 /* $OpenLDAP: pkg/ldap/include/ldap_pvt.h,v 1.91.2.6 2008/02/11 23:26:40 kurt Exp $ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2008 The OpenLDAP Foundation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
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>.
16 /* ldap-pvt.h - Header for ldap_pvt_ functions.
17 * These are meant to be internal to OpenLDAP Software.
23 #include <lber.h> /* get ber_slen_t */
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 */
33 ldap_pvt_url_scheme2proto
LDAP_P((
36 ldap_pvt_url_scheme2tls
LDAP_P((
40 ldap_pvt_url_scheme_port
LDAP_P((
43 struct ldap_url_desc
; /* avoid pulling in <ldap.h> */
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)
55 ldap_url_parse_ext
LDAP_P((
57 struct ldap_url_desc
**ludpp
,
60 LDAP_F (int) ldap_url_parselist
LDAP_P(( /* deprecated, use ldap_url_parselist_ext() */
61 struct ldap_url_desc
**ludlist
,
64 LDAP_F (int) ldap_url_parselist_ext
LDAP_P((
65 struct ldap_url_desc
**ludlist
,
70 LDAP_F (char *) ldap_url_list2urls
LDAP_P((
71 struct ldap_url_desc
*ludlist
));
73 LDAP_F (void) ldap_free_urllist
LDAP_P((
74 struct ldap_url_desc
*ludlist
));
76 LDAP_F (int) ldap_pvt_scope2bv
LDAP_P ((
77 int scope
, struct berval
*bv
));
79 LDAP_F (LDAP_CONST
char *) ldap_pvt_scope2str
LDAP_P ((
82 LDAP_F (int) ldap_pvt_bv2scope
LDAP_P ((
85 LDAP_F (int) ldap_pvt_str2scope
LDAP_P ((
89 ldap_pvt_ctime
LDAP_P((
93 LDAP_F( char *) ldap_pvt_get_fqdn
LDAP_P(( char * ));
95 struct hostent
; /* avoid pulling in <netdb.h> */
98 ldap_pvt_gethostbyname_a
LDAP_P((
100 struct hostent
*resbuf
,
102 struct hostent
**result
,
106 ldap_pvt_gethostbyaddr_a
LDAP_P((
110 struct hostent
*resbuf
,
112 struct hostent
**result
,
118 ldap_pvt_get_hname
LDAP_P((
119 const struct sockaddr
* sa
,
129 ldap_charray_add
LDAP_P((
134 ldap_charray_merge
LDAP_P((
139 ldap_charray_free
LDAP_P(( char **a
));
142 ldap_charray_inlist
LDAP_P((
147 ldap_charray_dup
LDAP_P(( char **a
));
150 ldap_str2charray
LDAP_P((
152 const char *brkstr
));
155 ldap_charray2str
LDAP_P((
156 char **array
, const char* sep
));
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
));
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 /* LDAP_AVA_NULL */
175 LDAP_F (void) ldap_pvt_hex_unescape
LDAP_P(( char *s
));
178 * these macros assume 'x' is an ASCII x
179 * and assume the "C" locale
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))
189 #define LDAP_LDH(c) (LDAP_ALNUM(c) || (c) == '-')
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))
199 ldap_pvt_put_control
LDAP_P((
200 const struct ldapcontrol
*c
,
202 LDAP_F (int) ldap_pvt_get_controls
LDAP_P((
204 struct ldapcontrol
***ctrlsp
));
206 #ifdef HAVE_CYRUS_SASL
208 struct sasl_security_properties
; /* avoid pulling in <sasl.h> */
209 LDAP_F (int) ldap_pvt_sasl_secprops
LDAP_P((
211 struct sasl_security_properties
*secprops
));
212 LDAP_F (void) ldap_pvt_sasl_secprops_unparse
LDAP_P((
213 struct sasl_security_properties
*secprops
,
214 struct berval
*out
));
216 LDAP_F (void *) ldap_pvt_sasl_mutex_new
LDAP_P((void));
217 LDAP_F (int) ldap_pvt_sasl_mutex_lock
LDAP_P((void *mutex
));
218 LDAP_F (int) ldap_pvt_sasl_mutex_unlock
LDAP_P((void *mutex
));
219 LDAP_F (void) ldap_pvt_sasl_mutex_dispose
LDAP_P((void *mutex
));
221 struct sockbuf
; /* avoid pulling in <lber.h> */
222 LDAP_F (int) ldap_pvt_sasl_install
LDAP_P(( struct sockbuf
*, void * ));
223 LDAP_F (void) ldap_pvt_sasl_remove
LDAP_P(( struct sockbuf
* ));
224 #endif /* HAVE_CYRUS_SASL */
226 #ifndef LDAP_PVT_SASL_LOCAL_SSF
227 #define LDAP_PVT_SASL_LOCAL_SSF 71 /* SSF for Unix Domain Sockets */
228 #endif /* ! LDAP_PVT_SASL_LOCAL_SSF */
234 LDAP_F ( int ) ldap_pvt_discard
LDAP_P((
235 struct ldap
*ld
, ber_int_t msgid
));
238 LDAP_F( BerElement
* )
239 ldap_get_message_ber
LDAP_P((
243 LDAP_F (int) ldap_open_internal_connection
LDAP_P((
244 struct ldap
**ldp
, ber_socket_t
*fdp
));
245 LDAP_F (int) ldap_init_fd
LDAP_P((
246 ber_socket_t fd
, int proto
, LDAP_CONST
char *url
, struct ldap
**ldp
));
249 LDAP_F( int ) ldap_pvt_put_filter
LDAP_P((
254 ldap_pvt_find_wildcard
LDAP_P(( const char *s
));
257 ldap_pvt_filter_value_unescape
LDAP_P(( char *filter
));
260 ldap_bv2escaped_filter_value_len
LDAP_P(( struct berval
*in
));
263 ldap_bv2escaped_filter_value_x
LDAP_P(( struct berval
*in
, struct berval
*out
,
264 int inplace
, void *ctx
));
268 ldap_pvt_str2upper
LDAP_P(( char *str
));
271 ldap_pvt_str2lower
LDAP_P(( char *str
));
273 LDAP_F( struct berval
* )
274 ldap_pvt_str2upperbv
LDAP_P(( char *str
, struct berval
*bv
));
276 LDAP_F( struct berval
* )
277 ldap_pvt_str2lowerbv
LDAP_P(( char *str
, struct berval
*bv
));
280 LDAP_F (int) ldap_int_tls_config
LDAP_P(( struct ldap
*ld
,
281 int option
, const char *arg
));
282 LDAP_F (int) ldap_pvt_tls_get_option
LDAP_P(( struct ldap
*ld
,
283 int option
, void *arg
));
284 LDAP_F (int) ldap_pvt_tls_set_option
LDAP_P(( struct ldap
*ld
,
285 int option
, void *arg
));
287 LDAP_F (void) ldap_pvt_tls_destroy
LDAP_P(( void ));
288 LDAP_F (int) ldap_pvt_tls_init
LDAP_P(( void ));
289 LDAP_F (int) ldap_pvt_tls_init_def_ctx
LDAP_P(( int is_server
));
290 LDAP_F (int) ldap_pvt_tls_accept
LDAP_P(( Sockbuf
*sb
, void *ctx_arg
));
291 LDAP_F (int) ldap_pvt_tls_inplace
LDAP_P(( Sockbuf
*sb
));
292 LDAP_F (void *) ldap_pvt_tls_sb_ctx
LDAP_P(( Sockbuf
*sb
));
293 LDAP_F (void) ldap_pvt_tls_ctx_free
LDAP_P(( void * ));
295 typedef int LDAPDN_rewrite_dummy
LDAP_P (( void *dn
, unsigned flags
));
297 typedef int (LDAP_TLS_CONNECT_CB
) LDAP_P (( struct ldap
*ld
, void *ssl
,
298 void *ctx
, void *arg
));
300 LDAP_F (int) ldap_pvt_tls_get_my_dn
LDAP_P(( void *ctx
, struct berval
*dn
,
301 LDAPDN_rewrite_dummy
*func
, unsigned flags
));
302 LDAP_F (int) ldap_pvt_tls_get_peer_dn
LDAP_P(( void *ctx
, struct berval
*dn
,
303 LDAPDN_rewrite_dummy
*func
, unsigned flags
));
304 LDAP_F (int) ldap_pvt_tls_get_strength
LDAP_P(( void *ctx
));
309 * Multiple precision stuff
311 * May use OpenSSL's BIGNUM if built with TLS,
312 * or GNU's multiple precision library. But if
313 * long long is available, that's big enough
314 * and much more efficient.
316 * If none is available, unsigned long data is used.
323 * Use OpenSSL's BIGNUM
325 #include <openssl/crypto.h>
326 #include <openssl/bn.h>
328 typedef BIGNUM
* ldap_pvt_mp_t
;
329 #define LDAP_PVT_MP_INIT (NULL)
331 #define ldap_pvt_mp_init(mp) \
332 do { (mp) = BN_new(); } while (0)
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)
338 #define ldap_pvt_mp_add(mpr,mpv) \
339 BN_add((mpr), (mpr), (mpv))
341 #define ldap_pvt_mp_add_ulong(mp,v) \
342 BN_add_word((mp), (v))
344 #define ldap_pvt_mp_clear(mp) \
345 do { BN_free((mp)); (mp) = 0; } while (0)
347 #elif defined(USE_MP_GMP)
349 * Use GNU's multiple precision library
353 typedef mpz_t ldap_pvt_mp_t
;
354 #define LDAP_PVT_MP_INIT { 0 }
356 #define ldap_pvt_mp_init(mp) \
359 #define ldap_pvt_mp_init_set(mpr,mpv) \
360 mpz_init_set((mpr), (mpv))
362 #define ldap_pvt_mp_add(mpr,mpv) \
363 mpz_add((mpr), (mpr), (mpv))
365 #define ldap_pvt_mp_add_ulong(mp,v) \
366 mpz_add_ui((mp), (mp), (v))
368 #define ldap_pvt_mp_clear(mp) \
373 * Use unsigned long long
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)
386 typedef unsigned long ldap_pvt_mp_t
;
387 #define LDAP_PVT_MP_INIT (0L)
390 #define ldap_pvt_mp_init(mp) \
391 do { (mp) = 0; } while (0)
393 #define ldap_pvt_mp_init_set(mpr,mpv) \
394 do { (mpr) = (mpv); } while (0)
396 #define ldap_pvt_mp_add(mpr,mpv) \
397 do { (mpr) += (mpv); } while (0)
399 #define ldap_pvt_mp_add_ulong(mp,v) \
400 do { (mp) += (v); } while (0)
402 #define ldap_pvt_mp_clear(mp) \
403 do { (mp) = 0; } while (0)
407 #include "ldap_pvt_uc.h"
413 #include <limits.h> /* get CHAR_BIT */
415 /* Buffer space for sign, decimal digits and \0. Note: log10(2) < 146/485. */
416 #define LDAP_PVT_INTTYPE_CHARS(type) (((sizeof(type)*CHAR_BIT-1)*146)/485 + 3)
420 #endif /* _LDAP_PVT_H */