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.

2321 lines
57 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. apitest.c
  5. Abstract:
  6. Program to test CSC apis.
  7. Author:
  8. Shishir Pardikar (shishirp) 4-24-97
  9. Environment:
  10. User Mode - Win32
  11. Revision History:
  12. --*/
  13. #ifdef CSC_ON_NT
  14. #include <nt.h>
  15. #include <ntrtl.h>
  16. #include <nturtl.h>
  17. #else
  18. typedef const char * LPCSTR;
  19. #endif
  20. #include <windows.h>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #include <time.h>
  25. #include <cscapi.h>
  26. #include "lmcons.h"
  27. #include "lmuse.h"
  28. //#include <timelog.h>
  29. //=================================================================================
  30. #define MAX_COMMAND_ARGS 32
  31. #define DEFAULT_BUFFER_SIZE 1024 // 1k
  32. //=================================================================================
  33. // The order of these must match the order in GlobalCommandInfo[]
  34. typedef enum _COMMAND_CODE {
  35. CmdCSCPinFile,
  36. CmdCSCUnPinFile,
  37. CmdCSCQueryFileStatus,
  38. CmdCSCEnum,
  39. CmdCSCDelete,
  40. CmdCSCFill,
  41. CmdCSCMerge,
  42. CmdCSCCopyReplica,
  43. CmdTimeLog,
  44. CmdCheckCSC,
  45. CmdDbCheckCSC,
  46. CmdCSCEnumForStats,
  47. CmdCSCDoLocalRename,
  48. CmdCSCDoEnableDisable,
  49. CmdShowTime,
  50. CmdEncryptDecrypt,
  51. CmdDoRandomWrites,
  52. CmdHelp,
  53. CmdQuit,
  54. UnknownCommand
  55. } COMMAND_CODE, *LPCOMMAND_CODE;
  56. typedef struct _COMMAND_INFO {
  57. LPSTR CommandName;
  58. LPSTR CommandParams;
  59. COMMAND_CODE CommandCode;
  60. } COMMAND_INFO, *LPCOMMAND_INFO;
  61. typedef VOID (*PRINTPROC)(LPSTR);
  62. #ifndef CSC_ON_NT
  63. typedef BOOL (*CHECKCSCEX)(LPSTR, LPCSCPROCA, DWORD, DWORD);
  64. #else
  65. typedef BOOL (*CHECKCSCEX)(LPSTR, LPCSCPROCW, DWORD, DWORD);
  66. #endif
  67. // If Count is not already aligned, then
  68. // round Count up to an even multiple of "Pow2". "Pow2" must be a power of 2.
  69. //
  70. // DWORD
  71. // ROUND_UP_COUNT(
  72. // IN DWORD Count,
  73. // IN DWORD Pow2
  74. // );
  75. #define ROUND_UP_COUNT(Count,Pow2) \
  76. ( ((Count)+(Pow2)-1) & (~((Pow2)-1)) )
  77. #define ALIGN_WCHAR sizeof(WCHAR)
  78. //=================================================================================
  79. FILE *UncList = NULL;
  80. LPSTR g_lpWriteFileBuf = NULL;
  81. FILE *DumpUncList = NULL;
  82. DWORD cCommands = 0;
  83. DWORD cFails = 0;
  84. DWORD g_dwNumIterations = 1;
  85. DWORD g_dwIteration = 0;
  86. DWORD g_dwNumCmdIterations = 1;
  87. DWORD g_dwCmdIteration = 0;
  88. DWORD g_dwFileSize = 0;
  89. DWORD g_dwDiskCache = 0;
  90. BOOL g_bWriteFile = FALSE;
  91. BOOL g_bQuietMode = FALSE;
  92. BOOL g_bPerfMode = FALSE;
  93. BOOL g_bUseFile = FALSE;
  94. char szDefaultTimeLogFile[] = "c:\\debug\\kd.log";
  95. char vszFile[] = "C:\\WINNT\\private\\ntos\\rdr2\\csc\\usermode\\reint\\foo";
  96. WCHAR vwzFileName[] = L"\\\\shishir1\\public\\foo.txt";
  97. COMMAND_INFO GlobalCommandInfo[] = {
  98. {"pin", "UNCName", CmdCSCPinFile},
  99. {"unpin", "UNCName", CmdCSCUnPinFile},
  100. {"query", "UNCName", CmdCSCQueryFileStatus},
  101. {"Enum", "UNCName or nothing", CmdCSCEnum},
  102. {"Del", "UNCName", CmdCSCDelete},
  103. {"Fill", "UNCName", CmdCSCFill},
  104. {"Merge", "\\\\Server\\Share", CmdCSCMerge},
  105. {"Move", "UNCNAME", CmdCSCCopyReplica},
  106. {"tlog", "logfile", CmdTimeLog},
  107. {"check", "\\\\Server\\Share", CmdCheckCSC},
  108. {"dbcheck", "dbdir <0 (verify) or 1 (fix)>", CmdDbCheckCSC},
  109. {"stats", "" , CmdCSCEnumForStats},
  110. {"Ren", "ren src containing_dst_dir [1:-replace files]", CmdCSCDoLocalRename},
  111. {"EnDis", "0 (disable) or 1 enable", CmdCSCDoEnableDisable},
  112. {"ShowTime", "HHHHHHHH LLLLLLLL (Hex HighDateTime and LowDateTime)", CmdShowTime},
  113. {"EncDec", "U (decrypt) anything else=> encrypt", CmdEncryptDecrypt},
  114. {"RandW", "Randw filename", CmdDoRandomWrites},
  115. {"Help", "", CmdHelp},
  116. {"Quit", "", CmdQuit}
  117. };
  118. LPSTR rgszNameArray[] =
  119. {
  120. "EditRecordEx",
  121. "AddFileRecordFR",
  122. "DeleteFileRecFromInode",
  123. "FindFileRecord",
  124. "UpdateFileRecordFR",
  125. "AddPriQRecord",
  126. "DeletePriQRecord",
  127. "FindPriQRecordInternal",
  128. "SetPriorityForInode",
  129. "CreateShadowInternal",
  130. "GetShadow",
  131. "GetShadowInfo",
  132. "SetShadowInfoInternal",
  133. "ChangePriEntryStatusHSHADOW",
  134. "MRxSmbCscCreateShadowFromPath",
  135. "MRxSmbGetFileInfoFromServer",
  136. "EditRecordEx_OpenFileLocal",
  137. "EditRecordEx_Lookup",
  138. "KeAttachProcess_R0Open",
  139. "IoCreateFile_R0Open",
  140. "KeDetachProcess_R0Open",
  141. "KeAttachProcess_R0Read",
  142. "R0ReadWrite",
  143. "KeDetachProcess_R0Read",
  144. "FindQRecordInsertionPoint_Addq",
  145. "LinkQRecord_Addq",
  146. "UnlinkQRecord_Addq",
  147. "FindQRecordInsertionPoint_Addq_dir",
  148. "EditRecordEx_Validate",
  149. "EditRecordEx_dat"
  150. };
  151. typedef struct tagCSCSTATS{
  152. DWORD dwTotal;
  153. DWORD dwTotalFiles;
  154. DWORD dwTotalDirs;
  155. DWORD dwSparseFiles;
  156. DWORD dwDirtyFiles;
  157. DWORD dwPinned;
  158. DWORD dwPinnedAndSparse;
  159. DWORD dwMismatched;
  160. } CSCSTATS, *LPCSCSTATS;
  161. DWORD WINAPIV Format_String(LPSTR *plpsz, LPSTR lpszFmt, ...);
  162. DWORD WINAPI Format_Error(DWORD dwErr, LPSTR *plpsz);
  163. DWORD WINAPI Format_StringV(LPSTR *plpsz, LPCSTR lpszFmt, va_list *vArgs);
  164. DWORD WINAPI Format_MessageV(DWORD dwFlags, DWORD dwErr, LPSTR *plpsz, LPCSTR lpszFmt, va_list *vArgs);
  165. VOID PrintBuffer(
  166. LPSTR lpszBuff
  167. );
  168. BOOL WINAPI CheckCSC(LPSTR lpszDataBaseLocation, BOOL fFix);
  169. BOOL
  170. DoPinningA(
  171. LPSTR lpszName,
  172. DWORD dwHintFlags,
  173. BOOL fRecurse
  174. );
  175. BOOL
  176. DoPinningW(
  177. LPWSTR lpwzName,
  178. DWORD dwHintFlags,
  179. BOOL fRecurse
  180. );
  181. DWORD
  182. ProcessShowTime (
  183. DWORD argc,
  184. LPSTR *argv
  185. );
  186. DWORD
  187. ProcessEncryptDecrypt(
  188. DWORD argc,
  189. LPSTR *argv
  190. );
  191. //=================================================================================
  192. DWORD
  193. ProcessCommandCode (
  194. DWORD CommandCode,
  195. DWORD CommandArgc,
  196. LPSTR *CommandArgv
  197. );
  198. DWORD
  199. GetLeafLenFromPath(
  200. LPSTR lpszPath
  201. );
  202. BOOL
  203. GetStreamInformation(
  204. LPCSTR lpExistingFileName,
  205. LPVOID *lpStreamInformation
  206. );
  207. //=================================================================================
  208. #if DBG
  209. #define TestDbgAssert(Predicate) \
  210. { \
  211. if (!(Predicate)) \
  212. TestDbgAssertFailed( #Predicate, __FILE__, __LINE__, NULL ); \
  213. }
  214. VOID
  215. TestDbgAssertFailed(
  216. LPSTR FailedAssertion,
  217. LPSTR FileName,
  218. DWORD LineNumber,
  219. LPSTR Message
  220. )
  221. /*++
  222. Routine Description:
  223. Assertion failed.
  224. Arguments:
  225. FailedAssertion :
  226. FileName :
  227. LineNumber :
  228. Message :
  229. Return Value:
  230. none.
  231. --*/
  232. {
  233. printf("Assert @ %s \n", FailedAssertion );
  234. printf("Assert Filename, %s \n", FileName );
  235. printf("Line Num. = %ld.\n", LineNumber );
  236. printf("Message is %s\n", Message );
  237. DebugBreak();
  238. }
  239. #else
  240. #define TestDbgAssert(_x_)
  241. #endif // DBG
  242. //=================================================================================
  243. VOID
  244. ParseArguments(
  245. LPSTR InBuffer,
  246. LPSTR *CArgv,
  247. LPDWORD CArgc
  248. )
  249. {
  250. LPSTR CurrentPtr = InBuffer;
  251. DWORD i = 0;
  252. DWORD Cnt = 0;
  253. for ( ;; ) {
  254. //
  255. // skip blanks.
  256. //
  257. while( *CurrentPtr == ' ' ) {
  258. CurrentPtr++;
  259. }
  260. if( *CurrentPtr == '\0' ) {
  261. break;
  262. }
  263. CArgv[i++] = CurrentPtr;
  264. //
  265. // go to next space.
  266. //
  267. while( (*CurrentPtr != '\0') &&
  268. (*CurrentPtr != '\n') ) {
  269. if( *CurrentPtr == '"' ) { // Deal with simple quoted args
  270. if( Cnt == 0 )
  271. CArgv[i-1] = ++CurrentPtr; // Set arg to after quote
  272. else
  273. *CurrentPtr = '\0'; // Remove end quote
  274. Cnt = !Cnt;
  275. }
  276. if( (Cnt == 0) && (*CurrentPtr == ' ') || // If we hit a space and no quotes yet we are done with this arg
  277. (*CurrentPtr == '\0') )
  278. break;
  279. CurrentPtr++;
  280. }
  281. if( *CurrentPtr == '\0' ) {
  282. break;
  283. }
  284. *CurrentPtr++ = '\0';
  285. }
  286. *CArgc = i;
  287. return;
  288. }
  289. #ifdef MAYBE
  290. //=================================================================================
  291. LPSTR
  292. GetUncFromFile ()
  293. {
  294. if (!UncList)
  295. {
  296. UncList = fopen ("Unclist", "r");
  297. if (UncList == NULL)
  298. return NULL;
  299. }
  300. if (fgets( UncBuffer, DEFAULT_BUFFER_SIZE, UncList))
  301. {
  302. UncBuffer[strlen(UncBuffer) -1] = '\0'; //kill line feed for no param cmds
  303. return UncBuffer;
  304. }
  305. else
  306. {
  307. fclose (UncList);
  308. UncList = NULL;
  309. return GetUncFromFile();
  310. }
  311. }
  312. #endif
  313. //=================================================================================
  314. COMMAND_CODE
  315. DecodeCommand(
  316. LPSTR CommandName
  317. )
  318. {
  319. DWORD i;
  320. DWORD NumCommands;
  321. NumCommands = sizeof(GlobalCommandInfo) / sizeof(COMMAND_INFO);
  322. TestDbgAssert( NumCommands <= UnknownCommand );
  323. for( i = 0; i < NumCommands; i++) {
  324. if(( lstrcmpi( CommandName, GlobalCommandInfo[i].CommandName ) == 0 )){
  325. return( GlobalCommandInfo[i].CommandCode );
  326. }
  327. }
  328. return( UnknownCommand );
  329. }
  330. //=================================================================================
  331. VOID
  332. PrintCommands(
  333. VOID
  334. )
  335. {
  336. DWORD i;
  337. DWORD NumCommands;
  338. NumCommands = sizeof(GlobalCommandInfo) / sizeof(COMMAND_INFO);
  339. TestDbgAssert( NumCommands <= UnknownCommand );
  340. for( i = 0; i < NumCommands; i++) {
  341. fprintf(stderr, " %s (%s)\n",
  342. GlobalCommandInfo[i].CommandName,
  343. GlobalCommandInfo[i].CommandParams );
  344. }
  345. }
  346. //=================================================================================
  347. VOID
  348. DisplayUsage(
  349. VOID
  350. )
  351. {
  352. fprintf(stderr, "Usage: command <command parameters>\n" );
  353. fprintf(stderr, "Commands : \n");
  354. PrintCommands();
  355. return;
  356. }
  357. //=================================================================================
  358. FILETIME
  359. GetGmtTime(
  360. VOID
  361. )
  362. {
  363. SYSTEMTIME SystemTime;
  364. FILETIME Time;
  365. GetSystemTime( &SystemTime );
  366. SystemTimeToFileTime( &SystemTime, &Time );
  367. return( Time );
  368. }
  369. //=================================================================================
  370. LPSTR
  371. ConvertGmtTimeToString(
  372. FILETIME Time,
  373. LPSTR OutputBuffer
  374. )
  375. {
  376. SYSTEMTIME SystemTime;
  377. FILETIME LocalTime;
  378. static FILETIME ftNone = {0, 0};
  379. if (!memcmp (&Time, &ftNone, sizeof(FILETIME)))
  380. sprintf (OutputBuffer, "<none>");
  381. else
  382. {
  383. FileTimeToLocalFileTime( &Time , &LocalTime );
  384. FileTimeToSystemTime( &LocalTime, &SystemTime );
  385. sprintf( OutputBuffer,
  386. "%02u/%02u/%04u %02u:%02u:%02u ",
  387. SystemTime.wMonth,
  388. SystemTime.wDay,
  389. SystemTime.wYear,
  390. SystemTime.wHour,
  391. SystemTime.wMinute,
  392. SystemTime.wSecond );
  393. }
  394. return( OutputBuffer );
  395. }
  396. void
  397. PrintCSCEntryInfo(
  398. WIN32_FIND_DATA *lpFind32,
  399. DWORD dwStatus,
  400. DWORD dwPinCount,
  401. DWORD dwHintFlags,
  402. FILETIME *lpftOrgTime
  403. )
  404. {
  405. char buff[128];
  406. fprintf(stderr, "\n");
  407. if (lpFind32)
  408. {
  409. fprintf(stderr, "LFN: %s\n", lpFind32->cFileName);
  410. fprintf(stderr, "SFN: %s\n", lpFind32->cAlternateFileName);
  411. fprintf(stderr, "Attr: %x\n", lpFind32->dwFileAttributes);
  412. fprintf(stderr, "Size: %d %d\n", lpFind32->nFileSizeHigh, lpFind32->nFileSizeLow);
  413. ConvertGmtTimeToString(lpFind32->ftLastWriteTime, buff);
  414. fprintf(stderr, "LastWriteTime: %s\n", buff);
  415. }
  416. if (lpftOrgTime)
  417. {
  418. ConvertGmtTimeToString(*lpftOrgTime, buff);
  419. fprintf(stderr, "ORGTime: %s\n", buff);
  420. }
  421. fprintf(stderr, "Status: %x\n", dwStatus);
  422. fprintf(stderr, "PinCount: %x\n", dwPinCount);
  423. fprintf(stderr, "PinFlags: %x\n", dwHintFlags);
  424. fprintf(stderr, "\n");
  425. }
  426. void
  427. PrintCSCEntryInfoW(
  428. WIN32_FIND_DATAW *lpFind32,
  429. DWORD dwStatus,
  430. DWORD dwPinCount,
  431. DWORD dwHintFlags,
  432. FILETIME *lpftOrgTime
  433. )
  434. {
  435. WIN32_FIND_DATA *lpFind32P = NULL;
  436. fprintf(stderr, "\n");
  437. if (lpFind32)
  438. {
  439. WIN32_FIND_DATA sFind32;
  440. lpFind32P = &sFind32;
  441. memset(&sFind32, 0, sizeof(WIN32_FIND_DATAA));
  442. memcpy(&sFind32, lpFind32, sizeof(WIN32_FIND_DATAA)-sizeof(sFind32.cFileName)-sizeof(sFind32.cAlternateFileName));
  443. WideCharToMultiByte(CP_ACP, 0, lpFind32->cFileName, wcslen(lpFind32->cFileName), sFind32.cFileName, sizeof(sFind32.cFileName), NULL, NULL);
  444. WideCharToMultiByte(CP_OEMCP, 0, lpFind32->cAlternateFileName, wcslen(lpFind32->cAlternateFileName), sFind32.cAlternateFileName, sizeof(sFind32.cAlternateFileName), NULL, NULL);
  445. }
  446. PrintCSCEntryInfo( lpFind32P,
  447. dwStatus,
  448. dwPinCount,
  449. dwHintFlags,
  450. lpftOrgTime
  451. );
  452. }
  453. DWORD
  454. MyCSCProc(
  455. const char *lpszFullPath,
  456. DWORD dwStatus,
  457. DWORD dwHintFlags,
  458. DWORD dwPinCount,
  459. WIN32_FIND_DATAA *lpFind32,
  460. DWORD dwReason,
  461. DWORD dwParam1,
  462. DWORD dwParam2,
  463. DWORD dwContext
  464. )
  465. {
  466. if (dwReason==CSCPROC_REASON_BEGIN)
  467. {
  468. printf("CSCPROC:Name=%s Status=0x%x HintFlags=0x%x PinCount=%d Reason=%d Param1=%d Param2=%d\r\n",
  469. (lpszFullPath)?lpszFullPath:"None",
  470. dwStatus,
  471. dwHintFlags,
  472. dwPinCount,
  473. dwReason,
  474. dwParam1,
  475. dwParam2
  476. );
  477. }
  478. else if (dwReason==CSCPROC_REASON_MORE_DATA)
  479. {
  480. printf(".");
  481. }
  482. else
  483. {
  484. printf("\r\n");
  485. if (dwParam2==ERROR_SUCCESS)
  486. {
  487. printf("Succeeded\r\n");
  488. }
  489. else
  490. {
  491. printf("Error=%d \r\n", dwParam2);
  492. }
  493. }
  494. return (CSCPROC_RETURN_CONTINUE);
  495. }
  496. DWORD
  497. MyCSCProcW(
  498. const unsigned short *lpszFullPath,
  499. DWORD dwStatus,
  500. DWORD dwHintFlags,
  501. DWORD dwPinCount,
  502. WIN32_FIND_DATAW *lpFind32,
  503. DWORD dwReason,
  504. DWORD dwParam1,
  505. DWORD dwParam2,
  506. DWORD dwContext
  507. )
  508. {
  509. if (dwReason==CSCPROC_REASON_BEGIN)
  510. {
  511. printf("CSCPROC:Name=%ls Status=0x%x HintFlags=0x%x PinCount=%d Reason=%d Param1=%d Param2=%d\r\n",
  512. (lpszFullPath)?lpszFullPath:L"None",
  513. dwStatus,
  514. dwHintFlags,
  515. dwPinCount,
  516. dwReason,
  517. dwParam1,
  518. dwParam2
  519. );
  520. }
  521. else if (dwReason==CSCPROC_REASON_MORE_DATA)
  522. {
  523. printf(".");
  524. }
  525. else
  526. {
  527. printf("\r\n");
  528. if (dwParam2==ERROR_SUCCESS)
  529. {
  530. printf("Succeeded\r\n");
  531. }
  532. else
  533. {
  534. printf("Error=%d \r\n", dwParam2);
  535. }
  536. }
  537. return (CSCPROC_RETURN_CONTINUE);
  538. }
  539. DWORD
  540. MyCSCEnumForStatsProc(
  541. const char *lpszFullPath,
  542. DWORD dwStatus,
  543. DWORD dwHintFlags,
  544. DWORD dwPinCount,
  545. WIN32_FIND_DATAA *lpFind32,
  546. DWORD dwReason,
  547. DWORD dwParam1,
  548. DWORD dwParam2,
  549. DWORD dwContext
  550. )
  551. {
  552. LPCSCSTATS lpStats = (LPCSCSTATS)dwContext;
  553. lpStats->dwTotal++;
  554. if(dwParam1)
  555. {
  556. lpStats->dwTotalFiles++;
  557. if (dwStatus & FLAG_CSC_COPY_STATUS_SPARSE)
  558. {
  559. lpStats->dwSparseFiles++;
  560. }
  561. if (dwStatus & FLAG_CSC_COPY_STATUS_DATA_LOCALLY_MODIFIED)
  562. {
  563. lpStats->dwDirtyFiles++;
  564. }
  565. if ((dwHintFlags & (FLAG_CSC_HINT_PIN_USER|FLAG_CSC_HINT_PIN_SYSTEM))||dwPinCount)
  566. {
  567. lpStats->dwPinned++;
  568. if (dwStatus & FLAG_CSC_COPY_STATUS_SPARSE)
  569. {
  570. lpStats->dwPinnedAndSparse++;
  571. }
  572. }
  573. }
  574. else
  575. {
  576. lpStats->dwTotalDirs++;
  577. }
  578. return (CSCPROC_RETURN_CONTINUE);
  579. }
  580. DWORD
  581. MyCSCEnumForStatsProcW(
  582. const unsigned short *lpszFullPath,
  583. DWORD dwStatus,
  584. DWORD dwHintFlags,
  585. DWORD dwPinCount,
  586. WIN32_FIND_DATAW *lpFind32,
  587. DWORD dwReason,
  588. DWORD dwParam1,
  589. DWORD dwParam2,
  590. DWORD dwContext
  591. )
  592. {
  593. LPCSCSTATS lpStats = (LPCSCSTATS)dwContext;
  594. lpStats->dwTotal++;
  595. if(dwParam1)
  596. {
  597. lpStats->dwTotalFiles++;
  598. if (dwStatus & FLAG_CSC_COPY_STATUS_SPARSE)
  599. {
  600. lpStats->dwSparseFiles++;
  601. }
  602. if (dwStatus & FLAG_CSC_COPY_STATUS_DATA_LOCALLY_MODIFIED)
  603. {
  604. lpStats->dwDirtyFiles++;
  605. }
  606. if ((dwHintFlags & (FLAG_CSC_HINT_PIN_USER|FLAG_CSC_HINT_PIN_SYSTEM))||dwPinCount)
  607. {
  608. lpStats->dwPinned++;
  609. if (dwStatus & FLAG_CSC_COPY_STATUS_SPARSE)
  610. {
  611. lpStats->dwPinnedAndSparse++;
  612. }
  613. }
  614. }
  615. else
  616. {
  617. lpStats->dwTotalDirs++;
  618. }
  619. return (CSCPROC_RETURN_CONTINUE);
  620. }
  621. DWORD
  622. MyCSCCheckExProc(
  623. const char *lpszFullPath,
  624. DWORD dwStatus,
  625. DWORD dwHintFlags,
  626. DWORD dwPinCount,
  627. WIN32_FIND_DATAA *lpFind32,
  628. DWORD dwReason,
  629. DWORD dwParam1,
  630. DWORD dwParam2,
  631. DWORD dwContext
  632. )
  633. {
  634. LPCSCSTATS lpStats = (LPCSCSTATS)dwContext;
  635. if (dwReason == CSCPROC_REASON_BEGIN)
  636. {
  637. if (lpFind32)
  638. {
  639. printf("%s size=%d\r\n", lpszFullPath, lpFind32->nFileSizeLow);
  640. lpStats->dwTotal++;
  641. lpStats->dwTotalFiles++;
  642. }
  643. else
  644. {
  645. printf("%s\r\n", lpszFullPath);
  646. }
  647. }
  648. else if (dwReason == CSCPROC_REASON_END)
  649. {
  650. if (dwParam2 != NO_ERROR)
  651. {
  652. if (dwParam2 == ERROR_INVALID_DATA)
  653. {
  654. printf("Mismatched, press any key to continue...\r\n", dwParam2);
  655. }
  656. else
  657. {
  658. printf("Error in comparing Errcode=%d, press any key to continue...\r\n", dwParam2);
  659. }
  660. getchar();
  661. lpStats->dwMismatched++;
  662. }
  663. }
  664. return (CSCPROC_RETURN_CONTINUE);
  665. }
  666. DWORD
  667. MyCSCCheckExProcW(
  668. const unsigned short *lpszFullPath,
  669. DWORD dwStatus,
  670. DWORD dwHintFlags,
  671. DWORD dwPinCount,
  672. WIN32_FIND_DATAW *lpFind32,
  673. DWORD dwReason,
  674. DWORD dwParam1,
  675. DWORD dwParam2,
  676. DWORD dwContext
  677. )
  678. {
  679. LPCSCSTATS lpStats = (LPCSCSTATS)dwContext;
  680. if (dwReason == CSCPROC_REASON_BEGIN)
  681. {
  682. if (lpFind32)
  683. {
  684. printf("%ls size=%d\r\n", lpszFullPath, lpFind32->nFileSizeLow);
  685. lpStats->dwTotal++;
  686. lpStats->dwTotalFiles++;
  687. }
  688. else
  689. {
  690. printf("%s\r\n", lpszFullPath);
  691. }
  692. }
  693. else if (dwReason == CSCPROC_REASON_END)
  694. {
  695. if (dwParam2 != NO_ERROR)
  696. {
  697. if (dwParam2 == ERROR_INVALID_DATA)
  698. {
  699. printf("Mismatched, press any key to continue...\r\n", dwParam2);
  700. }
  701. else
  702. {
  703. printf("Error in comparing Errcode=%d, press any key to continue...\r\n", dwParam2);
  704. }
  705. getchar();
  706. lpStats->dwMismatched++;
  707. }
  708. }
  709. return (CSCPROC_RETURN_CONTINUE);
  710. }
  711. DWORD
  712. ProcessCSCPinFile(
  713. DWORD argc,
  714. LPSTR *argv
  715. )
  716. {
  717. DWORD dwError=ERROR_SUCCESS, dwHintFlags=0;
  718. BOOL fRecurse = FALSE, fRet=FALSE;
  719. #ifdef CSC_ON_NT
  720. unsigned short uBuff[MAX_PATH];
  721. #endif
  722. if (argc < 1)
  723. {
  724. printf("CSCPinFile: must provide a UNC path \r\n");
  725. }
  726. else
  727. {
  728. if (argc > 1)
  729. {
  730. if ((*argv[1] == 'u')||(*argv[1] == 'U'))
  731. {
  732. dwHintFlags |= FLAG_CSC_HINT_PIN_USER;
  733. }
  734. else if ((*argv[1] == 's')||(*argv[1] == 'S'))
  735. {
  736. dwHintFlags |= FLAG_CSC_HINT_PIN_SYSTEM;
  737. }
  738. else if (*argv[1] == 'i')
  739. {
  740. dwHintFlags |= FLAG_CSC_HINT_PIN_INHERIT_USER;
  741. }
  742. else if (*argv[1] == 'I')
  743. {
  744. dwHintFlags |= FLAG_CSC_HINT_PIN_INHERIT_SYSTEM;
  745. }
  746. else if (*argv[1] == 'T')
  747. {
  748. fRecurse = TRUE;
  749. }
  750. }
  751. #ifndef CSC_ON_NT
  752. fRet = DoPinningA(argv[0], dwHintFlags, fRecurse);
  753. #else
  754. memset(uBuff, 0, sizeof(uBuff));
  755. MultiByteToWideChar(CP_ACP, 0, argv[0], strlen(argv[0]), uBuff, MAX_PATH*sizeof(unsigned short));
  756. fRet = DoPinningW(uBuff, dwHintFlags, fRecurse);
  757. #endif
  758. }
  759. if (!fRet)
  760. {
  761. dwError = GetLastError();
  762. }
  763. return (dwError);
  764. }
  765. DWORD
  766. ProcessCSCUnPinFile(
  767. DWORD argc,
  768. LPSTR *argv
  769. )
  770. {
  771. DWORD dwStatus, dwError=ERROR_SUCCESS, dwPinCount, dwHintFlags=0;
  772. #ifdef CSC_ON_NT
  773. unsigned short uBuff[MAX_PATH];
  774. #endif
  775. if (argc < 1)
  776. {
  777. printf("CSCUnPinFile: must provide a UNC path \r\n");
  778. }
  779. else
  780. {
  781. if (argc > 1)
  782. {
  783. if ((*argv[1] == 'u')||(*argv[1] == 'U'))
  784. {
  785. dwHintFlags |= FLAG_CSC_HINT_PIN_USER;
  786. }
  787. else if ((*argv[1] == 's')||(*argv[1] == 'S'))
  788. {
  789. dwHintFlags |= FLAG_CSC_HINT_PIN_SYSTEM;
  790. }
  791. else if (*argv[1] == 'i')
  792. {
  793. dwHintFlags |= FLAG_CSC_HINT_PIN_INHERIT_USER;
  794. }
  795. else if (*argv[1] == 'I')
  796. {
  797. dwHintFlags |= FLAG_CSC_HINT_PIN_INHERIT_SYSTEM;
  798. }
  799. }
  800. #ifndef CSC_ON_NT
  801. if (!CSCUnpinFileA(argv[0], dwHintFlags, &dwStatus, &dwPinCount, &dwHintFlags))
  802. {
  803. dwError = GetLastError();
  804. }
  805. else
  806. {
  807. PrintCSCEntryInfo(NULL, dwStatus, dwPinCount, dwHintFlags, NULL);
  808. }
  809. #else
  810. memset(uBuff, 0, sizeof(uBuff));
  811. MultiByteToWideChar(CP_ACP, 0, argv[0], strlen(argv[0]), uBuff, MAX_PATH*sizeof(unsigned short));
  812. if (!CSCUnpinFileW(uBuff, dwHintFlags, &dwStatus, &dwPinCount, &dwHintFlags))
  813. {
  814. dwError = GetLastError();
  815. }
  816. else
  817. {
  818. PrintCSCEntryInfo(NULL, dwStatus, dwPinCount, dwHintFlags, NULL);
  819. }
  820. #endif
  821. }
  822. return (dwError);
  823. }
  824. DWORD
  825. ProcessCSCQueryFileStatus(
  826. DWORD argc,
  827. LPSTR *argv
  828. )
  829. {
  830. DWORD dwStatus, dwError=ERROR_SUCCESS, dwPinCount, dwHintFlags;
  831. #ifdef CSC_ON_NT
  832. unsigned short uBuff[MAX_PATH];
  833. #endif
  834. if (argc < 1)
  835. {
  836. printf("CSCQueryFileStatusA: must provide a UNC path \r\n");
  837. }
  838. else
  839. {
  840. #ifndef CSC_ON_NT
  841. if (!CSCQueryFileStatusA(argv[0], &dwStatus, &dwPinCount, &dwHintFlags))
  842. {
  843. dwError = GetLastError();
  844. }
  845. else
  846. {
  847. PrintCSCEntryInfo(NULL, dwStatus, dwPinCount, dwHintFlags, NULL);
  848. }
  849. #else
  850. memset(uBuff, 0, sizeof(uBuff));
  851. MultiByteToWideChar(CP_ACP, 0, argv[0], strlen(argv[0]), uBuff, MAX_PATH*sizeof(unsigned short));
  852. if (!CSCQueryFileStatusW(uBuff, &dwStatus, &dwPinCount, &dwHintFlags))
  853. {
  854. dwError = GetLastError();
  855. }
  856. else
  857. {
  858. PrintCSCEntryInfo(NULL, dwStatus, dwPinCount, dwHintFlags, NULL);
  859. }
  860. #endif
  861. }
  862. return (dwError);
  863. }
  864. DWORD
  865. ProcessCSCEnum(
  866. DWORD argc,
  867. LPSTR *argv
  868. )
  869. {
  870. HANDLE hFind;
  871. DWORD dwError = ERROR_SUCCESS, dwStatus, dwPinCount, dwHintFlags;
  872. FILETIME ftOrgTime;
  873. #ifndef CSC_ON_NT
  874. WIN32_FIND_DATAA sFind32;
  875. #else
  876. WIN32_FIND_DATAW sFind32;
  877. unsigned short uBuff[MAX_PATH];
  878. #endif
  879. #ifndef CSC_ON_NT
  880. hFind = CSCFindFirstFileA((argc<1)?NULL:argv[0], &sFind32, &dwStatus, &dwPinCount, &dwHintFlags, &ftOrgTime);
  881. if (hFind != INVALID_HANDLE_VALUE)
  882. {
  883. PrintCSCEntryInfo(&sFind32, dwStatus, dwPinCount, dwHintFlags, &ftOrgTime);
  884. while (CSCFindNextFileA(hFind, &sFind32, &dwStatus, &dwPinCount, &dwHintFlags, &ftOrgTime))
  885. {
  886. PrintCSCEntryInfo(&sFind32, dwStatus, dwPinCount, dwHintFlags, &ftOrgTime);
  887. }
  888. CSCFindClose(hFind);
  889. }
  890. else
  891. {
  892. dwError = GetLastError();
  893. }
  894. #else
  895. memset(uBuff, 0, sizeof(uBuff));
  896. MultiByteToWideChar(CP_ACP, 0, argv[0], strlen(argv[0]), uBuff, MAX_PATH*sizeof(unsigned short));
  897. hFind = CSCFindFirstFileW(uBuff, &sFind32, &dwStatus, &dwPinCount, &dwHintFlags, &ftOrgTime);
  898. if (hFind != INVALID_HANDLE_VALUE)
  899. {
  900. PrintCSCEntryInfoW(&sFind32, dwStatus, dwPinCount, dwHintFlags, &ftOrgTime);
  901. while (CSCFindNextFileW(hFind, &sFind32, &dwStatus, &dwPinCount, &dwHintFlags, &ftOrgTime))
  902. {
  903. PrintCSCEntryInfoW(&sFind32, dwStatus, dwPinCount, dwHintFlags, &ftOrgTime);
  904. }
  905. CSCFindClose(hFind);
  906. }
  907. else
  908. {
  909. dwError = GetLastError();
  910. }
  911. #endif
  912. return (dwError);
  913. }
  914. DWORD
  915. ProcessCSCDelete(
  916. DWORD argc,
  917. LPSTR *argv
  918. )
  919. {
  920. DWORD dwError=ERROR_SUCCESS;
  921. #ifdef CSC_ON_NT
  922. unsigned short uBuff[MAX_PATH];
  923. #endif
  924. if (argc < 1)
  925. {
  926. printf("CSCQueryFileStatusA: must provide a UNC path \r\n");
  927. }
  928. else
  929. {
  930. #ifndef CSC_ON_NT
  931. if (!CSCDeleteA(argv[0]))
  932. {
  933. dwError = GetLastError();
  934. }
  935. #else
  936. memset(uBuff, 0, sizeof(uBuff));
  937. MultiByteToWideChar(CP_ACP, 0, argv[0], strlen(argv[0]), uBuff, MAX_PATH*sizeof(unsigned short));
  938. if (!CSCDeleteW(uBuff))
  939. {
  940. dwError = GetLastError();
  941. }
  942. #endif
  943. }
  944. return (dwError);
  945. }
  946. DWORD
  947. ProcessTimeLog(
  948. DWORD argc,
  949. LPSTR *argv
  950. )
  951. {
  952. DWORD dwError=ERROR_SUCCESS;
  953. LPSTR lpszLogFile;
  954. FILE *fp= (FILE *)NULL;
  955. char buff[256];
  956. int indx = 0;
  957. LONGLONG llTime = 0;
  958. DWORD dwMin, dwSec, dwMSec;
  959. if (argc < 1)
  960. {
  961. printf("No file specified assuming %s\r\n", szDefaultTimeLogFile);
  962. lpszLogFile = szDefaultTimeLogFile;
  963. }
  964. else
  965. {
  966. lpszLogFile = argv[0];
  967. }
  968. if (fp = fopen(lpszLogFile, "rb")){
  969. printf("Total time spent by routine \r\n");
  970. while(fgets(buff, sizeof(buff), fp) != NULL)
  971. {
  972. if (sscanf(buff, "%x %x", (DWORD *)&llTime, (DWORD *)(((BYTE *)&llTime)+sizeof(DWORD)))==2)
  973. {
  974. dwMin = (DWORD)((llTime/10000000)/60);
  975. dwSec = (DWORD)((llTime/10000000)%60);
  976. if (!dwMin && !dwSec)
  977. {
  978. dwMSec = (DWORD)(llTime/10000);
  979. printf("%d msecs: %s\r\n", dwMSec, rgszNameArray[indx]);
  980. }
  981. else
  982. {
  983. printf("%d min %d sec: %s \r\n",
  984. dwMin,
  985. dwSec,
  986. rgszNameArray[indx]);
  987. }
  988. }
  989. ++indx;
  990. }
  991. fclose(fp);
  992. }
  993. return (dwError);
  994. }
  995. DWORD
  996. ProcessCheckCSC(
  997. DWORD argc,
  998. LPSTR *argv
  999. )
  1000. {
  1001. CHECKCSCEX lpCheckCscEx;
  1002. HANDLE hLib;
  1003. CSCSTATS sCscStats;
  1004. DWORD dwError=ERROR_SUCCESS;
  1005. BOOL fRet = TRUE;
  1006. if (hLib = LoadLibraryA("cscdll.dll"))
  1007. {
  1008. if (lpCheckCscEx = (CHECKCSCEX)GetProcAddress(hLib, "CheckCSCEx"))
  1009. {
  1010. memset(&sCscStats, 0, sizeof(sCscStats));
  1011. #ifndef CSC_ON_NT
  1012. fRet = lpCheckCscEx(argv[0], MyCSCCheckExProc, (DWORD)&sCscStats, 0); // verify
  1013. #else
  1014. fRet = lpCheckCscEx(argv[0], MyCSCCheckExProcW, (DWORD)&sCscStats, 0); // verify
  1015. #endif
  1016. }
  1017. else
  1018. {
  1019. printf("Older version of cscdll \r\n");
  1020. fRet = FALSE;
  1021. }
  1022. FreeLibrary(hLib);
  1023. }
  1024. if (!fRet)
  1025. {
  1026. dwError = GetLastError();
  1027. }
  1028. return dwError;
  1029. }
  1030. DWORD
  1031. ProcessDbCheckCSC(
  1032. DWORD argc,
  1033. LPSTR *argv
  1034. )
  1035. {
  1036. DWORD dwError=ERROR_SUCCESS;
  1037. DWORD dwLevel=0;
  1038. BOOL fRet = TRUE;
  1039. PRINTPROC lpfnPrintProc = NULL;
  1040. #if 0
  1041. PFILE_STREAM_INFORMATION pStream = NULL, pstreamT;
  1042. char buff[1024];
  1043. if (GetStreamInformation((LPCSTR)vszFile, (LPVOID *)&pStream))
  1044. {
  1045. pstreamT = pStream;
  1046. do
  1047. {
  1048. memset(buff, 0, sizeof(buff));
  1049. wcstombs(buff, pstreamT->StreamName, pstreamT->StreamNameLength);
  1050. printf("%s\r\n", buff);
  1051. if (!pstreamT->NextEntryOffset)
  1052. {
  1053. break;
  1054. }
  1055. pstreamT = (PFILE_STREAM_INFORMATION)((LPBYTE)pstreamT + pstreamT->NextEntryOffset);
  1056. }
  1057. while (TRUE);
  1058. LocalFree(pStream);
  1059. }
  1060. #endif
  1061. if (argc < 1)
  1062. {
  1063. printf("Usage: check cscdir level{0 for verify, 1 for rebuild}\r\n");
  1064. return (ERROR_INVALID_PARAMETER);
  1065. }
  1066. else if (argc>1)
  1067. {
  1068. dwLevel = *argv[1] - '0';
  1069. }
  1070. if (dwLevel > 1)
  1071. {
  1072. printf("Usage: check cscdir level{0 for verify, 1 for rebuild}\r\n");
  1073. return (ERROR_INVALID_PARAMETER);
  1074. }
  1075. printf("Calling CheckCSC with cscdir=%s level=%d \r\n", argv[0], dwLevel);
  1076. switch (dwLevel)
  1077. {
  1078. case 0:
  1079. fRet = CheckCSC(argv[0], FALSE); // don't fix
  1080. break;
  1081. case 1:
  1082. fRet = CheckCSC(argv[0], TRUE); // fix
  1083. break;
  1084. default:
  1085. break;
  1086. }
  1087. if (!fRet)
  1088. {
  1089. dwError = GetLastError();
  1090. }
  1091. return dwError;
  1092. }
  1093. DWORD
  1094. ProcessCSCFill(
  1095. DWORD argc,
  1096. LPSTR *argv
  1097. )
  1098. {
  1099. DWORD dwError=ERROR_FILE_NOT_FOUND;
  1100. #ifdef CSC_ON_NT
  1101. unsigned short uBuff[MAX_PATH];
  1102. #endif
  1103. if (argc>=1)
  1104. {
  1105. #ifndef CSC_ON_NT
  1106. if (!CSCFillSparseFilesA((const char *)argv[0], FALSE, MyCSCProc, 0))
  1107. {
  1108. dwError = GetLastError();
  1109. }
  1110. else
  1111. {
  1112. dwError = ERROR_SUCCESS;
  1113. }
  1114. #else
  1115. memset(uBuff, 0, sizeof(uBuff));
  1116. MultiByteToWideChar(CP_ACP, 0, argv[0], strlen(argv[0]), uBuff, MAX_PATH*sizeof(unsigned short));
  1117. if (!CSCFillSparseFilesW((const unsigned short *)uBuff, FALSE, MyCSCProcW, 0))
  1118. {
  1119. dwError = GetLastError();
  1120. }
  1121. else
  1122. {
  1123. dwError = ERROR_SUCCESS;
  1124. }
  1125. #endif
  1126. }
  1127. return dwError;
  1128. }
  1129. DWORD
  1130. ProcessCSCMerge(
  1131. DWORD argc,
  1132. LPSTR *argv
  1133. )
  1134. {
  1135. DWORD dwError=ERROR_FILE_NOT_FOUND;
  1136. #ifdef CSC_ON_NT
  1137. unsigned short uBuff[MAX_PATH];
  1138. #endif
  1139. if (argc>=1)
  1140. {
  1141. #ifndef CSC_ON_NT
  1142. if (!CSCMergeShareA((const char *)(argv[0]), MyCSCProc, 0))
  1143. {
  1144. dwError = GetLastError();
  1145. }
  1146. else
  1147. {
  1148. dwError = ERROR_SUCCESS;
  1149. }
  1150. #else
  1151. memset(uBuff, 0, sizeof(uBuff));
  1152. MultiByteToWideChar(CP_ACP, 0, argv[0], strlen(argv[0]), uBuff, MAX_PATH*sizeof(unsigned short));
  1153. if (!CSCMergeShareW((const unsigned short *)uBuff, MyCSCProcW, 0))
  1154. {
  1155. dwError = GetLastError();
  1156. }
  1157. else
  1158. {
  1159. dwError = ERROR_SUCCESS;
  1160. }
  1161. CSCTransitionServerOnlineW((const unsigned short *)uBuff);
  1162. #endif
  1163. }
  1164. return dwError;
  1165. }
  1166. DWORD
  1167. ProcessCSCCopyReplica(
  1168. DWORD argc,
  1169. LPSTR *argv
  1170. )
  1171. {
  1172. DWORD dwError=ERROR_FILE_NOT_FOUND;
  1173. #ifdef CSC_ON_NT
  1174. LPWSTR lpszTempName = NULL;
  1175. unsigned short uBuff[MAX_PATH];
  1176. #else
  1177. LPSTR lpszTempName = NULL;
  1178. #endif
  1179. if (argc>=1)
  1180. {
  1181. #ifndef CSC_ON_NT
  1182. if (!CSCCopyReplicaA((const char *)argv[0], &lpszTempName))
  1183. {
  1184. dwError = GetLastError();
  1185. }
  1186. else
  1187. {
  1188. dwError = ERROR_SUCCESS;
  1189. }
  1190. #else
  1191. memset(uBuff, 0, sizeof(uBuff));
  1192. MultiByteToWideChar(CP_ACP, 0, argv[0], strlen(argv[0]), uBuff, MAX_PATH*sizeof(unsigned short));
  1193. if (!CSCCopyReplicaW((const unsigned short *)uBuff, &lpszTempName))
  1194. {
  1195. dwError = GetLastError();
  1196. }
  1197. else
  1198. {
  1199. dwError = ERROR_SUCCESS;
  1200. }
  1201. #endif
  1202. }
  1203. if (dwError == ERROR_SUCCESS)
  1204. {
  1205. #ifdef CSC_ON_NT
  1206. OutputDebugStringW(lpszTempName);
  1207. OutputDebugStringW(L"\r\n");
  1208. #else
  1209. OutputDebugStringA(lpszTempName);
  1210. OutputDebugStringA("\r\n");
  1211. #endif
  1212. }
  1213. return dwError;
  1214. }
  1215. DWORD
  1216. ProcessCSCEnumForStats(
  1217. DWORD argc,
  1218. LPSTR *argv
  1219. )
  1220. {
  1221. DWORD dwError=ERROR_FILE_NOT_FOUND;
  1222. CSCSTATS sStats;
  1223. #ifdef CSC_ON_NT
  1224. unsigned short uBuff[MAX_PATH];
  1225. #endif
  1226. memset(&sStats, 0, sizeof(sStats));
  1227. #ifndef CSC_ON_NT
  1228. if (!CSCEnumForStatsA((argc >=1)?(const char *)(argv[0]):NULL, MyCSCEnumForStatsProc, (DWORD)&sStats))
  1229. {
  1230. dwError = GetLastError();
  1231. }
  1232. else
  1233. {
  1234. dwError = ERROR_SUCCESS;
  1235. }
  1236. #else
  1237. if (argc >= 1)
  1238. {
  1239. memset(uBuff, 0, sizeof(uBuff));
  1240. MultiByteToWideChar(CP_ACP, 0, argv[0], strlen(argv[0]), uBuff, MAX_PATH*sizeof(unsigned short));
  1241. }
  1242. if (!CSCEnumForStatsW((argc>=1)?(const unsigned short *)uBuff:NULL, MyCSCEnumForStatsProcW, (DWORD)&sStats))
  1243. {
  1244. dwError = GetLastError();
  1245. }
  1246. else
  1247. {
  1248. dwError = ERROR_SUCCESS;
  1249. }
  1250. #if 0
  1251. if (argc < 1)
  1252. {
  1253. DWORD dwMaxSpaceHigh, dwMaxSpaceLow, dwCurrentSpaceHigh, dwCurrentSpaceLow, cntTotalFiles, cntTotalDirs;
  1254. if(CSCGetSpaceUsageW(uBuff, sizeof(uBuff),
  1255. &dwMaxSpaceHigh, &dwMaxSpaceLow,
  1256. &dwCurrentSpaceHigh, &dwCurrentSpaceLow,
  1257. &cntTotalFiles, &cntTotalDirs))
  1258. {
  1259. printf("\r\n Space Stats \r\n");
  1260. printf("CSC directory location: %ls \r\n", uBuff);
  1261. printf("MaxSpace=%d, CurrentSpaceUsed=%d, Fnles=%d Dirs=%d \r\n", dwMaxSpaceLow, dwCurrentSpaceLow, cntTotalFiles, cntTotalDirs);
  1262. }
  1263. else
  1264. {
  1265. printf("Error=%d in CSCGetSpaceUsage\r\n", GetLastError());
  1266. }
  1267. }
  1268. #endif
  1269. #endif
  1270. if (dwError == ERROR_SUCCESS)
  1271. {
  1272. printf("Stats\n");
  1273. printf("Total = %d, files=%d dirs=%d sparse=%d dirty=%d pinned=%d pinnedAndSparse=%d\r\n",
  1274. sStats.dwTotal,
  1275. sStats.dwTotalFiles,
  1276. sStats.dwTotalDirs,
  1277. sStats.dwSparseFiles,
  1278. sStats.dwDirtyFiles,
  1279. sStats.dwPinned,
  1280. sStats.dwPinnedAndSparse
  1281. );
  1282. }
  1283. return dwError;
  1284. }
  1285. DWORD
  1286. ProcessCSCDoLocalRename(
  1287. DWORD argc,
  1288. LPSTR *argv
  1289. )
  1290. {
  1291. DWORD dwError=ERROR_FILE_NOT_FOUND;
  1292. #ifdef CSC_ON_NT
  1293. unsigned short uBuffSrc[MAX_PATH], uBuffDst[MAX_PATH];
  1294. #endif
  1295. if (argc<2)
  1296. {
  1297. printf("Usage: ren source_name dest_dir [optional character to indicate replace]\r\n");
  1298. return ERROR_INVALID_PARAMETER;
  1299. }
  1300. #ifndef CSC_ON_NT
  1301. dwError = ERROR_CALL_NOT_IMPLEMENTED;
  1302. #else
  1303. memset(uBuffSrc, 0, sizeof(uBuffSrc));
  1304. MultiByteToWideChar(CP_ACP, 0, argv[0], strlen(argv[0]), uBuffSrc, MAX_PATH*sizeof(unsigned short));
  1305. memset(uBuffDst, 0, sizeof(uBuffDst));
  1306. MultiByteToWideChar(CP_ACP, 0, argv[1], strlen(argv[1]), uBuffDst, MAX_PATH*sizeof(unsigned short));
  1307. if (!CSCDoLocalRenameW(uBuffSrc, uBuffDst, (argc > 2)))
  1308. {
  1309. dwError = GetLastError();
  1310. }
  1311. else
  1312. {
  1313. dwError = ERROR_SUCCESS;
  1314. }
  1315. #endif
  1316. return dwError;
  1317. }
  1318. DWORD
  1319. ProcessCSCDoEnableDisable(
  1320. DWORD argc,
  1321. LPSTR *argv
  1322. )
  1323. {
  1324. DWORD dwError=ERROR_FILE_NOT_FOUND;
  1325. if (argc<1)
  1326. {
  1327. printf("Usage: endis fEnable\r\n");
  1328. return ERROR_INVALID_PARAMETER;
  1329. }
  1330. #ifndef CSC_ON_NT
  1331. dwError = ERROR_CALL_NOT_IMPLEMENTED;
  1332. #else
  1333. if (!CSCDoEnableDisable(*argv[0]!='0'))
  1334. {
  1335. dwError = GetLastError();
  1336. }
  1337. else
  1338. {
  1339. dwError = ERROR_SUCCESS;
  1340. }
  1341. #endif
  1342. return dwError;
  1343. }
  1344. DWORD
  1345. ProcessDoRandomWrites(
  1346. DWORD argc,
  1347. LPSTR *argv
  1348. )
  1349. {
  1350. DWORD dwError=ERROR_SUCCESS, dwFileSize, dwOffset, dwOffsetHigh;
  1351. unsigned short uBuff[MAX_PATH];
  1352. unsigned char uchData;
  1353. HANDLE hFile = INVALID_HANDLE_VALUE;
  1354. int i, count;
  1355. if (argc>=1)
  1356. {
  1357. memset(uBuff, 0, sizeof(uBuff));
  1358. MultiByteToWideChar(CP_ACP, 0, argv[0], strlen(argv[0]), uBuff, MAX_PATH*sizeof(unsigned short));
  1359. hFile = CreateFileW(
  1360. uBuff, // name
  1361. GENERIC_READ|GENERIC_WRITE, // access mode
  1362. FILE_SHARE_READ|FILE_SHARE_WRITE, // share mode
  1363. NULL, // security descriptor
  1364. OPEN_EXISTING, // create disposition
  1365. 0, // file statributes if created
  1366. NULL); // template handle
  1367. #if LARGE_FILE
  1368. hFile = CreateFileW(
  1369. uBuff, // name
  1370. GENERIC_READ|GENERIC_WRITE, // access mode
  1371. FILE_SHARE_READ|FILE_SHARE_WRITE, // share mode
  1372. NULL, // security descriptor
  1373. OPEN_ALWAYS, // create disposition
  1374. 0, // file statributes if created
  1375. NULL); // template handle
  1376. #endif
  1377. if (hFile != INVALID_HANDLE_VALUE)
  1378. {
  1379. dwFileSize = GetFileSize(hFile, NULL);
  1380. if (dwFileSize == -1)
  1381. {
  1382. dwError = GetLastError();
  1383. goto bailout;
  1384. }
  1385. if (dwFileSize == 0)
  1386. {
  1387. printf("0 sized file \n");
  1388. goto bailout;
  1389. }
  1390. srand( (unsigned)time( NULL ) );
  1391. // count = rand() % 100;
  1392. count = 2;
  1393. printf("writing %d times \n", count);
  1394. for (i=0; i< count; ++i)
  1395. {
  1396. DWORD dwReturn;
  1397. dwOffset = rand() % dwFileSize;
  1398. uchData = (unsigned char)rand();
  1399. if (SetFilePointer(hFile, dwOffset, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER)
  1400. {
  1401. dwError = GetLastError();
  1402. printf("Failed SetFilePointer %d \n", dwError);
  1403. goto bailout;
  1404. }
  1405. printf("writing %c at %d \n", uchData, dwOffset);
  1406. if (!WriteFile(hFile, &uchData, 1, &dwReturn, NULL))
  1407. {
  1408. dwError = GetLastError();
  1409. printf("Failed write with error %d \n", dwError);
  1410. goto bailout;
  1411. }
  1412. }
  1413. }
  1414. #if LARGE_FILE
  1415. dwOffsetHigh = 1;
  1416. if (SetFilePointer(hFile, 0x400000, &dwOffsetHigh, FILE_BEGIN) == INVALID_SET_FILE_POINTER)
  1417. {
  1418. dwError = GetLastError();
  1419. printf("Failed SetFilePointer %d \n", dwError);
  1420. goto bailout;
  1421. }
  1422. if (!SetEndOfFile(hFile))
  1423. {
  1424. dwError = GetLastError();
  1425. printf("Failed SetEof %d \n", dwError);
  1426. goto bailout;
  1427. }
  1428. #endif
  1429. }
  1430. bailout:
  1431. if (hFile != INVALID_HANDLE_VALUE)
  1432. {
  1433. CloseHandle(hFile);
  1434. }
  1435. return dwError;
  1436. }
  1437. VOID
  1438. PrintBuffer(
  1439. LPSTR lpszBuff
  1440. )
  1441. {
  1442. printf(lpszBuff);
  1443. }
  1444. //=================================================================================
  1445. DWORD
  1446. ProcessCommandCode (
  1447. DWORD CommandCode,
  1448. DWORD CommandArgc,
  1449. LPSTR *CommandArgv
  1450. )
  1451. {
  1452. DWORD Error = ERROR_SUCCESS;
  1453. switch( CommandCode ) {
  1454. case CmdCSCPinFile:
  1455. Error = ProcessCSCPinFile(CommandArgc, CommandArgv);
  1456. break;
  1457. case CmdCSCUnPinFile:
  1458. Error = ProcessCSCUnPinFile(CommandArgc, CommandArgv);
  1459. break;
  1460. case CmdCSCQueryFileStatus:
  1461. Error = ProcessCSCQueryFileStatus(CommandArgc, CommandArgv);
  1462. break;
  1463. case CmdCSCEnum:
  1464. Error = ProcessCSCEnum(CommandArgc, CommandArgv);
  1465. break;
  1466. case CmdCSCDelete:
  1467. Error = ProcessCSCDelete(CommandArgc, CommandArgv);
  1468. break;
  1469. case CmdHelp:
  1470. DisplayUsage();
  1471. break;
  1472. case CmdTimeLog:
  1473. Error = ProcessTimeLog(CommandArgc, CommandArgv);
  1474. break;
  1475. case CmdCheckCSC:
  1476. Error = ProcessCheckCSC(CommandArgc, CommandArgv);
  1477. break;
  1478. case CmdDbCheckCSC:
  1479. Error = ProcessDbCheckCSC(CommandArgc, CommandArgv);
  1480. break;
  1481. case CmdCSCFill:
  1482. Error = ProcessCSCFill(CommandArgc, CommandArgv);
  1483. break;
  1484. case CmdCSCMerge:
  1485. Error = ProcessCSCMerge(CommandArgc, CommandArgv);
  1486. break;
  1487. case CmdCSCCopyReplica:
  1488. Error = ProcessCSCCopyReplica(CommandArgc, CommandArgv);
  1489. break;
  1490. case CmdCSCEnumForStats:
  1491. Error = ProcessCSCEnumForStats(CommandArgc, CommandArgv);
  1492. break;
  1493. case CmdCSCDoLocalRename:
  1494. Error = ProcessCSCDoLocalRename(CommandArgc, CommandArgv);
  1495. break;
  1496. case CmdCSCDoEnableDisable:
  1497. Error = ProcessCSCDoEnableDisable(CommandArgc, CommandArgv);
  1498. break;
  1499. case CmdShowTime:
  1500. Error = ProcessShowTime( CommandArgc, CommandArgv );
  1501. break;
  1502. case CmdEncryptDecrypt:
  1503. Error = ProcessEncryptDecrypt(CommandArgc, CommandArgv );
  1504. break;
  1505. case CmdDoRandomWrites:
  1506. Error = ProcessDoRandomWrites(CommandArgc, CommandArgv );
  1507. break;
  1508. case CmdQuit :
  1509. exit (0);
  1510. default:
  1511. TestDbgAssert( FALSE );
  1512. fprintf(stderr, "Unknown Command Specified.\n");
  1513. DisplayUsage();
  1514. break;
  1515. }
  1516. cCommands++;
  1517. if( Error != ERROR_SUCCESS ) {
  1518. LPSTR lpstr;
  1519. cFails++;
  1520. Format_Error(Error, &lpstr);
  1521. printf("FAILED (%s), %ld-%s.\n",
  1522. GlobalCommandInfo[CommandCode].CommandName, Error, lpstr );
  1523. LocalFree(lpstr);
  1524. }
  1525. else {
  1526. if(!g_bQuietMode)
  1527. printf("Command (%s) successfully completed.\n", GlobalCommandInfo[CommandCode].CommandName );
  1528. }
  1529. return Error;
  1530. }
  1531. //=================================================================================
  1532. VOID
  1533. __cdecl
  1534. main(
  1535. int argc,
  1536. char *argv[]
  1537. )
  1538. {
  1539. DWORD Error;
  1540. COMMAND_CODE CommandCode;
  1541. CHAR InBuffer[DEFAULT_BUFFER_SIZE];
  1542. DWORD CArgc;
  1543. LPSTR CArgv[MAX_COMMAND_ARGS];
  1544. unsigned u1 = 1, u2 = 0xffffffff;
  1545. DWORD CommandArgc;
  1546. LPSTR *CommandArgv;
  1547. printf("u1=0x%x u2=0x%x, (int)(u1-u2)=%d, (u1-u2)=0x%x \r\n", u1, u2, (int)(u1-u2), (u1-u2));
  1548. /* must check for batch mode. if there are command line parms, assume batch mode */
  1549. if (argc > 1)
  1550. {
  1551. //this means that the arguments translate directly into CommandArgc....
  1552. CommandCode = DecodeCommand( argv[1] );
  1553. if( CommandCode == UnknownCommand ) {
  1554. printf("Unknown Command Specified.\n");
  1555. return;
  1556. }
  1557. CommandArgc = argc - 2;
  1558. CommandArgv = &argv[2];
  1559. Error = ProcessCommandCode (CommandCode,CommandArgc,CommandArgv);
  1560. if (DumpUncList)
  1561. fclose(DumpUncList);
  1562. if (UncList)
  1563. fclose(UncList);
  1564. return;
  1565. }
  1566. DisplayUsage();
  1567. for(;;) {
  1568. fprintf(stderr, "Command : " );
  1569. gets( InBuffer );
  1570. CArgc = 0;
  1571. ParseArguments( InBuffer, CArgv, &CArgc );
  1572. if( CArgc < 1 ) {
  1573. continue;
  1574. }
  1575. //
  1576. // decode command.
  1577. //
  1578. CommandCode = DecodeCommand( CArgv[0] );
  1579. if( CommandCode == UnknownCommand ) {
  1580. fprintf(stderr, "Unknown Command Specified.\n");
  1581. continue;
  1582. }
  1583. CommandArgc = CArgc - 1;
  1584. CommandArgv = &CArgv[1];
  1585. Error = ProcessCommandCode (CommandCode,CommandArgc,CommandArgv);
  1586. }
  1587. return;
  1588. }
  1589. //=================================================================================
  1590. DWORD
  1591. GetLeafLenFromPath(
  1592. LPSTR lpszPath
  1593. )
  1594. {
  1595. DWORD len;
  1596. LPSTR lpT;
  1597. if(!lpszPath)
  1598. return(0);
  1599. len = lstrlen(lpszPath);
  1600. if (len == 0) {
  1601. return (len);
  1602. }
  1603. lpT = lpszPath+len-1;
  1604. if (*lpT =='\\') {
  1605. --lpT;
  1606. }
  1607. for (; lpT >= lpszPath; --lpT) {
  1608. if (*lpT == '\\') {
  1609. break;
  1610. }
  1611. }
  1612. return (lstrlen(lpT));
  1613. }
  1614. //=================================================================================
  1615. DWORD WINAPIV Format_String(LPSTR *plpsz, LPSTR lpszFmt, ...)
  1616. {
  1617. const char c_Func_Name[] = "[Format_String] ";
  1618. DWORD dwRet;
  1619. va_list vArgs;
  1620. va_start (vArgs, lpszFmt);
  1621. dwRet = Format_StringV(plpsz, lpszFmt, &vArgs);
  1622. va_end (vArgs);
  1623. return(dwRet);
  1624. }
  1625. //=================================================================================
  1626. DWORD WINAPI Format_Error(DWORD dwErr, LPSTR *plpsz)
  1627. {
  1628. DWORD dwRet;
  1629. if(dwErr != ERROR_SUCCESS)
  1630. {
  1631. dwRet = Format_MessageV(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
  1632. dwErr, plpsz, NULL, NULL);
  1633. }
  1634. else
  1635. {
  1636. const char szMsg[] = "No Error";
  1637. Format_String(plpsz, (LPSTR)szMsg);
  1638. dwRet = lstrlen(szMsg);
  1639. }
  1640. return(dwRet);
  1641. }
  1642. //=================================================================================
  1643. DWORD WINAPI Format_StringV(LPSTR *plpsz, LPCSTR lpszFmt, va_list *vArgs)
  1644. {
  1645. return(Format_MessageV(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING,
  1646. 0, plpsz, lpszFmt, vArgs));
  1647. }
  1648. // ***************************************************************************
  1649. DWORD WINAPI Format_MessageV(DWORD dwFlags, DWORD dwErr, LPSTR *plpsz, LPCSTR lpszFmt, va_list *vArgs)
  1650. {
  1651. const char c_Func_Name[] = "[Format_MessageV]";
  1652. DWORD dwRet;
  1653. DWORD dwGLE;
  1654. *plpsz = NULL;
  1655. dwRet = FormatMessage(dwFlags, lpszFmt, dwErr, 0, (LPSTR) plpsz, 0, vArgs);
  1656. if (!dwRet || !*plpsz)
  1657. {
  1658. dwGLE = GetLastError();
  1659. printf("%s FormatMessage Failed: %s. dwRet: %#lx!. *plpsz:%#lx! GLE:%d\r\n", c_Func_Name, lpszFmt, dwRet, *plpsz, dwGLE);
  1660. if (*plpsz)
  1661. LocalFree ((HLOCAL) *plpsz);
  1662. *plpsz = NULL;
  1663. return 0;
  1664. }
  1665. return(dwRet);
  1666. }
  1667. #if 0
  1668. BOOL
  1669. GetStreamInformation(
  1670. LPCSTR lpExistingFileName,
  1671. LPVOID *lpStreamInformation
  1672. )
  1673. {
  1674. HANDLE SourceFile = INVALID_HANDLE_VALUE;
  1675. PFILE_STREAM_INFORMATION StreamInfoBase = NULL;
  1676. ULONG StreamInfoSize;
  1677. IO_STATUS_BLOCK IoStatus;
  1678. BOOL fRet = FALSE;
  1679. DWORD Status;
  1680. *lpStreamInformation = NULL;
  1681. SourceFile = CreateFile(
  1682. lpExistingFileName,
  1683. GENERIC_READ,
  1684. FILE_SHARE_READ | FILE_SHARE_WRITE,
  1685. NULL,
  1686. OPEN_EXISTING,
  1687. FILE_FLAG_SEQUENTIAL_SCAN,
  1688. NULL
  1689. );
  1690. if (SourceFile == INVALID_HANDLE_VALUE)
  1691. {
  1692. return FALSE;
  1693. }
  1694. //
  1695. // Obtain the full set of streams we have to copy. Since the Io subsystem does
  1696. // not provide us a way to find out how much space this information will take,
  1697. // we must iterate the call, doubling the buffer size upon each failure.
  1698. //
  1699. // If the underlying file system does not support stream enumeration, we end up
  1700. // with a NULL buffer. This is acceptable since we have at least a default
  1701. // data stream,
  1702. //
  1703. StreamInfoSize = 4096;
  1704. do {
  1705. StreamInfoBase = LocalAlloc(LPTR, StreamInfoSize );
  1706. if ( !StreamInfoBase ) {
  1707. SetLastError( STATUS_NO_MEMORY );
  1708. goto bailout;
  1709. }
  1710. Status = NtQueryInformationFile(
  1711. SourceFile,
  1712. &IoStatus,
  1713. (PVOID) StreamInfoBase,
  1714. StreamInfoSize,
  1715. FileStreamInformation
  1716. );
  1717. if (Status != STATUS_SUCCESS) {
  1718. //
  1719. // We failed the call. Free up the previous buffer and set up
  1720. // for another pass with a buffer twice as large
  1721. //
  1722. LocalFree(StreamInfoBase);
  1723. StreamInfoBase = NULL;
  1724. StreamInfoSize *= 2;
  1725. }
  1726. } while ( Status == STATUS_BUFFER_OVERFLOW || Status == STATUS_BUFFER_TOO_SMALL );
  1727. if (Status == STATUS_SUCCESS)
  1728. {
  1729. fRet = TRUE;
  1730. }
  1731. bailout:
  1732. if (SourceFile != INVALID_HANDLE_VALUE)
  1733. {
  1734. CloseHandle(SourceFile);
  1735. }
  1736. *lpStreamInformation = StreamInfoBase;
  1737. return fRet;
  1738. }
  1739. #endif
  1740. #ifdef CSC_ON_NT
  1741. BOOL
  1742. DoPinningW(
  1743. LPWSTR lpwzName,
  1744. DWORD dwHintFlags,
  1745. BOOL fRecurse
  1746. )
  1747. {
  1748. unsigned short uBuff[MAX_PATH];
  1749. WIN32_FIND_DATAW sFind32W;
  1750. HANDLE hFind = NULL;
  1751. BOOL fRet = TRUE;
  1752. DWORD lenName, dwStatus, dwPinCount, dwError;
  1753. lenName = lstrlenW(lpwzName);
  1754. if (lenName < 5)
  1755. {
  1756. return FALSE;
  1757. }
  1758. lstrcpyW(uBuff, lpwzName);
  1759. if (uBuff[lenName-1] == (USHORT)'\\')
  1760. {
  1761. uBuff[lenName-1] = 0;
  1762. --lenName;
  1763. if (lenName < 5)
  1764. {
  1765. return FALSE;
  1766. }
  1767. }
  1768. hFind = FindFirstFileW(uBuff, &sFind32W);
  1769. if (hFind==INVALID_HANDLE_VALUE)
  1770. {
  1771. lstrcatW(uBuff, L"\\*");
  1772. hFind = FindFirstFileW(uBuff, &sFind32W);
  1773. uBuff[lenName] = 0;
  1774. if (hFind==INVALID_HANDLE_VALUE)
  1775. {
  1776. return FALSE;
  1777. }
  1778. }
  1779. else if (sFind32W.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
  1780. {
  1781. FindClose(hFind);
  1782. lstrcatW(uBuff, L"\\*");
  1783. hFind = FindFirstFileW(uBuff, &sFind32W);
  1784. uBuff[lenName] = 0;
  1785. if (hFind==INVALID_HANDLE_VALUE)
  1786. {
  1787. return FALSE;
  1788. }
  1789. }
  1790. do
  1791. {
  1792. if (!CSCPinFileW(uBuff, dwHintFlags, &dwStatus, &dwPinCount, &dwHintFlags))
  1793. {
  1794. dwError = GetLastError();
  1795. }
  1796. else
  1797. {
  1798. PrintCSCEntryInfo(NULL, dwStatus, dwPinCount, dwHintFlags, NULL);
  1799. }
  1800. if (fRecurse)
  1801. {
  1802. do
  1803. {
  1804. if(!FindNextFileW(hFind, &sFind32W))
  1805. {
  1806. goto bailout;
  1807. }
  1808. if ((!lstrcmpW(sFind32W.cFileName, L"."))||(!lstrcmpW(sFind32W.cFileName, L"..")))
  1809. {
  1810. continue;
  1811. }
  1812. uBuff[lenName] = (USHORT)'\\';
  1813. uBuff[lenName+1] = 0;
  1814. lstrcatW(uBuff, sFind32W.cFileName);
  1815. if (sFind32W.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
  1816. {
  1817. DoPinningW(uBuff, dwHintFlags, fRecurse);
  1818. }
  1819. break;
  1820. }
  1821. while (TRUE);
  1822. }
  1823. else
  1824. {
  1825. break;
  1826. }
  1827. }
  1828. while (TRUE);
  1829. bailout:
  1830. if (hFind)
  1831. {
  1832. FindClose(hFind);
  1833. }
  1834. return fRet;
  1835. }
  1836. #else
  1837. BOOL
  1838. DoPinningA(
  1839. LPSTR lpszName,
  1840. DWORD dwHintFlags,
  1841. BOOL fRecurse
  1842. )
  1843. {
  1844. char chBuff[MAX_PATH];
  1845. WIN32_FIND_DATAA sFind32A;
  1846. HANDLE hFind = NULL;
  1847. BOOL fRet = TRUE;
  1848. DWORD lenName, dwStatus, dwPinCount, dwError;
  1849. lenName = lstrlen(lpszName);
  1850. if (lenName < 5)
  1851. {
  1852. return FALSE;
  1853. }
  1854. lstrcpy(chBuff, lpszName);
  1855. if (chBuff[lenName-1] == (USHORT)'\\')
  1856. {
  1857. chBuff[lenName-1] = 0;
  1858. --lenName;
  1859. if (lenName < 5)
  1860. {
  1861. return FALSE;
  1862. }
  1863. }
  1864. hFind = FindFirstFileA(chBuff, &sFind32A);
  1865. if (hFind==INVALID_HANDLE_VALUE)
  1866. {
  1867. lstrcatA(chBuff, "\\*");
  1868. hFind = FindFirstFileA(chBuff, &sFind32A);
  1869. if (hFind==INVALID_HANDLE_VALUE)
  1870. {
  1871. return FALSE;
  1872. }
  1873. chBuff[lenName] = 0;
  1874. }
  1875. if (sFind32A.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
  1876. {
  1877. FindClose(hFind);
  1878. lstrcatA(chBuff, "\\*");
  1879. hFind = FindFirstFileA(chBuff, &sFind32A);
  1880. if (hFind==INVALID_HANDLE_VALUE)
  1881. {
  1882. return FALSE;
  1883. }
  1884. chBuff[lenName] = 0;
  1885. }
  1886. do
  1887. {
  1888. if (!CSCPinFileA(chBuff, dwHintFlags, &dwStatus, &dwPinCount, &dwHintFlags))
  1889. {
  1890. dwError = GetLastError();
  1891. }
  1892. else
  1893. {
  1894. PrintCSCEntryInfo(NULL, dwStatus, dwPinCount, dwHintFlags, NULL);
  1895. }
  1896. if (fRecurse)
  1897. {
  1898. if(!FindNextFile(hFind, &sFind32A))
  1899. {
  1900. goto bailout;
  1901. }
  1902. chBuff[lenName] = '\\';
  1903. lstrcat(chBuff, sFind32A.cFileName);
  1904. if (sFind32A.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
  1905. {
  1906. DoPinningA(chBuff, dwHintFlags, fRecurse);
  1907. }
  1908. }
  1909. else
  1910. {
  1911. break;
  1912. }
  1913. }
  1914. while (TRUE);
  1915. bailout:
  1916. if (hFind)
  1917. {
  1918. FindClose(hFind);
  1919. }
  1920. return fRet;
  1921. }
  1922. #endif
  1923. //=================================================================================
  1924. DWORD
  1925. ProcessShowTime (
  1926. DWORD argc,
  1927. LPSTR *argv
  1928. )
  1929. {
  1930. DWORD Error, dwSize;
  1931. FILETIME ftTemp;
  1932. SYSTEMTIME SystemTime;
  1933. if(argc != 2)
  1934. return 0xffffffff;
  1935. sscanf(argv[0], "%x", &(ftTemp.dwHighDateTime));
  1936. sscanf(argv[1], "%x", &(ftTemp.dwLowDateTime));
  1937. if(FileTimeToSystemTime( &ftTemp, &SystemTime )) {
  1938. printf("%02u/%02u/%04u %02u:%02u:%02u\n ",
  1939. SystemTime.wMonth,
  1940. SystemTime.wDay,
  1941. SystemTime.wYear,
  1942. SystemTime.wHour,
  1943. SystemTime.wMinute,
  1944. SystemTime.wSecond );
  1945. }
  1946. else {
  1947. printf("Wrong Times \n");
  1948. }
  1949. return ERROR_SUCCESS;
  1950. }
  1951. DWORD
  1952. ProcessEncryptDecrypt(
  1953. DWORD argc,
  1954. LPSTR *argv
  1955. )
  1956. {
  1957. DWORD dwStatus, dwError=ERROR_SUCCESS;
  1958. BOOL fEncrypt = FALSE;
  1959. #ifdef CSC_ON_NT
  1960. unsigned short uBuff[MAX_PATH];
  1961. #endif
  1962. if (argc != 1)
  1963. {
  1964. printf("CSCUnPinFile: must provide a UNC path \r\n");
  1965. }
  1966. else
  1967. {
  1968. fEncrypt = !((*argv[0] == 'u')||(*argv[0] == 'U'));
  1969. if (argc == 1)
  1970. {
  1971. if(!CSCEncryptDecryptDatabase(fEncrypt, NULL, 0))
  1972. {
  1973. dwError = GetLastError();
  1974. }
  1975. }
  1976. else
  1977. {
  1978. #if 0
  1979. memset(uBuff, 0, sizeof(uBuff));
  1980. MultiByteToWideChar(CP_ACP, 0, argv[1], strlen(argv[1]), uBuff, MAX_PATH*sizeof(unsigned short));
  1981. if (!CSCEncryptDecryptFileW(uBuff, fEncrypt))
  1982. {
  1983. dwError = GetLastError();
  1984. }
  1985. #endif
  1986. }
  1987. }
  1988. return (dwError);
  1989. }