From 99c4031d89ce4f72e3899b3cac660082a1820a48 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Sun, 29 May 2016 01:30:53 +0200 Subject: Windows: better implementation for support of smart card PIN in command line. Supported now also on Format. --- src/Common/Dlgcode.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'src/Common/Dlgcode.c') diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c index 13a439e0..d70dfbcd 100644 --- a/src/Common/Dlgcode.c +++ b/src/Common/Dlgcode.c @@ -78,6 +78,7 @@ char *LastDialogId; wchar_t szHelpFile[TC_MAX_PATH]; wchar_t szHelpFile2[TC_MAX_PATH]; wchar_t SecurityTokenLibraryPath[TC_MAX_PATH]; +char CmdTokenPin [TC_MAX_PATH] = {0}; HFONT hFixedDigitFont = NULL; HFONT hBoldFont = NULL; @@ -329,6 +330,8 @@ typedef struct void cleanup () { + burn (&CmdTokenPin, sizeof (CmdTokenPin)); + /* Cleanup the GDI fonts */ if (hFixedFont != NULL) DeleteObject (hFixedFont); @@ -2535,6 +2538,8 @@ void InitApp (HINSTANCE hInstance, wchar_t *lpszCommandLine) InitOSVersionInfo(); + VirtualLock (&CmdTokenPin, sizeof (CmdTokenPin)); + InitializeCriticalSection (&csWNetCalls); LoadSystemDll (L"ntmarta.dll", &hntmartadll, TRUE, SRC_POS); @@ -10980,15 +10985,27 @@ BOOL InitSecurityTokenLibrary (HWND hwndDlg) PinRequestHandler(HWND hwnd) : m_hwnd(hwnd) {} virtual void operator() (string &str) { - HWND hParent = IsWindow (m_hwnd)? m_hwnd : GetActiveWindow(); - if (!hParent) - hParent = GetForegroundWindow (); - if (DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_TOKEN_PASSWORD), hParent, (DLGPROC) SecurityTokenPasswordDlgProc, (LPARAM) &str) == IDCANCEL) - throw UserAbort (SRC_POS); - + if (CmdTokenPin[0]) + { + str = CmdTokenPin; + } + else + { + HWND hParent = IsWindow (m_hwnd)? m_hwnd : GetActiveWindow(); + if (!hParent) + hParent = GetForegroundWindow (); + if (DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_TOKEN_PASSWORD), hParent, (DLGPROC) SecurityTokenPasswordDlgProc, (LPARAM) &str) == IDCANCEL) + throw UserAbort (SRC_POS); + } if (hCursor != NULL) SetCursor (hCursor); } + + virtual void notifyIncorrectPin () + { + // clear wrong PIN + burn (&CmdTokenPin, sizeof (CmdTokenPin)); + } }; struct WarningHandler : public SendExceptionFunctor -- cgit v1.2.3