ldap-private.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. #ident "@(#)ldap-private.h 1.6 06/10/98 SMI"
  2. /** BEGIN COPYRIGHT BLOCK
  3. * This Program is free software; you can redistribute it and/or modify it under
  4. * the terms of the GNU General Public License as published by the Free Software
  5. * Foundation; version 2 of the License.
  6. *
  7. * This Program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  10. *
  11. * You should have received a copy of the GNU General Public License along with
  12. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  13. * Place, Suite 330, Boston, MA 02111-1307 USA.
  14. *
  15. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  16. * right to link the code of this Program with code not covered under the GNU
  17. * General Public License ("Non-GPL Code") and to distribute linked combinations
  18. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  19. * permitted under this exception must only link to the code of this Program
  20. * through those well defined interfaces identified in the file named EXCEPTION
  21. * found in the source code files (the "Approved Interfaces"). The files of
  22. * Non-GPL Code may instantiate templates or use macros or inline functions from
  23. * the Approved Interfaces without causing the resulting work to be covered by
  24. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  25. * additions to the list of Approved Interfaces. You must obey the GNU General
  26. * Public License in all respects for all of the Program code and other code used
  27. * in conjunction with the Program except the Non-GPL Code covered by this
  28. * exception. If you modify this file, you may extend this exception to your
  29. * version of the file, but you are not obligated to do so. If you do not wish to
  30. * provide this exception without modification, you must delete this exception
  31. * statement from your version and license this file solely under the GPL without
  32. * exception.
  33. *
  34. *
  35. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  36. * Copyright (C) 2006 Red Hat, Inc.
  37. * All rights reserved.
  38. * END COPYRIGHT BLOCK **/
  39. #ifdef HAVE_CONFIG_H
  40. # include <config.h>
  41. #endif
  42. #ifndef _LDAP_PRIVATE_H
  43. #define _LDAP_PRIVATE_H
  44. #ifdef _REENTRANT
  45. #ifndef MAX_THREAD_ID
  46. #define MAX_THREAD_ID 500
  47. #endif /* MAX_THREAD_ID */
  48. #else /* _REENTRANT */
  49. #ifndef MAX_THREAD_ID
  50. #define MAX_THREAD_ID 1
  51. #endif /* MAX_THREAD_ID */
  52. #endif /* _REENTRANT */
  53. #define COMPAT20
  54. #define COMPAT30
  55. #if defined(COMPAT20) || defined(COMPAT30)
  56. #define COMPAT
  57. #endif
  58. #ifdef LDAP_DNS
  59. #define LDAP_OPT_DNS 0x00000001 /* use DN & DNS */
  60. #endif /* LDAP_DNS */
  61. /*
  62. #define DBG_LOCK1(st) printf("%d> %s %d:%s\n", _thr_self(), st, __LINE__, __FILE__);
  63. #define DBG_LOCK2(ld,st) printf("%d> %s ld_lockcount=%d %d:%s\n", _thr_self(), st, (ld)->ld_lockcount, __LINE__, __FILE__);
  64. */
  65. #define DBG_LOCK1(st)
  66. #define DBG_LOCK2(ld,st)
  67. #define LOCK_RESPONSE(ld) \
  68. if ((ld)->ld_response_lockthread != _thr_self()) { \
  69. DBG_LOCK1("waiting for response lock") \
  70. pthread_mutex_lock( &((ld)->ld_response_mutex) ); \
  71. DBG_LOCK1("got response lock") \
  72. (ld)->ld_response_lockthread = _thr_self(); \
  73. } else { \
  74. (ld)->ld_response_lockcount++; \
  75. DBG_LOCK2(ld, "fake ldap lock") \
  76. }
  77. #define UNLOCK_RESPONSE(ld) \
  78. if ((ld)->ld_response_lockcount==0) { \
  79. (ld)->ld_response_lockthread = 0; \
  80. pthread_mutex_unlock( &((ld)->ld_response_mutex) ); \
  81. DBG_LOCK1("freed response lock") \
  82. } else { \
  83. (ld)->ld_response_lockcount--; \
  84. DBG_LOCK2(ld, "fake ldap unlock") \
  85. }
  86. #define LOCK_LDAP(ld) \
  87. if ((ld)->ld_lockthread != _thr_self()) { \
  88. DBG_LOCK1("waiting for ldap lock") \
  89. pthread_mutex_lock( &((ld)->ld_ldap_mutex) ); \
  90. DBG_LOCK1("got ldap lock") \
  91. (ld)->ld_lockthread = _thr_self(); \
  92. } else { \
  93. (ld)->ld_lockcount++; \
  94. DBG_LOCK2(ld, "fake ldap lock") \
  95. }
  96. #define UNLOCK_LDAP(ld) \
  97. if ((ld)->ld_lockcount==0) { \
  98. (ld)->ld_lockthread = 0; \
  99. pthread_mutex_unlock( &((ld)->ld_ldap_mutex) ); \
  100. DBG_LOCK1("freed ldap lock") \
  101. } else { \
  102. (ld)->ld_lockcount--; \
  103. DBG_LOCK2(ld, "fake ldap unlock") \
  104. }
  105. #define LOCK_POLL(ld) pthread_mutex_lock( &ld->ld_poll_mutex )
  106. #define UNLOCK_POLL(ld) pthread_mutex_unlock( &ld->ld_poll_mutex )
  107. /*
  108. * This structure represents both ldap messages and ldap responses.
  109. * These are really the same, except in the case of search responses,
  110. * where a response has multiple messages.
  111. */
  112. typedef struct ldapmsg {
  113. int lm_msgid; /* the message id */
  114. int lm_msgtype; /* the message type */
  115. BerElement *lm_ber; /* the ber encoded message contents */
  116. struct ldapmsg *lm_chain; /* for search - next msg in the resp */
  117. struct ldapmsg *lm_next; /* next response */
  118. unsigned long lm_time; /* used to maintain cache */
  119. } _struct_LDAPMessage;
  120. typedef struct ldap_filt_list {
  121. char *lfl_tag;
  122. char *lfl_pattern;
  123. char *lfl_delims;
  124. LDAPFiltInfo *lfl_ilist;
  125. struct ldap_filt_list *lfl_next;
  126. } _struct_FiltList;
  127. typedef struct ldap_filt_desc {
  128. LDAPFiltList *lfd_filtlist;
  129. LDAPFiltInfo *lfd_curfip;
  130. LDAPFiltInfo lfd_retfi;
  131. char lfd_filter[ LDAP_FILT_MAXSIZ ];
  132. char *lfd_curval;
  133. char *lfd_curvalcopy;
  134. char **lfd_curvalwords;
  135. char *lfd_filtprefix;
  136. char *lfd_filtsuffix;
  137. } _struct_FiltDesc;
  138. /*
  139. * structure for tracking LDAP server host, ports, DNs, etc.
  140. */
  141. typedef struct ldap_server {
  142. char *lsrv_host;
  143. char *lsrv_dn; /* if NULL, use default */
  144. int lsrv_port;
  145. struct ldap_server *lsrv_next;
  146. } LDAPServer;
  147. /*
  148. * structure for representing an LDAP server connection
  149. */
  150. typedef struct ldap_conn {
  151. Sockbuf *lconn_sb;
  152. int lconn_refcnt;
  153. unsigned long lconn_lastused; /* time */
  154. int lconn_status;
  155. #define LDAP_CONNST_NEEDSOCKET 1
  156. #define LDAP_CONNST_CONNECTING 2
  157. #define LDAP_CONNST_CONNECTED 3
  158. LDAPServer *lconn_server;
  159. char *lconn_krbinstance;
  160. struct ldap_conn *lconn_next;
  161. } LDAPConn;
  162. /*
  163. * Structure used to keep track of search references
  164. */
  165. typedef struct ldap_reference {
  166. char ** lref_refs;
  167. struct ldap_reference *lref_next;
  168. } LDAPRef;
  169. /*
  170. * structure used to track outstanding requests
  171. */
  172. typedef struct ldapreq {
  173. int lr_msgid; /* the message id */
  174. int lr_status; /* status of request */
  175. #define LDAP_REQST_INPROGRESS 1
  176. #define LDAP_REQST_CHASINGREFS 2
  177. #define LDAP_REQST_NOTCONNECTED 3
  178. #define LDAP_REQST_WRITING 4
  179. int lr_outrefcnt; /* count of outstanding referrals */
  180. int lr_origid; /* original request's message id */
  181. int lr_parentcnt; /* count of parent requests */
  182. int lr_res_msgtype; /* result message type */
  183. int lr_res_errno; /* result LDAP errno */
  184. char *lr_res_error; /* result error string */
  185. char *lr_res_matched;/* result matched DN string */
  186. BerElement *lr_ber; /* ber encoded request contents */
  187. LDAPConn *lr_conn; /* connection used to send request */
  188. LDAPRef *lr_references;
  189. char **lr_ref_followed; /* referral being followed */
  190. char **lr_ref_unfollowed; /* Not being followed */
  191. char **lr_ref_tofollow; /* referral to follow if the one being
  192. followed fails. */
  193. struct ldapreq *lr_parent; /* request that spawned this referral */
  194. struct ldapreq *lr_refnext; /* next referral spawned */
  195. struct ldapreq *lr_prev; /* previous request */
  196. struct ldapreq *lr_next; /* next request */
  197. } LDAPRequest;
  198. /*
  199. * structure for client cache
  200. */
  201. #define LDAP_CACHE_BUCKETS 31 /* cache hash table size */
  202. typedef struct ldapcache {
  203. LDAPMessage *lc_buckets[LDAP_CACHE_BUCKETS];/* hash table */
  204. LDAPMessage *lc_requests; /* unfulfilled reqs */
  205. long lc_timeout; /* request timeout */
  206. long lc_maxmem; /* memory to use */
  207. long lc_memused; /* memory in use */
  208. int lc_enabled; /* enabled? */
  209. unsigned long lc_options; /* options */
  210. #define LDAP_CACHE_OPT_CACHENOERRS 0x00000001
  211. #define LDAP_CACHE_OPT_CACHEALLERRS 0x00000002
  212. } LDAPCache;
  213. #define NULLLDCACHE ((LDAPCache *)NULL)
  214. /*
  215. * structure representing an ldap connection
  216. */
  217. typedef struct ldap {
  218. Sockbuf ld_sb; /* socket descriptor & buffer */
  219. char *ld_host;
  220. int ld_version;
  221. char ld_lberoptions;
  222. int ld_deref;
  223. int ld_timelimit;
  224. int ld_sizelimit;
  225. LDAPFiltDesc *ld_filtd; /* from getfilter for ufn searches */
  226. char *ld_ufnprefix; /* for incomplete ufn's */
  227. int ld_errno[MAX_THREAD_ID]; /* thread-specific */
  228. #define ld_errno ld_errno[ldap_thr_index()]
  229. char *ld_error[MAX_THREAD_ID]; /* thread-specific */
  230. #define ld_error ld_error[ldap_thr_index()]
  231. char *ld_matched[MAX_THREAD_ID]; /* thread-specific */
  232. #define ld_matched ld_matched[ldap_thr_index()]
  233. char **ld_referrals[MAX_THREAD_ID]; /* thread-specific */
  234. #define ld_referrals ld_referrals[ldap_thr_index()]
  235. LDAPControl **ld_ret_ctrls[MAX_THREAD_ID]; /* thread-specific */
  236. #define ld_ret_ctrls ld_ret_ctrls[ldap_thr_index()]
  237. int ld_msgid;
  238. int ld_follow_referral; /* flag set to true if lib follow referrals */
  239. LDAPRequest *ld_requests; /* list of outstanding requests -- referrals*/
  240. LDAPMessage *ld_responses; /* list of outstanding responses */
  241. int *ld_abandoned; /* array of abandoned requests */
  242. pthread_mutex_t ld_response_mutex; /* mutex for responses part of structure */
  243. pthread_t ld_response_lockthread; /* thread which currently holds the response lock */
  244. int ld_response_lockcount; /* response lock depth */
  245. char *ld_attrbuffer[MAX_THREAD_ID];
  246. #define ld_attrbuffer ld_attrbuffer[ldap_thr_index()]
  247. LDAPCache *ld_cache; /* non-null if cache is initialized */
  248. char *ld_cldapdn; /* DN used in connectionless search */
  249. /* it is OK to change these next four values directly */
  250. int ld_cldaptries; /* connectionless search retry count */
  251. int ld_cldaptimeout;/* time between retries */
  252. int ld_refhoplimit; /* limit on referral nesting */
  253. int ld_restart; /* Decide if continue after interruption */
  254. #ifdef LDAP_SSL
  255. int ld_use_ssl;
  256. char *ld_ssl_key;
  257. #endif
  258. unsigned long ld_options; /* boolean options */
  259. /* do not mess with the rest though */
  260. char *ld_defhost; /* full name of default server */
  261. int ld_defport; /* port of default server */
  262. BERTranslateProc ld_lber_encode_translate_proc;
  263. BERTranslateProc ld_lber_decode_translate_proc;
  264. LDAPConn *ld_defconn; /* default connection */
  265. LDAPConn *ld_conns; /* list of server connections */
  266. void *ld_selectinfo; /* platform specifics for select */
  267. LDAP_REBIND_FUNCTION *ld_rebindproc;
  268. void *ld_rebind_extra_arg;
  269. /* int (*ld_rebindproc)( struct ldap *ld, char **dnp, */
  270. /* char **passwdp, int *authmethodp, int freeit ); */
  271. /* routine to get info needed for re-bind */
  272. pthread_mutex_t ld_ldap_mutex; /* mutex for thread dependent part of struct */
  273. pthread_t ld_lockthread; /* thread which currently holds the lock */
  274. int ld_lockcount; /* lock depth */
  275. pthread_mutex_t ld_poll_mutex; /* a seperate lock for polling */
  276. LDAPControl **ld_srvctrls; /* Controls used by ldap and server */
  277. LDAPControl **ld_cltctrls; /* Client side controls */
  278. /* KE: Lists of unsolicited notifications */
  279. LDAPMessage *ld_notifs[MAX_THREAD_ID];
  280. #define ld_notifs ld_notifs[ldap_thr_index()]
  281. } _struct_LDAP;
  282. /*
  283. * handy macro to check whether LDAP struct is set up for CLDAP or not
  284. */
  285. #define LDAP_IS_CLDAP( ld ) ( ld->ld_sb.sb_naddr > 0 )
  286. #endif /* _LDAP_PRIVATE_H */