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