ReactOS 0.4.16-dev-1948-gd260c1d
msgina.h File Reference
#include <stdarg.h>
#include <stdlib.h>
#include <tchar.h>
#include <windef.h>
#include <winbase.h>
#include <winreg.h>
#include <winuser.h>
#include <winwlx.h>
#include <ndk/rtlfuncs.h>
#include <ndk/setypes.h>
#include <ntsecapi.h>
#include <strsafe.h>
#include <wine/debug.h>
#include "resource.h"
Include dependency graph for msgina.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  GINA_CONTEXT
 
struct  _GINA_UI
 

Macros

#define WIN32_NO_STATUS
 
#define _INC_WINDOWS
 
#define COM_NO_WINDOWS_H
 
#define WLX_SHUTDOWN_STATE_LOGOFF   0x01
 Shutdown state flags.
 
#define WLX_SHUTDOWN_STATE_POWER_OFF   0x02
 "Shut down"
 
#define WLX_SHUTDOWN_STATE_REBOOT   0x04
 "Restart"
 
#define WLX_SHUTDOWN_STATE_SLEEP   0x10
 "Stand by"
 
#define WLX_SHUTDOWN_STATE_SLEEP2   0x20
 "Stand by (with wakeup events disabled)"
 
#define WLX_SHUTDOWN_STATE_HIBERNATE   0x40
 "Hibernate"
 
#define WLX_SHUTDOWN_STATE_DISCONNECT   0x80
 "Disconnect" (only available in Terminal Services sessions)
 
#define WLX_SHUTDOWN_AUTOUPDATE   0x100
 Set when updates are queued.
 

Typedefs

typedef struct GINA_CONTEXTPGINA_CONTEXT
 
typedef BOOL(* PFGINA_INITIALIZE) (PGINA_CONTEXT)
 
typedef BOOL(* PFGINA_DISPLAYSTATUSMESSAGE) (PGINA_CONTEXT, HDESK, DWORD, PWSTR, PWSTR)
 
typedef BOOL(* PFGINA_REMOVESTATUSMESSAGE) (PGINA_CONTEXT)
 
typedef VOID(* PFGINA_DISPLAYSASNOTICE) (PGINA_CONTEXT)
 
typedef INT(* PFGINA_LOGGEDONSAS) (PGINA_CONTEXT, DWORD)
 
typedef INT(* PFGINA_LOGGEDOUTSAS) (PGINA_CONTEXT)
 
typedef INT(* PFGINA_LOCKEDSAS) (PGINA_CONTEXT)
 
typedef VOID(* PFGINA_DISPLAYLOCKEDNOTICE) (PGINA_CONTEXT)
 
typedef struct _GINA_UI GINA_UI
 
typedef struct _GINA_UIPGINA_UI
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (msgina)
 
NTSTATUS ConnectToLsa (PGINA_CONTEXT pgContext)
 
NTSTATUS MyLogonUser (HANDLE LsaHandle, ULONG AuthenticationPackage, LPWSTR lpszUsername, LPWSTR lpszDomain, LPWSTR lpszPassword, PHANDLE phToken, PNTSTATUS SubStatus)
 
BOOL DoAdminUnlock (IN PGINA_CONTEXT pgContext, IN PWSTR UserName, IN PWSTR Domain, IN PWSTR Password)
 
NTSTATUS DoLoginTasks (IN OUT PGINA_CONTEXT pgContext, IN PWSTR UserName, IN PWSTR Domain, IN PWSTR Password, OUT PNTSTATUS SubStatus)
 
BOOL CreateProfile (IN OUT PGINA_CONTEXT pgContext, IN PWSTR UserName, IN PWSTR Domain, IN PWSTR Password)
 
DWORD LoadShutdownSelState (_In_ HKEY hKeyCurrentUser)
 
VOID SaveShutdownSelState (_In_ HKEY hKeyCurrentUser, _In_ DWORD ShutdownCode)
 
DWORD GetAllowedShutdownOptions (_In_opt_ HKEY hKeyCurrentUser, _In_opt_ HANDLE hUserToken)
 
INT_PTR ShutdownDialog (IN HWND hwndDlg, IN DWORD ShutdownOptions, IN PGINA_CONTEXT pgContext)
 
LONG RegOpenLoggedOnHKCU (_In_opt_ HANDLE hUserToken, _In_ REGSAM samDesired, _Out_ PHKEY phkResult)
 Opens and retrieves a handle to the HKEY_CURRENT_USER corresponding to the specified logged-on user.
 
LONG ReadRegSzValue (_In_ HKEY hKey, _In_ PCWSTR pszValue, _Out_ PWSTR *pValue)
 
LONG ReadRegDwordValue (_In_ HKEY hKey, _In_ PCWSTR pszValue, _Out_ PDWORD pValue)
 
BOOL TestTokenPrivilege (_In_opt_ HANDLE hToken, _In_ ULONG Privilege)
 Verifies whether the specified token has the given privilege.
 
PWSTR DuplicateString (_In_opt_ PCWSTR Str)
 

Variables

HINSTANCE hDllInstance
 

Macro Definition Documentation

◆ _INC_WINDOWS

#define _INC_WINDOWS

Definition at line 13 of file msgina.h.

◆ COM_NO_WINDOWS_H

#define COM_NO_WINDOWS_H

Definition at line 14 of file msgina.h.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 12 of file msgina.h.

◆ WLX_SHUTDOWN_AUTOUPDATE

#define WLX_SHUTDOWN_AUTOUPDATE   0x100

Set when updates are queued.

Definition at line 141 of file msgina.h.

◆ WLX_SHUTDOWN_STATE_DISCONNECT

#define WLX_SHUTDOWN_STATE_DISCONNECT   0x80

"Disconnect" (only available in Terminal Services sessions)

Definition at line 140 of file msgina.h.

◆ WLX_SHUTDOWN_STATE_HIBERNATE

#define WLX_SHUTDOWN_STATE_HIBERNATE   0x40

"Hibernate"

Definition at line 139 of file msgina.h.

◆ WLX_SHUTDOWN_STATE_LOGOFF

◆ WLX_SHUTDOWN_STATE_POWER_OFF

#define WLX_SHUTDOWN_STATE_POWER_OFF   0x02

"Shut down"

Definition at line 134 of file msgina.h.

◆ WLX_SHUTDOWN_STATE_REBOOT

#define WLX_SHUTDOWN_STATE_REBOOT   0x04

"Restart"

Definition at line 135 of file msgina.h.

◆ WLX_SHUTDOWN_STATE_SLEEP

#define WLX_SHUTDOWN_STATE_SLEEP   0x10

"Stand by"

Definition at line 137 of file msgina.h.

◆ WLX_SHUTDOWN_STATE_SLEEP2

#define WLX_SHUTDOWN_STATE_SLEEP2   0x20

"Stand by (with wakeup events disabled)"

Definition at line 138 of file msgina.h.

Typedef Documentation

◆ GINA_UI

◆ PFGINA_DISPLAYLOCKEDNOTICE

