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