ReactOS 0.4.16-dev-329-g9223134
setup.c File Reference
#include <windef.h>
#include <winbase.h>
#include <winreg.h>
#include <winsvc.h>
#include <ndk/rtlfuncs.h>
#include <ntsecapi.h>
#include "wine/debug.h"
Include dependency graph for setup.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (rpcss)
 
static BOOL SetupIsActive (VOID)
 
static BOOL RunningAsSYSTEM (VOID)
 
static VOID RpcSsConfigureAsNetworkService (VOID)
 
static VOID AddImpersonatePrivilege (VOID)
 
VOID DoRpcSsSetupConfiguration (VOID)
 

Macro Definition Documentation

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 11 of file setup.c.

Function Documentation

◆ AddImpersonatePrivilege()

static VOID AddImpersonatePrivilege ( VOID  )
static

Definition at line 133 of file setup.c.

134{
135 /* S-1-5-6 -- "Service" group */
136 static SID ServiceSid = { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_SERVICE_RID } };
137
139 LSA_HANDLE PolicyHandle;
141 LSA_UNICODE_STRING RightString;
142
146 &PolicyHandle);
147 if (!NT_SUCCESS(Status))
148 {
149 ERR("LsaOpenPolicy() failed with Status 0x%08lx\n", Status);
150 return;
151 }
152
153 RtlInitUnicodeString(&RightString, L"SeImpersonatePrivilege");
154 Status = LsaAddAccountRights(PolicyHandle, &ServiceSid, &RightString, 1);
155 if (!NT_SUCCESS(Status))
156 {
157 ERR("LsaAddAccountRights(\"S-1-5-6\", \"%wZ\") failed with Status 0x%08lx\n", Status, &RightString);
158 }
159
160 LsaClose(PolicyHandle);
161}
LONG NTSTATUS
Definition: precomp.h:26
#define ERR(fmt,...)
Definition: precomp.h:57
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
NTSTATUS WINAPI LsaOpenPolicy(IN PLSA_UNICODE_STRING SystemName OPTIONAL, IN PLSA_OBJECT_ATTRIBUTES ObjectAttributes, IN ACCESS_MASK DesiredAccess, OUT PLSA_HANDLE PolicyHandle)
Definition: lsa.c:1183
NTSTATUS WINAPI LsaAddAccountRights(IN LSA_HANDLE PolicyHandle, IN PSID AccountSid, IN PLSA_UNICODE_STRING UserRights, IN ULONG CountOfRights)
Definition: lsa.c:105
NTSTATUS WINAPI LsaClose(IN LSA_HANDLE ObjectHandle)
Definition: lsa.c:194
Status
Definition: gdiplustypes.h:25
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define POLICY_CREATE_ACCOUNT
Definition: ntsecapi.h:65
#define POLICY_LOOKUP_NAMES
Definition: ntsecapi.h:72
#define L(x)
Definition: ntvdm.h:50
#define ZeroMemory
Definition: winbase.h:1737
#define SECURITY_SERVICE_RID
Definition: setypes.h:562
#define SECURITY_NT_AUTHORITY
Definition: setypes.h:554
#define SID_REVISION
Definition: setypes.h:481

Referenced by DoRpcSsSetupConfiguration().

◆ DoRpcSsSetupConfiguration()

VOID DoRpcSsSetupConfiguration ( VOID  )

Definition at line 163 of file setup.c.

164{
165 /*
166 * On first run during the setup phase, the RPCSS service runs under
167 * the LocalSystem account. RPCSS then re-configures itself to run
168 * under the NetworkService account and adds the Impersonate privilege
169 * to the "Service" group.
170 * This is done in this way, because the NetworkService account does not
171 * initially exist when the setup phase is running and the RPCSS service
172 * is started, but this account is created later during the setup phase.
173 */
175 {
178 }
179}
static BOOL SetupIsActive(VOID)
Definition: setup.c:27
static BOOL RunningAsSYSTEM(VOID)
Definition: setup.c:53
static VOID AddImpersonatePrivilege(VOID)
Definition: setup.c:133
static VOID RpcSsConfigureAsNetworkService(VOID)
Definition: setup.c:92

Referenced by ServiceMain().

◆ RpcSsConfigureAsNetworkService()

static VOID RpcSsConfigureAsNetworkService ( VOID  )
static

Definition at line 92 of file setup.c.

