changed data type of group and entry list from vector (STL) to QList (Qt)

git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@19 b624d157-de02-0410-bad0-e51aec6abb33
master
tariq 19 years ago
parent 16060b08e4
commit 3c4ac74af1
  1. 10
      src/Database.cpp
  2. 11
      src/Database.h
  3. 113
      src/PwManager.cpp
  4. 12
      src/PwManager.h
  5. 28
      src/lib/GroupView.cpp
  6. 12
      src/lib/SecString.cpp
  7. 4
      src/lib/SecString.h
  8. 1
      src/mainwindow.cpp

@ -34,6 +34,16 @@ pBinaryData=NULL;
bool CGroup::UI_ExpandByDefault=true;
bool CEntry::operator==(const CEntry& e)const{
if(sID==e.sID)return true;
else return false;
}
bool CGroup::operator==(const CGroup& g)const{
if(ID==g.ID)return true;
else return false;
}
CGroup::CGroup(){
Creation=QDateTime::currentDateTime();
LastAccess=QDateTime::currentDateTime();

@ -20,7 +20,7 @@
#ifndef _DATABASE_H_
#define _DATABASE_H_
#include <vector.h>
#include <QList>
#include <QDateTime>
#include "lib/SecString.h"
using namespace std;
@ -47,6 +47,7 @@ Q_UINT8 *pBinaryData;
Q_UINT32 BinaryDataLength;
Q_UINT32 PasswordLength;
bool ReadEntryField(Q_UINT16 FieldType, Q_UINT32 FieldSize, Q_UINT8 *pData);
bool operator==(const CEntry&) const;
};
@ -65,6 +66,7 @@ QDateTime Expire;
Q_UINT16 Level;
Q_UINT32 Flags;
bool ReadGroupField(Q_UINT16 FieldType, Q_UINT32 FieldSize, Q_UINT8 *pData);
bool operator==(const CGroup&) const;
bool UI_ItemIsExpanded;
static bool UI_ExpandByDefault;
@ -72,9 +74,6 @@ static bool UI_ExpandByDefault;
};
typedef vector<CEntry>::iterator EntryItr;
typedef vector<CGroup>::iterator GroupItr;
class Database{
public:
@ -83,8 +82,8 @@ public:
QString filename;
bool modflag;
int SearchGroupID;
vector<CGroup>Groups;
vector<CEntry>Entries;
QList<CGroup>Groups;
QList<CEntry>Entries;
protected:
Q_UINT8 MasterKey[32];

@ -140,16 +140,13 @@ err=trUtf8("Hash-Test fehlgeschlage: der Schlüssl ist falsch oder die Datei ist
return false;}
Groups.resize(NumGroups);
Entries.resize(NumEntries);
unsigned long tmp_id=0;
unsigned long pos = DB_HEADER_SIZE;
Q_UINT16 FieldType;
Q_UINT32 FieldSize;
char* pField;
bool bRet;
CGroup group;
for(unsigned long CurGroup = 0; CurGroup < NumGroups; )
{
@ -165,8 +162,9 @@ bool bRet;
if(pos >= (total_size + FieldSize)) {
return false;}
bRet = Groups[CurGroup].ReadGroupField(FieldType, FieldSize, (Q_UINT8 *)pField);
bRet = group.ReadGroupField(FieldType, FieldSize, (Q_UINT8 *)pField);
if((FieldType == 0xFFFF) && (bRet == true)){
Groups << group;
CurGroup++;} // Now and ONLY now the counter gets increased
pField += FieldSize;
@ -174,6 +172,7 @@ bool bRet;
if(pos >= total_size) { return false;}
}
CEntry entry;
for(unsigned long CurEntry = 0; CurEntry < NumEntries;)
{
@ -189,9 +188,10 @@ bool bRet;
if(pos >= (total_size + FieldSize)) {
return false; }
bRet = Entries[CurEntry].ReadEntryField(FieldType,FieldSize,(Q_UINT8*)pField);
bRet = entry.ReadEntryField(FieldType,FieldSize,(Q_UINT8*)pField);
if((FieldType == 0xFFFF) && (bRet == true)){
Entries[CurEntry].sID=tmp_id++;
entry.sID=tmp_id++;
Entries << entry;
CurEntry++;} // Now and ONLY now the counter gets increased
pField += FieldSize;
@ -203,10 +203,10 @@ bool bRet;
unsigned long CurGID, g, e, z, num;
delete [] buffer;
for(vector<CEntry>::iterator i=Entries.begin();i!=Entries.end();i++){
if(IsMetaStream(*i)==true){
for(int i=0;i<Entries.size();i++){
if(IsMetaStream(Entries[i])==true){
///@TODO Parse Metastreams
deleteEntry(i);
deleteEntry(&Entries[i]);
i--;
}
}
@ -387,13 +387,8 @@ delete[] PasswordKey;
delete[] FileKey;
}
vector<CEntry>::iterator PwDatabase::deleteEntry(vector<CEntry>::iterator iterator){
return Entries.erase(iterator);
}
vector<CEntry>::iterator PwDatabase::deleteEntry(CEntry* entry){
return deleteEntry(getEntryIterator(entry));
void PwDatabase::deleteEntry(CEntry* entry){
Entries.removeAt(Entries.indexOf(*entry));
}
bool PwDatabase::IsMetaStream(CEntry& p){
@ -559,6 +554,7 @@ Q_UINT8 FinalRandomSeed[16];
Q_UINT8 ContentsHash[32];
Q_UINT8 EncryptionIV[16];
/*
if(SearchGroupID!=-1){
for(int i=0;i<Groups.size();i++){
if(Groups[i].ID==SearchGroupID){
@ -566,6 +562,8 @@ if(SearchGroupID!=-1){
Groups.erase(getGroupIterator(&Groups[i]));}
}
}
*/
if(filename==QString::null)return false;
QFile file(filename);
unsigned int FileSize;
@ -815,16 +813,6 @@ if(SearchGroupID!=-1)Groups.push_back(SearchGroup);
return true;
}
GroupItr PwDatabase::getGroupIterator(CGroup* pGroup){
//for(vector<CGroup>::iterator i=Groups.begin();i!=Groups.end();i++){
//if((*i).ID==pGroup->ID)return i;}
return Groups.begin()+(pGroup-&Groups[0]);
}
EntryItr PwDatabase::getEntryIterator(CEntry* pEntry){
return Entries.begin()+(pEntry-&Entries[0]);
}
CGroup* PwDatabase::addGroup(CGroup* parent){
CGroup group;
@ -833,41 +821,51 @@ group.ImageID=0;
group.ID=getNewGroupId();
if(!Groups.size() || !parent){
Groups.push_back(group);
Groups << group;
return &Groups.back();
}
else { GroupItr groupIt;
groupIt=Groups.insert(getGroupIterator(parent)+1,group);
return &(*groupIt);}
else { int i=Groups.indexOf(*parent)+1;
Groups.insert(i,group);
return &Groups[i];}
}
GroupItr PwDatabase::deleteGroup(unsigned long id){
void PwDatabase::deleteGroup(unsigned long id){
for(int i=0;i<Groups.size();i++){
if(Groups[i].ID==id) return deleteGroup(&Groups[i]);
}
}
GroupItr PwDatabase::deleteGroup(CGroup* group){
GroupItr first=getGroupIterator(group);
GroupItr last=Groups.end();
for(GroupItr i=getGroupIterator(group)+1; i!=Groups.end();i++){
if((*i).Level<=group->Level){
last=i;
break;}
}
void PwDatabase::deleteGroup(CGroup* group){
int GroupIndex=Groups.indexOf(*group);
int NumChilds;
for(GroupItr g=first;g!=last;g++){
for(EntryItr e=Entries.begin();e!=Entries.end();){
if((*g).ID==(*e).GroupID)e=deleteEntry(e);
else e++;
int i;
for(i=GroupIndex+1; i<Groups.size(); i++){
if(Groups[i].Level<=group->Level)break;
}
NumChilds=i-GroupIndex-1;
qDebug("NUMCHILDS=%i\n",NumChilds);
//delete entries
for(i=GroupIndex; i<=GroupIndex+NumChilds; i++){
for(int j=0; j<Entries.size();){
if(Entries[j].GroupID==Groups[i].ID)
deleteEntry(&Entries[j]);
else
j++;
}
}
return Groups.erase(first,last);
for(i=NumChilds; i>=0; i--){
Groups.removeAt(GroupIndex+i);
}
}
int PwDatabase::getGroupIndex(CGroup* g){
return getGroupIndex(g->ID);
}
int PwDatabase::getGroupIndex(unsigned long ID){
@ -959,6 +957,31 @@ for(int i=0; i<64; i+=2){
}
}
void PwDatabase::moveGroup(CGroup* group, CGroup* DstGroup){
/*
int NumSubGroups=0;
int GroupIndex=getGroupIndex(group);
int i;
for(i=GroupIndex+1; i<groups.size(); i++){
if(groups[i].Level <= group->Level) break;
}
NumSubGroups=i-GroupIndex-1;
int LevelDiff;
if(DstGroup)
LevelDiff=DstGroup->Level - group->Level;
else
LevelDiff=-group->Level;
if(DstGroup){
groups.insert(pos, groups[
}
*/
}
void memcpyFromLEnd32(Q_UINT32* dst,char* src){
if(QSysInfo::ByteOrder==QSysInfo::BigEndian){

@ -55,10 +55,13 @@ public:
bool CalcMasterKeyByFileAndPw(QString filename, QString& password);
CGroup* addGroup(CGroup* parent);
GroupItr deleteGroup(CGroup* pGroup);
GroupItr deleteGroup(unsigned long ID);
void deleteGroup(CGroup* pGroup);
void deleteGroup(unsigned long ID);
void moveGroup(CGroup* group, CGroup* DstGroup);
int getGroupIndex(CGroup* group);
int getGroupIndex(unsigned long ID);
EntryItr deleteEntry(CEntry* pEntry);
void deleteEntry(CEntry* pEntry);
void moveEntry(CEntry* pEntry,CGroup* pDstGroup);
CEntry* addEntry();
void merge(PwDatabase* db2);
@ -69,9 +72,6 @@ public:
private:
EntryItr deleteEntry(vector<CEntry>::iterator i);
EntryItr getEntryIterator(CEntry* pEntry);
GroupItr getGroupIterator(CGroup* pGroup);
bool IsMetaStream(CEntry& Entry);
void transformKey(Q_UINT8* src,Q_UINT8* dst,Q_UINT8* seed,int rounds);
bool readHeader(char* raw);

@ -127,29 +127,29 @@ void KeepassGroupView::mouseMoveEvent(QMouseEvent *event){
void KeepassGroupView::updateItems(){
clear();
Items.clear();
for(GroupItr i=db->Groups.begin();i!=db->Groups.end();i++){
if((*i).Level==0){
for(int i=0; i<db->Groups.size();i++){
if(db->Groups[i].Level==0){
if(Items.size()) Items.push_back(new GroupViewItem(this,getLastSameLevelItem(0)));
else Items.push_back(new GroupViewItem(this));
Items.back()->setText(0,(*i).Name);
Items.back()->pGroup=&(*i);
Items.back()->setText(0,db->Groups[i].Name);
Items.back()->pGroup=&db->Groups[i];
}
else{
if((*i).Level>(*(i-1)).Level){
Items.push_back(new GroupViewItem(Items.back(),getLastSameLevelItem((*i).Level)));
Items.back()->setText(0,(*i).Name);
Items.back()->pGroup=&(*i);
if(db->Groups[i].Level>db->Groups[i-1].Level){
Items.push_back(new GroupViewItem(Items.back(),getLastSameLevelItem(db->Groups[i].Level)));
Items.back()->setText(0,db->Groups[i].Name);
Items.back()->pGroup=&db->Groups[i];
}
if((*i).Level<=(*(i-1)).Level){
if(db->Groups[i].Level<=db->Groups[i-1].Level){
GroupItemItr j;
for(j=Items.end()-1;j!=Items.begin();j--){
if((*j)->pGroup->Level<(*i).Level)break;}
Items.push_back(new GroupViewItem((*j),getLastSameLevelItem((*i).Level)));
Items.back()->setText(0,(*i).Name);
Items.back()->pGroup=&(*i);
if((*j)->pGroup->Level<db->Groups[i].Level)break;}
Items.push_back(new GroupViewItem((*j),getLastSameLevelItem(db->Groups[i].Level)));
Items.back()->setText(0,db->Groups[i].Name);
Items.back()->pGroup=&db->Groups[i];
}
}
Items.back()->setIcon(0,EntryIcons[(*i).ImageID]);
Items.back()->setIcon(0,EntryIcons[db->Groups[i].ImageID]);
}
for(int i=0;i<Items.size();i++){

@ -26,25 +26,22 @@ using namespace std;
Q_UINT8 SecString::Key[32]={0};
SecString::SecString(){
data=NULL;
len=0;
cryptlen=0;
}
SecString::~SecString(){
//if(data)delete [] data; ///@FIXME zerschießt den Stack, aber warum???
overwrite(plaintext);
}
void SecString::getString(QString & str){
if(data){
if(data.size()){
Rijndael aes;
int r=aes.init(Rijndael::CBC, Rijndael::Decrypt,Key,Rijndael::Key32Bytes);
if(r){ cout << "AES error, code " << r << endl;
exit(-1);}
char* out=new char[len];
r=aes.padDecrypt((unsigned char*)data,cryptlen,(unsigned char*)out);
r=aes.padDecrypt((unsigned char*)data.data(),data.size(),(unsigned char*)out);
if(r!=len){ cout << "AES error in SecString::getString(), r!=length, r=" << r << endl;
exit(-1);}
str=QString::fromUtf8(out,len);
@ -74,10 +71,8 @@ memcpy(input,str.utf8(),il);
r=aes.padEncrypt((unsigned char*)input,il,(unsigned char*)output);
if(r<0){ cout << "AES error, code " << r << endl;
exit(-1);}
cryptlen=r;
len=il;
if(data)delete [] data;
data=output;
data=QByteArray(output,r);
overwrite(input,il);
delete [] input;
if(DelSrc)overwrite(str);
@ -103,3 +98,4 @@ return len;
void SecString::generateSessionKey(){
getRandomBytes(Key,32,1,false);
}

@ -20,6 +20,7 @@
#ifndef _SECSTRING_H_
#define _SECSTRING_H_
#include <QByteArray>
#include <qstring.h>
#include <qglobal.h>
#include "crypto/rijndael.h"
@ -42,9 +43,8 @@ public:
private:
static Q_UINT8 Key[32];
QString plaintext;
char* data;
QByteArray data;
int len;
int cryptlen;
};

@ -412,4 +412,5 @@ Q_ASSERT(GroupView->selectedItems().size());
CGroup *pGroup=static_cast<GroupViewItem*>(GroupView->selectedItems()[0])->pGroup;
db->deleteGroup(pGroup);
GroupView->updateItems();
setStateFileModified(true);
}