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.

314 lines
6.5 KiB

  1. /*++
  2. Copyright (c) 1989-2001 Microsoft Corporation
  3. Module Name:
  4. smbstat.c
  5. Abstract:
  6. Platform independent utility functions
  7. Author:
  8. Jiandong Ruan
  9. Revision History:
  10. --*/
  11. #include <nt.h>
  12. #include <ntrtl.h>
  13. #include <nturtl.h>
  14. #include <windows.h>
  15. #include <shellapi.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <locale.h>
  19. #include <tdi.h>
  20. #include "ip6util.h"
  21. #include "smbioctl.h"
  22. #include <nls.h>
  23. #include "localmsg.h"
  24. HANDLE
  25. OpenSmb(LPWSTR Name);
  26. NTSTATUS
  27. SmbstatStop(HANDLE);
  28. NTSTATUS
  29. SmbstatStart(HANDLE);
  30. void AddOrRemoveSmb6(BOOL fAddIpv6);
  31. BOOL IsSmb6Installed();
  32. NTSTATUS
  33. SmbstatEnableNagling(HANDLE);
  34. NTSTATUS
  35. SmbstatDisableNagling(HANDLE);
  36. NTSTATUS
  37. SmbSetIPv6ProtectionLevel(
  38. HANDLE hSmb,
  39. PNBSMB_IPV6_PROTECTION_PARAM pNbParam
  40. );
  41. void _cdecl main(void)
  42. {
  43. LPWSTR CommandLine;
  44. int Argc;
  45. LPWSTR *Argv;
  46. HANDLE handle;
  47. setlocale(LC_ALL, "");
  48. CommandLine = GetCommandLineW();
  49. if (NULL == CommandLine) {
  50. exit (1);
  51. }
  52. Argv = CommandLineToArgvW(CommandLine, &Argc);
  53. if (Argc < 2) {
  54. exit (1);
  55. }
  56. if (!IsSmb6Installed()) {
  57. if (_wcsicmp(Argv[1], L"install") == 0) {
  58. AddOrRemoveSmb6 (TRUE);
  59. }
  60. NlsPutMsg(STDOUT, SMB_MESSAGE_16);
  61. NlsPutMsg(STDOUT, SMB_MESSAGE_17, Argv[0]);
  62. exit (0);
  63. }
  64. if (_wcsicmp(Argv[1], L"uninstall") == 0) {
  65. AddOrRemoveSmb6 (FALSE);
  66. exit (0);
  67. }
  68. handle = OpenSmb(DD_SMB6_EXPORT_NAME);
  69. if (handle == NULL) {
  70. exit(1);
  71. }
  72. if (_wcsicmp(Argv[1], L"EnableNagling") == 0) {
  73. SmbstatEnableNagling(handle);
  74. } else if (_wcsicmp(Argv[1], L"DisableNagling") == 0) {
  75. SmbstatDisableNagling(handle);
  76. } else if (_wcsicmp(Argv[1], L"Stop") == 0) {
  77. SmbstatStop(handle);
  78. } else if (_wcsicmp(Argv[1], L"Start") == 0) {
  79. SmbstatStart(handle);
  80. } else if (_wcsicmp(Argv[1], L"IPv6ProtectionLevel") == 0) {
  81. if (Argc < 4) {
  82. fprintf(stderr, "Usage: %s IPv6ProtectionLevel <InboundLevel> <OutgoundFlag>\n", Argv[0]);
  83. fprintf(stderr, "\tInboundLevel: inbound protection level (valid value=10, 20, or 30)\n");
  84. fprintf(stderr, "\tOutboundFlag: outbound flag for skipping global IPv6 address\n");
  85. } else {
  86. NBSMB_IPV6_PROTECTION_PARAM NbParam = { 0 };
  87. NbParam.uIPv6ProtectionLevel = _wtoi(Argv[2]);
  88. NbParam.bIPv6EnableOutboundGlobal = _wtoi(Argv[3]);
  89. SmbSetIPv6ProtectionLevel(handle, &NbParam);
  90. }
  91. }
  92. NtClose(handle);
  93. }
  94. HANDLE
  95. OpenSmb(
  96. LPWSTR Name
  97. )
  98. {
  99. UNICODE_STRING ucName;
  100. OBJECT_ATTRIBUTES ObAttr;
  101. HANDLE StreamHandle;
  102. IO_STATUS_BLOCK IoStatusBlock;
  103. NTSTATUS status;
  104. RtlInitUnicodeString(&ucName, Name);
  105. InitializeObjectAttributes(
  106. &ObAttr,
  107. &ucName,
  108. OBJ_CASE_INSENSITIVE,
  109. (HANDLE) NULL,
  110. (PSECURITY_DESCRIPTOR) NULL
  111. );
  112. status = NtCreateFile (
  113. &StreamHandle,
  114. SYNCHRONIZE | FILE_READ_DATA | FILE_WRITE_DATA,
  115. &ObAttr,
  116. &IoStatusBlock,
  117. NULL,
  118. FILE_ATTRIBUTE_NORMAL,
  119. FILE_SHARE_READ | FILE_SHARE_WRITE,
  120. FILE_OPEN_IF,
  121. 0,
  122. NULL,
  123. 0
  124. );
  125. if (status != STATUS_SUCCESS) {
  126. return NULL;
  127. }
  128. return StreamHandle;
  129. }
  130. NTSTATUS
  131. CallDriver(
  132. HANDLE hSmb,
  133. DWORD Ioctl,
  134. PVOID OutputBuffer,
  135. ULONG OutputLength,
  136. PVOID InputBuffer,
  137. ULONG InputLength
  138. )
  139. {
  140. NTSTATUS status;
  141. IO_STATUS_BLOCK iosb;
  142. status = NtDeviceIoControlFile(
  143. hSmb,
  144. NULL,
  145. NULL,
  146. NULL,
  147. &iosb,
  148. Ioctl,
  149. InputBuffer,
  150. InputLength,
  151. OutputBuffer,
  152. OutputLength
  153. );
  154. if (status == STATUS_PENDING) {
  155. status = NtWaitForSingleObject(
  156. hSmb,
  157. TRUE,
  158. NULL
  159. );
  160. if (NT_SUCCESS(status)) {
  161. status = iosb.Status;
  162. }
  163. }
  164. return status; }
  165. NTSTATUS
  166. SmbstatEnableNagling(
  167. HANDLE hSmb
  168. )
  169. {
  170. NTSTATUS status;
  171. status = CallDriver(
  172. hSmb,
  173. IOCTL_SMB_ENABLE_NAGLING,
  174. NULL,
  175. 0,
  176. NULL,
  177. 0
  178. );
  179. if (status != STATUS_SUCCESS) {
  180. printf ("SmbStop: return 0x%08lx\n", status);
  181. }
  182. return status;
  183. }
  184. NTSTATUS
  185. SmbstatDisableNagling(
  186. HANDLE hSmb
  187. )
  188. {
  189. NTSTATUS status;
  190. status = CallDriver(
  191. hSmb,
  192. IOCTL_SMB_DISABLE_NAGLING,
  193. NULL,
  194. 0,
  195. NULL,
  196. 0
  197. );
  198. if (status != STATUS_SUCCESS) {
  199. printf ("SmbStop: return 0x%08lx\n", status);
  200. }
  201. return status;
  202. }
  203. NTSTATUS
  204. SmbstatStart(
  205. HANDLE hSmb
  206. )
  207. {
  208. NTSTATUS status;
  209. status = CallDriver(
  210. hSmb,
  211. IOCTL_SMB_START,
  212. NULL,
  213. 0,
  214. NULL,
  215. 0
  216. );
  217. if (status != STATUS_SUCCESS) {
  218. printf ("SmbStop: return 0x%08lx\n", status);
  219. }
  220. return status;
  221. }
  222. NTSTATUS
  223. SmbstatStop(
  224. HANDLE hSmb
  225. )
  226. {
  227. NTSTATUS status;
  228. status = CallDriver(
  229. hSmb,
  230. IOCTL_SMB_STOP,
  231. NULL,
  232. 0,
  233. NULL,
  234. 0
  235. );
  236. if (status != STATUS_SUCCESS) {
  237. printf ("SmbStop: return 0x%08lx\n", status);
  238. }
  239. return status;
  240. }
  241. NTSTATUS
  242. SmbSetIPv6ProtectionLevel(
  243. HANDLE hSmb,
  244. PNBSMB_IPV6_PROTECTION_PARAM pNbParam
  245. )
  246. {
  247. NTSTATUS status;
  248. printf("Level %d\n", pNbParam->uIPv6ProtectionLevel);
  249. printf("Flag %d\n", pNbParam->bIPv6EnableOutboundGlobal);
  250. status = CallDriver(
  251. hSmb,
  252. IOCTL_SMB_SET_IPV6_PROTECTION_LEVEL,
  253. NULL,
  254. 0,
  255. pNbParam,
  256. sizeof(pNbParam[0])
  257. );
  258. if (status != STATUS_SUCCESS) {
  259. printf ("SmbSetIPv6ProtectionLevel: return 0x%08lx\n", status);
  260. }
  261. return status;
  262. }
  263. void
  264. ausage(void)
  265. {
  266. NlsPutMsg(STDOUT, SMB_MESSAGE_15);
  267. // printf("You do not have local Administrator privileges.\n");
  268. exit(1);
  269. }