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.

2423 lines
80 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996.
  5. //
  6. //--------------------------------------------------------------------------
  7. #include <pch.cxx>
  8. #pragma hdrstop
  9. #include <ole2.h>
  10. #define TRKDATA_ALLOCATE
  11. #include "trkwks.hxx"
  12. #include "trksvr.hxx"
  13. #include "dltadmin.hxx"
  14. OLECHAR *
  15. tcstoocs(OLECHAR *poszBuf, const TCHAR *ptsz)
  16. {
  17. #ifdef OLE2ANSI
  18. return tcstombs( poszBuf, ptsz );
  19. #else
  20. return tcstowcs( poszBuf, ptsz );
  21. #endif
  22. }
  23. TCHAR *
  24. ocstotcs(TCHAR *ptszBuf, const OLECHAR *posz)
  25. {
  26. #ifdef OLE2ANSI
  27. return mbstotcs( ptszBuf, posz );
  28. #else
  29. return wcstotcs( ptszBuf, posz );
  30. #endif
  31. }
  32. void Usage()
  33. {
  34. printf( "\nDistributed Link Tracking service admin tools\n"
  35. "\n"
  36. "Usage: dltadmin [command command-parameters]\n"
  37. "For help: dltadmin [command] -?\n"
  38. "Commands: -VolInfoFile (get volume info from a file path)\n"
  39. " -VolStat (volume statistics)\n"
  40. " -FileOid (set/get/use file Object IDs)\n"
  41. " -EnumOids (enumerate object IDs)\n"
  42. " -OidSnap (save/restore all OIDs)\n"
  43. " -Link (create/resolve shell link)\n"
  44. " -VolId (get/set volume IDs)\n"
  45. " -CleanVol (clean Object/Volume IDs)\n"
  46. " -LockVol (lock/dismount a volume)\n"
  47. " -SvrStat (trkSvr statistics)\n"
  48. " -LoadLib (load a dll into a process)\n"
  49. " -FreeLib (unload a dll from a process)\n"
  50. " -Config (configure the registry and/or runing service)\n"
  51. " -Refresh (refresh the trkwks volume list)\n"
  52. " -DebugBreak (break into a process)\n"
  53. " -LookupVolId (look up entry in DC volume table)\n"
  54. " -LookupDroid (look up entry in DC move table)\n"
  55. " -DelDcMoveId (del move table entry from DC)\n"
  56. " -DelDcVolId (del volume table entry from DC)\n"
  57. " -SetVolSeq (set volid sequence number)\n"
  58. " -SetDroidSeq (set move entry sequence number)\n" );
  59. }
  60. // Dummy function to make it link
  61. void
  62. ServiceStopCallback( PVOID pContext, BOOLEAN fTimeout )
  63. {
  64. return;
  65. }
  66. VOID
  67. TSZ2CLSID( const LPTSTR tszCLSID, CLSID *pclsid )
  68. {
  69. HRESULT hr = S_OK;
  70. OLECHAR oszCLSID[ CCH_GUID_STRING + 1 ];
  71. tcstoocs( oszCLSID, tszCLSID );
  72. hr = CLSIDFromString( oszCLSID, pclsid );
  73. if( FAILED(hr) )
  74. {
  75. TrkLog((TRKDBG_ERROR, TEXT("Couldn't convert string to CLSID") ));
  76. TrkRaiseException( hr );
  77. }
  78. }
  79. BOOL
  80. DltAdminLockVol( ULONG cArgs, TCHAR * const rgptszArgs[], ULONG *pcEaten )
  81. {
  82. HRESULT hr = S_OK;
  83. NTSTATUS status = 0;
  84. ULONG iVolume = static_cast<ULONG>(-1);
  85. TCHAR tszVolume[ ] = TEXT("\\\\.\\A:");
  86. OBJECT_ATTRIBUTES ObjAttr;
  87. IO_STATUS_BLOCK Iosb;
  88. UNICODE_STRING uPath = { 0, 0, NULL };
  89. HANDLE hVolume = NULL;
  90. BOOL fSuccess = FALSE;
  91. CHAR rgcCommands[ 10 ];
  92. ULONG iCommand = 0, cCommands = 0;
  93. *pcEaten = 0;
  94. if( 0 == cArgs
  95. ||
  96. 1 <= cArgs && IsHelpArgument(rgptszArgs[0]) )
  97. {
  98. *pcEaten = 1;
  99. printf( "\nOption LockVol\n"
  100. " Purpose: Lock and/or dismount a volume\n"
  101. " Usage: -LockVol <options> <drive letter>:\n"
  102. " Where: <options> are any combination (up to %d) of:\n"
  103. " -d Send FSCTL_DISMOUNT_VOLUME\n"
  104. " -l Send FSCTL_LOCK_VOLUME\n"
  105. " -u Send FSCTL_UNLOCK_VOLUME\n"
  106. " -p Pause for user input\n"
  107. " E.g.: -LockVol -d -l -u c:\n"
  108. " -LockVol -l c:\n",
  109. ELEMENTS(rgcCommands) );
  110. return( TRUE );
  111. }
  112. for( int iArgs = 0; iArgs < cArgs; iArgs++ )
  113. {
  114. if( 2 == _tcslen( rgptszArgs[iArgs] ) && TEXT(':') == rgptszArgs[iArgs][1] )
  115. {
  116. TCHAR tc = rgptszArgs[iArgs][0];
  117. if( TEXT('A') <= tc && TEXT('Z') >= tc )
  118. iVolume = tc - TEXT('A');
  119. else if( TEXT('a') <= tc && TEXT('z') >= tc )
  120. iVolume = tc - TEXT('a');
  121. }
  122. else if( TEXT('-') == rgptszArgs[iArgs][0]
  123. ||
  124. TEXT('/') == rgptszArgs[iArgs][0] )
  125. {
  126. _tcslwr(rgptszArgs[iArgs]);
  127. if( iCommand >= ELEMENTS(rgcCommands) )
  128. {
  129. printf( "Too many commands to LockVol. Use -? for usage info.\n" );
  130. return( FALSE );
  131. }
  132. if( TEXT('d') == rgptszArgs[iArgs][1] )
  133. rgcCommands[iCommand] = 'd';
  134. else
  135. if( TEXT('l') == rgptszArgs[iArgs][1] )
  136. rgcCommands[iCommand] = 'l';
  137. else
  138. if( TEXT('u') == rgptszArgs[iArgs][1] )
  139. rgcCommands[iCommand] = 'u';
  140. else
  141. if( TEXT('p') == rgptszArgs[iArgs][1] )
  142. rgcCommands[iCommand] = 'p';
  143. else
  144. {
  145. printf( "Invalid option. Use -? for usage info.\n" );
  146. return( FALSE );
  147. }
  148. }
  149. cCommands++;
  150. iCommand++;
  151. (*pcEaten)++;
  152. }
  153. if( static_cast<ULONG>(-1) == iVolume )
  154. {
  155. printf( "Invalid parameter. Use -? for usage info\n" );
  156. return( FALSE );
  157. }
  158. tszVolume[4] += static_cast<TCHAR>(iVolume);
  159. if( !RtlDosPathNameToNtPathName_U( tszVolume, &uPath, NULL, NULL ))
  160. {
  161. status = STATUS_OBJECT_NAME_INVALID;
  162. goto Exit;
  163. }
  164. InitializeObjectAttributes(
  165. &ObjAttr,
  166. &uPath,
  167. OBJ_CASE_INSENSITIVE,
  168. NULL,
  169. NULL
  170. );
  171. status = NtOpenFile(
  172. &hVolume,
  173. FILE_READ_DATA|FILE_WRITE_DATA|SYNCHRONIZE,
  174. &ObjAttr,
  175. &Iosb,
  176. FILE_SHARE_READ | FILE_SHARE_WRITE,
  177. FILE_SYNCHRONOUS_IO_ALERT
  178. );
  179. if( !NT_SUCCESS(status) )
  180. {
  181. printf( "Failed NtOpenFile of %s (%08x)\n", tszVolume, status );
  182. goto Exit;
  183. }
  184. for( iCommand = 0; iCommand < cCommands; iCommand++ )
  185. {
  186. switch( rgcCommands[iCommand] )
  187. {
  188. case 'd':
  189. {
  190. status = NtFsControlFile(
  191. hVolume,
  192. NULL, /* Event */
  193. NULL, /* ApcRoutine */
  194. NULL, /* ApcContext */
  195. &Iosb,
  196. FSCTL_DISMOUNT_VOLUME,
  197. NULL, /* InputBuffer */
  198. 0, /* InputBufferLength */
  199. NULL, /* OutputBuffer */
  200. 0 /* OutputBufferLength */
  201. );
  202. if( !NT_SUCCESS(status) )
  203. printf( "Failed FSCTL_DISMOUNT_VOLUME (%08x)\n", status );
  204. else
  205. printf( "Volume dismounted\n" );
  206. }
  207. break;
  208. case 'l':
  209. {
  210. status = NtFsControlFile(
  211. hVolume,
  212. NULL, /* Event */
  213. NULL, /* ApcRoutine */
  214. NULL, /* ApcContext */
  215. &Iosb,
  216. FSCTL_LOCK_VOLUME,
  217. NULL, /* InputBuffer */
  218. 0, /* InputBufferLength */
  219. NULL, /* OutputBuffer */
  220. 0 /* OutputBufferLength */
  221. );
  222. if( !NT_SUCCESS(status) )
  223. printf( "Failed FSCTL_LOCK_VOLUME (%08x)\n", status );
  224. else
  225. printf( "Volume is locked\n" );
  226. }
  227. break;
  228. case 'u':
  229. {
  230. status = NtFsControlFile(
  231. hVolume,
  232. NULL, /* Event */
  233. NULL, /* ApcRoutine */
  234. NULL, /* ApcContext */
  235. &Iosb,
  236. FSCTL_UNLOCK_VOLUME,
  237. NULL, /* InputBuffer */
  238. 0, /* InputBufferLength */
  239. NULL, /* OutputBuffer */
  240. 0 /* OutputBufferLength */
  241. );
  242. if( !NT_SUCCESS(status) )
  243. printf( "Failed FSCTL_UNLOCK_VOLUME (%08x)\n", status );
  244. else
  245. printf( "Volume unlocked\n" );
  246. }
  247. break;
  248. case 'p':
  249. {
  250. printf( "Press enter to unlock ..." );
  251. getchar();
  252. }
  253. break;
  254. } // switch( rgcCommands[iCommand] )
  255. } // for( iCommand = 0; iCommand < cCommands; iCommand++ )
  256. fSuccess = TRUE;
  257. Exit:
  258. if( NULL != uPath.Buffer )
  259. RtlFreeUnicodeString( &uPath );
  260. return( fSuccess );
  261. }
  262. void
  263. MakeAbsolutePath( TCHAR * ptszAbsolute, TCHAR * ptszRelative )
  264. {
  265. if( !_tcsncmp( TEXT("\\\\"), ptszRelative, 2 ) // A UNC path
  266. ||
  267. TEXT(':') == ptszRelative[1] ) // A drive-based path
  268. {
  269. // The command-line has an absolute path
  270. _tcscpy( ptszAbsolute, ptszRelative );
  271. }
  272. else
  273. {
  274. // The command-line has a relative path
  275. DWORD dwLength = 0;
  276. dwLength = GetCurrentDirectory( MAX_PATH, ptszAbsolute );
  277. if( 0 == dwLength )
  278. {
  279. TrkLog((TRKDBG_ERROR, TEXT("Couldn't get current directory") ));
  280. TrkRaiseLastError( );
  281. }
  282. if( TEXT('\\') != ptszAbsolute[dwLength-1] )
  283. _tcscat( ptszAbsolute, TEXT("\\") );
  284. _tcscat( ptszAbsolute, ptszRelative );
  285. }
  286. }
  287. BOOL
  288. DltAdminFileOid( ULONG cArgs, TCHAR * const rgptszArgs[], ULONG *pcEaten )
  289. {
  290. HRESULT hr = S_OK;
  291. NTSTATUS status = 0;
  292. TCHAR tszFile[ MAX_PATH + 1 ];
  293. WCHAR wszFile[ MAX_PATH + 1 ];
  294. TCHAR tszUNCPath[ MAX_PATH + 1 ];
  295. WCHAR wszOID[ CCH_GUID_STRING + 1 ];
  296. ULONG cbInBuffer;
  297. TCHAR tszMachineName[ MAX_PATH + 1 ];
  298. LPCTSTR tszVolumePath = NULL;
  299. USHORT iVolume;
  300. OLECHAR oszOID[ CCH_GUID_STRING + 1 ];
  301. EnablePrivilege( SE_RESTORE_NAME );
  302. *pcEaten = 0;
  303. // -------------------------
  304. // Validate the command-line
  305. // -------------------------
  306. if( 1 <= cArgs && IsHelpArgument( rgptszArgs[0] ))
  307. {
  308. *pcEaten = 1;
  309. printf( "\nOption FileOID\n"
  310. " Purpose: Get/set/use file Object IDs\n"
  311. " Usage: -fileoid <option> <filename or object id, depending on the option>\n"
  312. " Options: -r => Read the object ID from a file\n"
  313. " -g => Get (creating if necessary) the object ID from a file\n"
  314. " -f => Search the local machine for an object ID's filename\n"
  315. " -s => Set an ID on a file (specify objid, then filename)\n"
  316. " -sr => Make a file reborn\n"
  317. " -df => Delete the object ID from it's file, given the filename\n"
  318. " -do => Delete the object ID from it's file, given the object ID\n"
  319. " E.g.: -fileoid -g d:\\test.txt\n"
  320. " -fileoid -r d:\\test.txt\n"
  321. " -fileoid -f {C69F3AA6-8B4C-11D0-8C9D-00C04FD90F85}\n"
  322. " -fileoid -do {C69F3AA6-8B4C-11D0-8C9D-00C04FD90F85}\n"
  323. " -fileoid -df d:\\test.txt\n" );
  324. return( TRUE );
  325. }
  326. else
  327. if( 2 > cArgs
  328. ||
  329. rgptszArgs[0][0] != TEXT('-')
  330. &&
  331. rgptszArgs[0][0] != TEXT('/')
  332. )
  333. {
  334. printf( "Parameter error. Use -? for usage info\n" );
  335. }
  336. *pcEaten = 2;
  337. // Convert the option to upper case (options are case-insensitive).
  338. _tcsupr( rgptszArgs[0] );
  339. __try
  340. {
  341. // Switch on the option (e.g, the 'F' in "-F")
  342. switch( rgptszArgs[0][1] )
  343. {
  344. // --------------------------------
  345. // Get a file name from an ObjectID
  346. // --------------------------------
  347. case TEXT('F'):
  348. {
  349. CDomainRelativeObjId droidBirth;
  350. // Get the OID in binary format
  351. CObjId oid;
  352. TSZ2CLSID( rgptszArgs[1], (GUID*)&oid );
  353. // Scan the volumes for this objectID
  354. for (LONG vol = 0; vol < 26; vol++)
  355. {
  356. if( IsLocalObjectVolume( vol )
  357. &&
  358. NT_SUCCESS(FindLocalPath(vol, oid, &droidBirth, &tszUNCPath[2])) )
  359. {
  360. tszUNCPath[0] = VolChar(vol);
  361. tszUNCPath[1] = TEXT(':');
  362. break;
  363. }
  364. }
  365. if( 'z'-'a' == vol )
  366. {
  367. hr = ERROR_FILE_NOT_FOUND;
  368. __leave;
  369. }
  370. // Display the filename
  371. wprintf( L"File name = \"%s\"\n", tszUNCPath );
  372. }
  373. break;
  374. // --------------------
  375. // Read/Get an ObjectID
  376. // --------------------
  377. case TEXT('R'):
  378. case TEXT('G'):
  379. {
  380. TCHAR tszFile[ MAX_PATH + 1 ];
  381. MakeAbsolutePath( tszFile, rgptszArgs[1] );
  382. CDomainRelativeObjId droidCurrent;
  383. CDomainRelativeObjId droidBirth;
  384. status = GetDroids( tszFile, &droidCurrent, &droidBirth,
  385. rgptszArgs[0][1] == TEXT('R') ? RGO_READ_OBJECTID : RGO_GET_OBJECTID );
  386. if( !NT_SUCCESS(status) )
  387. {
  388. hr = status;
  389. __leave;
  390. }
  391. _tprintf( TEXT("Current:\n") );
  392. _tprintf( TEXT(" volid = %s\n"),
  393. static_cast<const TCHAR*>(CStringize(droidCurrent.GetVolumeId() )));
  394. _tprintf( TEXT(" objid = %s\n"),
  395. static_cast<const TCHAR*>(CStringize(droidCurrent.GetObjId() )));
  396. _tprintf( TEXT("Birth:\n") );
  397. _tprintf( TEXT(" volid = %s\n"),
  398. static_cast<const TCHAR*>(CStringize(droidBirth.GetVolumeId() )));
  399. _tprintf( TEXT(" objid = %s\n"),
  400. static_cast<const TCHAR*>(CStringize(droidBirth.GetObjId() )));
  401. }
  402. break;
  403. // ---------------
  404. // Set an ObjectID
  405. // ---------------
  406. case TEXT('S'):
  407. {
  408. HANDLE hFile;
  409. CObjId objid;
  410. IO_STATUS_BLOCK IoStatus;
  411. TCHAR tszFile[ MAX_PATH + 1 ];
  412. if( TEXT('R') == rgptszArgs[0][2] )
  413. {
  414. if( 2 > cArgs )
  415. {
  416. printf( "Parameter error. Use -? for usage info\n" );
  417. hr = E_FAIL;
  418. goto Exit;
  419. }
  420. (*pcEaten)++;
  421. MakeAbsolutePath( tszFile, rgptszArgs[1] );
  422. status = TrkCreateFile( tszFile, FILE_READ_ATTRIBUTES,
  423. FILE_ATTRIBUTE_NORMAL,
  424. FILE_SHARE_DELETE|FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN,
  425. FILE_OPEN_FOR_BACKUP_INTENT | FILE_OPEN_NO_RECALL | FILE_SYNCHRONOUS_IO_NONALERT,
  426. NULL,
  427. &hFile );
  428. if (!NT_SUCCESS(status))
  429. {
  430. printf( "TrkCreateFile failed\n" );
  431. hr = status;
  432. __leave;
  433. }
  434. status = MakeObjIdReborn( hFile );
  435. if( NT_SUCCESS(status) )
  436. printf( "File is reborn\n" );
  437. else
  438. printf( "Failed to make reborn (%08x)\n", status );
  439. }
  440. else
  441. {
  442. TSZ2CLSID( rgptszArgs[1], (GUID*)&objid );
  443. if( 3 > cArgs )
  444. {
  445. printf( "Parameter error. Use -? for usage info\n" );
  446. hr = E_FAIL;
  447. goto Exit;
  448. }
  449. (*pcEaten)++;
  450. MakeAbsolutePath( tszFile, rgptszArgs[2] );
  451. status = TrkCreateFile( tszFile, FILE_READ_ATTRIBUTES,
  452. FILE_ATTRIBUTE_NORMAL,
  453. FILE_SHARE_DELETE|FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN,
  454. FILE_OPEN_FOR_BACKUP_INTENT | FILE_OPEN_NO_RECALL | FILE_SYNCHRONOUS_IO_NONALERT,
  455. NULL,
  456. &hFile );
  457. if (!NT_SUCCESS(status))
  458. {
  459. printf( "TrkCreateFile failed\n" );
  460. hr = status;
  461. __leave;
  462. }
  463. status = SetObjId( hFile, objid, CDomainRelativeObjId() );
  464. if (!NT_SUCCESS(status))
  465. {
  466. printf( "FSCTL_SET_OBJECT_ID failed\n" );
  467. hr = status;
  468. __leave;
  469. }
  470. printf( "ID set ok\n" );
  471. }
  472. }
  473. break;
  474. case TEXT('D'):
  475. {
  476. if( TEXT('F') == rgptszArgs[0][2] )
  477. {
  478. TCHAR tszFile[ MAX_PATH + 1 ];
  479. HANDLE hFile;
  480. NTSTATUS status;
  481. IO_STATUS_BLOCK IoStatus;
  482. MakeAbsolutePath( tszFile, rgptszArgs[1] );
  483. status = TrkCreateFile( tszFile, FILE_GENERIC_READ | FILE_GENERIC_WRITE,
  484. FILE_ATTRIBUTE_NORMAL,
  485. FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN,
  486. FILE_OPEN_FOR_BACKUP_INTENT | FILE_OPEN_NO_RECALL | FILE_SYNCHRONOUS_IO_NONALERT,
  487. NULL,
  488. &hFile );
  489. if (!NT_SUCCESS(status))
  490. {
  491. printf( "TrkCreateFile failed\n" );
  492. hr = status;
  493. __leave;
  494. }
  495. status = NtFsControlFile(
  496. hFile,
  497. NULL,
  498. NULL,
  499. NULL,
  500. &IoStatus,
  501. FSCTL_DELETE_OBJECT_ID,
  502. NULL, // in buffer
  503. 0, // in buffer size
  504. NULL, // Out buffer
  505. 0); // Out buffer size
  506. if (!NT_SUCCESS(status))
  507. {
  508. printf( "FSCTL_DELETE_OBJECT_ID failed\n" );
  509. hr = status;
  510. __leave;
  511. }
  512. printf( "Deleted ok\n" );
  513. }
  514. else if( TEXT('O') == rgptszArgs[0][2] )
  515. {
  516. // Get the OID in binary format
  517. CObjId oid;
  518. CDomainRelativeObjId droidBirth;
  519. TSZ2CLSID( rgptszArgs[1], (GUID*)&oid );
  520. BOOL fFound = FALSE;
  521. for (int vol='a'-'a'; vol<'z'-'a'; vol++)
  522. {
  523. if( IsLocalObjectVolume(CVolumeDeviceName(vol)) )
  524. {
  525. status = FindLocalPath(vol, oid, &droidBirth, &tszUNCPath[2]);
  526. if( STATUS_OBJECT_NAME_NOT_FOUND == status )
  527. continue;
  528. if( !NT_SUCCESS(status) ) goto Exit;
  529. tszUNCPath[0] = VolChar(vol);
  530. tszUNCPath[1] = TEXT(':');
  531. _tprintf( TEXT("Deleting object ID on %s\n"), tszUNCPath );
  532. status = DelObjId( vol, oid );
  533. if( !NT_SUCCESS(status) ) goto Exit;
  534. printf( "Deleted ok\n" );
  535. break;
  536. }
  537. }
  538. if( fFound ) printf( "Not found\n" );
  539. }
  540. else
  541. printf( "Bad parameter\n" );
  542. } // case TEXT('D'):
  543. break;
  544. } // switch
  545. hr = S_OK;
  546. } // __try
  547. __except( BreakOnDebuggableException() )
  548. {
  549. hr = GetExceptionCode();
  550. }
  551. Exit:
  552. if( FAILED(hr) )
  553. printf( "HR = %08X\n", hr );
  554. return SUCCEEDED(hr);
  555. }
  556. BOOL
  557. DltAdminTemp( ULONG cArgs, TCHAR * const rgptszArgs[], ULONG *pcEaten )
  558. {
  559. HRESULT hr = E_FAIL;
  560. RPC_STATUS rpcstatus;
  561. RPC_TCHAR * ptszStringBinding;
  562. RPC_BINDING_HANDLE hBinding = NULL;
  563. WCHAR wszMachine[ 256 ];
  564. BOOL fBound = FALSE;
  565. LONG iVol = 4;
  566. GUID volid = { /* 9f1534ee-ceab-4710-98b9-daaf048e3ad2 */
  567. 0x9f1534ee,
  568. 0xceab,
  569. 0x4710,
  570. {0x98, 0xb9, 0xda, 0xaf, 0x04, 0x8e, 0x3a, 0xd2}
  571. };
  572. if( 2 > cArgs || IsHelpArgument( rgptszArgs[0] ))
  573. {
  574. printf("\nOption Mend\n"
  575. " Purpose: Temp test placeholder\n"
  576. " Usage: -temp <machine>\n" );
  577. return( TRUE );
  578. }
  579. wsprintf( wszMachine, TEXT("\\\\%s"), rgptszArgs[1] );
  580. rpcstatus = RpcStringBindingCompose( NULL, TEXT("ncacn_np"), wszMachine, TEXT("\\pipe\\trkwks"),
  581. NULL, &ptszStringBinding);
  582. wprintf( L"StringBinding = %s\n", ptszStringBinding );
  583. if( rpcstatus )
  584. {
  585. TrkLog(( TRKDBG_ERROR, TEXT("Failed RpcStringBindingCompose %lu"), rpcstatus ));
  586. hr = HRESULT_FROM_WIN32(rpcstatus);
  587. goto Exit;
  588. }
  589. rpcstatus = RpcBindingFromStringBinding( ptszStringBinding, &hBinding );
  590. RpcStringFree( &ptszStringBinding );
  591. if( rpcstatus )
  592. {
  593. TrkLog(( TRKDBG_ERROR, TEXT("Failed RpcBindingFromStringBinding") ));
  594. hr = HRESULT_FROM_WIN32(rpcstatus);
  595. goto Exit;
  596. }
  597. fBound = TRUE;
  598. __try
  599. {
  600. //hr = LnkSetVolumeId( hBinding, iVol, volid );
  601. CDomainRelativeObjId droidBirth, droidLast, droidCurrent;
  602. CMachineId mcidLast, mcidCurrent;
  603. FILETIME ftLimit = { 0x01d27f63, 0x01d27f63 };
  604. WCHAR wsz[ 256 ];
  605. ULONG cbPath = 128*1024*1024; //256;
  606. HANDLE hEvent = NULL;
  607. PRPC_ASYNC_STATE pRpcAsyncState;
  608. pRpcAsyncState = reinterpret_cast<PRPC_ASYNC_STATE>( new BYTE[ sizeof(RPC_ASYNC_STATE) ] );
  609. if( NULL == pRpcAsyncState )
  610. {
  611. TrkRaiseException( E_OUTOFMEMORY );
  612. __leave; // Unnecessary, but prevents prefast error.
  613. }
  614. rpcstatus = RpcAsyncInitializeHandle( pRpcAsyncState, RPC_ASYNC_VERSION_1_0 );
  615. if( RPC_S_OK != rpcstatus )
  616. TrkRaiseWin32Error( rpcstatus );
  617. hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); // Auto-reset, not initially signaled
  618. if (NULL == hEvent)
  619. TrkRaiseLastError();
  620. pRpcAsyncState->NotificationType = RpcNotificationTypeEvent;
  621. pRpcAsyncState->u.hEvent = hEvent;
  622. pRpcAsyncState->UserInfo = NULL;
  623. memset( &droidBirth, 1, sizeof(droidBirth) );
  624. memset( &droidLast, 2, sizeof(droidBirth) );
  625. memset( &droidCurrent, 3, sizeof(droidBirth) );
  626. memset( &mcidLast, 1, sizeof(mcidLast) );
  627. memset( &mcidCurrent, 2, sizeof(mcidLast) );
  628. LnkMendLink( pRpcAsyncState,
  629. hBinding, ftLimit, 0,
  630. &droidBirth,
  631. &droidLast,
  632. &mcidLast,
  633. &droidCurrent,
  634. &mcidCurrent,
  635. &cbPath,
  636. wsz );
  637. DWORD dwWaitReturn = WaitForSingleObject(hEvent, INFINITE);
  638. if (WAIT_OBJECT_0 != dwWaitReturn)
  639. TrkRaiseLastError();
  640. rpcstatus = RpcAsyncCompleteCall(pRpcAsyncState, &hr);
  641. if (RPC_S_OK != rpcstatus)
  642. TrkRaiseWin32Error( rpcstatus );
  643. }
  644. __except( EXCEPTION_EXECUTE_HANDLER )
  645. {
  646. hr = HRESULT_FROM_WIN32( GetExceptionCode() );
  647. }
  648. if( FAILED(hr) )
  649. {
  650. _tprintf( TEXT("Failed call to service (%08x)\n"), hr );
  651. goto Exit;
  652. }
  653. Exit:
  654. if( fBound )
  655. RpcBindingFree( &hBinding );
  656. return( TRUE );
  657. } // main()
  658. BOOL
  659. DltAdminTemp2( ULONG cArgs, TCHAR * const rgptszArgs[], ULONG *pcEaten )
  660. {
  661. HRESULT hr = E_FAIL;
  662. RPC_STATUS rpcstatus;
  663. RPC_TCHAR * ptszStringBinding;
  664. RPC_BINDING_HANDLE hBinding = NULL;
  665. BOOL fBound = FALSE;
  666. LONG iVol = 4;
  667. TCHAR tszMachine[ MAX_PATH ];
  668. GUID volid = { /* 9f1534ee-ceab-4710-98b9-daaf048e3ad2 */
  669. 0x9f1534ee,
  670. 0xceab,
  671. 0x4710,
  672. {0x98, 0xb9, 0xda, 0xaf, 0x04, 0x8e, 0x3a, 0xd2}
  673. };
  674. if( 2 > cArgs || IsHelpArgument( rgptszArgs[0] ))
  675. {
  676. printf("\nOption Temp2\n"
  677. " Purpose: Temp2 test placeholder\n"
  678. " Usage: -temp2 <machine> <cVolumes>\n"
  679. " E.g.: -temp2 mikehill 100\n" );
  680. return( TRUE );
  681. }
  682. wsprintf( tszMachine, TEXT("\\\\%s"), rgptszArgs[1] );
  683. ULONG cVolumes = _ttoi( rgptszArgs[2] );
  684. *pcEaten = 2;
  685. rpcstatus = RpcStringBindingCompose( NULL,
  686. TEXT("ncacn_np"),
  687. tszMachine,
  688. TEXT("\\pipe\\ntsvcs"),
  689. NULL,
  690. &ptszStringBinding);
  691. wprintf( L"Binding string = %s\n", ptszStringBinding );
  692. /*
  693. rpcstatus = RpcStringBindingCompose( NULL,
  694. TEXT("ncacn_ip_tcp"),
  695. TEXT("mikehill1"),
  696. TEXT(""),
  697. NULL,
  698. &ptszStringBinding);
  699. */
  700. if( rpcstatus )
  701. {
  702. TrkLog(( TRKDBG_ERROR, TEXT("Failed RpcStringBindingCompose %lu"), rpcstatus ));
  703. hr = HRESULT_FROM_WIN32(rpcstatus);
  704. goto Exit;
  705. }
  706. rpcstatus = RpcBindingFromStringBinding( ptszStringBinding, &hBinding );
  707. RpcStringFree( &ptszStringBinding );
  708. if( rpcstatus )
  709. {
  710. TrkLog(( TRKDBG_ERROR, TEXT("Failed RpcBindingFromStringBinding") ));
  711. hr = HRESULT_FROM_WIN32(rpcstatus);
  712. goto Exit;
  713. }
  714. fBound = TRUE;
  715. __try
  716. {
  717. /*
  718. CVolumeId *rgvolid = new CVolumeId[ cVolumes ];
  719. DWORD *pdw = (DWORD*) rgvolid;
  720. for( ULONG i = 0; i < (cVolumes * sizeof(CVolumeId)/sizeof(DWORD) ); i++ )
  721. *(pdw++) = (DWORD)i;
  722. printf( "Buffer size = %d (0x%x DWORDs)\n",
  723. cVolumes * sizeof(CVolumeId),
  724. cVolumes * sizeof(CVolumeId) / sizeof(DWORD) );
  725. hr = TriggerVolumeClaims( hBinding, cVolumes, rgvolid );
  726. */
  727. TRKSVR_MESSAGE_UNION Msg;
  728. memset( &Msg, 0, sizeof(Msg) );
  729. Msg.MessageType = SEARCH;
  730. Msg.Search.cSearch = cVolumes;
  731. Msg.Search.pSearches = new TRK_FILE_TRACKING_INFORMATION[ cVolumes ];
  732. hr = LnkCallSvrMessage( hBinding, &Msg );
  733. }
  734. __except( EXCEPTION_EXECUTE_HANDLER )
  735. {
  736. hr = HRESULT_FROM_WIN32( GetExceptionCode() );
  737. }
  738. if( FAILED(hr) )
  739. {
  740. _tprintf( TEXT("Failed call to service (%08x)\n"), hr );
  741. goto Exit;
  742. }
  743. Exit:
  744. if( fBound )
  745. RpcBindingFree( &hBinding );
  746. return( TRUE );
  747. }
  748. BOOL
  749. DltAdminTemp3( ULONG cArgs, TCHAR * const rgptszArgs[], ULONG *pcEaten )
  750. {
  751. HRESULT hr = E_FAIL;
  752. RPC_STATUS rpcstatus;
  753. RPC_TCHAR * ptszStringBinding;
  754. RPC_BINDING_HANDLE hBinding = NULL;
  755. BOOL fBound = FALSE;
  756. LONG iVol = 4;
  757. TCHAR tszMachine[ MAX_PATH ];
  758. /*
  759. if( 1 > cArgs || IsHelpArgument( rgptszArgs[0] ))
  760. {
  761. printf("\nOption Temp3\n"
  762. " Purpose: Temp3 test placeholder\n"
  763. " Usage: -temp3 <machine>\n"
  764. " E.g.: -temp3 mikehill\n" );
  765. return( TRUE );
  766. }
  767. wsprintf( tszMachine, TEXT("\\\\%s"), rgptszArgs[1] );
  768. ULONG cVolumes = _ttoi( rgptszArgs[2] );
  769. *pcEaten = 2;
  770. */
  771. rpcstatus = RpcStringBindingCompose( NULL,
  772. TEXT("ncacn_np"),
  773. NULL, //tszMachine,
  774. TEXT("\\pipe\\trkwks"),
  775. NULL,
  776. &ptszStringBinding);
  777. wprintf( L"Binding string = %s\n", ptszStringBinding );
  778. if( rpcstatus )
  779. {
  780. TrkLog(( TRKDBG_ERROR, TEXT("Failed RpcStringBindingCompose %lu"), rpcstatus ));
  781. hr = HRESULT_FROM_WIN32(rpcstatus);
  782. goto Exit;
  783. }
  784. rpcstatus = RpcBindingFromStringBinding( ptszStringBinding, &hBinding );
  785. RpcStringFree( &ptszStringBinding );
  786. if( rpcstatus )
  787. {
  788. TrkLog(( TRKDBG_ERROR, TEXT("Failed RpcBindingFromStringBinding") ));
  789. hr = HRESULT_FROM_WIN32(rpcstatus);
  790. goto Exit;
  791. }
  792. fBound = TRUE;
  793. __try
  794. {
  795. TRKSVR_MESSAGE_UNION Msg;
  796. TRKSVR_SYNC_VOLUME syncvol;
  797. CVolumeSecret *pTempSecret = new CVolumeSecret();
  798. memset( &Msg, 0, sizeof(Msg) );
  799. Msg.MessageType = SYNC_VOLUMES;
  800. Msg.Priority = PRI_0;
  801. Msg.SyncVolumes.cVolumes = 1;
  802. Msg.SyncVolumes.pVolumes = &syncvol;
  803. memset( &syncvol, 0, sizeof(syncvol) );
  804. ((BYTE*)pTempSecret)[0] = 1;
  805. syncvol.secret = *pTempSecret;
  806. syncvol.SyncType = CREATE_VOLUME;
  807. hr = LnkCallSvrMessage( hBinding, &Msg );
  808. //hr = LnkSvrMessage( hBinding, &Msg );
  809. }
  810. __except( EXCEPTION_EXECUTE_HANDLER )
  811. {
  812. hr = HRESULT_FROM_WIN32( GetExceptionCode() );
  813. }
  814. if( FAILED(hr) )
  815. {
  816. _tprintf( TEXT("Failed call to service (%08x)\n"), hr );
  817. goto Exit;
  818. }
  819. else
  820. _tprintf( TEXT("Call succeeded\n") );
  821. Exit:
  822. if( fBound )
  823. RpcBindingFree( &hBinding );
  824. return( TRUE );
  825. } // main()
  826. CVolumeId
  827. DisplayLogStatus( LONG iVol )
  828. {
  829. NTSTATUS status = STATUS_SUCCESS;
  830. HANDLE hFile = NULL;
  831. TCHAR tszLog[ MAX_PATH + 1 ];
  832. ULONG cbRead;
  833. LogHeader logheader;
  834. LogInfo loginfo;
  835. VolumePersistentInfo volinfo;
  836. _tcscpy( tszLog, CVolumeDeviceName(iVol) );
  837. _tcscat( tszLog, s_tszLogFileName );
  838. status = TrkCreateFile( tszLog, FILE_GENERIC_READ, FILE_ATTRIBUTE_NORMAL,
  839. FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
  840. FILE_OPEN, FILE_SYNCHRONOUS_IO_NONALERT, NULL, &hFile );
  841. if( !NT_SUCCESS(status) )
  842. {
  843. TrkLog(( TRKDBG_ERROR, TEXT("Couldn't open %s"), tszLog ));
  844. TrkRaiseNtStatus(status);
  845. }
  846. if( !ReadFile( hFile, &logheader, sizeof(logheader), &cbRead, NULL )
  847. ||
  848. sizeof(logheader) != cbRead )
  849. {
  850. TrkLog(( TRKDBG_ERROR, TEXT("Couldn't read log header") ));
  851. TrkRaiseLastError();
  852. }
  853. if( !ReadFile( hFile, &volinfo, sizeof(volinfo), &cbRead, NULL )
  854. ||
  855. sizeof(volinfo) != cbRead )
  856. {
  857. TrkLog(( TRKDBG_ERROR, TEXT("Couldn't read volinfo") ));
  858. TrkRaiseLastError();
  859. }
  860. if( !ReadFile( hFile, &loginfo, sizeof(loginfo), &cbRead, NULL )
  861. ||
  862. sizeof(loginfo) != cbRead )
  863. {
  864. TrkLog(( TRKDBG_ERROR, TEXT("Couldn't read loginfo") ));
  865. TrkRaiseLastError();
  866. }
  867. _tprintf( TEXT("\nLog Header:\n") );
  868. _tprintf( TEXT(" guidSignature = \t%s\n"), static_cast<const TCHAR*>(CStringize(logheader.guidSignature)) );
  869. _tprintf( TEXT(" dwFormat = \t\t0x%x,0x%x\n"), logheader.dwFormat>>16, logheader.dwFormat&0xFFFF );
  870. _tprintf( TEXT(" ProperShutdown = \t%s\n"), (logheader.dwFlags & PROPER_SHUTDOWN) ? TEXT("True") : TEXT("False") );
  871. _tprintf( TEXT(" DownlevelDirtied = \t%s\n"), (logheader.dwFlags & DOWNLEVEL_DIRTIED) ? TEXT("True") : TEXT("False") );
  872. _tprintf( TEXT(" Expansion start = \t%d\n"), logheader.expand.ilogStart );
  873. _tprintf( TEXT(" end = \t%d\n"), logheader.expand.ilogEnd );
  874. _tprintf( TEXT(" cb = \t%d\n"), logheader.expand.cbFile );
  875. _tprintf( TEXT("\nLog Information:\n") );
  876. _tprintf( TEXT(" Start = \t\t%lu\n"), loginfo.ilogStart );
  877. _tprintf( TEXT(" End = \t\t%lu\n"), loginfo.ilogEnd );
  878. _tprintf( TEXT(" Write = \t\t%lu\n"), loginfo.ilogWrite );
  879. _tprintf( TEXT(" Read = \t\t%lu\n"), loginfo.ilogRead );
  880. _tprintf( TEXT(" Last = \t\t%lu\n"), loginfo.ilogLast );
  881. _tprintf( TEXT(" seqNext = \t\t%li\n"), loginfo.seqNext );
  882. _tprintf( TEXT(" seqLastRead = \t%li\n"), loginfo.seqLastRead );
  883. CVolumeId volidNTFS;
  884. status = QueryVolumeId( iVol, &volidNTFS );
  885. if( !NT_SUCCESS(status) )
  886. {
  887. TrkLog(( TRKDBG_ERROR, TEXT("Couldn't get NTFS volume ID") ));
  888. TrkRaiseNtStatus(status);
  889. }
  890. _tprintf( TEXT("\nVolume Information:\n") );
  891. _tprintf( TEXT(" Machine = \t\t%s\n"), static_cast<const TCHAR*>(CStringize(volinfo.machine)) );
  892. _tprintf( TEXT(" VolId (log) = \t%s\n"), static_cast<const TCHAR*>(CStringize(volinfo.volid)) );
  893. _tprintf( TEXT(" VolId (NTFS) = \t%s\n"), static_cast<const TCHAR*>(CStringize(volidNTFS)) );
  894. _tprintf( TEXT(" Secret = \t\t%s\n"), static_cast<const TCHAR*>(CStringize(volinfo.secret)) );
  895. _tprintf( TEXT(" Last Refresh = \t%d\n"), volinfo.cftLastRefresh.LowDateTime() );
  896. _tprintf( TEXT(" Enter not-owned = \t%s\n"), volinfo.cftEnterNotOwned == CFILETIME(0)
  897. ? TEXT("(N/A)")
  898. : static_cast<const TCHAR*>(CStringize(volinfo.cftEnterNotOwned)) );
  899. _tprintf( TEXT(" Make OIDs reborn = \t%s\n"), volinfo.fDoMakeAllOidsReborn ? TEXT("True") : TEXT("False") );
  900. _tprintf( TEXT(" Not-Created = \t%s\n"), volinfo.fNotCreated ? TEXT("True") : TEXT("False") );
  901. if( NULL != hFile )
  902. NtClose( hFile );
  903. return( volinfo.volid );
  904. }
  905. void
  906. DisplayDcStatus( const CVolumeId &volid )
  907. {
  908. CRpcClientBinding rc;
  909. TRKSVR_SYNC_VOLUME SyncVolume;
  910. TRKSVR_MESSAGE_UNION Msg;
  911. CMachineId mcidLocal( MCID_LOCAL );
  912. HRESULT hr = S_OK;
  913. rc.RcInitialize( mcidLocal, s_tszTrkWksLocalRpcProtocol, s_tszTrkWksLocalRpcEndPoint, NO_AUTHENTICATION );
  914. printf( "\nDC Information:\n" );
  915. __try
  916. {
  917. Msg.MessageType = SYNC_VOLUMES;
  918. Msg.ptszMachineID = NULL;
  919. Msg.Priority = PRI_9;
  920. Msg.SyncVolumes.cVolumes = 1;
  921. Msg.SyncVolumes.pVolumes = &SyncVolume;
  922. SyncVolume.hr = S_OK;
  923. SyncVolume.SyncType = QUERY_VOLUME;
  924. SyncVolume.volume = volid;
  925. hr = LnkCallSvrMessage( rc, &Msg );
  926. }
  927. __except( EXCEPTION_EXECUTE_HANDLER )
  928. {
  929. hr = HRESULT_FROM_WIN32(GetExceptionCode());
  930. }
  931. if( FAILED(hr) )
  932. {
  933. printf( " Couldn't get status from DC: %08x\n", hr );
  934. if( HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED) == hr )
  935. printf( " Make sure you have the 0x1 bit set in the TestFlags registry value\n" );
  936. goto Exit;
  937. }
  938. if( TRK_S_VOLUME_NOT_FOUND == SyncVolume.hr )
  939. {
  940. printf( " Volume is not in DC\n" );
  941. }
  942. else if( TRK_S_VOLUME_NOT_OWNED == SyncVolume.hr )
  943. {
  944. printf( " Volume is not owned by this machine\n" );
  945. }
  946. else if( S_OK == SyncVolume.hr )
  947. {
  948. _tprintf( TEXT(" Sequence # = \t%li\n"), SyncVolume.seq );
  949. _tprintf( TEXT(" Last Refresh = \t%lu\n"), SyncVolume.ftLastRefresh.dwLowDateTime );
  950. //static_cast<const TCHAR*>(CStringize(CFILETIME(SyncVolume.ftLastRefresh))) );
  951. }
  952. else
  953. {
  954. printf( " Volume state couldn't get queried from DC: %08x\n", hr );
  955. }
  956. Exit:
  957. return;
  958. }
  959. void
  960. DisplayOidInformation( LONG iVol )
  961. {
  962. CObjId objid;
  963. CDomainRelativeObjId droid;
  964. CObjIdEnumerator oie;
  965. ULONG cFilesWithOid = 0;
  966. ULONG cCrossVolumeBitSet = 0;
  967. if(oie.Initialize(CVolumeDeviceName(iVol)) == TRUE)
  968. {
  969. if(oie.FindFirst(&objid, &droid))
  970. {
  971. do
  972. {
  973. cFilesWithOid++;
  974. if( droid.GetVolumeId().GetUserBitState() )
  975. cCrossVolumeBitSet++;
  976. } while(oie.FindNext(&objid, &droid));
  977. }
  978. }
  979. printf( "\nObjectID Information\n" );
  980. printf( " Files with ObjectIDs = \t\t%lu\n", cFilesWithOid );
  981. printf( " Files with x-volume bit set = \t%lu\n", cCrossVolumeBitSet );
  982. }
  983. VolumeStatistics( ULONG cArgs, const TCHAR * const rgptszArgs[], ULONG *pcEaten )
  984. {
  985. NTSTATUS status = 0;
  986. TCHAR tszFile[ MAX_PATH + 1 ];
  987. TCHAR tszDir[ MAX_PATH + 1 ];
  988. TCHAR* ptcTmp = NULL;
  989. BOOL fSuccess = FALSE;
  990. LONG iVol = 0;
  991. *pcEaten = 0;
  992. if( 1 > cArgs || IsHelpArgument(rgptszArgs[0]) )
  993. {
  994. printf( "\nOption VolStat\n"
  995. " Purpose: Get link tracking info about a volume\n"
  996. " Usage: -volstat <drive letter>\n"
  997. " E.g.: -volstat D:\n" );
  998. *pcEaten = 1;
  999. return( TRUE );
  1000. }
  1001. if( TEXT('a') > rgptszArgs[0][0]
  1002. &&
  1003. TEXT('z') < rgptszArgs[0][0]
  1004. &&
  1005. TEXT('A') > rgptszArgs[0][0]
  1006. &&
  1007. TEXT('Z') < rgptszArgs[0][0]
  1008. ||
  1009. TEXT(':') != rgptszArgs[0][1] )
  1010. {
  1011. printf( "Parameter error. Use -? for usage info\n" );
  1012. return( FALSE );
  1013. }
  1014. iVol = (LONG)((ULONG_PTR)CharLower((LPTSTR)rgptszArgs[0][0]) - TEXT('a'));
  1015. if( !IsLocalObjectVolume( iVol ))
  1016. {
  1017. _tprintf( TEXT("%c: isn't a local NTFS5 volume\n"), VolChar(iVol) );
  1018. goto Exit;
  1019. }
  1020. __try
  1021. {
  1022. CVolumeId volid;
  1023. EnablePrivilege( SE_RESTORE_NAME );
  1024. volid = DisplayLogStatus(iVol);
  1025. DisplayDcStatus( volid );
  1026. DisplayOidInformation( iVol );
  1027. fSuccess = TRUE;
  1028. }
  1029. __except( EXCEPTION_EXECUTE_HANDLER )
  1030. {
  1031. printf( "Fatal error: %08x\n", GetExceptionCode() );
  1032. }
  1033. Exit:
  1034. return( fSuccess );
  1035. } // main()
  1036. VolumeIdSetOrGet( ULONG cArgs, TCHAR * const rgptszArgs[], ULONG *pcEaten )
  1037. {
  1038. HRESULT hr = E_FAIL;
  1039. NTSTATUS status = STATUS_SUCCESS;
  1040. TCHAR tszFile[ MAX_PATH + 1 ];
  1041. WCHAR wszFile[ MAX_PATH + 1 ];
  1042. TCHAR tszUNCPath[ MAX_PATH + 1 ];
  1043. WCHAR wszOID[ CCH_GUID_STRING + 1 ];
  1044. ULONG cbInBuffer;
  1045. TCHAR tszMachineName[ MAX_PATH + 1 ];
  1046. LPCTSTR tszVolumePath = NULL;
  1047. USHORT iVolume;
  1048. OLECHAR oszOID[ CCH_GUID_STRING + 1 ];
  1049. if( 1 == cArgs && IsHelpArgument( rgptszArgs[0] ))
  1050. {
  1051. printf( "\nOption VolId\n"
  1052. " Purpose: Set or get volume IDs\n"
  1053. " Usage: -volid [-s <drive>: {GUID} | -g <drive>:]\n"
  1054. " Where: '-s' means Set, and '-g' means Get\n"
  1055. " E.g.: -volid -g d:\n"
  1056. " -volid -s d: {d2a2ac27-b89a-11d2-9335-00805ffe11b8}\n" );
  1057. // The volid in this example is actually the well-known invalid volid
  1058. *pcEaten = 1;
  1059. return( TRUE );
  1060. }
  1061. else
  1062. if( 2 > cArgs
  1063. ||
  1064. TEXT('-') != rgptszArgs[0][0]
  1065. &&
  1066. TEXT('/') != rgptszArgs[0][0]
  1067. ||
  1068. TEXT(':') != rgptszArgs[1][1] )
  1069. {
  1070. printf( "Invalid parameter. Use -? for help\n" );
  1071. *pcEaten = 0;
  1072. return( FALSE );
  1073. }
  1074. *pcEaten = 2;
  1075. __try
  1076. {
  1077. CVolumeId volid;
  1078. TCHAR tcCommand = (TCHAR)CharUpper( (LPTSTR) rgptszArgs[0][1] );
  1079. TCHAR tcDrive = (TCHAR)CharUpper( (LPTSTR) rgptszArgs[1][0] );
  1080. LONG iVol = tcDrive - TEXT('A');
  1081. if( TEXT('G') == tcCommand )
  1082. {
  1083. OLECHAR *poszVolId;
  1084. status = QueryVolumeId( iVol, &volid );
  1085. if( FAILED(status) )
  1086. {
  1087. TrkLog(( TRKDBG_ERROR, TEXT("Couldn't query for volume id") ));
  1088. TrkRaiseNtStatus(status);
  1089. }
  1090. hr = StringFromCLSID( *(GUID*)&volid, &poszVolId );
  1091. if( FAILED(hr) )
  1092. {
  1093. TrkLog(( TRKDBG_ERROR, TEXT("Failed StringFromClsid %08x"), hr ));
  1094. TrkRaiseException( hr );
  1095. }
  1096. _tprintf( TEXT("VolID = %s\n"), poszVolId );
  1097. CoTaskMemFree( poszVolId );
  1098. }
  1099. else if( TEXT('S') == tcCommand && 3 <= cArgs )
  1100. {
  1101. TSZ2CLSID( rgptszArgs[2], (GUID*)&volid );
  1102. EnablePrivilege( SE_RESTORE_NAME );
  1103. status = SetVolId( iVol, volid );
  1104. if( FAILED(status) )
  1105. {
  1106. TrkLog(( TRKDBG_ERROR, TEXT("Couldn't set volume id") ));
  1107. TrkRaiseNtStatus(status);
  1108. }
  1109. }
  1110. else
  1111. {
  1112. printf( "Invalid parameter. Use -? for help\n" );
  1113. goto Exit;
  1114. }
  1115. hr = S_OK;
  1116. }
  1117. __except( BreakOnDebuggableException() )
  1118. {
  1119. hr = GetExceptionCode();
  1120. }
  1121. Exit:
  1122. if( FAILED(hr) )
  1123. printf( "Failed: hr = %08x\n", hr );
  1124. return( SUCCEEDED(hr) );
  1125. } // main()
  1126. BOOL
  1127. DltAdminVolInfoFile( ULONG cArgs, const TCHAR * const rgptszArgs[], ULONG *pcEaten )
  1128. {
  1129. NTSTATUS status;
  1130. HRESULT hr;
  1131. HANDLE hFile = NULL;
  1132. IO_STATUS_BLOCK Iosb;
  1133. OLECHAR *poszVolId = NULL;
  1134. BYTE rgb[ 2 * MAX_PATH ];
  1135. PFILE_FS_VOLUME_INFORMATION pfile_fs_volume_information
  1136. = reinterpret_cast<PFILE_FS_VOLUME_INFORMATION>(rgb);
  1137. PFILE_FS_ATTRIBUTE_INFORMATION pfile_fs_attribute_information
  1138. = reinterpret_cast<PFILE_FS_ATTRIBUTE_INFORMATION>(rgb);
  1139. PFILE_FS_OBJECTID_INFORMATION pfile_fs_objectid_information
  1140. = reinterpret_cast<PFILE_FS_OBJECTID_INFORMATION>(rgb);
  1141. FILE_FS_SIZE_INFORMATION file_fs_size_information;
  1142. FILE_FS_FULL_SIZE_INFORMATION file_fs_full_size_information;
  1143. FILE_FS_DEVICE_INFORMATION file_fs_device_information;
  1144. TCHAR tszFileSystemAttributes[ 2 * MAX_PATH ];
  1145. DWORD dwFileSystemAttributeMask;
  1146. TCHAR *ptszDeviceType = NULL;
  1147. if( 0 == cArgs )
  1148. {
  1149. printf( "Missing parameter: a file/directory name must be specified\n" );
  1150. *pcEaten = 0;
  1151. return( FALSE );
  1152. }
  1153. if( IsHelpArgument( rgptszArgs[0] ))
  1154. {
  1155. printf( "\nOption VolInfoFile\n"
  1156. " Purpose: Get volume information, given a file or directory name\n"
  1157. " Usage: -volinfofile <file or directory>\n"
  1158. " E.g. -volinfofile C:\\foo.doc\n"
  1159. " -volinfofile \\\\scratch\\scratch\\jdoe\n" );
  1160. *pcEaten = 1;
  1161. return( TRUE );
  1162. }
  1163. __try
  1164. {
  1165. *pcEaten = 1;
  1166. TCHAR tszFileTime[ 80 ];
  1167. status = TrkCreateFile(
  1168. rgptszArgs[0],
  1169. FILE_READ_ATTRIBUTES,
  1170. FILE_ATTRIBUTE_NORMAL,
  1171. FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
  1172. FILE_OPEN,
  1173. FILE_SYNCHRONOUS_IO_NONALERT,
  1174. NULL,
  1175. &hFile );
  1176. if( !NT_SUCCESS(status) )
  1177. {
  1178. TrkLog(( TRKDBG_ERROR, TEXT("Couldn't open file \"%s\" (%08x)"), rgptszArgs[1], status ));
  1179. TrkRaiseNtStatus(status);
  1180. }
  1181. status = NtQueryVolumeInformationFile( hFile, &Iosb,
  1182. pfile_fs_volume_information,
  1183. sizeof(rgb),
  1184. FileFsVolumeInformation );
  1185. if( !NT_SUCCESS(status) )
  1186. {
  1187. TrkLog(( TRKDBG_ERROR, TEXT("Couldn't query volume information (%08x)"), status ));
  1188. TrkRaiseNtStatus(status);
  1189. }
  1190. pfile_fs_volume_information->VolumeLabel[ pfile_fs_volume_information->VolumeLabelLength/sizeof(WCHAR) ]
  1191. = L'\0';
  1192. static_cast<CFILETIME>(pfile_fs_volume_information->VolumeCreationTime)
  1193. .Stringize( ELEMENTS(tszFileTime), tszFileTime );
  1194. _tprintf( TEXT("\n")
  1195. TEXT("Volume creation time:\t%08x:%08x (%s)\n")
  1196. TEXT("Volume serial number:\t%08x\n")
  1197. TEXT("Supports objects:\t%s\n")
  1198. TEXT("Volume label:\t\t%s\n"),
  1199. pfile_fs_volume_information->VolumeCreationTime.HighPart,
  1200. pfile_fs_volume_information->VolumeCreationTime.LowPart,
  1201. tszFileTime,
  1202. pfile_fs_volume_information->VolumeSerialNumber,
  1203. pfile_fs_volume_information->SupportsObjects ? TEXT("True") : TEXT("False"),
  1204. pfile_fs_volume_information->VolumeLabel );
  1205. status = NtQueryVolumeInformationFile( hFile, &Iosb,
  1206. pfile_fs_attribute_information,
  1207. sizeof(rgb),
  1208. FileFsAttributeInformation );
  1209. if( !NT_SUCCESS(status) )
  1210. {
  1211. TrkLog(( TRKDBG_ERROR, TEXT("Couldn't query attribute information (%08x)"), status ));
  1212. TrkRaiseNtStatus(status);
  1213. }
  1214. pfile_fs_attribute_information->FileSystemName[ pfile_fs_attribute_information->FileSystemNameLength/sizeof(WCHAR) ]
  1215. = L'\0';
  1216. _tcscpy( tszFileSystemAttributes, TEXT("") );
  1217. dwFileSystemAttributeMask = FILE_CASE_SENSITIVE_SEARCH
  1218. | FILE_CASE_PRESERVED_NAMES
  1219. | FILE_UNICODE_ON_DISK
  1220. | FILE_PERSISTENT_ACLS
  1221. | FILE_FILE_COMPRESSION
  1222. | FILE_VOLUME_QUOTAS
  1223. | FILE_SUPPORTS_SPARSE_FILES
  1224. | FILE_SUPPORTS_REPARSE_POINTS
  1225. | FILE_SUPPORTS_REMOTE_STORAGE
  1226. | FILE_VOLUME_IS_COMPRESSED
  1227. | FILE_SUPPORTS_OBJECT_IDS
  1228. | FILE_SUPPORTS_ENCRYPTION;
  1229. if( FILE_CASE_SENSITIVE_SEARCH & pfile_fs_attribute_information->FileSystemAttributes )
  1230. _tcscat( tszFileSystemAttributes, TEXT("\t\t\tCase sensitive search\n"));
  1231. if( FILE_CASE_PRESERVED_NAMES & pfile_fs_attribute_information->FileSystemAttributes )
  1232. _tcscat( tszFileSystemAttributes, TEXT("\t\t\tCase preserved names\n"));
  1233. if( FILE_UNICODE_ON_DISK & pfile_fs_attribute_information->FileSystemAttributes )
  1234. _tcscat( tszFileSystemAttributes, TEXT("\t\t\tUnicode on disk\n"));
  1235. if( FILE_PERSISTENT_ACLS & pfile_fs_attribute_information->FileSystemAttributes )
  1236. _tcscat( tszFileSystemAttributes, TEXT("\t\t\tPersistent ACLs\n"));
  1237. if( FILE_FILE_COMPRESSION & pfile_fs_attribute_information->FileSystemAttributes )
  1238. _tcscat( tszFileSystemAttributes, TEXT("\t\t\tFile compression\n"));
  1239. if( FILE_VOLUME_QUOTAS & pfile_fs_attribute_information->FileSystemAttributes )
  1240. _tcscat( tszFileSystemAttributes, TEXT("\t\t\tVolume quotas\n"));
  1241. if( FILE_SUPPORTS_SPARSE_FILES & pfile_fs_attribute_information->FileSystemAttributes )
  1242. _tcscat( tszFileSystemAttributes, TEXT("\t\t\tSupports sparse files\n"));
  1243. if( FILE_SUPPORTS_REPARSE_POINTS & pfile_fs_attribute_information->FileSystemAttributes )
  1244. _tcscat( tszFileSystemAttributes, TEXT("\t\t\tSupports reparse points\n"));
  1245. if( FILE_SUPPORTS_REMOTE_STORAGE & pfile_fs_attribute_information->FileSystemAttributes )
  1246. _tcscat( tszFileSystemAttributes, TEXT("\t\t\tSupports remote storage\n"));
  1247. if( FILE_VOLUME_IS_COMPRESSED & pfile_fs_attribute_information->FileSystemAttributes )
  1248. _tcscat( tszFileSystemAttributes, TEXT("\t\t\tVolume is compressed\n"));
  1249. if( FILE_SUPPORTS_OBJECT_IDS & pfile_fs_attribute_information->FileSystemAttributes )
  1250. _tcscat( tszFileSystemAttributes, TEXT("\t\t\tSupports object IDs\n"));
  1251. if( FILE_SUPPORTS_ENCRYPTION & pfile_fs_attribute_information->FileSystemAttributes )
  1252. _tcscat( tszFileSystemAttributes, TEXT("\t\t\tSupports encryption\n"));
  1253. if( FILE_NAMED_STREAMS & pfile_fs_attribute_information->FileSystemAttributes )
  1254. _tcscat( tszFileSystemAttributes, TEXT("\t\t\tSupports named streams\n"));
  1255. if( !(dwFileSystemAttributeMask & pfile_fs_attribute_information->FileSystemAttributes) )
  1256. _tcscat( tszFileSystemAttributes, TEXT("\t\t\t(Unknown bit)"));
  1257. _tprintf( TEXT("File system attributes:\t%08x\n%s")
  1258. TEXT("Max component name:\t%d\n")
  1259. TEXT("File system name\t%s\n"),
  1260. pfile_fs_attribute_information->FileSystemAttributes, tszFileSystemAttributes,
  1261. pfile_fs_attribute_information->MaximumComponentNameLength,
  1262. pfile_fs_attribute_information->FileSystemName );
  1263. status = NtQueryVolumeInformationFile( hFile, &Iosb,
  1264. pfile_fs_objectid_information,
  1265. sizeof(rgb),
  1266. FileFsObjectIdInformation );
  1267. if( NT_SUCCESS(status) )
  1268. {
  1269. hr = StringFromCLSID( *(GUID*)pfile_fs_objectid_information->ObjectId, &poszVolId );
  1270. if( FAILED(hr) )
  1271. {
  1272. TrkLog(( TRKDBG_ERROR, TEXT("Failed StringFromClsid %08x"), hr ));
  1273. TrkRaiseException( hr );
  1274. }
  1275. _tprintf( TEXT("Volume Id:\t\t%s\n"), poszVolId );
  1276. CoTaskMemFree( poszVolId );
  1277. }
  1278. else if( status != STATUS_INVALID_PARAMETER && status != STATUS_OBJECT_NAME_NOT_FOUND )
  1279. {
  1280. TrkLog(( TRKDBG_ERROR, TEXT("Couldn't query objectid information (%08x)"), status ));
  1281. TrkRaiseNtStatus(status);
  1282. }
  1283. status = NtQueryVolumeInformationFile( hFile, &Iosb,
  1284. &file_fs_full_size_information,
  1285. sizeof(file_fs_full_size_information),
  1286. FileFsFullSizeInformation );
  1287. if( !NT_SUCCESS(status) )
  1288. {
  1289. status = NtQueryVolumeInformationFile( hFile, &Iosb,
  1290. &file_fs_size_information,
  1291. sizeof(file_fs_size_information),
  1292. FileFsSizeInformation );
  1293. if( !NT_SUCCESS(status) )
  1294. {
  1295. TrkLog(( TRKDBG_ERROR, TEXT("Couldn't query full size info or size info (%08x)"), status ));
  1296. TrkRaiseNtStatus( status );
  1297. }
  1298. double TotalAllocInMB = file_fs_size_information.TotalAllocationUnits.QuadPart
  1299. *
  1300. file_fs_size_information.SectorsPerAllocationUnit
  1301. *
  1302. file_fs_size_information.BytesPerSector
  1303. /
  1304. 1000000.0;
  1305. _tprintf( TEXT("Total allocation units:\t%I64u (%.2fMB)\n")
  1306. TEXT("Available alloc:\t%I64u units\n")
  1307. TEXT("Sectors per alloc unit:\t%d\n")
  1308. TEXT("Bytes per sector:\t%d\n"),
  1309. file_fs_size_information.TotalAllocationUnits.QuadPart,
  1310. TotalAllocInMB,
  1311. file_fs_size_information.AvailableAllocationUnits.QuadPart,
  1312. file_fs_size_information.SectorsPerAllocationUnit,
  1313. file_fs_size_information.BytesPerSector );
  1314. }
  1315. else
  1316. {
  1317. double TotalAllocInMB = file_fs_full_size_information.TotalAllocationUnits.QuadPart
  1318. *
  1319. file_fs_full_size_information.SectorsPerAllocationUnit
  1320. *
  1321. file_fs_full_size_information.BytesPerSector
  1322. /
  1323. 1000000.0;
  1324. double CallerAvailAllocInMB
  1325. = file_fs_full_size_information.CallerAvailableAllocationUnits.QuadPart
  1326. *
  1327. file_fs_full_size_information.SectorsPerAllocationUnit
  1328. *
  1329. file_fs_full_size_information.BytesPerSector
  1330. /
  1331. 1000000.0;
  1332. double ActualAvailAllocInMB
  1333. = file_fs_full_size_information.ActualAvailableAllocationUnits.QuadPart
  1334. *
  1335. file_fs_full_size_information.SectorsPerAllocationUnit
  1336. *
  1337. file_fs_full_size_information.BytesPerSector
  1338. /
  1339. 1000000.0;
  1340. _tprintf( TEXT("Total allocation units:\t%I64u (%.2fMB)\n")
  1341. TEXT("Caller avail alloc:\t%I64u units (%.2fMB)\n")
  1342. TEXT("Actual avail alloc:\t%I64u units (%.2fMB)\n")
  1343. TEXT("Sectors per alloc unit:\t%d\n")
  1344. TEXT("Bytes per sector:\t%d\n"),
  1345. file_fs_full_size_information.TotalAllocationUnits.QuadPart,
  1346. TotalAllocInMB,
  1347. file_fs_full_size_information.CallerAvailableAllocationUnits.QuadPart,
  1348. CallerAvailAllocInMB,
  1349. file_fs_full_size_information.ActualAvailableAllocationUnits.QuadPart,
  1350. ActualAvailAllocInMB,
  1351. file_fs_full_size_information.SectorsPerAllocationUnit,
  1352. file_fs_full_size_information.BytesPerSector );
  1353. }
  1354. status = NtQueryVolumeInformationFile( hFile, &Iosb,
  1355. &file_fs_device_information,
  1356. sizeof(file_fs_device_information),
  1357. FileFsDeviceInformation );
  1358. if( !NT_SUCCESS(status) )
  1359. {
  1360. TrkLog(( TRKDBG_ERROR, TEXT("Couldn't query file fs device information (%08x)"), status ));
  1361. TrkRaiseNtStatus(status);
  1362. }
  1363. switch( file_fs_device_information.DeviceType )
  1364. {
  1365. case FILE_DEVICE_NETWORK:
  1366. ptszDeviceType = L"Network"; break;
  1367. case FILE_DEVICE_NETWORK_FILE_SYSTEM:
  1368. ptszDeviceType = L"Network file system"; break;
  1369. case FILE_DEVICE_CD_ROM:
  1370. ptszDeviceType = L"CDROM"; break;
  1371. case FILE_DEVICE_CD_ROM_FILE_SYSTEM:
  1372. ptszDeviceType = L"CDROM file system"; break;
  1373. case FILE_DEVICE_VIRTUAL_DISK:
  1374. ptszDeviceType = L"Virtual disk"; break;
  1375. case FILE_DEVICE_DISK:
  1376. ptszDeviceType = file_fs_device_information.Characteristics & FILE_REMOVABLE_MEDIA
  1377. ? L"Removable disk" : L"Fixed disk";
  1378. break;
  1379. case FILE_DEVICE_DISK_FILE_SYSTEM:
  1380. ptszDeviceType = file_fs_device_information.Characteristics & FILE_REMOVABLE_MEDIA
  1381. ? L"Removable disk file system" : L"Fixed disk file system";
  1382. break;
  1383. default:
  1384. ptszDeviceType = L"Unknown";
  1385. }
  1386. _tprintf( TEXT("Device Type:\t\t%s%s\n"),
  1387. ptszDeviceType,
  1388. (file_fs_device_information.Characteristics & FILE_REMOTE_DEVICE)
  1389. ? TEXT(" (remote)")
  1390. : TEXT("")
  1391. );
  1392. hr = S_OK;
  1393. }
  1394. __except( EXCEPTION_EXECUTE_HANDLER )
  1395. {
  1396. hr = GetExceptionCode();
  1397. }
  1398. if( NULL != hFile )
  1399. NtClose( hFile );
  1400. if( FAILED(hr) )
  1401. printf( "Failed: hr = %08x\n", hr );
  1402. return SUCCEEDED(hr);
  1403. }
  1404. BOOL
  1405. DeleteIdFromVolumeTable( ULONG cArgs, const TCHAR * const rgptszArgs[], ULONG *pcEaten )
  1406. {
  1407. CVolumeId volid;
  1408. CStringize stringize;
  1409. CRpcClientBinding rc;
  1410. TRKSVR_SYNC_VOLUME SyncVolume;
  1411. TRKSVR_MESSAGE_UNION Msg;
  1412. CMachineId mcidLocal( MCID_LOCAL );
  1413. HRESULT hr = S_OK;
  1414. if( 0 == cArgs )
  1415. {
  1416. printf( "Missing parameter: a volume ID name must be specified\n"
  1417. "(in \"{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}\" form)\n" );
  1418. *pcEaten = 0;
  1419. return( FALSE );
  1420. }
  1421. _tprintf( TEXT("Deleting volume %s from DC volume table\n"), rgptszArgs[0] );
  1422. if( IsHelpArgument( rgptszArgs[0] ))
  1423. {
  1424. printf( "\nOption DelDcVolId\n"
  1425. " Purpose: Delete a volume ID from the DC volume table\n"
  1426. " Usage: -deldcvolid <stringized volume ID>\n"
  1427. " E.g. -deldcvolid {56730825-3ddc-11d2-a168-00805ffe11b8}\n"
  1428. " Note: The volume ID must be owned by this machine.\n"
  1429. " Also, the services\\trkwks\\parameters\\configuration\\trkflags\n"
  1430. " reg value must have the 0x1 bit set.\n" );
  1431. *pcEaten = 1;
  1432. return( TRUE );
  1433. }
  1434. *pcEaten = 1;
  1435. // Convert the volid string to a volid
  1436. stringize.Use( rgptszArgs[0] );
  1437. volid = stringize;
  1438. if( CVolumeId() == volid )
  1439. {
  1440. _tprintf( TEXT("Error: Invalid volume ID\n") );
  1441. return( FALSE );
  1442. }
  1443. // Send the delete request
  1444. rc.RcInitialize( mcidLocal, s_tszTrkWksLocalRpcProtocol, s_tszTrkWksLocalRpcEndPoint, NO_AUTHENTICATION );
  1445. __try
  1446. {
  1447. Msg.MessageType = SYNC_VOLUMES;
  1448. Msg.ptszMachineID = NULL;
  1449. Msg.Priority = PRI_9;
  1450. Msg.SyncVolumes.cVolumes = 1;
  1451. Msg.SyncVolumes.pVolumes = &SyncVolume;
  1452. SyncVolume.hr = S_OK;
  1453. SyncVolume.SyncType = DELETE_VOLUME;
  1454. SyncVolume.volume = volid;
  1455. hr = LnkCallSvrMessage( rc, &Msg );
  1456. }
  1457. __except( EXCEPTION_EXECUTE_HANDLER )
  1458. {
  1459. hr = HRESULT_FROM_WIN32(GetLastError());
  1460. }
  1461. if( SUCCEEDED(hr) )
  1462. hr = SyncVolume.hr;
  1463. if( FAILED(hr) )
  1464. _tprintf( TEXT("Error: %08x\n"), hr );
  1465. else if( S_OK != hr )
  1466. _tprintf( TEXT("Success code: %08x\n"), hr );
  1467. if( FAILED(hr) )
  1468. printf( "Failed: hr = %08x\n", hr );
  1469. return( SUCCEEDED(hr) );
  1470. }
  1471. BOOL
  1472. DeleteIdFromMoveTable( ULONG cArgs, const TCHAR * const rgptszArgs[], ULONG *pcEaten )
  1473. {
  1474. CDomainRelativeObjId droid;
  1475. CStringize stringize;
  1476. CRpcClientBinding rc;
  1477. TRKSVR_MESSAGE_UNION Msg;
  1478. CMachineId mcidLocal( MCID_LOCAL );
  1479. HRESULT hr = S_OK;
  1480. if( 0 == cArgs )
  1481. {
  1482. printf( "Missing parameter: a birth ID name must be specified\n"
  1483. "(in \"{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}\" form)\n" );
  1484. *pcEaten = 0;
  1485. return( FALSE );
  1486. }
  1487. _tprintf( TEXT("Deleting file %s from DC move table\n"), rgptszArgs[0] );
  1488. if( IsHelpArgument( rgptszArgs[0] ))
  1489. {
  1490. printf( "\nOption DelDcMoveId\n"
  1491. " Purpose: Delete an entry from the DC move table\n"
  1492. " Usage: -deldcmoveid <stringized GUIDs of birth ID>\n"
  1493. " E.g. -deldcmoveid {xxx...xxx}{xxx...xxx}\n"
  1494. " Where: a stringized GUID is e.g. \"{56730825-3ddc-11d2-a168-00805ffe11b8}\"\n"
  1495. " Note: The birth ID must be owned by this machine.\n"
  1496. " Also, the services\\trkwks\\parameters\\configuration\\trkflags\n"
  1497. " reg value must have the 0x1 bit set.\n" );
  1498. *pcEaten = 1;
  1499. return( TRUE );
  1500. }
  1501. *pcEaten = 1;
  1502. stringize.Use( rgptszArgs[0] );
  1503. droid = stringize;
  1504. if( CDomainRelativeObjId() == droid )
  1505. {
  1506. _tprintf( TEXT("Error: Invalid birth ID\n") );
  1507. return( FALSE );
  1508. }
  1509. rc.RcInitialize( mcidLocal, s_tszTrkWksLocalRpcProtocol, s_tszTrkWksLocalRpcEndPoint, NO_AUTHENTICATION );
  1510. __try
  1511. {
  1512. CVolumeId volidDummy;
  1513. Msg.MessageType = DELETE_NOTIFY;
  1514. Msg.ptszMachineID = NULL;
  1515. Msg.Priority = PRI_5;
  1516. Msg.Delete.cVolumes = 0;
  1517. Msg.Delete.pVolumes = &volidDummy;
  1518. Msg.Delete.adroidBirth = &droid;
  1519. Msg.Delete.cdroidBirth = 1;
  1520. LnkCallSvrMessage(rc, &Msg);
  1521. }
  1522. __except( EXCEPTION_EXECUTE_HANDLER )
  1523. {
  1524. hr = HRESULT_FROM_WIN32(GetExceptionCode());
  1525. }
  1526. if( FAILED(hr) )
  1527. _tprintf( TEXT("Error: %08x\n"), hr );
  1528. else if( S_OK != hr )
  1529. _tprintf( TEXT("Success code: %x\n"), hr );
  1530. return( SUCCEEDED(hr) );
  1531. }
  1532. BOOL
  1533. DltAdminLookupVolId( ULONG cArgs, const TCHAR * const rgptszArgs[], ULONG *pcEaten )
  1534. {
  1535. CVolumeId volid;
  1536. CStringize stringize;
  1537. CRpcClientBinding rc;
  1538. TRKSVR_SYNC_VOLUME SyncVolume;
  1539. TRKSVR_MESSAGE_UNION Msg;
  1540. CMachineId mcidLocal( MCID_LOCAL );
  1541. HRESULT hr = S_OK;
  1542. if( 0 == cArgs )
  1543. {
  1544. printf( "Missing parameter: a volume ID name must be specified\n"
  1545. "(in \"{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}\" form)\n" );
  1546. *pcEaten = 0;
  1547. return( FALSE );
  1548. }
  1549. _tprintf( TEXT("Searching for volume %s in DC volume table\n"), rgptszArgs[0] );
  1550. if( IsHelpArgument( rgptszArgs[0] ))
  1551. {
  1552. printf( "\nOption LookupVolId\n"
  1553. " Purpose: Look up a volume ID from the DC volume table\n"
  1554. " Usage: -lookupvolid <stringized volume ID>\n"
  1555. " E.g. -lookupvolid {56730825-3ddc-11d2-a168-00805ffe11b8}\n"
  1556. " Note: The services\\trkwks\\parameters\\configuration\\trkflags\n"
  1557. " reg value must have the 0x1 bit set before trkwks is started.\n" );
  1558. *pcEaten = 1;
  1559. return( TRUE );
  1560. }
  1561. *pcEaten = 1;
  1562. // Convert the volid string to a volid
  1563. stringize.Use( rgptszArgs[0] );
  1564. volid = stringize;
  1565. if( CVolumeId() == volid )
  1566. {
  1567. _tprintf( TEXT("Error: Invalid volume ID\n") );
  1568. return( FALSE );
  1569. }
  1570. // Send the delete request
  1571. rc.RcInitialize( mcidLocal, s_tszTrkWksLocalRpcProtocol, s_tszTrkWksLocalRpcEndPoint, NO_AUTHENTICATION );
  1572. __try
  1573. {
  1574. Msg.MessageType = SYNC_VOLUMES;
  1575. Msg.ptszMachineID = NULL;
  1576. Msg.Priority = PRI_9;
  1577. Msg.SyncVolumes.cVolumes = 1;
  1578. Msg.SyncVolumes.pVolumes = &SyncVolume;
  1579. SyncVolume.hr = S_OK;
  1580. SyncVolume.SyncType = FIND_VOLUME;
  1581. SyncVolume.volume = volid;
  1582. hr = LnkCallSvrMessage( rc, &Msg );
  1583. }
  1584. __except( EXCEPTION_EXECUTE_HANDLER )
  1585. {
  1586. hr = HRESULT_FROM_WIN32(GetLastError());
  1587. }
  1588. if( SUCCEEDED(hr) )
  1589. hr = SyncVolume.hr;
  1590. if( FAILED(hr) )
  1591. _tprintf( TEXT("Error: %08x\n"), hr );
  1592. else
  1593. {
  1594. if( S_OK != hr )
  1595. _tprintf( TEXT("Success code is %08x\n"), hr );
  1596. _tprintf( TEXT("Machine = \"%s\"\n"), static_cast<const TCHAR*>(CStringize(SyncVolume.machine)) );
  1597. }
  1598. if( FAILED(hr) )
  1599. printf( "Failed: hr = %08x\n", hr );
  1600. return( SUCCEEDED(hr) );
  1601. }
  1602. BOOL
  1603. DltAdminLookupDroid( ULONG cArgs, const TCHAR * const rgptszArgs[], ULONG *pcEaten )
  1604. {
  1605. CVolumeId volid;
  1606. CStringize stringize;
  1607. CRpcClientBinding rc;
  1608. TRK_FILE_TRACKING_INFORMATION FileTrackingInformation;
  1609. TRKSVR_MESSAGE_UNION Msg;
  1610. CDomainRelativeObjId droid;
  1611. CMachineId mcidLocal( MCID_LOCAL );
  1612. HRESULT hr = S_OK;
  1613. if( 0 == cArgs )
  1614. {
  1615. printf( "Missing parameter: a DROID must be specified\n"
  1616. "(in \"{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}\" form)\n" );
  1617. *pcEaten = 0;
  1618. return( FALSE );
  1619. }
  1620. _tprintf( TEXT("Searching for move ID %s in DC volume table\n"), rgptszArgs[0] );
  1621. if( IsHelpArgument( rgptszArgs[0] ))
  1622. {
  1623. printf( "\nOption LookupDroid\n"
  1624. " Purpose: Look up a DROID from the DC move table\n"
  1625. " Usage: -lookupdroid <stringized DROIID>\n"
  1626. " E.g. -lookupdroid {f8b534f0-b65b-11d2-8fd8-0008c709d19e}{0ed45deb-03ed-11d3-b766-00805ffe11b8}\n"
  1627. " Note: You must be running as an administrator\n" );
  1628. *pcEaten = 1;
  1629. return( TRUE );
  1630. }
  1631. *pcEaten = 1;
  1632. stringize.Use( rgptszArgs[0] );
  1633. droid = stringize;
  1634. if( CDomainRelativeObjId() == droid )
  1635. {
  1636. _tprintf( TEXT("Error: Invalid birth ID\n") );
  1637. return( FALSE );
  1638. }
  1639. rc.RcInitialize( mcidLocal, s_tszTrkWksLocalRpcProtocol, s_tszTrkWksLocalRpcEndPoint, NO_AUTHENTICATION );
  1640. __try
  1641. {
  1642. memset( &FileTrackingInformation, 0, sizeof(FileTrackingInformation) );
  1643. FileTrackingInformation.droidLast = droid;
  1644. Msg.MessageType = SEARCH;
  1645. Msg.ptszMachineID = NULL;
  1646. Msg.Priority = PRI_5;
  1647. Msg.Search.cSearch = 1;
  1648. Msg.Search.pSearches = &FileTrackingInformation;
  1649. LnkCallSvrMessage(rc, &Msg);
  1650. }
  1651. __except( EXCEPTION_EXECUTE_HANDLER )
  1652. {
  1653. hr = HRESULT_FROM_WIN32(GetExceptionCode());
  1654. }
  1655. if( SUCCEEDED(hr) )
  1656. hr = FileTrackingInformation.hr;
  1657. if( FAILED(hr) )
  1658. _tprintf( TEXT("Error: %08x\n"), hr );
  1659. else
  1660. {
  1661. if( S_OK != hr )
  1662. _tprintf( TEXT("Success code is %08x\n"), hr );
  1663. _tprintf( TEXT("Machine = \"%s\"\n"), static_cast<const TCHAR*>(CStringize(FileTrackingInformation.mcidLast)) );
  1664. }
  1665. return( TRUE );
  1666. }
  1667. EXTERN_C void __cdecl _tmain( int cArgs, TCHAR *prgtszArg[])
  1668. {
  1669. HRESULT hr = S_OK;
  1670. NTSTATUS status = STATUS_SUCCESS;
  1671. int iArg = 0;
  1672. int iError = 0;
  1673. OLECHAR oszOID[ CCH_GUID_STRING + 1 ];
  1674. TrkDebugCreate( TRK_DBG_FLAGS_WRITE_TO_DBG, "DltAdmin" );
  1675. hr = CoInitialize( NULL );
  1676. if (FAILED(hr))
  1677. {
  1678. _tprintf( TEXT("Unable to CoInitialize( NULL )-- aborting. (0x%08x)\n"),
  1679. hr );
  1680. return;
  1681. }
  1682. TCHAR tszStringizedTime[ 80 ];
  1683. __try
  1684. {
  1685. // Skip over the executable name
  1686. iArg++;
  1687. cArgs--;
  1688. if( 0 == cArgs )
  1689. {
  1690. Usage();
  1691. exit(1);
  1692. }
  1693. for( ; iArg <= cArgs; cArgs--, iArg++ )
  1694. {
  1695. ULONG cEaten = 0;
  1696. if( TEXT('-') != prgtszArg[iArg][0]
  1697. &&
  1698. TEXT('/') != prgtszArg[iArg][0] )
  1699. {
  1700. _tprintf( TEXT("Invalid option, ignoring: %s\n"), prgtszArg[iArg] );
  1701. iError = max( iError, 1 );
  1702. continue;
  1703. }
  1704. if( !_tcsicmp( TEXT("deldcvolid"), &prgtszArg[iArg][1] ) )
  1705. {
  1706. iArg++;
  1707. cArgs--;
  1708. if( !DeleteIdFromVolumeTable( cArgs, &prgtszArg[iArg], &cEaten ))
  1709. iError = max( iError, 2 );
  1710. iArg += cEaten;
  1711. cArgs -= cEaten;
  1712. }
  1713. else if( !_tcsicmp( TEXT("deldcmoveid"), &prgtszArg[iArg][1] ))
  1714. {
  1715. iArg++;
  1716. cArgs--;
  1717. if( !DeleteIdFromMoveTable( cArgs, &prgtszArg[iArg], &cEaten ))
  1718. iError = max( iError, 2 );
  1719. iArg += cEaten;
  1720. cArgs -= cEaten;
  1721. }
  1722. else if( !_tcsicmp( TEXT("lookupvolid"), &prgtszArg[iArg][1] ))
  1723. {
  1724. iArg++;
  1725. cArgs--;
  1726. if( !DltAdminLookupVolId( cArgs, &prgtszArg[iArg], &cEaten ))
  1727. iError = max( iError, 2 );
  1728. iArg += cEaten;
  1729. cArgs -= cEaten;
  1730. }
  1731. else if( !_tcsicmp( TEXT("lookupdroid"), &prgtszArg[iArg][1] ))
  1732. {
  1733. iArg++;
  1734. cArgs--;
  1735. if( !DltAdminLookupDroid( cArgs, &prgtszArg[iArg], &cEaten ))
  1736. iError = max( iError, 2 );
  1737. iArg += cEaten;
  1738. cArgs -= cEaten;
  1739. }
  1740. else if( !_tcsicmp( TEXT("volinfofile"), &prgtszArg[iArg][1] ))
  1741. {
  1742. iArg++;
  1743. cArgs--;
  1744. if( !DltAdminVolInfoFile( cArgs, &prgtszArg[iArg], &cEaten ))
  1745. iError = max( iError, 2 );
  1746. iArg += cEaten;
  1747. cArgs -= cEaten;
  1748. }
  1749. else if( !_tcsicmp( TEXT("cleanvol"), &prgtszArg[iArg][1] ))
  1750. {
  1751. iArg++;
  1752. cArgs--;
  1753. if( !DltAdminCleanVol( cArgs, &prgtszArg[iArg], &cEaten ))
  1754. iError = max( iError, 2 );
  1755. iArg += cEaten;
  1756. cArgs -= cEaten;
  1757. }
  1758. else if( !_tcsicmp( TEXT("svrstat"), &prgtszArg[iArg][1] ))
  1759. {
  1760. iArg++;
  1761. cArgs--;
  1762. if( !DltAdminSvrStat( cArgs, &prgtszArg[iArg], &cEaten ))
  1763. iError = max( iError, 2 );
  1764. iArg += cEaten;
  1765. cArgs -= cEaten;
  1766. }
  1767. else if( !_tcsicmp( TEXT("volstat"), &prgtszArg[iArg][1] ))
  1768. {
  1769. iArg++;
  1770. cArgs--;
  1771. if( !VolumeStatistics( cArgs, &prgtszArg[iArg], &cEaten ))
  1772. iError = max( iError, 2 );
  1773. iArg += cEaten;
  1774. cArgs -= cEaten;
  1775. }
  1776. else if( !_tcsicmp( TEXT("volid"), &prgtszArg[iArg][1] ))
  1777. {
  1778. iArg++;
  1779. cArgs--;
  1780. if( !VolumeIdSetOrGet( cArgs, &prgtszArg[iArg], &cEaten ))
  1781. iError = max( iError, 2 );
  1782. iArg += cEaten;
  1783. cArgs -= cEaten;
  1784. }
  1785. else if( !_tcsicmp( TEXT("lockvol"), &prgtszArg[iArg][1] ))
  1786. {
  1787. iArg++;
  1788. cArgs--;
  1789. if( !DltAdminLockVol( cArgs, &prgtszArg[iArg], &cEaten ))
  1790. iError = max( iError, 2 );
  1791. iArg += cEaten;
  1792. cArgs -= cEaten;
  1793. }
  1794. else if( !_tcsicmp( TEXT("fileoid"), &prgtszArg[iArg][1] ))
  1795. {
  1796. iArg++;
  1797. cArgs--;
  1798. if( !DltAdminFileOid( cArgs, &prgtszArg[iArg], &cEaten ))
  1799. iError = max( iError, 2 );
  1800. iArg += cEaten;
  1801. cArgs -= cEaten;
  1802. }
  1803. else if( !_tcsicmp( TEXT("enumoids"), &prgtszArg[iArg][1] ))
  1804. {
  1805. iArg++;
  1806. cArgs--;
  1807. if( !DltAdminEnumOids( cArgs, &prgtszArg[iArg], &cEaten ))
  1808. iError = max( iError, 2 );
  1809. iArg += cEaten;
  1810. cArgs -= cEaten;
  1811. }
  1812. else if( !_tcsicmp( TEXT("oidsnap"), &prgtszArg[iArg][1] ))
  1813. {
  1814. iArg++;
  1815. cArgs--;
  1816. if( !DltAdminOidSnap( cArgs, &prgtszArg[iArg], &cEaten ))
  1817. iError = max( iError, 2 );
  1818. iArg += cEaten;
  1819. cArgs -= cEaten;
  1820. }
  1821. else if( !_tcsicmp( TEXT("link"), &prgtszArg[iArg][1] ))
  1822. {
  1823. iArg++;
  1824. cArgs--;
  1825. if( !DltAdminLink( cArgs, &prgtszArg[iArg], &cEaten ))
  1826. iError = max( iError, 2 );
  1827. iArg += cEaten;
  1828. cArgs -= cEaten;
  1829. }
  1830. else if( !_tcsicmp( TEXT("loadlib"), &prgtszArg[iArg][1] ))
  1831. {
  1832. iArg++;
  1833. cArgs--;
  1834. if( !DltAdminProcessAction( LOAD_LIBRARY, cArgs, &prgtszArg[iArg], &cEaten ))
  1835. iError = max( iError, 2 );
  1836. iArg += cEaten;
  1837. cArgs -= cEaten;
  1838. }
  1839. else if( !_tcsicmp( TEXT("freelib"), &prgtszArg[iArg][1] ))
  1840. {
  1841. iArg++;
  1842. cArgs--;
  1843. if( !DltAdminProcessAction( FREE_LIBRARY, cArgs, &prgtszArg[iArg], &cEaten ))
  1844. iError = max( iError, 2 );
  1845. iArg += cEaten;
  1846. cArgs -= cEaten;
  1847. }
  1848. else if( !_tcsicmp( TEXT("debugbreak"), &prgtszArg[iArg][1] ))
  1849. {
  1850. iArg++;
  1851. cArgs--;
  1852. if( !DltAdminProcessAction( DEBUG_BREAK, cArgs, &prgtszArg[iArg], &cEaten ))
  1853. iError = max( iError, 2 );
  1854. iArg += cEaten;
  1855. cArgs -= cEaten;
  1856. }
  1857. else if( !_tcsicmp( TEXT("createprocess"), &prgtszArg[iArg][1] ))
  1858. {
  1859. iArg++;
  1860. cArgs--;
  1861. if( !DltAdminProcessAction( CREATE_PROCESS, cArgs, &prgtszArg[iArg], &cEaten ))
  1862. iError = max( iError, 2 );
  1863. iArg += cEaten;
  1864. cArgs -= cEaten;
  1865. }
  1866. else if( !_tcsicmp( TEXT("config"), &prgtszArg[iArg][1] ))
  1867. {
  1868. iArg++;
  1869. cArgs--;
  1870. if( !DltAdminConfig( cArgs, &prgtszArg[iArg], &cEaten ))
  1871. iError = max( iError, 2 );
  1872. iArg += cEaten;
  1873. cArgs -= cEaten;
  1874. }
  1875. else if( !_tcsicmp( TEXT("refresh"), &prgtszArg[iArg][1] ))
  1876. {
  1877. iArg++;
  1878. cArgs--;
  1879. if( !DltAdminRefresh( cArgs, &prgtszArg[iArg], &cEaten ))
  1880. iError = max( iError, 2 );
  1881. iArg += cEaten;
  1882. cArgs -= cEaten;
  1883. }
  1884. else if( !_tcsicmp( TEXT("setvolseq"), &prgtszArg[iArg][1] ))
  1885. {
  1886. iArg++;
  1887. cArgs--;
  1888. if( !DltAdminSetVolumeSeqNumber( cArgs, &prgtszArg[iArg], &cEaten ))
  1889. iError = max( iError, 2 );
  1890. iArg += cEaten;
  1891. cArgs -= cEaten;
  1892. }
  1893. else if( !_tcsicmp( TEXT("setdroidseq"), &prgtszArg[iArg][1] ))
  1894. {
  1895. iArg++;
  1896. cArgs--;
  1897. if( !DltAdminSetDroidSeqNumber( cArgs, &prgtszArg[iArg], &cEaten ))
  1898. iError = max( iError, 2 );
  1899. iArg += cEaten;
  1900. cArgs -= cEaten;
  1901. }
  1902. else if( !_tcsicmp( TEXT("backupread"), &prgtszArg[iArg][1] ))
  1903. {
  1904. iArg++;
  1905. cArgs--;
  1906. if( !DltAdminBackupRead( cArgs, &prgtszArg[iArg], &cEaten ))
  1907. iError = max( iError, 2 );
  1908. iArg += cEaten;
  1909. cArgs -= cEaten;
  1910. }
  1911. else if( !_tcsicmp( TEXT("backupwrite"), &prgtszArg[iArg][1] ))
  1912. {
  1913. iArg++;
  1914. cArgs--;
  1915. if( !DltAdminBackupWrite( cArgs, &prgtszArg[iArg], &cEaten ))
  1916. iError = max( iError, 2 );
  1917. iArg += cEaten;
  1918. cArgs -= cEaten;
  1919. }
  1920. else if( !_tcsicmp( TEXT("sleep"), &prgtszArg[iArg][1] ))
  1921. {
  1922. iArg++;
  1923. cArgs--;
  1924. Sleep( 1000 );
  1925. }
  1926. else if( !_tcsicmp( TEXT("temp"), &prgtszArg[iArg][1] ))
  1927. {
  1928. if( !DltAdminTemp( cArgs, &prgtszArg[iArg], &cEaten ))
  1929. iError = max( iError, 2 );
  1930. iArg += cEaten;
  1931. cArgs -= cEaten;
  1932. }
  1933. else if( !_tcsicmp( TEXT("temp2"), &prgtszArg[iArg][1] ))
  1934. {
  1935. if( !DltAdminTemp2( cArgs, &prgtszArg[iArg], &cEaten ))
  1936. iError = max( iError, 2 );
  1937. iArg += cEaten;
  1938. cArgs -= cEaten;
  1939. }
  1940. else if( !_tcsicmp( TEXT("temp3"), &prgtszArg[iArg][1] ))
  1941. {
  1942. if( !DltAdminTemp3( cArgs, &prgtszArg[iArg], &cEaten ))
  1943. iError = max( iError, 2 );
  1944. iArg += cEaten;
  1945. cArgs -= cEaten;
  1946. }
  1947. else if( TEXT('?') == prgtszArg[iArg][1] )
  1948. {
  1949. Usage();
  1950. exit( 1 );
  1951. }
  1952. else
  1953. {
  1954. _tprintf( TEXT("Invalid option, ignoring: %s\n"), prgtszArg[iArg] );
  1955. iError = max( iError, 1 );
  1956. continue;
  1957. }
  1958. }
  1959. }
  1960. __except( BreakOnDebuggableException() )
  1961. {
  1962. hr = GetExceptionCode();
  1963. iError = max( iError, 2 );
  1964. }
  1965. if( FAILED(hr) )
  1966. printf( "HR = %08X\n", hr );
  1967. CoUninitialize();
  1968. // return( iError );
  1969. } // main()