acl_ext.c 37 KB

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