typedef VOID(* PFGINA_DISPLAYLOCKEDNOTICE) (PGINA_CONTEXT)

Definition at line 71 of file msgina.h.

◆ PFGINA_DISPLAYSASNOTICE

typedef VOID(* PFGINA_DISPLAYSASNOTICE) (PGINA_CONTEXT)

Definition at line 67 of file msgina.h.

◆ PFGINA_DISPLAYSTATUSMESSAGE

typedef BOOL(* PFGINA_DISPLAYSTATUSMESSAGE) (PGINA_CONTEXT, HDESK, DWORD, PWSTR, PWSTR)

Definition at line 65 of file msgina.h.

◆ PFGINA_INITIALIZE

typedef BOOL(* PFGINA_INITIALIZE) (PGINA_CONTEXT)

Definition at line 64 of file msgina.h.

◆ PFGINA_LOCKEDSAS

typedef INT(* PFGINA_LOCKEDSAS) (PGINA_CONTEXT)

Definition at line 70 of file msgina.h.

◆ PFGINA_LOGGEDONSAS

typedef INT(* PFGINA_LOGGEDONSAS) (PGINA_CONTEXT, DWORD)

Definition at line 68 of file msgina.h.

◆ PFGINA_LOGGEDOUTSAS

typedef INT(* PFGINA_LOGGEDOUTSAS) (PGINA_CONTEXT)

Definition at line 69 of file msgina.h.

◆ PFGINA_REMOVESTATUSMESSAGE

typedef BOOL(* PFGINA_REMOVESTATUSMESSAGE) (PGINA_CONTEXT)

Definition at line 66 of file msgina.h.

◆ PGINA_CONTEXT

◆ PGINA_UI

Function Documentation

◆ ConnectToLsa()

NTSTATUS ConnectToLsa ( PGINA_CONTEXT  pgContext)

Definition at line 11 of file lsa.c.

