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.

220 lines
4.8 KiB

  1. //
  2. // Author: DebiM
  3. // Date: September 1996
  4. //
  5. //
  6. // Class Store Schema creation and access using ADs
  7. //
  8. // This source file contains implementations for IClassAccess,
  9. // interface for CClassAccess object.
  10. //
  11. //
  12. //---------------------------------------------------------------------
  13. #include "dsbase.hxx"
  14. HRESULT CreateContainer (IADsContainer * pParent,
  15. LPOLESTR szParentName,
  16. LPOLESTR szName,
  17. LPOLESTR szDesc,
  18. IADsContainer ** ppChild)
  19. {
  20. HRESULT hr;
  21. IADs * pADs = NULL;
  22. IDispatch * pUnknown = NULL;
  23. int l;
  24. //
  25. // Use the Parent Container interface to Create the child.
  26. //
  27. hr = pParent->Create(
  28. CLASS_CS_CONTAINER,
  29. szName,
  30. &pUnknown
  31. );
  32. RETURN_ON_FAILURE(hr);
  33. //
  34. // Get IADs pointer on the new object
  35. //
  36. hr = pUnknown->QueryInterface(
  37. IID_IADs,
  38. (void **)&pADs
  39. );
  40. pUnknown->Release();
  41. RETURN_ON_FAILURE(hr);
  42. //
  43. // Set its description
  44. //
  45. hr = SetProperty (pADs, DESCRIPTION, szDesc);
  46. RETURN_ON_FAILURE(hr);
  47. //
  48. // Set its schema version
  49. //
  50. hr = SetPropertyDW (pADs, STOREVERSION, SCHEMA_VERSION_NUMBER);
  51. RETURN_ON_FAILURE(hr);
  52. //
  53. // persist the object
  54. //
  55. hr = StoreIt (pADs);
  56. RETURN_ON_FAILURE(hr);
  57. if (ppChild)
  58. {
  59. //
  60. // Get IADsContainer pointer on the child object to return
  61. //
  62. hr = pADs->QueryInterface(
  63. IID_IADsContainer,
  64. (void **)ppChild
  65. );
  66. }
  67. pADs->Release();
  68. return hr;
  69. }
  70. HRESULT CreateRepository(LPOLESTR szParentPath, LPOLESTR szStoreName)
  71. {
  72. HRESULT hr;
  73. IADsContainer * pADsParent = NULL;
  74. IADsContainer * pADsContainer = NULL;
  75. LPOLESTR szContainerName = NULL;
  76. int l;
  77. WCHAR szPath [_MAX_PATH+1];
  78. if (!szParentPath)
  79. {
  80. hr = GetRootPath(szPath);
  81. //
  82. // If failed go away
  83. //
  84. if (FAILED(hr))
  85. {
  86. return hr;
  87. }
  88. szParentPath = szPath;
  89. }
  90. hr = ADsGetObject(
  91. szParentPath,
  92. IID_IADsContainer,
  93. (void **)&pADsParent
  94. );
  95. RETURN_ON_FAILURE(hr);
  96. hr = CreateContainer (pADsParent,
  97. szParentPath,
  98. szStoreName,
  99. L"Application Store",
  100. &pADsContainer);
  101. pADsParent->Release();
  102. RETURN_ON_FAILURE(hr);
  103. //
  104. // Create the class container
  105. //
  106. hr = CreateContainer (pADsContainer,
  107. szContainerName,
  108. CLASSCONTAINERNAME,
  109. L"Application Object Classes",
  110. NULL);
  111. RETURN_ON_FAILURE(hr);
  112. //
  113. // Create the category container
  114. //
  115. hr = CreateContainer (pADsContainer,
  116. szContainerName,
  117. CATEGORYCONTAINERNAME,
  118. L"Component Categories",
  119. NULL);
  120. RETURN_ON_FAILURE(hr);
  121. //
  122. // Create the Packages container
  123. //
  124. hr = CreateContainer (pADsContainer,
  125. szContainerName,
  126. PACKAGECONTAINERNAME,
  127. L"Application Packages",
  128. NULL);
  129. //CoTaskMemFree (szContainerName);
  130. pADsContainer->Release();
  131. RETURN_ON_FAILURE(hr);
  132. return S_OK;
  133. }
  134. HRESULT GetRootPath(LPOLESTR szContainer)
  135. {
  136. HRESULT hr;
  137. IEnumVARIANT * pEnum;
  138. IADs *pADs;
  139. VARIANT VariantArray[2];
  140. IDispatch *pDispatch = NULL;
  141. ULONG cFetched;
  142. IADsContainer *pContainer = NULL;
  143. LPOLESTR pszContainer;
  144. //
  145. // Do a bind to the machine by a GetObject for the Path
  146. //
  147. hr = ADsGetObject(
  148. L"LDAP:",
  149. IID_IADsContainer,
  150. (void **)&pContainer
  151. );
  152. RETURN_ON_FAILURE(hr);
  153. hr = ADsBuildEnumerator(
  154. pContainer,
  155. &pEnum
  156. );
  157. hr = ADsEnumerateNext(
  158. pEnum,
  159. 1,
  160. VariantArray,
  161. &cFetched
  162. );
  163. pEnum->Release();
  164. if ((hr == S_FALSE) || (cFetched == 0))
  165. {
  166. return E_FAIL;
  167. }
  168. pDispatch = VariantArray[0].pdispVal;
  169. memset(VariantArray, 0, sizeof(VARIANT)*2);
  170. hr = pDispatch->QueryInterface(IID_IADs, (void **) &pADs) ;
  171. pDispatch->Release();
  172. pADs->get_ADsPath(&pszContainer);
  173. pADs->Release();
  174. pContainer->Release();
  175. wcscpy (szContainer, pszContainer);
  176. SysFreeString (pszContainer);
  177. return S_OK;
  178. }