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.

796 lines
27 KiB

  1. /****************************************************************************/
  2. // icasrv.h
  3. //
  4. // TermSrv types, data, prototypes.
  5. //
  6. // Copyright (C) 1997-2000 Microsoft Corporation
  7. /****************************************************************************/
  8. #include <tssd.h>
  9. #include <tssec.h>
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. #define STR_CITRIX_IDLE_TITLE 249
  14. #define STR_CITRIX_IDLE_MSG_LOGOFF 250
  15. #define STR_CITRIX_LOGON_TITLE 251
  16. #define STR_CITRIX_LOGON_MSG_LOGOFF 252
  17. #define STR_CITRIX_SHADOW_TITLE 253
  18. #define STR_CITRIX_SHADOW_MSG_1 254
  19. #define STR_CITRIX_SHADOW_MSG_2 255
  20. #define STR_TEMP_LICENSE_EXPIRED_MSG 257
  21. #define STR_TEMP_LICENSE_EXPIRATION_MSG 258
  22. #define STR_TEMP_LICENSE_MSG_TITLE 259
  23. #define STR_ALL_LAN_ADAPTERS 260
  24. #define STR_CANNOT_ALLOW_CONCURRENT_MSG 261
  25. #define STR_CITRIX_IDLE_MSG_DISCON 262
  26. #define STR_CITRIX_LOGON_MSG_DISCON 263
  27. #define STR_FUS_REMOTE_DISCONNECT_TITLE 264
  28. #define STR_FUS_REMOTE_DISCONNECT_MSG 265
  29. /*
  30. * Resource definitions for the Licensing Core.
  31. */
  32. #define IDS_LSCORE_RA_NAME 1100
  33. #define IDS_LSCORE_RA_DESC 1101
  34. #define IDS_LSCORE_PERSEAT_NAME 1200
  35. #define IDS_LSCORE_PERSEAT_DESC 1201
  36. #define IDS_LSCORE_CONCURRENT_NAME 1300
  37. #define IDS_LSCORE_CONCURRENT_DESC 1301
  38. #define IDS_LSCORE_PERUSER_NAME 1302
  39. #define IDS_LSCORE_PERUSER_DESC 1303
  40. /*
  41. * defines for memory allocation
  42. */
  43. #define MemAlloc( _x ) RtlAllocateHeap( IcaHeap, 0, _x )
  44. #define MemFree( _p ) RtlFreeHeap( IcaHeap, 0, _p )
  45. /*
  46. * Prototype for reference lock delete procedure
  47. */
  48. typedef VOID (*PREFLOCKDELETEPROCEDURE)( struct _REFLOCK * );
  49. typedef struct _WINSTATION *PWINSTATION;
  50. /*
  51. * Reference counted lock structure
  52. */
  53. typedef struct _REFLOCK {
  54. HANDLE Mutex; // mutex handle
  55. LONG RefCount; // reference count
  56. BOOLEAN Invalid; // containing struct no longer valid
  57. PREFLOCKDELETEPROCEDURE pDeleteProcedure; // pointer to delete procedure
  58. } REFLOCK, *PREFLOCK;
  59. /*
  60. * Structure used to get the exact credentials used for logon by the client
  61. * We use this to send back the notification to the client
  62. */
  63. typedef struct _CLIENTNOTIFICATIONCREDENTIALS {
  64. WCHAR UserName[EXTENDED_USERNAME_LEN + 1];
  65. WCHAR Domain[EXTENDED_DOMAIN_LEN + 1] ;
  66. } CLIENTNOTIFICATIONCREDENTIALS, *PCLIENTNOTIFICATIONCREDENTIALS;
  67. //
  68. // Private contents of the autoreconnect cookie
  69. //
  70. typedef struct _AUTORECONNECTIONINFO {
  71. BOOLEAN Valid;
  72. BYTE ArcRandomBits[ARC_SC_SECURITY_TOKEN_LEN];
  73. } AUTORECONNECTIONINFO, *PAUTORECONNECTIONINFO;
  74. /*
  75. * Remembered Client address structure
  76. */
  77. typedef struct _REMEMBERED_CLIENT_ADDRESS{
  78. ULONG length;
  79. BYTE addr[1];
  80. } REMEMBERED_CLIENT_ADDRESS, *PREMEMBERED_CLIENT_ADDRESS;
  81. typedef enum _RECONNECT_TYPE {
  82. NeverReconnected = 0,
  83. ManualReconnect,
  84. AutoReconnect
  85. } RECONNECT_TYPE, *PRECONNECT_TYPE;
  86. /*
  87. * Session Manager WinStation struct
  88. */
  89. typedef struct _WINSTATION {
  90. LIST_ENTRY Links;
  91. BOOLEAN Starting; // WinStation is starting
  92. BOOLEAN Terminating; // WinStation is terminating
  93. BOOLEAN NeverConnected; // WinStation not connected yet
  94. REFLOCK Lock;
  95. ULONG LogonId; // Logon Id
  96. WINSTATIONNAME WinStationName; // WinStation Name
  97. WINSTATIONNAME ListenName; // Listen Name (for limits checking)
  98. WINSTATIONCONFIG2 Config; // WinStation Config
  99. WINSTATIONCLIENT Client; // WinStation client data
  100. ULONG State; // current state
  101. ULONG Flags; // WinStation Flags (see WSF_??? below)
  102. PVOID pSecurityDescriptor;
  103. HANDLE CreateEvent;
  104. NTSTATUS CreateStatus;
  105. HANDLE ConnectEvent;
  106. HANDLE hIca; // WinStation's primary Device
  107. HANDLE hStack; // WinStation's primary stack
  108. ULONG ShadowId;
  109. HANDLE hPassthruStack; // passthru (shadow client) stack
  110. HANDLE ShadowBrokenEvent;
  111. HANDLE ShadowDoneEvent;
  112. HANDLE ShadowDisplayChangeEvent;
  113. NTSTATUS ShadowTargetStatus;
  114. BOOLEAN ShadowConnectionWait;
  115. LIST_ENTRY ShadowHead; // head of shadow list
  116. HANDLE WindowsSubSysProcess; // process handle for Win32 SS (csrss)
  117. HANDLE WindowsSubSysProcessId; // process id for Win32 SS
  118. HANDLE InitialCommandProcess; // process handle for initial command
  119. HANDLE InitialCommandProcessId; // process id for initial command
  120. BOOLEAN InitialProcessSet; // Flag for console communication
  121. HANDLE CsrStartEventHandle; // Handle for CsrStartEvent
  122. HANDLE Win32CommandPort;
  123. PORT_MESSAGE Win32CommandPortMsg;
  124. LIST_ENTRY Win32CommandHead; // head of COMMAND_ENTRY list
  125. struct _LPC_CLIENT_CONTEXT *pWin32Context;
  126. PSID pUserSid; // SID for currently logged on user
  127. WCHAR Password[PASSWORD_LENGTH+1]; // password for currently logged on user
  128. UCHAR Seed; // seed for above password
  129. HANDLE UserToken; // User Token
  130. HANDLE hIdleTimer;
  131. HANDLE hLogonTimer;
  132. HANDLE hDisconnectTimer;
  133. ULONG fIdleTimer : 1;
  134. ULONG fLogonTimer : 1;
  135. ULONG fDisconnectTimer : 1;
  136. LARGE_INTEGER ConnectTime;
  137. LARGE_INTEGER DisconnectTime;
  138. LARGE_INTEGER LogonTime;
  139. WCHAR Domain[ DOMAIN_LENGTH + 1 ]; // Domain
  140. WCHAR UserName[USERNAME_LENGTH + 1]; // UserName
  141. BYTE VideoModuleName[9]; // For reconnect checking
  142. HANDLE hConnectThread; // Connect thread for this WinStation
  143. HANDLE hIcaBeepChannel;
  144. HANDLE hIcaThinwireChannel;
  145. PVOID pEndpoint;
  146. ULONG EndpointLength;
  147. struct _WSEXTENSION *pWsx;
  148. PVOID pWsxContext;
  149. BROKENCLASS BrokenReason; // reason/source why this WinStation..
  150. BROKENSOURCECLASS BrokenSource; // ..is being reset/disconnected
  151. ULONG StateFlags; // WinStation State (see WSF_ST_??? below)
  152. ULONG SessionSerialNumber; // Session Id is reused when session is deleted. Serial number not
  153. PSID pProfileSid; // SID for previously logged on user kept for profile cleanup
  154. BOOLEAN fOwnsConsoleTerminal; // session currently connected to the console
  155. WCHAR DisplayDriverName[9];
  156. WCHAR ProtocolName[9];
  157. LPARAM lpLicenseContext; // Licensing context for the winstation
  158. BOOLEAN fUserIsAdmin; // Needed for LLS licensing
  159. // Server pool (cluster) support - disconnected session query results
  160. // and client capabilities for this client.
  161. ULONG bClientSupportsRedirection : 1;
  162. ULONG bRequestedSessionIDFieldValid : 1;
  163. ULONG bClientRequireServerAddr : 1;
  164. UINT32 RequestedSessionID;
  165. unsigned NumClusterDiscSessions;
  166. TSSD_DisconnectedSessionInfo ClusterDiscSessions[TSSD_MaxDisconnectedSessions];
  167. HANDLE hWinmmConsoleAudioEvent; // Event that set if console audio is enabled remotely
  168. HANDLE hRDPAudioDisabledEvent; // Event that is set if remote audio is disabled for session 0, rdpsnd.dll is checking it
  169. // Support for longer UserName and Password during client autologon to a Terminal Server
  170. pExtendedClientCredentials pNewClientCredentials ;
  171. HANDLE hReconnectReadyEvent;
  172. // The following structure is used to send back the logon notification to the client
  173. PCLIENTNOTIFICATIONCREDENTIALS pNewNotificationCredentials;
  174. // Cache original shadow setting when session is created.
  175. // this is to fix a security hole created by Salem/pcHealth in that
  176. // pcHealth dynamically switch shadow to full control without
  177. // user permission and does not reset it, a normal
  178. // termination of Help will trigger Salem sessmgr to reset shadow
  179. // back to original setting, but a bad expert can stop sessmgr service
  180. // and our session's shadow setting will still be FULL CONTROL
  181. // WITHOUT USER PERMISSION, anyone with enough priviledge can then
  182. // start shadow and take control of this session .
  183. SHADOWCLASS OriginalShadowClass;
  184. //termsrv's cached cache statistics
  185. CACHE_STATISTICS Cache;
  186. PREMEMBERED_CLIENT_ADDRESS pRememberedAddress;
  187. PREMEMBERED_CLIENT_ADDRESS pLastClientAddress;
  188. BOOLEAN fReconnectPending; // Flag to indicate Reconnect is still Pending
  189. BOOLEAN fReconnectingToConsole; // Flag to indicate we r going to reconnect a session to the Console
  190. HANDLE SessionInitializedEvent; // Event which indicates winlogon is done creating desktop for this session
  191. AUTORECONNECTIONINFO AutoReconnectInfo;
  192. RECONNECT_TYPE LastReconnectType;
  193. BOOLEAN fDisallowAutoReconnect;
  194. WCHAR ExecSrvSystemPipe[EXECSRVPIPENAMELEN];
  195. BOOLEAN fSmartCardLogon; // Flag to indicate if a SmartCard was used to Logon to this session
  196. BOOLEAN fSDRedirectedSmartCardLogon; // Flag to indicate that this is gonna be a Session directory redirected AutoLogon
  197. } WINSTATION, *PWINSTATION;
  198. /*
  199. * WinStation Flags
  200. */
  201. #define WSF_CONNECT 0x00000001 // being connected
  202. #define WSF_DISCONNECT 0x00000002 // being disconnected
  203. #define WSF_RESET 0x00000004 // being reset
  204. #define WSF_DELETE 0x00000008 // being deleted
  205. #define WSF_DOWNPENDING 0x00000010 // down pending
  206. #define WSF_LOGOFF 0x00000020 // being logged off
  207. #define WSF_LISTEN 0x00000040 // this is a "listening" WinStation
  208. #define WSF_IDLE 0x00000080 // part of the idle pool
  209. #define WSF_IDLEBUSY 0x00000100 // idle but in process of connecting
  210. #define WSF_AUTORECONNECTING 0x00000200 // autoreconnecting
  211. /*
  212. * WinStation State Flags
  213. */
  214. #define WSF_ST_WINSTATIONTERMINATE 0x00000001 //Called WinstationTerminate for this session
  215. #define WSF_ST_DELAYED_STACK_TERMINATE 0x00000002 //Need to delay stack termination till WinstationDeleProc()
  216. #define WSF_ST_BROKEN_CONNECTION 0x00000004 // received a broken connection indication
  217. #define WSF_ST_CONNECTED_TO_CSRSS 0x00000008 // Connected or reconnected to CSRSS
  218. #define WSF_ST_IN_DISCONNECT 0x00000010 // Disconnect processing is pending
  219. #define WSF_ST_LOGON_NOTIFIED 0x00000020 // Logon notification is received
  220. #define WSF_ST_SHADOW 0x00000200 // In shadow or waiting for user
  221. #define WSF_ST_LICENSING 0x00000400 // Postlogon licensing hapened.
  222. /*
  223. * Help Assistant Session flag.
  224. * 3 bits, winlogon, msgina, licensing query termsrv in different
  225. * phrase of logon, we don't want to make repeated call, and since
  226. * we can't be sure if a session is a help session until winlogon
  227. * actually logon a user, we need more than TRUE/FALSE bit.
  228. */
  229. #define WSF_ST_HELPSESSION_FLAGS 0xF0000000 // reserved flags.
  230. #define WSF_ST_HELPSESSION_NOTSURE 0x00000000 // No sure it is helpassistant session
  231. #define WSF_ST_HELPSESSION_NOTHELPSESSION 0x20000000 // Detemined not a helpassistant session
  232. #define WSF_ST_HELPSESSION_HELPSESSION 0x40000000 // Session is a helpassistant session
  233. #define WSF_ST_HELPSESSION_HELPSESSIONINVALID 0x80000000 // HelpAssistant logon but ticket is invalid
  234. /*
  235. * Reconnect struct
  236. *
  237. * This structure is used to store WinStation connection information.
  238. * This structure is transferred from one WinStation to another when
  239. * processing a reconnect.
  240. */
  241. typedef struct _RECONNECT_INFO {
  242. WINSTATIONNAME WinStationName; // WinStation Name
  243. WINSTATIONNAME ListenName; // WinStation Name
  244. WINSTATIONCONFIG2 Config; // Registry config data
  245. WINSTATIONCLIENT Client; // WinStation client data
  246. struct _WSEXTENSION *pWsx;
  247. PVOID pWsxContext;
  248. HANDLE hIca; // temp ICA device handle to connect
  249. // stack to while in disconnect state
  250. HANDLE hStack; // handle of stack being reconnected
  251. PVOID pEndpoint; // endpoint data for connection..
  252. ULONG EndpointLength; // ..being reconnected
  253. BOOLEAN fOwnsConsoleTerminal; // session currently connected to the console
  254. WCHAR DisplayDriverName[9];
  255. WCHAR ProtocolName[9];
  256. // The following structure is used to send back the logon notification to the client
  257. PCLIENTNOTIFICATIONCREDENTIALS pNotificationCredentials;
  258. PREMEMBERED_CLIENT_ADDRESS pRememberedAddress;
  259. } RECONNECT_INFO, *PRECONNECT_INFO;
  260. /*
  261. * Shadow entry
  262. * There is one of these for each shadow client,
  263. * linked from the target WinStation (ShadowHead).
  264. */
  265. typedef struct _SHADOW_INFO {
  266. LIST_ENTRY Links;
  267. HANDLE hStack;
  268. HANDLE hBrokenEvent;
  269. PVOID pEndpoint;
  270. ULONG EndpointLength;
  271. } SHADOW_INFO, *PSHADOW_INFO;
  272. /*
  273. * Command entry struct
  274. */
  275. typedef struct _COMMAND_ENTRY {
  276. LIST_ENTRY Links;
  277. HANDLE Event;
  278. struct _WINSTATION_APIMSG * pMsg;
  279. } COMMAND_ENTRY, *PCOMMAND_ENTRY;
  280. /*
  281. * Event wait structure
  282. */
  283. typedef struct _EVENT {
  284. LIST_ENTRY EventListEntry;
  285. HANDLE Event;
  286. BOOLEAN fWaiter;
  287. BOOLEAN fClosing;
  288. NTSTATUS WaitResult;
  289. ULONG EventMask;
  290. ULONG EventFlags;
  291. } EVENT, *PEVENT;
  292. /*
  293. * RPC client context structure
  294. */
  295. typedef struct _RPC_CLIENT_CONTEXT{
  296. PEVENT pWaitEvent;
  297. } RPC_CLIENT_CONTEXT, *PRPC_CLIENT_CONTEXT;
  298. /*
  299. * This structure is used to keep track of the client accessing the
  300. * LPC interfaces. This structure is pointed to by the CONTEXT value
  301. * that the NT LPC system maintains for us on a per communication port
  302. * basis.
  303. */
  304. typedef struct _LPC_CLIENT_CONTEXT {
  305. ULONG ClientLogonId;
  306. HANDLE CommunicationPort;
  307. ULONG AccessRights;
  308. PVOID ClientViewBase;
  309. PVOID ClientViewBounds;
  310. PVOID ViewBase;
  311. SIZE_T ViewSize;
  312. PVOID ViewRemoteBase;
  313. } LPC_CLIENT_CONTEXT, *PLPC_CLIENT_CONTEXT;
  314. typedef struct _LOAD_BALANCING_METRICS {
  315. BOOLEAN fInitialized;
  316. // Basic system information
  317. ULONG NumProcessors;
  318. ULONG PageSize;
  319. ULONG PhysicalPages;
  320. // Idle system values to remove base system usage
  321. ULONG BaselineFreePtes ;
  322. ULONG BaselinePagedPool;
  323. ULONG BaselineCommit;
  324. // Minimum usage values to prevent absurdly large estimates
  325. ULONG MinPtesPerUser;
  326. ULONG MinPagedPoolPerUser;
  327. ULONG MinCommitPerUser;
  328. // Live usage values derived from runtime data: totals
  329. ULONG PtesUsed;
  330. ULONG PagedPoolUsed;
  331. ULONG CommitUsed;
  332. // Live usage values derived from runtime data: per user
  333. ULONG AvgPtesPerUser;
  334. ULONG AvgPagedPoolPerUser;
  335. ULONG AvgCommitPerUser;
  336. // Raw and Estimated values for session capacity
  337. ULONG RemainingSessions;
  338. ULONG EstimatedSessions;
  339. // CPU utilization metrics
  340. ULONG AvgIdleCPU;
  341. LARGE_INTEGER TotalCPU;
  342. LARGE_INTEGER IdleCPU;
  343. } LOAD_BALANCING_METRICS, *PLOAD_BALANCING_METRICS;
  344. // TODO: Is there a better place to get this value from?
  345. //
  346. #define MAX_PROCESSORS 32
  347. // Minimum assumed resource usage per user
  348. //
  349. // TODO: Use these as registry defaults, but attempt to read from registry
  350. //
  351. // Floating point optimization: (Avg >> 1) == 0.50 (growth reservation)
  352. #define SimGrowthBias 1
  353. #define SimUserMinimum 5
  354. // DEW (34 threads) = 1434KB (PTE) + 649KB (PP) + 172KB (NPP)
  355. #define DEWAvgPtesPerUser 1434
  356. #define DEWAvgPagedPoolPerUser 649
  357. #define DEWAvgNonPagedPoolPerUser 172
  358. #define DEWCommitPerUser 3481
  359. // KW (65 threads) = 2812KB (PTE) + 987KB (PP) + 460KB (NPP)
  360. #define KWAvgPtesPerUser 2812
  361. #define KWAvgPagedPoolPerUser 987
  362. #define KWAvgNonPagedPoolPerUser 460
  363. #define KWCommitPerUser 7530
  364. #define SimAvgPtesPerUser DEWAvgPtesPerUser
  365. #define SimAvgPagedPoolPerUser DEWAvgPagedPoolPerUser
  366. #define SimAvgNonPagedPoolPerUser DEWAvgNonPagedPoolPerUser
  367. #define SimCommitPerUser DEWCommitPerUser
  368. /*
  369. * Global variables
  370. */
  371. extern BOOLEAN ShutdownInProgress;
  372. //extern BOOLEAN ShutdownTerminateNoWait;
  373. extern ULONG ShutDownFromSessionID;
  374. extern RTL_CRITICAL_SECTION WinStationListLock;
  375. extern RTL_CRITICAL_SECTION WinStationListenersLock;
  376. extern RTL_CRITICAL_SECTION TimerCritSec;
  377. extern LIST_ENTRY SystemEventHead;
  378. extern HANDLE hTrace;
  379. extern BOOL g_bPersonalTS;
  380. extern BOOL g_bAdvancedServer;
  381. extern BOOL g_bPersonalWks;
  382. extern BOOL gbServer;
  383. extern BOOL gbListenerOff;
  384. extern BOOLEAN g_fDenyTSConnectionsPolicy;
  385. extern BOOL g_PreAuthenticateClient;
  386. extern HANDLE hCleanupTimer;
  387. extern BOOL g_BlackListPolicy;
  388. extern LONG g_CleanupTimerOn;
  389. /*
  390. * Globals to support load balancing. Since this is queried frequently we can't
  391. * afford to lock the winstation list and count them up.
  392. */
  393. extern ULONG IdleWinStationPoolCount;
  394. extern ULONG WinStationTotalCount;
  395. extern ULONG WinStationDiscCount;
  396. extern LOAD_BALANCING_METRICS gLB;
  397. extern ExtendedClientCredentials g_MprNotifyInfo;
  398. /*
  399. * Function prototypes
  400. */
  401. NTSTATUS InitTermSrv(HKEY);
  402. void StartAllWinStations(HKEY);
  403. NTSTATUS CheckWinStationEnable(LPWSTR);
  404. NTSTATUS SetWinStationEnable(LPWSTR, ULONG);
  405. NTSTATUS
  406. LoadSubSystemsForWinStation(
  407. IN PWINSTATION pWinStation );
  408. VOID
  409. FreeWinStationLists(
  410. PWINSTATION pWinStation );
  411. NTSTATUS
  412. GetProcessLogonId(
  413. IN HANDLE Process,
  414. OUT PULONG pLogonId );
  415. NTSTATUS
  416. SetProcessLogonId(
  417. IN HANDLE Process,
  418. IN ULONG LogonId );
  419. PWINSTATION FindWinStationById( ULONG, BOOLEAN );
  420. PWINSTATION FindWinStationByName( LPWSTR, BOOLEAN );
  421. void IncrementReference(PWINSTATION pWinStation);
  422. BOOLEAN IsWinStationLockedByCaller( PWINSTATION );
  423. NTSTATUS QueueWinStationReset( IN ULONG LogonId );
  424. NTSTATUS QueueWinStationDisconnect( IN ULONG LogonId );
  425. VOID ResetGroupByListener( PWINSTATIONNAME );
  426. VOID NotifySystemEvent(ULONG);
  427. NTSTATUS WinStationOpenChannel(
  428. HANDLE IcaDevice,
  429. HANDLE ProcessHandle,
  430. CHANNELCLASS ChannelClass,
  431. PVIRTUALCHANNELNAME pVirtualName,
  432. PHANDLE pDupChannel);
  433. VOID InvalidateTerminateWaitList(VOID);
  434. #define UnlockWinStation( _p ) UnlockRefLock( &_p->Lock )
  435. #define RelockWinStation( _p ) RelockRefLock( &_p->Lock )
  436. #if DBG
  437. #define ReleaseWinStation( _p ) ReleaseRefLock( &_p->Lock ); \
  438. _p = NULL;
  439. #else
  440. #define ReleaseWinStation( _p ) ReleaseRefLock( &_p->Lock )
  441. #endif
  442. NTSTATUS InitRefLock( PREFLOCK, PREFLOCKDELETEPROCEDURE );
  443. BOOLEAN LockRefLock( PREFLOCK );
  444. VOID UnlockRefLock( PREFLOCK );
  445. BOOLEAN RelockRefLock( PREFLOCK );
  446. VOID ReleaseRefLock( PREFLOCK );
  447. VOID DeleteRefLock( PREFLOCK );
  448. #if DBG
  449. #define ENTERCRIT(_x) \
  450. { \
  451. ASSERT( (HANDLE)LongToHandle( GetCurrentThreadId() ) != (_x)->OwningThread ); \
  452. RtlEnterCriticalSection(_x); \
  453. }
  454. #define LEAVECRIT(_x) \
  455. { \
  456. ASSERT( (HANDLE)LongToHandle( GetCurrentThreadId() ) == (_x)->OwningThread ); \
  457. RtlLeaveCriticalSection(_x); \
  458. }
  459. #else
  460. #define ENTERCRIT(_x) RtlEnterCriticalSection(_x)
  461. #define LEAVECRIT(_x) RtlLeaveCriticalSection(_x)
  462. #endif
  463. NTSTATUS
  464. MakeUserGlobalPath(
  465. IN OUT PUNICODE_STRING Unicode,
  466. IN ULONG LogonId );
  467. NTSTATUS SendWinStationCommand( PWINSTATION, PWINSTATION_APIMSG, ULONG );
  468. NTSTATUS
  469. WsxStackIoControl(
  470. PVOID pContext,
  471. IN HANDLE pStack,
  472. IN ULONG IoControlCode,
  473. IN PVOID pInBuffer,
  474. IN ULONG InBufferSize,
  475. OUT PVOID pOutBuffer,
  476. IN ULONG OutBufferSize,
  477. OUT PULONG pBytesReturned );
  478. VOID MergeUserConfigData( PWINSTATION pWinStation,
  479. PPOLICY_TS_USER pPolicy,
  480. PUSERCONFIGW pPolicyData,
  481. PUSERCONFIG pUserConfig ) ;
  482. VOID StartLogonTimers( PWINSTATION );
  483. VOID ResetUserConfigData( PWINSTATION );
  484. LONG IcaTimerCreate( ULONG, HANDLE * );
  485. NTSTATUS IcaTimerStart( HANDLE, PVOID, PVOID, ULONG );
  486. BOOLEAN IcaTimerCancel( HANDLE );
  487. BOOLEAN IcaTimerClose( HANDLE );
  488. VOID InitializeTrace(IN PWINSTATION, IN BOOLEAN, OUT PICA_TRACE);
  489. void InitializeSystemTrace(HKEY);
  490. void GetSetSystemParameters(HKEY);
  491. NTSTATUS CdmConnect( ULONG, HANDLE );
  492. NTSTATUS CdmDisconnect( ULONG, HANDLE );
  493. VOID VirtualChannelSecurity( PWINSTATION );
  494. VOID
  495. WinstationUnloadProfile( PWINSTATION pWinStation);
  496. NTSTATUS
  497. WinStationResetWorker(
  498. ULONG LogonId,
  499. BOOLEAN bWait,
  500. BOOLEAN CallerIsRpc,
  501. BOOLEAN bRecreate
  502. );
  503. BOOL StartStopListeners( LPWSTR WinStationName, BOOLEAN bStart );
  504. NTSTATUS WinStationCreateWorker( PWINSTATIONNAME, PULONG, BOOLEAN );
  505. NTSTATUS ConsoleShadowStart( IN PWINSTATION pWinStation,
  506. IN PWINSTATIONCONFIG2 pClientConfig,
  507. IN PVOID pModuleData,
  508. IN ULONG ModuleDataLength);
  509. NTSTATUS ConsoleShadowStop(PWINSTATION pWinStation);
  510. NTSTATUS TransferConnectionToIdleWinStation(
  511. PWINSTATION pListenWinStation,
  512. PVOID pEndpoint,
  513. ULONG EndpointLength,
  514. PICA_STACK_ADDRESS pStackAddress );
  515. PWINSTATION
  516. GetWinStationFromArcInfo(
  517. PBYTE pClientRandom,
  518. LONG cbClientRandomLen,
  519. PTS_AUTORECONNECTINFO pArc
  520. );
  521. // Why doesn't the compiler complain that each source file is redefining
  522. // a global variable? This file _is_ included by all source files in this
  523. // directory. But these definitions will cause warnings if they show up
  524. // in the licensing core, so give the core the ability to ifdef them out.
  525. #ifndef LSCORE_NO_ICASRV_GLOBALS
  526. PVOID IcaHeap;
  527. PVOID DefaultEnvironment;
  528. HANDLE IcaSmApiPort;
  529. HANDLE hModuleWin;
  530. #endif
  531. #if DBG
  532. #define DBGPRINT(_arg) DbgPrint _arg
  533. #else
  534. #define DBGPRINT(_arg)
  535. #endif
  536. #if DBG
  537. #undef TRACE
  538. #define TRACE(_arg) { if (hTrace) IcaSystemTrace _arg; }
  539. #else
  540. #define TRACE(_arg)
  541. #endif
  542. /*=============================================================================
  543. == TermSrv Server Extension supplied procs
  544. =============================================================================*/
  545. /*
  546. * Macros
  547. */
  548. #define WSX_INITIALIZE "WsxInitialize"
  549. #define WSX_WINSTATIONINITIALIZE "WsxWinStationInitialize"
  550. #define WSX_WINSTATIONREINITIALIZE "WsxWinStationReInitialize"
  551. #define WSX_WINSTATIONRUNDOWN "WsxWinStationRundown"
  552. #define WSX_CDMCONNECT "WsxConnect"
  553. #define WSX_CDMDISCONNECT "WsxDisconnect"
  554. #define WSX_VERIFYCLIENTLICENSE "WsxVerifyClientLicense"
  555. #define WSX_QUERYLICENSE "WsxQueryLicense"
  556. #define WSX_GETLICENSE "WsxGetLicense"
  557. #define WSX_WINSTATIONLOGONANNOYANCE "WsxWinStationLogonAnnoyance"
  558. #define WSX_WINSTATIONGENERATELICENSE "WsxWinStationGenerateLicense"
  559. #define WSX_WINSTATIONINSTALLLICENSE "WsxWinStationInstallLicense"
  560. #define WSX_WINSTATIONENUMERATELICENSES "WsxWinStationEnumerateLicenses"
  561. #define WSX_WINSTATIONACTIVATELICENSE "WsxWinStationActivateLicense"
  562. #define WSX_WINSTATIONREMOVELICENSE "WsxWinStationRemoveLicense"
  563. #define WSX_WINSTATIONSETPOOLCOUNT "WsxWinStationSetPoolCount"
  564. #define WSX_WINSTATIONQUERYUPDATEREQUIRED "WsxWinStationQueryUpdateRequired"
  565. #define WSX_WINSTATIONANNOYANCETHREAD "WsxWinStationAnnoyanceThread"
  566. #define WSX_DUPLICATECONTEXT "WsxDuplicateContext"
  567. #define WSX_COPYCONTEXT "WsxCopyContext"
  568. #define WSX_CLEARCONTEXT "WsxClearContext"
  569. #define WSX_INITIALIZECLIENTDATA "WsxInitializeClientData"
  570. #define WSX_INITIALIZEUSERCONFIG "WsxInitializeUserConfig"
  571. #define WSX_CONVERTPUBLISHEDAPP "WsxConvertPublishedApp"
  572. #define WSX_VIRTUALCHANNELSECURITY "WsxVirtualChannelSecurity"
  573. #define WSX_ICASTACKIOCONTROL "WsxIcaStackIoControl"
  574. #define WSX_BROKENCONNECTION "WsxBrokenConnection"
  575. #define WSX_LOGONNOTIFY "WsxLogonNotify"
  576. #define WSX_SETERRORINFO "WsxSetErrorInfo"
  577. #define WSX_ESCAPE "WsxEscape"
  578. #define WSX_SENDAUTORECONNECTSTATUS "WsxSendAutoReconnectStatus"
  579. /*
  580. * Typedefs and structures
  581. */
  582. typedef struct _WSEXTENSION {
  583. LIST_ENTRY Links; // Links
  584. DLLNAME WsxDLL; // DLL name
  585. HANDLE hInstance; // Handle of the DLL
  586. PVOID Context; // Extension context data
  587. PWSX_INITIALIZE pWsxInitialize;
  588. PWSX_WINSTATIONINITIALIZE pWsxWinStationInitialize;
  589. PWSX_WINSTATIONREINITIALIZE pWsxWinStationReInitialize;
  590. PWSX_WINSTATIONRUNDOWN pWsxWinStationRundown;
  591. PWSX_CDMCONNECT pWsxCdmConnect;
  592. PWSX_CDMDISCONNECT pWsxCdmDisconnect;
  593. PWSX_VERIFYCLIENTLICENSE pWsxVerifyClientLicense;
  594. PWSX_QUERYLICENSE pWsxQueryLicense;
  595. PWSX_GETLICENSE pWsxGetLicense;
  596. PWSX_WINSTATIONLOGONANNOYANCE pWsxWinStationLogonAnnoyance;
  597. PWSX_WINSTATIONGENERATELICENSE pWsxWinStationGenerateLicense;
  598. PWSX_WINSTATIONINSTALLLICENSE pWsxWinStationInstallLicense;
  599. PWSX_WINSTATIONENUMERATELICENSES pWsxWinStationEnumerateLicenses;
  600. PWSX_WINSTATIONACTIVATELICENSE pWsxWinStationActivateLicense;
  601. PWSX_WINSTATIONREMOVELICENSE pWsxWinStationRemoveLicense;
  602. PWSX_WINSTATIONSETPOOLCOUNT pWsxWinStationSetPoolCount;
  603. PWSX_WINSTATIONQUERYUPDATEREQUIRED pWsxWinStationQueryUpdateRequired;
  604. PWSX_WINSTATIONANNOYANCETHREAD pWsxWinStationAnnoyanceThread;
  605. PWSX_DUPLICATECONTEXT pWsxDuplicateContext;
  606. PWSX_COPYCONTEXT pWsxCopyContext;
  607. PWSX_CLEARCONTEXT pWsxClearContext;
  608. PWSX_INITIALIZECLIENTDATA pWsxInitializeClientData;
  609. PWSX_INITIALIZEUSERCONFIG pWsxInitializeUserConfig;
  610. PWSX_CONVERTPUBLISHEDAPP pWsxConvertPublishedApp;
  611. PWSX_VIRTUALCHANNELSECURITY pWsxVirtualChannelSecurity;
  612. PWSX_ICASTACKIOCONTROL pWsxIcaStackIoControl;
  613. PWSX_BROKENCONNECTION pWsxBrokenConnection;
  614. PWSX_LOGONNOTIFY pWsxLogonNotify;
  615. PWSX_SETERRORINFO pWsxSetErrorInfo;
  616. PWSX_SENDAUTORECONNECTSTATUS pWsxSendAutoReconnectStatus;
  617. PWSX_ESCAPE pWsxEscape;
  618. } WSEXTENSION, * PWSEXTENSION;
  619. //
  620. // For disconnect / reconnect completion constants
  621. // Currently we wait 5000 milisecs (12*15) times,
  622. // which make a maximum total wait of 3 minutes.
  623. #define WINSTATION_WAIT_COMPLETE_DURATION 5000
  624. #define WINSTATION_WAIT_COMPLETE_RETRIES (12*15)
  625. // For disconnect completion constant when we do a reconnect
  626. // Currently we wait 2000 milisecs, (5*3) times,
  627. // which make a maximum total wait of 30 seconds
  628. #define WINSTATION_WAIT_DURATION 2000
  629. #define WINSTATION_WAIT_RETRIES (5*3)
  630. #ifdef __cplusplus
  631. }
  632. #endif