Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2144 lines
50 KiB

  1. /*
  2. File netcfgdb.c
  3. Implements a database abstraction on top of the net config
  4. items needed by the ras server ui for connections.
  5. Paul Mayfield, 12/15/97
  6. */
  7. #include <rassrv.h>
  8. #include "protedit.h"
  9. // Macro for bounds checking
  10. #define netDbBoundsCheck(db, ind) (((ind) < (db)->dwCompCount) ? TRUE : FALSE)
  11. //
  12. // Defines function that sends pnp event through ndis
  13. //
  14. typedef
  15. UINT
  16. (* pNdisHandlePnpEventFunc)(
  17. IN UINT Layer,
  18. IN UINT Operation,
  19. IN PUNICODE_STRING LowerComponent,
  20. IN PUNICODE_STRING UpperComponent,
  21. IN PUNICODE_STRING BindList,
  22. IN PVOID ReConfigBuffer,
  23. IN UINT ReConfigBufferSize);
  24. //
  25. // Maps a protocol string to its integer id
  26. //
  27. typedef struct _COMP_MAPPING
  28. {
  29. LPCTSTR pszId;
  30. DWORD dwId;
  31. } COMP_MAPPING;
  32. //
  33. // Defines attributes of a network component
  34. //
  35. typedef struct _RASSRV_NET_COMPONENT
  36. {
  37. DWORD dwType; // Is it client/service/protocol
  38. PWCHAR pszName; // Display name
  39. PWCHAR pszDesc; // Display description
  40. PWCHAR pszId; // Id to destinguish which client/service, etc
  41. BOOL bManip; // Whether is manipulatable by ras (ip, ipx, etc.)
  42. BOOL bHasUi; // For whether has properties ui (non-manip only)
  43. INetCfgComponent * pINetCfgComp;
  44. // The following fields only apply to manipulatable
  45. // components (bManip == TRUE)
  46. //
  47. DWORD dwId; // DWORD counterpart to pszId.
  48. BOOL bEnabled; // whether it is enabled for dialin
  49. BOOL bEnabledOrig; // original value of bEnabled (optimization)
  50. BOOL bExposes; // whether it exposes the network its on
  51. LPBYTE pbData; // pointer to protocol specific data
  52. BOOL bDataDirty; // should the protocol specific data be flushed?
  53. //For whistler bug 347355
  54. //
  55. BOOL bRemovable; //If this component removable //TCP/IP is not user removable
  56. } RASSRV_NET_COMPONENT;
  57. //
  58. // Defines attributes of a network component database
  59. //
  60. typedef struct _RASSRV_COMPONENT_DB
  61. {
  62. INetCfg * pINetCfg;
  63. BOOL bHasINetCfgLock;
  64. BOOL bInitCom;
  65. DWORD dwCompCount;
  66. BOOL bFlushOnClose;
  67. RASSRV_NET_COMPONENT ** pComps;
  68. PWCHAR pszClientName;
  69. INetConnectionUiUtilities * pNetConUtilities;
  70. } RASSRV_COMPONENT_DB;
  71. //
  72. // Definitions of functions taken from ndis
  73. //
  74. const static WCHAR pszNdispnpLib[] = L"ndispnp.dll";
  75. const static CHAR pszNidspnpFunc[] = "NdisHandlePnPEvent";
  76. // Parameters for the protocols
  77. const static WCHAR pszRemoteAccessParamStub[] =
  78. L"SYSTEM\\CurrentControlSet\\Services\\RemoteAccess\\Parameters\\";
  79. static WCHAR pszIpParams[] = L"Ip";
  80. static WCHAR pszIpxParams[] = L"Ipx";
  81. static WCHAR pszNetBuiParams[] = L"Nbf";
  82. static WCHAR pszArapParams[] = L"AppleTalk";
  83. static WCHAR pszShowNetworkToClients[] = L"AllowNetworkAccess";
  84. static WCHAR pszShowNetworkArap[] = L"NetworkAccess";
  85. static WCHAR pszEnableForDialin[] = L"EnableIn";
  86. static WCHAR pszIpPoolSubKey[] = L"\\StaticAddressPool\\0";
  87. // Ip specific registry parameters
  88. const static WCHAR pszIpFrom[] = L"From";
  89. const static WCHAR pszIpTo[] = L"To";
  90. const static WCHAR pszIpAddress[] = L"IpAddress";
  91. const static WCHAR pszIpMask[] = L"IpMask";
  92. const static WCHAR pszIpClientSpec[] = L"AllowClientIpAddresses";
  93. const static WCHAR pszIpShowNetworkToClients[] = L"AllowNetworkAccess";
  94. const static WCHAR pszIpUseDhcp[] = L"UseDhcpAddressing";
  95. // Ipx specific registry paramters
  96. const static WCHAR pszIpxAddress[] = L"FirstWanNet";
  97. const static WCHAR pszIpxClientSpec[] = L"AcceptRemoteNodeNumber";
  98. const static WCHAR pszIpxAutoAssign[] = L"AutoWanNetAllocation";
  99. const static WCHAR pszIpxAssignSame[] = L"GlobalWanNet";
  100. // Tcp specific registry parameters
  101. const static WCHAR pszTcpipParamsKey[]
  102. = L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\";
  103. const static WCHAR pszTcpEnableRouter[] = L"IPEnableRouter";
  104. const static WCHAR pszEmptyString[] = L"";
  105. //
  106. // Initializes a unicode string
  107. //
  108. VOID SetUnicodeString (
  109. IN OUT UNICODE_STRING* pustr,
  110. IN LPCWSTR psz )
  111. {
  112. pustr->Buffer = (PWSTR)(psz);
  113. pustr->Length = (USHORT)(lstrlenW(pustr->Buffer) * sizeof(WCHAR));
  114. pustr->MaximumLength = pustr->Length + sizeof(WCHAR);
  115. }
  116. //
  117. // Sets the expose property of a protocol
  118. //
  119. DWORD
  120. protSetExpose(
  121. IN BOOL bExposes,
  122. IN DWORD dwId)
  123. {
  124. PWCHAR pszProtocol = NULL, pszKey = NULL;
  125. PWCHAR pszAccess = pszShowNetworkToClients;
  126. DWORD dwErr;
  127. WCHAR pszProtKey[1024];
  128. bExposes = (bExposes) ? 1 : 0;
  129. // Base the registry location on the
  130. // id of the protocol
  131. switch (dwId)
  132. {
  133. case NETCFGDB_ID_IP:
  134. pszProtocol = (PWCHAR)pszIpParams;
  135. break;
  136. case NETCFGDB_ID_IPX:
  137. pszProtocol = (PWCHAR)pszIpxParams;
  138. break;
  139. case NETCFGDB_ID_NETBUI:
  140. pszProtocol = (PWCHAR)pszNetBuiParams;
  141. break;
  142. case NETCFGDB_ID_ARAP:
  143. pszProtocol = (PWCHAR)pszArapParams;
  144. pszAccess = (PWCHAR)pszShowNetworkArap;
  145. break;
  146. default:
  147. return ERROR_CAN_NOT_COMPLETE;
  148. }
  149. // Generate the registry key
  150. //
  151. wsprintfW(pszProtKey, L"%s%s", pszRemoteAccessParamStub, pszProtocol);
  152. if (! pszKey)
  153. {
  154. pszKey = pszProtKey;
  155. }
  156. // Set the value and return
  157. //
  158. dwErr = RassrvRegSetDw(bExposes, pszKey, pszAccess);
  159. return dwErr;
  160. }
  161. //
  162. // Gets the expose property of a protocol
  163. //
  164. DWORD
  165. protGetExpose(
  166. OUT BOOL* pbExposed,
  167. IN DWORD dwId)
  168. {
  169. PWCHAR pszProtocol = NULL, pszKey = NULL;
  170. PWCHAR pszAccess = pszShowNetworkToClients;
  171. DWORD dwErr;
  172. WCHAR pszProtKey[1024];
  173. switch (dwId)
  174. {
  175. case NETCFGDB_ID_IP:
  176. pszProtocol = (PWCHAR)pszIpParams;
  177. break;
  178. case NETCFGDB_ID_IPX:
  179. pszProtocol = (PWCHAR)pszIpxParams;
  180. break;
  181. case NETCFGDB_ID_NETBUI:
  182. pszProtocol = (PWCHAR)pszNetBuiParams;
  183. break;
  184. case NETCFGDB_ID_ARAP:
  185. pszProtocol = (PWCHAR)pszArapParams;
  186. pszAccess = (PWCHAR)pszShowNetworkArap;
  187. break;
  188. default:
  189. return ERROR_CAN_NOT_COMPLETE;
  190. }
  191. // Generate the registry key if needed
  192. if (! pszKey)
  193. {
  194. wsprintfW(
  195. pszProtKey,
  196. L"%s%s",
  197. pszRemoteAccessParamStub,
  198. pszProtocol);
  199. pszKey = pszProtKey;
  200. }
  201. // Get the value and return it
  202. dwErr = RassrvRegGetDw(pbExposed, TRUE, pszKey, pszAccess);
  203. return dwErr;
  204. }
  205. //
  206. // Sets the enable property of a protocol
  207. //
  208. DWORD
  209. protSetEnabling(
  210. IN BOOL bExposes,
  211. IN DWORD dwId)
  212. {
  213. PWCHAR pszProtocol = NULL;
  214. DWORD dwErr;
  215. bExposes = (bExposes) ? 1 : 0;
  216. if (dwId == NETCFGDB_ID_IP)
  217. {
  218. pszProtocol = pszIpParams;
  219. }
  220. else if (dwId == NETCFGDB_ID_IPX)
  221. {
  222. pszProtocol = pszIpxParams;
  223. }
  224. else if (dwId == NETCFGDB_ID_NETBUI)
  225. {
  226. pszProtocol = pszNetBuiParams;
  227. }
  228. else if (dwId == NETCFGDB_ID_ARAP)
  229. {
  230. pszProtocol = pszArapParams;
  231. }
  232. if (pszProtocol)
  233. {
  234. WCHAR pszProtKey[512];
  235. wsprintfW(
  236. pszProtKey,
  237. L"%s%s",
  238. pszRemoteAccessParamStub,
  239. pszProtocol);
  240. dwErr = RassrvRegSetDw(bExposes, pszProtKey, pszEnableForDialin);
  241. if (dwErr != NO_ERROR)
  242. {
  243. DbgOutputTrace(
  244. "protSetEnabling: Failed for %S: 0x%08x",
  245. pszProtocol,
  246. dwErr);
  247. }
  248. return dwErr;
  249. }
  250. return ERROR_CAN_NOT_COMPLETE;
  251. }
  252. //
  253. // Gets the Enabling property of a protocol
  254. //
  255. DWORD
  256. protGetEnabling(
  257. OUT BOOL* pbExposed,
  258. IN DWORD dwId)
  259. {
  260. PWCHAR pszProtocol = NULL;
  261. DWORD dwErr;
  262. if (dwId == NETCFGDB_ID_IP)
  263. {
  264. pszProtocol = pszIpParams;
  265. }
  266. else if (dwId == NETCFGDB_ID_IPX)
  267. {
  268. pszProtocol = pszIpxParams;
  269. }
  270. else if (dwId == NETCFGDB_ID_NETBUI)
  271. {
  272. pszProtocol = pszNetBuiParams;
  273. }
  274. else if (dwId == NETCFGDB_ID_ARAP)
  275. {
  276. pszProtocol = pszArapParams;
  277. }
  278. if (pszProtocol)
  279. {
  280. WCHAR pszProtKey[512];
  281. wsprintfW(
  282. pszProtKey,
  283. L"%s%s",
  284. pszRemoteAccessParamStub,
  285. pszProtocol);
  286. dwErr = RassrvRegGetDw(
  287. pbExposed,
  288. TRUE,
  289. pszProtKey,
  290. pszEnableForDialin);
  291. if (dwErr != NO_ERROR)
  292. {
  293. DbgOutputTrace(
  294. "protGetEnabling: Failed for %S: 0x%08x",
  295. pszProtocol,
  296. dwErr);
  297. }
  298. return dwErr;
  299. }
  300. return ERROR_CAN_NOT_COMPLETE;
  301. }
  302. //
  303. // Saves the enabling of a service out to the
  304. // system.
  305. //
  306. DWORD
  307. svcSetEnabling(
  308. IN RASSRV_NET_COMPONENT* pComp)
  309. {
  310. HANDLE hService = NULL;
  311. DWORD dwErr = NO_ERROR;
  312. do
  313. {
  314. // Or enable the component
  315. //
  316. if (pComp->bEnabled)
  317. {
  318. if (pComp->dwId == NETCFGDB_ID_FILEPRINT)
  319. {
  320. // Start the service
  321. //
  322. dwErr = SvcOpenServer(&hService);
  323. if (dwErr != NO_ERROR)
  324. {
  325. break;
  326. }
  327. dwErr = SvcStart(hService, 10);
  328. if (dwErr != NO_ERROR)
  329. {
  330. break;
  331. }
  332. }
  333. }
  334. } while (FALSE);
  335. // Cleanup
  336. {
  337. if (hService)
  338. {
  339. SvcClose(hService);
  340. }
  341. }
  342. return dwErr;
  343. }
  344. //
  345. // Gets the enabling property of a service
  346. //
  347. DWORD
  348. svcGetEnabling(
  349. OUT BOOL* pbExposed,
  350. IN DWORD dwId)
  351. {
  352. HANDLE hService = NULL;
  353. DWORD dwErr = NO_ERROR;
  354. do
  355. {
  356. dwErr = SvcOpenServer(&hService);
  357. if (dwErr != NO_ERROR)
  358. {
  359. break;
  360. }
  361. dwErr = SvcIsStarted(hService, pbExposed);
  362. if (dwErr != NO_ERROR)
  363. {
  364. break;
  365. }
  366. } while (FALSE);
  367. // Cleanup
  368. {
  369. if (hService)
  370. {
  371. SvcClose(hService);
  372. }
  373. }
  374. return dwErr;
  375. }
  376. //
  377. // Loads the tcpip parameters from the system
  378. //
  379. DWORD
  380. TcpipLoadParamsFromSystem(
  381. OUT TCPIP_PARAMS *pTcpipParams)
  382. {
  383. WCHAR buf[256], pszKey[512];
  384. DWORD dwRet = NO_ERROR, dwErr;
  385. DWORD dwNet = 0, dwMask = 0;
  386. wsprintfW(pszKey, L"%s%s", pszRemoteAccessParamStub, pszIpParams);
  387. // Load the params from the various registry locations.
  388. dwErr = RassrvRegGetDw(
  389. &pTcpipParams->bUseDhcp,
  390. TRUE,
  391. pszKey,
  392. (const PWCHAR)pszIpUseDhcp);
  393. if (dwErr != NO_ERROR)
  394. {
  395. DbgOutputTrace("TcpipLoad: dhcp fail 0x%08x", dwErr);
  396. dwRet = dwErr;
  397. }
  398. dwErr = RassrvRegGetDw(
  399. &pTcpipParams->bCaller,
  400. TRUE,
  401. pszKey,
  402. (const PWCHAR)pszIpClientSpec);
  403. if (dwErr != NO_ERROR)
  404. {
  405. DbgOutputTrace("TcpipLoad: clientspec fail 0x%08x", dwErr);
  406. dwRet = dwErr;
  407. }
  408. // Read in the "legacy" pool values (w2k RC1, w2k Beta3)
  409. //
  410. {
  411. WCHAR pszNet[256]=L"0.0.0.0", pszMask[256]=L"0.0.0.0";
  412. RassrvRegGetStr(
  413. pszNet,
  414. L"0.0.0.0",
  415. pszKey,
  416. (PWCHAR)pszIpAddress);
  417. RassrvRegGetStr(
  418. pszMask,
  419. L"0.0.0.0",
  420. pszKey,
  421. (PWCHAR)pszIpMask);
  422. dwNet = IpPszToHostAddr(pszNet);
  423. dwMask = IpPszToHostAddr(pszMask);
  424. }
  425. // Generate the path the the new registry values
  426. //
  427. wcscat(pszKey, pszIpPoolSubKey);
  428. // See if new info is stored by reading the "from"
  429. // value
  430. //
  431. dwErr = RassrvRegGetDwEx(
  432. &pTcpipParams->dwPoolStart,
  433. 0,
  434. pszKey,
  435. (const PWCHAR)pszIpFrom,
  436. FALSE);
  437. // There is new info in the registry -- use it
  438. //
  439. if (dwErr == ERROR_SUCCESS)
  440. {
  441. // Read in the "to" value
  442. //
  443. dwErr = RassrvRegGetDwEx(
  444. &pTcpipParams->dwPoolEnd,
  445. 0,
  446. pszKey,
  447. (const PWCHAR)pszIpTo,
  448. FALSE);
  449. if (dwErr != NO_ERROR)
  450. {
  451. DbgOutputTrace("TcpipLoad: mask fail 0x%08x", dwErr);
  452. dwRet = dwErr;
  453. }
  454. }
  455. // There is not new data in the new section -- use legacy
  456. // values
  457. //
  458. else if (dwErr == ERROR_FILE_NOT_FOUND)
  459. {
  460. pTcpipParams->dwPoolStart = dwNet;
  461. pTcpipParams->dwPoolEnd = (dwNet + ~dwMask);
  462. }
  463. // An unexpected error occured
  464. //
  465. else if (dwErr != NO_ERROR)
  466. {
  467. DbgOutputTrace("TcpipLoad: pool fail 0x%08x", dwErr);
  468. dwRet = dwErr;
  469. }
  470. return dwRet;
  471. }
  472. //
  473. // Commits the given tcpip parameters to the system.
  474. //
  475. DWORD
  476. TcpipSaveParamsToSystem(
  477. IN TCPIP_PARAMS * pTcpipParams)
  478. {
  479. WCHAR pszKey[512];
  480. DWORD dwRet = NO_ERROR, dwErr;
  481. wsprintfW(pszKey, L"%s%s", pszRemoteAccessParamStub, pszIpParams);
  482. // Load the params from the various registry locations.
  483. dwErr = RassrvRegSetDw(
  484. pTcpipParams->bUseDhcp,
  485. pszKey,
  486. (const PWCHAR)pszIpUseDhcp);
  487. if (dwErr != NO_ERROR)
  488. {
  489. DbgOutputTrace("TcpipSave: dhcp fail 0x%08x", dwErr);
  490. dwRet = dwErr;
  491. }
  492. dwErr = RassrvRegSetDw(
  493. pTcpipParams->bCaller,
  494. pszKey,
  495. (const PWCHAR)pszIpClientSpec);
  496. if (dwErr != NO_ERROR)
  497. {
  498. DbgOutputTrace("TcpipSave: callerspec fail 0x%08x", dwErr);
  499. dwRet = dwErr;
  500. }
  501. wcscat(pszKey, pszIpPoolSubKey);
  502. dwErr = RassrvRegSetDwEx(
  503. pTcpipParams->dwPoolStart,
  504. pszKey,
  505. (const PWCHAR)pszIpFrom,
  506. TRUE);
  507. if (dwErr != NO_ERROR)
  508. {
  509. DbgOutputTrace("TcpipSave: from fail 0x%08x", dwErr);
  510. dwRet = dwErr;
  511. }
  512. dwErr = RassrvRegSetDwEx(
  513. pTcpipParams->dwPoolEnd,
  514. pszKey,
  515. (const PWCHAR)pszIpTo,
  516. TRUE);
  517. if (dwErr != NO_ERROR)
  518. {
  519. DbgOutputTrace("TcpipSave: to fail 0x%08x", dwErr);
  520. dwRet = dwErr;
  521. }
  522. return dwRet;
  523. }
  524. //
  525. // Loads the ipx parameters from the system
  526. //
  527. DWORD
  528. IpxLoadParamsFromSystem(
  529. OUT IPX_PARAMS *pIpxParams)
  530. {
  531. WCHAR pszKey[512];
  532. DWORD dwRet = NO_ERROR, dwErr;
  533. wsprintfW(pszKey, L"%s%s", pszRemoteAccessParamStub, pszIpxParams);
  534. // Load the params from the various registry locations.
  535. dwErr = RassrvRegGetDw(
  536. &pIpxParams->bAutoAssign,
  537. TRUE,
  538. pszKey,
  539. (const PWCHAR)pszIpxAutoAssign);
  540. if (dwErr != NO_ERROR)
  541. {
  542. DbgOutputTrace("IpxLoad: auto-assign fail 0x%08x", dwErr);
  543. dwRet = dwErr;
  544. }
  545. dwErr = RassrvRegGetDw(
  546. &pIpxParams->bCaller,
  547. TRUE,
  548. pszKey,
  549. (const PWCHAR)pszIpxClientSpec);
  550. if (dwErr != NO_ERROR)
  551. {
  552. DbgOutputTrace("IpxLoad: client-spec fail 0x%08x", dwErr);
  553. dwRet = dwErr;
  554. }
  555. dwErr = RassrvRegGetDw(
  556. &pIpxParams->dwIpxAddress,
  557. 0,
  558. pszKey,
  559. (const PWCHAR)pszIpxAddress);
  560. if (dwErr != NO_ERROR)
  561. {
  562. DbgOutputTrace("IpxLoad: address fail 0x%08x", dwErr);
  563. dwRet = dwErr;
  564. }
  565. dwErr = RassrvRegGetDw(
  566. &pIpxParams->bGlobalWan,
  567. 0,
  568. pszKey,
  569. (const PWCHAR)pszIpxAssignSame);
  570. if (dwErr != NO_ERROR)
  571. {
  572. DbgOutputTrace("IpxLoad: same-addr fail 0x%08x", dwErr);
  573. dwRet = dwErr;
  574. }
  575. return dwRet;
  576. }
  577. //
  578. // Commits the given ipx parameters to the system.
  579. //
  580. DWORD
  581. IpxSaveParamsToSystem(
  582. IN IPX_PARAMS * pIpxParams)
  583. {
  584. WCHAR pszKey[512];
  585. DWORD dwRet = NO_ERROR, dwErr;
  586. wsprintfW(pszKey, L"%s%s", pszRemoteAccessParamStub, pszIpxParams);
  587. // Save params to the various registry locations.
  588. dwErr = RassrvRegSetDw(
  589. pIpxParams->bAutoAssign,
  590. pszKey,
  591. (const PWCHAR)pszIpxAutoAssign);
  592. if (dwErr != NO_ERROR)
  593. {
  594. DbgOutputTrace("IpxSave: auto-addr save 0x%08x", dwErr);
  595. dwRet = dwErr;
  596. }
  597. dwErr = RassrvRegSetDw(
  598. pIpxParams->bCaller,
  599. pszKey,
  600. (const PWCHAR)pszIpxClientSpec);
  601. if (dwErr != NO_ERROR)
  602. {
  603. DbgOutputTrace("IpxSave: client-spec fail 0x%08x", dwErr);
  604. dwRet = dwErr;
  605. }
  606. dwErr = RassrvRegSetDw(
  607. pIpxParams->dwIpxAddress,
  608. pszKey,
  609. (const PWCHAR)pszIpxAddress);
  610. if (dwErr != NO_ERROR)
  611. {
  612. DbgOutputTrace("IpxSave: addr save 0x%08x", dwErr);
  613. dwRet = dwErr;
  614. }
  615. dwErr = RassrvRegSetDw(
  616. pIpxParams->bGlobalWan,
  617. pszKey,
  618. (const PWCHAR)pszIpxAssignSame);
  619. if (dwErr != NO_ERROR)
  620. {
  621. DbgOutputTrace("IpxSave: assign-same fail 0x%08x", dwErr);
  622. dwRet = dwErr;
  623. }
  624. return dwRet;
  625. }
  626. //
  627. // Dialog procedure that handles the editing of generic protocol
  628. // information. Dialog proc that governs the ipx settings dialog
  629. //
  630. INT_PTR
  631. CALLBACK
  632. GenericProtSettingsDialogProc (
  633. IN HWND hwndDlg,
  634. IN UINT uMsg,
  635. IN WPARAM wParam,
  636. IN LPARAM lParam)
  637. {
  638. switch (uMsg)
  639. {
  640. case WM_INITDIALOG:
  641. {
  642. PROT_EDIT_DATA* pEditData = ((PROT_EDIT_DATA*)lParam);
  643. // Set the network exposure check
  644. SendDlgItemMessage(
  645. hwndDlg,
  646. CID_NetTab_GenProt_CB_ExposeNetwork,
  647. BM_SETCHECK,
  648. (pEditData->bExpose) ? BST_CHECKED : BST_UNCHECKED,
  649. 0);
  650. SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
  651. return FALSE;
  652. }
  653. break;
  654. case WM_DESTROY:
  655. SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0);
  656. break;
  657. case WM_COMMAND:
  658. {
  659. PROT_EDIT_DATA * pEditData = (PROT_EDIT_DATA*)
  660. GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
  661. switch (wParam)
  662. {
  663. case IDOK:
  664. pEditData->bExpose =
  665. SendDlgItemMessage(
  666. hwndDlg,
  667. CID_NetTab_GenProt_CB_ExposeNetwork,
  668. BM_GETCHECK,
  669. 0,
  670. 0) == BST_CHECKED;
  671. EndDialog(hwndDlg, 1);
  672. break;
  673. case IDCANCEL:
  674. EndDialog(hwndDlg, 0);
  675. break;
  676. }
  677. }
  678. break;
  679. }
  680. return FALSE;
  681. }
  682. //
  683. // Function edits the properties of a generic protocol,
  684. // that is a protocol that has no ras-specific properties.
  685. //
  686. DWORD
  687. GenericProtocolEditProperties(
  688. IN HWND hwndParent,
  689. IN OUT PROT_EDIT_DATA * pEditData,
  690. IN OUT BOOL * pbCommit)
  691. {
  692. DWORD dwErr;
  693. INT_PTR iRet;
  694. // Popup the dialog box
  695. iRet = DialogBoxParam(
  696. Globals.hInstDll,
  697. MAKEINTRESOURCE(DID_NetTab_GenProt),
  698. hwndParent,
  699. GenericProtSettingsDialogProc,
  700. (LPARAM)pEditData);
  701. // If ok was pressed, save off the new settings
  702. *pbCommit = FALSE;
  703. if ( (iRet) && (iRet != -1) )
  704. {
  705. *pbCommit = TRUE;
  706. }
  707. return NO_ERROR;
  708. }
  709. //
  710. // Releases resources reserved by this
  711. // network component database.
  712. //
  713. DWORD
  714. netDbCleanup(
  715. RASSRV_COMPONENT_DB* This)
  716. {
  717. DWORD i, dwCount;
  718. // Free all of the strings
  719. if (This->pComps)
  720. {
  721. for (i = 0; i < This->dwCompCount; i++)
  722. {
  723. if (This->pComps[i])
  724. {
  725. if (This->pComps[i]->pINetCfgComp)
  726. {
  727. dwCount = INetCfgComponent_Release(
  728. This->pComps[i]->pINetCfgComp);
  729. DbgOutputTrace(
  730. "netDbCleanup: %ls ref=%x",
  731. This->pComps[i]->pszId,
  732. dwCount);
  733. }
  734. if (This->pComps[i]->pszName)
  735. {
  736. CoTaskMemFree(This->pComps[i]->pszName);
  737. }
  738. if (This->pComps[i]->pszDesc)
  739. {
  740. CoTaskMemFree(This->pComps[i]->pszDesc);
  741. }
  742. if (This->pComps[i]->pszId)
  743. {
  744. CoTaskMemFree(This->pComps[i]->pszId);
  745. }
  746. RassrvFree(This->pComps[i]);
  747. }
  748. }
  749. RassrvFree(This->pComps);
  750. }
  751. // Reset all of the values
  752. This->dwCompCount = 0;
  753. This->pComps = 0;
  754. return NO_ERROR;
  755. }
  756. //
  757. // Loads in the netshell library which is responsible for adding
  758. // and removing network components
  759. //
  760. DWORD
  761. netDbLoadNetShell (
  762. RASSRV_COMPONENT_DB* This)
  763. {
  764. if (!This->pNetConUtilities)
  765. {
  766. HRESULT hr;
  767. hr = HrCreateNetConnectionUtilities(&This->pNetConUtilities);
  768. if (FAILED(hr))
  769. {
  770. DbgOutputTrace("LoadNetShell: loadlib fial 0x%08x", hr);
  771. }
  772. }
  773. return NO_ERROR;
  774. }
  775. //
  776. // Loads protocol specific info for a ras-manipulatable protocol. This
  777. // function assumes that the component passed in is a ras-manipulatable
  778. // component. (tcpip, ipx, nbf, arap)
  779. //
  780. DWORD
  781. netDbLoadProtcolInfo(
  782. IN OUT RASSRV_NET_COMPONENT * pNetComp)
  783. {
  784. LPBYTE pbData;
  785. // Initialize the dirty bit and the data
  786. pNetComp->bDataDirty = FALSE;
  787. pNetComp->pbData = NULL;
  788. // Get the enabled and exposed properties
  789. protGetEnabling(&(pNetComp->bEnabled), pNetComp->dwId);
  790. protGetExpose(&(pNetComp->bExposes), pNetComp->dwId);
  791. pNetComp->bEnabledOrig = pNetComp->bEnabled;
  792. // Load protocol specific data
  793. //
  794. switch (pNetComp->dwId)
  795. {
  796. case NETCFGDB_ID_IP:
  797. pNetComp->pbData = RassrvAlloc(sizeof(TCPIP_PARAMS), TRUE);
  798. if (pNetComp->pbData == NULL)
  799. {
  800. return ERROR_NOT_ENOUGH_MEMORY;
  801. }
  802. TcpipLoadParamsFromSystem((TCPIP_PARAMS*)(pNetComp->pbData));
  803. break;
  804. case NETCFGDB_ID_IPX:
  805. pNetComp->pbData = RassrvAlloc(sizeof(IPX_PARAMS), TRUE);
  806. if (pNetComp->pbData == NULL)
  807. {
  808. return ERROR_NOT_ENOUGH_MEMORY;
  809. }
  810. IpxLoadParamsFromSystem((IPX_PARAMS*)(pNetComp->pbData));
  811. break;
  812. }
  813. return NO_ERROR;
  814. }
  815. //
  816. // Loads service specific info for a ras-manipulatable service. This
  817. // function assumes that the component passed in is a ras-manipulatable
  818. // component.
  819. //
  820. DWORD
  821. netDbLoadServiceInfo(
  822. IN OUT RASSRV_NET_COMPONENT * pNetComp)
  823. {
  824. // Get the enabled property
  825. //
  826. svcGetEnabling(&(pNetComp->bEnabled), pNetComp->dwId);
  827. pNetComp->bEnabledOrig = pNetComp->bEnabled;
  828. return NO_ERROR;
  829. }
  830. //
  831. // Returns the protol id of the given component
  832. //
  833. DWORD
  834. netDbLoadCompId (
  835. IN OUT RASSRV_NET_COMPONENT * pNetComp)
  836. {
  837. DWORD i;
  838. static const COMP_MAPPING pManipCompMap [] =
  839. {
  840. { NETCFG_TRANS_CID_MS_TCPIP, NETCFGDB_ID_IP },
  841. { NETCFG_TRANS_CID_MS_NWIPX, NETCFGDB_ID_IPX },
  842. { NETCFG_TRANS_CID_MS_NETBEUI, NETCFGDB_ID_NETBUI },
  843. { NETCFG_TRANS_CID_MS_APPLETALK, NETCFGDB_ID_ARAP },
  844. { NETCFG_SERVICE_CID_MS_SERVER, NETCFGDB_ID_FILEPRINT }
  845. };
  846. // See if the id matches any of the protocols that we manage.
  847. //
  848. pNetComp->dwId = NETCFGDB_ID_OTHER;
  849. for (i = 0; i < sizeof(pManipCompMap)/sizeof(*pManipCompMap); i++)
  850. {
  851. if (lstrcmpi(pNetComp->pszId, pManipCompMap[i].pszId) == 0)
  852. {
  853. pNetComp->dwId = pManipCompMap[i].dwId;
  854. break;
  855. }
  856. }
  857. return pNetComp->dwId;
  858. }
  859. //
  860. // Returns TRUE if this iNetCfg component is not hidden and if
  861. // it successfully yeilds it's information.
  862. //
  863. BOOL
  864. netDbGetCompInfo(
  865. IN INetCfgComponent * pComponent,
  866. IN OUT RASSRV_NET_COMPONENT * pNetComp,
  867. IN RASSRV_COMPONENT_DB * pCompDb )
  868. {
  869. DWORD dwCharacter;
  870. GUID Guid;
  871. HRESULT hr = S_OK, hr2;
  872. // Make sure that this is not a "hidden" component
  873. //
  874. hr = INetCfgComponent_GetCharacteristics (pComponent, &dwCharacter);
  875. if ( (FAILED(hr)) || (dwCharacter & NCF_HIDDEN) )
  876. {
  877. return FALSE;
  878. }
  879. // Get the display name
  880. hr = INetCfgComponent_GetDisplayName (pComponent, &pNetComp->pszName);
  881. if (FAILED(hr))
  882. {
  883. return FALSE;
  884. }
  885. // Assign the has properties value
  886. pNetComp->bHasUi = !!(dwCharacter & NCF_HAS_UI);
  887. // pmay: 323274
  888. //
  889. // Make sure that the component can display properties without
  890. // a context if it claims to support displaying properties.
  891. //
  892. if (pNetComp->bHasUi)
  893. {
  894. hr2 = INetCfgComponent_RaisePropertyUi(
  895. pComponent,
  896. GetActiveWindow(),
  897. NCRP_QUERY_PROPERTY_UI,
  898. NULL);
  899. pNetComp->bHasUi = !!(hr2 == S_OK);
  900. }
  901. // Load the rest of the props
  902. if (FAILED(INetCfgComponent_GetClassGuid (pComponent, &Guid)) ||
  903. FAILED(INetCfgComponent_GetId (pComponent, &pNetComp->pszId)) ||
  904. FAILED(INetCfgComponent_GetHelpText(pComponent, &pNetComp->pszDesc))
  905. )
  906. {
  907. DbgOutputTrace("GetCompInfo: fail %S", pNetComp->pszName);
  908. return FALSE;
  909. }
  910. // Assign the type
  911. if (memcmp(&Guid, &GUID_DEVCLASS_NETCLIENT, sizeof(GUID)) == 0)
  912. {
  913. pNetComp->dwType = NETCFGDB_CLIENT;
  914. }
  915. else if (memcmp(&Guid, &GUID_DEVCLASS_NETSERVICE, sizeof(GUID)) == 0)
  916. {
  917. pNetComp->dwType = NETCFGDB_SERVICE;
  918. }
  919. else
  920. {
  921. pNetComp->dwType = NETCFGDB_PROTOCOL;
  922. }
  923. // If this is a protocol that ras server can manipulate,
  924. // initailize its additional fields here.
  925. pNetComp->dwId = netDbLoadCompId(pNetComp);
  926. if (pNetComp->dwId != NETCFGDB_ID_OTHER)
  927. {
  928. if (pNetComp->dwType == NETCFGDB_PROTOCOL)
  929. {
  930. netDbLoadProtcolInfo(pNetComp);
  931. }
  932. else if (pNetComp->dwType == NETCFGDB_SERVICE)
  933. {
  934. netDbLoadServiceInfo(pNetComp);
  935. }
  936. pNetComp->bManip = TRUE;
  937. }
  938. // Assign the inetcfg component
  939. pNetComp->pINetCfgComp = pComponent;
  940. INetCfgComponent_AddRef(pComponent);
  941. //For whistler bug 347355
  942. //
  943. {
  944. BOOL fEnableRemove=FALSE;
  945. DWORD dwFlags;
  946. HRESULT hr;
  947. fEnableRemove = INetConnectionUiUtilities_UserHasPermission(
  948. pCompDb->pNetConUtilities,
  949. NCPERM_AddRemoveComponents);
  950. hr = INetCfgComponent_GetCharacteristics(pComponent, &dwFlags );
  951. if( SUCCEEDED(hr) && (NCF_NOT_USER_REMOVABLE & dwFlags) )
  952. {
  953. fEnableRemove = FALSE;
  954. }
  955. pNetComp->bRemovable = fEnableRemove;
  956. }
  957. return TRUE;
  958. }
  959. //
  960. // Raise the ui for a ras-manipulatable protocol
  961. //
  962. DWORD
  963. netDbRaiseRasProps(
  964. IN RASSRV_NET_COMPONENT * pNetComp,
  965. IN HWND hwndParent)
  966. {
  967. PROT_EDIT_DATA ProtEditData;
  968. TCPIP_PARAMS TcpParams;
  969. IPX_PARAMS IpxParams;
  970. BOOL bOk;
  971. DWORD dwErr;
  972. // Initialize the protocol data properties structure
  973. //
  974. ProtEditData.bExpose = pNetComp->bExposes;
  975. ProtEditData.pbData = NULL;
  976. // Launch the appropriate ui
  977. switch (pNetComp->dwId)
  978. {
  979. case NETCFGDB_ID_IP:
  980. CopyMemory(&TcpParams, pNetComp->pbData, sizeof(TCPIP_PARAMS));
  981. ProtEditData.pbData = (LPBYTE)(&TcpParams);
  982. dwErr = TcpipEditProperties(hwndParent, &ProtEditData, &bOk);
  983. if (dwErr != NO_ERROR)
  984. {
  985. return dwErr;
  986. }
  987. if (bOk)
  988. {
  989. pNetComp->bDataDirty = TRUE;
  990. CopyMemory(
  991. pNetComp->pbData,
  992. &TcpParams,
  993. sizeof(TCPIP_PARAMS));
  994. pNetComp->bExposes = ProtEditData.bExpose;;
  995. }
  996. break;
  997. case NETCFGDB_ID_IPX:
  998. CopyMemory(&IpxParams, pNetComp->pbData, sizeof(IPX_PARAMS));
  999. ProtEditData.pbData = (LPBYTE)(&IpxParams);
  1000. dwErr = IpxEditProperties(hwndParent, &ProtEditData, &bOk);
  1001. if (dwErr != NO_ERROR)
  1002. {
  1003. return dwErr;
  1004. }
  1005. if (bOk)
  1006. {
  1007. pNetComp->bDataDirty = TRUE;
  1008. CopyMemory(pNetComp->pbData, &IpxParams, sizeof(IPX_PARAMS));
  1009. pNetComp->bExposes = ProtEditData.bExpose;;
  1010. }
  1011. break;
  1012. default:
  1013. dwErr = GenericProtocolEditProperties(
  1014. hwndParent,
  1015. &ProtEditData,
  1016. &bOk);
  1017. if (dwErr != NO_ERROR)
  1018. {
  1019. return dwErr;
  1020. }
  1021. if (bOk)
  1022. {
  1023. pNetComp->bDataDirty = TRUE;
  1024. pNetComp->bExposes = ProtEditData.bExpose;;
  1025. }
  1026. break;
  1027. }
  1028. return NO_ERROR;
  1029. }
  1030. //
  1031. // Comparison function used to sort the network components
  1032. // It's easier to implement here rather than the UI
  1033. //
  1034. int
  1035. __cdecl
  1036. netDbCompare (
  1037. CONST VOID* pElem1,
  1038. CONST VOID* pElem2)
  1039. {
  1040. RASSRV_NET_COMPONENT * pc1 = *((RASSRV_NET_COMPONENT **)pElem1);
  1041. RASSRV_NET_COMPONENT * pc2 = *((RASSRV_NET_COMPONENT **)pElem2);
  1042. if (pc1->bManip == pc2->bManip)
  1043. {
  1044. if (pc1->bManip == FALSE)
  1045. {
  1046. return 0;
  1047. }
  1048. if (pc1->dwId == pc2->dwId)
  1049. {
  1050. return 0;
  1051. }
  1052. else if (pc1->dwId < pc2->dwId)
  1053. {
  1054. return -1;
  1055. }
  1056. return 1;
  1057. }
  1058. else if (pc1->bManip)
  1059. {
  1060. return -1;
  1061. }
  1062. return 1;
  1063. }
  1064. //
  1065. // Opens the database of network config components
  1066. //
  1067. DWORD
  1068. netDbOpen (
  1069. OUT PHANDLE phNetCompDatabase,
  1070. IN PWCHAR pszClientName)
  1071. {
  1072. RASSRV_COMPONENT_DB * This;
  1073. DWORD dwLength;
  1074. // Validate parameters
  1075. if (! phNetCompDatabase || !pszClientName)
  1076. {
  1077. return ERROR_INVALID_PARAMETER;
  1078. }
  1079. // Allocate the database
  1080. This = RassrvAlloc (sizeof(RASSRV_COMPONENT_DB), TRUE);
  1081. if (This == NULL)
  1082. {
  1083. return ERROR_NOT_ENOUGH_MEMORY;
  1084. }
  1085. // Initialize
  1086. dwLength = wcslen(pszClientName);
  1087. if (dwLength)
  1088. {
  1089. This->pszClientName =
  1090. RassrvAlloc((dwLength + 1) * sizeof(WCHAR), FALSE);
  1091. if (This->pszClientName)
  1092. {
  1093. wcscpy(This->pszClientName, pszClientName);
  1094. }
  1095. }
  1096. This->bFlushOnClose = FALSE;
  1097. *phNetCompDatabase = (HANDLE)This;
  1098. // Load the net shell library
  1099. netDbLoadNetShell(This);
  1100. return NO_ERROR;
  1101. }
  1102. //
  1103. // Cleans up all resources held by the database
  1104. //
  1105. DWORD
  1106. netDbClose (
  1107. IN HANDLE hNetCompDatabase)
  1108. {
  1109. RASSRV_COMPONENT_DB* This = (RASSRV_COMPONENT_DB*)hNetCompDatabase;
  1110. // Validate parameters
  1111. if (!This)
  1112. {
  1113. return ERROR_INVALID_PARAMETER;
  1114. }
  1115. // Flush if needed
  1116. if (This->bFlushOnClose)
  1117. {
  1118. netDbFlush(hNetCompDatabase);
  1119. }
  1120. else
  1121. {
  1122. // If we've made changes to inetcfg that require backing out,
  1123. // do so now.
  1124. if (This->pINetCfg)
  1125. {
  1126. INetCfg_Cancel(This->pINetCfg);
  1127. }
  1128. }
  1129. netDbCleanup(This);
  1130. // Free the client name
  1131. if (This->pszClientName)
  1132. {
  1133. RassrvFree(This->pszClientName);
  1134. }
  1135. // Release our reference to inetcfg. We will still have it
  1136. // at this point if a protocol/client/service was added.
  1137. if (This->pINetCfg)
  1138. {
  1139. HrUninitializeAndReleaseINetCfg (
  1140. This->bInitCom,
  1141. This->pINetCfg,
  1142. This->bHasINetCfgLock);
  1143. }
  1144. // Free the netshell library if appropriate
  1145. if (This->pNetConUtilities)
  1146. {
  1147. INetConnectionUiUtilities_Release(This->pNetConUtilities);
  1148. }
  1149. // Free this
  1150. RassrvFree(This);
  1151. return NO_ERROR;
  1152. }
  1153. // Commits all changes to the database to the system
  1154. DWORD
  1155. netDbFlush (
  1156. IN HANDLE hNetCompDatabase)
  1157. {
  1158. RASSRV_COMPONENT_DB * This = (RASSRV_COMPONENT_DB*)hNetCompDatabase;
  1159. RASSRV_NET_COMPONENT* pComp = NULL;
  1160. DWORD i;
  1161. // Validate parameters
  1162. if (!This)
  1163. {
  1164. return ERROR_INVALID_PARAMETER;
  1165. }
  1166. // Flush any ras-manipulatable's data if dirty
  1167. for (i = 0; i < This->dwCompCount; i++)
  1168. {
  1169. pComp = This->pComps[i];
  1170. // If the enabling of this component has changed, commit
  1171. // that change
  1172. if ((pComp->bEnabled != pComp->bEnabledOrig) && (pComp->bManip))
  1173. {
  1174. if (pComp ->dwType == NETCFGDB_PROTOCOL)
  1175. {
  1176. protSetEnabling(
  1177. pComp->bEnabled,
  1178. pComp->dwId);
  1179. }
  1180. else if (pComp->dwType == NETCFGDB_SERVICE)
  1181. {
  1182. svcSetEnabling(pComp);
  1183. }
  1184. }
  1185. // If the ras-server-specific properties of the component
  1186. // have changed, commit the changes.
  1187. if (pComp->bDataDirty)
  1188. {
  1189. protSetExpose(pComp->bExposes, pComp->dwId);
  1190. switch (pComp->dwId)
  1191. {
  1192. case NETCFGDB_ID_IP:
  1193. {
  1194. TCPIP_PARAMS* pTcpParams =
  1195. (TCPIP_PARAMS*)(pComp->pbData);
  1196. TcpipSaveParamsToSystem(pTcpParams);
  1197. }
  1198. break;
  1199. case NETCFGDB_ID_IPX:
  1200. {
  1201. IPX_PARAMS* pIpxParams =
  1202. (IPX_PARAMS*)(pComp->pbData);
  1203. IpxSaveParamsToSystem(pIpxParams);
  1204. }
  1205. break;
  1206. }
  1207. }
  1208. }
  1209. // If we have a pointer to the inetcfg instance then we can
  1210. // commit the changes now
  1211. if (This->pINetCfg)
  1212. {
  1213. INetCfg_Apply(This->pINetCfg);
  1214. }
  1215. return NO_ERROR;
  1216. }
  1217. //
  1218. // Loads the net config database for the first time. Because inetcfg
  1219. // requires time to load and be manipulated, we delay the load of this
  1220. // database until it is explicitly requested.
  1221. //
  1222. DWORD
  1223. netDbLoad(
  1224. IN HANDLE hNetCompDatabase)
  1225. {
  1226. return netDbReload(hNetCompDatabase);
  1227. }
  1228. //
  1229. // Reloads net information from system
  1230. //
  1231. DWORD
  1232. netDbReload(
  1233. IN HANDLE hNetCompDatabase)
  1234. {
  1235. RASSRV_COMPONENT_DB * This = (RASSRV_COMPONENT_DB*)hNetCompDatabase;
  1236. DWORD i, j, dwProtCount = 0, dwRefCount;
  1237. HRESULT hr;
  1238. RASSRV_NET_COMPONENT TempComp;
  1239. INetCfgComponent* pComponents [256];
  1240. PWCHAR pszName = NULL;
  1241. static const GUID* c_apguidClasses [] =
  1242. {
  1243. &GUID_DEVCLASS_NETTRANS,
  1244. &GUID_DEVCLASS_NETCLIENT,
  1245. &GUID_DEVCLASS_NETSERVICE,
  1246. };
  1247. // Validate
  1248. if (!This)
  1249. {
  1250. return ERROR_INVALID_PARAMETER;
  1251. }
  1252. DbgOutputTrace(
  1253. "netDbReload %x %x %x %x %x %x %x %x",
  1254. This->pINetCfg,
  1255. This->bHasINetCfgLock,
  1256. This->bInitCom,
  1257. This->dwCompCount,
  1258. This->bFlushOnClose,
  1259. This->pComps,
  1260. This->pszClientName,
  1261. This->pNetConUtilities);
  1262. // Cleanup any previous values
  1263. netDbCleanup(This);
  1264. // If we don't have a reference to inetcfg yet, get it
  1265. // here.
  1266. if (This->pINetCfg == NULL)
  1267. {
  1268. This->bInitCom = TRUE;
  1269. This->bHasINetCfgLock = TRUE;
  1270. hr = HrCreateAndInitializeINetCfg(
  1271. &This->bInitCom,
  1272. &This->pINetCfg,
  1273. TRUE,
  1274. 0,
  1275. This->pszClientName,
  1276. NULL);
  1277. // Handle error conditions here
  1278. if (S_FALSE == hr)
  1279. {
  1280. return ERROR_CAN_NOT_COMPLETE;
  1281. }
  1282. else if (FAILED(hr))
  1283. {
  1284. return ERROR_CAN_NOT_COMPLETE;
  1285. }
  1286. }
  1287. //
  1288. // Enumerate all of the client and service components in the system.
  1289. //
  1290. hr = HrEnumComponentsInClasses (
  1291. This->pINetCfg,
  1292. sizeof(c_apguidClasses) / sizeof(c_apguidClasses[0]),
  1293. (GUID**)c_apguidClasses,
  1294. sizeof(pComponents) / sizeof(pComponents[0]),
  1295. pComponents,
  1296. &This->dwCompCount);
  1297. if (!SUCCEEDED(hr))
  1298. {
  1299. return ERROR_CAN_NOT_COMPLETE;
  1300. }
  1301. // Initialize the array of internal objects
  1302. This->pComps = RassrvAlloc (
  1303. This->dwCompCount * sizeof (RASSRV_NET_COMPONENT*),
  1304. TRUE);
  1305. if (!This->pComps)
  1306. {
  1307. return ERROR_NOT_ENOUGH_MEMORY;
  1308. }
  1309. // Initialize the installed component array
  1310. //
  1311. j = 0;
  1312. ZeroMemory(&TempComp, sizeof(TempComp));
  1313. for (i = 0; i < This->dwCompCount; i++)
  1314. {
  1315. pszName = L"";
  1316. //Add this (RASSRV_COMPONENT_DB *) for whistler bug 347355
  1317. //
  1318. if (netDbGetCompInfo(pComponents[i], &TempComp, This))
  1319. {
  1320. This->pComps[j] =
  1321. RassrvAlloc (sizeof(RASSRV_NET_COMPONENT), FALSE);
  1322. if (!This->pComps[j])
  1323. {
  1324. return ERROR_NOT_ENOUGH_MEMORY;
  1325. }
  1326. // Fill in the fields
  1327. CopyMemory(This->pComps[j], &TempComp, sizeof(TempComp));
  1328. ZeroMemory(&TempComp, sizeof(TempComp));
  1329. if (This->pComps[j]->dwType == NETCFGDB_PROTOCOL)
  1330. {
  1331. dwProtCount++;
  1332. }
  1333. pszName = This->pComps[j]->pszName;
  1334. j++;
  1335. }
  1336. dwRefCount = INetCfgComponent_Release(pComponents[i]);
  1337. DbgOutputTrace(
  1338. "netDbReload: %ls ref=%d", pszName, dwRefCount);
  1339. }
  1340. This->dwCompCount = j;
  1341. // Sort the array.
  1342. //
  1343. qsort(
  1344. This->pComps,
  1345. This->dwCompCount,
  1346. sizeof(This->pComps[0]),
  1347. netDbCompare);
  1348. return NO_ERROR;
  1349. }
  1350. //
  1351. // Reload the status of a given component
  1352. //
  1353. DWORD
  1354. netDbReloadComponent (
  1355. IN HANDLE hNetCompDatabase,
  1356. IN DWORD dwComponentId)
  1357. {
  1358. RASSRV_COMPONENT_DB * This = (RASSRV_COMPONENT_DB*)hNetCompDatabase;
  1359. RASSRV_NET_COMPONENT* pComp = NULL;
  1360. DWORD i;
  1361. // Validate
  1362. if (!This)
  1363. {
  1364. return ERROR_INVALID_PARAMETER;
  1365. }
  1366. // Currently, we only need to support the fileprint
  1367. // component
  1368. //
  1369. if (dwComponentId != NETCFGDB_ID_FILEPRINT)
  1370. {
  1371. return ERROR_INVALID_PARAMETER;
  1372. }
  1373. // Find the appropriate component
  1374. //
  1375. for (i = 0; i < This->dwCompCount; i++)
  1376. {
  1377. if (This->pComps[i]->dwId == dwComponentId)
  1378. {
  1379. pComp = This->pComps[i];
  1380. break;
  1381. }
  1382. }
  1383. // Nothing to do if we can't find the component
  1384. //
  1385. if (pComp == NULL)
  1386. {
  1387. return ERROR_NOT_FOUND;
  1388. }
  1389. // Reload the component information
  1390. //
  1391. if (dwComponentId == NETCFGDB_ID_FILEPRINT)
  1392. {
  1393. svcGetEnabling(&(pComp->bEnabled), NETCFGDB_ID_FILEPRINT);
  1394. }
  1395. return NO_ERROR;
  1396. }
  1397. //
  1398. // Reverts the database to the state it was in when opened
  1399. //
  1400. DWORD
  1401. netDbRollback (
  1402. IN HANDLE hNetCompDatabase)
  1403. {
  1404. RASSRV_COMPONENT_DB * This = (RASSRV_COMPONENT_DB*)hNetCompDatabase;
  1405. if (!This)
  1406. {
  1407. return ERROR_INVALID_PARAMETER;
  1408. }
  1409. This->bFlushOnClose = FALSE;
  1410. return NO_ERROR;
  1411. }
  1412. //
  1413. // Special function denotes whether the network tab has been
  1414. // loaded
  1415. //
  1416. BOOL
  1417. netDbIsLoaded (
  1418. IN HANDLE hNetCompDatabase)
  1419. {
  1420. RASSRV_COMPONENT_DB * This = (RASSRV_COMPONENT_DB*)hNetCompDatabase;
  1421. if (!This)
  1422. {
  1423. return ERROR_INVALID_PARAMETER;
  1424. }
  1425. return (!!(This->pINetCfg));// || (This->bHasINetCfgLock));
  1426. }
  1427. //
  1428. // Gets the number of components in the database
  1429. //
  1430. DWORD
  1431. netDbGetCompCount (
  1432. IN HANDLE hNetCompDatabase,
  1433. OUT LPDWORD lpdwCount)
  1434. {
  1435. RASSRV_COMPONENT_DB * This = (RASSRV_COMPONENT_DB*)hNetCompDatabase;
  1436. DWORD i;
  1437. // Validate parameters
  1438. if (!This || !lpdwCount)
  1439. {
  1440. return ERROR_INVALID_PARAMETER;
  1441. }
  1442. *lpdwCount = This->dwCompCount;
  1443. return NO_ERROR;
  1444. }
  1445. //
  1446. // Returns a pointer to the name of a component (don't alter it)
  1447. //
  1448. DWORD
  1449. netDbGetName(
  1450. IN HANDLE hNetCompDatabase,
  1451. IN DWORD dwIndex,
  1452. OUT PWCHAR* pszName)
  1453. {
  1454. RASSRV_COMPONENT_DB * This = (RASSRV_COMPONENT_DB*)hNetCompDatabase;
  1455. // Validate
  1456. if (!This || !pszName)
  1457. {
  1458. return ERROR_INVALID_PARAMETER;
  1459. }
  1460. // Bounds check
  1461. if (!netDbBoundsCheck(This, dwIndex))
  1462. {
  1463. return ERROR_INVALID_INDEX;
  1464. }
  1465. // return the name
  1466. *pszName = This->pComps[dwIndex]->pszName;
  1467. return NO_ERROR;
  1468. }
  1469. //
  1470. // Returns a description of a component (don't alter it)
  1471. //
  1472. DWORD
  1473. netDbGetDesc(
  1474. IN HANDLE hNetCompDatabase,
  1475. IN DWORD dwIndex,
  1476. IN PWCHAR* pszName)
  1477. {
  1478. RASSRV_COMPONENT_DB * This = (RASSRV_COMPONENT_DB*)hNetCompDatabase;
  1479. // Validate
  1480. if (!This || !pszName)
  1481. {
  1482. return ERROR_INVALID_PARAMETER;
  1483. }
  1484. // Bounds check
  1485. if (!netDbBoundsCheck(This, dwIndex))
  1486. {
  1487. return ERROR_INVALID_INDEX;
  1488. }
  1489. // return the name
  1490. *pszName = This->pComps[dwIndex]->pszDesc;
  1491. return NO_ERROR;
  1492. }
  1493. //
  1494. // Returns a type of a component (don't alter it)
  1495. //
  1496. DWORD
  1497. netDbGetType (
  1498. IN HANDLE hNetCompDatabase,
  1499. IN DWORD dwIndex,
  1500. OUT LPDWORD lpdwType)
  1501. {
  1502. RASSRV_COMPONENT_DB * This = (RASSRV_COMPONENT_DB*)hNetCompDatabase;
  1503. // Validate
  1504. if (!This || !lpdwType)
  1505. {
  1506. return ERROR_INVALID_PARAMETER;
  1507. }
  1508. // Bounds check
  1509. if (!netDbBoundsCheck(This, dwIndex))
  1510. {
  1511. return ERROR_INVALID_INDEX;
  1512. }
  1513. // return the name
  1514. *lpdwType = This->pComps[dwIndex]->dwType;
  1515. return NO_ERROR;
  1516. }
  1517. //
  1518. // Get a component id
  1519. //
  1520. DWORD
  1521. netDbGetId(
  1522. IN HANDLE hNetCompDatabase,
  1523. IN DWORD dwIndex,
  1524. OUT LPDWORD lpdwId)
  1525. {
  1526. RASSRV_COMPONENT_DB * This = (RASSRV_COMPONENT_DB*)hNetCompDatabase;
  1527. // Validate
  1528. if (!This || !lpdwId)
  1529. {
  1530. return ERROR_INVALID_PARAMETER;
  1531. }
  1532. // Bounds check
  1533. if (!netDbBoundsCheck(This, dwIndex))
  1534. {
  1535. return ERROR_INVALID_INDEX;
  1536. }
  1537. // return the name
  1538. *lpdwId = This->pComps[dwIndex]->dwId;
  1539. return NO_ERROR;
  1540. }
  1541. //
  1542. // Gets whether the given component is enabled. For non-ras-manipulatable
  1543. // components, this yields TRUE
  1544. //
  1545. DWORD
  1546. netDbGetEnable(
  1547. IN HANDLE hNetCompDatabase,
  1548. IN DWORD dwIndex,
  1549. OUT PBOOL pbEnabled)
  1550. {
  1551. RASSRV_COMPONENT_DB * This = (RASSRV_COMPONENT_DB*)hNetCompDatabase;
  1552. // Validate
  1553. if (!This || !pbEnabled)
  1554. {
  1555. return ERROR_INVALID_PARAMETER;
  1556. }
  1557. // Bounds check
  1558. if (!netDbBoundsCheck(This, dwIndex))
  1559. {
  1560. return ERROR_INVALID_INDEX;
  1561. }
  1562. // return the name
  1563. if (This->pComps[dwIndex]->bManip)
  1564. {
  1565. *pbEnabled = This->pComps[dwIndex]->bEnabled;
  1566. }
  1567. else
  1568. {
  1569. *pbEnabled = TRUE;
  1570. }
  1571. return NO_ERROR;
  1572. }
  1573. //
  1574. // Gets whether the given component is enabled. This function only has
  1575. // effect on ras-manipulatable components.
  1576. //
  1577. DWORD
  1578. netDbSetEnable(
  1579. IN HANDLE hNetCompDatabase,
  1580. IN DWORD dwIndex,
  1581. IN BOOL bEnabled)
  1582. {
  1583. RASSRV_COMPONENT_DB * This = (RASSRV_COMPONENT_DB*)hNetCompDatabase;
  1584. // Validate
  1585. if (!This)
  1586. {
  1587. return ERROR_INVALID_PARAMETER;
  1588. }
  1589. // Bounds check
  1590. if (!netDbBoundsCheck(This, dwIndex))
  1591. {
  1592. return ERROR_INVALID_INDEX;
  1593. }
  1594. // return the name
  1595. This->pComps[dwIndex]->bEnabled = bEnabled;
  1596. return NO_ERROR;
  1597. }
  1598. //
  1599. // Returns whether the given network component can
  1600. // be manipulated by ras server.
  1601. //
  1602. DWORD
  1603. netDbIsRasManipulatable (
  1604. IN HANDLE hNetCompDatabase,
  1605. IN DWORD dwIndex,
  1606. OUT PBOOL pbManip)
  1607. {
  1608. RASSRV_COMPONENT_DB * This = (RASSRV_COMPONENT_DB*)hNetCompDatabase;
  1609. // Validate
  1610. if (!This || !pbManip)
  1611. {
  1612. return ERROR_INVALID_PARAMETER;
  1613. }
  1614. // Bounds check
  1615. if (! netDbBoundsCheck(This, dwIndex))
  1616. {
  1617. return ERROR_INVALID_INDEX;
  1618. }
  1619. // return the name
  1620. *pbManip = This->pComps[dwIndex]->bManip;
  1621. return NO_ERROR;
  1622. }
  1623. //
  1624. ////Disable/Enable the Uninstall button for whislter bug 347355 gangz
  1625. //
  1626. DWORD
  1627. netDbHasRemovePermission(
  1628. IN HANDLE hNetCompDatabase,
  1629. IN DWORD dwIndex,
  1630. OUT PBOOL pbHasPermit)
  1631. {
  1632. RASSRV_COMPONENT_DB * This = NULL;
  1633. INetCfgComponent* pComponent = NULL;
  1634. BOOL fEnableRemove = FALSE;
  1635. HRESULT hr = S_OK;
  1636. DWORD dwErr = NO_ERROR, dwFlags;
  1637. //Disable/Enable Uninstall button according to its user permission and user
  1638. // removability
  1639. //
  1640. do
  1641. {
  1642. This = (RASSRV_COMPONENT_DB*)hNetCompDatabase;
  1643. // Validate pointer
  1644. if (!This || !pbHasPermit || ( -1 == dwIndex ))
  1645. {
  1646. dwErr = ERROR_INVALID_PARAMETER;
  1647. break;
  1648. }
  1649. // Make sure that netshell library has been opened
  1650. if (!This->pNetConUtilities)
  1651. {
  1652. dwErr = ERROR_CAN_NOT_COMPLETE;
  1653. break;
  1654. }
  1655. if (dwIndex >= This->dwCompCount)
  1656. {
  1657. dwErr = ERROR_CAN_NOT_COMPLETE;
  1658. break;
  1659. }
  1660. ASSERT(This->pComps[dwIndex]);
  1661. if( !(This->pComps[dwIndex]) )
  1662. {
  1663. dwErr = ERROR_CAN_NOT_COMPLETE;
  1664. break;
  1665. }
  1666. fEnableRemove = This->pComps[dwIndex]->bRemovable;
  1667. *pbHasPermit = fEnableRemove;
  1668. }
  1669. while(FALSE);
  1670. return dwErr;
  1671. }
  1672. //
  1673. // Returns whether the given network component has
  1674. // a properties ui that it can raise
  1675. //
  1676. DWORD
  1677. netDbHasPropertiesUI(
  1678. IN HANDLE hNetCompDatabase,
  1679. IN DWORD dwIndex,
  1680. OUT PBOOL pbHasUi)
  1681. {
  1682. RASSRV_COMPONENT_DB * This = (RASSRV_COMPONENT_DB*)hNetCompDatabase;
  1683. RASSRV_NET_COMPONENT* pComp = NULL;
  1684. // Validate
  1685. if (!This || !pbHasUi)
  1686. {
  1687. return ERROR_INVALID_PARAMETER;
  1688. }
  1689. // Bounds check
  1690. if (!netDbBoundsCheck(This, dwIndex))
  1691. {
  1692. return ERROR_INVALID_INDEX;
  1693. }
  1694. pComp = This->pComps[dwIndex];
  1695. if ((pComp->bManip) && (pComp->dwType == NETCFGDB_PROTOCOL))
  1696. {
  1697. *pbHasUi = TRUE;
  1698. }
  1699. else
  1700. {
  1701. *pbHasUi = pComp->bHasUi;
  1702. }
  1703. return NO_ERROR;
  1704. }
  1705. //
  1706. // Raises the properties of the component at the given index
  1707. //
  1708. DWORD
  1709. netDbRaisePropertiesDialog (
  1710. IN HANDLE hNetCompDatabase,
  1711. IN DWORD dwIndex,
  1712. IN HWND hwndParent)
  1713. {
  1714. RASSRV_COMPONENT_DB * This = (RASSRV_COMPONENT_DB*)hNetCompDatabase;
  1715. RASSRV_NET_COMPONENT* pComp = NULL;
  1716. // Validate
  1717. if (!This)
  1718. {
  1719. return ERROR_INVALID_PARAMETER;
  1720. }
  1721. // Bounds check
  1722. if (dwIndex >= This->dwCompCount)
  1723. {
  1724. return ERROR_INVALID_INDEX;
  1725. }
  1726. pComp = This->pComps[dwIndex];
  1727. // If this is a ras-manipulatable protocol, raise its
  1728. // properties manually.
  1729. if ((pComp->bManip) && (pComp->dwType == NETCFGDB_PROTOCOL))
  1730. {
  1731. netDbRaiseRasProps(This->pComps[dwIndex], hwndParent);
  1732. }
  1733. // Otherwise, let inetcfg do the work
  1734. else
  1735. {
  1736. return INetCfgComponent_RaisePropertyUi (
  1737. pComp->pINetCfgComp,
  1738. hwndParent,
  1739. NCRP_SHOW_PROPERTY_UI,
  1740. NULL);
  1741. }
  1742. return NO_ERROR;
  1743. }
  1744. //
  1745. // Brings up the UI that allows a user to install a component
  1746. //
  1747. DWORD
  1748. netDbRaiseInstallDialog(
  1749. IN HANDLE hNetCompDatabase,
  1750. IN HWND hwndParent)
  1751. {
  1752. RASSRV_COMPONENT_DB * This = (RASSRV_COMPONENT_DB*)hNetCompDatabase;
  1753. HRESULT hr;
  1754. // Validate
  1755. if (!This)
  1756. {
  1757. return ERROR_INVALID_PARAMETER;
  1758. }
  1759. // Make sure that netshell library has been opened
  1760. if (!This->pNetConUtilities)
  1761. {
  1762. return ERROR_CAN_NOT_COMPLETE;
  1763. }
  1764. else
  1765. {
  1766. // If we have our pointer to the function used to bring up the add
  1767. // component dialog (obtained above only once), call it.
  1768. HRESULT hr = S_OK;
  1769. // We want to filter out protocols that RAS does not care about
  1770. // We do this by sending in a CI_FILTER_INFO structure indicating
  1771. // we want non-RAS protocols filtered out
  1772. //
  1773. CI_FILTER_INFO cfi = {0};
  1774. cfi.eFilter = FC_RASSRV;
  1775. hr = INetConnectionUiUtilities_DisplayAddComponentDialog(
  1776. This->pNetConUtilities,
  1777. hwndParent,
  1778. This->pINetCfg,
  1779. &cfi);
  1780. // Ui will handle reboot
  1781. if (hr == NETCFG_S_REBOOT)
  1782. {
  1783. netDbReload(hNetCompDatabase);
  1784. return hr;
  1785. }
  1786. // If the user didn't cancel, refresh the database.
  1787. if (S_FALSE != hr)
  1788. {
  1789. if (SUCCEEDED (hr))
  1790. {
  1791. netDbReload(hNetCompDatabase);
  1792. return NO_ERROR;
  1793. }
  1794. else
  1795. {
  1796. return hr;
  1797. }
  1798. }
  1799. }
  1800. return ERROR_CANCELLED;
  1801. }
  1802. //
  1803. // Uninstalls the given component
  1804. //
  1805. DWORD
  1806. netDbRaiseRemoveDialog (
  1807. IN HANDLE hNetCompDatabase,
  1808. IN DWORD dwIndex,
  1809. IN HWND hwndParent)
  1810. {
  1811. RASSRV_COMPONENT_DB * This = (RASSRV_COMPONENT_DB*)hNetCompDatabase;
  1812. HRESULT hr;
  1813. // Validate
  1814. if (!This)
  1815. {
  1816. return ERROR_INVALID_PARAMETER;
  1817. }
  1818. // Make sure that netshell library has been opened
  1819. if (!This->pNetConUtilities)
  1820. {
  1821. return ERROR_CAN_NOT_COMPLETE;
  1822. }
  1823. // If we have our pointer to the function used to bring up the add
  1824. // component dialog (obtained above only once), call it.
  1825. if (dwIndex < This->dwCompCount)
  1826. {
  1827. if (This->pComps[dwIndex]->pINetCfgComp)
  1828. {
  1829. hr = INetConnectionUiUtilities_QueryUserAndRemoveComponent(
  1830. This->pNetConUtilities,
  1831. hwndParent,
  1832. This->pINetCfg,
  1833. This->pComps[dwIndex]->pINetCfgComp);
  1834. // Ui will handle reboot
  1835. if (hr == NETCFG_S_REBOOT)
  1836. {
  1837. netDbReload(hNetCompDatabase);
  1838. return hr;
  1839. }
  1840. // If the user didn't cancel, refresh the database.
  1841. else if (S_FALSE != hr)
  1842. {
  1843. if (SUCCEEDED (hr))
  1844. {
  1845. netDbReload(hNetCompDatabase);
  1846. return NO_ERROR;
  1847. }
  1848. else
  1849. {
  1850. return hr;
  1851. }
  1852. }
  1853. }
  1854. }
  1855. return ERROR_CANCELLED;
  1856. }