No empty .Rs/.Re
[netbsd-mini2440.git] / external / bsd / openldap / dist / include / ldap_pvt.h
blob2a4ff3e5eedfce0153908943695604b9af38dfb1
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/>.
3 *
4 * Copyright 1998-2008 The OpenLDAP Foundation.
5 * All rights reserved.
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.
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.
20 #ifndef _LDAP_PVT_H
21 #define _LDAP_PVT_H 1
23 #include <lber.h> /* get ber_slen_t */
25 LDAP_BEGIN_DECL
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 */
32 LDAP_F ( int )
33 ldap_pvt_url_scheme2proto LDAP_P((
34 const char * ));
35 LDAP_F ( int )
36 ldap_pvt_url_scheme2tls LDAP_P((
37 const char * ));
39 LDAP_F ( int )
40 ldap_pvt_url_scheme_port LDAP_P((
41 const char *, int ));
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)
54 LDAP_F( int )
55 ldap_url_parse_ext LDAP_P((
56 LDAP_CONST char *url,
57 struct ldap_url_desc **ludpp,
58 unsigned flags ));
60 LDAP_F (int) ldap_url_parselist LDAP_P(( /* deprecated, use ldap_url_parselist_ext() */
61 struct ldap_url_desc **ludlist,
62 const char *url ));
64 LDAP_F (int) ldap_url_parselist_ext LDAP_P((
65 struct ldap_url_desc **ludlist,
66 const char *url,
67 const char *sep,
68 unsigned flags ));
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 ((
80 int scope ));
82 LDAP_F (int) ldap_pvt_bv2scope LDAP_P ((
83 struct berval *bv ));
85 LDAP_F (int) ldap_pvt_str2scope LDAP_P ((
86 LDAP_CONST char * ));
88 LDAP_F( char * )
89 ldap_pvt_ctime LDAP_P((
90 const time_t *tp,
91 char *buf ));
93 LDAP_F( char *) ldap_pvt_get_fqdn LDAP_P(( char * ));
95 struct hostent; /* avoid pulling in <netdb.h> */
97 LDAP_F( int )
98 ldap_pvt_gethostbyname_a LDAP_P((
99 const char *name,
100 struct hostent *resbuf,
101 char **buf,
102 struct hostent **result,
103 int *herrno_ptr ));
105 LDAP_F( int )
106 ldap_pvt_gethostbyaddr_a LDAP_P((
107 const char *addr,
108 int len,
109 int type,
110 struct hostent *resbuf,
111 char **buf,
112 struct hostent **result,
113 int *herrno_ptr ));
115 struct sockaddr;
117 LDAP_F( int )
118 ldap_pvt_get_hname LDAP_P((
119 const struct sockaddr * sa,
120 int salen,
121 char *name,
122 int namelen,
123 char **herr ));
126 /* charray.c */
128 LDAP_F( int )
129 ldap_charray_add LDAP_P((
130 char ***a,
131 const char *s ));
133 LDAP_F( int )
134 ldap_charray_merge LDAP_P((
135 char ***a,
136 char **s ));
138 LDAP_F( void )
139 ldap_charray_free LDAP_P(( char **a ));
141 LDAP_F( int )
142 ldap_charray_inlist LDAP_P((
143 char **a,
144 const char *s ));
146 LDAP_F( char ** )
147 ldap_charray_dup LDAP_P(( char **a ));
149 LDAP_F( char ** )
150 ldap_str2charray LDAP_P((
151 const char *str,
152 const char *brkstr ));
154 LDAP_F( char * )
155 ldap_charray2str LDAP_P((
156 char **array, const char* sep ));
158 /* getdn.c */
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 */
174 /* url.c */
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))
196 /* controls.c */
197 struct ldapcontrol;
198 LDAP_F (int)
199 ldap_pvt_put_control LDAP_P((
200 const struct ldapcontrol *c,
201 BerElement *ber ));
202 LDAP_F (int) ldap_pvt_get_controls LDAP_P((
203 BerElement *be,
204 struct ldapcontrol ***ctrlsp));
206 #ifdef HAVE_CYRUS_SASL
207 /* cyrus.c */
208 struct sasl_security_properties; /* avoid pulling in <sasl.h> */
209 LDAP_F (int) ldap_pvt_sasl_secprops LDAP_P((
210 const char *in,
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 */
230 struct ldap;
231 struct ldapmsg;
233 /* abandon */
234 LDAP_F ( int ) ldap_pvt_discard LDAP_P((
235 struct ldap *ld, ber_int_t msgid ));
237 /* messages.c */
238 LDAP_F( BerElement * )
239 ldap_get_message_ber LDAP_P((
240 struct ldapmsg * ));
242 /* open */
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 ));
248 /* search.c */
249 LDAP_F( int ) ldap_pvt_put_filter LDAP_P((
250 BerElement *ber,
251 const char *str ));
253 LDAP_F( char * )
254 ldap_pvt_find_wildcard LDAP_P(( const char *s ));
256 LDAP_F( ber_slen_t )
257 ldap_pvt_filter_value_unescape LDAP_P(( char *filter ));
259 LDAP_F( ber_len_t )
260 ldap_bv2escaped_filter_value_len LDAP_P(( struct berval *in ));
262 LDAP_F( int )
263 ldap_bv2escaped_filter_value_x LDAP_P(( struct berval *in, struct berval *out,
264 int inplace, void *ctx ));
266 /* string.c */
267 LDAP_F( char * )
268 ldap_pvt_str2upper LDAP_P(( char *str ));
270 LDAP_F( char * )
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 ));
279 /* tls.c */
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 ));
306 LDAP_END_DECL
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.
319 LDAP_BEGIN_DECL
321 #ifdef USE_MP_BIGNUM
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
351 #include <gmp.h>
353 typedef mpz_t ldap_pvt_mp_t;
354 #define LDAP_PVT_MP_INIT { 0 }
356 #define ldap_pvt_mp_init(mp) \
357 mpz_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) \
369 mpz_clear((mp))
371 #else
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)
385 #else
386 typedef unsigned long ldap_pvt_mp_t;
387 #define LDAP_PVT_MP_INIT (0L)
388 #endif
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)
405 #endif /* MP */
407 #include "ldap_pvt_uc.h"
409 LDAP_END_DECL
411 LDAP_BEGIN_DECL
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)
418 LDAP_END_DECL
420 #endif /* _LDAP_PVT_H */