2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2006 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> */
44 #define LDAP_PVT_URL_PARSE_NONE (0x00U)
45 #define LDAP_PVT_URL_PARSE_NOEMPTY_HOST (0x01U)
46 #define LDAP_PVT_URL_PARSE_DEF_PORT (0x02U)
47 #define LDAP_PVT_URL_PARSE_NOEMPTY_DN (0x04U)
48 #define LDAP_PVT_URL_PARSE_NODEF_SCOPE (0x08U)
49 #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_url_parse_ext LDAP_P((
53 struct ldap_url_desc **ludpp,
56 LDAP_F (int) ldap_url_parselist_ext LDAP_P((
57 struct ldap_url_desc **ludlist,
62 LDAP_F (char *) ldap_url_list2urls LDAP_P((
63 struct ldap_url_desc *ludlist ));
65 LDAP_F (void) ldap_free_urllist LDAP_P((
66 struct ldap_url_desc *ludlist ));
68 LDAP_F (int) ldap_pvt_scope2bv LDAP_P ((
69 int scope, struct berval *bv ));
71 LDAP_F (LDAP_CONST char *) ldap_pvt_scope2str LDAP_P ((
74 LDAP_F (int) ldap_pvt_bv2scope LDAP_P ((
77 LDAP_F (int) ldap_pvt_str2scope LDAP_P ((
81 ldap_pvt_ctime LDAP_P((
85 LDAP_F( char *) ldap_pvt_get_fqdn LDAP_P(( char * ));
87 struct hostent; /* avoid pulling in <netdb.h> */
90 ldap_pvt_gethostbyname_a LDAP_P((
92 struct hostent *resbuf,
94 struct hostent **result,
98 ldap_pvt_gethostbyaddr_a LDAP_P((
102 struct hostent *resbuf,
104 struct hostent **result,
110 ldap_pvt_get_hname LDAP_P((
111 const struct sockaddr * sa,
121 ldap_charray_add LDAP_P((
126 ldap_charray_merge LDAP_P((
131 ldap_charray_free LDAP_P(( char **a ));
134 ldap_charray_inlist LDAP_P((
139 ldap_charray_dup LDAP_P(( char **a ));
142 ldap_str2charray LDAP_P((
144 const char *brkstr ));
147 ldap_charray2str LDAP_P((
148 char **array, const char* sep ));
152 #ifdef LDAP_AVA_NULL /* in ldap.h */
153 LDAP_F( void ) ldap_rdnfree_x LDAP_P(( LDAPRDN rdn, void *ctx ));
154 LDAP_F( void ) ldap_dnfree_x LDAP_P(( LDAPDN dn, void *ctx ));
156 LDAP_F( int ) ldap_bv2dn_x LDAP_P((
157 struct berval *bv, LDAPDN *dn, unsigned flags, void *ctx ));
158 LDAP_F( int ) ldap_dn2bv_x LDAP_P((
159 LDAPDN dn, struct berval *bv, unsigned flags, void *ctx ));
160 LDAP_F( int ) ldap_bv2rdn_x LDAP_P((
161 struct berval *, LDAPRDN *, char **, unsigned flags, void *ctx ));
162 LDAP_F( int ) ldap_rdn2bv_x LDAP_P((
163 LDAPRDN rdn, struct berval *bv, unsigned flags, void *ctx ));
167 LDAP_F (void) ldap_pvt_hex_unescape LDAP_P(( char *s ));
170 * these macros assume 'x' is an ASCII x
171 * and assume the "C" locale
173 #define LDAP_ASCII(c) (!((c) & 0x80))
174 #define LDAP_SPACE(c) ((c) == ' ' || (c) == '\t' || (c) == '\n')
175 #define LDAP_DIGIT(c) ((c) >= '0' && (c) <= '9')
176 #define LDAP_LOWER(c) ((c) >= 'a' && (c) <= 'z')
177 #define LDAP_UPPER(c) ((c) >= 'A' && (c) <= 'Z')
178 #define LDAP_ALPHA(c) (LDAP_LOWER(c) || LDAP_UPPER(c))
179 #define LDAP_ALNUM(c) (LDAP_ALPHA(c) || LDAP_DIGIT(c))
181 #define LDAP_LDH(c) (LDAP_ALNUM(c) || (c) == '-')
183 #define LDAP_HEXLOWER(c) ((c) >= 'a' && (c) <= 'f')
184 #define LDAP_HEXUPPER(c) ((c) >= 'A' && (c) <= 'F')
185 #define LDAP_HEX(c) (LDAP_DIGIT(c) || \
186 LDAP_HEXLOWER(c) || LDAP_HEXUPPER(c))
190 LDAP_F (struct ldapcontrol *) ldap_control_dup LDAP_P((
191 const struct ldapcontrol *ctrl ));
193 LDAP_F (struct ldapcontrol **) ldap_controls_dup LDAP_P((
194 struct ldapcontrol *const *ctrls ));
196 LDAP_F (int) ldap_pvt_get_controls LDAP_P((
198 struct ldapcontrol ***ctrlsp));
200 #ifdef HAVE_CYRUS_SASL
202 struct sasl_security_properties; /* avoid pulling in <sasl.h> */
203 LDAP_F (int) ldap_pvt_sasl_secprops LDAP_P((
205 struct sasl_security_properties *secprops ));
206 LDAP_F (void) ldap_pvt_sasl_secprops_unparse LDAP_P((
207 struct sasl_security_properties *secprops,
208 struct berval *out ));
210 LDAP_F (void *) ldap_pvt_sasl_mutex_new LDAP_P((void));
211 LDAP_F (int) ldap_pvt_sasl_mutex_lock LDAP_P((void *mutex));
212 LDAP_F (int) ldap_pvt_sasl_mutex_unlock LDAP_P((void *mutex));
213 LDAP_F (void) ldap_pvt_sasl_mutex_dispose LDAP_P((void *mutex));
215 struct sockbuf; /* avoid pulling in <lber.h> */
216 LDAP_F (int) ldap_pvt_sasl_install LDAP_P(( struct sockbuf *, void * ));
217 LDAP_F (void) ldap_pvt_sasl_remove LDAP_P(( struct sockbuf * ));
218 #endif /* HAVE_CYRUS_SASL */
220 #ifndef LDAP_PVT_SASL_LOCAL_SSF
221 #define LDAP_PVT_SASL_LOCAL_SSF 71 /* SSF for Unix Domain Sockets */
227 LDAP_F (int) ldap_open_internal_connection LDAP_P((
228 struct ldap **ldp, ber_socket_t *fdp ));
231 LDAP_F( BerElement * )
232 ldap_get_message_ber LDAP_P((
236 LDAP_F( int ) ldap_pvt_put_filter LDAP_P((
241 ldap_pvt_find_wildcard LDAP_P(( const char *s ));
244 ldap_pvt_filter_value_unescape LDAP_P(( char *filter ));
247 ldap_bv2escaped_filter_value_len LDAP_P(( struct berval *in ));
250 ldap_bv2escaped_filter_value_x LDAP_P(( struct berval *in, struct berval *out,
251 int inplace, void *ctx ));
255 ldap_pvt_str2upper LDAP_P(( char *str ));
258 ldap_pvt_str2lower LDAP_P(( char *str ));
260 LDAP_F( struct berval * )
261 ldap_pvt_str2upperbv LDAP_P(( char *str, struct berval *bv ));
263 LDAP_F( struct berval * )
264 ldap_pvt_str2lowerbv LDAP_P(( char *str, struct berval *bv ));
267 LDAP_F (int) ldap_int_tls_config LDAP_P(( struct ldap *ld,
268 int option, const char *arg ));
269 LDAP_F (int) ldap_pvt_tls_get_option LDAP_P(( struct ldap *ld,
270 int option, void *arg ));
271 LDAP_F (int) ldap_pvt_tls_set_option LDAP_P(( struct ldap *ld,
272 int option, void *arg ));
274 LDAP_F (void) ldap_pvt_tls_destroy LDAP_P(( void ));
275 LDAP_F (int) ldap_pvt_tls_init LDAP_P(( void ));
276 LDAP_F (int) ldap_pvt_tls_init_def_ctx LDAP_P(( int is_server ));
277 LDAP_F (int) ldap_pvt_tls_accept LDAP_P(( Sockbuf *sb, void *ctx_arg ));
278 LDAP_F (int) ldap_pvt_tls_inplace LDAP_P(( Sockbuf *sb ));
279 LDAP_F (void *) ldap_pvt_tls_sb_ctx LDAP_P(( Sockbuf *sb ));
281 LDAP_F (int) ldap_pvt_tls_init_default_ctx LDAP_P(( void ));
283 typedef int LDAPDN_rewrite_dummy LDAP_P (( void *dn, unsigned flags ));
285 typedef int (LDAP_TLS_CONNECT_CB) LDAP_P (( struct ldap *ld, void *ssl,
286 void *ctx, void *arg ));
288 LDAP_F (int) ldap_pvt_tls_get_my_dn LDAP_P(( void *ctx, struct berval *dn,
289 LDAPDN_rewrite_dummy *func, unsigned flags ));
290 LDAP_F (int) ldap_pvt_tls_get_peer_dn LDAP_P(( void *ctx, struct berval *dn,
291 LDAPDN_rewrite_dummy *func, unsigned flags ));
292 LDAP_F (int) ldap_pvt_tls_get_strength LDAP_P(( void *ctx ));
297 * Multiple precision stuff
299 * May use OpenSSL's BIGNUM if built with TLS,
300 * or GNU's multiple precision library. But if
301 * long long is available, that's big enough
302 * and much more efficient.
304 * If none is available, unsigned long data is used.
309 * Use OpenSSL's BIGNUM
311 #include <openssl/crypto.h>
312 #include <openssl/bn.h>
314 typedef BIGNUM* ldap_pvt_mp_t;
315 #define LDAP_PVT_MP_INIT (NULL)
317 #define ldap_pvt_mp_init(mp) \
318 do { (mp) = BN_new(); } while (0)
320 /* FIXME: we rely on mpr being initialized */
321 #define ldap_pvt_mp_init_set(mpr,mpv) \
322 do { ldap_pvt_mp_init((mpr)); BN_add((mpr), (mpr), (mpv)); } while (0)
324 #define ldap_pvt_mp_add(mpr,mpv) \
325 BN_add((mpr), (mpr), (mpv))
327 #define ldap_pvt_mp_add_ulong(mp,v) \
328 BN_add_word((mp), (v))
330 #define ldap_pvt_mp_clear(mp) \
331 do { BN_free((mp)); (mp) = 0; } while (0)
335 * Use GNU's multiple precision library
339 typedef mpz_t ldap_pvt_mp_t;
340 #define LDAP_PVT_MP_INIT { 0 }
342 #define ldap_pvt_mp_init(mp) \
345 #define ldap_pvt_mp_init_set(mpr,mpv) \
346 mpz_init_set((mpr), (mpv))
348 #define ldap_pvt_mp_add(mpr,mpv) \
349 mpz_add((mpr), (mpr), (mpv))
351 #define ldap_pvt_mp_add_ulong(mp,v) \
352 mpz_add_ui((mp), (mp), (v))
354 #define ldap_pvt_mp_clear(mp) \
359 * Use unsigned long long
363 typedef unsigned long long ldap_pvt_mp_t;
364 #define LDAP_PVT_MP_INIT (0LL)
366 typedef unsigned long ldap_pvt_mp_t;
367 #define LDAP_PVT_MP_INIT (0L)
369 typedef unsigned long long ldap_pvt_mp_t;
370 #define LDAP_PVT_MP_INIT (0LL)
372 typedef unsigned long ldap_pvt_mp_t;
373 #define LDAP_PVT_MP_INIT (0L)
376 #define ldap_pvt_mp_init(mp) \
377 do { (mp) = 0; } while (0)
379 #define ldap_pvt_mp_init_set(mpr,mpv) \
380 do { (mpr) = (mpv); } while (0)
382 #define ldap_pvt_mp_add(mpr,mpv) \
383 do { (mpr) += (mpv); } while (0)
385 #define ldap_pvt_mp_add_ulong(mp,v) \
386 do { (mp) += (v); } while (0)
388 #define ldap_pvt_mp_clear(mp) \
389 do { (mp) = 0; } while (0)
393 #include "ldap_pvt_uc.h"
395 #endif /* _LDAP_PVT_H */