/* Derived from source code of TrueCrypt 7.1a, which is Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed by the TrueCrypt License 3.0. Modifications and additions to the original source code (contained in this file) and all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ #include "System.h" #include #ifdef TC_WINDOWS #include #else #include #include #endif #include "Common/SecurityToken.h" #include "Main/Main.h" #include "Main/Application.h" #include "Main/GraphicUserInterface.h" #include "Volume/Cipher.h" #include "PreferencesDialog.h" namespace VeraCrypt { PreferencesDialog::PreferencesDialog (wxWindow* parent) : PreferencesDialogBase (parent), LastVirtualKeyPressed (0), Preferences (Gui->GetPreferences()), RestoreValidatorBell (false) { #define TC_CHECK_BOX_VALIDATOR(NAME) (TC_JOIN(NAME,CheckBox))->SetValidator (wxGenericValidator (&Preferences.NAME)); #ifdef TC_MACOSX PreferencesNotebook->SetMinSize (wxSize (Gui->GetCharWidth (PreferencesNotebook) * 108, -1)); #endif // Security TC_CHECK_BOX_VALIDATOR (DismountOnLogOff); TC_CHECK_BOX_VALIDATOR (DismountOnPowerSaving); TC_CHECK_BOX_VALIDATOR (DismountOnScreenSaver); TC_CHECK_BOX_VALIDATOR (DismountOnInactivity); DismountOnInactivitySpinCtrl->SetValidator (wxGenericValidator (&Preferences.MaxVolumeIdleTime)); TC_CHECK_BOX_VALIDATOR (ForceAutoDismount); PreserveTimestampsCheckBox->SetValidator (wxGenericValidator (&Preferences.DefaultMountOptions.PreserveTimestamps)); TC_CHECK_BOX_VALIDATOR (WipeCacheOnAutoDismount); TC_CHECK_BOX_VALIDATOR (WipeCacheOnClose); // Mount options CachePasswordsCheckBox->SetValidator (wxGenericValidator (&Preferences.DefaultMountOptions.CachePassword)); MountReadOnlyCheckBox->SetValue (Preferences.DefaultMountOptions.Protection == VolumeProtection::ReadOnly); MountRemovableCheckBox->SetValidator (wxGenericValidator (&Preferences.DefaultMountOptions.Removable)); FilesystemOptionsTextCtrl->SetValue (Preferences.DefaultMountOptions.FilesystemOptions); int index, prfInitialIndex = 0; Pkcs5PrfChoice->Append (LangString["AUTODETECTION"]); foreach_ref (const Pkcs5Kdf &kdf, Pkcs5Kdf::GetAvailableAlgorithms()) { index = Pkcs5PrfChoice->Append (kdf.GetName()); if (Preferences.DefaultMountOptions.Kdf && (Preferences.DefaultMountOptions.Kdf->GetName() == kdf.GetName()) ) { prfInitialIndex = index; } } Pkcs5PrfChoice->Select (prfInitialIndex); // Language for non-Windows #ifndef TC_WINDOWS #if defined (TC_MACOSX) wxDir languagesFolder(StringConverter::ToSingle (Application::GetExecutableDirectory()) + "/../Resources/languages/"); #else wxDir languagesFolder("/usr/share/veracrypt/languages/"); #endif wxArrayString langArray; LanguageListBox->Append("System default"); LanguageListBox->Append("English"); langEntries = { {"system", L"System default"}, {"ar", L"العربية"}, {"be", L"Беларуская"}, {"bg", L"Български"}, {"ca", L"Català"}, {"co", L"Corsu"}, {"cs", L"Čeština"}, {"da", L"Dansk"}, {"de", L"Deutsch"}, {"el", L"Ελληνικά"}, {"en", L"English"}, {"es", L"Español"}, {"et", L"Eesti"}, {"eu", L"Euskara"}, {"fa", L"فارسي"}, {"fi", L"Suomi"}, {"fr", L"Français"}, {"he", L"עברית"}, {"hu", L"Magyar"}, {"id", L"Bahasa Indonesia"}, {"it", L"Italiano"}, {"ja", L"日本語"}, {"ka", L"ქართული"}, {"ko", L"한국어"}, {"lv", L"Latviešu"}, {"nb", L"Norsk Bokmål"}, {"nl", L"Nederlands"}, {"nn", L"Norsk Nynorsk"}, {"pl", L"Polski"}, {"ro", L"Română"}, {"ru", L"Русский"}, {"pt-br", L"Português-Brasil"}, {"sk", L"Slovenčina"}, {"sl", L"Slovenščina"}, {"sv", L"Svenska"}, {"th", L"ภาษาไทย"}, {"tr", L"Türkçe"}, {"uk", L"Українська"}, {"uz", L"Ўзбекча"}, {"vi", L"Tiếng Việt"}, {"zh-cn", L"简体中文"}, {"zh-hk", L"繁體中文(香港)"}, {"zh-tw", L"繁體中文"} }; if (wxDir::Exists(languagesFolder.GetName())) { size_t langCount; langCount = wxDir::GetAllFiles(languagesFolder.GetName(), &langArray, "*.xml", wxDIR_FILES); for (size_t i = 0; i < langCount; ++i) { wxFileName filename(langArray[i]); // Get the name part of the file (without extension) wxString basename = filename.GetName(); // Check if the basename matches the pattern "Language.langId" if (basename.StartsWith("Language.")) { wxString langId = basename.AfterFirst('.'); // Verify if the language ID exists in langEntries map wxString langNative = langEntries[langId]; if (!langNative.empty()) { LanguageListBox->Append(langNative); } } } } #endif // Keyfiles TC_CHECK_BOX_VALIDATOR (UseKeyfiles); DefaultKeyfilesPanel = new KeyfilesPanel (DefaultKeyfilesPage, make_shared (Preferences.DefaultKeyfiles)); DefaultKeyfilesSizer->Add (DefaultKeyfilesPanel, 1, wxALL | wxEXPAND); DefaultKeyfilesSizer->Layout(); TC_CHECK_BOX_VALIDATOR (BackgroundTaskEnabled); TC_CHECK_BOX_VALIDATOR (CloseBackgroundTaskOnNoVolumes); CloseBackgroundTaskOnNoVolumesChe
/*
  zip_source_close.c -- close zip_source (stop reading)
  Copyright (C) 2009-2014 Dieter Baron and Thomas Klausner

  This file is part of libzip, a library to manipulate ZIP archives.
  The authors can be contacted at <libzip@nih.at>

  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions
  are met:
  1. Redistributions of source code must retain the above copyright
     notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright
     notice, this list of conditions and the following disclaimer in
     the documentation and/or other materials provided with the
     distribution.
  3. The names of the authors may not be used to endorse or promote
     products derived from this software without specific prior
     written permission.
 
  THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


#include "zipint.h"


int
zip_source_close(zip_source_t *src)
{
    if (!ZIP_SOURCE_IS_OPEN_READING(src)) {
        zip_error_set(&src->error, ZIP_ER_INVAL, 0);
        return -1;
    }
    
    src->open_count--;
    if (src->open_count == 0) {
	_zip_source_call(src, NULL, 0, ZIP_SOURCE_CLOSE);

	if (ZIP_SOURCE_IS_LAYERED(src)) {
	    if (zip_source_close(src->src) < 0) {
		zip_error_set(&src->error, ZIP_ER_INTERNAL, 0);
	    }
	}
    }

    return 0;
}
= LanguageListBox->GetString(LanguageListBox->GetSelection()); for (map::const_iterator each = langEntries.begin(); each != langEntries.end(); ++each) { if (each->second == langToFind) { Preferences.Language = each->first; #ifdef DEBUG cout << "Lang set to: " << each->first << endl; #endif } } Gui->ShowInfo (LangString["LINUX_RESTART_FOR_LANGUAGE_CHANGE"]); } Gui->SetPreferences (Preferences); try { if (securityTokenModuleChanged) { if (Preferences.SecurityTokenModule.IsEmpty()) { if (SecurityToken::IsInitialized()) SecurityToken::CloseLibrary (); } else { Gui->InitSecurityTokenLibrary(); } } } catch (exception &e) { Gui->ShowError (e); } #ifdef TC_WINDOWS // Hotkeys Hotkey::RegisterList (Gui->GetMainFrame(), Preferences.Hotkeys); #endif EndModal (wxID_OK); } void PreferencesDialog::OnPreserveTimestampsCheckBoxClick (wxCommandEvent& event) { #ifdef TC_LINUX if (!event.IsChecked()) Gui->ShowInfo (LangString["LINUX_KERNEL_CRYPT_OPTION_CHANGE_MOUNTED_HINT"]); #endif } void PreferencesDialog::OnRemoveHotkeyButtonClick (wxCommandEvent& event) { #ifdef TC_WINDOWS foreach (long item, Gui->GetListCtrlSelectedItems (HotkeyListCtrl)) { Hotkey *hotkey = reinterpret_cast (HotkeyListCtrl->GetItemData (item)); hotkey->VirtualKeyCode = 0; hotkey->VirtualKeyModifiers = 0; vector fields (HotkeyListCtrl->GetColumnCount()); fields[ColumnHotkeyDescription] = hotkey->Description; fields[ColumnHotkey] = hotkey->GetShortcutString(); Gui->UpdateListCtrlItem (HotkeyListCtrl, item, fields); UpdateHotkeyButtons(); } #endif } void PreferencesDialog::OnSelectPkcs11ModuleButtonClick (wxCommandEvent& event) { list < pair > extensions; wxString libExtension; libExtension = wxDynamicLibrary::CanonicalizeName (L"x"); #ifdef TC_MACOSX extensions.push_back (make_pair (L"dylib", LangString["DLL_FILES"].ToStdWstring())); #endif if (!libExtension.empty()) { extensions.push_back (make_pair (libExtension.Mid (libExtension.find (L'.') + 1).ToStdWstring(), LangString["DLL_FILES"].ToStdWstring())); extensions.push_back (make_pair (L"*", L"")); } string libDir; #ifdef TC_WINDOWS char sysDir[TC_MAX_PATH]; GetSystemDirectoryA (sysDir, sizeof (sysDir)); libDir = sysDir; #elif defined (TC_MACOSX) libDir = "/usr/local/lib"; #elif defined (TC_UNIX) libDir = "/usr/lib"; #endif Gui->ShowInfo ("SELECT_PKCS11_MODULE_HELP"); FilePathList files = Gui->SelectFiles (this, LangString["SELECT_PKCS11_MODULE"], false, false, extensions, libDir); if (!files.empty()) Pkcs11ModulePathTextCtrl->SetValue (wstring (*files.front())); } void PreferencesDialog::OnTimer () { #ifdef TC_WINDOWS for (UINT vKey = 0; vKey <= 0xFF; vKey++) { if (GetAsyncKeyState (vKey) < 0) { bool shift = wxGetKeyState (WXK_SHIFT); bool control = wxGetKeyState (WXK_CONTROL); bool alt = wxGetKeyState (WXK_ALT); bool win = wxGetKeyState (WXK_WINDOWS_LEFT) || wxGetKeyState (WXK_WINDOWS_RIGHT); if (!Hotkey::GetVirtualKeyCodeString (vKey).empty()) // If the key is allowed and its name has been resolved { LastVirtualKeyPressed = vKey; HotkeyShiftCheckBox->SetValue (shift); HotkeyControlCheckBox->SetValue (control); HotkeyAltCheckBox->SetValue (alt); HotkeyWinCheckBox->SetValue (win); HotkeyTextCtrl->ChangeValue (Hotkey::GetVirtualKeyCodeString (LastVirtualKeyPressed)); UpdateHotkeyButtons(); return; } } } #endif } void PreferencesDialog::UpdateHotkeyButtons() { AssignHotkeyButton->Enable (!HotkeyTextCtrl->IsEmpty() && HotkeyListCtrl->GetSelectedItemCount() > 0); bool remove = false; foreach (long item, Gui->GetListCtrlSelectedItems (HotkeyListCtrl)) { if (reinterpret_cast (HotkeyListCtrl->GetItemData (item))->VirtualKeyCode != 0) remove = true; } RemoveHotkeyButton->Enable (remove); } }