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.

2198 lines
53 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. WCHAR * pszwId = NULL;
  872. HRESULT hr = S_OK, hr2;
  873. // Make sure that this is not a "hidden" component
  874. //
  875. hr = INetCfgComponent_GetCharacteristics (pComponent, &dwCharacter);
  876. if ( (FAILED(hr)) || (dwCharacter & NCF_HIDDEN) )
  877. {
  878. return FALSE;
  879. }
  880. //
  881. //for .Net 605988 filter out IPX, at this point
  882. //pNetComp->pszId should be valid
  883. //
  884. if ( SUCCEEDED(INetCfgComponent_GetId (pComponent, &pszwId) ) )
  885. {
  886. WCHAR * pszwTmpId = NULL;
  887. pszwTmpId = StrDupWFromT(NETCFG_TRANS_CID_MS_NWIPX);
  888. if(pszwTmpId)
  889. {
  890. if ( 0 == lstrcmpW(pszwId, pszwTmpId))
  891. {
  892. Free0(pszwTmpId);
  893. CoTaskMemFree(pszwId);
  894. return FALSE;
  895. }
  896. Free0(pszwTmpId);
  897. }
  898. pszwTmpId = StrDupWFromT( TEXT("ms_nwnb") );
  899. if(pszwTmpId)
  900. {
  901. if ( 0 == lstrcmpW(pszwId, pszwTmpId))
  902. {
  903. Free0(pszwTmpId);
  904. CoTaskMemFree(pszwId);
  905. return FALSE;
  906. }
  907. Free0(pszwTmpId);
  908. }
  909. CoTaskMemFree(pszwId);
  910. }
  911. // Get the display name
  912. hr = INetCfgComponent_GetDisplayName (pComponent, &pNetComp->pszName);
  913. if (FAILED(hr))
  914. {
  915. return FALSE;
  916. }
  917. // Assign the has properties value
  918. pNetComp->bHasUi = !!(dwCharacter & NCF_HAS_UI);
  919. // pmay: 323274
  920. //
  921. // Make sure that the component can display properties without
  922. // a context if it claims to support displaying properties.
  923. //
  924. if (pNetComp->bHasUi)
  925. {
  926. hr2 = INetCfgComponent_RaisePropertyUi(
  927. pComponent,
  928. GetActiveWindow(),
  929. NCRP_QUERY_PROPERTY_UI,
  930. NULL);
  931. pNetComp->bHasUi = !!(hr2 == S_OK);
  932. }
  933. // Load the rest of the props
  934. if (FAILED(INetCfgComponent_GetClassGuid (pComponent, &Guid)) ||
  935. FAILED(INetCfgComponent_GetId (pComponent, &pNetComp->pszId)) ||
  936. FAILED(INetCfgComponent_GetHelpText(pComponent, &pNetComp->pszDesc))
  937. )
  938. {
  939. DbgOutputTrace("GetCompInfo: fail %S", pNetComp->pszName);
  940. return FALSE;
  941. }
  942. // Assign the type
  943. if (memcmp(&Guid, &GUID_DEVCLASS_NETCLIENT, sizeof(GUID)) == 0)
  944. {
  945. pNetComp->dwType = NETCFGDB_CLIENT;
  946. }
  947. else if (memcmp(&Guid, &GUID_DEVCLASS_NETSERVICE, sizeof(GUID)) == 0)
  948. {
  949. pNetComp->dwType = NETCFGDB_SERVICE;
  950. }
  951. else
  952. {
  953. pNetComp->dwType = NETCFGDB_PROTOCOL;
  954. }
  955. // If this is a protocol that ras server can manipulate,
  956. // initailize its additional fields here.
  957. pNetComp->dwId = netDbLoadCompId(pNetComp);
  958. if (pNetComp->dwId != NETCFGDB_ID_OTHER)
  959. {
  960. if (pNetComp->dwType == NETCFGDB_PROTOCOL)
  961. {
  962. netDbLoadProtcolInfo(pNetComp);
  963. }
  964. else if (pNetComp->dwType == NETCFGDB_SERVICE)
  965. {
  966. netDbLoadServiceInfo(pNetComp);
  967. }
  968. pNetComp->bManip = TRUE;
  969. }
  970. // Assign the inetcfg component
  971. pNetComp->pINetCfgComp = pComponent;
  972. INetCfgComponent_AddRef(pComponent);
  973. //For whistler bug 347355
  974. //
  975. {
  976. BOOL fEnableRemove=FALSE;
  977. DWORD dwFlags;
  978. fEnableRemove = INetConnectionUiUtilities_UserHasPermission(
  979. pCompDb->pNetConUtilities,
  980. NCPERM_AddRemoveComponents);
  981. hr = INetCfgComponent_GetCharacteristics(pComponent, &dwFlags );
  982. if( SUCCEEDED(hr) && (NCF_NOT_USER_REMOVABLE & dwFlags) )
  983. {
  984. fEnableRemove = FALSE;
  985. }
  986. pNetComp->bRemovable = fEnableRemove;
  987. }
  988. return TRUE;
  989. }
  990. //
  991. // Raise the ui for a ras-manipulatable protocol
  992. //
  993. DWORD
  994. netDbRaiseRasProps(
  995. IN RASSRV_NET_COMPONENT * pNetComp,
  996. IN HWND hwndParent)
  997. {
  998. PROT_EDIT_DATA ProtEditData;
  999. TCPIP_PARAMS TcpParams;
  1000. IPX_PARAMS IpxParams;
  1001. BOOL bOk;
  1002. DWORD dwErr;
  1003. // Initialize the protocol data properties structure
  1004. //
  1005. ProtEditData.bExpose = pNetComp->bExposes;
  1006. ProtEditData.pbData = NULL;
  1007. // Launch the appropriate ui
  1008. switch (pNetComp->dwId)
  1009. {
  1010. case NETCFGDB_ID_IP:
  1011. CopyMemory(&TcpParams, pNetComp->pbData, sizeof(TCPIP_PARAMS));
  1012. ProtEditData.pbData = (LPBYTE)(&TcpParams);
  1013. dwErr = TcpipEditProperties(hwndParent, &ProtEditData, &bOk);
  1014. if (dwErr != NO_ERROR)
  1015. {
  1016. return dwErr;
  1017. }
  1018. if (bOk)
  1019. {
  1020. pNetComp->bDataDirty = TRUE;
  1021. CopyMemory(
  1022. pNetComp->pbData,
  1023. &TcpParams,
  1024. sizeof(TCPIP_PARAMS));
  1025. pNetComp->bExposes = ProtEditData.bExpose;;
  1026. }
  1027. break;
  1028. case NETCFGDB_ID_IPX:
  1029. CopyMemory(&IpxParams, pNetComp->pbData, sizeof(IPX_PARAMS));
  1030. ProtEditData.pbData = (LPBYTE)(&IpxParams);
  1031. dwErr = IpxEditProperties(hwndParent, &ProtEditData, &bOk);
  1032. if (dwErr != NO_ERROR)
  1033. {
  1034. return dwErr;
  1035. }
  1036. if (bOk)
  1037. {
  1038. pNetComp->bDataDirty = TRUE;
  1039. CopyMemory(pNetComp->pbData, &IpxParams, sizeof(IPX_PARAMS));
  1040. pNetComp->bExposes = ProtEditData.bExpose;;
  1041. }
  1042. break;
  1043. default:
  1044. dwErr = GenericProtocolEditProperties(
  1045. hwndParent,
  1046. &ProtEditData,
  1047. &bOk);
  1048. if (dwErr != NO_ERROR)
  1049. {
  1050. return dwErr;
  1051. }
  1052. if (bOk)
  1053. {
  1054. pNetComp->bDataDirty = TRUE;
  1055. pNetComp->bExposes = ProtEditData.bExpose;;
  1056. }
  1057. break;
  1058. }
  1059. return NO_ERROR;
  1060. }
  1061. //
  1062. // Comparison function used to sort the network components
  1063. // It's easier to implement here rather than the UI
  1064. //
  1065. int
  1066. __cdecl
  1067. netDbCompare (
  1068. CONST VOID* pElem1,
  1069. CONST VOID* pElem2)
  1070. {
  1071. RASSRV_NET_COMPONENT * pc1 = *((RASSRV_NET_COMPONENT **)pElem1);
  1072. RASSRV_NET_COMPONENT * pc2 = *((RASSRV_NET_COMPONENT **)pElem2);
  1073. if (pc1->bManip == pc2->bManip)
  1074. {
  1075. if (pc1->bManip == FALSE)
  1076. {
  1077. return 0;
  1078. }
  1079. if (pc1->dwId == pc2->dwId)
  1080. {
  1081. return 0;
  1082. }
  1083. else if (pc1->dwId < pc2->dwId)
  1084. {
  1085. return -1;
  1086. }
  1087. return 1;
  1088. }
  1089. else if (pc1->bManip)
  1090. {
  1091. return -1;
  1092. }
  1093. return 1;
  1094. }
  1095. //
  1096. // Opens the database of network config components
  1097. //
  1098. DWORD
  1099. netDbOpen (
  1100. OUT PHANDLE phNetCompDatabase,
  1101. IN PWCHAR pszClientName)
  1102. {
  1103. RASSRV_COMPONENT_DB * This;
  1104. DWORD dwLength;
  1105. // Validate parameters
  1106. if (! phNetCompDatabase || !pszClientName)
  1107. {
  1108. return ERROR_INVALID_PARAMETER;
  1109. }
  1110. // Allocate the database
  1111. This = RassrvAlloc (sizeof(RASSRV_COMPONENT_DB), TRUE);
  1112. if (This == NULL)
  1113. {
  1114. return ERROR_NOT_ENOUGH_MEMORY;
  1115. }
  1116. // Initialize
  1117. dwLength = wcslen(pszClientName);
  1118. if (dwLength)
  1119. {
  1120. This->pszClientName =
  1121. RassrvAlloc((dwLength + 1) * sizeof(WCHAR), FALSE);
  1122. if (This->pszClientName)
  1123. {
  1124. wcscpy(This->pszClientName, pszClientName);
  1125. }
  1126. }
  1127. This->bFlushOnClose = FALSE;
  1128. *phNetCompDatabase = (HANDLE)This;
  1129. // Load the net shell library
  1130. netDbLoadNetShell(This);
  1131. return NO_ERROR;
  1132. }
  1133. //
  1134. // Cleans up all resources held by the database
  1135. //
  1136. DWORD
  1137. netDbClose (
  1138. IN HANDLE hNetCompDatabase)
  1139. {
  1140. RASSRV_COMPONENT_DB* This = (RASSRV_COMPONENT_DB*)hNetCompDatabase;
  1141. // Validate parameters
  1142. if (!This)
  1143. {
  1144. return ERROR_INVALID_PARAMETER;
  1145. }
  1146. // Flush if needed
  1147. if (This->bFlushOnClose)
  1148. {
  1149. netDbFlush(hNetCompDatabase);
  1150. }
  1151. else
  1152. {
  1153. // If we've made changes to inetcfg that require backing out,
  1154. // do so now.
  1155. if (This->pINetCfg)
  1156. {
  1157. INetCfg_Cancel(This->pINetCfg);
  1158. }
  1159. }
  1160. netDbCleanup(This);
  1161. // Free the client name
  1162. if (This->pszClientName)
  1163. {
  1164. RassrvFree(This->pszClientName);
  1165. }
  1166. // Release our reference to inetcfg. We will still have it
  1167. // at this point if a protocol/client/service was added.
  1168. if (This->pINetCfg)
  1169. {
  1170. HrUninitializeAndReleaseINetCfg (
  1171. This->bInitCom,
  1172. This->pINetCfg,
  1173. This->bHasINetCfgLock);
  1174. }
  1175. // Free the netshell library if appropriate
  1176. if (This->pNetConUtilities)
  1177. {
  1178. INetConnectionUiUtilities_Release(This->pNetConUtilities);
  1179. }
  1180. // Free this
  1181. RassrvFree(This);
  1182. return NO_ERROR;
  1183. }
  1184. // Commits all changes to the database to the system
  1185. DWORD
  1186. netDbFlush (
  1187. IN HANDLE hNetCompDatabase)
  1188. {
  1189. RASSRV_COMPONENT_DB * This = (RASSRV_COMPONENT_DB*)hNetCompDatabase;
  1190. RASSRV_NET_COMPONENT* pComp = NULL;
  1191. DWORD i;
  1192. // Validate parameters
  1193. if (!This)
  1194. {
  1195. return ERROR_INVALID_PARAMETER;
  1196. }
  1197. // Flush any ras-manipulatable's data if dirty
  1198. for (i = 0; i < This->dwCompCount; i++)
  1199. {
  1200. pComp = This->pComps[i];
  1201. // If the enabling of this component has changed, commit
  1202. // that change
  1203. if ((pComp->bEnabled != pComp->bEnabledOrig) && (pComp->bManip))
  1204. {
  1205. if (pComp ->dwType == NETCFGDB_PROTOCOL)
  1206. {
  1207. protSetEnabling(
  1208. pComp->bEnabled,
  1209. pComp->dwId);
  1210. }
  1211. else if (pComp->dwType == NETCFGDB_SERVICE)
  1212. {
  1213. svcSetEnabling(pComp);
  1214. }
  1215. }
  1216. // If the ras-server-specific properties of the component
  1217. // have changed, commit the changes.
  1218. if (pComp->bDataDirty)
  1219. {
  1220. protSetExpose(pComp->bExposes, pComp->dwId);
  1221. switch (pComp->dwId)
  1222. {
  1223. case NETCFGDB_ID_IP:
  1224. {
  1225. TCPIP_PARAMS* pTcpParams =
  1226. (TCPIP_PARAMS*)(pComp->pbData);
  1227. TcpipSaveParamsToSystem(pTcpParams);
  1228. }
  1229. break;
  1230. case NETCFGDB_ID_IPX:
  1231. {
  1232. IPX_PARAMS* pIpxParams =
  1233. (IPX_PARAMS*)(pComp->pbData);
  1234. IpxSaveParamsToSystem(pIpxParams);
  1235. }
  1236. break;
  1237. }
  1238. }
  1239. }
  1240. // If we have a pointer to the inetcfg instance then we can
  1241. // commit the changes now
  1242. if (This->pINetCfg)
  1243. {
  1244. INetCfg_Apply(This->pINetCfg);
  1245. }
  1246. return NO_ERROR;
  1247. }
  1248. //
  1249. // Loads the net config database for the first time. Because inetcfg
  1250. // requires time to load and be manipulated, we delay the load of this
  1251. // database until it is explicitly requested.
  1252. //
  1253. DWORD
  1254. netDbLoad(
  1255. IN HANDLE hNetCompDatabase)
  1256. {
  1257. return netDbReload(hNetCompDatabase);
  1258. }
  1259. //
  1260. // Reloads net information from system
  1261. //
  1262. DWORD
  1263. netDbReload(
  1264. IN HANDLE hNetCompDatabase)
  1265. {
  1266. RASSRV_COMPONENT_DB * This = (RASSRV_COMPONENT_DB*)hNetCompDatabase;
  1267. DWORD i, j, dwProtCount = 0, dwRefCount;
  1268. HRESULT hr;
  1269. RASSRV_NET_COMPONENT TempComp;
  1270. INetCfgComponent* pComponents [256];
  1271. PWCHAR pszName = NULL;
  1272. static const GUID* c_apguidClasses [] =
  1273. {
  1274. &GUID_DEVCLASS_NETTRANS,
  1275. &GUID_DEVCLASS_NETCLIENT,
  1276. &GUID_DEVCLASS_NETSERVICE,
  1277. };
  1278. // Validate
  1279. if (!This)
  1280. {
  1281. return ERROR_INVALID_PARAMETER;
  1282. }
  1283. DbgOutputTrace(
  1284. "netDbReload %x %x %x %x %x %x %x %x",
  1285. This->pINetCfg,
  1286. This->bHasINetCfgLock,
  1287. This->bInitCom,
  1288. This->dwCompCount,
  1289. This->bFlushOnClose,
  1290. This->pComps,
  1291. This->pszClientName,
  1292. This->pNetConUtilities);
  1293. // Cleanup any previous values
  1294. netDbCleanup(This);
  1295. // If we don't have a reference to inetcfg yet, get it
  1296. // here.
  1297. if (This->pINetCfg == NULL)
  1298. {
  1299. This->bInitCom = TRUE;
  1300. This->bHasINetCfgLock = TRUE;
  1301. hr = HrCreateAndInitializeINetCfg(
  1302. &This->bInitCom,
  1303. &This->pINetCfg,
  1304. TRUE,
  1305. 0,
  1306. This->pszClientName,
  1307. NULL);
  1308. // Handle error conditions here
  1309. if (S_FALSE == hr)
  1310. {
  1311. return ERROR_CAN_NOT_COMPLETE;
  1312. }
  1313. else if (FAILED(hr))
  1314. {
  1315. return ERROR_CAN_NOT_COMPLETE;
  1316. }
  1317. }
  1318. //
  1319. // Enumerate all of the client and service components in the system.
  1320. //
  1321. hr = HrEnumComponentsInClasses (
  1322. This->pINetCfg,
  1323. sizeof(c_apguidClasses) / sizeof(c_apguidClasses[0]),
  1324. (GUID**)c_apguidClasses,
  1325. sizeof(pComponents) / sizeof(pComponents[0]),
  1326. pComponents,
  1327. &This->dwCompCount);
  1328. if (!SUCCEEDED(hr))
  1329. {
  1330. return ERROR_CAN_NOT_COMPLETE;
  1331. }
  1332. // Initialize the array of internal objects
  1333. This->pComps = RassrvAlloc (
  1334. This->dwCompCount * sizeof (RASSRV_NET_COMPONENT*),
  1335. TRUE);
  1336. if (!This->pComps)
  1337. {
  1338. return ERROR_NOT_ENOUGH_MEMORY;
  1339. }
  1340. // Initialize the installed component array
  1341. //
  1342. j = 0;
  1343. ZeroMemory(&TempComp, sizeof(TempComp));
  1344. for (i = 0; i < This->dwCompCount; i++)
  1345. {
  1346. pszName = L"";
  1347. //Add this (RASSRV_COMPONENT_DB *) for whistler bug 347355
  1348. //
  1349. if (netDbGetCompInfo(pComponents[i], &TempComp, This))
  1350. {
  1351. //
  1352. // Currently we do not support IPv6 for incoming connections.
  1353. // If this component is IPv6, skip it
  1354. //
  1355. if ((TempComp.dwType == NETCFGDB_PROTOCOL) &&
  1356. (lstrcmpi(TempComp.pszId, TEXT("ms_tcpip6")) == 0))
  1357. {
  1358. dwRefCount = INetCfgComponent_Release(pComponents[i]);
  1359. DbgOutputTrace(
  1360. "netDbReload: skipping %ls ref=%d", pszName, dwRefCount);
  1361. continue;
  1362. }
  1363. This->pComps[j] =
  1364. RassrvAlloc (sizeof(RASSRV_NET_COMPONENT), FALSE);
  1365. if (!This->pComps[j])
  1366. {
  1367. return ERROR_NOT_ENOUGH_MEMORY;
  1368. }
  1369. // Fill in the fields
  1370. CopyMemory(This->pComps[j], &TempComp, sizeof(TempComp));
  1371. ZeroMemory(&TempComp, sizeof(TempComp));
  1372. if (This->pComps[j]->dwType == NETCFGDB_PROTOCOL)
  1373. {
  1374. dwProtCount++;
  1375. }
  1376. pszName = This->pComps[j]->pszName;
  1377. j++;
  1378. }
  1379. dwRefCount = INetCfgComponent_Release(pComponents[i]);
  1380. DbgOutputTrace(
  1381. "netDbReload: %ls ref=%d", pszName, dwRefCount);
  1382. }
  1383. This->dwCompCount = j;
  1384. // Sort the array.
  1385. //
  1386. qsort(
  1387. This->pComps,
  1388. This->dwCompCount,
  1389. sizeof(This->pComps[0]),
  1390. netDbCompare);
  1391. return NO_ERROR;
  1392. }
  1393. //
  1394. // Reload the status of a given component
  1395. //
  1396. DWORD
  1397. netDbReloadComponent (
  1398. IN HANDLE hNetCompDatabase,
  1399. IN DWORD dwComponentId)
  1400. {
  1401. RASSRV_COMPONENT_DB * This = (RASSRV_COMPONENT_DB*)hNetCompDatabase;
  1402. RASSRV_NET_COMPONENT* pComp = NULL;
  1403. DWORD i;
  1404. // Validate
  1405. if (!This)
  1406. {
  1407. return ERROR_INVALID_PARAMETER;
  1408. }
  1409. // Currently, we only need to support the fileprint
  1410. // component
  1411. //
  1412. if (dwComponentId != NETCFGDB_ID_FILEPRINT)
  1413. {
  1414. return ERROR_INVALID_PARAMETER;
  1415. }
  1416. // Find the appropriate component
  1417. //
  1418. for (i = 0; i < This->dwCompCount; i++)
  1419. {
  1420. if (This->pComps[i]->dwId == dwComponentId)
  1421. {
  1422. pComp = This->pComps[i];
  1423. break;
  1424. }
  1425. }
  1426. // Nothing to do if we can't find the component
  1427. //
  1428. if (pComp == NULL)
  1429. {
  1430. return ERROR_NOT_FOUND;
  1431. }
  1432. // Reload the component information
  1433. //
  1434. if (dwComponentId == NETCFGDB_ID_FILEPRINT)
  1435. {
  1436. svcGetEnabling(&(pComp->bEnabled), NETCFGDB_ID_FILEPRINT);
  1437. }
  1438. return NO_ERROR;
  1439. }
  1440. //
  1441. // Reverts the database to the state it was in when opened
  1442. //
  1443. DWORD
  1444. netDbRollback (
  1445. IN HANDLE hNetCompDatabase)
  1446. {
  1447. RASSRV_COMPONENT_DB * This = (RASSRV_COMPONENT_DB*)hNetCompDatabase;
  1448. if (!This)
  1449. {
  1450. return ERROR_INVALID_PARAMETER;
  1451. }
  1452. This->bFlushOnClose = FALSE;
  1453. return NO_ERROR;
  1454. }
  1455. //
  1456. // Special function denotes whether the network tab has been
  1457. // loaded
  1458. //
  1459. BOOL
  1460. netDbIsLoaded (
  1461. IN HANDLE hNetCompDatabase)
  1462. {
  1463. RASSRV_COMPONENT_DB * This = (RASSRV_COMPONENT_DB*)hNetCompDatabase;
  1464. if (!This)
  1465. {
  1466. return ERROR_INVALID_PARAMETER;
  1467. }
  1468. return (!!(This->pINetCfg));// || (This->bHasINetCfgLock));
  1469. }
  1470. //
  1471. // Gets the number of components in the database
  1472. //
  1473. DWORD
  1474. netDbGetCompCount (
  1475. IN HANDLE hNetCompDatabase,
  1476. OUT LPDWORD lpdwCount)
  1477. {
  1478. RASSRV_COMPONENT_DB * This = (RASSRV_COMPONENT_DB*)hNetCompDatabase;
  1479. DWORD i;
  1480. // Validate parameters
  1481. if (!This || !lpdwCount)
  1482. {
  1483. return ERROR_INVALID_PARAMETER;
  1484. }
  1485. *lpdwCount = This->dwCompCount;
  1486. return NO_ERROR;
  1487. }
  1488. //
  1489. // Returns a pointer to the name of a component (don't alter it)
  1490. //
  1491. DWORD
  1492. netDbGetName(
  1493. IN HANDLE hNetCompDatabase,
  1494. IN DWORD dwIndex,
  1495. OUT PWCHAR* pszName)
  1496. {
  1497. RASSRV_COMPONENT_DB * This = (RASSRV_COMPONENT_DB*)hNetCompDatabase;
  1498. // Validate
  1499. if (!This || !pszName)
  1500. {
  1501. return ERROR_INVALID_PARAMETER;
  1502. }
  1503. // Bounds check
  1504. if (!netDbBoundsCheck(This, dwIndex))
  1505. {
  1506. return ERROR_INVALID_INDEX;
  1507. }
  1508. // return the name
  1509. *pszName = This->pComps[dwIndex]->pszName;
  1510. return NO_ERROR;
  1511. }
  1512. //
  1513. // Returns a description of a component (don't alter it)
  1514. //
  1515. DWORD
  1516. netDbGetDesc(
  1517. IN HANDLE hNetCompDatabase,
  1518. IN DWORD dwIndex,
  1519. IN PWCHAR* pszName)
  1520. {
  1521. RASSRV_COMPONENT_DB * This = (RASSRV_COMPONENT_DB*)hNetCompDatabase;
  1522. // Validate
  1523. if (!This || !pszName)
  1524. {
  1525. return ERROR_INVALID_PARAMETER;
  1526. }
  1527. // Bounds check
  1528. if (!netDbBoundsCheck(This, dwIndex))
  1529. {
  1530. return ERROR_INVALID_INDEX;
  1531. }
  1532. // return the name
  1533. *pszName = This->pComps[dwIndex]->pszDesc;
  1534. return NO_ERROR;
  1535. }
  1536. //
  1537. // Returns a type of a component (don't alter it)
  1538. //
  1539. DWORD
  1540. netDbGetType (
  1541. IN HANDLE hNetCompDatabase,
  1542. IN DWORD dwIndex,
  1543. OUT LPDWORD lpdwType)
  1544. {
  1545. RASSRV_COMPONENT_DB * This = (RASSRV_COMPONENT_DB*)hNetCompDatabase;
  1546. // Validate
  1547. if (!This || !lpdwType)
  1548. {
  1549. return ERROR_INVALID_PARAMETER;
  1550. }
  1551. // Bounds check
  1552. if (!netDbBoundsCheck(This, dwIndex))
  1553. {
  1554. return ERROR_INVALID_INDEX;
  1555. }
  1556. // return the name
  1557. *lpdwType = This->pComps[dwIndex]->dwType;
  1558. return NO_ERROR;
  1559. }
  1560. //
  1561. // Get a component id
  1562. //
  1563. DWORD
  1564. netDbGetId(
  1565. IN HANDLE hNetCompDatabase,
  1566. IN DWORD dwIndex,
  1567. OUT LPDWORD lpdwId)
  1568. {
  1569. RASSRV_COMPONENT_DB * This = (RASSRV_COMPONENT_DB*)hNetCompDatabase;
  1570. // Validate
  1571. if (!This || !lpdwId)
  1572. {
  1573. return ERROR_INVALID_PARAMETER;
  1574. }
  1575. // Bounds check
  1576. if (!netDbBoundsCheck(This, dwIndex))
  1577. {
  1578. return ERROR_INVALID_INDEX;
  1579. }
  1580. // return the name
  1581. *lpdwId = This->pComps[dwIndex]->dwId;
  1582. return NO_ERROR;
  1583. }
  1584. //
  1585. // Gets whether the given component is enabled. For non-ras-manipulatable
  1586. // components, this yields TRUE
  1587. //
  1588. DWORD
  1589. netDbGetEnable(
  1590. IN HANDLE hNetCompDatabase,
  1591. IN DWORD dwIndex,
  1592. OUT PBOOL pbEnabled)
  1593. {
  1594. RASSRV_COMPONENT_DB * This = (RASSRV_COMPONENT_DB*)hNetCompDatabase;
  1595. // Validate
  1596. if (!This || !pbEnabled)
  1597. {
  1598. return ERROR_INVALID_PARAMETER;
  1599. }
  1600. // Bounds check
  1601. if (!netDbBoundsCheck(This, dwIndex))
  1602. {
  1603. return ERROR_INVALID_INDEX;
  1604. }
  1605. // return the name
  1606. if (This->pComps[dwIndex]->bManip)
  1607. {
  1608. *pbEnabled = This->pComps[dwIndex]->bEnabled;
  1609. }
  1610. else
  1611. {
  1612. *pbEnabled = TRUE;
  1613. }
  1614. return NO_ERROR;
  1615. }
  1616. //
  1617. // Gets whether the given component is enabled. This function only has
  1618. // effect on ras-manipulatable components.
  1619. //
  1620. DWORD
  1621. netDbSetEnable(
  1622. IN HANDLE hNetCompDatabase,
  1623. IN DWORD dwIndex,
  1624. IN BOOL bEnabled)
  1625. {
  1626. RASSRV_COMPONENT_DB * This = (RASSRV_COMPONENT_DB*)hNetCompDatabase;
  1627. // Validate
  1628. if (!This)
  1629. {
  1630. return ERROR_INVALID_PARAMETER;
  1631. }
  1632. // Bounds check
  1633. if (!netDbBoundsCheck(This, dwIndex))
  1634. {
  1635. return ERROR_INVALID_INDEX;
  1636. }
  1637. // return the name
  1638. This->pComps[dwIndex]->bEnabled = bEnabled;
  1639. return NO_ERROR;
  1640. }
  1641. //
  1642. // Returns whether the given network component can
  1643. // be manipulated by ras server.
  1644. //
  1645. DWORD
  1646. netDbIsRasManipulatable (
  1647. IN HANDLE hNetCompDatabase,
  1648. IN DWORD dwIndex,
  1649. OUT PBOOL pbManip)
  1650. {
  1651. RASSRV_COMPONENT_DB * This = (RASSRV_COMPONENT_DB*)hNetCompDatabase;
  1652. // Validate
  1653. if (!This || !pbManip)
  1654. {
  1655. return ERROR_INVALID_PARAMETER;
  1656. }
  1657. // Bounds check
  1658. if (! netDbBoundsCheck(This, dwIndex))
  1659. {
  1660. return ERROR_INVALID_INDEX;
  1661. }
  1662. // return the name
  1663. *pbManip = This->pComps[dwIndex]->bManip;
  1664. return NO_ERROR;
  1665. }
  1666. //
  1667. ////Disable/Enable the Uninstall button for whislter bug 347355 gangz
  1668. //
  1669. DWORD
  1670. netDbHasRemovePermission(
  1671. IN HANDLE hNetCompDatabase,
  1672. IN DWORD dwIndex,
  1673. OUT PBOOL pbHasPermit)
  1674. {
  1675. RASSRV_COMPONENT_DB * This = NULL;
  1676. INetCfgComponent* pComponent = NULL;
  1677. BOOL fEnableRemove = FALSE;
  1678. HRESULT hr = S_OK;
  1679. DWORD dwErr = NO_ERROR, dwFlags;
  1680. //Disable/Enable Uninstall button according to its user permission and user
  1681. // removability
  1682. //
  1683. do
  1684. {
  1685. This = (RASSRV_COMPONENT_DB*)hNetCompDatabase;
  1686. // Validate pointer
  1687. if (!This || !pbHasPermit || ( -1 == dwIndex ))
  1688. {
  1689. dwErr = ERROR_INVALID_PARAMETER;
  1690. break;
  1691. }
  1692. // Make sure that netshell library has been opened
  1693. if (!This->pNetConUtilities)
  1694. {
  1695. dwErr = ERROR_CAN_NOT_COMPLETE;
  1696. break;
  1697. }
  1698. if (dwIndex >= This->dwCompCount)
  1699. {
  1700. dwErr = ERROR_CAN_NOT_COMPLETE;
  1701. break;
  1702. }
  1703. ASSERT(This->pComps[dwIndex]);
  1704. if( !(This->pComps[dwIndex]) )
  1705. {
  1706. dwErr = ERROR_CAN_NOT_COMPLETE;
  1707. break;
  1708. }
  1709. fEnableRemove = This->pComps[dwIndex]->bRemovable;
  1710. *pbHasPermit = fEnableRemove;
  1711. }
  1712. while(FALSE);
  1713. return dwErr;
  1714. }
  1715. //
  1716. // Returns whether the given network component has
  1717. // a properties ui that it can raise
  1718. //
  1719. DWORD
  1720. netDbHasPropertiesUI(
  1721. IN HANDLE hNetCompDatabase,
  1722. IN DWORD dwIndex,
  1723. OUT PBOOL pbHasUi)
  1724. {
  1725. RASSRV_COMPONENT_DB * This = (RASSRV_COMPONENT_DB*)hNetCompDatabase;
  1726. RASSRV_NET_COMPONENT* pComp = NULL;
  1727. // Validate
  1728. if (!This || !pbHasUi)
  1729. {
  1730. return ERROR_INVALID_PARAMETER;
  1731. }
  1732. // Bounds check
  1733. if (!netDbBoundsCheck(This, dwIndex))
  1734. {
  1735. return ERROR_INVALID_INDEX;
  1736. }
  1737. pComp = This->pComps[dwIndex];
  1738. if ((pComp->bManip) && (pComp->dwType == NETCFGDB_PROTOCOL))
  1739. {
  1740. *pbHasUi = TRUE;
  1741. }
  1742. else
  1743. {
  1744. *pbHasUi = pComp->bHasUi;
  1745. }
  1746. return NO_ERROR;
  1747. }
  1748. //
  1749. // Raises the properties of the component at the given index
  1750. //
  1751. DWORD
  1752. netDbRaisePropertiesDialog (
  1753. IN HANDLE hNetCompDatabase,
  1754. IN DWORD dwIndex,
  1755. IN HWND hwndParent)
  1756. {
  1757. RASSRV_COMPONENT_DB * This = (RASSRV_COMPONENT_DB*)hNetCompDatabase;
  1758. RASSRV_NET_COMPONENT* pComp = NULL;
  1759. // Validate
  1760. if (!This)
  1761. {
  1762. return ERROR_INVALID_PARAMETER;
  1763. }
  1764. // Bounds check
  1765. if (dwIndex >= This->dwCompCount)
  1766. {
  1767. return ERROR_INVALID_INDEX;
  1768. }
  1769. pComp = This->pComps[dwIndex];
  1770. // If this is a ras-manipulatable protocol, raise its
  1771. // properties manually.
  1772. if ((pComp->bManip) && (pComp->dwType == NETCFGDB_PROTOCOL))
  1773. {
  1774. netDbRaiseRasProps(This->pComps[dwIndex], hwndParent);
  1775. }
  1776. // Otherwise, let inetcfg do the work
  1777. else
  1778. {
  1779. return INetCfgComponent_RaisePropertyUi (
  1780. pComp->pINetCfgComp,
  1781. hwndParent,
  1782. NCRP_SHOW_PROPERTY_UI,
  1783. NULL);
  1784. }
  1785. return NO_ERROR;
  1786. }
  1787. //
  1788. // Brings up the UI that allows a user to install a component
  1789. //
  1790. DWORD
  1791. netDbRaiseInstallDialog(
  1792. IN HANDLE hNetCompDatabase,
  1793. IN HWND hwndParent)
  1794. {
  1795. RASSRV_COMPONENT_DB * This = (RASSRV_COMPONENT_DB*)hNetCompDatabase;
  1796. HRESULT hr = S_OK; // For whistler 524777
  1797. // Validate
  1798. if (!This)
  1799. {
  1800. return ERROR_INVALID_PARAMETER;
  1801. }
  1802. // Make sure that netshell library has been opened
  1803. if (!This->pNetConUtilities)
  1804. {
  1805. return ERROR_CAN_NOT_COMPLETE;
  1806. }
  1807. else
  1808. {
  1809. // If we have our pointer to the function used to bring up the add
  1810. // component dialog (obtained above only once), call it.
  1811. // We want to filter out protocols that RAS does not care about
  1812. // We do this by sending in a CI_FILTER_INFO structure indicating
  1813. // we want non-RAS protocols filtered out
  1814. //
  1815. CI_FILTER_INFO cfi = {0};
  1816. cfi.eFilter = FC_RASSRV;
  1817. hr = INetConnectionUiUtilities_DisplayAddComponentDialog(
  1818. This->pNetConUtilities,
  1819. hwndParent,
  1820. This->pINetCfg,
  1821. &cfi);
  1822. // Ui will handle reboot
  1823. if (hr == NETCFG_S_REBOOT)
  1824. {
  1825. netDbReload(hNetCompDatabase);
  1826. return hr;
  1827. }
  1828. // If the user didn't cancel, refresh the database.
  1829. if (S_FALSE != hr)
  1830. {
  1831. if (SUCCEEDED (hr))
  1832. {
  1833. netDbReload(hNetCompDatabase);
  1834. return NO_ERROR;
  1835. }
  1836. else
  1837. {
  1838. return hr;
  1839. }
  1840. }
  1841. }
  1842. return ERROR_CANCELLED;
  1843. }
  1844. //
  1845. // Uninstalls the given component
  1846. //
  1847. DWORD
  1848. netDbRaiseRemoveDialog (
  1849. IN HANDLE hNetCompDatabase,
  1850. IN DWORD dwIndex,
  1851. IN HWND hwndParent)
  1852. {
  1853. RASSRV_COMPONENT_DB * This = (RASSRV_COMPONENT_DB*)hNetCompDatabase;
  1854. HRESULT hr;
  1855. // Validate
  1856. if (!This)
  1857. {
  1858. return ERROR_INVALID_PARAMETER;
  1859. }
  1860. // Make sure that netshell library has been opened
  1861. if (!This->pNetConUtilities)
  1862. {
  1863. return ERROR_CAN_NOT_COMPLETE;
  1864. }
  1865. // If we have our pointer to the function used to bring up the add
  1866. // component dialog (obtained above only once), call it.
  1867. if (dwIndex < This->dwCompCount)
  1868. {
  1869. if (This->pComps[dwIndex]->pINetCfgComp)
  1870. {
  1871. hr = INetConnectionUiUtilities_QueryUserAndRemoveComponent(
  1872. This->pNetConUtilities,
  1873. hwndParent,
  1874. This->pINetCfg,
  1875. This->pComps[dwIndex]->pINetCfgComp);
  1876. // Ui will handle reboot
  1877. if (hr == NETCFG_S_REBOOT)
  1878. {
  1879. netDbReload(hNetCompDatabase);
  1880. return hr;
  1881. }
  1882. // If the user didn't cancel, refresh the database.
  1883. else if (S_FALSE != hr)
  1884. {
  1885. if (SUCCEEDED (hr))
  1886. {
  1887. netDbReload(hNetCompDatabase);
  1888. return NO_ERROR;
  1889. }
  1890. else
  1891. {
  1892. return hr;
  1893. }
  1894. }
  1895. }
  1896. }
  1897. return ERROR_CANCELLED;
  1898. }