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) )
35 #define LDAP_URL_PREFIX "ldap://"
36 #define LDAP_URL_PREFIX_LEN (sizeof(LDAP_URL_PREFIX)-1)
37 #define LDAPS_URL_PREFIX "ldaps://"
38 #define LDAPS_URL_PREFIX_LEN (sizeof(LDAPS_URL_PREFIX)-1)
39 #define LDAPI_URL_PREFIX "ldapi://"
40 #define LDAPI_URL_PREFIX_LEN (sizeof(LDAPI_URL_PREFIX)-1)
41 #define LDAPIS_URL_PREFIX "ldapis://"
42 #define LDAPIS_URL_PREFIX_LEN (sizeof(LDAPIS_URL_PREFIX)-1)
43 #define LDAP_URL_URLCOLON "URL:"
44 #define LDAP_URL_URLCOLON_LEN (sizeof(LDAP_URL_URLCOLON)-1)
45 #define NULLLDAPURLDESC ((LDAPURLDesc *)NULL)
47 #define LDAP_REF_STR "Referral:\n"
48 #define LDAP_REF_STR_LEN (sizeof(LDAP_REF_STR)-1)
49 #define LDAP_LDAP_REF_STR LDAP_URL_PREFIX
50 #define LDAP_LDAP_REF_STR_LEN (sizeof(LDAP_LDAP_REF_STR)-1)
52 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
53 #define LDAP_DX_REF_STR "dx://"
54 #define LDAP_DX_REF_STR_LEN (sizeof(LDAP_DX_REF_STR)-1)
55 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
57 #define LDAP_DEFAULT_REFHOPLIMIT 5
59 #define LDAP_BOOL_REFERRALS 0
60 #define LDAP_BOOL_RESTART 1
61 #define LDAP_BOOL_DNS 2
62 #define LDAP_BOOL_TLS 3
64 #define LDAP_BOOLEANS unsigned long
65 #define LDAP_BOOL(n) (1 << (n))
66 #define LDAP_BOOL_GET(lo, bool) ((lo)->ldo_booleans & LDAP_BOOL(bool) \
68 #define LDAP_BOOL_SET(lo, bool) ((lo)->ldo_booleans |= LDAP_BOOL(bool))
69 #define LDAP_BOOL_CLR(lo, bool) ((lo)->ldo_booleans &= ~LDAP_BOOL(bool))
70 #define LDAP_BOOL_ZERO(lo) ((lo)->ldo_booleans = 0)
73 * This structure represents both ldap messages and ldap responses.
74 * These are really the same, except in the case of search responses,
75 * where a response has multiple messages.
79 ber_int_t lm_msgid; /* the message id */
80 ber_tag_t lm_msgtype; /* the message type */
81 BerElement *lm_ber; /* the ber encoded message contents */
82 struct ldapmsg *lm_chain; /* for search - next msg in the resp */
83 struct ldapmsg *lm_next; /* next response */
84 time_t lm_time; /* used to maintain cache */
88 * structure representing get/set'able options
89 * which have global defaults.
93 #define LDAP_UNINITIALIZED 0x0
94 #define LDAP_INITIALIZED 0x1
95 #define LDAP_VALID_SESSION 0x2
98 /* per API call timeout */
99 struct timeval *ldo_tm_api;
100 struct timeval *ldo_tm_net;
102 ber_int_t ldo_version; /* version to connect at */
104 ber_int_t ldo_timelimit;
105 ber_int_t ldo_sizelimit;
107 LDAPURLDesc *ldo_defludp;
110 char* ldo_defbinddn; /* simple bind dn */
112 #ifdef LDAP_CONNECTIONLESS
113 int ldo_cldaptries; /* connectionless search retry count */
114 int ldo_cldaptimeout;/* time between retries */
117 int ldo_refhoplimit; /* limit on referral nesting */
119 /* LDAPv3 server and client controls */
120 LDAPControl **ldo_sctrls;
121 LDAPControl **ldo_cctrls;
128 LDAP_BOOLEANS ldo_booleans; /* boolean options */
133 * structure for tracking LDAP server host, ports, DNs, etc.
135 typedef struct ldap_server {
137 char *lsrv_dn; /* if NULL, use default */
139 /* int lsrv_protocol; */
140 struct ldap_server *lsrv_next;
145 * structure for representing an LDAP server connection
147 typedef struct ldap_conn {
150 time_t lconn_lastused; /* time */
152 #define LDAP_CONNST_NEEDSOCKET 1
153 #define LDAP_CONNST_CONNECTING 2
154 #define LDAP_CONNST_CONNECTED 3
155 LDAPURLDesc *lconn_server;
156 char *lconn_krbinstance;
157 struct ldap_conn *lconn_next;
158 BerElement *lconn_ber;/* ber receiving on this conn. */
163 * structure used to track outstanding requests
165 typedef struct ldapreq {
166 ber_int_t lr_msgid; /* the message id */
167 int lr_status; /* status of request */
168 #define LDAP_REQST_INPROGRESS 1
169 #define LDAP_REQST_CHASINGREFS 2
170 #define LDAP_REQST_NOTCONNECTED 3
171 #define LDAP_REQST_WRITING 4
172 int lr_outrefcnt; /* count of outstanding referrals */
173 ber_int_t lr_origid; /* original request's message id */
174 int lr_parentcnt; /* count of parent requests */
175 ber_tag_t lr_res_msgtype; /* result message type */
176 ber_int_t lr_res_errno; /* result LDAP errno */
177 char *lr_res_error; /* result error string */
178 char *lr_res_matched;/* result matched DN string */
179 BerElement *lr_ber; /* ber encoded request contents */
180 LDAPConn *lr_conn; /* connection used to send request */
181 struct ldapreq *lr_parent; /* request that spawned this referral */
182 struct ldapreq *lr_refnext; /* next referral spawned */
183 struct ldapreq *lr_prev; /* previous request */
184 struct ldapreq *lr_next; /* next request */
188 * structure for client cache
190 #define LDAP_CACHE_BUCKETS 31 /* cache hash table size */
191 typedef struct ldapcache {
192 LDAPMessage *lc_buckets[LDAP_CACHE_BUCKETS];/* hash table */
193 LDAPMessage *lc_requests; /* unfulfilled reqs */
194 long lc_timeout; /* request timeout */
195 ber_len_t lc_maxmem; /* memory to use */
196 ber_len_t lc_memused; /* memory in use */
197 int lc_enabled; /* enabled? */
198 unsigned long lc_options; /* options */
199 #define LDAP_CACHE_OPT_CACHENOERRS 0x00000001
200 #define LDAP_CACHE_OPT_CACHEALLERRS 0x00000002
204 * handy macro for checking if handle is connectionless
207 #define LDAP_IS_CLDAP(ld) ((ld)->ld_cldapnaddr>0)
210 * structure representing an ldap connection
214 Sockbuf ld_sb; /* socket descriptor & buffer */
216 struct ldapoptions ld_options;
218 #define ld_valid ld_options.ldo_valid
219 #define ld_debug ld_options.ldo_debug
221 #define ld_deref ld_options.ldo_deref
222 #define ld_timelimit ld_options.ldo_timelimit
223 #define ld_sizelimit ld_options.ldo_sizelimit
225 #define ld_defbinddn ld_options.ldo_defbinddn
226 #define ld_defbase ld_options.ldo_defbase
227 #define ld_defhost ld_options.ldo_defhost
228 #define ld_defport ld_options.ldo_defport
230 #define ld_cldaptries ld_options.ldo_cldaptries
231 #define ld_cldaptimeout ld_options.ldo_cldaptimeout
232 #define ld_refhoplimit ld_options.ldo_refhoplimit
234 #define ld_sctrls ld_options.ldo_sctrls
235 #define ld_cctrls ld_options.ldo_cctrls
237 ber_int_t ld_version; /* version connected at */
241 unsigned short ld_lberoptions;
243 LDAPFiltDesc *ld_filtd; /* from getfilter for ufn searches */
244 char *ld_ufnprefix; /* for incomplete ufn's */
251 /* do not mess with these */
252 LDAPRequest *ld_requests; /* list of outstanding requests */
253 LDAPMessage *ld_responses; /* list of outstanding responses */
255 ber_int_t *ld_abandoned; /* array of abandoned requests */
257 LDAPCache *ld_cache; /* non-null if cache is initialized */
258 /* stuff used by connectionless searches. */
260 char *ld_cldapdn; /* DN used in connectionless search */
261 int ld_cldapnaddr; /* number of addresses */
262 void **ld_cldapaddrs;/* addresses to send request to */
264 /* do not mess with the rest though */
265 BERTranslateProc ld_lber_encode_translate_proc;
266 BERTranslateProc ld_lber_decode_translate_proc;
268 LDAPConn *ld_defconn; /* default connection */
269 LDAPConn *ld_conns; /* list of server connections */
270 void *ld_selectinfo; /* platform specifics for select */
271 int (*ld_rebindproc)( struct ldap *ld, char **dnp,
272 char **passwdp, int *authmethodp, int freeit );
273 /* routine to get info needed for re-bind */
274 #ifdef HAVE_CYRUS_SASL
275 sasl_conn_t *ld_sasl_context;
276 #endif /* HAVE_CYRUS_SASL */
278 #define LDAP_VALID(ld) ( (ld)->ld_valid == LDAP_VALID_SESSION )
280 #if defined(HAVE_RES_SEARCH) && defined(LDAP_R_COMPILE)
281 #include <ldap_pvt_thread.h>
282 extern ldap_pvt_thread_mutex_t ldap_int_resolv_mutex;
283 #endif /* HAVE_RES_SEARCH && LDAP_R_COMPILE */
289 LIBLDAP_F ( struct ldapoptions ) ldap_int_global_options;
290 LIBLDAP_F ( void ) ldap_int_initialize LDAP_P((void));
294 /* simple macros to realloc for now */
295 #define LDAP_INT_MALLOC(s) (LBER_MALLOC((s)))
296 #define LDAP_INT_CALLOC(n,s) (LBER_CALLOC((n),(s)))
297 #define LDAP_INT_REALLOC(p,s) (LBER_REALLOC((p),(s)))
298 #define LDAP_INT_FREE(p) (LBER_FREE((p)))
299 #define LDAP_INT_VFREE(v) (LBER_VFREE((void **)(v)))
300 #define LDAP_INT_STRDUP(s) (LBER_STRDUP((s)))
302 #define LDAP_MALLOC(s) (LBER_MALLOC((s)))
303 #define LDAP_CALLOC(n,s) (LBER_CALLOC((n),(s)))
304 #define LDAP_REALLOC(p,s) (LBER_REALLOC((p),(s)))
305 #define LDAP_FREE(p) (LBER_FREE((p)))
306 #define LDAP_VFREE(v) (LBER_VFREE((void **)(v)))
307 #define LDAP_STRDUP(s) (LBER_STRDUP((s)))
312 LIBLDAP_F (void) ldap_int_utils_init LDAP_P(( void ));
318 LIBLDAP_F (int) ldap_log_printf LDAP_P((LDAP *ld, int level, const char *fmt, ...)) LDAP_GCCATTR((format(printf, 3, 4)));
323 LIBLDAP_F (void) ldap_add_request_to_cache LDAP_P(( LDAP *ld, ber_tag_t msgtype,
324 BerElement *request ));
325 LIBLDAP_F (void) ldap_add_result_to_cache LDAP_P(( LDAP *ld, LDAPMessage *result ));
326 LIBLDAP_F (int) ldap_check_cache LDAP_P(( LDAP *ld, ber_tag_t msgtype, BerElement *request ));
331 LIBLDAP_F (LDAPControl *) ldap_control_dup LDAP_P((
332 const LDAPControl *ctrl ));
334 LIBLDAP_F (LDAPControl **) ldap_controls_dup LDAP_P((
335 LDAPControl *const *ctrls ));
337 LIBLDAP_F (int) ldap_int_get_controls LDAP_P((
339 LDAPControl ***ctrlsp));
341 LIBLDAP_F (int) ldap_int_put_controls LDAP_P((
343 LDAPControl *const *ctrls,
349 LIBLDAP_F (int) next_line_tokens LDAP_P(( char **bufp, ber_len_t *blenp, char ***toksp ));
350 LIBLDAP_F (void) free_strarray LDAP_P(( char **sap ));
352 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
356 LIBLDAP_F (char *) ldap_get_kerberosv4_credentials LDAP_P((
358 LDAP_CONST char *who,
359 LDAP_CONST char *service,
362 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND */
368 LIBLDAP_F (int) ldap_open_defconn( LDAP *ld );
369 LIBLDAP_F (int) open_ldap_connection( LDAP *ld, Sockbuf *sb, LDAPURLDesc *srvlist, char **krbinstancep, int async );
374 LIBLDAP_F (int) ldap_int_tblsize;
375 LIBLDAP_F (int) ldap_int_timeval_dup( struct timeval **dest, const struct timeval *tm );
376 LIBLDAP_F (int) ldap_connect_to_host( LDAP *ld, Sockbuf *sb, const char *host, unsigned long address, int port, int async );
378 LIBLDAP_F (void) ldap_close_connection( Sockbuf *sb );
380 #if defined(LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND) || defined(HAVE_TLS) || defined(HAVE_CYRUS_SASL)
381 LIBLDAP_F (char *) ldap_host_connected_to( Sockbuf *sb );
382 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND */
384 LIBLDAP_F (void) ldap_int_ip_init( void );
385 LIBLDAP_F (int) do_ldap_select( LDAP *ld, struct timeval *timeout );
386 LIBLDAP_F (void *) ldap_new_select_info( void );
387 LIBLDAP_F (void) ldap_free_select_info( void *sip );
388 LIBLDAP_F (void) ldap_mark_select_write( LDAP *ld, Sockbuf *sb );
389 LIBLDAP_F (void) ldap_mark_select_read( LDAP *ld, Sockbuf *sb );
390 LIBLDAP_F (void) ldap_mark_select_clear( LDAP *ld, Sockbuf *sb );
391 LIBLDAP_F (int) ldap_is_read_ready( LDAP *ld, Sockbuf *sb );
392 LIBLDAP_F (int) ldap_is_write_ready( LDAP *ld, Sockbuf *sb );
398 LIBLDAP_F (int) ldap_connect_to_path( LDAP *ld, Sockbuf *sb, const char *path, int async );
399 #endif /* LDAP_PF_LOCAL */
404 LIBLDAP_F (ber_int_t) ldap_send_initial_request( LDAP *ld, ber_tag_t msgtype,
405 const char *dn, BerElement *ber );
406 LIBLDAP_F (BerElement *) ldap_alloc_ber_with_options( LDAP *ld );
407 LIBLDAP_F (void) ldap_set_ber_options( LDAP *ld, BerElement *ber );
409 LIBLDAP_F (int) ldap_send_server_request( LDAP *ld, BerElement *ber, ber_int_t msgid, LDAPRequest *parentreq, LDAPURLDesc *srvlist, LDAPConn *lc, int bind );
410 LIBLDAP_F (LDAPConn *) ldap_new_connection( LDAP *ld, LDAPURLDesc *srvlist, int use_ldsb, int connect, int bind );
411 LIBLDAP_F (LDAPRequest *) ldap_find_request_by_msgid( LDAP *ld, ber_int_t msgid );
412 LIBLDAP_F (void) ldap_free_request( LDAP *ld, LDAPRequest *lr );
413 LIBLDAP_F (void) ldap_free_connection( LDAP *ld, LDAPConn *lc, int force, int unbind );
414 LIBLDAP_F (void) ldap_dump_connection( LDAP *ld, LDAPConn *lconns, int all );
415 LIBLDAP_F (void) ldap_dump_requests_and_responses( LDAP *ld );
416 LIBLDAP_F (int) ldap_chase_referrals( LDAP *ld, LDAPRequest *lr, char **errstrp, int *hadrefp );
417 LIBLDAP_F (int) ldap_append_referral( LDAP *ld, char **referralsp, char *s );
422 #ifdef LDAP_CONNECTIONLESS
423 LIBLDAP_F (int) cldap_getmsg( LDAP *ld, struct timeval *timeout, BerElement *ber );
429 LIBLDAP_F (BerElement *) ldap_build_search_req LDAP_P((
436 LDAPControl **sctrls,
437 LDAPControl **cctrls,
439 ber_int_t sizelimit ));
444 /* see <ac/string.h> */
449 LIBLDAP_F (int) ldap_ld_free LDAP_P((
452 LDAPControl **sctrls,
453 LDAPControl **cctrls ));
455 LIBLDAP_F (int) ldap_send_unbind LDAP_P((
458 LDAPControl **sctrls,
459 LDAPControl **cctrls ));
464 LIBLDAP_F (LDAPURLDesc *) ldap_url_dup LDAP_P((
465 LDAPURLDesc *ludp ));
467 LIBLDAP_F (LDAPURLDesc *) ldap_url_duplist LDAP_P((
468 LDAPURLDesc *ludlist ));
470 LIBLDAP_F (int) ldap_url_parselist LDAP_P((
471 LDAPURLDesc **ludlist,
474 LIBLDAP_F (int) ldap_url_parsehosts LDAP_P((
475 LDAPURLDesc **ludlist,
476 const char *hosts ));
478 LIBLDAP_F (char *) ldap_url_list2hosts LDAP_P((
479 LDAPURLDesc *ludlist ));
481 LIBLDAP_F (char *) ldap_url_list2urls LDAP_P((
482 LDAPURLDesc *ludlist ));
484 LIBLDAP_F (void) ldap_free_urllist LDAP_P((
485 LDAPURLDesc *ludlist ));
488 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
492 LIBLDAP_F (char **) ldap_getdxbyname( const char *domain );
493 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
495 #if defined( STR_TRANSLATION ) && defined( LDAP_DEFAULT_CHARSET )
499 * added-in this stuff so that libldap.a would build, i.e. refs to
500 * these routines from open.c would resolve.
501 * hodges@stanford.edu 5-Feb-96
503 #if LDAP_CHARSET_8859 == LDAP_DEFAULT_CHARSET
504 LIBLDAP_F (int) ldap_t61_to_8859( char **bufp, ber_len_t *buflenp, int free_input );
505 LIBLDAP_F (int) ldap_8859_to_t61( char **bufp, ber_len_t *buflenp, int free_input );
506 #endif /* LDAP_CHARSET_8859 == LDAP_DEFAULT_CHARSET */
507 #endif /* STR_TRANSLATION && LDAP_DEFAULT_CHARSET */
513 LIBLDAP_F (ber_len_t) ldap_utf8_bytes( const char * );
514 LIBLDAP_F (ber_len_t) ldap_utf8_chars( const char * );
515 LIBLDAP_F (int) ldap_utf8_charlen( const char * );
517 LIBLDAP_F (char*) ldap_utf8_next( const char * );
518 LIBLDAP_F (char*) ldap_utf8_prev( const char * );
520 LIBLDAP_F (int) ldap_utf8_isascii( const char * );
521 LIBLDAP_F (int) ldap_utf8_isalpa( const char * );
522 LIBLDAP_F (int) ldap_utf8_isalnum( const char * );
523 LIBLDAP_F (int) ldap_utf8_isdigit( const char * );
524 LIBLDAP_F (int) ldap_utf8_isxdigit( const char * );
525 LIBLDAP_F (int) ldap_utf8_isspace( const char * );
527 LIBLDAP_F (ber_len_t) ldap_utf8_strcspn( const char* str, const char *set);
528 LIBLDAP_F (ber_len_t) ldap_utf8_strspn( const char* str, const char *set);
529 LIBLDAP_F (char*) ldap_utf8_strtok( char* sp, const char* sep, char **last);
533 #endif /* _LDAP_INT_H */