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.

238 lines
4.9 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. Drrdr.c
  5. Abstract:
  6. This module implements a minimal app to load and unload,
  7. the minirdr. Also explicit start/stop control is
  8. provided
  9. --*/
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <nt.h>
  14. #include <ntrtl.h>
  15. #include <nturtl.h>
  16. #include <windows.h>
  17. #include <..\sys\rdpdr.h>
  18. void DrMrxStart(void);
  19. void DrMrxStop(void);
  20. void DrMrxLoad(void);
  21. void DrMrxUnload(void);
  22. void DrMrxUsage(void);
  23. char* DrMrxDriverName = "RdpDr";
  24. VOID
  25. _CRTAPI1
  26. main(
  27. int argc,
  28. char *argv[]
  29. )
  30. {
  31. char command[16];
  32. BOOL fRun = TRUE;
  33. DrMrxUsage();
  34. while (fRun)
  35. {
  36. printf("\nCommand:");
  37. scanf("%s",command);
  38. switch(command[0])
  39. {
  40. case 'Q':
  41. case 'q':
  42. fRun = FALSE;
  43. break;
  44. case 'L':
  45. case 'l':
  46. DrMrxLoad();
  47. break;
  48. case 'U':
  49. case 'u':
  50. DrMrxUnload();
  51. break;
  52. case 'S':
  53. case 's':
  54. DrMrxStart();
  55. break;
  56. case 'T':
  57. case 't':
  58. DrMrxStop();
  59. break;
  60. case '?':
  61. default:
  62. DrMrxUsage();
  63. break;
  64. }
  65. }
  66. }
  67. VOID DrMrxStart()
  68. /*++
  69. Routine Description:
  70. This routine starts the Dr mini redirector.
  71. Notes:
  72. The start is distinguished from Load. During this phase the appropriate FSCTL
  73. is issued.
  74. --*/
  75. {
  76. NTSTATUS ntstatus;
  77. UNICODE_STRING DeviceName;
  78. IO_STATUS_BLOCK IoStatusBlock;
  79. OBJECT_ATTRIBUTES ObjectAttributes;
  80. HANDLE DrMrxHandle;
  81. //
  82. // Open the Dr Mrx device.
  83. //
  84. RtlInitUnicodeString(&DeviceName, RDPDR_DEVICE_NAME_U);
  85. InitializeObjectAttributes(
  86. &ObjectAttributes,
  87. &DeviceName,
  88. OBJ_CASE_INSENSITIVE,
  89. NULL,
  90. NULL
  91. );
  92. ntstatus = NtOpenFile(
  93. &DrMrxHandle,
  94. SYNCHRONIZE,
  95. &ObjectAttributes,
  96. &IoStatusBlock,
  97. FILE_SHARE_VALID_FLAGS,
  98. FILE_SYNCHRONOUS_IO_NONALERT
  99. );
  100. if (ntstatus == STATUS_SUCCESS) {
  101. ntstatus = NtFsControlFile(
  102. DrMrxHandle,
  103. 0,
  104. NULL,
  105. NULL,
  106. &IoStatusBlock,
  107. FSCTL_DR_START,
  108. NULL,
  109. 0,
  110. NULL,
  111. 0
  112. );
  113. NtClose(DrMrxHandle);
  114. }
  115. printf("Dr MRx mini redirector start status %lx\n",ntstatus);
  116. }
  117. VOID DrMrxStop()
  118. /*++
  119. Routine Description:
  120. This routine stops the Dr mini redirector.
  121. Notes:
  122. The stop is distinguished from unload. During this phase the appropriate FSCTL
  123. is issued and the shared memory/mutex data structures required for the Network
  124. provider DLL are torn down.
  125. --*/
  126. {
  127. NTSTATUS ntstatus;
  128. UNICODE_STRING DeviceName;
  129. IO_STATUS_BLOCK IoStatusBlock;
  130. OBJECT_ATTRIBUTES ObjectAttributes;
  131. HANDLE DrMrxHandle;
  132. //
  133. // Open the Dr Mrx device.
  134. //
  135. RtlInitUnicodeString(&DeviceName, RDPDR_DEVICE_NAME_U);
  136. InitializeObjectAttributes(
  137. &ObjectAttributes,
  138. &DeviceName,
  139. OBJ_CASE_INSENSITIVE,
  140. NULL,
  141. NULL
  142. );
  143. ntstatus = NtOpenFile(
  144. &DrMrxHandle,
  145. SYNCHRONIZE,
  146. &ObjectAttributes,
  147. &IoStatusBlock,
  148. FILE_SHARE_VALID_FLAGS,
  149. FILE_SYNCHRONOUS_IO_NONALERT
  150. );
  151. if (ntstatus == STATUS_SUCCESS) {
  152. ntstatus = NtFsControlFile(
  153. DrMrxHandle,
  154. 0,
  155. NULL,
  156. NULL,
  157. &IoStatusBlock,
  158. FSCTL_DR_STOP,
  159. NULL,
  160. 0,
  161. NULL,
  162. 0
  163. );
  164. NtClose(DrMrxHandle);
  165. }
  166. printf("Dr MRx mini redirector stop status %lx\n",ntstatus);
  167. }
  168. VOID DrMrxLoad()
  169. {
  170. printf("Loading Dr minirdr.......\n");
  171. system("net start rdpdr");
  172. }
  173. VOID DrMrxUnload(void)
  174. {
  175. printf("Unloading Dr minirdr\n");
  176. system("net stop rdpdr");
  177. }
  178. VOID DrMrxUsage(void){
  179. printf("\n");
  180. printf(" Dr Mini-rdr Utility");
  181. printf(" The following commands are valid \n");
  182. printf(" L -> load the Dr minirdr driver\n");
  183. printf(" U -> unload the Dr minirdr driver\n");
  184. printf(" S -> start the Dr minirdr driver\n");
  185. printf(" T -> stop the Dr minirdr driver\n");
  186. }