]>
Commit | Line | Data |
---|---|---|
61a2844b | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
2 | * | |
3 | * The contents of this file are subject to the Netscape Public License | |
4 | * Version 1.0 (the "NPL"); you may not use this file except in | |
5 | * compliance with the NPL. You may obtain a copy of the NPL at | |
6 | * http://www.mozilla.org/NPL/ | |
7 | * | |
8 | * Software distributed under the NPL is distributed on an "AS IS" basis, | |
9 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL | |
10 | * for the specific language governing rights and limitations under the | |
11 | * NPL. | |
12 | * | |
13 | * The Initial Developer of this code under the NPL is Netscape | |
14 | * Communications Corporation. Portions created by Netscape are | |
15 | * Copyright (C) 1998 Netscape Communications Corporation. All Rights | |
16 | * Reserved. | |
17 | */ | |
18 | #ifndef _LDAPINT_H | |
19 | #define _LDAPINT_H | |
20 | ||
21 | #include <stdio.h> | |
22 | #include <string.h> | |
23 | #include <stdlib.h> | |
24 | #include <errno.h> | |
25 | #ifdef hpux | |
26 | #include <strings.h> | |
27 | #include <time.h> | |
28 | #endif /* hpux */ | |
29 | ||
30 | #ifdef _WINDOWS | |
31 | #ifndef FD_SETSIZE | |
32 | # define FD_SETSIZE 256 /* number of connections we support */ | |
33 | #endif | |
34 | # define WIN32_LEAN_AND_MEAN | |
35 | # include <windows.h> | |
36 | # include <time.h> | |
37 | #elif defined(macintosh) | |
38 | #include "ldap-macos.h" | |
39 | # include <time.h> | |
40 | #elif defined(XP_OS2) | |
41 | #include <os2sock.h> | |
42 | #else /* _WINDOWS */ | |
43 | # include <sys/time.h> | |
44 | # include <sys/types.h> | |
45 | # include <sys/socket.h> | |
46 | # include <netinet/in.h> | |
47 | # include <netdb.h> | |
48 | #if !defined(hpux) && !defined(SUNOS4) && !defined(LINUX1_2) && !defined(LINUX2_0) | |
49 | # include <sys/select.h> | |
50 | #endif /* !defined(hpux) and others */ | |
51 | #endif /* _WINDOWS */ | |
52 | ||
53 | #if defined(BSDI) || defined(LINUX1_2) || defined(SNI) || defined(IRIX) | |
54 | #include <arpa/inet.h> | |
55 | #endif /* BSDI */ | |
56 | ||
57 | #if defined(IRIX) | |
58 | #include <bstring.h> | |
59 | #endif /* IRIX */ | |
60 | ||
61 | #include "lber-int.h" | |
62 | #include "ldap.h" | |
63 | #include "ldaprot.h" | |
64 | #include "ldaplog.h" | |
65 | #include "portable.h" | |
66 | ||
67 | #ifdef LDAP_ASYNC_IO | |
68 | #ifdef NEED_FILIO | |
69 | #include <sys/filio.h> /* to get FIONBIO for ioctl() call */ | |
70 | #else /* NEED_FILIO */ | |
71 | #include <sys/ioctl.h> /* to get FIONBIO for ioctl() call */ | |
72 | #endif /* NEED_FILIO */ | |
73 | #endif /* LDAP_ASYNC_IO */ | |
74 | ||
75 | #ifdef USE_SYSCONF | |
76 | # include <unistd.h> | |
77 | #endif /* USE_SYSCONF */ | |
78 | ||
79 | #if !defined(_WINDOWS) && !defined(macintosh) && !defined(LINUX2_0) | |
80 | #define NSLDAPI_HAVE_POLL 1 | |
81 | #endif | |
82 | ||
83 | /* SSL version, or 0 if not built with SSL */ | |
84 | #if defined(NET_SSL) | |
85 | # define SSL_VERSION 3 | |
86 | #else | |
87 | # define SSL_VERSION 0 | |
88 | #endif | |
89 | ||
90 | #define LDAP_URL_URLCOLON "URL:" | |
91 | #define LDAP_URL_URLCOLON_LEN 4 | |
92 | ||
93 | #define LDAP_LDAP_REF_STR LDAP_URL_PREFIX | |
94 | #define LDAP_LDAP_REF_STR_LEN LDAP_URL_PREFIX_LEN | |
95 | #define LDAP_LDAPS_REF_STR LDAPS_URL_PREFIX | |
96 | #define LDAP_LDAPS_REF_STR_LEN LDAPS_URL_PREFIX_LEN | |
97 | ||
98 | /* default limit on nesting of referrals */ | |
99 | #define LDAP_DEFAULT_REFHOPLIMIT 5 | |
100 | #ifdef LDAP_DNS | |
101 | #define LDAP_DX_REF_STR "dx://" | |
102 | #define LDAP_DX_REF_STR_LEN 5 | |
103 | #endif /* LDAP_DNS */ | |
104 | ||
105 | typedef enum { LDAP_CACHE_LOCK, LDAP_MEMCACHE_LOCK, LDAP_MSGID_LOCK, | |
106 | LDAP_REQ_LOCK, LDAP_RESP_LOCK, LDAP_ABANDON_LOCK, LDAP_CTRL_LOCK, | |
107 | LDAP_OPTION_LOCK, LDAP_ERR_LOCK, LDAP_CONN_LOCK, LDAP_SELECT_LOCK, | |
108 | LDAP_RESULT_LOCK, LDAP_PEND_LOCK, LDAP_MAX_LOCK } LDAPLock; | |
109 | ||
110 | /* | |
111 | * This structure represents both ldap messages and ldap responses. | |
112 | * These are really the same, except in the case of search responses, | |
113 | * where a response has multiple messages. | |
114 | */ | |
115 | ||
116 | struct ldapmsg { | |
117 | int lm_msgid; /* the message id */ | |
118 | int lm_msgtype; /* the message type */ | |
119 | BerElement *lm_ber; /* the ber encoded message contents */ | |
120 | struct ldapmsg *lm_chain; /* for search - next msg in the resp */ | |
121 | struct ldapmsg *lm_next; /* next response */ | |
122 | int lm_fromcache; /* memcache: origin of message */ | |
123 | }; | |
124 | ||
125 | /* | |
126 | * structure for tracking LDAP server host, ports, DNs, etc. | |
127 | */ | |
128 | typedef struct ldap_server { | |
129 | char *lsrv_host; | |
130 | char *lsrv_dn; /* if NULL, use default */ | |
131 | int lsrv_port; | |
132 | unsigned long lsrv_options; /* boolean options */ | |
133 | #define LDAP_SRV_OPT_SECURE 0x01 | |
134 | struct ldap_server *lsrv_next; | |
135 | } LDAPServer; | |
136 | ||
137 | /* | |
138 | * structure for representing an LDAP server connection | |
139 | */ | |
140 | typedef struct ldap_conn { | |
141 | Sockbuf *lconn_sb; | |
142 | BerElement *lconn_ber; /* non-NULL if in midst of msg. */ | |
143 | int lconn_version; /* LDAP protocol version */ | |
144 | int lconn_refcnt; | |
145 | unsigned long lconn_lastused; /* time */ | |
146 | int lconn_status; | |
147 | #define LDAP_CONNST_NEEDSOCKET 1 | |
148 | #define LDAP_CONNST_CONNECTING 2 | |
149 | #define LDAP_CONNST_CONNECTED 3 | |
150 | #define LDAP_CONNST_DEAD 4 | |
151 | LDAPServer *lconn_server; | |
152 | char *lconn_binddn; /* DN of last successful bind */ | |
153 | int lconn_bound; /* has a bind been done? */ | |
154 | char *lconn_krbinstance; | |
155 | struct ldap_conn *lconn_next; | |
156 | } LDAPConn; | |
157 | ||
158 | ||
159 | /* | |
160 | * structure used to track outstanding requests | |
161 | */ | |
162 | typedef struct ldapreq { | |
163 | int lr_msgid; /* the message id */ | |
164 | int lr_status; /* status of request */ | |
165 | #define LDAP_REQST_INPROGRESS 1 | |
166 | #define LDAP_REQST_CHASINGREFS 2 | |
167 | #define LDAP_REQST_NOTCONNECTED 3 | |
168 | #define LDAP_REQST_WRITING 4 | |
169 | #define LDAP_REQST_CONNDEAD 5 /* associated conn. has failed */ | |
170 | int lr_outrefcnt; /* count of outstanding referrals */ | |
171 | int lr_origid; /* original request's message id */ | |
172 | int lr_parentcnt; /* count of parent requests */ | |
173 | int lr_res_msgtype; /* result message type */ | |
174 | int lr_res_errno; /* result LDAP errno */ | |
175 | char *lr_res_error; /* result error string */ | |
176 | char *lr_res_matched;/* result matched DN string */ | |
177 | BerElement *lr_ber; /* ber encoded request contents */ | |
178 | LDAPConn *lr_conn; /* connection used to send request */ | |
179 | char *lr_binddn; /* request is a bind for this DN */ | |
180 | struct ldapreq *lr_parent; /* request that spawned this referral */ | |
181 | struct ldapreq *lr_refnext; /* next referral spawned */ | |
182 | struct ldapreq *lr_prev; /* previous request */ | |
183 | struct ldapreq *lr_next; /* next request */ | |
184 | } LDAPRequest; | |
185 | ||
186 | typedef struct ldappend { | |
187 | void *lp_sema; /* semaphore to post */ | |
188 | int lp_msgid; /* message id */ | |
189 | LDAPMessage *lp_result; /* result storage */ | |
190 | struct ldappend *lp_prev; /* previous pending */ | |
191 | struct ldappend *lp_next; /* next pending */ | |
192 | } LDAPPend; | |
193 | ||
194 | /* | |
195 | * structure representing an ldap connection | |
196 | */ | |
197 | struct ldap { | |
198 | struct sockbuf *ld_sbp; /* pointer to socket desc. & buffer */ | |
199 | char *ld_host; | |
200 | int ld_version; /* LDAP protocol version */ | |
201 | char ld_lberoptions; | |
202 | int ld_deref; | |
203 | ||
204 | int ld_timelimit; | |
205 | int ld_sizelimit; | |
206 | ||
207 | struct ldap_filt_desc *ld_filtd; /* from getfilter for ufn searches */ | |
208 | char *ld_ufnprefix; /* for incomplete ufn's */ | |
209 | ||
210 | int ld_errno; | |
211 | char *ld_error; | |
212 | char *ld_matched; | |
213 | int ld_msgid; | |
214 | ||
215 | /* do not mess with these */ | |
216 | LDAPRequest *ld_requests; /* list of outstanding requests */ | |
217 | LDAPMessage *ld_responses; /* list of outstanding responses */ | |
218 | int *ld_abandoned; /* array of abandoned requests */ | |
219 | char *ld_cldapdn; /* DN used in connectionless search */ | |
220 | ||
221 | /* it is OK to change these next four values directly */ | |
222 | int ld_cldaptries; /* connectionless search retry count */ | |
223 | int ld_cldaptimeout;/* time between retries */ | |
224 | int ld_refhoplimit; /* limit on referral nesting */ | |
225 | unsigned long ld_options; /* boolean options */ | |
226 | #define LDAP_BITOPT_REFERRALS 0x80000000 | |
227 | #define LDAP_BITOPT_SSL 0x40000000 | |
228 | #define LDAP_BITOPT_DNS 0x20000000 | |
229 | #define LDAP_BITOPT_RESTART 0x10000000 | |
230 | #define LDAP_BITOPT_RECONNECT 0x08000000 | |
231 | #define LDAP_BITOPT_ASYNC 0x04000000 | |
232 | ||
233 | /* do not mess with the rest though */ | |
234 | char *ld_defhost; /* full name of default server */ | |
235 | int ld_defport; /* port of default server */ | |
236 | BERTranslateProc ld_lber_encode_translate_proc; | |
237 | BERTranslateProc ld_lber_decode_translate_proc; | |
238 | LDAPConn *ld_defconn; /* default connection */ | |
239 | LDAPConn *ld_conns; /* list of all server connections */ | |
240 | void *ld_selectinfo; /* platform specifics for select */ | |
241 | int ld_selectreadcnt; /* count of read sockets */ | |
242 | int ld_selectwritecnt; /* count of write sockets */ | |
243 | LDAP_REBINDPROC_CALLBACK *ld_rebind_fn; | |
244 | void *ld_rebind_arg; | |
245 | ||
246 | /* function pointers, etc. for io */ | |
247 | struct ldap_io_fns ld_io; | |
248 | #define ld_read_fn ld_io.liof_read | |
249 | #define ld_write_fn ld_io.liof_write | |
250 | #define ld_select_fn ld_io.liof_select | |
251 | #define ld_socket_fn ld_io.liof_socket | |
252 | #define ld_ioctl_fn ld_io.liof_ioctl | |
253 | #define ld_connect_fn ld_io.liof_connect | |
254 | #define ld_close_fn ld_io.liof_close | |
255 | #define ld_ssl_enable_fn ld_io.liof_ssl_enable | |
256 | ||
257 | /* function pointers, etc. for DNS */ | |
258 | struct ldap_dns_fns ld_dnsfn; | |
259 | #define ld_dns_extradata ld_dnsfn.lddnsfn_extradata | |
260 | #define ld_dns_bufsize ld_dnsfn.lddnsfn_bufsize | |
261 | #define ld_dns_gethostbyname_fn ld_dnsfn.lddnsfn_gethostbyname | |
262 | #define ld_dns_gethostbyaddr_fn ld_dnsfn.lddnsfn_gethostbyaddr | |
263 | ||
264 | /* function pointers, etc. for threading */ | |
265 | struct ldap_thread_fns ld_thread; | |
266 | #define ld_mutex_alloc_fn ld_thread.ltf_mutex_alloc | |
267 | #define ld_mutex_free_fn ld_thread.ltf_mutex_free | |
268 | #define ld_mutex_lock_fn ld_thread.ltf_mutex_lock | |
269 | #define ld_mutex_unlock_fn ld_thread.ltf_mutex_unlock | |
270 | #define ld_get_errno_fn ld_thread.ltf_get_errno | |
271 | #define ld_set_errno_fn ld_thread.ltf_set_errno | |
272 | #define ld_get_lderrno_fn ld_thread.ltf_get_lderrno | |
273 | #define ld_set_lderrno_fn ld_thread.ltf_set_lderrno | |
274 | #define ld_lderrno_arg ld_thread.ltf_lderrno_arg | |
275 | void **ld_mutex; | |
276 | ||
277 | /* function pointers, etc. for caching */ | |
278 | int ld_cache_on; | |
279 | int ld_cache_strategy; | |
280 | struct ldap_cache_fns ld_cache; | |
281 | #define ld_cache_config ld_cache.lcf_config | |
282 | #define ld_cache_bind ld_cache.lcf_bind | |
283 | #define ld_cache_unbind ld_cache.lcf_unbind | |
284 | #define ld_cache_search ld_cache.lcf_search | |
285 | #define ld_cache_compare ld_cache.lcf_compare | |
286 | #define ld_cache_add ld_cache.lcf_add | |
287 | #define ld_cache_delete ld_cache.lcf_delete | |
288 | #if 0 | |
289 | #define ld_cache_rename ld_cache.lcf_rename | |
290 | #endif | |
291 | #define ld_cache_modify ld_cache.lcf_modify | |
292 | #define ld_cache_modrdn ld_cache.lcf_modrdn | |
293 | #define ld_cache_abandon ld_cache.lcf_abandon | |
294 | #define ld_cache_result ld_cache.lcf_result | |
295 | #define ld_cache_flush ld_cache.lcf_flush | |
296 | #define ld_cache_arg ld_cache.lcf_arg | |
297 | ||
298 | /* ldapv3 controls */ | |
299 | LDAPControl **ld_servercontrols; | |
300 | LDAPControl **ld_clientcontrols; | |
301 | ||
302 | /* Preferred language */ | |
303 | char *ld_preferred_language; | |
304 | ||
305 | /* MemCache */ | |
306 | LDAPMemCache *ld_memcache; | |
307 | ||
308 | /* Pending results */ | |
309 | LDAPPend *ld_pend; /* list of pending results */ | |
310 | ||
311 | /* extra thread function pointers */ | |
312 | struct ldap_extra_thread_fns ld_thread2; | |
313 | #define ld_mutex_trylock_fn ld_thread2.ltf_mutex_trylock | |
314 | #define ld_sema_alloc_fn ld_thread2.ltf_sema_alloc | |
315 | #define ld_sema_free_fn ld_thread2.ltf_sema_free | |
316 | #define ld_sema_wait_fn ld_thread2.ltf_sema_wait | |
317 | #define ld_sema_post_fn ld_thread2.ltf_sema_post | |
318 | }; | |
319 | ||
320 | /* allocate/free mutex */ | |
321 | #define LDAP_MUTEX_ALLOC( ld ) \ | |
322 | (((ld)->ld_mutex_alloc_fn != NULL) ? (ld)->ld_mutex_alloc_fn() : NULL) | |
323 | ||
324 | /* allocate/free mutex */ | |
325 | #define LDAP_MUTEX_FREE( ld, m ) \ | |
326 | if ( (ld)->ld_mutex_free_fn != NULL && m != NULL ) { \ | |
327 | (ld)->ld_mutex_free_fn( m ); \ | |
328 | } | |
329 | ||
330 | /* enter/exit critical sections */ | |
331 | #define LDAP_MUTEX_TRYLOCK( ld, i ) \ | |
332 | ( (ld)->ld_mutex_trylock_fn == NULL ) ? 0 : \ | |
333 | (ld)->ld_mutex_trylock_fn( (ld)->ld_mutex[i] ) | |
334 | #define LDAP_MUTEX_LOCK( ld, i ) \ | |
335 | if ( (ld)->ld_mutex_lock_fn != NULL ) { \ | |
336 | (ld)->ld_mutex_lock_fn( (ld)->ld_mutex[i] ); \ | |
337 | } | |
338 | #define LDAP_MUTEX_UNLOCK( ld, i ) \ | |
339 | if ( (ld)->ld_mutex_unlock_fn != NULL ) { \ | |
340 | (ld)->ld_mutex_unlock_fn( (ld)->ld_mutex[i] ); \ | |
341 | } | |
342 | ||
343 | /* Backword compatibility locks */ | |
344 | #define LDAP_MUTEX_BC_LOCK( ld, i ) \ | |
345 | if( (ld)->ld_mutex_trylock_fn == NULL ) { \ | |
346 | if ( (ld)->ld_mutex_lock_fn != NULL ) { \ | |
347 | (ld)->ld_mutex_lock_fn( (ld)->ld_mutex[i] ); \ | |
348 | } \ | |
349 | } | |
350 | #define LDAP_MUTEX_BC_UNLOCK( ld, i ) \ | |
351 | if( (ld)->ld_mutex_trylock_fn == NULL ) { \ | |
352 | if ( (ld)->ld_mutex_unlock_fn != NULL ) { \ | |
353 | (ld)->ld_mutex_unlock_fn( (ld)->ld_mutex[i] ); \ | |
354 | } \ | |
355 | } | |
356 | ||
357 | /* allocate/free semaphore */ | |
358 | #define LDAP_SEMA_ALLOC( ld ) \ | |
359 | (((ld)->ld_sema_alloc_fn != NULL) ? (ld)->ld_sema_alloc_fn() : NULL) | |
360 | #define LDAP_SEMA_FREE( ld, m ) \ | |
361 | if ( (ld)->ld_sema_free_fn != NULL && m != NULL ) { \ | |
362 | (ld)->ld_sema_free_fn( m ); \ | |
363 | } | |
364 | ||
365 | /* wait/post binary semaphore */ | |
366 | #define LDAP_SEMA_WAIT( ld, lp ) \ | |
367 | if ( (ld)->ld_sema_wait_fn != NULL ) { \ | |
368 | (ld)->ld_sema_wait_fn( lp->lp_sema ); \ | |
369 | } | |
370 | #define LDAP_SEMA_POST( ld, lp ) \ | |
371 | if ( (ld)->ld_sema_post_fn != NULL ) { \ | |
372 | (ld)->ld_sema_post_fn( lp->lp_sema ); \ | |
373 | } | |
374 | #define POST( ld, y, z ) \ | |
375 | if( (ld)->ld_mutex_trylock_fn != NULL ) { \ | |
376 | nsldapi_post_result( ld, y, z ); \ | |
377 | } | |
378 | ||
379 | /* get/set errno */ | |
380 | #ifndef macintosh | |
381 | #define LDAP_SET_ERRNO( ld, e ) \ | |
382 | if ( (ld)->ld_set_errno_fn != NULL ) { \ | |
383 | (ld)->ld_set_errno_fn( e ); \ | |
384 | } else { \ | |
385 | errno = e; \ | |
386 | } | |
387 | #define LDAP_GET_ERRNO( ld ) \ | |
388 | (((ld)->ld_get_errno_fn != NULL) ? \ | |
389 | (ld)->ld_get_errno_fn() : errno) | |
390 | #else /* macintosh */ | |
391 | #define LDAP_SET_ERRNO( ld, e ) \ | |
392 | if ( (ld)->ld_set_errno_fn != NULL ) { \ | |
393 | (ld)->ld_set_errno_fn( e ); \ | |
394 | } | |
395 | #define LDAP_GET_ERRNO( ld ) \ | |
396 | (((ld)->ld_get_errno_fn != NULL) ? \ | |
397 | (ld)->ld_get_errno_fn() : 0) | |
398 | #endif | |
399 | ||
400 | ||
401 | /* get/set ldap-specific errno */ | |
402 | #define LDAP_SET_LDERRNO( ld, e, m, s ) ldap_set_lderrno( ld, e, m, s ) | |
403 | #define LDAP_GET_LDERRNO( ld, m, s ) ldap_get_lderrno( ld, m, s ) | |
404 | ||
405 | /* | |
406 | * your standard "mimimum of two values" macro | |
407 | */ | |
408 | #define NSLDAPI_MIN(a, b) (((a) < (b)) ? (a) : (b)) | |
409 | ||
410 | /* | |
411 | * handy macro to check whether LDAP struct is set up for CLDAP or not | |
412 | */ | |
413 | #define LDAP_IS_CLDAP( ld ) ( ld->ld_sbp->sb_naddr > 0 ) | |
414 | ||
415 | /* | |
416 | * handy macro to check errno "e" for an "in progress" sort of error | |
417 | */ | |
418 | #if defined(macintosh) || defined(_WINDOWS) | |
419 | #define NSLDAPI_ERRNO_IO_INPROGRESS( e ) ((e) == EWOULDBLOCK || (e) == EAGAIN) | |
420 | #else | |
421 | #ifdef EAGAIN | |
422 | #define NSLDAPI_ERRNO_IO_INPROGRESS( e ) ((e) == EWOULDBLOCK || (e) == EINPROGRESS || (e) == EAGAIN) | |
423 | #else /* EAGAIN */ | |
424 | #define NSLDAPI_ERRNO_IO_INPROGRESS( e ) ((e) == EWOULDBLOCK || (e) == EINPROGRESS) | |
425 | #endif /* EAGAIN */ | |
426 | #endif /* macintosh || _WINDOWS*/ | |
427 | ||
428 | /* | |
429 | * macro to return the LDAP protocol version we are using | |
430 | */ | |
431 | #define NSLDAPI_LDAP_VERSION( ld ) ( (ld)->ld_defconn == NULL ? \ | |
432 | (ld)->ld_version : \ | |
433 | (ld)->ld_defconn->lconn_version ) | |
434 | ||
435 | /* | |
436 | * Structures used for handling client filter lists. | |
437 | */ | |
438 | #define LDAP_FILT_MAXSIZ 1024 | |
439 | ||
440 | struct ldap_filt_list { | |
441 | char *lfl_tag; | |
442 | char *lfl_pattern; | |
443 | char *lfl_delims; | |
444 | struct ldap_filt_info *lfl_ilist; | |
445 | struct ldap_filt_list *lfl_next; | |
446 | }; | |
447 | ||
448 | struct ldap_filt_desc { | |
449 | LDAPFiltList *lfd_filtlist; | |
450 | LDAPFiltInfo *lfd_curfip; | |
451 | LDAPFiltInfo lfd_retfi; | |
452 | char lfd_filter[ LDAP_FILT_MAXSIZ ]; | |
453 | char *lfd_curval; | |
454 | char *lfd_curvalcopy; | |
455 | char **lfd_curvalwords; | |
456 | char *lfd_filtprefix; | |
457 | char *lfd_filtsuffix; | |
458 | }; | |
459 | ||
460 | /* | |
461 | * "internal" globals used to track defaults and memory allocation callbacks: | |
462 | * (the actual definitions are in open.c) | |
463 | */ | |
464 | extern struct ldap nsldapi_ld_defaults; | |
465 | extern struct ldap_memalloc_fns nsldapi_memalloc_fns; | |
466 | extern int nsldapi_initialized; | |
467 | ||
468 | ||
469 | /* | |
470 | * Memory allocation done in liblber should all go through one of the | |
471 | * following macros. This is so we can plug-in alternative memory | |
472 | * allocators, etc. as the need arises. | |
473 | */ | |
474 | #define NSLDAPI_MALLOC( size ) ldap_x_malloc( size ) | |
475 | #define NSLDAPI_CALLOC( nelem, elsize ) nsldapi_calloc( nelem, elsize ) | |
476 | #define NSLDAPI_REALLOC( ptr, size ) nsldapi_realloc( ptr, size ) | |
477 | #define NSLDAPI_FREE( ptr ) ldap_x_free( ptr ) | |
478 | ||
479 | ||
480 | /* | |
481 | * macros used to check validity of data structures and parameters | |
482 | */ | |
483 | #define NSLDAPI_VALID_LDAP_POINTER( ld ) \ | |
484 | ( (ld) != NULL ) | |
485 | ||
486 | #define NSLDAPI_VALID_LDAPMESSAGE_POINTER( lm ) \ | |
487 | ( (lm) != NULL ) | |
488 | ||
489 | #define NSLDAPI_VALID_LDAPMESSAGE_ENTRY_POINTER( lm ) \ | |
490 | ( (lm) != NULL && (lm)->lm_msgtype == LDAP_RES_SEARCH_ENTRY ) | |
491 | ||
492 | #define NSLDAPI_VALID_LDAPMESSAGE_REFERENCE_POINTER( lm ) \ | |
493 | ( (lm) != NULL && (lm)->lm_msgtype == LDAP_RES_SEARCH_REFERENCE ) | |
494 | ||
495 | #define NSLDAPI_VALID_LDAPMESSAGE_BINDRESULT_POINTER( lm ) \ | |
496 | ( (lm) != NULL && (lm)->lm_msgtype == LDAP_RES_BIND ) | |
497 | ||
498 | #define NSLDAPI_VALID_LDAPMESSAGE_EXRESULT_POINTER( lm ) \ | |
499 | ( (lm) != NULL && (lm)->lm_msgtype == LDAP_RES_EXTENDED ) | |
500 | ||
501 | #define NSLDAPI_VALID_LDAPMOD_ARRAY( mods ) \ | |
502 | ( (mods) != NULL ) | |
503 | ||
504 | #define NSLDAPI_VALID_NONEMPTY_LDAPMOD_ARRAY( mods ) \ | |
505 | ( (mods) != NULL && (mods)[0] != NULL ) | |
506 | ||
507 | #define NSLDAPI_IS_SEARCH_ENTRY( code ) \ | |
508 | ((code) == LDAP_RES_SEARCH_ENTRY) | |
509 | ||
510 | #define NSLDAPI_IS_SEARCH_RESULT( code ) \ | |
511 | ((code) == LDAP_RES_SEARCH_RESULT) | |
512 | ||
513 | #define NSLDAPI_SEARCH_RELATED_RESULT( code ) \ | |
514 | (NSLDAPI_IS_SEARCH_RESULT( code ) || NSLDAPI_IS_SEARCH_ENTRY( code )) | |
515 | ||
516 | /* | |
517 | * in bind.c | |
518 | */ | |
519 | char *nsldapi_get_binddn( LDAP *ld ); | |
520 | ||
521 | /* | |
522 | * in cache.c | |
523 | */ | |
524 | void nsldapi_add_result_to_cache( LDAP *ld, LDAPMessage *result ); | |
525 | ||
526 | /* | |
527 | * in dsparse.c | |
528 | */ | |
529 | int nsldapi_next_line_tokens( char **bufp, long *blenp, char ***toksp ); | |
530 | void nsldapi_free_strarray( char **sap ); | |
531 | ||
532 | /* | |
533 | * in error.c | |
534 | */ | |
535 | int nsldapi_parse_result( LDAP *ld, int msgtype, BerElement *rber, | |
536 | int *errcodep, char **matchednp, char **errmsgp, char ***referralsp, | |
537 | LDAPControl ***serverctrlsp ); | |
538 | ||
539 | /* | |
540 | * in open.c | |
541 | */ | |
542 | void nsldapi_initialize_defaults( void ); | |
543 | int nsldapi_open_ldap_connection( LDAP *ld, Sockbuf *sb, char *host, | |
544 | int defport, char **krbinstancep, int async, int secure ); | |
545 | int nsldapi_open_ldap_defconn( LDAP *ld ); | |
546 | void *nsldapi_malloc( size_t size ); | |
547 | void *nsldapi_calloc( size_t nelem, size_t elsize ); | |
548 | void *nsldapi_realloc( void *ptr, size_t size ); | |
549 | void nsldapi_free( void *ptr ); | |
550 | char *nsldapi_strdup( const char *s ); | |
551 | ||
552 | /* | |
553 | * in os-ip.c | |
554 | */ | |
555 | int nsldapi_connect_to_host( LDAP *ld, Sockbuf *sb, char *host, | |
556 | unsigned long address, int port, int async, int secure ); | |
557 | void nsldapi_close_connection( LDAP *ld, Sockbuf *sb ); | |
558 | ||
559 | int nsldapi_do_ldap_select( LDAP *ld, struct timeval *timeout ); | |
560 | void *nsldapi_new_select_info( void ); | |
561 | void nsldapi_free_select_info( void *vsip ); | |
562 | void nsldapi_mark_select_write( LDAP *ld, Sockbuf *sb ); | |
563 | void nsldapi_mark_select_read( LDAP *ld, Sockbuf *sb ); | |
564 | void nsldapi_mark_select_clear( LDAP *ld, Sockbuf *sb ); | |
565 | int nsldapi_is_read_ready( LDAP *ld, Sockbuf *sb ); | |
566 | int nsldapi_is_write_ready( LDAP *ld, Sockbuf *sb ); | |
567 | ||
568 | /* | |
569 | * if referral.c | |
570 | */ | |
571 | int nsldapi_parse_reference( LDAP *ld, BerElement *rber, char ***referralsp, | |
572 | LDAPControl ***serverctrlsp ); | |
573 | ||
574 | ||
575 | /* | |
576 | * in result.c | |
577 | */ | |
578 | int ldap_msgdelete( LDAP *ld, int msgid ); | |
579 | int nsldapi_result_nolock( LDAP *ld, int msgid, int all, int unlock_permitted, | |
580 | struct timeval *timeout, LDAPMessage **result ); | |
581 | int nsldapi_wait_result( LDAP *ld, int msgid, int all, struct timeval *timeout, | |
582 | LDAPMessage **result ); | |
583 | int nsldapi_post_result( LDAP *ld, int msgid, LDAPMessage *result ); | |
584 | ||
585 | /* | |
586 | * in request.c | |
587 | */ | |
588 | int nsldapi_send_initial_request( LDAP *ld, int msgid, unsigned long msgtype, | |
589 | char *dn, BerElement *ber ); | |
590 | int nsldapi_alloc_ber_with_options( LDAP *ld, BerElement **berp ); | |
591 | void nsldapi_set_ber_options( LDAP *ld, BerElement *ber ); | |
592 | int nsldapi_ber_flush( LDAP *ld, Sockbuf *sb, BerElement *ber, int freeit, | |
593 | int async ); | |
594 | int nsldapi_send_server_request( LDAP *ld, BerElement *ber, int msgid, | |
595 | LDAPRequest *parentreq, LDAPServer *srvlist, LDAPConn *lc, | |
596 | char *bindreqdn, int bind ); | |
597 | LDAPConn *nsldapi_new_connection( LDAP *ld, LDAPServer **srvlistp, int use_ldsb, | |
598 | int connect, int bind ); | |
599 | LDAPRequest *nsldapi_find_request_by_msgid( LDAP *ld, int msgid ); | |
600 | void nsldapi_free_request( LDAP *ld, LDAPRequest *lr, int free_conn ); | |
601 | void nsldapi_free_connection( LDAP *ld, LDAPConn *lc, int force, int unbind ); | |
602 | void nsldapi_dump_connection( LDAP *ld, LDAPConn *lconns, int all ); | |
603 | void nsldapi_dump_requests_and_responses( LDAP *ld ); | |
604 | int nsldapi_chase_v2_referrals( LDAP *ld, LDAPRequest *lr, char **errstrp, | |
605 | int *totalcountp, int *chasingcountp ); | |
606 | int nsldapi_chase_v3_refs( LDAP *ld, LDAPRequest *lr, char **refs, | |
607 | int is_reference, int *totalcountp, int *chasingcountp ); | |
608 | int nsldapi_append_referral( LDAP *ld, char **referralsp, char *s ); | |
609 | void nsldapi_connection_lost_nolock( LDAP *ld, Sockbuf *sb ); | |
610 | ||
611 | /* | |
612 | * in search.c | |
613 | */ | |
614 | int ldap_build_search_req( LDAP *ld, char *base, int scope, | |
615 | char *filter, char **attrs, int attrsonly, LDAPControl **serverctrls, | |
616 | LDAPControl **clientctrls, struct timeval *timeoutp, int sizelimit, | |
617 | int msgid, BerElement **berp ); | |
618 | ||
619 | /* | |
620 | * in unbind.c | |
621 | */ | |
622 | int ldap_ld_free( LDAP *ld, int close ); | |
623 | int nsldapi_send_unbind( LDAP *ld, Sockbuf *sb ); | |
624 | ||
625 | #ifdef LDAP_DNS | |
626 | /* | |
627 | * in getdxbyname.c | |
628 | */ | |
629 | char **nsldapi_getdxbyname( char *domain ); | |
630 | ||
631 | #endif /* LDAP_DNS */ | |
632 | ||
633 | /* | |
634 | * in unescape.c | |
635 | */ | |
636 | void nsldapi_hex_unescape( char *s ); | |
637 | ||
638 | /* | |
639 | * in reslist.c | |
640 | */ | |
641 | LDAPMessage *ldap_delete_result_entry( LDAPMessage **list, LDAPMessage *e ); | |
642 | void ldap_add_result_entry( LDAPMessage **list, LDAPMessage *e ); | |
643 | ||
644 | /* | |
645 | * in compat.c | |
646 | */ | |
647 | #ifdef hpux | |
648 | char *nsldapi_compat_ctime_r( const time_t *clock, char *buf, int buflen ); | |
649 | struct hostent *nsldapi_compat_gethostbyname_r( const char *name, | |
650 | struct hostent *result, char *buffer, int buflen, int *h_errnop ); | |
651 | #endif /* hpux */ | |
652 | ||
653 | /* | |
654 | * in control.c | |
655 | */ | |
656 | int nsldapi_put_controls( LDAP *ld, LDAPControl **ctrls, int closeseq, | |
657 | BerElement *ber ); | |
658 | int nsldapi_get_controls( BerElement *ber, LDAPControl ***controlsp ); | |
659 | int nsldapi_dup_controls( LDAP *ld, LDAPControl ***ldctrls, | |
660 | LDAPControl **newctrls ); | |
661 | int nsldapi_build_control( char *oid, BerElement *ber, int freeber, | |
662 | char iscritical, LDAPControl **ctrlp ); | |
663 | ||
664 | ||
665 | /* | |
666 | * in url.c | |
667 | */ | |
668 | int nsldapi_url_parse( char *url, LDAPURLDesc **ludpp, int dn_required ); | |
669 | ||
670 | ||
671 | /* | |
672 | * in charset.c | |
673 | * | |
674 | * If we ever want to expose character set translation functionality to | |
675 | * users of libldap, all of these prototypes will need to be moved to ldap.h | |
676 | */ | |
677 | #ifdef STR_TRANSLATION | |
678 | void ldap_set_string_translators( LDAP *ld, | |
679 | BERTranslateProc encode_proc, BERTranslateProc decode_proc ); | |
680 | int ldap_translate_from_t61( LDAP *ld, char **bufp, | |
681 | unsigned long *lenp, int free_input ); | |
682 | int ldap_translate_to_t61( LDAP *ld, char **bufp, | |
683 | unsigned long *lenp, int free_input ); | |
684 | void ldap_enable_translation( LDAP *ld, LDAPMessage *entry, | |
685 | int enable ); | |
686 | #ifdef LDAP_CHARSET_8859 | |
687 | int ldap_t61_to_8859( char **bufp, unsigned long *buflenp, | |
688 | int free_input ); | |
689 | int ldap_8859_to_t61( char **bufp, unsigned long *buflenp, | |
690 | int free_input ); | |
691 | #endif /* LDAP_CHARSET_8859 */ | |
692 | #endif /* STR_TRANSLATION */ | |
693 | ||
694 | /* | |
695 | * in memcache.h | |
696 | */ | |
697 | int ldap_memcache_createkey( LDAP *ld, const char *base, int scope, | |
698 | const char *filter, char **attrs, int attrsonly, | |
699 | LDAPControl **serverctrls, LDAPControl **clientctrls, | |
700 | unsigned long *keyp ); | |
701 | int ldap_memcache_result( LDAP *ld, int msgid, unsigned long key ); | |
702 | int ldap_memcache_new( LDAP *ld, int msgid, unsigned long key, | |
703 | const char *basedn ); | |
704 | int ldap_memcache_append( LDAP *ld, int msgid, int bLast, LDAPMessage *result ); | |
705 | int ldap_memcache_abandon( LDAP *ld, int msgid ); | |
706 | ||
707 | #endif /* _LDAPINT_H */ |