ldap-int.h 25 KB

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