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.

203 lines
5.2 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: B R O W S D L G . C P P
  7. //
  8. // Contents: Dialog box handling for Browser configuration.
  9. //
  10. // Notes:
  11. //
  12. // Author: danielwe 3 Mar 1997
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include <lm.h>
  18. #include <icanon.h>
  19. #include "mscliobj.h"
  20. #include "ncreg.h"
  21. #include "ncui.h"
  22. static const WCHAR c_szWksParams[] = L"System\\CurrentControlSet\\Services\\LanmanWorkstation\\Parameters";
  23. static const WCHAR c_szBrowserParams[] = L"System\\CurrentControlSet\\Services\\Browser\\Parameters";
  24. static const WCHAR c_szOtherDomains[] = L"OtherDomains";
  25. //+---------------------------------------------------------------------------
  26. //
  27. // Function: FIsValidDomainName
  28. //
  29. // Purpose: Returns TRUE if the given domain name is a valid NetBIOS name.
  30. //
  31. // Arguments:
  32. // pszName [in] Domain name to validate
  33. //
  34. // Returns: TRUE if the name is valid, FALSE otherwise.
  35. //
  36. // Author: danielwe 3 Mar 1997
  37. //
  38. // Notes: $REVIEW (danielwe): Use new netsetup function instead?
  39. //
  40. BOOL FIsValidDomainName(PCWSTR pszName)
  41. {
  42. NET_API_STATUS nerr;
  43. // Make sure the given name is a valid domain name
  44. nerr = NetpNameValidate(NULL, const_cast<PWSTR>(pszName),
  45. NAMETYPE_DOMAIN, 0L);
  46. return !!(NERR_Success == nerr);
  47. }
  48. //+---------------------------------------------------------------------------
  49. //
  50. // Member: CMSClient::HrGetBrowserRegistryInfo
  51. //
  52. // Purpose: Read data from the registry into an in-memory copy.
  53. //
  54. // Arguments:
  55. // (none)
  56. //
  57. // Returns: HRESULT, Error code.
  58. //
  59. // Author: danielwe 3 Mar 1997
  60. //
  61. // Notes:
  62. //
  63. HRESULT CMSClient::HrGetBrowserRegistryInfo()
  64. {
  65. HRESULT hr = S_OK;
  66. HKEY hkeyWksParams = NULL;
  67. Assert(!m_szDomainList);
  68. // Open LanmanWorkstation Parameters key
  69. hr = HrRegOpenKeyEx(HKEY_LOCAL_MACHINE, c_szWksParams,
  70. KEY_READ, &hkeyWksParams);
  71. if (FAILED(hr))
  72. {
  73. if (hr == HRESULT_FROM_WIN32 (ERROR_FILE_NOT_FOUND))
  74. {
  75. // Optional value. Ok if not there.
  76. hr = S_OK;
  77. }
  78. else
  79. {
  80. goto err;
  81. }
  82. }
  83. if (hkeyWksParams)
  84. {
  85. hr = HrRegQueryMultiSzWithAlloc(hkeyWksParams, c_szOtherDomains,
  86. &m_szDomainList);
  87. if (FAILED(hr))
  88. {
  89. if (hr == HRESULT_FROM_WIN32 (ERROR_FILE_NOT_FOUND))
  90. {
  91. AssertSz(!m_szDomainList, "Call failed, so why is this not "
  92. "still NULL?");
  93. // No problem if value is not there.
  94. hr = S_OK;
  95. }
  96. else
  97. {
  98. goto err;
  99. }
  100. }
  101. }
  102. Assert(SUCCEEDED(hr));
  103. // If we didn't get a domain list yet, make a new default one.
  104. if (!m_szDomainList)
  105. {
  106. // Allocate space for empty string
  107. m_szDomainList = new WCHAR[1];
  108. if (m_szDomainList != NULL)
  109. {
  110. *m_szDomainList = 0;
  111. }
  112. }
  113. err:
  114. RegSafeCloseKey(hkeyWksParams);
  115. TraceError("CMSClient::HrGetBrowserRegistryInfo", hr);
  116. return hr;
  117. }
  118. //+---------------------------------------------------------------------------
  119. //
  120. // Member: CMSClient::HrSetBrowserRegistryInfo
  121. //
  122. // Purpose: Write what we have saved in memory into the registry.
  123. //
  124. // Arguments:
  125. // (none)
  126. //
  127. // Returns: HRESULT, Error code.
  128. //
  129. // Author: danielwe 3 Mar 1997
  130. //
  131. // Notes:
  132. //
  133. HRESULT CMSClient::HrSetBrowserRegistryInfo()
  134. {
  135. HRESULT hr = S_OK;
  136. if (m_fBrowserChanges)
  137. {
  138. HKEY hkeyBrowserParams = NULL;
  139. // Verify that the Browser Parameters key exists. If not, we can't
  140. // continue.
  141. hr = HrRegOpenKeyEx(HKEY_LOCAL_MACHINE, c_szBrowserParams,
  142. KEY_ALL_ACCESS, &hkeyBrowserParams);
  143. if (SUCCEEDED(hr))
  144. {
  145. HKEY hkeyWksParams = NULL;
  146. // Open LanmanWorkstation Parameters key
  147. hr = HrRegOpenKeyEx(HKEY_LOCAL_MACHINE, c_szWksParams,
  148. KEY_ALL_ACCESS, &hkeyWksParams);
  149. if (SUCCEEDED(hr))
  150. {
  151. hr = HrRegSetMultiSz(hkeyWksParams, c_szOtherDomains,
  152. m_szDomainList);
  153. RegSafeCloseKey(hkeyWksParams);
  154. }
  155. RegSafeCloseKey(hkeyBrowserParams);
  156. }
  157. }
  158. TraceError("CMSClient::HrSetBrowserRegistryInfo", hr);
  159. return hr;
  160. }
  161. //+---------------------------------------------------------------------------
  162. //
  163. // Member: CMSClient::SetBrowserDomainList
  164. //
  165. // Purpose: Replace the current domain list with a new copy (obtained from
  166. // the dialog).
  167. //
  168. // Arguments:
  169. // pszNewList [in] New domain list in MULTI_SZ format.
  170. //
  171. // Returns: Nothing.
  172. //
  173. // Author: danielwe 3 Mar 1997
  174. //
  175. // Notes:
  176. //
  177. VOID CMSClient::SetBrowserDomainList(PWSTR pszNewList)
  178. {
  179. delete [] m_szDomainList;
  180. m_szDomainList = pszNewList;
  181. m_fBrowserChanges = TRUE;
  182. }