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 LDAP_URL_URLCOLON "URL:"
40 #define LDAP_URL_URLCOLON_LEN (sizeof(LDAP_URL_URLCOLON)-1)
41 #define NULLLDAPURLDESC ((LDAPURLDesc *)NULL)
43 #define LDAP_REF_STR "Referral:\n"
44 #define LDAP_REF_STR_LEN (sizeof(LDAP_REF_STR)-1)
45 #define LDAP_LDAP_REF_STR LDAP_URL_PREFIX
46 #define LDAP_LDAP_REF_STR_LEN (sizeof(LDAP_LDAP_REF_STR)-1)
48 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
49 #define LDAP_DX_REF_STR "dx://"
50 #define LDAP_DX_REF_STR_LEN (sizeof(LDAP_DX_REF_STR)-1)
51 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
53 #define LDAP_DEFAULT_REFHOPLIMIT 5
55 #define LDAP_BOOL_REFERRALS 0
56 #define LDAP_BOOL_RESTART 1
57 #define LDAP_BOOL_DNS 2
58 #define LDAP_BOOL_TLS 3
60 #define LDAP_BOOLEANS unsigned long
61 #define LDAP_BOOL(n) (1 << (n))
62 #define LDAP_BOOL_GET(lo, bool) ((lo)->ldo_booleans & LDAP_BOOL(bool) \
64 #define LDAP_BOOL_SET(lo, bool) ((lo)->ldo_booleans |= LDAP_BOOL(bool))
65 #define LDAP_BOOL_CLR(lo, bool) ((lo)->ldo_booleans &= ~LDAP_BOOL(bool))
66 #define LDAP_BOOL_ZERO(lo) ((lo)->ldo_booleans = 0)
69 * This structure represents both ldap messages and ldap responses.
70 * These are really the same, except in the case of search responses,
71 * where a response has multiple messages.
75 ber_int_t lm_msgid; /* the message id */
76 ber_tag_t lm_msgtype; /* the message type */
77 BerElement *lm_ber; /* the ber encoded message contents */
78 struct ldapmsg *lm_chain; /* for search - next msg in the resp */
79 struct ldapmsg *lm_next; /* next response */
80 time_t lm_time; /* used to maintain cache */
84 * structure representing get/set'able options
85 * which have global defaults.
89 #define LDAP_UNINITIALIZED 0x0
90 #define LDAP_INITIALIZED 0x1
91 #define LDAP_VALID_SESSION 0x2
94 /* per API call timeout */
95 struct timeval *ldo_tm_api;
96 struct timeval *ldo_tm_net;
98 ber_int_t ldo_version; /* version to connect at */
100 ber_int_t ldo_timelimit;
101 ber_int_t ldo_sizelimit;
107 #ifdef LDAP_CONNECTIONLESS
108 int ldo_cldaptries; /* connectionless search retry count */
109 int ldo_cldaptimeout;/* time between retries */
112 int ldo_refhoplimit; /* limit on referral nesting */
114 /* LDAPv3 server and client controls */
115 LDAPControl **ldo_sctrls;
116 LDAPControl **ldo_cctrls;
123 LDAP_BOOLEANS ldo_booleans; /* boolean options */
128 * structure for tracking LDAP server host, ports, DNs, etc.
130 typedef struct ldap_server {
132 char *lsrv_dn; /* if NULL, use default */
134 struct ldap_server *lsrv_next;
139 * structure for representing an LDAP server connection
141 typedef struct ldap_conn {
144 time_t lconn_lastused; /* time */
146 #define LDAP_CONNST_NEEDSOCKET 1
147 #define LDAP_CONNST_CONNECTING 2
148 #define LDAP_CONNST_CONNECTED 3
149 LDAPServer *lconn_server;
150 char *lconn_krbinstance;
151 struct ldap_conn *lconn_next;
152 BerElement *lconn_ber;/* ber receiving on this conn. */
157 * structure used to track outstanding requests
159 typedef struct ldapreq {
160 ber_int_t lr_msgid; /* the message id */
161 int lr_status; /* status of request */
162 #define LDAP_REQST_INPROGRESS 1
163 #define LDAP_REQST_CHASINGREFS 2
164 #define LDAP_REQST_NOTCONNECTED 3
165 #define LDAP_REQST_WRITING 4
166 int lr_outrefcnt; /* count of outstanding referrals */
167 ber_int_t lr_origid; /* original request's message id */
168 int lr_parentcnt; /* count of parent requests */
169 ber_tag_t lr_res_msgtype; /* result message type */
170 ber_int_t lr_res_errno; /* result LDAP errno */
171 char *lr_res_error; /* result error string */
172 char *lr_res_matched;/* result matched DN string */
173 BerElement *lr_ber; /* ber encoded request contents */
174 LDAPConn *lr_conn; /* connection used to send request */
175 struct ldapreq *lr_parent; /* request that spawned this referral */
176 struct ldapreq *lr_refnext; /* next referral spawned */
177 struct ldapreq *lr_prev; /* previous request */
178 struct ldapreq *lr_next; /* next request */
182 * structure for client cache
184 #define LDAP_CACHE_BUCKETS 31 /* cache hash table size */
185 typedef struct ldapcache {
186 LDAPMessage *lc_buckets[LDAP_CACHE_BUCKETS];/* hash table */
187 LDAPMessage *lc_requests; /* unfulfilled reqs */
188 long lc_timeout; /* request timeout */
189 ber_len_t lc_maxmem; /* memory to use */
190 ber_len_t lc_memused; /* memory in use */
191 int lc_enabled; /* enabled? */
192 unsigned long lc_options; /* options */
193 #define LDAP_CACHE_OPT_CACHENOERRS 0x00000001
194 #define LDAP_CACHE_OPT_CACHEALLERRS 0x00000002
198 * handy macro for checking if handle is connectionless
201 #define LDAP_IS_CLDAP(ld) ((ld)->ld_cldapnaddr>0)
204 * structure representing an ldap connection
208 Sockbuf ld_sb; /* socket descriptor & buffer */
210 struct ldapoptions ld_options;
212 #define ld_valid ld_options.ldo_valid
213 #define ld_debug ld_options.ldo_debug
215 #define ld_deref ld_options.ldo_deref
216 #define ld_timelimit ld_options.ldo_timelimit
217 #define ld_sizelimit ld_options.ldo_sizelimit
219 #define ld_defbase ld_options.ldo_defbase
220 #define ld_defhost ld_options.ldo_defhost
221 #define ld_defport ld_options.ldo_defport
223 #define ld_cldaptries ld_options.ldo_cldaptries
224 #define ld_cldaptimeout ld_options.ldo_cldaptimeout
225 #define ld_refhoplimit ld_options.ldo_refhoplimit
227 #define ld_sctrls ld_options.ldo_sctrls
228 #define ld_cctrls ld_options.ldo_cctrls
230 ber_int_t ld_version; /* version connected at */
234 unsigned short ld_lberoptions;
236 LDAPFiltDesc *ld_filtd; /* from getfilter for ufn searches */
237 char *ld_ufnprefix; /* for incomplete ufn's */
244 /* do not mess with these */
245 LDAPRequest *ld_requests; /* list of outstanding requests */
246 LDAPMessage *ld_responses; /* list of outstanding responses */
248 ber_int_t *ld_abandoned; /* array of abandoned requests */
250 LDAPCache *ld_cache; /* non-null if cache is initialized */
251 /* stuff used by connectionless searches. */
253 char *ld_cldapdn; /* DN used in connectionless search */
254 int ld_cldapnaddr; /* number of addresses */
255 void **ld_cldapaddrs;/* addresses to send request to */
257 /* do not mess with the rest though */
258 BERTranslateProc ld_lber_encode_translate_proc;
259 BERTranslateProc ld_lber_decode_translate_proc;
261 LDAPConn *ld_defconn; /* default connection */
262 LDAPConn *ld_conns; /* list of server connections */
263 void *ld_selectinfo; /* platform specifics for select */
264 int (*ld_rebindproc)( struct ldap *ld, char **dnp,
265 char **passwdp, int *authmethodp, int freeit );
266 /* routine to get info needed for re-bind */
268 #define LDAP_VALID(ld) ( (ld)->ld_valid == LDAP_VALID_SESSION )
274 LDAP_F ( struct ldapoptions ) ldap_int_global_options;
275 void ldap_int_initialize LDAP_P((void));
279 /* simple macros to realloc for now */
280 #define LDAP_INT_MALLOC(s) (LBER_MALLOC((s)))
281 #define LDAP_INT_CALLOC(n,s) (LBER_CALLOC((n),(s)))
282 #define LDAP_INT_REALLOC(p,s) (LBER_REALLOC((p),(s)))
283 #define LDAP_INT_FREE(p) (LBER_FREE((p)))
284 #define LDAP_INT_VFREE(v) (LBER_VFREE((void **)(v)))
285 #define LDAP_INT_STRDUP(s) (LBER_STRDUP((s)))
287 #define LDAP_MALLOC(s) (LBER_MALLOC((s)))
288 #define LDAP_CALLOC(n,s) (LBER_CALLOC((n),(s)))
289 #define LDAP_REALLOC(p,s) (LBER_REALLOC((p),(s)))
290 #define LDAP_FREE(p) (LBER_FREE((p)))
291 #define LDAP_VFREE(v) (LBER_VFREE((void **)(v)))
292 #define LDAP_STRDUP(s) (LBER_STRDUP((s)))
297 void ldap_int_utils_init LDAP_P(( void ));
303 int ldap_log_printf LDAP_P((LDAP *ld, int level, const char *fmt, ...))
304 LDAP_GCCATTR((format(printf, 3, 4)));
309 void ldap_add_request_to_cache LDAP_P(( LDAP *ld, ber_tag_t msgtype,
310 BerElement *request ));
311 void ldap_add_result_to_cache LDAP_P(( LDAP *ld, LDAPMessage *result ));
312 int ldap_check_cache LDAP_P(( LDAP *ld, ber_tag_t msgtype, BerElement *request ));
317 LDAPControl *ldap_control_dup LDAP_P((
318 const LDAPControl *ctrl ));
320 LDAPControl **ldap_controls_dup LDAP_P((
321 LDAPControl *const *ctrls ));
323 int ldap_int_get_controls LDAP_P((
325 LDAPControl ***ctrlsp));
327 int ldap_int_put_controls LDAP_P((
329 LDAPControl *const *ctrls,
335 int next_line_tokens LDAP_P(( char **bufp, ber_len_t *blenp, char ***toksp ));
336 void free_strarray LDAP_P(( char **sap ));
342 char *ldap_get_kerberosv4_credentials LDAP_P((
344 LDAP_CONST char *who,
345 LDAP_CONST char *service,
348 #endif /* HAVE_KERBEROS */
354 int ldap_open_defconn( LDAP *ld );
355 int open_ldap_connection( LDAP *ld, Sockbuf *sb, const char *host, int defport,
356 char **krbinstancep, int async );
362 extern int ldap_int_tblsize;
363 int ldap_int_timeval_dup( struct timeval **dest, const struct timeval *tm );
364 int ldap_connect_to_host( LDAP *ld, Sockbuf *sb, const char *host,
365 unsigned long address, int port, int async );
367 void ldap_close_connection( Sockbuf *sb );
370 char *ldap_host_connected_to( Sockbuf *sb );
371 #endif /* HAVE_KERBEROS */
373 void ldap_int_ip_init( void );
374 int do_ldap_select( LDAP *ld, struct timeval *timeout );
375 void *ldap_new_select_info( void );
376 void ldap_free_select_info( void *sip );
377 void ldap_mark_select_write( LDAP *ld, Sockbuf *sb );
378 void ldap_mark_select_read( LDAP *ld, Sockbuf *sb );
379 void ldap_mark_select_clear( LDAP *ld, Sockbuf *sb );
380 int ldap_is_read_ready( LDAP *ld, Sockbuf *sb );
381 int ldap_is_write_ready( LDAP *ld, Sockbuf *sb );
387 ber_int_t ldap_send_initial_request( LDAP *ld, ber_tag_t msgtype,
388 const char *dn, BerElement *ber );
389 BerElement *ldap_alloc_ber_with_options( LDAP *ld );
390 void ldap_set_ber_options( LDAP *ld, BerElement *ber );
392 int ldap_send_server_request( LDAP *ld, BerElement *ber, ber_int_t msgid,
393 LDAPRequest *parentreq, LDAPServer *srvlist, LDAPConn *lc,
395 LDAPConn *ldap_new_connection( LDAP *ld, LDAPServer **srvlistp, int use_ldsb,
396 int connect, int bind );
397 LDAPRequest *ldap_find_request_by_msgid( LDAP *ld, ber_int_t msgid );
398 void ldap_free_request( LDAP *ld, LDAPRequest *lr );
399 void ldap_free_connection( LDAP *ld, LDAPConn *lc, int force, int unbind );
400 void ldap_dump_connection( LDAP *ld, LDAPConn *lconns, int all );
401 void ldap_dump_requests_and_responses( LDAP *ld );
403 int ldap_chase_referrals( LDAP *ld, LDAPRequest *lr, char **errstrp, int *hadrefp );
404 int ldap_append_referral( LDAP *ld, char **referralsp, char *s );
409 #ifdef LDAP_CONNECTIONLESS
410 int cldap_getmsg( LDAP *ld, struct timeval *timeout, BerElement *ber );
416 BerElement *ldap_build_search_req LDAP_P((
423 LDAPControl **sctrls,
424 LDAPControl **cctrls,
426 ber_int_t sizelimit ));
431 /* see <ac/string.h> */
436 int ldap_ld_free LDAP_P((
439 LDAPControl **sctrls,
440 LDAPControl **cctrls ));
442 int ldap_send_unbind LDAP_P((
445 LDAPControl **sctrls,
446 LDAPControl **cctrls ));
448 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
452 char **ldap_getdxbyname( const char *domain );
453 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
455 #if defined( STR_TRANSLATION ) && defined( LDAP_DEFAULT_CHARSET )
459 * added-in this stuff so that libldap.a would build, i.e. refs to
460 * these routines from open.c would resolve.
461 * hodges@stanford.edu 5-Feb-96
463 #if LDAP_CHARSET_8859 == LDAP_DEFAULT_CHARSET
465 int ldap_t61_to_8859( char **bufp, ber_len_t *buflenp, int free_input );
467 int ldap_8859_to_t61( char **bufp, ber_len_t *buflenp, int free_input );
468 #endif /* LDAP_CHARSET_8859 == LDAP_DEFAULT_CHARSET */
469 #endif /* STR_TRANSLATION && LDAP_DEFAULT_CHARSET */
473 #endif /* _LDAP_INT_H */