2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2005 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:// */
32 ldap_pvt_url_scheme2proto LDAP_P((
35 ldap_pvt_url_scheme2tls LDAP_P((
39 ldap_pvt_url_scheme_port LDAP_P((
42 struct ldap_url_desc; /* avoid pulling in <ldap.h> */
45 ldap_url_parse_ext LDAP_P((
47 struct ldap_url_desc **ludpp ));
50 ldap_pvt_ctime LDAP_P((
54 LDAP_F( char *) ldap_pvt_get_fqdn LDAP_P(( char * ));
56 struct hostent; /* avoid pulling in <netdb.h> */
59 ldap_pvt_gethostbyname_a LDAP_P((
61 struct hostent *resbuf,
63 struct hostent **result,
67 ldap_pvt_gethostbyaddr_a LDAP_P((
71 struct hostent *resbuf,
73 struct hostent **result,
79 ldap_pvt_get_hname LDAP_P((
80 const struct sockaddr * sa,
90 ldap_charray_add LDAP_P((
95 ldap_charray_merge LDAP_P((
100 ldap_charray_free LDAP_P(( char **a ));
103 ldap_charray_inlist LDAP_P((
108 ldap_charray_dup LDAP_P(( char **a ));
111 ldap_str2charray LDAP_P((
113 const char *brkstr ));
116 ldap_charray2str LDAP_P((
117 char **array, const char* sep ));
121 #ifdef LDAP_AVA_NULL /* in ldap.h */
122 LDAP_F( void ) ldap_rdnfree_x LDAP_P(( LDAPRDN rdn, void *ctx ));
123 LDAP_F( void ) ldap_dnfree_x LDAP_P(( LDAPDN dn, void *ctx ));
125 LDAP_F( int ) ldap_bv2dn_x LDAP_P((
126 struct berval *bv, LDAPDN *dn, unsigned flags, void *ctx ));
127 LDAP_F( int ) ldap_dn2bv_x LDAP_P((
128 LDAPDN dn, struct berval *bv, unsigned flags, void *ctx ));
129 LDAP_F( int ) ldap_bv2rdn_x LDAP_P((
130 struct berval *, LDAPRDN *, char **, unsigned flags, void *ctx ));
131 LDAP_F( int ) ldap_rdn2bv_x LDAP_P((
132 LDAPRDN rdn, struct berval *bv, unsigned flags, void *ctx ));
136 LDAP_F (void) ldap_pvt_hex_unescape LDAP_P(( char *s ));
139 * these macros assume 'x' is an ASCII x
140 * and assume the "C" locale
142 #define LDAP_ASCII(c) (!((c) & 0x80))
143 #define LDAP_SPACE(c) ((c) == ' ' || (c) == '\t' || (c) == '\n')
144 #define LDAP_DIGIT(c) ((c) >= '0' && (c) <= '9')
145 #define LDAP_LOWER(c) ((c) >= 'a' && (c) <= 'z')
146 #define LDAP_UPPER(c) ((c) >= 'A' && (c) <= 'Z')
147 #define LDAP_ALPHA(c) (LDAP_LOWER(c) || LDAP_UPPER(c))
148 #define LDAP_ALNUM(c) (LDAP_ALPHA(c) || LDAP_DIGIT(c))
150 #define LDAP_LDH(c) (LDAP_ALNUM(c) || (c) == '-')
152 #define LDAP_HEXLOWER(c) ((c) >= 'a' && (c) <= 'f')
153 #define LDAP_HEXUPPER(c) ((c) >= 'A' && (c) <= 'F')
154 #define LDAP_HEX(c) (LDAP_DIGIT(c) || \
155 LDAP_HEXLOWER(c) || LDAP_HEXUPPER(c))
159 LDAP_F (struct ldapcontrol *) ldap_control_dup LDAP_P((
160 const struct ldapcontrol *ctrl ));
162 LDAP_F (struct ldapcontrol **) ldap_controls_dup LDAP_P((
163 struct ldapcontrol *const *ctrls ));
165 LDAP_F (int) ldap_pvt_get_controls LDAP_P((
167 struct ldapcontrol ***ctrlsp));
169 #ifdef HAVE_CYRUS_SASL
171 struct sasl_security_properties; /* avoid pulling in <sasl.h> */
172 LDAP_F (int) ldap_pvt_sasl_secprops LDAP_P((
174 struct sasl_security_properties *secprops ));
175 LDAP_F (void) ldap_pvt_sasl_secprops_unparse LDAP_P((
176 struct sasl_security_properties *secprops,
177 struct berval *out ));
179 LDAP_F (void *) ldap_pvt_sasl_mutex_new LDAP_P((void));
180 LDAP_F (int) ldap_pvt_sasl_mutex_lock LDAP_P((void *mutex));
181 LDAP_F (int) ldap_pvt_sasl_mutex_unlock LDAP_P((void *mutex));
182 LDAP_F (void) ldap_pvt_sasl_mutex_dispose LDAP_P((void *mutex));
184 struct sockbuf; /* avoid pulling in <lber.h> */
185 LDAP_F (int) ldap_pvt_sasl_install LDAP_P(( struct sockbuf *, void * ));
186 LDAP_F (void) ldap_pvt_sasl_remove LDAP_P(( struct sockbuf * ));
187 #endif /* HAVE_CYRUS_SASL */
189 #ifndef LDAP_PVT_SASL_LOCAL_SSF
190 #define LDAP_PVT_SASL_LOCAL_SSF 71 /* SSF for Unix Domain Sockets */
196 LDAP_F (int) ldap_open_internal_connection LDAP_P((
197 struct ldap **ldp, ber_socket_t *fdp ));
200 LDAP_F( BerElement * )
201 ldap_get_message_ber LDAP_P((
205 LDAP_F( int ) ldap_pvt_put_filter LDAP_P((
210 ldap_pvt_find_wildcard LDAP_P(( const char *s ));
213 ldap_pvt_filter_value_unescape LDAP_P(( char *filter ));
217 ldap_pvt_str2upper LDAP_P(( char *str ));
220 ldap_pvt_str2lower LDAP_P(( char *str ));
222 LDAP_F( struct berval * )
223 ldap_pvt_str2upperbv LDAP_P(( char *str, struct berval *bv ));
225 LDAP_F( struct berval * )
226 ldap_pvt_str2lowerbv LDAP_P(( char *str, struct berval *bv ));
229 LDAP_F (int) ldap_int_tls_config LDAP_P(( struct ldap *ld,
230 int option, const char *arg ));
231 LDAP_F (int) ldap_pvt_tls_get_option LDAP_P(( struct ldap *ld,
232 int option, void *arg ));
233 LDAP_F (int) ldap_pvt_tls_set_option LDAP_P(( struct ldap *ld,
234 int option, void *arg ));
236 LDAP_F (void) ldap_pvt_tls_destroy LDAP_P(( void ));
237 LDAP_F (int) ldap_pvt_tls_init LDAP_P(( void ));
238 LDAP_F (int) ldap_pvt_tls_init_def_ctx LDAP_P(( void ));
239 LDAP_F (int) ldap_pvt_tls_accept LDAP_P(( Sockbuf *sb, void *ctx_arg ));
240 LDAP_F (int) ldap_pvt_tls_inplace LDAP_P(( Sockbuf *sb ));
241 LDAP_F (void *) ldap_pvt_tls_sb_ctx LDAP_P(( Sockbuf *sb ));
243 LDAP_F (int) ldap_pvt_tls_init_default_ctx LDAP_P(( void ));
245 typedef int LDAPDN_rewrite_dummy LDAP_P (( void *dn, unsigned flags ));
247 typedef int (LDAP_TLS_CONNECT_CB) LDAP_P (( struct ldap *ld, void *ssl,
248 void *ctx, void *arg ));
250 LDAP_F (int) ldap_pvt_tls_get_my_dn LDAP_P(( void *ctx, struct berval *dn,
251 LDAPDN_rewrite_dummy *func, unsigned flags ));
252 LDAP_F (int) ldap_pvt_tls_get_peer_dn LDAP_P(( void *ctx, struct berval *dn,
253 LDAPDN_rewrite_dummy *func, unsigned flags ));
254 LDAP_F (int) ldap_pvt_tls_get_strength LDAP_P(( void *ctx ));
259 * Multiple precision stuff
261 * May use OpenSSL's BIGNUM if built with TLS,
262 * or GNU's multiple precision library.
264 * If none is available, unsigned long data is used.
268 * Use OpenSSL's BIGNUM
270 #if defined(HAVE_OPENSSL_CRYPTO_H)
271 #include <openssl/crypto.h>
274 #endif /* HAVE_OPENSSL_CRYPTO_H || HAVE_CRYPTO_H */
275 #ifdef HAVE_OPENSSL_BN_H
276 #include <openssl/bn.h>
279 #endif /* HAVE_OPENSSL_BN_H || HAVE_BN_H */
281 typedef BIGNUM* ldap_pvt_mp_t;
282 #define LDAP_PVT_MP_INIT (NULL)
284 #define ldap_pvt_mp_init(mp) \
287 /* FIXME: we rely on mpr being initialized */
288 #define ldap_pvt_mp_init_set(mpr,mpv) \
289 do { ldap_pvt_mp_init((mpr)); BN_add((mpr), (mpr), (mpv)); } while (0)
291 #define ldap_pvt_mp_add(mpr,mpv) \
292 BN_add((mpr), (mpr), (mpv))
294 #define ldap_pvt_mp_add_ulong(mp,v) \
295 BN_add_word((mp), (v))
297 #define ldap_pvt_mp_clear(mp) \
298 do { BN_free((mp)); (mp) = 0; } while (0)
300 #elif defined(HAVE_GMP)
302 * Use GNU's multiple precision library
308 typedef mpz_t ldap_pvt_mp_t;
309 #define LDAP_PVT_MP_INIT { 0 }
311 #define ldap_pvt_mp_init(mp) \
314 #define ldap_pvt_mp_init_set(mpr,mpv) \
315 mpz_init_set((mpr), (mpv))
317 #define ldap_pvt_mp_add(mpr,mpv) \
318 mpz_add((mpr), (mpr), (mpv))
320 #define ldap_pvt_mp_add_ulong(mp,v) \
321 mpz_add_ui((mp), (mp), (v))
323 #define ldap_pvt_mp_clear(mp) \
326 #else /* ! HAVE_BIGNUM && ! HAVE_GMP */
331 #ifdef HAVE_LONG_LONG
332 typedef unsigned long long ldap_pvt_mp_t;
333 #define LDAP_PVT_MP_INIT (0LL)
334 #else /* !HAVE_LONG_LONG */
335 typedef unsigned long ldap_pvt_mp_t;
336 #define LDAP_PVT_MP_INIT (0L)
337 #endif /* !HAVE_LONG_LONG */
339 #define ldap_pvt_mp_init(mp) \
342 #define ldap_pvt_mp_init_set(mpr,mpv) \
345 #define ldap_pvt_mp_add(mpr,mpv) \
348 #define ldap_pvt_mp_add_ulong(mp,v) \
351 #define ldap_pvt_mp_clear(mp) \
354 #endif /* ! HAVE_BIGNUM && ! HAVE_GMP */
356 #include "ldap_pvt_uc.h"