Home | History | Annotate | Line # | Download | only in libldap
      1 /*	$NetBSD: ldap-int.h,v 1.4 2025/09/05 21:16:21 christos Exp $	*/
      2 
      3 /*  ldap-int.h - defines & prototypes internal to the LDAP library */
      4 /* $OpenLDAP$ */
      5 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
      6  *
      7  * Copyright 1998-2024 The OpenLDAP Foundation.
      8  * All rights reserved.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted only as authorized by the OpenLDAP
     12  * Public License.
     13  *
     14  * A copy of this license is available in the file LICENSE in the
     15  * top-level directory of the distribution or, alternatively, at
     16  * <http://www.OpenLDAP.org/license.html>.
     17  */
     18 /*  Portions Copyright (c) 1995 Regents of the University of Michigan.
     19  *  All rights reserved.
     20  */
     21 
     22 #ifndef	_LDAP_INT_H
     23 #define	_LDAP_INT_H 1
     24 
     25 #ifndef NO_THREADS
     26 #define LDAP_R_COMPILE 1
     27 #endif
     28 
     29 #include "../liblber/lber-int.h"
     30 #include "lutil.h"
     31 #include "ldap_avl.h"
     32 
     33 #ifdef LDAP_R_COMPILE
     34 #include <ldap_pvt_thread.h>
     35 #endif
     36 
     37 #ifdef HAVE_CYRUS_SASL
     38 	/* the need for this should be removed */
     39 #ifdef HAVE_SASL_SASL_H
     40 #include <sasl/sasl.h>
     41 #else
     42 #include <sasl.h>
     43 #endif
     44 
     45 #define SASL_MAX_BUFF_SIZE	(0xffffff)
     46 #define SASL_MIN_BUFF_SIZE	4096
     47 #endif
     48 
     49 /* for struct timeval */
     50 #include <ac/time.h>
     51 #include <ac/socket.h>
     52 
     53 #undef TV2MILLISEC
     54 #define TV2MILLISEC(tv) (((tv)->tv_sec * 1000) + ((tv)->tv_usec/1000))
     55 
     56 /*
     57  * Support needed if the library is running in the kernel
     58  */
     59 #if LDAP_INT_IN_KERNEL
     60 	/*
     61 	 * Platform specific function to return a pointer to the
     62 	 * process-specific global options.
     63 	 *
     64 	 * This function should perform the following functions:
     65 	 *  Allocate and initialize a global options struct on a per process basis
     66 	 *  Use callers process identifier to return its global options struct
     67 	 *  Note: Deallocate structure when the process exits
     68 	 */
     69 #	define LDAP_INT_GLOBAL_OPT() ldap_int_global_opt()
     70 	struct ldapoptions *ldap_int_global_opt(void);
     71 #else
     72 #	define LDAP_INT_GLOBAL_OPT() (&ldap_int_global_options)
     73 #endif
     74 
     75 /* if used from server code, ldap_debug already points elsewhere */
     76 #ifndef ldap_debug
     77 #define ldap_debug	((LDAP_INT_GLOBAL_OPT())->ldo_debug)
     78 #endif /* !ldap_debug */
     79 
     80 #define LDAP_INT_DEBUG
     81 #include "ldap_log.h"
     82 
     83 #ifdef LDAP_DEBUG
     84 
     85 #define DebugTest( level ) \
     86 	( ldap_debug & level )
     87 
     88 #define Debug0( level, fmt ) \
     89 	do { if ( DebugTest( (level) ) ) \
     90 	ldap_log_printf( NULL, (level), fmt ); \
     91 	} while ( 0 )
     92 
     93 #define Debug1( level, fmt, arg1 ) \
     94 	do { if ( DebugTest( (level) ) ) \
     95 	ldap_log_printf( NULL, (level), fmt, arg1 ); \
     96 	} while ( 0 )
     97 
     98 #define Debug2( level, fmt, arg1, arg2 ) \
     99 	do { if ( DebugTest( (level) ) ) \
    100 	ldap_log_printf( NULL, (level), fmt, arg1, arg2 ); \
    101 	} while ( 0 )
    102 
    103 #define Debug3( level, fmt, arg1, arg2, arg3 ) \
    104 	do { if ( DebugTest( (level) ) ) \
    105 	ldap_log_printf( NULL, (level), fmt, arg1, arg2, arg3 ); \
    106 	} while ( 0 )
    107 
    108 #else
    109 
    110 #define DebugTest( level )                                    (0 == 1)
    111 #define Debug0( level, fmt )                                  ((void)0)
    112 #define Debug1( level, fmt, arg1 )                            ((void)0)
    113 #define Debug2( level, fmt, arg1, arg2 )                      ((void)0)
    114 #define Debug3( level, fmt, arg1, arg2, arg3 )                ((void)0)
    115 
    116 #endif /* LDAP_DEBUG */
    117 
    118 #define LDAP_DEPRECATED 1
    119 #include "ldap.h"
    120 
    121 #include "ldap_pvt.h"
    122 
    123 LDAP_BEGIN_DECL
    124 
    125 #define LDAP_URL_PREFIX         "ldap://"
    126 #define LDAP_URL_PREFIX_LEN     STRLENOF(LDAP_URL_PREFIX)
    127 #define PLDAP_URL_PREFIX	"pldap://"
    128 #define PLDAP_URL_PREFIX_LEN	STRLENOF(PLDAP_URL_PREFIX)
    129 #define LDAPS_URL_PREFIX	"ldaps://"
    130 #define LDAPS_URL_PREFIX_LEN	STRLENOF(LDAPS_URL_PREFIX)
    131 #define PLDAPS_URL_PREFIX	"pldaps://"
    132 #define PLDAPS_URL_PREFIX_LEN	STRLENOF(PLDAPS_URL_PREFIX)
    133 #define LDAPI_URL_PREFIX	"ldapi://"
    134 #define LDAPI_URL_PREFIX_LEN	STRLENOF(LDAPI_URL_PREFIX)
    135 #ifdef LDAP_CONNECTIONLESS
    136 #define LDAPC_URL_PREFIX	"cldap://"
    137 #define LDAPC_URL_PREFIX_LEN	STRLENOF(LDAPC_URL_PREFIX)
    138 #endif
    139 #define LDAP_URL_URLCOLON	"URL:"
    140 #define LDAP_URL_URLCOLON_LEN	STRLENOF(LDAP_URL_URLCOLON)
    141 
    142 #define LDAP_REF_STR		"Referral:\n"
    143 #define LDAP_REF_STR_LEN	STRLENOF(LDAP_REF_STR)
    144 #define LDAP_LDAP_REF_STR	LDAP_URL_PREFIX
    145 #define LDAP_LDAP_REF_STR_LEN	LDAP_URL_PREFIX_LEN
    146 
    147 #define LDAP_DEFAULT_REFHOPLIMIT 5
    148 
    149 #define LDAP_BOOL_REFERRALS		0
    150 #define LDAP_BOOL_RESTART		1
    151 #define LDAP_BOOL_TLS			3
    152 #define	LDAP_BOOL_CONNECT_ASYNC		4
    153 #define	LDAP_BOOL_SASL_NOCANON		5
    154 #define	LDAP_BOOL_KEEPCONN		6
    155 
    156 #define LDAP_BOOLEANS	unsigned long
    157 #define LDAP_BOOL(n)	((LDAP_BOOLEANS)1 << (n))
    158 #define LDAP_BOOL_GET(lo, bool)	\
    159 	((lo)->ldo_booleans & LDAP_BOOL(bool) ? -1 : 0)
    160 #define LDAP_BOOL_SET(lo, bool) ((lo)->ldo_booleans |= LDAP_BOOL(bool))
    161 #define LDAP_BOOL_CLR(lo, bool) ((lo)->ldo_booleans &= ~LDAP_BOOL(bool))
    162 #define LDAP_BOOL_ZERO(lo) ((lo)->ldo_booleans = 0)
    163 
    164 /*
    165  * This structure represents both ldap messages and ldap responses.
    166  * These are really the same, except in the case of search responses,
    167  * where a response has multiple messages.
    168  */
    169 
    170 struct ldapmsg {
    171 	ber_int_t		lm_msgid;	/* the message id */
    172 	ber_tag_t		lm_msgtype;	/* the message type */
    173 	BerElement	*lm_ber;	/* the ber encoded message contents */
    174 	struct ldapmsg	*lm_chain;	/* for search - next msg in the resp */
    175 	struct ldapmsg	*lm_chain_tail;
    176 	struct ldapmsg	*lm_next;	/* next response */
    177 	time_t	lm_time;	/* used to maintain cache */
    178 };
    179 
    180 #ifdef HAVE_TLS
    181 struct ldaptls {
    182 	char		*lt_certfile;
    183 	char		*lt_keyfile;
    184 	char		*lt_dhfile;
    185 	char		*lt_cacertfile;
    186 	char		*lt_cacertdir;
    187 	char		*lt_ciphersuite;
    188 	char		*lt_crlfile;
    189 	char		*lt_randfile;	/* OpenSSL only */
    190 	char		*lt_ecname;		/* OpenSSL only */
    191 	int		lt_protocol_min;
    192 	int		lt_protocol_max;
    193 	struct berval	lt_cacert;
    194 	struct berval	lt_cert;
    195 	struct berval	lt_key;
    196 };
    197 #endif
    198 
    199 typedef struct ldaplist {
    200 	struct ldaplist *ll_next;
    201 	void *ll_data;
    202 } ldaplist;
    203 
    204 /*
    205  * LDAP Client Source IP structure
    206  */
    207 typedef struct ldapsourceip {
    208 	char	*local_ip_addrs;
    209 	struct in_addr	ip4_addr;
    210 	unsigned short	has_ipv4;
    211 #ifdef LDAP_PF_INET6
    212 	struct in6_addr	ip6_addr;
    213 	unsigned short	has_ipv6;
    214 #endif
    215 } ldapsourceip;
    216 
    217 /*
    218  * structure representing get/set'able options
    219  * which have global defaults.
    220  * Protect access to this struct with ldo_mutex
    221  * ldap_log.h:ldapoptions_prefix must match the head of this struct.
    222  */
    223 struct ldapoptions {
    224 	short ldo_valid;
    225 #define LDAP_UNINITIALIZED	0x0
    226 #define LDAP_INITIALIZED	0x1
    227 #define LDAP_VALID_SESSION	0x2
    228 #define LDAP_TRASHED_SESSION	0xFF
    229 	int   ldo_debug;
    230 
    231 	ber_int_t		ldo_version;
    232 	ber_int_t		ldo_deref;
    233 	ber_int_t		ldo_timelimit;
    234 	ber_int_t		ldo_sizelimit;
    235 
    236 	/* per API call timeout */
    237 	struct timeval		ldo_tm_api;
    238 	struct timeval		ldo_tm_net;
    239 
    240 	LDAPURLDesc *ldo_defludp;
    241 	int		ldo_defport;
    242 	char*	ldo_defbase;
    243 	char*	ldo_defbinddn;	/* bind dn */
    244 
    245 	/*
    246 	 * Per connection tcp-keepalive settings (Linux only,
    247 	 * ignored where unsupported)
    248 	 */
    249 	ber_int_t ldo_keepalive_idle;
    250 	ber_int_t ldo_keepalive_probes;
    251 	ber_int_t ldo_keepalive_interval;
    252 
    253 	/*
    254 	 * Per connection tcp user timeout (Linux >= 2.6.37 only,
    255 	 * ignored where unsupported)
    256 	 */
    257 	ber_uint_t ldo_tcp_user_timeout;
    258 
    259 	int		ldo_refhoplimit;	/* limit on referral nesting */
    260 
    261 	/* LDAPv3 server and client controls */
    262 	LDAPControl	**ldo_sctrls;
    263 	LDAPControl **ldo_cctrls;
    264 
    265 	/* LDAP rebind callback function */
    266 	LDAP_REBIND_PROC *ldo_rebind_proc;
    267 	void *ldo_rebind_params;
    268 	LDAP_NEXTREF_PROC *ldo_nextref_proc;
    269 	void *ldo_nextref_params;
    270 	LDAP_URLLIST_PROC *ldo_urllist_proc;
    271 	void *ldo_urllist_params;
    272 
    273 	/* LDAP connection callback stack */
    274 	ldaplist *ldo_conn_cbs;
    275 
    276 	LDAP_BOOLEANS ldo_booleans;	/* boolean options */
    277 
    278 #define LDAP_LDO_NULLARG	,0,0,0,0 ,{0},{0} ,0,0,0,0, 0,0,0,0,0, 0,0, 0,0,0,0,0,0, 0, 0
    279 
    280 	/* LDAP user configured bind IPs */
    281 	struct ldapsourceip ldo_local_ip_addrs;
    282 
    283 #ifdef LDAP_PF_INET6
    284 #define LDAP_LDO_SOURCEIP_NULLARG	,{0,0,0,0,0}
    285 #else
    286 #define LDAP_LDO_SOURCEIP_NULLARG	,{0,0,0}
    287 #endif
    288 
    289 #ifdef LDAP_CONNECTIONLESS
    290 #define	LDAP_IS_UDP(ld)		((ld)->ld_options.ldo_is_udp)
    291 	void*			ldo_peer;	/* struct sockaddr* */
    292 	char*			ldo_cldapdn;
    293 	int			ldo_is_udp;
    294 #define	LDAP_LDO_CONNECTIONLESS_NULLARG	,0,0,0
    295 #else
    296 #define	LDAP_LDO_CONNECTIONLESS_NULLARG
    297 #endif
    298 
    299 #ifdef HAVE_TLS
    300    	/* tls context */
    301    	void		*ldo_tls_ctx;
    302 	LDAP_TLS_CONNECT_CB	*ldo_tls_connect_cb;
    303 	void*			ldo_tls_connect_arg;
    304 	struct ldaptls ldo_tls_info;
    305 #define ldo_tls_certfile	ldo_tls_info.lt_certfile
    306 #define ldo_tls_keyfile	ldo_tls_info.lt_keyfile
    307 #define ldo_tls_dhfile	ldo_tls_info.lt_dhfile
    308 #define ldo_tls_ecname	ldo_tls_info.lt_ecname
    309 #define ldo_tls_cacertfile	ldo_tls_info.lt_cacertfile
    310 #define ldo_tls_cacertdir	ldo_tls_info.lt_cacertdir
    311 #define ldo_tls_ciphersuite	ldo_tls_info.lt_ciphersuite
    312 #define ldo_tls_protocol_min	ldo_tls_info.lt_protocol_min
    313 #define ldo_tls_protocol_max	ldo_tls_info.lt_protocol_max
    314 #define ldo_tls_crlfile	ldo_tls_info.lt_crlfile
    315 #define ldo_tls_randfile	ldo_tls_info.lt_randfile
    316 #define ldo_tls_cacert	ldo_tls_info.lt_cacert
    317 #define ldo_tls_cert	ldo_tls_info.lt_cert
    318 #define ldo_tls_key	ldo_tls_info.lt_key
    319    	int			ldo_tls_mode;
    320    	int			ldo_tls_require_cert;
    321 	int			ldo_tls_impl;
    322    	int			ldo_tls_crlcheck;
    323 	int			ldo_tls_require_san;
    324 	char		*ldo_tls_pin_hashalg;
    325 	struct berval	ldo_tls_pin;
    326 #define LDAP_LDO_TLS_NULLARG ,0,0,0,{0,0,0,0,0,0,0,0,0},0,0,0,0,0,0,{0,0}
    327 #else
    328 #define LDAP_LDO_TLS_NULLARG
    329 #endif
    330 
    331 #ifdef HAVE_CYRUS_SASL
    332 	char*	ldo_def_sasl_mech;		/* SASL Mechanism(s) */
    333 	char*	ldo_def_sasl_realm;		/* SASL realm */
    334 	char*	ldo_def_sasl_authcid;	/* SASL authentication identity */
    335 	char*	ldo_def_sasl_authzid;	/* SASL authorization identity */
    336 
    337 	/* SASL Security Properties */
    338 	struct sasl_security_properties	ldo_sasl_secprops;
    339 	int ldo_sasl_cbinding;
    340 #define LDAP_LDO_SASL_NULLARG ,0,0,0,0,{0},0
    341 #else
    342 #define LDAP_LDO_SASL_NULLARG
    343 #endif
    344 
    345 #ifdef HAVE_GSSAPI
    346 	unsigned ldo_gssapi_flags;
    347 #define LDAP_GSSAPI_OPT_DO_NOT_FREE_GSS_CONTEXT	0x0001
    348 #define LDAP_GSSAPI_OPT_ALLOW_REMOTE_PRINCIPAL	0x0002
    349 	unsigned ldo_gssapi_options;
    350 #define LDAP_LDO_GSSAPI_NULLARG ,0,0
    351 #else
    352 #define LDAP_LDO_GSSAPI_NULLARG
    353 #endif
    354 
    355 #ifdef LDAP_R_COMPILE
    356 	ldap_pvt_thread_mutex_t	ldo_mutex;
    357 #define LDAP_LDO_MUTEX_NULLARG	, LDAP_PVT_MUTEX_NULL
    358 #else
    359 #define LDAP_LDO_MUTEX_NULLARG
    360 #endif
    361 };
    362 
    363 
    364 /*
    365  * structure for representing an LDAP server connection
    366  */
    367 typedef struct ldap_conn {
    368 	Sockbuf		*lconn_sb;
    369 #ifdef HAVE_CYRUS_SASL
    370 	void		*lconn_sasl_authctx;	/* context for bind */
    371 	void		*lconn_sasl_sockctx;	/* for security layer */
    372 	void		*lconn_sasl_cbind;		/* for channel binding */
    373 #endif
    374 #ifdef HAVE_GSSAPI
    375 	void		*lconn_gss_ctx;		/* gss_ctx_id_t */
    376 #endif
    377 	int			lconn_refcnt;
    378 	time_t		lconn_created;	/* time */
    379 	time_t		lconn_lastused;	/* time */
    380 	int			lconn_rebind_inprogress;	/* set if rebind in progress */
    381 	char		***lconn_rebind_queue;		/* used if rebind in progress */
    382 	int			lconn_status;
    383 #define LDAP_CONNST_NEEDSOCKET		1
    384 #define LDAP_CONNST_CONNECTING		2
    385 #define LDAP_CONNST_CONNECTED		3
    386 #define LDAP_CONNST_TLS_INPROGRESS	4
    387 	LDAPURLDesc		*lconn_server;
    388 	BerElement		*lconn_ber;	/* ber receiving on this conn. */
    389 
    390 	struct ldap_conn *lconn_next;
    391 } LDAPConn;
    392 
    393 
    394 /*
    395  * structure used to track outstanding requests
    396  */
    397 typedef struct ldapreq {
    398 	ber_int_t	lr_msgid;	/* the message id */
    399 	int		lr_status;	/* status of request */
    400 #define LDAP_REQST_COMPLETED	0
    401 #define LDAP_REQST_INPROGRESS	1
    402 #define LDAP_REQST_CHASINGREFS	2
    403 #define LDAP_REQST_NOTCONNECTED	3
    404 #define LDAP_REQST_WRITING	4
    405 	int		lr_refcnt;	/* count of references */
    406 	int		lr_outrefcnt;	/* count of outstanding referrals */
    407 	int		lr_abandoned;	/* the request has been abandoned */
    408 	ber_int_t	lr_origid;	/* original request's message id */
    409 	int		lr_parentcnt;	/* count of parent requests */
    410 	ber_tag_t	lr_res_msgtype;	/* result message type */
    411 	ber_int_t	lr_res_errno;	/* result LDAP errno */
    412 	char		*lr_res_error;	/* result error string */
    413 	char		*lr_res_matched;/* result matched DN string */
    414 	BerElement	*lr_ber;	/* ber encoded request contents */
    415 	LDAPConn	*lr_conn;	/* connection used to send request */
    416 	struct berval	lr_dn;		/* DN of request, in lr_ber */
    417 	struct ldapreq	*lr_parent;	/* request that spawned this referral */
    418 	struct ldapreq	*lr_child;	/* first child request */
    419 	struct ldapreq	*lr_refnext;	/* next referral spawned */
    420 	struct ldapreq	*lr_prev;	/* previous request */
    421 	struct ldapreq	*lr_next;	/* next request */
    422 } LDAPRequest;
    423 
    424 /*
    425  * structure for client cache
    426  */
    427 #define LDAP_CACHE_BUCKETS	31	/* cache hash table size */
    428 typedef struct ldapcache {
    429 	LDAPMessage	*lc_buckets[LDAP_CACHE_BUCKETS];/* hash table */
    430 	LDAPMessage	*lc_requests;			/* unfulfilled reqs */
    431 	long		lc_timeout;			/* request timeout */
    432 	ber_len_t		lc_maxmem;			/* memory to use */
    433 	ber_len_t		lc_memused;			/* memory in use */
    434 	int		lc_enabled;			/* enabled? */
    435 	unsigned long	lc_options;			/* options */
    436 #define LDAP_CACHE_OPT_CACHENOERRS	0x00000001
    437 #define LDAP_CACHE_OPT_CACHEALLERRS	0x00000002
    438 }  LDAPCache;
    439 
    440 /*
    441  * structure containing referral request info for rebind procedure
    442  */
    443 typedef struct ldapreqinfo {
    444 	ber_len_t	ri_msgid;
    445 	int			ri_request;
    446 	char 		*ri_url;
    447 } LDAPreqinfo;
    448 
    449 /*
    450  * structure representing an ldap connection
    451  */
    452 
    453 struct ldap_common {
    454 	Sockbuf		*ldc_sb;	/* socket descriptor & buffer */
    455 #define ld_sb			ldc->ldc_sb
    456 
    457 	unsigned short	ldc_lberoptions;
    458 #define	ld_lberoptions		ldc->ldc_lberoptions
    459 
    460 	/* protected by msgid_mutex */
    461 	ber_len_t		ldc_msgid;
    462 #define	ld_msgid		ldc->ldc_msgid
    463 
    464 	/* do not mess with these */
    465 	/* protected by req_mutex */
    466 	TAvlnode	*ldc_requests;	/* list of outstanding requests */
    467 	/* protected by res_mutex */
    468 	LDAPMessage	*ldc_responses;	/* list of outstanding responses */
    469 #define	ld_requests		ldc->ldc_requests
    470 #define	ld_responses		ldc->ldc_responses
    471 
    472 	/* protected by abandon_mutex */
    473 	ber_len_t	ldc_nabandoned;
    474 	ber_int_t	*ldc_abandoned;	/* array of abandoned requests */
    475 #define	ld_nabandoned		ldc->ldc_nabandoned
    476 #define	ld_abandoned		ldc->ldc_abandoned
    477 
    478 	/* unused by libldap */
    479 	LDAPCache	*ldc_cache;	/* non-null if cache is initialized */
    480 #define	ld_cache		ldc->ldc_cache
    481 
    482 	/* do not mess with the rest though */
    483 
    484 	/* protected by conn_mutex */
    485 	LDAPConn	*ldc_defconn;	/* default connection */
    486 #define	ld_defconn		ldc->ldc_defconn
    487 	LDAPConn	*ldc_conns;	/* list of server connections */
    488 #define	ld_conns		ldc->ldc_conns
    489 	void		*ldc_selectinfo;/* platform specifics for select */
    490 #define	ld_selectinfo		ldc->ldc_selectinfo
    491 
    492 	/* ldap_common refcnt - free only if 0 */
    493 	/* protected by ldc_mutex */
    494 	unsigned int		ldc_refcnt;
    495 #define	ld_ldcrefcnt		ldc->ldc_refcnt
    496 
    497 	/* protected by ldo_mutex */
    498 	struct ldapoptions ldc_options;
    499 #define ld_options		ldc->ldc_options
    500 
    501 #define ld_valid		ld_options.ldo_valid
    502 #define ld_debug		ld_options.ldo_debug
    503 
    504 #define ld_deref		ld_options.ldo_deref
    505 #define ld_timelimit		ld_options.ldo_timelimit
    506 #define ld_sizelimit		ld_options.ldo_sizelimit
    507 
    508 #define ld_defbinddn		ld_options.ldo_defbinddn
    509 #define ld_defbase		ld_options.ldo_defbase
    510 #define ld_defhost		ld_options.ldo_defhost
    511 #define ld_defport		ld_options.ldo_defport
    512 
    513 #define ld_refhoplimit		ld_options.ldo_refhoplimit
    514 
    515 #define ld_sctrls		ld_options.ldo_sctrls
    516 #define ld_cctrls		ld_options.ldo_cctrls
    517 #define ld_rebind_proc		ld_options.ldo_rebind_proc
    518 #define ld_rebind_params	ld_options.ldo_rebind_params
    519 #define ld_nextref_proc		ld_options.ldo_nextref_proc
    520 #define ld_nextref_params	ld_options.ldo_nextref_params
    521 #define ld_urllist_proc		ld_options.ldo_urllist_proc
    522 #define ld_urllist_params	ld_options.ldo_urllist_params
    523 
    524 #define ld_version		ld_options.ldo_version
    525 
    526 #ifdef LDAP_R_COMPILE
    527 	ldap_pvt_thread_mutex_t	ldc_mutex;
    528 	ldap_pvt_thread_mutex_t	ldc_msgid_mutex;
    529 	ldap_pvt_thread_mutex_t	ldc_conn_mutex;
    530 	ldap_pvt_thread_mutex_t	ldc_req_mutex;
    531 	ldap_pvt_thread_mutex_t	ldc_res_mutex;
    532 	ldap_pvt_thread_mutex_t	ldc_abandon_mutex;
    533 #define	ld_ldopts_mutex		ld_options.ldo_mutex
    534 #define	ld_ldcmutex		ldc->ldc_mutex
    535 #define	ld_msgid_mutex		ldc->ldc_msgid_mutex
    536 #define	ld_conn_mutex		ldc->ldc_conn_mutex
    537 #define	ld_req_mutex		ldc->ldc_req_mutex
    538 #define	ld_res_mutex		ldc->ldc_res_mutex
    539 #define	ld_abandon_mutex	ldc->ldc_abandon_mutex
    540 #endif
    541 };
    542 
    543 struct ldap {
    544 	/* thread shared */
    545 	struct ldap_common	*ldc;
    546 
    547 	/* thread specific */
    548 	ber_int_t		ld_errno;
    549 	char			*ld_error;
    550 	char			*ld_matched;
    551 	char			**ld_referrals;
    552 };
    553 
    554 #define LDAP_VALID(ld)		( (ld)->ld_valid == LDAP_VALID_SESSION )
    555 #define LDAP_TRASHED(ld)	( (ld)->ld_valid == LDAP_TRASHED_SESSION )
    556 #define LDAP_TRASH(ld)		( (ld)->ld_valid = LDAP_TRASHED_SESSION )
    557 
    558 #ifdef LDAP_R_COMPILE
    559 LDAP_V ( ldap_pvt_thread_mutex_t ) ldap_int_resolv_mutex;
    560 LDAP_V ( ldap_pvt_thread_mutex_t ) ldap_int_hostname_mutex;
    561 LDAP_V ( int ) ldap_int_stackguard;
    562 
    563 #ifdef HAVE_GSSAPI
    564 LDAP_V( ldap_pvt_thread_mutex_t ) ldap_int_gssapi_mutex;
    565 #endif
    566 #endif
    567 
    568 #ifdef LDAP_R_COMPILE
    569 #define LDAP_MUTEX_LOCK(mutex)    ldap_pvt_thread_mutex_lock( mutex )
    570 #define LDAP_MUTEX_UNLOCK(mutex)  ldap_pvt_thread_mutex_unlock( mutex )
    571 #define LDAP_ASSERT_MUTEX_OWNER(mutex) \
    572 	LDAP_PVT_THREAD_ASSERT_MUTEX_OWNER(mutex)
    573 #else
    574 #define LDAP_MUTEX_LOCK(mutex)    ((void) 0)
    575 #define LDAP_MUTEX_UNLOCK(mutex)  ((void) 0)
    576 #define LDAP_ASSERT_MUTEX_OWNER(mutex) ((void) 0)
    577 #endif
    578 
    579 #define	LDAP_NEXT_MSGID(ld, id) do { \
    580 	LDAP_MUTEX_LOCK( &(ld)->ld_msgid_mutex ); \
    581 	(id) = ++(ld)->ld_msgid; \
    582 	LDAP_MUTEX_UNLOCK( &(ld)->ld_msgid_mutex ); \
    583 } while (0)
    584 
    585 /*
    586  * in abandon.c
    587  */
    588 
    589 LDAP_F (int)
    590 ldap_int_bisect_find( ber_int_t *v, ber_len_t n, ber_int_t id, int *idxp );
    591 LDAP_F (int)
    592 ldap_int_bisect_insert( ber_int_t **vp, ber_len_t *np, int id, int idx );
    593 LDAP_F (int)
    594 ldap_int_bisect_delete( ber_int_t **vp, ber_len_t *np, int id, int idx );
    595 
    596 /*
    597  * in add.c
    598  */
    599 
    600 LDAP_F (BerElement *) ldap_build_add_req LDAP_P((
    601 	LDAP *ld,
    602 	const char *dn,
    603 	LDAPMod **attrs,
    604 	LDAPControl **sctrls,
    605 	LDAPControl **cctrls,
    606 	ber_int_t *msgidp ));
    607 
    608 /*
    609  * in lbase64.c
    610  */
    611 
    612 LDAP_F (int) ldap_int_decode_b64_inplace LDAP_P((
    613 	struct berval *value ));
    614 
    615 /*
    616  * in compare.c
    617  */
    618 
    619 LDAP_F (BerElement *) ldap_build_compare_req LDAP_P((
    620 	LDAP *ld,
    621 	const char *dn,
    622 	const char *attr,
    623 	struct berval *bvalue,
    624 	LDAPControl **sctrls,
    625 	LDAPControl **cctrls,
    626 	ber_int_t *msgidp ));
    627 
    628 /*
    629  * in delete.c
    630  */
    631 
    632 LDAP_F (BerElement *) ldap_build_delete_req LDAP_P((
    633 	LDAP *ld,
    634 	const char *dn,
    635 	LDAPControl **sctrls,
    636 	LDAPControl **cctrls,
    637 	ber_int_t *msgidp ));
    638 
    639 /*
    640  * in extended.c
    641  */
    642 
    643 LDAP_F (BerElement *) ldap_build_extended_req LDAP_P((
    644 	LDAP *ld,
    645 	const char *reqoid,
    646 	struct berval *reqdata,
    647 	LDAPControl **sctrls,
    648 	LDAPControl **cctrls,
    649 	ber_int_t *msgidp ));
    650 
    651 /*
    652  * in init.c
    653  */
    654 
    655 LDAP_V ( struct ldapoptions ) ldap_int_global_options;
    656 
    657 LDAP_F ( void ) ldap_int_initialize LDAP_P((struct ldapoptions *, int *));
    658 LDAP_F ( void ) ldap_int_initialize_global_options LDAP_P((
    659 	struct ldapoptions *, int *));
    660 
    661 /* memory.c */
    662 	/* simple macros to realloc for now */
    663 #define LDAP_MALLOC(s)		(ber_memalloc_x((s),NULL))
    664 #define LDAP_CALLOC(n,s)	(ber_memcalloc_x((n),(s),NULL))
    665 #define LDAP_REALLOC(p,s)	(ber_memrealloc_x((p),(s),NULL))
    666 #define LDAP_FREE(p)		(ber_memfree_x((p),NULL))
    667 #define LDAP_VFREE(v)		(ber_memvfree_x((void **)(v),NULL))
    668 #define LDAP_STRDUP(s)		(ber_strdup_x((s),NULL))
    669 #define LDAP_STRNDUP(s,l)	(ber_strndup_x((s),(l),NULL))
    670 
    671 #define LDAP_MALLOCX(s,x)	(ber_memalloc_x((s),(x)))
    672 #define LDAP_CALLOCX(n,s,x)	(ber_memcalloc_x((n),(s),(x)))
    673 #define LDAP_REALLOCX(p,s,x)	(ber_memrealloc_x((p),(s),(x)))
    674 #define LDAP_FREEX(p,x)		(ber_memfree_x((p),(x)))
    675 #define LDAP_VFREEX(v,x)	(ber_memvfree_x((void **)(v),(x)))
    676 #define LDAP_STRDUPX(s,x)	(ber_strdup_x((s),(x)))
    677 #define LDAP_STRNDUPX(s,l,x)	(ber_strndup_x((s),(l),(x)))
    678 
    679 /*
    680  * in error.c
    681  */
    682 LDAP_F (void) ldap_int_error_init( void );
    683 
    684 /*
    685  * in modify.c
    686  */
    687 
    688 LDAP_F (BerElement *) ldap_build_modify_req LDAP_P((
    689 	LDAP *ld,
    690 	const char *dn,
    691 	LDAPMod **mods,
    692 	LDAPControl **sctrls,
    693 	LDAPControl **cctrls,
    694 	ber_int_t *msgidp ));
    695 
    696 /*
    697  * in modrdn.c
    698  */
    699 
    700 LDAP_F (BerElement *) ldap_build_moddn_req LDAP_P((
    701 	LDAP *ld,
    702 	const char *dn,
    703 	const char *newrdn,
    704 	const char *newSuperior,
    705 	int deleteoldrdn,
    706 	LDAPControl **sctrls,
    707 	LDAPControl **cctrls,
    708 	ber_int_t *msgidp ));
    709 
    710 /*
    711  * in unit-int.c
    712  */
    713 LDAP_F (void) ldap_int_utils_init LDAP_P(( void ));
    714 
    715 
    716 /*
    717  * in print.c
    718  */
    719 LDAP_F (int) ldap_log_printf LDAP_P((LDAP *ld, int level, const char *fmt, ...)) LDAP_GCCATTR((format(printf, 3, 4)));
    720 
    721 /*
    722  * in controls.c
    723  */
    724 LDAP_F (int) ldap_int_put_controls LDAP_P((
    725 	LDAP *ld,
    726 	LDAPControl *const *ctrls,
    727 	BerElement *ber ));
    728 
    729 LDAP_F (int) ldap_int_client_controls LDAP_P((
    730 	LDAP *ld,
    731 	LDAPControl **ctrlp ));
    732 
    733 /*
    734  * in dsparse.c
    735  */
    736 LDAP_F (int) ldap_int_next_line_tokens LDAP_P(( char **bufp, ber_len_t *blenp, char ***toksp ));
    737 
    738 
    739 /*
    740  * in open.c
    741  */
    742 LDAP_F (int) ldap_open_defconn( LDAP *ld );
    743 LDAP_F (int) ldap_int_open_connection( LDAP *ld,
    744 	LDAPConn *conn, LDAPURLDesc *srvlist, int async );
    745 LDAP_F (int) ldap_int_check_async_open( LDAP *ld, ber_socket_t sd );
    746 
    747 /*
    748  * in os-ip.c
    749  */
    750 #ifndef HAVE_POLL
    751 LDAP_V (int) ldap_int_tblsize;
    752 LDAP_F (void) ldap_int_ip_init( void );
    753 #endif
    754 
    755 LDAP_F (int) ldap_int_timeval_dup( struct timeval **dest,
    756 	const struct timeval *tm );
    757 LDAP_F (int) ldap_connect_to_host( LDAP *ld, Sockbuf *sb,
    758 	int proto, LDAPURLDesc *srv, int async );
    759 LDAP_F (int) ldap_int_poll( LDAP *ld, ber_socket_t s,
    760 	struct timeval *tvp, int wr );
    761 
    762 #if defined(HAVE_TLS) || defined(HAVE_CYRUS_SASL)
    763 LDAP_V (char *) ldap_int_hostname;
    764 LDAP_F (char *) ldap_host_connected_to( Sockbuf *sb,
    765 	const char *host );
    766 #endif
    767 
    768 LDAP_F (int) ldap_int_select( LDAP *ld, struct timeval *timeout );
    769 LDAP_F (void *) ldap_new_select_info( void );
    770 LDAP_F (void) ldap_free_select_info( void *sip );
    771 LDAP_F (void) ldap_mark_select_write( LDAP *ld, Sockbuf *sb );
    772 LDAP_F (void) ldap_mark_select_read( LDAP *ld, Sockbuf *sb );
    773 LDAP_F (void) ldap_mark_select_clear( LDAP *ld, Sockbuf *sb );
    774 LDAP_F (void) ldap_clear_select_write( LDAP *ld, Sockbuf *sb );
    775 LDAP_F (int) ldap_is_read_ready( LDAP *ld, Sockbuf *sb );
    776 LDAP_F (int) ldap_is_write_ready( LDAP *ld, Sockbuf *sb );
    777 
    778 LDAP_F (int) ldap_validate_and_fill_sourceip  ( char** source_ip_lst,
    779 	ldapsourceip* temp_source_ip );
    780 
    781 LDAP_F (int) ldap_int_connect_cbs( LDAP *ld, Sockbuf *sb,
    782 	ber_socket_t *s, LDAPURLDesc *srv, struct sockaddr *addr );
    783 
    784 /*
    785  * in os-local.c
    786  */
    787 #ifdef LDAP_PF_LOCAL
    788 LDAP_F (int) ldap_connect_to_path( LDAP *ld, Sockbuf *sb,
    789 	LDAPURLDesc *srv, int async );
    790 #endif /* LDAP_PF_LOCAL */
    791 
    792 /*
    793  * in request.c
    794  */
    795 LDAP_F (ber_int_t) ldap_send_initial_request( LDAP *ld, ber_tag_t msgtype,
    796 	const char *dn, BerElement *ber, ber_int_t msgid );
    797 LDAP_F (BerElement *) ldap_alloc_ber_with_options( LDAP *ld );
    798 LDAP_F (void) ldap_set_ber_options( LDAP *ld, BerElement *ber );
    799 
    800 LDAP_F (int) ldap_send_server_request( LDAP *ld, BerElement *ber,
    801 	ber_int_t msgid, LDAPRequest *parentreq, LDAPURLDesc **srvlist,
    802 	LDAPConn *lc, LDAPreqinfo *bind, int noconn, int m_res );
    803 LDAP_F (LDAPConn *) ldap_new_connection( LDAP *ld, LDAPURLDesc **srvlist,
    804 	int use_ldsb, int connect, LDAPreqinfo *bind, int m_req, int m_res );
    805 LDAP_F (LDAPRequest *) ldap_find_request_by_msgid( LDAP *ld, ber_int_t msgid );
    806 LDAP_F (void) ldap_return_request( LDAP *ld, LDAPRequest *lr, int freeit );
    807 LDAP_F (int) ldap_req_cmp( const void *l, const void *r );
    808 LDAP_F (void) ldap_do_free_request( void *arg );
    809 LDAP_F (void) ldap_free_request( LDAP *ld, LDAPRequest *lr );
    810 LDAP_F (void) ldap_free_connection( LDAP *ld, LDAPConn *lc, int force, int unbind );
    811 LDAP_F (void) ldap_dump_connection( LDAP *ld, LDAPConn *lconns, int all );
    812 LDAP_F (void) ldap_dump_requests_and_responses( LDAP *ld );
    813 LDAP_F (int) ldap_chase_referrals( LDAP *ld, LDAPRequest *lr,
    814 	char **errstrp, int sref, int *hadrefp );
    815 LDAP_F (int) ldap_chase_v3referrals( LDAP *ld, LDAPRequest *lr,
    816 	char **refs, int sref, char **referralsp, int *hadrefp );
    817 LDAP_F (int) ldap_append_referral( LDAP *ld, char **referralsp, char *s );
    818 LDAP_F (int) ldap_int_flush_request( LDAP *ld, LDAPRequest *lr );
    819 
    820 /*
    821  * in result.c:
    822  */
    823 LDAP_F (const char *) ldap_int_msgtype2str( ber_tag_t tag );
    824 
    825 /*
    826  * in search.c
    827  */
    828 LDAP_F (BerElement *) ldap_build_search_req LDAP_P((
    829 	LDAP *ld,
    830 	const char *base,
    831 	ber_int_t scope,
    832 	const char *filter,
    833 	char **attrs,
    834 	ber_int_t attrsonly,
    835 	LDAPControl **sctrls,
    836 	LDAPControl **cctrls,
    837 	ber_int_t timelimit,
    838 	ber_int_t sizelimit,
    839 	ber_int_t deref,
    840 	ber_int_t *msgidp));
    841 
    842 
    843 /*
    844  * in unbind.c
    845  */
    846 LDAP_F (int) ldap_ld_free LDAP_P((
    847 	LDAP *ld,
    848 	int close,
    849 	LDAPControl **sctrls,
    850 	LDAPControl **cctrls ));
    851 
    852 LDAP_F (int) ldap_send_unbind LDAP_P((
    853 	LDAP *ld,
    854 	Sockbuf *sb,
    855 	LDAPControl **sctrls,
    856 	LDAPControl **cctrls ));
    857 
    858 /*
    859  * in url.c
    860  */
    861 LDAP_F (LDAPURLDesc *) ldap_url_dup LDAP_P((
    862 	LDAPURLDesc *ludp ));
    863 
    864 LDAP_F (LDAPURLDesc *) ldap_url_duplist LDAP_P((
    865 	LDAPURLDesc *ludlist ));
    866 
    867 LDAP_F (int) ldap_url_parsehosts LDAP_P((
    868 	LDAPURLDesc **ludlist,
    869 	const char *hosts,
    870 	int port ));
    871 
    872 LDAP_F (char *) ldap_url_list2hosts LDAP_P((
    873 	LDAPURLDesc *ludlist ));
    874 
    875 /*
    876  * in cyrus.c
    877  */
    878 
    879 LDAP_F (int) ldap_int_sasl_init LDAP_P(( void ));
    880 
    881 LDAP_F (int) ldap_int_sasl_open LDAP_P((
    882 	LDAP *ld, LDAPConn *conn,
    883 	const char* host ));
    884 LDAP_F (int) ldap_int_sasl_close LDAP_P(( LDAP *ld, LDAPConn *conn ));
    885 
    886 LDAP_F (int) ldap_int_sasl_external LDAP_P((
    887 	LDAP *ld, LDAPConn *conn,
    888 	const char* authid, ber_len_t ssf ));
    889 
    890 LDAP_F (int) ldap_int_sasl_get_option LDAP_P(( LDAP *ld,
    891 	int option, void *arg ));
    892 LDAP_F (int) ldap_int_sasl_set_option LDAP_P(( LDAP *ld,
    893 	int option, void *arg ));
    894 LDAP_F (int) ldap_int_sasl_config LDAP_P(( struct ldapoptions *lo,
    895 	int option, const char *arg ));
    896 
    897 LDAP_F (int) ldap_int_sasl_bind LDAP_P((
    898 	LDAP *ld,
    899 	const char *,
    900 	const char *,
    901 	LDAPControl **, LDAPControl **,
    902 
    903 	/* should be passed in client controls */
    904 	unsigned flags,
    905 	LDAP_SASL_INTERACT_PROC *interact,
    906 	void *defaults,
    907 	LDAPMessage *result,
    908 	const char **rmech,
    909 	int *msgid ));
    910 
    911 /* in sasl.c */
    912 
    913 LDAP_F (BerElement *) ldap_build_bind_req LDAP_P((
    914 	LDAP *ld,
    915 	const char *dn,
    916 	const char *mech,
    917 	struct berval *cred,
    918 	LDAPControl **sctrls,
    919 	LDAPControl **cctrls,
    920 	ber_int_t *msgidp ));
    921 
    922 /* in schema.c */
    923 LDAP_F (char *) ldap_int_parse_numericoid LDAP_P((
    924 	const char **sp,
    925 	int *code,
    926 	const int flags ));
    927 
    928 /*
    929  * in tls.c
    930  */
    931 LDAP_F (int) ldap_int_tls_start LDAP_P(( LDAP *ld,
    932 	LDAPConn *conn, LDAPURLDesc *srv ));
    933 
    934 LDAP_F (void) ldap_int_tls_destroy LDAP_P(( struct ldapoptions *lo ));
    935 
    936 /*
    937  *	in getvalues.c
    938  */
    939 LDAP_F (char **) ldap_value_dup LDAP_P((
    940 	char *const *vals ));
    941 
    942 /*
    943  *	in gssapi.c
    944  */
    945 #ifdef HAVE_GSSAPI
    946 LDAP_F(int) ldap_int_gssapi_get_option LDAP_P(( LDAP *ld, int option, void *arg ));
    947 LDAP_F(int) ldap_int_gssapi_set_option LDAP_P(( LDAP *ld, int option, void *arg ));
    948 LDAP_F(int) ldap_int_gssapi_config LDAP_P(( struct ldapoptions *lo, int option, const char *arg ));
    949 LDAP_F(void) ldap_int_gssapi_close LDAP_P(( LDAP *ld, LDAPConn *lc ));
    950 #endif
    951 
    952 LDAP_END_DECL
    953 
    954 #endif /* _LDAP_INT_H */
    955