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