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.

373 lines
11 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. Networks.c
  5. Abstract:
  6. functions that detect the presence of network services
  7. Author:
  8. Bob Watson (a-robw)
  9. Revision History:
  10. 23 Dec 94
  11. --*/
  12. #include <windows.h>
  13. #include <tchar.h>
  14. #include <cpl.h>
  15. #include <stdio.h>
  16. #include <c2dll.h>
  17. #include <c2inc.h>
  18. #include <c2utils.h>
  19. #include "c2funcs.h"
  20. #include "c2funres.h"
  21. // define action codes here. They are only meaningful in the
  22. // context of this module.
  23. #define AC_NO_CHANGE 0
  24. #define AC_SHOW_NCPA 1
  25. static WCHAR wszNetwork[] = L"Network";
  26. #define SECURE C2DLL_C2
  27. static
  28. BOOL
  29. NetworkServicesFound (
  30. )
  31. {
  32. HKEY hkeySoftware;
  33. HKEY hkeyLevel1;
  34. HKEY hkeyLevel2;
  35. HKEY hkeyNetId;
  36. DWORD dwSwIndex;
  37. DWORD dwLevel1Index;
  38. LONG lStatus;
  39. LONG lBufLen;
  40. LONG lLevel1BufLen;
  41. TCHAR szSoftwareKeyNameBuffer [MAX_PATH];
  42. TCHAR szLevel1KeyNameBuffer [MAX_PATH];
  43. BOOL bReturn = FALSE;
  44. // open top key under root to begin search
  45. SET_WAIT_CURSOR;
  46. lStatus = RegOpenKeyEx (
  47. HKEY_LOCAL_MACHINE,
  48. GetStringResource (GetDllInstance(), IDS_SOFTWARE_KEY),
  49. 0L,
  50. KEY_READ,
  51. &hkeySoftware);
  52. if (lStatus == ERROR_SUCCESS) {
  53. //
  54. // if top key opened, then search each sub-key under it for
  55. // network service entries
  56. //
  57. dwSwIndex = 0;
  58. lBufLen = MAX_PATH;
  59. while (RegEnumKeyEx(hkeySoftware,
  60. dwSwIndex,
  61. szSoftwareKeyNameBuffer,
  62. &lBufLen,
  63. NULL,
  64. NULL,
  65. NULL,
  66. NULL) == ERROR_SUCCESS) {
  67. // try to open this key
  68. lStatus = RegOpenKeyEx (
  69. hkeySoftware,
  70. szSoftwareKeyNameBuffer,
  71. 0L,
  72. KEY_READ,
  73. &hkeyLevel1);
  74. if (lStatus == ERROR_SUCCESS) {
  75. // now enumerate the sub keys to this key and look for
  76. // network services
  77. dwLevel1Index = 0;
  78. lLevel1BufLen = MAX_PATH;
  79. while (RegEnumKeyEx(hkeyLevel1,
  80. dwLevel1Index,
  81. szLevel1KeyNameBuffer,
  82. &lLevel1BufLen,
  83. NULL,
  84. NULL,
  85. NULL,
  86. NULL) == ERROR_SUCCESS) {
  87. // try to open this key
  88. lStatus = RegOpenKeyEx (
  89. hkeyLevel1,
  90. szLevel1KeyNameBuffer,
  91. 0L,
  92. KEY_READ,
  93. &hkeyLevel2);
  94. if (lStatus == ERROR_SUCCESS) {
  95. // now enumerate the sub keys to this key and look for
  96. // network services
  97. // if that worked, then try to open the "Find" key
  98. lStatus = RegOpenKeyEx (
  99. hkeyLevel2,
  100. GetStringResource (GetDllInstance(), IDS_NETWORK_SERVICE_ID_KEY),
  101. 0L,
  102. KEY_READ,
  103. &hkeyNetId);
  104. if (lStatus == ERROR_SUCCESS){
  105. // network service of some kind found
  106. bReturn = TRUE;
  107. RegCloseKey (hkeyNetId);
  108. break;
  109. } // end if network service ID key opened
  110. RegCloseKey (hkeyLevel2);
  111. } // end if Level 2 key opened
  112. dwLevel1Index++;
  113. lLevel1BufLen = MAX_PATH;
  114. } // end while enum level1 sub keys (level 2 keys)
  115. RegCloseKey (hkeyLevel1);
  116. } // end if Level 1 key opened
  117. if (bReturn) break;
  118. dwSwIndex++;
  119. lBufLen = MAX_PATH;
  120. } // end while enum Software subkeys (level 1 keys)
  121. RegCloseKey (hkeySoftware);
  122. SetLastError (ERROR_SUCCESS);
  123. } else { // end if software key opened
  124. SetLastError (lStatus);
  125. }
  126. SET_ARROW_CURSOR;
  127. return bReturn;
  128. }
  129. LONG
  130. C2QueryNetworkServices (
  131. IN LPARAM lParam
  132. )
  133. /*++
  134. Routine Description:
  135. Function called to find out the current state of this configuration
  136. item. This function reads the current state of the item and
  137. sets the C2 Compliance flag and the Status string to reflect
  138. the current value of the configuration item.
  139. Arguments:
  140. Pointer to the Dll data block passed as an LPARAM.
  141. ReturnValue:
  142. ERROR_SUCCESS if the function succeeds otherwise a
  143. WIN32 error is returned if an error occurs
  144. --*/
  145. {
  146. PC2DLL_DATA pC2Data;
  147. UINT nMsgId = 0;
  148. if (lParam != 0) {
  149. pC2Data = (PC2DLL_DATA)lParam;
  150. if (NetworkServicesFound()) {
  151. pC2Data->lC2Compliance = C2DLL_NOT_SECURE;
  152. nMsgId = IDS_NETWORK_SERVICE_FOUND;
  153. } else {
  154. pC2Data->lC2Compliance = SECURE;
  155. nMsgId = IDS_NETWORK_SERVICE_NOT_FOUND;
  156. }
  157. _stprintf (pC2Data->szStatusName,
  158. GetStringResource (GetDllInstance(), nMsgId));
  159. return ERROR_SUCCESS;
  160. } else {
  161. return ERROR_BAD_ARGUMENTS;
  162. }
  163. }
  164. LONG
  165. C2SetNetworkServices (
  166. IN LPARAM lParam
  167. )
  168. /*++
  169. Routine Description:
  170. Function called to change the current state of this configuration
  171. item based on an action code passed in the DLL data block. If
  172. this function successfully sets the state of the configuration
  173. item, then the C2 Compliance flag and the Status string to reflect
  174. the new value of the configuration item.
  175. Arguments:
  176. Pointer to the Dll data block passed as an LPARAM.
  177. ReturnValue:
  178. ERROR_SUCCESS if the function succeeds otherwise a
  179. WIN32 error is returned if an error occurs
  180. --*/
  181. {
  182. #define MAX_CPL_DLGS 4
  183. PC2DLL_DATA pC2Data;
  184. HINSTANCE hNcpaDll;
  185. APPLET_PROC CPlApplet;
  186. LONG lNcpaResult;
  187. LONG lDlgCount;
  188. LONG lDlgId;
  189. LONG lNetworksDlgId;
  190. UINT nMsgId;
  191. WNEWCPLINFO ncpaDlgInfo[MAX_CPL_DLGS];
  192. if (lParam != 0) {
  193. pC2Data = (PC2DLL_DATA)lParam;
  194. if (pC2Data->lActionCode == AC_SHOW_NCPA) {
  195. SET_WAIT_CURSOR;
  196. // load NCPA DLL
  197. hNcpaDll = LoadLibrary (
  198. GetStringResource (GetDllInstance(), IDS_NCPA_DLL));
  199. if (hNcpaDll != NULL) {
  200. // look up Control Panel function
  201. CPlApplet = (APPLET_PROC)GetProcAddressT ((HMODULE)hNcpaDll,
  202. GetStringResource (GetDllInstance(), IDS_NCPA_CPL_APPLET));
  203. if (CPlApplet != NULL) {
  204. // init control panel applet
  205. if ((*CPlApplet)(pC2Data->hWnd, CPL_INIT, 0, 0) != 0) {
  206. lDlgCount = (*CPlApplet)(pC2Data->hWnd, CPL_GETCOUNT, 0, 0);
  207. if (lDlgCount > MAX_CPL_DLGS) lDlgCount = MAX_CPL_DLGS; // set limit
  208. for (lDlgId = 0; lDlgId < lDlgCount; lDlgId++) {
  209. (*CPlApplet)(pC2Data->hWnd, CPL_NEWINQUIRE,
  210. lDlgId, (LONG)&ncpaDlgInfo[lDlgId]);
  211. if (lstrcmpW (ncpaDlgInfo[lDlgId].szName,
  212. wszNetwork) == 0) {
  213. lNetworksDlgId = lDlgId;
  214. }
  215. }
  216. // call Network dialog
  217. SET_ARROW_CURSOR;
  218. lNcpaResult = (*CPlApplet)(pC2Data->hWnd, CPL_DBLCLK,
  219. lNetworksDlgId, ncpaDlgInfo[lNetworksDlgId].lData);
  220. SET_WAIT_CURSOR;
  221. // update networking status
  222. if (NetworkServicesFound()) {
  223. pC2Data->lC2Compliance = C2DLL_NOT_SECURE;
  224. nMsgId = IDS_NETWORK_SERVICE_FOUND;
  225. } else {
  226. pC2Data->lC2Compliance = SECURE;
  227. nMsgId = IDS_NETWORK_SERVICE_NOT_FOUND;
  228. }
  229. _stprintf (pC2Data->szStatusName,
  230. GetStringResource (GetDllInstance(), nMsgId));
  231. // close control panel dialogs and applet
  232. for (lDlgId = 1; lDlgId <= lDlgCount; lDlgId++) {
  233. (*CPlApplet)(pC2Data->hWnd, CPL_STOP,
  234. lDlgId, (LONG)&ncpaDlgInfo[lDlgId-1]);
  235. }
  236. (*CPlApplet)(pC2Data->hWnd, CPL_EXIT, 0, 0);
  237. } else {
  238. // Applet could not initialize
  239. DisplayDllMessageBox (
  240. pC2Data->hWnd,
  241. IDS_NETWORK_ERROR_INIT_CPL,
  242. IDS_NETWORK_CAPTION,
  243. MBOK_EXCLAIM);
  244. }
  245. } else {
  246. // unable to find control panel entry point
  247. DisplayDllMessageBox (
  248. pC2Data->hWnd,
  249. IDS_NETWORK_ERROR_FIND_CPL,
  250. IDS_NETWORK_CAPTION,
  251. MBOK_EXCLAIM);
  252. }
  253. // free DLL
  254. FreeLibrary (hNcpaDll);
  255. } else {
  256. // unable to load DLL
  257. DisplayDllMessageBox (
  258. pC2Data->hWnd,
  259. IDS_NETWORK_ERROR_LOAD_DLL,
  260. IDS_NETWORK_CAPTION,
  261. MBOK_EXCLAIM);
  262. }
  263. SET_ARROW_CURSOR;
  264. }
  265. return ERROR_SUCCESS;
  266. } else {
  267. return ERROR_BAD_ARGUMENTS;
  268. }
  269. }
  270. LONG
  271. C2DisplayNetworkServices (
  272. IN LPARAM lParam
  273. )
  274. /*++
  275. Routine Description:
  276. Function called to display more information on the configuration
  277. item and provide the user with the option to change the current
  278. setting (if appropriate). If the User "OK's" out of the UI,
  279. then the action code field in the DLL data block is set to the
  280. appropriate (and configuration item-specific) action code so the
  281. "Set" function can be called to perform the desired action. If
  282. the user Cancels out of the UI, then the Action code field is
  283. set to 0 (no action) and no action is performed.
  284. Arguments:
  285. Pointer to the Dll data block passed as an LPARAM.
  286. ReturnValue:
  287. ERROR_SUCCESS if the function succeeds otherwise a
  288. WIN32 error is returned if an error occurs
  289. --*/
  290. {
  291. PC2DLL_DATA pC2Data;
  292. if (lParam != 0) {
  293. pC2Data = (PC2DLL_DATA)lParam;
  294. if (NetworkServicesFound()) {
  295. if (DisplayDllMessageBox (
  296. pC2Data->hWnd,
  297. IDS_NETWORK_SHOW_NCPA,
  298. IDS_NETWORK_CAPTION,
  299. MBOKCANCEL_QUESTION) == IDOK){
  300. pC2Data->lActionCode = AC_SHOW_NCPA;
  301. } else {
  302. pC2Data->lActionCode = AC_NO_CHANGE;
  303. }
  304. } else {
  305. DisplayDllMessageBox (
  306. pC2Data->hWnd,
  307. IDS_NETWORK_SERVICE_NOT_FOUND,
  308. IDS_NETWORK_CAPTION,
  309. MBOK_INFO);
  310. pC2Data->lActionCode = AC_NO_CHANGE;
  311. }
  312. return ERROR_SUCCESS;
  313. } else {
  314. return ERROR_BAD_ARGUMENTS;
  315. }
  316. }
  317. 
  318.