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.

374 lines
14 KiB

  1. //++
  2. //
  3. // Copyright (C) Microsoft Corporation, 1987 - 1999
  4. //
  5. // Module Name:
  6. //
  7. // bindings.c
  8. //
  9. // Abstract:
  10. //
  11. // Queries into network drivers
  12. //
  13. // Author:
  14. //
  15. // Anilth - 4-20-1998
  16. //
  17. // Environment:
  18. //
  19. // User mode only.
  20. // Contains NT-specific code.
  21. //
  22. // Revision History:
  23. //
  24. //--
  25. #include "precomp.h"
  26. #undef IsEqualGUID
  27. #include "bindings.h"
  28. HRESULT
  29. BindingsTest(NETDIAG_PARAMS* pParams, NETDIAG_RESULT* pResults)
  30. //++
  31. // Description:
  32. // This Test uses the INetCfg COM interface to get the bingings.
  33. // COM Interface is accessed using C, not C++.
  34. //
  35. // Arguments:
  36. // None.
  37. //
  38. // Author:
  39. // Rajkumar .P ( 07/17/98 )
  40. //
  41. //--
  42. {
  43. INetCfg* pINetCfg = NULL;
  44. INetCfgClass *pINetCfgClass = NULL;
  45. IEnumNetCfgComponent *pIEnumNetCfgComponent = NULL;
  46. INetCfgComponent *pINetCfgComponent = NULL;
  47. INetCfgComponentBindings *pINetCfgComponentBindings = NULL;
  48. IEnumNetCfgBindingPath *pEnumNetCfgBindingPath = NULL;
  49. INetCfgBindingPath *pINetCfgBindingPath = NULL;
  50. IEnumNetCfgBindingInterface *pIEnumNetCfgBindingInterface = NULL;
  51. INetCfgBindingInterface *pINetBindingInterface = NULL;
  52. INetCfgComponent *pUpperComponent = NULL;
  53. INetCfgComponent *pLowerComponent = NULL;
  54. INetCfgComponent *pOwner = NULL;
  55. HRESULT hr;
  56. wchar_t *pszwDisplayName;
  57. wchar_t *pszwBindName;
  58. wchar_t *pszwDescription;
  59. wchar_t *pszwInterfaceName;
  60. wchar_t *pszwUpperComponent;
  61. wchar_t *pszwLowerComponent;
  62. wchar_t *pszwOwner;
  63. TCHAR szBuffer[512];
  64. DWORD dwPathId;
  65. int i;
  66. PrintStatusMessage( pParams, 4, IDS_BINDINGS_STATUS_MSG );
  67. InitializeListHead( &pResults->Bindings.lmsgOutput );
  68. // Only do this test if in really verbose mode
  69. if (!pParams->fReallyVerbose)
  70. return S_OK;
  71. // Initialize the COM library
  72. CoInitialize(NULL);
  73. hr = CoCreateInstance(&CLSID_NetCfg,
  74. NULL,
  75. CLSCTX_INPROC_SERVER,
  76. &IID_INetCfg,
  77. (void**)&pINetCfg) ;
  78. if(FAILED(hr))
  79. {
  80. DebugMessage("CreateInstance for IID_INetCfg failed\n");
  81. goto end_BindingsTest;
  82. }
  83. hr = pINetCfg->lpVtbl->Initialize(pINetCfg, NULL);
  84. if(FAILED(hr))
  85. {
  86. DebugMessage("pINetCfg->Initialize failed.\n");
  87. goto end_BindingsTest;
  88. }
  89. for ( i = 0; i < MAX_CLASS_GUID ; i++ )
  90. {
  91. hr = pINetCfg->lpVtbl->QueryNetCfgClass(pINetCfg,
  92. c_pNetClassGuid[i].pGuid,
  93. &IID_INetCfgClass, // This arg is undocumented
  94. &pINetCfgClass
  95. );
  96. if(FAILED(hr))
  97. {
  98. DebugMessage("QueryNetCfgClass failed\n");
  99. goto end_BindingsTest;
  100. }
  101. hr = pINetCfgClass->lpVtbl->EnumComponents(pINetCfgClass,
  102. &pIEnumNetCfgComponent);
  103. pINetCfgClass->lpVtbl->Release(pINetCfgClass);
  104. pINetCfgClass = NULL;
  105. if(FAILED(hr))
  106. {
  107. DebugMessage("EnumComponents failed\n");
  108. goto end_BindingsTest;
  109. }
  110. // pIEnumNetCfgComponent is a standard COM enumerator
  111. while (S_OK == pIEnumNetCfgComponent->lpVtbl->Next(pIEnumNetCfgComponent,1,&pINetCfgComponent,NULL))
  112. {
  113. HRESULT hrTmp;
  114. hrTmp = pINetCfgComponent->lpVtbl->GetDisplayName(pINetCfgComponent,
  115. (LPWSTR *)&pszwDisplayName
  116. );
  117. if (hrTmp == S_OK)
  118. {
  119. WideCharToMultiByte(CP_ACP, 0, pszwDisplayName, -1, szBuffer, sizeof(szBuffer), NULL, NULL);
  120. //IDS_BINDINGS_14801 "Component Name : %s\n"
  121. AddMessageToList(&pResults->Bindings.lmsgOutput, Nd_ReallyVerbose, IDS_BINDINGS_14801, szBuffer);
  122. CoTaskMemFree(pszwDisplayName);
  123. }
  124. hrTmp = pINetCfgComponent->lpVtbl->GetBindName(pINetCfgComponent,
  125. (LPWSTR *)&pszwBindName);
  126. if ( SUCCEEDED(hrTmp) )
  127. {
  128. WideCharToMultiByte(CP_ACP, 0, pszwBindName, -1, szBuffer, sizeof(szBuffer), NULL, NULL);
  129. //IDS_BINDINGS_14802 "Bind Name: %s\n"
  130. AddMessageToList(&pResults->Bindings.lmsgOutput, Nd_ReallyVerbose, IDS_BINDINGS_14802, szBuffer);
  131. //$REVIEW nsun: maybe we should use SysFreeString to free the buffer
  132. CoTaskMemFree(pszwBindName);
  133. }
  134. //
  135. // This function though found in doc , is not yet available
  136. //
  137. /*
  138. hrTmp = pINetCfgComponent->lpVtbl->GetDescriptionText(pINetCfgComponent,
  139. (LPWSTR *)&pszwDescription);
  140. if (hrTmp == S_OK) {
  141. WideCharToMultiByte(CP_ACP, 0, pszwBindName, -1, szBuffer, sizeof(szBuffer), NULL, NULL);
  142. //IDS_BINDINGS_14804 "Description: %s\n"
  143. wsPrintMessage(&pResults->Bindings.lmsgOutput, IDS_BINDINGS_14804,pszwDescription);
  144. CoTaskMemFree(pszwDescription);
  145. }
  146. */
  147. AddMessageToListSz(&pResults->Bindings.lmsgOutput, Nd_ReallyVerbose, _T(" Binding Paths:\n"));
  148. hrTmp = pINetCfgComponent->lpVtbl->QueryInterface(pINetCfgComponent,
  149. &IID_INetCfgComponentBindings,
  150. &pINetCfgComponentBindings);
  151. pINetCfgComponent->lpVtbl->Release(pINetCfgComponent);
  152. pINetCfgComponent = NULL;
  153. if (FAILED(hrTmp))
  154. continue;
  155. hrTmp = pINetCfgComponentBindings->lpVtbl->EnumBindingPaths(pINetCfgComponentBindings,EBP_BELOW,&pEnumNetCfgBindingPath);
  156. pINetCfgComponentBindings->lpVtbl->Release(pINetCfgComponentBindings);
  157. pINetCfgComponentBindings = NULL;
  158. if (FAILED(hrTmp))
  159. continue;
  160. while ( S_OK == pEnumNetCfgBindingPath->lpVtbl->Next(pEnumNetCfgBindingPath, 1,&pINetCfgBindingPath,NULL))
  161. {
  162. //
  163. // Got some problems using these two calls - need to take this up with sumitc
  164. //
  165. hrTmp = pINetCfgBindingPath->lpVtbl->GetOwner(pINetCfgBindingPath,
  166. &pOwner);
  167. if ( SUCCEEDED(hrTmp) )
  168. {
  169. hrTmp = pOwner->lpVtbl->GetDisplayName(pOwner,
  170. &pszwOwner);
  171. if (hrTmp == S_OK) {
  172. WideCharToMultiByte(CP_ACP, 0, pszwOwner, -1, szBuffer, sizeof(szBuffer), NULL, NULL);
  173. //IDS_BINDINGS_14805 "Owner of the binding path : %s\n"
  174. AddMessageToList(&pResults->Bindings.lmsgOutput, Nd_ReallyVerbose, IDS_BINDINGS_14805, szBuffer);
  175. CoTaskMemFree(pszwOwner);
  176. }
  177. }
  178. pOwner->lpVtbl->Release(pOwner);
  179. pOwner = NULL;
  180. hrTmp = pINetCfgBindingPath->lpVtbl->IsEnabled(pINetCfgBindingPath);
  181. if (hrTmp == S_OK)
  182. //IDS_BINDINGS_14806 "Binding Enabled: Yes\n"
  183. AddMessageToListId(&pResults->Bindings.lmsgOutput, Nd_ReallyVerbose, IDS_BINDINGS_14806);
  184. else
  185. if (hrTmp == S_FALSE)
  186. //IDS_BINDINGS_14807 "Binding Enabled: No\n"
  187. AddMessageToListId(&pResults->Bindings.lmsgOutput, Nd_ReallyVerbose, IDS_BINDINGS_14807);
  188. else
  189. if (hrTmp == NETCFG_E_NOT_INITIALIZED)
  190. //IDS_BINDINGS_14808 "Binding Enabled: Binding has not yet been intialized\n"
  191. AddMessageToListId(&pResults->Bindings.lmsgOutput, Nd_ReallyVerbose, IDS_BINDINGS_14808);
  192. AddMessageToListSz(&pResults->Bindings.lmsgOutput, Nd_ReallyVerbose, _T(" Interfaces of the binding path: \n"));
  193. hrTmp = pINetCfgBindingPath->lpVtbl->EnumBindingInterfaces(
  194. pINetCfgBindingPath,
  195. &pIEnumNetCfgBindingInterface);
  196. pINetCfgBindingPath->lpVtbl->Release(pINetCfgBindingPath);
  197. pINetCfgBindingPath = NULL;
  198. if( FAILED(hrTmp) )
  199. {
  200. DebugMessage("EnumBindingInterfaces failed\n" );
  201. continue;
  202. }
  203. while ( S_OK == pIEnumNetCfgBindingInterface->lpVtbl->Next(pIEnumNetCfgBindingInterface,1,&pINetBindingInterface,NULL))
  204. {
  205. hrTmp = pINetBindingInterface->lpVtbl->GetName(pINetBindingInterface,
  206. &pszwInterfaceName);
  207. if (hrTmp == S_OK)
  208. {
  209. WideCharToMultiByte(CP_ACP, 0, pszwInterfaceName, -1, szBuffer, sizeof(szBuffer), NULL, NULL);
  210. //IDS_BINDINGS_14810 "Interface Name: %s\n"
  211. AddMessageToList(&pResults->Bindings.lmsgOutput, Nd_ReallyVerbose, IDS_BINDINGS_14810, szBuffer);
  212. CoTaskMemFree(pszwInterfaceName);
  213. }
  214. hrTmp = pINetBindingInterface->lpVtbl->GetUpperComponent(
  215. pINetBindingInterface,
  216. &pUpperComponent);
  217. if (hrTmp == S_OK)
  218. {
  219. pszwUpperComponent = NULL;
  220. hrTmp = pUpperComponent->lpVtbl->GetDisplayName(
  221. pUpperComponent,
  222. &pszwUpperComponent);
  223. pUpperComponent->lpVtbl->Release(pUpperComponent);
  224. pUpperComponent = NULL;
  225. if (hrTmp == S_OK)
  226. {
  227. assert(pszwUpperComponent);
  228. WideCharToMultiByte(CP_ACP, 0, pszwUpperComponent, -1, szBuffer, sizeof(szBuffer), NULL, NULL);
  229. //IDS_BINDINGS_14811 "Upper Component: %s\n"
  230. AddMessageToList(&pResults->Bindings.lmsgOutput, Nd_ReallyVerbose, IDS_BINDINGS_14811, szBuffer);
  231. CoTaskMemFree(pszwUpperComponent);
  232. }
  233. }
  234. hrTmp = pINetBindingInterface->lpVtbl->GetLowerComponent(
  235. pINetBindingInterface,
  236. &pLowerComponent);
  237. pINetBindingInterface->lpVtbl->Release(pINetBindingInterface);
  238. pINetBindingInterface = NULL;
  239. if (hrTmp == S_OK )
  240. {
  241. pszwLowerComponent = NULL;
  242. hrTmp = pLowerComponent->lpVtbl->GetDisplayName(
  243. pLowerComponent,
  244. &pszwLowerComponent);
  245. pLowerComponent->lpVtbl->Release(pLowerComponent);
  246. pLowerComponent = NULL;
  247. if (hrTmp == S_OK )
  248. {
  249. assert(pszwLowerComponent);
  250. WideCharToMultiByte(CP_ACP, 0, pszwLowerComponent, -1, szBuffer, sizeof(szBuffer), NULL, NULL);
  251. //IDS_BINDINGS_14812 "Lower Component: %s\n"
  252. AddMessageToList(&pResults->Bindings.lmsgOutput, Nd_ReallyVerbose, IDS_BINDINGS_14812, szBuffer);
  253. CoTaskMemFree(pszwLowerComponent);
  254. }
  255. }
  256. }
  257. pIEnumNetCfgBindingInterface->lpVtbl->Release(pIEnumNetCfgBindingInterface);
  258. pIEnumNetCfgBindingInterface = NULL;
  259. AddMessageToList(&pResults->Bindings.lmsgOutput, Nd_ReallyVerbose, IDS_GLOBAL_EmptyLine);
  260. }
  261. AddMessageToList(&pResults->Bindings.lmsgOutput, Nd_ReallyVerbose, IDS_GLOBAL_EmptyLine);
  262. pEnumNetCfgBindingPath->lpVtbl->Release(pEnumNetCfgBindingPath);
  263. pEnumNetCfgBindingPath = NULL;
  264. }
  265. pIEnumNetCfgComponent->lpVtbl->Release(pIEnumNetCfgComponent);
  266. pIEnumNetCfgComponent = NULL;
  267. }
  268. pINetCfg->lpVtbl->Uninitialize(pINetCfg);
  269. pINetCfg->lpVtbl->Release(pINetCfg);
  270. end_BindingsTest:
  271. // Unitialize COM Library
  272. CoUninitialize();
  273. pResults->Bindings.hrTestResult = hr;
  274. return hr;
  275. }
  276. void BindingsGlobalPrint(NETDIAG_PARAMS *pParams, NETDIAG_RESULT *pResults)
  277. {
  278. if (pParams->fVerbose || !FHrOK(pResults->Bindings.hrTestResult))
  279. {
  280. PrintNewLine(pParams, 2);
  281. PrintTestTitleResult(pParams,
  282. IDS_BINDINGS_LONG,
  283. IDS_BINDINGS_SHORT,
  284. TRUE,
  285. pResults->Bindings.hrTestResult,
  286. 0);
  287. }
  288. PrintMessageList(pParams, &pResults->Bindings.lmsgOutput);
  289. }
  290. void BindingsPerInterfacePrint(NETDIAG_PARAMS *pParams, NETDIAG_RESULT *pResults, INTERFACE_RESULT *pInterfaceResults)
  291. {
  292. //no pre interface print
  293. }
  294. void BindingsCleanup(IN NETDIAG_PARAMS *pParams,
  295. IN OUT NETDIAG_RESULT *pResults)
  296. {
  297. MessageListCleanUp(&pResults->Bindings.lmsgOutput);
  298. }