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.

165 lines
3.0 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 "smbioctl.h"
  21. #define DD_SMB6_EXPORT_NAME L"\\Device\\Smb6"
  22. HANDLE
  23. OpenSmb(LPWSTR Name);
  24. NTSTATUS
  25. SmbStop(HANDLE);
  26. NTSTATUS
  27. SmbStart(HANDLE);
  28. void _cdecl main(void)
  29. {
  30. LPWSTR CommandLine;
  31. int Argc;
  32. LPWSTR *Argv;
  33. HANDLE handle;
  34. setlocale(LC_ALL, "");
  35. CommandLine = GetCommandLineW();
  36. if (NULL == CommandLine) {
  37. exit (1);
  38. }
  39. Argv = CommandLineToArgvW(CommandLine, &Argc);
  40. handle = OpenSmb(DD_SMB6_EXPORT_NAME);
  41. if (handle == NULL) {
  42. exit(1);
  43. }
  44. SmbStop(handle);
  45. NtClose(handle);
  46. }
  47. HANDLE
  48. OpenSmb(
  49. LPWSTR Name
  50. )
  51. {
  52. UNICODE_STRING ucName;
  53. OBJECT_ATTRIBUTES ObAttr;
  54. HANDLE StreamHandle;
  55. IO_STATUS_BLOCK IoStatusBlock;
  56. NTSTATUS status;
  57. RtlInitUnicodeString(&ucName, Name);
  58. InitializeObjectAttributes(
  59. &ObAttr,
  60. &ucName,
  61. OBJ_CASE_INSENSITIVE,
  62. (HANDLE) NULL,
  63. (PSECURITY_DESCRIPTOR) NULL
  64. );
  65. status = NtCreateFile (
  66. &StreamHandle,
  67. SYNCHRONIZE | GENERIC_EXECUTE,
  68. &ObAttr,
  69. &IoStatusBlock,
  70. NULL,
  71. FILE_ATTRIBUTE_NORMAL,
  72. FILE_SHARE_READ | FILE_SHARE_WRITE,
  73. FILE_OPEN_IF,
  74. 0,
  75. NULL,
  76. 0
  77. );
  78. if (status != STATUS_SUCCESS) {
  79. return NULL;
  80. }
  81. return StreamHandle;
  82. }
  83. NTSTATUS
  84. CallDriver(
  85. HANDLE hSmb,
  86. DWORD Ioctl,
  87. PVOID OutputBuffer,
  88. ULONG OutputLength,
  89. PVOID InputBuffer,
  90. ULONG InputLength
  91. )
  92. {
  93. NTSTATUS status;
  94. IO_STATUS_BLOCK iosb;
  95. status = NtDeviceIoControlFile(
  96. hSmb,
  97. NULL,
  98. NULL,
  99. NULL,
  100. &iosb,
  101. Ioctl,
  102. InputBuffer,
  103. InputLength,
  104. OutputBuffer,
  105. OutputLength
  106. );
  107. if (status == STATUS_PENDING) {
  108. status = NtWaitForSingleObject(
  109. hSmb,
  110. TRUE,
  111. NULL
  112. );
  113. if (NT_SUCCESS(status)) {
  114. status = iosb.Status;
  115. }
  116. }
  117. return status;
  118. }
  119. NTSTATUS
  120. SmbStop(
  121. HANDLE hSmb
  122. )
  123. {
  124. NTSTATUS status;
  125. status = CallDriver(
  126. hSmb,
  127. IOCTL_SMB_STOP,
  128. NULL,
  129. 0,
  130. NULL,
  131. 0
  132. );
  133. if (status != STATUS_SUCCESS) {
  134. printf ("SmbStop: return 0x%08lx\n", status);
  135. }
  136. return status;
  137. }