]> git.sur5r.net Git - openldap/blob - libraries/libldap/ldap-int.h
9f27a0a6a347086c52114095720f0fe6ba06170a
[openldap] / libraries / libldap / ldap-int.h
1 /*
2  * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
3  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
4  */
5 /*  Portions
6  *  Copyright (c) 1995 Regents of the University of Michigan.
7  *  All rights reserved.
8  *
9  *  ldap-int.h - defines & prototypes internal to the LDAP library
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 #define ldap_debug      (openldap_ldap_global_options.ldo_debug)
22 #undef Debug
23 #define Debug( level, fmt, arg1, arg2, arg3 ) \
24         ldap_log_printf( NULL, (level), (fmt), (arg1), (arg2), (arg3) )
25
26 #include "ldap_log.h"
27
28 #include "ldap.h"
29
30 #include "ldap_pvt.h"
31
32 LDAP_BEGIN_DECL
33
34 #define LDAP_URL_PREFIX         "ldap://"
35 #define LDAP_URL_PREFIX_LEN     7
36 #define LDAP_URL_URLCOLON       "URL:"
37 #define LDAP_URL_URLCOLON_LEN   4
38
39 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
40 #define LDAP_REF_STR            "Referral:\n"
41 #define LDAP_REF_STR_LEN        10
42 #define LDAP_LDAP_REF_STR       LDAP_URL_PREFIX
43 #define LDAP_LDAP_REF_STR_LEN   LDAP_URL_PREFIX_LEN
44 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
45 #define LDAP_DX_REF_STR         "dx://"
46 #define LDAP_DX_REF_STR_LEN     5
47 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
48 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
49
50 #define LDAP_BOOL_REFERRALS             0
51 #define LDAP_BOOL_RESTART               1
52 #define LDAP_BOOL_DNS                   2
53
54 #define LDAP_BOOLEANS   unsigned long
55 #define LDAP_BOOL(n)    (1 << (n))
56 #define LDAP_BOOL_GET(lo, bool) ((lo)->ldo_booleans & LDAP_BOOL(bool) \
57                                                                         ?  LDAP_OPT_ON : LDAP_OPT_OFF)
58 #define LDAP_BOOL_SET(lo, bool) ((lo)->ldo_booleans |= LDAP_BOOL(bool))
59 #define LDAP_BOOL_CLR(lo, bool) ((lo)->ldo_booleans &= ~LDAP_BOOL(bool))
60 #define LDAP_BOOL_ZERO(lo) ((lo)->ldo_booleans = 0)
61
62 /*
63  * This structure represents both ldap messages and ldap responses.
64  * These are really the same, except in the case of search responses,
65  * where a response has multiple messages.
66  */
67
68 struct ldapmsg {
69         int             lm_msgid;       /* the message id */
70         int             lm_msgtype;     /* the message type */
71         BerElement      *lm_ber;        /* the ber encoded message contents */
72         struct ldapmsg  *lm_chain;      /* for search - next msg in the resp */
73         struct ldapmsg  *lm_next;       /* next response */
74         unsigned int    lm_time;        /* used to maintain cache */
75 };
76
77 /*
78  * structure representing get/set'able options
79  * which have global defaults.
80  */
81 struct ldapoptions {
82         int             ldo_debug;
83
84         int             ldo_version;    /* version to connect at */
85         int             ldo_deref;
86         int             ldo_timelimit;
87         int             ldo_sizelimit;
88
89         int             ldo_defport;
90         char*   ldo_defbase;
91         char*   ldo_defhost;
92
93         int             ldo_cldaptries; /* connectionless search retry count */
94         int             ldo_cldaptimeout;/* time between retries */
95         int             ldo_refhoplimit;        /* limit on referral nesting */
96
97         /* LDAPv3 server and client controls */
98         LDAPControl     **ldo_server_controls;
99         LDAPControl **ldo_client_controls;
100         
101         LDAP_BOOLEANS ldo_booleans;     /* boolean options */
102 };
103
104 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
105 /*
106  * structure for tracking LDAP server host, ports, DNs, etc.
107  */
108 typedef struct ldap_server {
109         char                    *lsrv_host;
110         char                    *lsrv_dn;       /* if NULL, use default */
111         int                     lsrv_port;
112         struct ldap_server      *lsrv_next;
113 } LDAPServer;
114
115
116 /*
117  * structure for representing an LDAP server connection
118  */
119 typedef struct ldap_conn {
120         Sockbuf                 *lconn_sb;
121         int                     lconn_refcnt;
122         time_t          lconn_lastused; /* time */
123         int                     lconn_status;
124 #define LDAP_CONNST_NEEDSOCKET          1
125 #define LDAP_CONNST_CONNECTING          2
126 #define LDAP_CONNST_CONNECTED           3
127         LDAPServer              *lconn_server;
128         char                    *lconn_krbinstance;
129         struct ldap_conn        *lconn_next;
130         BerElement              lconn_ber;/* ber receiving on this conn. */
131 } LDAPConn;
132
133
134 /*
135  * structure used to track outstanding requests
136  */
137 typedef struct ldapreq {
138         int             lr_msgid;       /* the message id */
139         int             lr_status;      /* status of request */
140 #define LDAP_REQST_INPROGRESS   1
141 #define LDAP_REQST_CHASINGREFS  2
142 #define LDAP_REQST_NOTCONNECTED 3
143 #define LDAP_REQST_WRITING      4
144         int             lr_outrefcnt;   /* count of outstanding referrals */
145         int             lr_origid;      /* original request's message id */
146         int             lr_parentcnt;   /* count of parent requests */
147         int             lr_res_msgtype; /* result message type */
148         int             lr_res_errno;   /* result LDAP errno */
149         char            *lr_res_error;  /* result error string */
150         char            *lr_res_matched;/* result matched DN string */
151         BerElement      *lr_ber;        /* ber encoded request contents */
152         LDAPConn        *lr_conn;       /* connection used to send request */
153         struct ldapreq  *lr_parent;     /* request that spawned this referral */
154         struct ldapreq  *lr_refnext;    /* next referral spawned */
155         struct ldapreq  *lr_prev;       /* previous request */
156         struct ldapreq  *lr_next;       /* next request */
157 } LDAPRequest;
158 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
159
160 /*
161  * structure for client cache
162  */
163 #define LDAP_CACHE_BUCKETS      31      /* cache hash table size */
164 typedef struct ldapcache {
165         LDAPMessage     *lc_buckets[LDAP_CACHE_BUCKETS];/* hash table */
166         LDAPMessage     *lc_requests;                   /* unfulfilled reqs */
167         long            lc_timeout;                     /* request timeout */
168         long            lc_maxmem;                      /* memory to use */
169         long            lc_memused;                     /* memory in use */
170         int             lc_enabled;                     /* enabled? */
171         unsigned long   lc_options;                     /* options */
172 #define LDAP_CACHE_OPT_CACHENOERRS      0x00000001
173 #define LDAP_CACHE_OPT_CACHEALLERRS     0x00000002
174 }  LDAPCache;
175 #define NULLLDCACHE ((LDAPCache *)NULL)
176
177 /*
178  * handy macro for checking if handle is connectionless
179  */
180
181 #define LDAP_IS_CLDAP(ld) ((ld)->ld_cldapnaddr>0)
182
183 /*
184  * structure representing an ldap connection
185  */
186
187 struct ldap {
188         Sockbuf         ld_sb;          /* socket descriptor & buffer */
189
190         struct ldapoptions ld_options;
191
192 #define ld_deref                ld_options.ldo_deref
193 #define ld_timelimit    ld_options.ldo_timelimit
194 #define ld_sizelimit    ld_options.ldo_sizelimit
195
196 #define ld_defbase              ld_options.ldo_defbase
197 #define ld_defhost              ld_options.ldo_defhost
198 #define ld_defport              ld_options.ldo_defport
199
200 #define ld_cldaptries   ld_options.ldo_cldaptries
201 #define ld_cldaptimeout ld_options.ldo_cldaptimeout
202 #define ld_refhoplimit  ld_options.ldo_refhoplimit
203
204         int             ld_version;             /* version connected at */
205         char    *ld_host;
206         int             ld_port;
207
208         char    ld_lberoptions;
209
210         LDAPFiltDesc    *ld_filtd;      /* from getfilter for ufn searches */
211         char            *ld_ufnprefix;  /* for incomplete ufn's */
212
213         int             ld_errno;
214         char    *ld_error;
215         char    *ld_matched;
216         int             ld_msgid;
217
218         /* do not mess with these */
219 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
220         LDAPRequest     *ld_requests;   /* list of outstanding requests */
221 #else /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
222         LDAPMessage     *ld_requests;   /* list of outstanding requests */
223 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
224         LDAPMessage     *ld_responses;  /* list of outstanding responses */
225         int             *ld_abandoned;  /* array of abandoned requests */
226         char            ld_attrbuffer[LDAP_MAX_ATTR_LEN];
227         LDAPCache       *ld_cache;      /* non-null if cache is initialized */
228         /* stuff used by connectionless searches. */
229         char            *ld_cldapdn;    /* DN used in connectionless search */
230         int             ld_cldapnaddr; /* number of addresses */
231         void            **ld_cldapaddrs;/* addresses to send request to */
232 #ifndef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS        
233         /* BerElement that this connection is receiving. */
234         BerElement      ld_ber;
235 #endif  
236         /* do not mess with the rest though */
237         BERTranslateProc ld_lber_encode_translate_proc;
238         BERTranslateProc ld_lber_decode_translate_proc;
239
240 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
241         LDAPConn        *ld_defconn;    /* default connection */
242         LDAPConn        *ld_conns;      /* list of server connections */
243         void            *ld_selectinfo; /* platform specifics for select */
244         int             (*ld_rebindproc)( struct ldap *ld, char **dnp,
245                                 char **passwdp, int *authmethodp, int freeit );
246                                 /* routine to get info needed for re-bind */
247 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
248 };
249
250 /*
251  * in init.c
252  */
253 extern int openldap_ldap_initialized;
254 extern struct ldapoptions openldap_ldap_global_options;
255 void openldap_ldap_initialize LDAP_P((void));
256
257 /*
258  * in print.c
259  */
260 int ldap_log_printf LDAP_P((LDAP *ld, int level, char *fmt, ...));
261
262 /*
263  * in cache.c
264  */
265 void ldap_add_request_to_cache LDAP_P(( LDAP *ld, unsigned long msgtype,
266         BerElement *request ));
267 void ldap_add_result_to_cache LDAP_P(( LDAP *ld, LDAPMessage *result ));
268 int ldap_check_cache LDAP_P(( LDAP *ld, unsigned long msgtype, BerElement *request ));
269
270 /*
271  * in controls.c
272  */
273 LDAPControl *ldap_control_dup LDAP_P(( LDAPControl *ctrl ));
274 LDAPControl **ldap_controls_dup LDAP_P(( LDAPControl **ctrl ));
275 int ldap_get_ber_controls LDAP_P(( BerElement *be, LDAPControl ***cp));
276
277 /*
278  * in dsparse.c
279  */
280 int next_line_tokens LDAP_P(( char **bufp, long *blenp, char ***toksp ));
281 void free_strarray LDAP_P(( char **sap ));
282
283 #ifdef HAVE_KERBEROS
284 /*
285  * in kerberos.c
286  */
287 char *ldap_get_kerberosv4_credentials LDAP_P(( LDAP *ld, char *who, char *service,
288         int *len ));
289
290 #endif /* HAVE_KERBEROS */
291
292
293 /*
294  * in open.c
295  */
296 int open_ldap_connection( LDAP *ld, Sockbuf *sb, char *host, int defport,
297         char **krbinstancep, int async );
298
299
300 /*
301  * in os-ip.c
302  */
303 int ldap_connect_to_host( Sockbuf *sb, char *host, unsigned long address, int port,
304         int async );
305 void ldap_close_connection( Sockbuf *sb );
306
307 #ifdef HAVE_KERBEROS
308 char *ldap_host_connected_to( Sockbuf *sb );
309 #endif /* HAVE_KERBEROS */
310
311 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
312 int do_ldap_select( LDAP *ld, struct timeval *timeout );
313 void *ldap_new_select_info( void );
314 void ldap_free_select_info( void *sip );
315 void ldap_mark_select_write( LDAP *ld, Sockbuf *sb );
316 void ldap_mark_select_read( LDAP *ld, Sockbuf *sb );
317 void ldap_mark_select_clear( LDAP *ld, Sockbuf *sb );
318 int ldap_is_read_ready( LDAP *ld, Sockbuf *sb );
319 int ldap_is_write_ready( LDAP *ld, Sockbuf *sb );
320 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
321
322
323 /*
324  * in request.c
325  */
326 int ldap_send_initial_request( LDAP *ld, unsigned long msgtype,
327         char *dn, BerElement *ber );
328 BerElement *ldap_alloc_ber_with_options( LDAP *ld );
329 void ldap_set_ber_options( LDAP *ld, BerElement *ber );
330
331 #if defined( LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS ) || defined( LDAP_API_FEATURE_X_OPENLDAP_V2_DNS )
332 int ldap_send_server_request( LDAP *ld, BerElement *ber, int msgid,
333         LDAPRequest *parentreq, LDAPServer *srvlist, LDAPConn *lc,
334         int bind );
335 LDAPConn *ldap_new_connection( LDAP *ld, LDAPServer **srvlistp, int use_ldsb,
336         int connect, int bind );
337 LDAPRequest *ldap_find_request_by_msgid( LDAP *ld, int msgid );
338 void ldap_free_request( LDAP *ld, LDAPRequest *lr );
339 void ldap_free_connection( LDAP *ld, LDAPConn *lc, int force, int unbind );
340 void ldap_dump_connection( LDAP *ld, LDAPConn *lconns, int all );
341 void ldap_dump_requests_and_responses( LDAP *ld );
342 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS || LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
343
344 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
345 int ldap_chase_referrals( LDAP *ld, LDAPRequest *lr, char **errstrp, int *hadrefp );
346 int ldap_append_referral( LDAP *ld, char **referralsp, char *s );
347 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
348
349 /*
350  * in result.c:
351  */
352 #ifdef LDAP_CONNECTIONLESS
353 LDAP_F int cldap_getmsg ( LDAP *ld, struct timeval *timeout, BerElement *ber );
354 #endif
355
356 /*
357  * in search.c
358  */
359 BerElement *ldap_build_search_req( LDAP *ld, char *base, int scope,
360         char *filter, char **attrs, int attrsonly );
361
362 /*
363  * in strdup.c
364  */
365 char *ldap_strdup LDAP_P(( const char * ));
366
367 /*
368  * in unbind.c
369  */
370 int ldap_ld_free( LDAP *ld, int close );
371 int ldap_send_unbind( LDAP *ld, Sockbuf *sb );
372
373 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
374 /*
375  * in getdxbyname.c
376  */
377 char **ldap_getdxbyname( char *domain );
378 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
379
380 #if defined( STR_TRANSLATION ) && defined( LDAP_DEFAULT_CHARSET )
381 /*
382  * in charset.c
383  *
384  * added-in this stuff so that libldap.a would build, i.e. refs to 
385  * these routines from open.c would resolve. 
386  * hodges@stanford.edu 5-Feb-96
387  */
388 #if LDAP_CHARSET_8859 == LDAP_DEFAULT_CHARSET
389 extern 
390 int ldap_t61_to_8859( char **bufp, unsigned long *buflenp, int free_input );
391 extern 
392 int ldap_8859_to_t61( char **bufp, unsigned long *buflenp, int free_input );
393 #endif /* LDAP_CHARSET_8859 == LDAP_DEFAULT_CHARSET */
394 #endif /* STR_TRANSLATION && LDAP_DEFAULT_CHARSET */
395
396 LDAP_END_DECL
397
398 #endif /* _LDAP_INT_H */