acl_ext.c 35 KB

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