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.

218 lines
5.6 KiB

  1. // ProfMMgr.cpp : Implementation of CMcsPiPflApp and DLL registration.
  2. #include "stdafx.h"
  3. #include "McsPiPfl.h"
  4. #include "ProfMMgr.h"
  5. #include "ErrDct.hpp"
  6. #include "TReg.hpp"
  7. #include "ResStr.h"
  8. #include "EaLen.hpp"
  9. #include "cipher.hpp"
  10. #include "SecPI.h"
  11. TErrorDct err;
  12. TError & errCommon = err;
  13. StringLoader gString;
  14. // This method is called by the dispatcher to verify that this is a valid plug-in
  15. // Only valid plug-ins will be sent out with the agents
  16. // The purpose of this check is to make it more difficult for unauthorized parties
  17. // to use our plug-in interface, since it is currently undocumented.
  18. STDMETHODIMP CProfMMgr::Verify(/*[in,out]*/ULONG * pData,/*[in]*/ULONG size)
  19. {
  20. McsChallenge * pMcsChallenge;
  21. long lTemp1;
  22. long lTemp2;
  23. if( size == sizeof(McsChallenge) )
  24. {
  25. pMcsChallenge = (McsChallenge*)(pData);
  26. SimpleCipher((LPBYTE)pMcsChallenge,size);
  27. pMcsChallenge->MCS[0] = 'M';
  28. pMcsChallenge->MCS[1] = 'C';
  29. pMcsChallenge->MCS[2] = 'S';
  30. pMcsChallenge->MCS[3] = 0;
  31. lTemp1 = pMcsChallenge->lRand1 + pMcsChallenge->lRand2;
  32. lTemp2 = pMcsChallenge->lRand2 - pMcsChallenge->lRand1;
  33. pMcsChallenge->lRand1 = lTemp1;
  34. pMcsChallenge->lRand2 = lTemp2;
  35. pMcsChallenge->lTime += 100;
  36. SimpleCipher((LPBYTE)pMcsChallenge,size);
  37. }
  38. else
  39. return E_FAIL;
  40. return S_OK;
  41. }
  42. STDMETHODIMP CProfMMgr::GetRegisterableFiles(/* [out] */SAFEARRAY ** pArray)
  43. {
  44. SAFEARRAYBOUND bound[1] = { 1, 0 };
  45. LONG ndx[1] = { 0 };
  46. TNodeListEnum e;
  47. TFileList list;
  48. TFileNode * pNode;
  49. LONG i;
  50. BuildFileLists(NULL,&list);
  51. bound[0].cElements = list.Count();
  52. (*pArray) = SafeArrayCreate(VT_BSTR,1,bound);
  53. for (i = 0, pNode=(TFileNode*)e.OpenFirst(&list) ; pNode ; i++, pNode=(TFileNode*)e.Next() )
  54. {
  55. ndx[0] = i;
  56. SafeArrayPutElement(*pArray,ndx,SysAllocString(pNode->GetName()));
  57. }
  58. e.Close();
  59. return S_OK;
  60. }
  61. STDMETHODIMP CProfMMgr::GetRequiredFiles(/* [out] */SAFEARRAY ** pArray)
  62. {
  63. SAFEARRAYBOUND bound[1] = { 1, 0 };
  64. LONG ndx[1] = { 0 };
  65. TNodeListEnum e;
  66. TFileList list;
  67. TFileNode * pNode;
  68. LONG i;
  69. BuildFileLists(&list,NULL);
  70. bound[0].cElements = list.Count();
  71. (*pArray) = SafeArrayCreate(VT_BSTR,1,bound);
  72. for (i = 0, pNode=(TFileNode*)e.OpenFirst(&list) ; pNode ; i++, pNode=(TFileNode*)e.Next() )
  73. {
  74. ndx[0] = i;
  75. SafeArrayPutElement(*pArray,ndx,SysAllocString(pNode->GetName()));
  76. }
  77. e.Close();
  78. return S_OK;
  79. }
  80. STDMETHODIMP CProfMMgr::GetDescription(/* [out] */ BSTR * description)
  81. {
  82. (*description) = SysAllocString(L"");
  83. return S_OK;
  84. }
  85. STDMETHODIMP CProfMMgr::PreMigrationTask(/* [in] */IUnknown * pVarSet)
  86. {
  87. return S_OK;
  88. }
  89. STDMETHODIMP CProfMMgr::PostMigrationTask(/* [in] */IUnknown * pVarSet)
  90. {
  91. return S_OK;
  92. }
  93. STDMETHODIMP CProfMMgr::GetName(/* [out] */BSTR * name)
  94. {
  95. (*name) = SysAllocString(L"");
  96. return S_OK;
  97. }
  98. STDMETHODIMP CProfMMgr::GetResultString(/* [in] */IUnknown * pVarSet,/* [out] */ BSTR * text)
  99. {
  100. (*text) = SysAllocString(L"");
  101. return S_OK;
  102. }
  103. STDMETHODIMP CProfMMgr::StoreResults(/* [in] */IUnknown * pVarSet)
  104. {
  105. return S_OK;
  106. }
  107. STDMETHODIMP CProfMMgr::ConfigureSettings(/*[in]*/IUnknown * pVarSet)
  108. {
  109. return S_OK;
  110. }
  111. void CProfMMgr::BuildFileLists(TFileList * pRequired,TFileList * pRegisterable)
  112. {
  113. // Enumerate the profile extensions defined in the registry
  114. TRegKey profExt;
  115. DWORD rc;
  116. WCHAR subkey[LEN_Path];
  117. CLSID clsid;
  118. rc = profExt.Open(GET_STRING(IDS_REGKEY_PROFILE_EXTENSIONS));
  119. if ( ! rc )
  120. {
  121. for ( int i = 0 ; ! rc ; i++ )
  122. {
  123. rc = profExt.SubKeyEnum(i,subkey,DIM(subkey));
  124. if (! rc )
  125. {
  126. HRESULT hr = CLSIDFromString(subkey,&clsid);
  127. IMcsDomPlugIn * pExt = NULL;
  128. SAFEARRAY * pArray = NULL;
  129. if ( SUCCEEDED(hr) )
  130. {
  131. hr = CoCreateInstance(clsid,NULL,CLSCTX_ALL,IID_IMcsDomPlugIn,(void**)&pExt);
  132. if ( SUCCEEDED(hr) )
  133. {
  134. if ( pRequired )
  135. {
  136. hr = pExt->GetRequiredFiles(&pArray);
  137. if ( SUCCEEDED(hr) )
  138. {
  139. AddFilesToList(pArray,pRequired);
  140. SafeArrayDestroy(pArray);
  141. }
  142. }
  143. if ( pRegisterable )
  144. {
  145. hr = pExt->GetRegisterableFiles(&pArray);
  146. if (SUCCEEDED(hr) )
  147. {
  148. AddFilesToList(pArray,pRegisterable);
  149. SafeArrayDestroy(pArray);
  150. }
  151. }
  152. pExt->Release();
  153. }
  154. }
  155. }
  156. }
  157. }
  158. }
  159. void CProfMMgr::AddFilesToList(SAFEARRAY * pFileArray, TFileList * pList)
  160. {
  161. LONG bound = 0;
  162. LONG ndx[1];
  163. TFileNode * pNode = NULL;
  164. SafeArrayGetUBound(pFileArray,1,&bound);
  165. for ( ndx[0] = 0 ; ndx[0] <= bound ; ndx[0]++ )
  166. {
  167. BSTR val = NULL;
  168. SafeArrayGetElement(pFileArray,ndx,&val);
  169. pNode = new TFileNode(val);
  170. pList->InsertBottom(pNode);
  171. SysFreeString(val);
  172. }
  173. }