acl_ext.c 37 KB

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