VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common/Dlgcode.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/Common/Dlgcode.c')
-rw-r--r--src/Common/Dlgcode.c116
1 files changed, 58 insertions, 58 deletions
diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c
index 5e26ef0f..a317f607 100644
--- a/src/Common/Dlgcode.c
+++ b/src/Common/Dlgcode.c
@@ -547,20 +547,20 @@ BOOL IsDiskError (DWORD error)
return IsDiskReadError (error) || IsDiskWriteError (error);
}
-DWORD handleWin32Error (HWND hwndDlg)
+DWORD handleWin32Error (HWND hwndDlg, const char* srcPos)
{
PWSTR lpMsgBuf;
- DWORD dwError = GetLastError ();
+ DWORD dwError = GetLastError ();
if (Silent || dwError == 0 || dwError == ERROR_INVALID_WINDOW_HANDLE)
return dwError;
// Access denied
if (dwError == ERROR_ACCESS_DENIED && !IsAdmin ())
{
- Error ("ERR_ACCESS_DENIED", hwndDlg);
+ ErrorDirect ( AppendSrcPos (GetString ("ERR_ACCESS_DENIED"), srcPos).c_str (), hwndDlg);
SetLastError (dwError); // Preserve the original error code
return dwError;
}
@@ -573,9 +573,9 @@ DWORD handleWin32Error (HWND hwndDlg)
0,
NULL
);
- MessageBoxW (hwndDlg, lpMsgBuf, lpszTitle, ICON_HAND);
+ MessageBoxW (hwndDlg, AppendSrcPos (lpMsgBuf, srcPos).c_str (), lpszTitle, ICON_HAND);
LocalFree (lpMsgBuf);
// User-friendly hardware error explanation
if (IsDiskError (dwError))
@@ -1264,9 +1264,9 @@ void InitDialog (HWND hwndDlg)
StringCbCopyW (lf.lfFaceName, sizeof(lf.lfFaceName), L"Courier New");
hFixedDigitFont = CreateFontIndirectW (&lf);
if (hFixedDigitFont == NULL)
{
- handleWin32Error (hwndDlg);
+ handleWin32Error (hwndDlg, SRC_POS);
AbortProcess ("NOFONT");
}
// Bold
@@ -1278,9 +1278,9 @@ void InitDialog (HWND hwndDlg)
StringCbCopyW (lf.lfFaceName, sizeof(lf.lfFaceName), !font ? L"Arial" : font->FaceName);
hBoldFont = CreateFontIndirectW (&lf);
if (hBoldFont == NULL)
{
- handleWin32Error (hwndDlg);
+ handleWin32Error (hwndDlg, SRC_POS);
AbortProcess ("NOFONT");
}
// Title
@@ -1292,9 +1292,9 @@ void InitDialog (HWND hwndDlg)
StringCbCopyW (lf.lfFaceName, sizeof(lf.lfFaceName),!font ? L"Times New Roman" : font->FaceName);
hTitleFont = CreateFontIndirectW (&lf);
if (hTitleFont == NULL)
{
- handleWin32Error (hwndDlg);
+ handleWin32Error (hwndDlg, SRC_POS);
AbortProcess ("NOFONT");
}
// Fixed-size
@@ -1317,9 +1317,9 @@ void InitDialog (HWND hwndDlg)
StringCbCopyW (lf.lfFaceName, sizeof(lf.lfFaceName),!font ? L"Lucida Console" : font->FaceName);
hFixedFont = CreateFontIndirectW (&lf);
if (hFixedFont == NULL)
{
- handleWin32Error (hwndDlg);
+ handleWin32Error (hwndDlg, SRC_POS);
AbortProcess ("NOFONT");
}
if (!aboutMenuAppended)
@@ -2524,9 +2524,9 @@ void InitApp (HINSTANCE hInstance, char *lpszCommandLine)
/* Get the attributes for the standard dialog class */
if ((GetClassInfo (hInst, WINDOWS_DIALOG_CLASS, &wc)) == 0)
{
- handleWin32Error (NULL);
+ handleWin32Error (NULL, SRC_POS);
AbortProcess ("INIT_REGISTER");
}
#ifndef SETUP
@@ -2542,9 +2542,9 @@ void InitApp (HINSTANCE hInstance, char *lpszCommandLine)
hDlgClass = RegisterClass (&wc);
if (hDlgClass == 0)
{
- handleWin32Error (NULL);
+ handleWin32Error (NULL, SRC_POS);
AbortProcess ("INIT_REGISTER");
}
wc.lpszClassName = TC_SPLASH_CLASS;
@@ -2554,9 +2554,9 @@ void InitApp (HINSTANCE hInstance, char *lpszCommandLine)
hSplashClass = RegisterClass (&wc);
if (hSplashClass == 0)
{
- handleWin32Error (NULL);
+ handleWin32Error (NULL, SRC_POS);
AbortProcess ("INIT_REGISTER");
}
if (GetSystemDirectory(dllPath, MAX_PATH))
@@ -2566,9 +2566,9 @@ void InitApp (HINSTANCE hInstance, char *lpszCommandLine)
// Required for RichEdit text fields to work
if ((hRichEditDll = LoadLibrary(dllPath)) == NULL)
{
// This error is fatal e.g. because legal notices could not be displayed
- handleWin32Error (NULL);
+ handleWin32Error (NULL, SRC_POS);
AbortProcess ("INIT_RICHEDIT");
}
// DPI and GUI aspect ratio
@@ -2579,9 +2579,9 @@ void InitApp (HINSTANCE hInstance, char *lpszCommandLine)
#ifndef SETUP
if (!EncryptionThreadPoolStart (ReadEncryptionThreadPoolFreeCpuCountLimit()))
{
- handleWin32Error (NULL);
+ handleWin32Error (NULL, SRC_POS);
if (hRichEditDll)
{
FreeLibrary (hRichEditDll);
hRichEditDll = NULL;
@@ -3469,9 +3469,9 @@ BOOL DoDriverInstall (HWND hwndDlg)
error:
if (bOK == FALSE && GetLastError () != ERROR_SERVICE_ALREADY_RUNNING)
{
- handleWin32Error (hwndDlg);
+ handleWin32Error (hwndDlg, SRC_POS);
MessageBoxW (hwndDlg, GetString ("DRIVER_INSTALL_FAILED"), lpszTitle, MB_ICONHAND);
}
else
bOK = TRUE;
@@ -4090,76 +4090,76 @@ std::wstring GetWrongPasswordErrorMessage (HWND hwndDlg)
return msg;
}
-void handleError (HWND hwndDlg, int code)
+void handleError (HWND hwndDlg, int code, const char* srcPos)
{
WCHAR szTmp[4096];
if (Silent) return;
switch (code & 0x0000FFFF)
{
case ERR_OS_ERROR:
- handleWin32Error (hwndDlg);
+ handleWin32Error (hwndDlg, srcPos);
break;
case ERR_OUTOFMEMORY:
- MessageBoxW (hwndDlg, GetString ("OUTOFMEMORY"), lpszTitle, ICON_HAND);
+ MessageBoxW (hwndDlg, AppendSrcPos (GetString ("OUTOFMEMORY"), srcPos).c_str(), lpszTitle, ICON_HAND);
break;
case ERR_PASSWORD_WRONG:
- MessageBoxW (hwndDlg, GetWrongPasswordErrorMessage (hwndDlg).c_str(), lpszTitle, MB_ICONWARNING);
+ MessageBoxW (hwndDlg, AppendSrcPos (GetWrongPasswordErrorMessage (hwndDlg).c_str(), srcPos).c_str(), lpszTitle, MB_ICONWARNING);
break;
case ERR_DRIVE_NOT_FOUND:
- MessageBoxW (hwndDlg, GetString ("NOT_FOUND"), lpszTitle, ICON_HAND);
+ MessageBoxW (hwndDlg, AppendSrcPos (GetString ("NOT_FOUND"), srcPos).c_str(), lpszTitle, ICON_HAND);
break;
case ERR_FILES_OPEN:
- MessageBoxW (hwndDlg, GetString ("OPENFILES_DRIVER"), lpszTitle, ICON_HAND);
+ MessageBoxW (hwndDlg, AppendSrcPos (GetString ("OPENFILES_DRIVER"), srcPos).c_str(), lpszTitle, ICON_HAND);
break;
case ERR_FILES_OPEN_LOCK:
- MessageBoxW (hwndDlg, GetString ("OPENFILES_LOCK"), lpszTitle, ICON_HAND);
+ MessageBoxW (hwndDlg, AppendSrcPos (GetString ("OPENFILES_LOCK"), srcPos).c_str(), lpszTitle, ICON_HAND);
break;
case ERR_VOL_SIZE_WRONG:
- MessageBoxW (hwndDlg, GetString ("VOL_SIZE_WRONG"), lpszTitle, ICON_HAND);
+ MessageBoxW (hwndDlg, AppendSrcPos (GetString ("VOL_SIZE_WRONG"), srcPos).c_str(), lpszTitle, ICON_HAND);
break;
case ERR_COMPRESSION_NOT_SUPPORTED:
- MessageBoxW (hwndDlg, GetString ("COMPRESSION_NOT_SUPPORTED"), lpszTitle, ICON_HAND);
+ MessageBoxW (hwndDlg, AppendSrcPos (GetString ("COMPRESSION_NOT_SUPPORTED"), srcPos).c_str(), lpszTitle, ICON_HAND);
break;
case ERR_PASSWORD_CHANGE_VOL_TYPE:
- MessageBoxW (hwndDlg, GetString ("WRONG_VOL_TYPE"), lpszTitle, ICON_HAND);
+ MessageBoxW (hwndDlg, AppendSrcPos (GetString ("WRONG_VOL_TYPE"), srcPos).c_str(), lpszTitle, ICON_HAND);
break;
case ERR_VOL_SEEKING:
- MessageBoxW (hwndDlg, GetString ("VOL_SEEKING"), lpszTitle, ICON_HAND);
+ MessageBoxW (hwndDlg, AppendSrcPos (GetString ("VOL_SEEKING"), srcPos).c_str(), lpszTitle, ICON_HAND);
break;
case ERR_CIPHER_INIT_FAILURE:
- MessageBoxW (hwndDlg, GetString ("ERR_CIPHER_INIT_FAILURE"), lpszTitle, ICON_HAND);
+ MessageBoxW (hwndDlg, AppendSrcPos (GetString ("ERR_CIPHER_INIT_FAILURE"), srcPos).c_str(), lpszTitle, ICON_HAND);
break;
case ERR_CIPHER_INIT_WEAK_KEY:
- MessageBoxW (hwndDlg, GetString ("ERR_CIPHER_INIT_WEAK_KEY"), lpszTitle, ICON_HAND);
+ MessageBoxW (hwndDlg, AppendSrcPos (GetString ("ERR_CIPHER_INIT_WEAK_KEY"), srcPos).c_str(), lpszTitle, ICON_HAND);
break;
case ERR_VOL_ALREADY_MOUNTED:
- MessageBoxW (hwndDlg, GetString ("VOL_ALREADY_MOUNTED"), lpszTitle, ICON_HAND);
+ MessageBoxW (hwndDlg, AppendSrcPos (GetString ("VOL_ALREADY_MOUNTED"), srcPos).c_str(), lpszTitle, ICON_HAND);
break;
case ERR_FILE_OPEN_FAILED:
- MessageBoxW (hwndDlg, GetString ("FILE_OPEN_FAILED"), lpszTitle, ICON_HAND);
+ MessageBoxW (hwndDlg, AppendSrcPos (GetString ("FILE_OPEN_FAILED"), srcPos).c_str(), lpszTitle, ICON_HAND);
break;
case ERR_VOL_MOUNT_FAILED:
- MessageBoxW (hwndDlg, GetString ("VOL_MOUNT_FAILED"), lpszTitle, ICON_HAND);
+ MessageBoxW (hwndDlg, AppendSrcPos (GetString ("VOL_MOUNT_FAILED"), srcPos).c_str(), lpszTitle, ICON_HAND);
break;
case ERR_NO_FREE_DRIVES:
- MessageBoxW (hwndDlg, GetString ("NO_FREE_DRIVES"), lpszTitle, ICON_HAND);
+ MessageBoxW (hwndDlg, AppendSrcPos (GetString ("NO_FREE_DRIVES"), srcPos).c_str(), lpszTitle, ICON_HAND);
break;
case ERR_ACCESS_DENIED:
- MessageBoxW (hwndDlg, GetString ("ACCESS_DENIED"), lpszTitle, ICON_HAND);
+ MessageBoxW (hwndDlg, AppendSrcPos (GetString ("ACCESS_DENIED"), srcPos).c_str(), lpszTitle, ICON_HAND);
break;
case ERR_DRIVER_VERSION:
Error ("DRIVER_VERSION", hwndDlg);
break;
case ERR_NEW_VERSION_REQUIRED:
- MessageBoxW (hwndDlg, GetString ("NEW_VERSION_REQUIRED"), lpszTitle, ICON_HAND);
+ MessageBoxW (hwndDlg, AppendSrcPos (GetString ("NEW_VERSION_REQUIRED"), srcPos).c_str(), lpszTitle, ICON_HAND);
break;
case ERR_SELF_TESTS_FAILED:
Error ("ERR_SELF_TESTS_FAILED", hwndDlg);
@@ -4191,26 +4191,26 @@ void handleError (HWND hwndDlg, int code)
break;
case ERR_UNSUPPORTED_TRUECRYPT_FORMAT:
StringCbPrintfW (szTmp, sizeof(szTmp), GetString ("UNSUPPORTED_TRUECRYPT_FORMAT"), (code >> 24), (code >> 16) & 0x000000FF);
- MessageBoxW (hwndDlg, szTmp, lpszTitle, ICON_HAND);
+ MessageBoxW (hwndDlg, AppendSrcPos (szTmp, srcPos).c_str(), lpszTitle, ICON_HAND);
break;
#ifndef SETUP
case ERR_RAND_INIT_FAILED:
StringCbPrintfW (szTmp, sizeof(szTmp), GetString ("INIT_RAND"), SRC_POS, GetLastError ());
- MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_ICONERROR);
+ MessageBoxW (hwndDlg, AppendSrcPos (szTmp, srcPos).c_str(), lpszTitle, MB_ICONERROR);
break;
case ERR_CAPI_INIT_FAILED:
StringCbPrintfW (szTmp, sizeof(szTmp), GetString ("CAPI_RAND"), SRC_POS, CryptoAPILastError);
- MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_ICONERROR);
+ MessageBoxW (hwndDlg, AppendSrcPos (szTmp, srcPos).c_str(), lpszTitle, MB_ICONERROR);
break;
#endif
default:
StringCbPrintfW (szTmp, sizeof(szTmp), GetString ("ERR_UNKNOWN"), code);
- MessageBoxW (hwndDlg, szTmp, lpszTitle, ICON_HAND);
+ MessageBoxW (hwndDlg, AppendSrcPos (szTmp, srcPos).c_str(), lpszTitle, ICON_HAND);
}
}
@@ -5209,9 +5209,9 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
#ifndef VOLFORMAT
if (Randinit ())
{
- handleError (hwndDlg, (CryptoAPILastError == ERROR_SUCCESS)? ERR_RAND_INIT_FAILED : ERR_CAPI_INIT_FAILED);
+ handleError (hwndDlg, (CryptoAPILastError == ERROR_SUCCESS)? ERR_RAND_INIT_FAILED : ERR_CAPI_INIT_FAILED, SRC_POS);
EndDialog (hwndDlg, IDCLOSE);
}
#endif
SetTimer (hwndDlg, 0xfd, RANDPOOL_DISPLAY_REFRESH_INTERVAL, NULL);
@@ -5409,9 +5409,9 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
if ((fhKeyfile = _open(szFileName, _O_CREAT|_O_TRUNC|_O_WRONLY|_O_BINARY, _S_IREAD|_S_IWRITE)) == -1)
{
TCfree(keyfile);
NormalCursor();
- handleWin32Error (hwndDlg);
+ handleWin32Error (hwndDlg, SRC_POS);
return 1;
}
if (bRandomSize)
@@ -5451,9 +5451,9 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
if (status == -1)
{
TCfree(keyfile);
NormalCursor();
- handleWin32Error (hwndDlg);
+ handleWin32Error (hwndDlg, SRC_POS);
return 1;
}
}
@@ -5775,9 +5775,9 @@ CipherTestDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
break;
if ((tmpRetVal = EAInit (ci->ea, (unsigned char *) key, ci->ks)) != ERR_SUCCESS)
{
- handleError (hwndDlg, tmpRetVal);
+ handleError (hwndDlg, tmpRetVal, SRC_POS);
crypto_close (ci);
return 1;
}
@@ -6270,9 +6270,9 @@ int DriverUnmountVolume (HWND hwndDlg, int nDosDriveNo, BOOL forced)
sizeof (unmount), &unmount, sizeof (unmount), &dwResult, NULL);
if (bResult == FALSE)
{
- handleWin32Error (hwndDlg);
+ handleWin32Error (hwndDlg, SRC_POS);
return 1;
}
#ifdef TCMOUNT
@@ -6777,9 +6777,9 @@ retry:
return -1;
}
if (!quiet && (!MultipleMountOperationInProgress || GetLastError() != ERROR_NOT_READY))
- handleWin32Error (hwndDlg);
+ handleWin32Error (hwndDlg, SRC_POS);
return -1;
}
@@ -6815,20 +6815,20 @@ retry:
DWORD dwResult;
if (DeviceIoControl (hDriver, TC_IOCTL_OPEN_TEST, &openTestStruct, sizeof (OPEN_TEST_STRUCT), &openTestStruct, sizeof (OPEN_TEST_STRUCT), &dwResult, NULL) && openTestStruct.TCBootLoaderDetected)
WarningDirect ((GetWrongPasswordErrorMessage (hwndDlg) + L"\n\n" + GetString ("HIDDEN_VOL_PROT_PASSWORD_US_KEYB_LAYOUT")).c_str(), hwndDlg);
else
- handleError (hwndDlg, mount.nReturnCode);
+ handleError (hwndDlg, mount.nReturnCode, SRC_POS);
}
}
else
- handleError (hwndDlg, mount.nReturnCode);
+ handleError (hwndDlg, mount.nReturnCode, SRC_POS);
}
return 0;
}
if (!quiet)
- handleError (hwndDlg, mount.nReturnCode);
+ handleError (hwndDlg, mount.nReturnCode, SRC_POS);
return 0;
}
@@ -7233,9 +7233,9 @@ __int64 GetStatsFreeSpaceOnPartition (const char *devicePath, float *percentFree
if (!GetDiskFreeSpaceEx (szRootPath, &freeSpaceSize, &totalNumberOfBytes, &totalNumberOfFreeBytes))
{
if (!silent)
{
- handleWin32Error (MainDlg);
+ handleWin32Error (MainDlg, SRC_POS);
Error ("CANNOT_CALC_SPACE", MainDlg);
}
return -1;
@@ -7251,9 +7251,9 @@ __int64 GetStatsFreeSpaceOnPartition (const char *devicePath, float *percentFree
if (!GetPartitionInfo (devicePath, &partitionInfo))
{
if (!silent)
{
- handleWin32Error (MainDlg);
+ handleWin32Error (MainDlg, SRC_POS);
Error ("CANT_GET_VOLSIZE", MainDlg);
}
return -1;
}
@@ -7560,9 +7560,9 @@ BOOL SaveBufferToFile (const char *inputBuffer, const char *destinationFile, DWO
if (dst == INVALID_HANDLE_VALUE)
{
SetLastError (dwLastError);
- handleWin32Error (MainDlg);
+ handleWin32Error (MainDlg, SRC_POS);
return FALSE;
}
if (bAppend)
@@ -7578,9 +7578,9 @@ BOOL SaveBufferToFile (const char *inputBuffer, const char *destinationFile, DWO
{
// If CREATE_ALWAYS is used, ERROR_ALREADY_EXISTS is returned after successful overwrite
// of an existing file (it's not an error)
if (! (GetLastError() == ERROR_ALREADY_EXISTS && !bAppend) )
- handleWin32Error (MainDlg);
+ handleWin32Error (MainDlg, SRC_POS);
}
CloseHandle (dst);
@@ -9738,9 +9738,9 @@ BOOL CALLBACK SecurityTokenPasswordDlgProc (HWND hwndDlg, UINT msg, WPARAM wPara
wchar_t passwordWide[SecurityToken::MaxPasswordLength + 1];
if (GetWindowTextW (GetDlgItem (hwndDlg, IDC_TOKEN_PASSWORD), passwordWide, SecurityToken::MaxPasswordLength + 1) == 0)
{
- handleWin32Error (hwndDlg);
+ handleWin32Error (hwndDlg, SRC_POS);
break;
}
char passwordUtf8[SecurityToken::MaxPasswordLength + 1];
@@ -10019,9 +10019,9 @@ BOOL CALLBACK SecurityTokenKeyfileDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam
DWORD keyfileSize;
byte *keyfileData = (byte *) LoadFile (keyfilePath, &keyfileSize);
if (!keyfileData)
{
- handleWin32Error (hwndDlg);
+ handleWin32Error (hwndDlg, SRC_POS);
return 1;
}
if (keyfileSize != 0)
@@ -10058,9 +10058,9 @@ BOOL CALLBACK SecurityTokenKeyfileDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam
}
else
{
SetLastError (ERROR_HANDLE_EOF);
- handleWin32Error (hwndDlg);
+ handleWin32Error (hwndDlg, SRC_POS);
}
burn (keyfileData, keyfileSize);
TCfree (keyfileData);
@@ -10090,16 +10090,16 @@ BOOL CALLBACK SecurityTokenKeyfileDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam
if (keyfileData.empty())
{
SetLastError (ERROR_HANDLE_EOF);
- handleWin32Error (hwndDlg);
+ handleWin32Error (hwndDlg, SRC_POS);
return 1;
}
finally_do_arg (vector <byte> *, &keyfileData, { burn (&finally_arg->front(), finally_arg->size()); });
if (!SaveBufferToFile ((char *) &keyfileData.front(), keyfilePath, (DWORD) keyfileData.size(), FALSE, FALSE))
- throw SystemException ();
+ throw SystemException (SRC_POS);
}
Info ("KEYFILE_EXPORTED", hwndDlg);
}
@@ -10480,9 +10480,9 @@ BOOL RemoveDeviceWriteProtection (HWND hwndDlg, char *devicePath)
FILE *f = fopen (cmdBatch, "w");
if (!f)
{
- handleWin32Error (hwndDlg);
+ handleWin32Error (hwndDlg, SRC_POS);
return FALSE;
}
fprintf (f, "@diskpart /s \"%s\"\n@pause\n@del \"%s\" \"%s\"", diskpartScript, diskpartScript, cmdBatch);
@@ -10492,9 +10492,9 @@ BOOL RemoveDeviceWriteProtection (HWND hwndDlg, char *devicePath)
f = fopen (diskpartScript, "w");
if (!f)
{
- handleWin32Error (hwndDlg);
+ handleWin32Error (hwndDlg, SRC_POS);
DeleteFile (cmdBatch);
return FALSE;
}
@@ -10630,9 +10630,9 @@ BOOL LaunchWindowsIsoBurner (HWND hwnd, const char *isoPath)
if (r <= 32)
{
SetLastError (r);
- handleWin32Error (hwnd);
+ handleWin32Error (hwnd, SRC_POS);
return FALSE;
}