Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

server.c File Reference

#include "precomp.h"
#include "dbt.h"
#include "ntdddisk.h"
#include "ntuser.h"
#include <regstr.h>

Go to the source code of this file.

Defines

#define ID_NLS   0
#define ID_POWER   1
#define ID_MEDIACHANGE   2
#define ID_NETDEVCHANGE   3
#define ID_NUM_EVENTS   4
#define SC_BSM_EVENT_NAME   L"ScNetDrvMsg"

Typedefs

typedef BOOL(* PFNPROCESSCREATE )(DWORD, DWORD, ULONG_PTR, DWORD)

Functions

HANDLE CsrQueryApiPort (VOID)
ULONG SrvExitWindowsEx (IN OUT PCSR_API_MSG m, IN OUT PCSR_REPLY_STATUS ReplyStatus)
ULONG SrvEndTask (IN OUT PCSR_API_MSG m, IN OUT PCSR_REPLY_STATUS ReplyStatus)
ULONG SrvLogon (IN OUT PCSR_API_MSG m, IN OUT PCSR_REPLY_STATUS ReplyStatus)
ULONG SrvRegisterServicesProcess (IN OUT PCSR_API_MSG m, IN OUT PCSR_REPLY_STATUS ReplyStatus)
ULONG SrvActivateDebugger (IN OUT PCSR_API_MSG m, IN OUT PCSR_REPLY_STATUS ReplyStatus)
ULONG SrvGetThreadConsoleDesktop (IN OUT PCSR_API_MSG m, IN OUT PCSR_REPLY_STATUS ReplyStatus)
ULONG SrvDeviceEvent (IN OUT PCSR_API_MSG m, IN OUT PCSR_REPLY_STATUS ReplyStatus)
ULONG SrvRegisterLogonProcess (IN OUT PCSR_API_MSG m, IN OUT PCSR_REPLY_STATUS ReplyStatus)
ULONG SrvWin32HeapFail (IN OUT PCSR_API_MSG m, IN OUT PCSR_REPLY_STATUS ReplyStatus)
ULONG SrvWin32HeapStat (IN OUT PCSR_API_MSG m, IN OUT PCSR_REPLY_STATUS ReplyStatus)
NTSTATUS UserServerDllInitialization (PCSR_SERVER_DLL psrvdll)
NTSTATUS UserClientConnect (PCSR_PROCESS Process, PVOID ConnectionInformation, PULONG pulConnectionLen)
VOID UserHardError (PCSR_THREAD pcsrt, PHARDERROR_MSG pmsg)
NTSTATUS UserClientShutdown (PCSR_PROCESS Process, ULONG dwFlags, BOOLEAN fFirstPass)
VOID GetTimeouts (VOID)
VOID StartRegReadRead (VOID)
VOID RegReadApcProcedure (PVOID RegReadApcContext, PIO_STATUS_BLOCK IoStatus)
VOID NotificationThread (PVOID)
VOID InitializeConsoleAttributes (VOID)
NTSTATUS GetThreadConsoleDesktop (DWORD dwThreadId, HDESK *phdesk)
NTSTATUS MyRegOpenKey (IN HANDLE hKey, IN LPWSTR lpSubKey, OUT PHANDLE phResult)
BOOL BaseSetProcessCreateNotify (PFNPROCESSCREATE pfn)
VOID BaseSrvNlsUpdateRegistryCache (PVOID ApcContext, PIO_STATUS_BLOCK pIoStatusBlock)
NTSTATUS BaseSrvNlsLogon (BOOL)
NTSTATUS WinStationAPIInit (VOID)
VOID HandleMediaChangeEvent (VOID)
DWORD GetNetworkDrives ()
VOID HandleRemoteNetDeviceChangeEvent ()
BOOL CreateBSMEventSD (PSECURITY_DESCRIPTOR *SecurityDescriptor)
UINT GetRegIntFromID (HKEY hKey, int KeyID, UINT nDefault)
BOOL CALLBACK FindWindowFromThread (HWND hwnd, LPARAM lParam)
DWORD GetRipComponent (VOID)
DWORD GetDbgTagFlags (int tag)
DWORD GetRipPID (VOID)
DWORD GetRipFlags (VOID)
VOID SetRipFlags (DWORD dwRipFlags, DWORD dwRipPID)
VOID SetDbgTag (int tag, DWORD dwBitFlags)
VOID UserRtlRaiseStatus (NTSTATUS Status)

Variables

HANDLE hThreadNotification
HANDLE hKeyPriority
UNICODE_STRING PriorityValueName
IO_STATUS_BLOCK IoStatusRegChange
ULONG RegChangeBuffer
HANDLE ghNlsEvent
BOOL gfLogon
FARPROC gpfnAttachRoutine
HANDLE ghPowerRequestEvent
HANDLE ghMediaRequestEvent
DWORD LastNetDrives
HANDLE CsrApiPort
PCSR_API_ROUTINE UserServerApiDispatchTable [UserpMaxApiNumber-UserpExitWindowsEx]
BOOLEAN UserServerApiServerValidTable [UserpMaxApiNumber-UserpExitWindowsEx]
WORD gDispatchTableValues
CONST ALWAYSZERO gZero


Define Documentation

#define ID_MEDIACHANGE   2
 

Definition at line 38 of file server/server.c.

Referenced by NotificationThread().

#define ID_NETDEVCHANGE   3
 

Definition at line 39 of file server/server.c.

Referenced by NotificationThread().

#define ID_NLS   0
 

Definition at line 36 of file server/server.c.

Referenced by NotificationThread().

#define ID_NUM_EVENTS   4
 

Definition at line 41 of file server/server.c.

Referenced by NotificationThread().

#define ID_POWER   1
 

Definition at line 37 of file server/server.c.

Referenced by NotificationThread().

#define SC_BSM_EVENT_NAME   L"ScNetDrvMsg"
 

Definition at line 46 of file server/server.c.

Referenced by NotificationThread().


Typedef Documentation

typedef BOOL(* PFNPROCESSCREATE)(DWORD, DWORD, ULONG_PTR, DWORD)
 

Definition at line 162 of file server/server.c.


Function Documentation

BOOL BaseSetProcessCreateNotify PFNPROCESSCREATE  pfn  ) 
 

Referenced by UserServerDllInitialization().

NTSTATUS BaseSrvNlsLogon BOOL   ) 
 

Referenced by SrvLogon().

VOID BaseSrvNlsUpdateRegistryCache PVOID  ApcContext,
PIO_STATUS_BLOCK  pIoStatusBlock
 

Referenced by NotificationThread().

BOOL CreateBSMEventSD PSECURITY_DESCRIPTOR *  SecurityDescriptor  ) 
 

Definition at line 705 of file server/server.c.

References BOOL, BYTE, FALSE, NT_SUCCESS, NTSTATUS(), NULL, RtlAddAccessAllowedAce(), RtlAllocateAndInitializeSid(), RtlCreateAcl(), RtlCreateSecurityDescriptor(), RtlFreeSid(), RtlLengthSid(), RtlSetDaclSecurityDescriptor(), Status, TRUE, and WorldSid.

Referenced by NotificationThread().

