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.

266 lines
6.5 KiB

  1. /*
  2. **++
  3. **
  4. ** Copyright (c) 2000-2002 Microsoft Corporation
  5. **
  6. **
  7. ** Module Name:
  8. **
  9. ** sec.h
  10. **
  11. **
  12. ** Abstract:
  13. **
  14. ** Test program for VSS security
  15. **
  16. ** Author:
  17. **
  18. ** Adi Oltean [aoltean] 02/12/2002
  19. **
  20. ** Revision History:
  21. **
  22. **--
  23. */
  24. #ifndef __VSS_SEC_HEADER_H__
  25. #define __VSS_SEC_HEADER_H__
  26. #if _MSC_VER > 1000
  27. #pragma once
  28. #endif
  29. /*
  30. ** Defines
  31. **
  32. **
  33. ** C4290: C++ Exception Specification ignored
  34. ** warning C4511: 'class' : copy constructor could not be generated
  35. ** warning C4127: conditional expression is constant
  36. */
  37. #pragma warning(disable:4290)
  38. #pragma warning(disable:4511)
  39. #pragma warning(disable:4127)
  40. /*
  41. ** Includes
  42. */
  43. // Disable warning: 'identifier' : identifier was truncated to 'number' characters in the debug information
  44. //#pragma warning(disable:4786)
  45. //
  46. // C4290: C++ Exception Specification ignored
  47. //
  48. #pragma warning(disable:4290)
  49. //
  50. // C4511: copy constructor could not be generated
  51. //
  52. #pragma warning(disable:4511)
  53. #include <nt.h>
  54. #include <ntrtl.h>
  55. #include <nturtl.h>
  56. #include <ntioapi.h>
  57. #include <windows.h>
  58. #include <wtypes.h>
  59. #pragma warning( disable: 4201 ) // C4201: nonstandard extension used : nameless struct/union
  60. #include <winioctl.h>
  61. #pragma warning( default: 4201 ) // C4201: nonstandard extension used : nameless struct/union
  62. #include <winbase.h>
  63. #include <wchar.h>
  64. #include <string.h>
  65. #include <iostream.h>
  66. #include <fstream.h>
  67. #include <stdio.h>
  68. #include <process.h>
  69. #include <stddef.h>
  70. #include <stdlib.h>
  71. #include <errno.h>
  72. #include <time.h>
  73. #include <string.h>
  74. #include <sddl.h>
  75. #include <lm.h>
  76. #include <dsgetdc.h>
  77. #include <mstask.h>
  78. // Enabling asserts in ATL and VSS
  79. #include "vs_assert.hxx"
  80. #define STRSAFE_NO_DEPRECATE
  81. #include <strsafe.h>
  82. #include <oleauto.h>
  83. #include <stddef.h>
  84. #pragma warning( disable: 4127 ) // warning C4127: conditional expression is constant
  85. //#include <atlconv.h>
  86. #include <atlbase.h>
  87. #include "resource.h"
  88. extern CComModule _Module;
  89. #include <atlcom.h>
  90. #include "macros.h"
  91. #include "test.h"
  92. #include "cmdparse.h"
  93. #include "vs_inc.hxx"
  94. #include "vs_sec.hxx"
  95. ///////////////////////////////////////////////////////////////////////////////
  96. // Constants
  97. const MAX_TEXT_BUFFER = 512;
  98. const VSS_SEED = 1234;
  99. const MAX_ARGS = 40;
  100. ///////////////////////////////////////////////////////////////////////////////
  101. // Main class
  102. class CVssSecurityTest: public CGxnCmdLineParser<CVssSecurityTest>
  103. {
  104. // Constructors& destructors
  105. private:
  106. CVssSecurityTest(const CVssSecurityTest&);
  107. public:
  108. CVssSecurityTest();
  109. ~CVssSecurityTest();
  110. // Main routines
  111. public:
  112. // Initialize internal members
  113. void Initialize();
  114. // Run the test
  115. void Run();
  116. // Internal tests
  117. public:
  118. void TestLookupName();
  119. void TestLookupSid();
  120. void TestLookupPrimaryDomainName();
  121. void TestLookupTrustedName();
  122. void TestLookupGroupMembers();
  123. void IsAllowedToFire();
  124. void WriteRegistry();
  125. void DoQuerySnapshots();
  126. void DoQueryProviders();
  127. void DoFsctlDismount();
  128. void DisplayMessage();
  129. void AddDependency();
  130. void RemoveDependency();
  131. void AddRegKey();
  132. void RemoveRegKey();
  133. void AddTask();
  134. void UpdateTask();
  135. void RemoveTask();
  136. void DisplaySD();
  137. void GetVolumePath();
  138. void DisplayQuorumVolume();
  139. void GetVolumeName();
  140. void CoCreateInstance();
  141. // Command line processing
  142. public:
  143. BEGIN_CMD_PARSER(VSST)
  144. CMD_ENTRY(TestLookupName, L"-ln <name>", L"Lookup for an account name")
  145. CMD_ENTRY(TestLookupSid, L"-ls <sid>", L"Lookup for SID")
  146. CMD_ENTRY(TestLookupPrimaryDomainName, L"-lpdn", L"Lookup for primary domain name")
  147. CMD_ENTRY(TestLookupTrustedName, L"-lt", L"Lookup for trusted names")
  148. CMD_ENTRY(TestLookupGroupMembers, L"-gm <group>", L"Lookup for group members")
  149. CMD_ENTRY(IsAllowedToFire, L"-af <name>", L"Check if hte account is allowed to fire")
  150. CMD_ENTRY(WriteRegistry, L"-wr <max_iterations>", L"Write diag keys <max_iterations> times")
  151. CMD_ENTRY(DoQuerySnapshots, L"-qs", L"Query snapshots sample code")
  152. CMD_ENTRY(DoQueryProviders, L"-qp", L"Query providers sample code")
  153. CMD_ENTRY(DoFsctlDismount, L"-dismount <device>", L"Sends a FSCTL_DISMOUNT_VOLUME to the device")
  154. CMD_ENTRY(DisplayMessage, L"-msg <MessageID> <File>", L"Prints the message from this file")
  155. CMD_ENTRY(AddDependency, L"-cad <name1> <name2>", L"Add a cluster dependency")
  156. CMD_ENTRY(RemoveDependency, L"-crd <name1> <name2>", L"Remove a cluster dependency")
  157. CMD_ENTRY(AddRegKey, L"-car <name> <reg_key>", L"Add a reg key to a disk")
  158. CMD_ENTRY(RemoveRegKey, L"-crr <name> <reg_key>", L"Remove a reg key from a disk")
  159. CMD_ENTRY(AddTask, L"-cat <task_name> <app_name> <app_params> <volume>", L"Add a task")
  160. CMD_ENTRY(UpdateTask, L"-cut <resource_name>", L"Update the task")
  161. CMD_ENTRY(RemoveTask, L"-crt <resource_name>", L"Remove the task")
  162. CMD_ENTRY(DisplaySD, L"-dsd", L"Display the current writer security descriptor")
  163. CMD_ENTRY(GetVolumePath, L"-vol <path>", L"Display the volume that contains the path")
  164. CMD_ENTRY(DisplayQuorumVolume, L"-quorum <iterations>", L"Display the quorum volume N times")
  165. CMD_ENTRY(GetVolumeName, L"-volname <volume>", L"Display the volume name for this mount point")
  166. CMD_ENTRY(CoCreateInstance, L"-clsid <clsid>", L"Creates an object using the given CLSID")
  167. END_CMD_PARSER
  168. // Utility methods:
  169. public:
  170. static LPCWSTR GetStringFromFailureType(HRESULT hrStatus);
  171. static BOOL IsAdmin();
  172. static DWORD WINAPI ThreadRoutine(LPVOID);
  173. // Private data members
  174. private:
  175. bool m_bCoInitializeSucceeded;
  176. static CRITICAL_SECTION m_csTest;
  177. static volatile LONG m_lTestCounter;
  178. };
  179. HRESULT QuerySnapshots();
  180. HRESULT QueryProviders();
  181. HRESULT IsAdministrator2();
  182. /*
  183. // Sample COM server
  184. class CTestCOMServer:
  185. public CComObjectRoot,
  186. // public CComCoClass<CTestCOMServer, &CLSID_CRssSecTest>,
  187. public CComCoClass<CTestCOMServer, &CLSID_CFsaRecallNotifyClient>,
  188. public IFsaRecallNotifyClient
  189. {
  190. public:
  191. DECLARE_REGISTRY_RESOURCEID(IDR_TEST)
  192. DECLARE_NOT_AGGREGATABLE(CTestCOMServer)
  193. BEGIN_COM_MAP(CTestCOMServer)
  194. COM_INTERFACE_ENTRY(IRssSecTest)
  195. COM_INTERFACE_ENTRY(IFsaRecallNotifyClient)
  196. END_COM_MAP()
  197. // ITest interface
  198. STDMETHOD(Test)();
  199. // IFsaRecallNotifyClient interface
  200. STDMETHOD(IdentifyWithServer)( IN OLECHAR * szServerName );
  201. protected:
  202. CGxnTracer ft;
  203. };
  204. */
  205. #endif // __VSS_SEC_HEADER_H__