From cbe4e96467fe7ef3c3e7147526f55d1de9564f2b Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 8 Jan 2021 20:50:42 +0300 Subject: database options dialog also went into the core --- include/m_db_int.h | 2 + libs/win32/mir_app.lib | Bin 217476 -> 217822 bytes libs/win64/mir_app.lib | Bin 213280 -> 213630 bytes plugins/Db3x_mmap/db3x_mmap.vcxproj | 1 - plugins/Db3x_mmap/db3x_mmap.vcxproj.filters | 3 - plugins/Db3x_mmap/res/db3x_mmap.rc | 32 ----------- plugins/Db3x_mmap/src/dbcrypt.cpp | 6 +- plugins/Db3x_mmap/src/dbintf.cpp | 4 +- plugins/Db3x_mmap/src/dbintf.h | 15 ++--- plugins/Db3x_mmap/src/resource.h | 6 -- plugins/Db3x_mmap/src/ui.cpp | 82 ---------------------------- plugins/Dbx_mdbx/res/dbx_mdbx.rc | 17 ------ plugins/Dbx_mdbx/src/dbcrypt.cpp | 11 ++-- plugins/Dbx_mdbx/src/dbintf.h | 12 ++-- plugins/Dbx_mdbx/src/ui.cpp | 52 +----------------- plugins/Dbx_sqlite/src/dbcrypt.cpp | 8 +++ plugins/Dbx_sqlite/src/dbintf.h | 1 + src/mir_app/res/resource.rc | 13 +++++ src/mir_app/src/MDatabaseCommonCrypt.cpp | 56 +++++++++++++++++++ src/mir_app/src/MDatabaseReadonly.cpp | 5 ++ src/mir_app/src/mir_app.def | 1 + src/mir_app/src/mir_app64.def | 1 + src/mir_app/src/resource.h | 3 + 23 files changed, 115 insertions(+), 216 deletions(-) delete mode 100644 plugins/Db3x_mmap/src/ui.cpp diff --git a/include/m_db_int.h b/include/m_db_int.h index 0293111bb1..ac414315b0 100644 --- a/include/m_db_int.h +++ b/include/m_db_int.h @@ -242,6 +242,7 @@ public: STDMETHOD_(BOOL, ReadCryptoKey)(MBinBuffer&) PURE; STDMETHOD_(BOOL, StoreCryptoKey)() PURE; + STDMETHOD_(BOOL, EnableEncryption)(BOOL) PURE; STDMETHOD_(BOOL, ReadEncryption)() PURE; }; @@ -265,6 +266,7 @@ public: STDMETHODIMP_(BOOL) StoreProvider(CRYPTO_PROVIDER*) override; STDMETHODIMP_(BOOL) ReadCryptoKey(MBinBuffer&) override; STDMETHODIMP_(BOOL) StoreCryptoKey() override; + STDMETHODIMP_(BOOL) EnableEncryption(BOOL) override; STDMETHODIMP_(BOOL) ReadEncryption() override; //////////////////////////////////////////////////////////////////////////////////////// diff --git a/libs/win32/mir_app.lib b/libs/win32/mir_app.lib index 2a9a63849e..13cc053858 100644 Binary files a/libs/win32/mir_app.lib and b/libs/win32/mir_app.lib differ diff --git a/libs/win64/mir_app.lib b/libs/win64/mir_app.lib index 1f502bfd0e..eed2ea175f 100644 Binary files a/libs/win64/mir_app.lib and b/libs/win64/mir_app.lib differ diff --git a/plugins/Db3x_mmap/db3x_mmap.vcxproj b/plugins/Db3x_mmap/db3x_mmap.vcxproj index 4018dd621c..f28649acc8 100644 --- a/plugins/Db3x_mmap/db3x_mmap.vcxproj +++ b/plugins/Db3x_mmap/db3x_mmap.vcxproj @@ -39,7 +39,6 @@ Create - diff --git a/plugins/Db3x_mmap/db3x_mmap.vcxproj.filters b/plugins/Db3x_mmap/db3x_mmap.vcxproj.filters index 2ffffc35c5..989f5c0d3a 100644 --- a/plugins/Db3x_mmap/db3x_mmap.vcxproj.filters +++ b/plugins/Db3x_mmap/db3x_mmap.vcxproj.filters @@ -35,9 +35,6 @@ Source Files - - Source Files - diff --git a/plugins/Db3x_mmap/res/db3x_mmap.rc b/plugins/Db3x_mmap/res/db3x_mmap.rc index 2f9a539203..71859ae0f9 100644 --- a/plugins/Db3x_mmap/res/db3x_mmap.rc +++ b/plugins/Db3x_mmap/res/db3x_mmap.rc @@ -18,38 +18,6 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US #pragma code_page(1252) -///////////////////////////////////////////////////////////////////////////// -// -// Dialog -// - -IDD_OPTIONS DIALOGEX 0, 0, 318, 176 -STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD -EXSTYLE WS_EX_CONTROLPARENT -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - GROUPBOX "Database encryption mode",IDC_STATIC,6,22,305,125 - CONTROL "Standard",IDC_STANDARD,"Button",BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP,12,38,292,12 - CONTROL "Total",IDC_TOTAL,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,12,95,292,12 - LTEXT "Only critical data are encrypted (passwords, security tokens, etc). All other settings and history remains unencrypted. Fast and effective, suitable for the most cases",IDC_STATIC,22,54,284,37 - LTEXT "All string settings and all events in histories are encrypted. It also makes Miranda much slower and creates a risk of losing everything you've stored in a database in case of losing password. Recommended only for paranoid users",IDC_STATIC,22,110,284,33 -END - - -///////////////////////////////////////////////////////////////////////////// -// -// DESIGNINFO -// - -#ifdef APSTUDIO_INVOKED -GUIDELINES DESIGNINFO -BEGIN - IDD_OPTIONS, DIALOG - BEGIN - END -END -#endif // APSTUDIO_INVOKED - #ifdef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // diff --git a/plugins/Db3x_mmap/src/dbcrypt.cpp b/plugins/Db3x_mmap/src/dbcrypt.cpp index 2cb8fd7c9d..b32db5408a 100644 --- a/plugins/Db3x_mmap/src/dbcrypt.cpp +++ b/plugins/Db3x_mmap/src/dbcrypt.cpp @@ -127,8 +127,11 @@ STDMETHODIMP_(BOOL) CDb3Mmap::StoreProvider(CRYPTO_PROVIDER *pProvider) ///////////////////////////////////////////////////////////////////////////////////////// -void CDb3Mmap::ToggleEncryption() +STDMETHODIMP_(BOOL) CDb3Mmap::EnableEncryption(BOOL bEnable) { + if (bEnable == m_bEncrypted) + return TRUE; + HANDLE hSave1 = g_hevSettingChanged; g_hevSettingChanged = nullptr; HANDLE hSave2 = g_hevEventAdded; g_hevEventAdded = nullptr; HANDLE hSave3 = g_hevEventDeleted; g_hevEventDeleted = nullptr; @@ -154,6 +157,7 @@ void CDb3Mmap::ToggleEncryption() g_hevEventAdded = hSave2; g_hevEventDeleted = hSave3; g_hevEventFiltered = hSave4; + return TRUE; } void CDb3Mmap::ToggleSettingsEncryption(MCONTACT contactID) diff --git a/plugins/Db3x_mmap/src/dbintf.cpp b/plugins/Db3x_mmap/src/dbintf.cpp index 121d5a3d72..6a93e801f7 100644 --- a/plugins/Db3x_mmap/src/dbintf.cpp +++ b/plugins/Db3x_mmap/src/dbintf.cpp @@ -116,13 +116,11 @@ int CDb3Mmap::Load(bool bSkipInit) if (InitMap()) return 1; if (InitModuleNames()) return 1; if (InitCrypt()) return EGROKPRF_CANTREAD; - InitDialogs(); // everything is ok, go on - if (!m_bReadOnly) { + if (!m_bReadOnly) if (m_dbHeader.version < DB_095_1_VERSION) return EGROKPRF_CANTREAD; - } FillContacts(); } diff --git a/plugins/Db3x_mmap/src/dbintf.h b/plugins/Db3x_mmap/src/dbintf.h index d1206c9483..0b3582131d 100644 --- a/plugins/Db3x_mmap/src/dbintf.h +++ b/plugins/Db3x_mmap/src/dbintf.h @@ -192,8 +192,6 @@ struct CDb3Mmap : public MDatabaseCommon, public MZeroedObject int CreateDbHeaders(const DBSignature&); int CheckDbHeaders(bool bInteractive); - void ToggleEncryption(void); - void DatabaseCorruption(wchar_t *text); void WriteSignature(DBSignature&); @@ -225,13 +223,14 @@ public: STDMETHODIMP_(BOOL) EnumModuleNames(DBMODULEENUMPROC pFunc, void *pParam) override; - STDMETHODIMP_(BOOL) ReadCryptoKey(MBinBuffer&); - STDMETHODIMP_(BOOL) StoreCryptoKey(void); + STDMETHODIMP_(BOOL) ReadCryptoKey(MBinBuffer&) override; + STDMETHODIMP_(BOOL) StoreCryptoKey(void) override; - STDMETHODIMP_(BOOL) ReadEncryption(void); + STDMETHODIMP_(BOOL) EnableEncryption(BOOL) override; + STDMETHODIMP_(BOOL) ReadEncryption(void) override; - STDMETHODIMP_(CRYPTO_PROVIDER*) ReadProvider(); - STDMETHODIMP_(BOOL) StoreProvider(CRYPTO_PROVIDER*); + STDMETHODIMP_(CRYPTO_PROVIDER*) ReadProvider() override; + STDMETHODIMP_(BOOL) StoreProvider(CRYPTO_PROVIDER*) override; STDMETHODIMP_(BOOL) GetContactSettingWorker(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv, int isStatic) override; STDMETHODIMP_(BOOL) WriteContactSettingWorker(MCONTACT contactID, DBCONTACTWRITESETTING &dbcws) override; @@ -320,6 +319,4 @@ protected: int InitCrypt(void); void ToggleEventsEncryption(MCONTACT contactID); void ToggleSettingsEncryption(MCONTACT contactID); - - void InitDialogs(); }; diff --git a/plugins/Db3x_mmap/src/resource.h b/plugins/Db3x_mmap/src/resource.h index e9f022d2f3..b696e9603f 100644 --- a/plugins/Db3x_mmap/src/resource.h +++ b/plugins/Db3x_mmap/src/resource.h @@ -3,12 +3,6 @@ // Используется D:\Others\SVN\MirandaNG\trunk\plugins\Db3x_mmap\res\db3x_mmap.rc // #define IDREMOVE 3 -#define IDI_LOGO 101 -#define IDD_OPTIONS 105 -#define IDD_SELECT_CRYPTOPROVIDER 106 -#define IDC_HEADERBAR 1001 -#define IDC_STANDARD 1007 -#define IDC_TOTAL 1008 // Next default values for new objects // diff --git a/plugins/Db3x_mmap/src/ui.cpp b/plugins/Db3x_mmap/src/ui.cpp deleted file mode 100644 index ced14b5168..0000000000 --- a/plugins/Db3x_mmap/src/ui.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/* - -Miranda NG: the free IM client for Microsoft* Windows* - -Copyright (C) 2012-20 Miranda NG team (https://miranda-ng.org) -all portions of this codebase are copyrighted to the people -listed in contributors.txt. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -#include "stdafx.h" - -///////////////////////////////////////////////////////////////////////////////////////// - -INT_PTR CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - CDb3Mmap *db = (CDb3Mmap *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - - switch (msg) { - case WM_INITDIALOG: - TranslateDialogDefault(hwndDlg); - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); - - db = (CDb3Mmap*)lParam; - CheckRadioButton(hwndDlg, IDC_STANDARD, IDC_TOTAL, IDC_STANDARD + db->isEncrypted()); - return TRUE; - - case WM_COMMAND: - if (HIWORD(wParam) == BN_CLICKED && (HWND)lParam == GetFocus()) - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - break; - - case WM_NOTIFY: - if (((LPNMHDR)lParam)->code == PSN_APPLY) { - if (IsDlgButtonChecked(hwndDlg, IDC_TOTAL) != (UINT)db->isEncrypted()) { - db->ToggleEncryption(); - CheckRadioButton(hwndDlg, IDC_STANDARD, IDC_TOTAL, IDC_STANDARD + db->isEncrypted()); - } - break; - } - break; - } - - return FALSE; -} - -static int OnOptionsInit(PVOID obj, WPARAM wParam, LPARAM) -{ - OPTIONSDIALOGPAGE odp = {}; - odp.position = -790000000; - odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONS); - odp.flags = ODPF_BOLDGROUPS; - odp.szTitle.a = LPGEN("Database"); - odp.pfnDlgProc = DlgProcOptions; - odp.dwInitParam = (LPARAM)obj; - g_plugin.addOptions(wParam, &odp); - return 0; -} - -static int OnModulesLoaded(PVOID obj, WPARAM, LPARAM) -{ - HookEventObj(ME_OPT_INITIALISE, OnOptionsInit, obj); - return 0; -} - -void CDb3Mmap::InitDialogs() -{ - hHook = HookEventObj(ME_SYSTEM_MODULESLOADED, OnModulesLoaded, this); -} diff --git a/plugins/Dbx_mdbx/res/dbx_mdbx.rc b/plugins/Dbx_mdbx/res/dbx_mdbx.rc index d727349410..e52335b93f 100644 --- a/plugins/Dbx_mdbx/res/dbx_mdbx.rc +++ b/plugins/Dbx_mdbx/res/dbx_mdbx.rc @@ -18,23 +18,6 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US #pragma code_page(1252) -///////////////////////////////////////////////////////////////////////////// -// -// Dialog -// - -IDD_OPTIONS DIALOGEX 0, 0, 318, 176 -STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD -EXSTYLE WS_EX_CONTROLPARENT -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - GROUPBOX "Database encryption mode",IDC_STATIC,6,22,305,125 - CONTROL "Standard",IDC_STANDARD,"Button",BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP,12,38,292,12 - CONTROL "Total",IDC_TOTAL,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,12,95,292,12 - LTEXT "Only critical data are encrypted (passwords, security tokens, etc). All other settings and history remains unencrypted. Fast and effective, suitable for the most cases",IDC_STATIC,22,54,284,37 - LTEXT "All string settings and all events in histories are encrypted. It also makes Miranda much slower and creates a risk of losing everything you've stored in a database in case of losing password. Recommended only for paranoid users",IDC_STATIC,22,110,284,33 -END - ///////////////////////////////////////////////////////////////////////////// // // Icon diff --git a/plugins/Dbx_mdbx/src/dbcrypt.cpp b/plugins/Dbx_mdbx/src/dbcrypt.cpp index 9f41b534e5..fc2803eadd 100644 --- a/plugins/Dbx_mdbx/src/dbcrypt.cpp +++ b/plugins/Dbx_mdbx/src/dbcrypt.cpp @@ -94,17 +94,16 @@ STDMETHODIMP_(BOOL) CDbxMDBX::StoreProvider(CRYPTO_PROVIDER *pProv) ///////////////////////////////////////////////////////////////////////////////////////// -int CDbxMDBX::EnableEncryption(bool bEncrypted) +STDMETHODIMP_(BOOL) CDbxMDBX::EnableEncryption(BOOL bEncrypted) { if (m_bEncrypted == bEncrypted) - return 0; + return TRUE; std::vector lstEvents; MDBX_stat st; mdbx_dbi_stat(StartTran(), m_dbEvents, &st, sizeof(st)); lstEvents.reserve(st.ms_entries); - { MDBX_val key, data; cursor_ptr pCursor(StartTran(), m_dbEvents); @@ -157,7 +156,7 @@ int CDbxMDBX::EnableEncryption(bool bEncrypted) memcpy(pNewDBEvent + 1, pNewBlob, nNewBlob); if (mdbx_put(trnlck, m_dbEvents, &key, &data, MDBX_UPSERT) != MDBX_SUCCESS) - return 1; + return FALSE; } } @@ -169,10 +168,10 @@ int CDbxMDBX::EnableEncryption(bool bEncrypted) txn_ptr trnlck(this); MDBX_val key = { DBKey_Crypto_IsEncrypted, sizeof(DBKey_Crypto_IsEncrypted) }, value = { &bEncrypted, sizeof(bool) }; if (mdbx_put(trnlck, m_dbCrypto, &key, &value, MDBX_UPSERT) != MDBX_SUCCESS) - return 1; + return FALSE; } DBFlush(); m_bEncrypted = bEncrypted; - return 0; + return TRUE; } diff --git a/plugins/Dbx_mdbx/src/dbintf.h b/plugins/Dbx_mdbx/src/dbintf.h index 502b126ff4..ce7ecda46e 100644 --- a/plugins/Dbx_mdbx/src/dbintf.h +++ b/plugins/Dbx_mdbx/src/dbintf.h @@ -231,7 +231,6 @@ public: int Check(void); void DBFlush(bool bForce = false); - int EnableEncryption(bool bEnable); int Load(); int Map(); @@ -273,13 +272,14 @@ public: STDMETHODIMP_(BOOL) MetaSplitHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub) override; STDMETHODIMP_(BOOL) MetaRemoveSubHistory(DBCachedContact *ccSub) override; - STDMETHODIMP_(CRYPTO_PROVIDER*) ReadProvider(void); - STDMETHODIMP_(BOOL) StoreProvider(CRYPTO_PROVIDER*); + STDMETHODIMP_(CRYPTO_PROVIDER*) ReadProvider(void) override; + STDMETHODIMP_(BOOL) StoreProvider(CRYPTO_PROVIDER*) override; - STDMETHODIMP_(BOOL) ReadEncryption(void); + STDMETHODIMP_(BOOL) EnableEncryption(BOOL) override; + STDMETHODIMP_(BOOL) ReadEncryption(void) override; - STDMETHODIMP_(BOOL) ReadCryptoKey(MBinBuffer&); - STDMETHODIMP_(BOOL) StoreCryptoKey(void); + STDMETHODIMP_(BOOL) ReadCryptoKey(MBinBuffer&) override; + STDMETHODIMP_(BOOL) StoreCryptoKey(void) override; STDMETHODIMP_(BOOL) Compact(); STDMETHODIMP_(BOOL) Backup(const wchar_t*); diff --git a/plugins/Dbx_mdbx/src/ui.cpp b/plugins/Dbx_mdbx/src/ui.cpp index e32df8d296..ced24c801d 100644 --- a/plugins/Dbx_mdbx/src/ui.cpp +++ b/plugins/Dbx_mdbx/src/ui.cpp @@ -37,63 +37,15 @@ static INT_PTR CompactMe(void* obj, WPARAM, LPARAM) ///////////////////////////////////////////////////////////////////////////////////////// -class COptionsDialog : public CDlgBase -{ - CCtrlCheck m_chkStandart; - CCtrlCheck m_chkTotal; - CDbxMDBX *m_db; - - bool OnInitDialog() override - { - m_chkStandart.SetState(!m_db->isEncrypted()); - m_chkTotal.SetState(m_db->isEncrypted()); - return true; - } - - bool OnApply() override - { - SetCursor(LoadCursor(nullptr, IDC_WAIT)); - m_db->EnableEncryption(m_chkTotal.GetState() != 0); - SetCursor(LoadCursor(nullptr, IDC_ARROW)); - m_chkStandart.SetState(!m_db->isEncrypted()); - m_chkTotal.SetState(m_db->isEncrypted()); - return true; - } - -public: - COptionsDialog(CDbxMDBX *db) : - CDlgBase(g_plugin, IDD_OPTIONS), - m_chkStandart(this, IDC_STANDARD), - m_chkTotal(this, IDC_TOTAL), - m_db(db) - { - } -}; - -static int OnOptionsInit(PVOID obj, WPARAM wParam, LPARAM) -{ - OPTIONSDIALOGPAGE odp = { sizeof(odp) }; - odp.position = -790000000; - odp.flags = ODPF_BOLDGROUPS; - odp.szTitle.a = LPGEN("Database"); - odp.pDialog = new COptionsDialog((CDbxMDBX*)obj); - g_plugin.addOptions(wParam, &odp); - return 0; -} - -///////////////////////////////////////////////////////////////////////////////////////// - static IconItem iconList[] = { { LPGEN("Compact"), "compact", IDI_COMPACT } }; -static int OnModulesLoaded(PVOID obj, WPARAM, LPARAM) +static int OnModulesLoaded(WPARAM, LPARAM) { g_plugin.registerIcon(LPGEN("Database"), iconList, "mdbx"); - HookEventObj(ME_OPT_INITIALISE, OnOptionsInit, obj); - // main menu item CMenuItem mi(&g_plugin); mi.root = g_plugin.addRootMenu(MO_MAIN, LPGENW("Database"), 500000000, 0); @@ -113,5 +65,5 @@ void CDbxMDBX::InitDialogs() { hService[0] = CreateServiceFunctionObj(MS_DB_COMPACT, CompactMe, this); - hHook = HookEventObj(ME_SYSTEM_MODULESLOADED, OnModulesLoaded, this); + hHook = HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded); } diff --git a/plugins/Dbx_sqlite/src/dbcrypt.cpp b/plugins/Dbx_sqlite/src/dbcrypt.cpp index af4aa22682..8ba9ae64fa 100644 --- a/plugins/Dbx_sqlite/src/dbcrypt.cpp +++ b/plugins/Dbx_sqlite/src/dbcrypt.cpp @@ -67,3 +67,11 @@ STDMETHODIMP_(BOOL) CDbxSQLite::StoreProvider(CRYPTO_PROVIDER *pProvider) WriteContactSetting(0, &dbcws); return TRUE; } + +///////////////////////////////////////////////////////////////////////////////////////// +// Toggles full/partial encryption mode + +STDMETHODIMP_(BOOL) CDbxSQLite::EnableEncryption(BOOL) +{ + return FALSE; +} diff --git a/plugins/Dbx_sqlite/src/dbintf.h b/plugins/Dbx_sqlite/src/dbintf.h index 88638623a5..e3e2fc46d7 100755 --- a/plugins/Dbx_sqlite/src/dbintf.h +++ b/plugins/Dbx_sqlite/src/dbintf.h @@ -97,6 +97,7 @@ public: STDMETHODIMP_(CRYPTO_PROVIDER*) ReadProvider() override; STDMETHODIMP_(BOOL) StoreProvider(CRYPTO_PROVIDER*) override; + STDMETHODIMP_(BOOL) EnableEncryption(BOOL) override; STDMETHODIMP_(BOOL) ReadEncryption() override; STDMETHODIMP_(BOOL) WriteContactSettingWorker(MCONTACT contactID, DBCONTACTWRITESETTING &dbcws) override; diff --git a/src/mir_app/res/resource.rc b/src/mir_app/res/resource.rc index bc6d0d9d75..cd5f6037e3 100644 --- a/src/mir_app/res/resource.rc +++ b/src/mir_app/res/resource.rc @@ -939,6 +939,19 @@ BEGIN LTEXT "Old password",IDC_STATIC,11,31,140,10,0,WS_EX_TRANSPARENT END +IDD_OPT_DATABASE DIALOGEX 0, 0, 318, 176 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD +EXSTYLE WS_EX_CONTROLPARENT +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + GROUPBOX "Database encryption mode",IDC_STATIC,6,22,305,125 + CONTROL "Standard",IDC_STANDARD,"Button",BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP,12,38,292,12 + CONTROL "Total",IDC_TOTAL,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,12,95,292,12 + LTEXT "Only critical data are encrypted (passwords, security tokens, etc). All other settings and history remains unencrypted. Fast and effective, suitable for the most cases",IDC_STATIC,22,54,284,37 + LTEXT "All string settings and all events in histories are encrypted. It also makes Miranda much slower and creates a risk of losing everything you've stored in a database in case of losing password. Recommended only for paranoid users",IDC_STATIC,22,110,284,33 + PUSHBUTTON "Set password",IDC_USERPASS1,200,153,111,17 +END + ///////////////////////////////////////////////////////////////////////////// // // DESIGNINFO diff --git a/src/mir_app/src/MDatabaseCommonCrypt.cpp b/src/mir_app/src/MDatabaseCommonCrypt.cpp index 6418f46c24..9f98445219 100644 --- a/src/mir_app/src/MDatabaseCommonCrypt.cpp +++ b/src/mir_app/src/MDatabaseCommonCrypt.cpp @@ -259,12 +259,68 @@ static INT_PTR ChangePassword(void* obj, WPARAM, LPARAM) return 0; } +///////////////////////////////////////////////////////////////////////////////////////// +// Options + +class CDatabaseOptionsDialog : public CDlgBase +{ + CCtrlCheck m_chkStandart, m_chkTotal; + CCtrlButton m_btnChangePass; + MDatabaseCommon *m_db; + +public: + CDatabaseOptionsDialog(MDatabaseCommon *db) : + CDlgBase(g_plugin, IDD_OPT_DATABASE), + m_db(db), + m_chkTotal(this, IDC_TOTAL), + m_chkStandart(this, IDC_STANDARD), + m_btnChangePass(this, IDC_USERPASS1) + { + m_btnChangePass.OnClick = Callback(this, &CDatabaseOptionsDialog::onClick_ChangePass); + } + + bool OnInitDialog() override + { + m_chkStandart.SetState(!m_db->isEncrypted()); + m_chkTotal.SetState(m_db->isEncrypted()); + return true; + } + + bool OnApply() override + { + SetCursor(LoadCursor(nullptr, IDC_WAIT)); + m_db->EnableEncryption(m_chkTotal.GetState() != 0); + SetCursor(LoadCursor(nullptr, IDC_ARROW)); + m_chkStandart.SetState(!m_db->isEncrypted()); + m_chkTotal.SetState(m_db->isEncrypted()); + return true; + } + + void onClick_ChangePass(CCtrlButton *) + { + ChangePassword(m_db, 0, 0); + } +}; + +static int OnOptionsInit(PVOID obj, WPARAM wParam, LPARAM) +{ + OPTIONSDIALOGPAGE odp = { sizeof(odp) }; + odp.position = -790000000; + odp.flags = ODPF_BOLDGROUPS; + odp.szTitle.a = LPGEN("Database"); + odp.pDialog = new CDatabaseOptionsDialog((MDatabaseCommon*)obj); + g_plugin.addOptions(wParam, &odp); + return 0; +} + ///////////////////////////////////////////////////////////////////////////////////////// static int OnModulesLoaded(PVOID obj, WPARAM, LPARAM) { MDatabaseCommon *db = (MDatabaseCommon *)obj; + HookEventObj(ME_OPT_INITIALISE, OnOptionsInit, obj); + // main menu item CMenuItem mi(&g_plugin); mi.root = g_plugin.addRootMenu(MO_MAIN, LPGENW("Database"), 500000000, g_plugin.getIconHandle(IDI_DATABASE)); diff --git a/src/mir_app/src/MDatabaseReadonly.cpp b/src/mir_app/src/MDatabaseReadonly.cpp index a1fef48769..e19c09e4aa 100644 --- a/src/mir_app/src/MDatabaseReadonly.cpp +++ b/src/mir_app/src/MDatabaseReadonly.cpp @@ -64,6 +64,11 @@ STDMETHODIMP_(BOOL) MDatabaseReadonly::StoreProvider(CRYPTO_PROVIDER *) return FALSE; } +STDMETHODIMP_(BOOL) MDatabaseReadonly::EnableEncryption(BOOL) +{ + return FALSE; +} + STDMETHODIMP_(BOOL) MDatabaseReadonly::ReadEncryption() { return FALSE; diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index 7d9719b261..25c60a0135 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -768,3 +768,4 @@ _Netlib_GetTlsUnique@8 @831 NONAME ?StoreCryptoKey@MDatabaseReadonly@@UAGHXZ @856 NONAME ?usesPassword@MDatabaseCommon@@QBE_NXZ @857 NONAME ?SetPassword@MDatabaseCommon@@QAEXPB_W@Z @858 NONAME +?EnableEncryption@MDatabaseReadonly@@UAGHH@Z @859 NONAME diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index 3d5b36d584..f347c13879 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -768,3 +768,4 @@ Netlib_GetTlsUnique @831 NONAME ?StoreCryptoKey@MDatabaseReadonly@@UEAAHXZ @856 NONAME ?usesPassword@MDatabaseCommon@@QEBA_NXZ @857 NONAME ?SetPassword@MDatabaseCommon@@QEAAXPEB_W@Z @858 NONAME +?EnableEncryption@MDatabaseReadonly@@UEAAHH@Z @859 NONAME diff --git a/src/mir_app/src/resource.h b/src/mir_app/src/resource.h index ec6bc9f321..196878cf94 100644 --- a/src/mir_app/src/resource.h +++ b/src/mir_app/src/resource.h @@ -32,6 +32,7 @@ #define IDD_LOGIN 123 #define IDI_DATABASE 124 #define IDD_DETAILS 125 +#define IDD_OPT_DATABASE 126 #define IDD_HISTORY 127 #define IDI_AWAY 128 #define IDI_FREE4CHAT 129 @@ -529,6 +530,8 @@ #define IDC_PLUGINURL 1682 #define IDC_PLUGINPID 1683 #define IDC_IDLESPIN 1687 +#define IDC_STANDARD 1688 +#define IDC_TOTAL 1689 #define IDC_NODBDRIVERS 1690 #define IDC_IDLESTATUSLOCK 1691 #define IDC_RESTART 1692 -- cgit v1.2.3