00710 : 00711 00712 This function creates a security descriptor for the BSM request event. 00713 It grants EVENT_ALL_ACCESS to local system and EVENT_MODIFY_STATE access 00714 to the rest of the world. This prevents principals other than local 00715 system from waiting for the event. 00716 00717 Arguments: 00718 00719 SecurityDescriptor - Receives a pointer to the new security descriptor. 00720 Should be freed with LocalFree. 00721 00722 Return Value: 00723 00724 TRUE - success 00725 00726 FALSE - failure, use GetLastError 00727 00728 00729 --*/ 00730 { 00731 NTSTATUS Status; 00732 ULONG AclLength; 00733 PACL EventDacl; 00734 PSID WorldSid = NULL; 00735 PSID SystemSid = NULL; 00736 SID_IDENTIFIER_AUTHORITY NtSidAuthority = SECURITY_NT_AUTHORITY; 00737 SID_IDENTIFIER_AUTHORITY WorldSidAuthority = SECURITY_WORLD_SID_AUTHORITY; 00738 BOOL retval = TRUE; 00739 00740 *SecurityDescriptor = NULL; 00741 00742 Status = RtlAllocateAndInitializeSid( &NtSidAuthority, 00743 1, 00744 SECURITY_LOCAL_SYSTEM_RID, 00745 0, 0, 0, 0, 0, 0, 0, 00746 &SystemSid ); 00747 00748 if (!NT_SUCCESS(Status)) { 00749 retval = FALSE; 00750 goto Cleanup; 00751 } 00752 00753 Status = RtlAllocateAndInitializeSid( &WorldSidAuthority, 00754 1, 00755 SECURITY_WORLD_RID, 00756 0, 0, 0, 0, 0, 0, 0, 00757 &WorldSid ); 00758 00759 if (!NT_SUCCESS(Status)) { 00760 retval = FALSE; 00761 goto Cleanup; 00762 } 00763 00764 00765 // 00766 // Allocate a buffer to contain the SD followed by the DACL 00767 // Note, the well-known SIDs are expected to have been created 00768 // by this time 00769 // 00770 00771 AclLength = (ULONG)sizeof(ACL) + 00772 (2*((ULONG)sizeof(ACCESS_ALLOWED_ACE))) + 00773 RtlLengthSid( SystemSid ) + 00774 RtlLengthSid( WorldSid ) + 00775 8; // 8 is for good measure 00776 00777 *SecurityDescriptor = (PSECURITY_DESCRIPTOR) 00778 LocalAlloc( 0, SECURITY_DESCRIPTOR_MIN_LENGTH + AclLength ); 00779 00780 if (*SecurityDescriptor == NULL) { 00781 retval = FALSE; 00782 goto Cleanup; 00783 } 00784 00785 EventDacl = (PACL) ((BYTE*)(*SecurityDescriptor) + SECURITY_DESCRIPTOR_MIN_LENGTH); 00786 00787 00788 // 00789 // Set up a default ACL 00790 // 00791 // Public: WORLD:EVENT_MODIFY_STATE, SYSTEM:all 00792 00793 Status = RtlCreateAcl( EventDacl, AclLength, ACL_REVISION2); 00794 if (!NT_SUCCESS(Status)) { 00795 retval = FALSE; 00796 goto Cleanup; 00797 } 00798 00799 00800 // 00801 // WORLD access 00802 // 00803 00804 Status = RtlAddAccessAllowedAce ( 00805 EventDacl, 00806 ACL_REVISION2, 00807 EVENT_MODIFY_STATE, 00808 WorldSid 00809 ); 00810 if (!NT_SUCCESS(Status)) { 00811 retval = FALSE; 00812 goto Cleanup; 00813 } 00814 00815 00816 // 00817 // SYSTEM access 00818 // 00819 00820 Status = RtlAddAccessAllowedAce ( 00821 EventDacl, 00822 ACL_REVISION2, 00823 EVENT_ALL_ACCESS, 00824 SystemSid 00825 ); 00826 if (!NT_SUCCESS(Status)) { 00827 retval = FALSE; 00828 goto Cleanup; 00829 } 00830 00831 00832 00833 // 00834 // Now initialize security descriptors 00835 // that export this protection 00836 // 00837 00838 Status = RtlCreateSecurityDescriptor( 00839 *SecurityDescriptor, 00840 SECURITY_DESCRIPTOR_REVISION1 00841 ); 00842 if (!NT_SUCCESS(Status)) { 00843 retval = FALSE; 00844 goto Cleanup; 00845 } 00846 00847 Status = RtlSetDaclSecurityDescriptor( 00848 *SecurityDescriptor, 00849 TRUE, // DaclPresent 00850 EventDacl, 00851 FALSE // DaclDefaulted 00852 ); 00853 00854 if (!NT_SUCCESS(Status)) { 00855 retval = FALSE; 00856 goto Cleanup; 00857 } 00858 00859 Cleanup: 00860 00861 if (WorldSid) { 00862 RtlFreeSid(WorldSid); 00863 } 00864 00865 if (SystemSid) { 00866 RtlFreeSid(SystemSid); 00867 } 00868 00869 if ((retval == FALSE) && (*SecurityDescriptor != NULL)) { 00870 LocalFree(*SecurityDescriptor); 00871 *SecurityDescriptor = NULL; 00872 } 00873 00874 00875 return retval; 00876 }

HANDLE CsrQueryApiPort VOID   ) 
 

BOOL CALLBACK FindWindowFromThread HWND  hwnd,
LPARAM  lParam
 

Definition at line 1255 of file server/server.c.

References BOOL, GetWindow(), NULL, and TRUE.

Referenced by BoostHardError(), GetHardErrorText(), and ThreadShutdownNotify().

01256 { 01257 BOOL fTopLevelOwner; 01258 #ifdef FE_IME 01259 if ( IsImeWindow(hwnd) ) { 01260 return TRUE; 01261 } 01262 #endif 01263 01264 fTopLevelOwner = (GetWindow(hwnd, GW_OWNER) == NULL); 01265 if ((*((HWND *)lParam) == NULL) || fTopLevelOwner) { 01266 *((HWND *)lParam) = hwnd; 01267 } 01268 return !fTopLevelOwner; 01269 }

DWORD GetDbgTagFlags int  tag  ) 
 

Definition at line 1273 of file server/server.c.

References DWORD.

01274 { 01275 return 0; 01276 UNREFERENCED_PARAMETER(tag); 01277 }

DWORD GetNetworkDrives  ) 
 

Definition at line 549 of file server/server.c.

References DWORD, NT_SUCCESS, NtQueryInformationProcess(), and NULL.

Referenced by HandleRemoteNetDeviceChangeEvent().

00553 : 00554 00555 Returns a drive bitmask similar to GetLogicalDrives, but including 00556 only the network drives. 00557 00558 Arguments: 00559 00560 Return Value: 00561 00562 00563 --*/ 00564 { 00565 DWORD Mask = 0; 00566 DWORD DriveNumber; 00567 PROCESS_DEVICEMAP_INFORMATION ProcessDeviceMapInfo; 00568 00569 if (NT_SUCCESS(NtQueryInformationProcess( NtCurrentProcess(), 00570 ProcessDeviceMap, 00571 &ProcessDeviceMapInfo.Query, 00572 sizeof( ProcessDeviceMapInfo.Query ), 00573 NULL 00574 ))) { 00575 // For all the drives from C to Z 00576 for (DriveNumber = 2; DriveNumber < 26; DriveNumber++) 00577 { 00578 if (ProcessDeviceMapInfo.Query.DriveType[DriveNumber] == DOSDEVICE_DRIVE_REMOTE) 00579 { 00580 Mask |= (1 << DriveNumber); 00581 } 00582 } 00583 } 00584 00585 return Mask; 00586 }

UINT GetRegIntFromID HKEY  hKey,
int  KeyID,
UINT  nDefault
 

Definition at line 1029 of file server/server.c.

References BOOL, BYTE, DWORD, FALSE, ghModuleWin, NT_SUCCESS, NtQueryValueKey(), NTSTATUS(), NULL, RtlInitUnicodeString(), RtlLoadStringOrError(), RtlUnicodeStringToInteger(), Status, and UINT.

Referenced by GetTimeouts().

01033 { 01034 LPWSTR lpszValue; 01035 BOOL fAllocated; 01036 UNICODE_STRING Value; 01037 DWORD cbSize; 01038 BYTE Buf[sizeof(KEY_VALUE_PARTIAL_INFORMATION) + 20 * sizeof(WCHAR)]; 01039 NTSTATUS Status; 01040 UINT ReturnValue; 01041 01042 lpszValue = (LPWSTR)RtlLoadStringOrError(ghModuleWin, 01043 KeyID, NULL, &fAllocated, FALSE); 01044 01045 RtlInitUnicodeString(&Value, lpszValue); 01046 Status = NtQueryValueKey(hKey, 01047 &Value, 01048 KeyValuePartialInformation, 01049 (PKEY_VALUE_PARTIAL_INFORMATION)Buf, 01050 sizeof(Buf), 01051 &cbSize); 01052 if (NT_SUCCESS(Status)) { 01053 01054 /* 01055 * Convert string to int. 01056 */ 01057 RtlInitUnicodeString(&Value, (LPWSTR)((PKEY_VALUE_PARTIAL_INFORMATION)Buf)->Data); 01058 RtlUnicodeStringToInteger(&Value, 10, &ReturnValue); 01059 } else { 01060 ReturnValue = nDefault; 01061 } 01062 01063 LocalFree(lpszValue); 01064 01065 return(ReturnValue); 01066 }

DWORD GetRipComponent VOID   ) 
 

Definition at line 1271 of file server/server.c.

References DWORD.

01271 { return RIP_USERSRV; }

DWORD GetRipFlags VOID   ) 
 

Definition at line 1280 of file server/server.c.

References DWORD, and gdwRIPFlags.

01280 { return gdwRIPFlags; }

DWORD GetRipPID VOID   ) 
 

Definition at line 1279 of file server/server.c.

References DWORD.

01279 { return 0; }

NTSTATUS GetThreadConsoleDesktop DWORD  dwThreadId,
HDESK *  phdesk
 

Definition at line 3139 of file server/private.c.

References CONSOLE_FROMTHREADPERPROCESSDATA, _CONSOLE_PER_PROCESS_DATA::ConsoleHandle, _CONSOLE_INFORMATION::hDesk, NT_SUCCESS, NTSTATUS(), NULL, PCONSOLE_PER_PROCESS_DATA, RevalidateConsole(), Status, and UnlockConsole().

Referenced by SrvGetThreadConsoleDesktop().

03142 { 03143 PCSR_THREAD pcsrt; 03144 PCONSOLE_PER_PROCESS_DATA ProcessData; 03145 PCONSOLE_INFORMATION Console; 03146 NTSTATUS Status; 03147 HANDLE ConsoleHandle = NULL; 03148 03149 *phdeskConsole = NULL; 03150 Status = CsrLockThreadByClientId((HANDLE)dwThreadId, &pcsrt); 03151 if (NT_SUCCESS(Status)) { 03152 ProcessData = CONSOLE_FROMTHREADPERPROCESSDATA(pcsrt); 03153 ConsoleHandle = ProcessData->ConsoleHandle; 03154 CsrUnlockThread(pcsrt); 03155 } 03156 03157 // 03158 // If this process is a console app, return the 03159 // handle to its desktop. Otherwise, return NULL. 03160 // 03161 03162 if (ConsoleHandle != NULL) { 03163 Status = RevalidateConsole(ConsoleHandle, &Console); 03164 if (NT_SUCCESS(Status)) { 03165 *phdeskConsole = Console->hDesk; 03166 } 03167 UnlockConsole(Console); 03168 } 03169 03170 return STATUS_SUCCESS; 03171 }

VOID GetTimeouts VOID   ) 
 

