Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3242 lines
105 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. //
  906. // Making sure that Beacon checkbox is enabled only for
  907. // Pro and Per Types of the OS.
  908. //
  909. VER_SET_CONDITION(ConditionMask, VER_PRODUCT_TYPE, VER_EQUAL);
  910. if ( 0 == VerifyVersionInfo(&verInfo, VER_PRODUCT_TYPE, ConditionMask) &&
  911. ERROR_OLD_WIN_VERSION == GetLastError() )
  912. {
  913. ShowWindow(GetDlgItem(hwndPage, CID_SA_PB_Beacon), SW_HIDE);
  914. }
  915. return TRUE;
  916. }
  917. INT_PTR CALLBACK
  918. SaDisableFirewallWarningDlgProc(
  919. IN HWND hwnd,
  920. IN UINT unMsg,
  921. IN WPARAM wparam,
  922. IN LPARAM lparam )
  923. {
  924. switch(unMsg)
  925. {
  926. case WM_COMMAND:
  927. {
  928. switch(LOWORD(wparam))
  929. {
  930. case IDYES:
  931. case IDNO:
  932. if(BST_CHECKED == IsDlgButtonChecked(hwnd, CID_SA_PB_DisableFirewallWarning))
  933. {
  934. HKEY hFirewallKey;
  935. if(ERROR_SUCCESS == RegCreateKeyEx(HKEY_CURRENT_USER, g_pszFirewallRegKey, 0, NULL, 0, KEY_SET_VALUE, NULL, &hFirewallKey, NULL))
  936. {
  937. DWORD dwValue = TRUE;
  938. RegSetValueEx(hFirewallKey, g_pszDisableFirewallWarningValue, 0, REG_DWORD, (CONST BYTE*)&dwValue, sizeof(dwValue));
  939. RegCloseKey(hFirewallKey);
  940. }
  941. }
  942. // fallthru
  943. case IDCANCEL:
  944. EndDialog(hwnd, LOWORD(wparam));
  945. break;
  946. }
  947. break;
  948. }
  949. }
  950. return FALSE;
  951. }
  952. BOOL SaIsAdapterDHCPEnabled(IHNetConnection* pConnection)
  953. {
  954. HRESULT hr;
  955. BOOL fDHCP = FALSE;
  956. GUID* pAdapterGuid;
  957. hr = pConnection->GetGuid (&pAdapterGuid);
  958. if(SUCCEEDED(hr))
  959. {
  960. LPOLESTR pAdapterName;
  961. hr = StringFromCLSID(*pAdapterGuid, &pAdapterName);
  962. if(SUCCEEDED(hr))
  963. {
  964. SIZE_T Length = wcslen(pAdapterName);
  965. LPSTR pszAnsiAdapterName = (LPSTR)Malloc(Length + 1);
  966. if(NULL != pszAnsiAdapterName)
  967. {
  968. if(0 != WideCharToMultiByte(CP_ACP, 0, pAdapterName, (int)(Length + 1), pszAnsiAdapterName, (int)(Length + 1), NULL, NULL))
  969. {
  970. HMODULE hIpHelper;
  971. hIpHelper = LoadLibrary(L"iphlpapi");
  972. if(NULL != hIpHelper)
  973. {
  974. DWORD (WINAPI *pGetAdaptersInfo)(PIP_ADAPTER_INFO, PULONG);
  975. pGetAdaptersInfo = (DWORD (WINAPI*)(PIP_ADAPTER_INFO, PULONG)) GetProcAddress(hIpHelper, "GetAdaptersInfo");
  976. if(NULL != pGetAdaptersInfo)
  977. {
  978. ULONG ulSize = 0;
  979. if(ERROR_BUFFER_OVERFLOW == pGetAdaptersInfo(NULL, &ulSize))
  980. {
  981. PIP_ADAPTER_INFO pInfo = (PIP_ADAPTER_INFO)Malloc(ulSize);
  982. if(NULL != pInfo)
  983. {
  984. if(ERROR_SUCCESS == pGetAdaptersInfo(pInfo, &ulSize))
  985. {
  986. PIP_ADAPTER_INFO pAdapterInfo = pInfo;
  987. do
  988. {
  989. if(0 == lstrcmpA(pszAnsiAdapterName, pAdapterInfo->AdapterName))
  990. {
  991. fDHCP = !!pAdapterInfo->DhcpEnabled;
  992. break;
  993. }
  994. } while(NULL != (pAdapterInfo = pAdapterInfo->Next));
  995. }
  996. Free(pInfo);
  997. }
  998. }
  999. }
  1000. FreeLibrary(hIpHelper);
  1001. }
  1002. }
  1003. Free(pszAnsiAdapterName);
  1004. }
  1005. CoTaskMemFree(pAdapterName);
  1006. }
  1007. CoTaskMemFree(pAdapterGuid);
  1008. }
  1009. return fDHCP;
  1010. }
  1011. PEINFO* PeContext (IN HWND hwndPage)
  1012. {
  1013. // Retrieve the property sheet context from a property page handle.
  1014. //
  1015. // return (PEINFO* )GetProp( GetParent( hwndPage ), g_contextId );
  1016. // now hanging our stuff off our window (since it's not shared)
  1017. return (PEINFO* )GetProp( hwndPage, g_contextId );
  1018. }
  1019. void PeTerm (PEINFO * pEI)
  1020. {
  1021. _ASSERT (pEI);
  1022. _ASSERT (pEI->pArgs);
  1023. _ASSERT (pEI->pArgs->pEntry);
  1024. Free (pEI->pArgs->pEntry); // BILLSPBENTRY
  1025. EuFree (pEI->pArgs);
  1026. if (pEI->lpdt)
  1027. Free (pEI->lpdt);
  1028. Free (pEI);
  1029. }
  1030. VOID
  1031. EuFree(
  1032. IN EINFO* pInfo )
  1033. // Releases 'pInfo' and associated resources.
  1034. //
  1035. {
  1036. TCHAR* psz;
  1037. // INTERNALARGS* piargs;
  1038. // piargs = (INTERNALARGS* )pInfo->pApiArgs->reserved;
  1039. // Don't clean up the phonebook and user preferences if they arrived via
  1040. // the secret hack.
  1041. //
  1042. // if (!piargs)
  1043. // {
  1044. // if (pInfo->pFile)
  1045. // {
  1046. // ClosePhonebookFile( pInfo->pFile );
  1047. // }
  1048. // if (pInfo->pUser)
  1049. // {
  1050. // DestroyUserPreferences( pInfo->pUser );
  1051. // }
  1052. // }
  1053. // if (pInfo->pListPorts)
  1054. // {
  1055. // DtlDestroyList( pInfo->pListPorts, DestroyPortNode );
  1056. // }
  1057. // Free(pInfo->pszCurDevice);
  1058. // Free(pInfo->pszCurPort);
  1059. // if (pInfo->pNode)
  1060. // {
  1061. // DestroyEntryNode( pInfo->pNode );
  1062. // }
  1063. // Free router-information
  1064. //
  1065. // Free( pInfo->pszRouter );
  1066. // Free( pInfo->pszRouterUserName );
  1067. // Free( pInfo->pszRouterDomain );
  1068. // if (pInfo->pSharedNode)
  1069. // {
  1070. // DestroyLinkNode( pInfo->pSharedNode );
  1071. // }
  1072. // psz = pInfo->pszRouterPassword;
  1073. // if (psz)
  1074. // {
  1075. // ZeroMemory( psz, lstrlen( psz ) * sizeof(TCHAR) );
  1076. // Free( psz );
  1077. // }
  1078. // psz = pInfo->pszRouterDialInPassword;
  1079. // if (psz)
  1080. // {
  1081. // ZeroMemory( psz, lstrlen( psz ) * sizeof(TCHAR) );
  1082. // Free( psz );
  1083. // }
  1084. // Free credentials stuff
  1085. // Free(pInfo->pszDefUserName);
  1086. // Free(pInfo->pszDefPassword);
  1087. // Free home networking information
  1088. //
  1089. if (pInfo->rgPrivateConns)
  1090. {
  1091. UINT i;
  1092. for (i = 0; i < pInfo->dwLanCount; i++)
  1093. {
  1094. if (pInfo->rgPrivateConns[i])
  1095. {
  1096. pInfo->rgPrivateConns[i]->Release();
  1097. }
  1098. }
  1099. CoTaskMemFree(pInfo->rgPrivateConns);
  1100. }
  1101. if (pInfo->pHNetConn)
  1102. {
  1103. pInfo->pHNetConn->Release();
  1104. }
  1105. if (pInfo->pIcsSettings)
  1106. {
  1107. pInfo->pIcsSettings->Release();
  1108. }
  1109. if (pInfo->pOldSharedConnection)
  1110. {
  1111. pInfo->pOldSharedConnection->Release();
  1112. }
  1113. if (pInfo->pHNetCfgMgr)
  1114. {
  1115. pInfo->pHNetCfgMgr->Release();
  1116. }
  1117. if (pInfo->fComInitialized)
  1118. {
  1119. CoUninitialize();
  1120. }
  1121. Free( pInfo );
  1122. }
  1123. // helper
  1124. HRESULT GetRasEntry (TCHAR * pszPhonebook, TCHAR * pszEntry, RASENTRY ** ppRE)
  1125. {
  1126. *ppRE = NULL;
  1127. DWORD dwSize = 0;
  1128. DWORD dwErr = RasGetEntryProperties (pszPhonebook, pszEntry, NULL, &dwSize, NULL, NULL);
  1129. if (dwErr != ERROR_BUFFER_TOO_SMALL)
  1130. return HRESULT_FROM_WIN32(dwErr);
  1131. _ASSERT (dwSize != 0);
  1132. RASENTRY * pRE = (RASENTRY*)Malloc (dwSize);
  1133. if (!pRE)
  1134. return E_OUTOFMEMORY;
  1135. ZeroMemory (pRE, dwSize);
  1136. pRE->dwSize = sizeof(RASENTRY);
  1137. dwErr = RasGetEntryProperties (pszPhonebook, pszEntry, pRE, &dwSize, NULL, NULL);
  1138. if (dwErr) {
  1139. Free (pRE);
  1140. return HRESULT_FROM_WIN32(dwErr);
  1141. }
  1142. *ppRE = pRE;
  1143. return S_OK;
  1144. }
  1145. // wrapper....
  1146. HRESULT PeInit (GUID * pGuid, PEINFO ** ppEI)
  1147. {
  1148. _ASSERT (pGuid);
  1149. _ASSERT (ppEI);
  1150. *ppEI = (PEINFO *)Malloc (sizeof(PEINFO));
  1151. if (!*ppEI)
  1152. return E_OUTOFMEMORY;
  1153. ZeroMemory (*ppEI, sizeof(PEINFO));
  1154. CComPtr<IHNetConnection> spHNetConn = NULL;
  1155. CComPtr<IHNetCfgMgr> spHNetCfgMgr = NULL;
  1156. HRESULT hr = CoCreateInstance (CLSID_HNetCfgMgr,
  1157. NULL,
  1158. CLSCTX_ALL,
  1159. __uuidof(IHNetCfgMgr), // &IID_IHNetCfgMgr,
  1160. (void**)&spHNetCfgMgr);
  1161. if (SUCCEEDED(hr)) {
  1162. // Convert the entry to an IHNetConnection
  1163. hr = spHNetCfgMgr->GetIHNetConnectionForGuid (
  1164. pGuid, FALSE, TRUE, &spHNetConn);
  1165. }
  1166. if (SUCCEEDED(hr)) {
  1167. // the code below assumes UNICODE....
  1168. TCHAR * pszPhonebook = NULL;
  1169. TCHAR * pszEntry = NULL;
  1170. hr = spHNetConn->GetName (&pszEntry);
  1171. if (hr == S_OK)
  1172. hr = spHNetConn->GetRasPhonebookPath (&pszPhonebook);
  1173. if (hr == S_OK) {
  1174. // get RASENTRY dwType and guidId fields for code below
  1175. RASENTRY * pRE = NULL;
  1176. hr = GetRasEntry (pszPhonebook, pszEntry, &pRE);
  1177. if (pRE) {
  1178. DWORD dwOp = 0;
  1179. DWORD dwError = EuInit (pRE,
  1180. pszPhonebook,
  1181. pszEntry,
  1182. NULL, // IN RASENTRYDLG* pArgs,
  1183. FALSE, // IN BOOL fRouter,
  1184. &(*ppEI)->pArgs,
  1185. &dwOp);
  1186. if (dwError != 0) {
  1187. _ASSERT (dwOp != 0);
  1188. _ASSERT (!*ppEI);
  1189. if (HRESULT_SEVERITY(dwError))
  1190. hr = dwError;
  1191. else
  1192. hr = HRESULT_FROM_WIN32 (dwError);
  1193. } else {
  1194. _ASSERT (dwOp == 0);
  1195. _ASSERT (*ppEI);
  1196. }
  1197. Free (pRE);
  1198. }
  1199. }
  1200. if (pszPhonebook) CoTaskMemFree (pszPhonebook);
  1201. if (pszEntry) CoTaskMemFree (pszEntry);
  1202. }
  1203. return hr;
  1204. }
  1205. DWORD
  1206. EuInit(
  1207. IN RASENTRY * pRE,
  1208. IN TCHAR* pszPhonebook,
  1209. IN TCHAR* pszEntry,
  1210. IN RASENTRYDLG* pArgs,
  1211. IN BOOL fRouter,
  1212. OUT EINFO** ppInfo,
  1213. OUT DWORD* pdwOp )
  1214. // Allocates '*ppInfo' data for use by the property sheet or wizard.
  1215. // 'PszPhonebook', 'pszEntry', and 'pArgs', are the arguments passed by
  1216. // user to the API. 'FRouter' is set if running in "router mode", clear
  1217. // for the normal "dial-out" mode. '*pdwOp' is set to the operation code
  1218. // associated with any error.
  1219. //
  1220. // Returns 0 if successful, or an error code. If non-null '*ppInfo' is
  1221. // returned caller must eventually call EuFree to release the returned
  1222. // block.
  1223. //
  1224. {
  1225. DWORD dwErr;
  1226. EINFO* pInfo;
  1227. // INTERNALARGS* piargs;
  1228. *ppInfo = NULL;
  1229. *pdwOp = 0;
  1230. pInfo = (EINFO*)Malloc( sizeof(EINFO) );
  1231. if (!pInfo)
  1232. {
  1233. return ERROR_NOT_ENOUGH_MEMORY;
  1234. }
  1235. ZeroMemory( pInfo, sizeof(*pInfo ) );
  1236. /*
  1237. bhanlon: I'm filling out what used to be a PBENTRY with a
  1238. BILLSPBENTRY struct. This needs to be freed....
  1239. */
  1240. pInfo->pEntry = (BILLSPBENTRY *)Malloc (sizeof(BILLSPBENTRY));
  1241. if (!pInfo->pEntry) {
  1242. Free (pInfo);
  1243. return ERROR_NOT_ENOUGH_MEMORY;
  1244. }
  1245. _tcsncpy (pInfo->pEntry->pszEntryName, pszEntry, RAS_MaxEntryName);
  1246. _tcsncpy (pInfo->pEntry->pszPhonebookPath, pszPhonebook, MAX_PATH);
  1247. pInfo->pEntry->pGuid = &pInfo->pEntry->guidId;
  1248. pInfo->pEntry->dwfExcludedProtocols = 0;
  1249. pInfo->pEntry->dwType = pRE->dwType;
  1250. pInfo->pEntry->guidId = pRE->guidId;
  1251. *ppInfo = pInfo;
  1252. pInfo->pszPhonebook = pszPhonebook;
  1253. pInfo->pszEntry = pszEntry;
  1254. // pInfo->pApiArgs = pArgs;
  1255. pInfo->fRouter = fRouter;
  1256. // piargs = (INTERNALARGS *)pArgs->reserved;
  1257. // if (pInfo->fRouter)
  1258. // {
  1259. // LPTSTR pszRouter;
  1260. // DWORD dwVersion;
  1261. // ASSERT(piargs);
  1262. // pszRouter = RemoteGetServerName(piargs->hConnection);
  1263. // pmay: 348623
  1264. //
  1265. // Note that RemoteGetServerName is guarenteed to return
  1266. // NULL for local box, non-NULL for remote
  1267. //
  1268. // pInfo->fRemote = !!pszRouter;
  1269. // if(NULL == pszRouter)
  1270. // {
  1271. // pszRouter = TEXT("");
  1272. // }
  1273. // pInfo->pszRouter = StrDupTFromW(pszRouter);
  1274. // Find out if we're focused on an nt4 router
  1275. // pInfo->fNt4Router = FALSE;
  1276. // IsNt40Machine( pszRouter, &(pInfo->fNt4Router) );
  1277. // dwVersion = ((RAS_RPC *)(piargs->hConnection))->dwVersion;
  1278. // pInfo->fNt4Router = !!(VERSION_40 == dwVersion );
  1279. //Find out if the remote server is a win2k machine
  1280. //
  1281. // pInfo->fW2kRouter = !!(VERSION_50 == dwVersion );
  1282. // }
  1283. // Load the user preferences, or figure out that caller has already loaded
  1284. // them.
  1285. //
  1286. // if (piargs && !piargs->fInvalid)
  1287. // {
  1288. // // We've received user preferences and the "no user" status via the
  1289. // // secret hack.
  1290. // //
  1291. // pInfo->pUser = piargs->pUser;
  1292. // pInfo->fNoUser = piargs->fNoUser;
  1293. // pInfo->pFile = piargs->pFile;
  1294. // pInfo->fDisableFirstConnect = piargs->fDisableFirstConnect;
  1295. // }
  1296. // else
  1297. // {
  1298. // DWORD dwReadPbkFlags = 0;
  1299. // // Read user preferences from registry.
  1300. // //
  1301. // dwErr = g_pGetUserPreferences(
  1302. // (piargs) ? piargs->hConnection : NULL,
  1303. // &pInfo->user,
  1304. // (pInfo->fRouter) ? UPM_Router : UPM_Normal );
  1305. // if (dwErr != 0)
  1306. // {
  1307. // *pdwOp = SID_OP_LoadPrefs;
  1308. // return dwErr;
  1309. // }
  1310. // pInfo->pUser = &pInfo->user;
  1311. // if(pInfo->fRouter)
  1312. // {
  1313. // pInfo->file.hConnection = piargs->hConnection;
  1314. // dwReadPbkFlags |= RPBF_Router;
  1315. // }
  1316. // if(pInfo->fNoUser)
  1317. // {
  1318. // dwReadPbkFlags |= RPBF_NoUser;
  1319. // }
  1320. // Load and parse the phonebook file.
  1321. //
  1322. // dwErr = ReadPhonebookFile(
  1323. // pInfo->pszPhonebook, &pInfo->user, NULL,
  1324. // dwReadPbkFlags,
  1325. // &pInfo->file );
  1326. // if (dwErr != 0)
  1327. // {
  1328. // *pdwOp = SID_OP_LoadPhonebook;
  1329. // return dwErr;
  1330. // }
  1331. // pInfo->pFile = &pInfo->file;
  1332. // }
  1333. // Determine if strong encryption is supported. Export laws prevent it in
  1334. // some versions of the system.
  1335. //
  1336. {
  1337. // ULONG ulCaps;
  1338. // RAS_NDISWAN_DRIVER_INFO info;
  1339. //
  1340. // ZeroMemory( &info, sizeof(info) );
  1341. // ASSERT( g_pRasGetNdiswanDriverCaps );
  1342. // dwErr = g_pRasGetNdiswanDriverCaps(
  1343. // (piargs) ? piargs->hConnection : NULL, &info );
  1344. // if (dwErr == 0)
  1345. // {
  1346. // pInfo->fStrongEncryption =
  1347. // !!(info.DriverCaps & RAS_NDISWAN_128BIT_ENABLED);
  1348. // }
  1349. // else
  1350. {
  1351. pInfo->fStrongEncryption = FALSE;
  1352. }
  1353. }
  1354. // Load the list of ports.
  1355. //
  1356. // dwErr = LoadPortsList2(
  1357. // (piargs) ? piargs->hConnection : NULL,
  1358. // &pInfo->pListPorts,
  1359. // pInfo->fRouter );
  1360. // if (dwErr != 0)
  1361. // {
  1362. // TRACE1( "LoadPortsList=%d", dwErr );
  1363. // *pdwOp = SID_OP_RetrievingData;
  1364. // return dwErr;
  1365. // }
  1366. // Set up work entry node.
  1367. //
  1368. // if (pInfo->pApiArgs->dwFlags & RASEDFLAG_AnyNewEntry)
  1369. // {
  1370. // DTLNODE* pNodeL;
  1371. // DTLNODE* pNodeP;
  1372. // PBLINK* pLink;
  1373. // PBPORT* pPort;
  1374. // // New entry mode, so 'pNode' set to default settings.
  1375. // //
  1376. // pInfo->pNode = CreateEntryNode( TRUE );
  1377. // if (!pInfo->pNode)
  1378. // {
  1379. // TRACE( "CreateEntryNode failed" );
  1380. // *pdwOp = SID_OP_RetrievingData;
  1381. // return dwErr;
  1382. // }
  1383. // // Store entry within work node stored in context for convenience
  1384. // // elsewhere.
  1385. // //
  1386. // pInfo->pEntry = (PBENTRY* )DtlGetData( pInfo->pNode );
  1387. // ASSERT( pInfo->pEntry );
  1388. // if (pInfo->fRouter)
  1389. // {
  1390. // Set router specific defaults.
  1391. //
  1392. // pInfo->pEntry->dwIpNameSource = ASRC_None;
  1393. // pInfo->pEntry->dwRedialAttempts = 0;
  1394. // Since this is a new entry, setup a proposed entry name.
  1395. // This covers the case when the wizard is not used to
  1396. // create the entry and the property sheet has no way to enter
  1397. // the name.
  1398. // ASSERT( !pInfo->pEntry->pszEntryName );
  1399. // GetDefaultEntryName( pInfo->pFile,
  1400. // RASET_Phone,
  1401. // pInfo->fRouter,
  1402. // &pInfo->pEntry->pszEntryName );
  1403. // Disable MS client and File and Print services by default
  1404. //
  1405. // EnableOrDisableNetComponent( pInfo->pEntry, TEXT("ms_msclient"),
  1406. // FALSE);
  1407. // EnableOrDisableNetComponent( pInfo->pEntry, TEXT("ms_server"),
  1408. // FALSE);
  1409. // }
  1410. // Use caller's default name, if any.
  1411. //
  1412. // if (pInfo->pszEntry)
  1413. // {
  1414. // pInfo->pEntry->pszEntryName = StrDup( pInfo->pszEntry );
  1415. // }
  1416. // Set the default entry type to "phone", i.e. modems, ISDN, X.26 etc.
  1417. // This may be changed to "VPN" or "direct" by the new entry wizard
  1418. // after the initial wizard page.
  1419. //
  1420. // EuChangeEntryType( pInfo, RASET_Phone );
  1421. // }
  1422. // else
  1423. // {
  1424. // DTLNODE* pNode;
  1425. // Edit or clone entry mode, so 'pNode' set to entry's current
  1426. // settings.
  1427. //
  1428. // pInfo->pOldNode = EntryNodeFromName(
  1429. // pInfo->pFile->pdtllistEntries, pInfo->pszEntry );
  1430. // if ( !pInfo->pOldNode
  1431. // && !pInfo->fRouter)
  1432. // {
  1433. // if(NULL == pInfo->pszPhonebook)
  1434. // {
  1435. //
  1436. // Close the phonebook file we opened above.
  1437. // we will try to find the entry name in the
  1438. // per user phonebook file.
  1439. //
  1440. // ClosePhonebookFile(&pInfo->file);
  1441. // pInfo->pFile = NULL;
  1442. //
  1443. // Attempt to find the file in users profile
  1444. //
  1445. // dwErr = GetPbkAndEntryName(
  1446. // NULL,
  1447. // pInfo->pszEntry,
  1448. // 0,
  1449. // &pInfo->file,
  1450. // &pInfo->pOldNode);
  1451. // if(ERROR_SUCCESS != dwErr)
  1452. // {
  1453. // *pdwOp = SID_OP_RetrievingData;
  1454. // return ERROR_CANNOT_FIND_PHONEBOOK_ENTRY;
  1455. // }
  1456. // pInfo->pFile = &pInfo->file;
  1457. // }
  1458. // else
  1459. // {
  1460. // *pdwOp = SID_OP_RetrievingData;
  1461. // return ERROR_CANNOT_FIND_PHONEBOOK_ENTRY;
  1462. // }
  1463. // }
  1464. // if(NULL != pInfo->pOldNode)
  1465. // {
  1466. // PBENTRY *pEntry = (PBENTRY *) DtlGetData(pInfo->pOldNode);
  1467. // Before cloning or editing make sure that for dial up
  1468. // connections, share File And Print is disabled.
  1469. //
  1470. // if( ((RASET_Phone == pEntry->dwType)
  1471. // || (RASET_Broadband == pEntry->dwType))
  1472. // && (!pEntry->fShareMsFilePrint))
  1473. // {
  1474. // EnableOrDisableNetComponent( pEntry, TEXT("ms_server"),
  1475. // FALSE);
  1476. // }
  1477. // }
  1478. // if(NULL != pInfo->pOldNode)
  1479. // {
  1480. // if (pInfo->pApiArgs->dwFlags & RASEDFLAG_CloneEntry)
  1481. // {
  1482. // pInfo->pNode = CloneEntryNode( pInfo->pOldNode );
  1483. // }
  1484. // else
  1485. // {
  1486. // pInfo->pNode = DuplicateEntryNode( pInfo->pOldNode );
  1487. // }
  1488. // }
  1489. // if (!pInfo->pNode)
  1490. // {
  1491. // TRACE( "DuplicateEntryNode failed" );
  1492. // *pdwOp = SID_OP_RetrievingData;
  1493. // return ERROR_NOT_ENOUGH_MEMORY;
  1494. // }
  1495. // Store entry within work node stored in context for convenience
  1496. // elsewhere.
  1497. //
  1498. // pInfo->pEntry = (PBENTRY* )DtlGetData( pInfo->pNode );
  1499. // Save original entry name for comparison later.
  1500. //
  1501. // lstrcpyn(
  1502. // pInfo->szOldEntryName,
  1503. // pInfo->pEntry->pszEntryName,
  1504. // RAS_MaxEntryName + 1);
  1505. // For router, want unconfigured ports to show up as "unavailable" so
  1506. // they stand out to user who has been directed to change them.
  1507. //
  1508. // if (pInfo->fRouter)
  1509. // {
  1510. // DTLNODE* pNodeL;
  1511. // PBLINK* pLink;
  1512. // pNodeL = DtlGetFirstNode( pInfo->pEntry->pdtllistLinks );
  1513. // pLink = (PBLINK* )DtlGetData( pNodeL );
  1514. // if (!pLink->pbport.fConfigured)
  1515. // {
  1516. // Free( pLink->pbport.pszDevice );
  1517. // pLink->pbport.pszDevice = NULL;
  1518. // }
  1519. // }
  1520. // pmay: 277801
  1521. //
  1522. // Remember the "current" device if this entry was last saved
  1523. // as single link.
  1524. //
  1525. // if (DtlGetNodes(pInfo->pEntry->pdtllistLinks) == 1)
  1526. // {
  1527. // DTLNODE* pNodeL;
  1528. // PBLINK* pLink;
  1529. // pNodeL = DtlGetFirstNode( pInfo->pEntry->pdtllistLinks );
  1530. // pLink = (PBLINK* )DtlGetData( pNodeL );
  1531. // if (pLink->pbport.pszDevice && pLink->pbport.pszPort)
  1532. // {
  1533. // pInfo->pszCurDevice =
  1534. // StrDup(pLink->pbport.pszDevice);
  1535. // pInfo->pszCurPort =
  1536. // StrDup(pLink->pbport.pszPort);
  1537. // }
  1538. // }
  1539. // Append all non-configured ports of the entries type to the list of
  1540. // links. This is for the convenience of the UI. The non-configured
  1541. // ports are removed after editing prior to saving.
  1542. //
  1543. // AppendDisabledPorts( pInfo, pInfo->pEntry->dwType );
  1544. // }
  1545. // Set up the phone number storage for shared phone number mode.
  1546. // Initialize it to a copy of the information from the first link which at
  1547. // startup will always be enabled. Note the Dial case with non-0
  1548. // dwSubEntry is an exception, but in that case the pSharedNode anyway.
  1549. //
  1550. // {
  1551. // DTLNODE* pNode;
  1552. // pInfo->pSharedNode = CreateLinkNode();
  1553. // if (!pInfo->pSharedNode)
  1554. // {
  1555. // *pdwOp = SID_OP_RetrievingData;
  1556. // return ERROR_NOT_ENOUGH_MEMORY;
  1557. // }
  1558. // ASSERT( pInfo->pSharedNode );
  1559. // pNode = DtlGetFirstNode( pInfo->pEntry->pdtllistLinks );
  1560. // ASSERT( pNode );
  1561. // CopyLinkPhoneNumberInfo( pInfo->pSharedNode, pNode );
  1562. // }
  1563. // Load the current shared-access (and firewall) settings
  1564. //
  1565. if (!pInfo->fRouter)
  1566. {
  1567. HRESULT hr;
  1568. HNET_CONN_PROPERTIES *pProps;
  1569. // Make sure COM is initialized on this thread.
  1570. //
  1571. hr = CoInitializeEx(
  1572. NULL,
  1573. COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE
  1574. );
  1575. if (SUCCEEDED(hr))
  1576. {
  1577. pInfo->fComInitialized = TRUE;
  1578. }
  1579. else if (RPC_E_CHANGED_MODE == hr)
  1580. {
  1581. hr = S_OK;
  1582. }
  1583. if (SUCCEEDED(hr))
  1584. {
  1585. // Create the home networking configuration manager
  1586. //
  1587. hr = CoCreateInstance(
  1588. CLSID_HNetCfgMgr,
  1589. NULL,
  1590. CLSCTX_ALL,
  1591. __uuidof(IHNetCfgMgr),
  1592. (void**)&pInfo->pHNetCfgMgr);
  1593. }
  1594. if (SUCCEEDED(hr))
  1595. {
  1596. // Get the IHNetIcsSettings interface
  1597. //
  1598. hr = pInfo->pHNetCfgMgr->QueryInterface(
  1599. __uuidof(IHNetIcsSettings), (void**)&pInfo->pIcsSettings);
  1600. }
  1601. if (SUCCEEDED(hr))
  1602. {
  1603. // Convert the entry to an IHNetConnection
  1604. //
  1605. hr = pInfo->pHNetCfgMgr->GetIHNetConnectionForGuid(
  1606. pInfo->pEntry->pGuid, FALSE, TRUE,
  1607. &pInfo->pHNetConn);
  1608. }
  1609. if (SUCCEEDED(hr))
  1610. {
  1611. // Determine whether this entry is already shared;
  1612. // skip the check for new entries.
  1613. //
  1614. if (pInfo->pEntry->pszEntryName)
  1615. {
  1616. hr = pInfo->pHNetConn->GetProperties (&pProps);
  1617. if (SUCCEEDED(hr))
  1618. {
  1619. pInfo->fShared = pProps->fIcsPublic;
  1620. pInfo->fFirewalled = pProps->fFirewalled;
  1621. CoTaskMemFree(pProps);
  1622. }
  1623. }
  1624. else
  1625. {
  1626. pInfo->fShared = FALSE;
  1627. pInfo->fFirewalled = FALSE;
  1628. }
  1629. pInfo->fNewShared = pInfo->fShared;
  1630. pInfo->fNewFirewalled = pInfo->fFirewalled;
  1631. }
  1632. if (SUCCEEDED(hr))
  1633. {
  1634. // Obtain an array of possible ICS private connections
  1635. //
  1636. hr = pInfo->pIcsSettings->GetPossiblePrivateConnections(
  1637. pInfo->pHNetConn,
  1638. &pInfo->dwLanCount,
  1639. &pInfo->rgPrivateConns,
  1640. &pInfo->lxCurrentPrivate
  1641. );
  1642. RasQuerySharedAutoDial(&pInfo->fDemandDial);
  1643. pInfo->fNewDemandDial = pInfo->fDemandDial;
  1644. pInfo->fResetPrivateAdapter =
  1645. pInfo->fShared && -1 == pInfo->lxCurrentPrivate;
  1646. }
  1647. pInfo->hShowHNetPagesResult = hr;
  1648. if(SUCCEEDED(hr))
  1649. {
  1650. pInfo->fShowHNetPages = TRUE;
  1651. }
  1652. }
  1653. // if (pInfo->fRouter)
  1654. // {
  1655. // pInfo->pEntry->dwfExcludedProtocols |= NP_Nbf;
  1656. // }
  1657. // AboladeG - capture the security level of the current user.
  1658. //
  1659. pInfo->fIsUserAdminOrPowerUser = FIsUserAdminOrPowerUser();
  1660. return 0;
  1661. }
  1662. BOOL
  1663. FIsUserAdminOrPowerUser()
  1664. {
  1665. SID_IDENTIFIER_AUTHORITY SidAuth = SECURITY_NT_AUTHORITY;
  1666. PSID psid;
  1667. BOOL fIsMember = FALSE;
  1668. BOOL fRet = FALSE;
  1669. SID sidLocalSystem = { 1, 1,
  1670. SECURITY_NT_AUTHORITY,
  1671. SECURITY_LOCAL_SYSTEM_RID };
  1672. // Check to see if running under local system first
  1673. //
  1674. if (!CheckTokenMembership( NULL, &sidLocalSystem, &fIsMember ))
  1675. {
  1676. TRACE( "CheckTokenMemberShip for local system failed.");
  1677. fIsMember = FALSE;
  1678. }
  1679. fRet = fIsMember;
  1680. if (!fIsMember)
  1681. {
  1682. // Allocate a SID for the Administrators group and check to see
  1683. // if the user is a member.
  1684. //
  1685. if (AllocateAndInitializeSid( &SidAuth, 2,
  1686. SECURITY_BUILTIN_DOMAIN_RID,
  1687. DOMAIN_ALIAS_RID_ADMINS,
  1688. 0, 0, 0, 0, 0, 0,
  1689. &psid ))
  1690. {
  1691. if (!CheckTokenMembership( NULL, psid, &fIsMember ))
  1692. {
  1693. TRACE( "CheckTokenMemberShip for admins failed.");
  1694. fIsMember = FALSE;
  1695. }
  1696. FreeSid( psid );
  1697. // Changes to the Windows 2000 permission model mean that regular Users
  1698. // on workstations are in the power user group. So we no longer want to
  1699. // check for power user.
  1700. #if 0
  1701. if (!fIsMember)
  1702. {
  1703. // They're not a member of the Administrators group so allocate a
  1704. // SID for the Power Users group and check to see
  1705. // if the user is a member.
  1706. //
  1707. if (AllocateAndInitializeSid( &SidAuth, 2,
  1708. SECURITY_BUILTIN_DOMAIN_RID,
  1709. DOMAIN_ALIAS_RID_POWER_USERS,
  1710. 0, 0, 0, 0, 0, 0,
  1711. &psid ))
  1712. {
  1713. if (!CheckTokenMembership( NULL, psid, &fIsMember ))
  1714. {
  1715. TRACE( "CheckTokenMemberShip for power users failed.");
  1716. fIsMember = FALSE;
  1717. }
  1718. FreeSid( psid );
  1719. }
  1720. }
  1721. #endif
  1722. }
  1723. fRet = fIsMember;
  1724. }
  1725. return fRet;
  1726. }
  1727. BOOL PeApply (IN HWND hwndPage)
  1728. {
  1729. // Saves the contents of the property sheet. 'HwndPage is the handle of a
  1730. // property page. Pops up any errors that occur.
  1731. //
  1732. // Returns true is page can be dismissed, false otherwise.
  1733. //
  1734. DWORD dwErr;
  1735. PEINFO* pInfo;
  1736. BILLSPBENTRY* pEntry;
  1737. TRACE( "PeApply" );
  1738. pInfo = PeContext( hwndPage );
  1739. ASSERT( pInfo );
  1740. if (pInfo == NULL)
  1741. {
  1742. return ERROR_CAN_NOT_COMPLETE;
  1743. }
  1744. pEntry = pInfo->pArgs->pEntry;
  1745. ASSERT( pEntry );
  1746. // Save General page fields.
  1747. //
  1748. // ASSERT( pInfo->hwndGe );
  1749. // {
  1750. // DTLNODE* pNode;
  1751. // Retrieve the lone common control.
  1752. //
  1753. // pEntry->fShowMonitorIconInTaskBar =
  1754. // Button_GetCheck( pInfo->hwndCbShowIcon );
  1755. // if (pEntry->dwType == RASET_Phone)
  1756. // {
  1757. // DWORD dwCount;
  1758. // dwCount = GeSaveLvDeviceChecks( pInfo );
  1759. // Don't allow the user to deselect all of the
  1760. // devices
  1761. // if ( (pInfo->pArgs->fMultipleDevices) && (dwCount == 0) )
  1762. // {
  1763. // MsgDlg( hwndPage, SID_SelectDevice, NULL );
  1764. // PropSheet_SetCurSel ( pInfo->hwndDlg, pInfo->hwndGe, 0 );
  1765. // SetFocus ( pInfo->hwndLvDevices );
  1766. // return FALSE;
  1767. // }
  1768. // Save the "shared phone number" setting. As usual, single
  1769. // device mode implies shared mode, allowing things to fall
  1770. // through correctly.
  1771. //
  1772. // if (pInfo->pArgs->fMultipleDevices)
  1773. // {
  1774. // pEntry->fSharedPhoneNumbers =
  1775. // Button_GetCheck( pInfo->hwndCbSharedPhoneNumbers );
  1776. // }
  1777. // else
  1778. // {
  1779. // pEntry->fSharedPhoneNumbers = TRUE;
  1780. // }
  1781. // Set the phone number set for the first phone number of the
  1782. // current link (shared or selected) to the contents of the phone
  1783. // number controls.
  1784. //
  1785. // GeGetPhoneFields( pInfo, pInfo->pCurLinkNode );
  1786. // Swap lists, saving updates to caller's global list of area
  1787. // codes. Caller's original list will be destroyed by PeTerm.
  1788. //
  1789. // if (pInfo->pListAreaCodes)
  1790. // {
  1791. // DtlSwapLists(
  1792. // pInfo->pArgs->pUser->pdtllistAreaCodes,
  1793. // pInfo->pListAreaCodes );
  1794. // pInfo->pArgs->pUser->fDirty = TRUE;
  1795. // }
  1796. // }
  1797. // else if (pEntry->dwType == RASET_Vpn)
  1798. // {
  1799. // DTLNODE* pNode;
  1800. // PBLINK* pLink;
  1801. // PBPHONE* pPhone;
  1802. // Save host name, i.e. the VPN phone number.
  1803. //
  1804. // pNode = DtlGetFirstNode( pEntry->pdtllistLinks );
  1805. // ASSERT( pNode );
  1806. // pLink = (PBLINK* )DtlGetData( pNode );
  1807. // pNode = FirstPhoneNodeFromPhoneList( pLink->pdtllistPhones );
  1808. // if(NULL == pNode)
  1809. // {
  1810. // return FALSE;
  1811. // }
  1812. // pPhone = (PBPHONE* )DtlGetData( pNode );
  1813. // Free0( pPhone->pszPhoneNumber );
  1814. // pPhone->pszPhoneNumber = GetText( pInfo->hwndEbHostName );
  1815. // FirstPhoneNodeToPhoneList( pLink->pdtllistPhones, pNode );
  1816. // Any prequisite entry selection change has been saved already.
  1817. // Just need to toss it if disabled.
  1818. //
  1819. // if (!Button_GetCheck( pInfo->hwndCbDialAnotherFirst ))
  1820. // {
  1821. // Free0( pEntry->pszPrerequisiteEntry );
  1822. // pEntry->pszPrerequisiteEntry = NULL;
  1823. // Free0( pEntry->pszPrerequisitePbk );
  1824. // pEntry->pszPrerequisitePbk = NULL;
  1825. // }
  1826. // }
  1827. // else if (pEntry->dwType == RASET_Broadband)
  1828. // {
  1829. // DTLNODE* pNode;
  1830. // PBLINK* pLink;
  1831. // PBPHONE* pPhone;
  1832. // Save service name, i.e. the broadband phone number.
  1833. //
  1834. // pNode = DtlGetFirstNode( pEntry->pdtllistLinks );
  1835. // ASSERT( pNode );
  1836. // pLink = (PBLINK* )DtlGetData( pNode );
  1837. // pNode = FirstPhoneNodeFromPhoneList( pLink->pdtllistPhones );
  1838. // if(NULL == pNode)
  1839. // {
  1840. // return FALSE;
  1841. // }
  1842. // pPhone = (PBPHONE* )DtlGetData( pNode );
  1843. // Free0( pPhone->pszPhoneNumber );
  1844. // pPhone->pszPhoneNumber = GetText( pInfo->hwndEbBroadbandService );
  1845. // FirstPhoneNodeToPhoneList( pLink->pdtllistPhones, pNode );
  1846. // }
  1847. // else if (pEntry->dwType == RASET_Direct)
  1848. // {
  1849. // DTLNODE* pNode;
  1850. // PBLINK* pLink;
  1851. // The currently enabled device is the one
  1852. // that should be used for the connection. Only
  1853. // one device will be enabled (DnUpdateSelectedDevice).
  1854. // for (pNode = DtlGetFirstNode( pEntry->pdtllistLinks );
  1855. // pNode;
  1856. // pNode = DtlGetNextNode( pNode ))
  1857. // {
  1858. // pLink = (PBLINK* )DtlGetData( pNode );
  1859. // ASSERT(pLink);
  1860. // if ( pLink->fEnabled )
  1861. // break;
  1862. // }
  1863. // If we found a link successfully, deal with it
  1864. // now.
  1865. // if ( pLink && pLink->fEnabled ) {
  1866. // if (pLink->pbport.pbdevicetype == PBDT_ComPort)
  1867. // MdmInstallNullModem (pLink->pbport.pszPort);
  1868. // }
  1869. // }
  1870. // }
  1871. // Save Options page fields.
  1872. //
  1873. // if (pInfo->hwndOe)
  1874. // {
  1875. // UINT unValue;
  1876. // BOOL f;
  1877. // INT iSel;
  1878. // pEntry->fShowDialingProgress =
  1879. // Button_GetCheck( pInfo->hwndCbDisplayProgress );
  1880. // Note: The'fPreviewUserPw', 'fPreviewDomain' fields are updated as
  1881. // they are changed.
  1882. // pEntry->fPreviewPhoneNumber =
  1883. // Button_GetCheck( pInfo->hwndCbPreviewNumber );
  1884. // unValue = GetDlgItemInt(
  1885. // pInfo->hwndOe, CID_OE_EB_RedialAttempts, &f, FALSE );
  1886. // if (f && unValue <= 999999999)
  1887. // {
  1888. // pEntry->dwRedialAttempts = unValue;
  1889. // }
  1890. // iSel = ComboBox_GetCurSel( pInfo->hwndLbRedialTimes );
  1891. // pEntry->dwRedialSeconds =
  1892. // (DWORD )ComboBox_GetItemData( pInfo->hwndLbRedialTimes, iSel );
  1893. // iSel = ComboBox_GetCurSel( pInfo->hwndLbIdleTimes );
  1894. // pEntry->lIdleDisconnectSeconds =
  1895. // (LONG )ComboBox_GetItemData( pInfo->hwndLbIdleTimes, iSel );
  1896. // if (pInfo->pArgs->fRouter)
  1897. // {
  1898. // pEntry->fRedialOnLinkFailure =
  1899. // Button_GetCheck( pInfo->hwndRbPersistent );
  1900. // }
  1901. // else
  1902. // {
  1903. // pEntry->fRedialOnLinkFailure =
  1904. // Button_GetCheck( pInfo->hwndCbRedialOnDrop );
  1905. // }
  1906. // Note: dwDialMode is saved as changed.
  1907. // Note: X.25 settings are saved at OK on that dialog.
  1908. // }
  1909. // Save Security page fields.
  1910. //
  1911. // if (pInfo->hwndLo)
  1912. // {
  1913. // if (Button_GetCheck( pInfo->hwndRbTypicalSecurity ))
  1914. // {
  1915. // LoSaveTypicalAuthSettings( pInfo );
  1916. // if (pEntry->dwTypicalAuth == TA_CardOrCert)
  1917. // {
  1918. /*
  1919. // Toss any existing advanced EAP configuration remnants when
  1920. // typical smartcard, per bug 262702 and VBaliga email.
  1921. //
  1922. Free0( pEntry->pCustomAuthData );
  1923. pEntry->pCustomAuthData = NULL;
  1924. pEntry->cbCustomAuthData = 0;
  1925. */
  1926. // (void) DwSetCustomAuthData(
  1927. // pEntry,
  1928. // 0,
  1929. // NULL);
  1930. // TRACE( "RasSetEapUserData" );
  1931. // ASSERT( g_pRasGetEntryDialParams );
  1932. // g_pRasSetEapUserData(
  1933. // INVALID_HANDLE_VALUE,
  1934. // pInfo->pArgs->pFile->pszPath,
  1935. // pEntry->pszEntryName,
  1936. // NULL,
  1937. // 0 );
  1938. // TRACE( "RasSetEapUserData done" );
  1939. // }
  1940. // }
  1941. // if (pEntry->dwType == RASET_Phone)
  1942. // {
  1943. // Free0( pEntry->pszScriptAfter );
  1944. // SuGetInfo( &pInfo->suinfo,
  1945. // &pEntry->fScriptAfter,
  1946. // &pEntry->fScriptAfterTerminal,
  1947. // &pEntry->pszScriptAfter );
  1948. // }
  1949. // }
  1950. // Save Network page fields.
  1951. // We won't have anything to do if we never initialized pNetCfg.
  1952. //
  1953. // if (pInfo->pNetCfg)
  1954. // {
  1955. // HRESULT hr;
  1956. // Update the phone book entry with the enabled state of the components.
  1957. // Do this by enumerating the components from the list view item data
  1958. // and consulting the check state for each.
  1959. //
  1960. // NeSaveBindingChanges(pInfo);
  1961. // hr = INetCfg_Apply (pInfo->pNetCfg);
  1962. // if (((NETCFG_S_REBOOT == hr) || (pInfo->fRebootAlreadyRequested)) &&
  1963. // pInfo->pNetConUtilities)
  1964. // {
  1965. // DWORD dwFlags = QUFR_REBOOT;
  1966. // if (!pInfo->fRebootAlreadyRequested)
  1967. // dwFlags |= QUFR_PROMPT;
  1968. //$TODO NULL caption?
  1969. // INetConnectionUiUtilities_QueryUserForReboot (
  1970. // pInfo->pNetConUtilities, pInfo->hwndDlg, NULL, dwFlags);
  1971. // }
  1972. // }
  1973. // Save Shared Access page fields
  1974. //
  1975. if (pInfo->hwndSa)
  1976. {
  1977. // record the (new) sharing and demand-dial settings
  1978. //
  1979. pInfo->pArgs->fNewShared =
  1980. Button_GetCheck( pInfo->hwndSaPbShared );
  1981. pInfo->pArgs->fNewDemandDial =
  1982. Button_GetCheck( pInfo->hwndSaPbDemandDial );
  1983. pInfo->pArgs->fNewBeaconControl =
  1984. Button_GetCheck( GetDlgItem(pInfo->hwndSa, CID_SA_PB_Beacon) );
  1985. // we only look at the private-lan drop list
  1986. // if the user just turned on sharing, since that's the only time
  1987. // we display the drop-list to begin with. we also need to look if
  1988. // we need to reset the private adapter
  1989. //
  1990. if ((pInfo->pArgs->fNewShared && !pInfo->pArgs->fShared)
  1991. || pInfo->pArgs->fResetPrivateAdapter)
  1992. {
  1993. if (pInfo->pArgs->dwLanCount > 1)
  1994. {
  1995. INT item = ComboBox_GetCurSel( pInfo->hwndSaLbPrivateLan );
  1996. if (item != CB_ERR)
  1997. {
  1998. pInfo->pArgs->pPrivateLanConnection =
  1999. (IHNetConnection*)ComboBox_GetItemData(
  2000. pInfo->hwndSaLbPrivateLan, item );
  2001. }
  2002. }
  2003. else if (pInfo->pArgs->dwLanCount)
  2004. {
  2005. ASSERT(pInfo->pArgs->rgPrivateConns);
  2006. pInfo->pArgs->pPrivateLanConnection =
  2007. pInfo->pArgs->rgPrivateConns[0];
  2008. }
  2009. }
  2010. // Save Firewall fields
  2011. //
  2012. pInfo->pArgs->fNewFirewalled =
  2013. Button_GetCheck( pInfo->hwndSaPbFirewalled );
  2014. }
  2015. #if 0 //!!!
  2016. if ((fLocalPad || iPadSelection != 0)
  2017. && (!pEntry->pszX25Address || IsAllWhite( pEntry->pszX25Address )))
  2018. {
  2019. // Address field is blank with X.25 dial-up or local PAD chosen.
  2020. //
  2021. MsgDlg( pInfo->hwndDlg, SID_NoX25Address, NULL );
  2022. PropSheet_SetCurSel( pInfo->hwndDlg, NULL, PE_XsPage );
  2023. SetFocus( pInfo->hwndEbX25Address );
  2024. Edit_SetSel( pInfo->hwndEbX25Address, 0, -1 );
  2025. return FALSE;
  2026. }
  2027. #endif
  2028. // Make sure proprietary ISDN options are disabled if more than one link
  2029. // is enabled. The proprietary ISDN option is only meaningful when
  2030. // calling a down-level server that needs Digiboard channel aggragation
  2031. // instead of PPP multi-link.
  2032. //
  2033. // {
  2034. // DTLNODE* pNode;
  2035. // DWORD cIsdnLinks;
  2036. // cIsdnLinks = 0;
  2037. // for (pNode = DtlGetFirstNode( pEntry->pdtllistLinks );
  2038. // pNode;
  2039. // pNode = DtlGetNextNode( pNode ))
  2040. // {
  2041. // PBLINK* pLink = (PBLINK* )DtlGetData( pNode );
  2042. // ASSERT(pLink);
  2043. // if (pLink->fEnabled && pLink->pbport.pbdevicetype == PBDT_Isdn)
  2044. // {
  2045. // ++cIsdnLinks;
  2046. // }
  2047. // }
  2048. // if (cIsdnLinks > 1)
  2049. // {
  2050. // for (pNode = DtlGetFirstNode( pEntry->pdtllistLinks );
  2051. // pNode;
  2052. // pNode = DtlGetNextNode( pNode ))
  2053. // {
  2054. // PBLINK* pLink = (PBLINK* )DtlGetData( pNode );
  2055. // ASSERT(pLink);
  2056. // if (pLink->fEnabled && pLink->fProprietaryIsdn)
  2057. // {
  2058. // pLink->fProprietaryIsdn = FALSE;
  2059. // }
  2060. // }
  2061. // }
  2062. // }
  2063. // Inform user that edits to the connected entry won't take affect until
  2064. // the entry is hung up and re-dialed, per PierreS's insistence.
  2065. //
  2066. // if (HrasconnFromEntry( pInfo->pArgs->pFile->pszPath, pEntry->pszEntryName ))
  2067. // {
  2068. // MsgDlg( pInfo->hwndDlg, SID_EditConnected, NULL );
  2069. // }
  2070. // It's a valid new/changed entry. Commit the changes to the phonebook
  2071. // and preferences. This occurs immediately in "ShellOwned" mode where
  2072. // the RasEntryDlg API has already returned, but is otherwise deferred
  2073. // until the API is ready to return.
  2074. //
  2075. // if (pInfo->pArgs->pApiArgs->dwFlags & RASEDFLAG_ShellOwned)
  2076. // {
  2077. EuCommit( pInfo->pArgs );
  2078. // }
  2079. // else
  2080. // {
  2081. // pInfo->pArgs->fCommit = TRUE;
  2082. // }
  2083. return TRUE;
  2084. }
  2085. BOOL EuCommit(IN EINFO* pInfo )
  2086. {
  2087. // Commits the new or changed entry node to the phonebook file and list.
  2088. // Also adds the area code to the per-user list, if indicated. 'PInfo' is
  2089. // the common entry information block.
  2090. //
  2091. // Returns true if successful, false otherwise.
  2092. //
  2093. DWORD dwErr;
  2094. // BOOL fEditMode;
  2095. // BOOL fChangedNameInEditMode;
  2096. // If shared phone number, copy the phone number information from the
  2097. // shared link to each enabled link.
  2098. //
  2099. // if (pInfo->pEntry->fSharedPhoneNumbers)
  2100. // {
  2101. // DTLNODE* pNode;
  2102. // ASSERT( pInfo->pEntry->dwType == RASET_Phone );
  2103. // for (pNode = DtlGetFirstNode( pInfo->pEntry->pdtllistLinks );
  2104. // pNode;
  2105. // pNode = DtlGetNextNode( pNode ))
  2106. // {
  2107. // PBLINK* pLink = (PBLINK* )DtlGetData( pNode );
  2108. // ASSERT(pLink);
  2109. // if (pLink->fEnabled)
  2110. // {
  2111. // CopyLinkPhoneNumberInfo( pNode, pInfo->pSharedNode );
  2112. // }
  2113. // }
  2114. // }
  2115. // Delete all disabled link nodes.
  2116. //
  2117. // if (pInfo->fMultipleDevices)
  2118. // {
  2119. // DTLNODE* pNode;
  2120. // pNode = DtlGetFirstNode( pInfo->pEntry->pdtllistLinks );
  2121. // while (pNode)
  2122. // {
  2123. // PBLINK* pLink = (PBLINK* )DtlGetData( pNode );
  2124. // DTLNODE* pNextNode = DtlGetNextNode( pNode );
  2125. // if (!pLink->fEnabled)
  2126. // {
  2127. // DtlRemoveNode( pInfo->pEntry->pdtllistLinks, pNode );
  2128. // DestroyLinkNode( pNode );
  2129. // }
  2130. // pNode = pNextNode;
  2131. // }
  2132. // }
  2133. // pmay: 277801
  2134. //
  2135. // Update the preferred device if the one selected is different
  2136. // from the device this page was initialized with.
  2137. //
  2138. // if ((pInfo->fMultipleDevices) &&
  2139. // (DtlGetNodes(pInfo->pEntry->pdtllistLinks) == 1))
  2140. // {
  2141. // DTLNODE* pNodeL;
  2142. // PBLINK* pLink;
  2143. // BOOL bUpdatePref = FALSE;
  2144. // pNodeL = DtlGetFirstNode( pInfo->pEntry->pdtllistLinks );
  2145. // pLink = (PBLINK*) DtlGetData( pNodeL );
  2146. // TRACE( "Mult devs, only one selected -- check preferred dev." );
  2147. // if ((pInfo->pszCurDevice == NULL) || (pInfo->pszCurPort == NULL))
  2148. // {
  2149. // TRACE( "No preferred device. Resetting preferred to current." );
  2150. // bUpdatePref = TRUE;
  2151. // }
  2152. // else if (
  2153. // (lstrcmpi(pInfo->pszCurDevice, pLink->pbport.pszDevice)) ||
  2154. // (lstrcmpi(pInfo->pszCurPort, pLink->pbport.pszPort)))
  2155. // {
  2156. // TRACE( "New device selected as preferred device" );
  2157. // bUpdatePref = TRUE;
  2158. // }
  2159. // if (bUpdatePref)
  2160. // {
  2161. // Free0(pInfo->pEntry->pszPreferredDevice);
  2162. // Free0(pInfo->pEntry->pszPreferredPort);
  2163. // pInfo->pEntry->pszPreferredDevice =
  2164. // StrDup(pLink->pbport.pszDevice);
  2165. // pInfo->pEntry->pszPreferredPort =
  2166. // StrDup(pLink->pbport.pszPort);
  2167. // }
  2168. // }
  2169. // Save preferences if they've changed.
  2170. //
  2171. // if (pInfo->pUser->fDirty)
  2172. // {
  2173. // INTERNALARGS *pIArgs = (INTERNALARGS *)pInfo->pApiArgs->reserved;
  2174. // if (g_pSetUserPreferences(
  2175. // (pIArgs) ? pIArgs->hConnection : NULL,
  2176. // pInfo->pUser,
  2177. // (pInfo->fRouter) ? UPM_Router : UPM_Normal ) != 0)
  2178. // {
  2179. // return FALSE;
  2180. // }
  2181. // }
  2182. // Save the changed phonebook entry.
  2183. //
  2184. // pInfo->pEntry->fDirty = TRUE;
  2185. // The final name of the entry is output to caller via API structure.
  2186. //
  2187. // lstrcpyn(
  2188. // pInfo->pApiArgs->szEntry,
  2189. // pInfo->pEntry->pszEntryName,
  2190. // RAS_MaxEntryName + 1);
  2191. // Delete the old node if in edit mode, then add the new node.
  2192. //
  2193. // EuGetEditFlags( pInfo, &fEditMode, &fChangedNameInEditMode );
  2194. // if (fEditMode)
  2195. // {
  2196. // DtlDeleteNode( pInfo->pFile->pdtllistEntries, pInfo->pOldNode );
  2197. // }
  2198. // DtlAddNodeLast( pInfo->pFile->pdtllistEntries, pInfo->pNode );
  2199. // pInfo->pNode = NULL;
  2200. // Write the change to the phone book file.
  2201. //
  2202. // dwErr = WritePhonebookFile( pInfo->pFile,
  2203. // (fChangedNameInEditMode) ? pInfo->szOldEntryName : NULL );
  2204. // if (dwErr != 0)
  2205. // {
  2206. // ErrorDlg( pInfo->pApiArgs->hwndOwner, SID_OP_WritePhonebook, dwErr,
  2207. // NULL );
  2208. // // shaunco - fix RAID 171651 by assigning dwErr to callers structure.
  2209. // pInfo->pApiArgs->dwError = dwErr;
  2210. // return FALSE;
  2211. // }
  2212. // Notify through rasman that the entry has changed
  2213. //
  2214. // if(pInfo->pApiArgs->dwFlags & (RASEDFLAG_AnyNewEntry | RASEDFLAG_CloneEntry))
  2215. // {
  2216. // dwErr = DwSendRasNotification(
  2217. // ENTRY_ADDED,
  2218. // pInfo->pEntry,
  2219. // pInfo->pFile->pszPath);
  2220. // }
  2221. // else
  2222. // {
  2223. // dwErr = DwSendRasNotification(
  2224. // ENTRY_MODIFIED,
  2225. // pInfo->pEntry,
  2226. // pInfo->pFile->pszPath);
  2227. // }
  2228. // Ignore the error returned from DwSendRasNotification - we don't want
  2229. // to fail the operation in this case. The worst case scenario is that
  2230. // the connections folder won't refresh automatically.
  2231. //
  2232. // dwErr = ERROR_SUCCESS;
  2233. // If EuCommit is being called as a result of completing the "new demand
  2234. // dial interface" wizard, then we need to create the new demand dial
  2235. // interface now.
  2236. //
  2237. // if ( EuRouterInterfaceIsNew( pInfo ) )
  2238. // {
  2239. //Create Router MPR interface and save user credentials
  2240. //like UserName, Domain and Password
  2241. //IPSec credentials are save in EuCredentialsCommitRouterIPSec
  2242. //
  2243. // dwErr = EuRouterInterfaceCreate( pInfo );
  2244. // If we weren't successful at commiting the interface's
  2245. // credentials, then delete the new phonebook entry.
  2246. //
  2247. // if ( dwErr != NO_ERROR )
  2248. // {
  2249. // WritePhonebookFile( pInfo->pFile, pInfo->pApiArgs->szEntry );
  2250. // pInfo->pApiArgs->dwError = dwErr;
  2251. // return FALSE;
  2252. // }
  2253. // }
  2254. // Now save any per-connection credentials
  2255. //
  2256. // dwErr = EuCredentialsCommit( pInfo );
  2257. // If we weren't successful at commiting the interface's
  2258. // credentials, then delete the new phonebook entry.
  2259. //
  2260. // if ( dwErr != NO_ERROR )
  2261. // {
  2262. // ErrorDlg( pInfo->pApiArgs->hwndOwner,
  2263. // SID_OP_CredCommit,
  2264. // dwErr,
  2265. // NULL );
  2266. // pInfo->pApiArgs->dwError = dwErr;
  2267. // return FALSE;
  2268. // }
  2269. // Save the default Internet connection settings as appropriate. Igonre
  2270. // the error returned as failure to set the connection as default need
  2271. // not prevent the connection/interface creation.
  2272. //
  2273. // dwErr = EuInternetSettingsCommitDefault( pInfo );
  2274. // dwErr = NO_ERROR;
  2275. // If the user edited/created a router-phonebook entry, store the bitmask
  2276. // of selected network-protocols in 'reserved2'.
  2277. //
  2278. // if (pInfo->fRouter)
  2279. // {
  2280. // pInfo->pApiArgs->reserved2 =
  2281. // ((NP_Ip | NP_Ipx) & ~pInfo->pEntry->dwfExcludedProtocols);
  2282. // }
  2283. // Commit the user's changes to home networking settings.
  2284. // Ignore the return value.
  2285. //
  2286. dwErr = EuHomenetCommitSettings(pInfo);
  2287. dwErr = NO_ERROR;
  2288. // pInfo->pApiArgs->dwError = 0;
  2289. return TRUE;
  2290. }
  2291. DWORD EuHomenetCommitSettings(IN EINFO* pInfo)
  2292. {
  2293. HRESULT hr = S_OK;
  2294. ULONG ulcPublic;
  2295. ULONG ulcPrivate;
  2296. BOOL fPrivateConfigured = FALSE;
  2297. HNET_CONN_PROPERTIES *pProps;
  2298. DWORD dwErr = NO_ERROR;
  2299. BOOL fConflictMessageDisplayed = FALSE;
  2300. if (pInfo->fRouter)
  2301. {
  2302. return NO_ERROR;
  2303. }
  2304. if (!!pInfo->fShared != !!pInfo->fNewShared)
  2305. {
  2306. if (pInfo->fShared)
  2307. {
  2308. hr = pInfo->pIcsSettings->DisableIcs (&ulcPublic, &ulcPrivate);
  2309. }
  2310. else
  2311. {
  2312. // Check to see if the private connection is
  2313. // already properly configured
  2314. //
  2315. hr = pInfo->pPrivateLanConnection->GetProperties (&pProps);
  2316. if (SUCCEEDED(hr))
  2317. {
  2318. fPrivateConfigured = !!pProps->fIcsPrivate;
  2319. CoTaskMemFree(pProps);
  2320. }
  2321. if (pInfo->fOtherShared)
  2322. {
  2323. if (fPrivateConfigured)
  2324. {
  2325. // Using the same private connection, so
  2326. // only modify the old public
  2327. //
  2328. ASSERT(NULL != pInfo->pOldSharedConnection);
  2329. hr = pInfo->pOldSharedConnection->Unshare();
  2330. }
  2331. else
  2332. {
  2333. hr = pInfo->pIcsSettings->DisableIcs (&ulcPublic, &ulcPrivate);
  2334. }
  2335. }
  2336. if (SUCCEEDED(hr))
  2337. {
  2338. IHNetIcsPublicConnection *pIcsPublic;
  2339. IHNetIcsPrivateConnection *pIcsPrivate;
  2340. hr = pInfo->pHNetConn->SharePublic (&pIcsPublic);
  2341. if (SUCCEEDED(hr))
  2342. {
  2343. if (!fPrivateConfigured)
  2344. {
  2345. hr = pInfo->pPrivateLanConnection->SharePrivate (&pIcsPrivate);
  2346. if (SUCCEEDED(hr))
  2347. {
  2348. pIcsPrivate->Release();
  2349. }
  2350. else
  2351. {
  2352. pIcsPublic->Unshare();
  2353. }
  2354. }
  2355. pIcsPublic->Release();
  2356. }
  2357. }
  2358. if (hr == HRESULT_FROM_WIN32(ERROR_SHARING_RRAS_CONFLICT))
  2359. {
  2360. fConflictMessageDisplayed = TRUE;
  2361. MsgDlg(pInfo->hwndOwner, SID_SharingConflict, NULL);
  2362. }
  2363. else if (FAILED(hr))
  2364. {
  2365. if (FACILITY_WIN32 == HRESULT_FACILITY(hr))
  2366. {
  2367. dwErr = HRESULT_CODE(hr);
  2368. }
  2369. else
  2370. {
  2371. dwErr = (DWORD) hr;
  2372. }
  2373. ErrorDlg(
  2374. pInfo->hwndOwner,
  2375. pInfo->fShared
  2376. ? SID_OP_UnshareConnection : SID_OP_ShareConnection,
  2377. dwErr, NULL );
  2378. }
  2379. }
  2380. }
  2381. else if (pInfo->fResetPrivateAdapter && pInfo->dwLanCount)
  2382. {
  2383. IHNetIcsPrivateConnection *pIcsPrivateConnection;
  2384. hr = pInfo->pPrivateLanConnection->SharePrivate(&pIcsPrivateConnection);
  2385. if (SUCCEEDED(hr))
  2386. {
  2387. pIcsPrivateConnection->Release();
  2388. }
  2389. else
  2390. {
  2391. ULONG ulPublicCount, ulPrivateCount;
  2392. HRESULT hr2 = pInfo->pIcsSettings->DisableIcs(&ulPublicCount, &ulPrivateCount);
  2393. if (SUCCEEDED(hr2))
  2394. {
  2395. pInfo->fShared = FALSE;
  2396. }
  2397. ErrorDlg(pInfo->hwndOwner, SID_OP_ShareConnection, hr, NULL );
  2398. }
  2399. }
  2400. if (!!pInfo->fDemandDial != !!pInfo->fNewDemandDial)
  2401. {
  2402. dwErr = RasSetSharedAutoDial(pInfo->fNewDemandDial);
  2403. if (dwErr)
  2404. {
  2405. ErrorDlg(
  2406. pInfo->hwndOwner,
  2407. pInfo->fDemandDial
  2408. ? SID_OP_DisableDemandDial : SID_OP_EnableDemandDial,
  2409. dwErr, NULL );
  2410. }
  2411. }
  2412. HKEY hKey;
  2413. if(ERROR_SUCCESS == RegCreateKeyEx(HKEY_LOCAL_MACHINE, REGKEY_SHAREDACCESSCLIENTKEYPATH, 0, NULL, 0, KEY_SET_VALUE, NULL, &hKey, NULL))
  2414. {
  2415. DWORD dwData = pInfo->fNewBeaconControl;
  2416. RegSetValueEx(hKey, REGVAL_SHAREDACCESSCLIENTENABLECONTROL, 0, REG_DWORD, reinterpret_cast<LPBYTE>(&dwData), sizeof(dwData));
  2417. RegCloseKey(hKey);
  2418. }
  2419. // Commit changes to firewall settings
  2420. //
  2421. if (!!pInfo->fFirewalled != !!pInfo->fNewFirewalled)
  2422. {
  2423. IHNetFirewalledConnection *pFwConn;
  2424. if (pInfo->fNewFirewalled)
  2425. {
  2426. hr = pInfo->pHNetConn->Firewall (&pFwConn);
  2427. if (SUCCEEDED(hr))
  2428. {
  2429. pFwConn->Release();
  2430. }
  2431. }
  2432. else
  2433. {
  2434. hr = pInfo->pHNetConn->GetControlInterface (
  2435. IID_IHNetFirewalledConnection,
  2436. (void**)&pFwConn);
  2437. if (SUCCEEDED(hr))
  2438. {
  2439. hr = pFwConn->Unfirewall();
  2440. pFwConn->Release();
  2441. }
  2442. }
  2443. if (FAILED(hr))
  2444. {
  2445. if (FACILITY_WIN32 == HRESULT_FACILITY(hr))
  2446. {
  2447. dwErr = HRESULT_CODE(hr);
  2448. }
  2449. else
  2450. {
  2451. dwErr = (DWORD) hr;
  2452. }
  2453. if (dwErr != ERROR_SHARING_RRAS_CONFLICT)
  2454. {
  2455. ErrorDlg(
  2456. pInfo->hwndOwner,
  2457. pInfo->fFirewalled
  2458. ? SID_OP_UnshareConnection : SID_OP_ShareConnection,
  2459. dwErr, NULL );
  2460. }
  2461. else if (FALSE == fConflictMessageDisplayed)
  2462. {
  2463. MsgDlg(pInfo->hwndOwner, SID_SharingConflict, NULL);
  2464. }
  2465. }
  2466. }
  2467. return dwErr;
  2468. }
  2469. HRESULT APIENTRY
  2470. HrCreateNetConnectionUtilities(INetConnectionUiUtilities ** ppncuu)
  2471. {
  2472. HRESULT hr;
  2473. hr = CoCreateInstance (CLSID_NetConnectionUiUtilities, NULL,
  2474. CLSCTX_INPROC_SERVER,
  2475. IID_INetConnectionUiUtilities, (void**)ppncuu);
  2476. return hr;
  2477. }
  2478. // --------------------------------------------------------------------------
  2479. // exported function here
  2480. // --------------------------------------------------------------------------
  2481. static LPDLGTEMPLATE CopyDialogTemplate (HINSTANCE hinst, LPCWSTR wszResource)
  2482. {
  2483. LPDLGTEMPLATE lpdtCopy = NULL;
  2484. HRSRC hrsrc = FindResourceW (hinst, wszResource, (LPCWSTR)RT_DIALOG);
  2485. if (hrsrc) {
  2486. HGLOBAL hg = LoadResource (hinst, hrsrc);
  2487. if (hg) {
  2488. LPDLGTEMPLATE lpdt = (LPDLGTEMPLATE) LockResource (hg);
  2489. if (lpdt) {
  2490. DWORD dwSize = SizeofResource (hinst, hrsrc);
  2491. if (dwSize) {
  2492. lpdtCopy = (LPDLGTEMPLATE)Malloc (dwSize);
  2493. if (lpdtCopy) {
  2494. CopyMemory (lpdtCopy, lpdt, dwSize);
  2495. }
  2496. }
  2497. }
  2498. }
  2499. }
  2500. return lpdtCopy;
  2501. }
  2502. void SetSAUIhInstance (HINSTANCE hInstance)
  2503. {
  2504. _ASSERT (g_hinstDll == NULL);
  2505. _ASSERT (hInstance != NULL);
  2506. g_hinstDll = hInstance;
  2507. }
  2508. extern "C" HRESULT HNetGetFirewallSettingsPage (PROPSHEETPAGEW * pPSP, GUID * pGuid)
  2509. {
  2510. // zeroth thing: the PROPSHEETPAGEW struct is different sizes depending
  2511. // on what version of _WIN32_IE and _WIN32_WINNT are set to. So, check
  2512. // the dwSize field
  2513. if (IsBadWritePtr (pPSP, sizeof(DWORD)))
  2514. return E_POINTER;
  2515. if (IsBadWritePtr (pPSP, pPSP->dwSize))
  2516. return HRESULT_FROM_WIN32 (ERROR_INVALID_SIZE);
  2517. if (pPSP->dwSize < RTL_SIZEOF_THROUGH_FIELD (PROPSHEETPAGEW, lParam))
  2518. return HRESULT_FROM_WIN32 (ERROR_INVALID_SIZE);
  2519. // first thing: check rights
  2520. if (FALSE == FIsUserAdminOrPowerUser ())
  2521. return HRESULT_FROM_WIN32 (ERROR_ACCESS_DENIED);
  2522. {
  2523. // Check if ZAW is denying access to the Shared Access UI
  2524. BOOL fShowAdvancedUi = TRUE;
  2525. INetConnectionUiUtilities* pncuu = NULL;
  2526. HrCreateNetConnectionUtilities(&pncuu);
  2527. if (pncuu)
  2528. {
  2529. if ((FALSE == pncuu->UserHasPermission (NCPERM_ShowSharedAccessUi)) &&
  2530. (FALSE == pncuu->UserHasPermission (NCPERM_PersonalFirewallConfig)))
  2531. fShowAdvancedUi = FALSE;
  2532. pncuu->Release();
  2533. }
  2534. if (FALSE == fShowAdvancedUi)
  2535. return HRESULT_FROM_WIN32 (ERROR_ACCESS_DENIED);
  2536. }
  2537. // setup global(s)
  2538. g_contextId = (LPCTSTR)GlobalAddAtom (TEXT("SAUI"));
  2539. if (!g_contextId)
  2540. return GetLastError();
  2541. PEINFO * pPEINFO = NULL;
  2542. DWORD dwError = PeInit (pGuid, &pPEINFO);
  2543. if (dwError == S_OK) {
  2544. // we need this to init the link
  2545. LinkWindow_RegisterClass(); // no need to ever unregister: see ...\shell\shell32\linkwnd.cpp
  2546. // fill out PSP:
  2547. DWORD dwSize;
  2548. ZeroMemory (pPSP, dwSize = pPSP->dwSize);
  2549. pPSP->dwSize = dwSize;
  2550. pPSP->dwFlags = 0;
  2551. LPDLGTEMPLATE lpdt = CopyDialogTemplate (g_hinstDll, MAKEINTRESOURCE (PID_SA_Advanced));
  2552. if (lpdt) {
  2553. // avoid idd collisions
  2554. pPSP->dwFlags |= PSP_DLGINDIRECT;
  2555. pPSP->pResource = lpdt;
  2556. pPEINFO->lpdt = lpdt; // hang it here so I can free it
  2557. } else // if all else fails... (this should never happen).
  2558. pPSP->pszTemplate = MAKEINTRESOURCE (PID_SA_Advanced);
  2559. pPSP->hInstance = g_hinstDll;
  2560. pPSP->pfnDlgProc = SaDlgProc;
  2561. pPSP->lParam = (LPARAM)pPEINFO;
  2562. }
  2563. return dwError;
  2564. }
  2565. //
  2566. // Figure out if this is a single user connection. If it is, then we need
  2567. // to give them an error that explains that they should be using an all user
  2568. // connection instead.
  2569. // If this is an All-User connection, warn them if they don't have global credentials
  2570. //
  2571. VOID VerifyConnTypeAndCreds(IN PEINFO* pInfo)
  2572. {
  2573. if (NULL == pInfo)
  2574. {
  2575. return;
  2576. }
  2577. BOOL fAllUser = FALSE;
  2578. TCHAR szAppData[MAX_PATH+1]={0};
  2579. HINSTANCE hinstDll = LoadLibrary (TEXT("shfolder.dll"));;
  2580. if (hinstDll)
  2581. {
  2582. typedef HRESULT (*pfnGetFolderPathFunction) (HWND, int, HANDLE, DWORD, LPTSTR);
  2583. #ifdef UNICODE
  2584. pfnGetFolderPathFunction pfnGetFolderPath = (pfnGetFolderPathFunction)GetProcAddress (hinstDll, "SHGetFolderPathW");
  2585. #else
  2586. pfnGetFolderPathFunction pfnGetFolderPath = (pfnGetFolderPathFunction)GetProcAddress (hinstDll, "SHGetFolderPathA");
  2587. #endif
  2588. if (pfnGetFolderPath && pInfo->pArgs->pEntry->pszEntryName)
  2589. {
  2590. HRESULT hr = pfnGetFolderPath(pInfo->hwndDlg , CSIDL_COMMON_APPDATA, NULL, 0, szAppData);
  2591. if (SUCCEEDED(hr) && (S_FALSE != hr))
  2592. {
  2593. //
  2594. // Okay, now we have the path to the common application data directory.
  2595. // Let's compare that against the phonebook path that we have and see
  2596. // if this is an all user connection or not.
  2597. //
  2598. const TCHAR* const c_pszRelativePbkPath = TEXT("\\Microsoft\\Network\\Connections\\Pbk");
  2599. DWORD dwSize = (lstrlen(szAppData) + lstrlen(c_pszRelativePbkPath) + 1) * sizeof(TCHAR);
  2600. LPTSTR pszAllUserPhoneBookDir = (LPTSTR)Malloc(dwSize);
  2601. if (pszAllUserPhoneBookDir)
  2602. {
  2603. wsprintf(pszAllUserPhoneBookDir, TEXT("%s%s"), szAppData, c_pszRelativePbkPath);
  2604. //
  2605. // Compare
  2606. //
  2607. if (pInfo->pArgs->pEntry->pszPhonebookPath)
  2608. {
  2609. LPTSTR pszAllUser = _tcsstr(pInfo->pArgs->pEntry->pszPhonebookPath, pszAllUserPhoneBookDir);
  2610. if (pszAllUser)
  2611. {
  2612. fAllUser = TRUE;
  2613. }
  2614. else
  2615. {
  2616. //
  2617. // If the phonebook path wasn't based on the common app data dir, check to see
  2618. // if it was based on the old ras phonebook location %windir%\system32\ras.
  2619. //
  2620. HRESULT hr2 = pfnGetFolderPath(pInfo->hwndDlg , CSIDL_SYSTEM, NULL, 0, szAppData);
  2621. if (SUCCEEDED(hr2) && (S_FALSE != hr2))
  2622. {
  2623. const TCHAR* const c_pszRas = TEXT("\\Ras");
  2624. DWORD dwSize2 = (lstrlen(szAppData) + lstrlen(c_pszRas) + 1) * sizeof(TCHAR);
  2625. LPTSTR pszOldRasPhoneBook = (LPTSTR)Malloc(dwSize2);
  2626. if (pszOldRasPhoneBook)
  2627. {
  2628. wsprintf(pszOldRasPhoneBook, TEXT("%s%s"), szAppData, c_pszRas);
  2629. pszAllUser = _tcsstr(pInfo->pArgs->pEntry->pszPhonebookPath, pszOldRasPhoneBook);
  2630. if (pszAllUser)
  2631. {
  2632. fAllUser = TRUE;
  2633. }
  2634. }
  2635. Free0(pszOldRasPhoneBook);
  2636. }
  2637. }
  2638. }
  2639. else
  2640. {
  2641. //
  2642. // Phone book string is null - using default RAS phonebook which is for all users
  2643. //
  2644. fAllUser = TRUE;
  2645. }
  2646. //
  2647. // Finally check if we have the proper credentials for an all user profile. If not then
  2648. // prompt user to create and save global credentials (option A).
  2649. // or display a message that an all-user profile is needed (option B)
  2650. //
  2651. if (fAllUser)
  2652. {
  2653. //
  2654. // Check if we have global passwords
  2655. //
  2656. BOOL fUserCreds = FALSE;
  2657. BOOL fGlobalCreds = FALSE;
  2658. FindEntryCredentials(pInfo->pArgs->pEntry->pszPhonebookPath,
  2659. pInfo->pArgs->pEntry->pszEntryName,
  2660. &fUserCreds,
  2661. &fGlobalCreds);
  2662. if (FALSE == fGlobalCreds)
  2663. {
  2664. //
  2665. // need to display warning message (A) - should have global creds
  2666. //
  2667. MSGARGS msgargs;
  2668. ZeroMemory( &msgargs, sizeof(msgargs) );
  2669. msgargs.dwFlags = MB_OK | MB_ICONINFORMATION;
  2670. MsgDlg( pInfo->hwndDlg, IDS_ALL_USER_CONN_MUST_HAVE_GLOBAL_CREDS, &msgargs );
  2671. }
  2672. }
  2673. else
  2674. {
  2675. //
  2676. // need to display warning message (B) - should create an all-user connection
  2677. //
  2678. MSGARGS msgargs;
  2679. ZeroMemory( &msgargs, sizeof(msgargs) );
  2680. msgargs.dwFlags = MB_OK | MB_ICONINFORMATION;
  2681. MsgDlg( pInfo->hwndDlg, IDS_PER_USER_CONN_NEED_TO_CREATE_ALL_USER_CONN, &msgargs );
  2682. }
  2683. }
  2684. Free0(pszAllUserPhoneBookDir);
  2685. }
  2686. }
  2687. FreeLibrary(hinstDll);
  2688. }
  2689. }
  2690. //
  2691. // All of this function is taken from RAS - rasdlg - dial.c
  2692. // with some parts removed since we didn't need them here.
  2693. //
  2694. DWORD
  2695. FindEntryCredentials(
  2696. IN TCHAR* pszPath,
  2697. IN TCHAR* pszEntryName,
  2698. OUT BOOL* pfUser, // set true if per user creds found
  2699. OUT BOOL* pfGlobal // set true if global creds found
  2700. )
  2701. // Loads the credentials for the given entry into memory. This routine
  2702. // determines whether per-user or per-connection credentials exist or
  2703. // both.
  2704. //
  2705. // The logic is a little complicated because RasGetCredentials had to
  2706. // support legacy usage of the API.
  2707. //
  2708. // Here's how it works. If only one set of credentials is stored for a
  2709. // connection, then RasGetCredentials will return that set regardless of
  2710. // whether the RASCM_DefalutCreds flag is set. If two sets of credentials
  2711. // are saved, then RasGetCredentials will return the per-user credentials
  2712. // if the RASCM_DefaultCreds bit is set, and the per-connection credentials
  2713. // otherwise.
  2714. //
  2715. // Here is the algorithm for loading the credentials
  2716. //
  2717. // 1. Call RasGetCredentials with the RASCM_DefaultCreds bit cleared
  2718. // 1a. If nothing is returned, no credentials are saved
  2719. // 1b. If the RASCM_DefaultCreds bit is set on return, then only
  2720. // global credentials are saved.
  2721. //
  2722. // 2. Call RasGetCredentials with the RASCM_DefaultCreds bit set
  2723. // 2a. If the RASCM_DefaultCreds bit is set on return, then
  2724. // both global and per-connection credentials are saved.
  2725. // 2b. Otherwise, only per-user credentials are saved.
  2726. //
  2727. {
  2728. DWORD dwErr;
  2729. RASCREDENTIALS rc1, rc2;
  2730. BOOL fUseLogonDomain;
  2731. TRACE( "saui.cpp - FindEntryCredentials" );
  2732. // Initialize
  2733. //
  2734. *pfUser = FALSE;
  2735. *pfGlobal = FALSE;
  2736. ZeroMemory( &rc1, sizeof(rc1) );
  2737. ZeroMemory( &rc2, sizeof(rc2) );
  2738. rc1.dwSize = sizeof(rc1);
  2739. rc2.dwSize = sizeof(rc2);
  2740. if (NULL == pszPath || NULL == pszEntryName)
  2741. {
  2742. return (DWORD)-1;
  2743. }
  2744. do
  2745. {
  2746. // Look up per-user cached username, password, and domain.
  2747. // See comment '1.' in the function header
  2748. //
  2749. rc1.dwMask = RASCM_UserName | RASCM_Password | RASCM_Domain;
  2750. TRACE( "RasGetCredentials per-user" );
  2751. dwErr = RasGetCredentials(pszPath, pszEntryName, &rc1 );
  2752. TRACE2( "RasGetCredentials=%d,m=%d", dwErr, rc1.dwMask );
  2753. if (dwErr != NO_ERROR)
  2754. {
  2755. break;
  2756. }
  2757. // See 1a. in the function header comments
  2758. //
  2759. if (rc1.dwMask == 0)
  2760. {
  2761. dwErr = NO_ERROR;
  2762. break;
  2763. }
  2764. // See 1b. in the function header comments
  2765. //
  2766. else if (rc1.dwMask & RASCM_DefaultCreds)
  2767. {
  2768. *pfGlobal = TRUE;
  2769. dwErr = NO_ERROR;
  2770. break;
  2771. }
  2772. // Look up global per-user cached username, password, domain.
  2773. // See comment 2. in the function header
  2774. //
  2775. rc2.dwMask =
  2776. RASCM_UserName | RASCM_Password | RASCM_Domain | RASCM_DefaultCreds;
  2777. TRACE( "RasGetCredentials global" );
  2778. dwErr = RasGetCredentials(pszPath, pszEntryName, &rc2 );
  2779. TRACE2( "RasGetCredentials=%d,m=%d", dwErr, rc2.dwMask );
  2780. if (dwErr != NO_ERROR)
  2781. {
  2782. break;
  2783. }
  2784. // See 2a. in the function header comments
  2785. //
  2786. if (rc2.dwMask & RASCM_DefaultCreds)
  2787. {
  2788. *pfGlobal = TRUE;
  2789. if (rc1.dwMask & RASCM_Password)
  2790. {
  2791. *pfUser = TRUE;
  2792. }
  2793. }
  2794. // See 2b. in the function header comments
  2795. //
  2796. else
  2797. {
  2798. if (rc1.dwMask & RASCM_Password)
  2799. {
  2800. *pfUser = TRUE;
  2801. }
  2802. }
  2803. }while (FALSE);
  2804. // Cleanup
  2805. //
  2806. SecureZeroMemory( rc1.szPassword, sizeof(rc1.szPassword) );
  2807. SecureZeroMemory( rc2.szPassword, sizeof(rc2.szPassword) );
  2808. return dwErr;
  2809. }