acl_ext.c 35 KB

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