Definition at line 1068 of file server/server.c.

References CMSHUNGAPPTIMEOUT, gCmsHungAppTimeout, gCmsWaitToKillTimeout, gdwHungToKillCount, gdwProcessTerminateTimeout, gdwServicesWaitToKillTimeout, GetRegIntFromID(), gfAutoEndTask, L, MyRegOpenKey(), NT_SUCCESS, NtClose(), NTSTATUS(), NULL, PROCESSTERMINATETIMEOUT, RtlOpenCurrentUser(), Status, and VOID().

Referenced by SrvLogon().

01069 { 01070 HANDLE hCurrentUserKey; 01071 HANDLE hKey; 01072 NTSTATUS Status; 01073 01074 Status = RtlOpenCurrentUser(MAXIMUM_ALLOWED, &hCurrentUserKey); 01075 if (NT_SUCCESS(Status)) { 01076 Status = MyRegOpenKey(hCurrentUserKey, 01077 L"Control Panel\\Desktop", 01078 &hKey); 01079 if (NT_SUCCESS(Status)) { 01080 gCmsHungAppTimeout = GetRegIntFromID( 01081 hKey, 01082 STR_CMSHUNGAPPTIMEOUT, 01083 gCmsHungAppTimeout); 01084 gCmsWaitToKillTimeout = GetRegIntFromID( 01085 hKey, 01086 STR_CMSWAITTOKILLTIMEOUT, 01087 gCmsWaitToKillTimeout); 01088 01089 gdwHungToKillCount = gCmsWaitToKillTimeout / gCmsHungAppTimeout; 01090 01091 gfAutoEndTask = GetRegIntFromID( 01092 hKey, 01093 STR_AUTOENDTASK, 01094 gfAutoEndTask); 01095 NtClose(hKey); 01096 } 01097 NtClose(hCurrentUserKey); 01098 } 01099 01100 Status = MyRegOpenKey(NULL, 01101 L"\\Registry\\Machine\\System\\CurrentControlSet\\Control", 01102 &hKey); 01103 if (NT_SUCCESS(Status)) { 01104 gdwServicesWaitToKillTimeout = GetRegIntFromID( 01105 hKey, 01106 STR_WAITTOKILLSERVICETIMEOUT, 01107 gCmsWaitToKillTimeout); 01108 gdwProcessTerminateTimeout = GetRegIntFromID( 01109 hKey, 01110 STR_PROCESSTERMINATETIMEOUT, 01111 PROCESSTERMINATETIMEOUT); 01112 if (gdwProcessTerminateTimeout < CMSHUNGAPPTIMEOUT) { 01113 gdwProcessTerminateTimeout = CMSHUNGAPPTIMEOUT; 01114 } 01115 01116 NtClose(hKey); 01117 } 01118 }

VOID HandleMediaChangeEvent VOID   ) 
 

Definition at line 479 of file server/server.c.

References BOOL, BroadcastSystemMessage(), DWORD, NT_SUCCESS, NTSTATUS(), NtUserCallNoParam(), NtUserSetInformationThread(), NULL, Status, and VOID().

Referenced by NotificationThread().

