1 /* ldap-int.h - defines & prototypes internal to the LDAP library */
4 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
8 * Copyright (c) 1995 Regents of the University of Michigan.
16 #define LDAP_THREAD_SAFE 1
19 #include "../liblber/lber-int.h"
22 * Support needed if the library is running in the kernel
24 #if LDAP_INT_IN_KERNEL
26 * Platform specific function to return a pointer to the
27 * process-specific global options.
29 * This function should perform the following functions:
30 * Allocate and initialize a global options struct on a per process basis
31 * Use callers process identifier to return its global options struct
32 * Note: Deallocate structure when the process exits
34 # define LDAP_INT_GLOBAL_OPT() ldap_int_global_opt()
35 struct ldapoptions *ldap_int_global_opt(void);
37 # define LDAP_INT_GLOBAL_OPT() (&ldap_int_global_options)
40 #define ldap_debug ((LDAP_INT_GLOBAL_OPT())->ldo_debug)
45 #define Debug( level, fmt, arg1, arg2, arg3 ) \
46 ldap_log_printf( NULL, (level), (fmt), (arg1), (arg2), (arg3) )
54 #define LDAP_URL_PREFIX "ldap://"
55 #define LDAP_URL_PREFIX_LEN (sizeof(LDAP_URL_PREFIX)-1)
56 #define LDAPS_URL_PREFIX "ldaps://"
57 #define LDAPS_URL_PREFIX_LEN (sizeof(LDAPS_URL_PREFIX)-1)
58 #define LDAPI_URL_PREFIX "ldapi://"
59 #define LDAPI_URL_PREFIX_LEN (sizeof(LDAPI_URL_PREFIX)-1)
60 #define LDAP_URL_URLCOLON "URL:"
61 #define LDAP_URL_URLCOLON_LEN (sizeof(LDAP_URL_URLCOLON)-1)
63 #define CLDAP_URL_PREFIX "cldap://"
64 #define CLDAP_URL_PREFIX_LEN (sizeof(CLDAP_URL_PREFIX)-1)
66 #define LDAP_REF_STR "Referral:\n"
67 #define LDAP_REF_STR_LEN (sizeof(LDAP_REF_STR)-1)
68 #define LDAP_LDAP_REF_STR LDAP_URL_PREFIX
69 #define LDAP_LDAP_REF_STR_LEN LDAP_URL_PREFIX_LEN
71 #define LDAP_DEFAULT_REFHOPLIMIT 5
73 #define LDAP_BOOL_REFERRALS 0
74 #define LDAP_BOOL_RESTART 1
75 #define LDAP_BOOL_TLS 3
77 #define LDAP_BOOLEANS unsigned long
78 #define LDAP_BOOL(n) (1 << (n))
79 #define LDAP_BOOL_GET(lo, bool) \
80 ((lo)->ldo_booleans & LDAP_BOOL(bool) ? -1 : 0)
81 #define LDAP_BOOL_SET(lo, bool) ((lo)->ldo_booleans |= LDAP_BOOL(bool))
82 #define LDAP_BOOL_CLR(lo, bool) ((lo)->ldo_booleans &= ~LDAP_BOOL(bool))
83 #define LDAP_BOOL_ZERO(lo) ((lo)->ldo_booleans = 0)
86 * This structure represents both ldap messages and ldap responses.
87 * These are really the same, except in the case of search responses,
88 * where a response has multiple messages.
92 ber_int_t lm_msgid; /* the message id */
93 ber_tag_t lm_msgtype; /* the message type */
94 BerElement *lm_ber; /* the ber encoded message contents */
95 struct ldapmsg *lm_chain; /* for search - next msg in the resp */
96 struct ldapmsg *lm_next; /* next response */
97 time_t lm_time; /* used to maintain cache */
101 * structure representing get/set'able options
102 * which have global defaults.
106 #define LDAP_UNINITIALIZED 0x0
107 #define LDAP_INITIALIZED 0x1
108 #define LDAP_VALID_SESSION 0x2
111 /* per API call timeout */
112 struct timeval *ldo_tm_api;
113 struct timeval *ldo_tm_net;
115 ber_int_t ldo_version;
117 ber_int_t ldo_timelimit;
118 ber_int_t ldo_sizelimit;
120 LDAPURLDesc *ldo_defludp;
123 char* ldo_defbinddn; /* simple bind dn */
125 #ifdef LDAP_CONNECTIONLESS
126 int ldo_cldaptries; /* connectionless search retry count */
127 int ldo_cldaptimeout;/* time between retries */
130 int ldo_refhoplimit; /* limit on referral nesting */
132 /* LDAPv3 server and client controls */
133 LDAPControl **ldo_sctrls;
134 LDAPControl **ldo_cctrls;
136 /* LDAP rebind callback function */
137 LDAP_REBIND_PROC *ldo_rebindproc;
144 #ifdef HAVE_CYRUS_SASL
145 sasl_ssf_t ldo_sasl_minssf;
146 sasl_ssf_t ldo_sasl_maxssf;
148 LDAP_BOOLEANS ldo_booleans; /* boolean options */
153 * structure for tracking LDAP server host, ports, DNs, etc.
155 typedef struct ldap_server {
157 char *lsrv_dn; /* if NULL, use default */
159 struct ldap_server *lsrv_next;
164 * structure for representing an LDAP server connection
166 typedef struct ldap_conn {
169 time_t lconn_lastused; /* time */
170 int lconn_rebind_inprogress; /* set if rebind in progress */
171 char ***lconn_rebind_queue; /* used if rebind in progress */
173 #define LDAP_CONNST_NEEDSOCKET 1
174 #define LDAP_CONNST_CONNECTING 2
175 #define LDAP_CONNST_CONNECTED 3
176 LDAPURLDesc *lconn_server;
177 char *lconn_krbinstance;
178 struct ldap_conn *lconn_next;
179 BerElement *lconn_ber;/* ber receiving on this conn. */
184 * structure used to track outstanding requests
186 typedef struct ldapreq {
187 ber_int_t lr_msgid; /* the message id */
188 int lr_status; /* status of request */
189 #define LDAP_REQST_COMPLETED 0
190 #define LDAP_REQST_INPROGRESS 1
191 #define LDAP_REQST_CHASINGREFS 2
192 #define LDAP_REQST_NOTCONNECTED 3
193 #define LDAP_REQST_WRITING 4
194 int lr_outrefcnt; /* count of outstanding referrals */
195 ber_int_t lr_origid; /* original request's message id */
196 int lr_parentcnt; /* count of parent requests */
197 ber_tag_t lr_res_msgtype; /* result message type */
198 ber_int_t lr_res_errno; /* result LDAP errno */
199 char *lr_res_error; /* result error string */
200 char *lr_res_matched;/* result matched DN string */
201 BerElement *lr_ber; /* ber encoded request contents */
202 LDAPConn *lr_conn; /* connection used to send request */
203 struct ldapreq *lr_parent; /* request that spawned this referral */
204 struct ldapreq *lr_refnext; /* next referral spawned */
205 struct ldapreq *lr_prev; /* previous request */
206 struct ldapreq *lr_next; /* next request */
210 * structure for client cache
212 #define LDAP_CACHE_BUCKETS 31 /* cache hash table size */
213 typedef struct ldapcache {
214 LDAPMessage *lc_buckets[LDAP_CACHE_BUCKETS];/* hash table */
215 LDAPMessage *lc_requests; /* unfulfilled reqs */
216 long lc_timeout; /* request timeout */
217 ber_len_t lc_maxmem; /* memory to use */
218 ber_len_t lc_memused; /* memory in use */
219 int lc_enabled; /* enabled? */
220 unsigned long lc_options; /* options */
221 #define LDAP_CACHE_OPT_CACHENOERRS 0x00000001
222 #define LDAP_CACHE_OPT_CACHEALLERRS 0x00000002
226 * structure containing referral request info for rebind procedure
228 typedef struct ldapreqinfo {
235 * handy macro for checking if handle is connectionless
238 #define LDAP_IS_CLDAP(ld) ((ld)->ld_cldapnaddr>0)
241 * structure representing an ldap connection
245 Sockbuf *ld_sb; /* socket descriptor & buffer */
247 struct ldapoptions ld_options;
249 #define ld_valid ld_options.ldo_valid
250 #define ld_debug ld_options.ldo_debug
252 #define ld_deref ld_options.ldo_deref
253 #define ld_timelimit ld_options.ldo_timelimit
254 #define ld_sizelimit ld_options.ldo_sizelimit
256 #define ld_defbinddn ld_options.ldo_defbinddn
257 #define ld_defbase ld_options.ldo_defbase
258 #define ld_defhost ld_options.ldo_defhost
259 #define ld_defport ld_options.ldo_defport
261 #define ld_cldaptries ld_options.ldo_cldaptries
262 #define ld_cldaptimeout ld_options.ldo_cldaptimeout
263 #define ld_refhoplimit ld_options.ldo_refhoplimit
265 #define ld_sctrls ld_options.ldo_sctrls
266 #define ld_cctrls ld_options.ldo_cctrls
267 #define ld_rebindproc ld_options.ldo_rebindproc
269 #define ld_version ld_options.ldo_version
273 unsigned short ld_lberoptions;
275 LDAPFiltDesc *ld_filtd; /* from getfilter for ufn searches */
276 char *ld_ufnprefix; /* for incomplete ufn's */
283 /* do not mess with these */
284 LDAPRequest *ld_requests; /* list of outstanding requests */
285 LDAPMessage *ld_responses; /* list of outstanding responses */
287 ber_int_t *ld_abandoned; /* array of abandoned requests */
289 LDAPCache *ld_cache; /* non-null if cache is initialized */
290 /* stuff used by connectionless searches. */
292 char *ld_cldapdn; /* DN used in connectionless search */
293 int ld_cldapnaddr; /* number of addresses */
294 void **ld_cldapaddrs;/* addresses to send request to */
296 /* do not mess with the rest though */
298 LDAPConn *ld_defconn; /* default connection */
299 LDAPConn *ld_conns; /* list of server connections */
300 void *ld_selectinfo; /* platform specifics for select */
301 #ifdef HAVE_CYRUS_SASL
302 sasl_conn_t *ld_sasl_context;
303 #endif /* HAVE_CYRUS_SASL */
305 #define LDAP_VALID(ld) ( (ld)->ld_valid == LDAP_VALID_SESSION )
307 #if defined(HAVE_RES_QUERY) && defined(LDAP_R_COMPILE)
308 #include <ldap_pvt_thread.h>
309 extern ldap_pvt_thread_mutex_t ldap_int_resolv_mutex;
310 #endif /* HAVE_RES_QUERY && LDAP_R_COMPILE */
316 LDAP_F ( struct ldapoptions ) ldap_int_global_options;
317 LDAP_F ( void ) ldap_int_initialize LDAP_P((struct ldapoptions *, int *));
318 LDAP_F ( void ) ldap_int_initialize_global_options LDAP_P((
319 struct ldapoptions *, int *));
322 /* simple macros to realloc for now */
323 #define LDAP_INT_MALLOC(s) (LBER_MALLOC((s)))
324 #define LDAP_INT_CALLOC(n,s) (LBER_CALLOC((n),(s)))
325 #define LDAP_INT_REALLOC(p,s) (LBER_REALLOC((p),(s)))
326 #define LDAP_INT_FREE(p) (LBER_FREE((p)))
327 #define LDAP_INT_VFREE(v) (LBER_VFREE((void **)(v)))
328 #define LDAP_INT_STRDUP(s) (LBER_STRDUP((s)))
330 #define LDAP_MALLOC(s) (LBER_MALLOC((s)))
331 #define LDAP_CALLOC(n,s) (LBER_CALLOC((n),(s)))
332 #define LDAP_REALLOC(p,s) (LBER_REALLOC((p),(s)))
333 #define LDAP_FREE(p) (LBER_FREE((p)))
334 #define LDAP_VFREE(v) (LBER_VFREE((void **)(v)))
335 #define LDAP_STRDUP(s) (LBER_STRDUP((s)))
340 LDAP_F (void) ldap_int_utils_init LDAP_P(( void ));
346 LDAP_F (int) ldap_log_printf LDAP_P((LDAP *ld, int level, const char *fmt, ...)) LDAP_GCCATTR((format(printf, 3, 4)));
351 LDAP_F (void) ldap_add_request_to_cache LDAP_P(( LDAP *ld, ber_tag_t msgtype,
352 BerElement *request ));
353 LDAP_F (void) ldap_add_result_to_cache LDAP_P(( LDAP *ld, LDAPMessage *result ));
354 LDAP_F (int) ldap_check_cache LDAP_P(( LDAP *ld, ber_tag_t msgtype, BerElement *request ));
359 LDAP_F (LDAPControl *) ldap_control_dup LDAP_P((
360 const LDAPControl *ctrl ));
362 LDAP_F (LDAPControl **) ldap_controls_dup LDAP_P((
363 LDAPControl *const *ctrls ));
365 LDAP_F (int) ldap_int_get_controls LDAP_P((
367 LDAPControl ***ctrlsp));
369 LDAP_F (int) ldap_int_put_controls LDAP_P((
371 LDAPControl *const *ctrls,
375 ldap_int_create_control LDAP_P((
376 const char *requestOID,
379 LDAPControl **ctrlp ));
384 LDAP_F (int) ldap_int_next_line_tokens LDAP_P(( char **bufp, ber_len_t *blenp, char ***toksp ));
386 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
390 LDAP_F (char *) ldap_get_kerberosv4_credentials LDAP_P((
392 LDAP_CONST char *who,
393 LDAP_CONST char *service,
396 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND */
402 LDAP_F (int) ldap_open_defconn( LDAP *ld );
403 LDAP_F (int) open_ldap_connection( LDAP *ld, Sockbuf *sb, LDAPURLDesc *srvlist, char **krbinstancep, int async );
408 LDAP_F (int) ldap_int_tblsize;
409 LDAP_F (int) ldap_int_timeval_dup( struct timeval **dest, const struct timeval *tm );
410 LDAP_F (int) ldap_connect_to_host( LDAP *ld, Sockbuf *sb, const char *host, unsigned long address, int port, int async );
412 #if defined(LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND) || defined(HAVE_TLS) || defined(HAVE_CYRUS_SASL)
413 LDAP_F (char *) ldap_host_connected_to( Sockbuf *sb );
414 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND */
416 LDAP_F (void) ldap_int_ip_init( void );
417 LDAP_F (int) do_ldap_select( LDAP *ld, struct timeval *timeout );
418 LDAP_F (void *) ldap_new_select_info( void );
419 LDAP_F (void) ldap_free_select_info( void *sip );
420 LDAP_F (void) ldap_mark_select_write( LDAP *ld, Sockbuf *sb );
421 LDAP_F (void) ldap_mark_select_read( LDAP *ld, Sockbuf *sb );
422 LDAP_F (void) ldap_mark_select_clear( LDAP *ld, Sockbuf *sb );
423 LDAP_F (int) ldap_is_read_ready( LDAP *ld, Sockbuf *sb );
424 LDAP_F (int) ldap_is_write_ready( LDAP *ld, Sockbuf *sb );
430 LDAP_F (int) ldap_connect_to_path( LDAP *ld, Sockbuf *sb, const char *path, int async );
431 #endif /* LDAP_PF_UNIX */
436 LDAP_F (ber_int_t) ldap_send_initial_request( LDAP *ld, ber_tag_t msgtype,
437 const char *dn, BerElement *ber );
438 LDAP_F (BerElement *) ldap_alloc_ber_with_options( LDAP *ld );
439 LDAP_F (void) ldap_set_ber_options( LDAP *ld, BerElement *ber );
441 LDAP_F (int) ldap_send_server_request( LDAP *ld, BerElement *ber, ber_int_t msgid, LDAPRequest *parentreq, LDAPURLDesc *srvlist, LDAPConn *lc, LDAPreqinfo *bind );
442 LDAP_F (LDAPConn *) ldap_new_connection( LDAP *ld, LDAPURLDesc *srvlist, int use_ldsb, int connect, LDAPreqinfo *bind );
443 LDAP_F (LDAPRequest *) ldap_find_request_by_msgid( LDAP *ld, ber_int_t msgid );
444 LDAP_F (void) ldap_free_request( LDAP *ld, LDAPRequest *lr );
445 LDAP_F (void) ldap_free_connection( LDAP *ld, LDAPConn *lc, int force, int unbind );
446 LDAP_F (void) ldap_dump_connection( LDAP *ld, LDAPConn *lconns, int all );
447 LDAP_F (void) ldap_dump_requests_and_responses( LDAP *ld );
448 LDAP_F (int) ldap_chase_referrals( LDAP *ld, LDAPRequest *lr, char **errstrp, int *hadrefp );
449 LDAP_F (int) ldap_chase_v3referrals( LDAP *ld, LDAPRequest *lr, char **refs, char **referralsp, int *hadrefp );
450 LDAP_F (int) ldap_append_referral( LDAP *ld, char **referralsp, char *s );
455 #ifdef LDAP_CONNECTIONLESS
456 LDAP_F (int) cldap_getmsg( LDAP *ld, struct timeval *timeout, BerElement *ber );
458 LDAP_F (char *) ldap_int_msgtype2str( ber_tag_t tag );
463 LDAP_F (BerElement *) ldap_build_search_req LDAP_P((
470 LDAPControl **sctrls,
471 LDAPControl **cctrls,
473 ber_int_t sizelimit ));
478 /* see <ac/string.h> */
483 LDAP_F (int) ldap_ld_free LDAP_P((
486 LDAPControl **sctrls,
487 LDAPControl **cctrls ));
489 LDAP_F (int) ldap_send_unbind LDAP_P((
492 LDAPControl **sctrls,
493 LDAPControl **cctrls ));
498 LDAP_F (LDAPURLDesc *) ldap_url_dup LDAP_P((
499 LDAPURLDesc *ludp ));
501 LDAP_F (LDAPURLDesc *) ldap_url_duplist LDAP_P((
502 LDAPURLDesc *ludlist ));
504 LDAP_F (int) ldap_url_parselist LDAP_P((
505 LDAPURLDesc **ludlist,
508 LDAP_F (int) ldap_url_parsehosts LDAP_P((
509 LDAPURLDesc **ludlist,
510 const char *hosts ));
512 LDAP_F (char *) ldap_url_list2hosts LDAP_P((
513 LDAPURLDesc *ludlist ));
515 LDAP_F (char *) ldap_url_list2urls LDAP_P((
516 LDAPURLDesc *ludlist ));
518 LDAP_F (void) ldap_free_urllist LDAP_P((
519 LDAPURLDesc *ludlist ));
524 #endif /* _LDAP_INT_H */