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.

149 lines
4.2 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. Spnetupg.c
  5. Abstract:
  6. Configuration routines for the disabling the nework services
  7. Author:
  8. Terry Kwan (terryk) 23-Nov-1993, provided code
  9. Sunil Pai (sunilp) 23-Nov-1993, merged and modified code
  10. Michael Miller (MikeMi) 26-Jun-1997, updated to new model
  11. Revision History:
  12. --*/
  13. #include "spprecmp.h"
  14. #pragma hdrstop
  15. // TEXT MODE FLAGS
  16. // Note: TMF_DISABLE and TMF_REMOTE_BOOT_CRITICAL are retired.
  17. // The only TextModeFlag with meaning now is TMF_DISABLE_FOR_DELETION.
  18. // This flag is set during winnt32.exe to prepare networking services for
  19. // deletion during GUI mode setup. The start type is not saved and restored
  20. // any longer because GUI mode setup does not allow arbitrary services to
  21. // be auto-started.
  22. //
  23. #define TMF_DISABLE_FOR_DELETION 0x00000004
  24. // TEXT MODE START DISABLE VALUE
  25. #define STARTVALUE_DISABLE 4
  26. NTSTATUS
  27. SpDisableNetwork(
  28. IN PVOID SifHandle,
  29. IN HANDLE hKeySoftwareHive,
  30. IN HANDLE hKeyControlSet )
  31. {
  32. NTSTATUS Status = STATUS_SUCCESS;
  33. OBJECT_ATTRIBUTES Obja;
  34. UNICODE_STRING UnicodeString;
  35. UNICODE_STRING StringRegStartValueName;
  36. PWSTR pszServiceName;
  37. PUCHAR RegBuffer;
  38. const ULONG cbRegBuffer = sizeof(KEY_VALUE_PARTIAL_INFORMATION)+MAX_PATH+1;
  39. DWORD cbSize;
  40. HKEY hkeyServices;
  41. HKEY hkeyService;
  42. INT i;
  43. DWORD dwStart;
  44. DWORD dwNewStart = STARTVALUE_DISABLE;
  45. DWORD dwFlags;
  46. RtlInitUnicodeString(&StringRegStartValueName, L"Start");
  47. RegBuffer = SpMemAlloc(cbRegBuffer);
  48. pszServiceName = SpMemAlloc(MAX_PATH+1);
  49. // open services key
  50. //
  51. INIT_OBJA( &Obja, &UnicodeString, L"Services");
  52. Obja.RootDirectory = hKeyControlSet;
  53. Status = ZwOpenKey(&hkeyServices, KEY_ALL_ACCESS, &Obja);
  54. if (NT_SUCCESS(Status))
  55. {
  56. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_INFO_LEVEL, "SpDisableNetwork: Disabling network services...\n"));
  57. // enumerate all services
  58. //
  59. for ( i = 0;
  60. STATUS_SUCCESS == ZwEnumerateKey(hkeyServices,
  61. i,
  62. KeyBasicInformation,
  63. RegBuffer,
  64. cbRegBuffer,
  65. &cbSize);
  66. i++)
  67. {
  68. ((PKEY_BASIC_INFORMATION)RegBuffer)->Name[((PKEY_BASIC_INFORMATION)RegBuffer)->NameLength/sizeof(WCHAR)] = L'\0';
  69. wcscpy(pszServiceName, ((PKEY_BASIC_INFORMATION)RegBuffer)->Name);
  70. // open the service key
  71. //
  72. INIT_OBJA(&Obja, &UnicodeString, pszServiceName);
  73. Obja.RootDirectory = hkeyServices;
  74. Status = ZwOpenKey(&hkeyService, KEY_ALL_ACCESS, &Obja);
  75. if (NT_SUCCESS(Status))
  76. {
  77. // read the TextModeFlags
  78. //
  79. RtlInitUnicodeString(&UnicodeString, L"TextModeFlags");
  80. Status = ZwQueryValueKey(hkeyService,
  81. &UnicodeString,
  82. KeyValuePartialInformation,
  83. RegBuffer,
  84. cbRegBuffer,
  85. &cbSize);
  86. if (NT_SUCCESS(Status))
  87. {
  88. // Should the service be disabled?
  89. //
  90. dwFlags = *((DWORD*)(&(((PKEY_VALUE_PARTIAL_INFORMATION)RegBuffer)->Data)));
  91. if (dwFlags & TMF_DISABLE_FOR_DELETION)
  92. {
  93. Status = ZwSetValueKey(
  94. hkeyService,
  95. &StringRegStartValueName,
  96. 0,
  97. REG_DWORD,
  98. &dwNewStart,
  99. sizeof(DWORD));
  100. }
  101. }
  102. Status = STATUS_SUCCESS;
  103. ZwClose(hkeyService);
  104. }
  105. if (!NT_SUCCESS(Status))
  106. {
  107. break;
  108. }
  109. }
  110. ZwClose(hkeyServices);
  111. }
  112. SpMemFree(pszServiceName);
  113. SpMemFree(RegBuffer);
  114. return Status;
  115. }