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.

159 lines
3.7 KiB

  1. //*************************************************************
  2. //
  3. // Debugging functions
  4. //
  5. // Microsoft Confidential
  6. // Copyright (c) Microsoft Corporation 1995
  7. // All rights reserved
  8. //
  9. //*************************************************************
  10. #include "appmgext.hxx"
  11. //
  12. // Policy finish events for test code. Only used if DL_EVENT debug
  13. // level is on.
  14. //
  15. HANDLE ghUserPolicyEvent = 0;
  16. HANDLE ghMachinePolicyEvent = 0;
  17. void
  18. CreatePolicyEvents()
  19. {
  20. SECURITY_ATTRIBUTES SecAttr;
  21. SECURITY_DESCRIPTOR SecDesc;
  22. SID_IDENTIFIER_AUTHORITY authNT = SECURITY_NT_AUTHORITY;
  23. SID_IDENTIFIER_AUTHORITY authWORLD = SECURITY_WORLD_SID_AUTHORITY;
  24. PSID psidAdmin = NULL;
  25. PSID psidSystem = NULL;
  26. PSID psidEveryOne = NULL;
  27. PACL pAcl = NULL;
  28. DWORD cbMemSize;
  29. DWORD cbAcl;
  30. if ( ! (gDebugLevel & DL_EVENT) )
  31. return;
  32. if ( ghUserPolicyEvent && ghMachinePolicyEvent )
  33. return;
  34. //
  35. // Create an SD with following permissions
  36. // LocalSystem:F
  37. // Administrators:F
  38. // EveryOne:Synchronize
  39. //
  40. if (!AllocateAndInitializeSid(&authNT, 1, SECURITY_LOCAL_SYSTEM_RID,
  41. 0, 0, 0, 0, 0, 0, 0, &psidSystem))
  42. {
  43. goto Exit;
  44. }
  45. if (!AllocateAndInitializeSid(&authNT, 2, SECURITY_BUILTIN_DOMAIN_RID,
  46. DOMAIN_ALIAS_RID_ADMINS, 0, 0,
  47. 0, 0, 0, 0, &psidAdmin))
  48. {
  49. goto Exit;
  50. }
  51. if (!AllocateAndInitializeSid(&authWORLD, 1, SECURITY_WORLD_RID,
  52. 0, 0, 0, 0, 0, 0, 0, &psidEveryOne))
  53. {
  54. goto Exit;
  55. }
  56. cbAcl = (GetLengthSid (psidSystem)) +
  57. (GetLengthSid (psidAdmin)) +
  58. (GetLengthSid (psidEveryOne)) +
  59. sizeof(ACL) +
  60. (3 * (sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD)));
  61. pAcl = (PACL) LocalAlloc(LPTR, cbAcl);
  62. if (!pAcl)
  63. {
  64. goto Exit;
  65. }
  66. if (!InitializeAcl(pAcl, cbAcl, ACL_REVISION))
  67. {
  68. goto Exit;
  69. }
  70. if (!AddAccessAllowedAceEx(pAcl, ACL_REVISION, 0, GENERIC_ALL, psidSystem))
  71. {
  72. goto Exit;
  73. }
  74. if (!AddAccessAllowedAceEx(pAcl, ACL_REVISION, 0, GENERIC_ALL, psidAdmin))
  75. {
  76. goto Exit;
  77. }
  78. if (!AddAccessAllowedAceEx(pAcl, ACL_REVISION, 0, SYNCHRONIZE, psidEveryOne))
  79. {
  80. goto Exit;
  81. }
  82. if (!InitializeSecurityDescriptor( &SecDesc, SECURITY_DESCRIPTOR_REVISION ))
  83. {
  84. goto Exit;
  85. }
  86. if (!SetSecurityDescriptorDacl( &SecDesc, TRUE, pAcl, FALSE ))
  87. {
  88. goto Exit;
  89. }
  90. SecAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
  91. SecAttr.lpSecurityDescriptor = &SecDesc;
  92. SecAttr.bInheritHandle = FALSE;
  93. if ( ! ghUserPolicyEvent )
  94. {
  95. ghUserPolicyEvent = CreateEvent(
  96. &SecAttr,
  97. TRUE,
  98. FALSE,
  99. L"AppMgmtUserPolicyEvent" );
  100. }
  101. if ( ! ghMachinePolicyEvent )
  102. {
  103. ghMachinePolicyEvent = CreateEvent(
  104. &SecAttr,
  105. TRUE,
  106. FALSE,
  107. L"AppMgmtMachinePolicyEvent" );
  108. }
  109. Exit:
  110. if (psidSystem)
  111. {
  112. FreeSid(psidSystem);
  113. }
  114. if (psidAdmin)
  115. {
  116. FreeSid(psidAdmin);
  117. }
  118. if (psidEveryOne)
  119. {
  120. FreeSid(psidEveryOne);
  121. }
  122. if (pAcl)
  123. {
  124. LocalFree (pAcl);
  125. }
  126. return;
  127. }