ldap-private.h 9.2 KB

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