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.

107 lines
2.0 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. VJEDeltaSetup.cpp
  5. Abstract:
  6. This app' setup program has a MYDLL.DLL, it has memory corruption in it's
  7. IsAdmin(). Fixing this by provide a new procedure IsAdmin().
  8. (Copy/Paste from PSDK)
  9. History:
  10. 06/12/2001 xiaoz create
  11. --*/
  12. #include "precomp.h"
  13. //
  14. // app's private Prototype
  15. //
  16. typedef BOOL (WINAPI *_pfn_IsAdmin)(void);
  17. IMPLEMENT_SHIM_BEGIN(VJEDeltaSetup)
  18. #include "ShimHookMacro.h"
  19. APIHOOK_ENUM_BEGIN
  20. APIHOOK_ENUM_ENTRY(IsAdmin)
  21. APIHOOK_ENUM_END
  22. /*++
  23. New function to check whethe currently login as Admin, Copy/Paste from PSDK
  24. --*/
  25. BOOL
  26. APIHOOK(IsAdmin)(
  27. void
  28. )
  29. {
  30. PSID pSID = NULL;
  31. SID_IDENTIFIER_AUTHORITY SIDAuth = SECURITY_NT_AUTHORITY;
  32. BOOL IsMember;
  33. HANDLE hToken = INVALID_HANDLE_VALUE;
  34. TOKEN_OWNER SIDforOwner;
  35. BOOL bRet = FALSE;
  36. //
  37. // Open a handle to the access token for the calling process.
  38. //
  39. if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY | TOKEN_ADJUST_DEFAULT,
  40. &hToken ))
  41. {
  42. goto Cleanup;
  43. }
  44. //
  45. // Create a SID for the BUILTIN\Administrators group.
  46. //
  47. if (!AllocateAndInitializeSid(&SIDAuth, 2, SECURITY_BUILTIN_DOMAIN_RID,
  48. DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &pSID))
  49. {
  50. pSID = NULL;
  51. goto Cleanup;
  52. }
  53. //
  54. // Check if the administrator group SID is enabled in current process token
  55. //
  56. if (!CheckTokenMembership(NULL, pSID, &IsMember))
  57. {
  58. goto Cleanup;
  59. }
  60. if (IsMember)
  61. {
  62. bRet = TRUE;
  63. }
  64. Cleanup:
  65. if (pSID)
  66. {
  67. FreeSid(pSID);
  68. }
  69. if (hToken != INVALID_HANDLE_VALUE)
  70. {
  71. CloseHandle(hToken);
  72. }
  73. return bRet;
  74. }
  75. /*++
  76. Register hooked functions
  77. --*/
  78. HOOK_BEGIN
  79. APIHOOK_ENTRY(MYDLL.DLL, IsAdmin)
  80. HOOK_END
  81. IMPLEMENT_SHIM_END