diff options
author | George Hazan <ghazan@miranda.im> | 2018-04-15 13:34:49 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-04-15 13:34:49 +0300 |
commit | d8443a79d7c7bda64283da0337a04d8aed634dcf (patch) | |
tree | 0651c3293571673b2eabfed816384cfdaa9f8d30 | |
parent | 3868296f242d7595347e99beb9c239279de4bfff (diff) |
fixes #1230 (Database encryption mode)
-rw-r--r-- | plugins/Dbx_mdbx/src/dbcrypt.cpp | 88 | ||||
-rw-r--r-- | plugins/Dbx_mdbx/src/ui.h | 2 |
2 files changed, 49 insertions, 41 deletions
diff --git a/plugins/Dbx_mdbx/src/dbcrypt.cpp b/plugins/Dbx_mdbx/src/dbcrypt.cpp index e22b3a293d..36fb76a978 100644 --- a/plugins/Dbx_mdbx/src/dbcrypt.cpp +++ b/plugins/Dbx_mdbx/src/dbcrypt.cpp @@ -169,7 +169,6 @@ int CDbxMDBX::EnableEncryption(bool bEncrypted) std::vector<MEVENT> lstEvents;
lstEvents.reserve(st.ms_entries);
-
{
cursor_ptr_ro cursor(m_curEvents);
MDBX_val key, data;
@@ -178,49 +177,56 @@ int CDbxMDBX::EnableEncryption(bool bEncrypted) lstEvents.push_back(hDbEvent);
}
}
- for (auto it = lstEvents.begin(); it != lstEvents.end(); ++it) {
- MEVENT &hDbEvent = *it;
- MDBX_val key = { &hDbEvent, sizeof(MEVENT) }, data;
- int rc = mdbx_get(txnro, m_dbEvents, &key, &data);
- /* FIXME: throw an exception */
- assert(rc == MDBX_SUCCESS);
- (void)rc;
-
- const DBEvent *dbEvent = (const DBEvent*)data.iov_base;
- const BYTE *pBlob = (BYTE*)(dbEvent + 1);
-
- if (((dbEvent->flags & DBEF_ENCRYPTED) != 0) != bEncrypted) {
- mir_ptr<BYTE> pNewBlob;
- size_t nNewBlob;
- uint32_t 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;
- }
-
- data.iov_len = sizeof(DBEvent) + nNewBlob;
- mir_ptr<BYTE> pData((BYTE*)mir_alloc(data.iov_len));
- data.iov_base = pData.get();
- DBEvent *pNewDBEvent = (DBEvent *)data.iov_base;
- *pNewDBEvent = *dbEvent;
- pNewDBEvent->cbBlob = (uint16_t)nNewBlob;
- pNewDBEvent->flags = dwNewFlags;
- memcpy(pNewDBEvent + 1, pNewBlob, nNewBlob);
-
- txn_ptr trnlck(StartTran());
- if (mdbx_put(trnlck, m_dbEvents, &key, &data, 0) != MDBX_SUCCESS)
- return 1;
-
- if (trnlck.commit() != MDBX_SUCCESS)
- return 1;
+ do {
+ size_t portion = min(lstEvents.size(), 1000);
+
+ txn_ptr trnlck(StartTran());
+ for (size_t i = 0; i < portion; i++) {
+ MEVENT &hDbEvent = lstEvents[i];
+ MDBX_val key = { &hDbEvent, sizeof(MEVENT) }, data;
+ int rc = mdbx_get(txnro, m_dbEvents, &key, &data);
+ /* FIXME: throw an exception */
+ assert(rc == MDBX_SUCCESS);
+ (void)rc;
+
+ const DBEvent *dbEvent = (const DBEvent*)data.iov_base;
+ const BYTE *pBlob = (BYTE*)(dbEvent + 1);
+
+ if (((dbEvent->flags & DBEF_ENCRYPTED) != 0) != bEncrypted) {
+ mir_ptr<BYTE> pNewBlob;
+ size_t nNewBlob;
+ uint32_t 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;
+ }
+
+ data.iov_len = sizeof(DBEvent) + nNewBlob;
+ mir_ptr<BYTE> pData((BYTE*)mir_alloc(data.iov_len));
+ data.iov_base = pData.get();
+
+ DBEvent *pNewDBEvent = (DBEvent *)data.iov_base;
+ *pNewDBEvent = *dbEvent;
+ pNewDBEvent->cbBlob = (uint16_t)nNewBlob;
+ pNewDBEvent->flags = dwNewFlags;
+ memcpy(pNewDBEvent + 1, pNewBlob, nNewBlob);
+
+ if (mdbx_put(trnlck, m_dbEvents, &key, &data, 0) != MDBX_SUCCESS)
+ return 1;
+ }
}
+
+ lstEvents.erase(lstEvents.begin(), lstEvents.begin()+portion);
+ if (trnlck.commit() != MDBX_SUCCESS)
+ return 1;
}
+ while (lstEvents.size() > 0);
}
txn_ptr trnlck(StartTran());
diff --git a/plugins/Dbx_mdbx/src/ui.h b/plugins/Dbx_mdbx/src/ui.h index cfaf03b417..dc1a87c2e9 100644 --- a/plugins/Dbx_mdbx/src/ui.h +++ b/plugins/Dbx_mdbx/src/ui.h @@ -26,7 +26,9 @@ class COptionsDialog : public CDlgBase void OnApply()
{
+ 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());
}
|