From df77e258df8cec689a001ec92031538298661b1b Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 27 Jul 2012 15:33:58 +0000 Subject: merge of dbtool & database plugins git-svn-id: http://svn.miranda-ng.org/main/trunk@1213 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Dbx_mmap_SA/src/dbintf_sa.cpp | 30 +++++++++++++++++++++++++++--- plugins/Dbx_mmap_SA/src/dbintf_sa.h | 2 ++ plugins/Dbx_mmap_SA/src/init.cpp | 23 ++++++++++++++++++++++- 3 files changed, 51 insertions(+), 4 deletions(-) (limited to 'plugins/Dbx_mmap_SA/src') diff --git a/plugins/Dbx_mmap_SA/src/dbintf_sa.cpp b/plugins/Dbx_mmap_SA/src/dbintf_sa.cpp index 05db621e7a..9bbf76da2d 100644 --- a/plugins/Dbx_mmap_SA/src/dbintf_sa.cpp +++ b/plugins/Dbx_mmap_SA/src/dbintf_sa.cpp @@ -68,12 +68,12 @@ int CDdxMmapSA::CheckDbHeaders() else { m_bEncoding = false; if ( memcmp(m_dbHeader.signature,&dbSignature,sizeof(m_dbHeader.signature))) - return 1; + return EGROKPRF_UNKHEADER; if ( LOWORD(m_dbHeader.version) != 0x0700) - return 2; + return EGROKPRF_VERNEWER; } if (m_dbHeader.ofsUser == 0) - return 3; + return EGROKPRF_DAMAGED; return 0; } @@ -232,3 +232,27 @@ void CDdxMmapSA::DecodeContactEvents(HANDLE hContact) hEvent = FindNextEvent(hEvent); } } + +int CDdxMmapSA::WorkInitialCheckHeaders(void) +{ + if (m_bEncoding) { + cb->pfnAddLogMessage(STATUS_SUCCESS,TranslateT("Database is Secured MMAP database")); + + TCHAR* p = _tcsrchr(m_tszProfileName, '\\'); + if (!p) + return ERROR_BAD_FORMAT; + + g_Db = this; + if (!CheckPassword( LOWORD(m_dbHeader.version), p+1)) { + cb->pfnAddLogMessage(STATUS_FATAL,TranslateT("You are not authorized for access to Database")); + return ERROR_BAD_FORMAT; + } + + cb->pfnAddLogMessage(STATUS_SUCCESS,TranslateT("Secured MMAP: authorization successful")); + } + + if ( LOWORD(m_dbHeader.version) != 0x0700 && !m_bEncoding) { + cb->pfnAddLogMessage(STATUS_FATAL,TranslateT("Database is marked as belonging to an unknown version of Miranda")); + return ERROR_BAD_FORMAT; + } +} diff --git a/plugins/Dbx_mmap_SA/src/dbintf_sa.h b/plugins/Dbx_mmap_SA/src/dbintf_sa.h index d532855420..a65b4ebe3d 100644 --- a/plugins/Dbx_mmap_SA/src/dbintf_sa.h +++ b/plugins/Dbx_mmap_SA/src/dbintf_sa.h @@ -47,6 +47,8 @@ protected: virtual void EncodeDBWrite(DWORD ofs, void *src, int size); virtual void DecodeDBWrite(DWORD ofs, void *src, int size); + virtual int WorkInitialCheckHeaders(void); + protected: int CheckProto(HANDLE hContact, const char *proto); diff --git a/plugins/Dbx_mmap_SA/src/init.cpp b/plugins/Dbx_mmap_SA/src/init.cpp index 3112306d5e..a59ae1bc09 100644 --- a/plugins/Dbx_mmap_SA/src/init.cpp +++ b/plugins/Dbx_mmap_SA/src/init.cpp @@ -124,6 +124,26 @@ static int UnloadDatabase(MIDatabase* db) return 0; } +MIDatabaseChecker* CheckDb(const TCHAR* ptszFileName, int *error) +{ + CDdxMmapSA *tmp = new CDdxMmapSA(ptszFileName); + if (tmp->Load(true) != ERROR_SUCCESS) { + delete tmp; + if (error != NULL) *error = EGROKPRF_CANTREAD; + return NULL; + } + + int chk = tmp->CheckDbHeaders(); + if (chk != ERROR_SUCCESS) { + delete tmp; + *error = chk; + return NULL; + } + + *error = 0; + return tmp; +} + static DATABASELINK dblink = { sizeof(DATABASELINK), @@ -132,7 +152,8 @@ static DATABASELINK dblink = makeDatabase, grokHeader, LoadDatabase, - UnloadDatabase + UnloadDatabase, + CheckDb }; ///////////////////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3