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.

493 lines
11 KiB

  1. // Copyright (c) 1995, Microsoft Corporation, all rights reserved
  2. //
  3. // nwc.c
  4. // Remote Access Common Dialog APIs
  5. // NetWare Compatible warning dialog
  6. //
  7. // 12/06/95 Steve Cobb
  8. #include "rasdlgp.h"
  9. //----------------------------------------------------------------------------
  10. // Local datatypes
  11. //----------------------------------------------------------------------------
  12. // NetWare Compatible warning dialog argument block.
  13. //
  14. typedef struct
  15. _NWARGS
  16. {
  17. // Caller's arguments to the stub API.
  18. //
  19. BOOL fPosition;
  20. LONG xDlg;
  21. LONG yDlg;
  22. PBFILE* pFile;
  23. PBENTRY* pEntry;
  24. }
  25. NWARGS;
  26. // NetWare Compatible warning dialog context block.
  27. //
  28. typedef struct
  29. _NWINFO
  30. {
  31. // Stub API arguments.
  32. //
  33. NWARGS* pArgs;
  34. // Handle of this dialog and some of it's controls.
  35. //
  36. HWND hwndDlg;
  37. HWND hwndCb;
  38. }
  39. NWINFO;
  40. //----------------------------------------------------------------------------
  41. // Local prototypes (alphabetically)
  42. //----------------------------------------------------------------------------
  43. BOOL
  44. NwConnectionDlg(
  45. IN HWND hwndOwner,
  46. IN BOOL fPosition,
  47. IN LONG xDlg,
  48. IN LONG yDlg,
  49. IN PBFILE* pFile,
  50. IN PBENTRY* pEntry );
  51. INT_PTR CALLBACK
  52. NwDlgProc(
  53. IN HWND hwnd,
  54. IN UINT unMsg,
  55. IN WPARAM wparam,
  56. IN LPARAM lparam );
  57. BOOL
  58. NwCommand(
  59. IN NWINFO* pInfo,
  60. IN WORD wNotification,
  61. IN WORD wId,
  62. IN HWND hwndCtrl );
  63. BOOL
  64. NwInit(
  65. IN HWND hwndDlg,
  66. IN NWARGS* pArgs );
  67. VOID
  68. NwTerm(
  69. IN HWND hwndDlg );
  70. TCHAR*
  71. GetNwProviderName(
  72. void );
  73. BOOL
  74. IsActiveNwLanConnection(
  75. void );
  76. //----------------------------------------------------------------------------
  77. // Entry point
  78. //----------------------------------------------------------------------------
  79. BOOL
  80. NwConnectionCheck(
  81. IN HWND hwndOwner,
  82. IN BOOL fPosition,
  83. IN LONG xDlg,
  84. IN LONG yDlg,
  85. IN PBFILE* pFile,
  86. IN PBENTRY* pEntry )
  87. // Warns about active NetWare LAN connections being blown away, if
  88. // indicated. 'HwndOwner' is the owning window if a dialog is necessary.
  89. // 'FPosition', 'xDlg', and 'yDlg' are the dialog positioning parameters
  90. // as specified to the calling API. 'PFile' and 'pEntry' are the open
  91. // phonebook file and entry to check.
  92. //
  93. // Note: This call will write the phonebook file if user checks the "not
  94. // in the future" checkbox.
  95. //
  96. // Returns true if warning is not necessary or user pressed OK, false if
  97. // user presses cancel.
  98. //
  99. {
  100. TRACE("NwConnectionCheck");
  101. // Warn about active NetWare LAN connections being blown away, if
  102. // indicated.
  103. //
  104. if (!pEntry->fSkipNwcWarning
  105. && pEntry->dwBaseProtocol == BP_Ppp
  106. && (g_pGetInstalledProtocolsEx(NULL, FALSE, TRUE, FALSE) & NP_Ipx)
  107. && !(pEntry->dwfExcludedProtocols & NP_Ipx)
  108. && IsActiveNwLanConnection())
  109. {
  110. if (!NwConnectionDlg(
  111. hwndOwner, fPosition, xDlg, yDlg, pFile, pEntry ))
  112. {
  113. return FALSE;
  114. }
  115. }
  116. return TRUE;
  117. }
  118. //----------------------------------------------------------------------------
  119. // Netware dialog routines (alphabetically following stub and DlgProc)
  120. //----------------------------------------------------------------------------
  121. BOOL
  122. NwConnectionDlg(
  123. IN HWND hwndOwner,
  124. IN BOOL fPosition,
  125. IN LONG xDlg,
  126. IN LONG yDlg,
  127. IN PBFILE* pFile,
  128. IN PBENTRY* pEntry )
  129. // Pops up a warning about active NWC LAN connections being blown away.
  130. // 'HwndOwner' is the owning window if a dialog is necessary.
  131. // 'FPosition', 'xDlg', and 'yDlg' are the dialog positioning parameters
  132. // as specified to the calling API. 'PFile' and 'pEntry' are the open
  133. // phonebook file and entry to check.
  134. //
  135. // Note: This call will write the phonebook file if user checks the "not
  136. // in the future" checkbox.
  137. //
  138. // Returns true if user pressed OK, false if user presses cancel.
  139. //
  140. {
  141. INT_PTR nStatus;
  142. NWARGS args;
  143. TRACE( "NwConnectionDlg" );
  144. // Initialize dialog argument block.
  145. //
  146. args.fPosition = fPosition;
  147. args.xDlg = xDlg;
  148. args.yDlg = yDlg;
  149. args.pFile = pFile;
  150. args.pEntry = pEntry;
  151. // Run the dialog.
  152. //
  153. nStatus =
  154. DialogBoxParam(
  155. g_hinstDll,
  156. MAKEINTRESOURCE( DID_NW_NwcConnections ),
  157. hwndOwner,
  158. NwDlgProc,
  159. (LPARAM )&args );
  160. if (nStatus == -1)
  161. {
  162. ErrorDlg( hwndOwner, SID_OP_LoadDlg, ERROR_UNKNOWN, NULL );
  163. nStatus = FALSE;
  164. }
  165. return (nStatus) ? TRUE : FALSE;
  166. }
  167. INT_PTR CALLBACK
  168. NwDlgProc(
  169. IN HWND hwnd,
  170. IN UINT unMsg,
  171. IN WPARAM wparam,
  172. IN LPARAM lparam )
  173. // DialogProc callback for the Netware warning dialog. Parameters and
  174. // return value are as described for standard windows 'DialogProc's.
  175. //
  176. {
  177. #if 0
  178. TRACE4( "NwDlgProc(h=$%x,m=$%x,w=$%x,l=$%x)",
  179. (DWORD )hwnd, (DWORD )unMsg, (DWORD )wparam, (DWORD )lparam );
  180. #endif
  181. switch (unMsg)
  182. {
  183. case WM_INITDIALOG:
  184. {
  185. return NwInit( hwnd, (NWARGS* )lparam );
  186. }
  187. case WM_COMMAND:
  188. {
  189. NWINFO* pInfo = (NWINFO* )GetWindowLongPtr( hwnd, DWLP_USER );
  190. ASSERT(pInfo);
  191. return NwCommand(
  192. pInfo, HIWORD( wparam ), LOWORD( wparam ), (HWND )lparam );
  193. }
  194. case WM_DESTROY:
  195. {
  196. NwTerm( hwnd );
  197. break;
  198. }
  199. }
  200. return FALSE;
  201. }
  202. BOOL
  203. NwCommand(
  204. IN NWINFO* pInfo,
  205. IN WORD wNotification,
  206. IN WORD wId,
  207. IN HWND hwndCtrl )
  208. // Called on WM_COMMAND. 'PInfo' is the dialog context. 'WNotification'
  209. // is the notification code of the command. 'wId' is the control/menu
  210. // identifier of the command. 'HwndCtrl' is the control window handle of
  211. // the command.
  212. //
  213. // Returns true if processed message, false otherwise.
  214. //
  215. {
  216. TRACE3( "NwCommand(n=%d,i=%d,c=$%x)",
  217. (DWORD )wNotification, (DWORD )wId, (ULONG_PTR )hwndCtrl );
  218. switch (wId)
  219. {
  220. case IDOK:
  221. {
  222. TRACE( "OK pressed" );
  223. if (Button_GetCheck( pInfo->hwndCb ))
  224. {
  225. DWORD dwErr;
  226. // Save user's preference to skip this warning popup in the
  227. // phonebook.
  228. //
  229. pInfo->pArgs->pEntry->fSkipNwcWarning = TRUE;
  230. pInfo->pArgs->pEntry->fDirty = TRUE;
  231. dwErr = WritePhonebookFile( pInfo->pArgs->pFile, NULL );
  232. if (dwErr != 0)
  233. {
  234. ErrorDlg( pInfo->hwndDlg, SID_OP_WritePhonebook,
  235. dwErr, NULL );
  236. }
  237. }
  238. EndDialog( pInfo->hwndDlg, TRUE );
  239. return TRUE;
  240. }
  241. case IDCANCEL:
  242. {
  243. TRACE( "Cancel pressed" );
  244. EndDialog( pInfo->hwndDlg, FALSE );
  245. return TRUE;
  246. }
  247. }
  248. return FALSE;
  249. }
  250. BOOL
  251. NwInit(
  252. IN HWND hwndDlg,
  253. IN NWARGS* pArgs )
  254. // Called on WM_INITDIALOG. 'hwndDlg' is the handle of the owning window.
  255. // 'PArgs' is caller's arguments as passed to the stub API.
  256. //
  257. // Return false if focus was set, true otherwise, i.e. as defined for
  258. // WM_INITDIALOG.
  259. //
  260. {
  261. DWORD dwErr;
  262. TCHAR* psz;
  263. NWINFO* pInfo;
  264. TRACE( "NwInit" );
  265. // Allocate the dialog context block. Initialize minimally for proper
  266. // cleanup, then attach to the dialog window.
  267. //
  268. {
  269. pInfo = Malloc( sizeof(*pInfo) );
  270. if (!pInfo)
  271. {
  272. ErrorDlg( hwndDlg, SID_OP_LoadDlg, ERROR_NOT_ENOUGH_MEMORY, NULL );
  273. EndDialog( hwndDlg, FALSE );
  274. return TRUE;
  275. }
  276. ZeroMemory( pInfo, sizeof(*pInfo) );
  277. pInfo->pArgs = pArgs;
  278. pInfo->hwndDlg = hwndDlg;
  279. SetWindowLongPtr( hwndDlg, DWLP_USER, (ULONG_PTR )pInfo );
  280. TRACE( "Context set" );
  281. }
  282. pInfo->hwndCb = GetDlgItem( hwndDlg, CID_NW_CB_SkipPopup );
  283. ASSERT( pInfo->hwndCb );
  284. // Position the dialog per caller's instructions.
  285. //
  286. PositionDlg( hwndDlg, pArgs->fPosition, pArgs->xDlg, pArgs->yDlg );
  287. SetForegroundWindow( hwndDlg );
  288. // Add context help button to title bar.
  289. //
  290. AddContextHelpButton( hwndDlg );
  291. return TRUE;
  292. }
  293. VOID
  294. NwTerm(
  295. IN HWND hwndDlg )
  296. // Called on WM_DESTROY. 'HwndDlg' is that handle of the dialog window.
  297. //
  298. {
  299. NWINFO* pInfo = (NWINFO* )GetWindowLongPtr( hwndDlg, DWLP_USER );
  300. TRACE( "NwTerm" );
  301. if (pInfo)
  302. {
  303. Free( pInfo );
  304. }
  305. }
  306. //----------------------------------------------------------------------------
  307. // Utility routines
  308. //----------------------------------------------------------------------------
  309. TCHAR*
  310. GetNwProviderName(
  311. void )
  312. // Returns the NWC provider name from the registry or NULL if none. It's
  313. // caller's responsibility to Free the returned string.
  314. //
  315. {
  316. #define REGKEY_Nwc TEXT("SYSTEM\\CurrentControlSet\\Services\\NWCWorkstation\\networkprovider")
  317. #define REGVAL_Name TEXT("Name")
  318. HKEY hkey;
  319. DWORD dwErr;
  320. DWORD cb = 0; //Add this for prefix whislter bug 295921
  321. TCHAR* psz = NULL;
  322. DWORD dwType = REG_SZ;
  323. dwErr = RegOpenKey( HKEY_LOCAL_MACHINE, REGKEY_Nwc, &hkey );
  324. if (dwErr == 0)
  325. {
  326. dwErr = RegQueryValueEx(
  327. hkey, REGVAL_Name, NULL, &dwType, NULL, &cb );
  328. if (dwErr == 0)
  329. {
  330. psz = (TCHAR* )Malloc( cb );
  331. if (psz)
  332. {
  333. dwErr = RegQueryValueEx(
  334. hkey, REGVAL_Name, NULL, &dwType, (LPBYTE )psz, &cb );
  335. }
  336. }
  337. RegCloseKey( hkey );
  338. }
  339. if (!psz || dwErr != 0 || dwType != REG_SZ)
  340. {
  341. if (psz)
  342. {
  343. Free( psz );
  344. }
  345. return NULL;
  346. }
  347. return psz;
  348. }
  349. BOOL
  350. IsActiveNwLanConnection(
  351. void )
  352. // Returns true if NWC is installed and there are redirected drive or UNC
  353. // connections using NWC provider, false otherwise.
  354. //
  355. {
  356. DWORD dwErr;
  357. DWORD cEntries;
  358. DWORD cb;
  359. TCHAR* pszProvider;
  360. BYTE ab[ 1024 ];
  361. HANDLE hEnum = INVALID_HANDLE_VALUE;
  362. BOOL fStatus = FALSE;
  363. do
  364. {
  365. pszProvider = GetNwProviderName();
  366. if (!pszProvider)
  367. {
  368. break;
  369. }
  370. dwErr = WNetOpenEnum(
  371. RESOURCE_CONNECTED, RESOURCETYPE_ANY, 0, NULL, &hEnum );
  372. if (dwErr != NO_ERROR)
  373. {
  374. break;
  375. }
  376. for (;;)
  377. {
  378. NETRESOURCE* pnr;
  379. cEntries = 0xFFFFFFFF;
  380. cb = sizeof(ab);
  381. dwErr = WNetEnumResource( hEnum, &cEntries, ab, &cb );
  382. if (!cEntries || dwErr != NO_ERROR)
  383. {
  384. break;
  385. }
  386. for (pnr = (NETRESOURCE* )ab; cEntries--; ++pnr)
  387. {
  388. if (pnr->lpProvider
  389. && lstrcmp( pnr->lpProvider, pszProvider ) == 0)
  390. {
  391. fStatus = TRUE;
  392. break;
  393. }
  394. }
  395. }
  396. }
  397. while (FALSE);
  398. if (hEnum != INVALID_HANDLE_VALUE)
  399. {
  400. WNetCloseEnum( hEnum );
  401. }
  402. if (pszProvider)
  403. {
  404. Free( pszProvider );
  405. }
  406. return fStatus;
  407. }