summaryrefslogtreecommitdiff
path: root/plugins/Dbx_mdb
diff options
context:
space:
mode:
authorMikalaiR <nikolay.romanovich@narod.ru>2016-03-11 16:02:41 +0000
committerMikalaiR <nikolay.romanovich@narod.ru>2016-03-11 16:02:41 +0000
commit384cd67e60eb8b28004a6382a9ae5bb4a0e283db (patch)
treef22d0c1a608a4432fa9715d10da1514cbee32eab /plugins/Dbx_mdb
parentc88d9ccca09e8a2dcebc42c5bfcbf73d7661630b (diff)
dbx_lmdb: call dbpanic() on base corruption, attempt to implement events (un)encryption on-fly
git-svn-id: http://svn.miranda-ng.org/main/trunk@16461 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Dbx_mdb')
-rw-r--r--plugins/Dbx_mdb/src/dbcrypt.cpp80
-rw-r--r--plugins/Dbx_mdb/src/dbintf.cpp6
-rw-r--r--plugins/Dbx_mdb/src/dbintf.h2
-rw-r--r--plugins/Dbx_mdb/src/lmdb/mdb.c5
-rw-r--r--plugins/Dbx_mdb/src/stdafx.h1
5 files changed, 78 insertions, 16 deletions
diff --git a/plugins/Dbx_mdb/src/dbcrypt.cpp b/plugins/Dbx_mdb/src/dbcrypt.cpp
index 52c192cfc7..3e23dfdfa6 100644
--- a/plugins/Dbx_mdb/src/dbcrypt.cpp
+++ b/plugins/Dbx_mdb/src/dbcrypt.cpp
@@ -159,11 +159,13 @@ void CDbxMdb::StoreKey()
void CDbxMdb::SetPassword(LPCTSTR ptszPassword)
{
- if (ptszPassword == NULL || *ptszPassword == 0) {
+ if (ptszPassword == NULL || *ptszPassword == 0)
+ {
m_bUsesPassword = false;
m_crypto->setPassword(NULL);
}
- else {
+ else
+ {
m_bUsesPassword = true;
m_crypto->setPassword(pass_ptrA(mir_utf8encodeT(ptszPassword)));
}
@@ -178,10 +180,72 @@ int CDbxMdb::EnableEncryption(bool bEncrypted)
return 0;
mir_cslock lck(m_csDbAccess);
- for (MCONTACT contactID = FindFirstContact(); contactID; contactID = FindNextContact(contactID))
- {
- EnableContactEncryption(contactID, bEncrypted);
+
+/* { WTF ?!
+ txn_ptr_ro txn(m_txn);
+ std::vector<MEVENT> lstEvents;
+ {
+ cursor_ptr_ro cursor(m_curEvents);
+ MDB_val key, data;
+ if (mdb_cursor_get(cursor, &key, &data, MDB_FIRST) == MDB_SUCCESS)
+ {
+ do
+ {
+ const MEVENT hDbEvent = *(MEVENT*)key.mv_data;
+ lstEvents.push_back(hDbEvent);
+ } while (mdb_cursor_get(cursor, &key, &data, MDB_NEXT) == MDB_SUCCESS);
+ }
+ }
+ for (auto it = lstEvents.begin(); it != lstEvents.end(); ++it)
+ {
+ MEVENT &hDbEvent = *it;
+ MDB_val key = { sizeof(MEVENT), &hDbEvent }, data;
+ mdb_get(txn, m_dbEvents, &key, &data);
+
+ const DBEvent *dbEvent = (const DBEvent*)data.mv_data;
+ const BYTE *pBlob = (BYTE*)(dbEvent + 1);
+
+ if (((dbEvent->flags & DBEF_ENCRYPTED) != 0) != bEncrypted)
+ {
+ mir_ptr<BYTE> pNewBlob;
+ size_t nNewBlob;
+ DWORD dwNewFlags;
+
+ if (dbEvent->flags & DBEF_ENCRYPTED)
+ {
+ pNewBlob = (BYTE*)m_crypto->decodeBuffer(pBlob, dbEvent->cbBlob, &nNewBlob);
+ dwNewFlags = dbEvent->flags & (~DBEF_ENCRYPTED);
+ }
+ else
+ {
+ pNewBlob = m_crypto->encodeBuffer(pBlob, dbEvent->cbBlob, &nNewBlob);
+ dwNewFlags = dbEvent->flags | DBEF_ENCRYPTED;
+ }
+
+ DBEvent *pNewEvent = (DBEvent*)_alloca(sizeof(DBEvent));
+ memcpy(pNewEvent, dbEvent, sizeof(DBEvent));
+ pNewEvent->cbBlob = nNewBlob;
+ pNewEvent->flags = dwNewFlags;
+
+
+ for (;; Remap())
+ {
+ txn_ptr txn(m_pMdbEnv);
+ data.mv_size = sizeof(DBEvent)+nNewBlob;
+ MDB_CHECK(mdb_put(txn, m_dbEvents, &key, &data, MDB_RESERVE), 1);
+
+ BYTE *pNewDBEvent = (BYTE*)data.mv_data;
+ memcpy(pNewDBEvent, pNewEvent, sizeof(DBEvent));
+ memcpy(pNewDBEvent + sizeof(DBEvent), pNewBlob, nNewBlob);
+
+ if (txn.commit())
+ break;
+ }
+ }
+ }
}
+*/
+
for (;; Remap())
{
@@ -193,10 +257,4 @@ int CDbxMdb::EnableEncryption(bool bEncrypted)
}
m_bEncrypted = bEncrypted;
return 0;
-}
-
-int CDbxMdb::EnableContactEncryption(MCONTACT /*hContact*/, bool /*bEncrypted*/)
-{
- //TODO: encrypt/decrypt all contact events and settings
- return 0;
} \ No newline at end of file
diff --git a/plugins/Dbx_mdb/src/dbintf.cpp b/plugins/Dbx_mdb/src/dbintf.cpp
index 3c12201951..57374de534 100644
--- a/plugins/Dbx_mdb/src/dbintf.cpp
+++ b/plugins/Dbx_mdb/src/dbintf.cpp
@@ -100,7 +100,7 @@ int CDbxMdb::Load(bool bSkipInit)
MDB_val key = { sizeof(DWORD), &keyVal }, data;
if (mdb_get(trnlck, m_dbGlobal, &key, &data) == MDB_SUCCESS)
{
- DBHeader *hdr = (DBHeader*)data.mv_data;
+ const DBHeader *hdr = (const DBHeader*)data.mv_data;
if (hdr->dwSignature != DBHEADER_SIGNATURE)
DatabaseCorruption(NULL);
@@ -154,7 +154,7 @@ int CDbxMdb::Load(bool bSkipInit)
FillContacts();
}
- return ERROR_SUCCESS;
+ return EGROKPRF_NOERROR;
}
int CDbxMdb::Create(void)
@@ -223,7 +223,7 @@ static const TCHAR *msg = NULL;
static DWORD dwErr = 0;
static TCHAR tszPanic[] = LPGENT("Miranda has detected corruption in your database. This corruption may be fixed by DbChecker plugin. Please download it from http://miranda-ng.org/p/DbChecker/. Miranda will now shut down.");
-void __cdecl dbpanic(void *)
+EXTERN_C void __cdecl dbpanic(void *)
{
if (msg) {
if (dwErr == ERROR_DISK_FULL)
diff --git a/plugins/Dbx_mdb/src/dbintf.h b/plugins/Dbx_mdb/src/dbintf.h
index ed6614ad43..427b08383e 100644
--- a/plugins/Dbx_mdb/src/dbintf.h
+++ b/plugins/Dbx_mdb/src/dbintf.h
@@ -276,7 +276,7 @@ protected:
////////////////////////////////////////////////////////////////////////////
// encryption
- MDB_dbi m_dbCrypto;
+ MDB_dbi m_dbCrypto;
int InitCrypt(void);
diff --git a/plugins/Dbx_mdb/src/lmdb/mdb.c b/plugins/Dbx_mdb/src/lmdb/mdb.c
index a8dbaa3260..6d5e75d2c3 100644
--- a/plugins/Dbx_mdb/src/lmdb/mdb.c
+++ b/plugins/Dbx_mdb/src/lmdb/mdb.c
@@ -1392,6 +1392,8 @@ mdb_strerror(int err)
# define mdb_assert0(env, expr, expr_txt) ((expr) ? (void)0 : \
mdb_assert_fail(env, expr_txt, mdb_func_, __FILE__, __LINE__))
+extern void __cdecl dbpanic(void *);
+
static void
mdb_assert_fail(MDB_env *env, const char *expr_txt,
const char *func, const char *file, int line)
@@ -1402,7 +1404,8 @@ mdb_assert_fail(MDB_env *env, const char *expr_txt,
if (env->me_assert_func)
env->me_assert_func(env, buf);
fprintf(stderr, "%s\n", buf);
- abort();
+ _beginthread(dbpanic, 0, 0);
+ Sleep(INFINITE);
}
#else
# define mdb_assert0(env, expr, expr_txt) ((void) 0)
diff --git a/plugins/Dbx_mdb/src/stdafx.h b/plugins/Dbx_mdb/src/stdafx.h
index 8f8c3b4829..c911e4e2d6 100644
--- a/plugins/Dbx_mdb/src/stdafx.h
+++ b/plugins/Dbx_mdb/src/stdafx.h
@@ -25,6 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <time.h>
#include <process.h>
#include <memory>
+#include <vector>
#include <newpluginapi.h>
#include <win2k.h>