3 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
7 * Copyright (c) 1995 Regents of the University of Michigan.
10 * ldap-int.h - defines & prototypes internal to the LDAP library
17 #define LDAP_THREAD_SAFE 1
20 #include "../liblber/lber-int.h"
22 #define ldap_debug (ldap_int_global_options.ldo_debug)
24 #define Debug( level, fmt, arg1, arg2, arg3 ) \
25 ldap_log_printf( NULL, (level), (fmt), (arg1), (arg2), (arg3) )
35 #define LDAP_URL_PREFIX "ldap://"
36 #define LDAP_URL_PREFIX_LEN (sizeof(LDAP_URL_PREFIX)-1)
37 #define LDAPS_URL_PREFIX "ldaps://"
38 #define LDAPS_URL_PREFIX_LEN (sizeof(LDAPS_URL_PREFIX)-1)
39 #define LDAPI_URL_PREFIX "ldapi://"
40 #define LDAPI_URL_PREFIX_LEN (sizeof(LDAPI_URL_PREFIX)-1)
41 #define LDAPIS_URL_PREFIX "ldapis://"
42 #define LDAPIS_URL_PREFIX_LEN (sizeof(LDAPIS_URL_PREFIX)-1)
43 #define LDAP_URL_URLCOLON "URL:"
44 #define LDAP_URL_URLCOLON_LEN (sizeof(LDAP_URL_URLCOLON)-1)
45 #define NULLLDAPURLDESC ((LDAPURLDesc *)NULL)
47 #define LDAP_REF_STR "Referral:\n"
48 #define LDAP_REF_STR_LEN (sizeof(LDAP_REF_STR)-1)
49 #define LDAP_LDAP_REF_STR LDAP_URL_PREFIX
50 #define LDAP_LDAP_REF_STR_LEN (sizeof(LDAP_LDAP_REF_STR)-1)
52 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
53 #define LDAP_DX_REF_STR "dx://"
54 #define LDAP_DX_REF_STR_LEN (sizeof(LDAP_DX_REF_STR)-1)
55 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
57 #define LDAP_DEFAULT_REFHOPLIMIT 5
59 #define LDAP_BOOL_REFERRALS 0
60 #define LDAP_BOOL_RESTART 1
61 #define LDAP_BOOL_DNS 2
62 #define LDAP_BOOL_TLS 3
64 #define LDAP_BOOLEANS unsigned long
65 #define LDAP_BOOL(n) (1 << (n))
66 #define LDAP_BOOL_GET(lo, bool) ((lo)->ldo_booleans & LDAP_BOOL(bool) \
68 #define LDAP_BOOL_SET(lo, bool) ((lo)->ldo_booleans |= LDAP_BOOL(bool))
69 #define LDAP_BOOL_CLR(lo, bool) ((lo)->ldo_booleans &= ~LDAP_BOOL(bool))
70 #define LDAP_BOOL_ZERO(lo) ((lo)->ldo_booleans = 0)
73 * This structure represents both ldap messages and ldap responses.
74 * These are really the same, except in the case of search responses,
75 * where a response has multiple messages.
79 ber_int_t lm_msgid; /* the message id */
80 ber_tag_t lm_msgtype; /* the message type */
81 BerElement *lm_ber; /* the ber encoded message contents */
82 struct ldapmsg *lm_chain; /* for search - next msg in the resp */
83 struct ldapmsg *lm_next; /* next response */
84 time_t lm_time; /* used to maintain cache */
88 * structure representing get/set'able options
89 * which have global defaults.
93 #define LDAP_UNINITIALIZED 0x0
94 #define LDAP_INITIALIZED 0x1
95 #define LDAP_VALID_SESSION 0x2
98 /* per API call timeout */
99 struct timeval *ldo_tm_api;
100 struct timeval *ldo_tm_net;
102 ber_int_t ldo_version;
104 ber_int_t ldo_timelimit;
105 ber_int_t ldo_sizelimit;
107 LDAPURLDesc *ldo_defludp;
110 char* ldo_defbinddn; /* simple bind dn */
112 #ifdef LDAP_CONNECTIONLESS
113 int ldo_cldaptries; /* connectionless search retry count */
114 int ldo_cldaptimeout;/* time between retries */
117 int ldo_refhoplimit; /* limit on referral nesting */
119 /* LDAPv3 server and client controls */
120 LDAPControl **ldo_sctrls;
121 LDAPControl **ldo_cctrls;
128 #ifdef HAVE_CYRUS_SASL
129 sasl_ssf_t ldo_sasl_minssf;
130 sasl_ssf_t ldo_sasl_maxssf;
132 LDAP_BOOLEANS ldo_booleans; /* boolean options */
137 * structure for tracking LDAP server host, ports, DNs, etc.
139 typedef struct ldap_server {
141 char *lsrv_dn; /* if NULL, use default */
143 /* int lsrv_protocol; */
144 struct ldap_server *lsrv_next;
149 * structure for representing an LDAP server connection
151 typedef struct ldap_conn {
154 time_t lconn_lastused; /* time */
156 #define LDAP_CONNST_NEEDSOCKET 1
157 #define LDAP_CONNST_CONNECTING 2
158 #define LDAP_CONNST_CONNECTED 3
159 LDAPURLDesc *lconn_server;
160 char *lconn_krbinstance;
161 struct ldap_conn *lconn_next;
162 BerElement *lconn_ber;/* ber receiving on this conn. */
167 * structure used to track outstanding requests
169 typedef struct ldapreq {
170 ber_int_t lr_msgid; /* the message id */
171 int lr_status; /* status of request */
172 #define LDAP_REQST_INPROGRESS 1
173 #define LDAP_REQST_CHASINGREFS 2
174 #define LDAP_REQST_NOTCONNECTED 3
175 #define LDAP_REQST_WRITING 4
176 int lr_outrefcnt; /* count of outstanding referrals */
177 ber_int_t lr_origid; /* original request's message id */
178 int lr_parentcnt; /* count of parent requests */
179 ber_tag_t lr_res_msgtype; /* result message type */
180 ber_int_t lr_res_errno; /* result LDAP errno */
181 char *lr_res_error; /* result error string */
182 char *lr_res_matched;/* result matched DN string */
183 BerElement *lr_ber; /* ber encoded request contents */
184 LDAPConn *lr_conn; /* connection used to send request */
185 struct ldapreq *lr_parent; /* request that spawned this referral */
186 struct ldapreq *lr_refnext; /* next referral spawned */
187 struct ldapreq *lr_prev; /* previous request */
188 struct ldapreq *lr_next; /* next request */
192 * structure for client cache
194 #define LDAP_CACHE_BUCKETS 31 /* cache hash table size */
195 typedef struct ldapcache {
196 LDAPMessage *lc_buckets[LDAP_CACHE_BUCKETS];/* hash table */
197 LDAPMessage *lc_requests; /* unfulfilled reqs */
198 long lc_timeout; /* request timeout */
199 ber_len_t lc_maxmem; /* memory to use */
200 ber_len_t lc_memused; /* memory in use */
201 int lc_enabled; /* enabled? */
202 unsigned long lc_options; /* options */
203 #define LDAP_CACHE_OPT_CACHENOERRS 0x00000001
204 #define LDAP_CACHE_OPT_CACHEALLERRS 0x00000002
208 * handy macro for checking if handle is connectionless
211 #define LDAP_IS_CLDAP(ld) ((ld)->ld_cldapnaddr>0)
214 * structure representing an ldap connection
218 Sockbuf ld_sb; /* socket descriptor & buffer */
220 struct ldapoptions ld_options;
222 #define ld_valid ld_options.ldo_valid
223 #define ld_debug ld_options.ldo_debug
225 #define ld_deref ld_options.ldo_deref
226 #define ld_timelimit ld_options.ldo_timelimit
227 #define ld_sizelimit ld_options.ldo_sizelimit
229 #define ld_defbinddn ld_options.ldo_defbinddn
230 #define ld_defbase ld_options.ldo_defbase
231 #define ld_defhost ld_options.ldo_defhost
232 #define ld_defport ld_options.ldo_defport
234 #define ld_cldaptries ld_options.ldo_cldaptries
235 #define ld_cldaptimeout ld_options.ldo_cldaptimeout
236 #define ld_refhoplimit ld_options.ldo_refhoplimit
238 #define ld_sctrls ld_options.ldo_sctrls
239 #define ld_cctrls ld_options.ldo_cctrls
241 #define ld_version ld_options.ldo_version
245 unsigned short ld_lberoptions;
247 LDAPFiltDesc *ld_filtd; /* from getfilter for ufn searches */
248 char *ld_ufnprefix; /* for incomplete ufn's */
255 /* do not mess with these */
256 LDAPRequest *ld_requests; /* list of outstanding requests */
257 LDAPMessage *ld_responses; /* list of outstanding responses */
259 ber_int_t *ld_abandoned; /* array of abandoned requests */
261 LDAPCache *ld_cache; /* non-null if cache is initialized */
262 /* stuff used by connectionless searches. */
264 char *ld_cldapdn; /* DN used in connectionless search */
265 int ld_cldapnaddr; /* number of addresses */
266 void **ld_cldapaddrs;/* addresses to send request to */
268 /* do not mess with the rest though */
269 BERTranslateProc ld_lber_encode_translate_proc;
270 BERTranslateProc ld_lber_decode_translate_proc;
272 LDAPConn *ld_defconn; /* default connection */
273 LDAPConn *ld_conns; /* list of server connections */
274 void *ld_selectinfo; /* platform specifics for select */
275 int (*ld_rebindproc)( struct ldap *ld, char **dnp,
276 char **passwdp, int *authmethodp, int freeit );
277 /* routine to get info needed for re-bind */
278 #ifdef HAVE_CYRUS_SASL
279 sasl_conn_t *ld_sasl_context;
280 #endif /* HAVE_CYRUS_SASL */
282 #define LDAP_VALID(ld) ( (ld)->ld_valid == LDAP_VALID_SESSION )
284 #if defined(HAVE_RES_SEARCH) && defined(LDAP_R_COMPILE)
285 #include <ldap_pvt_thread.h>
286 extern ldap_pvt_thread_mutex_t ldap_int_resolv_mutex;
287 #endif /* HAVE_RES_SEARCH && LDAP_R_COMPILE */
293 LIBLDAP_F ( struct ldapoptions ) ldap_int_global_options;
294 LIBLDAP_F ( void ) ldap_int_initialize LDAP_P((int *));
297 /* simple macros to realloc for now */
298 #define LDAP_INT_MALLOC(s) (LBER_MALLOC((s)))
299 #define LDAP_INT_CALLOC(n,s) (LBER_CALLOC((n),(s)))
300 #define LDAP_INT_REALLOC(p,s) (LBER_REALLOC((p),(s)))
301 #define LDAP_INT_FREE(p) (LBER_FREE((p)))
302 #define LDAP_INT_VFREE(v) (LBER_VFREE((void **)(v)))
303 #define LDAP_INT_STRDUP(s) (LBER_STRDUP((s)))
305 #define LDAP_MALLOC(s) (LBER_MALLOC((s)))
306 #define LDAP_CALLOC(n,s) (LBER_CALLOC((n),(s)))
307 #define LDAP_REALLOC(p,s) (LBER_REALLOC((p),(s)))
308 #define LDAP_FREE(p) (LBER_FREE((p)))
309 #define LDAP_VFREE(v) (LBER_VFREE((void **)(v)))
310 #define LDAP_STRDUP(s) (LBER_STRDUP((s)))
315 LIBLDAP_F (void) ldap_int_utils_init LDAP_P(( void ));
321 LIBLDAP_F (int) ldap_log_printf LDAP_P((LDAP *ld, int level, const char *fmt, ...)) LDAP_GCCATTR((format(printf, 3, 4)));
326 LIBLDAP_F (void) ldap_add_request_to_cache LDAP_P(( LDAP *ld, ber_tag_t msgtype,
327 BerElement *request ));
328 LIBLDAP_F (void) ldap_add_result_to_cache LDAP_P(( LDAP *ld, LDAPMessage *result ));
329 LIBLDAP_F (int) ldap_check_cache LDAP_P(( LDAP *ld, ber_tag_t msgtype, BerElement *request ));
334 LIBLDAP_F (LDAPControl *) ldap_control_dup LDAP_P((
335 const LDAPControl *ctrl ));
337 LIBLDAP_F (LDAPControl **) ldap_controls_dup LDAP_P((
338 LDAPControl *const *ctrls ));
340 LIBLDAP_F (int) ldap_int_get_controls LDAP_P((
342 LDAPControl ***ctrlsp));
344 LIBLDAP_F (int) ldap_int_put_controls LDAP_P((
346 LDAPControl *const *ctrls,
352 LIBLDAP_F (int) next_line_tokens LDAP_P(( char **bufp, ber_len_t *blenp, char ***toksp ));
353 LIBLDAP_F (void) free_strarray LDAP_P(( char **sap ));
355 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
359 LIBLDAP_F (char *) ldap_get_kerberosv4_credentials LDAP_P((
361 LDAP_CONST char *who,
362 LDAP_CONST char *service,
365 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND */
371 LIBLDAP_F (int) ldap_open_defconn( LDAP *ld );
372 LIBLDAP_F (int) open_ldap_connection( LDAP *ld, Sockbuf *sb, LDAPURLDesc *srvlist, char **krbinstancep, int async );
377 LIBLDAP_F (int) ldap_int_tblsize;
378 LIBLDAP_F (int) ldap_int_timeval_dup( struct timeval **dest, const struct timeval *tm );
379 LIBLDAP_F (int) ldap_connect_to_host( LDAP *ld, Sockbuf *sb, const char *host, unsigned long address, int port, int async );
381 LIBLDAP_F (void) ldap_close_connection( Sockbuf *sb );
383 #if defined(LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND) || defined(HAVE_TLS) || defined(HAVE_CYRUS_SASL)
384 LIBLDAP_F (char *) ldap_host_connected_to( Sockbuf *sb );
385 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND */
387 LIBLDAP_F (void) ldap_int_ip_init( void );
388 LIBLDAP_F (int) do_ldap_select( LDAP *ld, struct timeval *timeout );
389 LIBLDAP_F (void *) ldap_new_select_info( void );
390 LIBLDAP_F (void) ldap_free_select_info( void *sip );
391 LIBLDAP_F (void) ldap_mark_select_write( LDAP *ld, Sockbuf *sb );
392 LIBLDAP_F (void) ldap_mark_select_read( LDAP *ld, Sockbuf *sb );
393 LIBLDAP_F (void) ldap_mark_select_clear( LDAP *ld, Sockbuf *sb );
394 LIBLDAP_F (int) ldap_is_read_ready( LDAP *ld, Sockbuf *sb );
395 LIBLDAP_F (int) ldap_is_write_ready( LDAP *ld, Sockbuf *sb );
401 LIBLDAP_F (int) ldap_connect_to_path( LDAP *ld, Sockbuf *sb, const char *path, int async );
402 #endif /* LDAP_PF_LOCAL */
407 LIBLDAP_F (ber_int_t) ldap_send_initial_request( LDAP *ld, ber_tag_t msgtype,
408 const char *dn, BerElement *ber );
409 LIBLDAP_F (BerElement *) ldap_alloc_ber_with_options( LDAP *ld );
410 LIBLDAP_F (void) ldap_set_ber_options( LDAP *ld, BerElement *ber );
412 LIBLDAP_F (int) ldap_send_server_request( LDAP *ld, BerElement *ber, ber_int_t msgid, LDAPRequest *parentreq, LDAPURLDesc *srvlist, LDAPConn *lc, int bind );
413 LIBLDAP_F (LDAPConn *) ldap_new_connection( LDAP *ld, LDAPURLDesc *srvlist, int use_ldsb, int connect, int bind );
414 LIBLDAP_F (LDAPRequest *) ldap_find_request_by_msgid( LDAP *ld, ber_int_t msgid );
415 LIBLDAP_F (void) ldap_free_request( LDAP *ld, LDAPRequest *lr );
416 LIBLDAP_F (void) ldap_free_connection( LDAP *ld, LDAPConn *lc, int force, int unbind );
417 LIBLDAP_F (void) ldap_dump_connection( LDAP *ld, LDAPConn *lconns, int all );
418 LIBLDAP_F (void) ldap_dump_requests_and_responses( LDAP *ld );
419 LIBLDAP_F (int) ldap_chase_referrals( LDAP *ld, LDAPRequest *lr, char **errstrp, int *hadrefp );
420 LIBLDAP_F (int) ldap_append_referral( LDAP *ld, char **referralsp, char *s );
425 #ifdef LDAP_CONNECTIONLESS
426 LIBLDAP_F (int) cldap_getmsg( LDAP *ld, struct timeval *timeout, BerElement *ber );
432 LIBLDAP_F (BerElement *) ldap_build_search_req LDAP_P((
439 LDAPControl **sctrls,
440 LDAPControl **cctrls,
442 ber_int_t sizelimit ));
447 /* see <ac/string.h> */
452 LIBLDAP_F (int) ldap_ld_free LDAP_P((
455 LDAPControl **sctrls,
456 LDAPControl **cctrls ));
458 LIBLDAP_F (int) ldap_send_unbind LDAP_P((
461 LDAPControl **sctrls,
462 LDAPControl **cctrls ));
467 LIBLDAP_F (LDAPURLDesc *) ldap_url_dup LDAP_P((
468 LDAPURLDesc *ludp ));
470 LIBLDAP_F (LDAPURLDesc *) ldap_url_duplist LDAP_P((
471 LDAPURLDesc *ludlist ));
473 LIBLDAP_F (int) ldap_url_parselist LDAP_P((
474 LDAPURLDesc **ludlist,
477 LIBLDAP_F (int) ldap_url_parsehosts LDAP_P((
478 LDAPURLDesc **ludlist,
479 const char *hosts ));
481 LIBLDAP_F (char *) ldap_url_list2hosts LDAP_P((
482 LDAPURLDesc *ludlist ));
484 LIBLDAP_F (char *) ldap_url_list2urls LDAP_P((
485 LDAPURLDesc *ludlist ));
487 LIBLDAP_F (void) ldap_free_urllist LDAP_P((
488 LDAPURLDesc *ludlist ));
491 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
495 LIBLDAP_F (char **) ldap_getdxbyname( const char *domain );
496 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
498 #if defined( STR_TRANSLATION ) && defined( LDAP_DEFAULT_CHARSET )
502 * added-in this stuff so that libldap.a would build, i.e. refs to
503 * these routines from open.c would resolve.
504 * hodges@stanford.edu 5-Feb-96
506 #if LDAP_CHARSET_8859 == LDAP_DEFAULT_CHARSET
507 LIBLDAP_F (int) ldap_t61_to_8859( char **bufp, ber_len_t *buflenp, int free_input );
508 LIBLDAP_F (int) ldap_8859_to_t61( char **bufp, ber_len_t *buflenp, int free_input );
509 #endif /* LDAP_CHARSET_8859 == LDAP_DEFAULT_CHARSET */
510 #endif /* STR_TRANSLATION && LDAP_DEFAULT_CHARSET */
514 #endif /* _LDAP_INT_H */