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.

850 lines
22 KiB

  1. /*++
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. helpass.c
  5. Abstract:
  6. Salem related function.
  7. Author:
  8. HueiWang 4/26/2000
  9. --*/
  10. #define LSCORE_NO_ICASRV_GLOBALS
  11. #include "precomp.h"
  12. #include <tdi.h>
  13. #include <winsock2.h>
  14. #include <ws2tcpip.h>
  15. #include "tsremdsk.h"
  16. #include "sessmgr.h"
  17. #include "sessmgr_i.c"
  18. extern "C"
  19. NTSTATUS
  20. xxxQueryRemoteAddress(
  21. PWINSTATION pWinStation,
  22. PWINSTATIONREMOTEADDRESS pRemoteAddress
  23. );
  24. HRESULT
  25. __LogSalemEvent(
  26. IN IRemoteDesktopHelpSessionMgr* iSessMgr,
  27. IN ULONG eventType,
  28. IN ULONG eventCode,
  29. IN int numStrings,
  30. IN BSTR EventStrings[]
  31. );
  32. //
  33. // Function copied from atlconv.h, we don't include
  34. // any ATL header in termsrv.
  35. //
  36. BSTR A2WBSTR(LPCSTR lp)
  37. {
  38. if (lp == NULL)
  39. return NULL;
  40. BSTR str = NULL;
  41. int nConvertedLen = MultiByteToWideChar(
  42. GetACP(), 0, lp,
  43. -1, NULL, NULL)-1;
  44. str = ::SysAllocStringLen(NULL, nConvertedLen);
  45. if (str != NULL)
  46. {
  47. MultiByteToWideChar(GetACP(), 0, lp, -1,
  48. str, nConvertedLen);
  49. }
  50. return str;
  51. }
  52. NTSTATUS
  53. TSHelpAssistantQueryLogonCredentials(
  54. ExtendedClientCredentials* pCredential
  55. )
  56. /*++
  57. Description:
  58. Retrieve HelpAssistant logon credential, routine first retrieve
  59. infor passed from client and then decrypt password
  60. Parameters:
  61. pWinStation : Pointer to WINSTATION
  62. pCredential : Pointer to ExtendedClientCredentials to receive HelpAssistant
  63. credential.
  64. Returns:
  65. STATUS_SUCCESS or STATUS_INVALID_PARAMETER
  66. --*/
  67. {
  68. LPWSTR pszHelpAssistantPassword = NULL;
  69. NTSTATUS Status;
  70. LPWSTR pszHelpAssistantAccountName = NULL;
  71. LPWSTR pszHelpAssistantAccountDomain = NULL;
  72. if( pCredential )
  73. {
  74. ZeroMemory( pCredential, sizeof(ExtendedClientCredentials) );
  75. Status = TSGetHelpAssistantAccountName(&pszHelpAssistantAccountDomain, &pszHelpAssistantAccountName);
  76. if( ERROR_SUCCESS == Status )
  77. {
  78. // make sure we don't overwrite buffer, length can't be
  79. // more than 255 characters.
  80. lstrcpyn(
  81. pCredential->UserName,
  82. pszHelpAssistantAccountName,
  83. EXTENDED_USERNAME_LEN
  84. );
  85. lstrcpyn(
  86. pCredential->Domain,
  87. pszHelpAssistantAccountDomain,
  88. EXTENDED_DOMAIN_LEN
  89. );
  90. Status = TSGetHelpAssistantAccountPassword( &pszHelpAssistantPassword );
  91. if( ERROR_SUCCESS == Status )
  92. {
  93. ASSERT( lstrlen(pszHelpAssistantPassword) < EXTENDED_PASSWORD_LEN );
  94. int nPasswordlen = lstrlen( pszHelpAssistantPassword );
  95. if( nPasswordlen < EXTENDED_PASSWORD_LEN )
  96. {
  97. // Password contains encrypted version, overwrite with
  98. // clear text.
  99. lstrcpy( pCredential->Password, pszHelpAssistantPassword );
  100. SecureZeroMemory( pszHelpAssistantPassword , nPasswordlen * sizeof( WCHAR ) );
  101. }
  102. else
  103. {
  104. Status = STATUS_INVALID_PARAMETER;
  105. }
  106. }
  107. }
  108. }
  109. else
  110. {
  111. ASSERT( FALSE );
  112. Status = STATUS_INVALID_PARAMETER;
  113. }
  114. if( NULL != pszHelpAssistantAccountDomain )
  115. {
  116. LocalFree( pszHelpAssistantAccountDomain );
  117. }
  118. if( NULL != pszHelpAssistantAccountName )
  119. {
  120. LocalFree(pszHelpAssistantAccountName);
  121. }
  122. if( NULL != pszHelpAssistantPassword )
  123. {
  124. LocalFree( pszHelpAssistantPassword );
  125. }
  126. return Status;
  127. }
  128. BOOL
  129. TSIsSessionHelpSession(
  130. PWINSTATION pWinStation,
  131. BOOL* pValid
  132. )
  133. /*++
  134. Routine Description:
  135. Determine if a session is HelpAssistant session.
  136. Parameters:
  137. pWinStation : Pointer to WINSTATION structure.
  138. pValid : Optional Pointer to BOOL to receive status of ticket,
  139. TRUE of ticket is valid, FALSE if ticket is invalid or
  140. help is disabled.
  141. Returns:
  142. TRUE/FALSE Funtion return TRUE even if ticket is invalid, caller
  143. should check pValid to determine if ticket is valid or not.
  144. --*/
  145. {
  146. BOOL bReturn;
  147. BOOL bValidHelpSession = FALSE;
  148. if( NULL == pWinStation )
  149. {
  150. ASSERT( NULL != pWinStation );
  151. SetLastError( ERROR_INVALID_PARAMETER );
  152. bReturn = FALSE;
  153. goto CLEANUPANDEXIT;
  154. }
  155. if( pWinStation->Client.ProtocolType != PROTOCOL_RDP )
  156. {
  157. //
  158. // HelpAssistant is RDP specific and not on console
  159. DBGPRINT( ("TermSrv : HelpAssistant protocol type not RDP \n") );
  160. bValidHelpSession = FALSE;
  161. bReturn = FALSE;
  162. }
  163. else if( WSF_ST_HELPSESSION_NOTHELPSESSION & pWinStation->StateFlags )
  164. {
  165. // We are sure that this session is not HelpAssistant Session.
  166. bReturn = FALSE;
  167. bValidHelpSession = FALSE;
  168. }
  169. else if( WSF_ST_HELPSESSION_HELPSESSIONINVALID & pWinStation->StateFlags )
  170. {
  171. // Help assistant logon but password or ticket ID is invalid
  172. bReturn = TRUE;
  173. bValidHelpSession = FALSE;
  174. }
  175. else if( WSF_ST_HELPSESSION_HELPSESSION & pWinStation->StateFlags )
  176. {
  177. // We are sure this is help assistant logon
  178. bReturn = TRUE;
  179. bValidHelpSession = TRUE;
  180. }
  181. else
  182. {
  183. //
  184. // Clear RA state flags.
  185. //
  186. pWinStation->StateFlags &= ~WSF_ST_HELPSESSION_FLAGS;
  187. if( !pWinStation->Client.UserName[0] || !pWinStation->Client.Password[0] ||
  188. !pWinStation->Client.WorkDirectory[0] )
  189. {
  190. bReturn = FALSE;
  191. bValidHelpSession = FALSE;
  192. pWinStation->StateFlags |= WSF_ST_HELPSESSION_NOTHELPSESSION;
  193. }
  194. else
  195. {
  196. //
  197. // TermSrv might call this routine with data send from client,
  198. // client always send hardcoded SALEMHELPASSISTANTACCOUNT_NAME
  199. //
  200. if( lstrcmpi( pWinStation->Client.UserName, SALEMHELPASSISTANTACCOUNT_NAME ) )
  201. {
  202. bReturn = FALSE;
  203. bValidHelpSession = FALSE;
  204. pWinStation->StateFlags |= WSF_ST_HELPSESSION_NOTHELPSESSION;
  205. goto CLEANUPANDEXIT;
  206. }
  207. //
  208. // this is helpassistant login.
  209. //
  210. bReturn = TRUE;
  211. //
  212. // Check if machine policy restrict help or
  213. // in Help mode, deny access if not.
  214. //
  215. if( FALSE == TSIsMachinePolicyAllowHelp() || FALSE == TSIsMachineInHelpMode() )
  216. {
  217. bValidHelpSession = FALSE;
  218. pWinStation->StateFlags |= WSF_ST_HELPSESSION_HELPSESSIONINVALID;
  219. goto CLEANUPANDEXIT;
  220. }
  221. if( TSVerifyHelpSessionAndLogSalemEvent(pWinStation) )
  222. {
  223. bValidHelpSession = TRUE;
  224. pWinStation->StateFlags |= WSF_ST_HELPSESSION_HELPSESSION;
  225. }
  226. else
  227. {
  228. //
  229. // Either ticket is invalid or expired.
  230. //
  231. bValidHelpSession = FALSE;
  232. pWinStation->StateFlags |= WSF_ST_HELPSESSION_HELPSESSIONINVALID;
  233. }
  234. }
  235. }
  236. CLEANUPANDEXIT:
  237. if( pValid )
  238. {
  239. *pValid = bValidHelpSession;
  240. }
  241. return bReturn;
  242. }
  243. DWORD WINAPI
  244. SalemStartupThreadProc( LPVOID ptr )
  245. /*++
  246. Temporary code to start up Salem sessmgr, post B2 need to move sessmgr into svchost
  247. --*/
  248. {
  249. HRESULT hRes = S_OK;
  250. IRemoteDesktopHelpSessionMgr* pISessMgr = NULL;
  251. //
  252. // Startup sessmgr if there is outstanding ticket and
  253. // we just rebooted from system restore.
  254. //
  255. if( !TSIsMachineInHelpMode() && !TSIsMachineInSystemRestore() && !TSIsFireWallPortsOpen( ) )
  256. {
  257. ExitThread(hRes);
  258. return hRes;
  259. }
  260. hRes = CoInitialize( NULL );
  261. if( FAILED(hRes) )
  262. {
  263. DBGPRINT( ("TermSrv : TSStartupSalem() CoInitialize() failed with 0x%08x\n", hRes) );
  264. // Failed in COM, return FALSE.
  265. goto CLEANUPANDEXIT;
  266. }
  267. hRes = CoCreateInstance(
  268. CLSID_RemoteDesktopHelpSessionMgr,
  269. NULL,
  270. CLSCTX_LOCAL_SERVER | CLSCTX_DISABLE_AAA,
  271. IID_IRemoteDesktopHelpSessionMgr,
  272. (LPVOID *) &pISessMgr
  273. );
  274. if( FAILED(hRes) || NULL == pISessMgr )
  275. {
  276. DBGPRINT( ("TermSrv : TSStartupSalem() CoCreateInstance() failed with 0x%08x\n", hRes) );
  277. // Can't initialize sessmgr
  278. goto CLEANUPANDEXIT;
  279. }
  280. CLEANUPANDEXIT:
  281. if( NULL != pISessMgr )
  282. {
  283. pISessMgr->Release();
  284. }
  285. CoUninitialize();
  286. ExitThread(hRes);
  287. return hRes;
  288. }
  289. void
  290. TSStartupSalem()
  291. {
  292. HANDLE hThread;
  293. hThread = CreateThread( NULL, 0, SalemStartupThreadProc, NULL, 0, NULL );
  294. if( NULL != hThread )
  295. {
  296. CloseHandle( hThread );
  297. }
  298. return;
  299. }
  300. BOOL
  301. TSVerifyHelpSessionAndLogSalemEvent(
  302. PWINSTATION pWinStation
  303. )
  304. /*++
  305. Description:
  306. Verify help session is a valid, non-expired pending help session,
  307. log an event if help session is invalid.
  308. Parameters:
  309. pWinStation : Point to WINSTATION
  310. Returns:
  311. TRUE/FALSE
  312. Note :
  313. WorkDirectory is HelpSessionID and InitialProgram contains
  314. password to pending help session
  315. --*/
  316. {
  317. HRESULT hRes;
  318. IRemoteDesktopHelpSessionMgr* pISessMgr = NULL;
  319. BOOL bSuccess = FALSE;
  320. BSTR bstrHelpSessId = NULL;
  321. BSTR bstrHelpSessPwd = NULL;
  322. WINSTATIONREMOTEADDRESS winstationRemoteAddress;
  323. DWORD dwReturnLength;
  324. NTSTATUS Status;
  325. BSTR bstrExpertIpAddressFromClient = NULL;
  326. BSTR bstrExpertIpAddressFromServer = NULL;
  327. // only have three strings in this event
  328. BSTR bstrEventStrings[3];
  329. hRes = CoInitialize( NULL );
  330. if( FAILED(hRes) )
  331. {
  332. DBGPRINT( ("TermSrv : TSIsHelpSessionValid() CoInitialize() failed with 0x%08x\n", hRes) );
  333. // Failed in COM, return FALSE.
  334. return FALSE;
  335. }
  336. hRes = CoCreateInstance(
  337. CLSID_RemoteDesktopHelpSessionMgr,
  338. NULL,
  339. CLSCTX_LOCAL_SERVER | CLSCTX_DISABLE_AAA,
  340. IID_IRemoteDesktopHelpSessionMgr,
  341. (LPVOID *) &pISessMgr
  342. );
  343. if( FAILED(hRes) || NULL == pISessMgr )
  344. {
  345. DBGPRINT( ("TermSrv : TSIsHelpSessionValid() CoCreateInstance() failed with 0x%08x\n", hRes) );
  346. // Can't initialize sessmgr
  347. goto CLEANUPANDEXIT;
  348. }
  349. //
  350. // Set the security level to impersonate. This is required by
  351. // the session manager.
  352. //
  353. hRes = CoSetProxyBlanket(
  354. (IUnknown *)pISessMgr,
  355. RPC_C_AUTHN_DEFAULT,
  356. RPC_C_AUTHZ_DEFAULT,
  357. NULL,
  358. RPC_C_AUTHN_LEVEL_DEFAULT,
  359. RPC_C_IMP_LEVEL_IDENTIFY,
  360. NULL,
  361. EOAC_NONE
  362. );
  363. if( FAILED(hRes) )
  364. {
  365. DBGPRINT( ("TermSrv : TSIsHelpSessionValid() CoSetProxyBlanket() failed with 0x%08x\n", hRes) );
  366. // can't impersonate, return FALSE
  367. goto CLEANUPANDEXIT;
  368. }
  369. bstrHelpSessId = ::SysAllocString(pWinStation->Client.WorkDirectory);
  370. bstrHelpSessPwd = ::SysAllocString(pWinStation->Client.InitialProgram);
  371. if( NULL == bstrHelpSessId || NULL == bstrHelpSessPwd )
  372. {
  373. // We are so out of memory, treat as error
  374. goto CLEANUPANDEXIT;
  375. }
  376. // Verify help session
  377. hRes = pISessMgr->IsValidHelpSession(
  378. bstrHelpSessId,
  379. bstrHelpSessPwd
  380. );
  381. bSuccess = SUCCEEDED(hRes);
  382. if( FALSE == bSuccess )
  383. {
  384. // Log invalid help ticket event here.
  385. Status = xxxQueryRemoteAddress( pWinStation, &winstationRemoteAddress );
  386. bstrExpertIpAddressFromClient = ::SysAllocString( pWinStation->Client.ClientAddress );
  387. if( !NT_SUCCESS(Status) || AF_INET != winstationRemoteAddress.sin_family )
  388. {
  389. //
  390. // we don't support other than IPV4 now or we failed to retrieve address
  391. // from driver, use what's send in from client.
  392. bstrExpertIpAddressFromServer = ::SysAllocString( pWinStation->Client.ClientAddress );
  393. }
  394. else
  395. {
  396. // refer to in_addr structure.
  397. struct in_addr S;
  398. S.S_un.S_addr = winstationRemoteAddress.ipv4.in_addr;
  399. bstrExpertIpAddressFromServer = A2WBSTR( inet_ntoa(S) );
  400. }
  401. if( !bstrExpertIpAddressFromClient || !bstrExpertIpAddressFromServer )
  402. {
  403. // we are out of memory, can't log event.
  404. goto CLEANUPANDEXIT;
  405. }
  406. bstrEventStrings[0] = bstrExpertIpAddressFromClient;
  407. bstrEventStrings[1] = bstrExpertIpAddressFromServer;
  408. bstrEventStrings[2] = bstrHelpSessId;
  409. __LogSalemEvent(
  410. pISessMgr,
  411. EVENTLOG_INFORMATION_TYPE,
  412. REMOTEASSISTANCE_EVENTLOG_TERMSRV_INVALID_TICKET,
  413. 3,
  414. bstrEventStrings
  415. );
  416. }
  417. CLEANUPANDEXIT:
  418. if( NULL != pISessMgr )
  419. {
  420. pISessMgr->Release();
  421. }
  422. if( NULL != bstrHelpSessId )
  423. {
  424. SecureZeroMemory( bstrHelpSessId , SysStringByteLen( bstrHelpSessId ) );
  425. ::SysFreeString( bstrHelpSessId );
  426. }
  427. if( NULL != bstrHelpSessPwd )
  428. {
  429. SecureZeroMemory( bstrHelpSessPwd , SysStringByteLen( bstrHelpSessPwd ) );
  430. ::SysFreeString( bstrHelpSessPwd );
  431. }
  432. if( NULL != bstrExpertIpAddressFromClient )
  433. {
  434. ::SysFreeString( bstrExpertIpAddressFromClient );
  435. }
  436. if( NULL != bstrExpertIpAddressFromServer )
  437. {
  438. ::SysFreeString( bstrExpertIpAddressFromServer );
  439. }
  440. DBGPRINT( ("TermSrv : TSIsHelpSessionValid() returns 0x%08x\n", hRes) );
  441. CoUninitialize();
  442. return bSuccess;
  443. }
  444. VOID
  445. TSLogSalemReverseConnection(
  446. PWINSTATION pWinStation,
  447. PICA_STACK_ADDRESS pStackAddress
  448. )
  449. /*++
  450. --*/
  451. {
  452. HRESULT hRes;
  453. IRemoteDesktopHelpSessionMgr* pISessMgr = NULL;
  454. BOOL bSuccess = FALSE;
  455. int index;
  456. // Fours string for this event
  457. BSTR bstrEventStrings[3];
  458. ZeroMemory( bstrEventStrings, sizeof(bstrEventStrings) );
  459. hRes = CoInitialize( NULL );
  460. if( FAILED(hRes) )
  461. {
  462. DBGPRINT( ("TermSrv : TSLogSalemReverseConnection() CoInitialize() failed with 0x%08x\n", hRes) );
  463. goto CLEANUPANDEXIT;
  464. }
  465. hRes = CoCreateInstance(
  466. CLSID_RemoteDesktopHelpSessionMgr,
  467. NULL,
  468. CLSCTX_LOCAL_SERVER | CLSCTX_DISABLE_AAA,
  469. IID_IRemoteDesktopHelpSessionMgr,
  470. (LPVOID *) &pISessMgr
  471. );
  472. if( FAILED(hRes) || NULL == pISessMgr )
  473. {
  474. DBGPRINT( ("TermSrv : TSLogSalemReverseConnection() CoCreateInstance() failed with 0x%08x\n", hRes) );
  475. // Can't initialize sessmgr
  476. goto CLEANUPANDEXIT;
  477. }
  478. //
  479. // Set the security level to impersonate. This is required by
  480. // the session manager.
  481. //
  482. hRes = CoSetProxyBlanket(
  483. (IUnknown *)pISessMgr,
  484. RPC_C_AUTHN_DEFAULT,
  485. RPC_C_AUTHZ_DEFAULT,
  486. NULL,
  487. RPC_C_AUTHN_LEVEL_DEFAULT,
  488. RPC_C_IMP_LEVEL_IDENTIFY,
  489. NULL,
  490. EOAC_NONE
  491. );
  492. if( FAILED(hRes) )
  493. {
  494. DBGPRINT( ("TermSrv : TSLogSalemReverseConnection() CoSetProxyBlanket() failed with 0x%08x\n", hRes) );
  495. // can't impersonate, return FALSE
  496. goto CLEANUPANDEXIT;
  497. }
  498. //
  499. // sessmgr expect event string in following order
  500. //
  501. // IP address send from client.
  502. // IP address that termsrv connect to, this is part of the expert connect parm.
  503. // Help Session Ticket ID
  504. //
  505. bstrEventStrings[0] = ::SysAllocString( pWinStation->Client.ClientAddress );
  506. {
  507. struct in_addr S;
  508. PTDI_ADDRESS_IP pIpAddress = (PTDI_ADDRESS_IP)&((PCHAR)pStackAddress)[2];
  509. // refer to in_addr structure.
  510. S.S_un.S_addr = pIpAddress->in_addr;
  511. bstrEventStrings[1] = A2WBSTR( inet_ntoa(S) );
  512. }
  513. bstrEventStrings[2] = ::SysAllocString(pWinStation->Client.WorkDirectory);
  514. if( NULL != bstrEventStrings[0] &&
  515. NULL != bstrEventStrings[1] &&
  516. NULL != bstrEventStrings[2] )
  517. {
  518. hRes = __LogSalemEvent(
  519. pISessMgr,
  520. EVENTLOG_INFORMATION_TYPE,
  521. REMOTEASSISTANCE_EVENTLOG_TERMSRV_REVERSE_CONNECT,
  522. 3,
  523. bstrEventStrings
  524. );
  525. }
  526. CLEANUPANDEXIT:
  527. if( NULL != pISessMgr )
  528. {
  529. pISessMgr->Release();
  530. }
  531. for(index=0; index < sizeof(bstrEventStrings)/sizeof(bstrEventStrings[0]); index++)
  532. {
  533. if( !bstrEventStrings[index] )
  534. {
  535. ::SysFreeString( bstrEventStrings[index] );
  536. }
  537. }
  538. DBGPRINT( ("TermSrv : TSLogSalemReverseConnection() returns 0x%08x\n", hRes) );
  539. CoUninitialize();
  540. return;
  541. }
  542. HRESULT
  543. __LogSalemEvent(
  544. IN IRemoteDesktopHelpSessionMgr* pISessMgr,
  545. IN ULONG eventType,
  546. IN ULONG eventCode,
  547. IN int numStrings,
  548. IN BSTR bstrEventStrings[]
  549. )
  550. /*++
  551. Description:
  552. Create a safearray and pass parameters to sessmgr.
  553. Parameters:
  554. Returns:
  555. S_OK or error code.
  556. --*/
  557. {
  558. HRESULT hRes = S_OK;
  559. VARIANT EventStrings;
  560. int index;
  561. // we only have three string to be included in the event log.
  562. SAFEARRAY* psa = NULL;
  563. SAFEARRAYBOUND bounds;
  564. BSTR* bstrArray = NULL;
  565. bounds.cElements = numStrings;
  566. bounds.lLbound = 0;
  567. VariantInit(&EventStrings);
  568. //
  569. // Create a safearray to pass all event string
  570. //
  571. psa = SafeArrayCreate(VT_BSTR, 1, &bounds);
  572. if( NULL == psa )
  573. {
  574. goto CLEANUPANDEXIT;
  575. }
  576. // Required, lock the safe array
  577. hRes = SafeArrayAccessData(psa, (void **)&bstrArray);
  578. if( SUCCEEDED(hRes) )
  579. {
  580. for(index=0; index < numStrings; index++)
  581. {
  582. bstrArray[index] = bstrEventStrings[index];
  583. }
  584. EventStrings.vt = VT_ARRAY | VT_BSTR;
  585. EventStrings.parray = psa;
  586. hRes = pISessMgr->LogSalemEvent(
  587. eventType,
  588. eventCode,
  589. &EventStrings
  590. );
  591. //
  592. // make sure we clear BSTR array or VariantClear() will invoke
  593. // SafeArrayDestroy() which in term will invoke ::SysFreeString()
  594. // on each BSTR.
  595. //
  596. for(index=0; index < numStrings; index++)
  597. {
  598. bstrArray[index] = NULL;
  599. }
  600. hRes = SafeArrayUnaccessData( psa );
  601. ASSERT( SUCCEEDED(hRes) );
  602. // make sure we don't destroy safe array twice, VariantClear()
  603. // will destroy it.
  604. psa = NULL;
  605. }
  606. CLEANUPANDEXIT:
  607. hRes = VariantClear(&EventStrings);
  608. ASSERT( SUCCEEDED(hRes) );
  609. if( psa != NULL )
  610. {
  611. SafeArrayDestroy(psa);
  612. }
  613. return hRes;
  614. }
  615. HRESULT
  616. TSRemoteAssistancePrepareSystemRestore()
  617. /*++
  618. Routine Description:
  619. Prepare system for RA specific system restore, this includes RA specific encryption key,
  620. registry settings that we need preserve.
  621. Parameters:
  622. None.
  623. Returns:
  624. S_OK or error code.
  625. --*/
  626. {
  627. HRESULT hRes;
  628. IRemoteDesktopHelpSessionMgr* pISessMgr = NULL;
  629. hRes = CoInitialize( NULL );
  630. if( FAILED(hRes) )
  631. {
  632. DBGPRINT( ("TermSrv : TSRemoteAssistancePrepareSystemRestore() CoInitialize() failed with 0x%08x\n", hRes) );
  633. goto CLEANUPANDEXIT;
  634. }
  635. hRes = CoCreateInstance(
  636. CLSID_RemoteDesktopHelpSessionMgr,
  637. NULL,
  638. CLSCTX_LOCAL_SERVER | CLSCTX_DISABLE_AAA,
  639. IID_IRemoteDesktopHelpSessionMgr,
  640. (LPVOID *) &pISessMgr
  641. );
  642. if( FAILED(hRes) || NULL == pISessMgr )
  643. {
  644. DBGPRINT( ("TermSrv : TSRemoteAssistancePrepareSystemRestore() CoCreateInstance() failed with 0x%08x\n", hRes) );
  645. // Can't initialize sessmgr
  646. goto CLEANUPANDEXIT;
  647. }
  648. //
  649. // Set the security level to impersonate. This is required by
  650. // the session manager.
  651. //
  652. hRes = CoSetProxyBlanket(
  653. (IUnknown *)pISessMgr,
  654. RPC_C_AUTHN_DEFAULT,
  655. RPC_C_AUTHZ_DEFAULT,
  656. NULL,
  657. RPC_C_AUTHN_LEVEL_DEFAULT,
  658. RPC_C_IMP_LEVEL_IDENTIFY,
  659. NULL,
  660. EOAC_NONE
  661. );
  662. if( FAILED(hRes) )
  663. {
  664. DBGPRINT( ("TermSrv : TSRemoteAssistancePrepareSystemRestore() CoSetProxyBlanket() failed with 0x%08x\n", hRes) );
  665. // can't impersonate, return FALSE
  666. goto CLEANUPANDEXIT;
  667. }
  668. hRes = pISessMgr->PrepareSystemRestore();
  669. CLEANUPANDEXIT:
  670. if( NULL != pISessMgr )
  671. {
  672. pISessMgr->Release();
  673. }
  674. return hRes;
  675. }