]> git.sur5r.net Git - openldap/blob - libraries/libldap/ldap-int.h
Import from devel
[openldap] / libraries / libldap / ldap-int.h
1 /*  ldap-int.h - defines & prototypes internal to the LDAP library */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7 /*  Portions
8  *  Copyright (c) 1995 Regents of the University of Michigan.
9  *  All rights reserved.
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 /* 
22  * Support needed if the library is running in the kernel
23  */
24 #if LDAP_INT_IN_KERNEL
25         /* 
26          * Platform specific function to return a pointer to the
27          * process-specific global options. 
28          *
29          * This function should perform the following functions:
30          *  Allocate and initialize a global options struct on a per process basis
31          *  Use callers process identifier to return its global options struct
32          *  Note: Deallocate structure when the process exits
33          */
34 #       define LDAP_INT_GLOBAL_OPT() ldap_int_global_opt()
35    struct ldapoptions *ldap_int_global_opt(void);
36 #else
37 #       define LDAP_INT_GLOBAL_OPT() (&ldap_int_global_options)
38 #endif
39
40 #define ldap_debug      ((LDAP_INT_GLOBAL_OPT())->ldo_debug)
41
42 #include "ldap_log.h"
43
44 #undef Debug
45 #define Debug( level, fmt, arg1, arg2, arg3 ) \
46         ldap_log_printf( NULL, (level), (fmt), (arg1), (arg2), (arg3) )
47
48 #include "ldap.h"
49
50 #include "ldap_pvt.h"
51
52 LDAP_BEGIN_DECL
53
54 #define LDAP_URL_PREFIX         "ldap://"
55 #define LDAP_URL_PREFIX_LEN     (sizeof(LDAP_URL_PREFIX)-1)
56 #define LDAPS_URL_PREFIX                "ldaps://"
57 #define LDAPS_URL_PREFIX_LEN    (sizeof(LDAPS_URL_PREFIX)-1)
58 #define LDAPI_URL_PREFIX        "ldapi://"
59 #define LDAPI_URL_PREFIX_LEN    (sizeof(LDAPI_URL_PREFIX)-1)
60 #define LDAP_URL_URLCOLON               "URL:"
61 #define LDAP_URL_URLCOLON_LEN   (sizeof(LDAP_URL_URLCOLON)-1)
62
63 #define CLDAP_URL_PREFIX         "cldap://"
64 #define CLDAP_URL_PREFIX_LEN     (sizeof(CLDAP_URL_PREFIX)-1)
65
66 #define LDAP_REF_STR            "Referral:\n"
67 #define LDAP_REF_STR_LEN        (sizeof(LDAP_REF_STR)-1)
68 #define LDAP_LDAP_REF_STR       LDAP_URL_PREFIX
69 #define LDAP_LDAP_REF_STR_LEN   LDAP_URL_PREFIX_LEN
70
71 #define LDAP_DEFAULT_REFHOPLIMIT 5
72
73 #define LDAP_BOOL_REFERRALS             0
74 #define LDAP_BOOL_RESTART               1
75 #define LDAP_BOOL_TLS                   3
76
77 #define LDAP_BOOLEANS   unsigned long
78 #define LDAP_BOOL(n)    (1 << (n))
79 #define LDAP_BOOL_GET(lo, bool) \
80         ((lo)->ldo_booleans & LDAP_BOOL(bool) ? -1 : 0)
81 #define LDAP_BOOL_SET(lo, bool) ((lo)->ldo_booleans |= LDAP_BOOL(bool))
82 #define LDAP_BOOL_CLR(lo, bool) ((lo)->ldo_booleans &= ~LDAP_BOOL(bool))
83 #define LDAP_BOOL_ZERO(lo) ((lo)->ldo_booleans = 0)
84
85 /*
86  * This structure represents both ldap messages and ldap responses.
87  * These are really the same, except in the case of search responses,
88  * where a response has multiple messages.
89  */
90
91 struct ldapmsg {
92         ber_int_t               lm_msgid;       /* the message id */
93         ber_tag_t               lm_msgtype;     /* the message type */
94         BerElement      *lm_ber;        /* the ber encoded message contents */
95         struct ldapmsg  *lm_chain;      /* for search - next msg in the resp */
96         struct ldapmsg  *lm_next;       /* next response */
97         time_t  lm_time;        /* used to maintain cache */
98 };
99
100 /*
101  * structure representing get/set'able options
102  * which have global defaults.
103  */
104 struct ldapoptions {
105         short ldo_valid;
106 #define LDAP_UNINITIALIZED      0x0
107 #define LDAP_INITIALIZED        0x1
108 #define LDAP_VALID_SESSION      0x2
109
110         int             ldo_debug;
111         /* per API call timeout */
112         struct timeval          *ldo_tm_api;
113         struct timeval          *ldo_tm_net;
114
115         ber_int_t               ldo_version;
116         ber_int_t               ldo_deref;
117         ber_int_t               ldo_timelimit;
118         ber_int_t               ldo_sizelimit;
119
120         LDAPURLDesc *ldo_defludp;
121         int             ldo_defport;
122         char*   ldo_defbase;
123         char*   ldo_defbinddn;  /* simple bind dn */
124
125 #ifdef LDAP_CONNECTIONLESS
126         int             ldo_cldaptries; /* connectionless search retry count */
127         int             ldo_cldaptimeout;/* time between retries */
128 #endif
129
130         int             ldo_refhoplimit;        /* limit on referral nesting */
131
132         /* LDAPv3 server and client controls */
133         LDAPControl     **ldo_sctrls;
134         LDAPControl **ldo_cctrls;
135
136         /* LDAP rebind callback function */
137         LDAP_REBIND_PROC                *ldo_rebindproc;
138
139 #ifdef HAVE_TLS
140         /* tls context */
141         void            *ldo_tls_ctx;
142         int             ldo_tls_mode;
143 #endif
144 #ifdef HAVE_CYRUS_SASL
145         sasl_ssf_t      ldo_sasl_minssf;
146         sasl_ssf_t      ldo_sasl_maxssf;
147 #endif
148         LDAP_BOOLEANS ldo_booleans;     /* boolean options */
149 };
150
151
152 /*
153  * structure for tracking LDAP server host, ports, DNs, etc.
154  */
155 typedef struct ldap_server {
156         char                    *lsrv_host;
157         char                    *lsrv_dn;       /* if NULL, use default */
158         int                     lsrv_port;
159         struct ldap_server      *lsrv_next;
160 } LDAPServer;
161
162
163 /*
164  * structure for representing an LDAP server connection
165  */
166 typedef struct ldap_conn {
167         Sockbuf                 *lconn_sb;
168         int                     lconn_refcnt;
169         time_t          lconn_lastused; /* time */
170         int                     lconn_rebind_inprogress;        /* set if rebind in progress */
171         char            ***lconn_rebind_queue;          /* used if rebind in progress */
172         int                     lconn_status;
173 #define LDAP_CONNST_NEEDSOCKET          1
174 #define LDAP_CONNST_CONNECTING          2
175 #define LDAP_CONNST_CONNECTED           3
176         LDAPURLDesc             *lconn_server;
177         char                    *lconn_krbinstance;
178         struct ldap_conn        *lconn_next;
179         BerElement              *lconn_ber;/* ber receiving on this conn. */
180 } LDAPConn;
181
182
183 /*
184  * structure used to track outstanding requests
185  */
186 typedef struct ldapreq {
187         ber_int_t               lr_msgid;       /* the message id */
188         int             lr_status;      /* status of request */
189 #define LDAP_REQST_COMPLETED    0
190 #define LDAP_REQST_INPROGRESS   1
191 #define LDAP_REQST_CHASINGREFS  2
192 #define LDAP_REQST_NOTCONNECTED 3
193 #define LDAP_REQST_WRITING      4
194         int             lr_outrefcnt;   /* count of outstanding referrals */
195         ber_int_t               lr_origid;      /* original request's message id */
196         int             lr_parentcnt;   /* count of parent requests */
197         ber_tag_t               lr_res_msgtype; /* result message type */
198         ber_int_t               lr_res_errno;   /* result LDAP errno */
199         char            *lr_res_error;  /* result error string */
200         char            *lr_res_matched;/* result matched DN string */
201         BerElement      *lr_ber;        /* ber encoded request contents */
202         LDAPConn        *lr_conn;       /* connection used to send request */
203         struct ldapreq  *lr_parent;     /* request that spawned this referral */
204         struct ldapreq  *lr_refnext;    /* next referral spawned */
205         struct ldapreq  *lr_prev;       /* previous request */
206         struct ldapreq  *lr_next;       /* next request */
207 } LDAPRequest;
208
209 /*
210  * structure for client cache
211  */
212 #define LDAP_CACHE_BUCKETS      31      /* cache hash table size */
213 typedef struct ldapcache {
214         LDAPMessage     *lc_buckets[LDAP_CACHE_BUCKETS];/* hash table */
215         LDAPMessage     *lc_requests;                   /* unfulfilled reqs */
216         long            lc_timeout;                     /* request timeout */
217         ber_len_t               lc_maxmem;                      /* memory to use */
218         ber_len_t               lc_memused;                     /* memory in use */
219         int             lc_enabled;                     /* enabled? */
220         unsigned long   lc_options;                     /* options */
221 #define LDAP_CACHE_OPT_CACHENOERRS      0x00000001
222 #define LDAP_CACHE_OPT_CACHEALLERRS     0x00000002
223 }  LDAPCache;
224
225 /*
226  * structure containing referral request info for rebind procedure
227  */
228 typedef struct ldapreqinfo {
229         ber_len_t       ri_msgid;
230         int                     ri_request;
231         char            *ri_url;
232 } LDAPreqinfo;
233
234 /*
235  * handy macro for checking if handle is connectionless
236  */
237
238 #define LDAP_IS_CLDAP(ld) ((ld)->ld_cldapnaddr>0)
239
240 /*
241  * structure representing an ldap connection
242  */
243
244 struct ldap {
245         Sockbuf         *ld_sb;         /* socket descriptor & buffer */
246
247         struct ldapoptions ld_options;
248
249 #define ld_valid                ld_options.ldo_valid
250 #define ld_debug                ld_options.ldo_debug
251
252 #define ld_deref                ld_options.ldo_deref
253 #define ld_timelimit    ld_options.ldo_timelimit
254 #define ld_sizelimit    ld_options.ldo_sizelimit
255
256 #define ld_defbinddn    ld_options.ldo_defbinddn
257 #define ld_defbase              ld_options.ldo_defbase
258 #define ld_defhost              ld_options.ldo_defhost
259 #define ld_defport              ld_options.ldo_defport
260
261 #define ld_cldaptries   ld_options.ldo_cldaptries
262 #define ld_cldaptimeout ld_options.ldo_cldaptimeout
263 #define ld_refhoplimit  ld_options.ldo_refhoplimit
264
265 #define ld_sctrls               ld_options.ldo_sctrls
266 #define ld_cctrls               ld_options.ldo_cctrls
267 #define ld_rebindproc   ld_options.ldo_rebindproc
268
269 #define ld_version              ld_options.ldo_version  
270         char    *ld_host;
271         int             ld_port;
272
273         unsigned short  ld_lberoptions;
274
275         LDAPFiltDesc    *ld_filtd;      /* from getfilter for ufn searches */
276         char            *ld_ufnprefix;  /* for incomplete ufn's */
277
278         ber_int_t       ld_errno;
279         char    *ld_error;
280         char    *ld_matched;
281         ber_len_t               ld_msgid;
282
283         /* do not mess with these */
284         LDAPRequest     *ld_requests;   /* list of outstanding requests */
285         LDAPMessage     *ld_responses;  /* list of outstanding responses */
286
287         ber_int_t               *ld_abandoned;  /* array of abandoned requests */
288
289         LDAPCache       *ld_cache;      /* non-null if cache is initialized */
290         /* stuff used by connectionless searches. */
291
292         char            *ld_cldapdn;    /* DN used in connectionless search */
293         int             ld_cldapnaddr; /* number of addresses */
294         void            **ld_cldapaddrs;/* addresses to send request to */
295
296         /* do not mess with the rest though */
297
298         LDAPConn        *ld_defconn;    /* default connection */
299         LDAPConn        *ld_conns;      /* list of server connections */
300         void            *ld_selectinfo; /* platform specifics for select */
301 #ifdef HAVE_CYRUS_SASL
302         sasl_conn_t             *ld_sasl_context;
303 #endif /* HAVE_CYRUS_SASL */
304 };
305 #define LDAP_VALID(ld)  ( (ld)->ld_valid == LDAP_VALID_SESSION )
306
307 #if defined(HAVE_RES_QUERY) && defined(LDAP_R_COMPILE)
308 #include <ldap_pvt_thread.h>
309 extern ldap_pvt_thread_mutex_t ldap_int_resolv_mutex;
310 #endif /* HAVE_RES_QUERY && LDAP_R_COMPILE */
311
312 /*
313  * in init.c
314  */
315
316 LDAP_F ( struct ldapoptions ) ldap_int_global_options;
317 LDAP_F ( void ) ldap_int_initialize LDAP_P((struct ldapoptions *, int *));
318 LDAP_F ( void ) ldap_int_initialize_global_options LDAP_P((
319         struct ldapoptions *, int *));
320
321 /* memory.c */
322         /* simple macros to realloc for now */
323 #define LDAP_INT_MALLOC(s)              (LBER_MALLOC((s)))
324 #define LDAP_INT_CALLOC(n,s)    (LBER_CALLOC((n),(s)))
325 #define LDAP_INT_REALLOC(p,s)   (LBER_REALLOC((p),(s)))
326 #define LDAP_INT_FREE(p)                (LBER_FREE((p)))
327 #define LDAP_INT_VFREE(v)               (LBER_VFREE((void **)(v)))
328 #define LDAP_INT_STRDUP(s)              (LBER_STRDUP((s)))
329
330 #define LDAP_MALLOC(s)          (LBER_MALLOC((s)))
331 #define LDAP_CALLOC(n,s)        (LBER_CALLOC((n),(s)))
332 #define LDAP_REALLOC(p,s)       (LBER_REALLOC((p),(s)))
333 #define LDAP_FREE(p)            (LBER_FREE((p)))
334 #define LDAP_VFREE(v)           (LBER_VFREE((void **)(v)))
335 #define LDAP_STRDUP(s)          (LBER_STRDUP((s)))
336
337 /*
338  * in unit-int.c
339  */
340 LDAP_F (void) ldap_int_utils_init LDAP_P(( void ));
341
342
343 /*
344  * in print.c
345  */
346 LDAP_F (int) ldap_log_printf LDAP_P((LDAP *ld, int level, const char *fmt, ...)) LDAP_GCCATTR((format(printf, 3, 4)));
347
348 /*
349  * in cache.c
350  */
351 LDAP_F (void) ldap_add_request_to_cache LDAP_P(( LDAP *ld, ber_tag_t msgtype,
352         BerElement *request ));
353 LDAP_F (void) ldap_add_result_to_cache LDAP_P(( LDAP *ld, LDAPMessage *result ));
354 LDAP_F (int) ldap_check_cache LDAP_P(( LDAP *ld, ber_tag_t msgtype, BerElement *request ));
355
356 /*
357  * in controls.c
358  */
359 LDAP_F (LDAPControl *) ldap_control_dup LDAP_P((
360         const LDAPControl *ctrl ));
361
362 LDAP_F (LDAPControl **) ldap_controls_dup LDAP_P((
363         LDAPControl *const *ctrls ));
364
365 LDAP_F (int) ldap_int_get_controls LDAP_P((
366         BerElement *be,
367         LDAPControl ***ctrlsp));
368
369 LDAP_F (int) ldap_int_put_controls LDAP_P((
370         LDAP *ld,
371         LDAPControl *const *ctrls,
372         BerElement *ber ));
373
374 LDAP_F( int ) 
375 ldap_int_create_control LDAP_P(( 
376         const char *requestOID, 
377         BerElement *ber, 
378         int iscritical,
379         LDAPControl **ctrlp ));
380
381 /*
382  * in dsparse.c
383  */
384 LDAP_F (int) ldap_int_next_line_tokens LDAP_P(( char **bufp, ber_len_t *blenp, char ***toksp ));
385
386 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
387 /*
388  * in kerberos.c
389  */
390 LDAP_F (char *) ldap_get_kerberosv4_credentials LDAP_P((
391         LDAP *ld,
392         LDAP_CONST char *who,
393         LDAP_CONST char *service,
394         ber_len_t *len ));
395
396 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND */
397
398
399 /*
400  * in open.c
401  */
402 LDAP_F (int) ldap_open_defconn( LDAP *ld );
403 LDAP_F (int) open_ldap_connection( LDAP *ld, Sockbuf *sb, LDAPURLDesc *srvlist, char **krbinstancep, int async );
404
405 /*
406  * in os-ip.c
407  */
408 LDAP_F (int) ldap_int_tblsize;
409 LDAP_F (int) ldap_int_timeval_dup( struct timeval **dest, const struct timeval *tm );
410 LDAP_F (int) ldap_connect_to_host( LDAP *ld, Sockbuf *sb, const char *host, unsigned long address, int port, int async );
411
412 #if defined(LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND) || defined(HAVE_TLS) || defined(HAVE_CYRUS_SASL)
413 LDAP_F (char *) ldap_host_connected_to( Sockbuf *sb );
414 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND */
415
416 LDAP_F (void) ldap_int_ip_init( void );
417 LDAP_F (int) do_ldap_select( LDAP *ld, struct timeval *timeout );
418 LDAP_F (void *) ldap_new_select_info( void );
419 LDAP_F (void) ldap_free_select_info( void *sip );
420 LDAP_F (void) ldap_mark_select_write( LDAP *ld, Sockbuf *sb );
421 LDAP_F (void) ldap_mark_select_read( LDAP *ld, Sockbuf *sb );
422 LDAP_F (void) ldap_mark_select_clear( LDAP *ld, Sockbuf *sb );
423 LDAP_F (int) ldap_is_read_ready( LDAP *ld, Sockbuf *sb );
424 LDAP_F (int) ldap_is_write_ready( LDAP *ld, Sockbuf *sb );
425
426 /*
427  * in os-local.c
428  */
429 #ifdef LDAP_PF_UNIX 
430 LDAP_F (int) ldap_connect_to_path( LDAP *ld, Sockbuf *sb, const char *path, int async );
431 #endif /* LDAP_PF_UNIX */
432
433 /*
434  * in request.c
435  */
436 LDAP_F (ber_int_t) ldap_send_initial_request( LDAP *ld, ber_tag_t msgtype,
437         const char *dn, BerElement *ber );
438 LDAP_F (BerElement *) ldap_alloc_ber_with_options( LDAP *ld );
439 LDAP_F (void) ldap_set_ber_options( LDAP *ld, BerElement *ber );
440
441 LDAP_F (int) ldap_send_server_request( LDAP *ld, BerElement *ber, ber_int_t msgid, LDAPRequest *parentreq, LDAPURLDesc *srvlist, LDAPConn *lc, LDAPreqinfo *bind );
442 LDAP_F (LDAPConn *) ldap_new_connection( LDAP *ld, LDAPURLDesc *srvlist, int use_ldsb, int connect, LDAPreqinfo *bind );
443 LDAP_F (LDAPRequest *) ldap_find_request_by_msgid( LDAP *ld, ber_int_t msgid );
444 LDAP_F (void) ldap_free_request( LDAP *ld, LDAPRequest *lr );
445 LDAP_F (void) ldap_free_connection( LDAP *ld, LDAPConn *lc, int force, int unbind );
446 LDAP_F (void) ldap_dump_connection( LDAP *ld, LDAPConn *lconns, int all );
447 LDAP_F (void) ldap_dump_requests_and_responses( LDAP *ld );
448 LDAP_F (int) ldap_chase_referrals( LDAP *ld, LDAPRequest *lr, char **errstrp, int *hadrefp );
449 LDAP_F (int) ldap_chase_v3referrals( LDAP *ld, LDAPRequest *lr, char **refs, char **referralsp, int *hadrefp );
450 LDAP_F (int) ldap_append_referral( LDAP *ld, char **referralsp, char *s );
451
452 /*
453  * in result.c:
454  */
455 #ifdef LDAP_CONNECTIONLESS
456 LDAP_F (int) cldap_getmsg( LDAP *ld, struct timeval *timeout, BerElement *ber );
457 #endif
458 LDAP_F (char *) ldap_int_msgtype2str( ber_tag_t tag );
459
460 /*
461  * in search.c
462  */
463 LDAP_F (BerElement *) ldap_build_search_req LDAP_P((
464         LDAP *ld,
465         const char *base,
466         ber_int_t scope,
467         const char *filter,
468         char **attrs,
469         ber_int_t attrsonly,
470         LDAPControl **sctrls,
471         LDAPControl **cctrls,
472         ber_int_t timelimit,
473         ber_int_t sizelimit ));
474
475 /*
476  * in string.c
477  */
478         /* see <ac/string.h> */
479
480 /*
481  * in unbind.c
482  */
483 LDAP_F (int) ldap_ld_free LDAP_P((
484         LDAP *ld,
485         int close,
486         LDAPControl **sctrls,
487         LDAPControl **cctrls ));
488
489 LDAP_F (int) ldap_send_unbind LDAP_P((
490         LDAP *ld,
491         Sockbuf *sb,
492         LDAPControl **sctrls,
493         LDAPControl **cctrls ));
494
495 /*
496  * in url.c
497  */
498 LDAP_F (LDAPURLDesc *) ldap_url_dup LDAP_P((
499         LDAPURLDesc *ludp ));
500
501 LDAP_F (LDAPURLDesc *) ldap_url_duplist LDAP_P((
502         LDAPURLDesc *ludlist ));
503
504 LDAP_F (int) ldap_url_parselist LDAP_P((
505         LDAPURLDesc **ludlist,
506         const char *url ));
507
508 LDAP_F (int) ldap_url_parsehosts LDAP_P((
509         LDAPURLDesc **ludlist,
510         const char *hosts ));
511
512 LDAP_F (char *) ldap_url_list2hosts LDAP_P((
513         LDAPURLDesc *ludlist ));
514
515 LDAP_F (char *) ldap_url_list2urls LDAP_P((
516         LDAPURLDesc *ludlist ));
517
518 LDAP_F (void) ldap_free_urllist LDAP_P((
519         LDAPURLDesc *ludlist ));
520
521
522 LDAP_END_DECL
523
524 #endif /* _LDAP_INT_H */