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.

234 lines
7.0 KiB

  1. /*---------------------------------------------------------------------------
  2. File: PlugInInfo.cpp
  3. Comments: COM Object to enumerate information about available plug-ins
  4. and extensions. These plug-ins are distributed with the agent to the remote
  5. machines to perform custom migration tasks.
  6. This interface would be used by the dispatcher, and possibly by the GUI, to
  7. enumerate the list of available plug-ins.
  8. (c) Copyright 1999, Mission Critical Software, Inc., All Rights Reserved
  9. Proprietary and confidential to Mission Critical Software, Inc.
  10. REVISION LOG ENTRY
  11. Revision By: Christy Boles
  12. Revised on 02/18/99 11:34:16
  13. ---------------------------------------------------------------------------
  14. */
  15. // PlugInInfo.cpp : Implementation of CPlugInInfo
  16. #include "stdafx.h"
  17. #include "WorkObj.h"
  18. #include "PlugInfo.h"
  19. #include "Common.hpp"
  20. #include "UString.hpp"
  21. #include "ErrDct.hpp"
  22. #include "TReg.hpp"
  23. #include "TNode.hpp"
  24. #include "EaLen.hpp"
  25. #include "McsPI.h"
  26. #include "McsPI_i.c"
  27. #include "ARExt_i.c"
  28. #ifdef _DEBUG
  29. #define new DEBUG_NEW
  30. #undef THIS_FILE
  31. static char THIS_FILE[] = __FILE__;
  32. #endif
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CPlugInInfo
  35. // the PlugInNode is used to build a list of available plug-ins
  36. class PlugInNode : public TNode
  37. {
  38. WCHAR name[LEN_Guid]; // CLSID of the plug-in
  39. public:
  40. PlugInNode(WCHAR const * n) { safecopy(name,n); }
  41. WCHAR const * GetName() { return name; }
  42. };
  43. // Checks the specified file to see if it implements any COM objects that implement the
  44. // McsDomPlugIn interface -- if so, it appends them to the list of available plug-ins
  45. void
  46. AppendPlugInsToList(
  47. TNodeList * pList, // in - list of plug-ins
  48. WCHAR const * path // in - file to examine for Plug-In COM objects
  49. )
  50. {
  51. HRESULT hr = S_OK;
  52. ITypeLib * pTlib = NULL;
  53. hr = LoadTypeLib(path,&pTlib);
  54. if ( SUCCEEDED(hr) )
  55. {
  56. UINT count = pTlib->GetTypeInfoCount();
  57. for ( UINT i = 0 ; i < count ; i++ )
  58. {
  59. ITypeInfo * pInfo = NULL;
  60. hr = pTlib->GetTypeInfo(i,&pInfo);
  61. if ( SUCCEEDED(hr) )
  62. {
  63. TYPEATTR * attr = NULL;
  64. hr = pInfo->GetTypeAttr(&attr);
  65. if ( SUCCEEDED(hr) )
  66. {
  67. if ( attr->typekind == TKIND_COCLASS )
  68. {
  69. IMcsDomPlugIn * pPlugIn = NULL;
  70. // see if it supports IMcsDomPlugIn
  71. hr = CoCreateInstance(attr->guid,NULL,CLSCTX_ALL,IID_IMcsDomPlugIn,(void**)&pPlugIn);
  72. if ( SUCCEEDED(hr) )
  73. {
  74. pPlugIn->Release();
  75. // add the coclass to the list
  76. LPOLESTR strClsid = NULL;
  77. hr = StringFromCLSID(attr->guid,&strClsid);
  78. if ( SUCCEEDED(hr) )
  79. {
  80. PlugInNode * pNode = new PlugInNode(strClsid);
  81. CoTaskMemFree(strClsid);
  82. pList->InsertBottom(pNode);
  83. }
  84. }
  85. }
  86. pInfo->ReleaseTypeAttr(attr);
  87. }
  88. pInfo->Release();
  89. }
  90. }
  91. pTlib->Release();
  92. }
  93. }
  94. SAFEARRAY * // ret- SAFEARRAY(BSTR) of filenames
  95. SafeArrayFromList(
  96. TNodeList * pList // in - list of filenames
  97. )
  98. {
  99. SAFEARRAYBOUND bound[1] = { pList->Count(),0 };
  100. SAFEARRAY * pArray = SafeArrayCreate(VT_BSTR,1,bound);
  101. TNodeListEnum tEnum;
  102. PlugInNode * pNode;
  103. PlugInNode * pNext;
  104. long ndx[1] = {0};
  105. for ( pNode = (PlugInNode *)tEnum.OpenFirst(pList) ; pNode ; pNode = pNext )
  106. {
  107. pNext = (PlugInNode *)tEnum.Next();
  108. SafeArrayPutElement(pArray,ndx,SysAllocString(pNode->GetName()));
  109. ndx[0]++;
  110. pList->Remove(pNode);
  111. delete pNode;
  112. }
  113. tEnum.Close();
  114. return pArray;
  115. }
  116. STDMETHODIMP
  117. CPlugInInfo::EnumerateExtensions(
  118. /*[out]*/ SAFEARRAY ** pExtensions // out- safearray of available account replication extensions
  119. )
  120. {
  121. HRESULT hr = S_OK;
  122. DWORD rc = 0;
  123. TRegKey key;
  124. WCHAR classid[MAX_PATH];
  125. TNodeList list;
  126. PlugInNode * node = NULL;
  127. long ndx = 0;
  128. // get the extensions registry key
  129. rc = key.Open(L"Software\\Mission Critical Software\\DomainAdmin\\Extensions",HKEY_LOCAL_MACHINE);
  130. if (! rc )
  131. {
  132. for ( ndx=0, rc = key.SubKeyEnum(ndx,classid,DIM(classid))
  133. ; rc == 0
  134. ; ndx++, rc = key.SubKeyEnum(ndx,classid,DIM(classid)) )
  135. {
  136. node = new PlugInNode(classid);
  137. list.InsertBottom(node);
  138. }
  139. if ( rc == ERROR_NO_MORE_ITEMS )
  140. rc = 0;
  141. }
  142. hr = HRESULT_FROM_WIN32(rc);
  143. return hr;
  144. }
  145. STDMETHODIMP
  146. CPlugInInfo::EnumeratePlugIns(
  147. SAFEARRAY ** pPlugIns // out- safearray containing clsids of available migration plug-ins
  148. )
  149. {
  150. HRESULT hr = S_OK;
  151. DWORD rc;
  152. TRegKey key;
  153. WCHAR directory[MAX_PATH];
  154. WCHAR path[MAX_PATH];
  155. WCHAR dllPath[MAX_PATH];
  156. TNodeList list;
  157. // Get the plug-ins directory from the registry
  158. #ifdef OFA
  159. rc = key.Open(L"Software\\Mission Critical Software\\OnePointFileAdmin",HKEY_LOCAL_MACHINE);
  160. #else
  161. rc = key.Open(L"Software\\Mission Critical Software\\DomainAdmin",HKEY_LOCAL_MACHINE);
  162. #endif
  163. if ( ! rc )
  164. {
  165. rc = key.ValueGetStr(L"PlugInDirectory",directory,(sizeof directory));
  166. if ( ! rc )
  167. {
  168. // Enumerate the files there that match the naming convention:
  169. WIN32_FIND_DATA fDat;
  170. HANDLE hFind;
  171. UStrCpy(path,directory);
  172. UStrCpy(path + UStrLen(path),L"\\McsPi*.Dll");
  173. hFind = FindFirstFile(path,&fDat);
  174. if ( hFind && hFind != INVALID_HANDLE_VALUE )
  175. {
  176. BOOL bRc = TRUE;
  177. for ( ; rc == 0 ; bRc = FindNextFile(hFind,&fDat) )
  178. {
  179. if ( bRc )
  180. {
  181. UStrCpy(dllPath,directory);
  182. UStrCpy(dllPath + UStrLen(dllPath),L"\\");
  183. UStrCpy(dllPath + UStrLen(dllPath),fDat.cFileName);
  184. // check each one to see if it is a plug-in
  185. AppendPlugInsToList(&list,dllPath);
  186. }
  187. else
  188. {
  189. rc = GetLastError();
  190. }
  191. }
  192. // create a safearray from the contents of the list
  193. (*pPlugIns) = SafeArrayFromList(&list);
  194. }
  195. }
  196. else
  197. {
  198. hr = HRESULT_FROM_WIN32(rc);
  199. }
  200. }
  201. else
  202. {
  203. hr = HRESULT_FROM_WIN32(rc);
  204. }
  205. return hr;
  206. }