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
16 #define LDAP_THREAD_SAFE 1
19 #include "../liblber/lber-int.h"
21 #define ldap_debug (openldap_ldap_global_options.ldo_debug)
23 #define Debug( level, fmt, arg1, arg2, arg3 ) \
24 ldap_log_printf( NULL, (level), (fmt), (arg1), (arg2), (arg3) )
34 #define LDAP_URL_PREFIX "ldap://"
35 #define LDAP_URL_PREFIX_LEN 7
36 #define LDAP_URL_URLCOLON "URL:"
37 #define LDAP_URL_URLCOLON_LEN 4
39 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
40 #define LDAP_REF_STR "Referral:\n"
41 #define LDAP_REF_STR_LEN 10
42 #define LDAP_LDAP_REF_STR LDAP_URL_PREFIX
43 #define LDAP_LDAP_REF_STR_LEN LDAP_URL_PREFIX_LEN
44 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
45 #define LDAP_DX_REF_STR "dx://"
46 #define LDAP_DX_REF_STR_LEN 5
47 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
48 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
50 #define LDAP_BOOL_REFERRALS 0
51 #define LDAP_BOOL_RESTART 1
52 #define LDAP_BOOL_DNS 2
54 #define LDAP_BOOLEANS unsigned long
55 #define LDAP_BOOL(n) (1 << (n))
56 #define LDAP_BOOL_GET(lo, bool) ((lo)->ldo_booleans & LDAP_BOOL(bool) \
57 ? LDAP_OPT_ON : LDAP_OPT_OFF)
58 #define LDAP_BOOL_SET(lo, bool) ((lo)->ldo_booleans |= LDAP_BOOL(bool))
59 #define LDAP_BOOL_CLR(lo, bool) ((lo)->ldo_booleans &= ~LDAP_BOOL(bool))
60 #define LDAP_BOOL_ZERO(lo) ((lo)->ldo_booleans = 0)
63 * This structure represents both ldap messages and ldap responses.
64 * These are really the same, except in the case of search responses,
65 * where a response has multiple messages.
69 int lm_msgid; /* the message id */
70 int lm_msgtype; /* the message type */
71 BerElement *lm_ber; /* the ber encoded message contents */
72 struct ldapmsg *lm_chain; /* for search - next msg in the resp */
73 struct ldapmsg *lm_next; /* next response */
74 unsigned int lm_time; /* used to maintain cache */
78 * structure representing get/set'able options
79 * which have global defaults.
84 int ldo_version; /* version to connect at */
93 int ldo_cldaptries; /* connectionless search retry count */
94 int ldo_cldaptimeout;/* time between retries */
95 int ldo_refhoplimit; /* limit on referral nesting */
97 /* LDAPv3 server and client controls */
98 LDAPControl **ldo_server_controls;
99 LDAPControl **ldo_client_controls;
101 LDAP_BOOLEANS ldo_booleans; /* boolean options */
104 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
106 * structure for tracking LDAP server host, ports, DNs, etc.
108 typedef struct ldap_server {
110 char *lsrv_dn; /* if NULL, use default */
112 struct ldap_server *lsrv_next;
117 * structure for representing an LDAP server connection
119 typedef struct ldap_conn {
122 time_t lconn_lastused; /* time */
124 #define LDAP_CONNST_NEEDSOCKET 1
125 #define LDAP_CONNST_CONNECTING 2
126 #define LDAP_CONNST_CONNECTED 3
127 LDAPServer *lconn_server;
128 char *lconn_krbinstance;
129 struct ldap_conn *lconn_next;
134 * structure used to track outstanding requests
136 typedef struct ldapreq {
137 int lr_msgid; /* the message id */
138 int lr_status; /* status of request */
139 #define LDAP_REQST_INPROGRESS 1
140 #define LDAP_REQST_CHASINGREFS 2
141 #define LDAP_REQST_NOTCONNECTED 3
142 #define LDAP_REQST_WRITING 4
143 int lr_outrefcnt; /* count of outstanding referrals */
144 int lr_origid; /* original request's message id */
145 int lr_parentcnt; /* count of parent requests */
146 int lr_res_msgtype; /* result message type */
147 int lr_res_errno; /* result LDAP errno */
148 char *lr_res_error; /* result error string */
149 char *lr_res_matched;/* result matched DN string */
150 BerElement *lr_ber; /* ber encoded request contents */
151 LDAPConn *lr_conn; /* connection used to send request */
152 struct ldapreq *lr_parent; /* request that spawned this referral */
153 struct ldapreq *lr_refnext; /* next referral spawned */
154 struct ldapreq *lr_prev; /* previous request */
155 struct ldapreq *lr_next; /* next request */
157 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
160 * structure for client cache
162 #define LDAP_CACHE_BUCKETS 31 /* cache hash table size */
163 typedef struct ldapcache {
164 LDAPMessage *lc_buckets[LDAP_CACHE_BUCKETS];/* hash table */
165 LDAPMessage *lc_requests; /* unfulfilled reqs */
166 long lc_timeout; /* request timeout */
167 long lc_maxmem; /* memory to use */
168 long lc_memused; /* memory in use */
169 int lc_enabled; /* enabled? */
170 unsigned long lc_options; /* options */
171 #define LDAP_CACHE_OPT_CACHENOERRS 0x00000001
172 #define LDAP_CACHE_OPT_CACHEALLERRS 0x00000002
174 #define NULLLDCACHE ((LDAPCache *)NULL)
178 * structure representing an ldap connection
182 Sockbuf ld_sb; /* socket descriptor & buffer */
184 struct ldapoptions ld_options;
186 #define ld_deref ld_options.ldo_deref
187 #define ld_timelimit ld_options.ldo_timelimit
188 #define ld_sizelimit ld_options.ldo_sizelimit
190 #define ld_defbase ld_options.ldo_defbase
191 #define ld_defhost ld_options.ldo_defhost
192 #define ld_defport ld_options.ldo_defport
194 #define ld_cldaptries ld_options.ldo_cldaptries
195 #define ld_cldaptimeout ld_options.ldo_cldaptimeout
196 #define ld_refhoplimit ld_options.ldo_refhoplimit
198 int ld_version; /* version connected at */
204 LDAPFiltDesc *ld_filtd; /* from getfilter for ufn searches */
205 char *ld_ufnprefix; /* for incomplete ufn's */
212 /* do not mess with these */
213 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
214 LDAPRequest *ld_requests; /* list of outstanding requests */
215 #else /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
216 LDAPMessage *ld_requests; /* list of outstanding requests */
217 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
218 LDAPMessage *ld_responses; /* list of outstanding responses */
219 int *ld_abandoned; /* array of abandoned requests */
220 char ld_attrbuffer[LDAP_MAX_ATTR_LEN];
221 LDAPCache *ld_cache; /* non-null if cache is initialized */
222 char *ld_cldapdn; /* DN used in connectionless search */
224 /* do not mess with the rest though */
225 BERTranslateProc ld_lber_encode_translate_proc;
226 BERTranslateProc ld_lber_decode_translate_proc;
228 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
229 LDAPConn *ld_defconn; /* default connection */
230 LDAPConn *ld_conns; /* list of server connections */
231 void *ld_selectinfo; /* platform specifics for select */
232 int (*ld_rebindproc)( struct ldap *ld, char **dnp,
233 char **passwdp, int *authmethodp, int freeit );
234 /* routine to get info needed for re-bind */
235 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
241 extern int openldap_ldap_initialized;
242 extern struct ldapoptions openldap_ldap_global_options;
243 void openldap_ldap_initialize LDAP_P((void));
248 int ldap_log_printf LDAP_P((LDAP *ld, int level, char *fmt, ...));
253 void ldap_add_request_to_cache LDAP_P(( LDAP *ld, unsigned long msgtype,
254 BerElement *request ));
255 void ldap_add_result_to_cache LDAP_P(( LDAP *ld, LDAPMessage *result ));
256 int ldap_check_cache LDAP_P(( LDAP *ld, unsigned long msgtype, BerElement *request ));
261 LDAPControl *ldap_control_dup LDAP_P(( LDAPControl *ctrl ));
262 LDAPControl **ldap_controls_dup LDAP_P(( LDAPControl **ctrl ));
263 int ldap_get_ber_controls LDAP_P(( BerElement *be, LDAPControl ***cp));
268 int next_line_tokens LDAP_P(( char **bufp, long *blenp, char ***toksp ));
269 void free_strarray LDAP_P(( char **sap ));
275 char *ldap_get_kerberosv4_credentials LDAP_P(( LDAP *ld, char *who, char *service,
278 #endif /* HAVE_KERBEROS */
284 int open_ldap_connection( LDAP *ld, Sockbuf *sb, char *host, int defport,
285 char **krbinstancep, int async );
291 int ldap_connect_to_host( Sockbuf *sb, char *host, unsigned long address, int port,
293 void ldap_close_connection( Sockbuf *sb );
296 char *ldap_host_connected_to( Sockbuf *sb );
297 #endif /* HAVE_KERBEROS */
299 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
300 int do_ldap_select( LDAP *ld, struct timeval *timeout );
301 void *ldap_new_select_info( void );
302 void ldap_free_select_info( void *sip );
303 void ldap_mark_select_write( LDAP *ld, Sockbuf *sb );
304 void ldap_mark_select_read( LDAP *ld, Sockbuf *sb );
305 void ldap_mark_select_clear( LDAP *ld, Sockbuf *sb );
306 int ldap_is_read_ready( LDAP *ld, Sockbuf *sb );
307 int ldap_is_write_ready( LDAP *ld, Sockbuf *sb );
308 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
314 int ldap_send_initial_request( LDAP *ld, unsigned long msgtype,
315 char *dn, BerElement *ber );
316 BerElement *ldap_alloc_ber_with_options( LDAP *ld );
317 void ldap_set_ber_options( LDAP *ld, BerElement *ber );
319 #if defined( LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS ) || defined( LDAP_API_FEATURE_X_OPENLDAP_V2_DNS )
320 int ldap_send_server_request( LDAP *ld, BerElement *ber, int msgid,
321 LDAPRequest *parentreq, LDAPServer *srvlist, LDAPConn *lc,
323 LDAPConn *ldap_new_connection( LDAP *ld, LDAPServer **srvlistp, int use_ldsb,
324 int connect, int bind );
325 LDAPRequest *ldap_find_request_by_msgid( LDAP *ld, int msgid );
326 void ldap_free_request( LDAP *ld, LDAPRequest *lr );
327 void ldap_free_connection( LDAP *ld, LDAPConn *lc, int force, int unbind );
328 void ldap_dump_connection( LDAP *ld, LDAPConn *lconns, int all );
329 void ldap_dump_requests_and_responses( LDAP *ld );
330 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS || LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
332 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
333 int ldap_chase_referrals( LDAP *ld, LDAPRequest *lr, char **errstrp, int *hadrefp );
334 int ldap_append_referral( LDAP *ld, char **referralsp, char *s );
335 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
340 #ifdef LDAP_CONNECTIONLESS
341 LDAP_F int cldap_getmsg ( LDAP *ld, struct timeval *timeout, BerElement *ber );
347 BerElement *ldap_build_search_req( LDAP *ld, char *base, int scope,
348 char *filter, char **attrs, int attrsonly );
353 char *ldap_strdup LDAP_P(( const char * ));
358 int ldap_ld_free( LDAP *ld, int close );
359 int ldap_send_unbind( LDAP *ld, Sockbuf *sb );
361 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
365 char **ldap_getdxbyname( char *domain );
366 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
368 #if defined( STR_TRANSLATION ) && defined( LDAP_DEFAULT_CHARSET )
372 * added-in this stuff so that libldap.a would build, i.e. refs to
373 * these routines from open.c would resolve.
374 * hodges@stanford.edu 5-Feb-96
376 #if LDAP_CHARSET_8859 == LDAP_DEFAULT_CHARSET
378 int ldap_t61_to_8859( char **bufp, unsigned long *buflenp, int free_input );
380 int ldap_8859_to_t61( char **bufp, unsigned long *buflenp, int free_input );
381 #endif /* LDAP_CHARSET_8859 == LDAP_DEFAULT_CHARSET */
382 #endif /* STR_TRANSLATION && LDAP_DEFAULT_CHARSET */
386 #endif /* _LDAP_INT_H */