13{
14 LSA_STRING LogonProcessName;
15 LSA_STRING PackageName;
18
19 /* We are already connected to the LSA */
20 if (pgContext->LsaHandle != NULL)
21 return STATUS_SUCCESS;
22
23 /* Connect to the LSA server */
24 RtlInitAnsiString((PANSI_STRING)&LogonProcessName,
25 "MSGINA");
26
27 Status = LsaRegisterLogonProcess(&LogonProcessName,
28 &pgContext->LsaHandle,
30 if (!NT_SUCCESS(Status))
31 {
32 ERR("LsaRegisterLogonProcess failed (Status 0x%08lx)\n", Status);
33 return Status;
34 }
35
36 /* Get the authentication package */
37 RtlInitAnsiString((PANSI_STRING)&PackageName,
39
41 &PackageName,
42 &pgContext->AuthenticationPackage);
43 if (!NT_SUCCESS(Status))
44 {
45 ERR("LsaLookupAuthenticationPackage failed (Status 0x%08lx)\n", Status);
46 }
47
48 return Status;
49}
LONG NTSTATUS
Definition: precomp.h:26
#define ERR(fmt,...)
Definition: precomp.h:57
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
Status
Definition: gdiplustypes.h:25
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
_IRQL_requires_same_ _Out_ PHANDLE _Out_ PLSA_OPERATIONAL_MODE SecurityMode
NTSTATUS NTAPI LsaLookupAuthenticationPackage(HANDLE, PLSA_STRING, PULONG)
#define MSV1_0_PACKAGE_NAME
Definition: ntsecapi.h:42
ULONG LSA_OPERATIONAL_MODE
Definition: ntsecapi.h:367
NTSTATUS NTAPI LsaRegisterLogonProcess(PLSA_STRING, PHANDLE, PLSA_OPERATIONAL_MODE)
#define STATUS_SUCCESS
Definition: shellext.h:65
HANDLE LsaHandle
Definition: msgina.h:40
ULONG AuthenticationPackage
Definition: msgina.h:41

Referenced by DoAdminUnlock(), DoChangePassword(), DoLoginTasks(), and TUILockedSAS().

◆ CreateProfile()

BOOL CreateProfile ( IN OUT PGINA_CONTEXT  pgContext,
IN PWSTR  UserName,
IN PWSTR  Domain,
IN PWSTR  Password 
)

Definition at line 759 of file msgina.c.

764{
765 PWLX_PROFILE_V2_0 pProfile = NULL;
766 PWSTR pEnvironment = NULL;
767 TOKEN_STATISTICS Stats;
768 DWORD cbStats, cbSize;
770#if 0
771 BOOL bIsDomainLogon;
772 WCHAR ComputerName[MAX_COMPUTERNAME_LENGTH+1];
773#endif
774
775 /* Store the logon time in the context */
776 GetLocalTime(&pgContext->LogonTime);
777
778 /* Store user and domain in the context */
779 wcscpy(pgContext->UserName, UserName);
780 if (Domain == NULL || !Domain[0])
781 {
782 dwLength = _countof(pgContext->DomainName);
783 GetComputerNameW(pgContext->DomainName, &dwLength);
784 }
785 else
786 {
787 wcscpy(pgContext->DomainName, Domain);
788 }
789 /* From now on we use in UserName and Domain the captured values from pgContext */
790 UserName = pgContext->UserName;
791 Domain = pgContext->DomainName;
792
793#if 0
794 /* Determine whether this is really a domain logon, by verifying
795 * that the specified domain is different from the local computer */
796 dwLength = _countof(ComputerName);
797 GetComputerNameW(ComputerName, &dwLength);
798 bIsDomainLogon = (_wcsicmp(ComputerName, Domain) != 0);
799#endif
800
801 /* Allocate memory for profile */
802 pProfile = LocalAlloc(LMEM_FIXED | LMEM_ZEROINIT, sizeof(*pProfile));
803 if (!pProfile)
804 {
805 WARN("HeapAlloc() failed\n");
806 goto cleanup;
807 }
808 pProfile->dwType = WLX_PROFILE_TYPE_V2_0;
809
810 /*
811 * TODO: For domain logon support:
812 *
813 * - pszProfile: Specifies the path to a *roaming* user profile on a
814 * domain server, if any. It is then used to create a local image
815 * (copy) of the profile on the local computer.
816 * ** This data should be retrieved from the LsaLogonUser() call
817 * made by MyLogonUser()! **
818 *
819 * - pszPolicy (for domain logon): Path to a policy file.
820 * Windows' msgina.dll hardcodes it as:
821 * "\<domain_controller>\netlogon\ntconfig.pol"
822 *
823 * - pszNetworkDefaultUserProfile (for domain logon): Path to the
824 * default user profile. Windows' msgina.dll hardcodes it as:
825 * "\<domain_controller>\netlogon\Default User"
826 *
827 * - pszServerName (for domain logon): Name ("domain_controller") of
828 * the server (local computer; Active Directory domain controller...)
829 * that validated the logon.
830 * ** This data should be retrieved from the LsaLogonUser() call
831 * made by MyLogonUser()! **
832 *
833 * NOTES:
834 * - The paths use the domain controllers' "netlogon" share.
835 * - These strings are LocalAlloc'd here, and LocalFree'd by Winlogon.
836 */
837 pProfile->pszProfile = NULL;
838 pProfile->pszPolicy = NULL;
840 pProfile->pszServerName = NULL;
841#if 0
842 if (bIsDomainLogon)
843 {
844 PWSTR pServerName;
845 cbSize = sizeof(L"\\\\") + wcslen(Domain) * sizeof(WCHAR);
846 pServerName = LocalAlloc(LMEM_FIXED, cbSize);
847 if (!pServerName)
848 WARN("HeapAlloc() failed\n"); // Consider this optional, so no failure.
849 else
850 StringCbPrintfW(pServerName, cbSize, L"\\\\%ws", Domain); // See LogonServer below.
851 pProfile->pszServerName = pServerName;
852 }
853#endif
854
855 /* Build the minimal environment string block */
856 // FIXME: LogonServer is the name of the server that processed the logon
857 // request ("domain_controller"). It can be different from the selected
858 // user's logon domain.
859 // See e.g.:
860 // - https://learn.microsoft.com/en-us/windows/win32/api/ntsecapi/ns-ntsecapi-msv1_0_interactive_profile
861 // - https://learn.microsoft.com/en-us/windows/win32/api/winwlx/ns-winwlx-wlx_consoleswitch_credentials_info_v1_0
862 cbSize = sizeof(L"LOGONSERVER=\\\\") +
863 wcslen(Domain) * sizeof(WCHAR) +
864 sizeof(UNICODE_NULL);
865 pEnvironment = LocalAlloc(LMEM_FIXED, cbSize);
866 if (!pEnvironment)
867 {
868 WARN("LocalAlloc() failed\n");
869 goto cleanup;
870 }
871
872 StringCbPrintfW(pEnvironment, cbSize, L"LOGONSERVER=\\\\%ws", Domain);
873 ASSERT(wcslen(pEnvironment) == cbSize / sizeof(WCHAR) - 2);
874 pEnvironment[cbSize / sizeof(WCHAR) - 1] = UNICODE_NULL;
875
876 pProfile->pszEnvironment = pEnvironment;
877
878 /* Return the other info */
879 if (!GetTokenInformation(pgContext->UserToken,
881 &Stats,
882 sizeof(Stats),
883 &cbStats))
884 {
885 WARN("Couldn't get Authentication Id from user token!\n");
886 goto cleanup;
887 }
888
889 *pgContext->pAuthenticationId = Stats.AuthenticationId;
890 pgContext->pMprNotifyInfo->pszUserName = DuplicateString(UserName);
891 pgContext->pMprNotifyInfo->pszDomain = DuplicateString(Domain);
892 pgContext->pMprNotifyInfo->pszPassword = DuplicateString(Password);
893 pgContext->pMprNotifyInfo->pszOldPassword = NULL;
894 *pgContext->pdwOptions = 0;
895 *pgContext->pProfile = pProfile;
896 return TRUE;
897
898cleanup:
899 if (pEnvironment)
900 LocalFree(pEnvironment);
901 if (pProfile)
902 LocalFree(pProfile);
903 return FALSE;
904}
#define WARN(fmt,...)
Definition: precomp.h:61
BOOL WINAPI GetComputerNameW(LPWSTR lpBuffer, LPDWORD lpnSize)
Definition: compname.c:446
wcscpy
#define TRUE
Definition: types.h:120
#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
static DWORD DWORD * dwLength
Definition: fusion.c:86
static void cleanup(void)
Definition: main.c:1335
VOID WINAPI GetLocalTime(OUT LPSYSTEMTIME lpSystemTime)
Definition: time.c:286
#define L(x)
Definition: resources.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1390
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define LMEM_ZEROINIT
Definition: minwinbase.h:85
#define LMEM_FIXED
Definition: minwinbase.h:81
#define ASSERT(a)
Definition: mode.c:44
#define UNICODE_NULL
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define _countof(array)
Definition: sndvol32.h:70
#define DuplicateString(x)
Definition: stringutils.h:45
STRSAFEAPI StringCbPrintfW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:557
LUID AuthenticationId
Definition: setypes.h:1099
PWSTR pszPolicy
Definition: winwlx.h:150
PWSTR pszEnvironment
Definition: winwlx.h:153
PWSTR pszServerName
Definition: winwlx.h:152
PWSTR pszProfile
Definition: winwlx.h:149
PWSTR pszNetworkDefaultUserProfile
Definition: winwlx.h:151
@ Password
Definition: telnetd.h:67
uint16_t * PWSTR
Definition: typedefs.h:56
#define MAX_COMPUTERNAME_LENGTH
Definition: winbase.h:267
#define WLX_PROFILE_TYPE_V2_0
Definition: winwlx.h:51
@ TokenStatistics
Definition: setypes.h:987
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by DoLogon(), and TUILoggedOutSAS().

◆ DoAdminUnlock()

BOOL DoAdminUnlock ( IN PGINA_CONTEXT  pgContext,
IN PWSTR  UserName,
IN PWSTR  Domain,
IN PWSTR  Password 
)

Definition at line 639 of file msgina.c.

644{
645 HANDLE hToken = NULL;
646 PTOKEN_GROUPS Groups = NULL;
647 BOOL bIsAdmin = FALSE;
648 ULONG Size;
649 ULONG i;
652
653 TRACE("(%S %S %S)\n", UserName, Domain, Password);
654
655 Status = ConnectToLsa(pgContext);
656 if (!NT_SUCCESS(Status))
657 {
658 WARN("ConnectToLsa() failed\n");
659 return FALSE;
660 }
661
662 Status = MyLogonUser(pgContext->LsaHandle,
663 pgContext->AuthenticationPackage,
664 UserName,
665 Domain,
666 Password,
667 &pgContext->UserToken,
668 &SubStatus);
669 if (!NT_SUCCESS(Status))
670 {
671 WARN("MyLogonUser() failed\n");
672 return FALSE;
673 }
674
677 NULL,
678 0,
679 &Size);
681 {
682 TRACE("NtQueryInformationToken() failed (Status 0x%08lx)\n", Status);
683 goto done;
684 }
685
686 Groups = HeapAlloc(GetProcessHeap(), 0, Size);
687 if (Groups == NULL)
688 {
689 TRACE("HeapAlloc() failed\n");
690 goto done;
691 }
692
695 Groups,
696 Size,
697 &Size);
698 if (!NT_SUCCESS(Status))
699 {
700 TRACE("NtQueryInformationToken() failed (Status 0x%08lx)\n", Status);
701 goto done;
702 }
703
704 for (i = 0; i < Groups->GroupCount; i++)
705 {
706 if (RtlEqualSid(Groups->Groups[i].Sid, AdminSid))
707 {
708 TRACE("Member of Admins group\n");
709 bIsAdmin = TRUE;
710 break;
711 }
712 }
713
714done:
715 if (Groups != NULL)
716 HeapFree(GetProcessHeap(), 0, Groups);
717
718 if (hToken != NULL)
719 CloseHandle(hToken);
720
721 return bIsAdmin;
722}
#define CloseHandle
Definition: compat.h:739
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
NTSTATUS MyLogonUser(HANDLE LsaHandle, ULONG AuthenticationPackage, LPWSTR lpszUsername, LPWSTR lpszDomain, LPWSTR lpszPassword, PHANDLE phToken, PNTSTATUS SubStatus)
Definition: lsa.c:55
NTSTATUS ConnectToLsa(PGINA_CONTEXT pgContext)
Definition: lsa.c:11
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static PSID AdminSid
Definition: msgina.c:39
NTSYSAPI BOOLEAN NTAPI RtlEqualSid(_In_ PSID Sid1, _In_ PSID Sid2)
_IRQL_requires_same_ _In_ PLSA_STRING _In_ SECURITY_LOGON_TYPE _In_ ULONG _In_ ULONG _In_opt_ PTOKEN_GROUPS _In_ PTOKEN_SOURCE _Out_ PVOID _Out_ PULONG _Inout_ PLUID _Out_ PHANDLE _Out_ PQUOTA_LIMITS _Out_ PNTSTATUS SubStatus
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define TRACE(s)
Definition: solgame.cpp:4
SID_AND_ATTRIBUTES Groups[ANYSIZE_ARRAY]
Definition: setypes.h:1030
$ULONG GroupCount
Definition: setypes.h:1026
_Must_inspect_result_ __kernel_entry NTSTATUS NTAPI NtQueryInformationToken(_In_ HANDLE TokenHandle, _In_ TOKEN_INFORMATION_CLASS TokenInformationClass, _Out_writes_bytes_to_opt_(TokenInformationLength, *ReturnLength) PVOID TokenInformation, _In_ ULONG TokenInformationLength, _Out_ PULONG ReturnLength)
Queries a specific type of information in regard of an access token based upon the information class....
Definition: tokencls.c:473
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4539
@ TokenGroups
Definition: setypes.h:979

