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.

345 lines
8.1 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 -99 **/
  4. /**********************************************************************/
  5. /*
  6. ipadddlg.cpp
  7. Comment goes here
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "winssnap.h"
  12. #include "IPAddDlg.h"
  13. #include "getipadd.h"
  14. #include "getnetbi.h"
  15. #include <objpick.h> // for CGetComputer
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. // Get replication trigger partner
  22. BOOL CGetTriggerPartner::OnInitDialog()
  23. {
  24. CIPAddressDlg::OnInitDialog();
  25. CString strText;
  26. strText.LoadString(IDS_SELECT_TRIGGER_PARTNER_TITLE);
  27. // Set the title of the dialog
  28. SetWindowText(strText);
  29. // set the description text
  30. strText.LoadString(IDS_SELECT_TRIGGER_PARTNER);
  31. m_staticDescription.SetWindowText(strText);
  32. return TRUE;
  33. }
  34. // add WINS server dialog
  35. BOOL CNewWinsServer::DoExtraValidation()
  36. {
  37. // check to see if the server is in the list
  38. BOOL fIsIpInList = m_pRootHandler->IsIPInList(m_spRootNode, m_dwServerIp);
  39. BOOL fIsNameInList = m_pRootHandler->IsServerInList(m_spRootNode, m_strServerName);
  40. if (fIsIpInList && fIsNameInList)
  41. {
  42. CThemeContextActivator themeActivator;
  43. m_editServerName.SetFocus();
  44. m_editServerName.SetSel(0, -1);
  45. AfxMessageBox(IDS_ERR_WINS_EXISTS, MB_OK);
  46. return FALSE;
  47. }
  48. return TRUE;
  49. }
  50. // add Persona Non Grata dialog
  51. BOOL CNewPersonaNonGrata::DoExtraValidation()
  52. {
  53. CThemeContextActivator themeActivator;
  54. // check if the server already exists
  55. if (m_pRepPropDlg->IsDuplicate(m_strServerName))
  56. {
  57. m_editServerName.SetFocus();
  58. m_editServerName.SetSel(0,-1);
  59. AfxMessageBox(IDS_ERR_WINS_EXISTS, MB_OK|MB_ICONINFORMATION);
  60. return FALSE;
  61. }
  62. // check the same server is being added
  63. if (m_pRepPropDlg->IsCurrentServer(m_strServerName))
  64. {
  65. m_editServerName.SetFocus();
  66. m_editServerName.SetSel(0,-1);
  67. AfxMessageBox(IDS_LOCALSERVER, MB_OK | MB_ICONINFORMATION);
  68. return FALSE;
  69. }
  70. return TRUE;
  71. }
  72. // add new replication partner dialog
  73. BOOL CNewReplicationPartner::OnInitDialog()
  74. {
  75. CIPAddressDlg::OnInitDialog();
  76. CString strText;
  77. strText.LoadString(IDS_NEW_REPLICATION_PARTNER_TITLE);
  78. // Set the title of the dialog
  79. SetWindowText(strText);
  80. strText.LoadString(IDS_NEW_REPLICATION_PARTNER_DESC);
  81. m_staticDescription.SetWindowText(strText);
  82. return TRUE;
  83. }
  84. BOOL CNewReplicationPartner::DoExtraValidation()
  85. {
  86. // check if the same servers is being added as a rep partner
  87. SPITFSNode spServerNode;
  88. m_spRepPartNode->GetParent(&spServerNode);
  89. CWinsServerHandler *pServer = GETHANDLER(CWinsServerHandler, spServerNode);
  90. CThemeContextActivator themeActivator;
  91. CString strThisServerName = pServer->m_strServerAddress;
  92. DWORD dwThisServerIP = pServer->m_dwIPAdd;
  93. if ( (m_dwServerIp == dwThisServerIP) && (m_strServerName.CompareNoCase(strThisServerName) == 0))
  94. {
  95. //The server is already present as replication partner
  96. AfxMessageBox(IDS_REP_PARTNER_LOCAL, MB_OK);
  97. m_editServerName.SetFocus();
  98. m_editServerName.SetSel(0,-1);
  99. return FALSE;
  100. }
  101. CIpNamePair ip;
  102. ip.SetIpAddress(m_dwServerIp);
  103. ip.SetNetBIOSName(m_strServerName);
  104. // check if the server already exists in the
  105. // list of replication folderss
  106. if ( m_pRepPartHandler->IsInList(ip, TRUE) != -1)
  107. {
  108. //The server is already present as replication partner
  109. AfxMessageBox(IDS_REP_PARTNER_EXISTS, MB_OK);
  110. m_editServerName.SetFocus();
  111. m_editServerName.SetSel(0,-1);
  112. return FALSE;
  113. }
  114. return TRUE;
  115. }
  116. /////////////////////////////////////////////////////////////////////////////
  117. // CIPAddressDlg dialog
  118. CIPAddressDlg::CIPAddressDlg(CWnd* pParent /*=NULL*/)
  119. : CBaseDialog(CIPAddressDlg::IDD, pParent),
  120. m_fNameRequired(TRUE)
  121. {
  122. //{{AFX_DATA_INIT(CIPAddressDlg)
  123. m_strNameOrIp = _T("");
  124. //}}AFX_DATA_INIT
  125. }
  126. void CIPAddressDlg::DoDataExchange(CDataExchange* pDX)
  127. {
  128. CBaseDialog::DoDataExchange(pDX);
  129. //{{AFX_DATA_MAP(CIPAddressDlg)
  130. DDX_Control(pDX, IDC_STATIC_WINS_SERVER_DESC, m_staticDescription);
  131. DDX_Control(pDX, IDC_EDIT_SERVER_NAME, m_editServerName);
  132. DDX_Control(pDX, IDOK, m_buttonOK);
  133. DDX_Text(pDX, IDC_EDIT_SERVER_NAME, m_strNameOrIp);
  134. //}}AFX_DATA_MAP
  135. }
  136. BEGIN_MESSAGE_MAP(CIPAddressDlg, CBaseDialog)
  137. //{{AFX_MSG_MAP(CIPAddressDlg)
  138. ON_EN_CHANGE(IDC_EDIT_SERVER_NAME, OnChangeEditServerName)
  139. ON_BN_CLICKED(IDC_BUTTON_BROWSE_COMPUTERS, OnButtonBrowseComputers)
  140. //}}AFX_MSG_MAP
  141. END_MESSAGE_MAP()
  142. /////////////////////////////////////////////////////////////////////////////
  143. // CIPAddressDlg message handlers
  144. void CIPAddressDlg::OnOK()
  145. {
  146. UpdateData();
  147. m_strNameOrIp.TrimLeft();
  148. m_strNameOrIp.TrimRight();
  149. if(m_strNameOrIp.IsEmpty())
  150. return;
  151. // resolve the IP address, if not valid, return
  152. if (!ValidateIPAddress())
  153. {
  154. // set back the focus to the IP address control
  155. m_editServerName.SetFocus();
  156. m_editServerName.SetSel(0,-1);
  157. return;
  158. }
  159. CBaseDialog::OnOK();
  160. }
  161. BOOL
  162. CIPAddressDlg::ValidateIPAddress()
  163. {
  164. CString strAddress;
  165. BOOL fIp = FALSE;
  166. DWORD err = ERROR_SUCCESS;
  167. BOOL bCheck = FALSE;
  168. DWORD dwAddress;
  169. CString strServerName;
  170. CThemeContextActivator themeActivator;
  171. strAddress = m_strNameOrIp;
  172. if (IsValidAddress(strAddress, &fIp, TRUE, TRUE))
  173. {
  174. // if not an IP adress, check if FQDN has been entered, if so
  175. // pass the letters before the first period
  176. if(!fIp)
  177. {
  178. int nPos = strAddress.Find(_T("."));
  179. if(nPos != -1)
  180. {
  181. CString strNetBIOSName = strAddress.Left(nPos);
  182. strAddress = strNetBIOSName;
  183. }
  184. }
  185. CWinsServerObj ws(NULL,"", TRUE, TRUE);
  186. strAddress.MakeUpper();
  187. // machine name specified
  188. if (fIp)
  189. ws = CWinsServerObj(CIpAddress(strAddress), "", TRUE, TRUE);
  190. // IP address specified
  191. else
  192. {
  193. ws = CWinsServerObj(CIpAddress(), strAddress, TRUE, TRUE);
  194. }
  195. BEGIN_WAIT_CURSOR
  196. err = ::VerifyWinsServer(strAddress, strServerName, dwAddress);
  197. END_WAIT_CURSOR
  198. if (err != ERROR_SUCCESS)
  199. {
  200. // The server isn't running wins. Ask user for name/ip.
  201. if (fIp && m_fNameRequired)
  202. {
  203. CGetNetBIOSNameDlg dlgGetNB(&ws);
  204. if (dlgGetNB.DoModal() == IDCANCEL)
  205. {
  206. return FALSE;
  207. }
  208. }
  209. else
  210. if (!fIp)
  211. {
  212. CGetIpAddressDlg dlgGetIP(&ws);
  213. if (dlgGetIP.DoModal() == IDCANCEL)
  214. {
  215. return FALSE;
  216. }
  217. }
  218. m_dwServerIp = (LONG) ws.QueryIpAddress();
  219. m_strServerName = ws.GetNetBIOSName();
  220. m_strServerName.MakeUpper();
  221. }
  222. else
  223. {
  224. m_dwServerIp = dwAddress;
  225. m_strServerName = strServerName;
  226. }
  227. ::MakeIPAddress(m_dwServerIp, m_strServerIp);
  228. return DoExtraValidation();
  229. }
  230. else
  231. {
  232. AfxMessageBox(IDS_SERVER_NO_EXIST, MB_OK);
  233. // set focus to the IP address comntrol
  234. m_editServerName.SetFocus();
  235. m_editServerName.SetSel(0,-1);
  236. return FALSE;
  237. }
  238. return bCheck;
  239. }
  240. BOOL CIPAddressDlg::OnInitDialog()
  241. {
  242. CBaseDialog::OnInitDialog();
  243. // limit the length of the edit ctrl
  244. m_editServerName.SetLimitText(MAX_PATH);
  245. // set the focus to the IP address control
  246. m_editServerName.SetFocus();
  247. return TRUE;
  248. }
  249. void CIPAddressDlg::OnChangeEditServerName()
  250. {
  251. // set the ok button state here
  252. if(m_editServerName.GetWindowTextLength() == 0)
  253. m_buttonOK.EnableWindow(FALSE);
  254. else
  255. m_buttonOK.EnableWindow(TRUE);
  256. }
  257. void CIPAddressDlg::OnButtonBrowseComputers()
  258. {
  259. CGetComputer dlgGetComputer;
  260. if (!dlgGetComputer.GetComputer(::FindMMCMainWindow()))
  261. return;
  262. m_editServerName.SetWindowText(dlgGetComputer.m_strComputerName);
  263. }