Author: ekohl Date: Sat Sep 20 15:28:23 2008 New Revision: 36357
URL: http://svn.reactos.org/svn/reactos?rev=36357&view=rev Log: [FORMATTING] No code changes!
Modified: trunk/reactos/dll/win32/advapi32/misc/hwprofiles.c trunk/reactos/dll/win32/advapi32/misc/logon.c trunk/reactos/dll/win32/advapi32/misc/shutdown.c
Modified: trunk/reactos/dll/win32/advapi32/misc/hwprofiles.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/advapi32/misc/hwp... ============================================================================== --- trunk/reactos/dll/win32/advapi32/misc/hwprofiles.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/advapi32/misc/hwprofiles.c [iso-8859-1] Sat Sep 20 15:28:23 2008 @@ -30,53 +30,53 @@ BOOL STDCALL GetCurrentHwProfileA(LPHW_PROFILE_INFOA lpHwProfileInfo) { - HW_PROFILE_INFOW ProfileInfo; - UNICODE_STRING StringU; - ANSI_STRING StringA; - BOOL bResult; - NTSTATUS Status; + HW_PROFILE_INFOW ProfileInfo; + UNICODE_STRING StringU; + ANSI_STRING StringA; + BOOL bResult; + NTSTATUS Status;
- TRACE("GetCurrentHwProfileA() called\n"); + TRACE("GetCurrentHwProfileA() called\n");
- bResult = GetCurrentHwProfileW(&ProfileInfo); - if (bResult == FALSE) - return FALSE; + bResult = GetCurrentHwProfileW(&ProfileInfo); + if (bResult == FALSE) + return FALSE;
- lpHwProfileInfo->dwDockInfo = ProfileInfo.dwDockInfo; + lpHwProfileInfo->dwDockInfo = ProfileInfo.dwDockInfo;
- /* Convert the profile GUID to ANSI */ - StringU.Buffer = (PWCHAR)ProfileInfo.szHwProfileGuid; - StringU.Length = wcslen(ProfileInfo.szHwProfileGuid) * sizeof(WCHAR); - StringU.MaximumLength = HW_PROFILE_GUIDLEN * sizeof(WCHAR); - StringA.Buffer = (PCHAR)&lpHwProfileInfo->szHwProfileGuid; - StringA.Length = 0; - StringA.MaximumLength = HW_PROFILE_GUIDLEN; - Status = RtlUnicodeStringToAnsiString(&StringA, - &StringU, - FALSE); - if (!NT_SUCCESS(Status)) + /* Convert the profile GUID to ANSI */ + StringU.Buffer = (PWCHAR)ProfileInfo.szHwProfileGuid; + StringU.Length = wcslen(ProfileInfo.szHwProfileGuid) * sizeof(WCHAR); + StringU.MaximumLength = HW_PROFILE_GUIDLEN * sizeof(WCHAR); + StringA.Buffer = (PCHAR)&lpHwProfileInfo->szHwProfileGuid; + StringA.Length = 0; + StringA.MaximumLength = HW_PROFILE_GUIDLEN; + Status = RtlUnicodeStringToAnsiString(&StringA, + &StringU, + FALSE); + if (!NT_SUCCESS(Status)) { - SetLastError(RtlNtStatusToDosError(Status)); - return FALSE; + SetLastError(RtlNtStatusToDosError(Status)); + return FALSE; }
- /* Convert the profile name to ANSI */ - StringU.Buffer = (PWCHAR)ProfileInfo.szHwProfileName; - StringU.Length = wcslen(ProfileInfo.szHwProfileName) * sizeof(WCHAR); - StringU.MaximumLength = MAX_PROFILE_LEN * sizeof(WCHAR); - StringA.Buffer = (PCHAR)&lpHwProfileInfo->szHwProfileName; - StringA.Length = 0; - StringA.MaximumLength = MAX_PROFILE_LEN; - Status = RtlUnicodeStringToAnsiString(&StringA, - &StringU, - FALSE); - if (!NT_SUCCESS(Status)) + /* Convert the profile name to ANSI */ + StringU.Buffer = (PWCHAR)ProfileInfo.szHwProfileName; + StringU.Length = wcslen(ProfileInfo.szHwProfileName) * sizeof(WCHAR); + StringU.MaximumLength = MAX_PROFILE_LEN * sizeof(WCHAR); + StringA.Buffer = (PCHAR)&lpHwProfileInfo->szHwProfileName; + StringA.Length = 0; + StringA.MaximumLength = MAX_PROFILE_LEN; + Status = RtlUnicodeStringToAnsiString(&StringA, + &StringU, + FALSE); + if (!NT_SUCCESS(Status)) { - SetLastError(RtlNtStatusToDosError(Status)); - return FALSE; + SetLastError(RtlNtStatusToDosError(Status)); + return FALSE; }
- return TRUE; + return TRUE; }
@@ -86,114 +86,114 @@ BOOL STDCALL GetCurrentHwProfileW(LPHW_PROFILE_INFOW lpHwProfileInfo) { - WCHAR szKeyName[256]; - HKEY hDbKey; - HKEY hProfileKey; - DWORD dwLength; - DWORD dwConfigId; + WCHAR szKeyName[256]; + HKEY hDbKey; + HKEY hProfileKey; + DWORD dwLength; + DWORD dwConfigId;
- TRACE("GetCurrentHwProfileW() called\n"); + TRACE("GetCurrentHwProfileW() called\n");
- if (lpHwProfileInfo == NULL) + if (lpHwProfileInfo == NULL) { - SetLastError(ERROR_INVALID_PARAMETER); - return FALSE; + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; }
- if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, - L"System\CurrentControlSet\Control\IDConfigDB", - 0, - KEY_QUERY_VALUE, - &hDbKey)) + if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, + L"System\CurrentControlSet\Control\IDConfigDB", + 0, + KEY_QUERY_VALUE, + &hDbKey)) { - SetLastError(ERROR_REGISTRY_CORRUPT); - return FALSE; + SetLastError(ERROR_REGISTRY_CORRUPT); + return FALSE; }
- dwLength = sizeof(DWORD); - if (RegQueryValueExW(hDbKey, - L"CurrentConfig", - 0, - NULL, - (LPBYTE)&dwConfigId, - &dwLength)) + dwLength = sizeof(DWORD); + if (RegQueryValueExW(hDbKey, + L"CurrentConfig", + 0, + NULL, + (LPBYTE)&dwConfigId, + &dwLength)) { - RegCloseKey(hDbKey); - SetLastError(ERROR_REGISTRY_CORRUPT); - return FALSE; + RegCloseKey(hDbKey); + SetLastError(ERROR_REGISTRY_CORRUPT); + return FALSE; }
- swprintf(szKeyName, - L"Hardware Profile\%04lu", - dwConfigId); + swprintf(szKeyName, + L"Hardware Profile\%04lu", + dwConfigId);
- if (RegOpenKeyExW(hDbKey, - szKeyName, - 0, - KEY_QUERY_VALUE | KEY_SET_VALUE, - &hProfileKey)) + if (RegOpenKeyExW(hDbKey, + szKeyName, + 0, + KEY_QUERY_VALUE | KEY_SET_VALUE, + &hProfileKey)) { - RegCloseKey(hDbKey); - SetLastError(ERROR_REGISTRY_CORRUPT); - return FALSE; + RegCloseKey(hDbKey); + SetLastError(ERROR_REGISTRY_CORRUPT); + return FALSE; }
- dwLength = sizeof(DWORD); - if (RegQueryValueExW(hProfileKey, - L"DockState", - 0, - NULL, - (LPBYTE)&lpHwProfileInfo->dwDockInfo, - &dwLength)) + dwLength = sizeof(DWORD); + if (RegQueryValueExW(hProfileKey, + L"DockState", + 0, + NULL, + (LPBYTE)&lpHwProfileInfo->dwDockInfo, + &dwLength)) { - lpHwProfileInfo->dwDockInfo = - DOCKINFO_DOCKED | DOCKINFO_UNDOCKED | DOCKINFO_USER_SUPPLIED; + lpHwProfileInfo->dwDockInfo = + DOCKINFO_DOCKED | DOCKINFO_UNDOCKED | DOCKINFO_USER_SUPPLIED; }
- dwLength = HW_PROFILE_GUIDLEN * sizeof(WCHAR); - if (RegQueryValueExW(hProfileKey, - L"HwProfileGuid", - 0, - NULL, - (LPBYTE)&lpHwProfileInfo->szHwProfileGuid, - &dwLength)) + dwLength = HW_PROFILE_GUIDLEN * sizeof(WCHAR); + if (RegQueryValueExW(hProfileKey, + L"HwProfileGuid", + 0, + NULL, + (LPBYTE)&lpHwProfileInfo->szHwProfileGuid, + &dwLength)) { - /* FIXME: Create a new GUID */ - wcscpy(lpHwProfileInfo->szHwProfileGuid, - L"{00000000-0000-0000-0000-000000000000}"); + /* FIXME: Create a new GUID */ + wcscpy(lpHwProfileInfo->szHwProfileGuid, + L"{00000000-0000-0000-0000-000000000000}");
- dwLength = (wcslen(lpHwProfileInfo->szHwProfileGuid) + 1) * sizeof(WCHAR); - RegSetValueExW(hProfileKey, - L"HwProfileGuid", - 0, - REG_SZ, - (LPBYTE)lpHwProfileInfo->szHwProfileGuid, - dwLength); + dwLength = (wcslen(lpHwProfileInfo->szHwProfileGuid) + 1) * sizeof(WCHAR); + RegSetValueExW(hProfileKey, + L"HwProfileGuid", + 0, + REG_SZ, + (LPBYTE)lpHwProfileInfo->szHwProfileGuid, + dwLength); }
- dwLength = MAX_PROFILE_LEN * sizeof(WCHAR); - if (RegQueryValueExW(hProfileKey, - L"FriendlyName", - 0, - NULL, - (LPBYTE)&lpHwProfileInfo->szHwProfileName, - &dwLength)) + dwLength = MAX_PROFILE_LEN * sizeof(WCHAR); + if (RegQueryValueExW(hProfileKey, + L"FriendlyName", + 0, + NULL, + (LPBYTE)&lpHwProfileInfo->szHwProfileName, + &dwLength)) { - wcscpy(lpHwProfileInfo->szHwProfileName, - L"Noname Hardware Profile"); - dwLength = (wcslen(lpHwProfileInfo->szHwProfileName) + 1) * sizeof(WCHAR); - RegSetValueExW(hProfileKey, - L"FriendlyName", - 0, - REG_SZ, - (LPBYTE)lpHwProfileInfo->szHwProfileName, - dwLength); + wcscpy(lpHwProfileInfo->szHwProfileName, + L"Noname Hardware Profile"); + dwLength = (wcslen(lpHwProfileInfo->szHwProfileName) + 1) * sizeof(WCHAR); + RegSetValueExW(hProfileKey, + L"FriendlyName", + 0, + REG_SZ, + (LPBYTE)lpHwProfileInfo->szHwProfileName, + dwLength); }
- RegCloseKey(hProfileKey); - RegCloseKey(hDbKey); + RegCloseKey(hProfileKey); + RegCloseKey(hDbKey);
- return TRUE; + return TRUE; }
/* EOF */
Modified: trunk/reactos/dll/win32/advapi32/misc/logon.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/advapi32/misc/log... ============================================================================== --- trunk/reactos/dll/win32/advapi32/misc/logon.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/advapi32/misc/logon.c [iso-8859-1] Sat Sep 20 15:28:23 2008 @@ -18,57 +18,57 @@ * @implemented */ BOOL STDCALL -CreateProcessAsUserA (HANDLE hToken, - LPCSTR lpApplicationName, - LPSTR lpCommandLine, - LPSECURITY_ATTRIBUTES lpProcessAttributes, - LPSECURITY_ATTRIBUTES lpThreadAttributes, - BOOL bInheritHandles, - DWORD dwCreationFlags, - LPVOID lpEnvironment, - LPCSTR lpCurrentDirectory, - LPSTARTUPINFOA lpStartupInfo, - LPPROCESS_INFORMATION lpProcessInformation) +CreateProcessAsUserA(HANDLE hToken, + LPCSTR lpApplicationName, + LPSTR lpCommandLine, + LPSECURITY_ATTRIBUTES lpProcessAttributes, + LPSECURITY_ATTRIBUTES lpThreadAttributes, + BOOL bInheritHandles, + DWORD dwCreationFlags, + LPVOID lpEnvironment, + LPCSTR lpCurrentDirectory, + LPSTARTUPINFOA lpStartupInfo, + LPPROCESS_INFORMATION lpProcessInformation) { - PROCESS_ACCESS_TOKEN AccessToken; - NTSTATUS Status; - - /* Create the process with a suspended main thread */ - if (!CreateProcessA (lpApplicationName, - lpCommandLine, - lpProcessAttributes, - lpThreadAttributes, - bInheritHandles, - dwCreationFlags | CREATE_SUSPENDED, - lpEnvironment, - lpCurrentDirectory, - lpStartupInfo, - lpProcessInformation)) - { - return FALSE; - } - - AccessToken.Token = hToken; - AccessToken.Thread = NULL; - - /* Set the new process token */ - Status = NtSetInformationProcess (lpProcessInformation->hProcess, - ProcessAccessToken, - (PVOID)&AccessToken, - sizeof (AccessToken)); - if (!NT_SUCCESS (Status)) - { - SetLastError (RtlNtStatusToDosError (Status)); - return FALSE; - } - - /* Resume the main thread */ - if (!(dwCreationFlags & CREATE_SUSPENDED)) - { - ResumeThread (lpProcessInformation->hThread); - } - - return TRUE; + PROCESS_ACCESS_TOKEN AccessToken; + NTSTATUS Status; + + /* Create the process with a suspended main thread */ + if (!CreateProcessA(lpApplicationName, + lpCommandLine, + lpProcessAttributes, + lpThreadAttributes, + bInheritHandles, + dwCreationFlags | CREATE_SUSPENDED, + lpEnvironment, + lpCurrentDirectory, + lpStartupInfo, + lpProcessInformation)) + { + return FALSE; + } + + AccessToken.Token = hToken; + AccessToken.Thread = NULL; + + /* Set the new process token */ + Status = NtSetInformationProcess(lpProcessInformation->hProcess, + ProcessAccessToken, + (PVOID)&AccessToken, + sizeof(AccessToken)); + if (!NT_SUCCESS (Status)) + { + SetLastError(RtlNtStatusToDosError(Status)); + return FALSE; + } + + /* Resume the main thread */ + if (!(dwCreationFlags & CREATE_SUSPENDED)) + { + ResumeThread(lpProcessInformation->hThread); + } + + return TRUE; }
@@ -76,57 +76,57 @@ * @implemented */ BOOL STDCALL -CreateProcessAsUserW (HANDLE hToken, - LPCWSTR lpApplicationName, - LPWSTR lpCommandLine, - LPSECURITY_ATTRIBUTES lpProcessAttributes, - LPSECURITY_ATTRIBUTES lpThreadAttributes, - BOOL bInheritHandles, - DWORD dwCreationFlags, - LPVOID lpEnvironment, - LPCWSTR lpCurrentDirectory, - LPSTARTUPINFOW lpStartupInfo, - LPPROCESS_INFORMATION lpProcessInformation) +CreateProcessAsUserW(HANDLE hToken, + LPCWSTR lpApplicationName, + LPWSTR lpCommandLine, + LPSECURITY_ATTRIBUTES lpProcessAttributes, + LPSECURITY_ATTRIBUTES lpThreadAttributes, + BOOL bInheritHandles, + DWORD dwCreationFlags, + LPVOID lpEnvironment, + LPCWSTR lpCurrentDirectory, + LPSTARTUPINFOW lpStartupInfo, + LPPROCESS_INFORMATION lpProcessInformation) { - PROCESS_ACCESS_TOKEN AccessToken; - NTSTATUS Status; - - /* Create the process with a suspended main thread */ - if (!CreateProcessW (lpApplicationName, - lpCommandLine, - lpProcessAttributes, - lpThreadAttributes, - bInheritHandles, - dwCreationFlags | CREATE_SUSPENDED, - lpEnvironment, - lpCurrentDirectory, - lpStartupInfo, - lpProcessInformation)) - { - return FALSE; - } - - AccessToken.Token = hToken; - AccessToken.Thread = NULL; - - /* Set the new process token */ - Status = NtSetInformationProcess (lpProcessInformation->hProcess, - ProcessAccessToken, - (PVOID)&AccessToken, - sizeof (AccessToken)); - if (!NT_SUCCESS (Status)) - { - SetLastError (RtlNtStatusToDosError (Status)); - return FALSE; - } - - /* Resume the main thread */ - if (!(dwCreationFlags & CREATE_SUSPENDED)) - { - ResumeThread (lpProcessInformation->hThread); - } - - return TRUE; + PROCESS_ACCESS_TOKEN AccessToken; + NTSTATUS Status; + + /* Create the process with a suspended main thread */ + if (!CreateProcessW(lpApplicationName, + lpCommandLine, + lpProcessAttributes, + lpThreadAttributes, + bInheritHandles, + dwCreationFlags | CREATE_SUSPENDED, + lpEnvironment, + lpCurrentDirectory, + lpStartupInfo, + lpProcessInformation)) + { + return FALSE; + } + + AccessToken.Token = hToken; + AccessToken.Thread = NULL; + + /* Set the new process token */ + Status = NtSetInformationProcess(lpProcessInformation->hProcess, + ProcessAccessToken, + (PVOID)&AccessToken, + sizeof(AccessToken)); + if (!NT_SUCCESS (Status)) + { + SetLastError(RtlNtStatusToDosError(Status)); + return FALSE; + } + + /* Resume the main thread */ + if (!(dwCreationFlags & CREATE_SUSPENDED)) + { + ResumeThread(lpProcessInformation->hThread); + } + + return TRUE; }
@@ -199,215 +199,214 @@
static BOOL STDCALL -SamGetUserSid (LPCWSTR UserName, - PSID *Sid) +SamGetUserSid(LPCWSTR UserName, + PSID *Sid) { - PSID lpSid; - DWORD dwLength; - HKEY hUsersKey; - HKEY hUserKey; - - if (Sid != NULL) - *Sid = NULL; - - /* Open the Users key */ - if (RegOpenKeyExW (HKEY_LOCAL_MACHINE, - L"SAM\SAM\Domains\Account\Users", - 0, - KEY_READ, - &hUsersKey)) - { - ERR("Failed to open Users key! (Error %lu)\n", GetLastError()); - return FALSE; - } - - /* Open the user key */ - if (RegOpenKeyExW (hUsersKey, - UserName, - 0, - KEY_READ, - &hUserKey)) - { - if (GetLastError () == ERROR_FILE_NOT_FOUND) - { - ERR("Invalid user name!\n"); - SetLastError (ERROR_NO_SUCH_USER); - } - else - { - ERR("Failed to open user key! (Error %lu)\n", GetLastError()); - } - - RegCloseKey (hUsersKey); - return FALSE; - } - - RegCloseKey (hUsersKey); - - /* Get SID size */ - dwLength = 0; - if (RegQueryValueExW (hUserKey, - L"Sid", - NULL, - NULL, - NULL, - &dwLength)) - { - ERR("Failed to read the SID size! (Error %lu)\n", GetLastError()); - RegCloseKey (hUserKey); - return FALSE; - } - - /* Allocate sid buffer */ - TRACE("Required SID buffer size: %lu\n", dwLength); - lpSid = (PSID)RtlAllocateHeap (RtlGetProcessHeap (), - 0, - dwLength); - if (lpSid == NULL) - { - ERR("Failed to allocate SID buffer!\n"); - RegCloseKey (hUserKey); - return FALSE; - } - - /* Read sid */ - if (RegQueryValueExW (hUserKey, - L"Sid", - NULL, - NULL, - (LPBYTE)lpSid, - &dwLength)) - { - ERR("Failed to read the SID! (Error %lu)\n", GetLastError()); - RtlFreeHeap (RtlGetProcessHeap (), - 0, - lpSid); - RegCloseKey (hUserKey); - return FALSE; - } - - RegCloseKey (hUserKey); - - *Sid = lpSid; - - return TRUE; + PSID lpSid; + DWORD dwLength; + HKEY hUsersKey; + HKEY hUserKey; + + if (Sid != NULL) + *Sid = NULL; + + /* Open the Users key */ + if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, + L"SAM\SAM\Domains\Account\Users", + 0, + KEY_READ, + &hUsersKey)) + { + ERR("Failed to open Users key! (Error %lu)\n", GetLastError()); + return FALSE; + } + + /* Open the user key */ + if (RegOpenKeyExW(hUsersKey, + UserName, + 0, + KEY_READ, + &hUserKey)) + { + if (GetLastError() == ERROR_FILE_NOT_FOUND) + { + ERR("Invalid user name!\n"); + SetLastError(ERROR_NO_SUCH_USER); + } + else + { + ERR("Failed to open user key! (Error %lu)\n", GetLastError()); + } + + RegCloseKey(hUsersKey); + return FALSE; + } + + RegCloseKey (hUsersKey); + + /* Get SID size */ + dwLength = 0; + if (RegQueryValueExW(hUserKey, + L"Sid", + NULL, + NULL, + NULL, + &dwLength)) + { + ERR("Failed to read the SID size! (Error %lu)\n", GetLastError()); + RegCloseKey(hUserKey); + return FALSE; + } + + /* Allocate sid buffer */ + TRACE("Required SID buffer size: %lu\n", dwLength); + lpSid = (PSID)RtlAllocateHeap(RtlGetProcessHeap(), + 0, + dwLength); + if (lpSid == NULL) + { + ERR("Failed to allocate SID buffer!\n"); + RegCloseKey(hUserKey); + return FALSE; + } + + /* Read sid */ + if (RegQueryValueExW(hUserKey, + L"Sid", + NULL, + NULL, + (LPBYTE)lpSid, + &dwLength)) + { + ERR("Failed to read the SID! (Error %lu)\n", GetLastError()); + RtlFreeHeap(RtlGetProcessHeap(), + 0, + lpSid); + RegCloseKey(hUserKey); + return FALSE; + } + + RegCloseKey(hUserKey); + + *Sid = lpSid; + + return TRUE; }
static BOOL STDCALL SamGetDomainSid(PSID *Sid) { - PSID lpSid; - DWORD dwLength; - HKEY hDomainKey; - - TRACE("SamGetDomainSid() called\n"); - - if (Sid != NULL) - *Sid = NULL; - - /* Open the account domain key */ - if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, - L"SAM\SAM\Domains\Account", - 0, - KEY_READ, - &hDomainKey)) - { - ERR("Failed to open the account domain key! (Error %lu)\n", GetLastError()); - return FALSE; - } - - /* Get SID size */ - dwLength = 0; - if (RegQueryValueExW(hDomainKey, - L"Sid", - NULL, - NULL, - NULL, - &dwLength)) - { - ERR("Failed to read the SID size! (Error %lu)\n", GetLastError()); - RegCloseKey(hDomainKey); - return FALSE; - } - - /* Allocate sid buffer */ - TRACE("Required SID buffer size: %lu\n", dwLength); - lpSid = (PSID)RtlAllocateHeap(RtlGetProcessHeap(), - 0, - dwLength); - if (lpSid == NULL) - { - ERR("Failed to allocate SID buffer!\n"); - RegCloseKey(hDomainKey); - return FALSE; - } - - /* Read sid */ - if (RegQueryValueExW(hDomainKey, - L"Sid", - NULL, - NULL, - (LPBYTE)lpSid, - &dwLength)) - { - ERR("Failed to read the SID! (Error %lu)\n", GetLastError()); - RtlFreeHeap(RtlGetProcessHeap(), - 0, - lpSid); - RegCloseKey(hDomainKey); - return FALSE; - } - - RegCloseKey(hDomainKey); - - *Sid = lpSid; - - TRACE("SamGetDomainSid() done\n"); - - return TRUE; + PSID lpSid; + DWORD dwLength; + HKEY hDomainKey; + + TRACE("SamGetDomainSid() called\n"); + + if (Sid != NULL) + *Sid = NULL; + + /* Open the account domain key */ + if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, + L"SAM\SAM\Domains\Account", + 0, + KEY_READ, + &hDomainKey)) + { + ERR("Failed to open the account domain key! (Error %lu)\n", GetLastError()); + return FALSE; + } + + /* Get SID size */ + dwLength = 0; + if (RegQueryValueExW(hDomainKey, + L"Sid", + NULL, + NULL, + NULL, + &dwLength)) + { + ERR("Failed to read the SID size! (Error %lu)\n", GetLastError()); + RegCloseKey(hDomainKey); + return FALSE; + } + + /* Allocate sid buffer */ + TRACE("Required SID buffer size: %lu\n", dwLength); + lpSid = (PSID)RtlAllocateHeap(RtlGetProcessHeap(), + 0, + dwLength); + if (lpSid == NULL) + { + ERR("Failed to allocate SID buffer!\n"); + RegCloseKey(hDomainKey); + return FALSE; + } + + /* Read sid */ + if (RegQueryValueExW(hDomainKey, + L"Sid", + NULL, + NULL, + (LPBYTE)lpSid, + &dwLength)) + { + ERR("Failed to read the SID! (Error %lu)\n", GetLastError()); + RtlFreeHeap(RtlGetProcessHeap(), + 0, + lpSid); + RegCloseKey(hDomainKey); + return FALSE; + } + + RegCloseKey(hDomainKey); + + *Sid = lpSid; + + TRACE("SamGetDomainSid() done\n"); + + return TRUE; }
static PSID AppendRidToSid(PSID SrcSid, - ULONG Rid) + ULONG Rid) { - ULONG Rids[8] = {0, 0, 0, 0, 0, 0, 0, 0}; - UCHAR RidCount; - PSID DstSid; - ULONG i; - - RidCount = *RtlSubAuthorityCountSid(SrcSid); - if (RidCount >= 8) - return NULL; - - for (i = 0; i < RidCount; i++) - Rids[i] = *RtlSubAuthoritySid(SrcSid, i); - - Rids[RidCount] = Rid; - RidCount++; - - RtlAllocateAndInitializeSid(RtlIdentifierAuthoritySid(SrcSid), - RidCount, - Rids[0], - Rids[1], - Rids[2], - Rids[3], - Rids[4], - Rids[5], - Rids[6], - Rids[7], - &DstSid); - - return DstSid; + ULONG Rids[8] = {0, 0, 0, 0, 0, 0, 0, 0}; + UCHAR RidCount; + PSID DstSid; + ULONG i; + + RidCount = *RtlSubAuthorityCountSid(SrcSid); + if (RidCount >= 8) + return NULL; + + for (i = 0; i < RidCount; i++) + Rids[i] = *RtlSubAuthoritySid(SrcSid, i); + + Rids[RidCount] = Rid; + RidCount++; + + RtlAllocateAndInitializeSid(RtlIdentifierAuthoritySid(SrcSid), + RidCount, + Rids[0], + Rids[1], + Rids[2], + Rids[3], + Rids[4], + Rids[5], + Rids[6], + Rids[7], + &DstSid); + + return DstSid; }
static PTOKEN_GROUPS -AllocateGroupSids( - OUT PSID *PrimaryGroupSid, - OUT PSID *OwnerSid) +AllocateGroupSids(OUT PSID *PrimaryGroupSid, + OUT PSID *OwnerSid) { SID_IDENTIFIER_AUTHORITY WorldAuthority = {SECURITY_WORLD_SID_AUTHORITY}; SID_IDENTIFIER_AUTHORITY LocalAuthority = {SECURITY_LOCAL_SID_AUTHORITY}; @@ -442,132 +441,133 @@
/* Member of the domain */ TokenGroups->Groups[GroupCount].Sid = Sid; - TokenGroups->Groups[GroupCount].Attributes = SE_GROUP_ENABLED | SE_GROUP_ENABLED_BY_DEFAULT | SE_GROUP_MANDATORY; + TokenGroups->Groups[GroupCount].Attributes = + SE_GROUP_ENABLED | SE_GROUP_ENABLED_BY_DEFAULT | SE_GROUP_MANDATORY; *PrimaryGroupSid = Sid; GroupCount++;
/* Member of 'Everyone' */ - RtlAllocateAndInitializeSid( - &WorldAuthority, - 1, - SECURITY_WORLD_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - &Sid); + RtlAllocateAndInitializeSid(&WorldAuthority, + 1, + SECURITY_WORLD_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + &Sid); TokenGroups->Groups[GroupCount].Sid = Sid; - TokenGroups->Groups[GroupCount].Attributes = SE_GROUP_ENABLED | SE_GROUP_ENABLED_BY_DEFAULT | SE_GROUP_MANDATORY; + TokenGroups->Groups[GroupCount].Attributes = + SE_GROUP_ENABLED | SE_GROUP_ENABLED_BY_DEFAULT | SE_GROUP_MANDATORY; GroupCount++;
#if 1 /* Member of 'Administrators' */ - RtlAllocateAndInitializeSid( - &SystemAuthority, - 2, - SECURITY_BUILTIN_DOMAIN_RID, - DOMAIN_ALIAS_RID_ADMINS, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - &Sid); + RtlAllocateAndInitializeSid(&SystemAuthority, + 2, + SECURITY_BUILTIN_DOMAIN_RID, + DOMAIN_ALIAS_RID_ADMINS, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + &Sid); TokenGroups->Groups[GroupCount].Sid = Sid; - TokenGroups->Groups[GroupCount].Attributes = SE_GROUP_ENABLED | SE_GROUP_ENABLED_BY_DEFAULT | SE_GROUP_MANDATORY; + TokenGroups->Groups[GroupCount].Attributes = + SE_GROUP_ENABLED | SE_GROUP_ENABLED_BY_DEFAULT | SE_GROUP_MANDATORY; GroupCount++; #else TRACE("Not adding user to Administrators group\n"); #endif
/* Member of 'Users' */ - RtlAllocateAndInitializeSid( - &SystemAuthority, - 2, - SECURITY_BUILTIN_DOMAIN_RID, - DOMAIN_ALIAS_RID_USERS, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - &Sid); + RtlAllocateAndInitializeSid(&SystemAuthority, + 2, + SECURITY_BUILTIN_DOMAIN_RID, + DOMAIN_ALIAS_RID_USERS, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + &Sid); TokenGroups->Groups[GroupCount].Sid = Sid; - TokenGroups->Groups[GroupCount].Attributes = SE_GROUP_ENABLED | SE_GROUP_ENABLED_BY_DEFAULT | SE_GROUP_MANDATORY; + TokenGroups->Groups[GroupCount].Attributes = + SE_GROUP_ENABLED | SE_GROUP_ENABLED_BY_DEFAULT | SE_GROUP_MANDATORY; GroupCount++;
/* Logon SID */ - RtlAllocateAndInitializeSid( - &SystemAuthority, - SECURITY_LOGON_IDS_RID_COUNT, - SECURITY_LOGON_IDS_RID, - Luid.HighPart, - Luid.LowPart, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - &Sid); + RtlAllocateAndInitializeSid(&SystemAuthority, + SECURITY_LOGON_IDS_RID_COUNT, + SECURITY_LOGON_IDS_RID, + Luid.HighPart, + Luid.LowPart, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + &Sid); TokenGroups->Groups[GroupCount].Sid = Sid; - TokenGroups->Groups[GroupCount].Attributes = SE_GROUP_ENABLED | SE_GROUP_ENABLED_BY_DEFAULT | SE_GROUP_MANDATORY | SE_GROUP_LOGON_ID; + TokenGroups->Groups[GroupCount].Attributes = + SE_GROUP_ENABLED | SE_GROUP_ENABLED_BY_DEFAULT | SE_GROUP_MANDATORY | SE_GROUP_LOGON_ID; GroupCount++; *OwnerSid = Sid;
/* Member of 'Local users */ - RtlAllocateAndInitializeSid( - &LocalAuthority, - 1, - SECURITY_LOCAL_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - &Sid); + RtlAllocateAndInitializeSid(&LocalAuthority, + 1, + SECURITY_LOCAL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + &Sid); TokenGroups->Groups[GroupCount].Sid = Sid; - TokenGroups->Groups[GroupCount].Attributes = SE_GROUP_ENABLED | SE_GROUP_ENABLED_BY_DEFAULT | SE_GROUP_MANDATORY; + TokenGroups->Groups[GroupCount].Attributes = + SE_GROUP_ENABLED | SE_GROUP_ENABLED_BY_DEFAULT | SE_GROUP_MANDATORY; GroupCount++;
/* Member of 'Interactive users' */ - RtlAllocateAndInitializeSid( - &SystemAuthority, - 1, - SECURITY_INTERACTIVE_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - &Sid); + RtlAllocateAndInitializeSid(&SystemAuthority, + 1, + SECURITY_INTERACTIVE_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + &Sid); TokenGroups->Groups[GroupCount].Sid = Sid; - TokenGroups->Groups[GroupCount].Attributes = SE_GROUP_ENABLED | SE_GROUP_ENABLED_BY_DEFAULT | SE_GROUP_MANDATORY; + TokenGroups->Groups[GroupCount].Attributes = + SE_GROUP_ENABLED | SE_GROUP_ENABLED_BY_DEFAULT | SE_GROUP_MANDATORY; GroupCount++;
/* Member of 'Authenticated users' */ - RtlAllocateAndInitializeSid( - &SystemAuthority, - 1, - SECURITY_AUTHENTICATED_USER_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - &Sid); + RtlAllocateAndInitializeSid(&SystemAuthority, + 1, + SECURITY_AUTHENTICATED_USER_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + &Sid); TokenGroups->Groups[GroupCount].Sid = Sid; - TokenGroups->Groups[GroupCount].Attributes = SE_GROUP_ENABLED | SE_GROUP_ENABLED_BY_DEFAULT | SE_GROUP_MANDATORY; + TokenGroups->Groups[GroupCount].Attributes = + SE_GROUP_ENABLED | SE_GROUP_ENABLED_BY_DEFAULT | SE_GROUP_MANDATORY; GroupCount++;
TokenGroups->GroupCount = GroupCount; @@ -580,15 +580,15 @@ static VOID FreeGroupSids(PTOKEN_GROUPS TokenGroups) { - ULONG i; - - for (i = 0; i < TokenGroups->GroupCount; i++) - { - if (TokenGroups->Groups[i].Sid != NULL) - RtlFreeHeap(GetProcessHeap(), 0, TokenGroups->Groups[i].Sid); - } - - RtlFreeHeap(GetProcessHeap(), 0, TokenGroups); + ULONG i; + + for (i = 0; i < TokenGroups->GroupCount; i++) + { + if (TokenGroups->Groups[i].Sid != NULL) + RtlFreeHeap(GetProcessHeap(), 0, TokenGroups->Groups[i].Sid); + } + + RtlFreeHeap(GetProcessHeap(), 0, TokenGroups); }
@@ -596,20 +596,20 @@ * @unimplemented */ BOOL STDCALL -LogonUserW (LPWSTR lpszUsername, - LPWSTR lpszDomain, - LPWSTR lpszPassword, - DWORD dwLogonType, - DWORD dwLogonProvider, - PHANDLE phToken) +LogonUserW(LPWSTR lpszUsername, + LPWSTR lpszDomain, + LPWSTR lpszPassword, + DWORD dwLogonType, + DWORD dwLogonProvider, + PHANDLE phToken) { - /* FIXME shouldn't use hard-coded list of privileges */ - static struct + /* FIXME shouldn't use hard-coded list of privileges */ + static struct { LPCWSTR PrivName; DWORD Attributes; } - DefaultPrivs[] = + DefaultPrivs[] = { { L"SeUnsolicitedInputPrivilege", 0 }, { L"SeMachineAccountPrivilege", 0 }, @@ -633,176 +633,178 @@ { L"SeImpersonatePrivilege", SE_PRIVILEGE_ENABLED | SE_PRIVILEGE_ENABLED_BY_DEFAULT }, { L"SeCreateGlobalPrivilege", SE_PRIVILEGE_ENABLED | SE_PRIVILEGE_ENABLED_BY_DEFAULT } }; - OBJECT_ATTRIBUTES ObjectAttributes; - SECURITY_QUALITY_OF_SERVICE Qos; - TOKEN_USER TokenUser; - TOKEN_OWNER TokenOwner; - TOKEN_PRIMARY_GROUP TokenPrimaryGroup; - PTOKEN_GROUPS TokenGroups; - PTOKEN_PRIVILEGES TokenPrivileges; - TOKEN_DEFAULT_DACL TokenDefaultDacl; - LARGE_INTEGER ExpirationTime; - LUID AuthenticationId; - TOKEN_SOURCE TokenSource; - PSID UserSid = NULL; - PSID PrimaryGroupSid = NULL; - PSID OwnerSid = NULL; - PSID LocalSystemSid; - PACL Dacl; - NTSTATUS Status; - SID_IDENTIFIER_AUTHORITY SystemAuthority = {SECURITY_NT_AUTHORITY}; - unsigned i; - - Qos.Length = sizeof(SECURITY_QUALITY_OF_SERVICE); - Qos.ImpersonationLevel = SecurityAnonymous; - Qos.ContextTrackingMode = SECURITY_STATIC_TRACKING; - Qos.EffectiveOnly = FALSE; - - ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES); - ObjectAttributes.RootDirectory = NULL; - ObjectAttributes.ObjectName = NULL; - ObjectAttributes.Attributes = 0; - ObjectAttributes.SecurityDescriptor = NULL; - ObjectAttributes.SecurityQualityOfService = &Qos; - - Status = NtAllocateLocallyUniqueId(&AuthenticationId); - if (!NT_SUCCESS(Status)) - { - return FALSE; - } - ExpirationTime.QuadPart = -1; - - /* Get the user SID from the registry */ - if (!SamGetUserSid (lpszUsername, &UserSid)) - { - ERR("SamGetUserSid() failed\n"); - return FALSE; - } - - TokenUser.User.Sid = UserSid; - TokenUser.User.Attributes = 0; - - /* Allocate and initialize token groups */ - TokenGroups = AllocateGroupSids(&PrimaryGroupSid, - &OwnerSid); - if (NULL == TokenGroups) - { - RtlFreeSid(UserSid); - SetLastError(ERROR_OUTOFMEMORY); - return FALSE; - } - - /* Allocate and initialize token privileges */ - TokenPrivileges = RtlAllocateHeap(GetProcessHeap(), 0, - sizeof(TOKEN_PRIVILEGES) + OBJECT_ATTRIBUTES ObjectAttributes; + SECURITY_QUALITY_OF_SERVICE Qos; + TOKEN_USER TokenUser; + TOKEN_OWNER TokenOwner; + TOKEN_PRIMARY_GROUP TokenPrimaryGroup; + PTOKEN_GROUPS TokenGroups; + PTOKEN_PRIVILEGES TokenPrivileges; + TOKEN_DEFAULT_DACL TokenDefaultDacl; + LARGE_INTEGER ExpirationTime; + LUID AuthenticationId; + TOKEN_SOURCE TokenSource; + PSID UserSid = NULL; + PSID PrimaryGroupSid = NULL; + PSID OwnerSid = NULL; + PSID LocalSystemSid; + PACL Dacl; + NTSTATUS Status; + SID_IDENTIFIER_AUTHORITY SystemAuthority = {SECURITY_NT_AUTHORITY}; + unsigned i; + + Qos.Length = sizeof(SECURITY_QUALITY_OF_SERVICE); + Qos.ImpersonationLevel = SecurityAnonymous; + Qos.ContextTrackingMode = SECURITY_STATIC_TRACKING; + Qos.EffectiveOnly = FALSE; + + ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES); + ObjectAttributes.RootDirectory = NULL; + ObjectAttributes.ObjectName = NULL; + ObjectAttributes.Attributes = 0; + ObjectAttributes.SecurityDescriptor = NULL; + ObjectAttributes.SecurityQualityOfService = &Qos; + + Status = NtAllocateLocallyUniqueId(&AuthenticationId); + if (!NT_SUCCESS(Status)) + { + return FALSE; + } + + ExpirationTime.QuadPart = -1; + + /* Get the user SID from the registry */ + if (!SamGetUserSid (lpszUsername, &UserSid)) + { + ERR("SamGetUserSid() failed\n"); + return FALSE; + } + + TokenUser.User.Sid = UserSid; + TokenUser.User.Attributes = 0; + + /* Allocate and initialize token groups */ + TokenGroups = AllocateGroupSids(&PrimaryGroupSid, + &OwnerSid); + if (NULL == TokenGroups) + { + RtlFreeSid(UserSid); + SetLastError(ERROR_OUTOFMEMORY); + return FALSE; + } + + /* Allocate and initialize token privileges */ + TokenPrivileges = RtlAllocateHeap(GetProcessHeap(), 0, + sizeof(TOKEN_PRIVILEGES) + sizeof(DefaultPrivs) / sizeof(DefaultPrivs[0]) * sizeof(LUID_AND_ATTRIBUTES)); - if (NULL == TokenPrivileges) - { - FreeGroupSids(TokenGroups); - RtlFreeSid(UserSid); - SetLastError(ERROR_OUTOFMEMORY); - return FALSE; - } - - TokenPrivileges->PrivilegeCount = 0; - for (i = 0; i < sizeof(DefaultPrivs) / sizeof(DefaultPrivs[0]); i++) - { - if (! LookupPrivilegeValueW(NULL, DefaultPrivs[i].PrivName, - &TokenPrivileges->Privileges[TokenPrivileges->PrivilegeCount].Luid)) + if (NULL == TokenPrivileges) + { + FreeGroupSids(TokenGroups); + RtlFreeSid(UserSid); + SetLastError(ERROR_OUTOFMEMORY); + return FALSE; + } + + TokenPrivileges->PrivilegeCount = 0; + for (i = 0; i < sizeof(DefaultPrivs) / sizeof(DefaultPrivs[0]); i++) + { + if (! LookupPrivilegeValueW(NULL, + DefaultPrivs[i].PrivName, + &TokenPrivileges->Privileges[TokenPrivileges->PrivilegeCount].Luid)) { - WARN("Can't set privilege %S\n", DefaultPrivs[i].PrivName); + WARN("Can't set privilege %S\n", DefaultPrivs[i].PrivName); } - else + else { - TokenPrivileges->Privileges[TokenPrivileges->PrivilegeCount].Attributes = DefaultPrivs[i].Attributes; - TokenPrivileges->PrivilegeCount++; + TokenPrivileges->Privileges[TokenPrivileges->PrivilegeCount].Attributes = DefaultPrivs[i].Attributes; + TokenPrivileges->PrivilegeCount++; } }
- TokenOwner.Owner = OwnerSid; - TokenPrimaryGroup.PrimaryGroup = PrimaryGroupSid; - - - Dacl = RtlAllocateHeap(GetProcessHeap(), 0, 1024); - if (Dacl == NULL) - { - FreeGroupSids(TokenGroups); - RtlFreeSid(UserSid); - SetLastError(ERROR_OUTOFMEMORY); - return FALSE; - } - - Status = RtlCreateAcl(Dacl, 1024, ACL_REVISION); - if (!NT_SUCCESS(Status)) - { - RtlFreeHeap(GetProcessHeap(), 0, Dacl); - FreeGroupSids(TokenGroups); - RtlFreeHeap(GetProcessHeap(), 0, TokenPrivileges); - RtlFreeSid(UserSid); - return FALSE; - } - - RtlAddAccessAllowedAce(Dacl, - ACL_REVISION, - GENERIC_ALL, - OwnerSid); + TokenOwner.Owner = OwnerSid; + TokenPrimaryGroup.PrimaryGroup = PrimaryGroupSid; + + Dacl = RtlAllocateHeap(GetProcessHeap(), 0, 1024); + if (Dacl == NULL) + { + FreeGroupSids(TokenGroups); + RtlFreeSid(UserSid); + SetLastError(ERROR_OUTOFMEMORY); + return FALSE; + } + + Status = RtlCreateAcl(Dacl, 1024, ACL_REVISION); + if (!NT_SUCCESS(Status)) + { + RtlFreeHeap(GetProcessHeap(), 0, Dacl); + FreeGroupSids(TokenGroups); + RtlFreeHeap(GetProcessHeap(), 0, TokenPrivileges); + RtlFreeSid(UserSid); + return FALSE; + } + + RtlAddAccessAllowedAce(Dacl, + ACL_REVISION, + GENERIC_ALL, + OwnerSid);
RtlAllocateAndInitializeSid(&SystemAuthority, - 1, - SECURITY_LOCAL_SYSTEM_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - SECURITY_NULL_RID, - &LocalSystemSid); - - /* SID: S-1-5-18 */ - RtlAddAccessAllowedAce(Dacl, - ACL_REVISION, - GENERIC_ALL, - LocalSystemSid); - - RtlFreeSid(LocalSystemSid); - - TokenDefaultDacl.DefaultDacl = Dacl; - - memcpy(TokenSource.SourceName, - "User32 ", - 8); - Status = NtAllocateLocallyUniqueId(&TokenSource.SourceIdentifier); - if (!NT_SUCCESS(Status)) - { - RtlFreeHeap(GetProcessHeap(), 0, Dacl); - FreeGroupSids(TokenGroups); - RtlFreeHeap(GetProcessHeap(), 0, TokenPrivileges); - RtlFreeSid(UserSid); - return FALSE; - } - - Status = NtCreateToken(phToken, - TOKEN_ALL_ACCESS, - &ObjectAttributes, - TokenPrimary, - &AuthenticationId, - &ExpirationTime, - &TokenUser, - TokenGroups, - TokenPrivileges, - &TokenOwner, - &TokenPrimaryGroup, - &TokenDefaultDacl, - &TokenSource); - - RtlFreeHeap(GetProcessHeap(), 0, Dacl); - FreeGroupSids(TokenGroups); - RtlFreeHeap(GetProcessHeap(), 0, TokenPrivileges); - RtlFreeSid(UserSid); - - return NT_SUCCESS(Status); + 1, + SECURITY_LOCAL_SYSTEM_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + &LocalSystemSid); + + /* SID: S-1-5-18 */ + RtlAddAccessAllowedAce(Dacl, + ACL_REVISION, + GENERIC_ALL, + LocalSystemSid); + + RtlFreeSid(LocalSystemSid); + + TokenDefaultDacl.DefaultDacl = Dacl; + + memcpy(TokenSource.SourceName, + "User32 ", + 8); + + Status = NtAllocateLocallyUniqueId(&TokenSource.SourceIdentifier); + if (!NT_SUCCESS(Status)) + { + RtlFreeHeap(GetProcessHeap(), 0, Dacl); + FreeGroupSids(TokenGroups); + RtlFreeHeap(GetProcessHeap(), 0, TokenPrivileges); + RtlFreeSid(UserSid); + return FALSE; + } + + Status = NtCreateToken(phToken, + TOKEN_ALL_ACCESS, + &ObjectAttributes, + TokenPrimary, + &AuthenticationId, + &ExpirationTime, + &TokenUser, + TokenGroups, + TokenPrivileges, + &TokenOwner, + &TokenPrimaryGroup, + &TokenDefaultDacl, + &TokenSource); + + RtlFreeHeap(GetProcessHeap(), 0, Dacl); + FreeGroupSids(TokenGroups); + RtlFreeHeap(GetProcessHeap(), 0, TokenPrivileges); + RtlFreeSid(UserSid); + + return NT_SUCCESS(Status); }
/* EOF */
Modified: trunk/reactos/dll/win32/advapi32/misc/shutdown.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/advapi32/misc/shu... ============================================================================== --- trunk/reactos/dll/win32/advapi32/misc/shutdown.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/advapi32/misc/shutdown.c [iso-8859-1] Sat Sep 20 15:28:23 2008 @@ -43,10 +43,12 @@
RtlInitAnsiString(&MachineNameA, (LPSTR)lpMachineName); Status = RtlAnsiStringToUnicodeString(&MachineNameW, &MachineNameA, TRUE); - if (STATUS_SUCCESS != Status) { + if (STATUS_SUCCESS != Status) + { SetLastError(RtlNtStatusToDosError(Status)); return FALSE; } + rv = AbortSystemShutdownW(MachineNameW.Buffer); RtlFreeUnicodeString(&MachineNameW); SetLastError(ERROR_SUCCESS); @@ -60,23 +62,26 @@ * @unimplemented */ BOOL STDCALL -InitiateSystemShutdownW( - LPWSTR lpMachineName, - LPWSTR lpMessage, - DWORD dwTimeout, - BOOL bForceAppsClosed, - BOOL bRebootAfterShutdown) +InitiateSystemShutdownW(LPWSTR lpMachineName, + LPWSTR lpMessage, + DWORD dwTimeout, + BOOL bForceAppsClosed, + BOOL bRebootAfterShutdown) { SHUTDOWN_ACTION Action = ShutdownNoReboot; - NTSTATUS Status; + NTSTATUS Status;
- if (lpMachineName) { - /* FIXME: remote machine shutdown not supported yet */ + if (lpMachineName) + { + /* FIXME: remote machine shutdown not supported yet */ SetLastError(ERROR_CALL_NOT_IMPLEMENTED); return FALSE; } - if (dwTimeout) { + + if (dwTimeout) + { } + Status = NtShutdownSystem(Action); SetLastError(RtlNtStatusToDosError(Status)); return FALSE; @@ -90,12 +95,11 @@ */ BOOL STDCALL -InitiateSystemShutdownA( - LPSTR lpMachineName, - LPSTR lpMessage, - DWORD dwTimeout, - BOOL bForceAppsClosed, - BOOL bRebootAfterShutdown) +InitiateSystemShutdownA(LPSTR lpMachineName, + LPSTR lpMessage, + DWORD dwTimeout, + BOOL bForceAppsClosed, + BOOL bRebootAfterShutdown) { ANSI_STRING MachineNameA; ANSI_STRING MessageA; @@ -105,38 +109,49 @@ INT LastError; BOOL rv;
- if (lpMachineName) { + if (lpMachineName) + { RtlInitAnsiString(&MachineNameA, lpMachineName); Status = RtlAnsiStringToUnicodeString(&MachineNameW, &MachineNameA, TRUE); - if (STATUS_SUCCESS != Status) { + if (STATUS_SUCCESS != Status) + { SetLastError(RtlNtStatusToDosError(Status)); return FALSE; } } - if (lpMessage) { + + if (lpMessage) + { RtlInitAnsiString(&MessageA, lpMessage); Status = RtlAnsiStringToUnicodeString(&MessageW, &MessageA, TRUE); - if (STATUS_SUCCESS != Status) { - if (MachineNameW.Length) { + if (STATUS_SUCCESS != Status) + { + if (MachineNameW.Length) + { RtlFreeUnicodeString(&MachineNameW); } + SetLastError(RtlNtStatusToDosError(Status)); return FALSE; } } - rv = InitiateSystemShutdownW( - MachineNameW.Buffer, - MessageW.Buffer, - dwTimeout, - bForceAppsClosed, - bRebootAfterShutdown); + + rv = InitiateSystemShutdownW(MachineNameW.Buffer, + MessageW.Buffer, + dwTimeout, + bForceAppsClosed, + bRebootAfterShutdown); LastError = GetLastError(); - if (lpMachineName) { + if (lpMachineName) + { RtlFreeUnicodeString(&MachineNameW); } - if (lpMessage) { + + if (lpMessage) + { RtlFreeUnicodeString(&MessageW); } + SetLastError(LastError); return rv; } @@ -146,9 +161,13 @@ * * see InitiateSystemShutdownExA */ -BOOL WINAPI InitiateSystemShutdownExW( LPWSTR lpMachineName, LPWSTR lpMessage, - DWORD dwTimeout, BOOL bForceAppsClosed, BOOL bRebootAfterShutdown, - DWORD dwReason) +BOOL WINAPI +InitiateSystemShutdownExW(LPWSTR lpMachineName, + LPWSTR lpMessage, + DWORD dwTimeout, + BOOL bForceAppsClosed, + BOOL bRebootAfterShutdown, + DWORD dwReason) { UNIMPLEMENTED; return TRUE;