Referenced by DoUnlock().

◆ DoLoginTasks()

NTSTATUS DoLoginTasks ( IN OUT PGINA_CONTEXT  pgContext,
IN PWSTR  UserName,
IN PWSTR  Domain,
IN PWSTR  Password,
OUT PNTSTATUS  SubStatus 
)

Definition at line 726 of file msgina.c.

732{
734
735 Status = ConnectToLsa(pgContext);
736 if (!NT_SUCCESS(Status))
737 {
738 WARN("ConnectToLsa() failed (Status 0x%08lx)\n", Status);
739 return Status;
740 }
741
742 Status = MyLogonUser(pgContext->LsaHandle,
743 pgContext->AuthenticationPackage,
744 UserName,
745 Domain,
746 Password,
747 &pgContext->UserToken,
748 SubStatus);
749 if (!NT_SUCCESS(Status))
750 {
751 WARN("MyLogonUser() failed (Status 0x%08lx)\n", Status);
752 }
753
754 return Status;
755}

Referenced by DoLogon(), and TUILoggedOutSAS().

◆ DuplicateString()

PWSTR DuplicateString ( _In_opt_ PCWSTR  Str)

Definition at line 189 of file utils.c.

191{
192 PWSTR NewStr;
193 SIZE_T cb;
194
195 if (!Str)
196 return NULL;
197
198 cb = (wcslen(Str) + 1) * sizeof(WCHAR);
199 if ((NewStr = LocalAlloc(LMEM_FIXED, cb)))
200 memcpy(NewStr, Str, cb);
201 return NewStr;
202}
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static HMODULE MODULEINFO DWORD cb
Definition: module.c:33
ULONG_PTR SIZE_T
Definition: typedefs.h:80

◆ GetAllowedShutdownOptions()

DWORD GetAllowedShutdownOptions ( _In_opt_ HKEY  hKeyCurrentUser,
_In_opt_ HANDLE  hUserToken 
)

Definition at line 808 of file shutdown.c.

811{
812 DWORD Options = 0;
813 DWORD dwPolicyValue;
816
817 dwPolicyValue = 0;
818 GetPolicyDWORDValue(hKeyCurrentUser,
819 L"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",
820 L"NoLogoff", &dwPolicyValue);
821 if (dwPolicyValue == 0)
823
824#if 0 // TODO: Enable and lookup on a Terminal Services session
825 dwPolicyValue = 0;
826 GetPolicyDWORDValue(hKeyCurrentUser,
827 L"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",
828 L"NoDisconnect", &dwPolicyValue);
829 if (dwPolicyValue == 0)
831#endif
832
833 /* Add shutdown options only if the user has shutdown privilege */
835 return Options; // The user doesn't have them, bail out.
836
837 /* We can always shutdown and restart */
839
840 /* Determine whether extra power options are available */
841 Status = NtPowerInformation(SystemPowerCapabilities, NULL, 0, &PowerCaps, sizeof(PowerCaps));
842 if (!NT_SUCCESS(Status))
843 {
844 ERR("NtPowerInformation(SystemPowerCapabilities) failed (Status 0x%08lx)\n", Status);
845 }
846 else
847 {
848 if (IS_PWR_SUSPEND_ALLOWED(&PowerCaps))
850
851 // TODO: "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Power" value "Shutdown"
852 // for sleep options. In particular, if set it tells that wakeup events can be disabled.
853 // This will enable WLX_SHUTDOWN_STATE_SLEEP2 support.
854
855 if (IS_PWR_HIBERNATE_ALLOWED(&PowerCaps))
857 }
858
859 // TODO: Consider Windows 8+ support for:
860 // "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Power" value "HiberbootEnabled"
861
862 // TODO: Add WLX_SHUTDOWN_AUTOUPDATE if:
863 // - Policy "Software\\Policies\\Microsoft\\Windows\\WindowsUpdate\\AU" value "NoAUShutdownOption"
864 // is absent or zero;
865 // - SystemBatteryState detects the computer is on external power;
866 // - wuaueng.dll!ordinal_4 tells there are pending updates.
867
868 return Options;
869}
HANDLE hUserToken
Definition: install.c:39
LONG GetPolicyDWORDValue(_In_opt_ HKEY hKeyCurrentUser, _In_ PCWSTR pPolicyKey, _In_ PCWSTR ValueName, _Out_ PDWORD pValue)
Looks up a policy value on both HKEY_LOCAL_MACHINE and HKEY_CURRENT_USER, under the same policy sub-k...
Definition: shutdown.c:76
#define SE_SHUTDOWN_PRIVILEGE
Definition: security.c:673
#define WLX_SHUTDOWN_STATE_REBOOT
"Restart"
Definition: msgina.h:135
BOOL TestTokenPrivilege(_In_opt_ HANDLE hToken, _In_ ULONG Privilege)
Verifies whether the specified token has the given privilege.
Definition: utils.c:140
#define WLX_SHUTDOWN_STATE_LOGOFF
Shutdown state flags.
Definition: msgina.h:133
#define WLX_SHUTDOWN_STATE_SLEEP
"Stand by"
Definition: msgina.h:137
#define WLX_SHUTDOWN_STATE_POWER_OFF
"Shut down"
Definition: msgina.h:134
#define WLX_SHUTDOWN_STATE_HIBERNATE
"Hibernate"
Definition: msgina.h:139
#define WLX_SHUTDOWN_STATE_DISCONNECT
"Disconnect" (only available in Terminal Services sessions)
Definition: msgina.h:140
#define IS_PWR_SUSPEND_ALLOWED(PowerCaps)
Definition: potypes.h:63
#define IS_PWR_HIBERNATE_ALLOWED(PowerCaps)
Definition: potypes.h:70
NTSTATUS NTAPI NtPowerInformation(IN POWER_INFORMATION_LEVEL PowerInformationLevel, IN PVOID InputBuffer OPTIONAL, IN ULONG InputBufferLength, OUT PVOID OutputBuffer OPTIONAL, IN ULONG OutputBufferLength)
Definition: power.c:901
@ SystemPowerCapabilities
Definition: ntpoapi.h:71
_In_ PWDFDEVICE_INIT _In_ PWDF_REMOVE_LOCK_OPTIONS Options
Definition: wdfdevice.h:3540

