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.

168 lines
4.1 KiB

  1. #include <ndis.h>
  2. #include <ntddndis.h>
  3. #include <cxport.h>
  4. #include "gpcifc.h"
  5. #include "gpcstruc.h"
  6. /*++
  7. Copyright (c) 1997 Microsoft Corporation
  8. Module Name:
  9. gpcprx.c
  10. Abstract:
  11. A GPC proxy to load msgpc.sys on demand
  12. Author:
  13. Ofer Bar (Oferbar) Nov 7, 1997
  14. Environment:
  15. Kernel Mode
  16. Revision History:
  17. --*/
  18. NTSTATUS
  19. NTAPI
  20. ZwLoadDriver(
  21. IN PUNICODE_STRING Name
  22. );
  23. NTSTATUS
  24. NTAPI
  25. ZwDeviceIoControlFile(
  26. IN HANDLE FileHandle,
  27. IN HANDLE Event OPTIONAL,
  28. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  29. IN PVOID ApcContext OPTIONAL,
  30. OUT PIO_STATUS_BLOCK IoStatusBlock,
  31. IN ULONG IoControlCode,
  32. IN PVOID InputBuffer OPTIONAL,
  33. IN ULONG InputBufferLength,
  34. OUT PVOID OutputBuffer OPTIONAL,
  35. IN ULONG OutputBufferLength
  36. );
  37. NTSTATUS
  38. GpcInitialize(
  39. OUT PGPC_EXPORTED_CALLS pGpcEntries
  40. )
  41. {
  42. NTSTATUS Status;
  43. OBJECT_ATTRIBUTES ObjAttr;
  44. HANDLE FileHandle;
  45. IO_STATUS_BLOCK IoStatusBlock;
  46. UNICODE_STRING DriverName;
  47. UNICODE_STRING DeviceName;
  48. ASSERT(pGpcEntries);
  49. RtlZeroMemory(pGpcEntries, sizeof(GPC_EXPORTED_CALLS));
  50. RtlInitUnicodeString(&DriverName,
  51. L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\Gpc");
  52. RtlInitUnicodeString(&DeviceName, DD_GPC_DEVICE_NAME);
  53. InitializeObjectAttributes(&ObjAttr,
  54. &DeviceName,
  55. 0,
  56. NULL,
  57. NULL
  58. );
  59. Status = ZwCreateFile(
  60. &FileHandle,
  61. GENERIC_READ | GENERIC_WRITE,
  62. &ObjAttr,
  63. &IoStatusBlock,
  64. 0, // AllocationSize
  65. FILE_ATTRIBUTE_NORMAL, // FileAttributes
  66. 0, // ShareAccess
  67. FILE_OPEN_IF, // CreateDisposition
  68. 0, // CreateOptions
  69. NULL, // EaBuffer
  70. 0 // EaLength
  71. );
  72. if (Status != STATUS_SUCCESS) {
  73. //
  74. // The GPC is not loaded yet, so we need to load it now
  75. //
  76. Status = ZwLoadDriver(&DriverName);
  77. if (Status != STATUS_SUCCESS) {
  78. return Status;
  79. }
  80. //
  81. // try again...
  82. //
  83. Status = ZwCreateFile(&FileHandle,
  84. GENERIC_READ | GENERIC_WRITE,
  85. &ObjAttr,
  86. &IoStatusBlock,
  87. 0, // AllocationSize
  88. FILE_ATTRIBUTE_NORMAL, // FileAttributes
  89. 0, // ShareAccess
  90. FILE_OPEN_IF, // CreateDisposition
  91. 0, // CreateOptions
  92. NULL, // EaBuffer
  93. 0 // EaLength
  94. );
  95. if (Status != STATUS_SUCCESS) {
  96. return Status;
  97. }
  98. }
  99. Status = ZwDeviceIoControlFile(FileHandle,
  100. NULL, // Event
  101. NULL, // ApcRoutine
  102. NULL, // ApcContext
  103. &IoStatusBlock,
  104. IOCTL_GPC_GET_ENTRIES,
  105. NULL,
  106. 0,
  107. (PVOID)pGpcEntries,
  108. sizeof(GPC_EXPORTED_CALLS)
  109. );
  110. pGpcEntries->Reserved = FileHandle;
  111. return Status;
  112. }
  113. NTSTATUS
  114. GpcDeinitialize(
  115. IN PGPC_EXPORTED_CALLS pGpcEntries
  116. )
  117. {
  118. NTSTATUS Status;
  119. Status = ZwClose(pGpcEntries->Reserved);
  120. if (NT_SUCCESS(Status)) {
  121. RtlZeroMemory(pGpcEntries, sizeof(GPC_EXPORTED_CALLS));
  122. }
  123. return Status;
  124. }