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.

385 lines
14 KiB

  1. /*************************************************************************
  2. *
  3. * setuinfo.c
  4. *
  5. * Sets user logon information.
  6. *
  7. * Copyright Microsoft Corporation, 1998
  8. *
  9. *
  10. *************************************************************************/
  11. #include "precomp.h"
  12. #include "tsremdsk.h"
  13. #pragma hdrstop
  14. // global vars
  15. extern POLICY_TS_MACHINE g_MachinePolicy;
  16. /*****************************************************************************
  17. *
  18. * MergeUserConfigData
  19. *
  20. * This is the final step in updating a Winstation's USERCONFIG data, which is the final merge of
  21. * settings from 5 different sources of data, in the following precedence where top most has the highest
  22. * precedence overriding all below it:
  23. * Machine Policy
  24. * User Policy
  25. * TSCC
  26. * TsUserEx
  27. * Client preference settings
  28. *
  29. * By the time this call is made, the Client preference and TsUserEX data is already merged, where
  30. * the result of that merge is in pWinstation's USERCONFIGW struct.
  31. *
  32. * The final call happens when user has logged in, and user policy data is present. When this func is called from
  33. * RpcWinStationUpdateUserConfig, any user policy data that is not already overriden by machine policy will be
  34. * set in USERCONFIG.
  35. *
  36. * The User policy has the following items which ARE repeated in Machine policy, and hence, Machine Policy takes precedence
  37. * Remote Control Settings ( SHADOW)
  38. * Start up program
  39. * Session time out:
  40. * time out for disconnected session
  41. * time limit for active session
  42. * time limit for idle session
  43. * allow reconnect from oirginal client only
  44. * terminate session when time limits are reaced (instead of disconnect).
  45. *
  46. * None of the session-time-out and start-up-program USER policies are relevant to
  47. * sesion 0, or any session that is physically connected on the console.
  48. *
  49. * ENTRY:
  50. * pWinStation
  51. * Pointer to WINSTATION structure
  52. * pPolicy
  53. * TS user policy flags, could be NULL
  54. * pPolicyData
  55. * policy data if pPolicy is not NULL, otherwise, can be NULL
  56. * pUserConfig
  57. * Pointer to USERCONFIG structure, can be NULL if pWinstation already has user conifig data from SAM
  58. *
  59. * EXIT:
  60. * STATUS_SUCCESS - no error
  61. *
  62. * USAGE
  63. * fn( pWinstation, NULL, NULL, pUserConfig) will do a legacy merge of user data into pWinstation.
  64. * Legacy merge means that data set by TSCC could override user data.
  65. *
  66. * fn( pWinstation, pPolicy, pPolicyData, NULL ) would override pWinstation data of user by per user data
  67. * from group policy
  68. *
  69. ****************************************************************************/
  70. VOID
  71. MergeUserConfigData( PWINSTATION pWinStation,
  72. PPOLICY_TS_USER pPolicy,
  73. PUSERCONFIGW pPolicyData,
  74. PUSERCONFIG pUserConfig )
  75. {
  76. PUSERCONFIG pWSConfig;
  77. PPOLICY_TS_MACHINE pMachinePolicy;
  78. BOOLEAN dontApplySomePolicy ;
  79. BOOL bValidHelpSessionLogin;
  80. pWSConfig = & pWinStation->Config.Config.User;
  81. pMachinePolicy = & g_MachinePolicy;
  82. // active console ID is the ID of the session that is physically connected to the real video drivers at this time.
  83. dontApplySomePolicy = ( pWinStation->LogonId == 0 ) || (pWinStation->LogonId == (USER_SHARED_DATA->ActiveConsoleId) );
  84. // None of the session-time-out and start-up-program USER policies are relevant to
  85. // sesion 0, or any session that is physically connected on the console.
  86. if (! dontApplySomePolicy )
  87. {
  88. // if sessions0, or if sessions is the phisical console, then we do not want to apply certain policies at all.
  89. if ( ! pMachinePolicy->fPolicyInitialProgram ) // if we don't have a machine policy for this, then it is ok to use User policy
  90. {
  91. if ( pPolicy && pPolicy->fPolicyInitialProgram )
  92. {
  93. wcscpy( pWSConfig->InitialProgram, pPolicyData->InitialProgram );
  94. wcscpy( pWSConfig->WorkDirectory, pPolicyData->WorkDirectory );
  95. pWSConfig->fInheritInitialProgram = FALSE;
  96. }
  97. else if (pUserConfig)
  98. {
  99. /*
  100. * Use initial program/working directory from user config if WinStation
  101. * config says inherit and user config does NOT say inherit from client.
  102. */
  103. if ( pWSConfig->fInheritInitialProgram &&
  104. !pUserConfig->fInheritInitialProgram ) {
  105. /*
  106. * Always copy the user config info in this case, plugs security hole.
  107. */
  108. wcsncpy( pWSConfig->InitialProgram, pUserConfig->InitialProgram, INITIALPROGRAM_LENGTH );
  109. wcsncpy( pWSConfig->WorkDirectory, pUserConfig->WorkDirectory, DIRECTORY_LENGTH );
  110. }
  111. }
  112. }
  113. if ( ! pMachinePolicy->fPolicyResetBroken ) // if we don't have a machine policy for this, then it is ok to use User policy
  114. {
  115. if ( pPolicy && pPolicy->fPolicyResetBroken )
  116. {
  117. pWSConfig->fResetBroken = pPolicyData->fResetBroken;
  118. pWSConfig->fInheritResetBroken = FALSE;
  119. }
  120. else if (pUserConfig)
  121. {
  122. if ( pWSConfig->fInheritResetBroken )
  123. pWSConfig->fResetBroken = pUserConfig->fResetBroken;
  124. }
  125. }
  126. // ----------------------------------------------
  127. if ( ! pMachinePolicy->fPolicyReconnectSame ) // if we don't have a machine policy for this, then it is ok to use User policy
  128. {
  129. if ( pPolicy && pPolicy->fPolicyReconnectSame )
  130. {
  131. pWSConfig->fReconnectSame = pPolicyData->fReconnectSame;
  132. pWSConfig->fInheritReconnectSame = FALSE;
  133. }
  134. else if (pUserConfig)
  135. {
  136. if ( pWSConfig->fInheritReconnectSame )
  137. pWSConfig->fReconnectSame = pUserConfig->fReconnectSame;
  138. }
  139. }
  140. // ----------------------------------------------
  141. if ( ! pMachinePolicy->fPolicyMaxSessionTime ) // if we don't have a machine policy for this, then it is ok to use User policy
  142. {
  143. if ( pPolicy && pPolicy->fPolicyMaxSessionTime )
  144. {
  145. pWSConfig->MaxConnectionTime = pPolicyData->MaxConnectionTime;
  146. pWSConfig->fInheritMaxSessionTime = FALSE;
  147. }
  148. else if (pUserConfig)
  149. {
  150. if ( pWSConfig->fInheritMaxSessionTime )
  151. pWSConfig->MaxConnectionTime = pUserConfig->MaxConnectionTime;
  152. }
  153. }
  154. // ----------------------------------------------
  155. if ( ! pMachinePolicy->fPolicyMaxDisconnectionTime ) // if we don't have a machine policy for this, then it is ok to use User policy
  156. {
  157. if ( pPolicy && pPolicy->fPolicyMaxDisconnectionTime )
  158. {
  159. pWSConfig->MaxDisconnectionTime = pPolicyData->MaxDisconnectionTime;
  160. pWSConfig->fInheritMaxDisconnectionTime = FALSE;
  161. }
  162. else if (pUserConfig)
  163. {
  164. if ( pWSConfig->fInheritMaxDisconnectionTime )
  165. pWSConfig->MaxDisconnectionTime = pUserConfig->MaxDisconnectionTime;
  166. }
  167. }
  168. // ----------------------------------------------
  169. if ( ! pMachinePolicy->fPolicyMaxIdleTime ) // if we don't have a machine policy for this, then it is ok to use User policy
  170. {
  171. if ( pPolicy && pPolicy->fPolicyMaxIdleTime )
  172. {
  173. pWSConfig->MaxIdleTime = pPolicyData->MaxIdleTime;
  174. pWSConfig->fInheritMaxIdleTime = FALSE;
  175. }
  176. else if (pUserConfig)
  177. {
  178. if ( pWSConfig->fInheritMaxIdleTime )
  179. pWSConfig->MaxIdleTime = pUserConfig->MaxIdleTime;
  180. }
  181. }
  182. }
  183. // ----------------------------------------------
  184. if ( ! pMachinePolicy->fPolicyShadow ) // if we don't have a machine policy for this, then it is ok to use User policy
  185. {
  186. if ( pPolicy && pPolicy->fPolicyShadow )
  187. {
  188. pWSConfig->Shadow = pPolicyData->Shadow;
  189. pWSConfig->fInheritShadow = FALSE;
  190. }
  191. else if (pUserConfig)
  192. {
  193. if ( pWSConfig->fInheritShadow )
  194. pWSConfig->Shadow = pUserConfig->Shadow;
  195. }
  196. }
  197. // ----------------------------------------------
  198. // we don't have a machine policy for this item, which does not even have a UI for user policy...
  199. // if ( ! pMachinePolicy->fPolicyCallback )
  200. //
  201. {
  202. if ( pPolicy && pPolicy->fPolicyCallback )
  203. {
  204. pWSConfig->Callback = pPolicyData->Callback;
  205. pWSConfig->fInheritCallback = FALSE;
  206. }
  207. else if (pUserConfig)
  208. {
  209. if ( pWSConfig->fInheritCallback )
  210. pWSConfig->Callback = pUserConfig->Callback;
  211. }
  212. }
  213. // ----------------------------------------------
  214. // we don't have a machine policy for this item, which does not even have a UI for user policy...
  215. // if ( ! pMachinePolicy->fPolicyCallbackNumber )
  216. //
  217. {
  218. if ( pPolicy && pPolicy->fPolicyCallbackNumber )
  219. {
  220. wcscpy( pWSConfig->CallbackNumber, pPolicyData->CallbackNumber );
  221. pWSConfig->fInheritCallbackNumber = FALSE;
  222. }
  223. else if (pUserConfig)
  224. {
  225. if ( pWSConfig->fInheritCallbackNumber )
  226. wcsncpy( pWSConfig->CallbackNumber, pUserConfig->CallbackNumber, CALLBACK_LENGTH );
  227. }
  228. }
  229. // ----------------------------------------------
  230. // we don't have a machine policy for this item. Policy forces a state, does not configure a preferance.
  231. // if ( ! pMachinePolicy->fPolicyAutoClientDrives )
  232. //
  233. {
  234. if ( pPolicy && pPolicy->fPolicyAutoClientDrives)
  235. {
  236. pWSConfig->fAutoClientDrives = pPolicyData->fAutoClientDrives;
  237. // In case other items such as
  238. // lpt or def-printer are set to be inherited, such an
  239. // inheritance of bits would continue for those items
  240. // pWSConfig->fInheritAutoClient = FALSE;
  241. //
  242. }
  243. else if (pUserConfig)
  244. {
  245. if ( pWSConfig->fInheritAutoClient )
  246. {
  247. pWSConfig->fAutoClientDrives = pUserConfig->fAutoClientDrives;
  248. }
  249. }
  250. }
  251. // ----------------------------------------------
  252. // we don't have a machine policy for this item. Policy forces a state, does not configure a preferance.
  253. // if ( ! pMachinePolicy->fPolicyAutoClientLpts )
  254. //
  255. {
  256. if ( pPolicy && pPolicy->fPolicyAutoClientLpts )
  257. {
  258. pWSConfig->fAutoClientLpts = pPolicyData->fAutoClientLpts;
  259. }
  260. else if (pUserConfig)
  261. {
  262. if (pWSConfig->fInheritAutoClient)
  263. {
  264. pWSConfig->fAutoClientLpts = pUserConfig->fAutoClientLpts;
  265. }
  266. }
  267. }
  268. // ----------------------------------------------
  269. if ( ! pMachinePolicy->fPolicyForceClientLptDef) // if we don't have a machine policy for this, then it is ok to use User policy
  270. {
  271. if ( pPolicy && pPolicy->fPolicyForceClientLptDef )
  272. {
  273. pWSConfig->fForceClientLptDef = pPolicyData->fForceClientLptDef;
  274. }
  275. else if (pUserConfig)
  276. {
  277. if ( pWSConfig->fInheritAutoClient )
  278. {
  279. pWSConfig->fForceClientLptDef = pUserConfig->fForceClientLptDef;
  280. }
  281. }
  282. }
  283. if( TSIsSessionHelpSession( pWinStation, &bValidHelpSessionLogin ) )
  284. {
  285. // We disconnected RA if ticket is invalid.
  286. ASSERT( TRUE == bValidHelpSessionLogin );
  287. // Reset initial program.
  288. pWSConfig->fInheritInitialProgram = FALSE;
  289. //
  290. // our string is still less than 256 (INITIALPROGRAM_LENGTH),
  291. // need to revisit this if ever increase ticket ID and password length
  292. //
  293. _snwprintf(
  294. pWSConfig->InitialProgram,
  295. INITIALPROGRAM_LENGTH,
  296. L"%s %s",
  297. SALEMRDSADDINNAME,
  298. pWinStation->Client.WorkDirectory
  299. );
  300. pWSConfig->WorkDirectory[0] = 0;
  301. // reset winstation when connection is broken
  302. pWSConfig->fInheritResetBroken = FALSE;
  303. pWSConfig->fResetBroken = TRUE;
  304. //
  305. // No re-direction
  306. //
  307. pWSConfig->fInheritAutoClient = FALSE;
  308. pWSConfig->fAutoClientDrives = FALSE;
  309. pWSConfig->fAutoClientLpts = FALSE;
  310. pWSConfig->fForceClientLptDef = FALSE;
  311. }
  312. // Cache the original shadow setting so we can reset shadow setting
  313. // at the end of shadow call, we don't to look it up from registry again
  314. // as winstion shadow setting might change, in addition, a common
  315. // winstation configuration for more than one NIC might get split
  316. // into different winstation, in that case, we will spend a lot time
  317. // figure out which winstation to use.
  318. // We do this here to pick up new value from RpcWinStationUpdateUserConfig
  319. //
  320. pWinStation->OriginalShadowClass = pWSConfig->Shadow;
  321. }
  322. /*****************************************************************************
  323. *
  324. * ResetUserConfigData
  325. *
  326. * ENTRY:
  327. * pWinStation
  328. * Pointer to WINSTATION structure
  329. *
  330. *
  331. * EXIT:
  332. * STATUS_SUCCESS - no error
  333. *
  334. ****************************************************************************/
  335. VOID
  336. ResetUserConfigData( PWINSTATION pWinStation )
  337. {
  338. PUSERCONFIG pWSConfig = &pWinStation->Config.Config.User;
  339. if ( pWSConfig->fInheritInitialProgram ) {
  340. pWSConfig->InitialProgram[0] = 0;
  341. pWSConfig->WorkDirectory[0] = 0;
  342. }
  343. }