Referenced by OnShutDown(), ShellShutdownDialog(), and ShutdownDialog().

◆ LoadShutdownSelState()

DWORD LoadShutdownSelState ( _In_ HKEY  hKeyCurrentUser)

Definition at line 696 of file shutdown.c.

698{
699 HKEY hKey;
700 DWORD dwValue, dwTemp, dwSize;
701 LONG lRet;
702
703 /* Default to first item */
704 dwValue = 0;
705
706 /* Open the subkey */
707 lRet = RegOpenKeyExW(hKeyCurrentUser,
708 L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
709 0, KEY_QUERY_VALUE, &hKey);
710 if (lRet != ERROR_SUCCESS)
711 return dwValue;
712
713 /* Read the value */
714 dwSize = sizeof(dwTemp);
715 lRet = RegQueryValueExW(hKey,
716 L"Shutdown Setting",
717 NULL, NULL,
718 (LPBYTE)&dwTemp, &dwSize);
720
721 if (lRet == ERROR_SUCCESS)
722 {
723 switch (dwTemp)
724 {
726 dwValue = WLX_SAS_ACTION_LOGOFF;
727 break;
728
731 break;
732
735 break;
736
737 // 0x08
738
741 break;
742
745 break;
746
749 break;
750
751 // WLX_SHUTDOWN_STATE_DISCONNECT
752 }
753 }
754
755 return dwValue;
756}
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_SUCCESS
Definition: deptool.c:10
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
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
#define WLX_SHUTDOWN_STATE_SLEEP2
"Stand by (with wakeup events disabled)"
Definition: msgina.h:138
#define KEY_QUERY_VALUE
Definition: nt_native.h:1019
long LONG
Definition: pedump.c:60
unsigned char * LPBYTE
Definition: typedefs.h:53
#define WLX_SAS_ACTION_SHUTDOWN_POWER_OFF
Definition: winwlx.h:62
#define WLX_SAS_ACTION_SHUTDOWN_SLEEP
Definition: winwlx.h:64
#define WLX_SAS_ACTION_SHUTDOWN_HIBERNATE
Definition: winwlx.h:66
#define WLX_SAS_ACTION_SHUTDOWN_REBOOT
Definition: winwlx.h:63
#define WLX_SAS_ACTION_SHUTDOWN_SLEEP2
Definition: winwlx.h:65
#define WLX_SAS_ACTION_LOGOFF
Definition: winwlx.h:56

Referenced by OnShutDown(), ShellShutdownDialog(), and ShutdownDialog().

◆ MyLogonUser()

NTSTATUS MyLogonUser ( HANDLE  LsaHandle,
ULONG  AuthenticationPackage,
LPWSTR  lpszUsername,
LPWSTR  lpszDomain,
LPWSTR  lpszPassword,
PHANDLE  phToken,
PNTSTATUS  SubStatus 
)

Definition at line 55 of file lsa.c.

