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.

119 lines
3.8 KiB

  1. #include <stdio.h>
  2. #include <nt.h>
  3. VOID
  4. DisplayUsage(
  5. wchar_t *ExeName
  6. )
  7. {
  8. printf( "This program tests opening a Volume with FILE_OPEN_REPARSE_POINT CreatOptions\n");
  9. printf( "usage: %S [volume]\n", ExeName );
  10. }
  11. //
  12. // Main program for TEST program
  13. //
  14. int _cdecl wmain(int argc, wchar_t *argv[])
  15. {
  16. NTSTATUS status;
  17. NTSTATUS closeStatus;
  18. HANDLE volHandle;
  19. IO_STATUS_BLOCK ioStatusBlock;
  20. OBJECT_ATTRIBUTES obja;
  21. UNICODE_STRING fname;
  22. wchar_t nameBuf[128];
  23. if (argc < 2) {
  24. DisplayUsage( argv[0] );
  25. return 1;
  26. }
  27. //
  28. // Create file normally
  29. //
  30. wcscpy(nameBuf,L"\\??\\");
  31. wcscat(nameBuf,argv[1]);
  32. fname.Buffer = nameBuf;
  33. fname.MaximumLength = (USHORT)(sizeof( nameBuf ) * sizeof( wchar_t ));
  34. fname.Length = (USHORT)(wcslen( nameBuf ) * sizeof( wchar_t ));
  35. InitializeObjectAttributes(
  36. &obja,
  37. &fname,
  38. OBJ_CASE_INSENSITIVE,
  39. NULL,
  40. NULL);
  41. status = NtCreateFile(
  42. &volHandle,
  43. (GENERIC_READ | GENERIC_EXECUTE | SYNCHRONIZE),
  44. &obja,
  45. &ioStatusBlock,
  46. NULL, //Initial allocation size
  47. FILE_ATTRIBUTE_NORMAL, //FileAttributes
  48. FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, //ShareMode
  49. FILE_OPEN, //CreateDisposition
  50. (FILE_OPEN_FOR_BACKUP_INTENT | //CreateOptions
  51. FILE_SEQUENTIAL_ONLY |
  52. FILE_OPEN_NO_RECALL |
  53. /*FILE_OPEN_REPARSE_POINT |*/
  54. FILE_SYNCHRONOUS_IO_NONALERT),
  55. NULL,0); //ea buffer and length
  56. if (status != 0) {
  57. printf("Error opening \"%S\" without FILE_FLAG_OPEN_REPARSE_POINT flag, status=%08x\n",argv[1],status);
  58. return 0;
  59. }
  60. printf("Successfully opened \"%S\" without FILE_FLAG_OPEN_REPARSE_POINT set\n",argv[1]);
  61. closeStatus = NtClose( volHandle );
  62. if (closeStatus != 0) {
  63. printf("Close failed, status=%08x\n",closeStatus);
  64. }
  65. //
  66. // Create file with FILE_FLAG_OPEN_REPARSE_POINT flag.
  67. //
  68. status = NtCreateFile(
  69. &volHandle,
  70. (GENERIC_READ | GENERIC_EXECUTE | SYNCHRONIZE),
  71. &obja,
  72. &ioStatusBlock,
  73. NULL, //Initial allocation size
  74. FILE_ATTRIBUTE_NORMAL, //FileAttributes
  75. FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, //ShareMode
  76. FILE_OPEN, //CreateDisposition
  77. (FILE_OPEN_FOR_BACKUP_INTENT | //CreateOptions
  78. FILE_SEQUENTIAL_ONLY |
  79. FILE_OPEN_NO_RECALL |
  80. FILE_OPEN_REPARSE_POINT |
  81. FILE_SYNCHRONOUS_IO_NONALERT),
  82. NULL,0); //ea buffer and length
  83. if (status != 0) {
  84. printf("Error opening \"%S\" with FILE_FLAG_OPEN_REPARSE_POINT flag, status=%08x\n",argv[1],status);
  85. return 0;
  86. }
  87. printf("Successfully opened \"%S\" with FILE_FLAG_OPEN_REPARSE_POINT set\n",argv[1]);
  88. closeStatus = NtClose( volHandle );
  89. if (closeStatus != 0) {
  90. printf("Close failed, status=%08x\n",closeStatus);
  91. }
  92. return 0;
  93. }