2 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
3 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6 * Copyright (c) 1995 Regents of the University of Michigan.
9 * ldap-int.h - defines & prototypes internal to the LDAP library
15 #ifdef LDAP_COMPILING_R
16 #define LDAP_THREAD_SAFE 1
19 #include "../liblber/lber-int.h"
21 #define ldap_debug (openldap_ldap_global_options.ldo_debug)
31 #define LDAP_URL_PREFIX "ldap://"
32 #define LDAP_URL_PREFIX_LEN 7
33 #define LDAP_URL_URLCOLON "URL:"
34 #define LDAP_URL_URLCOLON_LEN 4
36 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
37 #define LDAP_REF_STR "Referral:\n"
38 #define LDAP_REF_STR_LEN 10
39 #define LDAP_LDAP_REF_STR LDAP_URL_PREFIX
40 #define LDAP_LDAP_REF_STR_LEN LDAP_URL_PREFIX_LEN
41 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
42 #define LDAP_DX_REF_STR "dx://"
43 #define LDAP_DX_REF_STR_LEN 5
44 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
45 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
47 #define LDAP_BOOL_REFERRALS 0
48 #define LDAP_BOOL_RESTART 1
49 #define LDAP_BOOL_DNS 2
51 #define LDAP_BOOLEANS unsigned long
52 #define LDAP_BOOL(n) (1 << (n))
53 #define LDAP_BOOL_GET(lo, bool) ((lo)->ldo_booleans & LDAP_BOOL(bool) \
54 ? LDAP_OPT_ON : LDAP_OPT_OFF)
55 #define LDAP_BOOL_SET(lo, bool) ((lo)->ldo_booleans |= LDAP_BOOL(bool))
56 #define LDAP_BOOL_CLR(lo, bool) ((lo)->ldo_booleans &= ~LDAP_BOOL(bool))
57 #define LDAP_BOOL_ZERO(lo) ((lo)->ldo_booleans = 0)
60 * This structure represents both ldap messages and ldap responses.
61 * These are really the same, except in the case of search responses,
62 * where a response has multiple messages.
66 int lm_msgid; /* the message id */
67 int lm_msgtype; /* the message type */
68 BerElement *lm_ber; /* the ber encoded message contents */
69 struct ldapmsg *lm_chain; /* for search - next msg in the resp */
70 struct ldapmsg *lm_next; /* next response */
71 unsigned int lm_time; /* used to maintain cache */
75 * structure representing get/set'able options
76 * which have global defaults.
79 int ldo_version; /* version to connect at */
90 int ldo_cldaptries; /* connectionless search retry count */
91 int ldo_cldaptimeout;/* time between retries */
92 int ldo_refhoplimit; /* limit on referral nesting */
94 /* LDAPv3 server and client controls */
95 LDAPControl **ldo_server_controls;
96 LDAPControl **ldo_client_controls;
98 LDAP_BOOLEANS ldo_booleans; /* boolean options */
101 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
103 * structure for tracking LDAP server host, ports, DNs, etc.
105 typedef struct ldap_server {
107 char *lsrv_dn; /* if NULL, use default */
109 struct ldap_server *lsrv_next;
114 * structure for representing an LDAP server connection
116 typedef struct ldap_conn {
119 time_t lconn_lastused; /* time */
121 #define LDAP_CONNST_NEEDSOCKET 1
122 #define LDAP_CONNST_CONNECTING 2
123 #define LDAP_CONNST_CONNECTED 3
124 LDAPServer *lconn_server;
125 char *lconn_krbinstance;
126 struct ldap_conn *lconn_next;
131 * structure used to track outstanding requests
133 typedef struct ldapreq {
134 int lr_msgid; /* the message id */
135 int lr_status; /* status of request */
136 #define LDAP_REQST_INPROGRESS 1
137 #define LDAP_REQST_CHASINGREFS 2
138 #define LDAP_REQST_NOTCONNECTED 3
139 #define LDAP_REQST_WRITING 4
140 int lr_outrefcnt; /* count of outstanding referrals */
141 int lr_origid; /* original request's message id */
142 int lr_parentcnt; /* count of parent requests */
143 int lr_res_msgtype; /* result message type */
144 int lr_res_errno; /* result LDAP errno */
145 char *lr_res_error; /* result error string */
146 char *lr_res_matched;/* result matched DN string */
147 BerElement *lr_ber; /* ber encoded request contents */
148 LDAPConn *lr_conn; /* connection used to send request */
149 struct ldapreq *lr_parent; /* request that spawned this referral */
150 struct ldapreq *lr_refnext; /* next referral spawned */
151 struct ldapreq *lr_prev; /* previous request */
152 struct ldapreq *lr_next; /* next request */
154 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
157 * structure for client cache
159 #define LDAP_CACHE_BUCKETS 31 /* cache hash table size */
160 typedef struct ldapcache {
161 LDAPMessage *lc_buckets[LDAP_CACHE_BUCKETS];/* hash table */
162 LDAPMessage *lc_requests; /* unfulfilled reqs */
163 long lc_timeout; /* request timeout */
164 long lc_maxmem; /* memory to use */
165 long lc_memused; /* memory in use */
166 int lc_enabled; /* enabled? */
167 unsigned long lc_options; /* options */
168 #define LDAP_CACHE_OPT_CACHENOERRS 0x00000001
169 #define LDAP_CACHE_OPT_CACHEALLERRS 0x00000002
171 #define NULLLDCACHE ((LDAPCache *)NULL)
175 * structure representing an ldap connection
179 Sockbuf ld_sb; /* socket descriptor & buffer */
181 struct ldapoptions ld_options;
183 #define ld_deref ld_options.ldo_deref
184 #define ld_timelimit ld_options.ldo_timelimit
185 #define ld_sizelimit ld_options.ldo_sizelimit
187 #define ld_defbase ld_options.ldo_defbase
188 #define ld_defhost ld_options.ldo_defhost
189 #define ld_defport ld_options.ldo_defport
191 #define ld_cldaptries ld_options.ldo_cldaptries
192 #define ld_cldaptimeout ld_options.ldo_cldaptimeout
193 #define ld_refhoplimit ld_options.ldo_refhoplimit
195 int ld_version; /* version connected at */
201 LDAPFiltDesc *ld_filtd; /* from getfilter for ufn searches */
202 char *ld_ufnprefix; /* for incomplete ufn's */
209 /* do not mess with these */
210 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
211 LDAPRequest *ld_requests; /* list of outstanding requests */
212 #else /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
213 LDAPMessage *ld_requests; /* list of outstanding requests */
214 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
215 LDAPMessage *ld_responses; /* list of outstanding responses */
216 int *ld_abandoned; /* array of abandoned requests */
217 char ld_attrbuffer[LDAP_MAX_ATTR_LEN];
218 LDAPCache *ld_cache; /* non-null if cache is initialized */
219 char *ld_cldapdn; /* DN used in connectionless search */
221 /* do not mess with the rest though */
222 BERTranslateProc ld_lber_encode_translate_proc;
223 BERTranslateProc ld_lber_decode_translate_proc;
225 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
226 LDAPConn *ld_defconn; /* default connection */
227 LDAPConn *ld_conns; /* list of server connections */
228 void *ld_selectinfo; /* platform specifics for select */
229 int (*ld_rebindproc)( struct ldap *ld, char **dnp,
230 char **passwdp, int *authmethodp, int freeit );
231 /* routine to get info needed for re-bind */
232 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
238 extern int openldap_ldap_initialized;
239 extern struct ldapoptions openldap_ldap_global_options;
240 void openldap_ldap_initialize LDAP_P((void));
245 void ldap_add_request_to_cache LDAP_P(( LDAP *ld, unsigned long msgtype,
246 BerElement *request ));
247 void ldap_add_result_to_cache LDAP_P(( LDAP *ld, LDAPMessage *result ));
248 int ldap_check_cache LDAP_P(( LDAP *ld, unsigned long msgtype, BerElement *request ));
253 LDAPControl *ldap_control_dup LDAP_P(( LDAPControl *ctrl ));
254 LDAPControl **ldap_controls_dup LDAP_P(( LDAPControl **ctrl ));
259 int next_line_tokens LDAP_P(( char **bufp, long *blenp, char ***toksp ));
260 void free_strarray LDAP_P(( char **sap ));
266 char *ldap_get_kerberosv4_credentials LDAP_P(( LDAP *ld, char *who, char *service,
269 #endif /* HAVE_KERBEROS */
275 int open_ldap_connection( LDAP *ld, Sockbuf *sb, char *host, int defport,
276 char **krbinstancep, int async );
282 int ldap_connect_to_host( Sockbuf *sb, char *host, unsigned long address, int port,
284 void ldap_close_connection( Sockbuf *sb );
287 char *ldap_host_connected_to( Sockbuf *sb );
288 #endif /* HAVE_KERBEROS */
290 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
291 int do_ldap_select( LDAP *ld, struct timeval *timeout );
292 void *ldap_new_select_info( void );
293 void ldap_free_select_info( void *sip );
294 void ldap_mark_select_write( LDAP *ld, Sockbuf *sb );
295 void ldap_mark_select_read( LDAP *ld, Sockbuf *sb );
296 void ldap_mark_select_clear( LDAP *ld, Sockbuf *sb );
297 int ldap_is_read_ready( LDAP *ld, Sockbuf *sb );
298 int ldap_is_write_ready( LDAP *ld, Sockbuf *sb );
299 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
305 int ldap_send_initial_request( LDAP *ld, unsigned long msgtype,
306 char *dn, BerElement *ber );
307 BerElement *ldap_alloc_ber_with_options( LDAP *ld );
308 void ldap_set_ber_options( LDAP *ld, BerElement *ber );
310 #if defined( LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS ) || defined( LDAP_API_FEATURE_X_OPENLDAP_V2_DNS )
311 int ldap_send_server_request( LDAP *ld, BerElement *ber, int msgid,
312 LDAPRequest *parentreq, LDAPServer *srvlist, LDAPConn *lc,
314 LDAPConn *ldap_new_connection( LDAP *ld, LDAPServer **srvlistp, int use_ldsb,
315 int connect, int bind );
316 LDAPRequest *ldap_find_request_by_msgid( LDAP *ld, int msgid );
317 void ldap_free_request( LDAP *ld, LDAPRequest *lr );
318 void ldap_free_connection( LDAP *ld, LDAPConn *lc, int force, int unbind );
319 void ldap_dump_connection( LDAP *ld, LDAPConn *lconns, int all );
320 void ldap_dump_requests_and_responses( LDAP *ld );
321 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS || LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
323 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
324 int ldap_chase_referrals( LDAP *ld, LDAPRequest *lr, char **errstrp, int *hadrefp );
325 int ldap_append_referral( LDAP *ld, char **referralsp, char *s );
326 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
331 #ifdef LDAP_CONNECTIONLESS
332 LDAP_F int cldap_getmsg ( LDAP *ld, struct timeval *timeout, BerElement *ber );
338 BerElement *ldap_build_search_req( LDAP *ld, char *base, int scope,
339 char *filter, char **attrs, int attrsonly );
344 char *ldap_strdup LDAP_P(( const char * ));
349 int ldap_ld_free( LDAP *ld, int close );
350 int ldap_send_unbind( LDAP *ld, Sockbuf *sb );
352 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
356 char **ldap_getdxbyname( char *domain );
357 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
359 #if defined( STR_TRANSLATION ) && defined( LDAP_DEFAULT_CHARSET )
363 * added-in this stuff so that libldap.a would build, i.e. refs to
364 * these routines from open.c would resolve.
365 * hodges@stanford.edu 5-Feb-96
367 #if LDAP_CHARSET_8859 == LDAP_DEFAULT_CHARSET
369 int ldap_t61_to_8859( char **bufp, unsigned long *buflenp, int free_input );
371 int ldap_8859_to_t61( char **bufp, unsigned long *buflenp, int free_input );
372 #endif /* LDAP_CHARSET_8859 == LDAP_DEFAULT_CHARSET */
373 #endif /* STR_TRANSLATION && LDAP_DEFAULT_CHARSET */
377 #endif /* _LDAP_INT_H */