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.

106 lines
2.8 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. tracelib.c
  5. Abstract:
  6. Private trace libraries and stubs that allows user-mode to reside in NTDLL.
  7. Author:
  8. 15-Aug-2000 JeePang
  9. Revision History:
  10. --*/
  11. #include <nt.h>
  12. #include <ntrtl.h>
  13. #include <nturtl.h>
  14. #include <windows.h>
  15. #include "tracelib.h"
  16. #include "trcapi.h"
  17. HANDLE BaseNamedObjectDirectory;
  18. HANDLE
  19. EtwpCreateFile(
  20. LPCWSTR lpFileName,
  21. DWORD dwDesiredAccess,
  22. DWORD dwShareMode,
  23. DWORD dwCreationDisposition,
  24. DWORD dwCreateFlags
  25. )
  26. {
  27. UNICODE_STRING FileName;
  28. RTL_RELATIVE_NAME_U RelativeName;
  29. PVOID FreeBuffer;
  30. OBJECT_ATTRIBUTES ObjectAttributes;
  31. IO_STATUS_BLOCK Iosb;
  32. NTSTATUS Status;
  33. HANDLE FileHandle = INVALID_HANDLE_VALUE;
  34. SECURITY_QUALITY_OF_SERVICE SQos;
  35. RtlInitUnicodeString(&FileName, lpFileName);
  36. if (!RtlDosPathNameToRelativeNtPathName_U(
  37. lpFileName,
  38. &FileName,
  39. NULL,
  40. &RelativeName)) {
  41. EtwpSetDosError(ERROR_PATH_NOT_FOUND);
  42. return INVALID_HANDLE_VALUE;
  43. }
  44. FreeBuffer = FileName.Buffer;
  45. if (RelativeName.RelativeName.Length) {
  46. FileName = RelativeName.RelativeName;
  47. }
  48. else {
  49. RelativeName.ContainingDirectory = NULL;
  50. }
  51. InitializeObjectAttributes(
  52. &ObjectAttributes,
  53. &FileName,
  54. OBJ_CASE_INSENSITIVE,
  55. RelativeName.ContainingDirectory,
  56. NULL
  57. );
  58. SQos.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING;
  59. SQos.ImpersonationLevel = SecurityImpersonation;
  60. SQos.EffectiveOnly = TRUE;
  61. SQos.Length = sizeof(SECURITY_QUALITY_OF_SERVICE);
  62. ObjectAttributes.SecurityQualityOfService = &SQos;
  63. Status = NtCreateFile(
  64. &FileHandle,
  65. (ACCESS_MASK) dwDesiredAccess
  66. | SYNCHRONIZE | FILE_READ_ATTRIBUTES,
  67. &ObjectAttributes,
  68. &Iosb,
  69. NULL,
  70. FILE_ATTRIBUTE_NORMAL
  71. & (FILE_ATTRIBUTE_VALID_FLAGS & ~FILE_ATTRIBUTE_DIRECTORY),
  72. dwShareMode,
  73. dwCreationDisposition,
  74. dwCreateFlags | FILE_SYNCHRONOUS_IO_NONALERT,
  75. NULL,
  76. 0);
  77. if (!NT_SUCCESS(Status)) {
  78. if (Status == STATUS_OBJECT_NAME_COLLISION) {
  79. EtwpSetDosError(ERROR_FILE_EXISTS);
  80. }
  81. else {
  82. EtwpSetDosError(EtwpNtStatusToDosError(Status));
  83. }
  84. FileHandle = INVALID_HANDLE_VALUE;
  85. }
  86. RtlReleaseRelativeName(&RelativeName);
  87. if (lpFileName != FreeBuffer) {
  88. RtlFreeHeap(RtlProcessHeap(), 0, FreeBuffer);
  89. }
  90. return FileHandle;
  91. }