acl_ext.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146
  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_EvalDestroy(NULL, NULL, aclpb->aclpb_acleval);
  609. if (aclpb->aclpb_proplist)
  610. PListDestroy(aclpb->aclpb_proplist);
  611. slapi_ch_free((void**)&(aclpb->aclpb_handles_index));
  612. slapi_ch_free((void**)&(aclpb->aclpb_base_handles_index));
  613. slapi_ch_free((void**)&(aclpb->aclpb_cache_result));
  614. slapi_ch_free((void**)
  615. &(aclpb->aclpb_curr_entryEval_context.acle_handles_matched_target));
  616. slapi_ch_free((void**)
  617. &(aclpb->aclpb_prev_entryEval_context.acle_handles_matched_target));
  618. slapi_ch_free((void**)
  619. &(aclpb->aclpb_prev_opEval_context.acle_handles_matched_target));
  620. slapi_ch_free((void**)aclpb_ptr);
  621. }
  622. /* Initializes the aclpb */
  623. void
  624. acl_init_aclpb ( Slapi_PBlock *pb , Acl_PBlock *aclpb, const char *ndn, int copy_from_aclcb)
  625. {
  626. struct acl_cblock *aclcb = NULL;
  627. char *authType;
  628. void *conn;
  629. int op_type;
  630. intptr_t ssf = 0;
  631. if ( NULL == aclpb ) {
  632. slapi_log_error ( SLAPI_LOG_FATAL, plugin_name, "acl_init_aclpb:No ACLPB\n");
  633. return;
  634. }
  635. /* See if we have initialized already */
  636. if (aclpb->aclpb_state & ACLPB_INITIALIZED) return;
  637. slapi_pblock_get ( pb, SLAPI_OPERATION_TYPE, &op_type );
  638. if ( op_type == SLAPI_OPERATION_BIND || op_type == SLAPI_OPERATION_UNBIND )
  639. return;
  640. /* We indicate the initialize here becuase, if something goes wrong, it's cleaned up
  641. ** properly.
  642. */
  643. aclpb->aclpb_state = ACLPB_INITIALIZED;
  644. /* We make an anonymous user a non null dn which is empty */
  645. if (ndn && *ndn != '\0' )
  646. slapi_sdn_set_ndn_byval ( aclpb->aclpb_authorization_sdn, ndn );
  647. else
  648. slapi_sdn_set_ndn_byval ( aclpb->aclpb_authorization_sdn, "" );
  649. /* reset scoped entry cache to be empty */
  650. aclpb->aclpb_scoped_entry_anominfo.anom_e_nummatched = 0;
  651. if (PListAssignValue(aclpb->aclpb_proplist, DS_ATTR_USERDN,
  652. slapi_sdn_get_ndn(aclpb->aclpb_authorization_sdn), 0) < 0) {
  653. slapi_log_error(SLAPI_LOG_FATAL, plugin_name,
  654. "Unable to set the USER DN in the Plist\n");
  655. return;
  656. }
  657. slapi_pblock_get ( pb, SLAPI_OPERATION_AUTHTYPE, &authType );
  658. if (PListAssignValue(aclpb->aclpb_proplist, DS_ATTR_AUTHTYPE, authType, 0) < 0) {
  659. slapi_log_error(SLAPI_LOG_FATAL, plugin_name,
  660. "Unable to set the AUTH TYPE in the Plist\n");
  661. return;
  662. }
  663. slapi_pblock_get ( pb, SLAPI_OPERATION_SSF, &ssf);
  664. if (PListAssignValue(aclpb->aclpb_proplist, DS_ATTR_SSF, (const void *)ssf, 0) < 0) {
  665. slapi_log_error(SLAPI_LOG_FATAL, plugin_name,
  666. "Unable to set the SSF in the Plist\n");
  667. return;
  668. }
  669. /* PKBxxx: We should be getting it from the OP struct */
  670. slapi_pblock_get ( pb, SLAPI_CONN_CERT, &aclpb->aclpb_clientcert );
  671. /* See if the we have already a cached info about user's group */
  672. aclg_init_userGroup ( aclpb, ndn, 0 /* get lock */ );
  673. slapi_pblock_get( pb, SLAPI_BE_MAXNESTLEVEL, &aclpb->aclpb_max_nesting_level );
  674. slapi_pblock_get( pb, SLAPI_SEARCH_SIZELIMIT, &aclpb->aclpb_max_member_sizelimit );
  675. if ( aclpb->aclpb_max_member_sizelimit == 0 ) {
  676. aclpb->aclpb_max_member_sizelimit = SLAPD_DEFAULT_LOOKTHROUGHLIMIT;
  677. }
  678. slapi_pblock_get( pb, SLAPI_OPERATION_TYPE, &aclpb->aclpb_optype );
  679. aclpb->aclpb_signature = acl_get_aclsignature();
  680. aclpb->aclpb_last_cache_result = 0;
  681. aclpb->aclpb_pblock = pb;
  682. PR_ASSERT ( aclpb->aclpb_pblock != NULL );
  683. /* get the connection */
  684. slapi_pblock_get ( pb, SLAPI_CONNECTION, &conn);
  685. aclcb = (struct acl_cblock *) acl_get_ext ( ACL_EXT_CONNECTION, conn );
  686. if (NULL == aclcb || NULL == aclcb->aclcb_lock) {
  687. /* This could happen if the client is dead and we are in
  688. ** process of abondoning this operation
  689. */
  690. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  691. "No CONNECTION extension\n");
  692. } else if ( aclcb->aclcb_state == -1 ) {
  693. /* indicate that we need to update the cache */
  694. aclpb->aclpb_state |= ACLPB_UPD_ACLCB_CACHE;
  695. aclcb->aclcb_state = 0; /* Nore this is ACLCB and not ACLPB */
  696. } else if ( copy_from_aclcb ){
  697. char *cdn;
  698. Slapi_DN *c_sdn; /* client SDN */
  699. /* check if the operation is abandoned or not.*/
  700. if ( slapi_op_abandoned ( pb ) ) {
  701. return;
  702. }
  703. slapi_pblock_get ( pb, SLAPI_CONN_DN, &cdn ); /* We *must* free cdn! */
  704. c_sdn = slapi_sdn_new_dn_passin( cdn );
  705. PR_Lock ( aclcb->aclcb_lock );
  706. /*
  707. * since PR_Lock is taken,
  708. * we can mark the connection extension ok to be destroyed.
  709. */
  710. if ( (aclcb->aclcb_aclsignature != acl_get_aclsignature()) ||
  711. ( (NULL == cdn) && aclcb->aclcb_sdn ) ||
  712. (cdn && (NULL == aclcb->aclcb_sdn )) ||
  713. (cdn && aclcb->aclcb_sdn && ( 0 != slapi_sdn_compare ( c_sdn, aclcb->aclcb_sdn ) ))) {
  714. /* cleanup the aclcb cache */
  715. acl_clean_aclEval_context ( &aclcb->aclcb_eval_context, 0 /*clean*/ );
  716. aclcb->aclcb_state = 0;
  717. aclcb->aclcb_aclsignature = 0;
  718. slapi_sdn_done ( aclcb->aclcb_sdn );
  719. }
  720. slapi_sdn_free ( &c_sdn );
  721. /* COPY the cached information from ACLCB --> ACLPB */
  722. if ( aclcb->aclcb_state & ACLCB_HAS_CACHED_EVALCONTEXT) {
  723. acl_copyEval_context ( aclpb, &aclcb->aclcb_eval_context ,
  724. &aclpb->aclpb_prev_opEval_context, 0 );
  725. aclpb->aclpb_state |= ACLPB_HAS_ACLCB_EVALCONTEXT;
  726. }
  727. PR_Unlock ( aclcb->aclcb_lock );
  728. }
  729. }
  730. /* Cleans up the aclpb */
  731. static void
  732. acl__done_aclpb ( struct acl_pblock *aclpb )
  733. {
  734. int i;
  735. int dump_aclpb_info = 0;
  736. int rc=-1;
  737. char *tmp_ptr=NULL;
  738. /*
  739. ** First, let's do some sanity checks to see if we have everything what
  740. ** it should be.
  741. */
  742. /* Nothing needs to be cleaned up in this case */
  743. if (!(aclpb->aclpb_state & ACLPB_INITIALIZED))
  744. return;
  745. /* Check the state */
  746. if (aclpb->aclpb_state & ~ACLPB_STATE_ALL) {
  747. slapi_log_error( SLAPI_LOG_FATAL, plugin_name,
  748. "The aclpb.state value (%d) is incorrect. Exceeded the limit (%d)\n",
  749. aclpb->aclpb_state, ACLPB_STATE_ALL);
  750. dump_aclpb_info = 1;
  751. }
  752. #ifdef FOR_DEBUGGING
  753. acl__dump_stats ( aclpb, acl__get_aclpb_type(aclpb));
  754. #endif
  755. /* reset the usergroup cache */
  756. aclg_reset_userGroup ( aclpb );
  757. if ( aclpb->aclpb_res_type & ~ACLPB_RESTYPE_ALL ) {
  758. slapi_log_error( SLAPI_LOG_FATAL, plugin_name,
  759. "The aclpb res_type value (%d) has exceeded. Limit is (%d)\n",
  760. aclpb->aclpb_res_type, ACLPB_RESTYPE_ALL );
  761. dump_aclpb_info = 1;
  762. }
  763. if ( dump_aclpb_info ) {
  764. const char *ndn;
  765. slapi_log_error ( SLAPI_LOG_FATAL, plugin_name,
  766. "ACLPB value is:%p\n", aclpb );
  767. ndn = slapi_sdn_get_ndn ( aclpb->aclpb_curr_entry_sdn );
  768. slapi_log_error ( SLAPI_LOG_FATAL, plugin_name, "curr_entry:%p num_entries:%d curr_dn:%p\n",
  769. aclpb->aclpb_curr_entry ? (char *) aclpb->aclpb_curr_entry : "NULL",
  770. aclpb->aclpb_num_entries,
  771. ndn ? ndn : "NULL");
  772. slapi_log_error ( SLAPI_LOG_FATAL, plugin_name, "Last attr:%p, Plist:%p acleval: %p\n",
  773. aclpb->aclpb_Evalattr ? aclpb->aclpb_Evalattr : "NULL",
  774. aclpb->aclpb_proplist ? (char *) aclpb->aclpb_proplist : "NULL",
  775. aclpb->aclpb_acleval ? (char *) aclpb->aclpb_acleval : "NULL" );
  776. }
  777. /* Now Free the contents or clean it */
  778. slapi_sdn_done ( aclpb->aclpb_curr_entry_sdn );
  779. if (aclpb->aclpb_Evalattr)
  780. aclpb->aclpb_Evalattr[0] = '\0';
  781. /* deallocate the contents of the base array */
  782. for (i=0; i < aclpb->aclpb_numof_bases; i++) {
  783. if (aclpb->aclpb_grpsearchbase[i])
  784. slapi_ch_free ( (void **)&aclpb->aclpb_grpsearchbase[i] );
  785. }
  786. aclpb->aclpb_numof_bases = 0;
  787. acl_clean_aclEval_context ( &aclpb->aclpb_prev_opEval_context, 0 /*claen*/ );
  788. acl_clean_aclEval_context ( &aclpb->aclpb_prev_entryEval_context, 0 /*clean*/ );
  789. acl_clean_aclEval_context ( &aclpb->aclpb_curr_entryEval_context, 0/*clean*/ );
  790. if ( aclpb->aclpb_client_entry ) slapi_entry_free ( aclpb->aclpb_client_entry );
  791. aclpb->aclpb_client_entry = NULL;
  792. slapi_sdn_done ( aclpb->aclpb_authorization_sdn );
  793. aclpb->aclpb_pblock = NULL;
  794. if ( aclpb->aclpb_search_base )
  795. slapi_ch_free ( (void **) &aclpb->aclpb_search_base );
  796. for ( i=0; i < aclpb->aclpb_num_deny_handles; i++ )
  797. aclpb->aclpb_deny_handles[i] = NULL;
  798. aclpb->aclpb_num_deny_handles = 0;
  799. for ( i=0; i < aclpb->aclpb_num_allow_handles; i++ )
  800. aclpb->aclpb_allow_handles[i] = NULL;
  801. aclpb->aclpb_num_allow_handles = 0;
  802. /* clear results cache */
  803. memset((char*)aclpb->aclpb_cache_result, 0,
  804. sizeof(struct result_cache)*aclpb->aclpb_last_cache_result);
  805. aclpb->aclpb_last_cache_result = 0;
  806. aclpb->aclpb_handles_index[0] = -1;
  807. aclpb->aclpb_base_handles_index[0] = -1;
  808. aclpb->aclpb_stat_acllist_scanned = 0;
  809. aclpb->aclpb_stat_aclres_matched = 0;
  810. aclpb->aclpb_stat_total_entries = 0;
  811. aclpb->aclpb_stat_anom_list_scanned = 0;
  812. aclpb->aclpb_stat_num_copycontext = 0;
  813. aclpb->aclpb_stat_num_copy_attrs = 0;
  814. aclpb->aclpb_stat_num_tmatched_acls = 0;
  815. aclpb->aclpb_clientcert = NULL;
  816. aclpb->aclpb_proxy = NULL;
  817. acllist_done_aciContainer ( aclpb->aclpb_aclContainer );
  818. /*
  819. * Here, decide which things need to be freed/removed/whatever from the
  820. * aclpb_proplist.
  821. */
  822. /*
  823. * The DS_ATTR_DNS property contains the name of the client machine.
  824. *
  825. * The value pointed to by this property is stored in the pblock--it
  826. * points to the SLAPI_CLIENT_DNS object. So, that memory will
  827. * be freed elsewhere.
  828. *
  829. * It's removed here from the aclpb_proplist as it would be an error to
  830. * allow it to persist in the aclpb which is an operation time thing.
  831. * If we leave it here the next time this aclpb gets used, the DnsGetter
  832. * is not called by LASDnsEval/ACL_GetAttribute() as it thinks the
  833. * ACL_ATTR_DNS has already been initialized.
  834. *
  835. */
  836. if ((rc = PListFindValue(aclpb->aclpb_proplist, ACL_ATTR_DNS,
  837. (void **)&tmp_ptr, NULL)) > 0) {
  838. PListDeleteProp(aclpb->aclpb_proplist, rc, NULL);
  839. }
  840. /*
  841. * Remove the DS_ATTR_IP property from the property list.
  842. * The value of this property is just the property pointer
  843. * (an unsigned long) so that gets freed too when we delete the
  844. * property.
  845. * It's removed here from the aclpb_proplist as it would be an error to
  846. * allow it to persist in the aclpb which is an operation time thing.
  847. * If we leave it here the next time this aclpb gets used, the DnsGetter
  848. * is not called by LASIpEval/ACL_GetAttribute() as it thinks the
  849. * ACL_ATTR_IP has already been initialized.
  850. */
  851. if ((rc = PListFindValue(aclpb->aclpb_proplist, ACL_ATTR_IP,
  852. (void **)&tmp_ptr, NULL)) > 0) {
  853. PListDeleteProp(aclpb->aclpb_proplist, rc, NULL);
  854. }
  855. /*
  856. * The DS_ATTR_USERDN value comes from aclpb_authorization_sdn.
  857. * This memory
  858. * is freed above using aclpb_authorization_sdn so we don't need to free it here
  859. * before overwriting the old value.
  860. */
  861. PListAssignValue(aclpb->aclpb_proplist, DS_ATTR_USERDN, NULL, 0);
  862. /*
  863. * The DS_ATTR_AUTHTYPE value is a pointer into the pblock, so
  864. * we do not need to free that memory before overwriting the value.
  865. */
  866. PListAssignValue(aclpb->aclpb_proplist, DS_ATTR_AUTHTYPE, NULL, 0);
  867. /*
  868. * DO NOT overwrite the aclpb pointer--it is initialized at malloc_aclpb
  869. * time and is kept within the aclpb.
  870. *
  871. * PListAssignValue(aclpb->aclpb_proplist, DS_PROP_ACLPB, NULL, 0);
  872. */
  873. /*
  874. * The DS_ATTR_ENTRY value was a pointer to the entry being evaluated
  875. * by the ACL code. That entry comes from outside the context of
  876. * the acl code and so is dealt with out there. Ergo, here we can just
  877. * lose the pointer to that entry.
  878. */
  879. PListAssignValue(aclpb->aclpb_proplist, DS_ATTR_ENTRY, NULL, 0);
  880. aclpb->aclpb_signature = 0;
  881. /* reset scoped entry cache to be empty */
  882. aclpb->aclpb_scoped_entry_anominfo.anom_e_nummatched = 0;
  883. /* Free up any of the string values left in the macro ht and remove
  884. * the entries.*/
  885. acl_ht_free_all_entries_and_values(aclpb->aclpb_macro_ht);
  886. /* Finally, set it to the no use state */
  887. aclpb->aclpb_state = 0;
  888. }
  889. #ifdef FOR_DEBUGGING
  890. static char *
  891. acl__get_aclpb_type ( Acl_PBlock *aclpb )
  892. {
  893. if (aclpb->aclpb_state & ACLPB_TYPE_PROXY)
  894. return ACLPB_TYPE_PROXY_STR;
  895. return ACLPB_TYPE_MAIN_STR;
  896. }
  897. static void
  898. acl__dump_stats ( struct acl_pblock *aclpb , const char *block_type)
  899. {
  900. PRUint64 connid = 0;
  901. int opid = 0;
  902. Slapi_PBlock *pb = NULL;
  903. pb = aclpb->aclpb_pblock;
  904. if ( pb ) {
  905. slapi_pblock_get ( pb, SLAPI_CONN_ID, &connid );
  906. slapi_pblock_get ( pb, SLAPI_OPERATION_ID, &opid );
  907. }
  908. /* DUMP STAT INFO */
  909. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  910. "**** ACL OPERATION STAT BEGIN ( aclpb:%p Block type: %s): Conn:%" PRIu64 " Operation:%d *******\n",
  911. aclpb, block_type, connid, opid );
  912. slapi_log_error( SLAPI_LOG_ACL, plugin_name, "\tNumber of entries scanned: %d\n",
  913. aclpb->aclpb_stat_total_entries);
  914. slapi_log_error( SLAPI_LOG_ACL, plugin_name, "\tNumber of times ACL List scanned: %d\n",
  915. aclpb->aclpb_stat_acllist_scanned);
  916. slapi_log_error( SLAPI_LOG_ACL, plugin_name, "\tNumber of ACLs with target matched:%d\n",
  917. aclpb->aclpb_stat_num_tmatched_acls);
  918. slapi_log_error( SLAPI_LOG_ACL, plugin_name, "\tNumber of times acl resource matched:%d\n",
  919. aclpb->aclpb_stat_aclres_matched);
  920. slapi_log_error( SLAPI_LOG_ACL, plugin_name, "\tNumber of times ANOM list scanned:%d\n",
  921. aclpb->aclpb_stat_anom_list_scanned);
  922. slapi_log_error( SLAPI_LOG_ACL, plugin_name, "\tNumber of times Context was copied:%d\n",
  923. aclpb->aclpb_stat_num_copycontext);
  924. slapi_log_error( SLAPI_LOG_ACL, plugin_name, "\tNumber of times Attrs was copied:%d\n",
  925. aclpb->aclpb_stat_num_copy_attrs);
  926. slapi_log_error( SLAPI_LOG_ACL, plugin_name, " **** ACL OPERATION STAT END *******\n");
  927. }
  928. #endif
  929. /****************************************************************************/
  930. /* E N D */
  931. /****************************************************************************/