]> git.sur5r.net Git - openldap/blob - libraries/libldap/ldap-int.h
Split out ldapoptions from struct ldap to facilate global options.
[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_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_DNS
28 #define LDAP_DX_REF_STR         "dx://"
29 #define LDAP_DX_REF_STR_LEN     5
30 #endif /* LDAP_DNS */
31 #endif /* LDAP_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         int             ldo_cldaptries; /* connectionless search retry count */
71         int             ldo_cldaptimeout;/* time between retries */
72         int             ldo_refhoplimit;        /* limit on referral nesting */
73
74         LDAP_BOOLEANS ldo_booleans;     /* boolean options */
75 };
76
77 /*
78  * structure representing an ldap connection
79  */
80
81 struct ldap {
82         Sockbuf         ld_sb;          /* socket descriptor & buffer */
83
84         struct ldapoptions ld_options;
85
86 #define ld_deref                ld_options.ldo_deref
87 #define ld_timelimit    ld_options.ldo_timelimit
88 #define ld_sizelimit    ld_options.ldo_sizelimit
89
90 #define ld_cldaptries   ld_options.ldo_cldaptries
91 #define ld_cldaptimeout ld_options.ldo_cldaptimeout
92 #define ld_refhoplimit  ld_options.ldo_refhoplimit
93
94         int             ld_version;             /* version connected at */
95         char    *ld_host;
96         char    ld_lberoptions;
97
98         LDAPFiltDesc    *ld_filtd;      /* from getfilter for ufn searches */
99         char            *ld_ufnprefix;  /* for incomplete ufn's */
100
101         int             ld_errno;
102         char    *ld_error;
103         char    *ld_matched;
104         int             ld_msgid;
105
106         /* do not mess with these */
107 #ifdef LDAP_REFERRALS
108         LDAPRequest     *ld_requests;   /* list of outstanding requests */
109 #else /* LDAP_REFERRALS */
110         LDAPMessage     *ld_requests;   /* list of outstanding requests */
111 #endif /* LDAP_REFERRALS */
112         LDAPMessage     *ld_responses;  /* list of outstanding responses */
113         int             *ld_abandoned;  /* array of abandoned requests */
114         char            ld_attrbuffer[LDAP_MAX_ATTR_LEN];
115         LDAPCache       *ld_cache;      /* non-null if cache is initialized */
116         char            *ld_cldapdn;    /* DN used in connectionless search */
117
118         /* do not mess with the rest though */
119         char            *ld_defhost;    /* full name of default server */
120         int             ld_defport;     /* port of default server */
121         BERTranslateProc ld_lber_encode_translate_proc;
122         BERTranslateProc ld_lber_decode_translate_proc;
123
124 #ifdef LDAP_REFERRALS
125         LDAPConn        *ld_defconn;    /* default connection */
126         LDAPConn        *ld_conns;      /* list of server connections */
127         void            *ld_selectinfo; /* platform specifics for select */
128         int             (*ld_rebindproc)( struct ldap *ld, char **dnp,
129                                 char **passwdp, int *authmethodp, int freeit );
130                                 /* routine to get info needed for re-bind */
131 #endif /* LDAP_REFERRALS */
132 };
133
134
135 /*
136  * in init.c
137  */
138 extern int openldap_ldap_initialized;
139 extern struct ldapoptions openldap_ldap_global_options;
140 void openldap_ldap_initialize LDAP_P((void));
141
142 /*
143  * in cache.c
144  */
145 void ldap_add_request_to_cache LDAP_P(( LDAP *ld, unsigned long msgtype,
146         BerElement *request ));
147 void ldap_add_result_to_cache LDAP_P(( LDAP *ld, LDAPMessage *result ));
148 int ldap_check_cache LDAP_P(( LDAP *ld, unsigned long msgtype, BerElement *request ));
149
150
151 #ifdef HAVE_KERBEROS
152 /*
153  * in kerberos.c
154  */
155 char *ldap_get_kerberosv4_credentials LDAP_P(( LDAP *ld, char *who, char *service,
156         int *len ));
157
158 #endif /* HAVE_KERBEROS */
159
160
161 /*
162  * in open.c
163  */
164 int open_ldap_connection( LDAP *ld, Sockbuf *sb, char *host, int defport,
165         char **krbinstancep, int async );
166
167
168 /*
169  * in os-ip.c
170  */
171 int ldap_connect_to_host( Sockbuf *sb, char *host, unsigned long address, int port,
172         int async );
173 void ldap_close_connection( Sockbuf *sb );
174
175 #ifdef HAVE_KERBEROS
176 char *ldap_host_connected_to( Sockbuf *sb );
177 #endif /* HAVE_KERBEROS */
178
179 #ifdef LDAP_REFERRALS
180 int do_ldap_select( LDAP *ld, struct timeval *timeout );
181 void *ldap_new_select_info( void );
182 void ldap_free_select_info( void *sip );
183 void ldap_mark_select_write( LDAP *ld, Sockbuf *sb );
184 void ldap_mark_select_read( LDAP *ld, Sockbuf *sb );
185 void ldap_mark_select_clear( LDAP *ld, Sockbuf *sb );
186 int ldap_is_read_ready( LDAP *ld, Sockbuf *sb );
187 int ldap_is_write_ready( LDAP *ld, Sockbuf *sb );
188 #endif /* LDAP_REFERRALS */
189
190
191 /*
192  * in request.c
193  */
194 int ldap_send_initial_request( LDAP *ld, unsigned long msgtype,
195         char *dn, BerElement *ber );
196 BerElement *ldap_alloc_ber_with_options( LDAP *ld );
197 void ldap_set_ber_options( LDAP *ld, BerElement *ber );
198
199 #if defined( LDAP_REFERRALS ) || defined( LDAP_DNS )
200 int ldap_send_server_request( LDAP *ld, BerElement *ber, int msgid,
201         LDAPRequest *parentreq, LDAPServer *srvlist, LDAPConn *lc,
202         int bind );
203 LDAPConn *ldap_new_connection( LDAP *ld, LDAPServer **srvlistp, int use_ldsb,
204         int connect, int bind );
205 LDAPRequest *ldap_find_request_by_msgid( LDAP *ld, int msgid );
206 void ldap_free_request( LDAP *ld, LDAPRequest *lr );
207 void ldap_free_connection( LDAP *ld, LDAPConn *lc, int force, int unbind );
208 void ldap_dump_connection( LDAP *ld, LDAPConn *lconns, int all );
209 void ldap_dump_requests_and_responses( LDAP *ld );
210 #endif /* LDAP_REFERRALS || LDAP_DNS */
211
212 #ifdef LDAP_REFERRALS
213 int ldap_chase_referrals( LDAP *ld, LDAPRequest *lr, char **errstrp, int *hadrefp );
214 int ldap_append_referral( LDAP *ld, char **referralsp, char *s );
215 #endif /* LDAP_REFERRALS */
216
217
218 /*
219  * in search.c
220  */
221 BerElement *ldap_build_search_req( LDAP *ld, char *base, int scope,
222         char *filter, char **attrs, int attrsonly );
223
224
225 /*
226  * in unbind.c
227  */
228 int ldap_ld_free( LDAP *ld, int close );
229 int ldap_send_unbind( LDAP *ld, Sockbuf *sb );
230
231 #ifdef LDAP_DNS
232 /*
233  * in getdxbyname.c
234  */
235 char **ldap_getdxbyname( char *domain );
236 #endif /* LDAP_DNS */
237
238 #if defined( STR_TRANSLATION ) && defined( LDAP_DEFAULT_CHARSET )
239 /*
240  * in charset.c
241  *
242  * added-in this stuff so that libldap.a would build, i.e. refs to 
243  * these routines from open.c would resolve. 
244  * hodges@stanford.edu 5-Feb-96
245  */
246 #if LDAP_CHARSET_8859 == LDAP_DEFAULT_CHARSET
247 extern 
248 int ldap_t61_to_8859( char **bufp, unsigned long *buflenp, int free_input );
249 extern 
250 int ldap_8859_to_t61( char **bufp, unsigned long *buflenp, int free_input );
251 #endif /* LDAP_CHARSET_8859 == LDAP_DEFAULT_CHARSET */
252
253 LDAP_END_DECL
254 #endif /* STR_TRANSLATION && LDAP_DEFAULT_CHARSET */
255
256 #endif /* _LDAP_INT_H */