2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2007 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 | LDAP_PVT_URL_PARSE_NOEMPTY_HOST | LDAP_PVT_URL_PARSE_DEF_PORT)
52 ldap_url_parse_ext LDAP_P((
54 struct ldap_url_desc **ludpp,
57 LDAP_F (int) ldap_url_parselist_ext LDAP_P((
58 struct ldap_url_desc **ludlist,
63 LDAP_F (char *) ldap_url_list2urls LDAP_P((
64 struct ldap_url_desc *ludlist ));
66 LDAP_F (void) ldap_free_urllist LDAP_P((
67 struct ldap_url_desc *ludlist ));
69 LDAP_F (int) ldap_pvt_scope2bv LDAP_P ((
70 int scope, struct berval *bv ));
72 LDAP_F (LDAP_CONST char *) ldap_pvt_scope2str LDAP_P ((
75 LDAP_F (int) ldap_pvt_bv2scope LDAP_P ((
78 LDAP_F (int) ldap_pvt_str2scope LDAP_P ((
82 ldap_pvt_ctime LDAP_P((
86 LDAP_F( char *) ldap_pvt_get_fqdn LDAP_P(( char * ));
88 struct hostent; /* avoid pulling in <netdb.h> */
91 ldap_pvt_gethostbyname_a LDAP_P((
93 struct hostent *resbuf,
95 struct hostent **result,
99 ldap_pvt_gethostbyaddr_a LDAP_P((
103 struct hostent *resbuf,
105 struct hostent **result,
111 ldap_pvt_get_hname LDAP_P((
112 const struct sockaddr * sa,
122 ldap_charray_add LDAP_P((
127 ldap_charray_merge LDAP_P((
132 ldap_charray_free LDAP_P(( char **a ));
135 ldap_charray_inlist LDAP_P((
140 ldap_charray_dup LDAP_P(( char **a ));
143 ldap_str2charray LDAP_P((
145 const char *brkstr ));
148 ldap_charray2str LDAP_P((
149 char **array, const char* sep ));
153 #ifdef LDAP_AVA_NULL /* in ldap.h */
154 LDAP_F( void ) ldap_rdnfree_x LDAP_P(( LDAPRDN rdn, void *ctx ));
155 LDAP_F( void ) ldap_dnfree_x LDAP_P(( LDAPDN dn, void *ctx ));
157 LDAP_F( int ) ldap_bv2dn_x LDAP_P((
158 struct berval *bv, LDAPDN *dn, unsigned flags, void *ctx ));
159 LDAP_F( int ) ldap_dn2bv_x LDAP_P((
160 LDAPDN dn, struct berval *bv, unsigned flags, void *ctx ));
161 LDAP_F( int ) ldap_bv2rdn_x LDAP_P((
162 struct berval *, LDAPRDN *, char **, unsigned flags, void *ctx ));
163 LDAP_F( int ) ldap_rdn2bv_x LDAP_P((
164 LDAPRDN rdn, struct berval *bv, unsigned flags, void *ctx ));
168 LDAP_F (void) ldap_pvt_hex_unescape LDAP_P(( char *s ));
171 * these macros assume 'x' is an ASCII x
172 * and assume the "C" locale
174 #define LDAP_ASCII(c) (!((c) & 0x80))
175 #define LDAP_SPACE(c) ((c) == ' ' || (c) == '\t' || (c) == '\n')
176 #define LDAP_DIGIT(c) ((c) >= '0' && (c) <= '9')
177 #define LDAP_LOWER(c) ((c) >= 'a' && (c) <= 'z')
178 #define LDAP_UPPER(c) ((c) >= 'A' && (c) <= 'Z')
179 #define LDAP_ALPHA(c) (LDAP_LOWER(c) || LDAP_UPPER(c))
180 #define LDAP_ALNUM(c) (LDAP_ALPHA(c) || LDAP_DIGIT(c))
182 #define LDAP_LDH(c) (LDAP_ALNUM(c) || (c) == '-')
184 #define LDAP_HEXLOWER(c) ((c) >= 'a' && (c) <= 'f')
185 #define LDAP_HEXUPPER(c) ((c) >= 'A' && (c) <= 'F')
186 #define LDAP_HEX(c) (LDAP_DIGIT(c) || \
187 LDAP_HEXLOWER(c) || LDAP_HEXUPPER(c))
191 LDAP_F (struct ldapcontrol *) ldap_control_dup LDAP_P((
192 const struct ldapcontrol *ctrl ));
194 LDAP_F (struct ldapcontrol **) ldap_controls_dup LDAP_P((
195 struct ldapcontrol *const *ctrls ));
197 LDAP_F (int) ldap_pvt_get_controls LDAP_P((
199 struct ldapcontrol ***ctrlsp));
201 #ifdef HAVE_CYRUS_SASL
203 struct sasl_security_properties; /* avoid pulling in <sasl.h> */
204 LDAP_F (int) ldap_pvt_sasl_secprops LDAP_P((
206 struct sasl_security_properties *secprops ));
207 LDAP_F (void) ldap_pvt_sasl_secprops_unparse LDAP_P((
208 struct sasl_security_properties *secprops,
209 struct berval *out ));
211 LDAP_F (void *) ldap_pvt_sasl_mutex_new LDAP_P((void));
212 LDAP_F (int) ldap_pvt_sasl_mutex_lock LDAP_P((void *mutex));
213 LDAP_F (int) ldap_pvt_sasl_mutex_unlock LDAP_P((void *mutex));
214 LDAP_F (void) ldap_pvt_sasl_mutex_dispose LDAP_P((void *mutex));
216 struct sockbuf; /* avoid pulling in <lber.h> */
217 LDAP_F (int) ldap_pvt_sasl_install LDAP_P(( struct sockbuf *, void * ));
218 LDAP_F (void) ldap_pvt_sasl_remove LDAP_P(( struct sockbuf * ));
219 #endif /* HAVE_CYRUS_SASL */
221 #ifndef LDAP_PVT_SASL_LOCAL_SSF
222 #define LDAP_PVT_SASL_LOCAL_SSF 71 /* SSF for Unix Domain Sockets */
229 LDAP_F ( int ) ldap_pvt_discard LDAP_P((
230 struct ldap *ld, ber_int_t msgid ));
233 LDAP_F( BerElement * )
234 ldap_get_message_ber LDAP_P((
238 LDAP_F (int) ldap_open_internal_connection LDAP_P((
239 struct ldap **ldp, ber_socket_t *fdp ));
240 LDAP_F (int) ldap_init_fd LDAP_P((
241 ber_socket_t fd, int proto, LDAP_CONST char *url, struct ldap **ldp ));
244 LDAP_F( int ) ldap_pvt_put_filter LDAP_P((
249 ldap_pvt_find_wildcard LDAP_P(( const char *s ));
252 ldap_pvt_filter_value_unescape LDAP_P(( char *filter ));
255 ldap_bv2escaped_filter_value_len LDAP_P(( struct berval *in ));
258 ldap_bv2escaped_filter_value_x LDAP_P(( struct berval *in, struct berval *out,
259 int inplace, void *ctx ));
263 ldap_pvt_str2upper LDAP_P(( char *str ));
266 ldap_pvt_str2lower LDAP_P(( char *str ));
268 LDAP_F( struct berval * )
269 ldap_pvt_str2upperbv LDAP_P(( char *str, struct berval *bv ));
271 LDAP_F( struct berval * )
272 ldap_pvt_str2lowerbv LDAP_P(( char *str, struct berval *bv ));
275 LDAP_F (int) ldap_int_tls_config LDAP_P(( struct ldap *ld,
276 int option, const char *arg ));
277 LDAP_F (int) ldap_pvt_tls_get_option LDAP_P(( struct ldap *ld,
278 int option, void *arg ));
279 LDAP_F (int) ldap_pvt_tls_set_option LDAP_P(( struct ldap *ld,
280 int option, void *arg ));
282 LDAP_F (void) ldap_pvt_tls_destroy LDAP_P(( void ));
283 LDAP_F (int) ldap_pvt_tls_init LDAP_P(( void ));
284 LDAP_F (int) ldap_pvt_tls_init_def_ctx LDAP_P(( int is_server ));
285 LDAP_F (int) ldap_pvt_tls_accept LDAP_P(( Sockbuf *sb, void *ctx_arg ));
286 LDAP_F (int) ldap_pvt_tls_inplace LDAP_P(( Sockbuf *sb ));
287 LDAP_F (void *) ldap_pvt_tls_sb_ctx LDAP_P(( Sockbuf *sb ));
289 LDAP_F (int) ldap_pvt_tls_init_default_ctx LDAP_P(( void ));
291 typedef int LDAPDN_rewrite_dummy LDAP_P (( void *dn, unsigned flags ));
293 typedef int (LDAP_TLS_CONNECT_CB) LDAP_P (( struct ldap *ld, void *ssl,
294 void *ctx, void *arg ));
296 LDAP_F (int) ldap_pvt_tls_get_my_dn LDAP_P(( void *ctx, struct berval *dn,
297 LDAPDN_rewrite_dummy *func, unsigned flags ));
298 LDAP_F (int) ldap_pvt_tls_get_peer_dn LDAP_P(( void *ctx, struct berval *dn,
299 LDAPDN_rewrite_dummy *func, unsigned flags ));
300 LDAP_F (int) ldap_pvt_tls_get_strength LDAP_P(( void *ctx ));
305 * Multiple precision stuff
307 * May use OpenSSL's BIGNUM if built with TLS,
308 * or GNU's multiple precision library. But if
309 * long long is available, that's big enough
310 * and much more efficient.
312 * If none is available, unsigned long data is used.
317 * Use OpenSSL's BIGNUM
319 #include <openssl/crypto.h>
320 #include <openssl/bn.h>
322 typedef BIGNUM* ldap_pvt_mp_t;
323 #define LDAP_PVT_MP_INIT (NULL)
325 #define ldap_pvt_mp_init(mp) \
326 do { (mp) = BN_new(); } while (0)
328 /* FIXME: we rely on mpr being initialized */
329 #define ldap_pvt_mp_init_set(mpr,mpv) \
330 do { ldap_pvt_mp_init((mpr)); BN_add((mpr), (mpr), (mpv)); } while (0)
332 #define ldap_pvt_mp_add(mpr,mpv) \
333 BN_add((mpr), (mpr), (mpv))
335 #define ldap_pvt_mp_add_ulong(mp,v) \
336 BN_add_word((mp), (v))
338 #define ldap_pvt_mp_clear(mp) \
339 do { BN_free((mp)); (mp) = 0; } while (0)
343 * Use GNU's multiple precision library
347 typedef mpz_t ldap_pvt_mp_t;
348 #define LDAP_PVT_MP_INIT { 0 }
350 #define ldap_pvt_mp_init(mp) \
353 #define ldap_pvt_mp_init_set(mpr,mpv) \
354 mpz_init_set((mpr), (mpv))
356 #define ldap_pvt_mp_add(mpr,mpv) \
357 mpz_add((mpr), (mpr), (mpv))
359 #define ldap_pvt_mp_add_ulong(mp,v) \
360 mpz_add_ui((mp), (mp), (v))
362 #define ldap_pvt_mp_clear(mp) \
367 * Use unsigned long long
371 typedef unsigned long long ldap_pvt_mp_t;
372 #define LDAP_PVT_MP_INIT (0LL)
374 typedef unsigned long ldap_pvt_mp_t;
375 #define LDAP_PVT_MP_INIT (0L)
377 typedef unsigned long long ldap_pvt_mp_t;
378 #define LDAP_PVT_MP_INIT (0LL)
380 typedef unsigned long ldap_pvt_mp_t;
381 #define LDAP_PVT_MP_INIT (0L)
384 #define ldap_pvt_mp_init(mp) \
385 do { (mp) = 0; } while (0)
387 #define ldap_pvt_mp_init_set(mpr,mpv) \
388 do { (mpr) = (mpv); } while (0)
390 #define ldap_pvt_mp_add(mpr,mpv) \
391 do { (mpr) += (mpv); } while (0)
393 #define ldap_pvt_mp_add_ulong(mp,v) \
394 do { (mp) += (v); } while (0)
396 #define ldap_pvt_mp_clear(mp) \
397 do { (mp) = 0; } while (0)
401 #include "ldap_pvt_uc.h"
403 #endif /* _LDAP_PVT_H */