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.

904 lines
24 KiB

  1. /*
  2. **++
  3. **
  4. ** Copyright (c) 2000-2002 Microsoft Corporation
  5. **
  6. **
  7. ** Module Name:
  8. **
  9. ** sec.cpp
  10. **
  11. **
  12. ** Abstract:
  13. **
  14. ** Security Test program for VSS
  15. **
  16. ** Author:
  17. **
  18. ** Adi Oltean [aoltean] 02/12/2002
  19. **
  20. **
  21. ** Revision History:
  22. **
  23. **--
  24. */
  25. ///////////////////////////////////////////////////////////////////////////////
  26. // Includes
  27. #include "sec.h"
  28. #include <clusapi.h>
  29. #include <msclus.h>
  30. #include <mstask.h>
  31. #include <ntddsnap.h>
  32. #include "vswriter.h"
  33. #include "vsbackup.h"
  34. #include "vs_reg.hxx"
  35. #include "ntddsnap.h"
  36. #include "vs_clus.hxx"
  37. ///////////////////////////////////////////////////////////////////////////////
  38. // Static data
  39. CRITICAL_SECTION CVssSecurityTest::m_csTest;
  40. volatile LONG CVssSecurityTest::m_lTestCounter = 0;
  41. ///////////////////////////////////////////////////////////////////////////////
  42. // Processing functions
  43. // Run the tests
  44. void CVssSecurityTest::Run()
  45. {
  46. CVssFunctionTracer ft(VSSDBG_VSSTEST, L"CVssSecurityTest::Run");
  47. ft.Msg(L"\n--------------- %s ------------\n", GetCurrentComment());
  48. // Execute selected routine
  49. BS_ASSERT(GetCurrentRoutine());
  50. (this->*GetCurrentRoutine())();
  51. ft.Msg(L"\n-------------------------------------------------\n");
  52. }
  53. // Lookup name
  54. void CVssSecurityTest::TestLookupName()
  55. {
  56. CVssFunctionTracer ft(VSSDBG_VSSTEST, L"CVssSecurityTest::TestLookupName");
  57. BYTE pbSid[SECURITY_MAX_SID_SIZE];
  58. PSID pSid = (PSID)pbSid;
  59. WCHAR wszDomainName[MAX_TEXT_BUFFER];
  60. SID_NAME_USE snUse;
  61. DWORD cbSid = 0;
  62. DWORD dwDomainNameSize = 0;
  63. LookupAccountName( NULL, GetStringParam(L"<name>"),
  64. pSid, &cbSid,
  65. wszDomainName, &dwDomainNameSize,
  66. &snUse);
  67. ft.Msg( L"* cbSid = %ld, cbDomain = %ld, error = %ld\n", cbSid, dwDomainNameSize, GetLastError() );
  68. cbSid = SECURITY_MAX_SID_SIZE;
  69. dwDomainNameSize = MAX_TEXT_BUFFER;
  70. CHECK_WIN32( LookupAccountName( NULL, GetStringParam(L"<name>"),
  71. pSid, &cbSid,
  72. wszDomainName, &dwDomainNameSize,
  73. &snUse),
  74. ;
  75. );
  76. LPWSTR pwszStringSid = NULL;
  77. CHECK_WIN32( ConvertSidToStringSid( pSid, &pwszStringSid), ;);
  78. ft.Msg( L"* Sid: %s, Domain Name: %s, SidUse: %d\n", pwszStringSid, wszDomainName, snUse );
  79. // Now go back and recompute the name
  80. WCHAR wszName[MAX_TEXT_BUFFER];
  81. DWORD dwNameSize = MAX_TEXT_BUFFER;
  82. dwDomainNameSize = MAX_TEXT_BUFFER;
  83. CHECK_WIN32( LookupAccountSid( NULL, pSid,
  84. wszName, &dwNameSize,
  85. wszDomainName, &dwDomainNameSize,
  86. &snUse),
  87. LocalFree(pwszStringSid);
  88. );
  89. ft.Msg( L"* Name: %s, Domain Name: %s, SidUse: %d\n", wszName, wszDomainName, snUse );
  90. LocalFree(pwszStringSid);
  91. }
  92. // Lookup SID
  93. void CVssSecurityTest::TestLookupSid()
  94. {
  95. CVssFunctionTracer ft(VSSDBG_VSSTEST, L"CVssSecurityTest::TestLookupSid");
  96. PSID pSid = NULL;
  97. CHECK_WIN32( ConvertStringSidToSid( GetStringParam(L"<sid>"), &pSid) , ;);
  98. WCHAR wszName[MAX_TEXT_BUFFER];
  99. DWORD dwNameSize = MAX_TEXT_BUFFER;
  100. WCHAR wszDomainName[MAX_TEXT_BUFFER];
  101. DWORD dwDomainNameSize = MAX_TEXT_BUFFER;
  102. SID_NAME_USE snUse;
  103. CHECK_WIN32( LookupAccountSid( NULL, pSid,
  104. wszName, &dwNameSize,
  105. wszDomainName, &dwDomainNameSize,
  106. &snUse),
  107. LocalFree(pSid);
  108. );
  109. ft.Msg( L"* Name: %s, Domain Name: %s, SidUse: %d\n", wszName, wszDomainName, snUse );
  110. LocalFree(pSid);
  111. }
  112. // Lookup Names
  113. void CVssSecurityTest::TestLookupPrimaryDomainName()
  114. {
  115. CVssFunctionTracer ft(VSSDBG_VSSTEST, L"CVssSecurityTest::TestLookupPrimaryDomainName");
  116. // Also get the computer domain
  117. WCHAR wszDomainName[MAX_TEXT_BUFFER];
  118. DWORD dwDomainNameLen = MAX_TEXT_BUFFER;
  119. CHECK_WIN32( GetComputerNameExW(
  120. ComputerNamePhysicalDnsDomain,
  121. // ComputerNameDnsDomain,
  122. wszDomainName,
  123. &dwDomainNameLen), ;);
  124. ft.Msg( L"* Domain DNS Name for the local computer: %s\n", wszDomainName );
  125. BYTE pbSid[SECURITY_MAX_SID_SIZE];
  126. DWORD dwSidSize = SECURITY_MAX_SID_SIZE;
  127. PSID pSid = (PSID)pbSid;
  128. WCHAR wszReturnedDomainName[MAX_TEXT_BUFFER];
  129. DWORD dwReturnedDomainNameSize = MAX_TEXT_BUFFER;
  130. SID_NAME_USE snUse;
  131. CHECK_WIN32( LookupAccountName( NULL,
  132. wszDomainName,
  133. pSid,
  134. &dwSidSize,
  135. wszReturnedDomainName,
  136. &dwReturnedDomainNameSize,
  137. &snUse),
  138. ;
  139. );
  140. ft.Msg( L"* LookupAccountName returns Domain Name: %s, SidInuse: %d\n",
  141. wszReturnedDomainName, snUse );
  142. LPWSTR pwszAccountName = NULL;
  143. CHECK_WIN32( ConvertSidToStringSid( pSid, &pwszAccountName) , ;);
  144. ft.Msg( L"* ConvertSidToSidString returns %s\n",
  145. pwszAccountName );
  146. LocalFree( pwszAccountName );
  147. BYTE pbByte2[SECURITY_MAX_SID_SIZE];
  148. PSID pSid2 = (PSID)pbByte2;
  149. DWORD dwSid2Length = SECURITY_MAX_SID_SIZE;
  150. CHECK_WIN32( CreateWellKnownSid( WinAccountComputersSid,
  151. pSid,
  152. pSid2,
  153. &dwSid2Length
  154. ),
  155. ;
  156. );
  157. LPWSTR pwszAccountName2 = NULL;
  158. CHECK_WIN32( ConvertSidToStringSid( pSid2, &pwszAccountName2) , ;);
  159. ft.Msg( L"* ConvertSidToSidString returns %s\n",
  160. pwszAccountName2 );
  161. LocalFree( pwszAccountName2 );
  162. }
  163. // Lookup Names for all trusted domains
  164. void CVssSecurityTest::TestLookupTrustedName()
  165. {
  166. CVssFunctionTracer ft(VSSDBG_VSSTEST, L"CVssSecurityTest::TestLookupTrustedName");
  167. PDOMAIN_CONTROLLER_INFO pDomainInfo = NULL;
  168. CHECK_WIN32(
  169. DsGetDcName( NULL,
  170. NULL,
  171. NULL,
  172. NULL,
  173. 0,
  174. &pDomainInfo),
  175. ;
  176. );
  177. PDS_DOMAIN_TRUSTS pDomains = NULL;
  178. ULONG ulDomainCount = 0;
  179. CHECK_WIN32(
  180. DsEnumerateDomainTrusts( pDomainInfo->DomainControllerName,
  181. DS_DOMAIN_IN_FOREST,
  182. &pDomains,
  183. &ulDomainCount),
  184. NetApiBufferFree(pDomainInfo);
  185. );
  186. NetApiBufferFree(pDomainInfo);
  187. for (ULONG ulIndex = 0; ulIndex < ulDomainCount; ulIndex++)
  188. {
  189. ft.Msg( L"* Domain: %s, ", pDomains[ulIndex].DnsDomainName );
  190. LPWSTR pwszSidName = NULL;
  191. CHECK_WIN32( ConvertSidToStringSid( pDomains[ulIndex].DomainSid,
  192. &pwszSidName),
  193. NetApiBufferFree(pDomains);
  194. );
  195. ft.Msg( L"SID: %s, ", pwszSidName );
  196. LocalFree( pwszSidName );
  197. BYTE pbByte2[SECURITY_MAX_SID_SIZE];
  198. PSID pSid2 = (PSID)pbByte2;
  199. DWORD dwSid2Length = SECURITY_MAX_SID_SIZE;
  200. CHECK_WIN32( CreateWellKnownSid( WinAccountComputersSid,
  201. pDomains[ulIndex].DomainSid,
  202. pSid2,
  203. &dwSid2Length
  204. ),
  205. NetApiBufferFree(pDomains);
  206. );
  207. CHECK_WIN32( ConvertSidToStringSid( pSid2, &pwszSidName),
  208. NetApiBufferFree(pDomains);
  209. );
  210. ft.Msg( L"DM SID: %s\n", pwszSidName );
  211. LocalFree( pwszSidName );
  212. }
  213. NetApiBufferFree(pDomains);
  214. }
  215. // Lookup Names for all trusted domains
  216. void CVssSecurityTest::TestLookupGroupMembers()
  217. {
  218. CVssFunctionTracer ft(VSSDBG_VSSTEST, L"CVssSecurityTest::TestLookupGroupMembers");
  219. // get list of local group members
  220. CVssAutoNetApiPtr apBuffer;
  221. DWORD_PTR ResumeHandle = NULL;
  222. DWORD cEntriesRead = 0, cEntriesTotal = 0;
  223. NET_API_STATUS status = 0;
  224. CHECK_WIN32_FUNC(status, status == NERR_Success,
  225. NetLocalGroupGetMembers(
  226. NULL,
  227. GetStringParam(L"<group>"),
  228. 1,
  229. apBuffer.ResetAndGetAddress(),
  230. MAX_PREFERRED_LENGTH,
  231. &cEntriesRead,
  232. &cEntriesTotal,
  233. &ResumeHandle
  234. ),
  235. ;
  236. );
  237. // loop through member list to see if any sids mach the sid of the owner
  238. // of the subscription
  239. LOCALGROUP_MEMBERS_INFO_1 *rgMembers = (LOCALGROUP_MEMBERS_INFO_1 *) apBuffer.Get();
  240. for(DWORD iEntry = 0; iEntry < cEntriesRead; iEntry++)
  241. {
  242. CVssAutoLocalPtr<LPWSTR> pwszStringSid;
  243. CHECK_WIN32( ConvertSidToStringSid(
  244. rgMembers[iEntry].lgrmi1_sid, pwszStringSid.ResetAndGetAddress()), ;);
  245. ft.Msg(L"* Name = %s, Use = %ld, Sid = %s\n",
  246. rgMembers[iEntry].lgrmi1_name,
  247. (LONG)rgMembers[iEntry].lgrmi1_sidusage,
  248. pwszStringSid.Get()
  249. );
  250. }
  251. }
  252. // Lookup Names for all trusted domains
  253. void CVssSecurityTest::IsAllowedToFire()
  254. {
  255. CVssFunctionTracer ft(VSSDBG_VSSTEST, L"CVssSecurityTest::IsAllowedToFire");
  256. try
  257. {
  258. CVssSidCollection sidColl;
  259. sidColl.Initialize();
  260. BYTE pbSid[SECURITY_MAX_SID_SIZE];
  261. PSID pSid = (PSID)pbSid;
  262. WCHAR wszDomainName[MAX_TEXT_BUFFER];
  263. SID_NAME_USE snUse;
  264. DWORD cbSid = 0;
  265. DWORD dwDomainNameSize = 0;
  266. LookupAccountName( NULL, GetStringParam(L"<name>"),
  267. pSid, &cbSid,
  268. wszDomainName, &dwDomainNameSize,
  269. &snUse);
  270. ft.Msg( L"* cbSid = %ld, cbDomain = %ld, error = %ld\n", cbSid, dwDomainNameSize, GetLastError() );
  271. cbSid = SECURITY_MAX_SID_SIZE;
  272. dwDomainNameSize = MAX_TEXT_BUFFER;
  273. CHECK_WIN32( LookupAccountName( NULL, GetStringParam(L"<name>"),
  274. pSid, &cbSid,
  275. wszDomainName, &dwDomainNameSize,
  276. &snUse),
  277. ;
  278. );
  279. CVssAutoLocalPtr<LPWSTR> pwszStringSid;
  280. CHECK_WIN32( ConvertSidToStringSid( pSid, pwszStringSid.ResetAndGetAddress()), ;);
  281. ft.Msg( L"* Sid: %s, Domain Name: %s, SidUse: %d\n", pwszStringSid.Get(), wszDomainName, snUse );
  282. bool bAllowed = sidColl.IsSidAllowedToFire(pSid);
  283. ft.Msg( L"* IsAllowed: %s\n", bAllowed? L"TRUE": L"FALSE" );
  284. }
  285. VSS_STANDARD_CATCH(ft)
  286. if (ft.HrFailed())
  287. ft.Msg(L"Error catched 0x%08lx\n", ft.hr);
  288. }
  289. // Lookup Names for all trusted domains
  290. void CVssSecurityTest::WriteRegistry()
  291. {
  292. CVssFunctionTracer ft(VSSDBG_VSSTEST, L"CVssSecurityTest::WriteRegistry");
  293. #if 0
  294. try
  295. {
  296. CVssDiag test;
  297. test.Initialize(L"TEST");
  298. INT nCount = GetIntParam(L"<max_iterations>");
  299. GUID guidSnapshotSetID = GUID_NULL;
  300. for(INT nIterations = 0; nIterations < nCount; nIterations++)
  301. {
  302. for(INT nIndex = VSS_IN_IDENTIFY; nIndex < VSS_IN_COUNT; nIndex++)
  303. {
  304. test.RecordWriterEvent((VSS_OPERATION)nIndex, 0, 0, S_OK, guidSnapshotSetID);
  305. }
  306. }
  307. }
  308. VSS_STANDARD_CATCH(ft)
  309. if (ft.HrFailed())
  310. ft.Msg(L"Error catched 0x%08lx\n", ft.hr);
  311. #endif
  312. }
  313. void CVssSecurityTest::DoQuerySnapshots()
  314. {
  315. CVssFunctionTracer ft(VSSDBG_VSSTEST, L"CVssSecurityTest::DoQuerySnapshots");
  316. try
  317. {
  318. QuerySnapshots();
  319. }
  320. VSS_STANDARD_CATCH(ft)
  321. if (ft.HrFailed())
  322. ft.Msg(L"Error catched 0x%08lx\n", ft.hr);
  323. }
  324. void CVssSecurityTest::DoQueryProviders()
  325. {
  326. CVssFunctionTracer ft(VSSDBG_VSSTEST, L"CVssSecurityTest::DoQueryProviders");
  327. try
  328. {
  329. QueryProviders();
  330. }
  331. VSS_STANDARD_CATCH(ft)
  332. if (ft.HrFailed())
  333. ft.Msg(L"Error catched 0x%08lx\n", ft.hr);
  334. }
  335. #include "sample.cpp"
  336. void CVssSecurityTest::DoFsctlDismount()
  337. {
  338. CVssFunctionTracer ft(VSSDBG_VSSTEST, L"CVssSecurityTest::DoFsctlDismount");
  339. try
  340. {
  341. // Open the snapshot with no access rights for perf reasons (bug #537974)
  342. LPWSTR pwszDevice = GetStringParam(L"<device>");
  343. HANDLE hDevice;
  344. CHECK_WIN32_FUNC(
  345. hDevice,
  346. hDevice != INVALID_HANDLE_VALUE,
  347. CreateFile(pwszDevice,
  348. GENERIC_READ | GENERIC_WRITE,
  349. FILE_SHARE_READ | FILE_SHARE_WRITE,
  350. NULL,
  351. OPEN_EXISTING,
  352. FILE_ATTRIBUTE_NORMAL,
  353. INVALID_HANDLE_VALUE),
  354. ;
  355. );
  356. CHECK_WIN32(
  357. DeviceIoControl(hDevice, FSCTL_DISMOUNT_VOLUME, NULL, 0, NULL, 0, NULL, NULL),
  358. CloseHandle(hDevice);
  359. );
  360. CloseHandle(hDevice);
  361. }
  362. VSS_STANDARD_CATCH(ft)
  363. if (ft.HrFailed())
  364. ft.Msg(L"Error catched 0x%08lx\n", ft.hr);
  365. }
  366. void CVssSecurityTest::DisplayMessage()
  367. {
  368. CVssFunctionTracer ft(VSSDBG_VSSTEST, L"CVssSecurityTest::DisplayMessage");
  369. try
  370. {
  371. DWORD dwMessageID = GetIntParam(L"<MessageID>");
  372. HMODULE hModule = NULL; // default to system source
  373. LPWSTR pwszMessageBuffer;
  374. DWORD dwBufferLength;
  375. DWORD dwFormatFlags = FORMAT_MESSAGE_ALLOCATE_BUFFER |
  376. FORMAT_MESSAGE_IGNORE_INSERTS |
  377. FORMAT_MESSAGE_FROM_SYSTEM ;
  378. // Load the file
  379. hModule = LoadLibraryExW(
  380. GetStringParam(L"<File>"),
  381. NULL,
  382. LOAD_LIBRARY_AS_DATAFILE
  383. );
  384. if(hModule != NULL)
  385. dwFormatFlags |= FORMAT_MESSAGE_FROM_HMODULE;
  386. dwBufferLength = FormatMessageW(
  387. dwFormatFlags,
  388. hModule, // module to get message from (NULL == system)
  389. dwMessageID,
  390. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // default language
  391. (LPWSTR) &pwszMessageBuffer,
  392. 0,
  393. NULL
  394. );
  395. if (dwBufferLength)
  396. {
  397. ft.Msg(L"Message: %s for ID\n", pwszMessageBuffer);
  398. //
  399. // Free the buffer allocated by the system.
  400. //
  401. LocalFree(pwszMessageBuffer);
  402. }
  403. //
  404. // If we loaded a message source, unload it.
  405. //
  406. if(hModule != NULL)
  407. FreeLibrary(hModule);
  408. }
  409. VSS_STANDARD_CATCH(ft)
  410. if (ft.HrFailed())
  411. ft.Msg(L"Error catched 0x%08lx\n", ft.hr);
  412. }
  413. // add cluster dependency
  414. void CVssSecurityTest::AddDependency()
  415. {
  416. CVssFunctionTracer ft(VSSDBG_VSSTEST, L"CVssSecurityTest::AddDependency");
  417. try
  418. {
  419. CVssClusterAPI clus;
  420. if (!clus.Initialize())
  421. {
  422. ft.Msg( L"Cluster initialization failed\n" );
  423. ft.Throw( VSSDBG_VSSTEST, S_FALSE, L"Cluster initialization failed\n" );
  424. }
  425. clus.AddDependency(GetStringParam(L"<name1>"), GetStringParam(L"<name2>"));
  426. ft.Msg( L"* Depoendency was sucesfully added!" );
  427. }
  428. VSS_STANDARD_CATCH(ft)
  429. if (ft.HrFailed())
  430. ft.Msg(L"Error catched 0x%08lx\n", ft.hr);
  431. }
  432. // remove cluster dependency
  433. void CVssSecurityTest::RemoveDependency()
  434. {
  435. CVssFunctionTracer ft(VSSDBG_VSSTEST, L"CVssSecurityTest::RemoveDependency");
  436. try
  437. {
  438. CVssClusterAPI clus;
  439. if (!clus.Initialize())
  440. {
  441. ft.Msg( L"Cluster initialization failed\n" );
  442. ft.Throw( VSSDBG_VSSTEST, S_FALSE, L"Cluster initialization failed\n" );
  443. }
  444. clus.RemoveDependency(GetStringParam(L"<name1>"), GetStringParam(L"<name2>"));
  445. ft.Msg( L"* Dependency was sucesfully removed!" );
  446. }
  447. VSS_STANDARD_CATCH(ft)
  448. if (ft.HrFailed())
  449. ft.Msg(L"Error catched 0x%08lx\n", ft.hr);
  450. }
  451. // add registry key
  452. void CVssSecurityTest::AddRegKey()
  453. {
  454. CVssFunctionTracer ft(VSSDBG_VSSTEST, L"CVssSecurityTest::AddRegKey");
  455. try
  456. {
  457. CVssClusterAPI clus;
  458. if (!clus.Initialize())
  459. {
  460. ft.Msg( L"Cluster initialization failed\n" );
  461. ft.Throw( VSSDBG_VSSTEST, S_FALSE, L"Cluster initialization failed\n" );
  462. }
  463. clus.AddRegistryKey(GetStringParam(L"<name>"), GetStringParam(L"<reg_key>"));
  464. ft.Msg( L"* Reg key was sucesfully added!" );
  465. }
  466. VSS_STANDARD_CATCH(ft)
  467. if (ft.HrFailed())
  468. ft.Msg(L"Error catched 0x%08lx\n", ft.hr);
  469. }
  470. // remove registry key
  471. void CVssSecurityTest::RemoveRegKey()
  472. {
  473. CVssFunctionTracer ft(VSSDBG_VSSTEST, L"CVssSecurityTest::RemoveRegKey");
  474. try
  475. {
  476. CVssClusterAPI clus;
  477. if (!clus.Initialize())
  478. {
  479. ft.Msg( L"Cluster initialization failed\n" );
  480. ft.Throw( VSSDBG_VSSTEST, S_FALSE, L"Cluster initialization failed\n" );
  481. }
  482. clus.RemoveRegistryKey(GetStringParam(L"<name>"), GetStringParam(L"<reg_key>"));
  483. ft.Msg( L"* Reg key was sucesfully removed!" );
  484. }
  485. VSS_STANDARD_CATCH(ft)
  486. if (ft.HrFailed())
  487. ft.Msg(L"Error catched 0x%08lx\n", ft.hr);
  488. }
  489. // add scheduled task
  490. void CVssSecurityTest::AddTask()
  491. {
  492. CVssFunctionTracer ft(VSSDBG_VSSTEST, L"CVssSecurityTest::AddTask");
  493. try
  494. {
  495. CVssClusterAPI clus;
  496. if (!clus.Initialize())
  497. {
  498. ft.Msg( L"Cluster initialization failed\n" );
  499. ft.Throw( VSSDBG_VSSTEST, S_FALSE, L"Cluster initialization failed\n" );
  500. }
  501. SYSTEMTIME st = {0};
  502. GetSystemTime(&st);
  503. WORD wStartHours = 7;
  504. TASK_TRIGGER Trigger;
  505. ZeroMemory(&Trigger, sizeof(TASK_TRIGGER));
  506. Trigger.wBeginDay =st.wDay;
  507. Trigger.wBeginMonth =st.wMonth;
  508. Trigger.wBeginYear =st.wYear;
  509. Trigger.cbTriggerSize = sizeof(TASK_TRIGGER);
  510. Trigger.wStartHour = wStartHours;
  511. Trigger.TriggerType = TASK_TIME_TRIGGER_WEEKLY;
  512. Trigger.Type.Weekly.WeeksInterval = 1;
  513. Trigger.Type.Weekly.rgfDaysOfTheWeek = TASK_MONDAY | TASK_TUESDAY | TASK_WEDNESDAY | TASK_THURSDAY | TASK_FRIDAY;
  514. ft.Msg( L"Adding a %d TASK_TRIGGER structure...", sizeof(TASK_TRIGGER));
  515. CVssAutoPWSZ awszResource;
  516. bool bRet = clus.CreateTaskSchedulerResource(
  517. GetStringParam(L"<task_name>"),
  518. GetStringParam(L"<app_name>"),
  519. GetStringParam(L"<app_params>"),
  520. 1,
  521. &Trigger,
  522. GetStringParam(L"<volume>")
  523. );
  524. ft.Msg( L"* Task was sucesfully created! [Return code:%s Resource:%s]",
  525. bRet? L"TRUE": L"FALSE",
  526. GetStringParam(L"<task_name>") );
  527. }
  528. VSS_STANDARD_CATCH(ft)
  529. if (ft.HrFailed())
  530. ft.Msg(L"Error catched 0x%08lx\n", ft.hr);
  531. }
  532. // Update scheduled task
  533. void CVssSecurityTest::UpdateTask()
  534. {
  535. CVssFunctionTracer ft(VSSDBG_VSSTEST, L"CVssSecurityTest::UpdateTask");
  536. try
  537. {
  538. CVssClusterAPI clus;
  539. if (!clus.Initialize())
  540. {
  541. ft.Msg( L"Cluster initialization failed\n" );
  542. ft.Throw( VSSDBG_VSSTEST, S_FALSE, L"Cluster initialization failed\n" );
  543. }
  544. SYSTEMTIME st = {0};
  545. GetSystemTime(&st);
  546. WORD wStartHours = 12;
  547. TASK_TRIGGER Trigger;
  548. ZeroMemory(&Trigger, sizeof(TASK_TRIGGER));
  549. Trigger.wBeginDay =st.wDay;
  550. Trigger.wBeginMonth =st.wMonth;
  551. Trigger.wBeginYear =st.wYear;
  552. Trigger.cbTriggerSize = sizeof(TASK_TRIGGER);
  553. Trigger.wStartHour = wStartHours;
  554. Trigger.TriggerType = TASK_TIME_TRIGGER_WEEKLY;
  555. Trigger.Type.Weekly.WeeksInterval = 1;
  556. Trigger.Type.Weekly.rgfDaysOfTheWeek = TASK_MONDAY | TASK_TUESDAY | TASK_WEDNESDAY | TASK_THURSDAY | TASK_FRIDAY;
  557. ft.Msg( L"Upgrading a %d TASK_TRIGGER structure...", sizeof(TASK_TRIGGER));
  558. bool bRet = clus.UpdateTaskSchedulerResource(
  559. GetStringParam(L"<resource_name>"),
  560. 1,
  561. &Trigger
  562. );
  563. ft.Msg( L"* Task was sucesfully updated! [Return code:%s]",
  564. bRet? L"TRUE": L"FALSE");
  565. }
  566. VSS_STANDARD_CATCH(ft)
  567. if (ft.HrFailed())
  568. ft.Msg(L"Error catched 0x%08lx\n", ft.hr);
  569. }
  570. // Update scheduled task
  571. void CVssSecurityTest::RemoveTask()
  572. {
  573. CVssFunctionTracer ft(VSSDBG_VSSTEST, L"CVssSecurityTest::RemoveTask");
  574. try
  575. {
  576. CVssClusterAPI clus;
  577. if (!clus.Initialize())
  578. {
  579. ft.Msg( L"Cluster initialization failed\n" );
  580. ft.Throw( VSSDBG_VSSTEST, S_FALSE, L"Cluster initialization failed\n" );
  581. }
  582. bool bRet = clus.DeleteTaskSchedulerResource(
  583. GetStringParam(L"<resource_name>")
  584. );
  585. ft.Msg( L"* Task was sucesfully deleted! [Return code:%s]",
  586. bRet? L"TRUE": L"FALSE");
  587. }
  588. VSS_STANDARD_CATCH(ft)
  589. if (ft.HrFailed())
  590. ft.Msg(L"Error catched 0x%08lx\n", ft.hr);
  591. }
  592. // Display a COM security descriptor
  593. void CVssSecurityTest::DisplaySD()
  594. {
  595. CVssFunctionTracer ft(VSSDBG_VSSTEST, L"CVssSecurityTest::DisplaySD");
  596. try
  597. {
  598. CVssSidCollection scoll;
  599. scoll.Initialize();
  600. PSECURITY_DESCRIPTOR pSD = scoll.GetSecurityDescriptor();
  601. CVssAutoLocalString szSD;
  602. CHECK_WIN32(ConvertSecurityDescriptorToStringSecurityDescriptor(
  603. pSD, SDDL_REVISION_1,
  604. OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION | SACL_SECURITY_INFORMATION,
  605. szSD.ResetAndGetAddress(), NULL), );
  606. ft.Msg( L" Security descriptor:\n%s\n", szSD.Get() );
  607. }
  608. VSS_STANDARD_CATCH(ft)
  609. if (ft.HrFailed())
  610. ft.Msg(L"Error catched 0x%08lx\n", ft.hr);
  611. }
  612. void CVssSecurityTest::GetVolumePath()
  613. {
  614. CVssFunctionTracer ft(VSSDBG_VSSTEST, L"CVssSecurityTest::DisplaySD");
  615. try
  616. {
  617. WCHAR wszVolume[MAX_PATH + 1];
  618. CHECK_WIN32(GetVolumePathNameW( GetStringParam(L"<path>"), STRING_CCH_PARAM(wszVolume)), )
  619. ft.Msg( L"Returned volume: %s\n", wszVolume);
  620. }
  621. VSS_STANDARD_CATCH(ft)
  622. if (ft.HrFailed())
  623. ft.Msg(L"Error catched 0x%08lx\n", ft.hr);
  624. }
  625. // Display quorum volume
  626. void CVssSecurityTest::DisplayQuorumVolume()
  627. {
  628. CVssFunctionTracer ft(VSSDBG_VSSTEST, L"CVssSecurityTest::DisplayQuorumVolume");
  629. try
  630. {
  631. INT nIterations = GetIntParam(L"<iterations>");
  632. for (INT nIndex = 0; nIndex < nIterations; nIndex++)
  633. {
  634. CVssClusterAPI clus;
  635. if (!clus.Initialize())
  636. {
  637. ft.Msg( L"Cluster initialization failed\n" );
  638. ft.Throw( VSSDBG_VSSTEST, S_FALSE, L"Cluster initialization failed\n" );
  639. }
  640. CComBSTR szVolumeName;
  641. clus.GetQuorumPath(szVolumeName);
  642. ft.Msg( L"* Quorum volume: %s",
  643. (LPWSTR)szVolumeName);
  644. }
  645. }
  646. VSS_STANDARD_CATCH(ft)
  647. if (ft.HrFailed())
  648. ft.Msg(L"Error catched 0x%08lx\n", ft.hr);
  649. }
  650. // Get a volume name
  651. void CVssSecurityTest::GetVolumeName()
  652. {
  653. CVssFunctionTracer ft(VSSDBG_VSSTEST, L"CVssSecurityTest::GetVolumeName");
  654. try
  655. {
  656. LPWSTR pwszVolume = GetStringParam(L"<volume>");
  657. WCHAR wszVolumeName[MAX_PATH];
  658. CHECK_WIN32(GetVolumeNameForVolumeMountPointW( pwszVolume, STRING_CCH_PARAM(wszVolumeName)), );
  659. ft.Msg(L"* Volume Name: %s\n", wszVolumeName);
  660. }
  661. VSS_STANDARD_CATCH(ft)
  662. if (ft.HrFailed())
  663. ft.Msg(L"Error catched 0x%08lx\n", ft.hr);
  664. }
  665. // Create a object with a given CLSID
  666. void CVssSecurityTest::CoCreateInstance()
  667. {
  668. CVssFunctionTracer ft(VSSDBG_VSSTEST, L"CVssSecurityTest::CoCreateInstance");
  669. try
  670. {
  671. LPWSTR pwszGuid = GetStringParam(L"<clsid>");
  672. CVssID clsid;
  673. clsid.Initialize(ft, pwszGuid);
  674. CComPtr<IUnknown> ptrUnk;
  675. CHECK_COM(::CoGetClassObject(clsid, CLSCTX_ALL, NULL, IID_IClassFactory, (void**)&ptrUnk), );
  676. ft.Msg(L"* Instance created.\n");
  677. }
  678. VSS_STANDARD_CATCH(ft)
  679. if (ft.HrFailed())
  680. ft.Msg(L"Error catched 0x%08lx\n", ft.hr);
  681. }