00480 { 00481 /* 00482 * Local variables 00483 */ 00484 00485 DWORD dwRecipients; 00486 BOOL bResult; 00487 NTSTATUS Status; 00488 DEV_BROADCAST_VOLUME dbcvInfo; 00489 USERTHREAD_USEDESKTOPINFO utudi; 00490 00491 ULONG cDrive; 00492 00493 while (cDrive = (ULONG)NtUserCallNoParam(SFI_GETDEVICECHANGEINFO)) { 00494 00495 /* 00496 * Determine if it's an arrival or removal 00497 */ 00498 bResult = (cDrive & 0x80000000); 00499 00500 /* 00501 * Initialize the structures used for BroadcastSystemMessage 00502 */ 00503 dbcvInfo.dbcv_size = sizeof(dbcvInfo); 00504 dbcvInfo.dbcv_devicetype = DBT_DEVTYP_VOLUME; 00505 dbcvInfo.dbcv_reserved = 0; 00506 dbcvInfo.dbcv_flags = DBTF_MEDIA; 00507 dbcvInfo.dbcv_unitmask = cDrive; 00508 00509 dwRecipients = BSM_ALLCOMPONENTS | BSM_ALLDESKTOPS; 00510 00511 /* 00512 * Temporarily we must assign this thread to a desktop so we can 00513 * call USER's BroascastSystemMessage() routine. We call the 00514 * private SetThreadDesktopToDefault() to assign ourselves to the 00515 * desktop that is currently receiving input. 00516 */ 00517 utudi.hThread = NULL; 00518 utudi.drdRestore.pdeskRestore = NULL; 00519 Status = NtUserSetInformationThread(NtCurrentThread(), 00520 UserThreadUseActiveDesktop, 00521 &utudi, sizeof(utudi)); 00522 if (NT_SUCCESS(Status)) { 00523 /* 00524 * Broadcast the message 00525 */ 00526 BroadcastSystemMessage(BSF_FORCEIFHUNG | ((bResult) ? BSF_ALLOWSFW : 0), 00527 &dwRecipients, 00528 WM_DEVICECHANGE, 00529 // HACK: need to or 0x8000 in wParam 00530 // because this is a flag to let 00531 // BSM know that lParam is a pointer 00532 // to a data structure. 00533 0x8000 | ((bResult) ? DBT_DEVICEARRIVAL : DBT_DEVICEREMOVECOMPLETE), 00534 (LPARAM)&dbcvInfo); 00535 00536 /* 00537 * Set our thread's desktop back to NULL. This will decrement 00538 * the desktop's reference count. 00539 */ 00540 NtUserSetInformationThread(NtCurrentThread(), 00541 UserThreadUseDesktop, 00542 &utudi, 00543 sizeof(utudi)); 00544 } 00545 } 00546 }

VOID HandleRemoteNetDeviceChangeEvent  ) 
 

Definition at line 589 of file server/server.c.

References BroadcastSystemMessage(), DWORD, GetNetworkDrives(), LastNetDrives, NT_SUCCESS, NtUserSetInformationThread(), and NULL.

Referenced by NotificationThread().

00593 : 00594 00595 00596 Arguments: 00597 00598 Return Value: 00599 00600 --*/ 00601 { 00602 DWORD NetDrives; 00603 DEV_BROADCAST_VOLUME dbv; 00604 LONG status; 00605 USERTHREAD_USEDESKTOPINFO utudi; 00606 00607 00608 00609 /* 00610 * Temporarily we must assign this thread to a desktop so we can 00611 * call USER's BroascastSystemMessage() routine. We call the 00612 * private SetThreadDesktopToDefault() to assign ourselves to the 00613 * desktop that is currently receiving input. 00614 */ 00615 utudi.hThread = NULL; 00616 utudi.drdRestore.pdeskRestore = NULL; 00617 status = NtUserSetInformationThread(NtCurrentThread(), 00618 UserThreadUseActiveDesktop, 00619 &utudi, sizeof(utudi)); 00620 if (!NT_SUCCESS(status)) { 00621 return; 00622 } 00623 00624 // 00625 // Keep broadcasting until the set of net drives stops changing 00626 // 00627 for (;;) 00628 { 00629 00630 // 00631 // Get the current net drive bitmask and compare against the net 00632 // drive bitmask when we last broadcast 00633 // 00634 NetDrives = GetNetworkDrives(); 00635 00636 if (NetDrives == LastNetDrives) 00637 { 00638 break; 00639 } 00640 00641 // 00642 // Broadcast about deleted volumes 00643 // 00644 dbv.dbcv_size = sizeof(dbv); 00645 dbv.dbcv_devicetype = DBT_DEVTYP_VOLUME; 00646 dbv.dbcv_reserved = 0; 00647 dbv.dbcv_unitmask = LastNetDrives & ~NetDrives; 00648 dbv.dbcv_flags = DBTF_NET; 00649 if (dbv.dbcv_unitmask != 0) 00650 { 00651 DWORD dwRec = BSM_APPLICATIONS | BSM_ALLDESKTOPS; 00652 status = BroadcastSystemMessage( 00653 BSF_FORCEIFHUNG | BSF_NOHANG | BSF_NOTIMEOUTIFNOTHUNG, 00654 &dwRec, 00655 WM_DEVICECHANGE, 00656 (WPARAM) DBT_DEVICEREMOVECOMPLETE, 00657 (LPARAM)(DEV_BROADCAST_HDR*)(&dbv) 00658 ); 00659 00660 } 00661 00662 // 00663 // Broadcast about added volumes 00664 // 00665 dbv.dbcv_unitmask = NetDrives & ~LastNetDrives; 00666 if (dbv.dbcv_unitmask != 0) 00667 { 00668 DWORD dwRec = BSM_APPLICATIONS | BSM_ALLDESKTOPS; 00669 00670 status = BroadcastSystemMessage( 00671 BSF_FORCEIFHUNG | BSF_NOHANG | BSF_NOTIMEOUTIFNOTHUNG, 00672 &dwRec, 00673 WM_DEVICECHANGE, 00674 (WPARAM) DBT_DEVICEARRIVAL, 00675 (LPARAM)(DEV_BROADCAST_HDR*)(&dbv) 00676 ); 00677 00678 00679 } 00680 00681 // 00682 // Remember the drive set that we last broadcast about 00683 // 00684 LastNetDrives = NetDrives; 00685 00686 // 00687 // Go around the loop again to detect changes that may have occurred 00688 // while we were broadcasting 00689 // 00690 } 00691 00692 /* 00693 * Set our thread's desktop back to NULL. This will decrement 00694 * the desktop's reference count. 00695 */ 00696 NtUserSetInformationThread(NtCurrentThread(), 00697 UserThreadUseDesktop, 00698 &utudi, 00699 sizeof(utudi)); 00700 00701 return; 00702 }

VOID InitializeConsoleAttributes VOID   ) 
 

Definition at line 2132 of file srvinit.c.

References _CONSOLE_REGISTRY_INFO::AutoPosition, _CONSOLE_REGISTRY_INFO::ColorTable, CURSOR_SMALL_SIZE, _CONSOLE_REGISTRY_INFO::CursorSize, DEFAULT_NUMBER_OF_BUFFERS, DEFAULT_NUMBER_OF_COMMANDS, DefaultRegInfo, _CONSOLE_REGISTRY_INFO::FaceName, FALSE, _CONSOLE_REGISTRY_INFO::FontFamily, _CONSOLE_REGISTRY_INFO::FontSize, _CONSOLE_REGISTRY_INFO::FontWeight, _CONSOLE_REGISTRY_INFO::FullScreen, _CONSOLE_REGISTRY_INFO::HistoryBufferSize, _CONSOLE_REGISTRY_INFO::HistoryNoDup, InitializeSystemMetrics(), _CONSOLE_REGISTRY_INFO::InsertMode, L, _CONSOLE_REGISTRY_INFO::LastWriteTime, _CONSOLE_REGISTRY_INFO::NumberOfHistoryBuffers, OEMCP, _CONSOLE_REGISTRY_INFO::PopupFill, _CONSOLE_REGISTRY_INFO::QuickEdit, _CONSOLE_REGISTRY_INFO::ScreenBufferSize, _CONSOLE_REGISTRY_INFO::ScreenFill, TRUE, _CONSOLE_REGISTRY_INFO::WindowOrigin, and _CONSOLE_REGISTRY_INFO::WindowSize.

Referenced by SrvLogon().

02136 : 02137 02138 This routine initializes default attributes from the current 02139 user's registry values. It gets called during logon/logoff. 02140 02141 Arguments: 02142 02143 none 02144 02145 Return Value: 02146 02147 none 02148 02149 --*/ 02150 02151 { 02152 // 02153 // Store default values in structure and mark it 02154 // as invalid (by resetting LastWriteTime). 02155 // 02156 02157 DefaultRegInfo.ScreenFill.Attributes = 0x07; // white on black 02158 DefaultRegInfo.ScreenFill.Char.UnicodeChar = (WCHAR)' '; 02159 DefaultRegInfo.PopupFill.Attributes = 0xf5; // purple on white 02160 DefaultRegInfo.PopupFill.Char.UnicodeChar = (WCHAR)' '; 02161 DefaultRegInfo.InsertMode = FALSE; 02162 DefaultRegInfo.QuickEdit = FALSE; 02163 DefaultRegInfo.AutoPosition = TRUE; 02164 DefaultRegInfo.FullScreen = FALSE; 02165 DefaultRegInfo.ScreenBufferSize.X = 80; 02166 DefaultRegInfo.ScreenBufferSize.Y = 25; 02167 DefaultRegInfo.WindowSize.X = 80; 02168 DefaultRegInfo.WindowSize.Y = 25; 02169 DefaultRegInfo.WindowOrigin.X = 0; 02170 DefaultRegInfo.WindowOrigin.Y = 0; 02171 DefaultRegInfo.FontSize.X = 0; 02172 DefaultRegInfo.FontSize.Y = 0; 02173 DefaultRegInfo.FontFamily = 0; 02174 DefaultRegInfo.FontWeight = 0; 02175 DefaultRegInfo.FaceName[0] = L'\0'; 02176 DefaultRegInfo.CursorSize = CURSOR_SMALL_SIZE; 02177 DefaultRegInfo.HistoryBufferSize = DEFAULT_NUMBER_OF_COMMANDS; 02178 DefaultRegInfo.NumberOfHistoryBuffers = DEFAULT_NUMBER_OF_BUFFERS; 02179 DefaultRegInfo.HistoryNoDup = FALSE; 02180 DefaultRegInfo.ColorTable[ 0] = RGB(0, 0, 0 ); 02181 DefaultRegInfo.ColorTable[ 1] = RGB(0, 0, 0x80); 02182 DefaultRegInfo.ColorTable[ 2] = RGB(0, 0x80,0 ); 02183 DefaultRegInfo.ColorTable[ 3] = RGB(0, 0x80,0x80); 02184 DefaultRegInfo.ColorTable[ 4] = RGB(0x80,0, 0 ); 02185 DefaultRegInfo.ColorTable[ 5] = RGB(0x80,0, 0x80); 02186 DefaultRegInfo.ColorTable[ 6] = RGB(0x80,0x80,0 ); 02187 DefaultRegInfo.ColorTable[ 7] = RGB(0xC0,0xC0,0xC0); 02188 DefaultRegInfo.ColorTable[ 8] = RGB(0x80,0x80,0x80); 02189 DefaultRegInfo.ColorTable[ 9] = RGB(0, 0, 0xFF); 02190 DefaultRegInfo.ColorTable[10] = RGB(0, 0xFF,0 ); 02191 DefaultRegInfo.ColorTable[11] = RGB(0, 0xFF,0xFF); 02192 DefaultRegInfo.ColorTable[12] = RGB(0xFF,0, 0 ); 02193 DefaultRegInfo.ColorTable[13] = RGB(0xFF,0, 0xFF); 02194 DefaultRegInfo.ColorTable[14] = RGB(0xFF,0xFF,0 ); 02195 DefaultRegInfo.ColorTable[15] = RGB(0xFF,0xFF,0xFF); 02196 #if defined(FE_SB) // scotthsu 02197 DefaultRegInfo.CodePage = OEMCP; 02198 #endif 02199 DefaultRegInfo.LastWriteTime = 0; 02200 02201 // 02202 // Get system metrics for this user 02203 // 02204 02205 InitializeSystemMetrics(); 02206 }

NTSTATUS MyRegOpenKey IN HANDLE  hKey,
IN LPWSTR  lpSubKey,
OUT PHANDLE  phResult
 

Definition at line 1635 of file srvinit.c.

References NtOpenKey(), NULL, and RtlInitUnicodeString().

Referenced by GetRegistryValues(), and GetTimeouts().

01640 { 01641 OBJECT_ATTRIBUTES Obja; 01642 UNICODE_STRING SubKey; 01643 01644 // 01645 // Convert the subkey to a counted Unicode string. 01646 // 01647 01648 RtlInitUnicodeString( &SubKey, lpSubKey ); 01649 01650 // 01651 // Initialize the OBJECT_ATTRIBUTES structure and open the key. 01652 // 01653 01654 InitializeObjectAttributes( 01655 &Obja, 01656 &SubKey, 01657 OBJ_CASE_INSENSITIVE, 01658 hKey, 01659 NULL 01660 ); 01661 01662 return NtOpenKey( 01663 phResult, 01664 KEY_READ, 01665 &Obja 01666 ); 01667 }

VOID NotificationThread PVOID   ) 
 

Definition at line 881 of file server/server.c.

References BaseSrvNlsUpdateRegistryCache(), CreateBSMEventSD(), FALSE, gfLogon, ghMediaRequestEvent, ghNlsEvent, ghPowerRequestEvent, gSessionId, HandleMediaChangeEvent(), HandleRemoteNetDeviceChangeEvent(), hThreadNotification, ID_MEDIACHANGE, ID_NETDEVCHANGE, ID_NLS, ID_NUM_EVENTS, ID_POWER, L, MAX_SESSION_PATH, NT_SUCCESS, NtCreateEvent(), NtResetEvent(), NtSetInformationThread(), NTSTATUS(), NtUserCallNoParam(), NtWaitForMultipleObjects(), NULL, RtlInitUnicodeString(), SC_BSM_EVENT_NAME, SESSION_ROOT, StartRegReadRead(), Status, TRUE, and VOID().

Referenced by UserServerDllInitialization().

00883 { 00884 KPRIORITY Priority; 00885 NTSTATUS Status; 00886 HANDLE hEvent[ID_NUM_EVENTS]; 00887 WCHAR szObjectStr[MAX_SESSION_PATH]; 00888 OBJECT_ATTRIBUTES Attributes; 00889 UNICODE_STRING UnicodeString; 00890 PSECURITY_DESCRIPTOR pSD = NULL; 00891 ULONG NumEvents = ID_NUM_EVENTS; 00892 00893 UNREFERENCED_PARAMETER(pJunk); 00894 00895 try { 00896 00897 /* 00898 * Set the priority of the RIT to 3. 00899 */ 00900 Priority = LOW_PRIORITY + 3; 00901 NtSetInformationThread(hThreadNotification, ThreadPriority, &Priority, 00902 sizeof(KPRIORITY)); 00903 00904 /* 00905 * Setup the NLS event 00906 */ 00907 NtCreateEvent(&ghNlsEvent, EVENT_ALL_ACCESS, NULL, SynchronizationEvent, FALSE); 00908 UserAssert( ghNlsEvent != NULL ); 00909 hEvent[ID_NLS] = ghNlsEvent; 00910 00911 /* 00912 * Setup the power request event 00913 */ 00914 hEvent[ID_POWER] = ghPowerRequestEvent; 00915 00916 /* 00917 * Setup the MediaChangeEvent 00918 */ 00919 hEvent[ID_MEDIACHANGE] = ghMediaRequestEvent; 00920 00921 00922 /* 00923 * Setup the NetDeviceChange Event 00924 */ 00925 00926 if (gSessionId != 0) { 00927 // 00928 // Only on remote Session 00929 // 00930 00931 00932 swprintf(szObjectStr,L"%ws\\%ld\\BaseNamedObjects\\%ws", 00933 SESSION_ROOT,gSessionId,SC_BSM_EVENT_NAME); 00934 00935 RtlInitUnicodeString(&UnicodeString, szObjectStr); 00936 00937 if (CreateBSMEventSD(&pSD) ) { 00938 00939 InitializeObjectAttributes(&Attributes, 00940 &UnicodeString, 00941 OBJ_CASE_INSENSITIVE | OBJ_OPENIF, 00942 NULL, 00943 pSD); 00944 00945 if (!NT_SUCCESS(NtCreateEvent(&hEvent[ID_NETDEVCHANGE], EVENT_ALL_ACCESS, &Attributes, SynchronizationEvent, FALSE))) { 00946 00947 NumEvents--; 00948 00949 } 00950 00951 LocalFree(pSD); 00952 } else { 00953 00954 NumEvents--; 00955 } 00956 00957 } else { 00958 // 00959 // On Console we don't wait for NetDeviceEvent 00960 // 00961 NumEvents--; 00962 } 00963 00964 /* 00965 * Only want media change events on the console. 00966 */ 00967 if (gSessionId == 0) { 00968 } 00969 00970 StartRegReadRead(); 00971 00972 /* 00973 * Sit and wait forever. 00974 */ 00975 while (TRUE) { 00976 Status = NtWaitForMultipleObjects(NumEvents, 00977 hEvent, 00978 WaitAny, 00979 TRUE, 00980 NULL); 00981 00982 00983 if (Status == ID_NLS + WAIT_OBJECT_0) { 00984 00985 /* 00986 * Handle the NLS event 00987 */ 00988 if (gfLogon) { 00989 gfLogon = FALSE; 00990 BaseSrvNlsUpdateRegistryCache(NULL, NULL); 00991 } 00992 00993 } 00994 else if (Status == ID_POWER + WAIT_OBJECT_0) { 00995 00996 /* 00997 * Handle the power request event 00998 */ 00999 NtUserCallNoParam(SFI_XXXUSERPOWERCALLOUTWORKER); 01000 01001 } 01002 else if (Status == ID_MEDIACHANGE + WAIT_OBJECT_0) { 01003 01004 /* 01005 * Handle the media change event 01006 */ 01007 HandleMediaChangeEvent(); 01008 01009 NtResetEvent(hEvent[ID_MEDIACHANGE], NULL); 01010 } 01011 else if (Status == ID_NETDEVCHANGE + WAIT_OBJECT_0) { 01012 01013 /* 01014 * Handle the NetDevice change event for remote sessions 01015 */ 01016 HandleRemoteNetDeviceChangeEvent(); 01017 01018 } 01019 01020 01021 } // While (TRUE) 01022 01023 } except (CsrUnhandledExceptionFilter(GetExceptionInformation())) { 01024 KdPrint(("Registry notification thread is dead, sorry.\n")); 01025 } 01026 }

VOID RegReadApcProcedure PVOID  RegReadApcContext,
PIO_STATUS_BLOCK  IoStatus
 

Definition at line 387 of file server/server.c.

References BYTE, DWORD, FALSE, hKeyPriority, IoStatusRegChange, L, NT_SUCCESS, NtNotifyChangeKey(), NtQueryValueKey(), NtSetSystemInformation(), NULL, RegChangeBuffer, RegReadApcProcedure(), RtlInitUnicodeString(), Status, and TRUE.

Referenced by RegReadApcProcedure(), and StartRegReadRead().

00391 { 00392 UNICODE_STRING ValueString; 00393 LONG Status; 00394 BYTE Buf[sizeof(KEY_VALUE_PARTIAL_INFORMATION) + sizeof(DWORD)]; 00395 DWORD cbSize; 00396 ULONG l; 00397 00398 UNREFERENCED_PARAMETER(RegReadApcContext); 00399 UNREFERENCED_PARAMETER(IoStatus); 00400 00401 RtlInitUnicodeString(&ValueString, L"Win32PrioritySeparation"); 00402 Status = NtQueryValueKey(hKeyPriority, 00403 &ValueString, 00404 KeyValuePartialInformation, 00405 (PKEY_VALUE_PARTIAL_INFORMATION)Buf, 00406 sizeof(Buf), 00407 &cbSize); 00408 if (NT_SUCCESS(Status)) { 00409 l = *((PDWORD)((PKEY_VALUE_PARTIAL_INFORMATION)Buf)->Data); 00410 } else { 00411 l = PROCESS_PRIORITY_SEPARATION_MAX; // last resort default 00412 } 00413 00414 NtSetSystemInformation(SystemPrioritySeperation,&l,sizeof(ULONG)); 00415 00416 NtNotifyChangeKey( 00417 hKeyPriority, 00418 NULL, 00419 (PIO_APC_ROUTINE)RegReadApcProcedure, 00420 NULL, 00421 &IoStatusRegChange, 00422 REG_NOTIFY_CHANGE_LAST_SET, 00423 FALSE, 00424 &RegChangeBuffer, 00425 sizeof(RegChangeBuffer), 00426 TRUE 00427 ); 00428 }

VOID SetDbgTag int  tag,
DWORD  dwBitFlags
 

Definition at line 1290 of file server/server.c.

References VOID().

01291 { 01292 UNREFERENCED_PARAMETER(tag); 01293 UNREFERENCED_PARAMETER(dwBitFlags); 01294 }

VOID SetRipFlags DWORD  dwRipFlags,
DWORD  dwRipPID
 

Definition at line 1282 of file server/server.c.

References DWORD, gdwRIPFlags, RIPF_VALIDUSERFLAGS, and VOID().

01283 { 01284 if ((dwRipFlags != (DWORD)-1) && !(dwRipFlags & ~RIPF_VALIDUSERFLAGS)) { 01285 gdwRIPFlags = (WORD)((gdwRIPFlags & ~RIPF_VALIDUSERFLAGS) | dwRipFlags); 01286 } 01287 UNREFERENCED_PARAMETER(dwRipPID); 01288 }

ULONG SrvActivateDebugger IN OUT PCSR_API_MSG  m,
IN OUT PCSR_REPLY_STATUS  ReplyStatus
 

Definition at line 28 of file w32/ntuser/server/debug.c.

References ASSERT, _ACTIVATEDEBUGGERMSG::ClientId, FALSE, gpfnAttachRoutine, NT_SUCCESS, NtAlertThread(), NTSTATUS(), NULL, RtlRemoteCall(), Status, and TRUE.

00031 { 00032 PACTIVATEDEBUGGERMSG a = (PACTIVATEDEBUGGERMSG)&m->u.ApiMessageData; 00033 PCSR_THREAD Thread; 00034 NTSTATUS Status; 00035 00036 UNREFERENCED_PARAMETER(ReplyStatus); 00037 00038 /* 00039 * If the process is CSR, break 00040 */ 00041 if (a->ClientId.UniqueProcess == NtCurrentTeb()->ClientId.UniqueProcess) { 00042 DbgBreakPoint(); 00043 return STATUS_SUCCESS; 00044 } 00045 00046 /* 00047 * Impersonate the client if this is a user mode request. 00048 */ 00049 if (m->h.u2.s2.Type == LPC_REQUEST) { 00050 if (!CsrImpersonateClient(NULL)) { 00051 return STATUS_UNSUCCESSFUL; 00052 } 00053 } 00054 00055 /* 00056 * Lock the client thread 00057 */ 00058 Status = CsrLockThreadByClientId(a->ClientId.UniqueThread, &Thread); 00059 if (NT_SUCCESS(Status)) { 00060 ASSERT(a->ClientId.UniqueProcess == Thread->ClientId.UniqueProcess); 00061 00062 /* 00063 * Now that everything is set, rtlremote call to a debug breakpoint. 00064 * This causes the process to enter the debugger with a breakpoint. 00065 */ 00066 Status = RtlRemoteCall( 00067 Thread->Process->ProcessHandle, 00068 Thread->ThreadHandle, 00069 (PVOID)gpfnAttachRoutine, 00070 0, 00071 NULL, 00072 TRUE, 00073 FALSE 00074 ); 00075 UserAssert(NT_SUCCESS(Status)); 00076 Status = NtAlertThread(Thread->ThreadHandle); 00077 UserAssert(NT_SUCCESS(Status)); 00078 CsrUnlockThread(Thread); 00079 } 00080 00081 /* 00082 * Stop impersonating the client. 00083 */ 00084 if (m->h.u2.s2.Type == LPC_REQUEST) { 00085 CsrRevertToSelf(); 00086 } 00087 00088 return Status; 00089 }

ULONG SrvDeviceEvent IN OUT PCSR_API_MSG  m,
IN OUT PCSR_REPLY_STATUS  ReplyStatus
 

Definition at line 37 of file instdev.c.

References _DEVICEEVENTMSG::dwFlags, _DEVICEEVENTMSG::dwResult, EXCEPTION_EXECUTE_HANDLER, _DEVICEEVENTMSG::hWnd, IsWindow(), _DEVICEEVENTMSG::lParam, NT_SUCCESS, NTSTATUS(), NtUserSetInformationThread(), NULL, PostMessage(), SendMessageTimeout(), Status, and _DEVICEEVENTMSG::wParam.

00040 { 00041 NTSTATUS Status = STATUS_SUCCESS; 00042 PDEVICEEVENTMSG a = (PDEVICEEVENTMSG)&m->u.ApiMessageData; 00043 USERTHREAD_USEDESKTOPINFO utudi; 00044 00045 UNREFERENCED_PARAMETER(ReplyStatus); 00046 00047 try { 00048 00049 // 00050 // Set the desktop to the active desktop before sending the 00051 // message. 00052 // 00053 00054 utudi.hThread = NULL; 00055 utudi.drdRestore.pdeskRestore = NULL; 00056 Status = NtUserSetInformationThread(NtCurrentThread(), 00057 UserThreadUseActiveDesktop, 00058 &utudi, sizeof(utudi)); 00059 if (!NT_SUCCESS(Status)) { 00060 #if DBG 00061 KdPrint(("--> SrvDeviceEvent: NtUserSetInformationThread failed %d\n", Status)); 00062 #endif 00063 goto Clean1; 00064 } 00065 00066 // 00067 // Verify the window handle is still valid, if not, let the caller know 00068 // so it can be purged from the notification window hand list that the 00069 // user-mode pnp manager keeps. 00070 // 00071 00072 if ((a->hWnd != HWND_BROADCAST) && !IsWindow(a->hWnd)) { 00073 Status = STATUS_INVALID_HANDLE; 00074 goto Clean0; 00075 } 00076 00077 if (a->dwFlags) { 00078 00079 // 00080 // This is a query so we have to send the message but use 00081 // timeouts so an app can't stall us forever. 00082 // 00083 00084 RIPMSG3(RIP_VERBOSE, "--> SrvDeviceEvent: Sending WM_DEVICECHANGE to 0x%x, w 0x%x, l 0x%x", 00085 (ULONG_PTR)a->hWnd, 00086 a->wParam, 00087 a->lParam); 00088 00089 if (!SendMessageTimeout(a->hWnd, WM_DEVICECHANGE, a->wParam, a->lParam, 00090 SMTO_ABORTIFHUNG | SMTO_NORMAL, 00091 PNP_NOTIFY_TIMEOUT, &a->dwResult)) { 00092 Status = STATUS_UNSUCCESSFUL; 00093 } 00094 00095 } else { 00096 00097 // 00098 // It's not a query so just post it and return, we don't 00099 // care what the app returns. 00100 // 00101 00102 RIPMSG3(RIP_VERBOSE, "--> SrvDeviceEvent: Posting WM_DEVICECHANGE to 0x%x, w 0x%x, l 0x%x", 00103 (ULONG_PTR)a->hWnd, 00104 a->wParam, 00105 a->lParam); 00106 00107 if (!PostMessage(a->hWnd, WM_DEVICECHANGE, a->wParam, a->lParam)) { 00108 Status = STATUS_UNSUCCESSFUL; 00109 } 00110 } 00111 00112 Clean0: 00113 00114 // 00115 // Reset this thread's desktop back to NULL before returning. This 00116 // decrements the desktop's reference count. 00117 // 00118 00119 NtUserSetInformationThread(NtCurrentThread(), 00120 UserThreadUseDesktop, 00121 &utudi, sizeof(utudi)); 00122 00123 Clean1: 00124 ; 00125 00126 } except (EXCEPTION_EXECUTE_HANDLER) { 00127 KdPrint(("SrvDeviceEvent generated an exception (%d)\n", GetExceptionCode())); 00128 Status = STATUS_UNSUCCESSFUL; 00129 } 00130 00131 return Status; 00132 00133 } // SrvDeviceEvent

ULONG SrvEndTask IN OUT PCSR_API_MSG  m,
IN OUT PCSR_REPLY_STATUS  ReplyStatus
 

Definition at line 1963 of file server/exitwin.c.

References _EndTask(), _ENDTASKMSG::dwLastError, _ENDTASKMSG::fForce, _ENDTASKMSG::fShutdown, _ENDTASKMSG::fSuccess, _ENDTASKMSG::hwnd, NtReplyPort(), NULL, and TRUE.

01966 { 01967 PENDTASKMSG petm = (PENDTASKMSG)&m->u.ApiMessageData; 01968 PCSR_THREAD pcsrt; 01969 PTEB Teb = NtCurrentTeb(); 01970 01971 Teb->LastErrorValue = 0; 01972 pcsrt = CSR_SERVER_QUERYCLIENTTHREAD(); 01973 /* 01974 * Don't block the client so it can respond to messages while we 01975 * process this request -- we might bring up the End Application 01976 * dialog or the hwnd being shutdown might request some user action. 01977 */ 01978 if (pcsrt->Process->ClientPort != NULL) { 01979 m->ReturnValue = STATUS_SUCCESS; 01980 petm->dwLastError = 0; 01981 petm->fSuccess = TRUE; 01982 NtReplyPort(pcsrt->Process->ClientPort, (PPORT_MESSAGE)m); 01983 *ReplyStatus = CsrServerReplied; 01984 } 01985 01986 petm->fSuccess = _EndTask(petm->hwnd, petm->fShutdown, petm->fForce); 01987 01988 petm->dwLastError = Teb->LastErrorValue; 01989 return STATUS_SUCCESS; 01990 }

ULONG SrvExitWindowsEx IN OUT PCSR_API_MSG  m,
IN OUT PCSR_REPLY_STATUS  ReplyStatus
 

Definition at line 1950 of file server/exitwin.c.

References _ExitWindowsEx(), BEGIN_LPC_RECV, END_LPC_RECV, NT_SUCCESS, and Status.

01953 { 01954 BEGIN_LPC_RECV(EXITWINDOWSEX); 01955 01956 Status = _ExitWindowsEx(pcsrt, a->uFlags, a->dwReserved); 01957 a->fSuccess = NT_SUCCESS(Status); 01958 01959 END_LPC_RECV(); 01960 }

ULONG SrvGetThreadConsoleDesktop IN OUT PCSR_API_MSG  m,
IN OUT PCSR_REPLY_STATUS  ReplyStatus
 

Definition at line 1235 of file server/server.c.

References _GETTHREADCONSOLEDESKTOPMSG::dwThreadId, GetThreadConsoleDesktop(), _GETTHREADCONSOLEDESKTOPMSG::hdeskConsole, and PGETTHREADCONSOLEDESKTOPMSG.

01238 { 01239 PGETTHREADCONSOLEDESKTOPMSG a = (PGETTHREADCONSOLEDESKTOPMSG)&m->u.ApiMessageData; 01240 01241 UNREFERENCED_PARAMETER(ReplyStatus); 01242 01243 return GetThreadConsoleDesktop(a->dwThreadId, &a->hdeskConsole); 01244 }

ULONG SrvLogon IN OUT PCSR_API_MSG  m,
IN OUT PCSR_REPLY_STATUS  ReplyStatus
 

Definition at line 1121 of file server/server.c.

References ASSERT, BaseSrvNlsLogon(), FALSE, _LOGONMSG::fLogon, GetTimeouts(), gfLogon, ghNlsEvent, InitializeConsoleAttributes(), LdrFlushAlternateResourceModules(), NT_SUCCESS, NtSetEvent(), NTSTATUS(), NULL, PLOGONMSG, Status, and TRUE.

01124 { 01125 PLOGONMSG a = (PLOGONMSG)&m->u.ApiMessageData; 01126 NTSTATUS Status; 01127 01128 UNREFERENCED_PARAMETER(ReplyStatus); 01129 01130 if (!CsrImpersonateClient(NULL)) 01131 return (ULONG)STATUS_UNSUCCESSFUL; 01132 01133 if (a->fLogon) { 01134 01135 /* 01136 * Flush the MultiLingual UI (MUI) alternate 01137 * resource modules from within NTDLL, so that the 01138 * new user logging-on gets his chance to 01139 * load his own. 01140 */ 01141 LdrFlushAlternateResourceModules(); 01142 01143 /* 01144 * Take care of NLS cache for LogON. 01145 */ 01146 BaseSrvNlsLogon(TRUE); 01147 01148 /* 01149 * Set the cleanup event so that the RIT can handle the NLS 01150 * registry notification. 01151 */ 01152 gfLogon = TRUE; 01153 Status = NtSetEvent( ghNlsEvent, NULL ); 01154 ASSERT(NT_SUCCESS(Status)); 01155 } else { 01156 01157 /* 01158 * Take care of NLS cache for LogOFF. 01159 */ 01160 BaseSrvNlsLogon(FALSE); 01161 } 01162 01163 /* 01164 * Get timeout values from registry 01165 */ 01166 GetTimeouts(); 01167 01168 CsrRevertToSelf(); 01169 01170 /* 01171 * Initialize console attributes 01172 */ 01173 InitializeConsoleAttributes(); 01174 01175 return (ULONG)STATUS_SUCCESS; 01176 }

ULONG SrvRegisterLogonProcess IN OUT PCSR_API_MSG  m,
IN OUT PCSR_REPLY_STATUS  ReplyStatus
 

Definition at line 1179 of file server/server.c.

References DWORD, and gIdLogon.

01182 { 01183 /* 01184 * Fail if this is not the first call. 01185 */ 01186 if (gIdLogon != 0) { 01187 return (ULONG)STATUS_UNSUCCESSFUL; 01188 } 01189 01190 gIdLogon = *(DWORD*)m->u.ApiMessageData; 01191 01192 UNREFERENCED_PARAMETER(ReplyStatus); 01193 01194 return (ULONG)STATUS_SUCCESS; 01195 }

ULONG SrvRegisterServicesProcess IN OUT PCSR_API_MSG  m,
IN OUT PCSR_REPLY_STATUS  ReplyStatus
 

Definition at line 2053 of file server/exitwin.c.

References BEGIN_LPC_RECV, END_LPC_RECV, EnterCrit, FALSE, gdwServicesProcessId, IsPrivileged(), LeaveCrit, psTcb, and TRUE.

02056 { 02057 PRIVILEGE_SET psTcb = { 1, PRIVILEGE_SET_ALL_NECESSARY, 02058 { SE_TCB_PRIVILEGE, 0 } 02059 }; 02060 02061 BEGIN_LPC_RECV(REGISTERSERVICESPROCESS); 02062 02063 /* 02064 * Allow only one services process and then only if it has TCB 02065 * privilege. 02066 */ 02067 EnterCrit(); 02068 if ((gdwServicesProcessId != 0) || !IsPrivileged(&psTcb)) { 02069 SetLastError(ERROR_ACCESS_DENIED); 02070 a->fSuccess = FALSE; 02071 } else { 02072 gdwServicesProcessId = a->dwProcessId; 02073 a->fSuccess = TRUE; 02074 } 02075 LeaveCrit(); 02076 02077 END_LPC_RECV(); 02078 }

ULONG SrvWin32HeapFail IN OUT PCSR_API_MSG  m,
IN OUT PCSR_REPLY_STATUS  ReplyStatus
 

Definition at line 1198 of file server/server.c.

References _WIN32HEAPFAILMSG::bFail, and PWIN32HEAPFAILMSG.

01201 { 01202 #if DBG 01203 PWIN32HEAPFAILMSG a = (PWIN32HEAPFAILMSG)&m->u.ApiMessageData; 01204 01205 Win32HeapFailAllocations(a->bFail); 01206 01207 #endif 01208 return (ULONG)STATUS_SUCCESS; 01209 UNREFERENCED_PARAMETER(m); 01210 UNREFERENCED_PARAMETER(ReplyStatus); 01211 }

ULONG SrvWin32HeapStat IN OUT PCSR_API_MSG  m,
IN OUT PCSR_REPLY_STATUS  ReplyStatus
 

Definition at line 1214 of file server/server.c.

References BOOL, BYTE, _WIN32HEAPSTATMSG::dwLen, _WIN32HEAPSTATMSG::dwMaxTag, DWORD, _WIN32HEAPSTATMSG::phs, PWIN32HEAPSTATMSG, and TRUE.

01217 { 01218 #if DBG 01219 extern DWORD Win32HeapStat(PDBGHEAPSTAT phs, DWORD dwLen, BOOL bNeedTagShift); 01220 01221 PWIN32HEAPSTATMSG a = (PWIN32HEAPSTATMSG)&m->u.ApiMessageData; 01222 01223 if (!CsrValidateMessageBuffer(m, &a->phs, a->dwLen, sizeof(BYTE))) { 01224 return STATUS_INVALID_PARAMETER; 01225 } 01226 a->dwMaxTag = Win32HeapStat(a->phs, a->dwLen, TRUE); 01227 01228 #endif 01229 return (ULONG)STATUS_SUCCESS; 01230 UNREFERENCED_PARAMETER(m); 01231 UNREFERENCED_PARAMETER(ReplyStatus); 01232 }

VOID StartRegReadRead VOID   ) 
 

Definition at line 431 of file server/server.c.

References FALSE, hKeyPriority, L, NT_SUCCESS, NtOpenKey(), NULL, RegReadApcProcedure(), and RtlInitUnicodeString().

Referenced by NotificationThread().

00432 { 00433 UNICODE_STRING UnicodeString; 00434 OBJECT_ATTRIBUTES OA; 00435 00436 RtlInitUnicodeString(&UnicodeString, 00437 L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\PriorityControl"); 00438 InitializeObjectAttributes(&OA, &UnicodeString, OBJ_CASE_INSENSITIVE, NULL, NULL); 00439 00440 if (!NT_SUCCESS(NtOpenKey(&hKeyPriority, KEY_READ | KEY_NOTIFY, &OA))) 00441 UserAssert(FALSE); 00442 00443 RegReadApcProcedure(NULL, NULL); 00444 }

NTSTATUS UserClientConnect PCSR_PROCESS  Process,
PVOID  ConnectionInformation,
PULONG  pulConnectionLen
 

Definition at line 357 of file server/server.c.

References CsrApiPort, CsrQueryApiPort(), gDispatchTableValues, NTSTATUS(), NtUserProcessConnect(), NtUserSetInformationThread(), NULL, and USERCONNECT.

Referenced by UserServerDllInitialization().

00361 { 00362 /* 00363 * Pass the api port to the kernel. Do this early so the kernel 00364 * can send a datagram to CSR to activate a debugger. 00365 */ 00366 if (CsrApiPort == NULL) { 00367 CsrApiPort = CsrQueryApiPort(); 00368 NtUserSetInformationThread( 00369 NtCurrentThread(), 00370 UserThreadCsrApiPort, 00371 &CsrApiPort, 00372 sizeof(HANDLE)); 00373 } 00374 00375 UserAssert(*pulConnectionLen == sizeof(USERCONNECT)); 00376 if (*pulConnectionLen != sizeof(USERCONNECT)) { 00377 return STATUS_INVALID_PARAMETER; 00378 } 00379 00380 ((PUSERCONNECT)ConnectionInformation)->dwDispatchCount = gDispatchTableValues; 00381 return NtUserProcessConnect(Process->ProcessHandle, 00382 (PUSERCONNECT)ConnectionInformation, *pulConnectionLen); 00383 }

NTSTATUS UserClientShutdown PCSR_PROCESS  Process,
ULONG  dwFlags,
BOOLEAN  fFirstPass
 

VOID UserHardError PCSR_THREAD  pcsrt,
PHARDERROR_MSG  pmsg
 

Definition at line 1662 of file w32/ntuser/server/harderr.c.

References NULL, UserHardErrorEx(), and VOID().

Referenced by UserServerDllInitialization().

01665 { 01666 UserHardErrorEx(pt, pmsg, NULL); 01667 }

VOID UserRtlRaiseStatus NTSTATUS  Status  ) 
 

Definition at line 1296 of file server/server.c.

References RtlRaiseStatus(), Status, and VOID().

01297 { 01298 RtlRaiseStatus(Status); 01299 }

NTSTATUS UserServerDllInitialization PCSR_SERVER_DLL  psrvdll  ) 
 

Definition at line 192 of file server/server.c.

References BaseSetProcessCreateNotify(), BOOL, EnterCrit, FALSE, gcsUserSrv, gdwRIPFlags, gheventCancel, gheventCancelled, ghMediaRequestEvent, ghModuleWin, ghPowerRequestEvent, gpfnAttachRoutine, gpwszaSUCCESS, gpwszaSYSTEM_ERROR, gpwszaSYSTEM_INFORMATION, gpwszaSYSTEM_WARNING, hThreadNotification, ISTS, LeaveCrit, NotificationThread(), NT_SUCCESS, NtCreateEvent(), NTSTATUS(), NtUserInitialize(), NtUserNotifyProcessCreate(), NULL, RIPF_DEFAULT, RtlCreateUserThread(), RtlGetNtGlobalFlags(), RtlInitializeCriticalSection(), RtlLoadStringOrError(), Status, TRUE, UserClientConnect(), UserClientShutdown(), USERCURRENTVERSION, UserHardError(), UserpMaxApiNumber, UserServerApiDispatchTable, UserServerApiServerValidTable, and WinStationAPIInit().

00194 { 00195 CLIENT_ID ClientId; 00196 BOOL bAllocated; 00197 NTSTATUS Status; 00198 00199 /* 00200 * Initialize the RIP flags to default 00201 */ 00202 gdwRIPFlags = RIPF_DEFAULT; 00203 00204 #if DBG 00205 if (RtlGetNtGlobalFlags() & FLG_SHOW_LDR_SNAPS) { 00206 RIPMSG0(RIP_WARNING, 00207 "UserServerDllInitialization: entered"); 00208 } 00209 #endif 00210 00211 /* 00212 * Initialize a critical section structure that will be used to protect 00213 * all of the User Server's critical sections (except a few special 00214 * cases like the RIT -- see below). 00215 */ 00216 00217 Status = RtlInitializeCriticalSection(&gcsUserSrv); 00218 if (!NT_SUCCESS(Status)) 00219 { 00220 RIPMSG1(RIP_WARNING, 00221 "UserServerDllInitialization: InitializeCriticalSection failed with Status %x", 00222 Status); 00223 return Status; 00224 } 00225 EnterCrit(); 00226 00227 /* 00228 * Remember WINSRV.DLL's hmodule so we can grab resources from it later. 00229 */ 00230 ghModuleWin = psrvdll->ModuleHandle; 00231 00232 psrvdll->ApiNumberBase = USERSRV_FIRST_API_NUMBER; 00233 psrvdll->MaxApiNumber = UserpMaxApiNumber; 00234 psrvdll->ApiDispatchTable = UserServerApiDispatchTable; 00235 00236 if (ISTS()) { 00237 UserServerApiServerValidTable[0] = TRUE; // for ExitWindowsEx 00238 } 00239 00240 psrvdll->ApiServerValidTable = UserServerApiServerValidTable; 00241 #if DBG 00242 psrvdll->ApiNameTable = UserServerApiNameTable; 00243 #else 00244 psrvdll->ApiNameTable = NULL; 00245 #endif 00246 psrvdll->ConnectRoutine = UserClientConnect; 00247 psrvdll->HardErrorRoutine = UserHardError; 00248 psrvdll->ShutdownProcessRoutine = UserClientShutdown; 00249 00250 /* 00251 * Create these events used by shutdown 00252 */ 00253 //BUGBUG we should test the return code of NtCreateEvent 00254 NtCreateEvent(&gheventCancel, EVENT_ALL_ACCESS, NULL, 00255 NotificationEvent, FALSE); 00256 NtCreateEvent(&gheventCancelled, EVENT_ALL_ACCESS, NULL, 00257 NotificationEvent, FALSE); 00258 00259 /* 00260 * Create the event used by the power request code. 00261 */ 00262 NtCreateEvent(&ghPowerRequestEvent, EVENT_ALL_ACCESS, NULL, 00263 SynchronizationEvent, FALSE); 00264 00265 /* 00266 * Create the event used by the media change code. 00267 */ 00268 NtCreateEvent(&ghMediaRequestEvent, EVENT_ALL_ACCESS, NULL, 00269 SynchronizationEvent, FALSE); 00270 00271 /* 00272 * Tell the base what user address to call when it is creating a process 00273 * (but before the process starts running). 00274 */ 00275 BaseSetProcessCreateNotify(NtUserNotifyProcessCreate); 00276 00277 /* 00278 * Load some strings. 00279 */ 00280 gpwszaSUCCESS = (PWSTR)RtlLoadStringOrError(ghModuleWin, 00281 STR_SUCCESS, NULL, &bAllocated, FALSE); 00282 gpwszaSYSTEM_INFORMATION = (PWSTR)RtlLoadStringOrError(ghModuleWin, 00283 STR_SYSTEM_INFORMATION, NULL, &bAllocated, FALSE); 00284 gpwszaSYSTEM_WARNING = (PWSTR)RtlLoadStringOrError(ghModuleWin, 00285 STR_SYSTEM_WARNING, NULL, &bAllocated, FALSE); 00286 gpwszaSYSTEM_ERROR = (PWSTR)RtlLoadStringOrError(ghModuleWin, 00287 STR_SYSTEM_ERROR, NULL, &bAllocated, FALSE); 00288 /* 00289 * Initialize USER 00290 */ 00291 00292 { 00293 HANDLE hModBase; 00294 00295 hModBase = GetModuleHandle(TEXT("kernel32")); 00296 UserAssert(hModBase); 00297 gpfnAttachRoutine = GetProcAddress(hModBase,"BaseAttachCompleteThunk"); 00298 UserAssert(gpfnAttachRoutine); 00299 00300 Status = NtUserInitialize(USERCURRENTVERSION, ghPowerRequestEvent, ghMediaRequestEvent); 00301 if (!NT_SUCCESS(Status)) { 00302 RIPMSG1(RIP_WARNING, 00303 "UserServerDllInitialization: NtUserInitialize failed with Status %x", 00304 Status); 00305 goto ExitUserInit; 00306 } 00307 } 00308 00309 if (ISTS()) { 00310 00311 Status = WinStationAPIInit(); 00312 if (!NT_SUCCESS(Status)) { 00313 RIPMSG1(RIP_WARNING, 00314 "UserServerDllInitialization: WinStationAPIInit failed with Status %x", 00315 Status); 00316 goto ExitUserInit; 00317 } 00318 } 00319 00320 /* 00321 * Start registry notification thread 00322 */ 00323 Status = RtlCreateUserThread(NtCurrentProcess(), NULL, FALSE, 0, 0, 4*0x1000, 00324 (PUSER_THREAD_START_ROUTINE)NotificationThread, NULL, &hThreadNotification, 00325 &ClientId); 00326 if (!NT_SUCCESS(Status)) { 00327 RIPMSG1(RIP_WARNING, 00328 "UserServerDllInitialization: RtlCreateUserThread failed with Status %x", 00329 Status); 00330 } 00331 CsrAddStaticServerThread(hThreadNotification, &ClientId, 0); 00332 00333 ExitUserInit: 00334 LeaveCrit(); 00335 return Status; 00336 }

NTSTATUS WinStationAPIInit VOID   ) 
 

Definition at line 212 of file api.c.

References BOOL, DBGHYD, FALSE, gSessionId, L, NT_SUCCESS, NtResumeThread(), NtSetInformationThread(), NTSTATUS(), NULL, RtlCreateUserThread(), Status, TerminalServerRequestThread(), ThreadHandle, and TRUE.

Referenced by UserServerDllInitialization().

00214 { 00215 NTSTATUS Status; 00216 CLIENT_ID ClientId; 00217 HANDLE ThreadHandle; 00218 KPRIORITY Priority; 00219 00220 #if DBG 00221 static BOOL Inited = FALSE; 00222 #endif 00223 00224 UserAssert(Inited == FALSE); 00225 00226 gSessionId = NtCurrentPeb()->SessionId; 00227 00228 #if DBG 00229 if (Inited) 00230 DBGHYD(("WinStationAPIInit called twice !!!\n")); 00231 00232 Inited = TRUE; 00233 #endif 00234 00235 Status = RtlCreateUserThread(NtCurrentProcess(), 00236 NULL, 00237 TRUE, 00238 0L, 00239 0L, 00240 0L, 00241 TerminalServerRequestThread, 00242 NULL, 00243 &ThreadHandle, 00244 &ClientId); 00245 00246 if (!NT_SUCCESS(Status)) { 00247 DBGHYD(("WinStationAPIInit: failed to create TerminalServerRequestThread\n")); 00248 goto Exit; 00249 } 00250 /* 00251 * Add thread to server thread pool 00252 */ 00253 CsrAddStaticServerThread(ThreadHandle, &ClientId, 0); 00254 00255 /* 00256 * Boost priority of ICA SRV Request thread 00257 */ 00258 Priority = THREAD_BASE_PRIORITY_MAX; 00259 00260 Status = NtSetInformationThread(ThreadHandle, ThreadBasePriority, 00261 &Priority, sizeof(Priority)); 00262 00263 if (!NT_SUCCESS(Status)) { 00264 DBGHYD(("WinStationAPIInit: failed to set thread priority\n")); 00265 goto Exit; 00266 } 00267 00268 /* 00269 * Resume the thread now that we've initialized things. 00270 */ 00271 NtResumeThread(ThreadHandle, NULL); 00272 00273 00274 Exit: 00275 return Status; 00276 }


Variable Documentation

HANDLE CsrApiPort
 

Definition at line 54 of file server/server.c.

WORD gDispatchTableValues
 

Definition at line 355 of file server/server.c.

BOOL gfLogon
 

Definition at line 31 of file server/server.c.

Referenced by NotificationThread(), and SrvLogon().

HANDLE ghMediaRequestEvent
 

Definition at line 34 of file server/server.c.

Referenced by NotificationThread(), and UserServerDllInitialization().

HANDLE ghNlsEvent
 

Definition at line 30 of file server/server.c.

Referenced by NotificationThread(), and SrvLogon().

HANDLE ghPowerRequestEvent
 

Definition at line 33 of file server/server.c.

Referenced by NotificationThread(), and UserServerDllInitialization().

FARPROC gpfnAttachRoutine
 

Definition at line 32 of file server/server.c.

Referenced by SrvActivateDebugger(), and UserServerDllInitialization().

CONST ALWAYSZERO gZero
 

Definition at line 1310 of file server/server.c.

HANDLE hKeyPriority
 

Definition at line 26 of file server/server.c.

Referenced by RegReadApcProcedure(), and StartRegReadRead().

HANDLE hThreadNotification
 

Definition at line 25 of file server/server.c.

Referenced by NotificationThread(), and UserServerDllInitialization().

IO_STATUS_BLOCK IoStatusRegChange
 

Definition at line 28 of file server/server.c.

Referenced by RegReadApcProcedure().

DWORD LastNetDrives
 

Definition at line 51 of file server/server.c.

Referenced by HandleRemoteNetDeviceChangeEvent().

UNICODE_STRING PriorityValueName
 

Definition at line 27 of file server/server.c.

ULONG RegChangeBuffer
 

Definition at line 29 of file server/server.c.

Referenced by RegReadApcProcedure().

PCSR_API_ROUTINE UserServerApiDispatchTable[UserpMaxApiNumber-UserpExitWindowsEx]
 

Initial value:

{ (PCSR_API_ROUTINE)SrvExitWindowsEx, (PCSR_API_ROUTINE)SrvEndTask, (PCSR_API_ROUTINE)SrvLogon, (PCSR_API_ROUTINE)SrvRegisterServicesProcess, (PCSR_API_ROUTINE)SrvActivateDebugger, (PCSR_API_ROUTINE)SrvGetThreadConsoleDesktop, (PCSR_API_ROUTINE)SrvDeviceEvent, (PCSR_API_ROUTINE)SrvRegisterLogonProcess, (PCSR_API_ROUTINE)SrvWin32HeapFail, (PCSR_API_ROUTINE)SrvWin32HeapStat, }

Definition at line 107 of file server/server.c.

Referenced by UserServerDllInitialization().

BOOLEAN UserServerApiServerValidTable[UserpMaxApiNumber-UserpExitWindowsEx]
 

Initial value:

Definition at line 120 of file server/server.c.

Referenced by UserServerDllInitialization().


Generated on Sat May 15 19:45:37 2004 for test by doxygen 1.3.7