acl_ext.c 35 KB

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