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.

3221 lines
101 KiB

  1. #include "pch.h"
  2. #pragma hdrstop
  3. #include <shellapi.h>
  4. #include <rasdlg.h>
  5. #include "sautil.h"
  6. #include "resource.h"
  7. #include "beacon.h"
  8. #include "htmlhelp.h"
  9. #include "lm.h"
  10. #include <shlobj.h>
  11. // global(s)
  12. HINSTANCE g_hinstDll;
  13. LPCTSTR g_contextId = NULL;
  14. // external(s)
  15. extern "C" {
  16. extern BOOL WINAPI LinkWindow_RegisterClass();
  17. }
  18. // static(s)
  19. static DWORD g_adwSaHelp[] =
  20. {
  21. CID_SA_PB_Shared, HID_SA_PB_Shared,
  22. CID_SA_GB_Shared, -1,
  23. CID_SA_PB_DemandDial, HID_SA_PB_DemandDial,
  24. CID_SA_PB_Settings, HID_SA_PB_Settings,
  25. CID_SA_GB_PrivateLan, -1,
  26. // CID_SA_ST_PrivateLan, HID_SA_LB_PrivateLan,
  27. CID_SA_LB_PrivateLan, HID_SA_LB_PrivateLan,
  28. CID_FW_PB_Firewalled, HID_FW_PB_Firewalled,
  29. CID_SA_ST_ICFLink, HID_SA_ST_ICFLink,
  30. CID_SA_EB_PrivateLan, HID_SA_EB_PrivateLan,
  31. CID_SA_PB_Beacon, HID_SA_PB_Beacon,
  32. CID_SA_ST_ICSLink, HID_SA_ST_ICSLink,
  33. CID_SA_ST_HNWLink, HID_SA_ST_HNWLink,
  34. 0, 0
  35. };
  36. static TCHAR g_pszFirewallRegKey[] = TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\HomeNetworking\\PersonalFirewall");
  37. static TCHAR g_pszDisableFirewallWarningValue[] = TEXT("ShowDisableFirewallWarning");
  38. // replacement for (private) PBENTRY
  39. typedef struct _BILLSPBENTRY
  40. {
  41. TCHAR pszPhonebookPath[MAX_PATH];
  42. TCHAR pszEntryName[RAS_MaxEntryName];
  43. DWORD dwType;
  44. GUID guidId; // somewhere for pGuid to point
  45. GUID* pGuid;
  46. DWORD dwfExcludedProtocols;
  47. } BILLSPBENTRY;
  48. // Phonebook Entry common block.
  49. //
  50. typedef struct _EINFO
  51. {
  52. // RAS API arguments.
  53. //
  54. TCHAR* pszPhonebook;
  55. TCHAR* pszEntry;
  56. // RASENTRYDLG* pApiArgs;
  57. HWND hwndOwner; // bhanlon: so that EuHomenetCommit error dialogs work.
  58. // Set true by property sheet or wizard when changes should be committed
  59. // before returning from the API. Does not apply in ShellOwned-mode where
  60. // the API returns before the property sheet is dismissed.
  61. //
  62. // BOOL fCommit;
  63. // Set if we have been called via RouterEntryDlg.
  64. //
  65. BOOL fRouter;
  66. // Set if fRouter is TRUE and pszRouter refers to a remote machine.
  67. //
  68. // BOOL fRemote;
  69. // Set if pszRouter is an NT4 steelhead machine. Valid only
  70. // if fRouter is true.
  71. //
  72. // BOOL fNt4Router;
  73. //Set if pszRouter is an Windows 2000 machine, Valid only if
  74. // fRouter is true
  75. // BOOL fW2kRouter;
  76. // The name of the server in "\\server" form or NULL if none (or if
  77. // 'fRouter' is not set).
  78. //
  79. // TCHAR* pszRouter;
  80. // Set by the add entry or add interface wizards if user chooses to end
  81. // the wizard and go edit the properties directly. When this flag is set
  82. // the wizard should *not* call EuFree before returning.
  83. //
  84. // BOOL fChainPropertySheet;
  85. // Phonebook settings read from the phonebook file. All access should be
  86. // thru 'pFile' as 'file' will only be used in cases where the open
  87. // phonebook is not passed thru the reserved word hack.
  88. //
  89. // PBFILE* pFile;
  90. // PBFILE file;
  91. // Global preferences read via phonebook library. All access should be
  92. // thru 'pUser' as 'user' will only be used in cases where the preferences
  93. // are not passed thru the reserved word hack.
  94. //
  95. // PBUSER* pUser;
  96. // PBUSER user;
  97. // Set if "no user before logon" mode.
  98. //
  99. // BOOL fNoUser;
  100. // Set by the add-entry wizard if the selected port is an X.25 PAD.
  101. //
  102. // BOOL fPadSelected;
  103. // Set if there are multiple devices configured, i.e. if the UI is running
  104. // in the multiple device mode. This is implicitly false in VPN and
  105. // Direct modes.
  106. //
  107. // BOOL fMultipleDevices;
  108. // Link storing the List of PBPHONEs and alternate options for shared
  109. // phone number mode. This allows user to change the port/device to
  110. // another link without losing the phone number he typed.
  111. //
  112. // DTLNODE* pSharedNode;
  113. // The node being edited (still in the list), and the original entry name
  114. // for use in comparison later. These are valid in "edit" case only.
  115. //
  116. // DTLNODE* pOldNode;
  117. // TCHAR szOldEntryName[ RAS_MaxEntryName + 1 ];
  118. // The work entry node containing and a shortcut pointer to the entry
  119. // inside.
  120. //
  121. // DTLNODE* pNode;
  122. // PBENTRY* pEntry;
  123. BILLSPBENTRY* pEntry;
  124. // The master list of configured ports used by EuChangeEntryType to
  125. // construct an appropriate sub-list of PBLINKs in the work entry node.
  126. //
  127. // DTLLIST* pListPorts;
  128. // The "current" device. This value is NULL for multilink entries. It
  129. // is the device that the entry will use if no change is made. We compare
  130. // the current device to the device selected from the general tab to know
  131. // when it is appropriate to update the phonebook's "preferred" device.
  132. //
  133. // TCHAR* pszCurDevice;
  134. // TCHAR* pszCurPort;
  135. // Set true if there are no ports of the current entry type configured,
  136. // not including any bogus "uninstalled" ports added to the link list so
  137. // the rest of the code can assume there is at least one link.
  138. //
  139. // BOOL fNoPortsConfigured;
  140. // Dial-out user info for router; used by AiWizard. Used to set interface
  141. // credentials via MprAdminInterfaceSetCredentials.
  142. //
  143. // TCHAR* pszRouterUserName;
  144. // TCHAR* pszRouterDomain;
  145. // TCHAR* pszRouterPassword;
  146. // Dial-in user info for router (optional); used by AiWizard. Used to
  147. // create dial-in user account via NetUserAdd; the user name for the
  148. // account is the interface (phonebook entry) name.
  149. //
  150. // BOOL fAddUser;
  151. // TCHAR* pszRouterDialInPassword;
  152. // Home networking settings for the entry.
  153. //
  154. BOOL fComInitialized;
  155. IHNetConnection *pHNetConn;
  156. IHNetCfgMgr *pHNetCfgMgr;
  157. BOOL fShowHNetPages;
  158. HRESULT hShowHNetPagesResult;
  159. // ICS settings for the entry
  160. //
  161. IHNetIcsSettings *pIcsSettings;
  162. BOOL fOtherShared;
  163. BOOL fShared;
  164. BOOL fNewShared;
  165. BOOL fDemandDial;
  166. BOOL fNewDemandDial;
  167. BOOL fNewBeaconControl;
  168. BOOL fResetPrivateAdapter;
  169. IHNetConnection *pPrivateLanConnection;
  170. IHNetConnection **rgPrivateConns;
  171. IHNetIcsPublicConnection *pOldSharedConnection;
  172. DWORD dwLanCount;
  173. LONG lxCurrentPrivate;
  174. // Firewall settings for the entry
  175. //
  176. BOOL fFirewalled;
  177. BOOL fNewFirewalled;
  178. // AboladeG - security level of the current user.
  179. // Set true if the user is an administrator/power user.
  180. // This is required by several pages, both in the wizard
  181. // and in the property sheet.
  182. //
  183. BOOL fIsUserAdminOrPowerUser;
  184. // Set if strong encryption is supported by NDISWAN, as determined in
  185. // EuInit.
  186. //
  187. BOOL fStrongEncryption;
  188. // Set whent the VPN "first connect" controls should be read-only, e.g. in
  189. // the dialer's Properties button is pressed in the middle of a double
  190. // dial.
  191. //
  192. // BOOL fDisableFirstConnect;
  193. //Used in the IPSec Policy in the Security tab for a VPN connection
  194. //
  195. // BOOL fPSKCached;
  196. // TCHAR szPSK[PWLEN + 1];
  197. // Flags to track whether to save the default Internet connection
  198. //
  199. // BOOL fDefInternetPersonal;
  200. // BOOL fDefInternetGlobal;
  201. // Default credentials
  202. //
  203. // TCHAR* pszDefUserName;
  204. // TCHAR* pszDefPassword;
  205. }
  206. EINFO;
  207. // Phonebook Entry property sheet context block. All property pages refer to
  208. // the single context block is associated with the sheet.
  209. //
  210. typedef struct
  211. _PEINFO
  212. {
  213. // Common input arguments.
  214. //
  215. EINFO* pArgs;
  216. // Property sheet dialog and property page handles. 'hwndFirstPage' is
  217. // the handle of the first property page initialized. This is the page
  218. // that allocates and frees the context block.
  219. //
  220. // Note the "Network" page is missing. This "NCPA" page, developed
  221. // separately by ShaunCo, does not use this shared area for page specfic
  222. // controls, instead returning users selections via the "penettab.h"
  223. // interface.
  224. //
  225. HWND hwndDlg;
  226. // HWND hwndFirstPage;
  227. // HWND hwndGe;
  228. // HWND hwndOe;
  229. // HWND hwndLo;
  230. HWND hwndSa;
  231. // HWND hwndFw;
  232. // General page.
  233. //
  234. // HWND hwndLvDevices;
  235. // HWND hwndLbDevices;
  236. // HWND hwndPbUp;
  237. // HWND hwndPbDown;
  238. // HWND hwndCbSharedPhoneNumbers;
  239. // HWND hwndPbConfigureDevice;
  240. // HWND hwndGbPhoneNumber;
  241. // HWND hwndStAreaCodes;
  242. // HWND hwndClbAreaCodes;
  243. // HWND hwndStCountryCodes;
  244. // HWND hwndLbCountryCodes;
  245. // HWND hwndStPhoneNumber;
  246. // HWND hwndEbPhoneNumber;
  247. // HWND hwndCbUseDialingRules;
  248. // HWND hwndPbDialingRules;
  249. // HWND hwndPbAlternates;
  250. // HWND hwndCbShowIcon;
  251. // HWND hwndEbHostName;
  252. // HWND hwndCbDialAnotherFirst;
  253. // HWND hwndLbDialAnotherFirst;
  254. // HWND hwndEbBroadbandService;
  255. // Options page.
  256. //
  257. // HWND hwndCbDisplayProgress;
  258. // HWND hwndCbPreviewUserPw;
  259. // HWND hwndCbPreviewDomain;
  260. // HWND hwndCbPreviewNumber;
  261. // HWND hwndEbRedialAttempts;
  262. // HWND hwndLbRedialTimes;
  263. // HWND hwndLbIdleTimes;
  264. // HWND hwndCbRedialOnDrop;
  265. // HWND hwndGbMultipleDevices;
  266. // HWND hwndLbMultipleDevices;
  267. // HWND hwndPbConfigureDialing;
  268. // HWND hwndPbX25;
  269. // HWND hwndPbTunnel;
  270. // HWND hwndRbPersistent; // only for fRouter
  271. // HWND hwndRbDemandDial; // only for fRouter
  272. // Security page.
  273. //
  274. // HWND hwndGbSecurityOptions;
  275. // HWND hwndRbTypicalSecurity;
  276. // HWND hwndStAuths;
  277. // HWND hwndLbAuths;
  278. // HWND hwndCbUseWindowsPw;
  279. // HWND hwndCbEncryption;
  280. // HWND hwndRbAdvancedSecurity;
  281. // HWND hwndStAdvancedText;
  282. // HWND hwndPbAdvanced;
  283. // HWND hwndPbIPSec; //Only for VPN
  284. // HWND hwndGbScripting;
  285. // HWND hwndCbRunScript;
  286. // HWND hwndCbTerminal;
  287. // HWND hwndLbScripts;
  288. // HWND hwndPbEdit;
  289. // HWND hwndPbBrowse;
  290. // Networking page.
  291. //
  292. // HWND hwndLbServerType;
  293. // HWND hwndPbSettings;
  294. // HWND hwndLvComponents;
  295. // HWND hwndPbAdd;
  296. // HWND hwndPbRemove;
  297. // HWND hwndPbProperties;
  298. // HWND hwndDescription;
  299. // Shared Access page.
  300. //
  301. HWND hwndSaPbShared;
  302. HWND hwndSaGbShared;
  303. HWND hwndSaGbPrivateLan;
  304. HWND hwndSaEbPrivateLan;
  305. HWND hwndSaLbPrivateLan;
  306. HWND hwndSaSfPrivateLan;
  307. HWND hwndSaPbDemandDial;
  308. HWND hwndSaPbFirewalled;
  309. // Indicates that the informational popup noting that SLIP does not
  310. // support any authentication settings should appear the next time the
  311. // Security page is activated.
  312. //
  313. // BOOL fShowSlipPopup;
  314. // The "restore" states of the typical security mode listbox and
  315. // checkboxes. Initialized in LoInit and set whenever the controls are
  316. // disabled.
  317. //
  318. // DWORD iLbAuths;
  319. // BOOL fUseWindowsPw;
  320. // BOOL fEncryption;
  321. // MoveUp/MoveDown icons, for enabled/disabled cases.
  322. //
  323. // HANDLE hiconUpArr;
  324. // HANDLE hiconDnArr;
  325. // HANDLE hiconUpArrDis;
  326. // HANDLE hiconDnArrDis;
  327. // The currently displayed link node, i.e. either the node of the selected
  328. // device or the shared node. This is a shortcut for GeAlternates, that
  329. // keeps all the lookup code in GeUpdatePhoneNumberFields.
  330. //
  331. // DTLNODE* pCurLinkNode;
  332. // The currently selected device. Used to store phone number information
  333. // for the just unselected device when a new device is selected.
  334. //
  335. // INT iDeviceSelected;
  336. // Complex phone number helper context block, and a flag indicating if the
  337. // block has been initialized.
  338. //
  339. // CUINFO cuinfo;
  340. // BOOL fCuInfoInitialized;
  341. // After dial scripting helper context block, and a flag indicating if the
  342. // block has been initialized.
  343. //
  344. // SUINFO suinfo;
  345. // BOOL fSuInfoInitialized;
  346. // Flags whether the user authorized a reboot after installing or removing
  347. // and networking component.
  348. //
  349. // BOOL fRebootAlreadyRequested;
  350. // List of area codes passed CuInit plus all strings retrieved with
  351. // CuGetInfo. The list is an editing duplicate of the one from the
  352. // PBUSER.
  353. //
  354. // DTLLIST* pListAreaCodes;
  355. // Stash/restore values for Options page checkboxes.
  356. //
  357. // BOOL fPreviewUserPw;
  358. // BOOL fPreviewDomain;
  359. // Set when user changes to "Typical smartcard" security. This causes the
  360. // registry based association of EAP per-user information to be discarded,
  361. // sort of like flushing cached credentials.
  362. //
  363. // BOOL fDiscardEapUserData;
  364. // Set true on the first click of the Typical or Advanced radio button on
  365. // the security page, false before. The first click is the one
  366. // artificially generated in LoInit. The Advanced click handler uses the
  367. // information to avoid incorrectly adopting the Typical defaults in the
  368. // case of Advanced settings.
  369. //
  370. // BOOL fAuthRbInitialized;
  371. // Used by the networking page
  372. //
  373. // INetCfg* pNetCfg;
  374. // BOOL fInitCom;
  375. // BOOL fReadOnly; // Netcfg was initialized in
  376. // read-only mode
  377. // BOOL fNonAdmin; // Run in non-admin mode (406630)
  378. // BOOL fNetCfgLock;// NetCfg needs to be unlocked
  379. // when uninited.
  380. // SP_CLASSIMAGELIST_DATA cild;
  381. // INetConnectionUiUtilities * pNetConUtilities;
  382. // IUnknown* punkUiInfoCallback;
  383. // Set if COM has been initialized (necessary for calls to netshell).
  384. //
  385. // BOOL fComInitialized;
  386. // Keep track of whether we have shown this warning, or if it was disabled by the user
  387. //
  388. BOOL fShowDisableFirewallWarning;
  389. // r/w memory for indirect propsheet dialog
  390. LPDLGTEMPLATE lpdt;
  391. }
  392. PEINFO;
  393. // local protos
  394. INT_PTR CALLBACK SaDlgProc (IN HWND hwnd, IN UINT unMsg, IN WPARAM wparam, IN LPARAM lparam);
  395. BOOL SaCommand (IN PEINFO* pInfo, IN WORD wNotification, IN WORD wId, IN HWND hwndCtrl);
  396. BOOL SaInit (IN HWND hwndPage);
  397. // more local protos
  398. PEINFO* PeContext(IN HWND hwndPage);
  399. BOOL SaIsAdapterDHCPEnabled(IN IHNetConnection* pConnection);
  400. INT_PTR CALLBACK SaDisableFirewallWarningDlgProc(IN HWND hwnd, IN UINT unMsg, IN WPARAM wparam, IN LPARAM lparam);
  401. HRESULT PeInit (GUID * pGuid, PEINFO ** ppEI);
  402. DWORD EuInit (IN RASENTRY * pRE, IN TCHAR* pszPhonebook, IN TCHAR* pszEntry, IN RASENTRYDLG* pArgs, IN BOOL fRouter, OUT EINFO** ppInfo, OUT DWORD* pdwOp);
  403. BOOL FIsUserAdminOrPowerUser (void);
  404. void PeTerm (PEINFO * pEI);
  405. VOID EuFree (IN EINFO* pInfo);
  406. BOOL PeApply (IN HWND hwndPage);
  407. BOOL EuCommit(IN EINFO* pInfo);
  408. DWORD EuHomenetCommitSettings(IN EINFO* pInfo);
  409. LRESULT CALLBACK CenterDlgOnOwnerCallWndProc (int code, WPARAM wparam, LPARAM lparam);
  410. TCHAR* PszFromId(IN HINSTANCE hInstance,IN DWORD dwStringId);
  411. HRESULT APIENTRY HrCreateNetConnectionUtilities(INetConnectionUiUtilities ** ppncuu);
  412. VOID VerifyConnTypeAndCreds(IN PEINFO* pInfo);
  413. DWORD FindEntryCredentials(IN TCHAR* pszPath, IN TCHAR* pszEntryName, OUT BOOL* pfUser, OUT BOOL* pfGlobal);
  414. //----------------------------------------------------------------------------
  415. // Shared Access property page
  416. // Listed alphabetically following dialog proc
  417. //----------------------------------------------------------------------------
  418. INT_PTR CALLBACK
  419. SaDlgProc(
  420. IN HWND hwnd,
  421. IN UINT unMsg,
  422. IN WPARAM wparam,
  423. IN LPARAM lparam )
  424. // DialogProc callback for the Shared Access page of the Entry property
  425. // sheet.
  426. // Parameters and return value are as described for standard windows
  427. // 'DialogProc's.
  428. //
  429. {
  430. #if 0
  431. TRACE4( "SaDlgProc(h=$%x,m=$%x,w=$%x,l=$%x)",
  432. (DWORD )hwnd, (DWORD )unMsg, (DWORD )wparam, (DWORD )lparam );
  433. #endif
  434. switch (unMsg)
  435. {
  436. case WM_INITDIALOG:
  437. {
  438. // hang pPEINFO off prop
  439. PROPSHEETPAGEW * pPSP = (PROPSHEETPAGEW *)lparam;
  440. SetProp (hwnd, g_contextId, (HANDLE)pPSP->lParam);
  441. return SaInit( hwnd );
  442. }
  443. case WM_NCDESTROY:
  444. {
  445. PEINFO* pInfo = PeContext( hwnd );
  446. if (pInfo)
  447. PeTerm (pInfo);
  448. RemoveProp (hwnd, g_contextId);
  449. GlobalDeleteAtom ((ATOM)g_contextId);
  450. g_contextId = NULL;
  451. break;
  452. }
  453. case WM_HELP:
  454. case WM_CONTEXTMENU:
  455. {
  456. ContextHelp( g_adwSaHelp, hwnd, unMsg, wparam, lparam );
  457. break;
  458. }
  459. case WM_COMMAND:
  460. {
  461. PEINFO* pInfo = PeContext( hwnd );
  462. ASSERT(pInfo);
  463. if (pInfo == NULL)
  464. {
  465. break;
  466. }
  467. return SaCommand(
  468. pInfo, HIWORD( wparam ), LOWORD( wparam ),(HWND )lparam );
  469. }
  470. case WM_NOTIFY:
  471. {
  472. switch (((NMHDR* )lparam)->code)
  473. {
  474. case PSN_APPLY:
  475. {
  476. PeApply (hwnd);
  477. return TRUE;
  478. }
  479. case PSN_KILLACTIVE:
  480. {
  481. PEINFO* pInfo;
  482. TRACE("SwKILLACTIVE");
  483. pInfo = PeContext( hwnd );
  484. ASSERT(pInfo);
  485. if (pInfo == NULL)
  486. {
  487. break;
  488. }
  489. if ( Button_GetCheck( pInfo->hwndSaPbShared )
  490. && (!pInfo->pArgs->fShared || (pInfo->pArgs->fResetPrivateAdapter && 0 != pInfo->pArgs->dwLanCount)))
  491. {
  492. IHNetConnection* pPrivateConn = NULL;
  493. if(1 < pInfo->pArgs->dwLanCount) // if the combobox is showing make sure they selected a valid adapter
  494. {
  495. INT item = ComboBox_GetCurSel( pInfo->hwndSaLbPrivateLan );
  496. if (item != CB_ERR)
  497. {
  498. pPrivateConn = (IHNetConnection*)ComboBox_GetItemData( pInfo->hwndSaLbPrivateLan, item );
  499. }
  500. }
  501. else
  502. {
  503. pPrivateConn = pInfo->pArgs->rgPrivateConns[0];
  504. }
  505. if(NULL == pPrivateConn)
  506. {
  507. MSGARGS msgargs;
  508. ASSERT(1 < pInfo->pArgs->dwLanCount);
  509. ZeroMemory( &msgargs, sizeof(msgargs) );
  510. msgargs.dwFlags = MB_OK | MB_ICONWARNING;
  511. MsgDlg( pInfo->hwndDlg, SID_SA_SelectAdapterError, &msgargs );
  512. SetWindowLong( hwnd, DWLP_MSGRESULT, PSNRET_INVALID );
  513. return TRUE;
  514. }
  515. if(!pInfo->pArgs->fOtherShared && FALSE == SaIsAdapterDHCPEnabled(pPrivateConn))
  516. {
  517. // if shared access is being turned on for the first time,
  518. // explain its implications.
  519. //
  520. MSGARGS msgargs;
  521. UINT unId;
  522. ZeroMemory( &msgargs, sizeof(msgargs) );
  523. msgargs.dwFlags = MB_YESNO | MB_ICONINFORMATION;
  524. unId = MsgDlg( pInfo->hwndDlg, SID_EnableSharedAccess, &msgargs );
  525. if (unId == IDNO)
  526. SetWindowLong( hwnd, DWLP_MSGRESULT, TRUE );
  527. else
  528. SetWindowLong( hwnd, DWLP_MSGRESULT, FALSE );
  529. }
  530. }
  531. if ( TRUE == pInfo->pArgs->fFirewalled && TRUE == pInfo->fShowDisableFirewallWarning && FALSE == Button_GetCheck( pInfo->hwndSaPbFirewalled ) )
  532. {
  533. INT_PTR nDialogResult;
  534. pInfo->fShowDisableFirewallWarning = FALSE;
  535. nDialogResult = DialogBox(g_hinstDll, MAKEINTRESOURCE(DID_SA_DisableFirewallWarning), hwnd, SaDisableFirewallWarningDlgProc);
  536. if(-1 != nDialogResult && IDYES != nDialogResult)
  537. {
  538. Button_SetCheck ( pInfo->hwndSaPbFirewalled, TRUE );
  539. SaCommand( pInfo, BN_CLICKED, CID_FW_PB_Firewalled, pInfo->hwndSaPbFirewalled );
  540. }
  541. }
  542. return TRUE;
  543. }
  544. case NM_CLICK:
  545. case NM_RETURN:
  546. {
  547. HWND hPropertySheetWindow = GetParent(hwnd);
  548. if(NULL != hPropertySheetWindow)
  549. {
  550. if(CID_SA_ST_HNWLink == wparam)
  551. {
  552. ShellExecute(NULL,TEXT("open"),TEXT("rundll32"), TEXT("hnetwiz.dll,HomeNetWizardRunDll"),NULL,SW_SHOW);
  553. PostMessage(hPropertySheetWindow, WM_COMMAND, MAKEWPARAM(IDCANCEL, 0), (LPARAM) GetDlgItem(hPropertySheetWindow, IDCANCEL));
  554. }
  555. else if(CID_SA_ST_ICFLink == wparam || CID_SA_ST_ICSLink == wparam)
  556. {
  557. LPTSTR pszHelpTopic = CID_SA_ST_ICFLink == wparam ? TEXT("netcfg.chm::/hnw_understanding_firewall.htm") : TEXT("netcfg.chm::/Share_conn_overvw.htm");
  558. HtmlHelp(NULL, pszHelpTopic, HH_DISPLAY_TOPIC, 0);
  559. }
  560. }
  561. break;
  562. }
  563. }
  564. break;
  565. }
  566. }
  567. return FALSE;
  568. }
  569. BOOL
  570. SaCommand(
  571. IN PEINFO* pInfo,
  572. IN WORD wNotification,
  573. IN WORD wId,
  574. IN HWND hwndCtrl )
  575. // Called on WM_COMMAND. 'PInfo' is the dialog context. 'WNotification'
  576. // is the notification code of the command. 'wId' is the control/menu
  577. // identifier of the command. 'HwndCtrl' is the control window handle of
  578. // the command.
  579. //
  580. // Returns true if processed message, false otherwise.
  581. //
  582. {
  583. TRACE3( "SaCommand(n=%d,i=%d,c=$%x)",
  584. (DWORD )wNotification, (DWORD )wId, (ULONG_PTR )hwndCtrl );
  585. switch (wId)
  586. {
  587. case CID_FW_PB_Firewalled:
  588. {
  589. BOOL fFirewalled = Button_GetCheck( pInfo->hwndSaPbFirewalled );
  590. EnableWindow(
  591. GetDlgItem( pInfo->hwndSa, CID_SA_PB_Settings ), fFirewalled || Button_GetCheck( pInfo->hwndSaPbShared ));
  592. return TRUE;
  593. }
  594. case CID_SA_PB_Shared:
  595. {
  596. BOOL fShared = Button_GetCheck( pInfo->hwndSaPbShared );
  597. EnableWindow( pInfo->hwndSaPbDemandDial, fShared );
  598. EnableWindow( GetDlgItem(pInfo->hwndSa, CID_SA_PB_Beacon), fShared );
  599. EnableWindow(
  600. GetDlgItem( pInfo->hwndSa, CID_SA_PB_Settings ), fShared || Button_GetCheck( pInfo->hwndSaPbFirewalled ));
  601. if (fShared && !pInfo->pArgs->fShared)
  602. {
  603. MSGARGS msgargs;
  604. IEnumHNetIcsPublicConnections *pEnum;
  605. IHNetIcsPublicConnection *pOldIcsConn;
  606. IHNetConnection *pOldConn;
  607. LPWSTR pszwOldName = NULL;
  608. HRESULT hr;
  609. hr = pInfo->pArgs->pIcsSettings->EnumIcsPublicConnections (&pEnum);
  610. if (SUCCEEDED(hr))
  611. {
  612. ULONG ulCount;
  613. VerifyConnTypeAndCreds(pInfo);
  614. hr = pEnum->Next(
  615. 1,
  616. &pOldIcsConn,
  617. &ulCount
  618. );
  619. if (SUCCEEDED(hr) && 1 == ulCount)
  620. {
  621. hr = pOldIcsConn->QueryInterface(
  622. IID_IHNetConnection,
  623. (void**)&pOldConn
  624. );
  625. if (SUCCEEDED(hr))
  626. {
  627. // Transer pOldIcsConn reference
  628. //
  629. pInfo->pArgs->fOtherShared = TRUE;
  630. pInfo->pArgs->pOldSharedConnection = pOldIcsConn;
  631. hr = pOldConn->GetName (&pszwOldName);
  632. pOldConn->Release();
  633. }
  634. else
  635. {
  636. pOldIcsConn->Release();
  637. }
  638. }
  639. pEnum->Release();
  640. }
  641. if (SUCCEEDED(hr) && NULL != pszwOldName)
  642. {
  643. ZeroMemory( &msgargs, sizeof(msgargs) );
  644. msgargs.apszArgs[ 0 ] = pszwOldName;
  645. msgargs.apszArgs[ 1 ] = pInfo->pArgs->pEntry->pszEntryName;
  646. msgargs.dwFlags = MB_OK | MB_ICONINFORMATION;
  647. MsgDlg( pInfo->hwndDlg, SID_ChangeSharedConnection, &msgargs );
  648. CoTaskMemFree( pszwOldName );
  649. }
  650. }
  651. return TRUE;
  652. }
  653. case CID_SA_PB_Settings:
  654. {
  655. HNetSharingAndFirewallSettingsDlg(
  656. pInfo->hwndDlg,
  657. pInfo->pArgs->pHNetCfgMgr,
  658. Button_GetCheck( pInfo->hwndSaPbFirewalled ),
  659. pInfo->pArgs->pHNetConn
  660. );
  661. return TRUE;
  662. }
  663. }
  664. return FALSE;
  665. }
  666. BOOL
  667. SaInit(
  668. IN HWND hwndPage )
  669. // Called on WM_INITDIALOG. 'hwndPage' is the handle of the property
  670. // page.
  671. //
  672. // Return false if focus was set, true otherwise.
  673. //
  674. {
  675. PEINFO* pInfo;
  676. INetConnectionUiUtilities* pncuu = NULL;
  677. OSVERSIONINFOEXW verInfo = {0};
  678. ULONGLONG ConditionMask = 0;
  679. TRACE( "SaInit" );
  680. pInfo = PeContext( hwndPage );
  681. if (!pInfo)
  682. {
  683. return TRUE;
  684. }
  685. _ASSERT (pInfo->hwndDlg == NULL);
  686. pInfo->pArgs->hwndOwner = pInfo->hwndDlg = GetParent (hwndPage);
  687. _ASSERT (pInfo->hwndDlg);
  688. // Initialize page-specific context information.
  689. //
  690. pInfo->hwndSa = hwndPage;
  691. pInfo->hwndSaPbShared = GetDlgItem( hwndPage, CID_SA_PB_Shared );
  692. ASSERT( pInfo->hwndSaPbShared );
  693. pInfo->hwndSaGbShared = GetDlgItem( hwndPage, CID_SA_GB_Shared );
  694. ASSERT( pInfo->hwndSaGbShared );
  695. pInfo->hwndSaGbPrivateLan = GetDlgItem( hwndPage, CID_SA_GB_PrivateLan );
  696. ASSERT( pInfo->hwndSaGbPrivateLan );
  697. pInfo->hwndSaEbPrivateLan = GetDlgItem( hwndPage, CID_SA_EB_PrivateLan );
  698. ASSERT( pInfo->hwndSaEbPrivateLan );
  699. pInfo->hwndSaLbPrivateLan = GetDlgItem( hwndPage, CID_SA_LB_PrivateLan );
  700. ASSERT( pInfo->hwndSaLbPrivateLan );
  701. pInfo->hwndSaSfPrivateLan = GetDlgItem( hwndPage, CID_SA_SF_PrivateLan );
  702. ASSERT( pInfo->hwndSaSfPrivateLan );
  703. pInfo->hwndSaPbDemandDial = GetDlgItem( hwndPage, CID_SA_PB_DemandDial );
  704. ASSERT( pInfo->hwndSaPbDemandDial );
  705. pInfo->hwndSaPbFirewalled = GetDlgItem( hwndPage, CID_FW_PB_Firewalled );
  706. ASSERT( pInfo->hwndSaPbFirewalled );
  707. // Initialize checks.
  708. //
  709. // Check if ZAW is denying access to the Shared Access UI
  710. //
  711. if (FAILED(HrCreateNetConnectionUtilities(&pncuu)))
  712. {
  713. ASSERT(NULL == pncuu);
  714. }
  715. if(NULL == pncuu || TRUE == pncuu->UserHasPermission (NCPERM_PersonalFirewallConfig))
  716. {
  717. HKEY hFirewallKey;
  718. Button_SetCheck( pInfo->hwndSaPbFirewalled, pInfo->pArgs->fFirewalled );
  719. SaCommand( pInfo, BN_CLICKED, CID_FW_PB_Firewalled, pInfo->hwndSaPbFirewalled );
  720. pInfo->fShowDisableFirewallWarning = TRUE;
  721. if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, g_pszFirewallRegKey, 0, KEY_QUERY_VALUE, &hFirewallKey))
  722. {
  723. DWORD dwValue;
  724. DWORD dwType;
  725. DWORD dwSize = sizeof(dwValue);
  726. if(ERROR_SUCCESS == RegQueryValueEx(hFirewallKey, g_pszDisableFirewallWarningValue, NULL, &dwType, (BYTE*)&dwValue, &dwSize))
  727. {
  728. if(REG_DWORD == dwType && TRUE == dwValue)
  729. {
  730. pInfo->fShowDisableFirewallWarning = FALSE;
  731. }
  732. }
  733. RegCloseKey(hFirewallKey);
  734. }
  735. }
  736. else
  737. {
  738. EnableWindow(pInfo->hwndSaPbFirewalled, FALSE);
  739. }
  740. // Initialize the page's appearance.
  741. // If there are multiple private LAN connections, below the 'shared access'
  742. // checkbox we display either
  743. // (a) a drop-list of LAN connections if the connection is not shared, or
  744. // (b) a disabled edit-control with the current private LAN.
  745. // This involves moving everything in the 'on-demand dialing' groupbox
  746. // downward on the page at run-time.
  747. // To achieve this, we use a hidden static control to tell us the position
  748. // to which the groupbox should be moved.
  749. //
  750. BOOL fPolicyAllowsSharing = TRUE;
  751. if(NULL != pncuu && FALSE == pncuu->UserHasPermission (NCPERM_ShowSharedAccessUi))
  752. {
  753. fPolicyAllowsSharing = FALSE;
  754. }
  755. if (pInfo->pArgs->dwLanCount == 0)
  756. {
  757. ShowWindow(pInfo->hwndSaGbShared, SW_HIDE);
  758. ShowWindow(pInfo->hwndSaPbShared, SW_HIDE);
  759. ShowWindow(pInfo->hwndSaPbDemandDial, SW_HIDE);
  760. ShowWindow(GetDlgItem(hwndPage, CID_SA_PB_Shared), SW_HIDE);
  761. ShowWindow(GetDlgItem(hwndPage, CID_SA_ST_ICSLink), SW_HIDE);
  762. ShowWindow(GetDlgItem(hwndPage, CID_SA_PB_Beacon), SW_HIDE);
  763. }
  764. else if(FALSE == fPolicyAllowsSharing)
  765. {
  766. // if policy disables ICS just gray the checkbox
  767. EnableWindow(pInfo->hwndSaPbShared, FALSE);
  768. EnableWindow(pInfo->hwndSaPbDemandDial, FALSE);
  769. EnableWindow(GetDlgItem(hwndPage, CID_SA_PB_Beacon), FALSE);
  770. }
  771. else if (pInfo->pArgs->dwLanCount > 1)
  772. {
  773. INT cy;
  774. HDWP hdwp;
  775. DWORD i;
  776. INT item;
  777. RECT rc, rcFrame;
  778. IHNetConnection **rgPrivateConns;
  779. LPWSTR pszwName;
  780. HRESULT hr;
  781. // get the reference-frame and group-box coordinates
  782. //
  783. GetWindowRect( pInfo->hwndSaSfPrivateLan, &rcFrame );
  784. GetWindowRect( pInfo->hwndSaPbDemandDial, &rc );
  785. cy = rcFrame.top - rc.top;
  786. // move each control down by the amount in 'cy'
  787. //
  788. hdwp = BeginDeferWindowPos(3);
  789. if(NULL != hdwp)
  790. {
  791. GetWindowRect( pInfo->hwndSaPbDemandDial, &rc);
  792. MapWindowPoints(NULL, hwndPage, (LPPOINT)&rc, 2);
  793. DeferWindowPos(hdwp, pInfo->hwndSaPbDemandDial, NULL,
  794. rc.left, rc.top + cy, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
  795. HWND hBeaconCheck = GetDlgItem(hwndPage, CID_SA_PB_Beacon);
  796. GetWindowRect( hBeaconCheck, &rc);
  797. MapWindowPoints(NULL, hwndPage, (LPPOINT)&rc, 2);
  798. DeferWindowPos(hdwp, hBeaconCheck, NULL,
  799. rc.left, rc.top + cy, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
  800. HWND hICSLink = GetDlgItem(hwndPage, CID_SA_ST_ICSLink);
  801. GetWindowRect( hICSLink, &rc);
  802. MapWindowPoints(NULL, hwndPage, (LPPOINT)&rc, 2);
  803. DeferWindowPos(hdwp, hICSLink, NULL,
  804. rc.left, rc.top + cy, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
  805. EndDeferWindowPos(hdwp);
  806. }
  807. // hide the smaller shared-access group box, show the larger version,
  808. // and display either the drop-list or the edit-control.
  809. //
  810. rgPrivateConns = (IHNetConnection **)pInfo->pArgs->rgPrivateConns;
  811. ShowWindow( pInfo->hwndSaGbShared, SW_HIDE );
  812. ShowWindow( pInfo->hwndSaGbPrivateLan, SW_SHOW );
  813. ShowWindow(GetDlgItem(hwndPage, CID_SA_ST_HomeConnection), SW_SHOW);
  814. EnableWindow(GetDlgItem(hwndPage, CID_SA_ST_HomeConnection), TRUE);
  815. if (pInfo->pArgs->fShared && !pInfo->pArgs->fResetPrivateAdapter)
  816. {
  817. ShowWindow( pInfo->hwndSaEbPrivateLan, SW_SHOW );
  818. // Fill in name of current private connection
  819. //
  820. hr = rgPrivateConns[pInfo->pArgs->lxCurrentPrivate]->GetName (&pszwName);
  821. if (SUCCEEDED(hr))
  822. {
  823. SetWindowText(
  824. pInfo->hwndSaEbPrivateLan, pszwName );
  825. CoTaskMemFree( pszwName );
  826. }
  827. }
  828. else
  829. {
  830. ShowWindow( pInfo->hwndSaLbPrivateLan, SW_SHOW );
  831. // Add the bogus entry to the combobox
  832. pszwName = PszFromId( g_hinstDll, SID_SA_SelectAdapter );
  833. ASSERT(pszwName);
  834. item = ComboBox_AddString( pInfo->hwndSaLbPrivateLan, pszwName );
  835. if (item != CB_ERR && item != CB_ERRSPACE)
  836. {
  837. ComboBox_SetItemData( pInfo->hwndSaLbPrivateLan, item, NULL ); // ensure item data is null for validation purposes
  838. }
  839. // fill the combobox with LAN names
  840. //
  841. for (i = 0; i < pInfo->pArgs->dwLanCount; i++)
  842. {
  843. hr = rgPrivateConns[i]->GetName (&pszwName);
  844. if (SUCCEEDED(hr))
  845. {
  846. item =
  847. ComboBox_AddString(
  848. pInfo->hwndSaLbPrivateLan, pszwName );
  849. if (item != CB_ERR)
  850. {
  851. ComboBox_SetItemData(
  852. pInfo->hwndSaLbPrivateLan, item, rgPrivateConns[i] );
  853. }
  854. CoTaskMemFree( pszwName );
  855. }
  856. }
  857. ComboBox_SetCurSel( pInfo->hwndSaLbPrivateLan, 0 );
  858. }
  859. }
  860. if(NULL != pncuu)
  861. {
  862. pncuu->Release();
  863. }
  864. // Initialize checks.
  865. //
  866. BOOL fBeaconControl = TRUE;
  867. HKEY hKey;
  868. DWORD dwError = RegOpenKeyEx(HKEY_LOCAL_MACHINE, REGKEY_SHAREDACCESSCLIENTKEYPATH, 0, KEY_QUERY_VALUE, &hKey);
  869. if(ERROR_SUCCESS == dwError) // if this fails we assume it is on, set the box, and commit on apply
  870. {
  871. DWORD dwType;
  872. DWORD dwData = 0;
  873. DWORD dwSize = sizeof(dwData);
  874. dwError = RegQueryValueEx(hKey, REGVAL_SHAREDACCESSCLIENTENABLECONTROL, 0, &dwType, reinterpret_cast<LPBYTE>(&dwData), &dwSize);
  875. if(ERROR_SUCCESS == dwError && REG_DWORD == dwType && 0 == dwData)
  876. {
  877. fBeaconControl = FALSE;
  878. }
  879. RegCloseKey(hKey);
  880. }
  881. Button_SetCheck( pInfo->hwndSaPbShared, pInfo->pArgs->fShared );
  882. Button_SetCheck( pInfo->hwndSaPbDemandDial, pInfo->pArgs->fDemandDial );
  883. Button_SetCheck(GetDlgItem(hwndPage, CID_SA_PB_Beacon), fBeaconControl);
  884. EnableWindow( pInfo->hwndSaPbDemandDial, pInfo->pArgs->fShared && fPolicyAllowsSharing);
  885. EnableWindow( GetDlgItem(hwndPage, CID_SA_PB_Beacon), pInfo->pArgs->fShared && fPolicyAllowsSharing );
  886. EnableWindow( GetDlgItem( pInfo->hwndSa, CID_SA_PB_Settings ), pInfo->pArgs->fShared || pInfo->pArgs->fFirewalled );
  887. //if the machine is personal or workstation show the HNW link
  888. verInfo.dwOSVersionInfoSize = sizeof(verInfo);
  889. verInfo.wProductType = VER_NT_WORKSTATION;
  890. VER_SET_CONDITION(ConditionMask, VER_PRODUCT_TYPE, VER_LESS_EQUAL);
  891. if(0 != VerifyVersionInfo(&verInfo, VER_PRODUCT_TYPE, ConditionMask))
  892. {
  893. // but only if not on a domain
  894. LPWSTR pszNameBuffer;
  895. NETSETUP_JOIN_STATUS BufferType;
  896. if(NERR_Success == NetGetJoinInformation(NULL, &pszNameBuffer, &BufferType))
  897. {
  898. NetApiBufferFree(pszNameBuffer);
  899. if(NetSetupDomainName != BufferType)
  900. {
  901. ShowWindow(GetDlgItem(hwndPage, CID_SA_ST_HNWLink), SW_SHOW);
  902. }
  903. }
  904. }
  905. return TRUE;
  906. }
  907. INT_PTR CALLBACK
  908. SaDisableFirewallWarningDlgProc(
  909. IN HWND hwnd,
  910. IN UINT unMsg,
  911. IN WPARAM wparam,
  912. IN LPARAM lparam )
  913. {
  914. switch(unMsg)
  915. {
  916. case WM_COMMAND:
  917. {
  918. switch(LOWORD(wparam))
  919. {
  920. case IDYES:
  921. case IDNO:
  922. if(BST_CHECKED == IsDlgButtonChecked(hwnd, CID_SA_PB_DisableFirewallWarning))
  923. {
  924. HKEY hFirewallKey;
  925. if(ERROR_SUCCESS == RegCreateKeyEx(HKEY_CURRENT_USER, g_pszFirewallRegKey, 0, NULL, 0, KEY_SET_VALUE, NULL, &hFirewallKey, NULL))
  926. {
  927. DWORD dwValue = TRUE;
  928. RegSetValueEx(hFirewallKey, g_pszDisableFirewallWarningValue, 0, REG_DWORD, (CONST BYTE*)&dwValue, sizeof(dwValue));
  929. RegCloseKey(hFirewallKey);
  930. }
  931. }
  932. // fallthru
  933. case IDCANCEL:
  934. EndDialog(hwnd, LOWORD(wparam));
  935. break;
  936. }
  937. break;
  938. }
  939. }
  940. return FALSE;
  941. }
  942. BOOL SaIsAdapterDHCPEnabled(IHNetConnection* pConnection)
  943. {
  944. HRESULT hr;
  945. BOOL fDHCP = FALSE;
  946. GUID* pAdapterGuid;
  947. hr = pConnection->GetGuid (&pAdapterGuid);
  948. if(SUCCEEDED(hr))
  949. {
  950. LPOLESTR pAdapterName;
  951. hr = StringFromCLSID(*pAdapterGuid, &pAdapterName);
  952. if(SUCCEEDED(hr))
  953. {
  954. SIZE_T Length = wcslen(pAdapterName);
  955. LPSTR pszAnsiAdapterName = (LPSTR)Malloc(Length + 1);
  956. if(NULL != pszAnsiAdapterName)
  957. {
  958. if(0 != WideCharToMultiByte(CP_ACP, 0, pAdapterName, (int)(Length + 1), pszAnsiAdapterName, (int)(Length + 1), NULL, NULL))
  959. {
  960. HMODULE hIpHelper;
  961. hIpHelper = LoadLibrary(L"iphlpapi");
  962. if(NULL != hIpHelper)
  963. {
  964. DWORD (WINAPI *pGetAdaptersInfo)(PIP_ADAPTER_INFO, PULONG);
  965. pGetAdaptersInfo = (DWORD (WINAPI*)(PIP_ADAPTER_INFO, PULONG)) GetProcAddress(hIpHelper, "GetAdaptersInfo");
  966. if(NULL != pGetAdaptersInfo)
  967. {
  968. ULONG ulSize = 0;
  969. if(ERROR_BUFFER_OVERFLOW == pGetAdaptersInfo(NULL, &ulSize))
  970. {
  971. PIP_ADAPTER_INFO pInfo = (PIP_ADAPTER_INFO)Malloc(ulSize);
  972. if(NULL != pInfo)
  973. {
  974. if(ERROR_SUCCESS == pGetAdaptersInfo(pInfo, &ulSize))
  975. {
  976. PIP_ADAPTER_INFO pAdapterInfo = pInfo;
  977. do
  978. {
  979. if(0 == lstrcmpA(pszAnsiAdapterName, pAdapterInfo->AdapterName))
  980. {
  981. fDHCP = !!pAdapterInfo->DhcpEnabled;
  982. break;
  983. }
  984. } while(NULL != (pAdapterInfo = pAdapterInfo->Next));
  985. }
  986. Free(pInfo);
  987. }
  988. }
  989. }
  990. FreeLibrary(hIpHelper);
  991. }
  992. }
  993. Free(pszAnsiAdapterName);
  994. }
  995. CoTaskMemFree(pAdapterName);
  996. }
  997. CoTaskMemFree(pAdapterGuid);
  998. }
  999. return fDHCP;
  1000. }
  1001. PEINFO* PeContext (IN HWND hwndPage)
  1002. {
  1003. // Retrieve the property sheet context from a property page handle.
  1004. //
  1005. // return (PEINFO* )GetProp( GetParent( hwndPage ), g_contextId );
  1006. // now hanging our stuff off our window (since it's not shared)
  1007. return (PEINFO* )GetProp( hwndPage, g_contextId );
  1008. }
  1009. void PeTerm (PEINFO * pEI)
  1010. {
  1011. _ASSERT (pEI);
  1012. _ASSERT (pEI->pArgs);
  1013. _ASSERT (pEI->pArgs->pEntry);
  1014. Free (pEI->pArgs->pEntry); // BILLSPBENTRY
  1015. EuFree (pEI->pArgs);
  1016. if (pEI->lpdt)
  1017. Free (pEI->lpdt);
  1018. Free (pEI);
  1019. }
  1020. VOID
  1021. EuFree(
  1022. IN EINFO* pInfo )
  1023. // Releases 'pInfo' and associated resources.
  1024. //
  1025. {
  1026. TCHAR* psz;
  1027. // INTERNALARGS* piargs;
  1028. // piargs = (INTERNALARGS* )pInfo->pApiArgs->reserved;
  1029. // Don't clean up the phonebook and user preferences if they arrived via
  1030. // the secret hack.
  1031. //
  1032. // if (!piargs)
  1033. // {
  1034. // if (pInfo->pFile)
  1035. // {
  1036. // ClosePhonebookFile( pInfo->pFile );
  1037. // }
  1038. // if (pInfo->pUser)
  1039. // {
  1040. // DestroyUserPreferences( pInfo->pUser );
  1041. // }
  1042. // }
  1043. // if (pInfo->pListPorts)
  1044. // {
  1045. // DtlDestroyList( pInfo->pListPorts, DestroyPortNode );
  1046. // }
  1047. // Free(pInfo->pszCurDevice);
  1048. // Free(pInfo->pszCurPort);
  1049. // if (pInfo->pNode)
  1050. // {
  1051. // DestroyEntryNode( pInfo->pNode );
  1052. // }
  1053. // Free router-information
  1054. //
  1055. // Free( pInfo->pszRouter );
  1056. // Free( pInfo->pszRouterUserName );
  1057. // Free( pInfo->pszRouterDomain );
  1058. // if (pInfo->pSharedNode)
  1059. // {
  1060. // DestroyLinkNode( pInfo->pSharedNode );
  1061. // }
  1062. // psz = pInfo->pszRouterPassword;
  1063. // if (psz)
  1064. // {
  1065. // ZeroMemory( psz, lstrlen( psz ) * sizeof(TCHAR) );
  1066. // Free( psz );
  1067. // }
  1068. // psz = pInfo->pszRouterDialInPassword;
  1069. // if (psz)
  1070. // {
  1071. // ZeroMemory( psz, lstrlen( psz ) * sizeof(TCHAR) );
  1072. // Free( psz );
  1073. // }
  1074. // Free credentials stuff
  1075. // Free(pInfo->pszDefUserName);
  1076. // Free(pInfo->pszDefPassword);
  1077. // Free home networking information
  1078. //
  1079. if (pInfo->rgPrivateConns)
  1080. {
  1081. UINT i;
  1082. for (i = 0; i < pInfo->dwLanCount; i++)
  1083. {
  1084. if (pInfo->rgPrivateConns[i])
  1085. {
  1086. pInfo->rgPrivateConns[i]->Release();
  1087. }
  1088. }
  1089. CoTaskMemFree(pInfo->rgPrivateConns);
  1090. }
  1091. if (pInfo->pHNetConn)
  1092. {
  1093. pInfo->pHNetConn->Release();
  1094. }
  1095. if (pInfo->pIcsSettings)
  1096. {
  1097. pInfo->pIcsSettings->Release();
  1098. }
  1099. if (pInfo->pOldSharedConnection)
  1100. {
  1101. pInfo->pOldSharedConnection->Release();
  1102. }
  1103. if (pInfo->pHNetCfgMgr)
  1104. {
  1105. pInfo->pHNetCfgMgr->Release();
  1106. }
  1107. if (pInfo->fComInitialized)
  1108. {
  1109. CoUninitialize();
  1110. }
  1111. Free( pInfo );
  1112. }
  1113. // helper
  1114. HRESULT GetRasEntry (TCHAR * pszPhonebook, TCHAR * pszEntry, RASENTRY ** ppRE)
  1115. {
  1116. *ppRE = NULL;
  1117. DWORD dwSize = 0;
  1118. DWORD dwErr = RasGetEntryProperties (pszPhonebook, pszEntry, NULL, &dwSize, NULL, NULL);
  1119. if (dwErr != ERROR_BUFFER_TOO_SMALL)
  1120. return HRESULT_FROM_WIN32(dwErr);
  1121. _ASSERT (dwSize != 0);
  1122. RASENTRY * pRE = (RASENTRY*)Malloc (dwSize);
  1123. if (!pRE)
  1124. return E_OUTOFMEMORY;
  1125. ZeroMemory (pRE, dwSize);
  1126. pRE->dwSize = sizeof(RASENTRY);
  1127. dwErr = RasGetEntryProperties (pszPhonebook, pszEntry, pRE, &dwSize, NULL, NULL);
  1128. if (dwErr) {
  1129. Free (pRE);
  1130. return HRESULT_FROM_WIN32(dwErr);
  1131. }
  1132. *ppRE = pRE;
  1133. return S_OK;
  1134. }
  1135. // wrapper....
  1136. HRESULT PeInit (GUID * pGuid, PEINFO ** ppEI)
  1137. {
  1138. _ASSERT (pGuid);
  1139. _ASSERT (ppEI);
  1140. *ppEI = (PEINFO *)Malloc (sizeof(PEINFO));
  1141. if (!*ppEI)
  1142. return E_OUTOFMEMORY;
  1143. ZeroMemory (*ppEI, sizeof(PEINFO));
  1144. CComPtr<IHNetConnection> spHNetConn = NULL;
  1145. CComPtr<IHNetCfgMgr> spHNetCfgMgr = NULL;
  1146. HRESULT hr = CoCreateInstance (CLSID_HNetCfgMgr,
  1147. NULL,
  1148. CLSCTX_ALL,
  1149. __uuidof(IHNetCfgMgr), // &IID_IHNetCfgMgr,
  1150. (void**)&spHNetCfgMgr);
  1151. if (SUCCEEDED(hr)) {
  1152. // Convert the entry to an IHNetConnection
  1153. hr = spHNetCfgMgr->GetIHNetConnectionForGuid (
  1154. pGuid, FALSE, TRUE, &spHNetConn);
  1155. }
  1156. if (SUCCEEDED(hr)) {
  1157. // the code below assumes UNICODE....
  1158. TCHAR * pszPhonebook = NULL;
  1159. TCHAR * pszEntry = NULL;
  1160. HRESULT hr = spHNetConn->GetName (&pszEntry);
  1161. if (hr == S_OK)
  1162. hr = spHNetConn->GetRasPhonebookPath (&pszPhonebook);
  1163. if (hr == S_OK) {
  1164. // get RASENTRY dwType and guidId fields for code below
  1165. RASENTRY * pRE = NULL;
  1166. hr = GetRasEntry (pszPhonebook, pszEntry, &pRE);
  1167. if (pRE) {
  1168. DWORD dwOp = 0;
  1169. DWORD dwError = EuInit (pRE,
  1170. pszPhonebook,
  1171. pszEntry,
  1172. NULL, // IN RASENTRYDLG* pArgs,
  1173. FALSE, // IN BOOL fRouter,
  1174. &(*ppEI)->pArgs,
  1175. &dwOp);
  1176. if (dwError != 0) {
  1177. _ASSERT (dwOp != 0);
  1178. _ASSERT (!*ppEI);
  1179. if (HRESULT_SEVERITY(dwError))
  1180. hr = dwError;
  1181. else
  1182. hr = HRESULT_FROM_WIN32 (dwError);
  1183. } else {
  1184. _ASSERT (dwOp == 0);
  1185. _ASSERT (*ppEI);
  1186. }
  1187. Free (pRE);
  1188. }
  1189. }
  1190. if (pszPhonebook) CoTaskMemFree (pszPhonebook);
  1191. if (pszEntry) CoTaskMemFree (pszEntry);
  1192. }
  1193. return hr;
  1194. }
  1195. DWORD
  1196. EuInit(
  1197. IN RASENTRY * pRE,
  1198. IN TCHAR* pszPhonebook,
  1199. IN TCHAR* pszEntry,
  1200. IN RASENTRYDLG* pArgs,
  1201. IN BOOL fRouter,
  1202. OUT EINFO** ppInfo,
  1203. OUT DWORD* pdwOp )
  1204. // Allocates '*ppInfo' data for use by the property sheet or wizard.
  1205. // 'PszPhonebook', 'pszEntry', and 'pArgs', are the arguments passed by
  1206. // user to the API. 'FRouter' is set if running in "router mode", clear
  1207. // for the normal "dial-out" mode. '*pdwOp' is set to the operation code
  1208. // associated with any error.
  1209. //
  1210. // Returns 0 if successful, or an error code. If non-null '*ppInfo' is
  1211. // returned caller must eventually call EuFree to release the returned
  1212. // block.
  1213. //
  1214. {
  1215. DWORD dwErr;
  1216. EINFO* pInfo;
  1217. // INTERNALARGS* piargs;
  1218. *ppInfo = NULL;
  1219. *pdwOp = 0;
  1220. pInfo = (EINFO*)Malloc( sizeof(EINFO) );
  1221. if (!pInfo)
  1222. {
  1223. return ERROR_NOT_ENOUGH_MEMORY;
  1224. }
  1225. ZeroMemory( pInfo, sizeof(*pInfo ) );
  1226. /*
  1227. bhanlon: I'm filling out what used to be a PBENTRY with a
  1228. BILLSPBENTRY struct. This needs to be freed....
  1229. */
  1230. pInfo->pEntry = (BILLSPBENTRY *)Malloc (sizeof(BILLSPBENTRY));
  1231. if (!pInfo->pEntry) {
  1232. Free (pInfo);
  1233. return ERROR_NOT_ENOUGH_MEMORY;
  1234. }
  1235. _tcsncpy (pInfo->pEntry->pszEntryName, pszEntry, RAS_MaxEntryName);
  1236. _tcsncpy (pInfo->pEntry->pszPhonebookPath, pszPhonebook, MAX_PATH);
  1237. pInfo->pEntry->pGuid = &pInfo->pEntry->guidId;
  1238. pInfo->pEntry->dwfExcludedProtocols = 0;
  1239. pInfo->pEntry->dwType = pRE->dwType;
  1240. pInfo->pEntry->guidId = pRE->guidId;
  1241. *ppInfo = pInfo;
  1242. pInfo->pszPhonebook = pszPhonebook;
  1243. pInfo->pszEntry = pszEntry;
  1244. // pInfo->pApiArgs = pArgs;
  1245. pInfo->fRouter = fRouter;
  1246. // piargs = (INTERNALARGS *)pArgs->reserved;
  1247. // if (pInfo->fRouter)
  1248. // {
  1249. // LPTSTR pszRouter;
  1250. // DWORD dwVersion;
  1251. // ASSERT(piargs);
  1252. // pszRouter = RemoteGetServerName(piargs->hConnection);
  1253. // pmay: 348623
  1254. //
  1255. // Note that RemoteGetServerName is guarenteed to return
  1256. // NULL for local box, non-NULL for remote
  1257. //
  1258. // pInfo->fRemote = !!pszRouter;
  1259. // if(NULL == pszRouter)
  1260. // {
  1261. // pszRouter = TEXT("");
  1262. // }
  1263. // pInfo->pszRouter = StrDupTFromW(pszRouter);
  1264. // Find out if we're focused on an nt4 router
  1265. // pInfo->fNt4Router = FALSE;
  1266. // IsNt40Machine( pszRouter, &(pInfo->fNt4Router) );
  1267. // dwVersion = ((RAS_RPC *)(piargs->hConnection))->dwVersion;
  1268. // pInfo->fNt4Router = !!(VERSION_40 == dwVersion );
  1269. //Find out if the remote server is a win2k machine
  1270. //
  1271. // pInfo->fW2kRouter = !!(VERSION_50 == dwVersion );
  1272. // }
  1273. // Load the user preferences, or figure out that caller has already loaded
  1274. // them.
  1275. //
  1276. // if (piargs && !piargs->fInvalid)
  1277. // {
  1278. // // We've received user preferences and the "no user" status via the
  1279. // // secret hack.
  1280. // //
  1281. // pInfo->pUser = piargs->pUser;
  1282. // pInfo->fNoUser = piargs->fNoUser;
  1283. // pInfo->pFile = piargs->pFile;
  1284. // pInfo->fDisableFirstConnect = piargs->fDisableFirstConnect;
  1285. // }
  1286. // else
  1287. // {
  1288. // DWORD dwReadPbkFlags = 0;
  1289. // // Read user preferences from registry.
  1290. // //
  1291. // dwErr = g_pGetUserPreferences(
  1292. // (piargs) ? piargs->hConnection : NULL,
  1293. // &pInfo->user,
  1294. // (pInfo->fRouter) ? UPM_Router : UPM_Normal );
  1295. // if (dwErr != 0)
  1296. // {
  1297. // *pdwOp = SID_OP_LoadPrefs;
  1298. // return dwErr;
  1299. // }
  1300. // pInfo->pUser = &pInfo->user;
  1301. // if(pInfo->fRouter)
  1302. // {
  1303. // pInfo->file.hConnection = piargs->hConnection;
  1304. // dwReadPbkFlags |= RPBF_Router;
  1305. // }
  1306. // if(pInfo->fNoUser)
  1307. // {
  1308. // dwReadPbkFlags |= RPBF_NoUser;
  1309. // }
  1310. // Load and parse the phonebook file.
  1311. //
  1312. // dwErr = ReadPhonebookFile(
  1313. // pInfo->pszPhonebook, &pInfo->user, NULL,
  1314. // dwReadPbkFlags,
  1315. // &pInfo->file );
  1316. // if (dwErr != 0)
  1317. // {
  1318. // *pdwOp = SID_OP_LoadPhonebook;
  1319. // return dwErr;
  1320. // }
  1321. // pInfo->pFile = &pInfo->file;
  1322. // }
  1323. // Determine if strong encryption is supported. Export laws prevent it in
  1324. // some versions of the system.
  1325. //
  1326. {
  1327. // ULONG ulCaps;
  1328. // RAS_NDISWAN_DRIVER_INFO info;
  1329. //
  1330. // ZeroMemory( &info, sizeof(info) );
  1331. // ASSERT( g_pRasGetNdiswanDriverCaps );
  1332. // dwErr = g_pRasGetNdiswanDriverCaps(
  1333. // (piargs) ? piargs->hConnection : NULL, &info );
  1334. // if (dwErr == 0)
  1335. // {
  1336. // pInfo->fStrongEncryption =
  1337. // !!(info.DriverCaps & RAS_NDISWAN_128BIT_ENABLED);
  1338. // }
  1339. // else
  1340. {
  1341. pInfo->fStrongEncryption = FALSE;
  1342. }
  1343. }
  1344. // Load the list of ports.
  1345. //
  1346. // dwErr = LoadPortsList2(
  1347. // (piargs) ? piargs->hConnection : NULL,
  1348. // &pInfo->pListPorts,
  1349. // pInfo->fRouter );
  1350. // if (dwErr != 0)
  1351. // {
  1352. // TRACE1( "LoadPortsList=%d", dwErr );
  1353. // *pdwOp = SID_OP_RetrievingData;
  1354. // return dwErr;
  1355. // }
  1356. // Set up work entry node.
  1357. //
  1358. // if (pInfo->pApiArgs->dwFlags & RASEDFLAG_AnyNewEntry)
  1359. // {
  1360. // DTLNODE* pNodeL;
  1361. // DTLNODE* pNodeP;
  1362. // PBLINK* pLink;
  1363. // PBPORT* pPort;
  1364. // // New entry mode, so 'pNode' set to default settings.
  1365. // //
  1366. // pInfo->pNode = CreateEntryNode( TRUE );
  1367. // if (!pInfo->pNode)
  1368. // {
  1369. // TRACE( "CreateEntryNode failed" );
  1370. // *pdwOp = SID_OP_RetrievingData;
  1371. // return dwErr;
  1372. // }
  1373. // // Store entry within work node stored in context for convenience
  1374. // // elsewhere.
  1375. // //
  1376. // pInfo->pEntry = (PBENTRY* )DtlGetData( pInfo->pNode );
  1377. // ASSERT( pInfo->pEntry );
  1378. // if (pInfo->fRouter)
  1379. // {
  1380. // Set router specific defaults.
  1381. //
  1382. // pInfo->pEntry->dwIpNameSource = ASRC_None;
  1383. // pInfo->pEntry->dwRedialAttempts = 0;
  1384. // Since this is a new entry, setup a proposed entry name.
  1385. // This covers the case when the wizard is not used to
  1386. // create the entry and the property sheet has no way to enter
  1387. // the name.
  1388. // ASSERT( !pInfo->pEntry->pszEntryName );
  1389. // GetDefaultEntryName( pInfo->pFile,
  1390. // RASET_Phone,
  1391. // pInfo->fRouter,
  1392. // &pInfo->pEntry->pszEntryName );
  1393. // Disable MS client and File and Print services by default
  1394. //
  1395. // EnableOrDisableNetComponent( pInfo->pEntry, TEXT("ms_msclient"),
  1396. // FALSE);
  1397. // EnableOrDisableNetComponent( pInfo->pEntry, TEXT("ms_server"),
  1398. // FALSE);
  1399. // }
  1400. // Use caller's default name, if any.
  1401. //
  1402. // if (pInfo->pszEntry)
  1403. // {
  1404. // pInfo->pEntry->pszEntryName = StrDup( pInfo->pszEntry );
  1405. // }
  1406. // Set the default entry type to "phone", i.e. modems, ISDN, X.26 etc.
  1407. // This may be changed to "VPN" or "direct" by the new entry wizard
  1408. // after the initial wizard page.
  1409. //
  1410. // EuChangeEntryType( pInfo, RASET_Phone );
  1411. // }
  1412. // else
  1413. // {
  1414. // DTLNODE* pNode;
  1415. // Edit or clone entry mode, so 'pNode' set to entry's current
  1416. // settings.
  1417. //
  1418. // pInfo->pOldNode = EntryNodeFromName(
  1419. // pInfo->pFile->pdtllistEntries, pInfo->pszEntry );
  1420. // if ( !pInfo->pOldNode
  1421. // && !pInfo->fRouter)
  1422. // {
  1423. // if(NULL == pInfo->pszPhonebook)
  1424. // {
  1425. //
  1426. // Close the phonebook file we opened above.
  1427. // we will try to find the entry name in the
  1428. // per user phonebook file.
  1429. //
  1430. // ClosePhonebookFile(&pInfo->file);
  1431. // pInfo->pFile = NULL;
  1432. //
  1433. // Attempt to find the file in users profile
  1434. //
  1435. // dwErr = GetPbkAndEntryName(
  1436. // NULL,
  1437. // pInfo->pszEntry,
  1438. // 0,
  1439. // &pInfo->file,
  1440. // &pInfo->pOldNode);
  1441. // if(ERROR_SUCCESS != dwErr)
  1442. // {
  1443. // *pdwOp = SID_OP_RetrievingData;
  1444. // return ERROR_CANNOT_FIND_PHONEBOOK_ENTRY;
  1445. // }
  1446. // pInfo->pFile = &pInfo->file;
  1447. // }
  1448. // else
  1449. // {
  1450. // *pdwOp = SID_OP_RetrievingData;
  1451. // return ERROR_CANNOT_FIND_PHONEBOOK_ENTRY;
  1452. // }
  1453. // }
  1454. // if(NULL != pInfo->pOldNode)
  1455. // {
  1456. // PBENTRY *pEntry = (PBENTRY *) DtlGetData(pInfo->pOldNode);
  1457. // Before cloning or editing make sure that for dial up
  1458. // connections, share File And Print is disabled.
  1459. //
  1460. // if( ((RASET_Phone == pEntry->dwType)
  1461. // || (RASET_Broadband == pEntry->dwType))
  1462. // && (!pEntry->fShareMsFilePrint))
  1463. // {
  1464. // EnableOrDisableNetComponent( pEntry, TEXT("ms_server"),
  1465. // FALSE);
  1466. // }
  1467. // }
  1468. // if(NULL != pInfo->pOldNode)
  1469. // {
  1470. // if (pInfo->pApiArgs->dwFlags & RASEDFLAG_CloneEntry)
  1471. // {
  1472. // pInfo->pNode = CloneEntryNode( pInfo->pOldNode );
  1473. // }
  1474. // else
  1475. // {
  1476. // pInfo->pNode = DuplicateEntryNode( pInfo->pOldNode );
  1477. // }
  1478. // }
  1479. // if (!pInfo->pNode)
  1480. // {
  1481. // TRACE( "DuplicateEntryNode failed" );
  1482. // *pdwOp = SID_OP_RetrievingData;
  1483. // return ERROR_NOT_ENOUGH_MEMORY;
  1484. // }
  1485. // Store entry within work node stored in context for convenience
  1486. // elsewhere.
  1487. //
  1488. // pInfo->pEntry = (PBENTRY* )DtlGetData( pInfo->pNode );
  1489. // Save original entry name for comparison later.
  1490. //
  1491. // lstrcpyn(
  1492. // pInfo->szOldEntryName,
  1493. // pInfo->pEntry->pszEntryName,
  1494. // RAS_MaxEntryName + 1);
  1495. // For router, want unconfigured ports to show up as "unavailable" so
  1496. // they stand out to user who has been directed to change them.
  1497. //
  1498. // if (pInfo->fRouter)
  1499. // {
  1500. // DTLNODE* pNodeL;
  1501. // PBLINK* pLink;
  1502. // pNodeL = DtlGetFirstNode( pInfo->pEntry->pdtllistLinks );
  1503. // pLink = (PBLINK* )DtlGetData( pNodeL );
  1504. // if (!pLink->pbport.fConfigured)
  1505. // {
  1506. // Free( pLink->pbport.pszDevice );
  1507. // pLink->pbport.pszDevice = NULL;
  1508. // }
  1509. // }
  1510. // pmay: 277801
  1511. //
  1512. // Remember the "current" device if this entry was last saved
  1513. // as single link.
  1514. //
  1515. // if (DtlGetNodes(pInfo->pEntry->pdtllistLinks) == 1)
  1516. // {
  1517. // DTLNODE* pNodeL;
  1518. // PBLINK* pLink;
  1519. // pNodeL = DtlGetFirstNode( pInfo->pEntry->pdtllistLinks );
  1520. // pLink = (PBLINK* )DtlGetData( pNodeL );
  1521. // if (pLink->pbport.pszDevice && pLink->pbport.pszPort)
  1522. // {
  1523. // pInfo->pszCurDevice =
  1524. // StrDup(pLink->pbport.pszDevice);
  1525. // pInfo->pszCurPort =
  1526. // StrDup(pLink->pbport.pszPort);
  1527. // }
  1528. // }
  1529. // Append all non-configured ports of the entries type to the list of
  1530. // links. This is for the convenience of the UI. The non-configured
  1531. // ports are removed after editing prior to saving.
  1532. //
  1533. // AppendDisabledPorts( pInfo, pInfo->pEntry->dwType );
  1534. // }
  1535. // Set up the phone number storage for shared phone number mode.
  1536. // Initialize it to a copy of the information from the first link which at
  1537. // startup will always be enabled. Note the Dial case with non-0
  1538. // dwSubEntry is an exception, but in that case the pSharedNode anyway.
  1539. //
  1540. // {
  1541. // DTLNODE* pNode;
  1542. // pInfo->pSharedNode = CreateLinkNode();
  1543. // if (!pInfo->pSharedNode)
  1544. // {
  1545. // *pdwOp = SID_OP_RetrievingData;
  1546. // return ERROR_NOT_ENOUGH_MEMORY;
  1547. // }
  1548. // ASSERT( pInfo->pSharedNode );
  1549. // pNode = DtlGetFirstNode( pInfo->pEntry->pdtllistLinks );
  1550. // ASSERT( pNode );
  1551. // CopyLinkPhoneNumberInfo( pInfo->pSharedNode, pNode );
  1552. // }
  1553. // Load the current shared-access (and firewall) settings
  1554. //
  1555. if (!pInfo->fRouter)
  1556. {
  1557. HRESULT hr;
  1558. HNET_CONN_PROPERTIES *pProps;
  1559. // Make sure COM is initialized on this thread.
  1560. //
  1561. hr = CoInitializeEx(
  1562. NULL,
  1563. COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE
  1564. );
  1565. if (SUCCEEDED(hr))
  1566. {
  1567. pInfo->fComInitialized = TRUE;
  1568. }
  1569. else if (RPC_E_CHANGED_MODE == hr)
  1570. {
  1571. hr = S_OK;
  1572. }
  1573. if (SUCCEEDED(hr))
  1574. {
  1575. // Create the home networking configuration manager
  1576. //
  1577. hr = CoCreateInstance(
  1578. CLSID_HNetCfgMgr,
  1579. NULL,
  1580. CLSCTX_ALL,
  1581. __uuidof(IHNetCfgMgr),
  1582. (void**)&pInfo->pHNetCfgMgr);
  1583. }
  1584. if (SUCCEEDED(hr))
  1585. {
  1586. // Get the IHNetIcsSettings interface
  1587. //
  1588. hr = pInfo->pHNetCfgMgr->QueryInterface(
  1589. __uuidof(IHNetIcsSettings), (void**)&pInfo->pIcsSettings);
  1590. }
  1591. if (SUCCEEDED(hr))
  1592. {
  1593. // Convert the entry to an IHNetConnection
  1594. //
  1595. hr = pInfo->pHNetCfgMgr->GetIHNetConnectionForGuid(
  1596. pInfo->pEntry->pGuid, FALSE, TRUE,
  1597. &pInfo->pHNetConn);
  1598. }
  1599. if (SUCCEEDED(hr))
  1600. {
  1601. // Determine whether this entry is already shared;
  1602. // skip the check for new entries.
  1603. //
  1604. if (pInfo->pEntry->pszEntryName)
  1605. {
  1606. hr = pInfo->pHNetConn->GetProperties (&pProps);
  1607. if (SUCCEEDED(hr))
  1608. {
  1609. pInfo->fShared = pProps->fIcsPublic;
  1610. pInfo->fFirewalled = pProps->fFirewalled;
  1611. CoTaskMemFree(pProps);
  1612. }
  1613. }
  1614. else
  1615. {
  1616. pInfo->fShared = FALSE;
  1617. pInfo->fFirewalled = FALSE;
  1618. }
  1619. pInfo->fNewShared = pInfo->fShared;
  1620. pInfo->fNewFirewalled = pInfo->fFirewalled;
  1621. }
  1622. if (SUCCEEDED(hr))
  1623. {
  1624. // Obtain an array of possible ICS private connections
  1625. //
  1626. hr = pInfo->pIcsSettings->GetPossiblePrivateConnections(
  1627. pInfo->pHNetConn,
  1628. &pInfo->dwLanCount,
  1629. &pInfo->rgPrivateConns,
  1630. &pInfo->lxCurrentPrivate
  1631. );
  1632. RasQuerySharedAutoDial(&pInfo->fDemandDial);
  1633. pInfo->fNewDemandDial = pInfo->fDemandDial;
  1634. pInfo->fResetPrivateAdapter =
  1635. pInfo->fShared && -1 == pInfo->lxCurrentPrivate;
  1636. }
  1637. pInfo->hShowHNetPagesResult = hr;
  1638. if(SUCCEEDED(hr))
  1639. {
  1640. pInfo->fShowHNetPages = TRUE;
  1641. }
  1642. }
  1643. // if (pInfo->fRouter)
  1644. // {
  1645. // pInfo->pEntry->dwfExcludedProtocols |= NP_Nbf;
  1646. // }
  1647. // AboladeG - capture the security level of the current user.
  1648. //
  1649. pInfo->fIsUserAdminOrPowerUser = FIsUserAdminOrPowerUser();
  1650. return 0;
  1651. }
  1652. BOOL
  1653. FIsUserAdminOrPowerUser()
  1654. {
  1655. SID_IDENTIFIER_AUTHORITY SidAuth = SECURITY_NT_AUTHORITY;
  1656. PSID psid;
  1657. BOOL fIsMember = FALSE;
  1658. BOOL fRet = FALSE;
  1659. SID sidLocalSystem = { 1, 1,
  1660. SECURITY_NT_AUTHORITY,
  1661. SECURITY_LOCAL_SYSTEM_RID };
  1662. // Check to see if running under local system first
  1663. //
  1664. if (!CheckTokenMembership( NULL, &sidLocalSystem, &fIsMember ))
  1665. {
  1666. TRACE( "CheckTokenMemberShip for local system failed.");
  1667. fIsMember = FALSE;
  1668. }
  1669. fRet = fIsMember;
  1670. if (!fIsMember)
  1671. {
  1672. // Allocate a SID for the Administrators group and check to see
  1673. // if the user is a member.
  1674. //
  1675. if (AllocateAndInitializeSid( &SidAuth, 2,
  1676. SECURITY_BUILTIN_DOMAIN_RID,
  1677. DOMAIN_ALIAS_RID_ADMINS,
  1678. 0, 0, 0, 0, 0, 0,
  1679. &psid ))
  1680. {
  1681. if (!CheckTokenMembership( NULL, psid, &fIsMember ))
  1682. {
  1683. TRACE( "CheckTokenMemberShip for admins failed.");
  1684. fIsMember = FALSE;
  1685. }
  1686. FreeSid( psid );
  1687. // Changes to the Windows 2000 permission model mean that regular Users
  1688. // on workstations are in the power user group. So we no longer want to
  1689. // check for power user.
  1690. #if 0
  1691. if (!fIsMember)
  1692. {
  1693. // They're not a member of the Administrators group so allocate a
  1694. // SID for the Power Users group and check to see
  1695. // if the user is a member.
  1696. //
  1697. if (AllocateAndInitializeSid( &SidAuth, 2,
  1698. SECURITY_BUILTIN_DOMAIN_RID,
  1699. DOMAIN_ALIAS_RID_POWER_USERS,
  1700. 0, 0, 0, 0, 0, 0,
  1701. &psid ))
  1702. {
  1703. if (!CheckTokenMembership( NULL, psid, &fIsMember ))
  1704. {
  1705. TRACE( "CheckTokenMemberShip for power users failed.");
  1706. fIsMember = FALSE;
  1707. }
  1708. FreeSid( psid );
  1709. }
  1710. }
  1711. #endif
  1712. }
  1713. fRet = fIsMember;
  1714. }
  1715. return fRet;
  1716. }
  1717. BOOL PeApply (IN HWND hwndPage)
  1718. {
  1719. // Saves the contents of the property sheet. 'HwndPage is the handle of a
  1720. // property page. Pops up any errors that occur.
  1721. //
  1722. // Returns true is page can be dismissed, false otherwise.
  1723. //
  1724. DWORD dwErr;
  1725. PEINFO* pInfo;
  1726. BILLSPBENTRY* pEntry;
  1727. TRACE( "PeApply" );
  1728. pInfo = PeContext( hwndPage );
  1729. ASSERT( pInfo );
  1730. if (pInfo == NULL)
  1731. {
  1732. return ERROR_CAN_NOT_COMPLETE;
  1733. }
  1734. pEntry = pInfo->pArgs->pEntry;
  1735. ASSERT( pEntry );
  1736. // Save General page fields.
  1737. //
  1738. // ASSERT( pInfo->hwndGe );
  1739. // {
  1740. // DTLNODE* pNode;
  1741. // Retrieve the lone common control.
  1742. //
  1743. // pEntry->fShowMonitorIconInTaskBar =
  1744. // Button_GetCheck( pInfo->hwndCbShowIcon );
  1745. // if (pEntry->dwType == RASET_Phone)
  1746. // {
  1747. // DWORD dwCount;
  1748. // dwCount = GeSaveLvDeviceChecks( pInfo );
  1749. // Don't allow the user to deselect all of the
  1750. // devices
  1751. // if ( (pInfo->pArgs->fMultipleDevices) && (dwCount == 0) )
  1752. // {
  1753. // MsgDlg( hwndPage, SID_SelectDevice, NULL );
  1754. // PropSheet_SetCurSel ( pInfo->hwndDlg, pInfo->hwndGe, 0 );
  1755. // SetFocus ( pInfo->hwndLvDevices );
  1756. // return FALSE;
  1757. // }
  1758. // Save the "shared phone number" setting. As usual, single
  1759. // device mode implies shared mode, allowing things to fall
  1760. // through correctly.
  1761. //
  1762. // if (pInfo->pArgs->fMultipleDevices)
  1763. // {
  1764. // pEntry->fSharedPhoneNumbers =
  1765. // Button_GetCheck( pInfo->hwndCbSharedPhoneNumbers );
  1766. // }
  1767. // else
  1768. // {
  1769. // pEntry->fSharedPhoneNumbers = TRUE;
  1770. // }
  1771. // Set the phone number set for the first phone number of the
  1772. // current link (shared or selected) to the contents of the phone
  1773. // number controls.
  1774. //
  1775. // GeGetPhoneFields( pInfo, pInfo->pCurLinkNode );
  1776. // Swap lists, saving updates to caller's global list of area
  1777. // codes. Caller's original list will be destroyed by PeTerm.
  1778. //
  1779. // if (pInfo->pListAreaCodes)
  1780. // {
  1781. // DtlSwapLists(
  1782. // pInfo->pArgs->pUser->pdtllistAreaCodes,
  1783. // pInfo->pListAreaCodes );
  1784. // pInfo->pArgs->pUser->fDirty = TRUE;
  1785. // }
  1786. // }
  1787. // else if (pEntry->dwType == RASET_Vpn)
  1788. // {
  1789. // DTLNODE* pNode;
  1790. // PBLINK* pLink;
  1791. // PBPHONE* pPhone;
  1792. // Save host name, i.e. the VPN phone number.
  1793. //
  1794. // pNode = DtlGetFirstNode( pEntry->pdtllistLinks );
  1795. // ASSERT( pNode );
  1796. // pLink = (PBLINK* )DtlGetData( pNode );
  1797. // pNode = FirstPhoneNodeFromPhoneList( pLink->pdtllistPhones );
  1798. // if(NULL == pNode)
  1799. // {
  1800. // return FALSE;
  1801. // }
  1802. // pPhone = (PBPHONE* )DtlGetData( pNode );
  1803. // Free0( pPhone->pszPhoneNumber );
  1804. // pPhone->pszPhoneNumber = GetText( pInfo->hwndEbHostName );
  1805. // FirstPhoneNodeToPhoneList( pLink->pdtllistPhones, pNode );
  1806. // Any prequisite entry selection change has been saved already.
  1807. // Just need to toss it if disabled.
  1808. //
  1809. // if (!Button_GetCheck( pInfo->hwndCbDialAnotherFirst ))
  1810. // {
  1811. // Free0( pEntry->pszPrerequisiteEntry );
  1812. // pEntry->pszPrerequisiteEntry = NULL;
  1813. // Free0( pEntry->pszPrerequisitePbk );
  1814. // pEntry->pszPrerequisitePbk = NULL;
  1815. // }
  1816. // }
  1817. // else if (pEntry->dwType == RASET_Broadband)
  1818. // {
  1819. // DTLNODE* pNode;
  1820. // PBLINK* pLink;
  1821. // PBPHONE* pPhone;
  1822. // Save service name, i.e. the broadband phone number.
  1823. //
  1824. // pNode = DtlGetFirstNode( pEntry->pdtllistLinks );
  1825. // ASSERT( pNode );
  1826. // pLink = (PBLINK* )DtlGetData( pNode );
  1827. // pNode = FirstPhoneNodeFromPhoneList( pLink->pdtllistPhones );
  1828. // if(NULL == pNode)
  1829. // {
  1830. // return FALSE;
  1831. // }
  1832. // pPhone = (PBPHONE* )DtlGetData( pNode );
  1833. // Free0( pPhone->pszPhoneNumber );
  1834. // pPhone->pszPhoneNumber = GetText( pInfo->hwndEbBroadbandService );
  1835. // FirstPhoneNodeToPhoneList( pLink->pdtllistPhones, pNode );
  1836. // }
  1837. // else if (pEntry->dwType == RASET_Direct)
  1838. // {
  1839. // DTLNODE* pNode;
  1840. // PBLINK* pLink;
  1841. // The currently enabled device is the one
  1842. // that should be used for the connection. Only
  1843. // one device will be enabled (DnUpdateSelectedDevice).
  1844. // for (pNode = DtlGetFirstNode( pEntry->pdtllistLinks );
  1845. // pNode;
  1846. // pNode = DtlGetNextNode( pNode ))
  1847. // {
  1848. // pLink = (PBLINK* )DtlGetData( pNode );
  1849. // ASSERT(pLink);
  1850. // if ( pLink->fEnabled )
  1851. // break;
  1852. // }
  1853. // If we found a link successfully, deal with it
  1854. // now.
  1855. // if ( pLink && pLink->fEnabled ) {
  1856. // if (pLink->pbport.pbdevicetype == PBDT_ComPort)
  1857. // MdmInstallNullModem (pLink->pbport.pszPort);
  1858. // }
  1859. // }
  1860. // }
  1861. // Save Options page fields.
  1862. //
  1863. // if (pInfo->hwndOe)
  1864. // {
  1865. // UINT unValue;
  1866. // BOOL f;
  1867. // INT iSel;
  1868. // pEntry->fShowDialingProgress =
  1869. // Button_GetCheck( pInfo->hwndCbDisplayProgress );
  1870. // Note: The'fPreviewUserPw', 'fPreviewDomain' fields are updated as
  1871. // they are changed.
  1872. // pEntry->fPreviewPhoneNumber =
  1873. // Button_GetCheck( pInfo->hwndCbPreviewNumber );
  1874. // unValue = GetDlgItemInt(
  1875. // pInfo->hwndOe, CID_OE_EB_RedialAttempts, &f, FALSE );
  1876. // if (f && unValue <= 999999999)
  1877. // {
  1878. // pEntry->dwRedialAttempts = unValue;
  1879. // }
  1880. // iSel = ComboBox_GetCurSel( pInfo->hwndLbRedialTimes );
  1881. // pEntry->dwRedialSeconds =
  1882. // (DWORD )ComboBox_GetItemData( pInfo->hwndLbRedialTimes, iSel );
  1883. // iSel = ComboBox_GetCurSel( pInfo->hwndLbIdleTimes );
  1884. // pEntry->lIdleDisconnectSeconds =
  1885. // (LONG )ComboBox_GetItemData( pInfo->hwndLbIdleTimes, iSel );
  1886. // if (pInfo->pArgs->fRouter)
  1887. // {
  1888. // pEntry->fRedialOnLinkFailure =
  1889. // Button_GetCheck( pInfo->hwndRbPersistent );
  1890. // }
  1891. // else
  1892. // {
  1893. // pEntry->fRedialOnLinkFailure =
  1894. // Button_GetCheck( pInfo->hwndCbRedialOnDrop );
  1895. // }
  1896. // Note: dwDialMode is saved as changed.
  1897. // Note: X.25 settings are saved at OK on that dialog.
  1898. // }
  1899. // Save Security page fields.
  1900. //
  1901. // if (pInfo->hwndLo)
  1902. // {
  1903. // if (Button_GetCheck( pInfo->hwndRbTypicalSecurity ))
  1904. // {
  1905. // LoSaveTypicalAuthSettings( pInfo );
  1906. // if (pEntry->dwTypicalAuth == TA_CardOrCert)
  1907. // {
  1908. /*
  1909. // Toss any existing advanced EAP configuration remnants when
  1910. // typical smartcard, per bug 262702 and VBaliga email.
  1911. //
  1912. Free0( pEntry->pCustomAuthData );
  1913. pEntry->pCustomAuthData = NULL;
  1914. pEntry->cbCustomAuthData = 0;
  1915. */
  1916. // (void) DwSetCustomAuthData(
  1917. // pEntry,
  1918. // 0,
  1919. // NULL);
  1920. // TRACE( "RasSetEapUserData" );
  1921. // ASSERT( g_pRasGetEntryDialParams );
  1922. // g_pRasSetEapUserData(
  1923. // INVALID_HANDLE_VALUE,
  1924. // pInfo->pArgs->pFile->pszPath,
  1925. // pEntry->pszEntryName,
  1926. // NULL,
  1927. // 0 );
  1928. // TRACE( "RasSetEapUserData done" );
  1929. // }
  1930. // }
  1931. // if (pEntry->dwType == RASET_Phone)
  1932. // {
  1933. // Free0( pEntry->pszScriptAfter );
  1934. // SuGetInfo( &pInfo->suinfo,
  1935. // &pEntry->fScriptAfter,
  1936. // &pEntry->fScriptAfterTerminal,
  1937. // &pEntry->pszScriptAfter );
  1938. // }
  1939. // }
  1940. // Save Network page fields.
  1941. // We won't have anything to do if we never initialized pNetCfg.
  1942. //
  1943. // if (pInfo->pNetCfg)
  1944. // {
  1945. // HRESULT hr;
  1946. // Update the phone book entry with the enabled state of the components.
  1947. // Do this by enumerating the components from the list view item data
  1948. // and consulting the check state for each.
  1949. //
  1950. // NeSaveBindingChanges(pInfo);
  1951. // hr = INetCfg_Apply (pInfo->pNetCfg);
  1952. // if (((NETCFG_S_REBOOT == hr) || (pInfo->fRebootAlreadyRequested)) &&
  1953. // pInfo->pNetConUtilities)
  1954. // {
  1955. // DWORD dwFlags = QUFR_REBOOT;
  1956. // if (!pInfo->fRebootAlreadyRequested)
  1957. // dwFlags |= QUFR_PROMPT;
  1958. //$TODO NULL caption?
  1959. // INetConnectionUiUtilities_QueryUserForReboot (
  1960. // pInfo->pNetConUtilities, pInfo->hwndDlg, NULL, dwFlags);
  1961. // }
  1962. // }
  1963. // Save Shared Access page fields
  1964. //
  1965. if (pInfo->hwndSa)
  1966. {
  1967. // record the (new) sharing and demand-dial settings
  1968. //
  1969. pInfo->pArgs->fNewShared =
  1970. Button_GetCheck( pInfo->hwndSaPbShared );
  1971. pInfo->pArgs->fNewDemandDial =
  1972. Button_GetCheck( pInfo->hwndSaPbDemandDial );
  1973. pInfo->pArgs->fNewBeaconControl =
  1974. Button_GetCheck( GetDlgItem(pInfo->hwndSa, CID_SA_PB_Beacon) );
  1975. // we only look at the private-lan drop list
  1976. // if the user just turned on sharing, since that's the only time
  1977. // we display the drop-list to begin with. we also need to look if
  1978. // we need to reset the private adapter
  1979. //
  1980. if ((pInfo->pArgs->fNewShared && !pInfo->pArgs->fShared)
  1981. || pInfo->pArgs->fResetPrivateAdapter)
  1982. {
  1983. if (pInfo->pArgs->dwLanCount > 1)
  1984. {
  1985. INT item = ComboBox_GetCurSel( pInfo->hwndSaLbPrivateLan );
  1986. if (item != CB_ERR)
  1987. {
  1988. pInfo->pArgs->pPrivateLanConnection =
  1989. (IHNetConnection*)ComboBox_GetItemData(
  1990. pInfo->hwndSaLbPrivateLan, item );
  1991. }
  1992. }
  1993. else if (pInfo->pArgs->dwLanCount)
  1994. {
  1995. ASSERT(pInfo->pArgs->rgPrivateConns);
  1996. pInfo->pArgs->pPrivateLanConnection =
  1997. pInfo->pArgs->rgPrivateConns[0];
  1998. }
  1999. }
  2000. // Save Firewall fields
  2001. //
  2002. pInfo->pArgs->fNewFirewalled =
  2003. Button_GetCheck( pInfo->hwndSaPbFirewalled );
  2004. }
  2005. #if 0 //!!!
  2006. if ((fLocalPad || iPadSelection != 0)
  2007. && (!pEntry->pszX25Address || IsAllWhite( pEntry->pszX25Address )))
  2008. {
  2009. // Address field is blank with X.25 dial-up or local PAD chosen.
  2010. //
  2011. MsgDlg( pInfo->hwndDlg, SID_NoX25Address, NULL );
  2012. PropSheet_SetCurSel( pInfo->hwndDlg, NULL, PE_XsPage );
  2013. SetFocus( pInfo->hwndEbX25Address );
  2014. Edit_SetSel( pInfo->hwndEbX25Address, 0, -1 );
  2015. return FALSE;
  2016. }
  2017. #endif
  2018. // Make sure proprietary ISDN options are disabled if more than one link
  2019. // is enabled. The proprietary ISDN option is only meaningful when
  2020. // calling a down-level server that needs Digiboard channel aggragation
  2021. // instead of PPP multi-link.
  2022. //
  2023. // {
  2024. // DTLNODE* pNode;
  2025. // DWORD cIsdnLinks;
  2026. // cIsdnLinks = 0;
  2027. // for (pNode = DtlGetFirstNode( pEntry->pdtllistLinks );
  2028. // pNode;
  2029. // pNode = DtlGetNextNode( pNode ))
  2030. // {
  2031. // PBLINK* pLink = (PBLINK* )DtlGetData( pNode );
  2032. // ASSERT(pLink);
  2033. // if (pLink->fEnabled && pLink->pbport.pbdevicetype == PBDT_Isdn)
  2034. // {
  2035. // ++cIsdnLinks;
  2036. // }
  2037. // }
  2038. // if (cIsdnLinks > 1)
  2039. // {
  2040. // for (pNode = DtlGetFirstNode( pEntry->pdtllistLinks );
  2041. // pNode;
  2042. // pNode = DtlGetNextNode( pNode ))
  2043. // {
  2044. // PBLINK* pLink = (PBLINK* )DtlGetData( pNode );
  2045. // ASSERT(pLink);
  2046. // if (pLink->fEnabled && pLink->fProprietaryIsdn)
  2047. // {
  2048. // pLink->fProprietaryIsdn = FALSE;
  2049. // }
  2050. // }
  2051. // }
  2052. // }
  2053. // Inform user that edits to the connected entry won't take affect until
  2054. // the entry is hung up and re-dialed, per PierreS's insistence.
  2055. //
  2056. // if (HrasconnFromEntry( pInfo->pArgs->pFile->pszPath, pEntry->pszEntryName ))
  2057. // {
  2058. // MsgDlg( pInfo->hwndDlg, SID_EditConnected, NULL );
  2059. // }
  2060. // It's a valid new/changed entry. Commit the changes to the phonebook
  2061. // and preferences. This occurs immediately in "ShellOwned" mode where
  2062. // the RasEntryDlg API has already returned, but is otherwise deferred
  2063. // until the API is ready to return.
  2064. //
  2065. // if (pInfo->pArgs->pApiArgs->dwFlags & RASEDFLAG_ShellOwned)
  2066. // {
  2067. EuCommit( pInfo->pArgs );
  2068. // }
  2069. // else
  2070. // {
  2071. // pInfo->pArgs->fCommit = TRUE;
  2072. // }
  2073. return TRUE;
  2074. }
  2075. BOOL EuCommit(IN EINFO* pInfo )
  2076. {
  2077. // Commits the new or changed entry node to the phonebook file and list.
  2078. // Also adds the area code to the per-user list, if indicated. 'PInfo' is
  2079. // the common entry information block.
  2080. //
  2081. // Returns true if successful, false otherwise.
  2082. //
  2083. DWORD dwErr;
  2084. // BOOL fEditMode;
  2085. // BOOL fChangedNameInEditMode;
  2086. // If shared phone number, copy the phone number information from the
  2087. // shared link to each enabled link.
  2088. //
  2089. // if (pInfo->pEntry->fSharedPhoneNumbers)
  2090. // {
  2091. // DTLNODE* pNode;
  2092. // ASSERT( pInfo->pEntry->dwType == RASET_Phone );
  2093. // for (pNode = DtlGetFirstNode( pInfo->pEntry->pdtllistLinks );
  2094. // pNode;
  2095. // pNode = DtlGetNextNode( pNode ))
  2096. // {
  2097. // PBLINK* pLink = (PBLINK* )DtlGetData( pNode );
  2098. // ASSERT(pLink);
  2099. // if (pLink->fEnabled)
  2100. // {
  2101. // CopyLinkPhoneNumberInfo( pNode, pInfo->pSharedNode );
  2102. // }
  2103. // }
  2104. // }
  2105. // Delete all disabled link nodes.
  2106. //
  2107. // if (pInfo->fMultipleDevices)
  2108. // {
  2109. // DTLNODE* pNode;
  2110. // pNode = DtlGetFirstNode( pInfo->pEntry->pdtllistLinks );
  2111. // while (pNode)
  2112. // {
  2113. // PBLINK* pLink = (PBLINK* )DtlGetData( pNode );
  2114. // DTLNODE* pNextNode = DtlGetNextNode( pNode );
  2115. // if (!pLink->fEnabled)
  2116. // {
  2117. // DtlRemoveNode( pInfo->pEntry->pdtllistLinks, pNode );
  2118. // DestroyLinkNode( pNode );
  2119. // }
  2120. // pNode = pNextNode;
  2121. // }
  2122. // }
  2123. // pmay: 277801
  2124. //
  2125. // Update the preferred device if the one selected is different
  2126. // from the device this page was initialized with.
  2127. //
  2128. // if ((pInfo->fMultipleDevices) &&
  2129. // (DtlGetNodes(pInfo->pEntry->pdtllistLinks) == 1))
  2130. // {
  2131. // DTLNODE* pNodeL;
  2132. // PBLINK* pLink;
  2133. // BOOL bUpdatePref = FALSE;
  2134. // pNodeL = DtlGetFirstNode( pInfo->pEntry->pdtllistLinks );
  2135. // pLink = (PBLINK*) DtlGetData( pNodeL );
  2136. // TRACE( "Mult devs, only one selected -- check preferred dev." );
  2137. // if ((pInfo->pszCurDevice == NULL) || (pInfo->pszCurPort == NULL))
  2138. // {
  2139. // TRACE( "No preferred device. Resetting preferred to current." );
  2140. // bUpdatePref = TRUE;
  2141. // }
  2142. // else if (
  2143. // (lstrcmpi(pInfo->pszCurDevice, pLink->pbport.pszDevice)) ||
  2144. // (lstrcmpi(pInfo->pszCurPort, pLink->pbport.pszPort)))
  2145. // {
  2146. // TRACE( "New device selected as preferred device" );
  2147. // bUpdatePref = TRUE;
  2148. // }
  2149. // if (bUpdatePref)
  2150. // {
  2151. // Free0(pInfo->pEntry->pszPreferredDevice);
  2152. // Free0(pInfo->pEntry->pszPreferredPort);
  2153. // pInfo->pEntry->pszPreferredDevice =
  2154. // StrDup(pLink->pbport.pszDevice);
  2155. // pInfo->pEntry->pszPreferredPort =
  2156. // StrDup(pLink->pbport.pszPort);
  2157. // }
  2158. // }
  2159. // Save preferences if they've changed.
  2160. //
  2161. // if (pInfo->pUser->fDirty)
  2162. // {
  2163. // INTERNALARGS *pIArgs = (INTERNALARGS *)pInfo->pApiArgs->reserved;
  2164. // if (g_pSetUserPreferences(
  2165. // (pIArgs) ? pIArgs->hConnection : NULL,
  2166. // pInfo->pUser,
  2167. // (pInfo->fRouter) ? UPM_Router : UPM_Normal ) != 0)
  2168. // {
  2169. // return FALSE;
  2170. // }
  2171. // }
  2172. // Save the changed phonebook entry.
  2173. //
  2174. // pInfo->pEntry->fDirty = TRUE;
  2175. // The final name of the entry is output to caller via API structure.
  2176. //
  2177. // lstrcpyn(
  2178. // pInfo->pApiArgs->szEntry,
  2179. // pInfo->pEntry->pszEntryName,
  2180. // RAS_MaxEntryName + 1);
  2181. // Delete the old node if in edit mode, then add the new node.
  2182. //
  2183. // EuGetEditFlags( pInfo, &fEditMode, &fChangedNameInEditMode );
  2184. // if (fEditMode)
  2185. // {
  2186. // DtlDeleteNode( pInfo->pFile->pdtllistEntries, pInfo->pOldNode );
  2187. // }
  2188. // DtlAddNodeLast( pInfo->pFile->pdtllistEntries, pInfo->pNode );
  2189. // pInfo->pNode = NULL;
  2190. // Write the change to the phone book file.
  2191. //
  2192. // dwErr = WritePhonebookFile( pInfo->pFile,
  2193. // (fChangedNameInEditMode) ? pInfo->szOldEntryName : NULL );
  2194. // if (dwErr != 0)
  2195. // {
  2196. // ErrorDlg( pInfo->pApiArgs->hwndOwner, SID_OP_WritePhonebook, dwErr,
  2197. // NULL );
  2198. // // shaunco - fix RAID 171651 by assigning dwErr to callers structure.
  2199. // pInfo->pApiArgs->dwError = dwErr;
  2200. // return FALSE;
  2201. // }
  2202. // Notify through rasman that the entry has changed
  2203. //
  2204. // if(pInfo->pApiArgs->dwFlags & (RASEDFLAG_AnyNewEntry | RASEDFLAG_CloneEntry))
  2205. // {
  2206. // dwErr = DwSendRasNotification(
  2207. // ENTRY_ADDED,
  2208. // pInfo->pEntry,
  2209. // pInfo->pFile->pszPath);
  2210. // }
  2211. // else
  2212. // {
  2213. // dwErr = DwSendRasNotification(
  2214. // ENTRY_MODIFIED,
  2215. // pInfo->pEntry,
  2216. // pInfo->pFile->pszPath);
  2217. // }
  2218. // Ignore the error returned from DwSendRasNotification - we don't want
  2219. // to fail the operation in this case. The worst case scenario is that
  2220. // the connections folder won't refresh automatically.
  2221. //
  2222. // dwErr = ERROR_SUCCESS;
  2223. // If EuCommit is being called as a result of completing the "new demand
  2224. // dial interface" wizard, then we need to create the new demand dial
  2225. // interface now.
  2226. //
  2227. // if ( EuRouterInterfaceIsNew( pInfo ) )
  2228. // {
  2229. //Create Router MPR interface and save user credentials
  2230. //like UserName, Domain and Password
  2231. //IPSec credentials are save in EuCredentialsCommitRouterIPSec
  2232. //
  2233. // dwErr = EuRouterInterfaceCreate( pInfo );
  2234. // If we weren't successful at commiting the interface's
  2235. // credentials, then delete the new phonebook entry.
  2236. //
  2237. // if ( dwErr != NO_ERROR )
  2238. // {
  2239. // WritePhonebookFile( pInfo->pFile, pInfo->pApiArgs->szEntry );
  2240. // pInfo->pApiArgs->dwError = dwErr;
  2241. // return FALSE;
  2242. // }
  2243. // }
  2244. // Now save any per-connection credentials
  2245. //
  2246. // dwErr = EuCredentialsCommit( pInfo );
  2247. // If we weren't successful at commiting the interface's
  2248. // credentials, then delete the new phonebook entry.
  2249. //
  2250. // if ( dwErr != NO_ERROR )
  2251. // {
  2252. // ErrorDlg( pInfo->pApiArgs->hwndOwner,
  2253. // SID_OP_CredCommit,
  2254. // dwErr,
  2255. // NULL );
  2256. // pInfo->pApiArgs->dwError = dwErr;
  2257. // return FALSE;
  2258. // }
  2259. // Save the default Internet connection settings as appropriate. Igonre
  2260. // the error returned as failure to set the connection as default need
  2261. // not prevent the connection/interface creation.
  2262. //
  2263. // dwErr = EuInternetSettingsCommitDefault( pInfo );
  2264. // dwErr = NO_ERROR;
  2265. // If the user edited/created a router-phonebook entry, store the bitmask
  2266. // of selected network-protocols in 'reserved2'.
  2267. //
  2268. // if (pInfo->fRouter)
  2269. // {
  2270. // pInfo->pApiArgs->reserved2 =
  2271. // ((NP_Ip | NP_Ipx) & ~pInfo->pEntry->dwfExcludedProtocols);
  2272. // }
  2273. // Commit the user's changes to home networking settings.
  2274. // Ignore the return value.
  2275. //
  2276. dwErr = EuHomenetCommitSettings(pInfo);
  2277. dwErr = NO_ERROR;
  2278. // pInfo->pApiArgs->dwError = 0;
  2279. return TRUE;
  2280. }
  2281. DWORD EuHomenetCommitSettings(IN EINFO* pInfo)
  2282. {
  2283. HRESULT hr = S_OK;
  2284. ULONG ulcPublic;
  2285. ULONG ulcPrivate;
  2286. BOOL fPrivateConfigured = FALSE;
  2287. HNET_CONN_PROPERTIES *pProps;
  2288. DWORD dwErr = NO_ERROR;
  2289. if (pInfo->fRouter)
  2290. {
  2291. return NO_ERROR;
  2292. }
  2293. if (!!pInfo->fShared != !!pInfo->fNewShared)
  2294. {
  2295. if (pInfo->fShared)
  2296. {
  2297. hr = pInfo->pIcsSettings->DisableIcs (&ulcPublic, &ulcPrivate);
  2298. }
  2299. else
  2300. {
  2301. // Check to see if the private connection is
  2302. // already properly configured
  2303. //
  2304. hr = pInfo->pPrivateLanConnection->GetProperties (&pProps);
  2305. if (SUCCEEDED(hr))
  2306. {
  2307. fPrivateConfigured = !!pProps->fIcsPrivate;
  2308. CoTaskMemFree(pProps);
  2309. }
  2310. if (pInfo->fOtherShared)
  2311. {
  2312. if (fPrivateConfigured)
  2313. {
  2314. // Using the same private connection, so
  2315. // only modify the old public
  2316. //
  2317. ASSERT(NULL != pInfo->pOldSharedConnection);
  2318. hr = pInfo->pOldSharedConnection->Unshare();
  2319. }
  2320. else
  2321. {
  2322. hr = pInfo->pIcsSettings->DisableIcs (&ulcPublic, &ulcPrivate);
  2323. }
  2324. }
  2325. if (SUCCEEDED(hr))
  2326. {
  2327. IHNetIcsPublicConnection *pIcsPublic;
  2328. IHNetIcsPrivateConnection *pIcsPrivate;
  2329. hr = pInfo->pHNetConn->SharePublic (&pIcsPublic);
  2330. if (SUCCEEDED(hr))
  2331. {
  2332. if (!fPrivateConfigured)
  2333. {
  2334. hr = pInfo->pPrivateLanConnection->SharePrivate (&pIcsPrivate);
  2335. if (SUCCEEDED(hr))
  2336. {
  2337. pIcsPrivate->Release();
  2338. }
  2339. else
  2340. {
  2341. pIcsPublic->Unshare();
  2342. }
  2343. }
  2344. pIcsPublic->Release();
  2345. }
  2346. }
  2347. if (hr == HRESULT_FROM_WIN32(ERROR_SHARING_RRAS_CONFLICT))
  2348. {
  2349. MsgDlg(pInfo->hwndOwner, SID_SharingConflict, NULL);
  2350. }
  2351. else if (FAILED(hr))
  2352. {
  2353. if (FACILITY_WIN32 == HRESULT_FACILITY(hr))
  2354. {
  2355. dwErr = HRESULT_CODE(hr);
  2356. }
  2357. else
  2358. {
  2359. dwErr = (DWORD) hr;
  2360. }
  2361. ErrorDlg(
  2362. pInfo->hwndOwner,
  2363. pInfo->fShared
  2364. ? SID_OP_UnshareConnection : SID_OP_ShareConnection,
  2365. dwErr, NULL );
  2366. }
  2367. }
  2368. }
  2369. else if (pInfo->fResetPrivateAdapter && pInfo->dwLanCount)
  2370. {
  2371. IHNetIcsPrivateConnection *pIcsPrivateConnection;
  2372. hr = pInfo->pPrivateLanConnection->SharePrivate(&pIcsPrivateConnection);
  2373. if (SUCCEEDED(hr))
  2374. {
  2375. pIcsPrivateConnection->Release();
  2376. }
  2377. else
  2378. {
  2379. ULONG ulPublicCount, ulPrivateCount;
  2380. HRESULT hr2 = pInfo->pIcsSettings->DisableIcs(&ulPublicCount, &ulPrivateCount);
  2381. if (SUCCEEDED(hr2))
  2382. {
  2383. pInfo->fShared = FALSE;
  2384. }
  2385. ErrorDlg(pInfo->hwndOwner, SID_OP_ShareConnection, hr, NULL );
  2386. }
  2387. }
  2388. if (!!pInfo->fDemandDial != !!pInfo->fNewDemandDial)
  2389. {
  2390. dwErr = RasSetSharedAutoDial(pInfo->fNewDemandDial);
  2391. if (dwErr)
  2392. {
  2393. ErrorDlg(
  2394. pInfo->hwndOwner,
  2395. pInfo->fDemandDial
  2396. ? SID_OP_DisableDemandDial : SID_OP_EnableDemandDial,
  2397. dwErr, NULL );
  2398. }
  2399. }
  2400. HKEY hKey;
  2401. if(ERROR_SUCCESS == RegCreateKeyEx(HKEY_LOCAL_MACHINE, REGKEY_SHAREDACCESSCLIENTKEYPATH, 0, NULL, 0, KEY_SET_VALUE, NULL, &hKey, NULL))
  2402. {
  2403. DWORD dwData = pInfo->fNewBeaconControl;
  2404. RegSetValueEx(hKey, REGVAL_SHAREDACCESSCLIENTENABLECONTROL, 0, REG_DWORD, reinterpret_cast<LPBYTE>(&dwData), sizeof(dwData));
  2405. RegCloseKey(hKey);
  2406. }
  2407. // Commit changes to firewall settings
  2408. //
  2409. if (!!pInfo->fFirewalled != !!pInfo->fNewFirewalled)
  2410. {
  2411. IHNetFirewalledConnection *pFwConn;
  2412. if (pInfo->fNewFirewalled)
  2413. {
  2414. hr = pInfo->pHNetConn->Firewall (&pFwConn);
  2415. if (SUCCEEDED(hr))
  2416. {
  2417. pFwConn->Release();
  2418. }
  2419. }
  2420. else
  2421. {
  2422. hr = pInfo->pHNetConn->GetControlInterface (
  2423. IID_IHNetFirewalledConnection,
  2424. (void**)&pFwConn);
  2425. if (SUCCEEDED(hr))
  2426. {
  2427. hr = pFwConn->Unfirewall();
  2428. pFwConn->Release();
  2429. }
  2430. }
  2431. if (FAILED(hr))
  2432. {
  2433. if (FACILITY_WIN32 == HRESULT_FACILITY(hr))
  2434. {
  2435. dwErr = HRESULT_CODE(hr);
  2436. }
  2437. else
  2438. {
  2439. dwErr = (DWORD) hr;
  2440. }
  2441. ErrorDlg(
  2442. pInfo->hwndOwner,
  2443. pInfo->fFirewalled
  2444. ? SID_OP_UnshareConnection : SID_OP_ShareConnection,
  2445. dwErr, NULL );
  2446. }
  2447. }
  2448. return dwErr;
  2449. }
  2450. HRESULT APIENTRY
  2451. HrCreateNetConnectionUtilities(INetConnectionUiUtilities ** ppncuu)
  2452. {
  2453. HRESULT hr;
  2454. hr = CoCreateInstance (CLSID_NetConnectionUiUtilities, NULL,
  2455. CLSCTX_INPROC_SERVER,
  2456. IID_INetConnectionUiUtilities, (void**)ppncuu);
  2457. return hr;
  2458. }
  2459. // --------------------------------------------------------------------------
  2460. // exported function here
  2461. // --------------------------------------------------------------------------
  2462. static LPDLGTEMPLATE CopyDialogTemplate (HINSTANCE hinst, LPCWSTR wszResource)
  2463. {
  2464. LPDLGTEMPLATE lpdtCopy = NULL;
  2465. HRSRC hrsrc = FindResourceW (hinst, wszResource, (LPCWSTR)RT_DIALOG);
  2466. if (hrsrc) {
  2467. HGLOBAL hg = LoadResource (hinst, hrsrc);
  2468. if (hg) {
  2469. LPDLGTEMPLATE lpdt = (LPDLGTEMPLATE) LockResource (hg);
  2470. if (lpdt) {
  2471. DWORD dwSize = SizeofResource (hinst, hrsrc);
  2472. if (dwSize) {
  2473. lpdtCopy = (LPDLGTEMPLATE)Malloc (dwSize);
  2474. if (lpdtCopy) {
  2475. CopyMemory (lpdtCopy, lpdt, dwSize);
  2476. }
  2477. }
  2478. }
  2479. }
  2480. }
  2481. return lpdtCopy;
  2482. }
  2483. void SetSAUIhInstance (HINSTANCE hInstance)
  2484. {
  2485. _ASSERT (g_hinstDll == NULL);
  2486. _ASSERT (hInstance != NULL);
  2487. g_hinstDll = hInstance;
  2488. }
  2489. extern "C" HRESULT HNetGetFirewallSettingsPage (PROPSHEETPAGEW * pPSP, GUID * pGuid)
  2490. {
  2491. // zeroth thing: the PROPSHEETPAGEW struct is different sizes depending
  2492. // on what version of _WIN32_IE and _WIN32_WINNT are set to. So, check
  2493. // the dwSize field
  2494. if (IsBadWritePtr (pPSP, sizeof(DWORD)))
  2495. return E_POINTER;
  2496. if (IsBadWritePtr (pPSP, pPSP->dwSize))
  2497. return HRESULT_FROM_WIN32 (ERROR_INVALID_SIZE);
  2498. if (pPSP->dwSize < RTL_SIZEOF_THROUGH_FIELD (PROPSHEETPAGEW, lParam))
  2499. return HRESULT_FROM_WIN32 (ERROR_INVALID_SIZE);
  2500. // first thing: check rights
  2501. if (FALSE == FIsUserAdminOrPowerUser ())
  2502. return HRESULT_FROM_WIN32 (ERROR_ACCESS_DENIED);
  2503. {
  2504. // Check if ZAW is denying access to the Shared Access UI
  2505. BOOL fShowAdvancedUi = TRUE;
  2506. INetConnectionUiUtilities* pncuu = NULL;
  2507. HrCreateNetConnectionUtilities(&pncuu);
  2508. if (pncuu)
  2509. {
  2510. if ((FALSE == pncuu->UserHasPermission (NCPERM_ShowSharedAccessUi)) &&
  2511. (FALSE == pncuu->UserHasPermission (NCPERM_PersonalFirewallConfig)))
  2512. fShowAdvancedUi = FALSE;
  2513. pncuu->Release();
  2514. }
  2515. if (FALSE == fShowAdvancedUi)
  2516. return HRESULT_FROM_WIN32 (ERROR_ACCESS_DENIED);
  2517. }
  2518. // setup global(s)
  2519. g_contextId = (LPCTSTR)GlobalAddAtom (TEXT("SAUI"));
  2520. if (!g_contextId)
  2521. return GetLastError();
  2522. PEINFO * pPEINFO = NULL;
  2523. DWORD dwError = PeInit (pGuid, &pPEINFO);
  2524. if (dwError == S_OK) {
  2525. // we need this to init the link
  2526. LinkWindow_RegisterClass(); // no need to ever unregister: see ...\shell\shell32\linkwnd.cpp
  2527. // fill out PSP:
  2528. DWORD dwSize;
  2529. ZeroMemory (pPSP, dwSize = pPSP->dwSize);
  2530. pPSP->dwSize = dwSize;
  2531. pPSP->dwFlags = 0;
  2532. LPDLGTEMPLATE lpdt = CopyDialogTemplate (g_hinstDll, MAKEINTRESOURCE (PID_SA_Advanced));
  2533. if (lpdt) {
  2534. // avoid idd collisions
  2535. pPSP->dwFlags |= PSP_DLGINDIRECT;
  2536. pPSP->pResource = lpdt;
  2537. pPEINFO->lpdt = lpdt; // hang it here so I can free it
  2538. } else // if all else fails... (this should never happen).
  2539. pPSP->pszTemplate = MAKEINTRESOURCE (PID_SA_Advanced);
  2540. pPSP->hInstance = g_hinstDll;
  2541. pPSP->pfnDlgProc = SaDlgProc;
  2542. pPSP->lParam = (LPARAM)pPEINFO;
  2543. }
  2544. return dwError;
  2545. }
  2546. //
  2547. // Figure out if this is a single user connection. If it is, then we need
  2548. // to give them an error that explains that they should be using an all user
  2549. // connection instead.
  2550. // If this is an All-User connection, warn them if they don't have global credentials
  2551. //
  2552. VOID VerifyConnTypeAndCreds(IN PEINFO* pInfo)
  2553. {
  2554. if (NULL == pInfo)
  2555. {
  2556. return;
  2557. }
  2558. BOOL fAllUser = FALSE;
  2559. TCHAR szAppData[MAX_PATH+1]={0};
  2560. HINSTANCE hinstDll = LoadLibrary (TEXT("shfolder.dll"));;
  2561. if (hinstDll)
  2562. {
  2563. typedef HRESULT (*pfnGetFolderPathFunction) (HWND, int, HANDLE, DWORD, LPTSTR);
  2564. #ifdef UNICODE
  2565. pfnGetFolderPathFunction pfnGetFolderPath = (pfnGetFolderPathFunction)GetProcAddress (hinstDll, "SHGetFolderPathW");
  2566. #else
  2567. pfnGetFolderPathFunction pfnGetFolderPath = (pfnGetFolderPathFunction)GetProcAddress (hinstDll, "SHGetFolderPathA");
  2568. #endif
  2569. if (pfnGetFolderPath && pInfo->pArgs->pEntry->pszEntryName)
  2570. {
  2571. HRESULT hr = pfnGetFolderPath(pInfo->hwndDlg , CSIDL_COMMON_APPDATA, NULL, 0, szAppData);
  2572. if (SUCCEEDED(hr) && (S_FALSE != hr))
  2573. {
  2574. //
  2575. // Okay, now we have the path to the common application data directory.
  2576. // Let's compare that against the phonebook path that we have and see
  2577. // if this is an all user connection or not.
  2578. //
  2579. const TCHAR* const c_pszRelativePbkPath = TEXT("\\Microsoft\\Network\\Connections\\Pbk");
  2580. DWORD dwSize = (lstrlen(szAppData) + lstrlen(c_pszRelativePbkPath) + 1) * sizeof(TCHAR);
  2581. LPTSTR pszAllUserPhoneBookDir = (LPTSTR)Malloc(dwSize);
  2582. if (pszAllUserPhoneBookDir)
  2583. {
  2584. wsprintf(pszAllUserPhoneBookDir, TEXT("%s%s"), szAppData, c_pszRelativePbkPath);
  2585. //
  2586. // Compare
  2587. //
  2588. if (pInfo->pArgs->pEntry->pszPhonebookPath)
  2589. {
  2590. LPTSTR pszAllUser = _tcsstr(pInfo->pArgs->pEntry->pszPhonebookPath, pszAllUserPhoneBookDir);
  2591. if (pszAllUser)
  2592. {
  2593. fAllUser = TRUE;
  2594. }
  2595. else
  2596. {
  2597. //
  2598. // If the phonebook path wasn't based on the common app data dir, check to see
  2599. // if it was based on the old ras phonebook location %windir%\system32\ras.
  2600. //
  2601. HRESULT hr2 = pfnGetFolderPath(pInfo->hwndDlg , CSIDL_SYSTEM, NULL, 0, szAppData);
  2602. if (SUCCEEDED(hr2) && (S_FALSE != hr2))
  2603. {
  2604. const TCHAR* const c_pszRas = TEXT("\\Ras");
  2605. DWORD dwSize2 = (lstrlen(szAppData) + lstrlen(c_pszRas) + 1) * sizeof(TCHAR);
  2606. LPTSTR pszOldRasPhoneBook = (LPTSTR)Malloc(dwSize2);
  2607. if (pszOldRasPhoneBook)
  2608. {
  2609. wsprintf(pszOldRasPhoneBook, TEXT("%s%s"), szAppData, c_pszRas);
  2610. LPTSTR pszAllUser = _tcsstr(pInfo->pArgs->pEntry->pszPhonebookPath, pszOldRasPhoneBook);
  2611. if (pszAllUser)
  2612. {
  2613. fAllUser = TRUE;
  2614. }
  2615. }
  2616. Free0(pszOldRasPhoneBook);
  2617. }
  2618. }
  2619. }
  2620. else
  2621. {
  2622. //
  2623. // Phone book string is null - using default RAS phonebook which is for all users
  2624. //
  2625. fAllUser = TRUE;
  2626. }
  2627. //
  2628. // Finally check if we have the proper credentials for an all user profile. If not then
  2629. // prompt user to create and save global credentials (option A).
  2630. // or display a message that an all-user profile is needed (option B)
  2631. //
  2632. if (fAllUser)
  2633. {
  2634. //
  2635. // Check if we have global passwords
  2636. //
  2637. BOOL fUserCreds = FALSE;
  2638. BOOL fGlobalCreds = FALSE;
  2639. FindEntryCredentials(pInfo->pArgs->pEntry->pszPhonebookPath,
  2640. pInfo->pArgs->pEntry->pszEntryName,
  2641. &fUserCreds,
  2642. &fGlobalCreds);
  2643. if (FALSE == fGlobalCreds)
  2644. {
  2645. //
  2646. // need to display warning message (A) - should have global creds
  2647. //
  2648. MSGARGS msgargs;
  2649. ZeroMemory( &msgargs, sizeof(msgargs) );
  2650. msgargs.dwFlags = MB_OK | MB_ICONINFORMATION;
  2651. MsgDlg( pInfo->hwndDlg, IDS_ALL_USER_CONN_MUST_HAVE_GLOBAL_CREDS, &msgargs );
  2652. }
  2653. }
  2654. else
  2655. {
  2656. //
  2657. // need to display warning message (B) - should create an all-user connection
  2658. //
  2659. MSGARGS msgargs;
  2660. ZeroMemory( &msgargs, sizeof(msgargs) );
  2661. msgargs.dwFlags = MB_OK | MB_ICONINFORMATION;
  2662. MsgDlg( pInfo->hwndDlg, IDS_PER_USER_CONN_NEED_TO_CREATE_ALL_USER_CONN, &msgargs );
  2663. }
  2664. }
  2665. Free0(pszAllUserPhoneBookDir);
  2666. }
  2667. }
  2668. FreeLibrary(hinstDll);
  2669. }
  2670. }
  2671. //
  2672. // All of this function is taken from RAS - rasdlg - dial.c
  2673. // with some parts removed since we didn't need them here.
  2674. //
  2675. DWORD
  2676. FindEntryCredentials(
  2677. IN TCHAR* pszPath,
  2678. IN TCHAR* pszEntryName,
  2679. OUT BOOL* pfUser, // set true if per user creds found
  2680. OUT BOOL* pfGlobal // set true if global creds found
  2681. )
  2682. // Loads the credentials for the given entry into memory. This routine
  2683. // determines whether per-user or per-connection credentials exist or
  2684. // both.
  2685. //
  2686. // The logic is a little complicated because RasGetCredentials had to
  2687. // support legacy usage of the API.
  2688. //
  2689. // Here's how it works. If only one set of credentials is stored for a
  2690. // connection, then RasGetCredentials will return that set regardless of
  2691. // whether the RASCM_DefalutCreds flag is set. If two sets of credentials
  2692. // are saved, then RasGetCredentials will return the per-user credentials
  2693. // if the RASCM_DefaultCreds bit is set, and the per-connection credentials
  2694. // otherwise.
  2695. //
  2696. // Here is the algorithm for loading the credentials
  2697. //
  2698. // 1. Call RasGetCredentials with the RASCM_DefaultCreds bit cleared
  2699. // 1a. If nothing is returned, no credentials are saved
  2700. // 1b. If the RASCM_DefaultCreds bit is set on return, then only
  2701. // global credentials are saved.
  2702. //
  2703. // 2. Call RasGetCredentials with the RASCM_DefaultCreds bit set
  2704. // 2a. If the RASCM_DefaultCreds bit is set on return, then
  2705. // both global and per-connection credentials are saved.
  2706. // 2b. Otherwise, only per-user credentials are saved.
  2707. //
  2708. {
  2709. DWORD dwErr;
  2710. RASCREDENTIALS rc1, rc2;
  2711. BOOL fUseLogonDomain;
  2712. TRACE( "saui.cpp - FindEntryCredentials" );
  2713. // Initialize
  2714. //
  2715. *pfUser = FALSE;
  2716. *pfGlobal = FALSE;
  2717. ZeroMemory( &rc1, sizeof(rc1) );
  2718. ZeroMemory( &rc2, sizeof(rc2) );
  2719. rc1.dwSize = sizeof(rc1);
  2720. rc2.dwSize = sizeof(rc2);
  2721. if (NULL == pszPath || NULL == pszEntryName)
  2722. {
  2723. return (DWORD)-1;
  2724. }
  2725. do
  2726. {
  2727. // Look up per-user cached username, password, and domain.
  2728. // See comment '1.' in the function header
  2729. //
  2730. rc1.dwMask = RASCM_UserName | RASCM_Password | RASCM_Domain;
  2731. TRACE( "RasGetCredentials per-user" );
  2732. dwErr = RasGetCredentials(pszPath, pszEntryName, &rc1 );
  2733. TRACE2( "RasGetCredentials=%d,m=%d", dwErr, rc1.dwMask );
  2734. if (dwErr != NO_ERROR)
  2735. {
  2736. break;
  2737. }
  2738. // See 1a. in the function header comments
  2739. //
  2740. if (rc1.dwMask == 0)
  2741. {
  2742. dwErr = NO_ERROR;
  2743. break;
  2744. }
  2745. // See 1b. in the function header comments
  2746. //
  2747. else if (rc1.dwMask & RASCM_DefaultCreds)
  2748. {
  2749. *pfGlobal = TRUE;
  2750. dwErr = NO_ERROR;
  2751. break;
  2752. }
  2753. // Look up global per-user cached username, password, domain.
  2754. // See comment 2. in the function header
  2755. //
  2756. rc2.dwMask =
  2757. RASCM_UserName | RASCM_Password | RASCM_Domain | RASCM_DefaultCreds;
  2758. TRACE( "RasGetCredentials global" );
  2759. dwErr = RasGetCredentials(pszPath, pszEntryName, &rc2 );
  2760. TRACE2( "RasGetCredentials=%d,m=%d", dwErr, rc2.dwMask );
  2761. if (dwErr != NO_ERROR)
  2762. {
  2763. break;
  2764. }
  2765. // See 2a. in the function header comments
  2766. //
  2767. if (rc2.dwMask & RASCM_DefaultCreds)
  2768. {
  2769. *pfGlobal = TRUE;
  2770. if (rc1.dwMask & RASCM_Password)
  2771. {
  2772. *pfUser = TRUE;
  2773. }
  2774. }
  2775. // See 2b. in the function header comments
  2776. //
  2777. else
  2778. {
  2779. if (rc1.dwMask & RASCM_Password)
  2780. {
  2781. *pfUser = TRUE;
  2782. }
  2783. }
  2784. }while (FALSE);
  2785. // Cleanup
  2786. //
  2787. ZeroMemory( rc1.szPassword, sizeof(rc1.szPassword) );
  2788. ZeroMemory( rc2.szPassword, sizeof(rc2.szPassword) );
  2789. return dwErr;
  2790. }