📄 gina.cpp
字号:
dom = L"";
usr = L"";
pwd = L"";
//Thread* t;
//_beginthread(&Gina::StartServer,0,(void *)12);
DWORD win32Error;
MSV1_0_INTERACTIVE_PROFILE* pProfile = 0;
StartServer(dlg,pAuthenticationId, phToken );
/*
if (IDOK != dlg.Show()){
return WLX_SAS_ACTION_NONE;
}
*/
//BTH_Conn->SendMsg("OK");
//_pWinLogon->wlxMessageBox(0, L"Close connection", L"Logon Message", MB_ICONEXCLAMATION);
BTH_Conn->CloseConnection();
//_pWinLogon->wlxMessageBox(0, L"Attempt the login", L"Logon Message", MB_ICONEXCLAMATION);
dlg.close();
if (!SecurityHelper::CallLsaLogonUser(_hLsa, dom, usr, pwd, Interactive, pAuthenticationId, phToken, &pProfile, &win32Error)) {
wchar_t msg[256];
Log::LookupErrorMessage(msg, sizeof msg / sizeof *msg, win32Error);
// _pWinLogon->wlxMessageBox(0, msg, L"Logon Message", MB_ICONEXCLAMATION);
IsFail = true;
return WLX_SAS_ACTION_NONE;
}
if (!SecurityHelper::ExtractProfilePath(&profilePath, pProfile)) {
_pWinLogon->wlxMessageBox(0, L"Failed to extract profile path", L"Logon Message", MB_ICONEXCLAMATION);
IsFail = true;
return WLX_SAS_ACTION_NONE;
}
/*
if(ISFail){
BTH_Conn->SendMsg("ERR");
}else{
BTH_Conn->SendMsg("OK");
}*/
LsaFreeReturnBuffer(pProfile);
domain = dom;
userName = usr;
password = pwd;
}
else if (WLX_SAS_TYPE_AUTHENTICATED == dwSasType) {
WLX_CONSOLESWITCH_CREDENTIALS_INFO_V1_0 credInfo;
ZeroMemory(&credInfo, sizeof credInfo);
credInfo.dwType = WLX_CONSOLESWITCHCREDENTIAL_TYPE_V1_0;
LDB(L"Calling WlxQueryConsoleSwitchCredentials");
if (_pWinLogon->wlxQueryConsoleSwitchCredentials(&credInfo)) {
LDB(L"WlxQueryConsoleSwitchCredentials succeeded");
*phToken = credInfo.UserToken;
profilePath = credInfo.ProfilePath;
LDB1(L"Profile Path: [%d]", profilePath ? profilePath : L"<null>");
if (!SecurityHelper::GetLogonSessionId(credInfo.UserToken, pAuthenticationId)) {
return WLX_SAS_ACTION_NONE;
}
*pdwOptions = WLX_LOGON_OPT_NO_PROFILE;
}
else {
LCF(L"WlxQueryConsoleSwitchCredentials failed");
return WLX_SAS_ACTION_NONE;
}
}
else {
LDB1(L"WARNING: Unrecognized SAS type: %d", dwSasType);
return WLX_SAS_ACTION_NONE;
}
//emule
int action = WLX_SAS_ACTION_NONE;
bool success = false;
LocalFree(_profilePath);
_profilePath = profilePath;
if (SecurityHelper::GetLogonSid(*phToken, pLogonSid, LOGON_SID_SIZE)) {
if (SecurityHelper::AllocWinLogonProfile((WLX_PROFILE_V1_0**)ppWinLogonProfile, profilePath)) {
if (WLX_SAS_TYPE_AUTHENTICATED == dwSasType) {
success = true;
action = WLX_SAS_ACTION_LOGON;
}
else {
pNprNotifyInfo->pszUserName = _localAllocString(userName);
pNprNotifyInfo->pszDomain = _localAllocString(domain);
pNprNotifyInfo->pszPassword = _localAllocString(password);
if (pNprNotifyInfo->pszUserName &&
pNprNotifyInfo->pszDomain &&
pNprNotifyInfo->pszPassword) {
success = true;
action = WLX_SAS_ACTION_LOGON;
}
}
}
}
if (success) {
_hToken = *phToken;
}
else {
CloseHandle(*phToken);
*phToken = 0;
}
return action;
}
BOOL Gina::ActivateUserShell(PWSTR pszDesktopName, PWSTR /* pszMprLogonScript */ , PVOID pEnvironment) {
int programCount;
wchar_t** programList;
if (RegistryHelper::ReadUserInitProgramList(&programList, &programCount)) {
int i;
for (i = 0; i < programCount; ++i) {
if (!SecurityHelper::CreateProcessAsUserOnDesktop(_hToken, programList[i], pszDesktopName, pEnvironment)) {
break;
}
}
RegistryHelper::FreeUserInitProgramList(programList, programCount);
VirtualFree(pEnvironment, 0, MEM_RELEASE);
return i == programCount;
}
return FALSE;
}
int Gina::LoggedOnSAS(DWORD dwSasType) {
if (WLX_SAS_TYPE_CTRL_ALT_DEL != dwSasType) return WLX_SAS_ACTION_NONE;
for (;;) {
SecurityOptionsDialog dlg(_pWinLogon, _hToken);
switch (dlg.Show()) {
case SecurityOptionsDialog::Lock: return WLX_SAS_ACTION_LOCK_WKSTA;
case SecurityOptionsDialog::Logoff: return WLX_SAS_ACTION_LOGOFF;
case SecurityOptionsDialog::Shutdown: return WLX_SAS_ACTION_SHUTDOWN;
case SecurityOptionsDialog::TaskMan: return WLX_SAS_ACTION_TASKLIST;
case WLX_DLG_SAS: continue; // show dialog again
default: return WLX_SAS_ACTION_NONE;
}
}
}
void Gina::DisplayLockedNotice() {
NoticeDialog dlg(_pWinLogon, IDD_LOCKEDNOTICE);
dlg.Show();
}
int Gina::WkstaLockedSAS(DWORD dwSasType) {
if (WLX_SAS_TYPE_CTRL_ALT_DEL != dwSasType) return WLX_SAS_ACTION_NONE;
int result = WLX_SAS_ACTION_NONE;
if (WLX_SAS_TYPE_CTRL_ALT_DEL == dwSasType) {
LogonDialog dlg(_pWinLogon);
if (IDOK == dlg.Show()) {
// attempt the login
DWORD win32Error;
HANDLE hUnlockToken;
if (SecurityHelper::CallLsaLogonUser(_hLsa, dlg.domain, dlg.userName, dlg.password, Unlock, 0, &hUnlockToken, 0, &win32Error)) {
bool isSameUser;
if (SecurityHelper::IsSameUser(hUnlockToken, _hToken, &isSameUser) && isSameUser) {
result = WLX_SAS_ACTION_UNLOCK_WKSTA;
}
else if (SecurityHelper::IsAdmin(hUnlockToken)) {
if (IDYES == _pWinLogon->wlxMessageBox(0, L"Forcefully log off the current user? He/she may lose work!", L"Log Off Windows", MB_ICONHAND | MB_YESNO | MB_DEFBUTTON2)) {
result = WLX_SAS_ACTION_FORCE_LOGOFF;
}
}
else {
_pWinLogon->wlxMessageBox(0, L"You do not have permission to force this user to log off.", L"Security", MB_ICONSTOP);
}
CloseHandle(hUnlockToken);
}
else {
wchar_t msg[256];
Log::LookupErrorMessage(msg, sizeof msg / sizeof *msg, win32Error);
_pWinLogon->wlxMessageBox(0, msg, L"Logon Message", MB_ICONEXCLAMATION);
}
}
}
return result;
}
BOOL Gina::IsLockOk() {
return TRUE;
}
BOOL Gina::IsLogoffOk() {
return TRUE;
}
void Gina::Logoff() {
if (_hToken) {
CloseHandle(_hToken);
_hToken = 0;
}
LocalFree(_profilePath);
_profilePath = 0;
}
void Gina::Shutdown(DWORD /* ShutdownType */) {
if (_hToken) {
CloseHandle(_hToken);
_hToken = 0;
}
LocalFree(_profilePath);
_profilePath = 0;
if (_hLsa) {
LsaDeregisterLogonProcess(_hLsa);
_hLsa = 0;
}
}
BOOL Gina::NetworkProviderLoad(PWLX_MPR_NOTIFY_INFO pNprNotifyInfo) {
return FALSE;
}
BOOL Gina::DisplayStatusMessage(HDESK hDesktop, DWORD /* dwOptions */, PWSTR pTitle, PWSTR pMessage) {
delete _pStatusWindow;
_pStatusWindow = new StatusWindow(hDesktop, pTitle, pMessage);
if (!_pStatusWindow) {
LOOM;
return FALSE;
}
return TRUE;
}
BOOL Gina::GetStatusMessage(DWORD* /* pdwOptions */, PWSTR /* pMessage */, DWORD /* dwBufferSize */) {
return FALSE;
}
BOOL Gina::RemoveStatusMessage() {
delete _pStatusWindow;
_pStatusWindow = 0;
return TRUE;
}
BOOL Gina::GetConsoleSwitchCredentials(WLX_CONSOLESWITCH_CREDENTIALS_INFO_V1_0* pCredInfo) {
if (WLX_CONSOLESWITCHCREDENTIAL_TYPE_V1_0 != pCredInfo->dwType) return FALSE;
ZeroMemory(pCredInfo, sizeof(*pCredInfo));
pCredInfo->dwType = WLX_CONSOLESWITCHCREDENTIAL_TYPE_V1_0;
pCredInfo->UserToken = _hToken;
if (_profilePath) {
pCredInfo->ProfileLength = sizeof(MSV1_0_INTERACTIVE_PROFILE);
pCredInfo->ProfilePath = _localAllocString(_profilePath);
if (!pCredInfo->ProfilePath) return FALSE;
}
pCredInfo->UserName = _localAllocString(L"DummyUserName");
return TRUE;
}
void Gina::DisconnectNotify() {
}
void Gina::ReconnectNotify() {
}
void Gina::GenerateKey ( int vk , BOOL bExtended)
{
KEYBDINPUT kb={0};
INPUT Input={0};
// generate down
if ( bExtended )
kb.dwFlags = KEYEVENTF_EXTENDEDKEY;
kb.wVk = vk;
Input.type = INPUT_KEYBOARD;
Input.ki = kb;
SendInput(1,&Input,sizeof(Input));
// generate up
ZeroMemory(&kb,sizeof(KEYBDINPUT));
ZeroMemory(&Input,sizeof(INPUT));
kb.dwFlags = KEYEVENTF_KEYUP;
if ( bExtended )
kb.dwFlags |= KEYEVENTF_EXTENDEDKEY;
kb.wVk = vk;
Input.type = INPUT_KEYBOARD;
Input.ki = kb;
SendInput(1,&Input,sizeof(Input));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -