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.

879 lines
24 KiB

  1. /*************************************************************************
  2. *
  3. * rpcwire.c
  4. *
  5. * Common functions for converting internal WinStation API structures
  6. * to/from a wire format which enables interoperability between various
  7. * releases of icasrv and winsta.dll.
  8. *
  9. * Copyright Microsoft Corporation. 1998
  10. *
  11. *************************************************************************/
  12. /*
  13. * Includes
  14. */
  15. #include <nt.h>
  16. #include <ntrtl.h>
  17. #include <nturtl.h>
  18. #include <ntddkbd.h>
  19. #include <ntddmou.h>
  20. #include <windows.h>
  21. #include <winbase.h>
  22. #include <winerror.h>
  23. #include <winsta.h>
  24. #include "rpcwire.h"
  25. //
  26. // Allocation routines as defined by the client/server.
  27. //
  28. extern void * MIDL_user_allocate(size_t);
  29. extern void MIDL_user_free( void * );
  30. /*****************************************************************************
  31. *
  32. * InitVarData
  33. *
  34. * Initialize a generic structure which describes variable length data
  35. * within a wire buffer.
  36. *
  37. * ENTRY:
  38. * pVarData (input)
  39. * The structure to initialize.
  40. * Size (input)
  41. * The size of the variable length data.
  42. * Offset (input)
  43. * The offset to the start of the data in the wire buffer.
  44. *
  45. ****************************************************************************/
  46. VOID InitVarData(PVARDATA_WIRE pVarData,
  47. ULONG Size,
  48. ULONG Offset)
  49. {
  50. pVarData->Size = (USHORT) Size;
  51. pVarData->Offset = (USHORT) Offset;
  52. }
  53. /*****************************************************************************
  54. *
  55. * NextOffset
  56. *
  57. * Returns the offset to the next variable length data area.
  58. *
  59. * ENTRY:
  60. * PrevData (input)
  61. * The current last variable length data area.
  62. *
  63. *****************************************************************************/
  64. ULONG NextOffset(PVARDATA_WIRE PrevData)
  65. {
  66. return(PrevData->Offset + PrevData->Size);
  67. }
  68. /*****************************************************************************
  69. *
  70. * SdClassSize
  71. *
  72. * Returns the actual size of the data associated with a given SdClass.
  73. *
  74. * ENTRY:
  75. * SdClass (input)
  76. * The type of Sd.
  77. *
  78. * EXIT
  79. * Returns the data size if known otherwise 0.
  80. *****************************************************************************/
  81. ULONG SdClassSize(SDCLASS SdClass)
  82. {
  83. switch (SdClass) {
  84. case SdNetwork: return(sizeof(NETWORKCONFIGW));
  85. case SdAsync: return(sizeof(ASYNCCONFIGW));
  86. case SdNasi: return(sizeof(NASICONFIGW));
  87. case SdOemFilter: return(sizeof(OEMTDCONFIGW));
  88. #ifdef notdef
  89. // These cases are valid in 1.7
  90. case SdConsole: return(sizeof(CONSOLECONFIGW));
  91. case SdFrame: return(sizeof(FRAMECONFIG));
  92. case SdReliable: return(sizeof(RELIABLECONFIG));
  93. case SdCompress: return(sizeof(COMPRESSCONFIG));
  94. case SdModem: return(sizeof(MODEMCONFIGW));
  95. #endif
  96. default:
  97. return(0);
  98. }
  99. }
  100. /*****************************************************************************
  101. *
  102. * CopySourceToDest
  103. *
  104. * Copies variable length data to/from local/wire buffers. If the source
  105. * buffer is smaller than the destination buffer, the destination buffer
  106. * is zero filled after SourceSize, upto DestSize. (e.g. client queries
  107. * down-level icasrv). If the source buffer is larger than the
  108. * destination buffer, the data is truncated at DestSize (e.g. down-level
  109. * client queries newer icasrv).
  110. *
  111. * ENTRY:
  112. * SourceBuf (input)
  113. * Source buffer
  114. * SourceSize (input)
  115. * Source buffer size
  116. * DestBuf (input)
  117. * Destination buffer
  118. * DestSize (input)
  119. * Destiantion buffer size
  120. *
  121. * EXIT
  122. * Returns the amount of data copied.
  123. *****************************************************************************/
  124. ULONG CopySourceToDest(PCHAR SourceBuf, ULONG SourceSize,
  125. PCHAR DestBuf, ULONG DestSize)
  126. {
  127. ULONG DataSize;
  128. if (SourceSize >= DestSize ) {
  129. memcpy(DestBuf, SourceBuf, DestSize);
  130. DataSize = DestSize;
  131. }
  132. else {
  133. // Down-level server/client (zero fill)
  134. memcpy(DestBuf, SourceBuf, SourceSize);
  135. memset(DestBuf+SourceSize, 0, DestSize - SourceSize);
  136. DataSize = SourceSize;
  137. }
  138. return(DataSize);
  139. }
  140. /*****************************************************************************
  141. *
  142. * CopyPdParamsToWire
  143. *
  144. * Copies a PDPARAMSW structure to a wire buffer.
  145. *
  146. * ENTRY:
  147. * PdParamsWire (input)
  148. * Destination wire buffer
  149. * PdParams (input)
  150. * Source PDPARAMSW structure
  151. *
  152. *****************************************************************************/
  153. VOID
  154. CopyPdParamsToWire(PPDPARAMSWIREW PdParamsWire, PPDPARAMSW PdParams)
  155. {
  156. ULONG Size;
  157. ULONG DataSize;
  158. PdParamsWire->SdClass = PdParams->SdClass;
  159. Size = SdClassSize(PdParams->SdClass);
  160. DataSize = CopySourceToDest((PCHAR)&PdParams->Network,
  161. Size,
  162. (PCHAR)PdParamsWire +
  163. PdParamsWire->SdClassSpecific.Offset,
  164. PdParamsWire->SdClassSpecific.Size);
  165. PdParamsWire->SdClassSpecific.Size = (USHORT)DataSize;
  166. }
  167. /*****************************************************************************
  168. *
  169. * CopyPdParamsFromWire
  170. *
  171. * Copies a wire buffer to a PDPARAMSW structure.
  172. *
  173. * ENTRY:
  174. * PdParamsWire (input)
  175. * Source wire buffer
  176. * PdParams (input)
  177. * Destination PDPARAMSW structure.
  178. *
  179. *****************************************************************************/
  180. VOID
  181. CopyPdParamsFromWire(PPDPARAMSWIREW PdParamsWire, PPDPARAMSW PdParams)
  182. {
  183. ULONG Size;
  184. PdParams->SdClass = PdParamsWire->SdClass;
  185. Size = SdClassSize(PdParams->SdClass);
  186. CopySourceToDest((PCHAR)PdParamsWire + PdParamsWire->SdClassSpecific.Offset,
  187. PdParamsWire->SdClassSpecific.Size,
  188. (PCHAR)&PdParams->Network,
  189. Size);
  190. }
  191. /*****************************************************************************
  192. *
  193. * CopyPdConfigToWire
  194. *
  195. * Copies a PDCONFIGW structure to a wire buffer.
  196. *
  197. * ENTRY:
  198. * PdConfigWire (input)
  199. * Destination wire buffer
  200. * PdConfig (input)
  201. * Source PDCONFIGW structure
  202. *
  203. *****************************************************************************/
  204. VOID CopyPdConfigToWire(PPDCONFIGWIREW PdConfigWire, PPDCONFIGW PdConfig)
  205. {
  206. CopySourceToDest((PCHAR) &PdConfig->Create, sizeof(PDCONFIG2W),
  207. (PCHAR)PdConfigWire + PdConfigWire->PdConfig2W.Offset,
  208. PdConfigWire->PdConfig2W.Size);
  209. CopyPdParamsToWire(&PdConfigWire->PdParams,&PdConfig->Params);
  210. }
  211. /*****************************************************************************
  212. *
  213. * CopyPdConfigFromWire
  214. *
  215. * Copies a wire buffer to a PDCONFIGW structure.
  216. *
  217. * ENTRY:
  218. * PdConfigWire (input)
  219. * Destination wire buffer
  220. * PdConfig (input)
  221. * Source PDCONFIGW structure
  222. *
  223. *****************************************************************************/
  224. VOID CopyPdConfigFromWire(PPDCONFIGWIREW PdConfigWire, PPDCONFIGW PdConfig)
  225. {
  226. CopySourceToDest((PCHAR)PdConfigWire + PdConfigWire->PdConfig2W.Offset,
  227. PdConfigWire->PdConfig2W.Size,
  228. (PCHAR) &PdConfig->Create, sizeof(PDCONFIG2W));
  229. CopyPdParamsFromWire(&PdConfigWire->PdParams,&PdConfig->Params);
  230. }
  231. /*****************************************************************************
  232. *
  233. * CopyWinStaConfigToWire
  234. *
  235. * Copies a WINSTATIONCONFIGW structure to a wire buffer.
  236. *
  237. * ENTRY:
  238. * WinStaConfigWire (input)
  239. * Destination wire buffer
  240. * WinStaConfig (input)
  241. * Source WINSTATIONCONFIGW structure
  242. *
  243. *****************************************************************************/
  244. VOID CopyWinStaConfigToWire(PWINSTACONFIGWIREW WinStaConfigWire,
  245. PWINSTATIONCONFIGW WinStaConfig)
  246. {
  247. CopySourceToDest((PCHAR) &WinStaConfig->User, sizeof(USERCONFIGW),
  248. (PCHAR)WinStaConfigWire+WinStaConfigWire->UserConfig.Offset,
  249. WinStaConfigWire->UserConfig.Size);
  250. CopySourceToDest((PCHAR)&WinStaConfig->Comment,
  251. sizeof(WinStaConfig->Comment),
  252. (PCHAR)&WinStaConfigWire->Comment,
  253. sizeof(WinStaConfigWire->Comment));
  254. CopySourceToDest((PCHAR)&WinStaConfig->OEMId,
  255. sizeof(WinStaConfig->OEMId),
  256. (PCHAR)&WinStaConfigWire->OEMId,
  257. sizeof(WinStaConfigWire->OEMId));
  258. CopySourceToDest((PCHAR)&WinStaConfig + sizeof(WINSTATIONCONFIGW),
  259. 0, // Change this when new fields are added
  260. (PCHAR)WinStaConfigWire+WinStaConfigWire->NewFields.Offset,
  261. WinStaConfigWire->NewFields.Size);
  262. }
  263. /*****************************************************************************
  264. *
  265. * CopyWinStaConfigFromWire
  266. *
  267. * Copies a wire buffer to a WINSTATIONCONFIGW structure.
  268. *
  269. * ENTRY:
  270. * WinStaConfigWire (input)
  271. * Source wire buffer
  272. * WinStaConfig (input)
  273. * Destiantion WINSTATIONCONFIGW structure
  274. *
  275. *****************************************************************************/
  276. VOID CopyWinStaConfigFromWire(PWINSTACONFIGWIREW WinStaConfigWire,
  277. PWINSTATIONCONFIGW WinStaConfig)
  278. {
  279. CopySourceToDest((PCHAR)WinStaConfigWire+WinStaConfigWire->UserConfig.Offset,
  280. WinStaConfigWire->UserConfig.Size,
  281. (PCHAR) &WinStaConfig->User, sizeof(USERCONFIGW));
  282. CopySourceToDest((PCHAR)&WinStaConfigWire->Comment,
  283. sizeof(WinStaConfigWire->Comment),
  284. (PCHAR)&WinStaConfig->Comment,
  285. sizeof(WinStaConfig->Comment));
  286. CopySourceToDest((PCHAR)&WinStaConfigWire->OEMId,
  287. sizeof(WinStaConfigWire->OEMId),
  288. (PCHAR)&WinStaConfig->OEMId,
  289. sizeof(WinStaConfig->OEMId));
  290. CopySourceToDest((PCHAR)WinStaConfigWire+WinStaConfigWire->NewFields.Offset,
  291. WinStaConfigWire->NewFields.Size,
  292. (PCHAR) &WinStaConfig + sizeof(WINSTATIONCONFIGW),
  293. 0); // Change this when new fields are added
  294. }
  295. /*****************************************************************************
  296. *
  297. * CopyGenericToWire
  298. *
  299. * Copies a single variable length structure to a wire buffer.
  300. *
  301. * ENTRY:
  302. * WireBuf (input)
  303. * Destination wire buffer
  304. * LocalBuf (input)
  305. * Source structure
  306. * LocalBufLength (input)
  307. * Source structure length
  308. *****************************************************************************/
  309. VOID CopyGenericToWire(PVARDATA_WIRE WireBuf, PVOID LocalBuf, ULONG LocalBufLen)
  310. {
  311. CopySourceToDest((PCHAR)LocalBuf,
  312. LocalBufLen,
  313. (PCHAR) WireBuf + WireBuf->Offset,
  314. WireBuf->Size);
  315. }
  316. /*****************************************************************************
  317. *
  318. * CopyGenericFromWire
  319. *
  320. * Copies a wire buffer to a single variable length structure.
  321. *
  322. * ENTRY:
  323. * WireBuf (input)
  324. * Source wire buffer
  325. * LocalBuf (input)
  326. * Destination structure
  327. * LocalBufLength (input)
  328. * Destination structure length
  329. *****************************************************************************/
  330. VOID CopyGenericFromWire(PVARDATA_WIRE WireBuf, PVOID LocalBuf, ULONG LocalBufLen)
  331. {
  332. CopySourceToDest((PCHAR) WireBuf + WireBuf->Offset,
  333. WireBuf->Size,
  334. (PCHAR)LocalBuf,
  335. LocalBufLen);
  336. }
  337. /*****************************************************************************
  338. *
  339. * CopyOutWireBuf
  340. *
  341. * Copies a wire buffer to a local structure.
  342. *
  343. * ENTRY:
  344. * InfoClass (input)
  345. * WinStationQuery/Set information class
  346. * UserBuf (input)
  347. * Destination local structure
  348. * WireBuf
  349. * Source wire buffer
  350. *****************************************************************************/
  351. BOOLEAN
  352. CopyOutWireBuf(WINSTATIONINFOCLASS InfoClass,
  353. PVOID UserBuf,
  354. PVOID WireBuf)
  355. {
  356. ULONG BufSize;
  357. PPDCONFIGWIREW PdConfigWire;
  358. PPDCONFIGW PdConfig;
  359. PPDPARAMSWIREW PdParamsWire;
  360. PPDPARAMSW PdParam;
  361. PWINSTACONFIGWIREW WinStaConfigWire;
  362. PWINSTATIONCONFIGW WinStaConfig;
  363. switch (InfoClass) {
  364. case WinStationPd:
  365. PdConfigWire = (PPDCONFIGWIREW)WireBuf;
  366. PdConfig = (PPDCONFIGW)UserBuf;
  367. CopyPdConfigFromWire(PdConfigWire, PdConfig);
  368. break;
  369. case WinStationPdParams:
  370. PdParamsWire = (PPDPARAMSWIREW)WireBuf;
  371. CopyPdParamsFromWire(PdParamsWire,
  372. (PPDPARAMS)UserBuf);
  373. break;
  374. case WinStationConfiguration:
  375. WinStaConfigWire = (PWINSTACONFIGWIREW)WireBuf;
  376. WinStaConfig = (PWINSTATIONCONFIGW)UserBuf;
  377. CopyWinStaConfigFromWire(WinStaConfigWire, WinStaConfig);
  378. break;
  379. case WinStationInformation:
  380. CopyGenericFromWire((PVARDATA_WIRE)WireBuf,
  381. UserBuf,
  382. sizeof(WINSTATIONINFORMATIONW));
  383. break;
  384. case WinStationWd:
  385. CopyGenericFromWire((PVARDATA_WIRE)WireBuf,
  386. UserBuf,
  387. sizeof(WDCONFIGW));
  388. break;
  389. case WinStationClient:
  390. CopyGenericFromWire((PVARDATA_WIRE)WireBuf,
  391. UserBuf,
  392. sizeof(WINSTATIONCLIENTW));
  393. break;
  394. default:
  395. return(FALSE);
  396. }
  397. return(TRUE);
  398. }
  399. /*****************************************************************************
  400. *
  401. * CopyInWireBuf
  402. *
  403. * Copies a local structure to a wire buffer.
  404. *
  405. * ENTRY:
  406. * InfoClass (input)
  407. * WinStationQuery/Set information class
  408. * WireBuf (input)
  409. * Destination wire buffer
  410. * UserBuf (input)
  411. * Destination local structure
  412. *****************************************************************************/
  413. BOOLEAN
  414. CopyInWireBuf(WINSTATIONINFOCLASS InfoClass,
  415. PVOID UserBuf,
  416. PVOID WireBuf)
  417. {
  418. ULONG BufSize;
  419. PPDCONFIGWIREW PdConfigWire;
  420. PPDCONFIGW PdConfig;
  421. PPDPARAMSWIREW PdParamsWire;
  422. PPDPARAMSW PdParam;
  423. PWINSTACONFIGWIREW WinStaConfigWire;
  424. PWINSTATIONCONFIGW WinStaConfig;
  425. switch (InfoClass) {
  426. case WinStationPd:
  427. PdConfigWire = (PPDCONFIGWIREW)WireBuf;
  428. PdConfig = (PPDCONFIGW)UserBuf;
  429. CopyPdConfigToWire(PdConfigWire, PdConfig);
  430. break;
  431. case WinStationPdParams:
  432. PdParamsWire = (PPDPARAMSWIREW)WireBuf;
  433. CopyPdParamsToWire(PdParamsWire,
  434. (PPDPARAMS)UserBuf);
  435. break;
  436. case WinStationConfiguration:
  437. WinStaConfigWire = (PWINSTACONFIGWIREW)WireBuf;
  438. WinStaConfig = (PWINSTATIONCONFIGW)UserBuf;
  439. CopyWinStaConfigToWire(WinStaConfigWire, WinStaConfig);
  440. break;
  441. case WinStationInformation:
  442. CopyGenericToWire((PVARDATA_WIRE)WireBuf,
  443. UserBuf,
  444. sizeof(WINSTATIONINFORMATIONW));
  445. break;
  446. case WinStationWd:
  447. CopyGenericToWire((PVARDATA_WIRE)WireBuf,
  448. UserBuf,
  449. sizeof(WDCONFIGW));
  450. break;
  451. case WinStationClient:
  452. CopyGenericToWire((PVARDATA_WIRE)WireBuf,
  453. UserBuf,
  454. sizeof(WINSTATIONCLIENTW));
  455. break;
  456. default:
  457. return(FALSE);
  458. }
  459. return(TRUE);
  460. }
  461. /*****************************************************************************
  462. *
  463. * AllocateAndCopyCredToWire
  464. *
  465. * Allocates a buffer big enough for the credentials and then copies them in.
  466. *
  467. *****************************************************************************/
  468. ULONG
  469. AllocateAndCopyCredToWire(
  470. PWLXCLIENTCREDWIREW *ppWire,
  471. PWLX_CLIENT_CREDENTIALS_INFO_V2_0 pCredentials
  472. )
  473. {
  474. ULONG cchUserName;
  475. ULONG cchDomain;
  476. ULONG cchPassword;
  477. ULONG cbWireBuf;
  478. cchUserName = lstrlenW(pCredentials->pszUserName) + 1;
  479. cchDomain = lstrlenW(pCredentials->pszDomain) + 1;
  480. cchPassword = lstrlenW(pCredentials->pszPassword) + 1;
  481. cbWireBuf = sizeof(WLXCLIENTCREDWIREW) +
  482. (cchUserName + cchDomain + cchPassword) * sizeof(WCHAR);
  483. *ppWire = MIDL_user_allocate(cbWireBuf);
  484. if (*ppWire != NULL)
  485. {
  486. ZeroMemory(*ppWire, cbWireBuf);
  487. }
  488. else
  489. {
  490. SetLastError(ERROR_OUTOFMEMORY);
  491. return(0);
  492. }
  493. (*ppWire)->dwType = pCredentials->dwType;
  494. (*ppWire)->fDisconnectOnLogonFailure = pCredentials->fDisconnectOnLogonFailure;
  495. (*ppWire)->fPromptForPassword = pCredentials->fPromptForPassword;
  496. InitVarData(
  497. &((*ppWire)->UserNameData),
  498. cchUserName * sizeof(WCHAR),
  499. sizeof(WLXCLIENTCREDWIREW)
  500. );
  501. CopyMemory(
  502. (LPBYTE)(*ppWire) + (*ppWire)->UserNameData.Offset,
  503. pCredentials->pszUserName,
  504. (*ppWire)->UserNameData.Size
  505. );
  506. InitVarData(
  507. &((*ppWire)->DomainData),
  508. cchDomain * sizeof(WCHAR),
  509. NextOffset(&((*ppWire)->UserNameData))
  510. );
  511. CopyMemory(
  512. (LPBYTE)(*ppWire) + (*ppWire)->DomainData.Offset,
  513. pCredentials->pszDomain,
  514. (*ppWire)->DomainData.Size
  515. );
  516. InitVarData(
  517. &((*ppWire)->PasswordData),
  518. cchPassword * sizeof(WCHAR),
  519. NextOffset(&((*ppWire)->DomainData))
  520. );
  521. CopyMemory(
  522. (LPBYTE)(*ppWire) + (*ppWire)->PasswordData.Offset,
  523. pCredentials->pszPassword,
  524. (*ppWire)->PasswordData.Size
  525. );
  526. return(cbWireBuf);
  527. }
  528. /*****************************************************************************
  529. *
  530. * CopyCredFromWire
  531. *
  532. * Copies credentials from the wire buffer.
  533. *
  534. *****************************************************************************/
  535. BOOLEAN
  536. CopyCredFromWire(
  537. PWLXCLIENTCREDWIREW pWire,
  538. PWLX_CLIENT_CREDENTIALS_INFO_V2_0 pCredentials
  539. )
  540. {
  541. BOOLEAN fRet;
  542. pCredentials->pszUserName = LocalAlloc(
  543. LMEM_FIXED,
  544. pWire->UserNameData.Size
  545. );
  546. if (pCredentials->pszUserName != NULL)
  547. {
  548. CopyMemory(
  549. (LPBYTE)(pCredentials->pszUserName),
  550. (LPBYTE)pWire + pWire->UserNameData.Offset,
  551. pWire->UserNameData.Size
  552. );
  553. }
  554. else
  555. {
  556. SetLastError(ERROR_OUTOFMEMORY);
  557. fRet = FALSE;
  558. goto exit;
  559. }
  560. pCredentials->pszDomain = LocalAlloc(
  561. LMEM_FIXED,
  562. pWire->DomainData.Size
  563. );
  564. if (pCredentials->pszDomain != NULL)
  565. {
  566. CopyMemory(
  567. (LPBYTE)(pCredentials->pszDomain),
  568. (LPBYTE)pWire + pWire->DomainData.Offset,
  569. pWire->DomainData.Size
  570. );
  571. }
  572. else
  573. {
  574. SetLastError(ERROR_OUTOFMEMORY);
  575. fRet = FALSE;
  576. goto exit;
  577. }
  578. pCredentials->pszPassword = LocalAlloc(
  579. LMEM_FIXED,
  580. pWire->PasswordData.Size
  581. );
  582. if (pCredentials->pszPassword != NULL)
  583. {
  584. CopyMemory(
  585. (LPBYTE)(pCredentials->pszPassword),
  586. (LPBYTE)pWire + pWire->PasswordData.Offset,
  587. pWire->PasswordData.Size
  588. );
  589. }
  590. else
  591. {
  592. SetLastError(ERROR_OUTOFMEMORY);
  593. fRet = FALSE;
  594. goto exit;
  595. }
  596. pCredentials->dwType = pWire->dwType;
  597. pCredentials->fDisconnectOnLogonFailure = pWire->fDisconnectOnLogonFailure;
  598. pCredentials->fPromptForPassword = pWire->fPromptForPassword;
  599. fRet = TRUE;
  600. exit:
  601. if (!fRet)
  602. {
  603. if (pCredentials->pszUserName != NULL)
  604. {
  605. LocalFree(pCredentials->pszUserName);
  606. pCredentials->pszUserName = NULL;
  607. }
  608. if (pCredentials->pszDomain != NULL)
  609. {
  610. LocalFree(pCredentials->pszDomain);
  611. pCredentials->pszDomain = NULL;
  612. }
  613. if (pCredentials->pszPassword != NULL)
  614. {
  615. LocalFree(pCredentials->pszPassword);
  616. pCredentials->pszPassword = NULL;
  617. }
  618. }
  619. return(fRet);
  620. }
  621. /*
  622. * Licensing Core functions
  623. */
  624. ULONG
  625. CopyPolicyInformationToWire(
  626. LPLCPOLICYINFOGENERIC *ppWire,
  627. LPLCPOLICYINFOGENERIC pPolicyInfo
  628. )
  629. {
  630. ULONG ulReturn;
  631. ASSERT(ppWire != NULL);
  632. ASSERT(pPolicyInfo != NULL);
  633. if (pPolicyInfo->ulVersion == LCPOLICYINFOTYPE_V1)
  634. {
  635. LPLCPOLICYINFOWIRE_V1 *ppWireV1;
  636. LPLCPOLICYINFO_V1W pPolicyInfoV1;
  637. ULONG cbPolicyName;
  638. ULONG cbPolicyDescription;
  639. ppWireV1 = (LPLCPOLICYINFOWIRE_V1*)ppWire;
  640. pPolicyInfoV1 = (LPLCPOLICYINFO_V1W)pPolicyInfo;
  641. cbPolicyName = (lstrlenW(pPolicyInfoV1->lpPolicyName) + 1) * sizeof(WCHAR);
  642. cbPolicyDescription = (lstrlenW(pPolicyInfoV1->lpPolicyDescription) + 1) * sizeof(WCHAR);
  643. ulReturn = sizeof(LCPOLICYINFOWIRE_V1);
  644. ulReturn += cbPolicyName;
  645. ulReturn += cbPolicyDescription;
  646. *ppWireV1 = MIDL_user_allocate(ulReturn);
  647. if (*ppWireV1 != NULL)
  648. {
  649. (*ppWireV1)->ulVersion = LCPOLICYINFOTYPE_V1;
  650. InitVarData(
  651. &((*ppWireV1)->PolicyNameData),
  652. cbPolicyName,
  653. sizeof(LCPOLICYINFOWIRE_V1)
  654. );
  655. CopyMemory(
  656. (LPBYTE)(*ppWireV1) + (*ppWireV1)->PolicyNameData.Offset,
  657. pPolicyInfoV1->lpPolicyName,
  658. (*ppWireV1)->PolicyNameData.Size
  659. );
  660. InitVarData(
  661. &((*ppWireV1)->PolicyDescriptionData),
  662. cbPolicyDescription,
  663. NextOffset(&((*ppWireV1)->PolicyNameData))
  664. );
  665. CopyMemory(
  666. (LPBYTE)(*ppWireV1) + (*ppWireV1)->PolicyDescriptionData.Offset,
  667. pPolicyInfoV1->lpPolicyDescription,
  668. (*ppWireV1)->PolicyDescriptionData.Size
  669. );
  670. }
  671. else
  672. {
  673. SetLastError(ERROR_OUTOFMEMORY);
  674. ulReturn = 0;
  675. }
  676. }
  677. else
  678. {
  679. SetLastError(ERROR_UNKNOWN_REVISION);
  680. ulReturn = 0;
  681. }
  682. return(ulReturn);
  683. }
  684. BOOLEAN
  685. CopyPolicyInformationFromWire(
  686. LPLCPOLICYINFOGENERIC *ppPolicyInfo,
  687. LPLCPOLICYINFOGENERIC pWire
  688. )
  689. {
  690. BOOLEAN fRet;
  691. ASSERT(ppPolicyInfo != NULL);
  692. ASSERT(pWire != NULL);
  693. if (pWire->ulVersion == LCPOLICYINFOTYPE_V1)
  694. {
  695. LPLCPOLICYINFO_V1W *ppPolicyInfoV1;
  696. LPLCPOLICYINFOWIRE_V1 pWireV1;
  697. ppPolicyInfoV1 = (LPLCPOLICYINFO_V1W*)ppPolicyInfo;
  698. pWireV1 = (LPLCPOLICYINFOWIRE_V1)pWire;
  699. *ppPolicyInfoV1 = LocalAlloc(LPTR, sizeof(LCPOLICYINFO_V1W));
  700. if (*ppPolicyInfoV1 != NULL)
  701. {
  702. (*ppPolicyInfoV1)->ulVersion = LCPOLICYINFOTYPE_V1;
  703. (*ppPolicyInfoV1)->lpPolicyName = LocalAlloc(LPTR, pWireV1->PolicyNameData.Size);
  704. if ((*ppPolicyInfoV1)->lpPolicyName != NULL)
  705. {
  706. CopyMemory(
  707. (LPBYTE)((*ppPolicyInfoV1)->lpPolicyName),
  708. (LPBYTE)pWireV1 + pWireV1->PolicyNameData.Offset,
  709. pWireV1->PolicyNameData.Size
  710. );
  711. }
  712. else
  713. {
  714. SetLastError(ERROR_OUTOFMEMORY);
  715. fRet = FALSE;
  716. goto V1error;
  717. }
  718. (*ppPolicyInfoV1)->lpPolicyDescription = LocalAlloc(LPTR, pWireV1->PolicyDescriptionData.Size);
  719. if ((*ppPolicyInfoV1)->lpPolicyDescription != NULL)
  720. {
  721. CopyMemory(
  722. (LPBYTE)((*ppPolicyInfoV1)->lpPolicyDescription),
  723. (LPBYTE)pWireV1 + pWireV1->PolicyDescriptionData.Offset,
  724. pWireV1->PolicyDescriptionData.Size
  725. );
  726. }
  727. else
  728. {
  729. SetLastError(ERROR_OUTOFMEMORY);
  730. fRet = FALSE;
  731. goto V1error;
  732. }
  733. fRet = TRUE;
  734. goto exit;
  735. V1error:
  736. if ((*ppPolicyInfoV1)->lpPolicyName != NULL)
  737. {
  738. LocalFree((*ppPolicyInfoV1)->lpPolicyName);
  739. (*ppPolicyInfoV1)->lpPolicyName = NULL;
  740. }
  741. if ((*ppPolicyInfoV1)->lpPolicyDescription != NULL)
  742. {
  743. LocalFree((*ppPolicyInfoV1)->lpPolicyDescription);
  744. (*ppPolicyInfoV1)->lpPolicyDescription = NULL;
  745. }
  746. LocalFree(*ppPolicyInfoV1);
  747. *ppPolicyInfoV1 = NULL;
  748. }
  749. else
  750. {
  751. SetLastError(ERROR_OUTOFMEMORY);
  752. fRet = FALSE;
  753. }
  754. }
  755. else
  756. {
  757. SetLastError(ERROR_UNKNOWN_REVISION);
  758. fRet = FALSE;
  759. }
  760. exit:
  761. return(fRet);
  762. }