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;
122 /* LDAPV3 rebind callback function
124 LDAP_REBIND_PROC *ldo_rebindproc;
131 #ifdef HAVE_CYRUS_SASL
132 sasl_ssf_t ldo_sasl_minssf;
133 sasl_ssf_t ldo_sasl_maxssf;
135 LDAP_BOOLEANS ldo_booleans; /* boolean options */
140 * structure for tracking LDAP server host, ports, DNs, etc.
142 typedef struct ldap_server {
144 char *lsrv_dn; /* if NULL, use default */
146 /* int lsrv_protocol; */
147 struct ldap_server *lsrv_next;
152 * structure for representing an LDAP server connection
154 typedef struct ldap_conn {
157 time_t lconn_lastused; /* time */
158 int lconn_rebind_inprogress; /* set if rebind in progress */
159 char ***lconn_rebind_queue; /* used if rebind in progress */
161 #define LDAP_CONNST_NEEDSOCKET 1
162 #define LDAP_CONNST_CONNECTING 2
163 #define LDAP_CONNST_CONNECTED 3
164 LDAPURLDesc *lconn_server;
165 char *lconn_krbinstance;
166 struct ldap_conn *lconn_next;
167 BerElement *lconn_ber;/* ber receiving on this conn. */
172 * structure used to track outstanding requests
174 typedef struct ldapreq {
175 ber_int_t lr_msgid; /* the message id */
176 int lr_status; /* status of request */
177 #define LDAP_REQST_COMPLETED 0
178 #define LDAP_REQST_INPROGRESS 1
179 #define LDAP_REQST_CHASINGREFS 2
180 #define LDAP_REQST_NOTCONNECTED 3
181 #define LDAP_REQST_WRITING 4
182 int lr_outrefcnt; /* count of outstanding referrals */
183 ber_int_t lr_origid; /* original request's message id */
184 int lr_parentcnt; /* count of parent requests */
185 ber_tag_t lr_res_msgtype; /* result message type */
186 ber_int_t lr_res_errno; /* result LDAP errno */
187 char *lr_res_error; /* result error string */
188 char *lr_res_matched;/* result matched DN string */
189 BerElement *lr_ber; /* ber encoded request contents */
190 LDAPConn *lr_conn; /* connection used to send request */
191 struct ldapreq *lr_parent; /* request that spawned this referral */
192 struct ldapreq *lr_refnext; /* next referral spawned */
193 struct ldapreq *lr_prev; /* previous request */
194 struct ldapreq *lr_next; /* next request */
198 * structure for client cache
200 #define LDAP_CACHE_BUCKETS 31 /* cache hash table size */
201 typedef struct ldapcache {
202 LDAPMessage *lc_buckets[LDAP_CACHE_BUCKETS];/* hash table */
203 LDAPMessage *lc_requests; /* unfulfilled reqs */
204 long lc_timeout; /* request timeout */
205 ber_len_t lc_maxmem; /* memory to use */
206 ber_len_t lc_memused; /* memory in use */
207 int lc_enabled; /* enabled? */
208 unsigned long lc_options; /* options */
209 #define LDAP_CACHE_OPT_CACHENOERRS 0x00000001
210 #define LDAP_CACHE_OPT_CACHEALLERRS 0x00000002
214 * structure containing referral request info for rebind procedure
216 typedef struct ldapreqinfo {
223 * handy macro for checking if handle is connectionless
226 #define LDAP_IS_CLDAP(ld) ((ld)->ld_cldapnaddr>0)
229 * structure representing an ldap connection
233 Sockbuf ld_sb; /* socket descriptor & buffer */
235 struct ldapoptions ld_options;
237 #define ld_valid ld_options.ldo_valid
238 #define ld_debug ld_options.ldo_debug
240 #define ld_deref ld_options.ldo_deref
241 #define ld_timelimit ld_options.ldo_timelimit
242 #define ld_sizelimit ld_options.ldo_sizelimit
244 #define ld_defbinddn ld_options.ldo_defbinddn
245 #define ld_defbase ld_options.ldo_defbase
246 #define ld_defhost ld_options.ldo_defhost
247 #define ld_defport ld_options.ldo_defport
249 #define ld_cldaptries ld_options.ldo_cldaptries
250 #define ld_cldaptimeout ld_options.ldo_cldaptimeout
251 #define ld_refhoplimit ld_options.ldo_refhoplimit
253 #define ld_sctrls ld_options.ldo_sctrls
254 #define ld_cctrls ld_options.ldo_cctrls
255 #define ld_rebindproc ld_options.ldo_rebindproc
257 #define ld_version ld_options.ldo_version
261 unsigned short ld_lberoptions;
263 LDAPFiltDesc *ld_filtd; /* from getfilter for ufn searches */
264 char *ld_ufnprefix; /* for incomplete ufn's */
271 /* do not mess with these */
272 LDAPRequest *ld_requests; /* list of outstanding requests */
273 LDAPMessage *ld_responses; /* list of outstanding responses */
275 ber_int_t *ld_abandoned; /* array of abandoned requests */
277 LDAPCache *ld_cache; /* non-null if cache is initialized */
278 /* stuff used by connectionless searches. */
280 char *ld_cldapdn; /* DN used in connectionless search */
281 int ld_cldapnaddr; /* number of addresses */
282 void **ld_cldapaddrs;/* addresses to send request to */
284 /* do not mess with the rest though */
285 BERTranslateProc ld_lber_encode_translate_proc;
286 BERTranslateProc ld_lber_decode_translate_proc;
288 LDAPConn *ld_defconn; /* default connection */
289 LDAPConn *ld_conns; /* list of server connections */
290 void *ld_selectinfo; /* platform specifics for select */
291 #ifdef HAVE_CYRUS_SASL
292 sasl_conn_t *ld_sasl_context;
293 #endif /* HAVE_CYRUS_SASL */
295 #define LDAP_VALID(ld) ( (ld)->ld_valid == LDAP_VALID_SESSION )
297 #if defined(HAVE_RES_SEARCH) && defined(LDAP_R_COMPILE)
298 #include <ldap_pvt_thread.h>
299 extern ldap_pvt_thread_mutex_t ldap_int_resolv_mutex;
300 #endif /* HAVE_RES_SEARCH && LDAP_R_COMPILE */
306 LIBLDAP_F ( struct ldapoptions ) ldap_int_global_options;
307 LIBLDAP_F ( void ) ldap_int_initialize LDAP_P((int *));
310 /* simple macros to realloc for now */
311 #define LDAP_INT_MALLOC(s) (LBER_MALLOC((s)))
312 #define LDAP_INT_CALLOC(n,s) (LBER_CALLOC((n),(s)))
313 #define LDAP_INT_REALLOC(p,s) (LBER_REALLOC((p),(s)))
314 #define LDAP_INT_FREE(p) (LBER_FREE((p)))
315 #define LDAP_INT_VFREE(v) (LBER_VFREE((void **)(v)))
316 #define LDAP_INT_STRDUP(s) (LBER_STRDUP((s)))
318 #define LDAP_MALLOC(s) (LBER_MALLOC((s)))
319 #define LDAP_CALLOC(n,s) (LBER_CALLOC((n),(s)))
320 #define LDAP_REALLOC(p,s) (LBER_REALLOC((p),(s)))
321 #define LDAP_FREE(p) (LBER_FREE((p)))
322 #define LDAP_VFREE(v) (LBER_VFREE((void **)(v)))
323 #define LDAP_STRDUP(s) (LBER_STRDUP((s)))
328 LIBLDAP_F (void) ldap_int_utils_init LDAP_P(( void ));
334 LIBLDAP_F (int) ldap_log_printf LDAP_P((LDAP *ld, int level, const char *fmt, ...)) LDAP_GCCATTR((format(printf, 3, 4)));
339 LIBLDAP_F (void) ldap_add_request_to_cache LDAP_P(( LDAP *ld, ber_tag_t msgtype,
340 BerElement *request ));
341 LIBLDAP_F (void) ldap_add_result_to_cache LDAP_P(( LDAP *ld, LDAPMessage *result ));
342 LIBLDAP_F (int) ldap_check_cache LDAP_P(( LDAP *ld, ber_tag_t msgtype, BerElement *request ));
347 LIBLDAP_F (LDAPControl *) ldap_control_dup LDAP_P((
348 const LDAPControl *ctrl ));
350 LIBLDAP_F (LDAPControl **) ldap_controls_dup LDAP_P((
351 LDAPControl *const *ctrls ));
353 LIBLDAP_F (int) ldap_int_get_controls LDAP_P((
355 LDAPControl ***ctrlsp));
357 LIBLDAP_F (int) ldap_int_put_controls LDAP_P((
359 LDAPControl *const *ctrls,
365 LIBLDAP_F (int) next_line_tokens LDAP_P(( char **bufp, ber_len_t *blenp, char ***toksp ));
366 LIBLDAP_F (void) free_strarray LDAP_P(( char **sap ));
368 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
372 LIBLDAP_F (char *) ldap_get_kerberosv4_credentials LDAP_P((
374 LDAP_CONST char *who,
375 LDAP_CONST char *service,
378 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND */
384 LIBLDAP_F (int) ldap_open_defconn( LDAP *ld );
385 LIBLDAP_F (int) open_ldap_connection( LDAP *ld, Sockbuf *sb, LDAPURLDesc *srvlist, char **krbinstancep, int async );
390 LIBLDAP_F (int) ldap_int_tblsize;
391 LIBLDAP_F (int) ldap_int_timeval_dup( struct timeval **dest, const struct timeval *tm );
392 LIBLDAP_F (int) ldap_connect_to_host( LDAP *ld, Sockbuf *sb, const char *host, unsigned long address, int port, int async );
394 LIBLDAP_F (void) ldap_close_connection( Sockbuf *sb );
396 #if defined(LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND) || defined(HAVE_TLS) || defined(HAVE_CYRUS_SASL)
397 LIBLDAP_F (char *) ldap_host_connected_to( Sockbuf *sb );
398 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND */
400 LIBLDAP_F (void) ldap_int_ip_init( void );
401 LIBLDAP_F (int) do_ldap_select( LDAP *ld, struct timeval *timeout );
402 LIBLDAP_F (void *) ldap_new_select_info( void );
403 LIBLDAP_F (void) ldap_free_select_info( void *sip );
404 LIBLDAP_F (void) ldap_mark_select_write( LDAP *ld, Sockbuf *sb );
405 LIBLDAP_F (void) ldap_mark_select_read( LDAP *ld, Sockbuf *sb );
406 LIBLDAP_F (void) ldap_mark_select_clear( LDAP *ld, Sockbuf *sb );
407 LIBLDAP_F (int) ldap_is_read_ready( LDAP *ld, Sockbuf *sb );
408 LIBLDAP_F (int) ldap_is_write_ready( LDAP *ld, Sockbuf *sb );
414 LIBLDAP_F (int) ldap_connect_to_path( LDAP *ld, Sockbuf *sb, const char *path, int async );
415 #endif /* LDAP_PF_LOCAL */
420 LIBLDAP_F (ber_int_t) ldap_send_initial_request( LDAP *ld, ber_tag_t msgtype,
421 const char *dn, BerElement *ber );
422 LIBLDAP_F (BerElement *) ldap_alloc_ber_with_options( LDAP *ld );
423 LIBLDAP_F (void) ldap_set_ber_options( LDAP *ld, BerElement *ber );
425 LIBLDAP_F (int) ldap_send_server_request( LDAP *ld, BerElement *ber, ber_int_t msgid, LDAPRequest *parentreq, LDAPURLDesc *srvlist, LDAPConn *lc, LDAPreqinfo *bind );
426 LIBLDAP_F (LDAPConn *) ldap_new_connection( LDAP *ld, LDAPURLDesc *srvlist, int use_ldsb, int connect, LDAPreqinfo *bind );
427 LIBLDAP_F (LDAPRequest *) ldap_find_request_by_msgid( LDAP *ld, ber_int_t msgid );
428 LIBLDAP_F (void) ldap_free_request( LDAP *ld, LDAPRequest *lr );
429 LIBLDAP_F (void) ldap_free_connection( LDAP *ld, LDAPConn *lc, int force, int unbind );
430 LIBLDAP_F (void) ldap_dump_connection( LDAP *ld, LDAPConn *lconns, int all );
431 LIBLDAP_F (void) ldap_dump_requests_and_responses( LDAP *ld );
432 LIBLDAP_F (int) ldap_chase_referrals( LDAP *ld, LDAPRequest *lr, char **errstrp, int *hadrefp );
433 LIBLDAP_F (int) ldap_chase_v3referrals( LDAP *ld, LDAPRequest *lr, char **refs, char **referralsp, int *hadrefp );
434 LIBLDAP_F (int) ldap_append_referral( LDAP *ld, char **referralsp, char *s );
439 #ifdef LDAP_CONNECTIONLESS
440 LIBLDAP_F (int) cldap_getmsg( LDAP *ld, struct timeval *timeout, BerElement *ber );
446 LIBLDAP_F (BerElement *) ldap_build_search_req LDAP_P((
453 LDAPControl **sctrls,
454 LDAPControl **cctrls,
456 ber_int_t sizelimit ));
461 /* see <ac/string.h> */
466 LIBLDAP_F (int) ldap_ld_free LDAP_P((
469 LDAPControl **sctrls,
470 LDAPControl **cctrls ));
472 LIBLDAP_F (int) ldap_send_unbind LDAP_P((
475 LDAPControl **sctrls,
476 LDAPControl **cctrls ));
481 LIBLDAP_F (LDAPURLDesc *) ldap_url_dup LDAP_P((
482 LDAPURLDesc *ludp ));
484 LIBLDAP_F (LDAPURLDesc *) ldap_url_duplist LDAP_P((
485 LDAPURLDesc *ludlist ));
487 LIBLDAP_F (int) ldap_url_parselist LDAP_P((
488 LDAPURLDesc **ludlist,
491 LIBLDAP_F (int) ldap_url_parsehosts LDAP_P((
492 LDAPURLDesc **ludlist,
493 const char *hosts ));
495 LIBLDAP_F (char *) ldap_url_list2hosts LDAP_P((
496 LDAPURLDesc *ludlist ));
498 LIBLDAP_F (char *) ldap_url_list2urls LDAP_P((
499 LDAPURLDesc *ludlist ));
501 LIBLDAP_F (void) ldap_free_urllist LDAP_P((
502 LDAPURLDesc *ludlist ));
505 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
509 LIBLDAP_F (char **) ldap_getdxbyname( const char *domain );
510 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
512 #if defined( STR_TRANSLATION ) && defined( LDAP_DEFAULT_CHARSET )
516 * added-in this stuff so that libldap.a would build, i.e. refs to
517 * these routines from open.c would resolve.
518 * hodges@stanford.edu 5-Feb-96
520 #if LDAP_CHARSET_8859 == LDAP_DEFAULT_CHARSET
521 LIBLDAP_F (int) ldap_t61_to_8859( char **bufp, ber_len_t *buflenp, int free_input );
522 LIBLDAP_F (int) ldap_8859_to_t61( char **bufp, ber_len_t *buflenp, int free_input );
523 #endif /* LDAP_CHARSET_8859 == LDAP_DEFAULT_CHARSET */
524 #endif /* STR_TRANSLATION && LDAP_DEFAULT_CHARSET */
528 #endif /* _LDAP_INT_H */