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.

240 lines
4.5 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. adsiloc.cxx
  5. Abstract:
  6. Connects with servers.
  7. Enumerates servers
  8. Author:
  9. Sean Woodward (t-seanwo) 10/2/1997
  10. Revision History:
  11. --*/
  12. // defined functions
  13. // dump: dumps the Service Elements
  14. #include "svcloc.h"
  15. // TODO: Filter out the non-IIS services
  16. int
  17. ServiceDump(char *AnsiADsPath)
  18. {
  19. HRESULT hr = E_OUTOFMEMORY ;
  20. LPWSTR pszADsPath = NULL;
  21. IADs * pADs = NULL;
  22. //
  23. // Convert path to unicode and then bind to the object.
  24. //
  25. BAIL_ON_NULL(pszADsPath = AllocateUnicodeString(AnsiADsPath));
  26. hr = ADsGetObject(
  27. pszADsPath,
  28. IID_IADs,
  29. (void **)&pADs
  30. );
  31. if (FAILED(hr)) {
  32. printf("Failed to bind to object: %S\n", pszADsPath) ;
  33. }
  34. else {
  35. //
  36. // Dump the object
  37. //
  38. hr = DumpObject(pADs);
  39. if (FAILED(hr)) {
  40. printf("Unable to read properties of: %S\n", pszADsPath) ;
  41. }
  42. pADs->Release();
  43. }
  44. error:
  45. FreeUnicodeString(pszADsPath);
  46. return (FAILED(hr) ? 1 : 0) ;
  47. }
  48. //
  49. // Given an ADs pointer, dump the contents of the object
  50. //
  51. HRESULT
  52. DumpObject(
  53. IADs * pADs
  54. )
  55. {
  56. HRESULT hr;
  57. IADs * pADsProp = NULL;
  58. VARIANT * pVariantArray = NULL;
  59. VARIANT varProperty;
  60. DWORD dwNumProperties = 0;
  61. BSTR bstrPropName = NULL;
  62. DWORD i = 0;
  63. IDispatch * pDispatch = NULL;
  64. //
  65. // Access the schema for the object
  66. //
  67. hr = GetPropertyList(
  68. pADs,
  69. &pVariantArray,
  70. &dwNumProperties
  71. );
  72. BAIL_ON_FAILURE(hr);
  73. //
  74. // Get the information on the object
  75. //
  76. hr = pADs->GetInfo();
  77. BAIL_ON_FAILURE(hr);
  78. //
  79. // Loop and retrieve all properties
  80. //
  81. for (i = 0; i < dwNumProperties; i++ ) {
  82. pDispatch = (pVariantArray + i)->pdispVal;
  83. hr = pDispatch->QueryInterface(
  84. IID_IADs,
  85. (void **)&pADsProp
  86. );
  87. BAIL_ON_FAILURE(hr);
  88. pDispatch->Release();
  89. hr = pADsProp->get_Name(&bstrPropName);
  90. pADsProp->Release();
  91. BAIL_ON_FAILURE(hr);
  92. //
  93. // Get a property and print it out. The HRESULT is passed to
  94. // PrintProperty.
  95. //
  96. hr = pADs->Get(
  97. bstrPropName,
  98. &varProperty
  99. );
  100. PrintProperty(
  101. bstrPropName,
  102. hr,
  103. varProperty
  104. );
  105. if (bstrPropName) {
  106. SysFreeString(bstrPropName);
  107. }
  108. }
  109. error:
  110. free(pVariantArray);
  111. return(hr);
  112. }
  113. HRESULT
  114. GetPropertyList(
  115. IADs * pADs,
  116. VARIANT ** ppVariant,
  117. PDWORD pcElementFetched
  118. )
  119. {
  120. HRESULT hr= S_OK;
  121. BSTR bstrSchemaPath = NULL;
  122. IADsContainer * pADsContainer = NULL;
  123. IEnumVARIANT * pEnumVariant = NULL;
  124. BOOL fContinue = TRUE;
  125. ULONG cthisElement = 0L;
  126. ULONG cElementFetched = 0L;
  127. LPBYTE pVariantArray = NULL;
  128. VARIANT varProperty;
  129. DWORD cb = 0;
  130. hr = pADs->get_Schema(&bstrSchemaPath);
  131. BAIL_ON_FAILURE(hr);
  132. hr = ADsGetObject(
  133. bstrSchemaPath,
  134. IID_IADsContainer,
  135. (void **)&pADsContainer
  136. );
  137. BAIL_ON_FAILURE(hr);
  138. hr = ADsBuildEnumerator(
  139. pADsContainer,
  140. &pEnumVariant
  141. );
  142. BAIL_ON_FAILURE(hr);
  143. while (fContinue) {
  144. VariantInit(&varProperty);
  145. hr = ADsEnumerateNext(
  146. pEnumVariant,
  147. 1,
  148. &varProperty,
  149. &cthisElement
  150. );
  151. if (hr == S_FALSE) {
  152. fContinue = FALSE;
  153. break;
  154. }
  155. pVariantArray = (LPBYTE)realloc(
  156. (void *)pVariantArray,
  157. cb + sizeof(VARIANT)
  158. );
  159. if (!pVariantArray) {
  160. hr = E_OUTOFMEMORY;
  161. BAIL_ON_FAILURE(hr);
  162. }
  163. memcpy(pVariantArray + cb, (LPBYTE)&varProperty, sizeof(VARIANT));
  164. cb += sizeof(VARIANT);
  165. cElementFetched += cthisElement;
  166. }
  167. *ppVariant = (LPVARIANT)pVariantArray;
  168. *pcElementFetched = cElementFetched;
  169. error:
  170. if (bstrSchemaPath) {
  171. SysFreeString(bstrSchemaPath);
  172. }
  173. if (pADsContainer) {
  174. pADsContainer->Release();
  175. }
  176. return(hr);
  177. }