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