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