63{
66 PSID LogonSid = NULL;
69 UNICODE_STRING DomainName;
70 UNICODE_STRING UserName;
73 ULONG AuthInfoLength;
79 LUID Luid = {0, 0};
80 LUID LogonId = {0, 0};
82 QUOTA_LIMITS QuotaLimits;
84
85 *phToken = NULL;
86
88 "MSGINA Logon");
89
90 RtlInitUnicodeString(&DomainName,
92
93 RtlInitUnicodeString(&UserName,
94 lpszUsername);
95
98
99 AuthInfoLength = sizeof(MSV1_0_INTERACTIVE_LOGON)+
100 DomainName.MaximumLength +
101 UserName.MaximumLength +
102 Password.MaximumLength;
103
104 AuthInfo = RtlAllocateHeap(RtlGetProcessHeap(),
106 AuthInfoLength);
107 if (AuthInfo == NULL)
108 {
110 goto done;
111 }
112
114
115 Ptr = (ULONG_PTR)AuthInfo + sizeof(MSV1_0_INTERACTIVE_LOGON);
116
117 AuthInfo->LogonDomainName.Length = DomainName.Length;
118 AuthInfo->LogonDomainName.MaximumLength = DomainName.MaximumLength;
119 AuthInfo->LogonDomainName.Buffer = (DomainName.Buffer == NULL) ? NULL : (PWCHAR)Ptr;
120 if (DomainName.MaximumLength > 0)
121 {
123 DomainName.Buffer,
124 DomainName.MaximumLength);
125
126 Ptr += DomainName.MaximumLength;
127 }
128
129 AuthInfo->UserName.Length = UserName.Length;
130 AuthInfo->UserName.MaximumLength = UserName.MaximumLength;
131 AuthInfo->UserName.Buffer = (PWCHAR)Ptr;
132 if (UserName.MaximumLength > 0)
133 {
134 RtlCopyMemory(AuthInfo->UserName.Buffer,
135 UserName.Buffer,
136 UserName.MaximumLength);
137 }
138
139 Ptr += UserName.MaximumLength;
140
141 AuthInfo->Password.Length = Password.Length;
142 AuthInfo->Password.MaximumLength = Password.MaximumLength;
143 AuthInfo->Password.Buffer = (PWCHAR)Ptr;
144 if (Password.MaximumLength > 0)
145 {
146 RtlCopyMemory(AuthInfo->Password.Buffer,
147 Password.Buffer,
148 Password.MaximumLength);
149 }
150
151 /* Create the Logon SID*/
156 LogonId.HighPart,
157 LogonId.LowPart,
163 &LogonSid);
164 if (!NT_SUCCESS(Status))
165 goto done;
166
167 /* Create the Local SID*/
168 Status = RtlAllocateAndInitializeSid(&LocalAuthority,
169 1,
178 &LocalSid);
179 if (!NT_SUCCESS(Status))
180 goto done;
181
182 /* Allocate and set the token groups */
183 TokenGroups = RtlAllocateHeap(RtlGetProcessHeap(),
185 sizeof(TOKEN_GROUPS) + ((2 - ANYSIZE_ARRAY) * sizeof(SID_AND_ATTRIBUTES)));
186 if (TokenGroups == NULL)
187 {
189 goto done;
190 }
191
192 TokenGroups->GroupCount = 2;
193 TokenGroups->Groups[0].Sid = LogonSid;
194 TokenGroups->Groups[0].Attributes = SE_GROUP_MANDATORY | SE_GROUP_ENABLED |
196 TokenGroups->Groups[1].Sid = LocalSid;
197 TokenGroups->Groups[1].Attributes = SE_GROUP_MANDATORY | SE_GROUP_ENABLED |
199
200 /* Set the token source */
201 RtlCopyMemory(TokenSource.SourceName, User32TokenSourceName, sizeof(TokenSource.SourceName));
202 AllocateLocallyUniqueId(&TokenSource.SourceIdentifier);
203
205 &OriginName,
208 (PVOID)AuthInfo,
209 AuthInfoLength,
214 &Luid,
216 &QuotaLimits,
217 SubStatus);
218 if (!NT_SUCCESS(Status))
219 {
220 ERR("LsaLogonUser failed (Status 0x%08lx)\n", Status);
221 goto done;
222 }
223
224 if (ProfileBuffer != NULL)
225 {
226 TRACE("ProfileBuffer: %p\n", ProfileBuffer);
227 TRACE("MessageType: %u\n", ProfileBuffer->MessageType);
228
229 TRACE("FullName: %p\n", ProfileBuffer->FullName.Buffer);
230 TRACE("FullName: %S\n", ProfileBuffer->FullName.Buffer);
231
232 TRACE("LogonServer: %p\n", ProfileBuffer->LogonServer.Buffer);
233 TRACE("LogonServer: %S\n", ProfileBuffer->LogonServer.Buffer);
234 }
235
236 TRACE("Luid: 0x%08lx%08lx\n", Luid.HighPart, Luid.LowPart);
237
238 if (TokenHandle != NULL)
239 TRACE("TokenHandle: %p\n", TokenHandle);
240
242
243done:
245
246 if (ProfileBuffer != NULL)
248
249 if (!NT_SUCCESS(Status) && (TokenHandle != NULL))
251
252 if (TokenGroups != NULL)
253 RtlFreeHeap(RtlGetProcessHeap(), 0, TokenGroups);
254
255 if (LocalSid != NULL)
257
258 if (LogonSid != NULL)
259 RtlFreeSid(LogonSid);
260
261 if (AuthInfo != NULL)
262 {
263 /* Zero out the password buffers before freeing */
264 SecureZeroMemory(AuthInfo->Password.Buffer, AuthInfo->Password.MaximumLength);
265 SecureZeroMemory(&AuthInfo->Password, sizeof(AuthInfo->Password));
266 RtlFreeHeap(RtlGetProcessHeap(), 0, AuthInfo);
267 }
268
269 return Status;
270}
PSID LocalSid
Definition: globals.c:15
HANDLE LsaHandle
Definition: wkssvc.c:41
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:616
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:634
ULONG AuthenticationPackage
Definition: logon.c:18
BOOL WINAPI AllocateLocallyUniqueId(PLUID Luid)
Definition: security.c:1218
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
static const CHAR User32TokenSourceName[]
Definition: lsa.c:51
#define ULONG_PTR
Definition: config.h:101
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
static SID_IDENTIFIER_AUTHORITY SystemAuthority
Definition: msgina.c:38
_In_ ACCESS_MASK _In_ ULONG _Out_ PHANDLE TokenHandle
Definition: psfuncs.h:727
NTSYSAPI PVOID NTAPI RtlFreeSid(_In_ _Post_invalid_ PSID Sid)
#define SE_GROUP_LOGON_ID
Definition: setypes.h:98
#define SE_GROUP_MANDATORY
Definition: setypes.h:90
#define SE_GROUP_ENABLED_BY_DEFAULT
Definition: setypes.h:91
#define SE_GROUP_ENABLED
Definition: setypes.h:92
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
_IRQL_requires_same_ _In_ PLSA_STRING _In_ SECURITY_LOGON_TYPE _In_ ULONG _In_ ULONG _In_opt_ PTOKEN_GROUPS _In_ PTOKEN_SOURCE _Out_ PVOID * ProfileBuffer
_IRQL_requires_same_ _In_ PLSA_STRING _In_ SECURITY_LOGON_TYPE _In_ ULONG _In_ ULONG _In_opt_ PTOKEN_GROUPS _In_ PTOKEN_SOURCE _Out_ PVOID _Out_ PULONG ProfileBufferLength
_IRQL_requires_same_ _In_ PLSA_STRING _In_ SECURITY_LOGON_TYPE _In_ ULONG _In_ ULONG _In_opt_ PTOKEN_GROUPS _In_ PTOKEN_SOURCE _Out_ PVOID _Out_ PULONG _Inout_ PLUID LogonId
_IRQL_requires_same_ _In_ PLSA_STRING OriginName
NTSYSAPI NTSTATUS NTAPI RtlAllocateAndInitializeSid(IN PSID_IDENTIFIER_AUTHORITY IdentifierAuthority, IN UCHAR SubAuthorityCount, IN ULONG SubAuthority0, IN ULONG SubAuthority1, IN ULONG SubAuthority2, IN ULONG SubAuthority3, IN ULONG SubAuthority4, IN ULONG SubAuthority5, IN ULONG SubAuthority6, IN ULONG SubAuthority7, OUT PSID *Sid)
Definition: sid.c:290
NTSTATUS NTAPI LsaLogonUser(HANDLE, PLSA_STRING, SECURITY_LOGON_TYPE, ULONG, PVOID, ULONG, PTOKEN_GROUPS, PTOKEN_SOURCE, PVOID *, PULONG, PLUID, PHANDLE, PQUOTA_LIMITS, PNTSTATUS)
@ Interactive
Definition: ntsecapi.h:289
NTSTATUS NTAPI LsaFreeReturnBuffer(PVOID)
struct _MSV1_0_INTERACTIVE_LOGON MSV1_0_INTERACTIVE_LOGON
@ MsV1_0InteractiveLogon
Definition: ntsecapi.h:199
PCHAR Buffer
Definition: ntsecapi.h:174
LONG HighPart
DWORD LowPart
UNICODE_STRING Password
Definition: ntsecapi.h:437
UNICODE_STRING UserName
Definition: ntsecapi.h:436
MSV1_0_LOGON_SUBMIT_TYPE MessageType
Definition: ntsecapi.h:434
UNICODE_STRING LogonDomainName
Definition: ntsecapi.h:435
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define ANYSIZE_ARRAY
Definition: typedefs.h:46
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint16_t * PWCHAR
Definition: typedefs.h:56
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define SecureZeroMemory
Definition: winbase.h:1465
_In_opt_ LPSTR _In_opt_ LPSTR _In_ DWORD _In_ DWORD _Out_opt_ PHANDLE phToken
Definition: winbase.h:2469
_In_opt_ LPSTR _In_opt_ LPSTR lpszPassword
Definition: winbase.h:2466
_In_opt_ LPSTR lpszDomain
Definition: winbase.h:2465
#define SECURITY_LOGON_IDS_RID
Definition: setypes.h:560
#define SECURITY_LOCAL_SID_AUTHORITY
Definition: setypes.h:530
#define SECURITY_LOCAL_RID
Definition: setypes.h:542
#define SECURITY_NULL_RID
Definition: setypes.h:540
#define SECURITY_NT_AUTHORITY
Definition: setypes.h:554
@ TokenSource
Definition: setypes.h:984
#define SECURITY_LOGON_IDS_RID_COUNT
Definition: setypes.h:561

