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.

94 lines
2.1 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. KOEISecurityCheck.cpp
  5. Abstract:
  6. This shim sets the SID for TokenOwner at the beginning of the setup.exe. It checks
  7. if the administrator group SID is enabled in current process token. If it is enabled then
  8. we set the TokenOwner SID to administrator group SID. If its not then it does nothing.
  9. History:
  10. 04/17/2001 zhongyl create
  11. --*/
  12. #include "precomp.h"
  13. IMPLEMENT_SHIM_BEGIN(KOEISecurityCheck)
  14. #include "ShimHookMacro.h"
  15. APIHOOK_ENUM_BEGIN
  16. APIHOOK_ENUM_END
  17. /*++
  18. DisableStickyKeys saves the current value for LPSTICKYKEYS and then disables the option.
  19. --*/
  20. VOID
  21. SetSidForOwner()
  22. {
  23. BYTE sidBuffer[50];
  24. PSID pSID = (PSID)sidBuffer;
  25. SID_IDENTIFIER_AUTHORITY SIDAuth = SECURITY_NT_AUTHORITY;
  26. BOOL IsMember;
  27. HANDLE hToken;
  28. TOKEN_OWNER SIDforOwner;
  29. // Open a handle to the access token for the calling process.
  30. if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY | TOKEN_ADJUST_DEFAULT, &hToken ))
  31. return; //if OpenProcessToken fails, do nothing
  32. // Create a SID for the BUILTIN\Administrators group.
  33. if (!AllocateAndInitializeSid(&SIDAuth, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &pSID))
  34. return; //if AllocateAndInitializedSid fails, do nothing
  35. // Check if the administrator group SID is enabled in current process token
  36. if (!CheckTokenMembership(NULL, pSID, &IsMember))
  37. return; //if CheckTokenMembership fails, do nothing
  38. SIDforOwner.Owner = pSID;
  39. // if the administrator group SID is enabled in current process token, call SetTokenInformation to set the SID for Owner.
  40. if (IsMember)
  41. SetTokenInformation(hToken, TokenOwner, &SIDforOwner, sizeof(SIDforOwner));
  42. return;
  43. }
  44. BOOL
  45. NOTIFY_FUNCTION(
  46. DWORD fdwReason
  47. )
  48. {
  49. if (fdwReason == SHIM_STATIC_DLLS_INITIALIZED) {
  50. SetSidForOwner();
  51. }
  52. return TRUE;
  53. }
  54. /*++
  55. Register hooked functions
  56. --*/
  57. HOOK_BEGIN
  58. CALL_NOTIFY_FUNCTION
  59. HOOK_END
  60. IMPLEMENT_SHIM_END