]> git.sur5r.net Git - openldap/blob - libraries/libldap/ldap-int.h
9fc14c3e67c3d1f0bcd90fc039a3ba1174255e5b
[openldap] / libraries / libldap / ldap-int.h
1 /*
2  *  Copyright (c) 1995 Regents of the University of Michigan.
3  *  All rights reserved.
4  *
5  *  ldap-int.h - defines & prototypes internal to the LDAP library
6  */
7
8 #ifndef _LDAP_INT_H
9 #define _LDAP_INT_H 1
10
11 #ifdef LDAP_COMPILING_R
12 #define LDAP_THREAD_SAFE 1
13 #endif
14
15 #include "../liblber/lber-int.h"
16
17 #define ldap_debug      (openldap_ldap_global_options.ldo_debug)
18
19 #include "ldap_log.h"
20
21 #include "ldap.h"
22
23 LDAP_BEGIN_DECL
24
25 #define LDAP_URL_PREFIX         "ldap://"
26 #define LDAP_URL_PREFIX_LEN     7
27 #define LDAP_URL_URLCOLON       "URL:"
28 #define LDAP_URL_URLCOLON_LEN   4
29
30 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
31 #define LDAP_REF_STR            "Referral:\n"
32 #define LDAP_REF_STR_LEN        10
33 #define LDAP_LDAP_REF_STR       LDAP_URL_PREFIX
34 #define LDAP_LDAP_REF_STR_LEN   LDAP_URL_PREFIX_LEN
35 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
36 #define LDAP_DX_REF_STR         "dx://"
37 #define LDAP_DX_REF_STR_LEN     5
38 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
39 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
40
41 #define LDAP_BOOL_REFERRALS             0
42 #define LDAP_BOOL_RESTART               1
43 #define LDAP_BOOL_DNS                   2
44
45 #define LDAP_BOOLEANS   unsigned long
46 #define LDAP_BOOL(n)    (1 << (n))
47 #define LDAP_BOOL_GET(lo, bool) ((lo)->ldo_booleans & LDAP_BOOL(bool) \
48                                                                         ?  LDAP_OPT_ON : LDAP_OPT_OFF)
49 #define LDAP_BOOL_SET(lo, bool) ((lo)->ldo_booleans |= LDAP_BOOL(bool))
50 #define LDAP_BOOL_CLR(lo, bool) ((lo)->ldo_booleans &= ~LDAP_BOOL(bool))
51 #define LDAP_BOOL_ZERO(lo) ((lo)->ldo_booleans = 0)
52
53 /*
54  * This structure represents both ldap messages and ldap responses.
55  * These are really the same, except in the case of search responses,
56  * where a response has multiple messages.
57  */
58
59 struct ldapmsg {
60         int             lm_msgid;       /* the message id */
61         int             lm_msgtype;     /* the message type */
62         BerElement      *lm_ber;        /* the ber encoded message contents */
63         struct ldapmsg  *lm_chain;      /* for search - next msg in the resp */
64         struct ldapmsg  *lm_next;       /* next response */
65         unsigned int    lm_time;        /* used to maintain cache */
66 };
67
68 /*
69  * structure representing get/set'able options
70  * which have global defaults.
71  */
72 struct ldapoptions {
73         int             ldo_version;    /* version to connect at */
74         int             ldo_deref;
75         int             ldo_timelimit;
76         int             ldo_sizelimit;
77
78         int             ldo_debug;
79
80         char*   ldo_defbase;
81         char*   ldo_defhost;
82         int             ldo_defport;
83
84         int             ldo_cldaptries; /* connectionless search retry count */
85         int             ldo_cldaptimeout;/* time between retries */
86         int             ldo_refhoplimit;        /* limit on referral nesting */
87
88         LDAP_BOOLEANS ldo_booleans;     /* boolean options */
89 };
90
91 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
92 /*
93  * structure for tracking LDAP server host, ports, DNs, etc.
94  */
95 typedef struct ldap_server {
96         char                    *lsrv_host;
97         char                    *lsrv_dn;       /* if NULL, use default */
98         int                     lsrv_port;
99         struct ldap_server      *lsrv_next;
100 } LDAPServer;
101
102
103 /*
104  * structure for representing an LDAP server connection
105  */
106 typedef struct ldap_conn {
107         Sockbuf                 *lconn_sb;
108         int                     lconn_refcnt;
109         time_t          lconn_lastused; /* time */
110         int                     lconn_status;
111 #define LDAP_CONNST_NEEDSOCKET          1
112 #define LDAP_CONNST_CONNECTING          2
113 #define LDAP_CONNST_CONNECTED           3
114         LDAPServer              *lconn_server;
115         char                    *lconn_krbinstance;
116         struct ldap_conn        *lconn_next;
117 } LDAPConn;
118
119
120 /*
121  * structure used to track outstanding requests
122  */
123 typedef struct ldapreq {
124         int             lr_msgid;       /* the message id */
125         int             lr_status;      /* status of request */
126 #define LDAP_REQST_INPROGRESS   1
127 #define LDAP_REQST_CHASINGREFS  2
128 #define LDAP_REQST_NOTCONNECTED 3
129 #define LDAP_REQST_WRITING      4
130         int             lr_outrefcnt;   /* count of outstanding referrals */
131         int             lr_origid;      /* original request's message id */
132         int             lr_parentcnt;   /* count of parent requests */
133         int             lr_res_msgtype; /* result message type */
134         int             lr_res_errno;   /* result LDAP errno */
135         char            *lr_res_error;  /* result error string */
136         char            *lr_res_matched;/* result matched DN string */
137         BerElement      *lr_ber;        /* ber encoded request contents */
138         LDAPConn        *lr_conn;       /* connection used to send request */
139         struct ldapreq  *lr_parent;     /* request that spawned this referral */
140         struct ldapreq  *lr_refnext;    /* next referral spawned */
141         struct ldapreq  *lr_prev;       /* previous request */
142         struct ldapreq  *lr_next;       /* next request */
143 } LDAPRequest;
144 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
145
146 /*
147  * structure for client cache
148  */
149 #define LDAP_CACHE_BUCKETS      31      /* cache hash table size */
150 typedef struct ldapcache {
151         LDAPMessage     *lc_buckets[LDAP_CACHE_BUCKETS];/* hash table */
152         LDAPMessage     *lc_requests;                   /* unfulfilled reqs */
153         long            lc_timeout;                     /* request timeout */
154         long            lc_maxmem;                      /* memory to use */
155         long            lc_memused;                     /* memory in use */
156         int             lc_enabled;                     /* enabled? */
157         unsigned long   lc_options;                     /* options */
158 #define LDAP_CACHE_OPT_CACHENOERRS      0x00000001
159 #define LDAP_CACHE_OPT_CACHEALLERRS     0x00000002
160 }  LDAPCache;
161 #define NULLLDCACHE ((LDAPCache *)NULL)
162
163
164 /*
165  * structure representing an ldap connection
166  */
167
168 struct ldap {
169         Sockbuf         ld_sb;          /* socket descriptor & buffer */
170
171         struct ldapoptions ld_options;
172
173 #define ld_deref                ld_options.ldo_deref
174 #define ld_timelimit    ld_options.ldo_timelimit
175 #define ld_sizelimit    ld_options.ldo_sizelimit
176
177 #define ld_defbase              ld_options.ldo_defbase
178 #define ld_defhost              ld_options.ldo_defhost
179 #define ld_defport              ld_options.ldo_defport
180
181 #define ld_cldaptries   ld_options.ldo_cldaptries
182 #define ld_cldaptimeout ld_options.ldo_cldaptimeout
183 #define ld_refhoplimit  ld_options.ldo_refhoplimit
184
185         int             ld_version;             /* version connected at */
186         char    *ld_host;
187         int             ld_port;
188
189         char    ld_lberoptions;
190
191         LDAPFiltDesc    *ld_filtd;      /* from getfilter for ufn searches */
192         char            *ld_ufnprefix;  /* for incomplete ufn's */
193
194         int             ld_errno;
195         char    *ld_error;
196         char    *ld_matched;
197         int             ld_msgid;
198
199         /* do not mess with these */
200 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
201         LDAPRequest     *ld_requests;   /* list of outstanding requests */
202 #else /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
203         LDAPMessage     *ld_requests;   /* list of outstanding requests */
204 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
205         LDAPMessage     *ld_responses;  /* list of outstanding responses */
206         int             *ld_abandoned;  /* array of abandoned requests */
207         char            ld_attrbuffer[LDAP_MAX_ATTR_LEN];
208         LDAPCache       *ld_cache;      /* non-null if cache is initialized */
209         char            *ld_cldapdn;    /* DN used in connectionless search */
210
211         /* do not mess with the rest though */
212         BERTranslateProc ld_lber_encode_translate_proc;
213         BERTranslateProc ld_lber_decode_translate_proc;
214
215 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
216         LDAPConn        *ld_defconn;    /* default connection */
217         LDAPConn        *ld_conns;      /* list of server connections */
218         void            *ld_selectinfo; /* platform specifics for select */
219         int             (*ld_rebindproc)( struct ldap *ld, char **dnp,
220                                 char **passwdp, int *authmethodp, int freeit );
221                                 /* routine to get info needed for re-bind */
222 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
223 };
224
225 /*
226  * in init.c
227  */
228 extern int openldap_ldap_initialized;
229 extern struct ldapoptions openldap_ldap_global_options;
230 void openldap_ldap_initialize LDAP_P((void));
231
232 /*
233  * in cache.c
234  */
235 void ldap_add_request_to_cache LDAP_P(( LDAP *ld, unsigned long msgtype,
236         BerElement *request ));
237 void ldap_add_result_to_cache LDAP_P(( LDAP *ld, LDAPMessage *result ));
238 int ldap_check_cache LDAP_P(( LDAP *ld, unsigned long msgtype, BerElement *request ));
239
240 /*
241  * in dsparse.c
242  */
243 int next_line_tokens LDAP_P(( char **bufp, long *blenp, char ***toksp ));
244 void free_strarray LDAP_P(( char **sap ));
245
246 #ifdef HAVE_KERBEROS
247 /*
248  * in kerberos.c
249  */
250 char *ldap_get_kerberosv4_credentials LDAP_P(( LDAP *ld, char *who, char *service,
251         int *len ));
252
253 #endif /* HAVE_KERBEROS */
254
255
256 /*
257  * in open.c
258  */
259 int open_ldap_connection( LDAP *ld, Sockbuf *sb, char *host, int defport,
260         char **krbinstancep, int async );
261
262
263 /*
264  * in os-ip.c
265  */
266 int ldap_connect_to_host( Sockbuf *sb, char *host, unsigned long address, int port,
267         int async );
268 void ldap_close_connection( Sockbuf *sb );
269
270 #ifdef HAVE_KERBEROS
271 char *ldap_host_connected_to( Sockbuf *sb );
272 #endif /* HAVE_KERBEROS */
273
274 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
275 int do_ldap_select( LDAP *ld, struct timeval *timeout );
276 void *ldap_new_select_info( void );
277 void ldap_free_select_info( void *sip );
278 void ldap_mark_select_write( LDAP *ld, Sockbuf *sb );
279 void ldap_mark_select_read( LDAP *ld, Sockbuf *sb );
280 void ldap_mark_select_clear( LDAP *ld, Sockbuf *sb );
281 int ldap_is_read_ready( LDAP *ld, Sockbuf *sb );
282 int ldap_is_write_ready( LDAP *ld, Sockbuf *sb );
283 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
284
285
286 /*
287  * in request.c
288  */
289 int ldap_send_initial_request( LDAP *ld, unsigned long msgtype,
290         char *dn, BerElement *ber );
291 BerElement *ldap_alloc_ber_with_options( LDAP *ld );
292 void ldap_set_ber_options( LDAP *ld, BerElement *ber );
293
294 #if defined( LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS ) || defined( LDAP_API_FEATURE_X_OPENLDAP_V2_DNS )
295 int ldap_send_server_request( LDAP *ld, BerElement *ber, int msgid,
296         LDAPRequest *parentreq, LDAPServer *srvlist, LDAPConn *lc,
297         int bind );
298 LDAPConn *ldap_new_connection( LDAP *ld, LDAPServer **srvlistp, int use_ldsb,
299         int connect, int bind );
300 LDAPRequest *ldap_find_request_by_msgid( LDAP *ld, int msgid );
301 void ldap_free_request( LDAP *ld, LDAPRequest *lr );
302 void ldap_free_connection( LDAP *ld, LDAPConn *lc, int force, int unbind );
303 void ldap_dump_connection( LDAP *ld, LDAPConn *lconns, int all );
304 void ldap_dump_requests_and_responses( LDAP *ld );
305 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS || LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
306
307 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
308 int ldap_chase_referrals( LDAP *ld, LDAPRequest *lr, char **errstrp, int *hadrefp );
309 int ldap_append_referral( LDAP *ld, char **referralsp, char *s );
310 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
311
312 /*
313  * in result.c:
314  */
315 #ifdef LDAP_CONNECTIONLESS
316 LDAP_F int cldap_getmsg ( LDAP *ld, struct timeval *timeout, BerElement *ber );
317 #endif
318
319 /*
320  * in search.c
321  */
322 BerElement *ldap_build_search_req( LDAP *ld, char *base, int scope,
323         char *filter, char **attrs, int attrsonly );
324
325 /*
326  * in strdup.c
327  */
328 char *ldap_strdup LDAP_P(( const char * ));
329
330 /*
331  * in unbind.c
332  */
333 int ldap_ld_free( LDAP *ld, int close );
334 int ldap_send_unbind( LDAP *ld, Sockbuf *sb );
335
336 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
337 /*
338  * in getdxbyname.c
339  */
340 char **ldap_getdxbyname( char *domain );
341 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
342
343 #if defined( STR_TRANSLATION ) && defined( LDAP_DEFAULT_CHARSET )
344 /*
345  * in charset.c
346  *
347  * added-in this stuff so that libldap.a would build, i.e. refs to 
348  * these routines from open.c would resolve. 
349  * hodges@stanford.edu 5-Feb-96
350  */
351 #if LDAP_CHARSET_8859 == LDAP_DEFAULT_CHARSET
352 extern 
353 int ldap_t61_to_8859( char **bufp, unsigned long *buflenp, int free_input );
354 extern 
355 int ldap_8859_to_t61( char **bufp, unsigned long *buflenp, int free_input );
356 #endif /* LDAP_CHARSET_8859 == LDAP_DEFAULT_CHARSET */
357 #endif /* STR_TRANSLATION && LDAP_DEFAULT_CHARSET */
358
359 /*
360  * in util_r.c
361  * 
362  */
363
364 struct hostent; /* avoid pulling in <netdb.h> */
365
366 extern char *ldap_int_strtok( char *str, const char *delim, char **pos );
367 extern char *ldap_int_ctime( const time_t *tp, char *buf );
368 extern int ldap_int_gethostbyname_a(
369         const char *name, 
370         struct hostent *resbuf,
371         char **buf,
372         struct hostent **result,
373         int *herrno_ptr );
374 extern int ldap_int_gethostbyaddr_a(
375         const char *addr,
376         int len,
377         int type,
378         struct hostent *resbuf,
379         char **buf,
380         struct hostent **result,
381         int *herrno_ptr );
382
383 LDAP_END_DECL
384
385 #endif /* _LDAP_INT_H */