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.

323 lines
10 KiB

  1. //*************************************************************
  2. //
  3. // Microsoft Confidential. Copyright (c) Microsoft Corporation 1999. All rights reserved
  4. //
  5. // File: RsopInc.h
  6. //
  7. // Description: Headers for utility functions
  8. //
  9. // History: 8-26-99 NishadM Created
  10. //
  11. //*************************************************************
  12. #ifndef __RSOPINC_H__
  13. #define __RSOPINC_H__
  14. //****************************************************
  15. // Definitions used in constructing the name spaces.
  16. //
  17. // PM Stands for Planning Mode Provider
  18. // SM stands for Snapshot Mode Provider
  19. //
  20. // DIAG for diagnostic logging
  21. //****************************************************
  22. #define RSOP_MOF_SCHEMA_VERSION 0x00210000
  23. #define RSOP_NS_ROOT L"\\\\.\\Root\\Rsop"
  24. #define RSOP_NS_PM_ROOT RSOP_NS_ROOT
  25. #define RSOP_NS_SM_ROOT RSOP_NS_ROOT
  26. #define RSOP_NS_DIAG_ROOT RSOP_NS_ROOT
  27. #define RSOP_NS_ROOT_LEN 20
  28. // Garbage collectable name spaces
  29. #define RSOP_NS_TEMP_PREFIX L"NS"
  30. #define RSOP_NS_TEMP_FMT L"\\\\.\\Root\\Rsop\\"RSOP_NS_TEMP_PREFIX L"%s"
  31. #define RSOP_NS_TEMP_LEN 100
  32. #define RSOP_NS_PM_FMT RSOP_NS_TEMP_FMT
  33. #define RSOP_NS_SM_FMT RSOP_NS_TEMP_FMT
  34. // user offsets
  35. #define RSOP_NS_USER_OFFSET L"User"
  36. #define RSOP_NS_PM_USER_OFFSET RSOP_NS_USER_OFFSET
  37. #define RSOP_NS_SM_USER_OFFSET RSOP_NS_USER_OFFSET
  38. #define RSOP_NS_DIAG_ROOTUSER_OFFSET RSOP_NS_USER_OFFSET
  39. // The code assumes that this is a Sid when the name is generated and
  40. // and when users are enumerated in snapshot provider.
  41. #define RSOP_NS_DIAG_USER_OFFSET_FMT L"User\\%s"
  42. // machine offsets
  43. #define RSOP_NS_MACHINE_OFFSET L"Computer"
  44. #define RSOP_NS_PM_MACHINE_OFFSET RSOP_NS_MACHINE_OFFSET
  45. #define RSOP_NS_SM_MACHINE_OFFSET RSOP_NS_MACHINE_OFFSET
  46. #define RSOP_NS_DIAG_MACHINE_OFFSET RSOP_NS_MACHINE_OFFSET
  47. #define RSOP_NS_MAX_OFFSET_LEN 20
  48. // user
  49. #define RSOP_NS_USER L"\\\\.\\Root\\Rsop\\User"
  50. #define RSOP_NS_SM_USER RSOP_NS_USER
  51. #define RSOP_NS_PM_USER RSOP_NS_USER
  52. #define RSOP_NS_DIAG_USERROOT RSOP_NS_USER
  53. #define RSOP_NS_DIAG_USER_FMT L"\\\\.\\Root\\Rsop\\User\\%s"
  54. // machine
  55. #define RSOP_NS_MACHINE L"\\\\.\\Root\\Rsop\\Computer"
  56. #define RSOP_NS_SM_MACHINE RSOP_NS_MACHINE
  57. #define RSOP_NS_PM_MACHINE RSOP_NS_MACHINE
  58. #define RSOP_NS_DIAG_MACHINE RSOP_NS_MACHINE
  59. // remote name spaces
  60. #define RSOP_NS_REMOTE_ROOT_FMT L"\\\\%s\\Root\\Rsop"
  61. #define RSOP_NS_SM_REMOTE_ROOT_FMT RSOP_NS_REMOTE_ROOT_FMT
  62. #define RSOP_NS_PM_REMOTE_ROOT_FMT RSOP_NS_REMOTE_ROOT_FMT
  63. // user
  64. #define RSOP_NS_REMOTE_USER_FMT L"\\\\%s\\Root\\Rsop\\User"
  65. #define RSOP_NS_SM_REMOTE_USER_FMT RSOP_NS_REMOTE_USER_FMT
  66. #define RSOP_NS_PM_REMOTE_USER_FMT RSOP_NS_REMOTE_USER_FMT
  67. #define RSOP_NS_DIAG_REMOTE_USERROOT_FMT RSOP_NS_REMOTE_USER_FMT
  68. #define RSOP_NS_DIAG_REMOTE_USER_FMT L"\\\\%s\\Root\\Rsop\\User\\%s"
  69. // machine
  70. #define RSOP_NS_REMOTE_MACHINE_FMT L"\\\\%s\\Root\\Rsop\\Computer"
  71. #define RSOP_NS_SM_REMOTE_MACHINE_FMT RSOP_NS_REMOTE_MACHINE_FMT
  72. #define RSOP_NS_PM_REMOTE_MACHINE_FMT RSOP_NS_REMOTE_MACHINE_FMT
  73. // check to make sure that the namespace is under root\rsop
  74. #define RSOP_NS_ROOT_CHK L"root\\rsop\\"
  75. #define RSOP_ALL_PERMS (WBEM_ENABLE | WBEM_METHOD_EXECUTE | WBEM_FULL_WRITE_REP | WBEM_PARTIAL_WRITE_REP | \
  76. WBEM_WRITE_PROVIDER | WBEM_REMOTE_ACCESS | READ_CONTROL | WRITE_DAC)
  77. #define RSOP_READ_PERMS (WBEM_ENABLE | WBEM_METHOD_EXECUTE | WBEM_REMOTE_ACCESS | READ_CONTROL )
  78. // WMI bits passed as generic mask into AccessCheck
  79. #define WMI_GENERIC_READ 1
  80. #define WMI_GENERIC_WRITE 0x1C
  81. #define WMI_GENERIC_EXECUTE 0x2
  82. #define WMI_GENERIC_ALL 0x6001f
  83. #ifdef __cplusplus
  84. extern "C" {
  85. #endif
  86. #define DEFAULT_NAMESPACE_TTL_MINUTES 1440
  87. HRESULT
  88. CopyNameSpace( LPCWSTR wszSrc,
  89. LPCWSTR wszDest,
  90. BOOL bCopyInstances,
  91. BOOL* pbAbort,
  92. IWbemLocator* pWbemLocator );
  93. /*
  94. HRESULT
  95. SetupNewNameSpacePlanningMode( LPWSTR *pwszNameSpace,
  96. LPWSTR szRemoteComputer,
  97. IWbemLocator *pWbemLocator,
  98. PSECURITY_DESCRIPTOR pSDUser,
  99. PSECURITY_DESCRIPTOR pSDMach );
  100. HRESULT
  101. SetupNewNameSpaceDiagMode( LPWSTR *pwszNameSpace,
  102. LPWSTR szRemoteComputer,
  103. LPWSTR szUserSid,
  104. IWbemLocator *pWbemLocator);
  105. */
  106. // SetupNewNameSpace flags
  107. #define SETUP_NS_PM 0x1
  108. #define SETUP_NS_SM 0x2
  109. #define SETUP_NS_SM_NO_USER 0x4
  110. #define SETUP_NS_SM_NO_COMPUTER 0x8
  111. #define SETUP_NS_SM_INTERACTIVE 0x10
  112. HRESULT
  113. SetNameSpaceSecurity( LPCWSTR szNamespace,
  114. PSECURITY_DESCRIPTOR pSD,
  115. IWbemLocator* pWbemLocator);
  116. HRESULT
  117. GetNameSpaceSecurity( LPCWSTR szNamespace,
  118. PSECURITY_DESCRIPTOR *ppSD,
  119. IWbemLocator* pWbemLocator);
  120. HRESULT
  121. SetupNewNameSpace(
  122. LPWSTR *pwszNameSpace,
  123. LPWSTR szRemoteComputer,
  124. LPWSTR szUserSid,
  125. PSID pSid,
  126. IWbemLocator *pWbemLocator,
  127. DWORD dwFlags,
  128. DWORD *pdwExtendedInfo);
  129. HRESULT
  130. ProviderDeleteRsopNameSpace( IWbemLocator *pWbemLocator,
  131. LPWSTR szNameSpace,
  132. HANDLE hToken,
  133. LPWSTR szSidString,
  134. DWORD dwFlags);
  135. BOOL IsInteractiveNameSpace(WCHAR *pwszNameSpace, WCHAR *szSid);
  136. HRESULT GetInteractiveNameSpace(WCHAR *szSid, LPWSTR *szNameSpace);
  137. // copy flags
  138. #define NEW_NS_FLAGS_COPY_CLASSES 1 // Copy Instances
  139. #define NEW_NS_FLAGS_COPY_SD 2 // Copy Security Descriptor
  140. #define NEW_NS_FLAGS_COPY_INSTS 4 // Copy Classes
  141. HRESULT
  142. CreateAndCopyNameSpace( IWbemLocator *pWbemLocator,
  143. LPWSTR szSrcNameSpace,
  144. LPWSTR szDstRootNameSpace,
  145. LPWSTR szDstRelNameSpace,
  146. DWORD dwFlags,
  147. PSECURITY_DESCRIPTOR pSecDesc,
  148. LPWSTR *szDstNameSpaceOut);
  149. // WMI doesn't like '-' in names. so to create an entry in WMI space
  150. // using Sid use these 2 utility functions.
  151. void ConvertSidToWMIName(LPTSTR lpSid, LPTSTR lpWmiName);
  152. void ConvertWMINameToSid(LPTSTR lpWmiName, LPTSTR lpSid);
  153. HRESULT
  154. DeleteNameSpace( WCHAR *pwszNameSpace, WCHAR *pwszParentNameSpace, IWbemLocator *pWbemLocator );
  155. HRESULT
  156. DeleteRsopNameSpace( WCHAR *pwszNameSpace, IWbemLocator *pWbemLocator );
  157. HRESULT
  158. GetWbemServicesPtr( LPCWSTR wszNameSpace,
  159. IWbemLocator** ppLocator,
  160. IWbemServices** ppServices );
  161. /*
  162. typedef struct __tagPrincipal
  163. {
  164. LPWSTR szName; // e.g. Administrators, "Domain Admins"
  165. bool bLocal; // e.g. true, false
  166. } Principal;
  167. */
  168. #ifdef __cplusplus
  169. } // extern "C" {
  170. #endif
  171. #ifdef __cplusplus
  172. /*
  173. class CPrincipals
  174. {
  175. private:
  176. Principal* m_pPrincipals;
  177. DWORD m_nPrincipals;
  178. bool m_bNormalized;
  179. public:
  180. CPrincipals( Principal* pPrin, DWORD dwPrin = 0 ) : m_pPrincipals(pPrin), m_nPrincipals(dwPrin)
  181. {
  182. };
  183. ~CPrincipals()
  184. {
  185. if ( m_bNormalized )
  186. {
  187. for ( DWORD i = 0 ; i < m_nPrincipals ; i++ )
  188. {
  189. if ( !m_pPrincipals[i].bLocal && m_pPrincipals[i].szName )
  190. {
  191. LocalFree( m_pPrincipals[i].szName );
  192. }
  193. }
  194. }
  195. };
  196. HRESULT NormalizePrincipals( LPWSTR szDomainName )
  197. {
  198. HRESULT hr = S_OK;
  199. for ( DWORD i = 0 ; i < m_nPrincipals ; i++ )
  200. {
  201. if ( !m_pPrincipals[i].bLocal )
  202. {
  203. LPWSTR sz = ( LPWSTR )LocalAlloc( LPTR, sizeof( WCHAR ) * ( wcslen(szDomainName) + wcslen(m_pPrincipals[i].szName) + 2 ) );
  204. if ( sz )
  205. {
  206. wcscpy( sz, szDomainName );
  207. wcscat( sz, L"\\" );
  208. wcscat( sz, m_pPrincipals[i].szName );
  209. }
  210. else
  211. {
  212. hr = GetLastError();
  213. }
  214. m_pPrincipals[i].szName = sz;
  215. }
  216. }
  217. m_bNormalized = true;
  218. return hr;
  219. };
  220. void GetPrincipals( DWORD nCount, LPWSTR* pszNames )
  221. {
  222. for ( DWORD i = 0 ; i < m_nPrincipals && i < nCount ; i ++ )
  223. {
  224. pszNames[i] = m_pPrincipals[i].szName;
  225. }
  226. };
  227. };
  228. */
  229. class CFailRetStatus
  230. {
  231. private:
  232. IWbemObjectSink* m_pResponseHandler; // We don't own m_pResponseHandler
  233. HRESULT m_hr;
  234. public:
  235. CFailRetStatus( IWbemObjectSink* pResponseHandler )
  236. : m_pResponseHandler(pResponseHandler),
  237. m_hr( 0 )
  238. {
  239. }
  240. ~CFailRetStatus()
  241. {
  242. if ( m_pResponseHandler )
  243. m_pResponseHandler->SetStatus( WBEM_STATUS_COMPLETE, m_hr, NULL, NULL );
  244. }
  245. void SetError( HRESULT hr )
  246. {
  247. m_hr = hr;
  248. }
  249. };
  250. #ifndef MAX
  251. #define MAX(a,b) (((a)>(b))?(a):(b))
  252. #endif
  253. #ifndef MIN
  254. #define MIN(a,b) (((a)<(b))?(a):(b))
  255. #endif
  256. #endif
  257. #endif // __RSOPINC_H__