2 * Copyright (c) 1995 Regents of the University of Michigan.
5 * ldap-int.h - defines & prototypes internal to the LDAP library
11 #include "../liblber/lber-int.h"
17 #define LDAP_URL_PREFIX "ldap://"
18 #define LDAP_URL_PREFIX_LEN 7
19 #define LDAP_URL_URLCOLON "URL:"
20 #define LDAP_URL_URLCOLON_LEN 4
22 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
23 #define LDAP_REF_STR "Referral:\n"
24 #define LDAP_REF_STR_LEN 10
25 #define LDAP_LDAP_REF_STR LDAP_URL_PREFIX
26 #define LDAP_LDAP_REF_STR_LEN LDAP_URL_PREFIX_LEN
27 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
28 #define LDAP_DX_REF_STR "dx://"
29 #define LDAP_DX_REF_STR_LEN 5
30 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
31 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
33 #define LDAP_BOOL_REFERRALS 0
34 #define LDAP_BOOL_RESTART 1
35 #define LDAP_BOOL_DNS 2
37 #define LDAP_BOOLEANS unsigned long
38 #define LDAP_BOOL(n) (1 << (n))
39 #define LDAP_BOOL_GET(lo, bool) ((lo)->ldo_booleans & LDAP_BOOL(bool) \
40 ? LDAP_OPT_ON : LDAP_OPT_OFF)
41 #define LDAP_BOOL_SET(lo, bool) ((lo)->ldo_booleans |= LDAP_BOOL(bool))
42 #define LDAP_BOOL_CLR(lo, bool) ((lo)->ldo_booleans &= ~LDAP_BOOL(bool))
43 #define LDAP_BOOL_ZERO(lo) ((lo)->ldo_booleans = 0)
46 * This structure represents both ldap messages and ldap responses.
47 * These are really the same, except in the case of search responses,
48 * where a response has multiple messages.
52 int lm_msgid; /* the message id */
53 int lm_msgtype; /* the message type */
54 BerElement *lm_ber; /* the ber encoded message contents */
55 struct ldapmsg *lm_chain; /* for search - next msg in the resp */
56 struct ldapmsg *lm_next; /* next response */
57 unsigned int lm_time; /* used to maintain cache */
61 * structure representing get/set'able options
62 * which have global defaults.
65 int ldo_version; /* version to connect at */
74 int ldo_cldaptries; /* connectionless search retry count */
75 int ldo_cldaptimeout;/* time between retries */
76 int ldo_refhoplimit; /* limit on referral nesting */
78 LDAP_BOOLEANS ldo_booleans; /* boolean options */
82 * structure representing an ldap connection
86 Sockbuf ld_sb; /* socket descriptor & buffer */
88 struct ldapoptions ld_options;
90 #define ld_deref ld_options.ldo_deref
91 #define ld_timelimit ld_options.ldo_timelimit
92 #define ld_sizelimit ld_options.ldo_sizelimit
94 #define ld_defbase ld_options.ldo_defbase
95 #define ld_defhost ld_options.ldo_defhost
96 #define ld_defport ld_options.ldo_defport
98 #define ld_cldaptries ld_options.ldo_cldaptries
99 #define ld_cldaptimeout ld_options.ldo_cldaptimeout
100 #define ld_refhoplimit ld_options.ldo_refhoplimit
102 int ld_version; /* version connected at */
108 LDAPFiltDesc *ld_filtd; /* from getfilter for ufn searches */
109 char *ld_ufnprefix; /* for incomplete ufn's */
116 /* do not mess with these */
117 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
118 LDAPRequest *ld_requests; /* list of outstanding requests */
119 #else /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
120 LDAPMessage *ld_requests; /* list of outstanding requests */
121 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
122 LDAPMessage *ld_responses; /* list of outstanding responses */
123 int *ld_abandoned; /* array of abandoned requests */
124 char ld_attrbuffer[LDAP_MAX_ATTR_LEN];
125 LDAPCache *ld_cache; /* non-null if cache is initialized */
126 char *ld_cldapdn; /* DN used in connectionless search */
128 /* do not mess with the rest though */
129 BERTranslateProc ld_lber_encode_translate_proc;
130 BERTranslateProc ld_lber_decode_translate_proc;
132 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
133 LDAPConn *ld_defconn; /* default connection */
134 LDAPConn *ld_conns; /* list of server connections */
135 void *ld_selectinfo; /* platform specifics for select */
136 int (*ld_rebindproc)( struct ldap *ld, char **dnp,
137 char **passwdp, int *authmethodp, int freeit );
138 /* routine to get info needed for re-bind */
139 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
145 extern int openldap_ldap_initialized;
146 extern struct ldapoptions openldap_ldap_global_options;
147 void openldap_ldap_initialize LDAP_P((void));
152 void ldap_add_request_to_cache LDAP_P(( LDAP *ld, unsigned long msgtype,
153 BerElement *request ));
154 void ldap_add_result_to_cache LDAP_P(( LDAP *ld, LDAPMessage *result ));
155 int ldap_check_cache LDAP_P(( LDAP *ld, unsigned long msgtype, BerElement *request ));
160 int next_line_tokens LDAP_P(( char **bufp, long *blenp, char ***toksp ));
161 void free_strarray LDAP_P(( char **sap ));
167 char *ldap_get_kerberosv4_credentials LDAP_P(( LDAP *ld, char *who, char *service,
170 #endif /* HAVE_KERBEROS */
176 int open_ldap_connection( LDAP *ld, Sockbuf *sb, char *host, int defport,
177 char **krbinstancep, int async );
183 int ldap_connect_to_host( Sockbuf *sb, char *host, unsigned long address, int port,
185 void ldap_close_connection( Sockbuf *sb );
188 char *ldap_host_connected_to( Sockbuf *sb );
189 #endif /* HAVE_KERBEROS */
191 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
192 int do_ldap_select( LDAP *ld, struct timeval *timeout );
193 void *ldap_new_select_info( void );
194 void ldap_free_select_info( void *sip );
195 void ldap_mark_select_write( LDAP *ld, Sockbuf *sb );
196 void ldap_mark_select_read( LDAP *ld, Sockbuf *sb );
197 void ldap_mark_select_clear( LDAP *ld, Sockbuf *sb );
198 int ldap_is_read_ready( LDAP *ld, Sockbuf *sb );
199 int ldap_is_write_ready( LDAP *ld, Sockbuf *sb );
200 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
206 int ldap_send_initial_request( LDAP *ld, unsigned long msgtype,
207 char *dn, BerElement *ber );
208 BerElement *ldap_alloc_ber_with_options( LDAP *ld );
209 void ldap_set_ber_options( LDAP *ld, BerElement *ber );
211 #if defined( LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS ) || defined( LDAP_API_FEATURE_X_OPENLDAP_V2_DNS )
212 int ldap_send_server_request( LDAP *ld, BerElement *ber, int msgid,
213 LDAPRequest *parentreq, LDAPServer *srvlist, LDAPConn *lc,
215 LDAPConn *ldap_new_connection( LDAP *ld, LDAPServer **srvlistp, int use_ldsb,
216 int connect, int bind );
217 LDAPRequest *ldap_find_request_by_msgid( LDAP *ld, int msgid );
218 void ldap_free_request( LDAP *ld, LDAPRequest *lr );
219 void ldap_free_connection( LDAP *ld, LDAPConn *lc, int force, int unbind );
220 void ldap_dump_connection( LDAP *ld, LDAPConn *lconns, int all );
221 void ldap_dump_requests_and_responses( LDAP *ld );
222 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS || LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
224 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
225 int ldap_chase_referrals( LDAP *ld, LDAPRequest *lr, char **errstrp, int *hadrefp );
226 int ldap_append_referral( LDAP *ld, char **referralsp, char *s );
227 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
232 #ifdef LDAP_CONNECTIONLESS
233 LDAP_F int cldap_getmsg ( LDAP *ld, struct timeval *timeout, BerElement *ber );
239 BerElement *ldap_build_search_req( LDAP *ld, char *base, int scope,
240 char *filter, char **attrs, int attrsonly );
246 #define ldap_strdup(s) strdup(s)
247 extern char *strdup();
249 extern char *ldap_strdup LDAP_P(( const char * ));
255 int ldap_ld_free( LDAP *ld, int close );
256 int ldap_send_unbind( LDAP *ld, Sockbuf *sb );
258 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
262 char **ldap_getdxbyname( char *domain );
263 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
265 #if defined( STR_TRANSLATION ) && defined( LDAP_DEFAULT_CHARSET )
269 * added-in this stuff so that libldap.a would build, i.e. refs to
270 * these routines from open.c would resolve.
271 * hodges@stanford.edu 5-Feb-96
273 #if LDAP_CHARSET_8859 == LDAP_DEFAULT_CHARSET
275 int ldap_t61_to_8859( char **bufp, unsigned long *buflenp, int free_input );
277 int ldap_8859_to_t61( char **bufp, unsigned long *buflenp, int free_input );
278 #endif /* LDAP_CHARSET_8859 == LDAP_DEFAULT_CHARSET */
279 #endif /* STR_TRANSLATION && LDAP_DEFAULT_CHARSET */
283 #endif /* _LDAP_INT_H */