From f3c91cb05c9a3ba2651438f576d707f7a48d507b Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Wed, 7 Oct 2015 04:06:50 +0200 Subject: =?UTF-8?q?Windows:=20Don=E2=80=99t=20try=20to=20mount=20using=20e?= =?UTF-8?q?mpty=20password=20when=20default=20keyfile=20configured=20or=20?= =?UTF-8?q?keyfile=20specified=20in=20command=20line.=20Add=20option=20in?= =?UTF-8?q?=20default=20keyfiles=20dialog=20to=20restore=20the=20old=20beh?= =?UTF-8?q?avior.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Mount/Mount.c | 70 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 52 insertions(+), 18 deletions(-) (limited to 'src/Mount/Mount.c') diff --git a/src/Mount/Mount.c b/src/Mount/Mount.c index 09552c0a..ddf03faf 100644 --- a/src/Mount/Mount.c +++ b/src/Mount/Mount.c @@ -86,6 +86,9 @@ BOOL bCacheInDriver = FALSE; /* Cache any passwords we see */ BOOL bCacheInDriverDefault = FALSE; BOOL bCacheDuringMultipleMount = FALSE; BOOL bCmdCacheDuringMultipleMount = FALSE; +BOOL bTryEmptyPasswordWhenKeyfileUsed = FALSE; +BOOL bCmdTryEmptyPasswordWhenKeyfileUsed = FALSE; +BOOL bCmdTryEmptyPasswordWhenKeyfileUsedValid = FALSE; BOOL bHistoryCmdLine = FALSE; /* History control is always disabled */ BOOL bUseDifferentTrayIconIfVolMounted = TRUE; BOOL bCloseDismountedWindows=TRUE; /* Close all open explorer windows of dismounted volume */ @@ -680,6 +683,8 @@ void LoadSettingsAndCheckModified (HWND hwndDlg, BOOL bOnlyCheckModified, BOOL* ConfigReadCompareInt ("WipePasswordCacheOnExit", FALSE, &bWipeCacheOnExit, bOnlyCheckModified, pbSettingsModified); ConfigReadCompareInt ("WipeCacheOnAutoDismount", TRUE, &bWipeCacheOnAutoDismount, bOnlyCheckModified, pbSettingsModified); + ConfigReadCompareInt ("TryEmptyPasswordWhenKeyfileUsed",FALSE, &bTryEmptyPasswordWhenKeyfileUsed, bOnlyCheckModified, pbSettingsModified); + ConfigReadCompareInt ("StartOnLogon", FALSE, &bStartOnLogon, bOnlyCheckModified, pbSettingsModified); ConfigReadCompareInt ("MountDevicesOnLogon", FALSE, &bMountDevicesOnLogon, bOnlyCheckModified, pbSettingsModified); ConfigReadCompareInt ("MountFavoritesOnLogon", FALSE, &bMountFavoritesOnLogon, bOnlyCheckModified, pbSettingsModified); @@ -835,6 +840,8 @@ void SaveSettings (HWND hwndDlg) ConfigWriteInt ("WipePasswordCacheOnExit", bWipeCacheOnExit); ConfigWriteInt ("WipeCacheOnAutoDismount", bWipeCacheOnAutoDismount); + ConfigWriteInt ("TryEmptyPasswordWhenKeyfileUsed", bTryEmptyPasswordWhenKeyfileUsed); + ConfigWriteInt ("StartOnLogon", bStartOnLogon); ConfigWriteInt ("MountDevicesOnLogon", bMountDevicesOnLogon); ConfigWriteInt ("MountFavoritesOnLogon", bMountFavoritesOnLogon); @@ -4353,6 +4360,8 @@ static BOOL Mount (HWND hwndDlg, int nDosDriveNo, char *szFileName, int pim) BOOL EffectiveVolumeTrueCryptMode = CmdVolumeTrueCryptMode; int EffectiveVolumePim = (pim < 0)? CmdVolumePim : pim; BOOL bEffectiveCacheDuringMultipleMount = bCmdCacheDuringMultipleMount? TRUE: bCacheDuringMultipleMount; + BOOL bEffectiveTryEmptyPasswordWhenKeyfileUsed = bCmdTryEmptyPasswordWhenKeyfileUsedValid? bCmdTryEmptyPasswordWhenKeyfileUsed : bTryEmptyPasswordWhenKeyfileUsed; + BOOL bUseCmdVolumePassword = CmdVolumePasswordValid && ((CmdVolumePassword.Length > 0) || (KeyFilesEnable && FirstKeyFile)); /* Priority is given to command line parameters * Default values used only when nothing specified in command line @@ -4405,29 +4414,32 @@ static BOOL Mount (HWND hwndDlg, int nDosDriveNo, char *szFileName, int pim) ResetWrongPwdRetryCount (); - // First try cached passwords and if they fail ask user for a new one WaitCursor (); - // try TrueCrypt mode first since it is quick, only if pim = 0 - if (EffectiveVolumePim == 0) - mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, NULL, 0, 0, TRUE, bCacheInDriver, bForceMount, &mountOptions, Silent, FALSE); - if (!mounted) - mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, NULL, 0, EffectiveVolumePim, FALSE, bCacheInDriver, bForceMount, &mountOptions, Silent, FALSE); - - // If keyfiles are enabled, test empty password first - if (!mounted && KeyFilesEnable && FirstKeyFile) + if (!bUseCmdVolumePassword) { - Password emptyPassword; - emptyPassword.Length = 0; - - KeyFilesApply (hwndDlg, &emptyPassword, FirstKeyFile, szFileName); + // First try cached passwords and if they fail ask user for a new one // try TrueCrypt mode first since it is quick, only if pim = 0 if (EffectiveVolumePim == 0) - mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, &emptyPassword, 0, 0, TRUE, bCacheInDriver, bForceMount, &mountOptions, Silent, FALSE); + mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, NULL, 0, 0, TRUE, bCacheInDriver, bForceMount, &mountOptions, Silent, FALSE); if (!mounted) - mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, &emptyPassword, 0, EffectiveVolumePim, FALSE, bCacheInDriver, bForceMount, &mountOptions, Silent, FALSE); + mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, NULL, 0, EffectiveVolumePim, FALSE, bCacheInDriver, bForceMount, &mountOptions, Silent, FALSE); - burn (&emptyPassword, sizeof (emptyPassword)); + // If keyfiles are enabled, test empty password first + if (!mounted && KeyFilesEnable && FirstKeyFile && bEffectiveTryEmptyPasswordWhenKeyfileUsed) + { + Password emptyPassword; + emptyPassword.Length = 0; + + KeyFilesApply (hwndDlg, &emptyPassword, FirstKeyFile, szFileName); + // try TrueCrypt mode first since it is quick, only if pim = 0 + if (EffectiveVolumePim == 0) + mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, &emptyPassword, 0, 0, TRUE, bCacheInDriver, bForceMount, &mountOptions, Silent, FALSE); + if (!mounted) + mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, &emptyPassword, 0, EffectiveVolumePim, FALSE, bCacheInDriver, bForceMount, &mountOptions, Silent, FALSE); + + burn (&emptyPassword, sizeof (emptyPassword)); + } } // Test password and/or keyfiles used for the previous volume @@ -4452,7 +4464,7 @@ static BOOL Mount (HWND hwndDlg, int nDosDriveNo, char *szFileName, int pim) while (mounted == 0) { - if (CmdVolumePassword.Length > 0) + if (bUseCmdVolumePassword) { VolumePassword = CmdVolumePassword; VolumePkcs5 = EffectiveVolumePkcs5; @@ -6251,6 +6263,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa BOOL mounted = FALSE; int EffectiveVolumePkcs5 = CmdVolumePkcs5; BOOL EffectiveVolumeTrueCryptMode = CmdVolumeTrueCryptMode; + BOOL bEffectiveTryEmptyPasswordWhenKeyfileUsed = bCmdTryEmptyPasswordWhenKeyfileUsedValid? bCmdTryEmptyPasswordWhenKeyfileUsed : bTryEmptyPasswordWhenKeyfileUsed; if (!VolumePathExists (szFileName)) { @@ -6270,7 +6283,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa mounted = MountVolume (hwndDlg, szDriveLetter[0] - 'A', szFileName, NULL, EffectiveVolumePkcs5, CmdVolumePim, EffectiveVolumeTrueCryptMode, bCacheInDriver, bForceMount, &mountOptions, Silent, FALSE); // Command line password or keyfiles - if (!mounted && (CmdVolumePassword.Length != 0 || FirstCmdKeyFile)) + if (!mounted && (CmdVolumePassword.Length != 0 || (FirstCmdKeyFile && (CmdVolumePasswordValid || bEffectiveTryEmptyPasswordWhenKeyfileUsed)))) { BOOL reportBadPasswd = CmdVolumePassword.Length > 0; @@ -8086,6 +8099,7 @@ void ExtractCommandLine (HWND hwndDlg, char *lpszCommandLine) OptionPkcs5, OptionTrueCryptMode, OptionPim, + OptionTryEmptyPassword, }; argument args[]= @@ -8110,6 +8124,7 @@ void ExtractCommandLine (HWND hwndDlg, char *lpszCommandLine) { OptionTrueCryptMode, "/truecrypt", "/tc", FALSE }, { OptionVolume, "/volume", "/v", FALSE }, { CommandWipeCache, "/wipecache", "/w", FALSE }, + { OptionTryEmptyPassword, "/tryemptypass", NULL, FALSE }, }; argumentspec as; @@ -8143,6 +8158,25 @@ void ExtractCommandLine (HWND hwndDlg, char *lpszCommandLine) bBeep = TRUE; break; + case OptionTryEmptyPassword: + { + char szTmp[16] = {0}; + bCmdTryEmptyPasswordWhenKeyfileUsed = TRUE; + bCmdTryEmptyPasswordWhenKeyfileUsedValid = TRUE; + + if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, &i, nNoCommandLineArgs, + szTmp, sizeof (szTmp))) + { + if (!_stricmp(szTmp,"n") || !_stricmp(szTmp,"no")) + bCmdTryEmptyPasswordWhenKeyfileUsed = FALSE; + else if (!_stricmp(szTmp,"y") || !_stricmp(szTmp,"yes")) + bCmdTryEmptyPasswordWhenKeyfileUsed = TRUE; + else + AbortProcess ("COMMAND_LINE_ERROR"); + } + } + break; + case OptionCache: { char szTmp[16] = {0}; -- cgit v1.2.3