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.

72 lines
2.0 KiB

  1. //******************************************************************************
  2. //
  3. // Copyright (c) 1999-2000, Microsoft Corporation, All rights reserved
  4. //
  5. //*****************************************************************************
  6. #include "precomp.h"
  7. #include <stdio.h>
  8. #include <wbemcomn.h>
  9. #include <tkncache.h>
  10. #include <groupsforuser.h>
  11. CWmiToken::CWmiToken(ADDREF CTokenCache* pCache, const PSID pSid,
  12. ACQUIRE HANDLE hToken) :
  13. CUnkBase<IWbemToken, &IID_IWbemToken>(NULL), m_hToken(hToken),
  14. m_pCache(pCache), m_pSid(NULL), m_bOwnHandle(true)
  15. {
  16. if(m_pCache)
  17. m_pCache->AddRef();
  18. if(pSid)
  19. {
  20. m_pSid = (PSID)new BYTE[GetLengthSid(pSid)];
  21. if(m_pSid == NULL)
  22. return;
  23. CopySid(GetLengthSid(pSid), m_pSid, pSid);
  24. }
  25. }
  26. CWmiToken::CWmiToken(READ_ONLY HANDLE hToken) :
  27. CUnkBase<IWbemToken, &IID_IWbemToken>(NULL), m_hToken(hToken),
  28. m_pCache(NULL), m_pSid(NULL), m_bOwnHandle(false)
  29. {
  30. }
  31. CWmiToken::~CWmiToken()
  32. {
  33. if(m_pCache)
  34. m_pCache->Release();
  35. if(m_bOwnHandle)
  36. CloseHandle(m_hToken);
  37. delete [] (BYTE*)m_pSid;
  38. }
  39. STDMETHODIMP CWmiToken::AccessCheck(DWORD dwDesiredAccess, const BYTE* pSD,
  40. DWORD* pdwGrantedAccess)
  41. {
  42. if(m_hToken == NULL)
  43. return WBEM_E_CRITICAL_ERROR;
  44. // BUGBUG: figure out what this is for!
  45. GENERIC_MAPPING map;
  46. map.GenericRead = 1;
  47. map.GenericWrite = 0x1C;
  48. map.GenericExecute = 2;
  49. map.GenericAll = 0x6001f;
  50. PRIVILEGE_SET ps;
  51. DWORD dwPrivLength = sizeof(ps);
  52. BOOL bStatus;
  53. BOOL bRes = ::AccessCheck((SECURITY_DESCRIPTOR*)pSD, m_hToken,
  54. dwDesiredAccess, &map, &ps,
  55. &dwPrivLength, pdwGrantedAccess, &bStatus);
  56. if(!bRes)
  57. {
  58. return WBEM_E_ACCESS_DENIED;
  59. }
  60. else
  61. {
  62. return WBEM_S_NO_ERROR;
  63. }
  64. }