]> git.sur5r.net Git - openldap/blob - libraries/libldap/ldap-int.h
d9c77df4254c6c0e6e7367a95a7b951d9031ad9b
[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         int             ldo_defport;
81         char*   ldo_defbase;
82         char*   ldo_defhost;
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         /* LDAPv3 server and client controls */
89         LDAPControl     **ldo_server_controls;
90         LDAPControl **ldo_client_controls;
91         
92         LDAP_BOOLEANS ldo_booleans;     /* boolean options */
93 };
94
95 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
96 /*
97  * structure for tracking LDAP server host, ports, DNs, etc.
98  */
99 typedef struct ldap_server {
100         char                    *lsrv_host;
101         char                    *lsrv_dn;       /* if NULL, use default */
102         int                     lsrv_port;
103         struct ldap_server      *lsrv_next;
104 } LDAPServer;
105
106
107 /*
108  * structure for representing an LDAP server connection
109  */
110 typedef struct ldap_conn {
111         Sockbuf                 *lconn_sb;
112         int                     lconn_refcnt;
113         time_t          lconn_lastused; /* time */
114         int                     lconn_status;
115 #define LDAP_CONNST_NEEDSOCKET          1
116 #define LDAP_CONNST_CONNECTING          2
117 #define LDAP_CONNST_CONNECTED           3
118         LDAPServer              *lconn_server;
119         char                    *lconn_krbinstance;
120         struct ldap_conn        *lconn_next;
121 } LDAPConn;
122
123
124 /*
125  * structure used to track outstanding requests
126  */
127 typedef struct ldapreq {
128         int             lr_msgid;       /* the message id */
129         int             lr_status;      /* status of request */
130 #define LDAP_REQST_INPROGRESS   1
131 #define LDAP_REQST_CHASINGREFS  2
132 #define LDAP_REQST_NOTCONNECTED 3
133 #define LDAP_REQST_WRITING      4
134         int             lr_outrefcnt;   /* count of outstanding referrals */
135         int             lr_origid;      /* original request's message id */
136         int             lr_parentcnt;   /* count of parent requests */
137         int             lr_res_msgtype; /* result message type */
138         int             lr_res_errno;   /* result LDAP errno */
139         char            *lr_res_error;  /* result error string */
140         char            *lr_res_matched;/* result matched DN string */
141         BerElement      *lr_ber;        /* ber encoded request contents */
142         LDAPConn        *lr_conn;       /* connection used to send request */
143         struct ldapreq  *lr_parent;     /* request that spawned this referral */
144         struct ldapreq  *lr_refnext;    /* next referral spawned */
145         struct ldapreq  *lr_prev;       /* previous request */
146         struct ldapreq  *lr_next;       /* next request */
147 } LDAPRequest;
148 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
149
150 /*
151  * structure for client cache
152  */
153 #define LDAP_CACHE_BUCKETS      31      /* cache hash table size */
154 typedef struct ldapcache {
155         LDAPMessage     *lc_buckets[LDAP_CACHE_BUCKETS];/* hash table */
156         LDAPMessage     *lc_requests;                   /* unfulfilled reqs */
157         long            lc_timeout;                     /* request timeout */
158         long            lc_maxmem;                      /* memory to use */
159         long            lc_memused;                     /* memory in use */
160         int             lc_enabled;                     /* enabled? */
161         unsigned long   lc_options;                     /* options */
162 #define LDAP_CACHE_OPT_CACHENOERRS      0x00000001
163 #define LDAP_CACHE_OPT_CACHEALLERRS     0x00000002
164 }  LDAPCache;
165 #define NULLLDCACHE ((LDAPCache *)NULL)
166
167
168 /*
169  * structure representing an ldap connection
170  */
171
172 struct ldap {
173         Sockbuf         ld_sb;          /* socket descriptor & buffer */
174
175         struct ldapoptions ld_options;
176
177 #define ld_deref                ld_options.ldo_deref
178 #define ld_timelimit    ld_options.ldo_timelimit
179 #define ld_sizelimit    ld_options.ldo_sizelimit
180
181 #define ld_defbase              ld_options.ldo_defbase
182 #define ld_defhost              ld_options.ldo_defhost
183 #define ld_defport              ld_options.ldo_defport
184
185 #define ld_cldaptries   ld_options.ldo_cldaptries
186 #define ld_cldaptimeout ld_options.ldo_cldaptimeout
187 #define ld_refhoplimit  ld_options.ldo_refhoplimit
188
189         int             ld_version;             /* version connected at */
190         char    *ld_host;
191         int             ld_port;
192
193         char    ld_lberoptions;
194
195         LDAPFiltDesc    *ld_filtd;      /* from getfilter for ufn searches */
196         char            *ld_ufnprefix;  /* for incomplete ufn's */
197
198         int             ld_errno;
199         char    *ld_error;
200         char    *ld_matched;
201         int             ld_msgid;
202
203         /* do not mess with these */
204 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
205         LDAPRequest     *ld_requests;   /* list of outstanding requests */
206 #else /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
207         LDAPMessage     *ld_requests;   /* list of outstanding requests */
208 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
209         LDAPMessage     *ld_responses;  /* list of outstanding responses */
210         int             *ld_abandoned;  /* array of abandoned requests */
211         char            ld_attrbuffer[LDAP_MAX_ATTR_LEN];
212         LDAPCache       *ld_cache;      /* non-null if cache is initialized */
213         char            *ld_cldapdn;    /* DN used in connectionless search */
214
215         /* do not mess with the rest though */
216         BERTranslateProc ld_lber_encode_translate_proc;
217         BERTranslateProc ld_lber_decode_translate_proc;
218
219 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
220         LDAPConn        *ld_defconn;    /* default connection */
221         LDAPConn        *ld_conns;      /* list of server connections */
222         void            *ld_selectinfo; /* platform specifics for select */
223         int             (*ld_rebindproc)( struct ldap *ld, char **dnp,
224                                 char **passwdp, int *authmethodp, int freeit );
225                                 /* routine to get info needed for re-bind */
226 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
227 };
228
229 /*
230  * in init.c
231  */
232 extern int openldap_ldap_initialized;
233 extern struct ldapoptions openldap_ldap_global_options;
234 void openldap_ldap_initialize LDAP_P((void));
235
236 /*
237  * in cache.c
238  */
239 void ldap_add_request_to_cache LDAP_P(( LDAP *ld, unsigned long msgtype,
240         BerElement *request ));
241 void ldap_add_result_to_cache LDAP_P(( LDAP *ld, LDAPMessage *result ));
242 int ldap_check_cache LDAP_P(( LDAP *ld, unsigned long msgtype, BerElement *request ));
243
244 /*
245  * in controls.c
246  */
247 LDAPControl *ldap_control_dup LDAP_P(( LDAPControl *ctrl ));
248 LDAPControl **ldap_controls_dup LDAP_P(( LDAPControl **ctrl ));
249
250 /*
251  * in dsparse.c
252  */
253 int next_line_tokens LDAP_P(( char **bufp, long *blenp, char ***toksp ));
254 void free_strarray LDAP_P(( char **sap ));
255
256 #ifdef HAVE_KERBEROS
257 /*
258  * in kerberos.c
259  */
260 char *ldap_get_kerberosv4_credentials LDAP_P(( LDAP *ld, char *who, char *service,
261         int *len ));
262
263 #endif /* HAVE_KERBEROS */
264
265
266 /*
267  * in open.c
268  */
269 int open_ldap_connection( LDAP *ld, Sockbuf *sb, char *host, int defport,
270         char **krbinstancep, int async );
271
272
273 /*
274  * in os-ip.c
275  */
276 int ldap_connect_to_host( Sockbuf *sb, char *host, unsigned long address, int port,
277         int async );
278 void ldap_close_connection( Sockbuf *sb );
279
280 #ifdef HAVE_KERBEROS
281 char *ldap_host_connected_to( Sockbuf *sb );
282 #endif /* HAVE_KERBEROS */
283
284 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
285 int do_ldap_select( LDAP *ld, struct timeval *timeout );
286 void *ldap_new_select_info( void );
287 void ldap_free_select_info( void *sip );
288 void ldap_mark_select_write( LDAP *ld, Sockbuf *sb );
289 void ldap_mark_select_read( LDAP *ld, Sockbuf *sb );
290 void ldap_mark_select_clear( LDAP *ld, Sockbuf *sb );
291 int ldap_is_read_ready( LDAP *ld, Sockbuf *sb );
292 int ldap_is_write_ready( LDAP *ld, Sockbuf *sb );
293 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
294
295
296 /*
297  * in request.c
298  */
299 int ldap_send_initial_request( LDAP *ld, unsigned long msgtype,
300         char *dn, BerElement *ber );
301 BerElement *ldap_alloc_ber_with_options( LDAP *ld );
302 void ldap_set_ber_options( LDAP *ld, BerElement *ber );
303
304 #if defined( LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS ) || defined( LDAP_API_FEATURE_X_OPENLDAP_V2_DNS )
305 int ldap_send_server_request( LDAP *ld, BerElement *ber, int msgid,
306         LDAPRequest *parentreq, LDAPServer *srvlist, LDAPConn *lc,
307         int bind );
308 LDAPConn *ldap_new_connection( LDAP *ld, LDAPServer **srvlistp, int use_ldsb,
309         int connect, int bind );
310 LDAPRequest *ldap_find_request_by_msgid( LDAP *ld, int msgid );
311 void ldap_free_request( LDAP *ld, LDAPRequest *lr );
312 void ldap_free_connection( LDAP *ld, LDAPConn *lc, int force, int unbind );
313 void ldap_dump_connection( LDAP *ld, LDAPConn *lconns, int all );
314 void ldap_dump_requests_and_responses( LDAP *ld );
315 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS || LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
316
317 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
318 int ldap_chase_referrals( LDAP *ld, LDAPRequest *lr, char **errstrp, int *hadrefp );
319 int ldap_append_referral( LDAP *ld, char **referralsp, char *s );
320 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
321
322 /*
323  * in result.c:
324  */
325 #ifdef LDAP_CONNECTIONLESS
326 LDAP_F int cldap_getmsg ( LDAP *ld, struct timeval *timeout, BerElement *ber );
327 #endif
328
329 /*
330  * in search.c
331  */
332 BerElement *ldap_build_search_req( LDAP *ld, char *base, int scope,
333         char *filter, char **attrs, int attrsonly );
334
335 /*
336  * in strdup.c
337  */
338 char *ldap_strdup LDAP_P(( const char * ));
339
340 /*
341  * in unbind.c
342  */
343 int ldap_ld_free( LDAP *ld, int close );
344 int ldap_send_unbind( LDAP *ld, Sockbuf *sb );
345
346 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
347 /*
348  * in getdxbyname.c
349  */
350 char **ldap_getdxbyname( char *domain );
351 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
352
353 #if defined( STR_TRANSLATION ) && defined( LDAP_DEFAULT_CHARSET )
354 /*
355  * in charset.c
356  *
357  * added-in this stuff so that libldap.a would build, i.e. refs to 
358  * these routines from open.c would resolve. 
359  * hodges@stanford.edu 5-Feb-96
360  */
361 #if LDAP_CHARSET_8859 == LDAP_DEFAULT_CHARSET
362 extern 
363 int ldap_t61_to_8859( char **bufp, unsigned long *buflenp, int free_input );
364 extern 
365 int ldap_8859_to_t61( char **bufp, unsigned long *buflenp, int free_input );
366 #endif /* LDAP_CHARSET_8859 == LDAP_DEFAULT_CHARSET */
367 #endif /* STR_TRANSLATION && LDAP_DEFAULT_CHARSET */
368
369 /*
370  * in util_r.c
371  * 
372  */
373
374 struct hostent; /* avoid pulling in <netdb.h> */
375
376 extern char *ldap_int_strtok( char *str, const char *delim, char **pos );
377 extern char *ldap_int_ctime( const time_t *tp, char *buf );
378 extern int ldap_int_gethostbyname_a(
379         const char *name, 
380         struct hostent *resbuf,
381         char **buf,
382         struct hostent **result,
383         int *herrno_ptr );
384 extern int ldap_int_gethostbyaddr_a(
385         const char *addr,
386         int len,
387         int type,
388         struct hostent *resbuf,
389         char **buf,
390         struct hostent **result,
391         int *herrno_ptr );
392
393 LDAP_END_DECL
394
395 #endif /* _LDAP_INT_H */