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"
23 * Support needed if the library is running in the kernel
25 #if LDAP_INT_IN_KERNEL
27 * Platform specific function to return a pointer to the
28 * process-specific global options.
30 * This function should perform the following functions:
31 * Allocate and initialize a global options struct on a per process basis
32 * Use callers process identifier to return its global options struct
33 * Note: Deallocate structure when the process exits
35 # define LDAP_INT_GLOBAL_OPT() ldap_int_global_opt()
36 struct ldapoptions *ldap_int_global_opt(void);
38 # define LDAP_INT_GLOBAL_OPT() (&ldap_int_global_options)
41 #define ldap_debug ((LDAP_INT_GLOBAL_OPT())->ldo_debug)
46 #define Debug( level, fmt, arg1, arg2, arg3 ) \
47 ldap_log_printf( NULL, (level), (fmt), (arg1), (arg2), (arg3) )
55 #define LDAP_URL_PREFIX "ldap://"
56 #define LDAP_URL_PREFIX_LEN (sizeof(LDAP_URL_PREFIX)-1)
57 #define LDAPS_URL_PREFIX "ldaps://"
58 #define LDAPS_URL_PREFIX_LEN (sizeof(LDAPS_URL_PREFIX)-1)
59 #define LDAPI_URL_PREFIX "ldapi://"
60 #define LDAPI_URL_PREFIX_LEN (sizeof(LDAPI_URL_PREFIX)-1)
61 #define LDAPIS_URL_PREFIX "ldapis://"
62 #define LDAPIS_URL_PREFIX_LEN (sizeof(LDAPIS_URL_PREFIX)-1)
63 #define LDAP_URL_URLCOLON "URL:"
64 #define LDAP_URL_URLCOLON_LEN (sizeof(LDAP_URL_URLCOLON)-1)
65 #define NULLLDAPURLDESC ((LDAPURLDesc *)NULL)
67 #define LDAP_REF_STR "Referral:\n"
68 #define LDAP_REF_STR_LEN (sizeof(LDAP_REF_STR)-1)
69 #define LDAP_LDAP_REF_STR LDAP_URL_PREFIX
70 #define LDAP_LDAP_REF_STR_LEN (sizeof(LDAP_LDAP_REF_STR)-1)
73 #define LDAP_DEFAULT_REFHOPLIMIT 5
75 #define LDAP_BOOL_REFERRALS 0
76 #define LDAP_BOOL_RESTART 1
77 #define LDAP_BOOL_TLS 3
79 #define LDAP_BOOLEANS unsigned long
80 #define LDAP_BOOL(n) (1 << (n))
81 #define LDAP_BOOL_GET(lo, bool) ((lo)->ldo_booleans & LDAP_BOOL(bool) \
83 #define LDAP_BOOL_SET(lo, bool) ((lo)->ldo_booleans |= LDAP_BOOL(bool))
84 #define LDAP_BOOL_CLR(lo, bool) ((lo)->ldo_booleans &= ~LDAP_BOOL(bool))
85 #define LDAP_BOOL_ZERO(lo) ((lo)->ldo_booleans = 0)
88 * This structure represents both ldap messages and ldap responses.
89 * These are really the same, except in the case of search responses,
90 * where a response has multiple messages.
94 ber_int_t lm_msgid; /* the message id */
95 ber_tag_t lm_msgtype; /* the message type */
96 BerElement *lm_ber; /* the ber encoded message contents */
97 struct ldapmsg *lm_chain; /* for search - next msg in the resp */
98 struct ldapmsg *lm_next; /* next response */
99 time_t lm_time; /* used to maintain cache */
103 * structure representing get/set'able options
104 * which have global defaults.
108 #define LDAP_UNINITIALIZED 0x0
109 #define LDAP_INITIALIZED 0x1
110 #define LDAP_VALID_SESSION 0x2
113 /* per API call timeout */
114 struct timeval *ldo_tm_api;
115 struct timeval *ldo_tm_net;
117 ber_int_t ldo_version;
119 ber_int_t ldo_timelimit;
120 ber_int_t ldo_sizelimit;
122 LDAPURLDesc *ldo_defludp;
125 char* ldo_defbinddn; /* simple bind dn */
127 #ifdef LDAP_CONNECTIONLESS
128 int ldo_cldaptries; /* connectionless search retry count */
129 int ldo_cldaptimeout;/* time between retries */
132 int ldo_refhoplimit; /* limit on referral nesting */
134 /* LDAPv3 server and client controls */
135 LDAPControl **ldo_sctrls;
136 LDAPControl **ldo_cctrls;
137 /* LDAPV3 rebind callback function
139 LDAP_REBIND_PROC *ldo_rebindproc;
146 #ifdef HAVE_CYRUS_SASL
147 sasl_ssf_t ldo_sasl_minssf;
148 sasl_ssf_t ldo_sasl_maxssf;
150 LDAP_BOOLEANS ldo_booleans; /* boolean options */
155 * structure for tracking LDAP server host, ports, DNs, etc.
157 typedef struct ldap_server {
159 char *lsrv_dn; /* if NULL, use default */
161 /* int lsrv_protocol; */
162 struct ldap_server *lsrv_next;
167 * structure for representing an LDAP server connection
169 typedef struct ldap_conn {
172 time_t lconn_lastused; /* time */
173 int lconn_rebind_inprogress; /* set if rebind in progress */
174 char ***lconn_rebind_queue; /* used if rebind in progress */
176 #define LDAP_CONNST_NEEDSOCKET 1
177 #define LDAP_CONNST_CONNECTING 2
178 #define LDAP_CONNST_CONNECTED 3
179 LDAPURLDesc *lconn_server;
180 char *lconn_krbinstance;
181 struct ldap_conn *lconn_next;
182 BerElement *lconn_ber;/* ber receiving on this conn. */
187 * structure used to track outstanding requests
189 typedef struct ldapreq {
190 ber_int_t lr_msgid; /* the message id */
191 int lr_status; /* status of request */
192 #define LDAP_REQST_COMPLETED 0
193 #define LDAP_REQST_INPROGRESS 1
194 #define LDAP_REQST_CHASINGREFS 2
195 #define LDAP_REQST_NOTCONNECTED 3
196 #define LDAP_REQST_WRITING 4
197 int lr_outrefcnt; /* count of outstanding referrals */
198 ber_int_t lr_origid; /* original request's message id */
199 int lr_parentcnt; /* count of parent requests */
200 ber_tag_t lr_res_msgtype; /* result message type */
201 ber_int_t lr_res_errno; /* result LDAP errno */
202 char *lr_res_error; /* result error string */
203 char *lr_res_matched;/* result matched DN string */
204 BerElement *lr_ber; /* ber encoded request contents */
205 LDAPConn *lr_conn; /* connection used to send request */
206 struct ldapreq *lr_parent; /* request that spawned this referral */
207 struct ldapreq *lr_refnext; /* next referral spawned */
208 struct ldapreq *lr_prev; /* previous request */
209 struct ldapreq *lr_next; /* next request */
213 * structure for client cache
215 #define LDAP_CACHE_BUCKETS 31 /* cache hash table size */
216 typedef struct ldapcache {
217 LDAPMessage *lc_buckets[LDAP_CACHE_BUCKETS];/* hash table */
218 LDAPMessage *lc_requests; /* unfulfilled reqs */
219 long lc_timeout; /* request timeout */
220 ber_len_t lc_maxmem; /* memory to use */
221 ber_len_t lc_memused; /* memory in use */
222 int lc_enabled; /* enabled? */
223 unsigned long lc_options; /* options */
224 #define LDAP_CACHE_OPT_CACHENOERRS 0x00000001
225 #define LDAP_CACHE_OPT_CACHEALLERRS 0x00000002
229 * structure containing referral request info for rebind procedure
231 typedef struct ldapreqinfo {
238 * handy macro for checking if handle is connectionless
241 #define LDAP_IS_CLDAP(ld) ((ld)->ld_cldapnaddr>0)
244 * structure representing an ldap connection
248 Sockbuf *ld_sb; /* socket descriptor & buffer */
250 struct ldapoptions ld_options;
252 #define ld_valid ld_options.ldo_valid
253 #define ld_debug ld_options.ldo_debug
255 #define ld_deref ld_options.ldo_deref
256 #define ld_timelimit ld_options.ldo_timelimit
257 #define ld_sizelimit ld_options.ldo_sizelimit
259 #define ld_defbinddn ld_options.ldo_defbinddn
260 #define ld_defbase ld_options.ldo_defbase
261 #define ld_defhost ld_options.ldo_defhost
262 #define ld_defport ld_options.ldo_defport
264 #define ld_cldaptries ld_options.ldo_cldaptries
265 #define ld_cldaptimeout ld_options.ldo_cldaptimeout
266 #define ld_refhoplimit ld_options.ldo_refhoplimit
268 #define ld_sctrls ld_options.ldo_sctrls
269 #define ld_cctrls ld_options.ldo_cctrls
270 #define ld_rebindproc ld_options.ldo_rebindproc
272 #define ld_version ld_options.ldo_version
276 unsigned short ld_lberoptions;
278 LDAPFiltDesc *ld_filtd; /* from getfilter for ufn searches */
279 char *ld_ufnprefix; /* for incomplete ufn's */
286 /* do not mess with these */
287 LDAPRequest *ld_requests; /* list of outstanding requests */
288 LDAPMessage *ld_responses; /* list of outstanding responses */
290 ber_int_t *ld_abandoned; /* array of abandoned requests */
292 LDAPCache *ld_cache; /* non-null if cache is initialized */
293 /* stuff used by connectionless searches. */
295 char *ld_cldapdn; /* DN used in connectionless search */
296 int ld_cldapnaddr; /* number of addresses */
297 void **ld_cldapaddrs;/* addresses to send request to */
299 /* do not mess with the rest though */
301 LDAPConn *ld_defconn; /* default connection */
302 LDAPConn *ld_conns; /* list of server connections */
303 void *ld_selectinfo; /* platform specifics for select */
304 #ifdef HAVE_CYRUS_SASL
305 sasl_conn_t *ld_sasl_context;
306 #endif /* HAVE_CYRUS_SASL */
308 #define LDAP_VALID(ld) ( (ld)->ld_valid == LDAP_VALID_SESSION )
310 #if defined(HAVE_RES_QUERY) && defined(LDAP_R_COMPILE)
311 #include <ldap_pvt_thread.h>
312 extern ldap_pvt_thread_mutex_t ldap_int_resolv_mutex;
313 #endif /* HAVE_RES_QUERY && LDAP_R_COMPILE */
319 LIBLDAP_F ( struct ldapoptions ) ldap_int_global_options;
320 LIBLDAP_F ( void ) ldap_int_initialize LDAP_P((struct ldapoptions *, int *));
321 LIBLDAP_F ( void ) ldap_int_initialize_global_options LDAP_P((
322 struct ldapoptions *, int *));
325 /* simple macros to realloc for now */
326 #define LDAP_INT_MALLOC(s) (LBER_MALLOC((s)))
327 #define LDAP_INT_CALLOC(n,s) (LBER_CALLOC((n),(s)))
328 #define LDAP_INT_REALLOC(p,s) (LBER_REALLOC((p),(s)))
329 #define LDAP_INT_FREE(p) (LBER_FREE((p)))
330 #define LDAP_INT_VFREE(v) (LBER_VFREE((void **)(v)))
331 #define LDAP_INT_STRDUP(s) (LBER_STRDUP((s)))
333 #define LDAP_MALLOC(s) (LBER_MALLOC((s)))
334 #define LDAP_CALLOC(n,s) (LBER_CALLOC((n),(s)))
335 #define LDAP_REALLOC(p,s) (LBER_REALLOC((p),(s)))
336 #define LDAP_FREE(p) (LBER_FREE((p)))
337 #define LDAP_VFREE(v) (LBER_VFREE((void **)(v)))
338 #define LDAP_STRDUP(s) (LBER_STRDUP((s)))
343 LIBLDAP_F (void) ldap_int_utils_init LDAP_P(( void ));
349 LIBLDAP_F (int) ldap_log_printf LDAP_P((LDAP *ld, int level, const char *fmt, ...)) LDAP_GCCATTR((format(printf, 3, 4)));
354 LIBLDAP_F (void) ldap_add_request_to_cache LDAP_P(( LDAP *ld, ber_tag_t msgtype,
355 BerElement *request ));
356 LIBLDAP_F (void) ldap_add_result_to_cache LDAP_P(( LDAP *ld, LDAPMessage *result ));
357 LIBLDAP_F (int) ldap_check_cache LDAP_P(( LDAP *ld, ber_tag_t msgtype, BerElement *request ));
362 LIBLDAP_F (LDAPControl *) ldap_control_dup LDAP_P((
363 const LDAPControl *ctrl ));
365 LIBLDAP_F (LDAPControl **) ldap_controls_dup LDAP_P((
366 LDAPControl *const *ctrls ));
368 LIBLDAP_F (int) ldap_int_get_controls LDAP_P((
370 LDAPControl ***ctrlsp));
372 LIBLDAP_F (int) ldap_int_put_controls LDAP_P((
374 LDAPControl *const *ctrls,
378 ldap_int_create_control LDAP_P((
379 const char *requestOID,
382 LDAPControl **ctrlp ));
387 LIBLDAP_F (int) ldap_int_next_line_tokens LDAP_P(( char **bufp, ber_len_t *blenp, char ***toksp ));
389 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
393 LIBLDAP_F (char *) ldap_get_kerberosv4_credentials LDAP_P((
395 LDAP_CONST char *who,
396 LDAP_CONST char *service,
399 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND */
405 LIBLDAP_F (int) ldap_open_defconn( LDAP *ld );
406 LIBLDAP_F (int) open_ldap_connection( LDAP *ld, Sockbuf *sb, LDAPURLDesc *srvlist, char **krbinstancep, int async );
411 LIBLDAP_F (int) ldap_int_tblsize;
412 LIBLDAP_F (int) ldap_int_timeval_dup( struct timeval **dest, const struct timeval *tm );
413 LIBLDAP_F (int) ldap_connect_to_host( LDAP *ld, Sockbuf *sb, const char *host, unsigned long address, int port, int async );
415 #if defined(LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND) || defined(HAVE_TLS) || defined(HAVE_CYRUS_SASL)
416 LIBLDAP_F (char *) ldap_host_connected_to( Sockbuf *sb );
417 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND */
419 LIBLDAP_F (void) ldap_int_ip_init( void );
420 LIBLDAP_F (int) do_ldap_select( LDAP *ld, struct timeval *timeout );
421 LIBLDAP_F (void *) ldap_new_select_info( void );
422 LIBLDAP_F (void) ldap_free_select_info( void *sip );
423 LIBLDAP_F (void) ldap_mark_select_write( LDAP *ld, Sockbuf *sb );
424 LIBLDAP_F (void) ldap_mark_select_read( LDAP *ld, Sockbuf *sb );
425 LIBLDAP_F (void) ldap_mark_select_clear( LDAP *ld, Sockbuf *sb );
426 LIBLDAP_F (int) ldap_is_read_ready( LDAP *ld, Sockbuf *sb );
427 LIBLDAP_F (int) ldap_is_write_ready( LDAP *ld, Sockbuf *sb );
433 LIBLDAP_F (int) ldap_connect_to_path( LDAP *ld, Sockbuf *sb, const char *path, int async );
434 #endif /* LDAP_PF_UNIX */
439 LIBLDAP_F (ber_int_t) ldap_send_initial_request( LDAP *ld, ber_tag_t msgtype,
440 const char *dn, BerElement *ber );
441 LIBLDAP_F (BerElement *) ldap_alloc_ber_with_options( LDAP *ld );
442 LIBLDAP_F (void) ldap_set_ber_options( LDAP *ld, BerElement *ber );
444 LIBLDAP_F (int) ldap_send_server_request( LDAP *ld, BerElement *ber, ber_int_t msgid, LDAPRequest *parentreq, LDAPURLDesc *srvlist, LDAPConn *lc, LDAPreqinfo *bind );
445 LIBLDAP_F (LDAPConn *) ldap_new_connection( LDAP *ld, LDAPURLDesc *srvlist, int use_ldsb, int connect, LDAPreqinfo *bind );
446 LIBLDAP_F (LDAPRequest *) ldap_find_request_by_msgid( LDAP *ld, ber_int_t msgid );
447 LIBLDAP_F (void) ldap_free_request( LDAP *ld, LDAPRequest *lr );
448 LIBLDAP_F (void) ldap_free_connection( LDAP *ld, LDAPConn *lc, int force, int unbind );
449 LIBLDAP_F (void) ldap_dump_connection( LDAP *ld, LDAPConn *lconns, int all );
450 LIBLDAP_F (void) ldap_dump_requests_and_responses( LDAP *ld );
451 LIBLDAP_F (int) ldap_chase_referrals( LDAP *ld, LDAPRequest *lr, char **errstrp, int *hadrefp );
452 LIBLDAP_F (int) ldap_chase_v3referrals( LDAP *ld, LDAPRequest *lr, char **refs, char **referralsp, int *hadrefp );
453 LIBLDAP_F (int) ldap_append_referral( LDAP *ld, char **referralsp, char *s );
458 #ifdef LDAP_CONNECTIONLESS
459 LIBLDAP_F (int) cldap_getmsg( LDAP *ld, struct timeval *timeout, BerElement *ber );
465 LIBLDAP_F (BerElement *) ldap_build_search_req LDAP_P((
472 LDAPControl **sctrls,
473 LDAPControl **cctrls,
475 ber_int_t sizelimit ));
480 /* see <ac/string.h> */
485 LIBLDAP_F (int) ldap_ld_free LDAP_P((
488 LDAPControl **sctrls,
489 LDAPControl **cctrls ));
491 LIBLDAP_F (int) ldap_send_unbind LDAP_P((
494 LDAPControl **sctrls,
495 LDAPControl **cctrls ));
500 LIBLDAP_F (LDAPURLDesc *) ldap_url_dup LDAP_P((
501 LDAPURLDesc *ludp ));
503 LIBLDAP_F (LDAPURLDesc *) ldap_url_duplist LDAP_P((
504 LDAPURLDesc *ludlist ));
506 LIBLDAP_F (int) ldap_url_parselist LDAP_P((
507 LDAPURLDesc **ludlist,
510 LIBLDAP_F (int) ldap_url_parsehosts LDAP_P((
511 LDAPURLDesc **ludlist,
512 const char *hosts ));
514 LIBLDAP_F (char *) ldap_url_list2hosts LDAP_P((
515 LDAPURLDesc *ludlist ));
517 LIBLDAP_F (char *) ldap_url_list2urls LDAP_P((
518 LDAPURLDesc *ludlist ));
520 LIBLDAP_F (void) ldap_free_urllist LDAP_P((
521 LDAPURLDesc *ludlist ));
526 #endif /* _LDAP_INT_H */