Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

191 lines
3.3 KiB

  1. /*
  2. * PolRef.cpp
  3. *
  4. * Author: BreenH
  5. *
  6. * Policy reference list code.
  7. */
  8. /*
  9. * Includes
  10. */
  11. #include "precomp.h"
  12. #include "lscore.h"
  13. #include "session.h"
  14. #include "policy.h"
  15. #include "pollist.h"
  16. /*
  17. * Globals
  18. */
  19. LIST_ENTRY g_PolicyList;
  20. ULONG g_cPolicies;
  21. /*
  22. * Internal Function Prototypes
  23. */
  24. LPLCPOLICYREF
  25. FindPolicyListEntry(
  26. ULONG ulPolicyId
  27. );
  28. /*
  29. * Function Implementations
  30. */
  31. NTSTATUS
  32. PolicyListAdd(
  33. CPolicy *pPolicy
  34. )
  35. {
  36. LPLCPOLICYREF lpPolicyRef;
  37. ASSERT(pPolicy != NULL);
  38. lpPolicyRef = (LPLCPOLICYREF)LocalAlloc(LPTR, sizeof(LCPOLICYREF));
  39. if (lpPolicyRef != NULL)
  40. {
  41. lpPolicyRef->pPolicy = pPolicy;
  42. g_cPolicies++;
  43. InsertTailList(&g_PolicyList, &(lpPolicyRef->ListEntry));
  44. return(STATUS_SUCCESS);
  45. }
  46. else
  47. {
  48. return(STATUS_NO_MEMORY);
  49. }
  50. }
  51. VOID
  52. PolicyListDelete(
  53. ULONG ulPolicyId
  54. )
  55. {
  56. LPLCPOLICYREF lpPolicyRef;
  57. lpPolicyRef = FindPolicyListEntry(ulPolicyId);
  58. if (lpPolicyRef != NULL)
  59. {
  60. g_cPolicies--;
  61. RemoveEntryList(&(lpPolicyRef->ListEntry));
  62. LocalFree(lpPolicyRef);
  63. }
  64. }
  65. NTSTATUS
  66. PolicyListEnumerateIds(
  67. PULONG *ppulPolicyIds,
  68. PULONG pcPolicies
  69. )
  70. {
  71. NTSTATUS Status;
  72. *ppulPolicyIds = (PULONG)MIDL_user_allocate(g_cPolicies * sizeof(ULONG));
  73. if (*ppulPolicyIds != NULL)
  74. {
  75. LPLCPOLICYREF pTemp;
  76. ULONG i;
  77. pTemp = CONTAINING_RECORD(g_PolicyList.Flink, LCPOLICYREF, ListEntry);
  78. for (i = 0; i < g_cPolicies; i++)
  79. {
  80. (*ppulPolicyIds)[i] = pTemp->pPolicy->GetId();
  81. pTemp = CONTAINING_RECORD(pTemp->ListEntry.Flink, LCPOLICYREF, ListEntry);
  82. }
  83. *pcPolicies = g_cPolicies;
  84. Status = STATUS_SUCCESS;
  85. }
  86. else
  87. {
  88. *pcPolicies = 0;
  89. Status = STATUS_NO_MEMORY;
  90. }
  91. return(Status);
  92. }
  93. CPolicy *
  94. PolicyListFindById(
  95. ULONG ulPolicyId
  96. )
  97. {
  98. LPLCPOLICYREF lpPolicyRef;
  99. lpPolicyRef = FindPolicyListEntry(ulPolicyId);
  100. return(lpPolicyRef != NULL ? lpPolicyRef->pPolicy : NULL);
  101. }
  102. NTSTATUS
  103. PolicyListInitialize(
  104. VOID
  105. )
  106. {
  107. g_cPolicies = 0;
  108. InitializeListHead(&g_PolicyList);
  109. return(STATUS_SUCCESS);
  110. }
  111. CPolicy *
  112. PolicyListPop(
  113. VOID
  114. )
  115. {
  116. CPolicy *pPolicy;
  117. PLIST_ENTRY pTemp;
  118. LPLCPOLICYREF lpCurrentRef;
  119. if (!IsListEmpty(&g_PolicyList))
  120. {
  121. pTemp = RemoveHeadList(&g_PolicyList);
  122. lpCurrentRef = CONTAINING_RECORD(pTemp, LCPOLICYREF, ListEntry);
  123. pPolicy = lpCurrentRef->pPolicy;
  124. LocalFree(lpCurrentRef);
  125. }
  126. else
  127. {
  128. pPolicy = NULL;
  129. }
  130. return(pPolicy);
  131. }
  132. /*
  133. * Internal Function Implementations
  134. */
  135. LPLCPOLICYREF
  136. FindPolicyListEntry(
  137. ULONG ulPolicyId
  138. )
  139. {
  140. PLIST_ENTRY pNext;
  141. LPLCPOLICYREF lpPolicyRef, lpCurrentRef;
  142. lpPolicyRef = NULL;
  143. for (pNext = g_PolicyList.Flink; pNext != &g_PolicyList; pNext = pNext->Flink)
  144. {
  145. lpCurrentRef = CONTAINING_RECORD(pNext, LCPOLICYREF, ListEntry);
  146. if (lpCurrentRef->pPolicy->GetId() == ulPolicyId)
  147. {
  148. lpPolicyRef = lpCurrentRef;
  149. break;
  150. }
  151. }
  152. return(lpPolicyRef);
  153. }