From fa72ac51c4cb7d7a3184c718a48af589ebf9cf94 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Tue, 3 Mar 2020 01:34:21 +0100 Subject: Windows: Support using token keyfile when creating file container using command line --- src/Format/Tcformat.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'src/Format/Tcformat.c') diff --git a/src/Format/Tcformat.c b/src/Format/Tcformat.c index 3d394c16..976809de 100644 --- a/src/Format/Tcformat.c +++ b/src/Format/Tcformat.c @@ -260,6 +260,8 @@ BOOL bGuiMode = TRUE; BOOL bSystemIsGPT = FALSE; +KeyFile *FirstCmdKeyFile = NULL; + int nPbar = 0; /* Control ID of progress bar:- for format code */ wchar_t HeaderKeyGUIView [KEY_GUI_VIEW_SIZE]; @@ -488,6 +490,8 @@ static void localcleanup (void) burn (szFileName, sizeof(szFileName)); burn (szDiskFile, sizeof(szDiskFile)); + KeyFileRemoveAll (&FirstCmdKeyFile); + // Attempt to wipe the GUI fields showing portions of randpool, of the master and header keys wmemset (tmp, L'X', ARRAYSIZE(tmp)); tmp [ARRAYSIZE(tmp)-1] = 0; @@ -6176,7 +6180,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa showKeys = FALSE; bGuiMode = FALSE; - if (CmdVolumePassword.Length == 0) + if (CmdVolumePassword.Length == 0 && !FirstCmdKeyFile) AbortProcess ("ERR_PASSWORD_MISSING"); if (CmdVolumeFileSize == 0) @@ -6331,6 +6335,11 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa } } + if (!KeyFilesApply (hwndDlg, &volumePassword, FirstCmdKeyFile, NULL)) + { + exit (1); + } + volTransformThreadFunction (hwndDlg); exit (bOperationSuccess? 0 : 1); @@ -9008,6 +9017,7 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine) OptionQuickFormat, OptionFastCreateFile, OptionEnableMemoryProtection, + OptionKeyfile, }; argument args[]= @@ -9032,6 +9042,7 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine) { OptionQuickFormat, L"/quick", NULL, FALSE }, { OptionFastCreateFile, L"/fastcreatefile", NULL, FALSE }, { OptionEnableMemoryProtection, L"/protectMemory", NULL, FALSE }, + { OptionKeyfile, L"/keyfile", L"/k", FALSE }, // Internal { CommandResumeSysEncLogOn, L"/acsysenc", L"/a", TRUE }, @@ -9450,6 +9461,27 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine) } break; + case OptionKeyfile: + { + wchar_t tmpPath [2 * TC_MAX_PATH] = {0}; + if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, &i, + nNoCommandLineArgs, tmpPath, ARRAYSIZE (tmpPath))) + { + KeyFile *kf; + RelativePath2Absolute (tmpPath); + kf = (KeyFile *) malloc (sizeof (KeyFile)); + if (kf) + { + StringCchCopyW (kf->FileName, ARRAYSIZE(kf->FileName), tmpPath); + FirstCmdKeyFile = KeyFileAdd (FirstCmdKeyFile, kf); + } + } + else + AbortProcess ("COMMAND_LINE_ERROR"); + } + + break; + default: DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_COMMANDHELP_DLG), hwndDlg, (DLGPROC) CommandHelpDlgProc, (LPARAM) &as); -- cgit v1.2.3