1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 3*0Sstevel@tonic-gate * Use is subject to license terms. 4*0Sstevel@tonic-gate */ 5*0Sstevel@tonic-gate 6*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 7*0Sstevel@tonic-gate 8*0Sstevel@tonic-gate /* 9*0Sstevel@tonic-gate * The contents of this file are subject to the Netscape Public 10*0Sstevel@tonic-gate * License Version 1.1 (the "License"); you may not use this file 11*0Sstevel@tonic-gate * except in compliance with the License. You may obtain a copy of 12*0Sstevel@tonic-gate * the License at http://www.mozilla.org/NPL/ 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * Software distributed under the License is distributed on an "AS 15*0Sstevel@tonic-gate * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 16*0Sstevel@tonic-gate * implied. See the License for the specific language governing 17*0Sstevel@tonic-gate * rights and limitations under the License. 18*0Sstevel@tonic-gate * 19*0Sstevel@tonic-gate * The Original Code is Mozilla Communicator client code, released 20*0Sstevel@tonic-gate * March 31, 1998. 21*0Sstevel@tonic-gate * 22*0Sstevel@tonic-gate * The Initial Developer of the Original Code is Netscape 23*0Sstevel@tonic-gate * Communications Corporation. Portions created by Netscape are 24*0Sstevel@tonic-gate * Copyright (C) 1998-1999 Netscape Communications Corporation. All 25*0Sstevel@tonic-gate * Rights Reserved. 26*0Sstevel@tonic-gate * 27*0Sstevel@tonic-gate * Contributor(s): 28*0Sstevel@tonic-gate */ 29*0Sstevel@tonic-gate 30*0Sstevel@tonic-gate #ifndef _LDAPINT_H 31*0Sstevel@tonic-gate #define _LDAPINT_H 32*0Sstevel@tonic-gate 33*0Sstevel@tonic-gate #include <stdio.h> 34*0Sstevel@tonic-gate #include <string.h> 35*0Sstevel@tonic-gate #include <stdlib.h> 36*0Sstevel@tonic-gate #include <errno.h> 37*0Sstevel@tonic-gate #include <time.h> 38*0Sstevel@tonic-gate #include <fcntl.h> 39*0Sstevel@tonic-gate #ifdef hpux 40*0Sstevel@tonic-gate #include <strings.h> 41*0Sstevel@tonic-gate #endif /* hpux */ 42*0Sstevel@tonic-gate 43*0Sstevel@tonic-gate #ifdef _WINDOWS 44*0Sstevel@tonic-gate # define FD_SETSIZE 256 /* number of connections we support */ 45*0Sstevel@tonic-gate # define WIN32_LEAN_AND_MEAN 46*0Sstevel@tonic-gate # include <windows.h> 47*0Sstevel@tonic-gate #elif defined(macintosh) 48*0Sstevel@tonic-gate #include "ldap-macos.h" 49*0Sstevel@tonic-gate #elif defined(XP_OS2) 50*0Sstevel@tonic-gate #include <os2sock.h> 51*0Sstevel@tonic-gate #else /* _WINDOWS */ 52*0Sstevel@tonic-gate # include <sys/time.h> 53*0Sstevel@tonic-gate # include <sys/types.h> 54*0Sstevel@tonic-gate # include <sys/socket.h> 55*0Sstevel@tonic-gate # include <netinet/in.h> 56*0Sstevel@tonic-gate # include <arpa/inet.h> 57*0Sstevel@tonic-gate # include <netdb.h> 58*0Sstevel@tonic-gate #if !defined(hpux) && !defined(SUNOS4) && !defined(LINUX) 59*0Sstevel@tonic-gate # include <sys/select.h> 60*0Sstevel@tonic-gate #endif /* !defined(hpux) and others */ 61*0Sstevel@tonic-gate #endif /* _WINDOWS */ 62*0Sstevel@tonic-gate 63*0Sstevel@tonic-gate #if defined(IRIX) 64*0Sstevel@tonic-gate #include <bstring.h> 65*0Sstevel@tonic-gate #endif /* IRIX */ 66*0Sstevel@tonic-gate 67*0Sstevel@tonic-gate #define NSLBERI_LBER_INT_FRIEND 68*0Sstevel@tonic-gate #ifdef macintosh 69*0Sstevel@tonic-gate #include "lber-int.h" 70*0Sstevel@tonic-gate #elif defined(_SOLARIS_SDK) 71*0Sstevel@tonic-gate #include "../ber/lber-int.h" 72*0Sstevel@tonic-gate #else /* _SOLARIS_SDK */ 73*0Sstevel@tonic-gate #include "../liblber/lber-int.h" 74*0Sstevel@tonic-gate #endif /* macintosh */ 75*0Sstevel@tonic-gate 76*0Sstevel@tonic-gate #include "ldap.h" 77*0Sstevel@tonic-gate #include "ldaprot.h" 78*0Sstevel@tonic-gate #include "ldaplog.h" 79*0Sstevel@tonic-gate #include "portable.h" 80*0Sstevel@tonic-gate #include "regex.h" 81*0Sstevel@tonic-gate 82*0Sstevel@tonic-gate #ifdef LDAP_ASYNC_IO 83*0Sstevel@tonic-gate #ifdef NEED_FILIO 84*0Sstevel@tonic-gate #include <sys/filio.h> /* to get FIONBIO for ioctl() call */ 85*0Sstevel@tonic-gate #else /* NEED_FILIO */ 86*0Sstevel@tonic-gate #if !defined( _WINDOWS) && !defined (macintosh) 87*0Sstevel@tonic-gate #include <sys/ioctl.h> /* to get FIONBIO for ioctl() call */ 88*0Sstevel@tonic-gate #endif /* _WINDOWS && macintosh */ 89*0Sstevel@tonic-gate #endif /* NEED_FILIO */ 90*0Sstevel@tonic-gate #endif /* LDAP_ASYNC_IO */ 91*0Sstevel@tonic-gate 92*0Sstevel@tonic-gate #ifdef USE_SYSCONF 93*0Sstevel@tonic-gate # include <unistd.h> 94*0Sstevel@tonic-gate #endif /* USE_SYSCONF */ 95*0Sstevel@tonic-gate 96*0Sstevel@tonic-gate #ifdef _SOLARIS_SDK 97*0Sstevel@tonic-gate #include <libintl.h> 98*0Sstevel@tonic-gate #endif 99*0Sstevel@tonic-gate #ifdef LDAP_SASLIO_HOOKS 100*0Sstevel@tonic-gate #include <sasl/sasl.h> 101*0Sstevel@tonic-gate #define SASL_MAX_BUFF_SIZE 65536 102*0Sstevel@tonic-gate #define SASL_MIN_BUFF_SIZE 4096 103*0Sstevel@tonic-gate #endif 104*0Sstevel@tonic-gate 105*0Sstevel@tonic-gate #if !defined(_WINDOWS) && !defined(macintosh) && !defined(LINUX) && !defined(BSDI) 106*0Sstevel@tonic-gate #define NSLDAPI_HAVE_POLL 1 107*0Sstevel@tonic-gate #endif 108*0Sstevel@tonic-gate 109*0Sstevel@tonic-gate /* SSL version, or 0 if not built with SSL */ 110*0Sstevel@tonic-gate #if defined(NET_SSL) 111*0Sstevel@tonic-gate # define SSL_VERSION 3 112*0Sstevel@tonic-gate #else 113*0Sstevel@tonic-gate # define SSL_VERSION 0 114*0Sstevel@tonic-gate #endif 115*0Sstevel@tonic-gate 116*0Sstevel@tonic-gate 117*0Sstevel@tonic-gate #define LDAP_URL_URLCOLON "URL:" 118*0Sstevel@tonic-gate #define LDAP_URL_URLCOLON_LEN 4 119*0Sstevel@tonic-gate 120*0Sstevel@tonic-gate #define LDAP_LDAP_REF_STR LDAP_URL_PREFIX 121*0Sstevel@tonic-gate #define LDAP_LDAP_REF_STR_LEN LDAP_URL_PREFIX_LEN 122*0Sstevel@tonic-gate #define LDAP_LDAPS_REF_STR LDAPS_URL_PREFIX 123*0Sstevel@tonic-gate #define LDAP_LDAPS_REF_STR_LEN LDAPS_URL_PREFIX_LEN 124*0Sstevel@tonic-gate 125*0Sstevel@tonic-gate /* default limit on nesting of referrals */ 126*0Sstevel@tonic-gate #define LDAP_DEFAULT_REFHOPLIMIT 5 127*0Sstevel@tonic-gate #ifdef LDAP_DNS 128*0Sstevel@tonic-gate #define LDAP_DX_REF_STR "dx://" 129*0Sstevel@tonic-gate #define LDAP_DX_REF_STR_LEN 5 130*0Sstevel@tonic-gate #endif /* LDAP_DNS */ 131*0Sstevel@tonic-gate 132*0Sstevel@tonic-gate typedef enum { 133*0Sstevel@tonic-gate LDAP_CACHE_LOCK, 134*0Sstevel@tonic-gate LDAP_MEMCACHE_LOCK, 135*0Sstevel@tonic-gate LDAP_MSGID_LOCK, 136*0Sstevel@tonic-gate LDAP_REQ_LOCK, 137*0Sstevel@tonic-gate LDAP_RESP_LOCK, 138*0Sstevel@tonic-gate LDAP_ABANDON_LOCK, 139*0Sstevel@tonic-gate LDAP_CTRL_LOCK, 140*0Sstevel@tonic-gate LDAP_OPTION_LOCK, 141*0Sstevel@tonic-gate LDAP_ERR_LOCK, 142*0Sstevel@tonic-gate LDAP_CONN_LOCK, 143*0Sstevel@tonic-gate LDAP_IOSTATUS_LOCK, /* serializes access to ld->ld_iostatus */ 144*0Sstevel@tonic-gate LDAP_RESULT_LOCK, 145*0Sstevel@tonic-gate LDAP_PEND_LOCK, 146*0Sstevel@tonic-gate LDAP_THREADID_LOCK, 147*0Sstevel@tonic-gate #ifdef LDAP_SASLIO_HOOKS 148*0Sstevel@tonic-gate LDAP_SASL_LOCK, 149*0Sstevel@tonic-gate #endif 150*0Sstevel@tonic-gate LDAP_MAX_LOCK 151*0Sstevel@tonic-gate } LDAPLock; 152*0Sstevel@tonic-gate 153*0Sstevel@tonic-gate /* 154*0Sstevel@tonic-gate * This structure represents both ldap messages and ldap responses. 155*0Sstevel@tonic-gate * These are really the same, except in the case of search responses, 156*0Sstevel@tonic-gate * where a response has multiple messages. 157*0Sstevel@tonic-gate */ 158*0Sstevel@tonic-gate 159*0Sstevel@tonic-gate struct ldapmsg { 160*0Sstevel@tonic-gate int lm_msgid; /* the message id */ 161*0Sstevel@tonic-gate int lm_msgtype; /* the message type */ 162*0Sstevel@tonic-gate BerElement *lm_ber; /* the ber encoded message contents */ 163*0Sstevel@tonic-gate struct ldapmsg *lm_chain; /* for search - next msg in the resp */ 164*0Sstevel@tonic-gate struct ldapmsg *lm_next; /* next response */ 165*0Sstevel@tonic-gate int lm_fromcache; /* memcache: origin of message */ 166*0Sstevel@tonic-gate }; 167*0Sstevel@tonic-gate 168*0Sstevel@tonic-gate /* 169*0Sstevel@tonic-gate * structure for tracking LDAP server host, ports, DNs, etc. 170*0Sstevel@tonic-gate */ 171*0Sstevel@tonic-gate typedef struct ldap_server { 172*0Sstevel@tonic-gate char *lsrv_host; 173*0Sstevel@tonic-gate char *lsrv_dn; /* if NULL, use default */ 174*0Sstevel@tonic-gate int lsrv_port; 175*0Sstevel@tonic-gate unsigned long lsrv_options; /* boolean options */ 176*0Sstevel@tonic-gate #define LDAP_SRV_OPT_SECURE 0x01 177*0Sstevel@tonic-gate struct ldap_server *lsrv_next; 178*0Sstevel@tonic-gate } LDAPServer; 179*0Sstevel@tonic-gate 180*0Sstevel@tonic-gate /* 181*0Sstevel@tonic-gate * structure for representing an LDAP server connection 182*0Sstevel@tonic-gate */ 183*0Sstevel@tonic-gate typedef struct ldap_conn { 184*0Sstevel@tonic-gate Sockbuf *lconn_sb; 185*0Sstevel@tonic-gate BerElement *lconn_ber; /* non-NULL if in midst of msg. */ 186*0Sstevel@tonic-gate int lconn_version; /* LDAP protocol version */ 187*0Sstevel@tonic-gate int lconn_refcnt; 188*0Sstevel@tonic-gate unsigned long lconn_lastused; /* time */ 189*0Sstevel@tonic-gate int lconn_status; 190*0Sstevel@tonic-gate #define LDAP_CONNST_NEEDSOCKET 1 191*0Sstevel@tonic-gate #define LDAP_CONNST_CONNECTING 2 192*0Sstevel@tonic-gate #define LDAP_CONNST_CONNECTED 3 193*0Sstevel@tonic-gate #define LDAP_CONNST_DEAD 4 194*0Sstevel@tonic-gate LDAPServer *lconn_server; 195*0Sstevel@tonic-gate char *lconn_binddn; /* DN of last successful bind */ 196*0Sstevel@tonic-gate int lconn_bound; /* has a bind been done? */ 197*0Sstevel@tonic-gate char *lconn_krbinstance; 198*0Sstevel@tonic-gate struct ldap_conn *lconn_next; 199*0Sstevel@tonic-gate } LDAPConn; 200*0Sstevel@tonic-gate 201*0Sstevel@tonic-gate 202*0Sstevel@tonic-gate /* 203*0Sstevel@tonic-gate * structure used to track outstanding requests 204*0Sstevel@tonic-gate */ 205*0Sstevel@tonic-gate typedef struct ldapreq { 206*0Sstevel@tonic-gate int lr_msgid; /* the message id */ 207*0Sstevel@tonic-gate int lr_status; /* status of request */ 208*0Sstevel@tonic-gate #define LDAP_REQST_INPROGRESS 1 209*0Sstevel@tonic-gate #define LDAP_REQST_CHASINGREFS 2 210*0Sstevel@tonic-gate #define LDAP_REQST_NOTCONNECTED 3 211*0Sstevel@tonic-gate #define LDAP_REQST_WRITING 4 212*0Sstevel@tonic-gate #define LDAP_REQST_CONNDEAD 5 /* associated conn. has failed */ 213*0Sstevel@tonic-gate int lr_outrefcnt; /* count of outstanding referrals */ 214*0Sstevel@tonic-gate int lr_origid; /* original request's message id */ 215*0Sstevel@tonic-gate int lr_parentcnt; /* count of parent requests */ 216*0Sstevel@tonic-gate int lr_res_msgtype; /* result message type */ 217*0Sstevel@tonic-gate int lr_res_errno; /* result LDAP errno */ 218*0Sstevel@tonic-gate char *lr_res_error; /* result error string */ 219*0Sstevel@tonic-gate char *lr_res_matched;/* result matched DN string */ 220*0Sstevel@tonic-gate BerElement *lr_ber; /* ber encoded request contents */ 221*0Sstevel@tonic-gate LDAPConn *lr_conn; /* connection used to send request */ 222*0Sstevel@tonic-gate char *lr_binddn; /* request is a bind for this DN */ 223*0Sstevel@tonic-gate struct ldapreq *lr_parent; /* request that spawned this referral */ 224*0Sstevel@tonic-gate struct ldapreq *lr_child; /* list of requests we spawned */ 225*0Sstevel@tonic-gate struct ldapreq *lr_sibling; /* next referral spawned */ 226*0Sstevel@tonic-gate struct ldapreq *lr_prev; /* ld->ld_requests previous request */ 227*0Sstevel@tonic-gate struct ldapreq *lr_next; /* ld->ld_requests next request */ 228*0Sstevel@tonic-gate } LDAPRequest; 229*0Sstevel@tonic-gate 230*0Sstevel@tonic-gate typedef struct ldappend { 231*0Sstevel@tonic-gate void *lp_sema; /* semaphore to post */ 232*0Sstevel@tonic-gate int lp_msgid; /* message id */ 233*0Sstevel@tonic-gate LDAPMessage *lp_result; /* result storage */ 234*0Sstevel@tonic-gate struct ldappend *lp_prev; /* previous pending */ 235*0Sstevel@tonic-gate struct ldappend *lp_next; /* next pending */ 236*0Sstevel@tonic-gate } LDAPPend; 237*0Sstevel@tonic-gate 238*0Sstevel@tonic-gate /* 239*0Sstevel@tonic-gate * forward declaration for I/O status structure (defined in os-ip.c) 240*0Sstevel@tonic-gate */ 241*0Sstevel@tonic-gate typedef struct nsldapi_iostatus_info NSLDAPIIOStatus; 242*0Sstevel@tonic-gate 243*0Sstevel@tonic-gate /* 244*0Sstevel@tonic-gate * old extended IO structure (before writev callback was added) 245*0Sstevel@tonic-gate */ 246*0Sstevel@tonic-gate struct ldap_x_ext_io_fns_rev0 { 247*0Sstevel@tonic-gate int lextiof_size; 248*0Sstevel@tonic-gate LDAP_X_EXTIOF_CONNECT_CALLBACK *lextiof_connect; 249*0Sstevel@tonic-gate LDAP_X_EXTIOF_CLOSE_CALLBACK *lextiof_close; 250*0Sstevel@tonic-gate LDAP_X_EXTIOF_READ_CALLBACK *lextiof_read; 251*0Sstevel@tonic-gate LDAP_X_EXTIOF_WRITE_CALLBACK *lextiof_write; 252*0Sstevel@tonic-gate LDAP_X_EXTIOF_POLL_CALLBACK *lextiof_poll; 253*0Sstevel@tonic-gate LDAP_X_EXTIOF_NEWHANDLE_CALLBACK *lextiof_newhandle; 254*0Sstevel@tonic-gate LDAP_X_EXTIOF_DISPOSEHANDLE_CALLBACK *lextiof_disposehandle; 255*0Sstevel@tonic-gate void *lextiof_session_arg; 256*0Sstevel@tonic-gate }; 257*0Sstevel@tonic-gate #define LDAP_X_EXTIO_FNS_SIZE_REV0 sizeof(struct ldap_x_ext_io_fns_rev0) 258*0Sstevel@tonic-gate 259*0Sstevel@tonic-gate /* 260*0Sstevel@tonic-gate * structure representing an ldap connection 261*0Sstevel@tonic-gate */ 262*0Sstevel@tonic-gate struct ldap { 263*0Sstevel@tonic-gate struct sockbuf *ld_sbp; /* pointer to socket desc. & buffer */ 264*0Sstevel@tonic-gate char *ld_host; 265*0Sstevel@tonic-gate int ld_version; /* LDAP protocol version */ 266*0Sstevel@tonic-gate char ld_lberoptions; 267*0Sstevel@tonic-gate int ld_deref; 268*0Sstevel@tonic-gate 269*0Sstevel@tonic-gate int ld_timelimit; 270*0Sstevel@tonic-gate int ld_sizelimit; 271*0Sstevel@tonic-gate 272*0Sstevel@tonic-gate struct ldap_filt_desc *ld_filtd; /* from getfilter for ufn searches */ 273*0Sstevel@tonic-gate char *ld_ufnprefix; /* for incomplete ufn's */ 274*0Sstevel@tonic-gate 275*0Sstevel@tonic-gate int ld_errno; 276*0Sstevel@tonic-gate char *ld_error; 277*0Sstevel@tonic-gate char *ld_matched; 278*0Sstevel@tonic-gate int ld_msgid; 279*0Sstevel@tonic-gate 280*0Sstevel@tonic-gate /* do not mess with these */ 281*0Sstevel@tonic-gate LDAPRequest *ld_requests; /* list of outstanding requests */ 282*0Sstevel@tonic-gate LDAPMessage *ld_responses; /* list of outstanding responses */ 283*0Sstevel@tonic-gate int *ld_abandoned; /* array of abandoned requests */ 284*0Sstevel@tonic-gate char *ld_cldapdn; /* DN used in connectionless search */ 285*0Sstevel@tonic-gate 286*0Sstevel@tonic-gate /* it is OK to change these next four values directly */ 287*0Sstevel@tonic-gate int ld_cldaptries; /* connectionless search retry count */ 288*0Sstevel@tonic-gate int ld_cldaptimeout;/* time between retries */ 289*0Sstevel@tonic-gate int ld_refhoplimit; /* limit on referral nesting */ 290*0Sstevel@tonic-gate unsigned long ld_options; /* boolean options */ 291*0Sstevel@tonic-gate 292*0Sstevel@tonic-gate #define LDAP_BITOPT_REFERRALS 0x80000000 293*0Sstevel@tonic-gate #define LDAP_BITOPT_SSL 0x40000000 294*0Sstevel@tonic-gate #define LDAP_BITOPT_DNS 0x20000000 295*0Sstevel@tonic-gate #define LDAP_BITOPT_RESTART 0x10000000 296*0Sstevel@tonic-gate #define LDAP_BITOPT_RECONNECT 0x08000000 297*0Sstevel@tonic-gate #define LDAP_BITOPT_ASYNC 0x04000000 298*0Sstevel@tonic-gate 299*0Sstevel@tonic-gate /* do not mess with the rest though */ 300*0Sstevel@tonic-gate char *ld_defhost; /* full name of default server */ 301*0Sstevel@tonic-gate int ld_defport; /* port of default server */ 302*0Sstevel@tonic-gate BERTranslateProc ld_lber_encode_translate_proc; 303*0Sstevel@tonic-gate BERTranslateProc ld_lber_decode_translate_proc; 304*0Sstevel@tonic-gate LDAPConn *ld_defconn; /* default connection */ 305*0Sstevel@tonic-gate LDAPConn *ld_conns; /* list of all server connections */ 306*0Sstevel@tonic-gate NSLDAPIIOStatus *ld_iostatus; /* status info. about network sockets */ 307*0Sstevel@tonic-gate LDAP_REBINDPROC_CALLBACK *ld_rebind_fn; 308*0Sstevel@tonic-gate void *ld_rebind_arg; 309*0Sstevel@tonic-gate 310*0Sstevel@tonic-gate /* function pointers, etc. for extended I/O */ 311*0Sstevel@tonic-gate struct ldap_x_ext_io_fns ld_ext_io_fns; 312*0Sstevel@tonic-gate #define ld_extio_size ld_ext_io_fns.lextiof_size 313*0Sstevel@tonic-gate #define ld_extclose_fn ld_ext_io_fns.lextiof_close 314*0Sstevel@tonic-gate #define ld_extconnect_fn ld_ext_io_fns.lextiof_connect 315*0Sstevel@tonic-gate #define ld_extread_fn ld_ext_io_fns.lextiof_read 316*0Sstevel@tonic-gate #define ld_extwrite_fn ld_ext_io_fns.lextiof_write 317*0Sstevel@tonic-gate #define ld_extwritev_fn ld_ext_io_fns.lextiof_writev 318*0Sstevel@tonic-gate #define ld_extpoll_fn ld_ext_io_fns.lextiof_poll 319*0Sstevel@tonic-gate #define ld_extnewhandle_fn ld_ext_io_fns.lextiof_newhandle 320*0Sstevel@tonic-gate #define ld_extdisposehandle_fn ld_ext_io_fns.lextiof_disposehandle 321*0Sstevel@tonic-gate #define ld_ext_session_arg ld_ext_io_fns.lextiof_session_arg 322*0Sstevel@tonic-gate 323*0Sstevel@tonic-gate /* allocated pointer for older I/O functions */ 324*0Sstevel@tonic-gate struct ldap_io_fns *ld_io_fns_ptr; 325*0Sstevel@tonic-gate #define NSLDAPI_USING_CLASSIC_IO_FUNCTIONS( ld ) ((ld)->ld_io_fns_ptr != NULL) 326*0Sstevel@tonic-gate 327*0Sstevel@tonic-gate /* function pointers, etc. for DNS */ 328*0Sstevel@tonic-gate struct ldap_dns_fns ld_dnsfn; 329*0Sstevel@tonic-gate #define ld_dns_extradata ld_dnsfn.lddnsfn_extradata 330*0Sstevel@tonic-gate #define ld_dns_bufsize ld_dnsfn.lddnsfn_bufsize 331*0Sstevel@tonic-gate #define ld_dns_gethostbyname_fn ld_dnsfn.lddnsfn_gethostbyname 332*0Sstevel@tonic-gate #define ld_dns_gethostbyaddr_fn ld_dnsfn.lddnsfn_gethostbyaddr 333*0Sstevel@tonic-gate #define ld_dns_getpeername_fn ld_dnsfn.lddnsfn_getpeername 334*0Sstevel@tonic-gate 335*0Sstevel@tonic-gate /* function pointers, etc. for threading */ 336*0Sstevel@tonic-gate struct ldap_thread_fns ld_thread; 337*0Sstevel@tonic-gate #define ld_mutex_alloc_fn ld_thread.ltf_mutex_alloc 338*0Sstevel@tonic-gate #define ld_mutex_free_fn ld_thread.ltf_mutex_free 339*0Sstevel@tonic-gate #define ld_mutex_lock_fn ld_thread.ltf_mutex_lock 340*0Sstevel@tonic-gate #define ld_mutex_unlock_fn ld_thread.ltf_mutex_unlock 341*0Sstevel@tonic-gate #define ld_get_errno_fn ld_thread.ltf_get_errno 342*0Sstevel@tonic-gate #define ld_set_errno_fn ld_thread.ltf_set_errno 343*0Sstevel@tonic-gate #define ld_get_lderrno_fn ld_thread.ltf_get_lderrno 344*0Sstevel@tonic-gate #define ld_set_lderrno_fn ld_thread.ltf_set_lderrno 345*0Sstevel@tonic-gate #define ld_lderrno_arg ld_thread.ltf_lderrno_arg 346*0Sstevel@tonic-gate void **ld_mutex; 347*0Sstevel@tonic-gate 348*0Sstevel@tonic-gate /* function pointers, etc. for caching */ 349*0Sstevel@tonic-gate int ld_cache_on; 350*0Sstevel@tonic-gate int ld_cache_strategy; 351*0Sstevel@tonic-gate struct ldap_cache_fns ld_cache; 352*0Sstevel@tonic-gate #define ld_cache_config ld_cache.lcf_config 353*0Sstevel@tonic-gate #define ld_cache_bind ld_cache.lcf_bind 354*0Sstevel@tonic-gate #define ld_cache_unbind ld_cache.lcf_unbind 355*0Sstevel@tonic-gate #define ld_cache_search ld_cache.lcf_search 356*0Sstevel@tonic-gate #define ld_cache_compare ld_cache.lcf_compare 357*0Sstevel@tonic-gate #define ld_cache_add ld_cache.lcf_add 358*0Sstevel@tonic-gate #define ld_cache_delete ld_cache.lcf_delete 359*0Sstevel@tonic-gate #if 0 360*0Sstevel@tonic-gate #define ld_cache_rename ld_cache.lcf_rename 361*0Sstevel@tonic-gate #endif 362*0Sstevel@tonic-gate #define ld_cache_modify ld_cache.lcf_modify 363*0Sstevel@tonic-gate #define ld_cache_modrdn ld_cache.lcf_modrdn 364*0Sstevel@tonic-gate #define ld_cache_abandon ld_cache.lcf_abandon 365*0Sstevel@tonic-gate #define ld_cache_result ld_cache.lcf_result 366*0Sstevel@tonic-gate #define ld_cache_flush ld_cache.lcf_flush 367*0Sstevel@tonic-gate #define ld_cache_arg ld_cache.lcf_arg 368*0Sstevel@tonic-gate 369*0Sstevel@tonic-gate /* ldapv3 controls */ 370*0Sstevel@tonic-gate LDAPControl **ld_servercontrols; 371*0Sstevel@tonic-gate LDAPControl **ld_clientcontrols; 372*0Sstevel@tonic-gate 373*0Sstevel@tonic-gate /* Preferred language */ 374*0Sstevel@tonic-gate char *ld_preferred_language; 375*0Sstevel@tonic-gate 376*0Sstevel@tonic-gate /* MemCache */ 377*0Sstevel@tonic-gate LDAPMemCache *ld_memcache; 378*0Sstevel@tonic-gate 379*0Sstevel@tonic-gate /* Pending results */ 380*0Sstevel@tonic-gate LDAPPend *ld_pend; /* list of pending results */ 381*0Sstevel@tonic-gate 382*0Sstevel@tonic-gate /* extra thread function pointers */ 383*0Sstevel@tonic-gate struct ldap_extra_thread_fns ld_thread2; 384*0Sstevel@tonic-gate 385*0Sstevel@tonic-gate /* With the 4.0 version of the LDAP SDK */ 386*0Sstevel@tonic-gate /* the extra thread functions except for */ 387*0Sstevel@tonic-gate /* the ld_threadid_fn has been disabled */ 388*0Sstevel@tonic-gate /* Look at the release notes for the full */ 389*0Sstevel@tonic-gate /* explanation */ 390*0Sstevel@tonic-gate #define ld_mutex_trylock_fn ld_thread2.ltf_mutex_trylock 391*0Sstevel@tonic-gate #define ld_sema_alloc_fn ld_thread2.ltf_sema_alloc 392*0Sstevel@tonic-gate #define ld_sema_free_fn ld_thread2.ltf_sema_free 393*0Sstevel@tonic-gate #define ld_sema_wait_fn ld_thread2.ltf_sema_wait 394*0Sstevel@tonic-gate #define ld_sema_post_fn ld_thread2.ltf_sema_post 395*0Sstevel@tonic-gate #define ld_threadid_fn ld_thread2.ltf_threadid_fn 396*0Sstevel@tonic-gate 397*0Sstevel@tonic-gate /* extra data for mutex handling in referrals */ 398*0Sstevel@tonic-gate void *ld_mutex_threadid[LDAP_MAX_LOCK]; 399*0Sstevel@tonic-gate unsigned long ld_mutex_refcnt[LDAP_MAX_LOCK]; 400*0Sstevel@tonic-gate 401*0Sstevel@tonic-gate /* connect timeout value (milliseconds) */ 402*0Sstevel@tonic-gate int ld_connect_timeout; 403*0Sstevel@tonic-gate 404*0Sstevel@tonic-gate #ifdef LDAP_SASLIO_HOOKS 405*0Sstevel@tonic-gate /* SASL default option settings */ 406*0Sstevel@tonic-gate char *ld_def_sasl_mech; 407*0Sstevel@tonic-gate char *ld_def_sasl_realm; 408*0Sstevel@tonic-gate char *ld_def_sasl_authcid; 409*0Sstevel@tonic-gate char *ld_def_sasl_authzid; 410*0Sstevel@tonic-gate /* SASL Security properties */ 411*0Sstevel@tonic-gate struct sasl_security_properties ld_sasl_secprops; 412*0Sstevel@tonic-gate /* prldap shadow io functions */ 413*0Sstevel@tonic-gate struct ldap_x_ext_io_fns ld_sasl_io_fns; 414*0Sstevel@tonic-gate #endif 415*0Sstevel@tonic-gate }; 416*0Sstevel@tonic-gate 417*0Sstevel@tonic-gate /* allocate/free mutex */ 418*0Sstevel@tonic-gate #define LDAP_MUTEX_ALLOC( ld ) \ 419*0Sstevel@tonic-gate (((ld)->ld_mutex_alloc_fn != NULL) ? (ld)->ld_mutex_alloc_fn() : NULL) 420*0Sstevel@tonic-gate 421*0Sstevel@tonic-gate /* allocate/free mutex */ 422*0Sstevel@tonic-gate #define LDAP_MUTEX_FREE( ld, m ) \ 423*0Sstevel@tonic-gate if ( (ld)->ld_mutex_free_fn != NULL && m != NULL ) { \ 424*0Sstevel@tonic-gate (ld)->ld_mutex_free_fn( m ); \ 425*0Sstevel@tonic-gate } 426*0Sstevel@tonic-gate 427*0Sstevel@tonic-gate /* enter/exit critical sections */ 428*0Sstevel@tonic-gate /* 429*0Sstevel@tonic-gate * The locks assume that the locks are thread safe. XXXmcs: which means??? 430*0Sstevel@tonic-gate * 431*0Sstevel@tonic-gate * Note that we test for both ld_mutex_lock_fn != NULL AND ld_mutex != NULL. 432*0Sstevel@tonic-gate * This is necessary because there is a window in ldap_init() between the 433*0Sstevel@tonic-gate * time we set the ld_mutex_lock_fn pointer and the time we allocate the 434*0Sstevel@tonic-gate * mutexes in which external code COULD be called which COULD make a call to 435*0Sstevel@tonic-gate * something like ldap_get_option(), which uses LDAP_MUTEX_LOCK(). The 436*0Sstevel@tonic-gate * libprldap code does this in its newhandle callback (prldap_newhandle). 437*0Sstevel@tonic-gate */ 438*0Sstevel@tonic-gate 439*0Sstevel@tonic-gate #define LDAP_MUTEX_LOCK(ld, lock) \ 440*0Sstevel@tonic-gate if ((ld)->ld_mutex_lock_fn != NULL && ld->ld_mutex != NULL) { \ 441*0Sstevel@tonic-gate if ((ld)->ld_threadid_fn != NULL) { \ 442*0Sstevel@tonic-gate if ((ld)->ld_mutex_threadid[lock] == (ld)->ld_threadid_fn()) { \ 443*0Sstevel@tonic-gate (ld)->ld_mutex_refcnt[lock]++; \ 444*0Sstevel@tonic-gate } else { \ 445*0Sstevel@tonic-gate (ld)->ld_mutex_lock_fn(ld->ld_mutex[lock]); \ 446*0Sstevel@tonic-gate (ld)->ld_mutex_threadid[lock] = ld->ld_threadid_fn(); \ 447*0Sstevel@tonic-gate (ld)->ld_mutex_refcnt[lock] = 1; \ 448*0Sstevel@tonic-gate } \ 449*0Sstevel@tonic-gate } else { \ 450*0Sstevel@tonic-gate (ld)->ld_mutex_lock_fn(ld->ld_mutex[lock]); \ 451*0Sstevel@tonic-gate } \ 452*0Sstevel@tonic-gate } 453*0Sstevel@tonic-gate 454*0Sstevel@tonic-gate #define LDAP_MUTEX_UNLOCK(ld, lock) \ 455*0Sstevel@tonic-gate if ((ld)->ld_mutex_lock_fn != NULL && ld->ld_mutex != NULL) { \ 456*0Sstevel@tonic-gate if ((ld)->ld_threadid_fn != NULL) { \ 457*0Sstevel@tonic-gate if ((ld)->ld_mutex_threadid[lock] == (ld)->ld_threadid_fn()) { \ 458*0Sstevel@tonic-gate (ld)->ld_mutex_refcnt[lock]--; \ 459*0Sstevel@tonic-gate if ((ld)->ld_mutex_refcnt[lock] <= 0) { \ 460*0Sstevel@tonic-gate (ld)->ld_mutex_threadid[lock] = (void *) -1; \ 461*0Sstevel@tonic-gate (ld)->ld_mutex_refcnt[lock] = 0; \ 462*0Sstevel@tonic-gate (ld)->ld_mutex_unlock_fn(ld->ld_mutex[lock]); \ 463*0Sstevel@tonic-gate } \ 464*0Sstevel@tonic-gate } \ 465*0Sstevel@tonic-gate } else { \ 466*0Sstevel@tonic-gate ld->ld_mutex_unlock_fn(ld->ld_mutex[lock]); \ 467*0Sstevel@tonic-gate } \ 468*0Sstevel@tonic-gate } 469*0Sstevel@tonic-gate 470*0Sstevel@tonic-gate /* Backward compatibility locks */ 471*0Sstevel@tonic-gate #define LDAP_MUTEX_BC_LOCK( ld, i ) \ 472*0Sstevel@tonic-gate /* the ld_mutex_trylock_fn is always set to NULL */ \ 473*0Sstevel@tonic-gate /* in setoption.c as the extra thread functions were */ \ 474*0Sstevel@tonic-gate /* turned off in the 4.0 SDK. This check will */ \ 475*0Sstevel@tonic-gate /* always be true */ \ 476*0Sstevel@tonic-gate if( (ld)->ld_mutex_trylock_fn == NULL ) { \ 477*0Sstevel@tonic-gate LDAP_MUTEX_LOCK( ld, i ) ; \ 478*0Sstevel@tonic-gate } 479*0Sstevel@tonic-gate #define LDAP_MUTEX_BC_UNLOCK( ld, i ) \ 480*0Sstevel@tonic-gate /* the ld_mutex_trylock_fn is always set to NULL */ \ 481*0Sstevel@tonic-gate /* in setoption.c as the extra thread functions were */ \ 482*0Sstevel@tonic-gate /* turned off in the 4.0 SDK. This check will */ \ 483*0Sstevel@tonic-gate /* always be true */ \ 484*0Sstevel@tonic-gate if( (ld)->ld_mutex_trylock_fn == NULL ) { \ 485*0Sstevel@tonic-gate LDAP_MUTEX_UNLOCK( ld, i ) ; \ 486*0Sstevel@tonic-gate } 487*0Sstevel@tonic-gate 488*0Sstevel@tonic-gate /* allocate/free semaphore */ 489*0Sstevel@tonic-gate #define LDAP_SEMA_ALLOC( ld ) \ 490*0Sstevel@tonic-gate (((ld)->ld_sema_alloc_fn != NULL) ? (ld)->ld_sema_alloc_fn() : NULL) 491*0Sstevel@tonic-gate #define LDAP_SEMA_FREE( ld, m ) \ 492*0Sstevel@tonic-gate if ( (ld)->ld_sema_free_fn != NULL && m != NULL ) { \ 493*0Sstevel@tonic-gate (ld)->ld_sema_free_fn( m ); \ 494*0Sstevel@tonic-gate } 495*0Sstevel@tonic-gate 496*0Sstevel@tonic-gate /* wait/post binary semaphore */ 497*0Sstevel@tonic-gate #define LDAP_SEMA_WAIT( ld, lp ) \ 498*0Sstevel@tonic-gate if ( (ld)->ld_sema_wait_fn != NULL ) { \ 499*0Sstevel@tonic-gate (ld)->ld_sema_wait_fn( lp->lp_sema ); \ 500*0Sstevel@tonic-gate } 501*0Sstevel@tonic-gate #define LDAP_SEMA_POST( ld, lp ) \ 502*0Sstevel@tonic-gate if ( (ld)->ld_sema_post_fn != NULL ) { \ 503*0Sstevel@tonic-gate (ld)->ld_sema_post_fn( lp->lp_sema ); \ 504*0Sstevel@tonic-gate } 505*0Sstevel@tonic-gate #define POST( ld, y, z ) \ 506*0Sstevel@tonic-gate /* the ld_mutex_trylock_fn is always set to NULL */ \ 507*0Sstevel@tonic-gate /* in setoption.c as the extra thread functions were */ \ 508*0Sstevel@tonic-gate /* turned off in the 4.0 SDK. This check will */ \ 509*0Sstevel@tonic-gate /* always be false */ \ 510*0Sstevel@tonic-gate if( (ld)->ld_mutex_trylock_fn != NULL ) { \ 511*0Sstevel@tonic-gate nsldapi_post_result( ld, y, z ); \ 512*0Sstevel@tonic-gate } 513*0Sstevel@tonic-gate 514*0Sstevel@tonic-gate /* get/set errno */ 515*0Sstevel@tonic-gate #ifndef macintosh 516*0Sstevel@tonic-gate #define LDAP_SET_ERRNO( ld, e ) \ 517*0Sstevel@tonic-gate if ( (ld)->ld_set_errno_fn != NULL ) { \ 518*0Sstevel@tonic-gate (ld)->ld_set_errno_fn( e ); \ 519*0Sstevel@tonic-gate } else { \ 520*0Sstevel@tonic-gate errno = e; \ 521*0Sstevel@tonic-gate } 522*0Sstevel@tonic-gate #define LDAP_GET_ERRNO( ld ) \ 523*0Sstevel@tonic-gate (((ld)->ld_get_errno_fn != NULL) ? \ 524*0Sstevel@tonic-gate (ld)->ld_get_errno_fn() : errno) 525*0Sstevel@tonic-gate #else /* macintosh */ 526*0Sstevel@tonic-gate #define LDAP_SET_ERRNO( ld, e ) \ 527*0Sstevel@tonic-gate if ( (ld)->ld_set_errno_fn != NULL ) { \ 528*0Sstevel@tonic-gate (ld)->ld_set_errno_fn( e ); \ 529*0Sstevel@tonic-gate } 530*0Sstevel@tonic-gate #define LDAP_GET_ERRNO( ld ) \ 531*0Sstevel@tonic-gate (((ld)->ld_get_errno_fn != NULL) ? \ 532*0Sstevel@tonic-gate (ld)->ld_get_errno_fn() : 0) 533*0Sstevel@tonic-gate #endif 534*0Sstevel@tonic-gate 535*0Sstevel@tonic-gate 536*0Sstevel@tonic-gate /* get/set ldap-specific errno */ 537*0Sstevel@tonic-gate #define LDAP_SET_LDERRNO( ld, e, m, s ) ldap_set_lderrno( ld, e, m, s ) 538*0Sstevel@tonic-gate #define LDAP_GET_LDERRNO( ld, m, s ) ldap_get_lderrno( ld, m, s ) 539*0Sstevel@tonic-gate 540*0Sstevel@tonic-gate /* 541*0Sstevel@tonic-gate * your standard "mimimum of two values" macro 542*0Sstevel@tonic-gate */ 543*0Sstevel@tonic-gate #define NSLDAPI_MIN(a, b) (((a) < (b)) ? (a) : (b)) 544*0Sstevel@tonic-gate 545*0Sstevel@tonic-gate /* 546*0Sstevel@tonic-gate * handy macro to check whether LDAP struct is set up for CLDAP or not 547*0Sstevel@tonic-gate */ 548*0Sstevel@tonic-gate #define LDAP_IS_CLDAP( ld ) ( ld->ld_sbp->sb_naddr > 0 ) 549*0Sstevel@tonic-gate 550*0Sstevel@tonic-gate /* 551*0Sstevel@tonic-gate * handy macro to check errno "e" for an "in progress" sort of error 552*0Sstevel@tonic-gate */ 553*0Sstevel@tonic-gate #if defined(macintosh) || defined(_WINDOWS) 554*0Sstevel@tonic-gate #define NSLDAPI_ERRNO_IO_INPROGRESS( e ) ((e) == EWOULDBLOCK || (e) == EAGAIN) 555*0Sstevel@tonic-gate #else 556*0Sstevel@tonic-gate #ifdef EAGAIN 557*0Sstevel@tonic-gate #define NSLDAPI_ERRNO_IO_INPROGRESS( e ) ((e) == EWOULDBLOCK || (e) == EINPROGRESS || (e) == EAGAIN) 558*0Sstevel@tonic-gate #else /* EAGAIN */ 559*0Sstevel@tonic-gate #define NSLDAPI_ERRNO_IO_INPROGRESS( e ) ((e) == EWOULDBLOCK || (e) == EINPROGRESS) 560*0Sstevel@tonic-gate #endif /* EAGAIN */ 561*0Sstevel@tonic-gate #endif /* macintosh || _WINDOWS*/ 562*0Sstevel@tonic-gate 563*0Sstevel@tonic-gate /* 564*0Sstevel@tonic-gate * macro to return the LDAP protocol version we are using 565*0Sstevel@tonic-gate */ 566*0Sstevel@tonic-gate #define NSLDAPI_LDAP_VERSION( ld ) ( (ld)->ld_defconn == NULL ? \ 567*0Sstevel@tonic-gate (ld)->ld_version : \ 568*0Sstevel@tonic-gate (ld)->ld_defconn->lconn_version ) 569*0Sstevel@tonic-gate 570*0Sstevel@tonic-gate /* 571*0Sstevel@tonic-gate * Structures used for handling client filter lists. 572*0Sstevel@tonic-gate */ 573*0Sstevel@tonic-gate #define LDAP_FILT_MAXSIZ 1024 574*0Sstevel@tonic-gate 575*0Sstevel@tonic-gate struct ldap_filt_list { 576*0Sstevel@tonic-gate char *lfl_tag; 577*0Sstevel@tonic-gate char *lfl_pattern; 578*0Sstevel@tonic-gate char *lfl_delims; 579*0Sstevel@tonic-gate struct ldap_filt_info *lfl_ilist; 580*0Sstevel@tonic-gate struct ldap_filt_list *lfl_next; 581*0Sstevel@tonic-gate }; 582*0Sstevel@tonic-gate 583*0Sstevel@tonic-gate struct ldap_filt_desc { 584*0Sstevel@tonic-gate LDAPFiltList *lfd_filtlist; 585*0Sstevel@tonic-gate LDAPFiltInfo *lfd_curfip; 586*0Sstevel@tonic-gate LDAPFiltInfo lfd_retfi; 587*0Sstevel@tonic-gate char lfd_filter[ LDAP_FILT_MAXSIZ ]; 588*0Sstevel@tonic-gate char *lfd_curval; 589*0Sstevel@tonic-gate char *lfd_curvalcopy; 590*0Sstevel@tonic-gate char **lfd_curvalwords; 591*0Sstevel@tonic-gate char *lfd_filtprefix; 592*0Sstevel@tonic-gate char *lfd_filtsuffix; 593*0Sstevel@tonic-gate }; 594*0Sstevel@tonic-gate 595*0Sstevel@tonic-gate /* 596*0Sstevel@tonic-gate * "internal" globals used to track defaults and memory allocation callbacks: 597*0Sstevel@tonic-gate * (the actual definitions are in open.c) 598*0Sstevel@tonic-gate */ 599*0Sstevel@tonic-gate extern struct ldap nsldapi_ld_defaults; 600*0Sstevel@tonic-gate extern struct ldap_memalloc_fns nsldapi_memalloc_fns; 601*0Sstevel@tonic-gate extern int nsldapi_initialized; 602*0Sstevel@tonic-gate 603*0Sstevel@tonic-gate 604*0Sstevel@tonic-gate /* 605*0Sstevel@tonic-gate * Memory allocation done in liblber should all go through one of the 606*0Sstevel@tonic-gate * following macros. This is so we can plug-in alternative memory 607*0Sstevel@tonic-gate * allocators, etc. as the need arises. 608*0Sstevel@tonic-gate */ 609*0Sstevel@tonic-gate #define NSLDAPI_MALLOC( size ) ldap_x_malloc( size ) 610*0Sstevel@tonic-gate #define NSLDAPI_CALLOC( nelem, elsize ) ldap_x_calloc( nelem, elsize ) 611*0Sstevel@tonic-gate #define NSLDAPI_REALLOC( ptr, size ) ldap_x_realloc( ptr, size ) 612*0Sstevel@tonic-gate #define NSLDAPI_FREE( ptr ) ldap_x_free( ptr ) 613*0Sstevel@tonic-gate 614*0Sstevel@tonic-gate 615*0Sstevel@tonic-gate /* 616*0Sstevel@tonic-gate * macros used to check validity of data structures and parameters 617*0Sstevel@tonic-gate */ 618*0Sstevel@tonic-gate #define NSLDAPI_VALID_LDAP_POINTER( ld ) \ 619*0Sstevel@tonic-gate ( (ld) != NULL ) 620*0Sstevel@tonic-gate 621*0Sstevel@tonic-gate #define NSLDAPI_VALID_LDAPMESSAGE_POINTER( lm ) \ 622*0Sstevel@tonic-gate ( (lm) != NULL ) 623*0Sstevel@tonic-gate 624*0Sstevel@tonic-gate #define NSLDAPI_VALID_LDAPMESSAGE_ENTRY_POINTER( lm ) \ 625*0Sstevel@tonic-gate ( (lm) != NULL && (lm)->lm_msgtype == LDAP_RES_SEARCH_ENTRY ) 626*0Sstevel@tonic-gate 627*0Sstevel@tonic-gate #define NSLDAPI_VALID_LDAPMESSAGE_REFERENCE_POINTER( lm ) \ 628*0Sstevel@tonic-gate ( (lm) != NULL && (lm)->lm_msgtype == LDAP_RES_SEARCH_REFERENCE ) 629*0Sstevel@tonic-gate 630*0Sstevel@tonic-gate #define NSLDAPI_VALID_LDAPMESSAGE_BINDRESULT_POINTER( lm ) \ 631*0Sstevel@tonic-gate ( (lm) != NULL && (lm)->lm_msgtype == LDAP_RES_BIND ) 632*0Sstevel@tonic-gate 633*0Sstevel@tonic-gate #define NSLDAPI_VALID_LDAPMESSAGE_EXRESULT_POINTER( lm ) \ 634*0Sstevel@tonic-gate ( (lm) != NULL && (lm)->lm_msgtype == LDAP_RES_EXTENDED ) 635*0Sstevel@tonic-gate 636*0Sstevel@tonic-gate #define NSLDAPI_VALID_LDAPMOD_ARRAY( mods ) \ 637*0Sstevel@tonic-gate ( (mods) != NULL ) 638*0Sstevel@tonic-gate 639*0Sstevel@tonic-gate #define NSLDAPI_VALID_NONEMPTY_LDAPMOD_ARRAY( mods ) \ 640*0Sstevel@tonic-gate ( (mods) != NULL && (mods)[0] != NULL ) 641*0Sstevel@tonic-gate 642*0Sstevel@tonic-gate #define NSLDAPI_IS_SEARCH_ENTRY( code ) \ 643*0Sstevel@tonic-gate ((code) == LDAP_RES_SEARCH_ENTRY) 644*0Sstevel@tonic-gate 645*0Sstevel@tonic-gate #define NSLDAPI_IS_SEARCH_RESULT( code ) \ 646*0Sstevel@tonic-gate ((code) == LDAP_RES_SEARCH_RESULT) 647*0Sstevel@tonic-gate 648*0Sstevel@tonic-gate #define NSLDAPI_SEARCH_RELATED_RESULT( code ) \ 649*0Sstevel@tonic-gate (NSLDAPI_IS_SEARCH_RESULT( code ) || NSLDAPI_IS_SEARCH_ENTRY( code )) 650*0Sstevel@tonic-gate 651*0Sstevel@tonic-gate /* 652*0Sstevel@tonic-gate * in bind.c 653*0Sstevel@tonic-gate */ 654*0Sstevel@tonic-gate char *nsldapi_get_binddn( LDAP *ld ); 655*0Sstevel@tonic-gate 656*0Sstevel@tonic-gate /* 657*0Sstevel@tonic-gate * in cache.c 658*0Sstevel@tonic-gate */ 659*0Sstevel@tonic-gate void nsldapi_add_result_to_cache( LDAP *ld, LDAPMessage *result ); 660*0Sstevel@tonic-gate 661*0Sstevel@tonic-gate /* 662*0Sstevel@tonic-gate * in dsparse.c 663*0Sstevel@tonic-gate */ 664*0Sstevel@tonic-gate int ldap_next_line_tokens( char **bufp, long *blenp, char ***toksp ); 665*0Sstevel@tonic-gate void ldap_free_strarray( char **sap ); 666*0Sstevel@tonic-gate 667*0Sstevel@tonic-gate /* 668*0Sstevel@tonic-gate * in error.c 669*0Sstevel@tonic-gate */ 670*0Sstevel@tonic-gate int nsldapi_parse_result( LDAP *ld, int msgtype, BerElement *rber, 671*0Sstevel@tonic-gate int *errcodep, char **matchednp, char **errmsgp, char ***referralsp, 672*0Sstevel@tonic-gate LDAPControl ***serverctrlsp ); 673*0Sstevel@tonic-gate 674*0Sstevel@tonic-gate /* 675*0Sstevel@tonic-gate * in open.c 676*0Sstevel@tonic-gate */ 677*0Sstevel@tonic-gate void nsldapi_initialize_defaults( void ); 678*0Sstevel@tonic-gate void nsldapi_mutex_alloc_all( LDAP *ld ); 679*0Sstevel@tonic-gate void nsldapi_mutex_free_all( LDAP *ld ); 680*0Sstevel@tonic-gate int nsldapi_open_ldap_defconn( LDAP *ld ); 681*0Sstevel@tonic-gate char *nsldapi_strdup( const char *s ); /* if s is NULL, returns NULL */ 682*0Sstevel@tonic-gate 683*0Sstevel@tonic-gate /* 684*0Sstevel@tonic-gate * in os-ip.c 685*0Sstevel@tonic-gate */ 686*0Sstevel@tonic-gate int nsldapi_connect_to_host( LDAP *ld, Sockbuf *sb, const char *host, 687*0Sstevel@tonic-gate int port, int secure, char **krbinstancep ); 688*0Sstevel@tonic-gate void nsldapi_close_connection( LDAP *ld, Sockbuf *sb ); 689*0Sstevel@tonic-gate 690*0Sstevel@tonic-gate int nsldapi_iostatus_poll( LDAP *ld, struct timeval *timeout ); 691*0Sstevel@tonic-gate void nsldapi_iostatus_free( LDAP *ld ); 692*0Sstevel@tonic-gate int nsldapi_iostatus_interest_write( LDAP *ld, Sockbuf *sb ); 693*0Sstevel@tonic-gate int nsldapi_iostatus_interest_read( LDAP *ld, Sockbuf *sb ); 694*0Sstevel@tonic-gate int nsldapi_iostatus_interest_clear( LDAP *ld, Sockbuf *sb ); 695*0Sstevel@tonic-gate int nsldapi_iostatus_is_read_ready( LDAP *ld, Sockbuf *sb ); 696*0Sstevel@tonic-gate int nsldapi_iostatus_is_write_ready( LDAP *ld, Sockbuf *sb ); 697*0Sstevel@tonic-gate int nsldapi_install_lber_extiofns( LDAP *ld, Sockbuf *sb ); 698*0Sstevel@tonic-gate int nsldapi_install_compat_io_fns( LDAP *ld, struct ldap_io_fns *iofns ); 699*0Sstevel@tonic-gate 700*0Sstevel@tonic-gate /* 701*0Sstevel@tonic-gate * if referral.c 702*0Sstevel@tonic-gate */ 703*0Sstevel@tonic-gate int nsldapi_parse_reference( LDAP *ld, BerElement *rber, char ***referralsp, 704*0Sstevel@tonic-gate LDAPControl ***serverctrlsp ); 705*0Sstevel@tonic-gate 706*0Sstevel@tonic-gate /* 707*0Sstevel@tonic-gate * in result.c 708*0Sstevel@tonic-gate */ 709*0Sstevel@tonic-gate int ldap_msgdelete( LDAP *ld, int msgid ); 710*0Sstevel@tonic-gate int nsldapi_result_nolock( LDAP *ld, int msgid, int all, int unlock_permitted, 711*0Sstevel@tonic-gate struct timeval *timeout, LDAPMessage **result ); 712*0Sstevel@tonic-gate int nsldapi_wait_result( LDAP *ld, int msgid, int all, struct timeval *timeout, 713*0Sstevel@tonic-gate LDAPMessage **result ); 714*0Sstevel@tonic-gate int nsldapi_post_result( LDAP *ld, int msgid, LDAPMessage *result ); 715*0Sstevel@tonic-gate 716*0Sstevel@tonic-gate /* 717*0Sstevel@tonic-gate * in request.c 718*0Sstevel@tonic-gate */ 719*0Sstevel@tonic-gate int nsldapi_send_initial_request( LDAP *ld, int msgid, unsigned long msgtype, 720*0Sstevel@tonic-gate char *dn, BerElement *ber ); 721*0Sstevel@tonic-gate int nsldapi_alloc_ber_with_options( LDAP *ld, BerElement **berp ); 722*0Sstevel@tonic-gate void nsldapi_set_ber_options( LDAP *ld, BerElement *ber ); 723*0Sstevel@tonic-gate int nsldapi_ber_flush( LDAP *ld, Sockbuf *sb, BerElement *ber, int freeit, 724*0Sstevel@tonic-gate int async ); 725*0Sstevel@tonic-gate int nsldapi_send_server_request( LDAP *ld, BerElement *ber, int msgid, 726*0Sstevel@tonic-gate LDAPRequest *parentreq, LDAPServer *srvlist, LDAPConn *lc, 727*0Sstevel@tonic-gate char *bindreqdn, int bind ); 728*0Sstevel@tonic-gate LDAPConn *nsldapi_new_connection( LDAP *ld, LDAPServer **srvlistp, int use_ldsb, 729*0Sstevel@tonic-gate int connect, int bind ); 730*0Sstevel@tonic-gate LDAPRequest *nsldapi_find_request_by_msgid( LDAP *ld, int msgid ); 731*0Sstevel@tonic-gate void nsldapi_free_request( LDAP *ld, LDAPRequest *lr, int free_conn ); 732*0Sstevel@tonic-gate void nsldapi_free_connection( LDAP *ld, LDAPConn *lc, 733*0Sstevel@tonic-gate LDAPControl **serverctrls, LDAPControl **clientctrls, 734*0Sstevel@tonic-gate int force, int unbind ); 735*0Sstevel@tonic-gate void nsldapi_dump_connection( LDAP *ld, LDAPConn *lconns, int all ); 736*0Sstevel@tonic-gate void nsldapi_dump_requests_and_responses( LDAP *ld ); 737*0Sstevel@tonic-gate int nsldapi_chase_v2_referrals( LDAP *ld, LDAPRequest *lr, char **errstrp, 738*0Sstevel@tonic-gate int *totalcountp, int *chasingcountp ); 739*0Sstevel@tonic-gate int nsldapi_chase_v3_refs( LDAP *ld, LDAPRequest *lr, char **refs, 740*0Sstevel@tonic-gate int is_reference, int *totalcountp, int *chasingcountp ); 741*0Sstevel@tonic-gate int nsldapi_append_referral( LDAP *ld, char **referralsp, char *s ); 742*0Sstevel@tonic-gate void nsldapi_connection_lost_nolock( LDAP *ld, Sockbuf *sb ); 743*0Sstevel@tonic-gate 744*0Sstevel@tonic-gate /* 745*0Sstevel@tonic-gate * in search.c 746*0Sstevel@tonic-gate */ 747*0Sstevel@tonic-gate int nsldapi_build_search_req( LDAP *ld, const char *base, int scope, 748*0Sstevel@tonic-gate const char *filter, char **attrs, int attrsonly, 749*0Sstevel@tonic-gate LDAPControl **serverctrls, LDAPControl **clientctrls, 750*0Sstevel@tonic-gate int timelimit, int sizelimit, int msgid, BerElement **berp ); 751*0Sstevel@tonic-gate 752*0Sstevel@tonic-gate int ldap_put_filter( BerElement *ber, char *str ); 753*0Sstevel@tonic-gate /* 754*0Sstevel@tonic-gate * in unbind.c 755*0Sstevel@tonic-gate */ 756*0Sstevel@tonic-gate int ldap_ld_free( LDAP *ld, LDAPControl **serverctrls, 757*0Sstevel@tonic-gate LDAPControl **clientctrls, int close ); 758*0Sstevel@tonic-gate int nsldapi_send_unbind( LDAP *ld, Sockbuf *sb, LDAPControl **serverctrls, 759*0Sstevel@tonic-gate LDAPControl **clientctrls ); 760*0Sstevel@tonic-gate 761*0Sstevel@tonic-gate #ifdef LDAP_DNS 762*0Sstevel@tonic-gate /* 763*0Sstevel@tonic-gate * in getdxbyname.c 764*0Sstevel@tonic-gate */ 765*0Sstevel@tonic-gate char **nsldapi_getdxbyname( char *domain ); 766*0Sstevel@tonic-gate 767*0Sstevel@tonic-gate #endif /* LDAP_DNS */ 768*0Sstevel@tonic-gate 769*0Sstevel@tonic-gate /* 770*0Sstevel@tonic-gate * in unescape.c 771*0Sstevel@tonic-gate */ 772*0Sstevel@tonic-gate void nsldapi_hex_unescape( char *s ); 773*0Sstevel@tonic-gate 774*0Sstevel@tonic-gate /* 775*0Sstevel@tonic-gate * in reslist.c 776*0Sstevel@tonic-gate */ 777*0Sstevel@tonic-gate LDAPMessage *ldap_delete_result_entry( LDAPMessage **list, LDAPMessage *e ); 778*0Sstevel@tonic-gate void ldap_add_result_entry( LDAPMessage **list, LDAPMessage *e ); 779*0Sstevel@tonic-gate 780*0Sstevel@tonic-gate /* 781*0Sstevel@tonic-gate * in compat.c 782*0Sstevel@tonic-gate */ 783*0Sstevel@tonic-gate #ifdef hpux 784*0Sstevel@tonic-gate char *nsldapi_compat_ctime_r( const time_t *clock, char *buf, int buflen ); 785*0Sstevel@tonic-gate struct hostent *nsldapi_compat_gethostbyname_r( const char *name, 786*0Sstevel@tonic-gate struct hostent *result, char *buffer, int buflen, int *h_errnop ); 787*0Sstevel@tonic-gate #endif /* hpux */ 788*0Sstevel@tonic-gate 789*0Sstevel@tonic-gate /* 790*0Sstevel@tonic-gate * in control.c 791*0Sstevel@tonic-gate */ 792*0Sstevel@tonic-gate int nsldapi_put_controls( LDAP *ld, LDAPControl **ctrls, int closeseq, 793*0Sstevel@tonic-gate BerElement *ber ); 794*0Sstevel@tonic-gate int nsldapi_get_controls( BerElement *ber, LDAPControl ***controlsp ); 795*0Sstevel@tonic-gate int nsldapi_dup_controls( LDAP *ld, LDAPControl ***ldctrls, 796*0Sstevel@tonic-gate LDAPControl **newctrls ); 797*0Sstevel@tonic-gate int nsldapi_build_control( char *oid, BerElement *ber, int freeber, 798*0Sstevel@tonic-gate char iscritical, LDAPControl **ctrlp ); 799*0Sstevel@tonic-gate 800*0Sstevel@tonic-gate 801*0Sstevel@tonic-gate /* 802*0Sstevel@tonic-gate * in url.c 803*0Sstevel@tonic-gate */ 804*0Sstevel@tonic-gate int nsldapi_url_parse( const char *inurl, LDAPURLDesc **ludpp, 805*0Sstevel@tonic-gate int dn_required ); 806*0Sstevel@tonic-gate 807*0Sstevel@tonic-gate /* 808*0Sstevel@tonic-gate * in ../ber/bprint.c 809*0Sstevel@tonic-gate */ 810*0Sstevel@tonic-gate void ber_err_print( char *data ); 811*0Sstevel@tonic-gate 812*0Sstevel@tonic-gate #ifdef _SOLARIS_SDK 813*0Sstevel@tonic-gate /* 814*0Sstevel@tonic-gate * in ../prldap/ldappr-dns.c 815*0Sstevel@tonic-gate */ 816*0Sstevel@tonic-gate int prldap_x_install_dns_skipdb(LDAP *ld, const char *skip); 817*0Sstevel@tonic-gate /* 818*0Sstevel@tonic-gate * in ../prldap/ldappr-threads.c 819*0Sstevel@tonic-gate */ 820*0Sstevel@tonic-gate void prldap_nspr_init(void); 821*0Sstevel@tonic-gate #endif 822*0Sstevel@tonic-gate 823*0Sstevel@tonic-gate /* 824*0Sstevel@tonic-gate * in ../prldap/ldappr-public.c 825*0Sstevel@tonic-gate */ 826*0Sstevel@tonic-gate int 827*0Sstevel@tonic-gate prldap_install_io_functions( LDAP *ld, int shared ); 828*0Sstevel@tonic-gate int 829*0Sstevel@tonic-gate prldap_install_dns_functions( LDAP *ld ); 830*0Sstevel@tonic-gate int 831*0Sstevel@tonic-gate prldap_install_thread_functions( LDAP *ld, int shared ); 832*0Sstevel@tonic-gate 833*0Sstevel@tonic-gate 834*0Sstevel@tonic-gate 835*0Sstevel@tonic-gate #ifndef _SOLARIS_SDK 836*0Sstevel@tonic-gate 837*0Sstevel@tonic-gate /* 838*0Sstevel@tonic-gate * in charset.c 839*0Sstevel@tonic-gate * 840*0Sstevel@tonic-gate * If we ever want to expose character set translation functionality to 841*0Sstevel@tonic-gate * users of libldap, all of these prototypes will need to be moved to ldap.h 842*0Sstevel@tonic-gate * 843*0Sstevel@tonic-gate * These are moved to ldap.h in the Solaris version of the library 844*0Sstevel@tonic-gate * 845*0Sstevel@tonic-gate */ 846*0Sstevel@tonic-gate #ifdef STR_TRANSLATION 847*0Sstevel@tonic-gate void ldap_set_string_translators( LDAP *ld, 848*0Sstevel@tonic-gate BERTranslateProc encode_proc, BERTranslateProc decode_proc ); 849*0Sstevel@tonic-gate int ldap_translate_from_t61( LDAP *ld, char **bufp, 850*0Sstevel@tonic-gate unsigned long *lenp, int free_input ); 851*0Sstevel@tonic-gate int ldap_translate_to_t61( LDAP *ld, char **bufp, 852*0Sstevel@tonic-gate unsigned long *lenp, int free_input ); 853*0Sstevel@tonic-gate void ldap_enable_translation( LDAP *ld, LDAPMessage *entry, 854*0Sstevel@tonic-gate int enable ); 855*0Sstevel@tonic-gate #ifdef LDAP_CHARSET_8859 856*0Sstevel@tonic-gate int ldap_t61_to_8859( char **bufp, unsigned long *buflenp, 857*0Sstevel@tonic-gate int free_input ); 858*0Sstevel@tonic-gate int ldap_8859_to_t61( char **bufp, unsigned long *buflenp, 859*0Sstevel@tonic-gate int free_input ); 860*0Sstevel@tonic-gate #endif /* LDAP_CHARSET_8859 */ 861*0Sstevel@tonic-gate #endif /* STR_TRANSLATION */ 862*0Sstevel@tonic-gate 863*0Sstevel@tonic-gate #endif /* _SOLARIS_SDK */ 864*0Sstevel@tonic-gate 865*0Sstevel@tonic-gate /* 866*0Sstevel@tonic-gate * in memcache.h 867*0Sstevel@tonic-gate */ 868*0Sstevel@tonic-gate int ldap_memcache_createkey( LDAP *ld, const char *base, int scope, 869*0Sstevel@tonic-gate const char *filter, char **attrs, int attrsonly, 870*0Sstevel@tonic-gate LDAPControl **serverctrls, LDAPControl **clientctrls, 871*0Sstevel@tonic-gate unsigned long *keyp ); 872*0Sstevel@tonic-gate int ldap_memcache_result( LDAP *ld, int msgid, unsigned long key ); 873*0Sstevel@tonic-gate int ldap_memcache_new( LDAP *ld, int msgid, unsigned long key, 874*0Sstevel@tonic-gate const char *basedn ); 875*0Sstevel@tonic-gate int ldap_memcache_append( LDAP *ld, int msgid, int bLast, LDAPMessage *result ); 876*0Sstevel@tonic-gate int ldap_memcache_abandon( LDAP *ld, int msgid ); 877*0Sstevel@tonic-gate 878*0Sstevel@tonic-gate #endif /* _LDAPINT_H */ 879