3 * Copyright 1998-1999 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) )
33 #ifdef HAVE_CYRUS_SASL
35 #endif /* HAVE_CYRUS_SASL */
39 #define LDAP_URL_PREFIX "ldap://"
40 #define LDAP_URL_PREFIX_LEN (sizeof(LDAP_URL_PREFIX)-1)
41 #define LDAPS_URL_PREFIX "ldaps://"
42 #define LDAPS_URL_PREFIX_LEN (sizeof(LDAPS_URL_PREFIX)-1)
43 #define LDAPI_URL_PREFIX "ldapi://"
44 #define LDAPI_URL_PREFIX_LEN (sizeof(LDAPI_URL_PREFIX)-1)
45 #define LDAPIS_URL_PREFIX "ldapis://"
46 #define LDAPIS_URL_PREFIX_LEN (sizeof(LDAPIS_URL_PREFIX)-1)
47 #define LDAP_URL_URLCOLON "URL:"
48 #define LDAP_URL_URLCOLON_LEN (sizeof(LDAP_URL_URLCOLON)-1)
49 #define NULLLDAPURLDESC ((LDAPURLDesc *)NULL)
51 #define LDAP_REF_STR "Referral:\n"
52 #define LDAP_REF_STR_LEN (sizeof(LDAP_REF_STR)-1)
53 #define LDAP_LDAP_REF_STR LDAP_URL_PREFIX
54 #define LDAP_LDAP_REF_STR_LEN (sizeof(LDAP_LDAP_REF_STR)-1)
56 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
57 #define LDAP_DX_REF_STR "dx://"
58 #define LDAP_DX_REF_STR_LEN (sizeof(LDAP_DX_REF_STR)-1)
59 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
61 #define LDAP_DEFAULT_REFHOPLIMIT 5
63 #define LDAP_BOOL_REFERRALS 0
64 #define LDAP_BOOL_RESTART 1
65 #define LDAP_BOOL_DNS 2
66 #define LDAP_BOOL_TLS 3
68 #define LDAP_BOOLEANS unsigned long
69 #define LDAP_BOOL(n) (1 << (n))
70 #define LDAP_BOOL_GET(lo, bool) ((lo)->ldo_booleans & LDAP_BOOL(bool) \
72 #define LDAP_BOOL_SET(lo, bool) ((lo)->ldo_booleans |= LDAP_BOOL(bool))
73 #define LDAP_BOOL_CLR(lo, bool) ((lo)->ldo_booleans &= ~LDAP_BOOL(bool))
74 #define LDAP_BOOL_ZERO(lo) ((lo)->ldo_booleans = 0)
77 * This structure represents both ldap messages and ldap responses.
78 * These are really the same, except in the case of search responses,
79 * where a response has multiple messages.
83 ber_int_t lm_msgid; /* the message id */
84 ber_tag_t lm_msgtype; /* the message type */
85 BerElement *lm_ber; /* the ber encoded message contents */
86 struct ldapmsg *lm_chain; /* for search - next msg in the resp */
87 struct ldapmsg *lm_next; /* next response */
88 time_t lm_time; /* used to maintain cache */
92 * structure representing get/set'able options
93 * which have global defaults.
97 #define LDAP_UNINITIALIZED 0x0
98 #define LDAP_INITIALIZED 0x1
99 #define LDAP_VALID_SESSION 0x2
102 /* per API call timeout */
103 struct timeval *ldo_tm_api;
104 struct timeval *ldo_tm_net;
106 ber_int_t ldo_version; /* version to connect at */
108 ber_int_t ldo_timelimit;
109 ber_int_t ldo_sizelimit;
111 LDAPURLDesc *ldo_defludp;
114 char* ldo_defbinddn; /* simple bind dn */
116 #ifdef LDAP_CONNECTIONLESS
117 int ldo_cldaptries; /* connectionless search retry count */
118 int ldo_cldaptimeout;/* time between retries */
121 int ldo_refhoplimit; /* limit on referral nesting */
123 /* LDAPv3 server and client controls */
124 LDAPControl **ldo_sctrls;
125 LDAPControl **ldo_cctrls;
132 LDAP_BOOLEANS ldo_booleans; /* boolean options */
137 * structure for tracking LDAP server host, ports, DNs, etc.
139 typedef struct ldap_server {
141 char *lsrv_dn; /* if NULL, use default */
143 /* int lsrv_protocol; */
144 struct ldap_server *lsrv_next;
149 * structure for representing an LDAP server connection
151 typedef struct ldap_conn {
154 time_t lconn_lastused; /* time */
156 #define LDAP_CONNST_NEEDSOCKET 1
157 #define LDAP_CONNST_CONNECTING 2
158 #define LDAP_CONNST_CONNECTED 3
159 LDAPURLDesc *lconn_server;
160 char *lconn_krbinstance;
161 struct ldap_conn *lconn_next;
162 BerElement *lconn_ber;/* ber receiving on this conn. */
167 * structure used to track outstanding requests
169 typedef struct ldapreq {
170 ber_int_t lr_msgid; /* the message id */
171 int lr_status; /* status of request */
172 #define LDAP_REQST_INPROGRESS 1
173 #define LDAP_REQST_CHASINGREFS 2
174 #define LDAP_REQST_NOTCONNECTED 3
175 #define LDAP_REQST_WRITING 4
176 int lr_outrefcnt; /* count of outstanding referrals */
177 ber_int_t lr_origid; /* original request's message id */
178 int lr_parentcnt; /* count of parent requests */
179 ber_tag_t lr_res_msgtype; /* result message type */
180 ber_int_t lr_res_errno; /* result LDAP errno */
181 char *lr_res_error; /* result error string */
182 char *lr_res_matched;/* result matched DN string */
183 BerElement *lr_ber; /* ber encoded request contents */
184 LDAPConn *lr_conn; /* connection used to send request */
185 struct ldapreq *lr_parent; /* request that spawned this referral */
186 struct ldapreq *lr_refnext; /* next referral spawned */
187 struct ldapreq *lr_prev; /* previous request */
188 struct ldapreq *lr_next; /* next request */
192 * structure for client cache
194 #define LDAP_CACHE_BUCKETS 31 /* cache hash table size */
195 typedef struct ldapcache {
196 LDAPMessage *lc_buckets[LDAP_CACHE_BUCKETS];/* hash table */
197 LDAPMessage *lc_requests; /* unfulfilled reqs */
198 long lc_timeout; /* request timeout */
199 ber_len_t lc_maxmem; /* memory to use */
200 ber_len_t lc_memused; /* memory in use */
201 int lc_enabled; /* enabled? */
202 unsigned long lc_options; /* options */
203 #define LDAP_CACHE_OPT_CACHENOERRS 0x00000001
204 #define LDAP_CACHE_OPT_CACHEALLERRS 0x00000002
208 * handy macro for checking if handle is connectionless
211 #define LDAP_IS_CLDAP(ld) ((ld)->ld_cldapnaddr>0)
214 * structure representing an ldap connection
218 Sockbuf ld_sb; /* socket descriptor & buffer */
220 struct ldapoptions ld_options;
222 #define ld_valid ld_options.ldo_valid
223 #define ld_debug ld_options.ldo_debug
225 #define ld_deref ld_options.ldo_deref
226 #define ld_timelimit ld_options.ldo_timelimit
227 #define ld_sizelimit ld_options.ldo_sizelimit
229 #define ld_defbinddn ld_options.ldo_defbinddn
230 #define ld_defbase ld_options.ldo_defbase
231 #define ld_defhost ld_options.ldo_defhost
232 #define ld_defport ld_options.ldo_defport
234 #define ld_cldaptries ld_options.ldo_cldaptries
235 #define ld_cldaptimeout ld_options.ldo_cldaptimeout
236 #define ld_refhoplimit ld_options.ldo_refhoplimit
238 #define ld_sctrls ld_options.ldo_sctrls
239 #define ld_cctrls ld_options.ldo_cctrls
241 ber_int_t ld_version; /* version connected at */
245 unsigned short ld_lberoptions;
247 LDAPFiltDesc *ld_filtd; /* from getfilter for ufn searches */
248 char *ld_ufnprefix; /* for incomplete ufn's */
255 /* do not mess with these */
256 LDAPRequest *ld_requests; /* list of outstanding requests */
257 LDAPMessage *ld_responses; /* list of outstanding responses */
259 ber_int_t *ld_abandoned; /* array of abandoned requests */
261 LDAPCache *ld_cache; /* non-null if cache is initialized */
262 /* stuff used by connectionless searches. */
264 char *ld_cldapdn; /* DN used in connectionless search */
265 int ld_cldapnaddr; /* number of addresses */
266 void **ld_cldapaddrs;/* addresses to send request to */
268 /* do not mess with the rest though */
269 BERTranslateProc ld_lber_encode_translate_proc;
270 BERTranslateProc ld_lber_decode_translate_proc;
272 LDAPConn *ld_defconn; /* default connection */
273 LDAPConn *ld_conns; /* list of server connections */
274 void *ld_selectinfo; /* platform specifics for select */
275 int (*ld_rebindproc)( struct ldap *ld, char **dnp,
276 char **passwdp, int *authmethodp, int freeit );
277 /* routine to get info needed for re-bind */
278 #ifdef HAVE_CYRUS_SASL
279 sasl_conn_t *ld_sasl_context;
280 #endif /* HAVE_CYRUS_SASL */
282 #define LDAP_VALID(ld) ( (ld)->ld_valid == LDAP_VALID_SESSION )
288 LIBLDAP_F ( struct ldapoptions ) ldap_int_global_options;
289 LIBLDAP_F ( void ) ldap_int_initialize LDAP_P((void));
293 /* simple macros to realloc for now */
294 #define LDAP_INT_MALLOC(s) (LBER_MALLOC((s)))
295 #define LDAP_INT_CALLOC(n,s) (LBER_CALLOC((n),(s)))
296 #define LDAP_INT_REALLOC(p,s) (LBER_REALLOC((p),(s)))
297 #define LDAP_INT_FREE(p) (LBER_FREE((p)))
298 #define LDAP_INT_VFREE(v) (LBER_VFREE((void **)(v)))
299 #define LDAP_INT_STRDUP(s) (LBER_STRDUP((s)))
301 #define LDAP_MALLOC(s) (LBER_MALLOC((s)))
302 #define LDAP_CALLOC(n,s) (LBER_CALLOC((n),(s)))
303 #define LDAP_REALLOC(p,s) (LBER_REALLOC((p),(s)))
304 #define LDAP_FREE(p) (LBER_FREE((p)))
305 #define LDAP_VFREE(v) (LBER_VFREE((void **)(v)))
306 #define LDAP_STRDUP(s) (LBER_STRDUP((s)))
311 LIBLDAP_F (void) ldap_int_utils_init LDAP_P(( void ));
317 LIBLDAP_F (int) ldap_log_printf LDAP_P((LDAP *ld, int level, const char *fmt, ...)) LDAP_GCCATTR((format(printf, 3, 4)));
322 LIBLDAP_F (void) ldap_add_request_to_cache LDAP_P(( LDAP *ld, ber_tag_t msgtype,
323 BerElement *request ));
324 LIBLDAP_F (void) ldap_add_result_to_cache LDAP_P(( LDAP *ld, LDAPMessage *result ));
325 LIBLDAP_F (int) ldap_check_cache LDAP_P(( LDAP *ld, ber_tag_t msgtype, BerElement *request ));
330 LIBLDAP_F (LDAPControl *) ldap_control_dup LDAP_P((
331 const LDAPControl *ctrl ));
333 LIBLDAP_F (LDAPControl **) ldap_controls_dup LDAP_P((
334 LDAPControl *const *ctrls ));
336 LIBLDAP_F (int) ldap_int_get_controls LDAP_P((
338 LDAPControl ***ctrlsp));
340 LIBLDAP_F (int) ldap_int_put_controls LDAP_P((
342 LDAPControl *const *ctrls,
348 LIBLDAP_F (int) next_line_tokens LDAP_P(( char **bufp, ber_len_t *blenp, char ***toksp ));
349 LIBLDAP_F (void) free_strarray LDAP_P(( char **sap ));
355 LIBLDAP_F (char *) ldap_get_kerberosv4_credentials LDAP_P((
357 LDAP_CONST char *who,
358 LDAP_CONST char *service,
361 #endif /* HAVE_KERBEROS */
367 LIBLDAP_F (int) ldap_open_defconn( LDAP *ld );
368 LIBLDAP_F (int) open_ldap_connection( LDAP *ld, Sockbuf *sb, LDAPURLDesc *srvlist, char **krbinstancep, int async );
373 LIBLDAP_F (int) ldap_int_tblsize;
374 LIBLDAP_F (int) ldap_int_timeval_dup( struct timeval **dest, const struct timeval *tm );
375 LIBLDAP_F (int) ldap_connect_to_host( LDAP *ld, Sockbuf *sb, const char *host, unsigned long address, int port, int async );
377 LIBLDAP_F (void) ldap_close_connection( Sockbuf *sb );
379 #if defined(HAVE_KERBEROS) || defined(HAVE_TLS) || defined(HAVE_CYRUS_SASL)
380 LIBLDAP_F (char *) ldap_host_connected_to( Sockbuf *sb );
381 #endif /* HAVE_KERBEROS */
383 LIBLDAP_F (void) ldap_int_ip_init( void );
384 LIBLDAP_F (int) do_ldap_select( LDAP *ld, struct timeval *timeout );
385 LIBLDAP_F (void *) ldap_new_select_info( void );
386 LIBLDAP_F (void) ldap_free_select_info( void *sip );
387 LIBLDAP_F (void) ldap_mark_select_write( LDAP *ld, Sockbuf *sb );
388 LIBLDAP_F (void) ldap_mark_select_read( LDAP *ld, Sockbuf *sb );
389 LIBLDAP_F (void) ldap_mark_select_clear( LDAP *ld, Sockbuf *sb );
390 LIBLDAP_F (int) ldap_is_read_ready( LDAP *ld, Sockbuf *sb );
391 LIBLDAP_F (int) ldap_is_write_ready( LDAP *ld, Sockbuf *sb );
397 LIBLDAP_F (int) ldap_connect_to_path( LDAP *ld, Sockbuf *sb, const char *path, int async );
398 #endif /* LDAP_PF_LOCAL */
403 LIBLDAP_F (ber_int_t) ldap_send_initial_request( LDAP *ld, ber_tag_t msgtype,
404 const char *dn, BerElement *ber );
405 LIBLDAP_F (BerElement *) ldap_alloc_ber_with_options( LDAP *ld );
406 LIBLDAP_F (void) ldap_set_ber_options( LDAP *ld, BerElement *ber );
408 LIBLDAP_F (int) ldap_send_server_request( LDAP *ld, BerElement *ber, ber_int_t msgid, LDAPRequest *parentreq, LDAPURLDesc *srvlist, LDAPConn *lc, int bind );
409 LIBLDAP_F (LDAPConn *) ldap_new_connection( LDAP *ld, LDAPURLDesc *srvlist, int use_ldsb, int connect, int bind );
410 LIBLDAP_F (LDAPRequest *) ldap_find_request_by_msgid( LDAP *ld, ber_int_t msgid );
411 LIBLDAP_F (void) ldap_free_request( LDAP *ld, LDAPRequest *lr );
412 LIBLDAP_F (void) ldap_free_connection( LDAP *ld, LDAPConn *lc, int force, int unbind );
413 LIBLDAP_F (void) ldap_dump_connection( LDAP *ld, LDAPConn *lconns, int all );
414 LIBLDAP_F (void) ldap_dump_requests_and_responses( LDAP *ld );
415 LIBLDAP_F (int) ldap_chase_referrals( LDAP *ld, LDAPRequest *lr, char **errstrp, int *hadrefp );
416 LIBLDAP_F (int) ldap_append_referral( LDAP *ld, char **referralsp, char *s );
421 #ifdef LDAP_CONNECTIONLESS
422 LIBLDAP_F (int) cldap_getmsg( LDAP *ld, struct timeval *timeout, BerElement *ber );
428 LIBLDAP_F (BerElement *) ldap_build_search_req LDAP_P((
435 LDAPControl **sctrls,
436 LDAPControl **cctrls,
438 ber_int_t sizelimit ));
443 /* see <ac/string.h> */
448 LIBLDAP_F (int) ldap_ld_free LDAP_P((
451 LDAPControl **sctrls,
452 LDAPControl **cctrls ));
454 LIBLDAP_F (int) ldap_send_unbind LDAP_P((
457 LDAPControl **sctrls,
458 LDAPControl **cctrls ));
463 LIBLDAP_F (LDAPURLDesc *) ldap_url_dup LDAP_P((
464 LDAPURLDesc *ludp ));
466 LIBLDAP_F (LDAPURLDesc *) ldap_url_duplist LDAP_P((
467 LDAPURLDesc *ludlist ));
469 LIBLDAP_F (int) ldap_url_parselist LDAP_P((
470 LDAPURLDesc **ludlist,
473 LIBLDAP_F (int) ldap_url_parsehosts LDAP_P((
474 LDAPURLDesc **ludlist,
475 const char *hosts ));
477 LIBLDAP_F (char *) ldap_url_list2hosts LDAP_P((
478 LDAPURLDesc *ludlist ));
480 LIBLDAP_F (char *) ldap_url_list2urls LDAP_P((
481 LDAPURLDesc *ludlist ));
483 LIBLDAP_F (void) ldap_free_urllist LDAP_P((
484 LDAPURLDesc *ludlist ));
487 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
491 LIBLDAP_F (char **) ldap_getdxbyname( const char *domain );
492 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
494 #if defined( STR_TRANSLATION ) && defined( LDAP_DEFAULT_CHARSET )
498 * added-in this stuff so that libldap.a would build, i.e. refs to
499 * these routines from open.c would resolve.
500 * hodges@stanford.edu 5-Feb-96
502 #if LDAP_CHARSET_8859 == LDAP_DEFAULT_CHARSET
503 LIBLDAP_F (int) ldap_t61_to_8859( char **bufp, ber_len_t *buflenp, int free_input );
504 LIBLDAP_F (int) ldap_8859_to_t61( char **bufp, ber_len_t *buflenp, int free_input );
505 #endif /* LDAP_CHARSET_8859 == LDAP_DEFAULT_CHARSET */
506 #endif /* STR_TRANSLATION && LDAP_DEFAULT_CHARSET */
510 #endif /* _LDAP_INT_H */