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

service.c File Reference

#include "precomp.h"

Go to the source code of this file.

Functions

HWINSTA xxxConnectService (PUNICODE_STRING pstrWinSta, HDESK *phdesk)


Function Documentation

HWINSTA xxxConnectService PUNICODE_STRING  pstrWinSta,
HDESK *  phdesk
 

Definition at line 25 of file service.c.

References AllocAce(), CreateSecurityDescriptor(), FALSE, KernelMode, NT_SUCCESS, NTSTATUS(), NULL, OpenEffectiveToken(), PtiCurrent, RtlInitUnicodeString(), _SE_EXPORTS::SeAliasAdminsSid, SeExports, Status, ThreadLockPool, ThreadUnlockPool, TRACE_INIT, xxxCreateDesktop(), and xxxCreateWindowStation().

Referenced by xxxResolveDesktop().

00028 { 00029 NTSTATUS Status; 00030 HANDLE hToken; 00031 ULONG ulLength; 00032 PTOKEN_USER ptuService; 00033 PSECURITY_DESCRIPTOR psdService; 00034 PSID psid; 00035 PACCESS_ALLOWED_ACE paceService = NULL, pace; 00036 OBJECT_ATTRIBUTES ObjService; 00037 HWINSTA hwinsta; 00038 UNICODE_STRING strDesktop; 00039 TL tlPoolSdService, tlPoolAceService, tlPoolToken; 00040 00041 /* 00042 * Open the token of the service. 00043 */ 00044 Status = OpenEffectiveToken(&hToken); 00045 if (!NT_SUCCESS(Status)) { 00046 RIPMSG1(RIP_WARNING, "ConnectService: Could not open process/thread token (0x%X)", Status); 00047 return NULL; 00048 } 00049 00050 /* 00051 * Get the user SID assigned to the service. 00052 */ 00053 ptuService = NULL; 00054 paceService = NULL; 00055 psdService = NULL; 00056 hwinsta = NULL; 00057 ZwQueryInformationToken(hToken, TokenUser, NULL, 0, &ulLength); 00058 ptuService = (PTOKEN_USER)UserAllocPool(ulLength, TAG_TOKEN); 00059 if (ptuService == NULL) { 00060 RIPMSG1(RIP_WARNING, "ConnectService: Can't alloc buffer (size=%d) for token info", ulLength); 00061 goto sd_error; 00062 } 00063 Status = ZwQueryInformationToken(hToken, TokenUser, ptuService, 00064 ulLength, &ulLength); 00065 ZwClose(hToken); 00066 if (!NT_SUCCESS(Status)) { 00067 RIPMSG1(RIP_WARNING, "ConnectService: QueryInformationToken failed (0x%X)", Status); 00068 goto sd_error; 00069 } 00070 psid = ptuService->User.Sid; 00071 00072 /* 00073 * Create ACE list. 00074 */ 00075 paceService = AllocAce(NULL, ACCESS_ALLOWED_ACE_TYPE, 0, 00076 WINSTA_CREATEDESKTOP | WINSTA_READATTRIBUTES | 00077 WINSTA_ACCESSGLOBALATOMS | WINSTA_EXITWINDOWS | 00078 WINSTA_ACCESSCLIPBOARD | STANDARD_RIGHTS_REQUIRED, 00079 psid, &ulLength); 00080 if (paceService == NULL) { 00081 RIPMSG0(RIP_WARNING, "ConnectService: AllocAce for WindowStation attributes failed"); 00082 goto sd_error; 00083 } 00084 pace = AllocAce(paceService, ACCESS_ALLOWED_ACE_TYPE, OBJECT_INHERIT_ACE | 00085 INHERIT_ONLY_ACE | NO_PROPAGATE_INHERIT_ACE, 00086 DESKTOP_READOBJECTS | DESKTOP_WRITEOBJECTS | DESKTOP_ENUMERATE | 00087 DESKTOP_CREATEWINDOW | DESKTOP_CREATEMENU | DESKTOP_HOOKCONTROL | 00088 STANDARD_RIGHTS_REQUIRED, 00089 psid, &ulLength); 00090 if (pace == NULL) { 00091 RIPMSG0(RIP_WARNING, "ConnectService: AllocAce for Desktop Attributes failed"); 00092 goto sd_error; 00093 } 00094 paceService = pace; 00095 pace = AllocAce(pace, ACCESS_ALLOWED_ACE_TYPE, 0, 00096 WINSTA_ENUMERATE, 00097 SeExports->SeAliasAdminsSid, &ulLength); 00098 if (pace == NULL) { 00099 RIPMSG0(RIP_WARNING, "ConnectService: AllocAce for admin WinSta enumerate failed"); 00100 goto sd_error; 00101 } 00102 paceService = pace; 00103 pace = AllocAce(pace, ACCESS_ALLOWED_ACE_TYPE, OBJECT_INHERIT_ACE | 00104 INHERIT_ONLY_ACE | NO_PROPAGATE_INHERIT_ACE, 00105 DESKTOP_READOBJECTS | DESKTOP_WRITEOBJECTS | DESKTOP_ENUMERATE, 00106 SeExports->SeAliasAdminsSid, &ulLength); 00107 if (pace == NULL) { 00108 RIPMSG0(RIP_WARNING, "ConnectService: AllocAce for admin Desktop access failed"); 00109 goto sd_error; 00110 } 00111 paceService = pace; 00112 00113 /* 00114 * Initialize the SD 00115 */ 00116 psdService = CreateSecurityDescriptor(paceService, ulLength, FALSE); 00117 if (psdService == NULL) { 00118 RIPMSG0(RIP_WARNING, "ConnectService: CreateSecurityDescriptor failed"); 00119 goto sd_error; 00120 } 00121 00122 ThreadLockPool(PtiCurrent(), ptuService, &tlPoolToken); 00123 ThreadLockPool(PtiCurrent(), paceService, &tlPoolAceService); 00124 ThreadLockPool(PtiCurrent(), psdService, &tlPoolSdService); 00125 00126 /* 00127 * The windowstation does not exist and must be created. 00128 */ 00129 InitializeObjectAttributes(&ObjService, pstrWinSta, 00130 OBJ_OPENIF, NULL, psdService); 00131 hwinsta = xxxCreateWindowStation(&ObjService, 00132 KernelMode, 00133 MAXIMUM_ALLOWED, 00134 NULL, 0, NULL, 0); 00135 if (hwinsta != NULL) { 00136 00137 TRACE_INIT(("Service windowstation created\n")); 00138 00139 /* 00140 * We have the windowstation, now create the desktop. The security 00141 * descriptor will be inherited from the windowstation. Save the 00142 * winsta handle because the access struct may be moved by the 00143 * desktop creation. 00144 */ 00145 RtlInitUnicodeString(&strDesktop, TEXT("Default")); 00146 InitializeObjectAttributes(&ObjService, &strDesktop, 00147 OBJ_OPENIF | OBJ_CASE_INSENSITIVE, hwinsta, NULL); 00148 00149 *phdesk = xxxCreateDesktop(&ObjService, KernelMode, 00150 NULL, NULL, 0, MAXIMUM_ALLOWED); 00151 00152 if (*phdesk == NULL) { 00153 00154 /* 00155 * The creation failed, wake the desktop thread, close the 00156 * windowstation and leave. 00157 */ 00158 RIPMSG0(RIP_WARNING, "ConnectService: CreateDesktop('Default') failed."); 00159 00160 ZwClose(hwinsta); 00161 hwinsta = NULL; 00162 } else { 00163 TRACE_INIT(("Default desktop in Service windowstation created\n")); 00164 } 00165 } else { 00166 *phdesk = NULL; 00167 } 00168 00169 ThreadUnlockPool(PtiCurrent(), &tlPoolSdService); 00170 ThreadUnlockPool(PtiCurrent(), &tlPoolAceService); 00171 ThreadUnlockPool(PtiCurrent(), &tlPoolToken); 00172 00173 sd_error: 00174 if (ptuService != NULL) 00175 UserFreePool(ptuService); 00176 if (paceService != NULL) 00177 UserFreePool(paceService); 00178 if (psdService != NULL) 00179 UserFreePool(psdService); 00180 00181 return hwinsta; 00182 }


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