Referenced by DoAdminUnlock(), DoLoginTasks(), and TUILockedSAS().

◆ ReadRegDwordValue()

LONG ReadRegDwordValue ( _In_ HKEY  hKey,
_In_ PCWSTR  pszValue,
_Out_ PDWORD  pValue 
)

Definition at line 90 of file utils.c.

94{
95 LONG rc;
96 DWORD dwValue, dwType, cbData;
97 /* Buffer big enough to hold the NULL-terminated string L"4294967295",
98 * corresponding to the literal 0xFFFFFFFF (MAXULONG) in decimal. */
99 WCHAR Buffer[sizeof("4294967295")];
100 C_ASSERT(sizeof(Buffer) >= sizeof(DWORD));
101
102 cbData = sizeof(Buffer);
103 rc = RegQueryValueExW(hKey, pszValue, NULL, &dwType, (PBYTE)&Buffer, &cbData);
104 if (rc != ERROR_SUCCESS)
105 return rc;
106
107 if (dwType == REG_DWORD)
108 {
109 if (cbData != sizeof(dwValue))
110 return ERROR_INVALID_DATA; // ERROR_DATATYPE_MISMATCH;
111 dwValue = *(PDWORD)Buffer;
112 }
113 else if (dwType == REG_SZ)
114 {
115 PWCHAR pEnd = NULL;
116 Buffer[cbData / sizeof(WCHAR) - 1] = UNICODE_NULL;
117 dwValue = wcstoul(Buffer, &pEnd, 0);
118 if (*pEnd) // Don't consider REG_SZ to be supported in this case!
120 }
121 else
122 {
124 }
125
126 *pValue = dwValue;
127 return ERROR_SUCCESS;
128}
Definition: bufpool.h:45
PWCHAR pValue
#define C_ASSERT(e)
Definition: intsafe.h:73
#define REG_SZ
Definition: layer.c:22
BYTE * PBYTE
Definition: pedump.c:66
DWORD * PDWORD
Definition: pedump.c:68
_In_opt_ _In_opt_ _In_ _In_ DWORD cbData
Definition: shlwapi.h:761
_In_opt_ LPCSTR _In_opt_ LPCSTR pszValue
Definition: shlwapi.h:783
#define REG_DWORD
Definition: sdbapi.c:615
_Check_return_ unsigned long __cdecl wcstoul(_In_z_ const wchar_t *_Str, _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix)
#define ERROR_UNSUPPORTED_TYPE
Definition: winerror.h:1336
#define ERROR_INVALID_DATA
Definition: winerror.h:238

Referenced by GetPolicyDWORDValue(), GetRegistrySettings(), and OnInitSecurityDlg().

◆ ReadRegSzValue()

LONG ReadRegSzValue ( _In_ HKEY  hKey,
_In_ PCWSTR  pszValue,
_Out_ PWSTR pValue 
)

Definition at line 57 of file utils.c.

61{
62 LONG rc;
63 DWORD dwType;
64 DWORD cbData = 0;
66
67 *pValue = NULL;
68 rc = RegQueryValueExW(hKey, pszValue, NULL, &dwType, NULL, &cbData);
69 if (rc != ERROR_SUCCESS)
70 return rc;
71 if (dwType != REG_SZ)
73 Value = HeapAlloc(GetProcessHeap(), 0, cbData + sizeof(WCHAR));
74 if (!Value)
77 if (rc != ERROR_SUCCESS)
78 {
80 return rc;
81 }
82 /* NULL-terminate the string */
83 Value[cbData / sizeof(WCHAR)] = UNICODE_NULL;
84
85 *pValue = Value;
86 return ERROR_SUCCESS;
87}
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413

Referenced by ChooseGinaUI(), and GUILoggedOutSAS().

◆ RegOpenLoggedOnHKCU()

LONG RegOpenLoggedOnHKCU ( _In_opt_ HANDLE  hUserToken,
_In_ REGSAM  samDesired,
_Out_ PHKEY  phkResult 
)

Opens and retrieves a handle to the HKEY_CURRENT_USER corresponding to the specified logged-on user.

Parameters
[in]hUserTokenOptional handle to a primary or impersonation access token that represents a logged-on user. See ImpersonateLoggedOnUser() for more information. If NULL, opens the SYSTEM's HKEY_USERS.Default (i.e. HKEY_USERS\S-1-5-18).
[in]samDesiredA mask (type: REGSAM or ACCESS_MASK) that specifies the desired access rights to the key. See RegOpenCurrentUser() for more information.
[out]phkResultA pointer to a variable that receives a handle to the opened key. When the handle is no longer needed, close it with RegCloseKey().

Definition at line 31 of file utils.c.

35{
36 LONG rc;
37
38 /* Impersonate the logged-on user if necessary */
40 {
41 rc = GetLastError();
42 ERR("ImpersonateLoggedOnUser() failed with error %ld\n", rc);
43 return rc;
44 }
45
46 /* Open the logged-on user HKCU key */
47 rc = RegOpenCurrentUser(samDesired, phkResult);
48
49 /* Revert the impersonation */
50 if (hUserToken)
52
53 return rc;
54}
LONG WINAPI RegOpenCurrentUser(IN REGSAM samDesired, OUT PHKEY phkResult)
Definition: reg.c:3209
BOOL WINAPI ImpersonateLoggedOnUser(HANDLE hToken)
Definition: misc.c:152
BOOL WINAPI RevertToSelf(void)
Definition: security.c:855
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

Referenced by OnInitSecurityDlg(), OnShutDown(), and WlxActivateUserShell().

◆ SaveShutdownSelState()

VOID SaveShutdownSelState ( _In_ HKEY  hKeyCurrentUser,
_In_ DWORD  ShutdownCode 
)

Definition at line 759 of file shutdown.c.

762{
763 HKEY hKey;
764 DWORD dwValue = 0;
765 LONG lRet;
766
767 /* Create the subkey */
768 lRet = RegCreateKeyExW(hKeyCurrentUser,
769 L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
770 0, NULL,
773 NULL, &hKey, NULL);
774 if (lRet != ERROR_SUCCESS)
775 return;
776
777 switch (ShutdownCode)
778 {
781 break;
782
785 break;
786
789 break;
790
792 dwValue = WLX_SHUTDOWN_STATE_SLEEP;
793 break;
794
797 break;
798 }
799
801 L"Shutdown Setting",
802 0, REG_DWORD,
803 (LPBYTE)&dwValue, sizeof(dwValue));
805}
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1096
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4882
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1060
#define KEY_SET_VALUE
Definition: nt_native.h:1020

