Leaked source code of windows server 2003
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.

301 lines
5.2 KiB

  1. // StorageGlobal.cpp : Implementation of CStorageGlobal
  2. #include "stdafx.h"
  3. #include "mswmdm.h"
  4. #include "StorageGlobal.h"
  5. #include "Device.h"
  6. #include "Storage.h"
  7. #include "loghelp.h"
  8. #include "scserver.h"
  9. #include "scclient.h"
  10. #include "spinfo.h"
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CWMDMStorageGlobal
  13. extern CSecureChannelServer *g_pAppSCServer;
  14. extern CSPInfo **g_pSPs;
  15. // IWMDMStorageGlobals
  16. HRESULT CWMDMStorageGlobal::GetTotalSize(DWORD *pdwTotalSizeLow, DWORD *pdwTotalSizeHigh)
  17. {
  18. HRESULT hr;
  19. if (g_pAppSCServer)
  20. {
  21. if(!g_pAppSCServer->fIsAuthenticated())
  22. {
  23. hr = WMDM_E_NOTCERTIFIED;
  24. goto exit;
  25. }
  26. }
  27. else
  28. {
  29. hr = E_FAIL;
  30. goto exit;
  31. }
  32. hr = m_pStgGlobals->GetTotalSize(pdwTotalSizeLow, pdwTotalSizeHigh);
  33. if (FAILED(hr))
  34. {
  35. goto exit;
  36. }
  37. exit:
  38. hrLogDWORD("IWMDMStorageGlobals::GetTotalSize returned 0x%08lx", hr, hr);
  39. return hr;
  40. }
  41. HRESULT CWMDMStorageGlobal::GetCapabilities(DWORD *pdwCapabilities)
  42. {
  43. HRESULT hr;
  44. if (g_pAppSCServer)
  45. {
  46. if(!g_pAppSCServer->fIsAuthenticated())
  47. {
  48. hr = WMDM_E_NOTCERTIFIED;
  49. goto exit;
  50. }
  51. }
  52. else
  53. {
  54. hr = E_FAIL;
  55. goto exit;
  56. }
  57. hr = m_pStgGlobals->GetCapabilities(pdwCapabilities);
  58. if (FAILED(hr))
  59. {
  60. goto exit;
  61. }
  62. exit:
  63. hrLogDWORD("IWMDMStorageGlobals::GetCapabilities returned 0x%08lx", hr, hr);
  64. return hr;
  65. }
  66. HRESULT CWMDMStorageGlobal::GetSerialNumber(PWMDMID pSerialNum, BYTE abMac[WMDM_MAC_LENGTH])
  67. {
  68. HRESULT hr;
  69. HMAC hMAC;
  70. CSecureChannelClient *pSCClient;
  71. BYTE abTempMAC[SAC_MAC_LEN];
  72. BYTE abMACVerify[SAC_MAC_LEN];
  73. if (g_pAppSCServer)
  74. {
  75. if(!g_pAppSCServer->fIsAuthenticated())
  76. {
  77. hr = WMDM_E_NOTCERTIFIED;
  78. goto exit;
  79. }
  80. }
  81. else
  82. {
  83. hr = E_FAIL;
  84. goto exit;
  85. }
  86. if (!pSerialNum)
  87. {
  88. hr = E_INVALIDARG;
  89. goto exit;
  90. }
  91. g_pSPs[m_wSPIndex]->GetSCClient(&pSCClient);
  92. if (!pSCClient)
  93. {
  94. hr = E_FAIL;
  95. goto exit;
  96. }
  97. hr = m_pStgGlobals->GetSerialNumber(pSerialNum, abTempMAC);
  98. if (FAILED(hr))
  99. {
  100. goto exit;
  101. }
  102. // Verify the MAC from SP
  103. hr = pSCClient->MACInit(&hMAC);
  104. if (FAILED(hr))
  105. {
  106. goto exit;
  107. }
  108. hr = pSCClient->MACUpdate(hMAC, (BYTE*)(pSerialNum), sizeof(WMDMID));
  109. if (FAILED(hr))
  110. {
  111. goto exit;
  112. }
  113. hr = pSCClient->MACFinal(hMAC, abMACVerify);
  114. if (FAILED(hr))
  115. {
  116. goto exit;
  117. }
  118. if (memcmp(abMACVerify, abTempMAC, WMDM_MAC_LENGTH) != 0)
  119. {
  120. hr = WMDM_E_MAC_CHECK_FAILED;
  121. goto exit;
  122. }
  123. // Compute the MAC to send back to the application
  124. hr = g_pAppSCServer->MACInit(&hMAC);
  125. if (FAILED(hr))
  126. {
  127. goto exit;
  128. }
  129. hr = g_pAppSCServer->MACUpdate(hMAC, (BYTE*)(pSerialNum), sizeof(WMDMID));
  130. if (FAILED(hr))
  131. {
  132. goto exit;
  133. }
  134. hr = g_pAppSCServer->MACFinal(hMAC, abMac);
  135. if (FAILED(hr))
  136. {
  137. goto exit;
  138. }
  139. exit:
  140. hrLogDWORD("IWMDMStorageGlobals::GetSerialNumber returned 0x%08lx", hr, hr);
  141. return hr;
  142. }
  143. HRESULT CWMDMStorageGlobal::GetTotalFree(DWORD *pdwFreeLow,
  144. DWORD *pdwFreeHigh)
  145. {
  146. HRESULT hr;
  147. if (g_pAppSCServer)
  148. {
  149. if(!g_pAppSCServer->fIsAuthenticated())
  150. {
  151. hr = WMDM_E_NOTCERTIFIED;
  152. goto exit;
  153. }
  154. }
  155. else
  156. {
  157. hr = E_FAIL;
  158. goto exit;
  159. }
  160. hr = m_pStgGlobals->GetTotalFree(pdwFreeLow, pdwFreeHigh);
  161. if (FAILED(hr))
  162. {
  163. goto exit;
  164. }
  165. exit:
  166. hrLogDWORD("IWMDMStorageGlobals::GetTotalFree returned 0x%08lx", hr, hr);
  167. return hr;
  168. }
  169. HRESULT CWMDMStorageGlobal::GetTotalBad(DWORD *pdwBadLow,
  170. DWORD *pdwBadHigh)
  171. {
  172. HRESULT hr;
  173. if (g_pAppSCServer)
  174. {
  175. if(!g_pAppSCServer->fIsAuthenticated())
  176. {
  177. hr = WMDM_E_NOTCERTIFIED;
  178. goto exit;
  179. }
  180. }
  181. else
  182. {
  183. hr = E_FAIL;
  184. goto exit;
  185. }
  186. hr = m_pStgGlobals->GetTotalBad(pdwBadLow, pdwBadHigh);
  187. if (FAILED(hr))
  188. {
  189. goto exit;
  190. }
  191. exit:
  192. hrLogDWORD("IWMDMStorageGlobals::GetTotalBad returned 0x%08lx", hr, hr);
  193. return hr;
  194. }
  195. HRESULT CWMDMStorageGlobal::GetStatus(DWORD *pdwStatus)
  196. {
  197. HRESULT hr;
  198. if (g_pAppSCServer)
  199. {
  200. if(!g_pAppSCServer->fIsAuthenticated())
  201. {
  202. hr = WMDM_E_NOTCERTIFIED;
  203. goto exit;
  204. }
  205. }
  206. else
  207. {
  208. hr = E_FAIL;
  209. goto exit;
  210. }
  211. hr = m_pStgGlobals->GetStatus(pdwStatus);
  212. if (FAILED(hr))
  213. {
  214. goto exit;
  215. }
  216. exit:
  217. hrLogDWORD("IWMDMStorageGlobals::GetStatus returned 0x%08lx", hr, hr);
  218. return hr;
  219. }
  220. HRESULT CWMDMStorageGlobal::Initialize(UINT fuMode,
  221. IWMDMProgress *pProgress)
  222. {
  223. HRESULT hr;
  224. if (g_pAppSCServer)
  225. {
  226. if(!g_pAppSCServer->fIsAuthenticated())
  227. {
  228. hr = WMDM_E_NOTCERTIFIED;
  229. goto exit;
  230. }
  231. }
  232. else
  233. {
  234. hr = E_FAIL;
  235. goto exit;
  236. }
  237. hr = m_pStgGlobals->Initialize(fuMode, pProgress);
  238. if (FAILED(hr))
  239. {
  240. goto exit;
  241. }
  242. exit:
  243. hrLogDWORD("IWMDMStorageGlobals::Initialize returned 0x%08lx", hr, hr);
  244. return hr;
  245. }
  246. void CWMDMStorageGlobal::SetContainedPointer(IMDSPStorageGlobals *pStgGlobals, WORD wSPIndex)
  247. {
  248. m_pStgGlobals = pStgGlobals;
  249. m_pStgGlobals->AddRef();
  250. m_wSPIndex = wSPIndex;
  251. return;
  252. }