]> git.sur5r.net Git - openldap/blob - libraries/libldap/ldap-int.h
Added lber_get/set_option. Removed lber_debug/ldap_debug.
[openldap] / libraries / libldap / ldap-int.h
1 /*
2  *  Copyright (c) 1995 Regents of the University of Michigan.
3  *  All rights reserved.
4  *
5  *  ldap-int.h - defines & prototypes internal to the LDAP library
6  */
7
8 #ifndef _LDAP_INT_H
9 #define _LDAP_INT_H 1
10
11 #ifdef LDAP_COMPILING_R
12 #define LDAP_THREAD_SAFE 1
13 #endif
14
15 #include "../liblber/lber-int.h"
16
17 #define ldap_debug      (openldap_ldap_global_options.ldo_debug)
18
19 #include "ldap_log.h"
20
21 #include "ldap.h"
22
23 LDAP_BEGIN_DECL
24
25 #define LDAP_URL_PREFIX         "ldap://"
26 #define LDAP_URL_PREFIX_LEN     7
27 #define LDAP_URL_URLCOLON       "URL:"
28 #define LDAP_URL_URLCOLON_LEN   4
29
30 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
31 #define LDAP_REF_STR            "Referral:\n"
32 #define LDAP_REF_STR_LEN        10
33 #define LDAP_LDAP_REF_STR       LDAP_URL_PREFIX
34 #define LDAP_LDAP_REF_STR_LEN   LDAP_URL_PREFIX_LEN
35 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
36 #define LDAP_DX_REF_STR         "dx://"
37 #define LDAP_DX_REF_STR_LEN     5
38 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
39 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
40
41 #define LDAP_BOOL_REFERRALS             0
42 #define LDAP_BOOL_RESTART               1
43 #define LDAP_BOOL_DNS                   2
44
45 #define LDAP_BOOLEANS   unsigned long
46 #define LDAP_BOOL(n)    (1 << (n))
47 #define LDAP_BOOL_GET(lo, bool) ((lo)->ldo_booleans & LDAP_BOOL(bool) \
48                                                                         ?  LDAP_OPT_ON : LDAP_OPT_OFF)
49 #define LDAP_BOOL_SET(lo, bool) ((lo)->ldo_booleans |= LDAP_BOOL(bool))
50 #define LDAP_BOOL_CLR(lo, bool) ((lo)->ldo_booleans &= ~LDAP_BOOL(bool))
51 #define LDAP_BOOL_ZERO(lo) ((lo)->ldo_booleans = 0)
52
53 /*
54  * This structure represents both ldap messages and ldap responses.
55  * These are really the same, except in the case of search responses,
56  * where a response has multiple messages.
57  */
58
59 struct ldapmsg {
60         int             lm_msgid;       /* the message id */
61         int             lm_msgtype;     /* the message type */
62         BerElement      *lm_ber;        /* the ber encoded message contents */
63         struct ldapmsg  *lm_chain;      /* for search - next msg in the resp */
64         struct ldapmsg  *lm_next;       /* next response */
65         unsigned int    lm_time;        /* used to maintain cache */
66 };
67
68 /*
69  * structure representing get/set'able options
70  * which have global defaults.
71  */
72 struct ldapoptions {
73         int             ldo_version;    /* version to connect at */
74         int             ldo_deref;
75         int             ldo_timelimit;
76         int             ldo_sizelimit;
77
78         int             ldo_debug;
79
80         char*   ldo_defbase;
81         char*   ldo_defhost;
82         int             ldo_defport;
83
84         int             ldo_cldaptries; /* connectionless search retry count */
85         int             ldo_cldaptimeout;/* time between retries */
86         int             ldo_refhoplimit;        /* limit on referral nesting */
87
88         LDAP_BOOLEANS ldo_booleans;     /* boolean options */
89 };
90
91 /*
92  * structure representing an ldap connection
93  */
94
95 struct ldap {
96         Sockbuf         ld_sb;          /* socket descriptor & buffer */
97
98         struct ldapoptions ld_options;
99
100 #define ld_deref                ld_options.ldo_deref
101 #define ld_timelimit    ld_options.ldo_timelimit
102 #define ld_sizelimit    ld_options.ldo_sizelimit
103
104 #define ld_defbase              ld_options.ldo_defbase
105 #define ld_defhost              ld_options.ldo_defhost
106 #define ld_defport              ld_options.ldo_defport
107
108 #define ld_cldaptries   ld_options.ldo_cldaptries
109 #define ld_cldaptimeout ld_options.ldo_cldaptimeout
110 #define ld_refhoplimit  ld_options.ldo_refhoplimit
111
112         int             ld_version;             /* version connected at */
113         char    *ld_host;
114         int             ld_port;
115
116         char    ld_lberoptions;
117
118         LDAPFiltDesc    *ld_filtd;      /* from getfilter for ufn searches */
119         char            *ld_ufnprefix;  /* for incomplete ufn's */
120
121         int             ld_errno;
122         char    *ld_error;
123         char    *ld_matched;
124         int             ld_msgid;
125
126         /* do not mess with these */
127 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
128         LDAPRequest     *ld_requests;   /* list of outstanding requests */
129 #else /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
130         LDAPMessage     *ld_requests;   /* list of outstanding requests */
131 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
132         LDAPMessage     *ld_responses;  /* list of outstanding responses */
133         int             *ld_abandoned;  /* array of abandoned requests */
134         char            ld_attrbuffer[LDAP_MAX_ATTR_LEN];
135         LDAPCache       *ld_cache;      /* non-null if cache is initialized */
136         char            *ld_cldapdn;    /* DN used in connectionless search */
137
138         /* do not mess with the rest though */
139         BERTranslateProc ld_lber_encode_translate_proc;
140         BERTranslateProc ld_lber_decode_translate_proc;
141
142 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
143         LDAPConn        *ld_defconn;    /* default connection */
144         LDAPConn        *ld_conns;      /* list of server connections */
145         void            *ld_selectinfo; /* platform specifics for select */
146         int             (*ld_rebindproc)( struct ldap *ld, char **dnp,
147                                 char **passwdp, int *authmethodp, int freeit );
148                                 /* routine to get info needed for re-bind */
149 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
150 };
151
152 /*
153  * in init.c
154  */
155 extern int openldap_ldap_initialized;
156 extern struct ldapoptions openldap_ldap_global_options;
157 void openldap_ldap_initialize LDAP_P((void));
158
159 /*
160  * in cache.c
161  */
162 void ldap_add_request_to_cache LDAP_P(( LDAP *ld, unsigned long msgtype,
163         BerElement *request ));
164 void ldap_add_result_to_cache LDAP_P(( LDAP *ld, LDAPMessage *result ));
165 int ldap_check_cache LDAP_P(( LDAP *ld, unsigned long msgtype, BerElement *request ));
166
167 /*
168  * in dsparse.c
169  */
170 int next_line_tokens LDAP_P(( char **bufp, long *blenp, char ***toksp ));
171 void free_strarray LDAP_P(( char **sap ));
172
173 #ifdef HAVE_KERBEROS
174 /*
175  * in kerberos.c
176  */
177 char *ldap_get_kerberosv4_credentials LDAP_P(( LDAP *ld, char *who, char *service,
178         int *len ));
179
180 #endif /* HAVE_KERBEROS */
181
182
183 /*
184  * in open.c
185  */
186 int open_ldap_connection( LDAP *ld, Sockbuf *sb, char *host, int defport,
187         char **krbinstancep, int async );
188
189
190 /*
191  * in os-ip.c
192  */
193 int ldap_connect_to_host( Sockbuf *sb, char *host, unsigned long address, int port,
194         int async );
195 void ldap_close_connection( Sockbuf *sb );
196
197 #ifdef HAVE_KERBEROS
198 char *ldap_host_connected_to( Sockbuf *sb );
199 #endif /* HAVE_KERBEROS */
200
201 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
202 int do_ldap_select( LDAP *ld, struct timeval *timeout );
203 void *ldap_new_select_info( void );
204 void ldap_free_select_info( void *sip );
205 void ldap_mark_select_write( LDAP *ld, Sockbuf *sb );
206 void ldap_mark_select_read( LDAP *ld, Sockbuf *sb );
207 void ldap_mark_select_clear( LDAP *ld, Sockbuf *sb );
208 int ldap_is_read_ready( LDAP *ld, Sockbuf *sb );
209 int ldap_is_write_ready( LDAP *ld, Sockbuf *sb );
210 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
211
212
213 /*
214  * in request.c
215  */
216 int ldap_send_initial_request( LDAP *ld, unsigned long msgtype,
217         char *dn, BerElement *ber );
218 BerElement *ldap_alloc_ber_with_options( LDAP *ld );
219 void ldap_set_ber_options( LDAP *ld, BerElement *ber );
220
221 #if defined( LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS ) || defined( LDAP_API_FEATURE_X_OPENLDAP_V2_DNS )
222 int ldap_send_server_request( LDAP *ld, BerElement *ber, int msgid,
223         LDAPRequest *parentreq, LDAPServer *srvlist, LDAPConn *lc,
224         int bind );
225 LDAPConn *ldap_new_connection( LDAP *ld, LDAPServer **srvlistp, int use_ldsb,
226         int connect, int bind );
227 LDAPRequest *ldap_find_request_by_msgid( LDAP *ld, int msgid );
228 void ldap_free_request( LDAP *ld, LDAPRequest *lr );
229 void ldap_free_connection( LDAP *ld, LDAPConn *lc, int force, int unbind );
230 void ldap_dump_connection( LDAP *ld, LDAPConn *lconns, int all );
231 void ldap_dump_requests_and_responses( LDAP *ld );
232 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS || LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
233
234 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
235 int ldap_chase_referrals( LDAP *ld, LDAPRequest *lr, char **errstrp, int *hadrefp );
236 int ldap_append_referral( LDAP *ld, char **referralsp, char *s );
237 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
238
239 /*
240  * in result.c:
241  */
242 #ifdef LDAP_CONNECTIONLESS
243 LDAP_F int cldap_getmsg ( LDAP *ld, struct timeval *timeout, BerElement *ber );
244 #endif
245
246 /*
247  * in search.c
248  */
249 BerElement *ldap_build_search_req( LDAP *ld, char *base, int scope,
250         char *filter, char **attrs, int attrsonly );
251
252 /*
253  * in strdup.c
254  */
255 char *ldap_strdup LDAP_P(( const char * ));
256
257 /*
258  * in unbind.c
259  */
260 int ldap_ld_free( LDAP *ld, int close );
261 int ldap_send_unbind( LDAP *ld, Sockbuf *sb );
262
263 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
264 /*
265  * in getdxbyname.c
266  */
267 char **ldap_getdxbyname( char *domain );
268 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
269
270 #if defined( STR_TRANSLATION ) && defined( LDAP_DEFAULT_CHARSET )
271 /*
272  * in charset.c
273  *
274  * added-in this stuff so that libldap.a would build, i.e. refs to 
275  * these routines from open.c would resolve. 
276  * hodges@stanford.edu 5-Feb-96
277  */
278 #if LDAP_CHARSET_8859 == LDAP_DEFAULT_CHARSET
279 extern 
280 int ldap_t61_to_8859( char **bufp, unsigned long *buflenp, int free_input );
281 extern 
282 int ldap_8859_to_t61( char **bufp, unsigned long *buflenp, int free_input );
283 #endif /* LDAP_CHARSET_8859 == LDAP_DEFAULT_CHARSET */
284 #endif /* STR_TRANSLATION && LDAP_DEFAULT_CHARSET */
285
286 /*
287  * in util_r.c
288  * 
289  */
290
291 struct hostent; /* avoid pulling in <netdb.h> */
292
293 extern char *ldap_int_strtok( char *str, const char *delim, char **pos );
294 extern char *ldap_int_ctime( const time_t *tp, char *buf );
295 extern int ldap_int_gethostbyname_a(
296         const char *name, 
297         struct hostent *resbuf,
298         char **buf,
299         struct hostent **result,
300         int *herrno_ptr );
301 extern int ldap_int_gethostbyaddr_a(
302         const char *addr,
303         int len,
304         int type,
305         struct hostent *resbuf,
306         char **buf,
307         struct hostent **result,
308         int *herrno_ptr );
309
310 LDAP_END_DECL
311
312 #endif /* _LDAP_INT_H */