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)
27 #define Debug( level, fmt, arg1, arg2, arg3 ) \
28 ldap_log_printf( NULL, (level), (fmt), (arg1), (arg2), (arg3) )
36 #define LDAP_URL_PREFIX "ldap://"
37 #define LDAP_URL_PREFIX_LEN (sizeof(LDAP_URL_PREFIX)-1)
38 #define LDAPS_URL_PREFIX "ldaps://"
39 #define LDAPS_URL_PREFIX_LEN (sizeof(LDAPS_URL_PREFIX)-1)
40 #define LDAPI_URL_PREFIX "ldapi://"
41 #define LDAPI_URL_PREFIX_LEN (sizeof(LDAPI_URL_PREFIX)-1)
42 #define LDAPIS_URL_PREFIX "ldapis://"
43 #define LDAPIS_URL_PREFIX_LEN (sizeof(LDAPIS_URL_PREFIX)-1)
44 #define LDAP_URL_URLCOLON "URL:"
45 #define LDAP_URL_URLCOLON_LEN (sizeof(LDAP_URL_URLCOLON)-1)
46 #define NULLLDAPURLDESC ((LDAPURLDesc *)NULL)
48 #define LDAP_REF_STR "Referral:\n"
49 #define LDAP_REF_STR_LEN (sizeof(LDAP_REF_STR)-1)
50 #define LDAP_LDAP_REF_STR LDAP_URL_PREFIX
51 #define LDAP_LDAP_REF_STR_LEN (sizeof(LDAP_LDAP_REF_STR)-1)
53 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
54 #define LDAP_DX_REF_STR "dx://"
55 #define LDAP_DX_REF_STR_LEN (sizeof(LDAP_DX_REF_STR)-1)
56 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
58 #define LDAP_DEFAULT_REFHOPLIMIT 5
60 #define LDAP_BOOL_REFERRALS 0
61 #define LDAP_BOOL_RESTART 1
62 #define LDAP_BOOL_DNS 2
63 #define LDAP_BOOL_TLS 3
65 #define LDAP_BOOLEANS unsigned long
66 #define LDAP_BOOL(n) (1 << (n))
67 #define LDAP_BOOL_GET(lo, bool) ((lo)->ldo_booleans & LDAP_BOOL(bool) \
69 #define LDAP_BOOL_SET(lo, bool) ((lo)->ldo_booleans |= LDAP_BOOL(bool))
70 #define LDAP_BOOL_CLR(lo, bool) ((lo)->ldo_booleans &= ~LDAP_BOOL(bool))
71 #define LDAP_BOOL_ZERO(lo) ((lo)->ldo_booleans = 0)
74 * This structure represents both ldap messages and ldap responses.
75 * These are really the same, except in the case of search responses,
76 * where a response has multiple messages.
80 ber_int_t lm_msgid; /* the message id */
81 ber_tag_t lm_msgtype; /* the message type */
82 BerElement *lm_ber; /* the ber encoded message contents */
83 struct ldapmsg *lm_chain; /* for search - next msg in the resp */
84 struct ldapmsg *lm_next; /* next response */
85 time_t lm_time; /* used to maintain cache */
89 * structure representing get/set'able options
90 * which have global defaults.
94 #define LDAP_UNINITIALIZED 0x0
95 #define LDAP_INITIALIZED 0x1
96 #define LDAP_VALID_SESSION 0x2
99 /* per API call timeout */
100 struct timeval *ldo_tm_api;
101 struct timeval *ldo_tm_net;
103 ber_int_t ldo_version;
105 ber_int_t ldo_timelimit;
106 ber_int_t ldo_sizelimit;
108 LDAPURLDesc *ldo_defludp;
111 char* ldo_defbinddn; /* simple bind dn */
113 #ifdef LDAP_CONNECTIONLESS
114 int ldo_cldaptries; /* connectionless search retry count */
115 int ldo_cldaptimeout;/* time between retries */
118 int ldo_refhoplimit; /* limit on referral nesting */
120 /* LDAPv3 server and client controls */
121 LDAPControl **ldo_sctrls;
122 LDAPControl **ldo_cctrls;
123 /* LDAPV3 rebind callback function
125 LDAP_REBIND_PROC *ldo_rebindproc;
132 #ifdef HAVE_CYRUS_SASL
133 sasl_ssf_t ldo_sasl_minssf;
134 sasl_ssf_t ldo_sasl_maxssf;
136 LDAP_BOOLEANS ldo_booleans; /* boolean options */
141 * structure for tracking LDAP server host, ports, DNs, etc.
143 typedef struct ldap_server {
145 char *lsrv_dn; /* if NULL, use default */
147 /* int lsrv_protocol; */
148 struct ldap_server *lsrv_next;
153 * structure for representing an LDAP server connection
155 typedef struct ldap_conn {
158 time_t lconn_lastused; /* time */
159 int lconn_rebind_inprogress; /* set if rebind in progress */
160 char ***lconn_rebind_queue; /* used if rebind in progress */
162 #define LDAP_CONNST_NEEDSOCKET 1
163 #define LDAP_CONNST_CONNECTING 2
164 #define LDAP_CONNST_CONNECTED 3
165 LDAPURLDesc *lconn_server;
166 char *lconn_krbinstance;
167 struct ldap_conn *lconn_next;
168 BerElement *lconn_ber;/* ber receiving on this conn. */
173 * structure used to track outstanding requests
175 typedef struct ldapreq {
176 ber_int_t lr_msgid; /* the message id */
177 int lr_status; /* status of request */
178 #define LDAP_REQST_COMPLETED 0
179 #define LDAP_REQST_INPROGRESS 1
180 #define LDAP_REQST_CHASINGREFS 2
181 #define LDAP_REQST_NOTCONNECTED 3
182 #define LDAP_REQST_WRITING 4
183 int lr_outrefcnt; /* count of outstanding referrals */
184 ber_int_t lr_origid; /* original request's message id */
185 int lr_parentcnt; /* count of parent requests */
186 ber_tag_t lr_res_msgtype; /* result message type */
187 ber_int_t lr_res_errno; /* result LDAP errno */
188 char *lr_res_error; /* result error string */
189 char *lr_res_matched;/* result matched DN string */
190 BerElement *lr_ber; /* ber encoded request contents */
191 LDAPConn *lr_conn; /* connection used to send request */
192 struct ldapreq *lr_parent; /* request that spawned this referral */
193 struct ldapreq *lr_refnext; /* next referral spawned */
194 struct ldapreq *lr_prev; /* previous request */
195 struct ldapreq *lr_next; /* next request */
199 * structure for client cache
201 #define LDAP_CACHE_BUCKETS 31 /* cache hash table size */
202 typedef struct ldapcache {
203 LDAPMessage *lc_buckets[LDAP_CACHE_BUCKETS];/* hash table */
204 LDAPMessage *lc_requests; /* unfulfilled reqs */
205 long lc_timeout; /* request timeout */
206 ber_len_t lc_maxmem; /* memory to use */
207 ber_len_t lc_memused; /* memory in use */
208 int lc_enabled; /* enabled? */
209 unsigned long lc_options; /* options */
210 #define LDAP_CACHE_OPT_CACHENOERRS 0x00000001
211 #define LDAP_CACHE_OPT_CACHEALLERRS 0x00000002
215 * structure containing referral request info for rebind procedure
217 typedef struct ldapreqinfo {
224 * handy macro for checking if handle is connectionless
227 #define LDAP_IS_CLDAP(ld) ((ld)->ld_cldapnaddr>0)
230 * structure representing an ldap connection
234 Sockbuf *ld_sb; /* socket descriptor & buffer */
236 struct ldapoptions ld_options;
238 #define ld_valid ld_options.ldo_valid
239 #define ld_debug ld_options.ldo_debug
241 #define ld_deref ld_options.ldo_deref
242 #define ld_timelimit ld_options.ldo_timelimit
243 #define ld_sizelimit ld_options.ldo_sizelimit
245 #define ld_defbinddn ld_options.ldo_defbinddn
246 #define ld_defbase ld_options.ldo_defbase
247 #define ld_defhost ld_options.ldo_defhost
248 #define ld_defport ld_options.ldo_defport
250 #define ld_cldaptries ld_options.ldo_cldaptries
251 #define ld_cldaptimeout ld_options.ldo_cldaptimeout
252 #define ld_refhoplimit ld_options.ldo_refhoplimit
254 #define ld_sctrls ld_options.ldo_sctrls
255 #define ld_cctrls ld_options.ldo_cctrls
256 #define ld_rebindproc ld_options.ldo_rebindproc
258 #define ld_version ld_options.ldo_version
262 unsigned short ld_lberoptions;
264 LDAPFiltDesc *ld_filtd; /* from getfilter for ufn searches */
265 char *ld_ufnprefix; /* for incomplete ufn's */
272 /* do not mess with these */
273 LDAPRequest *ld_requests; /* list of outstanding requests */
274 LDAPMessage *ld_responses; /* list of outstanding responses */
276 ber_int_t *ld_abandoned; /* array of abandoned requests */
278 LDAPCache *ld_cache; /* non-null if cache is initialized */
279 /* stuff used by connectionless searches. */
281 char *ld_cldapdn; /* DN used in connectionless search */
282 int ld_cldapnaddr; /* number of addresses */
283 void **ld_cldapaddrs;/* addresses to send request to */
285 /* do not mess with the rest though */
286 BERTranslateProc ld_lber_encode_translate_proc;
287 BERTranslateProc ld_lber_decode_translate_proc;
289 LDAPConn *ld_defconn; /* default connection */
290 LDAPConn *ld_conns; /* list of server connections */
291 void *ld_selectinfo; /* platform specifics for select */
292 #ifdef HAVE_CYRUS_SASL
293 sasl_conn_t *ld_sasl_context;
294 #endif /* HAVE_CYRUS_SASL */
296 #define LDAP_VALID(ld) ( (ld)->ld_valid == LDAP_VALID_SESSION )
298 #if defined(HAVE_RES_SEARCH) && defined(LDAP_R_COMPILE)
299 #include <ldap_pvt_thread.h>
300 extern ldap_pvt_thread_mutex_t ldap_int_resolv_mutex;
301 #endif /* HAVE_RES_SEARCH && LDAP_R_COMPILE */
307 LIBLDAP_F ( struct ldapoptions ) ldap_int_global_options;
308 LIBLDAP_F ( void ) ldap_int_initialize LDAP_P((int *));
311 /* simple macros to realloc for now */
312 #define LDAP_INT_MALLOC(s) (LBER_MALLOC((s)))
313 #define LDAP_INT_CALLOC(n,s) (LBER_CALLOC((n),(s)))
314 #define LDAP_INT_REALLOC(p,s) (LBER_REALLOC((p),(s)))
315 #define LDAP_INT_FREE(p) (LBER_FREE((p)))
316 #define LDAP_INT_VFREE(v) (LBER_VFREE((void **)(v)))
317 #define LDAP_INT_STRDUP(s) (LBER_STRDUP((s)))
319 #define LDAP_MALLOC(s) (LBER_MALLOC((s)))
320 #define LDAP_CALLOC(n,s) (LBER_CALLOC((n),(s)))
321 #define LDAP_REALLOC(p,s) (LBER_REALLOC((p),(s)))
322 #define LDAP_FREE(p) (LBER_FREE((p)))
323 #define LDAP_VFREE(v) (LBER_VFREE((void **)(v)))
324 #define LDAP_STRDUP(s) (LBER_STRDUP((s)))
329 LIBLDAP_F (void) ldap_int_utils_init LDAP_P(( void ));
335 LIBLDAP_F (int) ldap_log_printf LDAP_P((LDAP *ld, int level, const char *fmt, ...)) LDAP_GCCATTR((format(printf, 3, 4)));
340 LIBLDAP_F (void) ldap_add_request_to_cache LDAP_P(( LDAP *ld, ber_tag_t msgtype,
341 BerElement *request ));
342 LIBLDAP_F (void) ldap_add_result_to_cache LDAP_P(( LDAP *ld, LDAPMessage *result ));
343 LIBLDAP_F (int) ldap_check_cache LDAP_P(( LDAP *ld, ber_tag_t msgtype, BerElement *request ));
348 LIBLDAP_F (LDAPControl *) ldap_control_dup LDAP_P((
349 const LDAPControl *ctrl ));
351 LIBLDAP_F (LDAPControl **) ldap_controls_dup LDAP_P((
352 LDAPControl *const *ctrls ));
354 LIBLDAP_F (int) ldap_int_get_controls LDAP_P((
356 LDAPControl ***ctrlsp));
358 LIBLDAP_F (int) ldap_int_put_controls LDAP_P((
360 LDAPControl *const *ctrls,
366 LIBLDAP_F (int) next_line_tokens LDAP_P(( char **bufp, ber_len_t *blenp, char ***toksp ));
367 LIBLDAP_F (void) free_strarray LDAP_P(( char **sap ));
369 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
373 LIBLDAP_F (char *) ldap_get_kerberosv4_credentials LDAP_P((
375 LDAP_CONST char *who,
376 LDAP_CONST char *service,
379 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND */
385 LIBLDAP_F (int) ldap_open_defconn( LDAP *ld );
386 LIBLDAP_F (int) open_ldap_connection( LDAP *ld, Sockbuf *sb, LDAPURLDesc *srvlist, char **krbinstancep, int async );
391 LIBLDAP_F (int) ldap_int_tblsize;
392 LIBLDAP_F (int) ldap_int_timeval_dup( struct timeval **dest, const struct timeval *tm );
393 LIBLDAP_F (int) ldap_connect_to_host( LDAP *ld, Sockbuf *sb, const char *host, unsigned long address, int port, int async );
395 #if defined(LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND) || defined(HAVE_TLS) || defined(HAVE_CYRUS_SASL)
396 LIBLDAP_F (char *) ldap_host_connected_to( Sockbuf *sb );
397 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND */
399 LIBLDAP_F (void) ldap_int_ip_init( void );
400 LIBLDAP_F (int) do_ldap_select( LDAP *ld, struct timeval *timeout );
401 LIBLDAP_F (void *) ldap_new_select_info( void );
402 LIBLDAP_F (void) ldap_free_select_info( void *sip );
403 LIBLDAP_F (void) ldap_mark_select_write( LDAP *ld, Sockbuf *sb );
404 LIBLDAP_F (void) ldap_mark_select_read( LDAP *ld, Sockbuf *sb );
405 LIBLDAP_F (void) ldap_mark_select_clear( LDAP *ld, Sockbuf *sb );
406 LIBLDAP_F (int) ldap_is_read_ready( LDAP *ld, Sockbuf *sb );
407 LIBLDAP_F (int) ldap_is_write_ready( LDAP *ld, Sockbuf *sb );
413 LIBLDAP_F (int) ldap_connect_to_path( LDAP *ld, Sockbuf *sb, const char *path, int async );
414 #endif /* LDAP_PF_LOCAL */
419 LIBLDAP_F (ber_int_t) ldap_send_initial_request( LDAP *ld, ber_tag_t msgtype,
420 const char *dn, BerElement *ber );
421 LIBLDAP_F (BerElement *) ldap_alloc_ber_with_options( LDAP *ld );
422 LIBLDAP_F (void) ldap_set_ber_options( LDAP *ld, BerElement *ber );
424 LIBLDAP_F (int) ldap_send_server_request( LDAP *ld, BerElement *ber, ber_int_t msgid, LDAPRequest *parentreq, LDAPURLDesc *srvlist, LDAPConn *lc, LDAPreqinfo *bind );
425 LIBLDAP_F (LDAPConn *) ldap_new_connection( LDAP *ld, LDAPURLDesc *srvlist, int use_ldsb, int connect, LDAPreqinfo *bind );
426 LIBLDAP_F (LDAPRequest *) ldap_find_request_by_msgid( LDAP *ld, ber_int_t msgid );
427 LIBLDAP_F (void) ldap_free_request( LDAP *ld, LDAPRequest *lr );
428 LIBLDAP_F (void) ldap_free_connection( LDAP *ld, LDAPConn *lc, int force, int unbind );
429 LIBLDAP_F (void) ldap_dump_connection( LDAP *ld, LDAPConn *lconns, int all );
430 LIBLDAP_F (void) ldap_dump_requests_and_responses( LDAP *ld );
431 LIBLDAP_F (int) ldap_chase_referrals( LDAP *ld, LDAPRequest *lr, char **errstrp, int *hadrefp );
432 LIBLDAP_F (int) ldap_chase_v3referrals( LDAP *ld, LDAPRequest *lr, char **refs, char **referralsp, int *hadrefp );
433 LIBLDAP_F (int) ldap_append_referral( LDAP *ld, char **referralsp, char *s );
438 #ifdef LDAP_CONNECTIONLESS
439 LIBLDAP_F (int) cldap_getmsg( LDAP *ld, struct timeval *timeout, BerElement *ber );
445 LIBLDAP_F (BerElement *) ldap_build_search_req LDAP_P((
452 LDAPControl **sctrls,
453 LDAPControl **cctrls,
455 ber_int_t sizelimit ));
460 /* see <ac/string.h> */
465 LIBLDAP_F (int) ldap_ld_free LDAP_P((
468 LDAPControl **sctrls,
469 LDAPControl **cctrls ));
471 LIBLDAP_F (int) ldap_send_unbind LDAP_P((
474 LDAPControl **sctrls,
475 LDAPControl **cctrls ));
480 LIBLDAP_F (LDAPURLDesc *) ldap_url_dup LDAP_P((
481 LDAPURLDesc *ludp ));
483 LIBLDAP_F (LDAPURLDesc *) ldap_url_duplist LDAP_P((
484 LDAPURLDesc *ludlist ));
486 LIBLDAP_F (int) ldap_url_parselist LDAP_P((
487 LDAPURLDesc **ludlist,
490 LIBLDAP_F (int) ldap_url_parsehosts LDAP_P((
491 LDAPURLDesc **ludlist,
492 const char *hosts ));
494 LIBLDAP_F (char *) ldap_url_list2hosts LDAP_P((
495 LDAPURLDesc *ludlist ));
497 LIBLDAP_F (char *) ldap_url_list2urls LDAP_P((
498 LDAPURLDesc *ludlist ));
500 LIBLDAP_F (void) ldap_free_urllist LDAP_P((
501 LDAPURLDesc *ludlist ));
504 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
508 LIBLDAP_F (char **) ldap_getdxbyname( const char *domain );
509 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
511 #if defined( STR_TRANSLATION ) && defined( LDAP_DEFAULT_CHARSET )
515 * added-in this stuff so that libldap.a would build, i.e. refs to
516 * these routines from open.c would resolve.
517 * hodges@stanford.edu 5-Feb-96
519 #if LDAP_CHARSET_8859 == LDAP_DEFAULT_CHARSET
520 LIBLDAP_F (int) ldap_t61_to_8859( char **bufp, ber_len_t *buflenp, int free_input );
521 LIBLDAP_F (int) ldap_8859_to_t61( char **bufp, ber_len_t *buflenp, int free_input );
522 #endif /* LDAP_CHARSET_8859 == LDAP_DEFAULT_CHARSET */
523 #endif /* STR_TRANSLATION && LDAP_DEFAULT_CHARSET */
527 #endif /* _LDAP_INT_H */