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.

535 lines
16 KiB

  1. //-----------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: A U N I F U N C . C P P
  7. //
  8. // Contents: CAtmUniCfg help member function implementation
  9. //
  10. // Notes:
  11. //
  12. // Author: tongl 21 Mar 1997
  13. //
  14. //-----------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "auniobj.h"
  18. #include "aunidlg.h"
  19. #include "atmutil.h"
  20. #include "ncmisc.h"
  21. #include "ncreg.h"
  22. #include "ncstl.h"
  23. #include "ncatlui.h"
  24. //#include "ncui.h"
  25. #include "netconp.h"
  26. #include "atmhelp.h"
  27. extern const WCHAR c_szAdapters[];
  28. //
  29. // Load cards on bind path to m_listAdapters on Initialize
  30. //
  31. HRESULT CAtmUniCfg::HrLoadSettings()
  32. {
  33. HRESULT hr = S_OK;
  34. CIterNetCfgBindingPath ncbpIter(m_pnccUni);
  35. INetCfgBindingPath * pncbp;
  36. // Go through all binding paths in search of uni call mgr to netcard bindings
  37. while(SUCCEEDED(hr) && (hr = ncbpIter.HrNext(&pncbp)) == S_OK)
  38. {
  39. INetCfgComponent * pnccNetComponent;
  40. hr = HrGetLastComponentAndInterface(pncbp,
  41. &pnccNetComponent,
  42. NULL);
  43. if SUCCEEDED(hr)
  44. {
  45. Assert(pnccNetComponent);
  46. // The last component should be of NET CLASS
  47. GUID ClassGuid;
  48. // What type is it?
  49. hr = pnccNetComponent->GetClassGuid(&ClassGuid);
  50. if (SUCCEEDED(hr))
  51. {
  52. // Is it a netcard?
  53. if (IsEqualGUID(ClassGuid, GUID_DEVCLASS_NET))
  54. {
  55. hr = HrAddAdapter(pnccNetComponent);
  56. if (SUCCEEDED(hr))
  57. {
  58. // Is the binding enabled ??
  59. hr = pncbp->IsEnabled();
  60. // hr == S_OK if the card is enabled (ie: bound)
  61. if (S_OK == hr)
  62. { // bind the card in our data strucutres
  63. hr = HrBindAdapter(pnccNetComponent);
  64. }
  65. else if (S_FALSE == hr)
  66. {
  67. hr = HrUnBindAdapter(pnccNetComponent);
  68. }
  69. }
  70. }
  71. }
  72. ReleaseObj(pnccNetComponent);
  73. }
  74. ReleaseObj(pncbp);
  75. }
  76. AssertSz(!pncbp, "BindingPath wasn't released");
  77. if (hr == S_FALSE) // We just got to the end of the loop
  78. hr = S_OK;
  79. TraceError("CAtmUniCfg::HrLoadSettings", hr);
  80. return hr;
  81. }
  82. //
  83. // Update registry with info in m_listAdapters on Apply
  84. //
  85. HRESULT CAtmUniCfg::HrSaveSettings()
  86. {
  87. HRESULT hr = S_OK;
  88. HKEY hkeyUniParam = NULL;
  89. hr = m_pnccUni->OpenParamKey(&hkeyUniParam);
  90. if SUCCEEDED(hr)
  91. {
  92. HKEY hkeyAdapters = NULL;
  93. DWORD dwDisposition;
  94. // Create or open the "Adapters" key under "Services\Atmuni\Parameters"
  95. hr = HrRegCreateKeyEx(hkeyUniParam,
  96. c_szAdapters,
  97. REG_OPTION_NON_VOLATILE,
  98. KEY_ALL_ACCESS,
  99. NULL,
  100. &hkeyAdapters,
  101. &dwDisposition);
  102. if SUCCEEDED(hr)
  103. {
  104. Assert(hkeyAdapters);
  105. HRESULT hrTmp = S_OK;
  106. if (dwDisposition == REG_OPENED_EXISTING_KEY)
  107. { // if the "adapters" key existed, there might be some old cards
  108. // Cleanup subkeys for adapters that are not in our memory structure
  109. VECSTR vstrAdapters;
  110. hrTmp = HrLoadSubkeysFromRegistry(hkeyAdapters, &vstrAdapters);
  111. if SUCCEEDED(hrTmp)
  112. {
  113. for (VECSTR::iterator iterRegKey = vstrAdapters.begin();
  114. iterRegKey != vstrAdapters.end();
  115. iterRegKey ++)
  116. {
  117. BOOL fFound = FALSE;
  118. for (UNI_ADAPTER_LIST::iterator iterAdapter = m_listAdapters.begin();
  119. iterAdapter != m_listAdapters.end();
  120. iterAdapter ++)
  121. {
  122. if ((*iterAdapter)->m_strBindName == (*iterRegKey)->c_str())
  123. {
  124. fFound = TRUE;
  125. break;
  126. }
  127. }
  128. if ((!fFound) ||
  129. ( fFound && ((*iterAdapter)->m_fDeleted)))
  130. {
  131. hrTmp = HrRegDeleteKeyTree(hkeyAdapters,
  132. (*iterRegKey)->c_str());
  133. if SUCCEEDED(hr)
  134. hr = hrTmp;
  135. }
  136. }
  137. }
  138. }
  139. // Save adapter info in memory state to registry
  140. for (UNI_ADAPTER_LIST::iterator iterAdapter = m_listAdapters.begin();
  141. iterAdapter != m_listAdapters.end();
  142. iterAdapter ++)
  143. {
  144. if ((*iterAdapter)->m_fDeleted)
  145. continue;
  146. HKEY hkeyAdapterParam;
  147. // Create specific card bindname key under
  148. // "Services\Atmuni\Parameters\Adapters\<card bind name>"
  149. hrTmp = HrRegCreateKeyEx(hkeyAdapters,
  150. (*iterAdapter)->m_strBindName.c_str(),
  151. REG_OPTION_NON_VOLATILE,
  152. KEY_ALL_ACCESS,
  153. NULL,
  154. &hkeyAdapterParam,
  155. &dwDisposition);
  156. if(SUCCEEDED(hrTmp))
  157. hr = hrTmp;
  158. if(SUCCEEDED(hrTmp))
  159. {
  160. #if 0
  161. // $REVIEW(tongl 4/27/98): Per ArvindM, we should no longer
  162. // write these to registry.
  163. // save defaults for SVC parameters for new adapters
  164. if (dwDisposition != REG_OPENED_EXISTING_KEY)
  165. {
  166. hrTmp = HrSaveDefaultSVCParam(hkeyAdapterParam);
  167. if SUCCEEDED(hr)
  168. hr = hrTmp;
  169. }
  170. #endif
  171. // Now update any PVC parameters
  172. // Only need to update PVC parameters for the Adapter of the
  173. // current connection, and if changes are made through the UI
  174. if (m_fUIParamChanged)
  175. {
  176. if (FIsSubstr(m_strGuidConn.c_str(), (*iterAdapter)->m_strBindName.c_str()))
  177. {
  178. if ((*iterAdapter)->m_listPVCs.size() > 0)
  179. {
  180. hrTmp = HrSaveAdapterPVCRegistry(hkeyAdapterParam, *iterAdapter);
  181. if SUCCEEDED(hr)
  182. hr = hrTmp;
  183. }
  184. }
  185. }
  186. }
  187. RegSafeCloseKey(hkeyAdapterParam);
  188. }
  189. }
  190. RegSafeCloseKey(hkeyAdapters);
  191. }
  192. RegSafeCloseKey(hkeyUniParam);
  193. TraceError("CAtmUniCfg::HrSaveSettings", hr);
  194. return hr;
  195. }
  196. // Adding a card
  197. HRESULT CAtmUniCfg::HrAddAdapter(INetCfgComponent * pnccAdapter)
  198. {
  199. PWSTR pszwBindName = NULL;
  200. HRESULT hr = pnccAdapter->GetBindName(&pszwBindName);
  201. AssertSz( SUCCEEDED(hr), "Net card on binding path with no bind path name!!");
  202. CUniAdapterInfo * pAdapterInfo = NULL;
  203. if (fIsAdapterOnList(pszwBindName, &pAdapterInfo))
  204. {
  205. AssertSz(pAdapterInfo->m_fDeleted, "Trying to add a card that already exists on binding path");
  206. pAdapterInfo->m_fDeleted = FALSE;
  207. }
  208. else // Add a new item
  209. {
  210. // create a new item
  211. m_listAdapters.push_back(new CUniAdapterInfo);
  212. m_listAdapters.back()->SetDefaults(pszwBindName);
  213. }
  214. CoTaskMemFree(pszwBindName);
  215. TraceError("CAtmUniCfg::HrAddAdapter", hr);
  216. return hr;
  217. }
  218. // Removing a card
  219. HRESULT CAtmUniCfg::HrRemoveAdapter(INetCfgComponent * pnccAdapter)
  220. {
  221. PWSTR pszwBindName = NULL;
  222. HRESULT hr = pnccAdapter->GetBindName(&pszwBindName);
  223. AssertSz( SUCCEEDED(hr), "Net card on binding path with no bind path name!!");
  224. CUniAdapterInfo * pAdapterInfo = NULL;
  225. if (!fIsAdapterOnList(pszwBindName, &pAdapterInfo))
  226. {
  227. AssertSz(FALSE, "Trying to remove a card that does not exists on binding path");
  228. }
  229. else // remove the card
  230. {
  231. // mark the adapter as for removal
  232. pAdapterInfo->m_fDeleted = TRUE;
  233. }
  234. CoTaskMemFree(pszwBindName);
  235. TraceError("CAtmUniCfg::HrRemoveAdapter", hr);
  236. return hr;
  237. }
  238. // Set binding state to enabled
  239. HRESULT CAtmUniCfg::HrBindAdapter(INetCfgComponent * pnccAdapter)
  240. {
  241. PWSTR pszwBindName = NULL;
  242. HRESULT hr = pnccAdapter->GetBindName(&pszwBindName);
  243. AssertSz(SUCCEEDED(hr), "Net card on binding path with no bind path name!!");
  244. CUniAdapterInfo * pAdapterInfo = NULL;
  245. if (!fIsAdapterOnList(pszwBindName, &pAdapterInfo))
  246. {
  247. AssertSz(FALSE, "Trying to bind a card that does not exists on binding path");
  248. }
  249. else // bind the adapter
  250. {
  251. pAdapterInfo->m_BindingState = BIND_ENABLE;
  252. }
  253. CoTaskMemFree(pszwBindName);
  254. TraceError("CAtmUniCfg::HrBindAdapter", hr);
  255. return hr;
  256. }
  257. // Set binding state to disabled
  258. HRESULT CAtmUniCfg::HrUnBindAdapter(INetCfgComponent * pnccAdapter)
  259. {
  260. PWSTR pszwBindName = NULL;
  261. HRESULT hr = pnccAdapter->GetBindName(&pszwBindName);
  262. AssertSz(SUCCEEDED(hr), "Net card on binding path with no bind path name!!");
  263. CUniAdapterInfo * pAdapterInfo = NULL;
  264. if (!fIsAdapterOnList(pszwBindName, &pAdapterInfo))
  265. {
  266. AssertSz(FALSE, "Trying to unbind a card that does not exists on binding path");
  267. }
  268. else // unbind the adapter
  269. {
  270. pAdapterInfo->m_BindingState = BIND_DISABLE;
  271. }
  272. CoTaskMemFree(pszwBindName);
  273. TraceError("CAtmUniCfg::HrUnBindAdapter", hr);
  274. return hr;
  275. }
  276. //
  277. // Save default values of non-configurable params to registry
  278. //
  279. HRESULT CAtmUniCfg::HrSaveDefaultSVCParam(HKEY hkey)
  280. {
  281. HRESULT hr = S_OK;
  282. PRODUCT_FLAVOR pf;
  283. // NT server and workstation has different default values
  284. GetProductFlavor(NULL, &pf);
  285. AssertSz( ((pf == PF_WORKSTATION) || (pf == PF_SERVER)),
  286. "Invalid product flavor.");
  287. HRESULT hrTmp = S_OK;
  288. switch (pf)
  289. {
  290. case PF_WORKSTATION:
  291. hr = HrRegSetDword(hkey,c_szMaxActiveSVCs,c_dwWksMaxActiveSVCs);
  292. if SUCCEEDED(hr)
  293. hr = hrTmp;
  294. hr = HrRegSetDword(hkey,c_szMaxSVCsInProgress,c_dwWksMaxSVCsInProgress);
  295. if SUCCEEDED(hr)
  296. hr = hrTmp;
  297. hr = HrRegSetDword(hkey,c_szMaxPMPSVCs,c_dwWksMaxPMPSVCs);
  298. if SUCCEEDED(hr)
  299. hr = hrTmp;
  300. hr = HrRegSetDword(hkey,c_szMaxActiveParties,c_dwWksMaxActiveParties);
  301. if SUCCEEDED(hr)
  302. hr = hrTmp;
  303. hr = HrRegSetDword(hkey,c_szMaxPartiesInProgress,c_dwWksMaxPartiesInProgress);
  304. if SUCCEEDED(hr)
  305. hr = hrTmp;
  306. break;
  307. case PF_SERVER:
  308. hr = HrRegSetDword(hkey,c_szMaxActiveSVCs,c_dwSrvMaxActiveSVCs);
  309. if SUCCEEDED(hr)
  310. hr = hrTmp;
  311. hr = HrRegSetDword(hkey,c_szMaxSVCsInProgress,c_dwSrvMaxSVCsInProgress);
  312. if SUCCEEDED(hr)
  313. hr = hrTmp;
  314. hr = HrRegSetDword(hkey,c_szMaxPMPSVCs,c_dwSrvMaxPMPSVCs);
  315. if SUCCEEDED(hr)
  316. hr = hrTmp;
  317. hr = HrRegSetDword(hkey,c_szMaxActiveParties,c_dwSrvMaxActiveParties);
  318. if SUCCEEDED(hr)
  319. hr = hrTmp;
  320. hr = HrRegSetDword(hkey,c_szMaxPartiesInProgress,c_dwSrvMaxPartiesInProgress);
  321. if SUCCEEDED(hr)
  322. hr = hrTmp;
  323. break;
  324. }
  325. TraceError("CAtmUniCfg::HrSaveDefaultSVCParam", hr);
  326. return hr;
  327. }
  328. // Checks if a card is on m_listAdapters
  329. BOOL CAtmUniCfg::fIsAdapterOnList(PCWSTR pszBindName, CUniAdapterInfo ** ppAdapterInfo)
  330. {
  331. BOOL fRet = FALSE;
  332. *ppAdapterInfo = NULL;
  333. for (UNI_ADAPTER_LIST::iterator iterAdapter = m_listAdapters.begin();
  334. iterAdapter != m_listAdapters.end();
  335. iterAdapter ++)
  336. {
  337. if ((*iterAdapter)->m_strBindName == pszBindName)
  338. {
  339. fRet = TRUE;
  340. *ppAdapterInfo = *iterAdapter;
  341. break;
  342. }
  343. }
  344. return fRet;
  345. }
  346. // Called by CAtmUniCfg::MergePropPages
  347. // Set the context in which the UI is brought up
  348. HRESULT CAtmUniCfg::HrSetConnectionContext()
  349. {
  350. AssertSz(m_pUnkContext, "Invalid IUnknown pointer passed to CAtmUniCfg::SetContext?");
  351. if (!m_pUnkContext)
  352. return E_FAIL;
  353. HRESULT hr = S_OK;
  354. GUID guidConn;
  355. // Is this a lan connection ?
  356. INetLanConnectionUiInfo * pLanConnUiInfo;
  357. hr = m_pUnkContext->QueryInterface( IID_INetLanConnectionUiInfo,
  358. reinterpret_cast<LPVOID *>(&pLanConnUiInfo));
  359. if (SUCCEEDED(hr))
  360. {
  361. // yes, lan connection
  362. pLanConnUiInfo->GetDeviceGuid(&guidConn);
  363. ReleaseObj(pLanConnUiInfo);
  364. WCHAR szGuid[c_cchGuidWithTerm];
  365. BOOL fSucceeded = StringFromGUID2(guidConn,
  366. szGuid,
  367. c_cchGuidWithTerm);
  368. Assert(fSucceeded);
  369. m_strGuidConn = szGuid;
  370. }
  371. TraceError("CAtmUniCfg::HrSetConnectionContext", hr);
  372. return hr;
  373. }
  374. // Called by CAtmUniCfg::MergePropPages
  375. // Inits the prop sheet page objects and creates the pages to be returned to
  376. // the installer object.
  377. HRESULT CAtmUniCfg::HrSetupPropSheets(HPROPSHEETPAGE **pahpsp, INT * pcPages)
  378. {
  379. HRESULT hr = S_OK;
  380. // initialize output parameters
  381. *pahpsp = NULL;
  382. *pcPages = 0;
  383. int cPages = 0;
  384. HPROPSHEETPAGE *ahpsp = NULL;
  385. m_fSecondMemoryModified = FALSE;
  386. // If PVC info has not been read from registry yet, load them
  387. if (!m_fPVCInfoLoaded)
  388. {
  389. hr = HrLoadPVCRegistry();
  390. m_fPVCInfoLoaded = TRUE;
  391. }
  392. if SUCCEEDED(hr)
  393. {
  394. // Copy PVC info of the corrent adapter to second memory
  395. hr = HrLoadAdapterPVCInfo();
  396. }
  397. // If we have found the matching adapter
  398. if SUCCEEDED(hr)
  399. {
  400. cPages = 1;
  401. delete m_uniPage;
  402. m_uniPage = new CUniPage(this, g_aHelpIDs_IDD_UNI_PROP);
  403. // Allocate a buffer large enough to hold the handles to all of our
  404. // property pages.
  405. ahpsp = (HPROPSHEETPAGE *)CoTaskMemAlloc(sizeof(HPROPSHEETPAGE)
  406. * cPages);
  407. if (!ahpsp)
  408. {
  409. hr = E_OUTOFMEMORY;
  410. goto err;
  411. }
  412. cPages =0;
  413. ahpsp[cPages++] = m_uniPage->CreatePage(IDD_UNI_PROP, 0);
  414. *pahpsp = ahpsp;
  415. *pcPages = cPages;
  416. }
  417. else // if the adapter is not bound, pop-up message box and don't show UI
  418. {
  419. NcMsgBox(::GetActiveWindow(),
  420. IDS_MSFT_UNI_TEXT,
  421. IDS_UNI_NO_BOUND_CARDS,
  422. MB_APPLMODAL | MB_ICONEXCLAMATION | MB_OK);
  423. AssertSz((0== *pcPages), "Invalid page number when no bound cards");
  424. AssertSz((NULL == *pahpsp), "Invalid page array pointer when no bound cards");
  425. }
  426. err:
  427. TraceError("CAtmUniCfg::HrSetupPropSheets", hr);
  428. return hr;
  429. }