]> git.sur5r.net Git - openldap/blob - libraries/libldap/ldap-int.h
Remove lint
[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 #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;
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 #ifdef HAVE_CYRUS_SASL
129         sasl_ssf_t      ldo_sasl_minssf;
130         sasl_ssf_t      ldo_sasl_maxssf;
131 #endif
132         LDAP_BOOLEANS ldo_booleans;     /* boolean options */
133 };
134
135
136 /*
137  * structure for tracking LDAP server host, ports, DNs, etc.
138  */
139 typedef struct ldap_server {
140         char                    *lsrv_host;
141         char                    *lsrv_dn;       /* if NULL, use default */
142         int                     lsrv_port;
143 /*      int                     lsrv_protocol; */
144         struct ldap_server      *lsrv_next;
145 } LDAPServer;
146
147
148 /*
149  * structure for representing an LDAP server connection
150  */
151 typedef struct ldap_conn {
152         Sockbuf                 *lconn_sb;
153         int                     lconn_refcnt;
154         time_t          lconn_lastused; /* time */
155         int                     lconn_status;
156 #define LDAP_CONNST_NEEDSOCKET          1
157 #define LDAP_CONNST_CONNECTING          2
158 #define LDAP_CONNST_CONNECTED           3
159         LDAPURLDesc             *lconn_server;
160         char                    *lconn_krbinstance;
161         struct ldap_conn        *lconn_next;
162         BerElement              *lconn_ber;/* ber receiving on this conn. */
163 } LDAPConn;
164
165
166 /*
167  * structure used to track outstanding requests
168  */
169 typedef struct ldapreq {
170         ber_int_t               lr_msgid;       /* the message id */
171         int             lr_status;      /* status of request */
172 #define LDAP_REQST_INPROGRESS   1
173 #define LDAP_REQST_CHASINGREFS  2
174 #define LDAP_REQST_NOTCONNECTED 3
175 #define LDAP_REQST_WRITING      4
176         int             lr_outrefcnt;   /* count of outstanding referrals */
177         ber_int_t               lr_origid;      /* original request's message id */
178         int             lr_parentcnt;   /* count of parent requests */
179         ber_tag_t               lr_res_msgtype; /* result message type */
180         ber_int_t               lr_res_errno;   /* result LDAP errno */
181         char            *lr_res_error;  /* result error string */
182         char            *lr_res_matched;/* result matched DN string */
183         BerElement      *lr_ber;        /* ber encoded request contents */
184         LDAPConn        *lr_conn;       /* connection used to send request */
185         struct ldapreq  *lr_parent;     /* request that spawned this referral */
186         struct ldapreq  *lr_refnext;    /* next referral spawned */
187         struct ldapreq  *lr_prev;       /* previous request */
188         struct ldapreq  *lr_next;       /* next request */
189 } LDAPRequest;
190
191 /*
192  * structure for client cache
193  */
194 #define LDAP_CACHE_BUCKETS      31      /* cache hash table size */
195 typedef struct ldapcache {
196         LDAPMessage     *lc_buckets[LDAP_CACHE_BUCKETS];/* hash table */
197         LDAPMessage     *lc_requests;                   /* unfulfilled reqs */
198         long            lc_timeout;                     /* request timeout */
199         ber_len_t               lc_maxmem;                      /* memory to use */
200         ber_len_t               lc_memused;                     /* memory in use */
201         int             lc_enabled;                     /* enabled? */
202         unsigned long   lc_options;                     /* options */
203 #define LDAP_CACHE_OPT_CACHENOERRS      0x00000001
204 #define LDAP_CACHE_OPT_CACHEALLERRS     0x00000002
205 }  LDAPCache;
206
207 /*
208  * handy macro for checking if handle is connectionless
209  */
210
211 #define LDAP_IS_CLDAP(ld) ((ld)->ld_cldapnaddr>0)
212
213 /*
214  * structure representing an ldap connection
215  */
216
217 struct ldap {
218         Sockbuf         ld_sb;          /* socket descriptor & buffer */
219
220         struct ldapoptions ld_options;
221
222 #define ld_valid                ld_options.ldo_valid
223 #define ld_debug                ld_options.ldo_debug
224
225 #define ld_deref                ld_options.ldo_deref
226 #define ld_timelimit    ld_options.ldo_timelimit
227 #define ld_sizelimit    ld_options.ldo_sizelimit
228
229 #define ld_defbinddn    ld_options.ldo_defbinddn
230 #define ld_defbase              ld_options.ldo_defbase
231 #define ld_defhost              ld_options.ldo_defhost
232 #define ld_defport              ld_options.ldo_defport
233
234 #define ld_cldaptries   ld_options.ldo_cldaptries
235 #define ld_cldaptimeout ld_options.ldo_cldaptimeout
236 #define ld_refhoplimit  ld_options.ldo_refhoplimit
237
238 #define ld_sctrls               ld_options.ldo_sctrls
239 #define ld_cctrls               ld_options.ldo_cctrls
240
241 #define ld_version              ld_options.ldo_version  
242         char    *ld_host;
243         int             ld_port;
244
245         unsigned short  ld_lberoptions;
246
247         LDAPFiltDesc    *ld_filtd;      /* from getfilter for ufn searches */
248         char            *ld_ufnprefix;  /* for incomplete ufn's */
249
250         ber_int_t       ld_errno;
251         char    *ld_error;
252         char    *ld_matched;
253         ber_len_t               ld_msgid;
254
255         /* do not mess with these */
256         LDAPRequest     *ld_requests;   /* list of outstanding requests */
257         LDAPMessage     *ld_responses;  /* list of outstanding responses */
258
259         ber_int_t               *ld_abandoned;  /* array of abandoned requests */
260
261         LDAPCache       *ld_cache;      /* non-null if cache is initialized */
262         /* stuff used by connectionless searches. */
263
264         char            *ld_cldapdn;    /* DN used in connectionless search */
265         int             ld_cldapnaddr; /* number of addresses */
266         void            **ld_cldapaddrs;/* addresses to send request to */
267
268         /* do not mess with the rest though */
269         BERTranslateProc ld_lber_encode_translate_proc;
270         BERTranslateProc ld_lber_decode_translate_proc;
271
272         LDAPConn        *ld_defconn;    /* default connection */
273         LDAPConn        *ld_conns;      /* list of server connections */
274         void            *ld_selectinfo; /* platform specifics for select */
275         int             (*ld_rebindproc)( struct ldap *ld, char **dnp,
276                                 char **passwdp, int *authmethodp, int freeit );
277                                 /* routine to get info needed for re-bind */
278 #ifdef HAVE_CYRUS_SASL
279         sasl_conn_t             *ld_sasl_context;
280 #endif /* HAVE_CYRUS_SASL */
281 };
282 #define LDAP_VALID(ld)  ( (ld)->ld_valid == LDAP_VALID_SESSION )
283
284 #if defined(HAVE_RES_SEARCH) && defined(LDAP_R_COMPILE)
285 #include <ldap_pvt_thread.h>
286 extern ldap_pvt_thread_mutex_t ldap_int_resolv_mutex;
287 #endif /* HAVE_RES_SEARCH && LDAP_R_COMPILE */
288
289 /*
290  * in init.c
291  */
292
293 LIBLDAP_F ( struct ldapoptions ) ldap_int_global_options;
294 LIBLDAP_F ( void ) ldap_int_initialize LDAP_P((int *));
295
296 /* memory.c */
297         /* simple macros to realloc for now */
298 #define LDAP_INT_MALLOC(s)              (LBER_MALLOC((s)))
299 #define LDAP_INT_CALLOC(n,s)    (LBER_CALLOC((n),(s)))
300 #define LDAP_INT_REALLOC(p,s)   (LBER_REALLOC((p),(s)))
301 #define LDAP_INT_FREE(p)                (LBER_FREE((p)))
302 #define LDAP_INT_VFREE(v)               (LBER_VFREE((void **)(v)))
303 #define LDAP_INT_STRDUP(s)              (LBER_STRDUP((s)))
304
305 #define LDAP_MALLOC(s)          (LBER_MALLOC((s)))
306 #define LDAP_CALLOC(n,s)        (LBER_CALLOC((n),(s)))
307 #define LDAP_REALLOC(p,s)       (LBER_REALLOC((p),(s)))
308 #define LDAP_FREE(p)            (LBER_FREE((p)))
309 #define LDAP_VFREE(v)           (LBER_VFREE((void **)(v)))
310 #define LDAP_STRDUP(s)          (LBER_STRDUP((s)))
311
312 /*
313  * in unit-int.c
314  */
315 LIBLDAP_F (void) ldap_int_utils_init LDAP_P(( void ));
316
317
318 /*
319  * in print.c
320  */
321 LIBLDAP_F (int) ldap_log_printf LDAP_P((LDAP *ld, int level, const char *fmt, ...)) LDAP_GCCATTR((format(printf, 3, 4)));
322
323 /*
324  * in cache.c
325  */
326 LIBLDAP_F (void) ldap_add_request_to_cache LDAP_P(( LDAP *ld, ber_tag_t msgtype,
327         BerElement *request ));
328 LIBLDAP_F (void) ldap_add_result_to_cache LDAP_P(( LDAP *ld, LDAPMessage *result ));
329 LIBLDAP_F (int) ldap_check_cache LDAP_P(( LDAP *ld, ber_tag_t msgtype, BerElement *request ));
330
331 /*
332  * in controls.c
333  */
334 LIBLDAP_F (LDAPControl *) ldap_control_dup LDAP_P((
335         const LDAPControl *ctrl ));
336
337 LIBLDAP_F (LDAPControl **) ldap_controls_dup LDAP_P((
338         LDAPControl *const *ctrls ));
339
340 LIBLDAP_F (int) ldap_int_get_controls LDAP_P((
341         BerElement *be,
342         LDAPControl ***ctrlsp));
343
344 LIBLDAP_F (int) ldap_int_put_controls LDAP_P((
345         LDAP *ld,
346         LDAPControl *const *ctrls,
347         BerElement *ber ));
348
349 /*
350  * in dsparse.c
351  */
352 LIBLDAP_F (int) next_line_tokens LDAP_P(( char **bufp, ber_len_t *blenp, char ***toksp ));
353 LIBLDAP_F (void) free_strarray LDAP_P(( char **sap ));
354
355 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
356 /*
357  * in kerberos.c
358  */
359 LIBLDAP_F (char *) ldap_get_kerberosv4_credentials LDAP_P((
360         LDAP *ld,
361         LDAP_CONST char *who,
362         LDAP_CONST char *service,
363         ber_len_t *len ));
364
365 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND */
366
367
368 /*
369  * in open.c
370  */
371 LIBLDAP_F (int) ldap_open_defconn( LDAP *ld );
372 LIBLDAP_F (int) open_ldap_connection( LDAP *ld, Sockbuf *sb, LDAPURLDesc *srvlist, char **krbinstancep, int async );
373
374 /*
375  * in os-ip.c
376  */
377 LIBLDAP_F (int) ldap_int_tblsize;
378 LIBLDAP_F (int) ldap_int_timeval_dup( struct timeval **dest, const struct timeval *tm );
379 LIBLDAP_F (int) ldap_connect_to_host( LDAP *ld, Sockbuf *sb, const char *host, unsigned long address, int port, int async );
380
381 LIBLDAP_F (void) ldap_close_connection( Sockbuf *sb );
382
383 #if defined(LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND) || defined(HAVE_TLS) || defined(HAVE_CYRUS_SASL)
384 LIBLDAP_F (char *) ldap_host_connected_to( Sockbuf *sb );
385 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND */
386
387 LIBLDAP_F (void) ldap_int_ip_init( void );
388 LIBLDAP_F (int) do_ldap_select( LDAP *ld, struct timeval *timeout );
389 LIBLDAP_F (void *) ldap_new_select_info( void );
390 LIBLDAP_F (void) ldap_free_select_info( void *sip );
391 LIBLDAP_F (void) ldap_mark_select_write( LDAP *ld, Sockbuf *sb );
392 LIBLDAP_F (void) ldap_mark_select_read( LDAP *ld, Sockbuf *sb );
393 LIBLDAP_F (void) ldap_mark_select_clear( LDAP *ld, Sockbuf *sb );
394 LIBLDAP_F (int) ldap_is_read_ready( LDAP *ld, Sockbuf *sb );
395 LIBLDAP_F (int) ldap_is_write_ready( LDAP *ld, Sockbuf *sb );
396
397 #ifdef LDAP_PF_LOCAL 
398 /*
399  * in os-local.c
400  */
401 LIBLDAP_F (int) ldap_connect_to_path( LDAP *ld, Sockbuf *sb, const char *path, int async );
402 #endif /* LDAP_PF_LOCAL */
403
404 /*
405  * in request.c
406  */
407 LIBLDAP_F (ber_int_t) ldap_send_initial_request( LDAP *ld, ber_tag_t msgtype,
408         const char *dn, BerElement *ber );
409 LIBLDAP_F (BerElement *) ldap_alloc_ber_with_options( LDAP *ld );
410 LIBLDAP_F (void) ldap_set_ber_options( LDAP *ld, BerElement *ber );
411
412 LIBLDAP_F (int) ldap_send_server_request( LDAP *ld, BerElement *ber, ber_int_t msgid, LDAPRequest *parentreq, LDAPURLDesc *srvlist, LDAPConn *lc, int bind );
413 LIBLDAP_F (LDAPConn *) ldap_new_connection( LDAP *ld, LDAPURLDesc *srvlist, int use_ldsb, int connect, int bind );
414 LIBLDAP_F (LDAPRequest *) ldap_find_request_by_msgid( LDAP *ld, ber_int_t msgid );
415 LIBLDAP_F (void) ldap_free_request( LDAP *ld, LDAPRequest *lr );
416 LIBLDAP_F (void) ldap_free_connection( LDAP *ld, LDAPConn *lc, int force, int unbind );
417 LIBLDAP_F (void) ldap_dump_connection( LDAP *ld, LDAPConn *lconns, int all );
418 LIBLDAP_F (void) ldap_dump_requests_and_responses( LDAP *ld );
419 LIBLDAP_F (int) ldap_chase_referrals( LDAP *ld, LDAPRequest *lr, char **errstrp, int *hadrefp );
420 LIBLDAP_F (int) ldap_append_referral( LDAP *ld, char **referralsp, char *s );
421
422 /*
423  * in result.c:
424  */
425 #ifdef LDAP_CONNECTIONLESS
426 LIBLDAP_F (int) cldap_getmsg( LDAP *ld, struct timeval *timeout, BerElement *ber );
427 #endif
428
429 /*
430  * in search.c
431  */
432 LIBLDAP_F (BerElement *) ldap_build_search_req LDAP_P((
433         LDAP *ld,
434         const char *base,
435         ber_int_t scope,
436         const char *filter,
437         char **attrs,
438         ber_int_t attrsonly,
439         LDAPControl **sctrls,
440         LDAPControl **cctrls,
441         ber_int_t timelimit,
442         ber_int_t sizelimit ));
443
444 /*
445  * in string.c
446  */
447         /* see <ac/string.h> */
448
449 /*
450  * in unbind.c
451  */
452 LIBLDAP_F (int) ldap_ld_free LDAP_P((
453         LDAP *ld,
454         int close,
455         LDAPControl **sctrls,
456         LDAPControl **cctrls ));
457
458 LIBLDAP_F (int) ldap_send_unbind LDAP_P((
459         LDAP *ld,
460         Sockbuf *sb,
461         LDAPControl **sctrls,
462         LDAPControl **cctrls ));
463
464 /*
465  * in url.c
466  */
467 LIBLDAP_F (LDAPURLDesc *) ldap_url_dup LDAP_P((
468         LDAPURLDesc *ludp ));
469
470 LIBLDAP_F (LDAPURLDesc *) ldap_url_duplist LDAP_P((
471         LDAPURLDesc *ludlist ));
472
473 LIBLDAP_F (int) ldap_url_parselist LDAP_P((
474         LDAPURLDesc **ludlist,
475         const char *url ));
476
477 LIBLDAP_F (int) ldap_url_parsehosts LDAP_P((
478         LDAPURLDesc **ludlist,
479         const char *hosts ));
480
481 LIBLDAP_F (char *) ldap_url_list2hosts LDAP_P((
482         LDAPURLDesc *ludlist ));
483
484 LIBLDAP_F (char *) ldap_url_list2urls LDAP_P((
485         LDAPURLDesc *ludlist ));
486
487 LIBLDAP_F (void) ldap_free_urllist LDAP_P((
488         LDAPURLDesc *ludlist ));
489
490
491 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
492 /*
493  * in getdxbyname.c
494  */
495 LIBLDAP_F (char **) ldap_getdxbyname( const char *domain );
496 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
497
498 #if defined( STR_TRANSLATION ) && defined( LDAP_DEFAULT_CHARSET )
499 /*
500  * in charset.c
501  *
502  * added-in this stuff so that libldap.a would build, i.e. refs to 
503  * these routines from open.c would resolve. 
504  * hodges@stanford.edu 5-Feb-96
505  */
506 #if LDAP_CHARSET_8859 == LDAP_DEFAULT_CHARSET
507 LIBLDAP_F (int) ldap_t61_to_8859( char **bufp, ber_len_t *buflenp, int free_input );
508 LIBLDAP_F (int) ldap_8859_to_t61( char **bufp, ber_len_t *buflenp, int free_input );
509 #endif /* LDAP_CHARSET_8859 == LDAP_DEFAULT_CHARSET */
510 #endif /* STR_TRANSLATION && LDAP_DEFAULT_CHARSET */
511
512 LDAP_END_DECL
513
514 #endif /* _LDAP_INT_H */