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