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.

353 lines
9.3 KiB

  1. #include "precomp.h"
  2. #include "fsdiag.h"
  3. DEBUG_FILEZONE(ZONE_T120_UTILITY);
  4. /*
  5. * appenrol.cpp
  6. *
  7. * Copyright (c) 1994 by DataBeam Corporation, Lexington, KY
  8. *
  9. * Abstract:
  10. * This is the implementation file for the class
  11. * ApplicationEnrollRequestData.
  12. *
  13. * Caveats:
  14. * None.
  15. *
  16. * Author:
  17. * jbo
  18. */
  19. #include "appenrol.h"
  20. /*
  21. * ApplicationEnrollRequestData ()
  22. *
  23. * Public Function Description:
  24. * This constructor is used to create a ApplicationEnrollRequestData object
  25. * from an ApplicationEnrollRequestMessage in preparation for serializing
  26. * the application enroll request data.
  27. */
  28. ApplicationEnrollRequestData::ApplicationEnrollRequestData(
  29. PApplicationEnrollRequestMessage enroll_request_message,
  30. PGCCError pRetCode)
  31. {
  32. GCCError rc = GCC_NO_ERROR;
  33. Session_Key_Data = NULL;
  34. Non_Collapsing_Caps_Data = NULL;
  35. Application_Capability_Data = NULL;
  36. /*
  37. * Save the message structure in an instance variable. This will save all
  38. * structure elements except the session key and the lists of non-collapsing
  39. * and application capabilities.
  40. */
  41. Enroll_Request_Message = *enroll_request_message;
  42. /*
  43. * Create a CSessKeyContainer object to be used to handle the session key
  44. * contained in the enroll request message.
  45. */
  46. if (Enroll_Request_Message.session_key != NULL)
  47. {
  48. DBG_SAVE_FILE_LINE
  49. Session_Key_Data = new CSessKeyContainer(
  50. Enroll_Request_Message.session_key,
  51. &rc);
  52. if ((Session_Key_Data != NULL) && (rc == GCC_NO_ERROR))
  53. {
  54. if (Enroll_Request_Message.number_of_non_collapsed_caps != 0)
  55. {
  56. /*
  57. * Create a CNonCollAppCap object to hold the non-
  58. * collapsing capabilities.
  59. */
  60. DBG_SAVE_FILE_LINE
  61. Non_Collapsing_Caps_Data = new CNonCollAppCap(
  62. (ULONG) Enroll_Request_Message.number_of_non_collapsed_caps,
  63. Enroll_Request_Message.non_collapsed_caps_list,
  64. &rc);
  65. if (Non_Collapsing_Caps_Data == NULL)
  66. {
  67. rc = GCC_ALLOCATION_FAILURE;
  68. }
  69. else if (rc != GCC_NO_ERROR)
  70. {
  71. Non_Collapsing_Caps_Data->Release();
  72. Non_Collapsing_Caps_Data = NULL;
  73. }
  74. }
  75. else
  76. {
  77. Non_Collapsing_Caps_Data = NULL;
  78. }
  79. if ((rc == GCC_NO_ERROR) &&
  80. (Enroll_Request_Message.number_of_collapsed_caps != 0))
  81. {
  82. /*
  83. * Create an CAppCap object to hold the
  84. * application capabilities.
  85. */
  86. DBG_SAVE_FILE_LINE
  87. Application_Capability_Data = new CAppCap(
  88. (ULONG) Enroll_Request_Message.number_of_collapsed_caps,
  89. Enroll_Request_Message.collapsed_caps_list,
  90. &rc);
  91. if (Application_Capability_Data == NULL)
  92. {
  93. rc = GCC_ALLOCATION_FAILURE;
  94. }
  95. else if (rc != GCC_NO_ERROR)
  96. {
  97. Application_Capability_Data->Release();
  98. Application_Capability_Data = NULL;
  99. }
  100. }
  101. else
  102. {
  103. Application_Capability_Data = NULL;
  104. }
  105. }
  106. else if (Session_Key_Data == NULL)
  107. {
  108. rc = GCC_ALLOCATION_FAILURE;
  109. }
  110. else
  111. {
  112. Session_Key_Data->Release();
  113. Session_Key_Data = NULL;
  114. }
  115. }
  116. else
  117. {
  118. Session_Key_Data = NULL;
  119. Application_Capability_Data = NULL;
  120. Non_Collapsing_Caps_Data = NULL;
  121. /*
  122. ** Note that if no session key is present there is no need to pass
  123. ** any capability information.
  124. */
  125. Enroll_Request_Message.number_of_non_collapsed_caps = 0;
  126. Enroll_Request_Message.non_collapsed_caps_list = NULL;
  127. Enroll_Request_Message.number_of_collapsed_caps = 0;
  128. Enroll_Request_Message.collapsed_caps_list = NULL;
  129. }
  130. *pRetCode = rc;
  131. }
  132. /*
  133. * ApplicationEnrollRequestData ()
  134. *
  135. * Public Function Description:
  136. * This constructor is used to create a ApplicationEnrollRequestData object
  137. * from an ApplicationEnrollRequestMessage and the memory holding the
  138. * enroll request's serialized data in preparation for deserializing
  139. * the application enroll request data.
  140. */
  141. ApplicationEnrollRequestData::ApplicationEnrollRequestData(
  142. PApplicationEnrollRequestMessage enroll_request_message)
  143. {
  144. Session_Key_Data = NULL;
  145. Non_Collapsing_Caps_Data = NULL;
  146. Application_Capability_Data = NULL;
  147. /*
  148. * Save the message structure in an instance variable. This will save all
  149. * structure elements but not the data associated with the session key and
  150. * the lists of non-collapsing and application capabilities.
  151. */
  152. Enroll_Request_Message = *enroll_request_message;
  153. }
  154. /*
  155. * ~ApplicationEnrollRequestData ()
  156. *
  157. * Public Function Description
  158. * The ApplicationEnrollRequestData destructor.
  159. *
  160. */
  161. ApplicationEnrollRequestData::~ApplicationEnrollRequestData()
  162. {
  163. /*
  164. * Delete any internal data objects which may exist.
  165. */
  166. if (NULL != Session_Key_Data)
  167. {
  168. Session_Key_Data->Release();
  169. }
  170. if (NULL != Non_Collapsing_Caps_Data)
  171. {
  172. Non_Collapsing_Caps_Data->Release();
  173. }
  174. if (NULL != Application_Capability_Data)
  175. {
  176. Application_Capability_Data->Release();
  177. }
  178. }
  179. /*
  180. * GetDataSize ()
  181. *
  182. * Public Function Description
  183. * This routine is used to determine the amount of memory necessary to
  184. * hold all of the data associated with an ApplicationEnrollRequestMessage
  185. * that is not held within the message strucuture.
  186. */
  187. ULONG ApplicationEnrollRequestData::GetDataSize(void)
  188. {
  189. ULONG data_size = 0;
  190. /*
  191. * The first data referenced by the enroll request message is the data for
  192. * the session key. Use the internal CSessKeyContainer object to determine
  193. * the length of the data referenced by the session key. Also add the size
  194. * of the actual session key structure.
  195. */
  196. if (Session_Key_Data != NULL)
  197. {
  198. data_size += Session_Key_Data->LockSessionKeyData();
  199. data_size += ROUNDTOBOUNDARY (sizeof(GCCSessionKey));
  200. }
  201. /*
  202. * Now determine the length of the list of non-collapsing capabilities and
  203. * the length of the list of application capabilities. This is done using
  204. * the internal CNonCollAppCap and CAppCap objects.
  205. */
  206. if (Non_Collapsing_Caps_Data != NULL)
  207. {
  208. data_size += Non_Collapsing_Caps_Data->LockCapabilityData();
  209. }
  210. if (Application_Capability_Data != NULL)
  211. {
  212. data_size += Application_Capability_Data->LockCapabilityData();
  213. }
  214. return (data_size);
  215. }
  216. /*
  217. * Serialize ()
  218. *
  219. * Public Function Description
  220. * This routine is used to prepare an ApplicationEnrollRequest message
  221. * for passing through shared memory. The message structure is filled in
  222. * and the data referenced by the structure written into the memory
  223. * provided.
  224. */
  225. ULONG ApplicationEnrollRequestData::Serialize(
  226. PApplicationEnrollRequestMessage enroll_request_message,
  227. LPSTR memory)
  228. {
  229. ULONG data_length;
  230. ULONG total_data_length = 0;
  231. USHORT app_capability_data_length;
  232. /*
  233. * Copy the internal message structure into the output structure. This will
  234. * copy all structure elements except the session key and the lists of
  235. * non-collapsing and application capabilities.
  236. */
  237. *enroll_request_message = Enroll_Request_Message;
  238. if (Session_Key_Data != NULL)
  239. {
  240. /*
  241. * Set the pointer to the session key structure.
  242. */
  243. enroll_request_message->session_key = (PGCCSessionKey)memory;
  244. /*
  245. * Move the memory pointer past the session key structure.
  246. */
  247. memory += ROUNDTOBOUNDARY(sizeof(GCCSessionKey));
  248. /*
  249. * Retrieve the session key data from the internal CSessKeyContainer
  250. * object. It will serialize the necessary data into memory and return
  251. * the amount of data written.
  252. */
  253. data_length = Session_Key_Data->GetGCCSessionKeyData (
  254. enroll_request_message->session_key, memory);
  255. total_data_length = data_length + ROUNDTOBOUNDARY(sizeof(GCCSessionKey));
  256. /*
  257. * Move the memory pointer past the session key data.
  258. */
  259. memory += data_length;
  260. Session_Key_Data->UnLockSessionKeyData();
  261. }
  262. else
  263. {
  264. enroll_request_message->session_key = NULL;
  265. }
  266. /*
  267. * Retrieve the non-collapsing capabilities data from the internal
  268. * CNonCollAppCap object. It will serialize the necessary data
  269. * into memory and return the amount of memory written.
  270. */
  271. if (Non_Collapsing_Caps_Data != NULL)
  272. {
  273. data_length = Non_Collapsing_Caps_Data->GetGCCNonCollapsingCapsList (
  274. &enroll_request_message->non_collapsed_caps_list,
  275. memory);
  276. total_data_length += data_length;
  277. /*
  278. * Move the memory pointer past the non-collapsing capabilities and the
  279. * associated data.
  280. */
  281. memory += data_length;
  282. Non_Collapsing_Caps_Data->UnLockCapabilityData();
  283. }
  284. else
  285. {
  286. enroll_request_message->non_collapsed_caps_list = NULL;
  287. }
  288. if (Application_Capability_Data != NULL)
  289. {
  290. /*
  291. * Retrieve the application capabilities from the internal
  292. * CAppCap object. It will serialize the necessary data
  293. * into memory and return the amount of memory written.
  294. */
  295. total_data_length += Application_Capability_Data->
  296. GetGCCApplicationCapabilityList(
  297. &app_capability_data_length,
  298. &enroll_request_message->collapsed_caps_list,
  299. memory);
  300. Application_Capability_Data->UnLockCapabilityData();
  301. }
  302. diagprint1("AppEnrollReqData: Serialized %ld bytes", total_data_length);
  303. return (total_data_length);
  304. }
  305. /*
  306. * Deserialize ()
  307. *
  308. * Public Function Description
  309. * This routine is used to retrieve an ApplicationEnrollRequest message
  310. * after it has been passed through shared memory.
  311. */
  312. void ApplicationEnrollRequestData::Deserialize(
  313. PApplicationEnrollRequestMessage enroll_request_message)
  314. {
  315. /*
  316. * The internal structure contains the enroll request data with the pointers
  317. * addressing the correct locations in memory so just copy the structure
  318. * into the output parameter.
  319. */
  320. *enroll_request_message = Enroll_Request_Message;
  321. }