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.

233 lines
8.0 KiB

  1. #include "pmcfg.h"
  2. #include <atlbase.h>
  3. #include <atlconv.h>
  4. DWORD g_dwSiteNameBufLen;
  5. DWORD g_dwHostNameBufLen;
  6. DWORD g_dwHostIPBufLen;
  7. LPTSTR g_szSiteNameBuf;
  8. LPTSTR g_szHostNameBuf;
  9. LPTSTR g_szHostIPBuf;
  10. INT_PTR CALLBACK NewConfigSetDlgProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  11. BOOL IsValidIP(
  12. LPCTSTR pszIP
  13. )
  14. {
  15. BOOL bIsValid = FALSE;
  16. SOCKADDR_STORAGE TmpSockAddr;
  17. INT cbAddr = sizeof(TmpSockAddr);
  18. WSADATA wsaData;
  19. if (0 != WSAStartup(MAKEWORD(2,0), &wsaData))
  20. {
  21. return FALSE;
  22. }
  23. if (0 == WSAStringToAddress((LPTSTR)pszIP,
  24. AF_INET,
  25. NULL,
  26. (LPSOCKADDR)&TmpSockAddr,
  27. &cbAddr))
  28. {
  29. bIsValid = TRUE;
  30. }
  31. WSACleanup();
  32. return bIsValid;
  33. }
  34. BOOL NewConfigSet
  35. (
  36. HWND hWndDlg,
  37. LPTSTR szSiteNameBuf,
  38. DWORD dwSiteNameBufLen,
  39. LPTSTR szHostNameBuf,
  40. DWORD dwHostNameBufLen,
  41. LPTSTR szHostIPBuf,
  42. DWORD dwHostIPBufLen
  43. )
  44. {
  45. g_dwSiteNameBufLen = dwSiteNameBufLen;
  46. g_dwHostNameBufLen = dwHostNameBufLen;
  47. g_dwHostIPBufLen = dwHostIPBufLen;
  48. g_szSiteNameBuf = szSiteNameBuf;
  49. g_szHostNameBuf = szHostNameBuf;
  50. g_szHostIPBuf = szHostIPBuf;
  51. if (IDOK == DialogBox( g_hInst,
  52. MAKEINTRESOURCE (IDD_NEW_CONFIGSET),
  53. hWndDlg,
  54. NewConfigSetDlgProc ))
  55. return TRUE;
  56. else
  57. return FALSE;
  58. }
  59. BOOL RemoveConfigSetWarning
  60. (
  61. HWND hWndDlg
  62. )
  63. {
  64. TCHAR szWarning[MAX_RESOURCE];
  65. TCHAR szTitle[MAX_RESOURCE];
  66. LoadString(g_hInst, IDS_REMOVE_WARNING, szWarning, DIMENSION(szWarning));
  67. LoadString(g_hInst, IDS_REMOVE_TITLE, szTitle, DIMENSION(szTitle));
  68. return (MessageBox(hWndDlg, szWarning, szTitle, MB_OKCANCEL | MB_ICONQUESTION) == IDOK);
  69. }
  70. INT_PTR CALLBACK NewConfigSetDlgProc
  71. (
  72. HWND hWndDlg,
  73. UINT uMsg,
  74. WPARAM wParam,
  75. LPARAM lParam
  76. )
  77. {
  78. switch ( uMsg )
  79. {
  80. case WM_INITDIALOG:
  81. {
  82. SendDlgItemMessage(hWndDlg, IDC_CONFIGSETEDIT, EM_SETLIMITTEXT, MAX_CONFIGSETNAME - 1, 0L);
  83. SendDlgItemMessage(hWndDlg, IDC_HOSTNAMEEDIT, EM_SETLIMITTEXT, INTERNET_MAX_HOST_NAME_LENGTH - 1, 0L);
  84. SendDlgItemMessage(hWndDlg, IDC_HOSTIPEDIT, EM_SETLIMITTEXT, MAX_IPLEN, 0L);
  85. SetFocus(GetDlgItem(hWndDlg, IDC_CONFIGSETEDIT));
  86. return FALSE;
  87. }
  88. case WM_COMMAND:
  89. {
  90. switch (LOWORD(wParam))
  91. {
  92. case IDOK:
  93. {
  94. TCHAR szTemp[MAX_RESOURCE];
  95. TCHAR szTitle[MAX_RESOURCE];
  96. LPTSTR lpszConfigSetNames, lpszCur;
  97. //
  98. // Check for empty site name
  99. //
  100. GetDlgItemText(hWndDlg, IDC_CONFIGSETEDIT, g_szSiteNameBuf, g_dwSiteNameBufLen);
  101. if(lstrlen(g_szSiteNameBuf) == 0)
  102. {
  103. LoadString(g_hInst, IDS_EMPTYSITENAME, szTemp, DIMENSION(szTemp));
  104. LoadString(g_hInst, IDS_ERROR, szTitle, DIMENSION(szTitle));
  105. MessageBox(hWndDlg, szTemp, szTitle, MB_OK | MB_ICONEXCLAMATION);
  106. SetFocus(GetDlgItem(hWndDlg, IDC_CONFIGSETEDIT));
  107. break;
  108. }
  109. //
  110. // Make sure the site name isn't default
  111. //
  112. LoadString(g_hInst, IDS_DEFAULT, szTemp, DIMENSION(szTemp));
  113. if(lstrcmp(g_szSiteNameBuf, szTemp) == 0)
  114. {
  115. LoadString(g_hInst, IDS_INVALIDSITENAME, szTemp, DIMENSION(szTemp));
  116. LoadString(g_hInst, IDS_ERROR, szTitle, DIMENSION(szTitle));
  117. MessageBox(hWndDlg, szTemp, szTitle, MB_OK | MB_ICONEXCLAMATION);
  118. SetFocus(GetDlgItem(hWndDlg, IDC_CONFIGSETEDIT));
  119. break;
  120. }
  121. //
  122. // Check for existing site w/same name
  123. //
  124. if(ReadRegConfigSetNames(hWndDlg, g_szRemoteComputer, &lpszConfigSetNames) &&
  125. lpszConfigSetNames)
  126. {
  127. BOOL bFoundMatch = FALSE;
  128. lpszCur = lpszConfigSetNames;
  129. while(*lpszCur)
  130. {
  131. if(_wcsicmp(lpszCur, g_szSiteNameBuf) == 0)
  132. {
  133. LoadString(g_hInst, IDS_EXISTINGSITENAME, szTemp, DIMENSION(szTemp));
  134. LoadString(g_hInst, IDS_ERROR, szTitle, DIMENSION(szTitle));
  135. MessageBox(hWndDlg, szTemp, szTitle, MB_OK | MB_ICONEXCLAMATION);
  136. SetFocus(GetDlgItem(hWndDlg, IDC_CONFIGSETEDIT));
  137. bFoundMatch = TRUE;
  138. break;
  139. }
  140. lpszCur = _tcschr(lpszCur, TEXT('\0')) + 1;
  141. }
  142. free(lpszConfigSetNames);
  143. lpszConfigSetNames = NULL;
  144. if(bFoundMatch)
  145. break;
  146. }
  147. //
  148. // Get data from other controls.
  149. //
  150. GetDlgItemText(hWndDlg, IDC_HOSTNAMEEDIT, g_szHostNameBuf, g_dwHostNameBufLen);
  151. if(lstrlen(g_szHostNameBuf) == 0)
  152. {
  153. LoadString(g_hInst, IDS_EMPTYHOSTNAME, szTemp, DIMENSION(szTemp));
  154. LoadString(g_hInst, IDS_ERROR, szTitle, DIMENSION(szTitle));
  155. MessageBox(hWndDlg, szTemp, szTitle, MB_OK | MB_ICONEXCLAMATION);
  156. SetFocus(GetDlgItem(hWndDlg, IDC_HOSTNAMEEDIT));
  157. break;
  158. }
  159. GetDlgItemText(hWndDlg, IDC_HOSTIPEDIT, g_szHostIPBuf, g_dwHostIPBufLen);
  160. if(lstrlen(g_szHostIPBuf) == 0)
  161. {
  162. LoadString(g_hInst, IDS_EMPTYHOSTIP, szTemp, DIMENSION(szTemp));
  163. LoadString(g_hInst, IDS_ERROR, szTitle, DIMENSION(szTitle));
  164. MessageBox(hWndDlg, szTemp, szTitle, MB_OK | MB_ICONEXCLAMATION);
  165. SetFocus(GetDlgItem(hWndDlg, IDC_HOSTIPEDIT));
  166. break;
  167. }
  168. //
  169. // Valid IP address?
  170. //
  171. if(!IsValidIP(g_szHostIPBuf))
  172. {
  173. LoadString(g_hInst, IDS_HOSTIP_ERROR, szTemp, DIMENSION(szTemp));
  174. LoadString(g_hInst, IDS_ERROR, szTitle, DIMENSION(szTitle));
  175. MessageBox(hWndDlg, szTemp, szTitle, MB_OK | MB_ICONEXCLAMATION);
  176. SetFocus(GetDlgItem(hWndDlg, IDC_HOSTIPEDIT));
  177. break;
  178. }
  179. EndDialog( hWndDlg, TRUE );
  180. break;
  181. }
  182. case IDCANCEL:
  183. {
  184. g_szSiteNameBuf[0] = TEXT('\0');
  185. g_szHostNameBuf[0] = TEXT('\0');
  186. g_szHostIPBuf[0] = TEXT('\0');
  187. EndDialog( hWndDlg, FALSE );
  188. break;
  189. }
  190. }
  191. break;
  192. }
  193. }
  194. return FALSE;
  195. }