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.

291 lines
9.4 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1994 **
  4. //*********************************************************************
  5. //
  6. // TCPCFG.C - Functions to read and set TCP/IP configuration
  7. //
  8. // HISTORY:
  9. //
  10. // 11/27/94 jeremys Created.
  11. // 96/02/29 markdu Replaced call to RNAGetIPInfo with call to
  12. // GetIPInfo in rnacall.c
  13. // 96/03/23 markdu Removed Get/ApplyInstanceTcpInfo functions.
  14. // 96/03/24 markdu Replaced memset with ZeroMemory for consistency.
  15. // 96/03/25 markdu Removed connectoid name parameter from
  16. // Get/ApplyGlobalTcpInfo functions since they should not
  17. // be setting per-connectoid stuff anymore.
  18. // Renamed ApplyGlobalTcpInfo to ClearGlobalTcpInfo, and
  19. // changed function to just clear the settings.
  20. // Renamed GetGlobalTcpInfo to IsThereGlobalTcpInfo, and
  21. // changed function to just get the settings.
  22. // 96/04/04 markdu Added pfNeedsRestart to WarnIfServerBound, and
  23. // added function RemoveIfServerBound.
  24. // 96/04/23 markdu NASH BUG 18748 Initialize reboot variable before
  25. // returning.
  26. // 96/05/26 markdu Use lpTurnOffFileSharing and lpIsFileSharingTurnedOn.
  27. //
  28. #include "wizard.h"
  29. extern ICFGTURNOFFFILESHARING lpIcfgTurnOffFileSharing;
  30. extern ICFGISFILESHARINGTURNEDON lpIcfgIsFileSharingTurnedOn;
  31. /*******************************************************************
  32. NAME: WarnIfServerBound
  33. SYNOPSIS: Checks to see if file server (VSERVER) is bound
  34. to TCP/IP instance used for Internet. If so,
  35. warns the user and recommends that she let us
  36. remove the binding. Removes the binding if user
  37. gives go-ahead.
  38. ENTRY: hDlg - parent window
  39. dwCardFlags - an INSTANCE_xxx flag to specify what
  40. card type to check server-TCP/IP bindings for
  41. pfNeedsRestart - set to TRUE if we need a restart
  42. NOTES: This is important because if we don't unbind server
  43. from instances of TCP/IP we install, user could be
  44. inadvertently sharing files over the Internet.
  45. Calls worker function DetectModifyTCPIPBindings to
  46. do work.
  47. ********************************************************************/
  48. HRESULT WarnIfServerBound(HWND hDlg,DWORD dwCardFlags,BOOL* pfNeedsRestart)
  49. {
  50. HRESULT err = ERROR_SUCCESS;
  51. // 96/04/23 markdu NASH BUG 18748 Initialize reboot variable before
  52. // returning.
  53. // Default to no restart.
  54. ASSERT(pfNeedsRestart);
  55. *pfNeedsRestart = FALSE;
  56. // this function may get called more than once (to guarantee we
  57. // call it regardless of how pages are navigated), set a flag
  58. // so we don't warn user more than once
  59. static BOOL fWarned = FALSE;
  60. if (fWarned)
  61. {
  62. return ERROR_SUCCESS;
  63. }
  64. // check to see if file server is bound to TCP/IP instance used
  65. // to connect to the internet
  66. BOOL fSharingOn;
  67. HRESULT hr = lpIcfgIsFileSharingTurnedOn(INSTANCE_PPPDRIVER, &fSharingOn);
  68. //
  69. // 5/12/97 jmazner Olympus #3442 IE #30886
  70. // TEMP TODO at the moment, icfgnt doesn't implement FileSharingTurnedOn
  71. // Until it does, assume that on NT file sharing is always off.
  72. //
  73. if( IsNT() )
  74. {
  75. DEBUGMSG("Ignoring return code from IcfgIsFileSharingTurnedOn");
  76. fSharingOn = FALSE;
  77. }
  78. if ((ERROR_SUCCESS == hr) && (TRUE == fSharingOn))
  79. {
  80. // if so, warn the user and ask if we should remove it
  81. BUFFER Msg(MAX_RES_LEN+1); // allocate buffer for part of message
  82. ASSERT(Msg);
  83. if (!Msg)
  84. {
  85. return ERROR_NOT_ENOUGH_MEMORY; // out of memory
  86. }
  87. // message is long and takes 2 strings, so load the 2nd resource and
  88. // use it as an insertable parameter into the first string
  89. LoadSz(IDS_WARN_SERVER_BOUND1,Msg.QueryPtr(),Msg.QuerySize());
  90. if (MsgBoxParam(hDlg,IDS_WARN_SERVER_BOUND,MB_ICONEXCLAMATION,MB_YESNO,
  91. Msg.QueryPtr()) == IDYES)
  92. {
  93. // remove the binding
  94. err = lpIcfgTurnOffFileSharing(dwCardFlags, hDlg);
  95. ASSERT(err == ERROR_SUCCESS);
  96. if (ERROR_SUCCESS == err)
  97. {
  98. // We need to restart.
  99. *pfNeedsRestart = TRUE;
  100. }
  101. }
  102. }
  103. fWarned = TRUE;
  104. return err;
  105. }
  106. /*******************************************************************
  107. NAME: RemoveIfServerBound
  108. SYNOPSIS: Checks to see if file server (VSERVER) is bound
  109. to TCP/IP instance used for Internet. If so,
  110. informs the user that we cannot continue unless we
  111. remove the binding. Removes the binding if user
  112. gives go-ahead.
  113. ENTRY: hDlg - parent window
  114. dwCardFlags - an INSTANCE_xxx flag to specify what
  115. card type to check server-TCP/IP bindings for
  116. pfNeedsRestart - set to TRUE if we need a restart
  117. NOTES: This is important because if we don't unbind server
  118. from instances of TCP/IP we install, user could be
  119. inadvertently sharing files over the Internet.
  120. Calls worker function DetectModifyTCPIPBindings to
  121. do work.
  122. ********************************************************************/
  123. HRESULT RemoveIfServerBound(HWND hDlg,DWORD dwCardFlags,BOOL* pfNeedsRestart)
  124. {
  125. HRESULT err = ERROR_SUCCESS;
  126. // Default to no restart.
  127. ASSERT(pfNeedsRestart);
  128. *pfNeedsRestart = FALSE;
  129. // check to see if file server is bound to TCP/IP instance used
  130. // to connect to the internet
  131. BOOL fSharingOn;
  132. HRESULT hr = lpIcfgIsFileSharingTurnedOn(INSTANCE_PPPDRIVER, &fSharingOn);
  133. if ((ERROR_SUCCESS == hr) && (TRUE == fSharingOn))
  134. {
  135. // if so, warn the user and ask if we should remove it
  136. BUFFER Msg(MAX_RES_LEN+1); // allocate buffer for part of message
  137. ASSERT(Msg);
  138. if (!Msg)
  139. {
  140. return ERROR_NOT_ENOUGH_MEMORY; // out of memory
  141. }
  142. // message is long and takes 2 strings, so load the 2nd resource and
  143. // use it as an insertable parameter into the first string
  144. LoadSz(IDS_REMOVE_SERVER_BOUND1,Msg.QueryPtr(),Msg.QuerySize());
  145. if (MsgBoxParam(hDlg,IDS_REMOVE_SERVER_BOUND,MB_ICONEXCLAMATION,MB_OKCANCEL,
  146. Msg.QueryPtr()) == IDOK)
  147. {
  148. // remove the binding
  149. err = lpIcfgTurnOffFileSharing(dwCardFlags, hDlg);
  150. ASSERT(err == ERROR_SUCCESS);
  151. if (ERROR_SUCCESS == err)
  152. {
  153. // We need to restart.
  154. *pfNeedsRestart = TRUE;
  155. }
  156. }
  157. else
  158. {
  159. // user cancelled.
  160. err = ERROR_CANCELLED;
  161. }
  162. }
  163. return err;
  164. }
  165. #define FIELD_LEN 3
  166. #define NUM_FIELDS 4
  167. /*******************************************************************
  168. NAME: IPStrToLong
  169. SYNOPSIS: Translates a text string to a numeric IPADDRESS
  170. ENTRY: pszAddress - text string with ip address
  171. pipAddress - IPADDRESS to translate into
  172. EXIT: TRUE if successful, FALSE if the string is invalid
  173. NOTES: borrowed from net setup TCP/IP UI
  174. ********************************************************************/
  175. BOOL IPStrToLong(LPCTSTR pszAddress,IPADDRESS * pipAddress)
  176. {
  177. LPTSTR pch = (LPTSTR) pszAddress;
  178. TCHAR szField[FIELD_LEN+1];
  179. int nFields = 0;
  180. int nFieldLen = 0;
  181. BYTE nFieldVal[NUM_FIELDS];
  182. BOOL fContinue = TRUE;
  183. ASSERT(pszAddress);
  184. ASSERT(pipAddress);
  185. *pipAddress = (IPADDRESS) 0;
  186. // retrieve the numeric value for each of the four fields
  187. while (fContinue) {
  188. if (!(*pch)) fContinue = FALSE;
  189. if (*pch == '.' || !*pch) {
  190. if (nFields >= NUM_FIELDS) return FALSE; // invalid pszAddress
  191. *(szField+nFieldLen) = '\0'; // null-terminate
  192. UINT uFieldVal = (UINT) myatoi(szField); // convert string to int
  193. if (uFieldVal > 255)
  194. return FALSE; // field is > 255, invalid
  195. nFieldVal[nFields] = (BYTE) uFieldVal;
  196. nFields++;
  197. nFieldLen = 0;
  198. pch++;
  199. } else {
  200. if (! ((*pch >= '0') && (*pch <= '9')) )
  201. return FALSE; // non-numeric character, invalid pszAddress
  202. *(szField + nFieldLen) = *pch;
  203. nFieldLen++;
  204. pch++;
  205. if (nFieldLen > FIELD_LEN) return FALSE; // invalid pszAddress
  206. }
  207. }
  208. if (nFields < NUM_FIELDS) return FALSE; // invalid szAddress
  209. // build an address from the fields
  210. *pipAddress = (IPADDRESS)MAKEIPADDRESS(nFieldVal[0],nFieldVal[1],nFieldVal[2],
  211. nFieldVal[3]);
  212. return TRUE;
  213. }
  214. /*******************************************************************
  215. NAME: IPLongToStr
  216. SYNOPSIS: Translates a single numeric IP address to a text string
  217. ENTRY: ipAddress - numeric IP address to translate from
  218. pszAddress - buffer for translated string
  219. cbAddress - size of pszAddress buffer
  220. EXIT: TRUE if successful, FALSE if the buffer is too short
  221. NOTES: borrowed from net setup TCP/IP UI
  222. ********************************************************************/
  223. BOOL IPLongToStr(IPADDRESS ipAddress,LPTSTR pszAddress,UINT cbAddress)
  224. {
  225. ASSERT(pszAddress);
  226. if (cbAddress < IP_ADDRESS_LEN + 1)
  227. return FALSE;
  228. wsprintf(pszAddress,TEXT("%u.%u.%u.%u"),
  229. (BYTE) (ipAddress>>24),(BYTE) (ipAddress>>16),
  230. (BYTE) (ipAddress>>8), (BYTE) ipAddress);
  231. return TRUE;
  232. }