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.

128 lines
3.1 KiB

  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. #include<windows.h>
  5. DWORD FileCreate(WCHAR *FileName, WCHAR *Time);
  6. DWORD DirCreate(WCHAR *FileName, WCHAR *Time, WCHAR *Modify, WCHAR *buf, WCHAR *Time2);
  7. PWCHAR *
  8. MainConvertArgV(
  9. DWORD ArgC,
  10. PCHAR *ArgV
  11. )
  12. /*++
  13. Routine Description:
  14. Convert short char ArgV into wide char ArgV
  15. Arguments:
  16. ArgC - From main
  17. ArgV - From main
  18. Return Value:
  19. Address of the new ArgV
  20. --*/
  21. {
  22. #undef DEBSUB
  23. #define DEBSUB "MainConvertArgV:"
  24. PWCHAR *wideArgV;
  25. wideArgV = (PWCHAR*)malloc((ArgC + 1) * sizeof(PWCHAR));
  26. wideArgV[ArgC] = NULL;
  27. while (ArgC-- >= 1) {
  28. wideArgV[ArgC] = (PWCHAR)malloc((strlen(ArgV[ArgC]) + 1) * sizeof(WCHAR));
  29. wsprintf(wideArgV[ArgC], L"%hs", ArgV[ArgC]);
  30. if (wideArgV[ArgC]) {
  31. _wcslwr(wideArgV[ArgC]);
  32. }
  33. }
  34. return wideArgV;
  35. }
  36. VOID __cdecl
  37. main(DWORD argc, CHAR **argv)
  38. {
  39. if(argc != 3) {
  40. printf("Usage\n");
  41. printf("lockedfile <filename> file|dir <time in seconds> 0|1 <change> <time in seconds>\n");
  42. printf("<filename>: name of the file or dir to lock\n");
  43. printf("file|dir: file if a file is locked, dir if a dir is locked\n");
  44. printf("<time in seconds>: time to hold locked file or dir before modifying\n");
  45. printf("0|1: 1 if there is to be a modification, 0 if not\n");
  46. printf("<change>: name of file to create if dir locked, else buffer to overwrite file with\n");
  47. printf("<time in seconds>: time to hold locked file after modification");
  48. return;
  49. }
  50. ArgV = MainConvertArgV(argc, argv);
  51. FileCreate(ArgV[1], ArgV[2]);
  52. // DirCreate(argv[1], argv[3], argv[4], argv[5], argv[6]);
  53. }
  54. DWORD FileCreate(WCHAR *FileName, WCHAR *Time)
  55. {
  56. HANDLE hFile;
  57. DWORD Duration;
  58. ULONG written = 0;
  59. hFile = CreateFile(FileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  60. SleepEx(10*1000, FALSE);
  61. //WriteFile(hFile, buf, 2*(wcslen(buf)+1), &written, NULL);
  62. CloseHandle(hFile);
  63. return 0;
  64. }
  65. DWORD DirCreate(WCHAR *FileName, WCHAR *Time, WCHAR *Modify, WCHAR *buf, WCHAR *Time2)
  66. {
  67. HANDLE hFile, hFile2;
  68. DWORD Duration;
  69. ULONG written = 0;
  70. WCHAR path[MAX_PATH];
  71. hFile = CreateFile(FileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
  72. if(hFile == INVALID_HANDLE_VALUE) {
  73. printf("directory open failed. GLE = %d\n", GetLastError());
  74. return 1;
  75. }
  76. Duration = wcstol(Time, NULL, 10);
  77. SleepEx(Duration*1000, FALSE);
  78. if(!wcscmp(Modify, L"1")) {
  79. wcscpy(path, FileName);
  80. wcscat(path, L"\\");
  81. wcscat(path, buf);
  82. hFile2 = CreateFile(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  83. if(hFile2 == INVALID_HANDLE_VALUE) {
  84. printf("file (%S) create failed. GLE = %d\n",path, GetLastError());
  85. return 1;
  86. }
  87. WriteFile(hFile2, L"test", 12, &written, NULL);
  88. CloseHandle(hFile2);
  89. wprintf(L"File %s created.\n",path);
  90. }
  91. Duration = wcstol(Time2, NULL, 10);
  92. SleepEx(Duration*1000, FALSE);
  93. CloseHandle(hFile);
  94. return 0;
  95. }