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"
21 #ifdef HAVE_CYRUS_SASL
22 /* the need for this should be removed */
27 * Support needed if the library is running in the kernel
29 #if LDAP_INT_IN_KERNEL
31 * Platform specific function to return a pointer to the
32 * process-specific global options.
34 * This function should perform the following functions:
35 * Allocate and initialize a global options struct on a per process basis
36 * Use callers process identifier to return its global options struct
37 * Note: Deallocate structure when the process exits
39 # define LDAP_INT_GLOBAL_OPT() ldap_int_global_opt()
40 struct ldapoptions *ldap_int_global_opt(void);
42 # define LDAP_INT_GLOBAL_OPT() (&ldap_int_global_options)
45 #define ldap_debug ((LDAP_INT_GLOBAL_OPT())->ldo_debug)
50 #define Debug( level, fmt, arg1, arg2, arg3 ) \
51 ldap_log_printf( NULL, (level), (fmt), (arg1), (arg2), (arg3) )
59 #define LDAP_URL_PREFIX "ldap://"
60 #define LDAP_URL_PREFIX_LEN (sizeof(LDAP_URL_PREFIX)-1)
61 #define LDAPS_URL_PREFIX "ldaps://"
62 #define LDAPS_URL_PREFIX_LEN (sizeof(LDAPS_URL_PREFIX)-1)
63 #define LDAPI_URL_PREFIX "ldapi://"
64 #define LDAPI_URL_PREFIX_LEN (sizeof(LDAPI_URL_PREFIX)-1)
65 #define LDAP_URL_URLCOLON "URL:"
66 #define LDAP_URL_URLCOLON_LEN (sizeof(LDAP_URL_URLCOLON)-1)
68 #define CLDAP_URL_PREFIX "cldap://"
69 #define CLDAP_URL_PREFIX_LEN (sizeof(CLDAP_URL_PREFIX)-1)
71 #define LDAP_REF_STR "Referral:\n"
72 #define LDAP_REF_STR_LEN (sizeof(LDAP_REF_STR)-1)
73 #define LDAP_LDAP_REF_STR LDAP_URL_PREFIX
74 #define LDAP_LDAP_REF_STR_LEN LDAP_URL_PREFIX_LEN
76 #define LDAP_DEFAULT_REFHOPLIMIT 5
78 #define LDAP_BOOL_REFERRALS 0
79 #define LDAP_BOOL_RESTART 1
80 #define LDAP_BOOL_TLS 3
82 #define LDAP_BOOLEANS unsigned long
83 #define LDAP_BOOL(n) (1 << (n))
84 #define LDAP_BOOL_GET(lo, bool) \
85 ((lo)->ldo_booleans & LDAP_BOOL(bool) ? -1 : 0)
86 #define LDAP_BOOL_SET(lo, bool) ((lo)->ldo_booleans |= LDAP_BOOL(bool))
87 #define LDAP_BOOL_CLR(lo, bool) ((lo)->ldo_booleans &= ~LDAP_BOOL(bool))
88 #define LDAP_BOOL_ZERO(lo) ((lo)->ldo_booleans = 0)
91 * This structure represents both ldap messages and ldap responses.
92 * These are really the same, except in the case of search responses,
93 * where a response has multiple messages.
97 ber_int_t lm_msgid; /* the message id */
98 ber_tag_t lm_msgtype; /* the message type */
99 BerElement *lm_ber; /* the ber encoded message contents */
100 struct ldapmsg *lm_chain; /* for search - next msg in the resp */
101 struct ldapmsg *lm_next; /* next response */
102 time_t lm_time; /* used to maintain cache */
106 * structure representing get/set'able options
107 * which have global defaults.
111 #define LDAP_UNINITIALIZED 0x0
112 #define LDAP_INITIALIZED 0x1
113 #define LDAP_VALID_SESSION 0x2
116 /* per API call timeout */
117 struct timeval *ldo_tm_api;
118 struct timeval *ldo_tm_net;
120 ber_int_t ldo_version;
122 ber_int_t ldo_timelimit;
123 ber_int_t ldo_sizelimit;
125 LDAPURLDesc *ldo_defludp;
128 char* ldo_defbinddn; /* simple bind dn */
130 #ifdef LDAP_CONNECTIONLESS
131 int ldo_cldaptries; /* connectionless search retry count */
132 int ldo_cldaptimeout;/* time between retries */
135 int ldo_refhoplimit; /* limit on referral nesting */
137 /* LDAPv3 server and client controls */
138 LDAPControl **ldo_sctrls;
139 LDAPControl **ldo_cctrls;
141 /* LDAP rebind callback function */
142 LDAP_REBIND_PROC *ldo_rebindproc;
149 #ifdef HAVE_CYRUS_SASL
150 struct sasl_security_properties ldo_sasl_secprops;
152 LDAP_BOOLEANS ldo_booleans; /* boolean options */
157 * structure for tracking LDAP server host, ports, DNs, etc.
159 typedef struct ldap_server {
161 char *lsrv_dn; /* if NULL, use default */
163 struct ldap_server *lsrv_next;
168 * structure for representing an LDAP server connection
170 typedef struct ldap_conn {
172 void *lconn_sasl_ctx;
174 time_t lconn_lastused; /* time */
175 int lconn_rebind_inprogress; /* set if rebind in progress */
176 char ***lconn_rebind_queue; /* used if rebind in progress */
178 #define LDAP_CONNST_NEEDSOCKET 1
179 #define LDAP_CONNST_CONNECTING 2
180 #define LDAP_CONNST_CONNECTED 3
181 LDAPURLDesc *lconn_server;
182 char *lconn_krbinstance;
183 struct ldap_conn *lconn_next;
184 BerElement *lconn_ber;/* ber receiving on this conn. */
189 * structure used to track outstanding requests
191 typedef struct ldapreq {
192 ber_int_t lr_msgid; /* the message id */
193 int lr_status; /* status of request */
194 #define LDAP_REQST_COMPLETED 0
195 #define LDAP_REQST_INPROGRESS 1
196 #define LDAP_REQST_CHASINGREFS 2
197 #define LDAP_REQST_NOTCONNECTED 3
198 #define LDAP_REQST_WRITING 4
199 int lr_outrefcnt; /* count of outstanding referrals */
200 ber_int_t lr_origid; /* original request's message id */
201 int lr_parentcnt; /* count of parent requests */
202 ber_tag_t lr_res_msgtype; /* result message type */
203 ber_int_t lr_res_errno; /* result LDAP errno */
204 char *lr_res_error; /* result error string */
205 char *lr_res_matched;/* result matched DN string */
206 BerElement *lr_ber; /* ber encoded request contents */
207 LDAPConn *lr_conn; /* connection used to send request */
208 struct ldapreq *lr_parent; /* request that spawned this referral */
209 struct ldapreq *lr_refnext; /* next referral spawned */
210 struct ldapreq *lr_prev; /* previous request */
211 struct ldapreq *lr_next; /* next request */
215 * structure for client cache
217 #define LDAP_CACHE_BUCKETS 31 /* cache hash table size */
218 typedef struct ldapcache {
219 LDAPMessage *lc_buckets[LDAP_CACHE_BUCKETS];/* hash table */
220 LDAPMessage *lc_requests; /* unfulfilled reqs */
221 long lc_timeout; /* request timeout */
222 ber_len_t lc_maxmem; /* memory to use */
223 ber_len_t lc_memused; /* memory in use */
224 int lc_enabled; /* enabled? */
225 unsigned long lc_options; /* options */
226 #define LDAP_CACHE_OPT_CACHENOERRS 0x00000001
227 #define LDAP_CACHE_OPT_CACHEALLERRS 0x00000002
231 * structure containing referral request info for rebind procedure
233 typedef struct ldapreqinfo {
240 * handy macro for checking if handle is connectionless
243 #define LDAP_IS_CLDAP(ld) ((ld)->ld_cldapnaddr>0)
246 * structure representing an ldap connection
250 Sockbuf *ld_sb; /* socket descriptor & buffer */
252 struct ldapoptions ld_options;
254 #define ld_valid ld_options.ldo_valid
255 #define ld_debug ld_options.ldo_debug
257 #define ld_deref ld_options.ldo_deref
258 #define ld_timelimit ld_options.ldo_timelimit
259 #define ld_sizelimit ld_options.ldo_sizelimit
261 #define ld_defbinddn ld_options.ldo_defbinddn
262 #define ld_defbase ld_options.ldo_defbase
263 #define ld_defhost ld_options.ldo_defhost
264 #define ld_defport ld_options.ldo_defport
266 #define ld_cldaptries ld_options.ldo_cldaptries
267 #define ld_cldaptimeout ld_options.ldo_cldaptimeout
268 #define ld_refhoplimit ld_options.ldo_refhoplimit
270 #define ld_sctrls ld_options.ldo_sctrls
271 #define ld_cctrls ld_options.ldo_cctrls
272 #define ld_rebindproc ld_options.ldo_rebindproc
274 #define ld_version ld_options.ldo_version
279 unsigned short ld_lberoptions;
281 LDAPFiltDesc *ld_filtd; /* from getfilter for ufn searches */
282 char *ld_ufnprefix; /* for incomplete ufn's */
289 /* do not mess with these */
290 LDAPRequest *ld_requests; /* list of outstanding requests */
291 LDAPMessage *ld_responses; /* list of outstanding responses */
293 ber_int_t *ld_abandoned; /* array of abandoned requests */
295 LDAPCache *ld_cache; /* non-null if cache is initialized */
296 /* stuff used by connectionless searches. */
298 char *ld_cldapdn; /* DN used in connectionless search */
299 int ld_cldapnaddr; /* number of addresses */
300 void **ld_cldapaddrs;/* addresses to send request to */
302 /* do not mess with the rest though */
304 LDAPConn *ld_defconn; /* default connection */
305 LDAPConn *ld_conns; /* list of server connections */
306 void *ld_selectinfo; /* platform specifics for select */
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 LDAP_V ( ldap_pvt_thread_mutex_t ) ldap_int_resolv_mutex;
313 #endif /* HAVE_RES_QUERY && LDAP_R_COMPILE */
319 LDAP_V ( struct ldapoptions ) ldap_int_global_options;
321 LDAP_F ( void ) ldap_int_initialize LDAP_P((struct ldapoptions *, int *));
322 LDAP_F ( void ) ldap_int_initialize_global_options LDAP_P((
323 struct ldapoptions *, int *));
326 /* simple macros to realloc for now */
327 #define LDAP_INT_MALLOC(s) (LBER_MALLOC((s)))
328 #define LDAP_INT_CALLOC(n,s) (LBER_CALLOC((n),(s)))
329 #define LDAP_INT_REALLOC(p,s) (LBER_REALLOC((p),(s)))
330 #define LDAP_INT_FREE(p) (LBER_FREE((p)))
331 #define LDAP_INT_VFREE(v) (LBER_VFREE((void **)(v)))
332 #define LDAP_INT_STRDUP(s) (LBER_STRDUP((s)))
334 #define LDAP_MALLOC(s) (LBER_MALLOC((s)))
335 #define LDAP_CALLOC(n,s) (LBER_CALLOC((n),(s)))
336 #define LDAP_REALLOC(p,s) (LBER_REALLOC((p),(s)))
337 #define LDAP_FREE(p) (LBER_FREE((p)))
338 #define LDAP_VFREE(v) (LBER_VFREE((void **)(v)))
339 #define LDAP_STRDUP(s) (LBER_STRDUP((s)))
344 LDAP_F (void) ldap_int_utils_init LDAP_P(( void ));
350 LDAP_F (int) ldap_log_printf LDAP_P((LDAP *ld, int level, const char *fmt, ...)) LDAP_GCCATTR((format(printf, 3, 4)));
355 LDAP_F (void) ldap_add_request_to_cache LDAP_P(( LDAP *ld, ber_tag_t msgtype,
356 BerElement *request ));
357 LDAP_F (void) ldap_add_result_to_cache LDAP_P(( LDAP *ld, LDAPMessage *result ));
358 LDAP_F (int) ldap_check_cache LDAP_P(( LDAP *ld, ber_tag_t msgtype, BerElement *request ));
363 LDAP_F (LDAPControl *) ldap_control_dup LDAP_P((
364 const LDAPControl *ctrl ));
366 LDAP_F (LDAPControl **) ldap_controls_dup LDAP_P((
367 LDAPControl *const *ctrls ));
369 LDAP_F (int) ldap_int_get_controls LDAP_P((
371 LDAPControl ***ctrlsp));
373 LDAP_F (int) ldap_int_put_controls LDAP_P((
375 LDAPControl *const *ctrls,
379 ldap_int_create_control LDAP_P((
380 const char *requestOID,
383 LDAPControl **ctrlp ));
388 LDAP_F (int) ldap_int_next_line_tokens LDAP_P(( char **bufp, ber_len_t *blenp, char ***toksp ));
390 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
394 LDAP_F (char *) ldap_get_kerberosv4_credentials LDAP_P((
396 LDAP_CONST char *who,
397 LDAP_CONST char *service,
400 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND */
406 LDAP_F (int) ldap_open_defconn( LDAP *ld );
407 LDAP_F (int) ldap_int_open_connection( LDAP *ld,
408 LDAPConn *conn, LDAPURLDesc *srvlist, int async );
413 LDAP_F (int) ldap_int_tblsize;
414 LDAP_F (int) ldap_int_timeval_dup( struct timeval **dest, const struct timeval *tm );
415 LDAP_F (int) ldap_connect_to_host( LDAP *ld, Sockbuf *sb,
416 int proto, const char *host, unsigned long address, int port,
419 #if defined(LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND) || defined(HAVE_TLS) || defined(HAVE_CYRUS_SASL)
420 LDAP_V (char *) ldap_int_hostname;
421 LDAP_F (char *) ldap_host_connected_to( Sockbuf *sb );
422 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND */
424 LDAP_F (void) ldap_int_ip_init( void );
425 LDAP_F (int) do_ldap_select( LDAP *ld, struct timeval *timeout );
426 LDAP_F (void *) ldap_new_select_info( void );
427 LDAP_F (void) ldap_free_select_info( void *sip );
428 LDAP_F (void) ldap_mark_select_write( LDAP *ld, Sockbuf *sb );
429 LDAP_F (void) ldap_mark_select_read( LDAP *ld, Sockbuf *sb );
430 LDAP_F (void) ldap_mark_select_clear( LDAP *ld, Sockbuf *sb );
431 LDAP_F (int) ldap_is_read_ready( LDAP *ld, Sockbuf *sb );
432 LDAP_F (int) ldap_is_write_ready( LDAP *ld, Sockbuf *sb );
438 LDAP_F (int) ldap_connect_to_path( LDAP *ld, Sockbuf *sb, int proto,
439 const char *path, int async );
440 #endif /* LDAP_PF_UNIX */
445 LDAP_F (ber_int_t) ldap_send_initial_request( LDAP *ld, ber_tag_t msgtype,
446 const char *dn, BerElement *ber );
447 LDAP_F (BerElement *) ldap_alloc_ber_with_options( LDAP *ld );
448 LDAP_F (void) ldap_set_ber_options( LDAP *ld, BerElement *ber );
450 LDAP_F (int) ldap_send_server_request( LDAP *ld, BerElement *ber, ber_int_t msgid, LDAPRequest *parentreq, LDAPURLDesc *srvlist, LDAPConn *lc, LDAPreqinfo *bind );
451 LDAP_F (LDAPConn *) ldap_new_connection( LDAP *ld, LDAPURLDesc *srvlist, int use_ldsb, int connect, LDAPreqinfo *bind );
452 LDAP_F (LDAPRequest *) ldap_find_request_by_msgid( LDAP *ld, ber_int_t msgid );
453 LDAP_F (void) ldap_free_request( LDAP *ld, LDAPRequest *lr );
454 LDAP_F (void) ldap_free_connection( LDAP *ld, LDAPConn *lc, int force, int unbind );
455 LDAP_F (void) ldap_dump_connection( LDAP *ld, LDAPConn *lconns, int all );
456 LDAP_F (void) ldap_dump_requests_and_responses( LDAP *ld );
457 LDAP_F (int) ldap_chase_referrals( LDAP *ld, LDAPRequest *lr, char **errstrp, int *hadrefp );
458 LDAP_F (int) ldap_chase_v3referrals( LDAP *ld, LDAPRequest *lr, char **refs, char **referralsp, int *hadrefp );
459 LDAP_F (int) ldap_append_referral( LDAP *ld, char **referralsp, char *s );
464 #ifdef LDAP_CONNECTIONLESS
465 LDAP_F (int) cldap_getmsg( LDAP *ld, struct timeval *timeout, BerElement *ber );
467 LDAP_F (char *) ldap_int_msgtype2str( ber_tag_t tag );
472 LDAP_F (BerElement *) ldap_build_search_req LDAP_P((
479 LDAPControl **sctrls,
480 LDAPControl **cctrls,
482 ber_int_t sizelimit ));
487 /* see <ac/string.h> */
492 LDAP_F (int) ldap_ld_free LDAP_P((
495 LDAPControl **sctrls,
496 LDAPControl **cctrls ));
498 LDAP_F (int) ldap_send_unbind LDAP_P((
501 LDAPControl **sctrls,
502 LDAPControl **cctrls ));
507 LDAP_F (LDAPURLDesc *) ldap_url_dup LDAP_P((
508 LDAPURLDesc *ludp ));
510 LDAP_F (LDAPURLDesc *) ldap_url_duplist LDAP_P((
511 LDAPURLDesc *ludlist ));
513 LDAP_F (int) ldap_url_parselist LDAP_P((
514 LDAPURLDesc **ludlist,
517 LDAP_F (int) ldap_url_parsehosts LDAP_P((
518 LDAPURLDesc **ludlist,
519 const char *hosts ));
521 LDAP_F (char *) ldap_url_list2hosts LDAP_P((
522 LDAPURLDesc *ludlist ));
524 LDAP_F (char *) ldap_url_list2urls LDAP_P((
525 LDAPURLDesc *ludlist ));
527 LDAP_F (void) ldap_free_urllist LDAP_P((
528 LDAPURLDesc *ludlist ));
533 LDAP_F (int) ldap_int_sasl_init LDAP_P(( void ));
535 LDAP_F (int) ldap_int_sasl_open LDAP_P((
536 LDAP *ld, LDAPConn *conn,
537 const char* host, ber_len_t ssf ));
538 LDAP_F (int) ldap_int_sasl_close LDAP_P(( LDAP *ld, LDAPConn *conn ));
540 LDAP_F (int) ldap_int_sasl_get_option LDAP_P(( LDAP *ld,
541 int option, void *arg ));
542 LDAP_F (int) ldap_int_sasl_set_option LDAP_P(( LDAP *ld,
543 int option, void *arg ));
544 LDAP_F (int) ldap_int_sasl_config LDAP_P(( struct ldapoptions *lo,
545 int option, const char *arg ));
547 LDAP_F (int) ldap_int_sasl_bind LDAP_P((
548 struct ldap *, LDAP_CONST char *,
549 const char *, LDAPControl **, LDAPControl **,
550 LDAP_SASL_INTERACT_PROC *interact ));
555 LDAP_F (int) ldap_int_tls_config LDAP_P(( struct ldapoptions *lo, int option, const char *arg ));
559 #endif /* _LDAP_INT_H */