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.

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