Source code of Windows XP (NT5)
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.

190 lines
4.0 KiB

  1. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft WMIOLE DB Provider
  4. // (C) Copyright 1999 Microsoft Corporation. All Rights Reserved.
  5. //
  6. //
  7. // IObjAccessControl.cpp - IObjectAccessControl interface implementation
  8. //
  9. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  10. #include "headers.h"
  11. //GUID g_rgObjectID[3]= {DBOBJECT_TABLE,DBOBJECT_DATABASE,DBOBJECT_WMIINSTANCE};
  12. const GUID *g_prgObjectID[] = { &DBOBJECT_TABLE,&DBOBJECT_DATABASE,&DBOBJECT_WMIINSTANCE };
  13. #define NUMBER_OF_SUPPORTEDOBJECTS 3
  14. STDMETHODIMP CImpISecurityInfo::GetCurrentTrustee(TRUSTEE_W ** ppTrustee)
  15. {
  16. HRESULT hr = S_OK;
  17. CSetStructuredExceptionHandler seh;
  18. TRY_BLOCK;
  19. // Serialize the object
  20. CAutoBlock cab(DATASOURCE->GetCriticalSection());
  21. g_pCError->ClearErrorInfo();
  22. hr = GetCurTrustee(ppTrustee);
  23. hr = hr == S_OK ? hr :g_pCError->PostHResult(hr,&IID_ISecurityInfo);
  24. CATCH_BLOCK_HRESULT(hr,L"ISecurityInfo::GetCurrentTrustee");
  25. return hr;
  26. }
  27. STDMETHODIMP CImpISecurityInfo::GetObjectTypes(ULONG *cObjectTypes,GUID **gObjectTypes)
  28. {
  29. HRESULT hr = S_OK;
  30. CSetStructuredExceptionHandler seh;
  31. TRY_BLOCK;
  32. // Serialize the object
  33. CAutoBlock cab(DATASOURCE->GetCriticalSection());
  34. g_pCError->ClearErrorInfo();
  35. if(!cObjectTypes || !gObjectTypes)
  36. {
  37. E_INVALIDARG;
  38. }
  39. else
  40. {
  41. try
  42. {
  43. *gObjectTypes = (GUID *)g_pIMalloc->Alloc(sizeof(GUID) * NUMBER_OF_SUPPORTEDOBJECTS);
  44. }
  45. catch(...)
  46. {
  47. if(*gObjectTypes)
  48. {
  49. g_pIMalloc->Free(*gObjectTypes);
  50. }
  51. }
  52. if(*gObjectTypes)
  53. {
  54. for(int lIndex = 0 ; lIndex < NUMBER_OF_SUPPORTEDOBJECTS ; lIndex++)
  55. {
  56. memcpy(gObjectTypes[lIndex] , g_prgObjectID[lIndex] , sizeof(GUID));
  57. }
  58. *cObjectTypes = NUMBER_OF_SUPPORTEDOBJECTS;
  59. }
  60. else
  61. {
  62. hr = E_OUTOFMEMORY;
  63. }
  64. }
  65. hr = hr == S_OK ? hr :g_pCError->PostHResult(hr,&IID_ISecurityInfo);
  66. CATCH_BLOCK_HRESULT(hr,L"ISecurityInfo::GetObjectTypes");
  67. return hr;
  68. }
  69. STDMETHODIMP CImpISecurityInfo::GetPermissions(GUID ObjectType,ACCESS_MASK *pPermissions)
  70. {
  71. HRESULT hr = S_OK;
  72. CSetStructuredExceptionHandler seh;
  73. TRY_BLOCK;
  74. // Serialize the object
  75. CAutoBlock cab(DATASOURCE->GetCriticalSection());
  76. g_pCError->ClearErrorInfo();
  77. if(ObjectType != DBOBJECT_TABLE &&
  78. ObjectType != DBOBJECT_DATABASE &&
  79. ObjectType != DBOBJECT_WMIINSTANCE)
  80. {
  81. hr = SEC_E_INVALIDOBJECT;
  82. }
  83. if(pPermissions == NULL)
  84. {
  85. hr = E_INVALIDARG;
  86. }
  87. else
  88. {
  89. *pPermissions = DELETE | READ_CONTROL | WRITE_DAC | WRITE_OWNER;
  90. }
  91. hr = hr == S_OK ? hr :g_pCError->PostHResult(hr,&IID_ISecurityInfo);
  92. CATCH_BLOCK_HRESULT(hr,L"ISecurityInfo::GetPermissions");
  93. return hr;
  94. }
  95. STDMETHODIMP CImpISecurityInfo::GetCurTrustee(TRUSTEE_W ** ppTrustee)
  96. {
  97. HRESULT hr = E_FAIL;
  98. HANDLE hToken;
  99. HANDLE hProcess;
  100. TOKEN_USER * pTokenUser = NULL;
  101. DWORD processID = GetCurrentProcessId();
  102. BOOL bRet = FALSE;
  103. ULONG lSize = 0;
  104. hProcess = OpenProcess(PROCESS_QUERY_INFORMATION,FALSE,processID);
  105. if(hProcess != NULL)
  106. {
  107. if(OpenProcessToken(hProcess,TOKEN_QUERY,&hToken))
  108. {
  109. if(GetTokenInformation(hToken,TokenUser,NULL,0,&lSize))
  110. {
  111. try
  112. {
  113. pTokenUser = (TOKEN_USER *) g_pIMalloc->Alloc(lSize);
  114. }
  115. catch(...)
  116. {
  117. if(pTokenUser)
  118. {
  119. g_pIMalloc->Free(pTokenUser);
  120. }
  121. throw;
  122. }
  123. if(!pTokenUser)
  124. {
  125. hr = E_OUTOFMEMORY;
  126. }
  127. else
  128. {
  129. if(GetTokenInformation(hToken,TokenUser,pTokenUser,lSize,&lSize))
  130. {
  131. *ppTrustee = NULL;
  132. try
  133. {
  134. *ppTrustee = (TRUSTEE_W *)g_pIMalloc->Alloc(sizeof(TRUSTEE_W));
  135. }
  136. catch(...)
  137. {
  138. if(*ppTrustee)
  139. g_pIMalloc->Free(*ppTrustee);
  140. throw;
  141. }
  142. if(!(*ppTrustee))
  143. {
  144. hr = E_OUTOFMEMORY;
  145. }
  146. else
  147. {
  148. BuildTrusteeWithSidW(*ppTrustee,pTokenUser->User.Sid);
  149. }
  150. }
  151. }
  152. if(pTokenUser)
  153. {
  154. g_pIMalloc->Free(pTokenUser);
  155. }
  156. }
  157. }
  158. CloseHandle(hProcess);
  159. }
  160. else
  161. {
  162. hr = E_FAIL;
  163. }
  164. return hr;
  165. }