acl_ext.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. #ifdef HAVE_CONFIG_H
  39. # include <config.h>
  40. #endif
  41. #include "acl.h"
  42. static void acl__done_aclpb ( struct acl_pblock *aclpb );
  43. #ifdef FOR_DEBUGGING
  44. static void acl__dump_stats ( struct acl_pblock *aclpb , const char *block_type);
  45. static char * acl__get_aclpb_type ( Acl_PBlock *aclpb );
  46. #endif
  47. static Acl_PBlock * acl__get_aclpb_from_pool ( );
  48. static int acl__put_aclpb_back_to_pool ( Acl_PBlock *aclpb );
  49. static Acl_PBlock * acl__malloc_aclpb ( );
  50. static void acl__free_aclpb ( Acl_PBlock **aclpb_ptr);
  51. static PRLock *aclext_get_lock ();
  52. struct acl_pbqueue {
  53. Acl_PBlock *aclq_free;
  54. Acl_PBlock *aclq_busy;
  55. short aclq_nfree;
  56. short aclq_nbusy;
  57. PRLock *aclq_lock;
  58. };
  59. typedef struct acl_pbqueue Acl_PBqueue;
  60. static Acl_PBqueue *aclQueue = NULL;
  61. /* structure with information for each extension */
  62. typedef struct acl_ext
  63. {
  64. char *object_name; /* name of the object extended */
  65. int object_type; /* handle to the extended object */
  66. int handle; /* extension handle */
  67. } acl_ext;
  68. static acl_ext acl_ext_list [ACL_EXT_ALL];
  69. /*
  70. * EXTENSION INITIALIZATION, CONSTRUCTION, & DESTRUCTION
  71. *
  72. */
  73. int
  74. acl_init_ext ()
  75. {
  76. int rc;
  77. acl_ext_list[ACL_EXT_OPERATION].object_name = SLAPI_EXT_OPERATION;
  78. rc = slapi_register_object_extension(plugin_name, SLAPI_EXT_OPERATION,
  79. acl_operation_ext_constructor,
  80. acl_operation_ext_destructor,
  81. &acl_ext_list[ACL_EXT_OPERATION].object_type,
  82. &acl_ext_list[ACL_EXT_OPERATION].handle);
  83. if ( rc != 0 ) return rc;
  84. acl_ext_list[ACL_EXT_CONNECTION].object_name = SLAPI_EXT_CONNECTION;
  85. rc = slapi_register_object_extension(plugin_name, SLAPI_EXT_CONNECTION,
  86. acl_conn_ext_constructor,
  87. acl_conn_ext_destructor,
  88. &acl_ext_list[ACL_EXT_CONNECTION].object_type,
  89. &acl_ext_list[ACL_EXT_CONNECTION].handle);
  90. return rc;
  91. }
  92. void
  93. acl_remove_ext ()
  94. {
  95. slapi_unregister_object_extension(plugin_name,
  96. SLAPI_EXT_OPERATION,
  97. &acl_ext_list[ACL_EXT_OPERATION].object_type,
  98. &acl_ext_list[ACL_EXT_OPERATION].handle);
  99. slapi_unregister_object_extension(plugin_name,
  100. SLAPI_EXT_CONNECTION,
  101. &acl_ext_list[ACL_EXT_CONNECTION].object_type,
  102. &acl_ext_list[ACL_EXT_CONNECTION].handle);
  103. }
  104. /* Interface to get the extensions */
  105. void *
  106. acl_get_ext (ext_type type, void *object)
  107. {
  108. struct acl_ext ext;
  109. void *data;
  110. if ( type >= ACL_EXT_ALL ) {
  111. slapi_log_error ( SLAPI_LOG_ACL, plugin_name,
  112. "Invalid extension type:%d\n", type );
  113. return NULL;
  114. }
  115. /* find the requested extension */
  116. ext = acl_ext_list [type];
  117. data = slapi_get_object_extension(ext.object_type, object, ext.handle);
  118. return data;
  119. }
  120. void
  121. acl_set_ext (ext_type type, void *object, void *data)
  122. {
  123. if ( type < ACL_EXT_ALL )
  124. {
  125. struct acl_ext ext = acl_ext_list [type];
  126. slapi_set_object_extension ( ext.object_type, object, ext.handle, data );
  127. }
  128. }
  129. /****************************************************************************
  130. * Global lock array so that private extension between connection and operation
  131. * co-exist
  132. *
  133. ******************************************************************************/
  134. struct ext_lockArray {
  135. PRLock **lockArray;
  136. int numlocks;
  137. };
  138. static struct ext_lockArray extLockArray;
  139. /* PKBxxx: make this a configurable. Start with 2 * maxThreads */
  140. #define ACLEXT_MAX_LOCKS 40
  141. int
  142. aclext_alloc_lockarray ( )
  143. {
  144. int i;
  145. PRLock *lock;
  146. extLockArray.lockArray =
  147. (PRLock **) slapi_ch_calloc ( ACLEXT_MAX_LOCKS, sizeof ( PRLock *) );
  148. for ( i = 0; i < ACLEXT_MAX_LOCKS; i++) {
  149. if (NULL == (lock = PR_NewLock()) ) {
  150. slapi_log_error( SLAPI_LOG_FATAL, plugin_name,
  151. "Unable to allocate locks used for private extension\n");
  152. return 1;
  153. }
  154. extLockArray.lockArray[i] = lock;
  155. }
  156. extLockArray.numlocks = ACLEXT_MAX_LOCKS;
  157. return 0;
  158. }
  159. /*
  160. * Not in use! The connection table still has references to these locks.
  161. * We need to free these after freeing the connection table in daemon.c
  162. */
  163. void
  164. aclext_free_lockarray()
  165. {
  166. int i = 0;
  167. for ( i = 0; i < ACLEXT_MAX_LOCKS; i++) {
  168. if(extLockArray.lockArray[i]){
  169. PR_DestroyLock(extLockArray.lockArray[i]);
  170. extLockArray.lockArray[i] = NULL;
  171. }
  172. }
  173. slapi_ch_free((void **)&extLockArray.lockArray);
  174. }
  175. static PRUint32 slot_id =0;
  176. static PRLock *
  177. aclext_get_lock ()
  178. {
  179. PRUint16 slot = slot_id % ACLEXT_MAX_LOCKS;
  180. slot_id++;
  181. return ( extLockArray.lockArray[slot] );
  182. }
  183. /****************************************************************************/
  184. /* CONNECTION EXTENSION SPECIFIC */
  185. /****************************************************************************/
  186. void *
  187. acl_conn_ext_constructor ( void *object, void *parent )
  188. {
  189. struct acl_cblock *ext = NULL;
  190. ext = (struct acl_cblock * ) slapi_ch_calloc (1, sizeof (struct acl_cblock ) );
  191. if (( ext->aclcb_lock = aclext_get_lock () ) == NULL ) {
  192. slapi_log_error( SLAPI_LOG_FATAL, plugin_name,
  193. "Unable to get Read/Write lock for CONNECTION extension\n");
  194. slapi_ch_free ( (void **) &ext );
  195. return NULL;
  196. }
  197. ext->aclcb_sdn = slapi_sdn_new ();
  198. /* store the signatures */
  199. ext->aclcb_aclsignature = acl_get_aclsignature();
  200. /* eval_context */
  201. ext->aclcb_eval_context.acle_handles_matched_target = (int *)
  202. slapi_ch_calloc (aclpb_max_selected_acls, sizeof (int));
  203. ext->aclcb_state = -1;
  204. return ext;
  205. }
  206. void
  207. acl_conn_ext_destructor ( void *ext, void *object, void *parent )
  208. {
  209. struct acl_cblock *aclcb = ext;
  210. PRLock *shared_lock;
  211. if ( NULL == aclcb ) return;
  212. PR_Lock ( aclcb->aclcb_lock );
  213. shared_lock = aclcb->aclcb_lock;
  214. acl_clean_aclEval_context ( &aclcb->aclcb_eval_context, 0 /* clean*/ );
  215. slapi_sdn_free ( &aclcb->aclcb_sdn );
  216. slapi_ch_free ( (void **)&(aclcb->aclcb_eval_context.acle_handles_matched_target));
  217. aclcb->aclcb_lock = NULL;
  218. slapi_ch_free ( (void **) &aclcb );
  219. PR_Unlock ( shared_lock );
  220. }
  221. /****************************************************************************/
  222. /* OPERATION EXTENSION SPECIFIC */
  223. /****************************************************************************/
  224. void *
  225. acl_operation_ext_constructor ( void *object, void *parent )
  226. {
  227. Acl_PBlock *aclpb = NULL;
  228. TNF_PROBE_0_DEBUG(acl_operation_ext_constructor_start ,"ACL","");
  229. /* This means internal operations */
  230. if ( NULL == parent) {
  231. TNF_PROBE_1_DEBUG(acl_operation_ext_constructor_end ,"ACL","",
  232. tnf_string,internal_op,"");
  233. return NULL;
  234. }
  235. aclpb = acl__get_aclpb_from_pool();
  236. if ( NULL == aclpb ) {
  237. slapi_log_error ( SLAPI_LOG_FATAL, plugin_name,
  238. "Operation extension allocation Failed\n");
  239. }
  240. TNF_PROBE_0_DEBUG(acl_operation_ext_constructor_end ,"ACL","");
  241. return aclpb;
  242. }
  243. void
  244. acl_operation_ext_destructor ( void *ext, void *object, void *parent )
  245. {
  246. struct acl_cblock *aclcb = NULL;
  247. struct acl_pblock *aclpb = NULL;
  248. TNF_PROBE_0_DEBUG(acl_operation_ext_destructor_start ,"ACL","");
  249. if ( (NULL == parent ) || (NULL == ext)) {
  250. TNF_PROBE_1_DEBUG(acl_operation_ext_destructor_end ,"ACL","",
  251. tnf_string,internal_op,"");
  252. return;
  253. }
  254. aclpb = (Acl_PBlock *) ext;
  255. if ( (NULL == aclpb) ||
  256. (NULL == aclpb->aclpb_pblock) ||
  257. (!(aclpb->aclpb_state & ACLPB_INITIALIZED)))
  258. goto clean_aclpb;
  259. if ( NULL == aclpb->aclpb_authorization_sdn ) {
  260. slapi_log_error (SLAPI_LOG_FATAL, plugin_name, "NULL aclcb_autorization_sdn\n");
  261. goto clean_aclpb;
  262. }
  263. /* get the connection extension */
  264. aclcb = (struct acl_cblock *) acl_get_ext ( ACL_EXT_CONNECTION, parent );
  265. /* We are about to get out of this connection. Move all the
  266. ** cached information to the acl private block which hangs
  267. ** from the connection struct.
  268. */
  269. if ( aclcb && aclcb->aclcb_lock &&
  270. ( (aclpb->aclpb_state & ACLPB_UPD_ACLCB_CACHE ) ||
  271. (aclpb->aclpb_state & ACLPB_INCR_ACLCB_CACHE ) ) ) {
  272. aclEvalContext *c_evalContext;
  273. int attr_only = 0;
  274. PRLock *shared_lock = aclcb->aclcb_lock;
  275. if (aclcb->aclcb_lock )
  276. PR_Lock ( shared_lock );
  277. else {
  278. goto clean_aclpb;
  279. }
  280. if ( !aclcb->aclcb_lock ) {
  281. slapi_log_error (SLAPI_LOG_FATAL, plugin_name,
  282. "aclcb lock released! aclcb cache can't be refreshed\n");
  283. PR_Unlock ( shared_lock );
  284. goto clean_aclpb;
  285. }
  286. /* We need to refresh the aclcb cache */
  287. if ( aclpb->aclpb_state & ACLPB_UPD_ACLCB_CACHE )
  288. acl_clean_aclEval_context ( &aclcb->aclcb_eval_context, 0 /* clean*/ );
  289. if ( aclpb->aclpb_prev_entryEval_context.acle_numof_attrs ) {
  290. c_evalContext = &aclpb->aclpb_prev_entryEval_context;
  291. } else {
  292. c_evalContext = &aclpb->aclpb_curr_entryEval_context;
  293. }
  294. if (( aclpb->aclpb_state & ACLPB_INCR_ACLCB_CACHE ) &&
  295. ! ( aclpb->aclpb_state & ACLPB_UPD_ACLCB_CACHE ))
  296. attr_only = 1;
  297. acl_copyEval_context ( NULL, c_evalContext, &aclcb->aclcb_eval_context, attr_only );
  298. aclcb->aclcb_aclsignature = aclpb->aclpb_signature;
  299. if ( aclcb->aclcb_sdn &&
  300. (0 != slapi_sdn_compare( aclcb->aclcb_sdn, aclpb->aclpb_authorization_sdn )))
  301. {
  302. slapi_sdn_set_ndn_byval( aclcb->aclcb_sdn,
  303. slapi_sdn_get_ndn ( aclpb->aclpb_authorization_sdn ) );
  304. }
  305. aclcb->aclcb_state = 0;
  306. aclcb->aclcb_state |= ACLCB_HAS_CACHED_EVALCONTEXT;
  307. PR_Unlock ( shared_lock );
  308. }
  309. clean_aclpb:
  310. if ( aclpb ) {
  311. if ( aclpb->aclpb_proxy ) {
  312. TNF_PROBE_0_DEBUG(acl_proxy_aclpbdoneback_start ,"ACL","");
  313. acl__done_aclpb( aclpb->aclpb_proxy );
  314. /* Put back to the Pool */
  315. acl__put_aclpb_back_to_pool ( aclpb->aclpb_proxy );
  316. aclpb->aclpb_proxy = NULL;
  317. TNF_PROBE_0_DEBUG(acl_proxy_aclpbdoneback_end ,"ACL","");
  318. }
  319. TNF_PROBE_0_DEBUG(acl_aclpbdoneback_start ,"ACL","");
  320. acl__done_aclpb( aclpb);
  321. acl__put_aclpb_back_to_pool ( aclpb );
  322. TNF_PROBE_0_DEBUG(acl_aclpbdoneback_end ,"ACL","");
  323. }
  324. TNF_PROBE_0_DEBUG(acl_operation_ext_destructor_end ,"ACL","");
  325. }
  326. /****************************************************************************/
  327. /* FUNCTIONS TO MANAGE THE ACLPB POOL */
  328. /****************************************************************************/
  329. /*
  330. * Get the right acl pblock
  331. */
  332. struct acl_pblock *
  333. acl_get_aclpb ( Slapi_PBlock *pb, int type )
  334. {
  335. Acl_PBlock *aclpb = NULL;
  336. void *op = NULL;
  337. slapi_pblock_get ( pb, SLAPI_OPERATION, &op );
  338. aclpb = (Acl_PBlock *) acl_get_ext ( ACL_EXT_OPERATION, op );
  339. if (NULL == aclpb ) return NULL;
  340. if ( type == ACLPB_BINDDN_PBLOCK )
  341. return aclpb;
  342. else if ( type == ACLPB_PROXYDN_PBLOCK )
  343. return aclpb->aclpb_proxy;
  344. else
  345. slapi_log_error ( SLAPI_LOG_FATAL, plugin_name,
  346. "acl_get_aclpb: Invalid aclpb type %d\n", type );
  347. return NULL;
  348. }
  349. /*
  350. * Create a new proxy acl pblock
  351. *
  352. */
  353. struct acl_pblock *
  354. acl_new_proxy_aclpb( Slapi_PBlock *pb )
  355. {
  356. void *op;
  357. Acl_PBlock *aclpb = NULL;
  358. Acl_PBlock *proxy_aclpb = NULL;
  359. slapi_pblock_get ( pb, SLAPI_OPERATION, &op );
  360. aclpb = (Acl_PBlock *) acl_get_ext ( ACL_EXT_OPERATION, op );
  361. if (NULL == aclpb ) return NULL;
  362. proxy_aclpb = acl__get_aclpb_from_pool();
  363. if (NULL == proxy_aclpb) return NULL;
  364. proxy_aclpb->aclpb_type = ACLPB_TYPE_PROXY;
  365. aclpb->aclpb_proxy = proxy_aclpb;
  366. return proxy_aclpb;
  367. }
  368. static int
  369. acl__handle_config_entry (Slapi_Entry *e, void *callback_data )
  370. {
  371. *(int * )callback_data = slapi_entry_attr_get_int( e, "nsslapd-threadnumber");
  372. return 0;
  373. }
  374. static int
  375. acl__handle_plugin_config_entry (Slapi_Entry *e, void *callback_data )
  376. {
  377. int value = slapi_entry_attr_get_int(e, ATTR_ACLPB_MAX_SELECTED_ACLS);
  378. if (value) {
  379. aclpb_max_selected_acls = value;
  380. aclpb_max_cache_results = value;
  381. } else {
  382. aclpb_max_selected_acls = DEFAULT_ACLPB_MAX_SELECTED_ACLS;
  383. aclpb_max_cache_results = DEFAULT_ACLPB_MAX_SELECTED_ACLS;
  384. }
  385. return 0;
  386. }
  387. /*
  388. * Create a pool of acl pblock. Created during the ACL plugin
  389. * initialization.
  390. */
  391. int
  392. acl_create_aclpb_pool ()
  393. {
  394. Acl_PBlock *aclpb;
  395. Acl_PBlock *prev_aclpb;
  396. Acl_PBlock *first_aclpb;
  397. int i;
  398. int maxThreads= 0;
  399. int callbackData= 0;
  400. slapi_search_internal_callback( "cn=config", LDAP_SCOPE_BASE, "(objectclass=*)",
  401. NULL, 0 /* attrsonly */,
  402. &maxThreads/* callback_data */,
  403. NULL /* controls */,
  404. NULL /* result_callback */,
  405. acl__handle_config_entry,
  406. NULL /* referral_callback */);
  407. slapi_search_internal_callback( ACL_PLUGIN_CONFIG_ENTRY_DN, LDAP_SCOPE_BASE, "(objectclass=*)",
  408. NULL, 0 /* attrsonly */,
  409. &callbackData /* callback_data, not used in this case */,
  410. NULL /* controls */,
  411. NULL /* result_callback */,
  412. acl__handle_plugin_config_entry,
  413. NULL /* referral_callback */);
  414. /* Create a pool pf aclpb */
  415. maxThreads = 2 * maxThreads;
  416. aclQueue = ( Acl_PBqueue *) slapi_ch_calloc ( 1, sizeof (Acl_PBqueue) );
  417. aclQueue->aclq_lock = PR_NewLock();
  418. if ( NULL == aclQueue->aclq_lock ) {
  419. /* ERROR */
  420. return 1;
  421. }
  422. prev_aclpb = NULL;
  423. first_aclpb = NULL;
  424. for ( i = 0; i < maxThreads; i++ ) {
  425. aclpb = acl__malloc_aclpb ();
  426. if ( 0 == i) first_aclpb = aclpb;
  427. aclpb->aclpb_prev = prev_aclpb;
  428. if ( prev_aclpb ) prev_aclpb->aclpb_next = aclpb;
  429. prev_aclpb = aclpb;
  430. }
  431. /* Since this is the begining, everybody is in free list */
  432. aclQueue->aclq_free = first_aclpb;
  433. aclQueue->aclq_nfree = maxThreads;
  434. return 0;
  435. }
  436. /*
  437. * Destroys the Acl_PBlock pool. To be called at shutdown,
  438. * from function registered as SLAPI_PLUGIN_CLOSE_FN
  439. */
  440. void
  441. acl_destroy_aclpb_pool ()
  442. {
  443. Acl_PBlock *currentPbBlock;
  444. Acl_PBlock *nextPbBlock;
  445. if (!aclQueue) {
  446. /* Nothing to do */
  447. return;
  448. }
  449. /* Free all busy pbBlocks in queue */
  450. currentPbBlock = aclQueue->aclq_busy;
  451. while (currentPbBlock) {
  452. nextPbBlock = currentPbBlock->aclpb_next;
  453. acl__free_aclpb(&currentPbBlock);
  454. currentPbBlock = nextPbBlock;
  455. }
  456. /* Free all free pbBlocks in queue */
  457. currentPbBlock = aclQueue->aclq_free;
  458. while (currentPbBlock) {
  459. nextPbBlock = currentPbBlock->aclpb_next;
  460. acl__free_aclpb(&currentPbBlock);
  461. currentPbBlock = nextPbBlock;
  462. }
  463. PR_DestroyLock(aclQueue->aclq_lock);
  464. slapi_ch_free((void**)&aclQueue);
  465. }
  466. /*
  467. * Get a FREE acl pblock from the pool.
  468. *
  469. */
  470. static Acl_PBlock *
  471. acl__get_aclpb_from_pool ( )
  472. {
  473. Acl_PBlock *aclpb = NULL;
  474. Acl_PBlock *t_aclpb = NULL;
  475. PR_Lock (aclQueue->aclq_lock );
  476. /* Get the first aclpb from the FREE List */
  477. aclpb = aclQueue->aclq_free;
  478. if ( aclpb ) {
  479. t_aclpb = aclpb->aclpb_next;
  480. if ( t_aclpb ) t_aclpb->aclpb_prev = NULL;
  481. aclQueue->aclq_free = t_aclpb;
  482. /* make the this an orphon */
  483. aclpb->aclpb_prev = aclpb->aclpb_next = NULL;
  484. aclQueue->aclq_nfree--;
  485. } else {
  486. slapi_log_error ( SLAPI_LOG_ACL, plugin_name,
  487. "Unable to find a free aclpb\n");
  488. aclpb = acl__malloc_aclpb ();
  489. }
  490. /* Now move it to the FRONT of busy list */
  491. t_aclpb = aclQueue->aclq_busy;
  492. aclpb->aclpb_next = t_aclpb;
  493. if ( t_aclpb ) t_aclpb->aclpb_prev = aclpb;
  494. aclQueue->aclq_busy = aclpb;
  495. aclQueue->aclq_nbusy++;
  496. PR_Unlock (aclQueue->aclq_lock );
  497. return aclpb;
  498. }
  499. /*
  500. * Put the acl pblock into the FREE pool.
  501. *
  502. */
  503. static int
  504. acl__put_aclpb_back_to_pool ( Acl_PBlock *aclpb )
  505. {
  506. Acl_PBlock *p_aclpb, *n_aclpb;
  507. PR_Lock (aclQueue->aclq_lock );
  508. /* Remove it from the busy list */
  509. n_aclpb = aclpb->aclpb_next;
  510. p_aclpb = aclpb->aclpb_prev;
  511. if ( p_aclpb ) {
  512. p_aclpb->aclpb_next = n_aclpb;
  513. if ( n_aclpb ) n_aclpb->aclpb_prev = p_aclpb;
  514. } else {
  515. aclQueue->aclq_busy = n_aclpb;
  516. if ( n_aclpb ) n_aclpb->aclpb_prev = NULL;
  517. }
  518. aclQueue->aclq_nbusy--;
  519. /* Put back to the FREE list */
  520. aclpb->aclpb_prev = NULL;
  521. n_aclpb = aclQueue->aclq_free;
  522. aclpb->aclpb_next = n_aclpb;
  523. if ( n_aclpb ) n_aclpb->aclpb_prev = aclpb;
  524. aclQueue->aclq_free = aclpb;
  525. aclQueue->aclq_nfree++;
  526. PR_Unlock (aclQueue->aclq_lock );
  527. return 0;
  528. }
  529. /*
  530. * Allocate the basic acl pb
  531. *
  532. */
  533. static Acl_PBlock *
  534. acl__malloc_aclpb ( )
  535. {
  536. Acl_PBlock *aclpb = NULL;
  537. aclpb = ( Acl_PBlock *) slapi_ch_calloc ( 1, sizeof ( Acl_PBlock) );
  538. /* Now set the propert we need for ACL evaluations */
  539. if ((aclpb->aclpb_proplist = PListNew(NULL)) == NULL) {
  540. slapi_log_error (SLAPI_LOG_FATAL, plugin_name,
  541. "Unable to allocate the aclprop PList\n");
  542. goto error;
  543. }
  544. if (PListInitProp(aclpb->aclpb_proplist, 0, DS_PROP_ACLPB, aclpb, 0) < 0) {
  545. slapi_log_error(SLAPI_LOG_FATAL, plugin_name,
  546. "Unable to set the ACL PBLOCK in the Plist\n");
  547. goto error;
  548. }
  549. if (PListInitProp(aclpb->aclpb_proplist, 0, DS_ATTR_USERDN, aclpb, 0) < 0) {
  550. slapi_log_error(SLAPI_LOG_FATAL, plugin_name,
  551. "Unable to set the USER DN in the Plist\n");
  552. goto error;
  553. }
  554. if (PListInitProp(aclpb->aclpb_proplist, 0, DS_ATTR_AUTHTYPE, aclpb, 0) < 0) {
  555. slapi_log_error(SLAPI_LOG_FATAL, plugin_name,
  556. "Unable to set the AUTH TYPE in the Plist\n");
  557. goto error;
  558. }
  559. if (PListInitProp(aclpb->aclpb_proplist, 0, DS_ATTR_LDAPI, aclpb, 0) < 0) {
  560. slapi_log_error(SLAPI_LOG_FATAL, plugin_name,
  561. "Unable to set the AUTH TYPE in the Plist\n");
  562. goto error;
  563. }
  564. if (PListInitProp(aclpb->aclpb_proplist, 0, DS_ATTR_ENTRY, aclpb, 0) < 0) {
  565. slapi_log_error(SLAPI_LOG_FATAL, plugin_name,
  566. "Unable to set the ENTRY TYPE in the Plist\n");
  567. goto error;
  568. }
  569. if (PListInitProp(aclpb->aclpb_proplist, 0, DS_ATTR_SSF, aclpb, 0) < 0) {
  570. slapi_log_error(SLAPI_LOG_FATAL, plugin_name,
  571. "Unable to set the SSF in the Plist\n");
  572. goto error;
  573. }
  574. /*
  575. * ACL_ATTR_IP and ACL_ATTR_DNS are initialized lazily in the
  576. * IpGetter and DnsGetter functions.
  577. * They are removed from the aclpb property list at acl__aclpb_done()
  578. * time.
  579. */
  580. /* allocate the acleval struct */
  581. aclpb->aclpb_acleval = (ACLEvalHandle_t *) ACL_EvalNew(NULL, NULL);
  582. if (aclpb->aclpb_acleval == NULL) {
  583. slapi_log_error(SLAPI_LOG_FATAL, plugin_name,
  584. "Unable to allocate the acleval block\n");
  585. goto error;
  586. }
  587. /*
  588. * This is a libaccess routine.
  589. * Need to setup subject and resource property information
  590. */
  591. ACL_EvalSetSubject(NULL, aclpb->aclpb_acleval, aclpb->aclpb_proplist);
  592. /* allocate some space for attr name */
  593. aclpb->aclpb_Evalattr = (char *) slapi_ch_malloc (ACLPB_MAX_ATTR_LEN);
  594. aclpb->aclpb_deny_handles = (aci_t **) slapi_ch_calloc (1,
  595. ACLPB_INCR_LIST_HANDLES * sizeof (aci_t *));
  596. aclpb->aclpb_allow_handles = (aci_t **) slapi_ch_calloc (1,
  597. ACLPB_INCR_LIST_HANDLES * sizeof (aci_t *));
  598. aclpb->aclpb_deny_handles_size = ACLPB_INCR_LIST_HANDLES;
  599. aclpb->aclpb_allow_handles_size = ACLPB_INCR_LIST_HANDLES;
  600. /* allocate the array for bases */
  601. aclpb->aclpb_grpsearchbase = (char **)
  602. slapi_ch_calloc (ACLPB_INCR_BASES, sizeof(char *));
  603. aclpb->aclpb_grpsearchbase_size = ACLPB_INCR_BASES;
  604. aclpb->aclpb_numof_bases = 0;
  605. /* Make sure aclpb_search_base is initialized to NULL..tested elsewhere! */
  606. aclpb->aclpb_search_base = NULL;
  607. aclpb->aclpb_authorization_sdn = slapi_sdn_new ();
  608. aclpb->aclpb_curr_entry_sdn = slapi_sdn_new();
  609. aclpb->aclpb_aclContainer = acllist_get_aciContainer_new ();
  610. /* hash table to store macro matched values from targets */
  611. aclpb->aclpb_macro_ht = acl_ht_new();
  612. /* allocate arrays for handles */
  613. aclpb->aclpb_handles_index = (int *)
  614. slapi_ch_calloc (aclpb_max_selected_acls, sizeof (int));
  615. aclpb->aclpb_base_handles_index = (int *)
  616. slapi_ch_calloc (aclpb_max_selected_acls, sizeof (int));
  617. /* allocate arrays for result cache */
  618. aclpb->aclpb_cache_result = (r_cache_t *)
  619. slapi_ch_calloc (aclpb_max_cache_results + 1 /* 1 for cache overflow warning */,
  620. sizeof (r_cache_t));
  621. /* allocate arrays for target handles in eval_context */
  622. aclpb->aclpb_curr_entryEval_context.acle_handles_matched_target = (int *)
  623. slapi_ch_calloc (aclpb_max_selected_acls, sizeof (int));
  624. aclpb->aclpb_prev_entryEval_context.acle_handles_matched_target = (int *)
  625. slapi_ch_calloc (aclpb_max_selected_acls, sizeof (int));
  626. aclpb->aclpb_prev_opEval_context.acle_handles_matched_target = (int *)
  627. slapi_ch_calloc (aclpb_max_selected_acls, sizeof (int));
  628. return aclpb;
  629. error:
  630. acl__free_aclpb(&aclpb);
  631. return NULL;
  632. }
  633. /*
  634. * Free the acl pb. To be used at shutdown (SLAPI_PLUGIN_CLOSE_FN)
  635. * when we free the aclQueue
  636. */
  637. static void
  638. acl__free_aclpb ( Acl_PBlock **aclpb_ptr)
  639. {
  640. Acl_PBlock *aclpb = NULL;
  641. if (aclpb_ptr == NULL || *aclpb_ptr == NULL)
  642. return; // Nothing to do
  643. aclpb = *aclpb_ptr;
  644. if (aclpb->aclpb_acleval) {
  645. ACL_EvalDestroyNoDecrement(NULL, NULL, aclpb->aclpb_acleval);
  646. }
  647. if (aclpb->aclpb_proplist)
  648. PListDestroy(aclpb->aclpb_proplist);
  649. slapi_ch_free((void**)&(aclpb->aclpb_handles_index));
  650. slapi_ch_free((void**)&(aclpb->aclpb_base_handles_index));
  651. slapi_ch_free((void**)&(aclpb->aclpb_cache_result));
  652. slapi_ch_free((void**)
  653. &(aclpb->aclpb_curr_entryEval_context.acle_handles_matched_target));
  654. slapi_ch_free((void**)
  655. &(aclpb->aclpb_prev_entryEval_context.acle_handles_matched_target));
  656. slapi_ch_free((void**)
  657. &(aclpb->aclpb_prev_opEval_context.acle_handles_matched_target));
  658. slapi_sdn_free(&aclpb->aclpb_authorization_sdn);
  659. slapi_sdn_free(&aclpb->aclpb_curr_entry_sdn);
  660. if(aclpb->aclpb_macro_ht){
  661. acl_ht_free_all_entries_and_values(aclpb->aclpb_macro_ht);
  662. PR_HashTableDestroy(aclpb->aclpb_macro_ht);
  663. aclpb->aclpb_macro_ht = NULL;
  664. }
  665. slapi_ch_free((void**)&(aclpb->aclpb_allow_handles));
  666. slapi_ch_free((void**)&(aclpb->aclpb_deny_handles));
  667. acllist_free_aciContainer(&aclpb->aclpb_aclContainer);
  668. slapi_ch_free((void**)&(aclpb->aclpb_aclContainer));
  669. slapi_ch_free_string(&aclpb->aclpb_Evalattr);
  670. slapi_ch_array_free(aclpb->aclpb_grpsearchbase);
  671. slapi_ch_free((void**)aclpb_ptr);
  672. }
  673. /* Initializes the aclpb */
  674. void
  675. acl_init_aclpb ( Slapi_PBlock *pb, Acl_PBlock *aclpb, const char *ndn, int copy_from_aclcb)
  676. {
  677. struct acl_cblock *aclcb = NULL;
  678. char *authType;
  679. void *conn;
  680. int op_type;
  681. intptr_t ssf = 0;
  682. if ( NULL == aclpb ) {
  683. slapi_log_error ( SLAPI_LOG_FATAL, plugin_name, "acl_init_aclpb:No ACLPB\n");
  684. return;
  685. }
  686. /* See if we have initialized already */
  687. if (aclpb->aclpb_state & ACLPB_INITIALIZED) return;
  688. slapi_pblock_get ( pb, SLAPI_OPERATION_TYPE, &op_type );
  689. if ( op_type == SLAPI_OPERATION_BIND || op_type == SLAPI_OPERATION_UNBIND )
  690. return;
  691. /* We indicate the initialize here becuase, if something goes wrong, it's cleaned up
  692. ** properly.
  693. */
  694. aclpb->aclpb_state = ACLPB_INITIALIZED;
  695. /* We make an anonymous user a non null dn which is empty */
  696. if (ndn && *ndn != '\0' )
  697. slapi_sdn_set_ndn_byval ( aclpb->aclpb_authorization_sdn, ndn );
  698. else
  699. slapi_sdn_set_ndn_byval ( aclpb->aclpb_authorization_sdn, "" );
  700. /* reset scoped entry cache to be empty */
  701. aclpb->aclpb_scoped_entry_anominfo.anom_e_nummatched = 0;
  702. if (PListAssignValue(aclpb->aclpb_proplist, DS_ATTR_USERDN,
  703. slapi_sdn_get_ndn(aclpb->aclpb_authorization_sdn), 0) < 0) {
  704. slapi_log_error(SLAPI_LOG_FATAL, plugin_name,
  705. "Unable to set the USER DN in the Plist\n");
  706. return;
  707. }
  708. slapi_pblock_get ( pb, SLAPI_OPERATION_AUTHTYPE, &authType );
  709. if (PListAssignValue(aclpb->aclpb_proplist, DS_ATTR_AUTHTYPE, authType, 0) < 0) {
  710. slapi_log_error(SLAPI_LOG_FATAL, plugin_name,
  711. "Unable to set the AUTH TYPE in the Plist\n");
  712. return;
  713. }
  714. if(slapi_is_ldapi_conn(pb)){
  715. if(PListAssignValue(aclpb->aclpb_proplist, DS_ATTR_LDAPI, "yes", 0) < 0){
  716. slapi_log_error(SLAPI_LOG_FATAL, plugin_name,
  717. "Unable to set the AUTH TYPE in the Plist\n");
  718. return;
  719. }
  720. }
  721. slapi_pblock_get ( pb, SLAPI_OPERATION_SSF, &ssf);
  722. if (PListAssignValue(aclpb->aclpb_proplist, DS_ATTR_SSF, (const void *)ssf, 0) < 0) {
  723. slapi_log_error(SLAPI_LOG_FATAL, plugin_name,
  724. "Unable to set the SSF in the Plist\n");
  725. return;
  726. }
  727. /* PKBxxx: We should be getting it from the OP struct */
  728. slapi_pblock_get ( pb, SLAPI_CONN_CERT, &aclpb->aclpb_clientcert );
  729. /* See if the we have already a cached info about user's group */
  730. aclg_init_userGroup ( aclpb, ndn, 0 /* get lock */ );
  731. slapi_pblock_get( pb, SLAPI_BE_MAXNESTLEVEL, &aclpb->aclpb_max_nesting_level );
  732. slapi_pblock_get( pb, SLAPI_SEARCH_SIZELIMIT, &aclpb->aclpb_max_member_sizelimit );
  733. if ( aclpb->aclpb_max_member_sizelimit == 0 ) {
  734. aclpb->aclpb_max_member_sizelimit = SLAPD_DEFAULT_LOOKTHROUGHLIMIT;
  735. } else if ( aclpb->aclpb_max_member_sizelimit < -1 ) {
  736. /* handle the case of a negtive size limit either set or due
  737. * to bug bz1065971. The member size limit should be dropped,
  738. * but for backward compatibility to the best we can
  739. */
  740. aclpb->aclpb_max_member_sizelimit = -1;
  741. }
  742. slapi_pblock_get( pb, SLAPI_OPERATION_TYPE, &aclpb->aclpb_optype );
  743. aclpb->aclpb_signature = acl_get_aclsignature();
  744. aclpb->aclpb_last_cache_result = 0;
  745. aclpb->aclpb_pblock = pb;
  746. PR_ASSERT ( aclpb->aclpb_pblock != NULL );
  747. /* get the connection */
  748. slapi_pblock_get ( pb, SLAPI_CONNECTION, &conn);
  749. aclcb = (struct acl_cblock *) acl_get_ext ( ACL_EXT_CONNECTION, conn );
  750. if (NULL == aclcb || NULL == aclcb->aclcb_lock) {
  751. /* This could happen if the client is dead and we are in
  752. ** process of abondoning this operation
  753. */
  754. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  755. "No CONNECTION extension\n");
  756. } else if ( aclcb->aclcb_state == -1 ) {
  757. /* indicate that we need to update the cache */
  758. aclpb->aclpb_state |= ACLPB_UPD_ACLCB_CACHE;
  759. aclcb->aclcb_state = 0; /* Nore this is ACLCB and not ACLPB */
  760. } else if ( copy_from_aclcb ){
  761. char *cdn;
  762. Slapi_DN *c_sdn; /* client SDN */
  763. /* check if the operation is abandoned or not.*/
  764. if ( slapi_op_abandoned ( pb ) ) {
  765. return;
  766. }
  767. slapi_pblock_get ( pb, SLAPI_CONN_DN, &cdn ); /* We *must* free cdn! */
  768. c_sdn = slapi_sdn_new_dn_passin( cdn );
  769. PR_Lock ( aclcb->aclcb_lock );
  770. /*
  771. * since PR_Lock is taken,
  772. * we can mark the connection extension ok to be destroyed.
  773. */
  774. if ( (aclcb->aclcb_aclsignature != acl_get_aclsignature()) ||
  775. ( (NULL == cdn) && aclcb->aclcb_sdn ) ||
  776. (cdn && (NULL == aclcb->aclcb_sdn )) ||
  777. (cdn && aclcb->aclcb_sdn && ( 0 != slapi_sdn_compare ( c_sdn, aclcb->aclcb_sdn ) ))) {
  778. /* cleanup the aclcb cache */
  779. acl_clean_aclEval_context ( &aclcb->aclcb_eval_context, 0 /*clean*/ );
  780. aclcb->aclcb_state = 0;
  781. aclcb->aclcb_aclsignature = 0;
  782. slapi_sdn_done ( aclcb->aclcb_sdn );
  783. }
  784. slapi_sdn_free ( &c_sdn );
  785. /* COPY the cached information from ACLCB --> ACLPB */
  786. if ( aclcb->aclcb_state & ACLCB_HAS_CACHED_EVALCONTEXT) {
  787. acl_copyEval_context ( aclpb, &aclcb->aclcb_eval_context ,
  788. &aclpb->aclpb_prev_opEval_context, 0 );
  789. aclpb->aclpb_state |= ACLPB_HAS_ACLCB_EVALCONTEXT;
  790. }
  791. PR_Unlock ( aclcb->aclcb_lock );
  792. }
  793. }
  794. /* Cleans up the aclpb */
  795. static void
  796. acl__done_aclpb ( struct acl_pblock *aclpb )
  797. {
  798. int i;
  799. int dump_aclpb_info = 0;
  800. int rc=-1;
  801. char *tmp_ptr=NULL;
  802. /*
  803. ** First, let's do some sanity checks to see if we have everything what
  804. ** it should be.
  805. */
  806. /* Nothing needs to be cleaned up in this case */
  807. if (!(aclpb->aclpb_state & ACLPB_INITIALIZED))
  808. return;
  809. /* Check the state */
  810. if (aclpb->aclpb_state & ~ACLPB_STATE_ALL) {
  811. slapi_log_error( SLAPI_LOG_FATAL, plugin_name,
  812. "The aclpb.state value (%d) is incorrect. Exceeded the limit (%d)\n",
  813. aclpb->aclpb_state, ACLPB_STATE_ALL);
  814. dump_aclpb_info = 1;
  815. }
  816. #ifdef FOR_DEBUGGING
  817. acl__dump_stats ( aclpb, acl__get_aclpb_type(aclpb));
  818. #endif
  819. /* reset the usergroup cache */
  820. aclg_reset_userGroup ( aclpb );
  821. if ( aclpb->aclpb_res_type & ~ACLPB_RESTYPE_ALL ) {
  822. slapi_log_error( SLAPI_LOG_FATAL, plugin_name,
  823. "The aclpb res_type value (%d) has exceeded. Limit is (%d)\n",
  824. aclpb->aclpb_res_type, ACLPB_RESTYPE_ALL );
  825. dump_aclpb_info = 1;
  826. }
  827. if ( dump_aclpb_info ) {
  828. const char *ndn;
  829. slapi_log_error ( SLAPI_LOG_FATAL, plugin_name,
  830. "ACLPB value is:%p\n", aclpb );
  831. ndn = slapi_sdn_get_ndn ( aclpb->aclpb_curr_entry_sdn );
  832. slapi_log_error ( SLAPI_LOG_FATAL, plugin_name, "curr_entry:%p num_entries:%d curr_dn:%p\n",
  833. aclpb->aclpb_curr_entry ? (char *) aclpb->aclpb_curr_entry : "NULL",
  834. aclpb->aclpb_num_entries,
  835. ndn ? ndn : "NULL");
  836. slapi_log_error ( SLAPI_LOG_FATAL, plugin_name, "Last attr:%p, Plist:%p acleval: %p\n",
  837. aclpb->aclpb_Evalattr ? aclpb->aclpb_Evalattr : "NULL",
  838. aclpb->aclpb_proplist ? (char *) aclpb->aclpb_proplist : "NULL",
  839. aclpb->aclpb_acleval ? (char *) aclpb->aclpb_acleval : "NULL" );
  840. }
  841. /* Now Free the contents or clean it */
  842. slapi_sdn_done ( aclpb->aclpb_curr_entry_sdn );
  843. if (aclpb->aclpb_Evalattr)
  844. aclpb->aclpb_Evalattr[0] = '\0';
  845. /* deallocate the contents of the base array */
  846. for (i=0; i < aclpb->aclpb_numof_bases; i++) {
  847. if (aclpb->aclpb_grpsearchbase[i])
  848. slapi_ch_free ( (void **)&aclpb->aclpb_grpsearchbase[i] );
  849. }
  850. aclpb->aclpb_numof_bases = 0;
  851. acl_clean_aclEval_context ( &aclpb->aclpb_prev_opEval_context, 0 /*claen*/ );
  852. acl_clean_aclEval_context ( &aclpb->aclpb_prev_entryEval_context, 0 /*clean*/ );
  853. acl_clean_aclEval_context ( &aclpb->aclpb_curr_entryEval_context, 0/*clean*/ );
  854. if ( aclpb->aclpb_client_entry ) slapi_entry_free ( aclpb->aclpb_client_entry );
  855. aclpb->aclpb_client_entry = NULL;
  856. slapi_sdn_done ( aclpb->aclpb_authorization_sdn );
  857. aclpb->aclpb_pblock = NULL;
  858. slapi_ch_free_string(&aclpb->aclpb_search_base );
  859. for ( i=0; i < aclpb->aclpb_num_deny_handles; i++ )
  860. aclpb->aclpb_deny_handles[i] = NULL;
  861. aclpb->aclpb_num_deny_handles = 0;
  862. for ( i=0; i < aclpb->aclpb_num_allow_handles; i++ )
  863. aclpb->aclpb_allow_handles[i] = NULL;
  864. aclpb->aclpb_num_allow_handles = 0;
  865. /* clear results cache */
  866. memset((char*)aclpb->aclpb_cache_result, 0,
  867. sizeof(struct result_cache)*aclpb->aclpb_last_cache_result);
  868. aclpb->aclpb_last_cache_result = 0;
  869. aclpb->aclpb_handles_index[0] = -1;
  870. aclpb->aclpb_base_handles_index[0] = -1;
  871. aclpb->aclpb_stat_acllist_scanned = 0;
  872. aclpb->aclpb_stat_aclres_matched = 0;
  873. aclpb->aclpb_stat_total_entries = 0;
  874. aclpb->aclpb_stat_anom_list_scanned = 0;
  875. aclpb->aclpb_stat_num_copycontext = 0;
  876. aclpb->aclpb_stat_num_copy_attrs = 0;
  877. aclpb->aclpb_stat_num_tmatched_acls = 0;
  878. aclpb->aclpb_clientcert = NULL;
  879. aclpb->aclpb_proxy = NULL;
  880. acllist_done_aciContainer ( aclpb->aclpb_aclContainer );
  881. /*
  882. * Here, decide which things need to be freed/removed/whatever from the
  883. * aclpb_proplist.
  884. */
  885. /*
  886. * The DS_ATTR_DNS property contains the name of the client machine.
  887. *
  888. * The value pointed to by this property is stored in the pblock--it
  889. * points to the SLAPI_CLIENT_DNS object. So, that memory will
  890. * be freed elsewhere.
  891. *
  892. * It's removed here from the aclpb_proplist as it would be an error to
  893. * allow it to persist in the aclpb which is an operation time thing.
  894. * If we leave it here the next time this aclpb gets used, the DnsGetter
  895. * is not called by LASDnsEval/ACL_GetAttribute() as it thinks the
  896. * ACL_ATTR_DNS has already been initialized.
  897. *
  898. */
  899. if ((rc = PListFindValue(aclpb->aclpb_proplist, ACL_ATTR_DNS,
  900. (void **)&tmp_ptr, NULL)) > 0) {
  901. PListDeleteProp(aclpb->aclpb_proplist, rc, NULL);
  902. }
  903. /* reset the LDAPI property */
  904. PListAssignValue(aclpb->aclpb_proplist, DS_ATTR_LDAPI, NULL, 0);
  905. /*
  906. * Remove the DS_ATTR_IP property from the property list.
  907. * The value of this property is just the property pointer
  908. * (an unsigned long) so that gets freed too when we delete the
  909. * property.
  910. * It's removed here from the aclpb_proplist as it would be an error to
  911. * allow it to persist in the aclpb which is an operation time thing.
  912. * If we leave it here the next time this aclpb gets used, the DnsGetter
  913. * is not called by LASIpEval/ACL_GetAttribute() as it thinks the
  914. * ACL_ATTR_IP has already been initialized.
  915. */
  916. if ((rc = PListFindValue(aclpb->aclpb_proplist, ACL_ATTR_IP,
  917. (void **)&tmp_ptr, NULL)) > 0) {
  918. PListDeleteProp(aclpb->aclpb_proplist, rc, NULL);
  919. }
  920. /*
  921. * The DS_ATTR_USERDN value comes from aclpb_authorization_sdn.
  922. * This memory
  923. * is freed above using aclpb_authorization_sdn so we don't need to free it here
  924. * before overwriting the old value.
  925. */
  926. PListAssignValue(aclpb->aclpb_proplist, DS_ATTR_USERDN, NULL, 0);
  927. /*
  928. * The DS_ATTR_AUTHTYPE value is a pointer into the pblock, so
  929. * we do not need to free that memory before overwriting the value.
  930. */
  931. PListAssignValue(aclpb->aclpb_proplist, DS_ATTR_AUTHTYPE, NULL, 0);
  932. /*
  933. * DO NOT overwrite the aclpb pointer--it is initialized at malloc_aclpb
  934. * time and is kept within the aclpb.
  935. *
  936. * PListAssignValue(aclpb->aclpb_proplist, DS_PROP_ACLPB, NULL, 0);
  937. */
  938. /*
  939. * The DS_ATTR_ENTRY value was a pointer to the entry being evaluated
  940. * by the ACL code. That entry comes from outside the context of
  941. * the acl code and so is dealt with out there. Ergo, here we can just
  942. * lose the pointer to that entry.
  943. */
  944. PListAssignValue(aclpb->aclpb_proplist, DS_ATTR_ENTRY, NULL, 0);
  945. aclpb->aclpb_signature = 0;
  946. /* reset scoped entry cache to be empty */
  947. aclpb->aclpb_scoped_entry_anominfo.anom_e_nummatched = 0;
  948. /* Free up any of the string values left in the macro ht and remove
  949. * the entries.*/
  950. acl_ht_free_all_entries_and_values(aclpb->aclpb_macro_ht);
  951. /* Finally, set it to the no use state */
  952. aclpb->aclpb_state = 0;
  953. }
  954. #ifdef FOR_DEBUGGING
  955. static char *
  956. acl__get_aclpb_type ( Acl_PBlock *aclpb )
  957. {
  958. if (aclpb->aclpb_state & ACLPB_TYPE_PROXY)
  959. return ACLPB_TYPE_PROXY_STR;
  960. return ACLPB_TYPE_MAIN_STR;
  961. }
  962. static void
  963. acl__dump_stats ( struct acl_pblock *aclpb , const char *block_type)
  964. {
  965. PRUint64 connid = 0;
  966. int opid = 0;
  967. Slapi_PBlock *pb = NULL;
  968. pb = aclpb->aclpb_pblock;
  969. if ( pb ) {
  970. slapi_pblock_get ( pb, SLAPI_CONN_ID, &connid );
  971. slapi_pblock_get ( pb, SLAPI_OPERATION_ID, &opid );
  972. }
  973. /* DUMP STAT INFO */
  974. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  975. "**** ACL OPERATION STAT BEGIN ( aclpb:%p Block type: %s): Conn:%" PRIu64 " Operation:%d *******\n",
  976. aclpb, block_type, connid, opid );
  977. slapi_log_error( SLAPI_LOG_ACL, plugin_name, "\tNumber of entries scanned: %d\n",
  978. aclpb->aclpb_stat_total_entries);
  979. slapi_log_error( SLAPI_LOG_ACL, plugin_name, "\tNumber of times ACL List scanned: %d\n",
  980. aclpb->aclpb_stat_acllist_scanned);
  981. slapi_log_error( SLAPI_LOG_ACL, plugin_name, "\tNumber of ACLs with target matched:%d\n",
  982. aclpb->aclpb_stat_num_tmatched_acls);
  983. slapi_log_error( SLAPI_LOG_ACL, plugin_name, "\tNumber of times acl resource matched:%d\n",
  984. aclpb->aclpb_stat_aclres_matched);
  985. slapi_log_error( SLAPI_LOG_ACL, plugin_name, "\tNumber of times ANOM list scanned:%d\n",
  986. aclpb->aclpb_stat_anom_list_scanned);
  987. slapi_log_error( SLAPI_LOG_ACL, plugin_name, "\tNumber of times Context was copied:%d\n",
  988. aclpb->aclpb_stat_num_copycontext);
  989. slapi_log_error( SLAPI_LOG_ACL, plugin_name, "\tNumber of times Attrs was copied:%d\n",
  990. aclpb->aclpb_stat_num_copy_attrs);
  991. slapi_log_error( SLAPI_LOG_ACL, plugin_name, " **** ACL OPERATION STAT END *******\n");
  992. }
  993. #endif
  994. /****************************************************************************/
  995. /* E N D */
  996. /****************************************************************************/