+/*
+ * structure for tracking LDAP server host, ports, DNs, etc.
+ */
+typedef struct ldap_server {
+ char *lsrv_host;
+ char *lsrv_dn; /* if NULL, use default */
+ int lsrv_port;
+ struct ldap_server *lsrv_next;
+} LDAPServer;
+
+
+/*
+ * structure for representing an LDAP server connection
+ */
+typedef struct ldap_conn {
+ Sockbuf *lconn_sb;
+ int lconn_refcnt;
+ time_t lconn_lastused; /* time */
+ int lconn_status;
+#define LDAP_CONNST_NEEDSOCKET 1
+#define LDAP_CONNST_CONNECTING 2
+#define LDAP_CONNST_CONNECTED 3
+ LDAPServer *lconn_server;
+ char *lconn_krbinstance;
+ struct ldap_conn *lconn_next;
+ BerElement *lconn_ber;/* ber receiving on this conn. */
+} LDAPConn;
+
+
+/*
+ * structure used to track outstanding requests
+ */
+typedef struct ldapreq {
+ ber_int_t lr_msgid; /* the message id */
+ int lr_status; /* status of request */
+#define LDAP_REQST_INPROGRESS 1
+#define LDAP_REQST_CHASINGREFS 2
+#define LDAP_REQST_NOTCONNECTED 3
+#define LDAP_REQST_WRITING 4
+ int lr_outrefcnt; /* count of outstanding referrals */
+ ber_int_t lr_origid; /* original request's message id */
+ int lr_parentcnt; /* count of parent requests */
+ ber_tag_t lr_res_msgtype; /* result message type */
+ ber_int_t lr_res_errno; /* result LDAP errno */
+ char *lr_res_error; /* result error string */
+ char *lr_res_matched;/* result matched DN string */
+ BerElement *lr_ber; /* ber encoded request contents */
+ LDAPConn *lr_conn; /* connection used to send request */
+ struct ldapreq *lr_parent; /* request that spawned this referral */
+ struct ldapreq *lr_refnext; /* next referral spawned */
+ struct ldapreq *lr_prev; /* previous request */
+ struct ldapreq *lr_next; /* next request */
+} LDAPRequest;
+
+/*
+ * structure for client cache
+ */
+#define LDAP_CACHE_BUCKETS 31 /* cache hash table size */
+typedef struct ldapcache {
+ LDAPMessage *lc_buckets[LDAP_CACHE_BUCKETS];/* hash table */
+ LDAPMessage *lc_requests; /* unfulfilled reqs */
+ long lc_timeout; /* request timeout */
+ ber_len_t lc_maxmem; /* memory to use */
+ ber_len_t lc_memused; /* memory in use */
+ int lc_enabled; /* enabled? */
+ unsigned long lc_options; /* options */
+#define LDAP_CACHE_OPT_CACHENOERRS 0x00000001
+#define LDAP_CACHE_OPT_CACHEALLERRS 0x00000002
+} LDAPCache;
+
+/*
+ * handy macro for checking if handle is connectionless
+ */
+
+#define LDAP_IS_CLDAP(ld) ((ld)->ld_cldapnaddr>0)
+
+/*
+ * structure representing an ldap connection
+ */
+
+struct ldap {
+ Sockbuf ld_sb; /* socket descriptor & buffer */
+
+ struct ldapoptions ld_options;
+
+#define ld_valid ld_options.ldo_valid
+#define ld_debug ld_options.ldo_debug
+
+#define ld_deref ld_options.ldo_deref
+#define ld_timelimit ld_options.ldo_timelimit
+#define ld_sizelimit ld_options.ldo_sizelimit
+
+#define ld_defbase ld_options.ldo_defbase
+#define ld_defhost ld_options.ldo_defhost
+#define ld_defport ld_options.ldo_defport
+
+#define ld_cldaptries ld_options.ldo_cldaptries
+#define ld_cldaptimeout ld_options.ldo_cldaptimeout
+#define ld_refhoplimit ld_options.ldo_refhoplimit
+
+#define ld_sctrls ld_options.ldo_sctrls
+#define ld_cctrls ld_options.ldo_cctrls
+
+ ber_int_t ld_version; /* version connected at */
+ char *ld_host;
+ int ld_port;
+
+ unsigned short ld_lberoptions;
+
+ LDAPFiltDesc *ld_filtd; /* from getfilter for ufn searches */
+ char *ld_ufnprefix; /* for incomplete ufn's */
+
+ ber_int_t ld_errno;
+ char *ld_error;
+ char *ld_matched;
+ ber_len_t ld_msgid;
+
+ /* do not mess with these */
+ LDAPRequest *ld_requests; /* list of outstanding requests */
+ LDAPMessage *ld_responses; /* list of outstanding responses */
+
+ ber_int_t *ld_abandoned; /* array of abandoned requests */
+
+ LDAPCache *ld_cache; /* non-null if cache is initialized */
+ /* stuff used by connectionless searches. */
+
+ char *ld_cldapdn; /* DN used in connectionless search */
+ int ld_cldapnaddr; /* number of addresses */
+ void **ld_cldapaddrs;/* addresses to send request to */
+
+ /* do not mess with the rest though */
+ BERTranslateProc ld_lber_encode_translate_proc;
+ BERTranslateProc ld_lber_decode_translate_proc;
+
+ LDAPConn *ld_defconn; /* default connection */
+ LDAPConn *ld_conns; /* list of server connections */
+ void *ld_selectinfo; /* platform specifics for select */
+ int (*ld_rebindproc)( struct ldap *ld, char **dnp,
+ char **passwdp, int *authmethodp, int freeit );
+ /* routine to get info needed for re-bind */
+};
+#define LDAP_VALID(ld) ( (ld)->ld_valid == LDAP_VALID_SESSION )
+
+/*
+ * in init.c
+ */
+
+extern struct ldapoptions ldap_int_global_options;
+void ldap_int_initialize LDAP_P((void));
+
+
+/* memory.c */
+ /* simple macros to realloc for now */
+#define LDAP_INT_MALLOC(s) (LBER_MALLOC((s)))
+#define LDAP_INT_CALLOC(n,s) (LBER_CALLOC((n),(s)))
+#define LDAP_INT_REALLOC(p,s) (LBER_REALLOC((p),(s)))
+#define LDAP_INT_FREE(p) (LBER_FREE((p)))
+#define LDAP_INT_VFREE(v) (LBER_VFREE((void **)(v)))
+#define LDAP_INT_STRDUP(s) (LBER_STRDUP((s)))
+
+#define LDAP_MALLOC(s) (LBER_MALLOC((s)))
+#define LDAP_CALLOC(n,s) (LBER_CALLOC((n),(s)))
+#define LDAP_REALLOC(p,s) (LBER_REALLOC((p),(s)))
+#define LDAP_FREE(p) (LBER_FREE((p)))
+#define LDAP_VFREE(v) (LBER_VFREE((void **)(v)))
+#define LDAP_STRDUP(s) (LBER_STRDUP((s)))
+
+/*
+ * in unit-int.c
+ */
+void ldap_int_utils_init LDAP_P(( void ));
+
+
+/*
+ * in print.c
+ */
+int ldap_log_printf LDAP_P((LDAP *ld, int level, const char *fmt, ...));
+