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