Source code of Windows XP (NT5)
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.

400 lines
8.7 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. smbrdr.c
  5. Abstract:
  6. This module implements a simple app to switch between rdr1 and rdr2
  7. Author:
  8. Joe Linn (JoeLinn) 21-jul-94
  9. Revision History:
  10. added in stuff to control the filesystem proxy mini AKA the reflector
  11. --*/
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <nt.h>
  16. #include <ntrtl.h>
  17. #include <nturtl.h>
  18. #include <windows.h>
  19. #include "smbrdr.h"
  20. #include <ntddnfs2.h> //this might should be in smbrdr.h
  21. #include <ntddumod.h> //this might should be in smbrdr.h
  22. VOID SwRxUsage(void);
  23. VOID SwRxPrintCurrentRdrMsg(void);
  24. BOOLEAN
  25. SwRxIsRdr2Running(
  26. void);
  27. BOOLEAN SwRxNoStop = FALSE;
  28. BOOLEAN SwRxNoStart = FALSE;
  29. BOOLEAN SwRxProxyEnabled = FALSE;
  30. VOID SwRxStartStop(
  31. IN PSWRX_REGISTRY_MUCKER Mucker
  32. )
  33. {
  34. BOOLEAN Rdr2WasRunning = FALSE;
  35. BOOLEAN Rdr2IsRunning = FALSE;
  36. Rdr2WasRunning = SwRxIsRdr2Running();
  37. if (!SwRxNoStop) {
  38. printf("Stopping rdr.......\n");
  39. system("net stop rdr /y");
  40. if (Rdr2WasRunning) {
  41. SwRxStopProxyFileSystem();
  42. printf("Stopping rdbss.......\n");
  43. system("net stop rdbss /y");
  44. }
  45. }
  46. Mucker();
  47. if (!SwRxNoStart) {
  48. printf("Starting rdr\n");
  49. system("net start rdr");
  50. printf("Starting messenger\n");
  51. system("net start messenger");
  52. printf("Starting netlogon\n");
  53. system("net start netlogon");
  54. if (SwRxProxyEnabled) {
  55. SwRxStartProxyFileSystem();
  56. }
  57. }
  58. Rdr2IsRunning = SwRxIsRdr2Running();
  59. DbgPrint("SMBRDR: %s was running, %s is running now\n",
  60. Rdr2WasRunning?"Rdr2":"Rdr1",
  61. Rdr2IsRunning?"Rdr2":"Rdr1"
  62. );
  63. }
  64. VOID
  65. __cdecl
  66. main(
  67. int argc,
  68. char *argv[]
  69. )
  70. {
  71. //NTSTATUS status;
  72. char *thisarg;
  73. ULONG i;
  74. if (argc<2) { SwRxPrintCurrentRdrMsg(); exit(0); }
  75. for (i=1;i<(ULONG)argc;i++) {
  76. thisarg=argv[i];
  77. printf("thisarg=%s,argc=%d\n",thisarg,argc);
  78. if (!strncmp(thisarg,"/?",2) || !strncmp(thisarg,"-?",2)){
  79. SwRxUsage();
  80. }
  81. if (!strncmp(thisarg,"/1",2) || !strncmp(thisarg,"-1",2)){
  82. printf("-1 no longer supported\n");
  83. //SwRxStartStop(SwRxRdr1Muck);
  84. exit(0);
  85. }
  86. if (!strncmp(thisarg,"/2",2) || !strncmp(thisarg,"-2",2)){
  87. SwRxStartStop(SwRxRdr2Muck);
  88. exit(0);
  89. }
  90. if (!strncmp(thisarg,"-!",2)){
  91. SwRxNoStop = TRUE;
  92. SwRxNoStart = TRUE;
  93. continue;
  94. }
  95. if (!strncmp(thisarg,"-proxy",6)){
  96. SwRxProxyEnabled = TRUE;
  97. continue;
  98. }
  99. if (!strncmp(thisarg,"-startproxy",11)){
  100. SwRxStartProxyFileSystem();
  101. exit(0);
  102. }
  103. break;
  104. }
  105. SwRxUsage();
  106. }
  107. VOID SwRxUsage(void){
  108. printf(" Usage: smbrdr [-!] [-1|-2] ");
  109. SwRxPrintCurrentRdrMsg();
  110. exit(0);
  111. }
  112. VOID SwRxPrintCurrentRdrMsg(void){
  113. PSZ notstring = "not ";
  114. if (SwRxIsRdr2Running()) {
  115. notstring = "";
  116. }
  117. printf(" (Currently, rdr2 is %srunning.)\n",notstring);
  118. }
  119. BOOLEAN
  120. SwRxIsRdr2Running(
  121. void)
  122. /*++
  123. Routine Description:
  124. This routine looks to see if the rdr is rdr2 by
  125. opening a handle and pushing down a FSCTL that rdr1 handles
  126. and rdr2 does not.
  127. Arguments:
  128. HANDLE pRdrHandle - a handle to be returned
  129. Return Value:
  130. NTSTATUS - STATUS_SUCCESS or reason for failure.
  131. --*/
  132. {
  133. NTSTATUS ntstatus;
  134. HANDLE h;
  135. UNICODE_STRING DeviceName;
  136. IO_STATUS_BLOCK IoStatusBlock;
  137. OBJECT_ATTRIBUTES ObjectAttributes;
  138. //
  139. // Open the RDBSS device.
  140. //
  141. RtlInitUnicodeString(&DeviceName,DD_NFS_DEVICE_NAME_U);
  142. InitializeObjectAttributes(
  143. &ObjectAttributes,
  144. &DeviceName,
  145. OBJ_CASE_INSENSITIVE,
  146. NULL,
  147. NULL
  148. );
  149. ntstatus = NtOpenFile(
  150. &h,
  151. SYNCHRONIZE,
  152. &ObjectAttributes,
  153. &IoStatusBlock,
  154. FILE_SHARE_VALID_FLAGS,
  155. FILE_SYNCHRONOUS_IO_NONALERT
  156. );
  157. //return(ntstatus);
  158. if (!NT_SUCCESS(ntstatus)) {
  159. printf("open didn't work\n");
  160. return(FALSE);
  161. }
  162. //
  163. // Send the request to the RDBSS FSD.
  164. //
  165. ntstatus = NtFsControlFile(
  166. h,
  167. NULL,
  168. NULL,
  169. NULL,
  170. &IoStatusBlock,
  171. FSCTL_LMR_GET_VERSIONS,
  172. NULL,
  173. 0,
  174. NULL,
  175. 0
  176. );
  177. NtClose(h);
  178. return(ntstatus==STATUS_INVALID_DEVICE_REQUEST);
  179. }
  180. VOID
  181. SwRxStartProxyFileSystem(void){
  182. NTSTATUS ntstatus;
  183. HANDLE h;
  184. UNICODE_STRING DeviceName;
  185. IO_STATUS_BLOCK IoStatusBlock;
  186. OBJECT_ATTRIBUTES ObjectAttributes;
  187. //UNICODE_STRING LinkTarget,VNetRootPart;
  188. //WCHAR StringBuffer[512];
  189. //
  190. // Get the driver loaded.
  191. //
  192. if (SwRxProxyEnabled) {
  193. printf("Starting proxy driver.......\n");
  194. system("net start reflctor");
  195. }
  196. //
  197. // Open the Proxy FileSystem driver device.
  198. //
  199. RtlInitUnicodeString(&DeviceName,UMRX_DEVICE_NAME_U);
  200. InitializeObjectAttributes(
  201. &ObjectAttributes,
  202. &DeviceName,
  203. OBJ_CASE_INSENSITIVE,
  204. NULL,
  205. NULL
  206. );
  207. ntstatus = NtOpenFile(
  208. &h,
  209. SYNCHRONIZE,
  210. &ObjectAttributes,
  211. &IoStatusBlock,
  212. FILE_SHARE_VALID_FLAGS,
  213. FILE_SYNCHRONOUS_IO_NONALERT
  214. );
  215. //
  216. // if we couldn't open.....just punt
  217. //
  218. if (!NT_SUCCESS(ntstatus)) {
  219. printf("Couldn't open the ProxyFilesystem device\n");
  220. return;
  221. }
  222. //
  223. // Send the start request...this will also set up the server, netroot
  224. // and vnetroot
  225. //
  226. ntstatus = NtFsControlFile(
  227. h,
  228. NULL,
  229. NULL,
  230. NULL,
  231. &IoStatusBlock,
  232. FSCTL_UMRX_START,
  233. NULL,
  234. 0,
  235. NULL,
  236. 0
  237. );
  238. NtClose(h);
  239. //
  240. // now we have to do the bit about making the dosdevice
  241. if (! DefineDosDeviceW(
  242. DDD_RAW_TARGET_PATH |
  243. DDD_NO_BROADCAST_SYSTEM,
  244. L"X:",
  245. UMRX_DEVICE_NAME_U L"\\;X:"
  246. UMRX_CLAIMED_SERVERNAME_U
  247. UMRX_CLAIMED_SHARENAME_U
  248. )) {
  249. printf("Couldn't set X: as a dosdevice\n");
  250. }
  251. }
  252. VOID
  253. SwRxStopProxyFileSystem(void){
  254. NTSTATUS ntstatus;
  255. HANDLE h;
  256. UNICODE_STRING DeviceName;
  257. IO_STATUS_BLOCK IoStatusBlock;
  258. OBJECT_ATTRIBUTES ObjectAttributes;
  259. //UNICODE_STRING LinkTarget,VNetRootPart;
  260. //WCHAR StringBuffer[512];
  261. //
  262. // Open the Proxy FileSystem driver device.
  263. //
  264. RtlInitUnicodeString(&DeviceName,UMRX_DEVICE_NAME_U);
  265. InitializeObjectAttributes(
  266. &ObjectAttributes,
  267. &DeviceName,
  268. OBJ_CASE_INSENSITIVE,
  269. NULL,
  270. NULL
  271. );
  272. ntstatus = NtOpenFile(
  273. &h,
  274. SYNCHRONIZE,
  275. &ObjectAttributes,
  276. &IoStatusBlock,
  277. FILE_SHARE_VALID_FLAGS,
  278. FILE_SYNCHRONOUS_IO_NONALERT
  279. );
  280. //
  281. // if we couldn't open.....just punt
  282. //
  283. if (!NT_SUCCESS(ntstatus)) {
  284. printf("Couldn't open the ProxyFilesystem device\n");
  285. return;
  286. }
  287. //
  288. // Send the stop request...this will also set up the server, netroot
  289. // and vnetroot
  290. //
  291. ntstatus = NtFsControlFile(
  292. h,
  293. NULL,
  294. NULL,
  295. NULL,
  296. &IoStatusBlock,
  297. FSCTL_UMRX_STOP,
  298. NULL,
  299. 0,
  300. NULL,
  301. 0
  302. );
  303. NtClose(h);
  304. //
  305. // now we have to get rid of the dosdevice
  306. if (! DefineDosDeviceW(
  307. DDD_REMOVE_DEFINITION |
  308. DDD_RAW_TARGET_PATH |
  309. DDD_EXACT_MATCH_ON_REMOVE |
  310. DDD_NO_BROADCAST_SYSTEM,
  311. L"X:",
  312. UMRX_DEVICE_NAME_U L"\\;X:"
  313. UMRX_CLAIMED_SERVERNAME_U
  314. UMRX_CLAIMED_SHARENAME_U
  315. )) {
  316. printf("Couldn't set X: as a dosdevice\n");
  317. }
  318. if (SwRxProxyEnabled) {
  319. printf("Stopping proxy driver.......\n");
  320. system("net stop reflctor /y");
  321. }
  322. }