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.

870 lines
32 KiB

  1. /*---------------------------------------------------------------------------
  2. File: WtsUser.cpp
  3. Comments: Windows Terminal Server support
  4. (c) Copyright 1999, Mission Critical Software, Inc., All Rights Reserved
  5. Proprietary and confidential to Mission Critical Software, Inc.
  6. REVISION LOG ENTRY
  7. Revision By: Christy Boles
  8. Revised on 03/08/99 13:22:54
  9. ---------------------------------------------------------------------------
  10. */
  11. #include <windows.h>
  12. #include "Common.hpp"
  13. #include "UString.hpp"
  14. #include "Err.hpp"
  15. #include "EaLen.hpp"
  16. #include "Dll.hpp"
  17. #include "WTSINFO.h"
  18. #include <WtsApi32.h>
  19. #include "wtsdyna.h"
  20. #include "WtsUtil.h"
  21. DllAccess gWtsDll;
  22. extern TError err;
  23. long gflDebug = 1;
  24. const long EaxDebugFl_Wts = 0;
  25. WTSQUERYUSERCONFIGW * gpWtsQueryUserConfig = NULL;
  26. WTSSETUSERCONFIGW * gpWtsSetUserConfig = NULL;
  27. WTSFREEMEMORY * gpWtsFreeMemory = NULL;
  28. WTSOPENSERVERW * gpWtsOpenServer = NULL;
  29. WTSCLOSESERVER * gpWtsCloseServer = NULL;
  30. DWORD
  31. WtsUserQueryProperty(
  32. WCHAR * pDomCtrl, // in -name of domain controller to read info from
  33. WCHAR * pUserName, // in -username of account to read
  34. WTS_CONFIG_CLASS infotype, // in -type of information to retrieve
  35. LPWSTR * pBuffer, // out-buffer containing information
  36. DWORD * lenBuffer // out-length of information returned
  37. )
  38. {
  39. DWORD rc = 0;
  40. MCSASSERT(pBuffer);
  41. MCSASSERT(lenBuffer);
  42. MCSASSERT(pDomCtrl);
  43. MCSASSERT(pUserName);
  44. MCSASSERT(gWtsDll.IsLoaded());
  45. MCSASSERT(gpWtsQueryUserConfig);
  46. (*pBuffer) = NULL;
  47. (*lenBuffer) = 0;
  48. if ( ! (*gpWtsQueryUserConfig)(pDomCtrl,pUserName, infotype, pBuffer, lenBuffer) )
  49. {
  50. rc = GetLastError();
  51. (*lenBuffer) = 0;
  52. (*pBuffer) = NULL;
  53. }
  54. return rc;
  55. }
  56. DWORD
  57. WtsUserSetProperty(
  58. WCHAR * pDomCtrl, // in -name of PDC to write info to
  59. WCHAR * pUserName, // in -username of account to modify
  60. WTS_CONFIG_CLASS infotype, // in -type of information to modify
  61. LPTSTR buffer, // in -buffer containing information to write
  62. DWORD lenBuffer // in -length of information to write
  63. )
  64. {
  65. DWORD rc = 0;
  66. MCSASSERT(buffer);
  67. MCSASSERT(lenBuffer);
  68. MCSASSERT(pDomCtrl);
  69. MCSASSERT(pUserName);
  70. MCSASSERT(gpWtsSetUserConfig);
  71. MCSASSERT(gWtsDll.IsLoaded());
  72. if ( ! (*gpWtsSetUserConfig)(pDomCtrl,pUserName, infotype, buffer,lenBuffer) )
  73. {
  74. rc = GetLastError();
  75. }
  76. return rc;
  77. }
  78. // Tries to determine if a server is running WTS
  79. BOOL // ret-TRUE-server is online and running WTS
  80. WtsTryServer(
  81. WCHAR * serverName // in -name of server
  82. )
  83. {
  84. HANDLE hServer;
  85. BOOL bOK = FALSE;
  86. DWORD count = 0;
  87. MCSASSERT(gpWtsOpenServer);
  88. MCSASSERT(gpWtsCloseServer);
  89. hServer = (*gpWtsOpenServer)(serverName);
  90. if ( hServer && hServer != INVALID_HANDLE_VALUE )
  91. {
  92. if ( gflDebug & EaxDebugFl_Wts )
  93. {
  94. // err.MsgWrite(ErrI,L"WTSOpenServer(%ls) succeeded.",serverName);
  95. }
  96. bOK = TRUE;
  97. (*gpWtsCloseServer)(hServer);
  98. }
  99. else
  100. {
  101. DWORD rc = GetLastError();
  102. if ( gflDebug & EaxDebugFl_Wts )
  103. {
  104. // err.SysMsgWrite(ErrW, rc, L"WTSOpenServer(%ls) failed, rc=%ld ",serverName,rc);
  105. }
  106. }
  107. return bOK;
  108. }
  109. DWORD
  110. WtsUserGetInfo( // ret-0 or OS return code
  111. WCHAR const * pDomCtrlName, // in -name of domain controller to read from
  112. WCHAR const * pUserName, // in -username of account to read properties for
  113. DWORD fieldmask, // in -which fields to read
  114. EaWtsUserInfo * pInfo // out-structure containing requested property values
  115. )
  116. {
  117. DWORD rc = 0;
  118. LPWSTR pProperty = NULL;
  119. DWORD lenProperty;
  120. WCHAR domctrl[LEN_Computer];
  121. WCHAR username[LEN_Account];
  122. MCSASSERT(pInfo);
  123. MCSASSERT(pUserName);
  124. MCSASSERT(pDomCtrlName);
  125. MCSASSERT(gpWtsFreeMemory);
  126. MCSASSERT(gWtsDll.IsLoaded());
  127. // Initialize output parameter
  128. memset(pInfo,0,(sizeof *pInfo));
  129. safecopy(domctrl,pDomCtrlName);
  130. safecopy(username,pUserName);
  131. do { // once
  132. if ( fieldmask & FM_WtsUser_inheritInitialProgram )
  133. {
  134. rc = WtsUserQueryProperty(domctrl,username,WTSUserConfigfInheritInitialProgram,&pProperty,&lenProperty);
  135. if ( ! rc )
  136. {
  137. // Copy the property to the structure
  138. if ( lenProperty == (sizeof pInfo->inheritInitialProgram ) )
  139. {
  140. memcpy(&pInfo->inheritInitialProgram,pProperty,lenProperty);
  141. }
  142. else
  143. {
  144. // err.MsgWrite(ErrW,L"Retrieved unexpected value for %ls %s, length=%ld",username,"InheritInitialProgram",lenProperty);
  145. }
  146. (*gpWtsFreeMemory)(pProperty);
  147. }
  148. else
  149. {
  150. // err.SysMsgWrite(ErrE,rc,L"Failed to retrieve %s property for %ls, rc=%ld ","InheritInitialProgram",username,rc);
  151. break;
  152. }
  153. }
  154. if ( fieldmask & FM_WtsUser_allowLogonTerminalServer )
  155. {
  156. rc = WtsUserQueryProperty(domctrl,username,WTSUserConfigfAllowLogonTerminalServer,&pProperty,&lenProperty);
  157. if ( ! rc )
  158. {
  159. // Copy the property to the structure
  160. if ( lenProperty == (sizeof pInfo->allowLogonTerminalServer ) )
  161. {
  162. memcpy(&pInfo->allowLogonTerminalServer,pProperty,lenProperty);
  163. }
  164. else
  165. {
  166. // err.MsgWrite(ErrW,L"Retrieved unexpected value for %ls %s, length=%ld",username,"AllowLogonTerminalServer",lenProperty);
  167. }
  168. (*gpWtsFreeMemory)(pProperty);
  169. }
  170. else
  171. {
  172. // err.SysMsgWrite(ErrE,rc,L"Failed to retrieve %s property for %ls, rc=%ld ","AllowLogonTerminalServer",username,rc);
  173. break;
  174. }
  175. }
  176. if ( fieldmask & FM_WtsUser_timeoutSettingsConnections )
  177. {
  178. rc = WtsUserQueryProperty(domctrl,username,WTSUserConfigTimeoutSettingsConnections,&pProperty,&lenProperty);
  179. if ( ! rc )
  180. {
  181. // Copy the property to the structure
  182. if ( lenProperty == (sizeof pInfo->timeoutSettingsConnections ) )
  183. {
  184. memcpy(&pInfo->timeoutSettingsConnections,pProperty,lenProperty);
  185. }
  186. else
  187. {
  188. // err.MsgWrite(ErrW,L"Retrieved unexpected value for %ls %s, length=%ld",username,"TimeoutSettingsConnections",lenProperty);
  189. }
  190. (*gpWtsFreeMemory)(pProperty);
  191. }
  192. else
  193. {
  194. // err.SysMsgWrite(ErrE,rc,L"Failed to retrieve %s property for %ls, rc=%ld ","TimeoutSettingsConnections",username,rc);
  195. break;
  196. }
  197. }
  198. if ( fieldmask & FM_WtsUser_timeoutSettingsDisconnections )
  199. {
  200. rc = WtsUserQueryProperty(domctrl,username,WTSUserConfigTimeoutSettingsDisconnections,&pProperty,&lenProperty);
  201. if ( ! rc )
  202. {
  203. // Copy the property to the structure
  204. if ( lenProperty == (sizeof pInfo->timeoutSettingsDisconnections ) )
  205. {
  206. memcpy(&pInfo->timeoutSettingsDisconnections,pProperty,lenProperty);
  207. }
  208. else
  209. {
  210. // err.MsgWrite(ErrW,L"Retrieved unexpected value for %ls %s, length=%ld",username,"TimeoutSettingsDisconnections",lenProperty);
  211. }
  212. (*gpWtsFreeMemory)(pProperty);
  213. }
  214. else
  215. {
  216. // err.SysMsgWrite(ErrE,rc,L"Failed to retrieve %s property for %ls, rc=%ld ","TimeoutSettingsDisconnections",username,rc);
  217. break;
  218. }
  219. }
  220. if ( fieldmask & FM_WtsUser_timeoutSettingsIdle )
  221. {
  222. rc = WtsUserQueryProperty(domctrl,username,WTSUserConfigTimeoutSettingsIdle,&pProperty,&lenProperty);
  223. if ( ! rc )
  224. {
  225. // Copy the property to the structure
  226. if ( lenProperty == (sizeof pInfo->timeoutSettingsIdle ) )
  227. {
  228. memcpy(&pInfo->timeoutSettingsIdle,pProperty,lenProperty);
  229. }
  230. else
  231. {
  232. // err.MsgWrite(ErrW,L"Retrieved unexpected value for %ls %s, length=%ld",username,"TimeoutSettingsIdle",lenProperty);
  233. }
  234. (*gpWtsFreeMemory)(pProperty);
  235. }
  236. else
  237. {
  238. // err.SysMsgWrite(ErrE,rc,L"Failed to retrieve %s property for %ls, rc=%ld ","TimeoutSettingsIdle",username,rc);
  239. break;
  240. }
  241. }
  242. if ( fieldmask & FM_WtsUser_deviceClientDrives )
  243. {
  244. rc = WtsUserQueryProperty(domctrl,username,WTSUserConfigfDeviceClientDrives,&pProperty,&lenProperty);
  245. if ( ! rc )
  246. {
  247. // Copy the property to the structure
  248. if ( lenProperty == (sizeof pInfo->deviceClientDrives ) )
  249. {
  250. memcpy(&pInfo->deviceClientDrives,pProperty,lenProperty);
  251. }
  252. else
  253. {
  254. // err.MsgWrite(ErrW,L"Retrieved unexpected value for %ls %s, length=%ld",username,"DeviceClientDrives",lenProperty);
  255. }
  256. (*gpWtsFreeMemory)(pProperty);
  257. }
  258. else
  259. {
  260. // err.SysMsgWrite(ErrE,rc,L"Failed to retrieve %s property for %ls, rc=%ld ","DeviceClientDrives",username,rc);
  261. break;
  262. }
  263. }
  264. if ( fieldmask & FM_WtsUser_deviceClientPrinters )
  265. {
  266. rc = WtsUserQueryProperty(domctrl,username,WTSUserConfigfDeviceClientPrinters,&pProperty,&lenProperty);
  267. if ( ! rc )
  268. {
  269. // Copy the property to the structure
  270. if ( lenProperty == (sizeof pInfo->deviceClientPrinters ) )
  271. {
  272. memcpy(&pInfo->deviceClientPrinters,pProperty,lenProperty);
  273. }
  274. else
  275. {
  276. // err.MsgWrite(ErrW,L"Retrieved unexpected value for %ls %s, length=%ld",username,"DeviceClientPrinters",lenProperty);
  277. }
  278. (*gpWtsFreeMemory)(pProperty);
  279. }
  280. else
  281. {
  282. // err.SysMsgWrite(ErrE,rc,L"Failed to retrieve %s property for %ls, rc=%ld ","DeviceClientPrinters",username,rc);
  283. break;
  284. }
  285. }
  286. if ( fieldmask & FM_WtsUser_deviceClientDefaultPrinter )
  287. {
  288. rc = WtsUserQueryProperty(domctrl,username,WTSUserConfigfDeviceClientDefaultPrinter,&pProperty,&lenProperty);
  289. if ( ! rc )
  290. {
  291. // Copy the property to the structure
  292. if ( lenProperty == (sizeof pInfo->deviceClientDefaultPrinter ) )
  293. {
  294. memcpy(&pInfo->deviceClientDefaultPrinter,pProperty,lenProperty);
  295. }
  296. else
  297. {
  298. // err.MsgWrite(ErrW,L"Retrieved unexpected value for %ls %s, length=%ld",username,"DeviceClientDefaultPrinter",lenProperty);
  299. }
  300. (*gpWtsFreeMemory)(pProperty);
  301. }
  302. else
  303. {
  304. // err.SysMsgWrite(ErrE,rc,L"Failed to retrieve %s property for %ls, rc=%ld ","DeviceClientDefaultPrinter",username,rc);
  305. break;
  306. }
  307. }
  308. if ( fieldmask & FM_WtsUser_brokenTimeoutSettings )
  309. {
  310. rc = WtsUserQueryProperty(domctrl,username,WTSUserConfigBrokenTimeoutSettings,&pProperty,&lenProperty);
  311. if ( ! rc )
  312. {
  313. // Copy the property to the structure
  314. if ( lenProperty == (sizeof pInfo->brokenTimeoutSettings ) )
  315. {
  316. memcpy(&pInfo->brokenTimeoutSettings,pProperty,lenProperty);
  317. }
  318. else
  319. {
  320. // err.MsgWrite(ErrW,L"Retrieved unexpected value for %ls %s, length=%ld",username,"BrokenTimeoutSettings",lenProperty);
  321. }
  322. (*gpWtsFreeMemory)(pProperty);
  323. }
  324. else
  325. {
  326. // err.SysMsgWrite(ErrE,rc,L"Failed to retrieve %s property for %ls, rc=%ld ","BrokenTimeoutSettings",username,rc);
  327. break;
  328. }
  329. }
  330. if ( fieldmask & FM_WtsUser_reconnectSettings )
  331. {
  332. rc = WtsUserQueryProperty(domctrl,username,WTSUserConfigReconnectSettings,&pProperty,&lenProperty);
  333. if ( ! rc )
  334. {
  335. // Copy the property to the structure
  336. if ( lenProperty == (sizeof pInfo->reconnectSettings ) )
  337. {
  338. memcpy(&pInfo->reconnectSettings,pProperty,lenProperty);
  339. }
  340. else
  341. {
  342. // err.MsgWrite(ErrW,L"Retrieved unexpected value for %ls %s, length=%ld",username,"ReconnectSettings",lenProperty);
  343. }
  344. (*gpWtsFreeMemory)(pProperty);
  345. }
  346. else
  347. {
  348. // err.SysMsgWrite(ErrE,rc,L"Failed to retrieve %s property for %ls, rc=%ld ","ReconnectSettings",username,rc);
  349. break;
  350. }
  351. }
  352. if ( fieldmask & FM_WtsUser_modemCallbackSettings )
  353. {
  354. rc = WtsUserQueryProperty(domctrl,username,WTSUserConfigModemCallbackSettings,&pProperty,&lenProperty);
  355. if ( ! rc )
  356. {
  357. // Copy the property to the structure
  358. if ( lenProperty == (sizeof pInfo->modemCallbackSettings ) )
  359. {
  360. memcpy(&pInfo->modemCallbackSettings,pProperty,lenProperty);
  361. }
  362. else
  363. {
  364. // err.MsgWrite(ErrW,L"Retrieved unexpected value for %ls %s, length=%ld",username,"ModemCallbackSettings",lenProperty);
  365. }
  366. (*gpWtsFreeMemory)(pProperty);
  367. }
  368. else
  369. {
  370. // err.SysMsgWrite(ErrE,rc,L"Failed to retrieve %s property for %ls, rc=%ld ","ModemCallbackSettings",username,rc);
  371. break;
  372. }
  373. }
  374. if ( fieldmask & FM_WtsUser_shadowingSettings )
  375. {
  376. rc = WtsUserQueryProperty(domctrl,username,WTSUserConfigShadowingSettings,&pProperty,&lenProperty);
  377. if ( ! rc )
  378. {
  379. // Copy the property to the structure
  380. if ( lenProperty == (sizeof pInfo->shadowingSettings ) )
  381. {
  382. memcpy(&pInfo->shadowingSettings,pProperty,lenProperty);
  383. }
  384. else
  385. {
  386. // err.MsgWrite(ErrW,L"Retrieved unexpected value for %ls %s, length=%ld",username,"ShadowingSettings",lenProperty);
  387. }
  388. (*gpWtsFreeMemory)(pProperty);
  389. }
  390. else
  391. {
  392. // err.SysMsgWrite(ErrE,rc,L"Failed to retrieve %s property for %ls, rc=%ld ","ShadowingSettings",username,rc);
  393. break;
  394. }
  395. }
  396. if ( fieldmask & FM_WtsUser_terminalServerRemoteHomeDir )
  397. {
  398. rc = WtsUserQueryProperty(domctrl,username,WTSUserConfigfTerminalServerRemoteHomeDir,&pProperty,&lenProperty);
  399. if ( ! rc )
  400. {
  401. // Copy the property to the structure
  402. if ( lenProperty == (sizeof pInfo->terminalServerRemoteHomeDir ) )
  403. {
  404. memcpy(&pInfo->terminalServerRemoteHomeDir,pProperty,lenProperty);
  405. }
  406. else
  407. {
  408. // err.MsgWrite(ErrW,L"Retrieved unexpected value for %ls %s, length=%ld",username,"TerminalServerRemoteHomeDir",lenProperty);
  409. }
  410. (*gpWtsFreeMemory)(pProperty);
  411. }
  412. else
  413. {
  414. // err.SysMsgWrite(ErrE,rc,L"Failed to retrieve %s property for %ls, rc=%ld ","TerminalServerRemoteHomeDir",username,rc);
  415. break;
  416. }
  417. }
  418. if ( fieldmask & FM_WtsUser_initialProgram )
  419. {
  420. rc = WtsUserQueryProperty(domctrl,username,WTSUserConfigInitialProgram,&pProperty,&lenProperty);
  421. if ( ! rc )
  422. {
  423. // Copy the property to the structure
  424. safecopy(pInfo->initialProgram,pProperty);
  425. (*gpWtsFreeMemory)(pProperty);
  426. }
  427. else
  428. {
  429. // err.SysMsgWrite(ErrE,rc,L"Failed to retrieve %s property for %ls, rc=%ld ","InitialProgram",username,rc);
  430. break;
  431. }
  432. }
  433. if ( fieldmask & FM_WtsUser_workingDirectory )
  434. {
  435. rc = WtsUserQueryProperty(domctrl,username,WTSUserConfigWorkingDirectory,&pProperty,&lenProperty);
  436. if ( ! rc )
  437. {
  438. // Copy the property to the structure
  439. safecopy(pInfo->workingDirectory,pProperty);
  440. (*gpWtsFreeMemory)(pProperty);
  441. }
  442. else
  443. {
  444. // err.SysMsgWrite(ErrE,rc,L"Failed to retrieve %s property for %ls, rc=%ld ","WorkingDirectory",username,rc);
  445. break;
  446. }
  447. }
  448. if ( fieldmask & FM_WtsUser_modemCallbackPhoneNumber )
  449. {
  450. rc = WtsUserQueryProperty(domctrl,username,WTSUserConfigModemCallbackPhoneNumber,&pProperty,&lenProperty);
  451. if ( ! rc )
  452. {
  453. // Copy the property to the structure
  454. safecopy(pInfo->modemCallbackPhoneNumber,pProperty);
  455. (*gpWtsFreeMemory)(pProperty);
  456. }
  457. else
  458. {
  459. // err.SysMsgWrite(ErrE,rc,L"Failed to retrieve %s property for %ls, rc=%ld ","ModemCallbackPhoneNumber",username,rc);
  460. break;
  461. }
  462. }
  463. if ( fieldmask & FM_WtsUser_terminalServerProfilePath )
  464. {
  465. rc = WtsUserQueryProperty(domctrl,username,WTSUserConfigTerminalServerProfilePath,&pProperty,&lenProperty);
  466. if ( ! rc )
  467. {
  468. // Copy the property to the structure
  469. safecopy(pInfo->terminalServerProfilePath,pProperty);
  470. (*gpWtsFreeMemory)(pProperty);
  471. }
  472. else
  473. {
  474. // err.SysMsgWrite(ErrE,rc,L"Failed to retrieve %s property for %ls, rc=%ld ","TerminalServerProfilePath",username,rc);
  475. break;
  476. }
  477. }
  478. if ( fieldmask & FM_WtsUser_terminalServerHomeDir )
  479. {
  480. rc = WtsUserQueryProperty(domctrl,username,WTSUserConfigTerminalServerHomeDir,&pProperty,&lenProperty);
  481. if ( ! rc )
  482. {
  483. // Copy the property to the structure
  484. safecopy(pInfo->terminalServerHomeDir,pProperty);
  485. (*gpWtsFreeMemory)(pProperty);
  486. }
  487. else
  488. {
  489. // err.SysMsgWrite(ErrE,rc,L"Failed to retrieve %s property for %ls, rc=%ld ","TerminalServerHomeDir",username,rc);
  490. break;
  491. }
  492. }
  493. if ( fieldmask & FM_WtsUser_terminalServerHomeDirDrive )
  494. {
  495. rc = WtsUserQueryProperty(domctrl,username,WTSUserConfigTerminalServerHomeDirDrive,&pProperty,&lenProperty);
  496. if ( ! rc )
  497. {
  498. // Copy the property to the structure
  499. safecopy(pInfo->terminalServerHomeDirDrive,pProperty);
  500. (*gpWtsFreeMemory)(pProperty);
  501. }
  502. else
  503. {
  504. // err.SysMsgWrite(ErrE,rc,L"Failed to retrieve %s property for %ls, rc=%ld ","TerminalServerHomeDirDrive",username,rc);
  505. break;
  506. }
  507. }
  508. } while (FALSE);
  509. return rc;
  510. }
  511. DWORD
  512. WtsUserSetInfo(
  513. WCHAR const * pDomCtrlName, // in -name of domain controller to read from
  514. WCHAR const * pUserName, // in -username of account to read properties for
  515. DWORD fieldmask, // in -which fields to read
  516. EaWtsUserInfo * pInfo // in -structure containing properties to update
  517. )
  518. {
  519. DWORD rc = 0;
  520. DWORD lenProperty;
  521. WCHAR domctrl[LEN_Computer];
  522. WCHAR username[LEN_Account];
  523. WCHAR property[1000];
  524. MCSASSERT(pInfo);
  525. MCSASSERT(pUserName);
  526. MCSASSERT(pDomCtrlName);
  527. MCSASSERT(gWtsDll.IsLoaded());
  528. safecopy(domctrl,pDomCtrlName);
  529. safecopy(username,pUserName);
  530. do { // once
  531. if ( fieldmask & FM_WtsUser_inheritInitialProgram )
  532. {
  533. lenProperty = sizeof(pInfo->inheritInitialProgram);
  534. rc = WtsUserSetProperty(domctrl,username,WTSUserConfigfInheritInitialProgram,(LPWSTR)&pInfo->inheritInitialProgram,lenProperty);
  535. if ( rc )
  536. {
  537. // err.SysMsgWrite(ErrE,rc,"Failed to update %s property for %ls, rc=%ld ","InheritInitialProgram",username,rc);
  538. break;
  539. }
  540. }
  541. if ( fieldmask & FM_WtsUser_allowLogonTerminalServer )
  542. {
  543. lenProperty = sizeof pInfo->allowLogonTerminalServer;
  544. rc = WtsUserSetProperty(domctrl,username,WTSUserConfigfAllowLogonTerminalServer,(LPWSTR)&pInfo->allowLogonTerminalServer,lenProperty);
  545. if ( rc )
  546. {
  547. // err.SysMsgWrite(ErrE,rc,"Failed to update %s property for %ls, rc=%ld ","AllowLogonTerminalServer",username,rc);
  548. break;
  549. }
  550. }
  551. if ( fieldmask & FM_WtsUser_timeoutSettingsConnections )
  552. {
  553. lenProperty = sizeof pInfo->timeoutSettingsConnections;
  554. rc = WtsUserSetProperty(domctrl,username,WTSUserConfigTimeoutSettingsConnections,(LPWSTR)&pInfo->timeoutSettingsConnections,lenProperty);
  555. if ( rc )
  556. {
  557. // err.SysMsgWrite(ErrE,rc,"Failed to update %s property for %ls, rc=%ld ","TimeoutSettingsConnections",username,rc);
  558. break;
  559. }
  560. }
  561. if ( fieldmask & FM_WtsUser_timeoutSettingsDisconnections )
  562. {
  563. lenProperty = sizeof pInfo->timeoutSettingsDisconnections;
  564. rc = WtsUserSetProperty(domctrl,username,WTSUserConfigTimeoutSettingsDisconnections,(LPWSTR)&pInfo->timeoutSettingsDisconnections,lenProperty);
  565. if ( rc )
  566. {
  567. // err.SysMsgWrite(ErrE,rc,"Failed to update %s property for %ls, rc=%ld ","TimeoutSettingsDisconnections",username,rc);
  568. break;
  569. }
  570. }
  571. if ( fieldmask & FM_WtsUser_timeoutSettingsIdle )
  572. {
  573. lenProperty = sizeof pInfo->timeoutSettingsIdle;
  574. rc = WtsUserSetProperty(domctrl,username,WTSUserConfigTimeoutSettingsIdle,(LPWSTR)&pInfo->timeoutSettingsIdle,lenProperty);
  575. if ( rc )
  576. {
  577. // err.SysMsgWrite(ErrE,rc,"Failed to update %s property for %ls, rc=%ld ","TimeoutSettingsIdle",username,rc);
  578. break;
  579. }
  580. }
  581. if ( fieldmask & FM_WtsUser_deviceClientDrives )
  582. {
  583. lenProperty = sizeof pInfo->deviceClientDrives;
  584. rc = WtsUserSetProperty(domctrl,username,WTSUserConfigfDeviceClientDrives,(LPWSTR)&pInfo->deviceClientDrives,lenProperty);
  585. if ( rc )
  586. {
  587. // err.SysMsgWrite(ErrE,rc,"Failed to update %s property for %ls, rc=%ld ","DeviceClientDrives",username,rc);
  588. break;
  589. }
  590. }
  591. if ( fieldmask & FM_WtsUser_deviceClientPrinters )
  592. {
  593. lenProperty = sizeof pInfo->deviceClientPrinters;
  594. rc = WtsUserSetProperty(domctrl,username,WTSUserConfigfDeviceClientPrinters,(LPWSTR)&pInfo->deviceClientPrinters,lenProperty);
  595. if ( rc )
  596. {
  597. // err.SysMsgWrite(ErrE,rc,"Failed to update %s property for %ls, rc=%ld ","DeviceClientPrinters",username,rc);
  598. break;
  599. }
  600. }
  601. if ( fieldmask & FM_WtsUser_deviceClientDefaultPrinter )
  602. {
  603. lenProperty = sizeof pInfo->deviceClientDefaultPrinter;
  604. rc = WtsUserSetProperty(domctrl,username,WTSUserConfigfDeviceClientDefaultPrinter,(LPWSTR)&pInfo->deviceClientDefaultPrinter,lenProperty);
  605. if ( rc )
  606. {
  607. // err.SysMsgWrite(ErrE,rc,"Failed to update %s property for %ls, rc=%ld ","DeviceClientDefaultPrinter",username,rc);
  608. break;
  609. }
  610. }
  611. if ( fieldmask & FM_WtsUser_brokenTimeoutSettings )
  612. {
  613. lenProperty = sizeof pInfo->brokenTimeoutSettings;
  614. rc = WtsUserSetProperty(domctrl,username,WTSUserConfigBrokenTimeoutSettings,(LPWSTR)&pInfo->brokenTimeoutSettings,lenProperty);
  615. if ( rc )
  616. {
  617. // err.SysMsgWrite(ErrE,rc,"Failed to update %s property for %ls, rc=%ld ","BrokenTimeoutSettings",username,rc);
  618. break;
  619. }
  620. }
  621. if ( fieldmask & FM_WtsUser_reconnectSettings )
  622. {
  623. lenProperty = sizeof pInfo->reconnectSettings;
  624. rc = WtsUserSetProperty(domctrl,username,WTSUserConfigReconnectSettings,(LPWSTR)&pInfo->reconnectSettings,lenProperty);
  625. if ( rc )
  626. {
  627. // err.SysMsgWrite(ErrE,rc,"Failed to update %s property for %ls, rc=%ld ","ReconnectSettings",username,rc);
  628. break;
  629. }
  630. }
  631. if ( fieldmask & FM_WtsUser_modemCallbackSettings )
  632. {
  633. lenProperty = sizeof pInfo->modemCallbackSettings;
  634. rc = WtsUserSetProperty(domctrl,username,WTSUserConfigModemCallbackSettings,(LPWSTR)&pInfo->modemCallbackSettings,lenProperty);
  635. if ( rc )
  636. {
  637. // err.SysMsgWrite(ErrE,rc,"Failed to update %s property for %ls, rc=%ld ","ModemCallbackSettings",username,rc);
  638. break;
  639. }
  640. }
  641. if ( fieldmask & FM_WtsUser_shadowingSettings )
  642. {
  643. lenProperty = sizeof pInfo->shadowingSettings;
  644. rc = WtsUserSetProperty(domctrl,username,WTSUserConfigShadowingSettings,(LPWSTR)&pInfo->shadowingSettings,lenProperty);
  645. if ( rc )
  646. {
  647. // err.SysMsgWrite(ErrE,rc,"Failed to update %s property for %ls, rc=%ld ","ShadowingSettings",username,rc);
  648. break;
  649. }
  650. }
  651. if ( fieldmask & FM_WtsUser_terminalServerRemoteHomeDir )
  652. {
  653. // This property is updated automatically when the HomeDirDrive is set
  654. //lenProperty = sizeof pInfo->terminalServerRemoteHomeDir;
  655. //rc = WtsUserSetProperty(domctrl,username,WTSUserConfigfTerminalServerRemoteHomeDir,(LPWSTR)&pInfo->terminalServerRemoteHomeDir,lenProperty);
  656. //if ( rc )
  657. //{
  658. // err.SysMsgWrite(ErrE,rc,"Failed to update %s property for %ls, rc=%ld ","TerminalServerRemoteHomeDir",username,rc );
  659. // break;
  660. //}
  661. }
  662. if ( fieldmask & FM_WtsUser_initialProgram )
  663. {
  664. MCSASSERT(DIM(pInfo->initialProgram) <= DIM(property));
  665. lenProperty = ( UStrLen(pInfo->initialProgram) + 1) * sizeof WCHAR;
  666. safecopy(property,pInfo->initialProgram);
  667. rc = WtsUserSetProperty(domctrl,username,WTSUserConfigInitialProgram,property,lenProperty);
  668. if ( rc )
  669. {
  670. // err.SysMsgWrite(ErrE,rc,"Failed to update %s property for %ls, rc=%ld ","InitialProgram",username,rc);
  671. break;
  672. }
  673. }
  674. if ( fieldmask & FM_WtsUser_workingDirectory )
  675. {
  676. MCSASSERT(DIM(pInfo->workingDirectory) <= DIM(property));
  677. lenProperty = ( UStrLen(pInfo->workingDirectory) + 1) * sizeof WCHAR;
  678. safecopy(property,pInfo->workingDirectory);
  679. rc = WtsUserSetProperty(domctrl,username,WTSUserConfigWorkingDirectory,property,lenProperty);
  680. if ( rc )
  681. {
  682. // err.SysMsgWrite(ErrE,rc,"Failed to update %s property for %ls, rc=%ld ","WorkingDirectory",username,rc);
  683. break;
  684. }
  685. }
  686. if ( fieldmask & FM_WtsUser_modemCallbackPhoneNumber )
  687. {
  688. MCSASSERT(DIM(pInfo->modemCallbackPhoneNumber) <= DIM(property));
  689. lenProperty = ( UStrLen(pInfo->modemCallbackPhoneNumber) + 1) * sizeof WCHAR;
  690. safecopy(property,pInfo->modemCallbackPhoneNumber);
  691. rc = WtsUserSetProperty(domctrl,username,WTSUserConfigModemCallbackPhoneNumber,property,lenProperty);
  692. if ( rc )
  693. {
  694. // err.SysMsgWrite(ErrE,rc,"Failed to update %s property for %ls, rc=%ld ","ModemCallbackPhoneNumber",username,rc);
  695. break;
  696. }
  697. }
  698. if ( fieldmask & FM_WtsUser_terminalServerProfilePath )
  699. {
  700. MCSASSERT(DIM(pInfo->terminalServerProfilePath) <= DIM(property));
  701. lenProperty = ( UStrLen(pInfo->terminalServerProfilePath) + 1) * sizeof WCHAR;
  702. safecopy(property,pInfo->terminalServerProfilePath);
  703. rc = WtsUserSetProperty(domctrl,username,WTSUserConfigTerminalServerProfilePath,property,lenProperty);
  704. if ( rc )
  705. {
  706. // err.SysMsgWrite(ErrE,rc,"Failed to update %s property for %ls, rc=%ld ","TerminalServerProfilePath",username,rc);
  707. break;
  708. }
  709. }
  710. if ( fieldmask & FM_WtsUser_terminalServerHomeDir )
  711. {
  712. MCSASSERT(DIM(pInfo->terminalServerHomeDir) <= DIM(property));
  713. lenProperty = ( UStrLen(pInfo->terminalServerHomeDir) + 1) * sizeof WCHAR;
  714. safecopy(property,pInfo->terminalServerHomeDir);
  715. rc = WtsUserSetProperty(domctrl,username,WTSUserConfigTerminalServerHomeDir,property,lenProperty);
  716. if ( rc )
  717. {
  718. // err.SysMsgWrite(ErrE,rc,"Failed to update %s property for %ls, rc=%ld ","TerminalServerHomeDir",username,rc);
  719. break;
  720. }
  721. }
  722. if ( fieldmask & FM_WtsUser_terminalServerHomeDirDrive )
  723. {
  724. MCSASSERT(DIM(pInfo->terminalServerHomeDirDrive) <= DIM(property));
  725. lenProperty = ( UStrLen(pInfo->terminalServerHomeDirDrive) + 1) * sizeof WCHAR;
  726. safecopy(property,pInfo->terminalServerHomeDirDrive);
  727. rc = WtsUserSetProperty(domctrl,username,WTSUserConfigTerminalServerHomeDirDrive,property,lenProperty);
  728. if ( rc )
  729. {
  730. // err.SysMsgWrite(ErrE,rc,"Failed to update %s property for %ls, rc=%ld ","TerminalServerHomeDirDrive",username,rc);
  731. break;
  732. }
  733. }
  734. } while (FALSE);
  735. return rc;
  736. }
  737. DWORD // ret- 0 or OS return code
  738. LoadWtsDLL(
  739. BOOL bSilent // in - FALSE logs error messages, TRUE does not (default=TRUE)
  740. )
  741. {
  742. DWORD rc = 0;
  743. bSilent = ( ( gflDebug & EaxDebugFl_Wts) == 0);
  744. if ( ! gWtsDll.IsLoaded() )
  745. {
  746. rc = gWtsDll.Open(WTS_DLL_NAME);
  747. if ( rc )
  748. {
  749. // if ( ! bSilent )
  750. // err.SysMsgWrite(ErrE,rc,"The EA Server could not load %ls. This DLL is needed for Windows Terminal Server suppport. ",WTS_DLL_NAME);
  751. }
  752. else
  753. {
  754. // Get the entry points we need
  755. do { // once
  756. rc = gWtsDll.Access(WTS_QUERY_FUNCTION_NAME,(FARPROC *)&gpWtsQueryUserConfig);
  757. if ( rc )
  758. {
  759. // if ( ! bSilent)
  760. // err.SysMsgWrite(ErrE,rc,"%ls does not contain the entry point %s, rc=%ld ",WTS_DLL_NAME,WTS_QUERY_FUNCTION_NAME);
  761. break;
  762. }
  763. rc = gWtsDll.Access(WTS_SET_FUNCTION_NAME,(FARPROC *)&gpWtsSetUserConfig);
  764. if ( rc )
  765. {
  766. // if (! bSilent)
  767. // err.SysMsgWrite(ErrE,rc,"%ls does not contain the entry point %s, rc=%ld ",WTS_DLL_NAME,WTS_SET_FUNCTION_NAME);
  768. break;
  769. }
  770. rc = gWtsDll.Access(WTS_FREE_FUNCTION_NAME,(FARPROC *)&gpWtsFreeMemory);
  771. if ( rc )
  772. {
  773. // if ( ! bSilent)
  774. // err.SysMsgWrite(ErrE,rc,"%ls does not contain the entry point %s, rc=%ld ",WTS_DLL_NAME,WTS_FREE_FUNCTION_NAME);
  775. break;
  776. }
  777. rc = gWtsDll.Access(WTS_OPEN_SERVER_FUNCTION_NAME, (FARPROC *)&gpWtsOpenServer);
  778. if ( rc )
  779. {
  780. // if ( ! bSilent)
  781. // err.SysMsgWrite(ErrE,rc,"%ls does not contain the entry point %s, rc=%ld ",WTS_DLL_NAME,WTS_OPEN_SERVER_FUNCTION_NAME);
  782. break;
  783. }
  784. rc = gWtsDll.Access(WTS_CLOSE_SERVER_FUNCTION_NAME, (FARPROC *)&gpWtsCloseServer);
  785. if ( rc )
  786. {
  787. // if ( ! bSilent)
  788. // err.SysMsgWrite(ErrE,rc,"%ls does not contain the entry point %s, rc=%ld ",WTS_DLL_NAME,WTS_CLOSE_SERVER_FUNCTION_NAME);
  789. break;
  790. }
  791. } while ( false ); // end - do once
  792. if ( rc )
  793. {
  794. gWtsDll.Close();
  795. // Set all the function pointers to 0.
  796. gpWtsQueryUserConfig = NULL;
  797. gpWtsSetUserConfig = NULL;
  798. gpWtsFreeMemory = NULL;
  799. gpWtsOpenServer = NULL;
  800. gpWtsCloseServer = NULL;
  801. }
  802. }
  803. if ( rc )
  804. {
  805. if ( gflDebug & EaxDebugFl_Wts )
  806. {
  807. // err.SysMsgWrite( ErrW, rc, "WTSAPI32.DLL not loaded, rc=%ld, WTS support is disabled. ",rc);
  808. }
  809. }
  810. }
  811. return rc;
  812. }