?? gina.cpp
字號:
#include "stdafx.h"
#include "Gina.h"
#include "WinLogonInterface.h"
#include "NoticeDialog.h"
#include "StatusWindow.h"
#include "SecurityOptionsDialog.h"
#include "SecurityHelper.h"
#include "RegistryHelper.h"
#include <stdio.h>
#include <winsock2.h>
#include <string>
#include <cstdlib>
#include <stdio.h>
#include "BTH_Connection.h"
#include "Base64.h"
#include <Windows.h>
#include <process.h>
#include <Winuser.h>
#include <WinAble.h>
#define LOGON_SID_SIZE 20
BTH_Connection* BTH_Conn;
static DWORD _winLogonVersion;
using namespace std;
void _cdecl test(void* dummy){
((LogonDialog *)dummy)->Show();
}
void _cdecl test1(void* dummy){
//hSASWnd = FindWindow("SAS Window class", "NoticeDialog");
//((NoticeDialog *)dummy)->Show();
}
static wchar_t* _localAllocString(const wchar_t* s) {
if (!s) return 0;
const int cb = (1 + lstrlen(s)) * sizeof *s;
wchar_t* newStr = (wchar_t*)LocalAlloc(LMEM_FIXED, cb);
if (newStr)
CopyMemory(newStr, s, cb);
else LOOM;
return newStr;
}
static BOOL _isRemoteSession() {
return 0 != GetSystemMetrics(SM_REMOTESESSION);
}
bool Gina::Start(){
if(BTH_Conn->StartBTH()&&BTH_Conn->RegisterBlueToothService()){
//_pWinLogon->wlxMessageBox(0, L"Start Bluetooth Success", L"Logon Message", MB_ICONINFORMATION);
//printf("Start Bluetooth Success\n");
return true;
}
else{
Sleep(2000);
//_pWinLogon->wlxMessageBox(0, L"Start Bluetooth failed", L"Logon Message", MB_ICONINFORMATION);
//printf("Start bluetooth failed\n");
return false;
}
}
bool Gina::WaitingForConnection(LogonDialog& ptrLD){
//_pWinLogon->wlxMessageBox(0, L"Waiting for Connection", L"Logon Message", MB_ICONINFORMATION);
bool IsListenSuccess = BTH_Conn->ListenConnection();
if(IsListenSuccess){
//nd->close();
_beginthread(test,0,&ptrLD);
//_pWinLogon->wlxMessageBox(0, L"Start Listen success", L"Logon Message", MB_ICONINFORMATION);
//printf("Start Listen success\n");
}else{
//_pWinLogon->wlxMessageBox(0, L"Start Listen failed", L"Logon Message", MB_ICONINFORMATION);
//printf("Start Listen failed\n");
return false;
}
BTH_Conn->AcceptConnection();
//_pWinLogon->wlxMessageBox(0, L"Connection estiblished", L"Logon Message", MB_ICONINFORMATION);
//printf("Connection estiblished\n");
return IsListenSuccess;
}
void Gina::StartRecieveData(bool& blnContinue, PLUID& pAuthenticationId, PHANDLE& phToken){
int i = 0;
int count =0;
while(blnContinue){
string s = *(BTH_Conn->RecieveMessage());
if(s.size() >= 4){
string s1 = s.substr(0,4);
string s2 = s.substr(4);
if (s1.compare("1100") ==0){
//set username
wchar_t *b = new wchar_t[1000];
mbstowcs(b, s2.c_str(), s2.size());
//puts(a);
if(s2.size()<8){
for(int i=0;i<8;i++){
if(b[i] == 0xfdfd || b[i] == 0xabab || b[i] == 0xcdcd ){
b[i] = 0x0000;
}
}
}else{
b[s2.size()] = 0x0000;
}
usr = b;
//_pWinLogon->wlxMessageBox(0, usr, L"This is received username", MB_ICONHAND );
}
if (s1.compare("1101") ==0){
// set password
wchar_t *b = new wchar_t[1000];
mbstowcs(b, s2.c_str(), s2.size());
if(s2.size()<8){
for(int i=0;i<8;i++){
if(b[i] == 0xfdfd || b[i] == 0xabab || b[i] == 0xcdcd ){
b[i] = 0x0000;
}
}
}else{
b[s2.size()] = 0x0000;
}
pwd = b;
//_pWinLogon->wlxMessageBox(0, pwd, L"This is received password", MB_ICONHAND );
}
if (s1.compare("1110") == 0){
DWORD win32Error;
MSV1_0_INTERACTIVE_PROFILE* pProfile = 0;
//if(SecurityHelper::CallLsaLogonUser(_hLsa, dom, usr, pwd, Interactive, pAuthenticationId, phToken, &pProfile, &win32Error)){
//_pWinLogon->wlxMessageBox(0, L"Password correct", L"This is received password", MB_ICONHAND );
//}else{
//_pWinLogon->wlxMessageBox(0, L"Password failed", L"This is received password", MB_ICONHAND );
//}
if(SecurityHelper::CallLsaLogonUser(_hLsa, dom, usr, pwd, Interactive, pAuthenticationId, phToken, &pProfile, &win32Error)){
BTH_Conn->SendMsg("true");
}else{
BTH_Conn->SendMsg("false");
}
//!SecurityHelper::CallLsaLogonUser( Interactive, pAuthenticationId, phToken, &pProfile, &win32Error)
//_pWinLogon->wlxMessageBox(0, L"Server Exiting", L"...", MB_ICONHAND );
blnContinue= false;
}
if (s1.compare("1111") == 0){
//_pWinLogon->wlxMessageBox(0, L"Server Exiting", L"...", MB_ICONHAND );
blnContinue= false;
}
}
// ack
if(BTH_Conn->IsDisconnected()) break;
}
//_pWinLogon->wlxMessageBox(0, L"ACK", L"Logon Message", MB_ICONINFORMATION);
}
void Gina::StartServer(LogonDialog& ptrLD,PLUID& pAuthenticationId,PHANDLE& phToken ){
//_pWinLogon->wlxMessageBox(0, L"Server Started", L"Logon Message", MB_ICONINFORMATION);
BTH_Conn = new BTH_Connection();
bool blnContinue=true;
while(blnContinue == true){
while((blnContinue == true) && Start()){
while((blnContinue == true)&& WaitingForConnection(ptrLD)){
StartRecieveData(blnContinue,pAuthenticationId,phToken);
}
}
}
//return 1;
}
wchar_t Gina::ToWChar(const char* nInfo, ...){
char infoString[256];
va_list marker;
va_start(marker, nInfo);
// vsprintf(infoString,nInfo,marker);
int i,lenI=(int)strlen(infoString);
wchar_t wInfo[256];
for(i=0; i<lenI; i++)
wInfo[i] = infoString[i];
wInfo[lenI] = 0;
return *wInfo;
//::MessageBoxW(NULL, wInfo, wTitle, MB_OK|MB_SETFOREGROUND|MB_TOPMOST);
}
// STATIC method
BOOL Gina::Negotiate(DWORD dwWinlogonVersion, DWORD* pdwDllVersion) {
// fail if WinLogon is not at least version 1.3
if (dwWinlogonVersion < WLX_VERSION_1_3) {
return FALSE;
}
// record which version of WinLogon we're dealing with
_winLogonVersion = dwWinlogonVersion;
LDB1(L"WinLogon version is 0x%08X", _winLogonVersion);
switch (_winLogonVersion) {
case WLX_VERSION_1_3:
case WLX_VERSION_1_4:
// we'll be whatever version WinLogon needs us to be
// we can support both 1.3 and 1.4
*pdwDllVersion = _winLogonVersion;
break;
}
return TRUE;
}
// STATIC method
BOOL Gina::Initialize(HANDLE hWlx, PVOID pWinlogonFunctions, Gina** ppNewGina) {
// to interactively debug, be sure _DEBUG is defined, and pass NULL for both hWlx and pWinlogonFunctions
#ifdef _DEBUG
IWinLogon* pWinLogon = 0;
if (pWinlogonFunctions)
pWinLogon = new WinLogonInterface(hWlx, _winLogonVersion, pWinlogonFunctions);
else pWinLogon = new MockWinLogonInterface();
#else
IWinLogon* pWinLogon = new WinLogonInterface(hWlx, _winLogonVersion, pWinlogonFunctions);
#endif
if (!pWinLogon) {
LOOM;
return FALSE;
}
HANDLE hLsa;
if (!SecurityHelper::RegisterLogonProcess(LOGON_PROCESS_NAME, &hLsa)) {
return FALSE;
}
*ppNewGina = new Gina(pWinLogon, hLsa);
if (!*ppNewGina) {
LOOM;
return FALSE;
}
return TRUE;
}
Gina::Gina(IWinLogon* pWinLogon, HANDLE hLsa)
: _pWinLogon(pWinLogon), _hLsa(hLsa), _hToken(0), _profilePath(0), _pStatusWindow(0) {
// tell WinLogon we wish to use Ctrl-Alt-Delete for our SAS
DWORD oldValue;
_pWinLogon->wlxSetOption(WLX_OPTION_USE_CTRL_ALT_DEL, TRUE, &oldValue);
if (_isRemoteSession()) {
// remote users cannot press Ctrl-Alt-Del, so we simulate it ourselves
_pWinLogon->wlxSasNotify(WLX_SAS_TYPE_CTRL_ALT_DEL);
}
}
void Gina::DisplaySASNotice() {
//FindWindow
// GenerateKey (VK_CONTROL, FALSE);
//GenerateKey (VK_MENU, FALSE);
//GenerateKey (VK_DELETE, FALSE);
//GenerateKey (VK_CONTROL, TRUE);
//GenerateKey (VK_MENU, TRUE);
//GenerateKey (VK_DELETE, TRUE);
//NoticeDialog dlg(_pWinLogon, IDD_SASNOTICE);
//dlg.Show();
_pWinLogon->wlxSasNotify(WLX_SAS_TYPE_CTRL_ALT_DEL);
////*nd = dlg;
//_beginthread(test1,0,&dlg);
}
int Gina::LoggedOutSAS(DWORD dwSasType, PLUID pAuthenticationId, PSID pLogonSid, PDWORD pdwOptions,
PHANDLE phToken, PWLX_MPR_NOTIFY_INFO pNprNotifyInfo, PVOID* ppWinLogonProfile) {
ZeroMemory(pNprNotifyInfo, sizeof *pNprNotifyInfo);
bool IsFail = false;
*pdwOptions = 0;
wchar_t* profilePath = 0;
const wchar_t* domain = 0;
const wchar_t* userName = 0;
const wchar_t* password = 0;
LogonDialog dlg = LogonDialog(_pWinLogon);
/* HANDLE hMutex;
hMutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, L"_ac952_z_cn_CTRL_ALT_DEL");
if (hMutex){
CloseHandle(hMutex);
return WLX_SAS_ACTION_NONE;
}
*/
if (WLX_SAS_TYPE_CTRL_ALT_DEL == dwSasType) {
//return prcWlxLoggedOnSAS (pWlxContext,dwSasType,pReserved);
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -