Hi all,
Using C++ .net I have developed a new Gina.dll to replace the one that windows has in order to add support to Biomatrics under windows NT.
At the end of the programming phase i detected that the Logon Scripts were executed,But In login Dialog box last successfully login Username not shown in textbox of 'usernsme'
I have use "ImpersonateLoggedOnUser" for this problem ut prolem not solved.
I have read as many docs as could, but there is something missing i dont see.
//////Code
ImpersonateAndGetUserName(HANDLE hToken, wchar_t* name, int cch) {
bool result = false;
if (ImpersonateLoggedOnUser(hToken)) {
DWORD cchName = cch;
if (GetUserName(name, &cchName))
result = true;
else LCF1(L"GetUserName failed: %d", GetLastError());
RevertToSelf();
}
else LCF1(L"ImpersonateLoggedOnUser failed: %d", GetLastError());
return result;
}
// LogonDialog.cpp
//
// Gather user credentials for Logon.
//
#include "stdafx.h"
#include "LogonDialog.h"
#include "GuiHelper.h"
#include <stdio.h>
//#include <tchar.h>
#include <time.h>
#include <stdlib.h>
#include "resource.h"
#include "UFScanner.h"
#include "UFMatcher.h"
#include "UFDatabase.h"
#include "usbBiomat.h"
#include "GuiHelper.h"
#include "SecurityHelper.h"
#include<iostream>
#include <fstream>
using namespace std;
HINSTANCE hDllInstance = NULL; // My instance, for resource loading
HANDLE hGlobalWlx = NULL;
HANDLE hMyToken = NULL;
HUFDatabase m_hDatabase = NULL;
HUFMatcher m_hMatcher = NULL;
wchar_t wUserInfoUserID[256];
wchar_t wUserInfoPassword[256];
BYTE pUserInfoTemplate[MAX_TEMPLATE_SIZE];
int nUserInfoTemplateSize;
INT_PTR LogonDialog::DialogProc(UINT msg, WPARAM wp, LPARAM lp) {
switch (msg) {
case WM_INITDIALOG:
{
/* char str[50];
ifstream fin("DomainName.txt");
if(fin.is_open())
{
while(!fin.eof())
{
fin.getline(str,50);
LDB1(L"<Gyanendra>Domain Name %s:",str);
// SendMessage(hwnd,IDC_DOMAIN,0,(LPARAM)str);
// SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)pVarName[i]);
// IDC_DOMAIN -> AddString(str);
}
fin.close();
}
else LDB(L"--> <Gyanendra>Enable to open file");*/
usbBiomat::InitScannerModule();
usbBiomat::OpenDatabase();
usbBiomat::InitMatcherModule();
wchar_t loginMsg[6 + MAX_SIZE_USER_NAME];
if (SecurityHelper::ImpersonateAndGetUserName(_hToken, loginMsg + 6, MAX_SIZE_USER_NAME)) {
GuiHelper::SetControlText(_hwnd, IDC_NAME, loginMsg);
LDB1(L"<mayank>UserName %s:", loginMsg);
}
GuiHelper::CenterWindow(_hwnd);
return TRUE;
break;
}
case WM_COMMAND: {
switch (LOWORD(wp)) {
case IDOK:
GuiHelper::ExtractControlText(_hwnd, IDC_NAME, &userName);
GuiHelper::ExtractControlText(_hwnd, IDC_PASSWORD, &password);
GuiHelper::ExtractControlText(_hwnd, IDC_DOMAIN, &domain);
GuiHelper::writeDomain(domain);
LDB1(L"<mayank>DataLogin Credentials %s:%s:%s:", userName, password, domain);
EndDialog(_hwnd, IDOK);
break;
case IDCANCEL:
EndDialog(_hwnd, IDCANCEL);
break;//IDCCANCEL
case IDC_SHUTDOWN1:
EndDialog(_hwnd, IDC_SHUTDOWN1);
break;//IDC_SHUTDOWN1
case IDC_RESTART1:
EndDialog(_hwnd, IDC_RESTART1);
break;//IDC_Restart1
/*//Gyanendra
case IDC_DELFINGER:
wchar_t *pusrID;
char cusrID[256];
GuiHelper::ExtractControlText(_hwnd, IDC_DELUSER, &pusrID);
wcstombs(cusrID, pusrID, 256);
if(!UFD_RemoveDataByUserID(mv_hDatabase, cusrID))
_pWinLogon->wlxMessageBox(_hwnd, L"Finger Deleted", L"Star Link", MB_OK);
else
_pWinLogon->wlxMessageBox(_hwnd, L"Finger Not Deleted", L"Star Link", MB_OK);
break;//IDC_DELFINGER
*/
case IDC_BUTTON1://varify
{
if (usbBiomat::DoEnrollFinger(pUserInfoTemplate, &nUserInfoTemplateSize)) {
int nMatchIndex;
nMatchIndex = usbBiomat::DoIdentifyFinger(pUserInfoTemplate, nUserInfoTemplateSize);
if (nMatchIndex == -1) {
_pWinLogon->wlxMessageBox(_hwnd, L"User identification is failed.", L"Star Link", MB_ICONQUESTION | MB_OKCANCEL);
} else {
UFD_STATUS ufd_res;
char strError[128];
char strTmp[256];
char szUserID[256];
char szPassword[256];
ufd_res = UFD_GetDataByIndex(m_hDatabase, nMatchIndex, NULL, szUserID, NULL, NULL, NULL, NULL, NULL, szPassword);
if (ufd_res != UFD_OK) {
UFD_GetErrorString(ufd_res, strError);
sprintf(strTmp, "UFD_GetDataByIndex: %s\n", strError);
#ifdef DEBUGLOG
if (fpginalog != NULL) {
fprintf(fpginalog, strTmp);
fflush(fpginalog);
}
#endif
return TRUE;
} else {
//class operating overloaing, with in the new class:mayank
// wchar_t buff1[256];
// wchar_t buff2[256];
// userName = &buff1[0];
// password = &buff2[0];
size_t origsize = strlen(szUserID) + 1;
const size_t newsize = 256;
size_t convertedChars = 0;
userName = new wchar_t[newsize];
// wchar_t wcstring[newsize];
// userName = &wcstring[0];
mbstowcs_s(&convertedChars, userName, origsize, szUserID, _TRUNCATE);
// wcscat_s(wcstring, L" (wchar_t *)");
size_t origsize1 = strlen(szPassword) + 1;
const size_t newsize1 = 256;
size_t convertedChars1 = 0;
password = new wchar_t[newsize1];
// wchar_t wcstring1[newsize1];
// password = &wcstring1[0];
mbstowcs_s(&convertedChars1, password, origsize1, szPassword, _TRUNCATE);
// wcscat_s(wcstring1, L" (wchar_t *)");
GuiHelper::ExtractControlText(_hwnd, IDC_DOMAIN, &domain);
// int c1 = mbstowcs(userName, szUserID, 5);
// int c2 = mbstowcs(password, szPassword, 5);
// mbstowcs(wUserInfoUserID, szUserID, 256);
// mbstowcs(wUserInfoPassword, szPassword, 256);
LDB1(L"<mayank>FPLogin Credentials %s:%s:%s:", userName, password, domain);
// LDB1(L"<mayank>Database Saved Credentials %s:%s.%d-%d", szUserID, szPassword, c1,c2);
_pWinLogon->wlxMessageBox(_hwnd, L"User identification is succeed.", L"Star Link", MB_OK);
usbBiomat::UninitScannerModule();
usbBiomat::CloseDatabase();
usbBiomat::UninitMatcherModule();
EndDialog(_hwnd, IDC_BUTTON1);
}
}
}
}
break;
/*
case IDC_BUTTON3: //enroll new finger ID
{
if (usbBiomat::DoEnrollFinger(pUserInfoTemplate, &nUserInfoTemplateSize)) {
HUFScanner hScanner;
UFS_STATUS ufs_res;
RECT rect;
ufs_res = UFS_GetScannerHandle(0, &hScanner);
if (ufs_res == UFS_OK) {
// HDC hDC = GetDC(hImageFrame);
// GetClientRect(hImageFrame, &rect);
// UFS_DrawCaptureImageBuffer(hScanner, hDC, rect.left, rect.top, rect.right, rect.bottom, TRUE);
// ReleaseDC(hImageFrame, hDC);
} else {
#ifdef DEBUGLOG
if (fpginalog != NULL) {
fprintf(fpginalog, "UFS_GetScannerHandle: ERROR\n");
fflush(fpginalog);
}
#endif
return TRUE;
}
{
wchar_t uid[256], pwd[256], pwd2[256],l1,l2,l3;
wchar_t *puid, *ppwd, *ppwd2;
l1=GuiHelper::ExtractControlText(_hwnd, IDC_ENROLLUSR, &puid);
l2=GuiHelper::ExtractControlText(_hwnd, IDC_ENROLLPWD1, &ppwd);
l3=GuiHelper::ExtractControlText(_hwnd, IDC_ENROLLPWD2, &ppwd2);
if(!wcslen(puid))
{
_pWinLogon->wlxMessageBox(_hwnd, L"User ID cannot left blank.", L"Star Link", MB_OK);
return FALSE;
}*/ // BY Gyanendra
/* else if(!wcslen(ppwd))
{
_pWinLogon->wlxMessageBox(_hwnd, L"Password1 cannot left blank.", L"", MB_OK);
return FALSE;
}
else if(!wcslen(ppwd2))
{
_pWinLogon->wlxMessageBox(_hwnd, L"Password2 cannot left blank.", L"", MB_OK);
return FALSE;
}
*/
/* //BY GYanendra End Start
wcscpy(uid, puid);
wcscpy(pwd, ppwd);
wcscpy(pwd2, ppwd2);
if (wcscmp(pwd, pwd2) == 0) {
wcscpy(wUserInfoUserID, uid);
wcscpy(wUserInfoPassword, pwd);
} else {
_pWinLogon->wlxMessageBox(_hwnd, L"Password is not correct.", L"Star Link", MB_OK);
// SetWindowText(hPassword, L"");
// SetWindowText(hPassword2, L"");
}
UFD_STATUS ufd_res;
char strError[128];
char strTmp[256];
wchar_t wstrTmp[256];
char szUserID[256];
char szPassword[256];
wcstombs(szUserID, wUserInfoUserID, 256);
wcstombs(szPassword, wUserInfoPassword, 256);
#ifdef DEBUGLOG
if (fpginalog != NULL) {
fprintf(fpginalog, "Input user data\n");
fflush(fpginalog);
}
#endif
ufd_res = UFD_AddData(m_hDatabase, szUserID, 0, pUserInfoTemplate, nUserInfoTemplateSize, NULL, 0, szPassword);
if (ufd_res != UFD_OK) {
UFD_GetErrorString(ufd_res, strError);
sprintf(strTmp, "UFD_AddData: %s\n", strError);
mbstowcs(wstrTmp, strTmp, 256);
_pWinLogon->wlxMessageBox(_hwnd, wstrTmp, L"", MB_OK);
#ifdef DEBUGLOG
if (fpginalog != NULL) {
fprintf(fpginalog, strTmp);
fflush(fpginalog);
}
#endif
return TRUE;
} else {
_pWinLogon->wlxMessageBox(_hwnd, L"User enrollment is successfully finishied.", L"Star Link", MB_OK);
}
}
}
}
break;
*/// GYanendra
}
return TRUE;
}
}
return FALSE;
}
SO, if you know what is missing, please, answer the post, ok? Thanks.
NOTE: Sorry if this thread is posted in the wrong forum.
Waiting your expert answers,
Gyanendra