93{
94 SC_HANDLE hSCManager, hService;
95
96 /* Open the service controller */
98 if (!hSCManager)
99 {
100 ERR("OpenSCManager() failed with error 0x%lx\n", GetLastError());
101 return;
102 }
103
104 /* Open the RPCSS service */
105 hService = OpenServiceW(hSCManager, L"RPCSS", SERVICE_CHANGE_CONFIG);
106 if (!hService)
107 ERR("OpenService(\"RPCSS\") failed with error 0x%lx\n", GetLastError());
108 if (hService)
109 {
110 /* Use the NetworkService account */
111 if (!ChangeServiceConfigW(hService,
115 NULL,
116 NULL,
117 NULL,
118 NULL,
119 L"NT AUTHORITY\\NetworkService",
120 L"",
121 NULL))
122 {
123 ERR("ChangeServiceConfig(\"RPCSS\") failed with error 0x%lx\n", GetLastError());
124 }
125
126 CloseServiceHandle(hService);
127 }
128
130}
SC_HANDLE hSCManager
Definition: sc.c:12
SC_HANDLE WINAPI OpenSCManagerW(LPCWSTR lpMachineName, LPCWSTR lpDatabaseName, DWORD dwDesiredAccess)
Definition: scm.c:2068
SC_HANDLE WINAPI OpenServiceW(SC_HANDLE hSCManager, LPCWSTR lpServiceName, DWORD dwDesiredAccess)
Definition: scm.c:2160
BOOL WINAPI ChangeServiceConfigW(SC_HANDLE hService, DWORD dwServiceType, DWORD dwStartType, DWORD dwErrorControl, LPCWSTR lpBinaryPathName, LPCWSTR lpLoadOrderGroup, LPDWORD lpdwTagId, LPCWSTR lpDependencies, LPCWSTR lpServiceStartName, LPCWSTR lpPassword, LPCWSTR lpDisplayName)
Definition: scm.c:482
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:580
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define SC_MANAGER_CONNECT
Definition: winsvc.h:14
#define SERVICE_NO_CHANGE
Definition: winsvc.h:20
#define SERVICE_CHANGE_CONFIG
Definition: winsvc.h:54
#define SERVICES_ACTIVE_DATABASE
Definition: winsvc.h:564

Referenced by DoRpcSsSetupConfiguration().

◆ RunningAsSYSTEM()

static BOOL RunningAsSYSTEM ( VOID  )
static

Definition at line 53 of file setup.c.

54{
55 /* S-1-5-18 -- Local System */
56 static SID SystemSid = { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_LOCAL_SYSTEM_RID } };
57
58 BOOL bRet = FALSE;
59 PTOKEN_USER pTokenUser;
60 HANDLE hToken;
61 DWORD cbTokenBuffer = 0;
62
63 /* Get the process token */
65 return FALSE;
66
67 /* Retrieve token's information */
68 if (GetTokenInformation(hToken, TokenUser, NULL, 0, &cbTokenBuffer) ||
70 {
71 goto Quit;
72 }
73
74 pTokenUser = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cbTokenBuffer);
75 if (!pTokenUser)
76 goto Quit;
77
78 if (GetTokenInformation(hToken, TokenUser, pTokenUser, cbTokenBuffer, &cbTokenBuffer))
79 {
80 /* Compare with SYSTEM SID */
81 bRet = EqualSid(pTokenUser->User.Sid, &SystemSid);
82 }
83
84 HeapFree(GetProcessHeap(), 0, pTokenUser);
85
86Quit:
87 CloseHandle(hToken);
88 return bRet;
89}
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define FALSE
Definition: types.h:117
BOOL WINAPI GetTokenInformation(HANDLE TokenHandle, TOKEN_INFORMATION_CLASS TokenInformationClass, LPVOID TokenInformation, DWORD TokenInformationLength, PDWORD ReturnLength)
Definition: security.c:411
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:294
BOOL WINAPI EqualSid(PSID pSid1, PSID pSid2)
Definition: security.c:829
#define CloseHandle
Definition: compat.h:739
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define GetCurrentProcess()
Definition: compat.h:759
#define HeapFree(x, y, z)
Definition: compat.h:735
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
SID_AND_ATTRIBUTES User
Definition: setypes.h:1010
#define TOKEN_QUERY
Definition: setypes.h:928
#define SECURITY_LOCAL_SYSTEM_RID
Definition: setypes.h:574
@ TokenUser
Definition: setypes.h:966

Referenced by DoRpcSsSetupConfiguration().

◆ SetupIsActive()

static BOOL SetupIsActive ( VOID  )
static

Definition at line 27 of file setup.c.

28{
29 LONG lResult;
30 HKEY hKey;
31 DWORD dwData = 0;
32 DWORD cbData = sizeof(dwData);
33 DWORD dwType = REG_NONE;
34
35 lResult = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\Setup", 0, KEY_QUERY_VALUE, &hKey);
36 if (lResult != ERROR_SUCCESS)
37 return FALSE;
38
39 lResult = RegQueryValueExW(hKey, L"SystemSetupInProgress", NULL,
40 &dwType, (LPBYTE)&dwData, &cbData);
42
43 if ((lResult == ERROR_SUCCESS) && (dwType == REG_DWORD) &&
44 (cbData == sizeof(dwData)) && (dwData == 1))
45 {
46 return TRUE;
47 }
48
49 return FALSE;
50}
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_SUCCESS
Definition: deptool.c:10
#define TRUE
Definition: types.h:120
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
FxAutoRegKey hKey
static HANDLE ULONG_PTR dwData
Definition: file.c:35
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define REG_NONE
Definition: nt_native.h:1492
long LONG
Definition: pedump.c:60
#define REG_DWORD
Definition: sdbapi.c:596
unsigned char * LPBYTE
Definition: typedefs.h:53
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by DoRpcSsSetupConfiguration(), and InitializePnPManager().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( rpcss  )