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.

161 lines
5.0 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: N C I D E N T . H
  7. //
  8. // Contents: CNetCfgIdentification object.
  9. //
  10. // Notes:
  11. //
  12. // Author: danielwe 19 Mar 1997
  13. //
  14. //----------------------------------------------------------------------------
  15. #pragma once
  16. #include "resource.h"
  17. // Include new NetSetup APIs
  18. extern "C"
  19. {
  20. #include <lmcons.h>
  21. #include <lmerr.h>
  22. #include <lmapibuf.h>
  23. #include <lmjoin.h>
  24. }
  25. typedef enum tagROLE_FLAGS
  26. {
  27. GCR_STANDALONE = 0x0001,
  28. GCR_MEMBER = 0x0002,
  29. GCR_PDC = 0x0004,
  30. GCR_BDC = 0x0008,
  31. } ROLE_FLAGS;
  32. typedef enum tagJOIN_DOMAIN_FLAGS
  33. {
  34. JDF_CREATE_ACCOUNT = 0x0001,
  35. JDF_WIN9x_UPGRADE = 0x0002,
  36. JDF_JOIN_UNSECURE = 0x0004,
  37. JDF_MACHINE_PWD_PASSED = 0x0008
  38. } JOIN_DOMAIN_FLAGS;
  39. class CNetCfgIdentification
  40. {
  41. public:
  42. CNetCfgIdentification();
  43. ~CNetCfgIdentification();
  44. // INetCfgIdentification
  45. STDMETHOD(Validate)();
  46. STDMETHOD(Cancel)();
  47. STDMETHOD(Apply)();
  48. STDMETHOD(GetWorkgroupName)(PWSTR* ppszwWorkgroup);
  49. STDMETHOD(GetDomainName)(PWSTR* ppszwDomain);
  50. STDMETHOD(GetComputerRole)(DWORD* pdwRoleFlags);
  51. STDMETHOD(JoinWorkgroup)(PCWSTR pszwWorkgroup);
  52. STDMETHOD(JoinDomain)(PCWSTR pszwDomain, PCWSTR pszMachineObjectOU,
  53. PCWSTR pszwUserName,
  54. PCWSTR pszwPassword, DWORD dwJoinFlags);
  55. private:
  56. // Need to hold onto info until Apply() is called.
  57. PWSTR m_szwNewDWName; // New domain or workgroup name.
  58. PWSTR m_szwPassword; // Password.
  59. PWSTR m_szwUserName; // User name.
  60. PWSTR m_szMachineObjectOU; // Machine Object OU
  61. PWSTR m_szwCurComputerName; // Current computer name
  62. PWSTR m_szwCurDWName; // Current domain or workgroup name
  63. NETSETUP_JOIN_STATUS m_jsCur; // Determines whether m_szwCurDWName
  64. // is a domain name or workgroup name
  65. NETSETUP_JOIN_STATUS m_jsNew; // Determines whether m_szwNewDWName
  66. // is a domain name or workgroup name
  67. DWORD m_dwJoinFlags; // Join flags for domain.
  68. DWORD m_dwCreateFlags; // Flags for creating domain controller.
  69. BOOL m_fValid; // TRUE if all data has been validated
  70. HRESULT HrValidateMachineName(PCWSTR pszwName);
  71. HRESULT HrValidateWorkgroupName(PCWSTR pszwName);
  72. HRESULT HrValidateDomainName(PCWSTR pszwName, PCWSTR pszwUserName,
  73. PCWSTR pszwPassword);
  74. HRESULT HrSetComputerName(VOID);
  75. HRESULT HrJoinWorkgroup(VOID);
  76. HRESULT HrJoinDomain(VOID);
  77. HRESULT HrGetCurrentComputerName(PWSTR* ppszwComputer);
  78. HRESULT HrGetNewComputerName(PWSTR* ppszwComputer);
  79. HRESULT HrGetNewestComputerName(PCWSTR* pwszName);
  80. HRESULT HrGetNewestDomainOrWorkgroupName(NETSETUP_JOIN_STATUS js,
  81. PCWSTR* pwszName);
  82. HRESULT HrEnsureCurrentComputerName(VOID);
  83. HRESULT HrEnsureCurrentDomainOrWorkgroupName(VOID);
  84. HRESULT HrEstablishNewDomainOrWorkgroupName(NETSETUP_JOIN_STATUS js);
  85. #ifdef DBG
  86. BOOL FIsJoinedToDomain(VOID);
  87. #else
  88. BOOL FIsJoinedToDomain()
  89. {
  90. AssertSzH(m_szwCurDWName, "I can't tell you if you're joined because "
  91. "I don't know yet!");
  92. return !!(m_jsCur == NetSetupDomainName);
  93. }
  94. #endif
  95. NETSETUP_JOIN_STATUS GetCurrentJoinStatus(VOID);
  96. NETSETUP_JOIN_STATUS GetNewJoinStatus(VOID);
  97. };
  98. inline NETSETUP_JOIN_STATUS CNetCfgIdentification::GetCurrentJoinStatus()
  99. {
  100. AssertSzH((m_jsCur == NetSetupDomainName) ||
  101. (m_jsCur == NetSetupWorkgroupName), "Invalid current join status!");
  102. AssertSzH(m_szwCurDWName, "Why are you asking for this without knowing "
  103. "what the current domain or workgroup name is??");
  104. return m_jsCur;
  105. }
  106. inline NETSETUP_JOIN_STATUS CNetCfgIdentification::GetNewJoinStatus()
  107. {
  108. AssertSzH((m_jsNew == NetSetupDomainName) ||
  109. (m_jsNew == NetSetupWorkgroupName), "Invalid new join status!");
  110. AssertSzH(m_szwNewDWName, "Why are you asking for this without knowing "
  111. "what the new domain or workgroup name is??");
  112. return m_jsNew;
  113. }
  114. inline CNetCfgIdentification::CNetCfgIdentification() :
  115. m_szwNewDWName(NULL),
  116. m_szwPassword(NULL),
  117. m_szwUserName(NULL),
  118. m_szMachineObjectOU(NULL),
  119. m_szwCurComputerName(NULL),
  120. m_szwCurDWName(NULL),
  121. m_dwJoinFlags(0),
  122. m_dwCreateFlags(0),
  123. m_fValid(FALSE),
  124. m_jsCur(NetSetupUnjoined),
  125. m_jsNew(NetSetupUnjoined)
  126. {
  127. }
  128. inline CNetCfgIdentification::~CNetCfgIdentification()
  129. {
  130. delete m_szwNewDWName;
  131. delete m_szwCurComputerName;
  132. delete m_szMachineObjectOU;
  133. delete m_szwCurDWName;
  134. delete m_szwPassword;
  135. delete m_szwUserName;
  136. }
  137. //
  138. // Global functions
  139. //
  140. HRESULT HrFromNerr(NET_API_STATUS nerr);