From 7748903e5c28d9e30a3970dfaaf464f163da2a1d Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 8 Jan 2021 20:13:39 +0300 Subject: Password change dialog also became common --- include/m_db_int.h | 30 +++--- libs/win32/mir_app.lib | Bin 217150 -> 217476 bytes libs/win64/mir_app.lib | Bin 212944 -> 213280 bytes plugins/Db3x_mmap/res/db3x_mmap.rc | 50 --------- plugins/Db3x_mmap/res/logo.ico | Bin 5430 -> 0 bytes plugins/Db3x_mmap/src/dbcrypt.cpp | 21 +--- plugins/Db3x_mmap/src/dbintf.h | 4 - plugins/Db3x_mmap/src/resource.h | 9 -- plugins/Db3x_mmap/src/ui.cpp | 174 +----------------------------- plugins/Dbx_mdbx/res/dbx_mdbx.rc | 65 ------------ plugins/Dbx_mdbx/res/logo.ico | Bin 5430 -> 0 bytes plugins/Dbx_mdbx/res/pass.ico | Bin 1150 -> 0 bytes plugins/Dbx_mdbx/src/dbcrypt.cpp | 15 --- plugins/Dbx_mdbx/src/dbintf.h | 6 +- plugins/Dbx_mdbx/src/resource.h | 8 -- plugins/Dbx_mdbx/src/ui.cpp | 170 ++--------------------------- plugins/Dbx_mdbx/src/ui.h | 1 - plugins/Dbx_sqlite/res/dbx_sqlite.rc | 60 ----------- plugins/Dbx_sqlite/src/resource.h | 13 --- src/mir_app/res/resource.rc | 35 ++++++ src/mir_app/src/MDatabaseCommonCrypt.cpp | 176 +++++++++++++++++++++++++++++++ src/mir_app/src/mir_app.def | 5 +- src/mir_app/src/mir_app64.def | 5 +- src/mir_app/src/resource.h | 6 ++ 24 files changed, 253 insertions(+), 600 deletions(-) delete mode 100644 plugins/Db3x_mmap/res/logo.ico delete mode 100644 plugins/Dbx_mdbx/res/logo.ico delete mode 100644 plugins/Dbx_mdbx/res/pass.ico diff --git a/include/m_db_int.h b/include/m_db_int.h index b4fef07719..0293111bb1 100644 --- a/include/m_db_int.h +++ b/include/m_db_int.h @@ -189,20 +189,6 @@ protected: bool LockName(const wchar_t *pwszProfileName); void UnlockName(); - //////////////////////////////////////////////////////////////////////////////////////// - // encryption support - - int InitCrypt(); - - CRYPTO_PROVIDER* SelectProvider(); - STDMETHOD_(CRYPTO_PROVIDER*, ReadProvider)() PURE; - STDMETHOD_(BOOL, StoreProvider)(CRYPTO_PROVIDER*) PURE; - - STDMETHOD_(BOOL, ReadCryptoKey)(MBinBuffer&) PURE; - STDMETHOD_(BOOL, StoreCryptoKey)() PURE; - - STDMETHOD_(BOOL, ReadEncryption)() PURE; - STDMETHOD_(BOOL, GetContactSettingWorker)(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv, int isStatic); STDMETHOD_(BOOL, WriteContactSettingWorker)(MCONTACT contactID, DBCONTACTWRITESETTING &dbcws) PURE; @@ -215,6 +201,8 @@ public: __forceinline MIDatabaseCache* getCache() const { return m_cache; } __forceinline bool usesPassword() const { return m_bUsesPassword; } + void SetPassword(const wchar_t *ptszPassword); + STDMETHODIMP_(BOOL) DeleteModule(MCONTACT contactID, LPCSTR szModule) override; STDMETHODIMP_(MCONTACT) FindFirstContact(const char *szProto = nullptr) override; @@ -241,6 +229,20 @@ public: STDMETHODIMP_(DB::EventCursor*) EventCursor(MCONTACT hContact, MEVENT hDbEvent) override; STDMETHODIMP_(DB::EventCursor*) EventCursorRev(MCONTACT hContact, MEVENT hDbEvent) override; + + //////////////////////////////////////////////////////////////////////////////////////// + // encryption support + + int InitCrypt(); + + CRYPTO_PROVIDER* SelectProvider(); + STDMETHOD_(CRYPTO_PROVIDER*, ReadProvider)() PURE; + STDMETHOD_(BOOL, StoreProvider)(CRYPTO_PROVIDER*) PURE; + + STDMETHOD_(BOOL, ReadCryptoKey)(MBinBuffer&) PURE; + STDMETHOD_(BOOL, StoreCryptoKey)() PURE; + + STDMETHOD_(BOOL, ReadEncryption)() PURE; }; #pragma warning(pop) diff --git a/libs/win32/mir_app.lib b/libs/win32/mir_app.lib index 1cc19b3133..2a9a63849e 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 58bc02d3d9..1f502bfd0e 100644 Binary files a/libs/win64/mir_app.lib and b/libs/win64/mir_app.lib differ diff --git a/plugins/Db3x_mmap/res/db3x_mmap.rc b/plugins/Db3x_mmap/res/db3x_mmap.rc index 464f7aa8fb..2f9a539203 100644 --- a/plugins/Db3x_mmap/res/db3x_mmap.rc +++ b/plugins/Db3x_mmap/res/db3x_mmap.rc @@ -23,41 +23,6 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US // Dialog // -IDD_NEWPASS DIALOGEX 0, 0, 190, 102 -STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU -EXSTYLE WS_EX_TOPMOST | WS_EX_TOOLWINDOW -CAPTION "New password" -FONT 8, "MS Shell Dlg", 400, 0, 0x1 -BEGIN - CONTROL "Please enter your new password",IDC_HEADERBAR, - "MHeaderbarCtrl",0x0,0,0,190,26 - CTEXT "",IDC_LANG,158,34,13,13,SS_CENTERIMAGE | NOT WS_GROUP - EDITTEXT IDC_USERPASS1,21,34,128,14,ES_PASSWORD | ES_AUTOHSCROLL - EDITTEXT IDC_USERPASS2,21,54,128,14,ES_PASSWORD | ES_AUTOHSCROLL - DEFPUSHBUTTON "OK",IDOK,36,84,50,14 - PUSHBUTTON "Cancel",IDCANCEL,100,84,50,14 - CONTROL "",IDC_STATIC,"Static",SS_ETCHEDFRAME,0,77,190,1 -END - -IDD_CHANGEPASS DIALOGEX 0, 0, 190, 148 -STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU -EXSTYLE WS_EX_TOOLWINDOW -CAPTION "Enter password" -FONT 8, "MS Shell Dlg", 400, 0, 0x1 -BEGIN - CONTROL "Change password",IDC_HEADERBAR,"MHeaderbarCtrl",0x0,0,0,190,26 - CTEXT "",IDC_LANG,158,42,13,13,SS_CENTERIMAGE | NOT WS_GROUP - EDITTEXT IDC_OLDPASS,21,42,128,14,ES_PASSWORD | ES_AUTOHSCROLL - EDITTEXT IDC_USERPASS1,21,77,128,14,ES_PASSWORD | ES_AUTOHSCROLL - EDITTEXT IDC_USERPASS2,21,98,128,14,ES_PASSWORD | ES_AUTOHSCROLL - DEFPUSHBUTTON "Change",IDOK,11,127,50,14 - PUSHBUTTON "Remove",IDREMOVE,69,127,50,14 - PUSHBUTTON "Cancel",IDCANCEL,126,127,50,14 - LTEXT "New password",IDC_STATIC,11,66,163,10,0,WS_EX_TRANSPARENT - CONTROL "",IDC_STATIC,"Static",SS_ETCHEDFRAME,0,119,190,1 - LTEXT "Old password",IDC_STATIC,11,31,140,10,0,WS_EX_TRANSPARENT -END - IDD_OPTIONS DIALOGEX 0, 0, 318, 176 STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD EXSTYLE WS_EX_CONTROLPARENT @@ -68,7 +33,6 @@ BEGIN 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_USERPASS,200,153,111,17 END @@ -80,26 +44,12 @@ END #ifdef APSTUDIO_INVOKED GUIDELINES DESIGNINFO BEGIN - IDD_CHANGEPASS, DIALOG - BEGIN - END - IDD_OPTIONS, DIALOG BEGIN END END #endif // APSTUDIO_INVOKED - -///////////////////////////////////////////////////////////////////////////// -// -// Icon -// - -// Icon with lowest ID value placed first to ensure application icon -// remains consistent on all systems. -IDI_LOGO ICON "logo.ico" - #ifdef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // diff --git a/plugins/Db3x_mmap/res/logo.ico b/plugins/Db3x_mmap/res/logo.ico deleted file mode 100644 index f49bbe83d6..0000000000 Binary files a/plugins/Db3x_mmap/res/logo.ico and /dev/null differ diff --git a/plugins/Db3x_mmap/src/dbcrypt.cpp b/plugins/Db3x_mmap/src/dbcrypt.cpp index 42a0cc57db..2cb8fd7c9d 100644 --- a/plugins/Db3x_mmap/src/dbcrypt.cpp +++ b/plugins/Db3x_mmap/src/dbcrypt.cpp @@ -125,27 +125,14 @@ STDMETHODIMP_(BOOL) CDb3Mmap::StoreProvider(CRYPTO_PROVIDER *pProvider) return TRUE; } -void CDb3Mmap::SetPassword(const wchar_t *ptszPassword) -{ - if (ptszPassword == nullptr || *ptszPassword == 0) { - m_bUsesPassword = false; - m_crypto->setPassword(nullptr); - } - else { - m_bUsesPassword = true; - m_crypto->setPassword(T2Utf(ptszPassword)); - } - UpdateMenuItem(); -} - ///////////////////////////////////////////////////////////////////////////////////////// void CDb3Mmap::ToggleEncryption() { - HANDLE hSave1 = g_hevSettingChanged; g_hevSettingChanged = nullptr; - HANDLE hSave2 = g_hevEventAdded; g_hevEventAdded = nullptr; - HANDLE hSave3 = g_hevEventDeleted; g_hevEventDeleted = nullptr; - HANDLE hSave4 = g_hevEventFiltered; g_hevEventFiltered = nullptr; + HANDLE hSave1 = g_hevSettingChanged; g_hevSettingChanged = nullptr; + HANDLE hSave2 = g_hevEventAdded; g_hevEventAdded = nullptr; + HANDLE hSave3 = g_hevEventDeleted; g_hevEventDeleted = nullptr; + HANDLE hSave4 = g_hevEventFiltered; g_hevEventFiltered = nullptr; mir_cslock lck(m_csDbAccess); ToggleSettingsEncryption(0); diff --git a/plugins/Db3x_mmap/src/dbintf.h b/plugins/Db3x_mmap/src/dbintf.h index 81aca25423..d1206c9483 100644 --- a/plugins/Db3x_mmap/src/dbintf.h +++ b/plugins/Db3x_mmap/src/dbintf.h @@ -193,10 +193,6 @@ struct CDb3Mmap : public MDatabaseCommon, public MZeroedObject int CheckDbHeaders(bool bInteractive); void ToggleEncryption(void); - void SetPassword(const wchar_t *ptszPassword); - void UpdateMenuItem(void); - - __forceinline LPTSTR GetMenuTitle() const { return m_bUsesPassword ? LPGENW("Change/remove password") : LPGENW("Set password"); } void DatabaseCorruption(wchar_t *text); void WriteSignature(DBSignature&); diff --git a/plugins/Db3x_mmap/src/resource.h b/plugins/Db3x_mmap/src/resource.h index 0f3113cc29..e9f022d2f3 100644 --- a/plugins/Db3x_mmap/src/resource.h +++ b/plugins/Db3x_mmap/src/resource.h @@ -4,20 +4,11 @@ // #define IDREMOVE 3 #define IDI_LOGO 101 -#define IDD_NEWPASS 103 -#define IDD_CHANGEPASS 104 #define IDD_OPTIONS 105 #define IDD_SELECT_CRYPTOPROVIDER 106 #define IDC_HEADERBAR 1001 -#define IDC_LANG 1002 -#define IDC_USERPASS 1003 -#define IDC_USERPASS1 1004 -#define IDC_USERPASS2 1005 -#define IDC_OLDPASS 1006 #define IDC_STANDARD 1007 #define IDC_TOTAL 1008 -#define IDC_SELECTCRYPT_COMBO 1010 -#define IDC_CRYPTOPROVIDER_DESCR 1011 // Next default values for new objects // diff --git a/plugins/Db3x_mmap/src/ui.cpp b/plugins/Db3x_mmap/src/ui.cpp index 10c428b9fd..ced14b5168 100644 --- a/plugins/Db3x_mmap/src/ui.cpp +++ b/plugins/Db3x_mmap/src/ui.cpp @@ -23,143 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" -#define MS_DB_CHANGEPASSWORD "DB/UI/ChangePassword" - -static IconItem iconList[] = -{ - { LPGEN("Logo"), "logo", IDI_LOGO } -}; - -static HGENMENU hSetPwdMenu; - -static ULONG_PTR oldLangID; -void LanguageChanged(HWND hwndDlg) -{ - ULONG_PTR LangID = (ULONG_PTR)GetKeyboardLayout(0); - char Lang[3] = { 0 }; - if (LangID != oldLangID) { - oldLangID = LangID; - GetLocaleInfoA(MAKELCID((LangID & 0xffffffff), SORT_DEFAULT), LOCALE_SABBREVLANGNAME, Lang, 2); - Lang[0] = toupper(Lang[0]); - Lang[1] = tolower(Lang[1]); - SetDlgItemTextA(hwndDlg, IDC_LANG, Lang); - } -} - -///////////////////////////////////////////////////////////////////////////////////////// - -static bool CheckOldPassword(HWND hwndDlg, CDb3Mmap *db) -{ - if (db->usesPassword()) { - wchar_t buf[100]; - GetDlgItemText(hwndDlg, IDC_OLDPASS, buf, _countof(buf)); - if (!db->getCrypt()->checkPassword(T2Utf(buf))) { - SetDlgItemText(hwndDlg, IDC_HEADERBAR, TranslateT("Wrong old password entered!")); - return false; - } - } - return true; -} - -struct DlgChangePassParam -{ - CDb3Mmap *db; - wchar_t newPass[100]; - int wrongPass; -}; - -static INT_PTR CALLBACK sttChangePassword(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - DlgChangePassParam *param = (DlgChangePassParam*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - wchar_t buf[100]; - - switch (uMsg) { - case WM_INITDIALOG: - TranslateDialogDefault(hwndDlg); - SendDlgItemMessage(hwndDlg, IDC_HEADERBAR, WM_SETICON, ICON_SMALL, (LPARAM)IcoLib_GetIconByHandle(iconList[0].hIcolib, true)); - - param = (DlgChangePassParam*)lParam; - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); - - oldLangID = 0; - SetTimer(hwndDlg, 1, 200, nullptr); - LanguageChanged(hwndDlg); - return TRUE; - - case WM_CTLCOLORSTATIC: - if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_LANG)) { - SetTextColor((HDC)wParam, GetSysColor(COLOR_HIGHLIGHTTEXT)); - SetBkMode((HDC)wParam, TRANSPARENT); - return (INT_PTR)GetSysColorBrush(COLOR_HIGHLIGHT); - } - return FALSE; - - case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDCANCEL: - EndDialog(hwndDlg, IDCANCEL); - break; - - case IDREMOVE: - if (!CheckOldPassword(hwndDlg, param->db)) { - LBL_Error: - SendDlgItemMessage(hwndDlg, IDC_HEADERBAR, WM_NCPAINT, 0, 0); - SetDlgItemTextA(hwndDlg, IDC_USERPASS1, ""); - SetDlgItemTextA(hwndDlg, IDC_USERPASS2, ""); - } - else { - param->db->WriteSignature(dbSignatureU); - param->db->SetPassword(nullptr); - param->db->StoreCryptoKey(); - EndDialog(hwndDlg, IDREMOVE); - } - break; - - case IDOK: - wchar_t buf2[100]; - GetDlgItemText(hwndDlg, IDC_USERPASS1, buf2, _countof(buf2)); - if (mir_wstrlen(buf2) < 3) { - SetDlgItemText(hwndDlg, IDC_HEADERBAR, TranslateT("Password is too short!")); - goto LBL_Error; - } - - GetDlgItemText(hwndDlg, IDC_USERPASS2, buf, _countof(buf)); - if (mir_wstrcmp(buf2, buf)) { - SetDlgItemText(hwndDlg, IDC_HEADERBAR, TranslateT("Passwords do not match!")); - goto LBL_Error; - } - - if (!CheckOldPassword(hwndDlg, param->db)) - goto LBL_Error; - - param->db->WriteSignature(dbSignatureE); - param->db->SetPassword(buf2); - param->db->StoreCryptoKey(); - SecureZeroMemory(buf2, sizeof(buf2)); - EndDialog(hwndDlg, IDOK); - } - break; - - case WM_TIMER: - LanguageChanged(hwndDlg); - return FALSE; - - case WM_DESTROY: - KillTimer(hwndDlg, 1); - Window_FreeIcon_IcoLib(hwndDlg); - } - - return FALSE; -} - -static INT_PTR ChangePassword(void* obj, WPARAM, LPARAM) -{ - CDb3Mmap *db = (CDb3Mmap*)obj; - DlgChangePassParam param = { db }; - DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(db->usesPassword() ? IDD_CHANGEPASS : IDD_NEWPASS), nullptr, sttChangePassword, (LPARAM)¶m); - return 0; -} - ///////////////////////////////////////////////////////////////////////////////////////// INT_PTR CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) @@ -176,12 +39,8 @@ INT_PTR CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP return TRUE; case WM_COMMAND: - if (HIWORD(wParam) == BN_CLICKED && (HWND)lParam == GetFocus()) { - if (LOWORD(wParam) == IDC_USERPASS) - CallService(MS_DB_CHANGEPASSWORD, 0, 0); - else - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - } + if (HIWORD(wParam) == BN_CLICKED && (HWND)lParam == GetFocus()) + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; case WM_NOTIFY: @@ -211,40 +70,13 @@ static int OnOptionsInit(PVOID obj, WPARAM wParam, LPARAM) return 0; } -///////////////////////////////////////////////////////////////////////////////////////// - -void CDb3Mmap::UpdateMenuItem() -{ - Menu_ModifyItem(hSetPwdMenu, GetMenuTitle(), Skin_GetIconHandle(SKINICON_OTHER_KEYS)); -} - static int OnModulesLoaded(PVOID obj, WPARAM, LPARAM) { - CDb3Mmap *db = (CDb3Mmap*)obj; - - g_plugin.registerIcon(LPGEN("Database"), iconList, "mmap"); - - HookEventObj(ME_OPT_INITIALISE, OnOptionsInit, db); - - CMenuItem mi(&g_plugin); - - // main menu item - mi.root = g_plugin.addRootMenu(MO_MAIN, LPGENW("Database"), 500000000, iconList[0].hIcolib); - Menu_ConfigureItem(mi.root, MCI_OPT_UID, "F7C5567C-D1EE-484B-B4F6-24677A5AAAEF"); - - SET_UID(mi, 0x50321866, 0xba1, 0x46dd, 0xb3, 0xa6, 0xc3, 0xcc, 0x55, 0xf2, 0x42, 0x9e); - mi.flags = CMIF_UNICODE; - mi.hIcolibItem = iconList[0].hIcolib; - mi.name.w = db->GetMenuTitle(); - mi.pszService = MS_DB_CHANGEPASSWORD; - hSetPwdMenu = Menu_AddMainMenuItem(&mi); + HookEventObj(ME_OPT_INITIALISE, OnOptionsInit, obj); return 0; } -///////////////////////////////////////////////////////////////////////////////////////// - void CDb3Mmap::InitDialogs() { - hService = CreateServiceFunctionObj(MS_DB_CHANGEPASSWORD, ChangePassword, this); 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 83b1661322..d727349410 100644 --- a/plugins/Dbx_mdbx/res/dbx_mdbx.rc +++ b/plugins/Dbx_mdbx/res/dbx_mdbx.rc @@ -23,41 +23,6 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US // Dialog // -IDD_NEWPASS DIALOGEX 0, 0, 190, 102 -STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU -EXSTYLE WS_EX_TOPMOST | WS_EX_TOOLWINDOW -CAPTION "New password" -FONT 8, "MS Shell Dlg", 400, 0, 0x1 -BEGIN - CONTROL "Please enter your new password",IDC_HEADERBAR, - "MHeaderbarCtrl",0x0,0,0,190,26 - CTEXT "",IDC_LANG,158,34,13,13,SS_CENTERIMAGE | NOT WS_GROUP - EDITTEXT IDC_USERPASS1,21,34,128,14,ES_PASSWORD | ES_AUTOHSCROLL - EDITTEXT IDC_USERPASS2,21,54,128,14,ES_PASSWORD | ES_AUTOHSCROLL - DEFPUSHBUTTON "OK",IDOK,36,84,50,14 - PUSHBUTTON "Cancel",IDCANCEL,100,84,50,14 - CONTROL "",IDC_STATIC,"Static",SS_ETCHEDFRAME,0,77,190,1 -END - -IDD_CHANGEPASS DIALOGEX 0, 0, 190, 148 -STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU -EXSTYLE WS_EX_TOOLWINDOW -CAPTION "Enter password" -FONT 8, "MS Shell Dlg", 400, 0, 0x1 -BEGIN - CONTROL "Change password",IDC_HEADERBAR,"MHeaderbarCtrl",0x0,0,0,190,26 - CTEXT "",IDC_LANG,158,42,13,13,SS_CENTERIMAGE | NOT WS_GROUP - EDITTEXT IDC_OLDPASS,21,42,128,14,ES_PASSWORD | ES_AUTOHSCROLL - EDITTEXT IDC_USERPASS1,21,77,128,14,ES_PASSWORD | ES_AUTOHSCROLL - EDITTEXT IDC_USERPASS2,21,98,128,14,ES_PASSWORD | ES_AUTOHSCROLL - DEFPUSHBUTTON "Change",IDOK,11,127,50,14 - PUSHBUTTON "Remove",IDREMOVE,69,127,50,14 - PUSHBUTTON "Cancel",IDCANCEL,126,127,50,14 - LTEXT "New password",IDC_STATIC,11,66,163,10,0,WS_EX_TRANSPARENT - CONTROL "",IDC_STATIC,"Static",SS_ETCHEDFRAME,0,119,190,1 - LTEXT "Old password",IDC_STATIC,11,31,140,10,0,WS_EX_TRANSPARENT -END - IDD_OPTIONS DIALOGEX 0, 0, 318, 176 STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD EXSTYLE WS_EX_CONTROLPARENT @@ -68,10 +33,8 @@ BEGIN 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_USERPASS,200,153,111,17 END - ///////////////////////////////////////////////////////////////////////////// // // Icon @@ -79,36 +42,8 @@ END // Icon with lowest ID value placed first to ensure application icon // remains consistent on all systems. -IDI_LOGO ICON "logo.ico" IDI_COMPACT ICON "compact.ico" -///////////////////////////////////////////////////////////////////////////// -// -// DESIGNINFO -// - -#ifdef APSTUDIO_INVOKED -GUIDELINES DESIGNINFO -BEGIN - IDD_SELECT_CRYPTOPROVIDER, DIALOG - BEGIN - END - - IDD_LOGIN, DIALOG - BEGIN - END - - IDD_CHANGEPASS, DIALOG - BEGIN - END - - IDD_OPTIONS, DIALOG - BEGIN - END -END -#endif // APSTUDIO_INVOKED - - #ifdef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // diff --git a/plugins/Dbx_mdbx/res/logo.ico b/plugins/Dbx_mdbx/res/logo.ico deleted file mode 100644 index f49bbe83d6..0000000000 Binary files a/plugins/Dbx_mdbx/res/logo.ico and /dev/null differ diff --git a/plugins/Dbx_mdbx/res/pass.ico b/plugins/Dbx_mdbx/res/pass.ico deleted file mode 100644 index dc47a6ed4f..0000000000 Binary files a/plugins/Dbx_mdbx/res/pass.ico and /dev/null differ diff --git a/plugins/Dbx_mdbx/src/dbcrypt.cpp b/plugins/Dbx_mdbx/src/dbcrypt.cpp index 3ee4ce9fc6..9f41b534e5 100644 --- a/plugins/Dbx_mdbx/src/dbcrypt.cpp +++ b/plugins/Dbx_mdbx/src/dbcrypt.cpp @@ -94,21 +94,6 @@ STDMETHODIMP_(BOOL) CDbxMDBX::StoreProvider(CRYPTO_PROVIDER *pProv) ///////////////////////////////////////////////////////////////////////////////////////// -void CDbxMDBX::SetPassword(const wchar_t *ptszPassword) -{ - if (ptszPassword == nullptr || *ptszPassword == 0) { - m_bUsesPassword = false; - m_crypto->setPassword(nullptr); - } - else { - m_bUsesPassword = true; - m_crypto->setPassword(pass_ptrA(mir_utf8encodeW(ptszPassword))); - } - UpdateMenuItem(); -} - -///////////////////////////////////////////////////////////////////////////////////////// - int CDbxMDBX::EnableEncryption(bool bEncrypted) { if (m_bEncrypted == bEncrypted) diff --git a/plugins/Dbx_mdbx/src/dbintf.h b/plugins/Dbx_mdbx/src/dbintf.h index e4d542ae07..502b126ff4 100644 --- a/plugins/Dbx_mdbx/src/dbintf.h +++ b/plugins/Dbx_mdbx/src/dbintf.h @@ -165,7 +165,6 @@ class CDbxMDBX : public MDatabaseCommon, public MIDatabaseChecker, public MZeroe bool EditEvent(MCONTACT contactID, MEVENT hDbEvent, const DBEVENTINFO *dbe, bool bNew); int PrepareCheck(void); void TouchFile(void); - void UpdateMenuItem(void); //////////////////////////////////////////////////////////////////////////// // database stuff @@ -186,7 +185,7 @@ class CDbxMDBX : public MDatabaseCommon, public MIDatabaseChecker, public MZeroe // settings MDBX_dbi m_dbSettings; - HANDLE hService[2], hHook; + HANDLE hService[1], hHook; void FillSettings(void); @@ -235,14 +234,11 @@ public: int EnableEncryption(bool bEnable); int Load(); int Map(); - void SetPassword(const wchar_t *ptszPassword); int CheckEvents1(void); int CheckEvents2(void); int CheckEvents3(void); - __forceinline LPSTR GetMenuTitle() const { return m_bUsesPassword ? (char*)LPGEN("Change/remove password") : (char*)LPGEN("Set password"); } - public: STDMETHODIMP_(BOOL) IsRelational(void) override { return TRUE; } STDMETHODIMP_(void) SetCacheSafetyMode(BOOL) override; diff --git a/plugins/Dbx_mdbx/src/resource.h b/plugins/Dbx_mdbx/src/resource.h index c705e3ad15..035c210f70 100644 --- a/plugins/Dbx_mdbx/src/resource.h +++ b/plugins/Dbx_mdbx/src/resource.h @@ -3,17 +3,9 @@ // Используется d:\Others\SVN\MirandaNG\trunk\plugins\Dbx_mdb\res\dbx_mdbx.rc // #define IDREMOVE 3 -#define IDI_LOGO 101 -#define IDD_NEWPASS 103 -#define IDD_CHANGEPASS 104 #define IDD_OPTIONS 105 #define IDI_COMPACT 107 #define IDC_HEADERBAR 1001 -#define IDC_LANG 1002 -#define IDC_USERPASS 1003 -#define IDC_USERPASS1 1004 -#define IDC_USERPASS2 1005 -#define IDC_OLDPASS 1006 #define IDC_STANDARD 1007 #define IDC_TOTAL 1008 diff --git a/plugins/Dbx_mdbx/src/ui.cpp b/plugins/Dbx_mdbx/src/ui.cpp index f538d99c51..e32df8d296 100644 --- a/plugins/Dbx_mdbx/src/ui.cpp +++ b/plugins/Dbx_mdbx/src/ui.cpp @@ -23,137 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" -static HGENMENU hSetPwdMenu; - -static UINT oldLangID; -void LanguageChanged(HWND hwndDlg) -{ - UINT_PTR LangID = (UINT_PTR)GetKeyboardLayout(0); - char Lang[3] = { 0 }; - if (LangID != oldLangID) { - oldLangID = LangID; - GetLocaleInfoA(MAKELCID((LangID & 0xffffffff), SORT_DEFAULT), LOCALE_SABBREVLANGNAME, Lang, 2); - Lang[0] = toupper(Lang[0]); - Lang[1] = tolower(Lang[1]); - SetDlgItemTextA(hwndDlg, IDC_LANG, Lang); - } -} - -///////////////////////////////////////////////////////////////////////////////////////// - -static bool CheckOldPassword(HWND hwndDlg, CDbxMDBX *db) -{ - if (db->usesPassword()) { - wchar_t buf[100]; - GetDlgItemText(hwndDlg, IDC_OLDPASS, buf, _countof(buf)); - pass_ptrA oldPass(mir_utf8encodeW(buf)); - if (!db->getCrypt()->checkPassword(oldPass)) { - SetDlgItemText(hwndDlg, IDC_HEADERBAR, TranslateT("Wrong old password entered!")); - return false; - } - } - return true; -} - -struct DlgChangePassParam -{ - CDbxMDBX *db; - wchar_t newPass[100]; - unsigned short wrongPass; -}; - -static INT_PTR CALLBACK sttChangePassword(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - DlgChangePassParam *param = (DlgChangePassParam*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - wchar_t buf[100]; - - switch (uMsg) { - case WM_INITDIALOG: - TranslateDialogDefault(hwndDlg); - SendDlgItemMessage(hwndDlg, IDC_HEADERBAR, WM_SETICON, ICON_SMALL, (LPARAM)g_plugin.getIcon(IDI_LOGO, true)); - - param = (DlgChangePassParam*)lParam; - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); - - oldLangID = 0; - SetTimer(hwndDlg, 1, 200, nullptr); - LanguageChanged(hwndDlg); - return TRUE; - - case WM_CTLCOLORSTATIC: - if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_LANG)) { - SetTextColor((HDC)wParam, GetSysColor(COLOR_HIGHLIGHTTEXT)); - SetBkMode((HDC)wParam, TRANSPARENT); - return (INT_PTR)GetSysColorBrush(COLOR_HIGHLIGHT); - } - return FALSE; - - case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDCANCEL: - EndDialog(hwndDlg, IDCANCEL); - break; - - case IDREMOVE: - if (!CheckOldPassword(hwndDlg, param->db)) { - LBL_Error: - SendDlgItemMessage(hwndDlg, IDC_HEADERBAR, WM_NCPAINT, 0, 0); - SetDlgItemTextA(hwndDlg, IDC_USERPASS1, ""); - SetDlgItemTextA(hwndDlg, IDC_USERPASS2, ""); - } - else { - // param->db->WriteSignature(dbSignatureU); - param->db->SetPassword(nullptr); - param->db->StoreCryptoKey(); - EndDialog(hwndDlg, IDREMOVE); - } - break; - - case IDOK: - wchar_t buf2[100]; - GetDlgItemText(hwndDlg, IDC_USERPASS1, buf2, _countof(buf2)); - if (wcslen(buf2) < 3) { - SetDlgItemText(hwndDlg, IDC_HEADERBAR, TranslateT("Password is too short!")); - goto LBL_Error; - } - - GetDlgItemText(hwndDlg, IDC_USERPASS2, buf, _countof(buf)); - if (wcscmp(buf2, buf)) { - SetDlgItemText(hwndDlg, IDC_HEADERBAR, TranslateT("Passwords do not match!")); - goto LBL_Error; - } - - if (!CheckOldPassword(hwndDlg, param->db)) - goto LBL_Error; - - // param->db->WriteSignature(dbSignatureE); - param->db->SetPassword(buf2); - param->db->StoreCryptoKey(); - SecureZeroMemory(buf2, sizeof(buf2)); - EndDialog(hwndDlg, IDOK); - } - break; - - case WM_TIMER: - LanguageChanged(hwndDlg); - return FALSE; - - case WM_DESTROY: - KillTimer(hwndDlg, 1); - Window_FreeIcon_IcoLib(GetDlgItem(hwndDlg, IDC_HEADERBAR)); - } - - return FALSE; -} - -static INT_PTR ChangePassword(void* obj, WPARAM, LPARAM) -{ - CDbxMDBX *db = (CDbxMDBX*)obj; - DlgChangePassParam param = { db }; - DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(db->usesPassword() ? IDD_CHANGEPASS : IDD_NEWPASS), nullptr, sttChangePassword, (LPARAM)¶m); - return 0; -} - ///////////////////////////////////////////////////////////////////////////////////////// static INT_PTR CompactMe(void* obj, WPARAM, LPARAM) @@ -172,14 +41,12 @@ class COptionsDialog : public CDlgBase { CCtrlCheck m_chkStandart; CCtrlCheck m_chkTotal; - CCtrlButton m_btnChangePass; CDbxMDBX *m_db; bool OnInitDialog() override { m_chkStandart.SetState(!m_db->isEncrypted()); m_chkTotal.SetState(m_db->isEncrypted()); - m_btnChangePass.SetTextA(Translate(m_db->GetMenuTitle())); return true; } @@ -193,20 +60,13 @@ class COptionsDialog : public CDlgBase return true; } - void ChangePass(CCtrlButton*) - { - CallService(MS_DB_CHANGEPASSWORD, 0, 0); - } - public: COptionsDialog(CDbxMDBX *db) : CDlgBase(g_plugin, IDD_OPTIONS), m_chkStandart(this, IDC_STANDARD), m_chkTotal(this, IDC_TOTAL), - m_btnChangePass(this, IDC_USERPASS), m_db(db) { - m_btnChangePass.OnClick = Callback(this, &COptionsDialog::ChangePass); } }; @@ -225,42 +85,25 @@ static int OnOptionsInit(PVOID obj, WPARAM wParam, LPARAM) static IconItem iconList[] = { - { LPGEN("Logo"), "logo", IDI_LOGO }, { LPGEN("Compact"), "compact", IDI_COMPACT } }; -void CDbxMDBX::UpdateMenuItem() -{ - Menu_ModifyItem(hSetPwdMenu, _A2T(GetMenuTitle()), Skin_GetIconHandle(SKINICON_OTHER_KEYS)); -} - static int OnModulesLoaded(PVOID obj, WPARAM, LPARAM) { - CDbxMDBX *db = (CDbxMDBX*)obj; - g_plugin.registerIcon(LPGEN("Database"), iconList, "mdbx"); - HookEventObj(ME_OPT_INITIALISE, OnOptionsInit, db); - - CMenuItem mi(&g_plugin); + HookEventObj(ME_OPT_INITIALISE, OnOptionsInit, obj); // main menu item - mi.root = g_plugin.addRootMenu(MO_MAIN, LPGENW("Database"), 500000000, iconList[0].hIcolib); - Menu_ConfigureItem(mi.root, MCI_OPT_UID, "F7C5567C-D1EE-484B-B4F6-24677A5AAAEF"); - - SET_UID(mi, 0x50321866, 0xba1, 0x46dd, 0xb3, 0xa6, 0xc3, 0xcc, 0x55, 0xf2, 0x42, 0x9e); - mi.position = 1000000001; - mi.hIcolibItem = Skin_GetIconHandle(SKINICON_OTHER_KEYS); - mi.name.a = db->GetMenuTitle(); - mi.pszService = MS_DB_CHANGEPASSWORD; - hSetPwdMenu = Menu_AddMainMenuItem(&mi); + CMenuItem mi(&g_plugin); + mi.root = g_plugin.addRootMenu(MO_MAIN, LPGENW("Database"), 500000000, 0); SET_UID(mi, 0x98c0caf3, 0xBfe5, 0x4e31, 0xac, 0xf0, 0xab, 0x95, 0xb2, 0x9b, 0x9f, 0x73); mi.position++; - mi.hIcolibItem = iconList[1].hIcolib; + mi.hIcolibItem = iconList[0].hIcolib; mi.name.a = LPGEN("Compact"); mi.pszService = MS_DB_COMPACT; - hSetPwdMenu = Menu_AddMainMenuItem(&mi); + Menu_AddMainMenuItem(&mi); return 0; } @@ -268,8 +111,7 @@ static int OnModulesLoaded(PVOID obj, WPARAM, LPARAM) void CDbxMDBX::InitDialogs() { - hService[0] = CreateServiceFunctionObj(MS_DB_CHANGEPASSWORD, ChangePassword, this); - hService[1] = CreateServiceFunctionObj(MS_DB_COMPACT, CompactMe, this); + hService[0] = CreateServiceFunctionObj(MS_DB_COMPACT, CompactMe, this); hHook = HookEventObj(ME_SYSTEM_MODULESLOADED, OnModulesLoaded, this); } diff --git a/plugins/Dbx_mdbx/src/ui.h b/plugins/Dbx_mdbx/src/ui.h index 832146ea33..e1c4fe5f4a 100644 --- a/plugins/Dbx_mdbx/src/ui.h +++ b/plugins/Dbx_mdbx/src/ui.h @@ -1,4 +1,3 @@ #pragma once -#define MS_DB_CHANGEPASSWORD "DB/UI/ChangePassword" #define MS_DB_COMPACT "DB/UI/Compact" diff --git a/plugins/Dbx_sqlite/res/dbx_sqlite.rc b/plugins/Dbx_sqlite/res/dbx_sqlite.rc index 7f2c2b022e..b9e3d9acf9 100644 --- a/plugins/Dbx_sqlite/res/dbx_sqlite.rc +++ b/plugins/Dbx_sqlite/res/dbx_sqlite.rc @@ -23,41 +23,6 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US // Dialog // -IDD_NEWPASS DIALOGEX 0, 0, 190, 102 -STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU -EXSTYLE WS_EX_TOPMOST | WS_EX_TOOLWINDOW -CAPTION "New password" -FONT 8, "MS Shell Dlg", 400, 0, 0x1 -BEGIN - CONTROL "Please enter your new password",IDC_HEADERBAR, - "MHeaderbarCtrl",0x0,0,0,190,26 - CTEXT "",IDC_LANG,158,34,13,13,SS_CENTERIMAGE | NOT WS_GROUP - EDITTEXT IDC_USERPASS1,21,34,128,14,ES_PASSWORD | ES_AUTOHSCROLL - EDITTEXT IDC_USERPASS2,21,54,128,14,ES_PASSWORD | ES_AUTOHSCROLL - DEFPUSHBUTTON "OK",IDOK,36,84,50,14 - PUSHBUTTON "Cancel",IDCANCEL,100,84,50,14 - CONTROL "",IDC_STATIC,"Static",SS_ETCHEDFRAME,0,77,190,1 -END - -IDD_CHANGEPASS DIALOGEX 0, 0, 190, 148 -STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU -EXSTYLE WS_EX_TOOLWINDOW -CAPTION "Enter password" -FONT 8, "MS Shell Dlg", 400, 0, 0x1 -BEGIN - CONTROL "Change password",IDC_HEADERBAR,"MHeaderbarCtrl",0x0,0,0,190,26 - CTEXT "",IDC_LANG,158,42,13,13,SS_CENTERIMAGE | NOT WS_GROUP - EDITTEXT IDC_OLDPASS,21,42,128,14,ES_PASSWORD | ES_AUTOHSCROLL - EDITTEXT IDC_USERPASS1,21,77,128,14,ES_PASSWORD | ES_AUTOHSCROLL - EDITTEXT IDC_USERPASS2,21,98,128,14,ES_PASSWORD | ES_AUTOHSCROLL - DEFPUSHBUTTON "Change",IDOK,11,127,50,14 - PUSHBUTTON "Remove",IDREMOVE,69,127,50,14 - PUSHBUTTON "Cancel",IDCANCEL,126,127,50,14 - LTEXT "New password",IDC_STATIC,11,66,163,10,0,WS_EX_TRANSPARENT - CONTROL "",IDC_STATIC,"Static",SS_ETCHEDFRAME,0,119,190,1 - LTEXT "Old password",IDC_STATIC,11,31,140,10,0,WS_EX_TRANSPARENT -END - IDD_OPTIONS DIALOGEX 0, 0, 318, 176 STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD EXSTYLE WS_EX_CONTROLPARENT @@ -68,33 +33,8 @@ BEGIN 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_USERPASS,200,153,111,17 END - -///////////////////////////////////////////////////////////////////////////// -// -// DESIGNINFO -// - -#ifdef APSTUDIO_INVOKED -GUIDELINES DESIGNINFO -BEGIN - IDD_LOGIN, DIALOG - BEGIN - END - - IDD_CHANGEPASS, DIALOG - BEGIN - END - - IDD_OPTIONS, DIALOG - BEGIN - END -END -#endif // APSTUDIO_INVOKED - - #ifdef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // diff --git a/plugins/Dbx_sqlite/src/resource.h b/plugins/Dbx_sqlite/src/resource.h index 9e2976c927..6f4c2838d5 100644 --- a/plugins/Dbx_sqlite/src/resource.h +++ b/plugins/Dbx_sqlite/src/resource.h @@ -3,22 +3,9 @@ // Используется D:\Others\SVN\MirandaNG\trunk\plugins\Db3x_mmap\res\db3x_mmap.rc // #define IDREMOVE 3 -#define IDI_ICONPASS 100 -#define IDI_LOGO 101 -#define IDD_NEWPASS 103 -#define IDD_CHANGEPASS 104 #define IDD_OPTIONS 105 -#define IDD_SELECT_CRYPTOPROVIDER 106 -#define IDC_HEADERBAR 1001 -#define IDC_LANG 1002 -#define IDC_USERPASS 1003 -#define IDC_USERPASS1 1004 -#define IDC_USERPASS2 1005 -#define IDC_OLDPASS 1006 #define IDC_STANDARD 1007 #define IDC_TOTAL 1008 -#define IDC_SELECTCRYPT_COMBO 1010 -#define IDC_CRYPTOPROVIDER_DESCR 1011 // Next default values for new objects // diff --git a/src/mir_app/res/resource.rc b/src/mir_app/res/resource.rc index 895593352c..bc6d0d9d75 100644 --- a/src/mir_app/res/resource.rc +++ b/src/mir_app/res/resource.rc @@ -904,6 +904,41 @@ BEGIN CONTROL "",IDC_STATIC,"Static",SS_ETCHEDFRAME,0,55,190,1 END +IDD_NEWPASS DIALOGEX 0, 0, 190, 102 +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU +EXSTYLE WS_EX_TOPMOST | WS_EX_TOOLWINDOW +CAPTION "New password" +FONT 8, "MS Shell Dlg", 400, 0, 0x1 +BEGIN + CONTROL "Please enter your new password",IDC_HEADERBAR, + "MHeaderbarCtrl",0x0,0,0,190,26 + CTEXT "",IDC_LANG,158,34,13,13,SS_CENTERIMAGE | NOT WS_GROUP + EDITTEXT IDC_USERPASS1,21,34,128,14,ES_PASSWORD | ES_AUTOHSCROLL + EDITTEXT IDC_USERPASS2,21,54,128,14,ES_PASSWORD | ES_AUTOHSCROLL + DEFPUSHBUTTON "OK",IDOK,36,84,50,14 + PUSHBUTTON "Cancel",IDCANCEL,100,84,50,14 + CONTROL "",IDC_STATIC,"Static",SS_ETCHEDFRAME,0,77,190,1 +END + +IDD_CHANGEPASS DIALOGEX 0, 0, 190, 148 +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU +EXSTYLE WS_EX_TOOLWINDOW +CAPTION "Enter password" +FONT 8, "MS Shell Dlg", 400, 0, 0x1 +BEGIN + CONTROL "Change password",IDC_HEADERBAR,"MHeaderbarCtrl",0x0,0,0,190,26 + CTEXT "",IDC_LANG,158,42,13,13,SS_CENTERIMAGE | NOT WS_GROUP + EDITTEXT IDC_OLDPASS,21,42,128,14,ES_PASSWORD | ES_AUTOHSCROLL + EDITTEXT IDC_USERPASS1,21,77,128,14,ES_PASSWORD | ES_AUTOHSCROLL + EDITTEXT IDC_USERPASS2,21,98,128,14,ES_PASSWORD | ES_AUTOHSCROLL + DEFPUSHBUTTON "Change",IDOK,11,127,50,14 + PUSHBUTTON "Remove",IDREMOVE,69,127,50,14 + PUSHBUTTON "Cancel",IDCANCEL,126,127,50,14 + LTEXT "New password",IDC_STATIC,11,66,163,10,0,WS_EX_TRANSPARENT + CONTROL "",IDC_STATIC,"Static",SS_ETCHEDFRAME,0,119,190,1 + LTEXT "Old password",IDC_STATIC,11,31,140,10,0,WS_EX_TRANSPARENT +END + ///////////////////////////////////////////////////////////////////////////// // // DESIGNINFO diff --git a/src/mir_app/src/MDatabaseCommonCrypt.cpp b/src/mir_app/src/MDatabaseCommonCrypt.cpp index 10a3e21881..6418f46c24 100644 --- a/src/mir_app/src/MDatabaseCommonCrypt.cpp +++ b/src/mir_app/src/MDatabaseCommonCrypt.cpp @@ -25,6 +25,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "database.h" #include "encrypt.h" +#define MS_DB_CHANGEPASSWORD "DB/UI/ChangePassword" + ///////////////////////////////////////////////////////////////////////////////////////// // Provider selection dialog @@ -109,6 +111,177 @@ BOOL MDatabaseCommon::IsSettingEncrypted(LPCSTR szModule, LPCSTR szSetting) ///////////////////////////////////////////////////////////////////////////////////////// +static HGENMENU hSetPwdMenu; + +__forceinline wchar_t *GetMenuTitle(bool bUsesPassword) +{ + return bUsesPassword ? LPGENW("Change/remove password") : LPGENW("Set password"); +} + +void MDatabaseCommon::SetPassword(const wchar_t *ptszPassword) +{ + if (ptszPassword == nullptr || *ptszPassword == 0) { + m_bUsesPassword = false; + m_crypto->setPassword(nullptr); + } + else { + m_bUsesPassword = true; + m_crypto->setPassword(T2Utf(ptszPassword)); + } + + Menu_ModifyItem(hSetPwdMenu, GetMenuTitle(m_bUsesPassword), Skin_GetIconHandle(SKINICON_OTHER_KEYS)); +} + +static UINT oldLangID; +void LanguageChanged(HWND hwndDlg) +{ + UINT_PTR LangID = (UINT_PTR)GetKeyboardLayout(0); + char Lang[3] = { 0 }; + if (LangID != oldLangID) { + oldLangID = LangID; + GetLocaleInfoA(MAKELCID((LangID & 0xffffffff), SORT_DEFAULT), LOCALE_SABBREVLANGNAME, Lang, 2); + Lang[0] = toupper(Lang[0]); + Lang[1] = tolower(Lang[1]); + SetDlgItemTextA(hwndDlg, IDC_LANG, Lang); + } +} + +///////////////////////////////////////////////////////////////////////////////////////// + +static bool CheckOldPassword(HWND hwndDlg, MDatabaseCommon *db) +{ + if (db->usesPassword()) { + wchar_t buf[100]; + GetDlgItemText(hwndDlg, IDC_OLDPASS, buf, _countof(buf)); + pass_ptrA oldPass(mir_utf8encodeW(buf)); + if (!db->getCrypt()->checkPassword(oldPass)) { + SetDlgItemText(hwndDlg, IDC_HEADERBAR, TranslateT("Wrong old password entered!")); + return false; + } + } + return true; +} + +struct DlgChangePassParam +{ + MDatabaseCommon *db; + wchar_t newPass[100]; + unsigned short wrongPass; +}; + +static INT_PTR CALLBACK sttChangePassword(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + DlgChangePassParam *param = (DlgChangePassParam*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + wchar_t buf[100]; + + switch (uMsg) { + case WM_INITDIALOG: + TranslateDialogDefault(hwndDlg); + SendDlgItemMessage(hwndDlg, IDC_HEADERBAR, WM_SETICON, ICON_SMALL, (LPARAM)g_plugin.getIcon(IDI_DATABASE, true)); + + param = (DlgChangePassParam*)lParam; + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); + + oldLangID = 0; + SetTimer(hwndDlg, 1, 200, nullptr); + LanguageChanged(hwndDlg); + return TRUE; + + case WM_CTLCOLORSTATIC: + if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_LANG)) { + SetTextColor((HDC)wParam, GetSysColor(COLOR_HIGHLIGHTTEXT)); + SetBkMode((HDC)wParam, TRANSPARENT); + return (INT_PTR)GetSysColorBrush(COLOR_HIGHLIGHT); + } + return FALSE; + + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDCANCEL: + EndDialog(hwndDlg, IDCANCEL); + break; + + case IDREMOVE: + if (!CheckOldPassword(hwndDlg, param->db)) { +LBL_Error: + SendDlgItemMessage(hwndDlg, IDC_HEADERBAR, WM_NCPAINT, 0, 0); + SetDlgItemTextA(hwndDlg, IDC_USERPASS1, ""); + SetDlgItemTextA(hwndDlg, IDC_USERPASS2, ""); + } + else { + param->db->SetPassword(nullptr); + param->db->StoreCryptoKey(); + EndDialog(hwndDlg, IDREMOVE); + } + break; + + case IDOK: + wchar_t buf2[100]; + GetDlgItemText(hwndDlg, IDC_USERPASS1, buf2, _countof(buf2)); + if (wcslen(buf2) < 3) { + SetDlgItemText(hwndDlg, IDC_HEADERBAR, TranslateT("Password is too short!")); + goto LBL_Error; + } + + GetDlgItemText(hwndDlg, IDC_USERPASS2, buf, _countof(buf)); + if (wcscmp(buf2, buf)) { + SetDlgItemText(hwndDlg, IDC_HEADERBAR, TranslateT("Passwords do not match!")); + goto LBL_Error; + } + + if (!CheckOldPassword(hwndDlg, param->db)) + goto LBL_Error; + + param->db->SetPassword(buf2); + param->db->StoreCryptoKey(); + SecureZeroMemory(buf2, sizeof(buf2)); + EndDialog(hwndDlg, IDOK); + } + break; + + case WM_TIMER: + LanguageChanged(hwndDlg); + return FALSE; + + case WM_DESTROY: + KillTimer(hwndDlg, 1); + Window_FreeIcon_IcoLib(GetDlgItem(hwndDlg, IDC_HEADERBAR)); + } + + return FALSE; +} + +static INT_PTR ChangePassword(void* obj, WPARAM, LPARAM) +{ + MDatabaseCommon *db = (MDatabaseCommon*)obj; + DlgChangePassParam param = { db }; + DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(db->usesPassword() ? IDD_CHANGEPASS : IDD_NEWPASS), nullptr, sttChangePassword, (LPARAM)¶m); + return 0; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +static int OnModulesLoaded(PVOID obj, WPARAM, LPARAM) +{ + MDatabaseCommon *db = (MDatabaseCommon *)obj; + + // main menu item + CMenuItem mi(&g_plugin); + mi.root = g_plugin.addRootMenu(MO_MAIN, LPGENW("Database"), 500000000, g_plugin.getIconHandle(IDI_DATABASE)); + Menu_ConfigureItem(mi.root, MCI_OPT_UID, "F7C5567C-D1EE-484B-B4F6-24677A5AAAEF"); + + SET_UID(mi, 0x50321866, 0xba1, 0x46dd, 0xb3, 0xa6, 0xc3, 0xcc, 0x55, 0xf2, 0x42, 0x9e); + mi.flags = CMIF_UNICODE; + mi.position = 1000000001; + mi.hIcolibItem = Skin_GetIconHandle(SKINICON_OTHER_KEYS); + mi.name.w = GetMenuTitle(db->usesPassword()); + mi.pszService = MS_DB_CHANGEPASSWORD; + hSetPwdMenu = Menu_AddMainMenuItem(&mi); + return 0; +} + +///////////////////////////////////////////////////////////////////////////////////////// + class CEnterPasswordDialog : public CDlgBase { friend class MDatabaseCommon; @@ -226,6 +399,9 @@ int MDatabaseCommon::InitCrypt() StoreCryptoKey(); } + CreateServiceFunctionObj(MS_DB_CHANGEPASSWORD, ChangePassword, this); + HookEventObj(ME_SYSTEM_MODULESLOADED, OnModulesLoaded, this); + m_bEncrypted = ReadEncryption(); return 0; } diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index 8e4c4994c5..7d9719b261 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -756,14 +756,15 @@ _Netlib_GetTlsUnique@8 @831 NONAME ?WriteContactSetting@MDatabaseCommon@@UAGHIPAUDBCONTACTWRITESETTING@@@Z @844 NONAME ?getCrypt@MDatabaseCommon@@QBEPAUMICryptoEngine@@XZ @845 NONAME ?isEncrypted@MDatabaseCommon@@QBE_NXZ @846 NONAME -?SelectProvider@MDatabaseCommon@@IAEPAUCRYPTO_PROVIDER@@XZ @847 NONAME +?SelectProvider@MDatabaseCommon@@QAEPAUCRYPTO_PROVIDER@@XZ @847 NONAME ?StoreProvider@MDatabaseReadonly@@UAGHPAUCRYPTO_PROVIDER@@@Z @848 NONAME ?Crypto_GetProvider@@YGPAUCRYPTO_PROVIDER@@PBD@Z @849 NONAME ?Crypto_ListProviders@@YGXPAHPAPAPAUCRYPTO_PROVIDER@@@Z @850 NONAME ?Crypto_RegisterEngine@@YGXPBUCRYPTO_PROVIDER@@@Z @851 NONAME -?InitCrypt@MDatabaseCommon@@IAEHXZ @852 NONAME +?InitCrypt@MDatabaseCommon@@QAEHXZ @852 NONAME ?ReadCryptoKey@MDatabaseReadonly@@UAGHAAVMBinBuffer@@@Z @853 NONAME ?ReadEncryption@MDatabaseReadonly@@UAGHXZ @854 NONAME ?ReadProvider@MDatabaseReadonly@@UAGPAUCRYPTO_PROVIDER@@XZ @855 NONAME ?StoreCryptoKey@MDatabaseReadonly@@UAGHXZ @856 NONAME ?usesPassword@MDatabaseCommon@@QBE_NXZ @857 NONAME +?SetPassword@MDatabaseCommon@@QAEXPB_W@Z @858 NONAME diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index f9f3d0e791..3d5b36d584 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -756,14 +756,15 @@ Netlib_GetTlsUnique @831 NONAME ?WriteContactSetting@MDatabaseCommon@@UEAAHIPEAUDBCONTACTWRITESETTING@@@Z @844 NONAME ?getCrypt@MDatabaseCommon@@QEBAPEAUMICryptoEngine@@XZ @845 NONAME ?isEncrypted@MDatabaseCommon@@QEBA_NXZ @846 NONAME -?SelectProvider@MDatabaseCommon@@IEAAPEAUCRYPTO_PROVIDER@@XZ @847 NONAME +?SelectProvider@MDatabaseCommon@@QEAAPEAUCRYPTO_PROVIDER@@XZ @847 NONAME ?StoreProvider@MDatabaseReadonly@@UEAAHPEAUCRYPTO_PROVIDER@@@Z @848 NONAME ?Crypto_GetProvider@@YAPEAUCRYPTO_PROVIDER@@PEBD@Z @849 NONAME ?Crypto_ListProviders@@YAXPEAHPEAPEAPEAUCRYPTO_PROVIDER@@@Z @850 NONAME ?Crypto_RegisterEngine@@YAXPEBUCRYPTO_PROVIDER@@@Z @851 NONAME -?InitCrypt@MDatabaseCommon@@IEAAHXZ @852 NONAME +?InitCrypt@MDatabaseCommon@@QEAAHXZ @852 NONAME ?ReadCryptoKey@MDatabaseReadonly@@UEAAHAEAVMBinBuffer@@@Z @853 NONAME ?ReadEncryption@MDatabaseReadonly@@UEAAHXZ @854 NONAME ?ReadProvider@MDatabaseReadonly@@UEAAPEAUCRYPTO_PROVIDER@@XZ @855 NONAME ?StoreCryptoKey@MDatabaseReadonly@@UEAAHXZ @856 NONAME ?usesPassword@MDatabaseCommon@@QEBA_NXZ @857 NONAME +?SetPassword@MDatabaseCommon@@QEAAXPEB_W@Z @858 NONAME diff --git a/src/mir_app/src/resource.h b/src/mir_app/src/resource.h index c4fb0e3a94..ec6bc9f321 100644 --- a/src/mir_app/src/resource.h +++ b/src/mir_app/src/resource.h @@ -63,6 +63,8 @@ #define IDI_MERROR 165 #define IDI_MWARNING 166 #define IDI_MINFO 167 +#define IDD_CHANGEPASS 168 +#define IDD_NEWPASS 169 #define IDI_MIRANDAWEBSITE 172 #define IDI_RENAME 173 #define IDI_HISTORY 174 @@ -400,7 +402,11 @@ #define IDC_CATEGORYLIST 1366 #define IDC_LOADICONS 1369 #define IDC_STICONSGROUP 1371 +#define IDC_OLDPASS 1372 +#define IDC_USERPASS1 1373 +#define IDC_USERPASS2 1374 #define IDC_MSGICON 1375 +#define IDREMOVE 1376 #define IDC_STNOPAGE 1377 #define IDC_STCHECKMARKS 1380 #define IDC_STATUSBAR 1389 -- cgit v1.2.3