Referenced by OnShutDown(), ShellShutdownDialog(), and ShutdownDialog().

◆ ShutdownDialog()

INT_PTR ShutdownDialog ( IN HWND  hwndDlg,
IN DWORD  ShutdownOptions,
IN PGINA_CONTEXT  pgContext 
)

Definition at line 1252 of file shutdown.c.

1256{
1257 INT_PTR ret;
1259
1260#if 0
1261 ShutdownOptions = GetAllowedShutdownOptions(hKeyCurrentUser, pgContext->UserToken);
1262 pgContext->nShutdownAction = LoadShutdownSelState(hKeyCurrentUser);
1263 ShutdownOptions &= ~dwExcludeOptions;
1264#endif
1265
1266 /* Bail out early if no shutdown options are available */
1267 if (ShutdownOptions == 0)
1268 return IDCANCEL;
1269
1270 Context.pgContext = pgContext;
1271 Context.ShutdownOptions = ShutdownOptions;
1272 Context.ShutdownDialogId = IDD_SHUTDOWN;
1273 Context.bCloseDlg = FALSE;
1274 Context.bReasonUI = GetShutdownReasonUI();
1275 Context.bFriendlyUI = ShellIsFriendlyUIActive();
1276
1277 if (pgContext->hWlx && pgContext->pWlxFuncs && !Context.bFriendlyUI)
1278 {
1279 ret = pgContext->pWlxFuncs->WlxDialogBoxParam(pgContext->hWlx,
1280 pgContext->hDllInstance,
1282 hwndDlg,
1284 (LPARAM)&Context);
1285 }
1286 else
1287 {
1288 if (Context.bFriendlyUI)
1289 {
1291 Context.ShutdownDialogId = IDD_SHUTDOWN_FANCY_LONG;
1292 else
1293 Context.ShutdownDialogId = IDD_SHUTDOWN_FANCY;
1294 }
1295
1296 ret = DialogBoxParamW(pgContext->hDllInstance,
1297 MAKEINTRESOURCEW(Context.bReasonUI ? IDD_SHUTDOWN_REASON : Context.ShutdownDialogId),
1298 hwndDlg,
1300 (LPARAM)&Context);
1301 }
1302
1303 // TODO: Handle shutdown reasons.
1304
1305#if 0
1306 if (ret == IDOK)
1307 SaveShutdownSelState(hKeyCurrentUser, pgContext->nShutdownAction);
1308#endif
1309
1310 return ret;
1311}
#define IDD_SHUTDOWN_FANCY
Definition: resource.h:44
#define IDD_SHUTDOWN
Definition: resource.h:43
#define IDD_SHUTDOWN_REASON
Definition: resource.h:46
#define IDD_SHUTDOWN_FANCY_LONG
Definition: resource.h:45
DWORD GetAllowedShutdownOptions(_In_opt_ HKEY hKeyCurrentUser, _In_opt_ HANDLE hUserToken)
Definition: shutdown.c:808
static BOOL GetShutdownReasonUI(VOID)
Definition: shutdown.c:123
static INT_PTR CALLBACK ShutdownDialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: shutdown.c:1092
static BOOL IsShowHibernateButtonActive(VOID)
Definition: shutdown.c:275
DWORD LoadShutdownSelState(_In_ HKEY hKeyCurrentUser)
Definition: shutdown.c:696
VOID SaveShutdownSelState(_In_ HKEY hKeyCurrentUser, _In_ DWORD ShutdownCode)
Definition: shutdown.c:759
BOOL WINAPI ShellIsFriendlyUIActive(VOID)
Definition: shutdown.c:467
return ret
Definition: mutex.c:146
LONG_PTR LPARAM
Definition: minwindef.h:175
int32_t INT_PTR
Definition: typedefs.h:64
#define IDCANCEL
Definition: winuser.h:842
#define IDOK
Definition: winuser.h:841
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
INT_PTR WINAPI DialogBoxParamW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_opt_ HWND, _In_opt_ DLGPROC, _In_ LPARAM)

Referenced by OnShutDown(), and ShellShutdownDialog().

◆ TestTokenPrivilege()

BOOL TestTokenPrivilege ( _In_opt_ HANDLE  hToken,
_In_ ULONG  Privilege 
)

Verifies whether the specified token has the given privilege.

See also
shell32!SHTestTokenPrivilegeW(), http://undoc.airesoft.co.uk/shell32.dll/SHTestTokenPrivilegeW.php and setupapi!DoesUserHavePrivilege().

Definition at line 140 of file utils.c.

143{
144 LUID PrivilegeLuid = {Privilege, 0};
145 HANDLE hNewToken = NULL;
146 PTOKEN_PRIVILEGES pTokenPriv;
148 BOOL ret = FALSE;
149
150 if (!hToken)
151 {
152 /* Open effective token */
154 if (!ret && (GetLastError() == ERROR_NO_TOKEN))
156 if (!ret || !hNewToken)
157 return FALSE;
158 hToken = hNewToken;
159 }
160
161 dwLength = 0;
164 goto Quit;
165
166 ret = FALSE;
168 if (!pTokenPriv)
169 goto Quit;
170
171 if (GetTokenInformation(hToken, TokenPrivileges, pTokenPriv, dwLength, &dwLength))
172 {
173 DWORD i, cPrivs = pTokenPriv->PrivilegeCount;
174 for (i = 0; !ret && i < cPrivs; ++i)
175 {
176 ret = RtlEqualLuid(&PrivilegeLuid, &pTokenPriv->Privileges[i].Luid);
177 }
178 }
179
180 LocalFree(pTokenPriv);
181
182Quit:
183 if (hToken == hNewToken)
184 CloseHandle(hNewToken);
185 return ret;
186}
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:294
BOOL WINAPI OpenThreadToken(HANDLE ThreadHandle, DWORD DesiredAccess, BOOL OpenAsSelf, HANDLE *TokenHandle)
Definition: security.c:336
#define GetCurrentProcess()
Definition: compat.h:759
#define LPTR
Definition: minwinbase.h:93
$ULONG PrivilegeCount
Definition: setypes.h:1035
LUID_AND_ATTRIBUTES Privileges[ANYSIZE_ARRAY]
Definition: setypes.h:1036
BOOL Privilege(LPTSTR pszPrivilege, BOOL bEnable)
Definition: user_lib.cpp:531
HANDLE WINAPI GetCurrentThread(void)
Definition: proc.c:1148
#define ERROR_NO_TOKEN
Definition: winerror.h:911
#define RtlEqualLuid(Luid1, Luid2)
Definition: rtlfuncs.h:304
#define TOKEN_QUERY
Definition: setypes.h:940
@ TokenPrivileges
Definition: setypes.h:980
struct _TOKEN_PRIVILEGES * PTOKEN_PRIVILEGES

Referenced by GetAllowedShutdownOptions(), and OnInitSecurityDlg().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( msgina  )

Variable Documentation

◆ hDllInstance

HINSTANCE hDllInstance
extern

Definition at line 17 of file browser.c.