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.

115 lines
2.4 KiB

  1. #pragma warning(disable:4201) // nameless struct/union
  2. #define COBJMACROS
  3. #include <windows.h>
  4. #include <objbase.h>
  5. #include <hnetcfg.h>
  6. DWORD
  7. APIENTRY
  8. RasQuerySharedPrivateLan(
  9. OUT GUID* LanGuid )
  10. /*++
  11. Routine Description:
  12. This routine is invoked to determine the private-lan which
  13. is allowed access to the shared-network, if any.
  14. Arguments:
  15. LanGuid - receives the GUID for the private lan
  16. Return Value:
  17. DWORD - Win32 status code.
  18. --*/
  19. {
  20. HRESULT hr;
  21. BOOLEAN fComInitialized = TRUE;
  22. IHNetIcsSettings *pIcsSettings;
  23. IEnumHNetIcsPrivateConnections *pEnum;
  24. IHNetIcsPrivateConnection *pPrivateConn;
  25. IHNetConnection *pConn;
  26. ULONG ulCount;
  27. GUID *pGuid;
  28. if (NULL == LanGuid) {
  29. return ERROR_BAD_ARGUMENTS;
  30. }
  31. hr = CoInitializeEx(0, COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE);
  32. if (FAILED(hr)) {
  33. fComInitialized = FALSE;
  34. if (RPC_E_CHANGED_MODE == hr) {
  35. hr = S_OK;
  36. }
  37. }
  38. if (FAILED(hr)) {
  39. goto Done;
  40. }
  41. hr = CoCreateInstance(
  42. &CLSID_HNetCfgMgr,
  43. NULL,
  44. CLSCTX_ALL,
  45. &IID_IHNetIcsSettings,
  46. (void**)&pIcsSettings
  47. );
  48. if (FAILED(hr)) {
  49. goto Done;
  50. }
  51. hr = IHNetIcsSettings_EnumIcsPrivateConnections(pIcsSettings, &pEnum);
  52. IHNetIcsSettings_Release(pIcsSettings);
  53. if (FAILED(hr)) {
  54. goto Done;
  55. }
  56. hr = IEnumHNetIcsPrivateConnections_Next(pEnum, 1, &pPrivateConn, &ulCount);
  57. IEnumHNetIcsPrivateConnections_Release(pEnum);
  58. if (FAILED(hr)) {
  59. goto Done;
  60. }
  61. if (1 == ulCount) {
  62. hr = IHNetIcsPrivateConnection_QueryInterface(
  63. pPrivateConn,
  64. &IID_IHNetConnection,
  65. (void**)&pConn
  66. );
  67. IHNetIcsPrivateConnection_Release(pPrivateConn);
  68. if (FAILED(hr)) {
  69. goto Done;
  70. }
  71. } else {
  72. hr = E_FAIL;
  73. goto Done;
  74. }
  75. hr = IHNetConnection_GetGuid(pConn, &pGuid);
  76. IHNetConnection_Release(pConn);
  77. if (SUCCEEDED(hr)) {
  78. CopyMemory(LanGuid, pGuid, sizeof(*pGuid));
  79. CoTaskMemFree(pGuid);
  80. }
  81. Done:
  82. if (TRUE == fComInitialized) {
  83. CoUninitialize();
  84. }
  85. return SUCCEEDED(hr) ? ERROR_SUCCESS : HRESULT_CODE(hr);
  86. }