VeraCrypt
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2015-08-25 11:42:01 +0200
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2015-09-16 01:33:11 +0200
commit4d7dc3ba25f562bea4be8898f11a97e911c48b99 (patch)
tree3a88d9a447e86a66017c145949e30406bdbf556c
parent85c1bc34e39a5e7682778c53ce68d6768346999c (diff)
downloadVeraCrypt-4d7dc3ba25f562bea4be8898f11a97e911c48b99.tar.gz
VeraCrypt-4d7dc3ba25f562bea4be8898f11a97e911c48b99.zip
Windows: first implementation of CLI support for creating volumes.
-rw-r--r--src/Common/Crypto.c4
-rw-r--r--src/Common/Format.c24
-rw-r--r--src/Common/Format.h4
-rw-r--r--src/Common/Language.xml11
-rw-r--r--src/Common/Password.c6
-rw-r--r--src/Common/Password.h2
-rw-r--r--src/Format/Tcformat.c442
-rw-r--r--src/Format/Tcformat.h2
-rw-r--r--src/Mount/Mount.c2
9 files changed, 443 insertions, 54 deletions
diff --git a/src/Common/Crypto.c b/src/Common/Crypto.c
index 0c4d59d1..ead091db 100644
--- a/src/Common/Crypto.c
+++ b/src/Common/Crypto.c
@@ -451,6 +451,6 @@ int EAGetByName (char *name)
do
{
- EAGetName (n, ea, 0);
- if (strcmp (n, name) == 0)
+ EAGetName (n, ea, 1);
+ if (_stricmp (n, name) == 0)
return ea;
}
diff --git a/src/Common/Format.c b/src/Common/Format.c
index fe1f271f..3fede6d5 100644
--- a/src/Common/Format.c
+++ b/src/Common/Format.c
@@ -285,5 +285,5 @@ begin_format:
if (dev != INVALID_HANDLE_VALUE)
{
- if (IDNO == MessageBoxW (volParams->hwndDlg, GetString ("DEVICE_IN_USE_FORMAT"), lpszTitle, MB_YESNO|MB_ICONWARNING|MB_DEFBUTTON2))
+ if (!volParams->bForceOperation && (Silent || (IDNO == MessageBoxW (volParams->hwndDlg, GetString ("DEVICE_IN_USE_FORMAT"), lpszTitle, MB_YESNO|MB_ICONWARNING|MB_DEFBUTTON2))))
{
nStatus = ERR_DONT_REPORT;
@@ -382,5 +382,5 @@ begin_format:
}
- KillTimer (volParams->hwndDlg, TIMER_ID_RANDVIEW);
+ if (volParams->hwndDlg && volParams->bGuiMode) KillTimer (volParams->hwndDlg, TIMER_ID_RANDVIEW);
/* Volume header */
@@ -619,6 +619,9 @@ error:
if (driveNo == -1)
{
- MessageBoxW (volParams->hwndDlg, GetString ("NO_FREE_DRIVES"), lpszTitle, ICON_HAND);
- MessageBoxW (volParams->hwndDlg, GetString ("FORMAT_NTFS_STOP"), lpszTitle, ICON_HAND);
+ if (!Silent)
+ {
+ MessageBoxW (volParams->hwndDlg, GetString ("NO_FREE_DRIVES"), lpszTitle, ICON_HAND);
+ MessageBoxW (volParams->hwndDlg, GetString ("FORMAT_NTFS_STOP"), lpszTitle, ICON_HAND);
+ }
nStatus = ERR_NO_FREE_DRIVES;
@@ -635,11 +638,14 @@ error:
if (MountVolume (volParams->hwndDlg, driveNo, volParams->volumePath, volParams->password, volParams->pkcs5, volParams->pim, FALSE, FALSE, TRUE, &mountOptions, FALSE, TRUE) < 1)
{
- MessageBoxW (volParams->hwndDlg, GetString ("CANT_MOUNT_VOLUME"), lpszTitle, ICON_HAND);
- MessageBoxW (volParams->hwndDlg, GetString ("FORMAT_NTFS_STOP"), lpszTitle, ICON_HAND);
+ if (!Silent)
+ {
+ MessageBoxW (volParams->hwndDlg, GetString ("CANT_MOUNT_VOLUME"), lpszTitle, ICON_HAND);
+ MessageBoxW (volParams->hwndDlg, GetString ("FORMAT_NTFS_STOP"), lpszTitle, ICON_HAND);
+ }
nStatus = ERR_VOL_MOUNT_FAILED;
goto fv_end;
}
- if (!IsAdmin () && IsUacSupported ())
+ if (!Silent && !IsAdmin () && IsUacSupported ())
retCode = UacFormatNtfs (volParams->hwndDlg, driveNo, volParams->clusterSize);
else
@@ -648,5 +654,5 @@ error:
if (retCode != TRUE)
{
- if (!UnmountVolumeAfterFormatExCall (volParams->hwndDlg, driveNo))
+ if (!UnmountVolumeAfterFormatExCall (volParams->hwndDlg, driveNo) && !Silent)
MessageBoxW (volParams->hwndDlg, GetString ("CANT_DISMOUNT_VOLUME"), lpszTitle, ICON_HAND);
@@ -670,5 +676,5 @@ error:
}
- if (!UnmountVolumeAfterFormatExCall (volParams->hwndDlg, driveNo))
+ if (!UnmountVolumeAfterFormatExCall (volParams->hwndDlg, driveNo) && !Silent)
MessageBoxW (volParams->hwndDlg, GetString ("CANT_DISMOUNT_VOLUME"), lpszTitle, ICON_HAND);
}
diff --git a/src/Common/Format.h b/src/Common/Format.h
index 20346876..3c39bec4 100644
--- a/src/Common/Format.h
+++ b/src/Common/Format.h
@@ -39,9 +39,11 @@ typedef struct
BOOL sparseFileSwitch;
BOOL quickFormat;
- int sectorSize;
+ DWORD sectorSize;
int *realClusterSize;
Password *password;
int pim;
HWND hwndDlg;
+ BOOL bForceOperation;
+ BOOL bGuiMode;
}
FORMAT_VOL_PARAMETERS;
diff --git a/src/Common/Language.xml b/src/Common/Language.xml
index df2890e4..27d7874e 100644
--- a/src/Common/Language.xml
+++ b/src/Common/Language.xml
@@ -541,5 +541,14 @@
<string lang="en" key="CONFIRM_RESTART">Your computer must be restarted.\n\nDo you want to restart it now?</string>
<string lang="en" key="ERR_GETTING_SYSTEM_ENCRYPTION_STATUS">An error occurred when obtaining the system encryption status.</string>
- <string lang="en" key="INIT_SYS_ENC">Cannot initialize application components for system encryption.</string>
+ <string lang="en" key="ERR_PASSWORD_MISSING">No password specified in the command line. The volume can't be created.</string>
+ <string lang="en" key="ERR_SIZE_MISSING">No volume size specified in the command line. The volume can't be created.</string>
+ <string lang="en" key="ERR_NTFS_INVALID_VOLUME_SIZE">The volume file size specified in the command line is incompatible with selected NTFS filesystem.</string>
+ <string lang="en" key="ERR_FAT_INVALID_VOLUME_SIZE">The volume file size specified in the command line is incompatible with selected FAT32 filesystem.</string>
+ <string lang="en" key="ERR_DYNAMIC_NOT_SUPPORTED">The filesystem on the target drive doesn't support creating sparse files which is required for dynamic volumes.</string>
+ <string lang="en" key="ERR_DEVICE_CLI_CREATE_NOT_SUPPORTED">Only container files can be created through the command line.</string>
+ <string lang="en" key="ERR_CONTAINER_SIZE_TOO_BIG">The container file size specified in the command line is greater than the available disk free space. Volume can't be created.</string>
+ <string lang="en" key="ERR_VOLUME_SIZE_TOO_SMALL">The volume size specified in the command line is too small. The volume can't be created.</string>
+ <string lang="en" key="ERR_VOLUME_SIZE_TOO_BIG">The volume size specified in the command line is too big. The volume can't be created.</string>
+ <string lang="en" key="INIT_SYS_ENC">Cannot initialize application components for system encryption.</string>
<string lang="en" key="INIT_RAND">Failed to initialize the random number generator!\n\n\n(If you report a bug in connection with this, please include the following technical information in the bug report:\n%hs, Last Error = 0x%.8X)</string>
<string lang="en" key="CAPI_RAND">Windows Crypto API failed!\n\n\n(If you report a bug in connection with this, please include the following technical information in the bug report:\n%hs, Last Error = 0x%.8X)</string>
diff --git a/src/Common/Password.c b/src/Common/Password.c
index 2dfd5373..8b44e7d5 100644
--- a/src/Common/Password.c
+++ b/src/Common/Password.c
@@ -114,5 +114,5 @@ BOOL CheckPasswordCharEncoding (HWND hPassword, Password *ptrPw)
-BOOL CheckPasswordLength (HWND hwndDlg, unsigned __int32 passwordLength, int pim, BOOL bForBoot, BOOL bSkipPasswordWarning)
+BOOL CheckPasswordLength (HWND hwndDlg, unsigned __int32 passwordLength, int pim, BOOL bForBoot, BOOL bSkipPasswordWarning, BOOL bSkipPimWarning)
{
BOOL bCustomPimSmall = ((pim != 0) && (pim < (bForBoot? 98 : 485)))? TRUE : FALSE;
@@ -133,5 +133,5 @@ BOOL CheckPasswordLength (HWND hwndDlg, unsigned __int32 passwordLength, int pim
else if (bCustomPimSmall)
{
- if (MessageBoxW (hwndDlg, GetString ("PIM_SMALL_WARNING"), lpszTitle, MB_YESNO|MB_ICONWARNING|MB_DEFBUTTON2) != IDYES)
+ if (!bSkipPimWarning && AskWarnNoYes ("PIM_SMALL_WARNING", hwndDlg) != IDYES)
return FALSE;
}
@@ -141,5 +141,5 @@ BOOL CheckPasswordLength (HWND hwndDlg, unsigned __int32 passwordLength, int pim
{
// warn that mount/boot will take more time
- MessageBoxW (hwndDlg, GetString ("PIM_LARGE_WARNING"), lpszTitle, MB_OK|MB_ICONWARNING);
+ Warning ("PIM_LARGE_WARNING", hwndDlg);
}
diff --git a/src/Common/Password.h b/src/Common/Password.h
index 04221c48..6523e88d 100644
--- a/src/Common/Password.h
+++ b/src/Common/Password.h
@@ -39,5 +39,5 @@ typedef struct
void VerifyPasswordAndUpdate ( HWND hwndDlg , HWND hButton , HWND hPassword , HWND hVerify , unsigned char *szPassword , char *szVerify, BOOL keyFilesEnabled );
-BOOL CheckPasswordLength (HWND hwndDlg, unsigned __int32 passwordLength, int pim, BOOL bForBoot, BOOL bSkipPasswordWarning);
+BOOL CheckPasswordLength (HWND hwndDlg, unsigned __int32 passwordLength, int pim, BOOL bForBoot, BOOL bSkipPasswordWarning, BOOL bSkipPimWarning);
BOOL CheckPasswordCharEncoding (HWND hPassword, Password *ptrPw);
int ChangePwd (const char *lpszVolume, Password *oldPassword, int old_pkcs5, int old_pim, BOOL truecryptMode, Password *newPassword, int pkcs5, int pim, int wipePassCount, HWND hwndDlg);
diff --git a/src/Format/Tcformat.c b/src/Format/Tcformat.c
index d520a635..7dd34196 100644
--- a/src/Format/Tcformat.c
+++ b/src/Format/Tcformat.c
@@ -157,4 +157,6 @@ BOOL DirectNonSysInplaceEncResumeMode = FALSE;
BOOL DirectNonSysInplaceDecResumeMode = FALSE;
BOOL DirectPromptNonSysInplaceEncResumeMode = FALSE;
+BOOL DirectCreationMode = FALSE;
+
volatile BOOL bInPlaceEncNonSys = FALSE; /* If TRUE, existing data on a non-system partition/volume are to be encrypted (or decrypted if bInPlaceDecNonSys is TRUE) in place (for system encryption, this flag is ignored) */
volatile BOOL bInPlaceDecNonSys = FALSE; /* If TRUE, existing data on a non-system partition/volume are to be decrypted in place (for system encryption, this flag is ignored) */
@@ -237,4 +239,19 @@ BOOL bHistoryCmdLine = FALSE; /* History control is always disabled */
BOOL ComServerMode = FALSE;
+
+Password CmdVolumePassword = {0}; /* Password passed from command line */
+int CmdVolumeEA = 0;
+int CmdVolumePkcs5 = 0;
+int CmdVolumePim = 0;
+int CmdVolumeFilesystem = FILESYS_NONE;
+unsigned __int64 CmdVolumeFileSize = 0;
+BOOL CmdSparseFileSwitch = FALSE;
+
+BOOL bForceOperation = FALSE;
+
+BOOL bOperationSuccess = FALSE;
+
+BOOL bGuiMode = TRUE;
+
int nPbar = 0; /* Control ID of progress bar:- for format code */
@@ -386,4 +403,6 @@ static void WipePasswordsAndKeyfiles (void)
burn (&szRawPassword[0], sizeof (szRawPassword));
burn (&volumePim, sizeof (volumePim));
+ burn (&CmdVolumePassword, sizeof (CmdVolumePassword));
+ burn (&CmdVolumePim, sizeof (CmdVolumePim));
SetWindowText (hPasswordInputField, "");
@@ -1459,5 +1478,5 @@ static void VerifySizeAndUpdate (HWND hwndDlg, BOOL bUpdate)
lTmp = _atoi64 (szTmp);
- int sectorSize = GetFormatSectorSize();
+ DWORD sectorSize = GetFormatSectorSize();
uint32 sectorSizeRem = (lTmp * nMultiplier) % sectorSize;
@@ -2453,5 +2472,5 @@ static void __cdecl volTransformThreadFunction (void *hwndDlgArg)
DWORD dwWin32FormatError;
BOOL bHidden;
- HWND hwndDlg = (HWND) hwndDlgArg;
+ HWND hwndDlg = (HWND) hwndDlgArg;
volatile FORMAT_VOL_PARAMETERS *volParams = (FORMAT_VOL_PARAMETERS *) malloc (sizeof(FORMAT_VOL_PARAMETERS));
@@ -2461,6 +2480,11 @@ static void __cdecl volTransformThreadFunction (void *hwndDlgArg)
VirtualLock ((LPVOID) volParams, sizeof(FORMAT_VOL_PARAMETERS));
- bVolTransformThreadRunning = TRUE;
- bVolTransformThreadToRun = FALSE;
+ bOperationSuccess = FALSE;
+
+ if (bGuiMode)
+ {
+ bVolTransformThreadRunning = TRUE;
+ bVolTransformThreadToRun = FALSE;
+ }
// Check administrator privileges
@@ -2469,10 +2493,10 @@ static void __cdecl volTransformThreadFunction (void *hwndDlgArg)
if (fileSystem == FILESYS_NTFS)
{
- if (MessageBoxW (hwndDlg, GetString ("ADMIN_PRIVILEGES_WARN_NTFS"), lpszTitle, MB_OKCANCEL|MB_ICONWARNING|MB_DEFBUTTON2) == IDCANCEL)
+ if (Silent || (MessageBoxW (hwndDlg, GetString ("ADMIN_PRIVILEGES_WARN_NTFS"), lpszTitle, MB_OKCANCEL|MB_ICONWARNING|MB_DEFBUTTON2) == IDCANCEL))
goto cancel;
}
if (bDevice)
{
- if (MessageBoxW (hwndDlg, GetString ("ADMIN_PRIVILEGES_WARN_DEVICES"), lpszTitle, MB_OKCANCEL|MB_ICONWARNING|MB_DEFBUTTON2) == IDCANCEL)
+ if (Silent || (MessageBoxW (hwndDlg, GetString ("ADMIN_PRIVILEGES_WARN_DEVICES"), lpszTitle, MB_OKCANCEL|MB_ICONWARNING|MB_DEFBUTTON2) == IDCANCEL))
goto cancel;
}
@@ -2488,5 +2512,5 @@ static void __cdecl volTransformThreadFunction (void *hwndDlgArg)
wchar_t szTmp[512];
- if (! ((bHiddenVol && !bHiddenVolHost) && errno != EACCES)) // Only ask ask for permission to overwrite an existing volume if we're not creating a hidden volume
+ if (!bForceOperation && !((bHiddenVol && !bHiddenVolHost) && errno != EACCES)) // Only ask ask for permission to overwrite an existing volume if we're not creating a hidden volume
{
StringCbPrintfW (szTmp, sizeof szTmp,
@@ -2494,5 +2518,5 @@ static void __cdecl volTransformThreadFunction (void *hwndDlgArg)
szDiskFile);
- x = MessageBoxW (hwndDlg, szTmp, lpszTitle, YES_NO|MB_ICONWARNING|MB_DEFBUTTON2);
+ x = Silent? IDNO : MessageBoxW (hwndDlg, szTmp, lpszTitle, YES_NO|MB_ICONWARNING|MB_DEFBUTTON2);
if (x != IDYES)
@@ -2507,5 +2531,5 @@ static void __cdecl volTransformThreadFunction (void *hwndDlgArg)
if (_chmod (szDiskFile, _S_IREAD | _S_IWRITE) != 0)
{
- MessageBoxW (hwndDlg, GetString ("ACCESSMODEFAIL"), lpszTitle, ICON_HAND);
+ if (!Silent) MessageBoxW (hwndDlg, GetString ("ACCESSMODEFAIL"), lpszTitle, ICON_HAND);
goto cancel;
}
@@ -2545,4 +2569,6 @@ static void __cdecl volTransformThreadFunction (void *hwndDlgArg)
volParams->pim = volumePim;
volParams->hwndDlg = hwndDlg;
+ volParams->bForceOperation = bForceOperation;
+ volParams->bGuiMode = bGuiMode;
if (bInPlaceDecNonSys)
@@ -2588,5 +2614,5 @@ static void __cdecl volTransformThreadFunction (void *hwndDlgArg)
// Format-encryption
- InitProgressBar (GetVolumeDataAreaSize (bHidden, nVolumeSize), 0, FALSE, FALSE, FALSE, TRUE);
+ if (hwndDlg && bGuiMode) InitProgressBar (GetVolumeDataAreaSize (bHidden, nVolumeSize), 0, FALSE, FALSE, FALSE, TRUE);
nStatus = TCFormatVolume (volParams);
@@ -2612,5 +2638,5 @@ static void __cdecl volTransformThreadFunction (void *hwndDlgArg)
dwWin32FormatError = GetLastError ();
- if (bHiddenVolHost && !bVolTransformThreadCancel && nStatus == 0)
+ if (bHiddenVolHost && (!bGuiMode || !bVolTransformThreadCancel) && nStatus == 0)
{
/* Auto mount the newly created hidden volume host */
@@ -2618,11 +2644,11 @@ static void __cdecl volTransformThreadFunction (void *hwndDlgArg)
{
case ERR_NO_FREE_DRIVES:
- MessageBoxW (hwndDlg, GetString ("NO_FREE_DRIVE_FOR_OUTER_VOL"), lpszTitle, ICON_HAND);
- bVolTransformThreadCancel = TRUE;
+ if (!Silent) MessageBoxW (hwndDlg, GetString ("NO_FREE_DRIVE_FOR_OUTER_VOL"), lpszTitle, ICON_HAND);
+ if (bGuiMode) bVolTransformThreadCancel = TRUE;
break;
case ERR_VOL_MOUNT_FAILED:
case ERR_PASSWORD_WRONG:
- MessageBoxW (hwndDlg, GetString ("CANT_MOUNT_OUTER_VOL"), lpszTitle, ICON_HAND);
- bVolTransformThreadCancel = TRUE;
+ if (!Silent) MessageBoxW (hwndDlg, GetString ("CANT_MOUNT_OUTER_VOL"), lpszTitle, ICON_HAND);
+ if (bGuiMode) bVolTransformThreadCancel = TRUE;
break;
}
@@ -2669,5 +2695,5 @@ static void __cdecl volTransformThreadFunction (void *hwndDlgArg)
}
}
- else if (!(bHiddenVolHost && hiddenVolHostDriveNo < 0)) // If the error was not that the hidden volume host could not be mounted (this error has already been reported to the user)
+ else if (!Silent && !(bHiddenVolHost && hiddenVolHostDriveNo < 0)) // If the error was not that the hidden volume host could not be mounted (this error has already been reported to the user)
{
StringCbPrintfW (szMsg, sizeof(szMsg), GetString ("CREATE_FAILED"), szDiskFile);
@@ -2690,4 +2716,6 @@ static void __cdecl volTransformThreadFunction (void *hwndDlgArg)
PimEnable = FALSE;
+ bOperationSuccess = TRUE;
+
if (bDevice && !bInPlaceEncNonSys)
{
@@ -2739,8 +2767,8 @@ static void __cdecl volTransformThreadFunction (void *hwndDlgArg)
burn(&szRawPassword[0], sizeof (szRawPassword));
- MessageBeep (MB_OK);
+ if (!Silent) MessageBeep (MB_OK);
}
- if (!bInPlaceEncNonSys)
+ if (!bInPlaceEncNonSys && hwndDlg && bGuiMode)
SetTimer (hwndDlg, TIMER_ID_RANDVIEW, TIMER_INTERVAL_RANDVIEW, NULL);
@@ -2752,11 +2780,14 @@ static void __cdecl volTransformThreadFunction (void *hwndDlgArg)
volParams = NULL;
- bVolTransformThreadRunning = FALSE;
- bVolTransformThreadCancel = FALSE;
+ if (bGuiMode)
+ {
+ bVolTransformThreadRunning = FALSE;
+ bVolTransformThreadCancel = FALSE;
+ }
- PostMessage (hwndDlg, bInPlaceEncNonSys ? TC_APPMSG_NONSYS_INPLACE_ENC_FINISHED : TC_APPMSG_FORMAT_FINISHED, 0, 0);
+ if (hwndDlg && bGuiMode) PostMessage (hwndDlg, bInPlaceEncNonSys ? TC_APPMSG_NONSYS_INPLACE_ENC_FINISHED : TC_APPMSG_FORMAT_FINISHED, 0, 0);
LastDialogId = "FORMAT_FINISHED";
- _endthread ();
+ if (bGuiMode) _endthread ();
}
}
@@ -2766,5 +2797,5 @@ cancel:
LastDialogId = (bInPlaceEncNonSys ? "NONSYS_INPLACE_ENC_CANCELED" : "FORMAT_CANCELED");
- if (!bInPlaceEncNonSys)
+ if (!bInPlaceEncNonSys && hwndDlg && bGuiMode)
SetTimer (hwndDlg, TIMER_ID_RANDVIEW, TIMER_INTERVAL_RANDVIEW, NULL);
@@ -2777,16 +2808,19 @@ cancel:
}
- bVolTransformThreadRunning = FALSE;
- bVolTransformThreadCancel = FALSE;
+ if (bGuiMode)
+ {
+ bVolTransformThreadRunning = FALSE;
+ bVolTransformThreadCancel = FALSE;
+ }
// Allow the OS to enter Sleep mode when idle
SetThreadExecutionState (ES_CONTINUOUS);
- PostMessage (hwndDlg, TC_APPMSG_VOL_TRANSFORM_THREAD_ENDED, 0, 0);
+ if (hwndDlg) PostMessage (hwndDlg, TC_APPMSG_VOL_TRANSFORM_THREAD_ENDED, 0, 0);
if (bHiddenVolHost && hiddenVolHostDriveNo < -1 && !bVolTransformThreadCancel) // If hidden volume host could not be mounted
AbortProcessSilent ();
- _endthread ();
+ if (bGuiMode) _endthread ();
}
@@ -3322,5 +3356,5 @@ BOOL QueryFreeSpace (HWND hwndDlg, HWND hwndTextBox, BOOL display)
}
- int sectorSize = GetFormatSectorSize();
+ DWORD sectorSize = GetFormatSectorSize();
if (sectorSize < TC_MIN_VOLUME_SECTOR_SIZE
@@ -3382,5 +3416,5 @@ static BOOL FinalPreTransformPrompts (void)
driveNo = GetDiskDeviceDriveLetter (deviceName);
- if (!(bHiddenVol && !bHiddenVolHost)) // Do not ask for permission to overwrite an existing volume if we're creating a hidden volume within it
+ if (!bForceOperation && !(bHiddenVol && !bHiddenVolHost)) // Do not ask for permission to overwrite an existing volume if we're creating a hidden volume within it
{
wchar_t drive[128];
@@ -3409,6 +3443,9 @@ static BOOL FinalPreTransformPrompts (void)
StringCbPrintfW (szTmp, sizeof(szTmp), GetString (bInPlaceEncNonSys ? (bInPlaceDecNonSys ? "NONSYS_INPLACE_DEC_CONFIRM" : "NONSYS_INPLACE_ENC_CONFIRM") : "OVERWRITEPROMPT_DEVICE"), type, szFileName, drive);
+ if (bInPlaceEncNonSys)
+ x = AskWarnYesNoString (szTmp, MainDlg);
+ else
+ x = AskWarnNoYesString (szTmp, MainDlg);
- x = MessageBoxW (MainDlg, szTmp, lpszTitle, YES_NO | MB_ICONWARNING | (bInPlaceEncNonSys ? MB_DEFBUTTON1 : MB_DEFBUTTON2));
if (x != IDYES)
return FALSE;
@@ -3496,5 +3533,5 @@ void HandleOldAssignedDriveLetter (void)
driveLetter = GetDiskDeviceDriveLetter (deviceName);
- if (!bHiddenVolHost
+ if (!Silent && !bHiddenVolHost
&& !bHiddenOS
&& driveLetter > 1) // If a drive letter is assigned to the device, but not A: or B:
@@ -4749,5 +4786,5 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
{
wstringstream s;
- int size = GetFormatSectorSize() * i;
+ DWORD size = GetFormatSectorSize() * i;
if (size > TC_MAX_FAT_CLUSTER_SIZE)
@@ -5852,4 +5889,165 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
}
+ if (DirectCreationMode)
+ {
+ char root[TC_MAX_PATH];
+ DWORD fileSystemFlags = 0;
+ uint64 dataAreaSize;
+ char szFileSystemNameBuffer[256];
+ ULARGE_INTEGER free;
+
+ showKeys = FALSE;
+ bGuiMode = FALSE;
+
+ if (CmdVolumePassword.Length == 0)
+ AbortProcess ("ERR_PASSWORD_MISSING");
+
+ if (CmdVolumeFileSize == 0)
+ AbortProcess ("ERR_SIZE_MISSING");
+
+ CreateFullVolumePath (szDiskFile, sizeof(szDiskFile), szFileName, &bDevice);
+
+ if (bDevice)
+ AbortProcess ("ERR_DEVICE_CLI_CREATE_NOT_SUPPORTED");
+
+ volumePassword = CmdVolumePassword;
+ volumePim = CmdVolumePim;
+
+ if (CmdVolumeEA > 0)
+ nVolumeEA = CmdVolumeEA;
+
+ if (CmdVolumePkcs5 > 0)
+ hash_algo = CmdVolumePkcs5;
+
+ if (CmdVolumeFilesystem > 0)
+ fileSystem = CmdVolumeFilesystem;
+ else
+ fileSystem = FILESYS_NTFS;
+
+ nVolumeSize = CmdVolumeFileSize;
+
+ // correct volume size to be multiple of sector size
+ if (bDevice && !(bHiddenVol && !bHiddenVolHost)) // If raw device but not a hidden volume
+ {
+ // do nothing. no correction is needed
+ }
+ else
+ {
+ unsigned __int64 sectorSize = (unsigned __int64) GetFormatSectorSize();
+ unsigned __int64 sectorSizeRem = nVolumeSize % sectorSize;
+
+ if (sectorSizeRem != 0)
+ nVolumeSize = nVolumeSize + (sectorSize - sectorSizeRem);
+ }
+
+ if (nVolumeSize < (bHiddenVolHost ? TC_MIN_HIDDEN_VOLUME_HOST_SIZE : (bHiddenVol ? TC_MIN_HIDDEN_VOLUME_SIZE : TC_MIN_VOLUME_SIZE)))
+ AbortProcess ("ERR_VOLUME_SIZE_TOO_SMALL");
+
+ if ( ((!bHiddenVolHost && bHiddenVol) && (nVolumeSize > nMaximumHiddenVolSize))
+ || (nVolumeSize > (bHiddenVolHost ? TC_MAX_HIDDEN_VOLUME_HOST_SIZE : TC_MAX_VOLUME_SIZE))
+ )
+ {
+ AbortProcess ("ERR_VOLUME_SIZE_TOO_BIG");
+ }
+
+ if (!GetVolumePathName (szFileName, root, sizeof (root)))
+ {
+ handleWin32Error (hwndDlg, SRC_POS);
+ exit (1);
+ }
+
+ if (CmdSparseFileSwitch)
+ {
+ /* Check if the host file system supports sparse files */
+ GetVolumeInformation (root, NULL, 0, NULL, NULL, &fileSystemFlags, NULL, 0);
+ bSparseFileSwitch = fileSystemFlags & FILE_SUPPORTS_SPARSE_FILES;
+
+ if (!bSparseFileSwitch)
+ {
+ AbortProcess ("ERR_DYNAMIC_NOT_SUPPORTED");
+ }
+ }
+
+ quickFormat = TRUE;
+
+ if (!GetDiskFreeSpaceEx (root, &free, 0, 0))
+ {
+ wchar_t szTmp[1024];
+
+ if (translateWin32Error (szTmp, sizeof (szTmp) / sizeof(szTmp[0])))
+ {
+ wchar_t szTmp2[1024];
+ StringCbPrintfW (szTmp2, sizeof(szTmp2), L"%s\n%s", GetString ("CANNOT_CALC_SPACE"), szTmp);
+ AbortProcessDirect (szTmp2);
+ }
+ else
+ {
+ handleWin32Error (hwndDlg, SRC_POS);
+ }
+
+ exit (1);
+ }
+ else
+ {
+ if (!bSparseFileSwitch && (nVolumeSize > free.QuadPart))
+ {
+ AbortProcess ("ERR_CONTAINER_SIZE_TOO_BIG");
+ }
+ }
+
+ dataAreaSize = GetVolumeDataAreaSize (bHiddenVol && !bHiddenVolHost, nVolumeSize);
+
+ if ( (fileSystem == FILESYS_NTFS) &&
+ (dataAreaSize < TC_MIN_NTFS_FS_SIZE || dataAreaSize > TC_MAX_NTFS_FS_SIZE)
+ )
+ {
+ AbortProcess ("ERR_NTFS_INVALID_VOLUME_SIZE");
+ }
+
+ if ( (fileSystem == FILESYS_FAT) &&
+ (dataAreaSize < TC_MIN_FAT_FS_SIZE || dataAreaSize > (TC_MAX_FAT_SECTOR_COUNT * GetFormatSectorSize()))
+ )
+ {
+ AbortProcess ("ERR_FAT_INVALID_VOLUME_SIZE");
+ }
+
+ /* Verify that the volume would not be too large for the host file system */
+ if (GetVolumePathName (szDiskFile, root, sizeof (root))
+ && GetVolumeInformation (root, NULL, 0, NULL, NULL, NULL, szFileSystemNameBuffer, sizeof(szFileSystemNameBuffer))
+ && !strncmp (szFileSystemNameBuffer, "FAT32", 5))
+ {
+ // The host file system is FAT32
+ if (nVolumeSize >= 4 * BYTES_PER_GB)
+ {
+ AbortProcess ("VOLUME_TOO_LARGE_FOR_FAT32");
+ }
+ }
+
+ /* Verify that the volume would not be too large for the operating system */
+ if (!IsOSAtLeast (WIN_VISTA)
+ && nVolumeSize > 2 * BYTES_PER_TB)
+ {
+ AbortProcess ("VOLUME_TOO_LARGE_FOR_WINXP");
+ }
+
+ if (volumePassword.Length > 0)
+ {
+ // Password character encoding
+ if (!CheckPasswordCharEncoding (NULL, &volumePassword))
+ {
+ AbortProcess ("UNSUPPORTED_CHARS_IN_PWD");
+ }
+ // Check password length (check also done for outer volume which is not the case in TrueCrypt).
+ else if (!CheckPasswordLength (NULL, volumePassword.Length, volumePim, FALSE, Silent, Silent))
+ {
+ exit (1);
+ }
+ }
+
+ volTransformThreadFunction (hwndDlg);
+
+ exit (bOperationSuccess? 0 : 1);
+ }
+
SHGetFolderPath (NULL, CSIDL_MYDOCUMENTS, NULL, 0, szRescueDiskISO);
StringCbCatA (szRescueDiskISO, sizeof(szRescueDiskISO), "\\VeraCrypt Rescue Disk.iso");
@@ -7103,5 +7301,5 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
}
// Check password length (check also done for outer volume which is not the case in TrueCrypt).
- else if (!CheckPasswordLength (hwndDlg, volumePassword.Length, 0, SysEncInEffect(), FALSE))
+ else if (!CheckPasswordLength (hwndDlg, volumePassword.Length, 0, SysEncInEffect(), FALSE, FALSE))
{
return 1;
@@ -7182,5 +7380,5 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
}
// Check password length (check also done for outer volume which is not the case in TrueCrypt).
- else if (!CheckPasswordLength (hwndDlg, volumePassword.Length, volumePim, SysEncInEffect(), TRUE))
+ else if (!CheckPasswordLength (hwndDlg, volumePassword.Length, volumePim, SysEncInEffect(), TRUE, FALSE))
{
return 1;
@@ -8459,4 +8657,14 @@ void ExtractCommandLine (HWND hwndDlg, char *lpszCommandLine)
CommandResumeInplaceDec,
CommandResumeInplace,
+ OptionEncryption,
+ OptionFilesystem,
+ OptionPkcs5,
+ OptionPassword,
+ OptionPim,
+ OptionSize,
+ OptionCreate,
+ OptionSilent,
+ OptionDynamic,
+ OptionForce,
};
@@ -8468,4 +8676,14 @@ void ExtractCommandLine (HWND hwndDlg, char *lpszCommandLine)
{ OptionTokenLib, "/tokenlib", NULL, FALSE },
{ OptionQuit, "/quit", "/q", FALSE },
+ { OptionEncryption, "/encryption", NULL , FALSE },
+ { OptionFilesystem, "/filesystem", NULL , FALSE },
+ { OptionPkcs5, "/hash", NULL , FALSE },
+ { OptionPassword, "/password", NULL, FALSE },
+ { OptionPim, "/pim", NULL, FALSE },
+ { OptionSize, "/size", NULL, FALSE },
+ { OptionCreate, "/create", NULL, FALSE },
+ { OptionSilent, "/silent", NULL, FALSE },
+ { OptionDynamic, "/dynamic", NULL, FALSE },
+ { OptionForce, "/force", NULL, FALSE },
// Internal
@@ -8497,4 +8715,158 @@ void ExtractCommandLine (HWND hwndDlg, char *lpszCommandLine)
switch (x)
{
+ case OptionCreate:
+ {
+ DirectCreationMode = TRUE;
+
+ if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, &i, nNoCommandLineArgs,
+ szFileName, sizeof (szFileName)))
+ {
+ RelativePath2Absolute (szFileName);
+ }
+ else
+ AbortProcess ("COMMAND_LINE_ERROR");
+ }
+ break;
+ case OptionEncryption:
+ {
+ char szTmp[64] = {0};
+ if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs,
+ &i, nNoCommandLineArgs, szTmp, sizeof (szTmp)))
+ {
+ CmdVolumeEA = EAGetByName (szTmp);
+ if (CmdVolumeEA == 0)
+ AbortProcess ("COMMAND_LINE_ERROR");
+ }
+ else
+ AbortProcess ("COMMAND_LINE_ERROR");
+ }
+ break;
+ case OptionFilesystem:
+ {
+ char szTmp[8] = {0};
+ if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs,
+ &i, nNoCommandLineArgs, szTmp, sizeof (szTmp)))
+ {
+ if (_stricmp(szTmp, "NONE") == 0)
+ CmdVolumeFilesystem = FILESYS_NONE;
+ else if (_stricmp(szTmp, "FAT32") == 0 || _stricmp(szTmp, "FAT") == 0)
+ CmdVolumeFilesystem = FILESYS_FAT;
+ else if (_stricmp(szTmp, "NTFS") == 0)
+ CmdVolumeFilesystem = FILESYS_NTFS;
+ else
+ {
+ AbortProcess ("COMMAND_LINE_ERROR");
+ }
+ }
+ else
+ AbortProcess ("COMMAND_LINE_ERROR");
+ }
+ break;
+ case OptionPassword:
+ if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, &i, nNoCommandLineArgs,
+ (char *) CmdVolumePassword.Text, sizeof (CmdVolumePassword.Text)))
+ {
+ CmdVolumePassword.Length = (unsigned __int32) strlen ((char *) CmdVolumePassword.Text);
+ }
+ else
+ AbortProcess ("COMMAND_LINE_ERROR");
+ break;
+ case OptionPkcs5:
+ {
+ char szTmp[32] = {0};
+ if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs,
+ &i, nNoCommandLineArgs, szTmp, sizeof (szTmp)))
+ {
+ if (_stricmp(szTmp, "sha512") == 0 || _stricmp(szTmp, "sha-512") == 0)
+ CmdVolumePkcs5 = SHA512;
+ else if (_stricmp(szTmp, "whirlpool") == 0)
+ CmdVolumePkcs5 = WHIRLPOOL;
+ else if (_stricmp(szTmp, "sha256") == 0 || _stricmp(szTmp, "sha-256") == 0)
+ CmdVolumePkcs5 = SHA256;
+ else if (_stricmp(szTmp, "ripemd160") == 0 || _stricmp(szTmp, "ripemd-160") == 0)
+ CmdVolumePkcs5 = RIPEMD160;
+ else
+ {
+ CmdVolumePkcs5 = 0;
+ AbortProcess ("COMMAND_LINE_ERROR");
+ }
+
+ }
+ else
+ AbortProcess ("COMMAND_LINE_ERROR");
+ }
+ break;
+
+ case OptionPim:
+ {
+ char szTmp[32] = {0};
+ if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs,
+ &i, nNoCommandLineArgs, szTmp, sizeof (szTmp)))
+ {
+ char* endPtr = NULL;
+ CmdVolumePim = (int) strtol(szTmp, &endPtr, 0);
+ if (CmdVolumePim < 0 || endPtr == szTmp || *endPtr != '\0')
+ {
+ CmdVolumePim = 0;
+ AbortProcess ("COMMAND_LINE_ERROR");
+ }
+
+ }
+ else
+ AbortProcess ("COMMAND_LINE_ERROR");
+ }
+ break;
+ case OptionSilent:
+ Silent = TRUE;
+ break;
+ case OptionDynamic:
+ CmdSparseFileSwitch = TRUE;
+ break;
+ case OptionForce:
+ bForceOperation = TRUE;
+ break;
+ case OptionSize:
+ {
+ char szTmp[32] = {0};
+ if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs,
+ &i, nNoCommandLineArgs, szTmp, sizeof (szTmp))
+ && (strlen (szTmp) >= 2)
+ )
+ {
+ /* size can be expressed in bytes or with suffixes K, M,G or T
+ * to indicate the unit to use
+ */
+ unsigned __int64 multiplier;
+ char* endPtr = NULL;
+ char lastChar = szTmp [strlen (szTmp) - 1];
+ if (lastChar >= '0' && lastChar <= '9')
+ multiplier = 1;
+ else if (lastChar == 'K' || lastChar == 'k')
+ multiplier = BYTES_PER_KB;
+ else if (lastChar == 'M' || lastChar == 'm')
+ multiplier = BYTES_PER_MB;
+ else if (lastChar == 'G' || lastChar == 'g')
+ multiplier = BYTES_PER_GB;
+ else if (lastChar == 'T' || lastChar == 't')
+ multiplier = BYTES_PER_TB;
+ else
+ AbortProcess ("COMMAND_LINE_ERROR");
+
+ if (multiplier != 1)
+ szTmp [strlen (szTmp) - 1] = 0;
+
+ CmdVolumeFileSize = _strtoui64(szTmp, &endPtr, 0);
+ if (CmdVolumeFileSize == 0 || CmdVolumeFileSize == _UI64_MAX
+ || endPtr == szTmp || *endPtr != '\0')
+ {
+ AbortProcess ("COMMAND_LINE_ERROR");
+ }
+
+ CmdVolumeFileSize *= multiplier;
+ }
+ else
+ AbortProcess ("COMMAND_LINE_ERROR");
+ }
+ break;
case CommandSysEnc:
// Encrypt system partition/drive (passed by Mount if system encryption hasn't started or to reverse decryption)
@@ -9694,5 +10066,5 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, char *lpszComm
-static int GetFormatSectorSize ()
+static DWORD GetFormatSectorSize ()
{
if (!bDevice)
diff --git a/src/Format/Tcformat.h b/src/Format/Tcformat.h
index d6d3ac4b..7e94782a 100644
--- a/src/Format/Tcformat.h
+++ b/src/Format/Tcformat.h
@@ -79,5 +79,5 @@ static void UpdateWipeProgressBar (void);
static void InitWipeProgressBar (void);
static void UpdateWipeControls (void);
-static int GetFormatSectorSize ();
+static DWORD GetFormatSectorSize ();
extern BOOL showKeys;
diff --git a/src/Mount/Mount.c b/src/Mount/Mount.c
index e67c9018..834ed198 100644
--- a/src/Mount/Mount.c
+++ b/src/Mount/Mount.c
@@ -2458,5 +2458,5 @@ BOOL CALLBACK PasswordChangeDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPAR
&& pwdChangeDlgMode == PCDM_CHANGE_PASSWORD)
{
- if (!CheckPasswordLength (hwndDlg, GetWindowTextLength(GetDlgItem (hwndDlg, IDC_PASSWORD)), pim, bSysEncPwdChangeDlgMode, FALSE))
+ if (!CheckPasswordLength (hwndDlg, GetWindowTextLength(GetDlgItem (hwndDlg, IDC_PASSWORD)), pim, bSysEncPwdChangeDlgMode, FALSE, FALSE))
return 1;
}