summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-10-16 01:05:12 (UTC)
committer ulf69 <ulf69>2004-10-16 01:05:12 (UTC)
commita6b0eba5c1aac3ba170b99c2b773fcabe10d8a40 (patch) (unidiff)
tree874b41d93e8cf796125038ea4fb5861788cfb2dd
parent6f229ba483beece68b9c408fb754864c8f0e3167 (diff)
downloadkdepimpi-a6b0eba5c1aac3ba170b99c2b773fcabe10d8a40.zip
kdepimpi-a6b0eba5c1aac3ba170b99c2b773fcabe10d8a40.tar.gz
kdepimpi-a6b0eba5c1aac3ba170b99c2b773fcabe10d8a40.tar.bz2
removed references to bzip2 compressformat
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/pwmanager/pwmdoc.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp
index a5df8f0..0ac5517 100644
--- a/pwmanager/pwmanager/pwmdoc.cpp
+++ b/pwmanager/pwmanager/pwmdoc.cpp
@@ -1,284 +1,284 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch * 3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de * 4 * email: mbuesch@freenet.de *
5 * * 5 * *
6 * This program is free software; you can redistribute it and/or modify * 6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 * 7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. * 8 * as published by the Free Software Foundation. *
9 * * 9 * *
10 ***************************************************************************/ 10 ***************************************************************************/
11 11
12/*************************************************************************** 12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk 13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 2.0 of pwmanager 14 * This file is originaly based on version 2.0 of pwmanager
15 * and was modified to run on embedded devices that run microkde 15 * and was modified to run on embedded devices that run microkde
16 * 16 *
17 * $Id$ 17 * $Id$
18 **************************************************************************/ 18 **************************************************************************/
19 19
20#include "pwmdoc.h" 20#include "pwmdoc.h"
21#include "pwmview.h" 21#include "pwmview.h"
22#include "blowfish.h" 22#include "blowfish.h"
23#include "sha1.h" 23#include "sha1.h"
24#include "globalstuff.h" 24#include "globalstuff.h"
25#include "gpasmanfile.h" 25#include "gpasmanfile.h"
26#include "serializer.h" 26#include "serializer.h"
27#include "compressgzip.h" 27#include "compressgzip.h"
28#include "compressbzip2.h" 28//US#include "compressbzip2.h"
29#include "randomizer.h" 29#include "randomizer.h"
30#include "pwminit.h" 30#include "pwminit.h"
31#include "libgcryptif.h" 31#include "libgcryptif.h"
32#ifdef PWM_EMBEDDED 32#ifdef PWM_EMBEDDED
33#include "pwmprefs.h" 33#include "pwmprefs.h"
34#include "kglobal.h" 34#include "kglobal.h"
35#endif 35#endif
36 36
37#include <kmessagebox.h> 37#include <kmessagebox.h>
38#include <libkcal/syncdefines.h> 38#include <libkcal/syncdefines.h>
39 39
40 40
41#ifdef CONFIG_KWALLETIF 41#ifdef CONFIG_KWALLETIF
42# include "kwalletemu.h" 42# include "kwalletemu.h"
43#endif // CONFIG_KWALLETIF 43#endif // CONFIG_KWALLETIF
44 44
45#include <qdatetime.h> 45#include <qdatetime.h>
46#include <qsize.h> 46#include <qsize.h>
47#include <qfileinfo.h> 47#include <qfileinfo.h>
48#include <qfile.h> 48#include <qfile.h>
49 49
50#include <stdio.h> 50#include <stdio.h>
51#include <stdlib.h> 51#include <stdlib.h>
52#include <errno.h> 52#include <errno.h>
53#include <string.h> 53#include <string.h>
54//US#include <iostream> 54//US#include <iostream>
55#include <algorithm> 55#include <algorithm>
56#include <sys/types.h> 56#include <sys/types.h>
57#include <sys/stat.h> 57#include <sys/stat.h>
58#include <unistd.h> 58#include <unistd.h>
59#include <stdint.h> 59#include <stdint.h>
60 60
61 61
62#ifdef PWM_EMBEDDED 62#ifdef PWM_EMBEDDED
63#ifndef Q_LONG 63#ifndef Q_LONG
64#define Q_LONG long 64#define Q_LONG long
65#endif 65#endif
66 66
67#ifndef Q_ULONG 67#ifndef Q_ULONG
68#define Q_ULONG unsigned long 68#define Q_ULONG unsigned long
69#endif 69#endif
70#endif //PWM_EMBEDDED 70#endif //PWM_EMBEDDED
71 71
72 72
73//TODO: reset to its normal value. 73//TODO: reset to its normal value.
74 #define META_CHECK_TIMER_INTERVAL10/*300*/ /* sek */ 74 #define META_CHECK_TIMER_INTERVAL10/*300*/ /* sek */
75 75
76using namespace std; 76using namespace std;
77 77
78 78
79void PwMDocList::add(PwMDoc *doc, const string &id) 79void PwMDocList::add(PwMDoc *doc, const string &id)
80{ 80{
81#ifdef PWM_DEBUG 81#ifdef PWM_DEBUG
82 // check for existance of object in debug mode only. 82 // check for existance of object in debug mode only.
83 vector<listItem>::iterator begin = docList.begin(), 83 vector<listItem>::iterator begin = docList.begin(),
84 end = docList.end(), 84 end = docList.end(),
85 i = begin; 85 i = begin;
86 while (i != end) { 86 while (i != end) {
87 if (i->doc == doc) { 87 if (i->doc == doc) {
88 BUG(); 88 BUG();
89 return; 89 return;
90 } 90 }
91 ++i; 91 ++i;
92 } 92 }
93#endif 93#endif
94 listItem newItem; 94 listItem newItem;
95 newItem.doc = doc; 95 newItem.doc = doc;
96 newItem.docId = id; 96 newItem.docId = id;
97 docList.push_back(newItem); 97 docList.push_back(newItem);
98} 98}
99 99
100void PwMDocList::edit(PwMDoc *doc, const string &newId) 100void PwMDocList::edit(PwMDoc *doc, const string &newId)
101{ 101{
102 vector<listItem>::iterator begin = docList.begin(), 102 vector<listItem>::iterator begin = docList.begin(),
103 end = docList.end(), 103 end = docList.end(),
104 i = begin; 104 i = begin;
105 while (i != end) { 105 while (i != end) {
106 if (i->doc == doc) { 106 if (i->doc == doc) {
107 i->docId = newId; 107 i->docId = newId;
108 return; 108 return;
109 } 109 }
110 ++i; 110 ++i;
111 } 111 }
112} 112}
113 113
114void PwMDocList::del(PwMDoc *doc) 114void PwMDocList::del(PwMDoc *doc)
115{ 115{
116 vector<listItem>::iterator begin = docList.begin(), 116 vector<listItem>::iterator begin = docList.begin(),
117 end = docList.end(), 117 end = docList.end(),
118 i = begin; 118 i = begin;
119 while (i != end) { 119 while (i != end) {
120 if (i->doc == doc) { 120 if (i->doc == doc) {
121 docList.erase(i); 121 docList.erase(i);
122 return; 122 return;
123 } 123 }
124 ++i; 124 ++i;
125 } 125 }
126} 126}
127 127
128bool PwMDocList::find(const string &id, listItem *ret) 128bool PwMDocList::find(const string &id, listItem *ret)
129{ 129{
130 vector<listItem>::iterator begin = docList.begin(), 130 vector<listItem>::iterator begin = docList.begin(),
131 end = docList.end(), 131 end = docList.end(),
132 i = begin; 132 i = begin;
133 while (i != end) { 133 while (i != end) {
134 if (i->docId == id) { 134 if (i->docId == id) {
135 if (ret) 135 if (ret)
136 *ret = *i; 136 *ret = *i;
137 return true; 137 return true;
138 } 138 }
139 ++i; 139 ++i;
140 } 140 }
141 return false; 141 return false;
142} 142}
143 143
144 144
145 145
146DocTimer::DocTimer(PwMDoc *_doc) 146DocTimer::DocTimer(PwMDoc *_doc)
147 : doc (_doc) 147 : doc (_doc)
148 , mpwLock (0) 148 , mpwLock (0)
149 , autoLockLock (0) 149 , autoLockLock (0)
150 , metaCheckLock (0) 150 , metaCheckLock (0)
151{ 151{
152 mpwTimer = new QTimer; 152 mpwTimer = new QTimer;
153 autoLockTimer = new QTimer; 153 autoLockTimer = new QTimer;
154 metaCheckTimer = new QTimer; 154 metaCheckTimer = new QTimer;
155 connect(mpwTimer, SIGNAL(timeout()), 155 connect(mpwTimer, SIGNAL(timeout()),
156 this, SLOT(mpwTimeout())); 156 this, SLOT(mpwTimeout()));
157 connect(autoLockTimer, SIGNAL(timeout()), 157 connect(autoLockTimer, SIGNAL(timeout()),
158 this, SLOT(autoLockTimeout())); 158 this, SLOT(autoLockTimeout()));
159 connect(metaCheckTimer, SIGNAL(timeout()), 159 connect(metaCheckTimer, SIGNAL(timeout()),
160 this, SLOT(metaCheckTimeout())); 160 this, SLOT(metaCheckTimeout()));
161} 161}
162 162
163DocTimer::~DocTimer() 163DocTimer::~DocTimer()
164{ 164{
165 delete mpwTimer; 165 delete mpwTimer;
166 delete autoLockTimer; 166 delete autoLockTimer;
167 delete metaCheckTimer; 167 delete metaCheckTimer;
168} 168}
169 169
170void DocTimer::start(TimerIDs timer) 170void DocTimer::start(TimerIDs timer)
171{ 171{
172 switch (timer) { 172 switch (timer) {
173 case id_mpwTimer: 173 case id_mpwTimer:
174 if (mpwTimer->isActive()) 174 if (mpwTimer->isActive())
175 mpwTimer->stop(); 175 mpwTimer->stop();
176 doc->setDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); 176 doc->setDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW);
177 mpwTimer->start(conf()->confGlobPwTimeout() * 1000, true); 177 mpwTimer->start(conf()->confGlobPwTimeout() * 1000, true);
178 break; 178 break;
179 case id_autoLockTimer: 179 case id_autoLockTimer:
180 if (autoLockTimer->isActive()) 180 if (autoLockTimer->isActive())
181 autoLockTimer->stop(); 181 autoLockTimer->stop();
182 if (conf()->confGlobLockTimeout() > 0) 182 if (conf()->confGlobLockTimeout() > 0)
183 autoLockTimer->start(conf()->confGlobLockTimeout() * 1000, true); 183 autoLockTimer->start(conf()->confGlobLockTimeout() * 1000, true);
184 break; 184 break;
185 case id_metaCheckTimer: 185 case id_metaCheckTimer:
186 if (metaCheckTimer->isActive()) 186 if (metaCheckTimer->isActive())
187 metaCheckTimer->stop(); 187 metaCheckTimer->stop();
188 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); 188 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true);
189 break; 189 break;
190 } 190 }
191} 191}
192 192
193void DocTimer::stop(TimerIDs timer) 193void DocTimer::stop(TimerIDs timer)
194{ 194{
195 switch (timer) { 195 switch (timer) {
196 case id_mpwTimer: 196 case id_mpwTimer:
197 mpwTimer->stop(); 197 mpwTimer->stop();
198 break; 198 break;
199 case id_autoLockTimer: 199 case id_autoLockTimer:
200 autoLockTimer->stop(); 200 autoLockTimer->stop();
201 break; 201 break;
202 case id_metaCheckTimer: 202 case id_metaCheckTimer:
203 metaCheckTimer->stop(); 203 metaCheckTimer->stop();
204 break; 204 break;
205 } 205 }
206} 206}
207 207
208void DocTimer::getLock(TimerIDs timer) 208void DocTimer::getLock(TimerIDs timer)
209{ 209{
210 switch (timer) { 210 switch (timer) {
211 case id_mpwTimer: 211 case id_mpwTimer:
212 ++mpwLock; 212 ++mpwLock;
213 break; 213 break;
214 case id_autoLockTimer: 214 case id_autoLockTimer:
215 ++autoLockLock; 215 ++autoLockLock;
216 break; 216 break;
217 case id_metaCheckTimer: 217 case id_metaCheckTimer:
218 ++metaCheckLock; 218 ++metaCheckLock;
219 break; 219 break;
220 } 220 }
221} 221}
222 222
223void DocTimer::putLock(TimerIDs timer) 223void DocTimer::putLock(TimerIDs timer)
224{ 224{
225 switch (timer) { 225 switch (timer) {
226 case id_mpwTimer: 226 case id_mpwTimer:
227 if (mpwLock) 227 if (mpwLock)
228 --mpwLock; 228 --mpwLock;
229 break; 229 break;
230 case id_autoLockTimer: 230 case id_autoLockTimer:
231 if (autoLockLock) 231 if (autoLockLock)
232 --autoLockLock; 232 --autoLockLock;
233 break; 233 break;
234 case id_metaCheckTimer: 234 case id_metaCheckTimer:
235 if (metaCheckLock) 235 if (metaCheckLock)
236 --metaCheckLock; 236 --metaCheckLock;
237 break; 237 break;
238 } 238 }
239} 239}
240 240
241void DocTimer::mpwTimeout() 241void DocTimer::mpwTimeout()
242{ 242{
243 if (mpwLock) { 243 if (mpwLock) {
244 mpwTimer->start(1000, true); 244 mpwTimer->start(1000, true);
245 return; 245 return;
246 } 246 }
247 doc->unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); 247 doc->unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW);
248} 248}
249 249
250void DocTimer::autoLockTimeout() 250void DocTimer::autoLockTimeout()
251{ 251{
252 if (autoLockLock) { 252 if (autoLockLock) {
253 autoLockTimer->start(1000, true); 253 autoLockTimer->start(1000, true);
254 return; 254 return;
255 } 255 }
256 if (conf()->confGlobAutoDeepLock() && 256 if (conf()->confGlobAutoDeepLock() &&
257 doc->filename != QString::null && 257 doc->filename != QString::null &&
258 doc->filename != "") { 258 doc->filename != "") {
259 doc->deepLock(true); 259 doc->deepLock(true);
260 } else { 260 } else {
261 doc->lockAll(true); 261 doc->lockAll(true);
262 } 262 }
263} 263}
264 264
265void DocTimer::metaCheckTimeout() 265void DocTimer::metaCheckTimeout()
266{ 266{
267 if (metaCheckLock) { 267 if (metaCheckLock) {
268 // check again in one second. 268 // check again in one second.
269 metaCheckTimer->start(1000, true); 269 metaCheckTimer->start(1000, true);
270 return; 270 return;
271 } 271 }
272 if (doc->isDeepLocked()) { 272 if (doc->isDeepLocked()) {
273 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); 273 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true);
274 return; 274 return;
275 } 275 }
276 if (doc->isDocEmpty()) { 276 if (doc->isDocEmpty()) {
277 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); 277 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true);
278 return; 278 return;
279 } 279 }
280#ifdef CONFIG_KWALLETIF 280#ifdef CONFIG_KWALLETIF
281 KWalletEmu *kwlEmu = doc->init->kwalletEmu(); 281 KWalletEmu *kwlEmu = doc->init->kwalletEmu();
282 if (kwlEmu) 282 if (kwlEmu)
283 kwlEmu->suspendDocSignals(); 283 kwlEmu->suspendDocSignals();
284#endif // CONFIG_KWALLETIF 284#endif // CONFIG_KWALLETIF
@@ -966,534 +966,536 @@ PwMerror PwMDoc::addEntry(const QString &category, PwMDataItem *d,
966 * But for now we only search in desc. 966 * But for now we only search in desc.
967 * That's a tweak to be KWallet compatible. But it should not add 967 * That's a tweak to be KWallet compatible. But it should not add
968 * usability-drop onto PwManager, does it? 968 * usability-drop onto PwManager, does it?
969 * (And yes, "int" was a bug. Correct is "unsigned int") 969 * (And yes, "int" was a bug. Correct is "unsigned int")
970 */ 970 */
971 const unsigned int searchIn = SEARCH_IN_DESC; 971 const unsigned int searchIn = SEARCH_IN_DESC;
972 findEntry(cat, *d, searchIn, &foundPositions, true); 972 findEntry(cat, *d, searchIn, &foundPositions, true);
973 if (foundPositions.size()) { 973 if (foundPositions.size()) {
974 // DOH! We found this entry. 974 // DOH! We found this entry.
975 return e_entryExists; 975 return e_entryExists;
976 } 976 }
977 977
978 d->listViewPos = -1; 978 d->listViewPos = -1;
979 d->lockStat = conf()->confGlobNewEntrLockStat(); 979 d->lockStat = conf()->confGlobNewEntrLockStat();
980 if (updateMeta) { 980 if (updateMeta) {
981 d->meta.create = QDateTime::currentDateTime(); 981 d->meta.create = QDateTime::currentDateTime();
982 d->meta.update = d->meta.create; 982 d->meta.update = d->meta.create;
983 } 983 }
984 dti.dta[cat].d.push_back(*d); 984 dti.dta[cat].d.push_back(*d);
985 985
986 delAllEmptyCat(true); 986 delAllEmptyCat(true);
987 987
988 if (!dontFlagDirty) 988 if (!dontFlagDirty)
989 flagDirty(); 989 flagDirty();
990 return e_success; 990 return e_success;
991} 991}
992 992
993PwMerror PwMDoc::addCategory(const QString &category, unsigned int *categoryIndex, 993PwMerror PwMDoc::addCategory(const QString &category, unsigned int *categoryIndex,
994 bool checkIfExist) 994 bool checkIfExist)
995{ 995{
996 if (isDeepLocked()) { 996 if (isDeepLocked()) {
997 PwMerror ret; 997 PwMerror ret;
998 ret = deepLock(false); 998 ret = deepLock(false);
999 if (ret != e_success) 999 if (ret != e_success)
1000 return e_lock; 1000 return e_lock;
1001 } 1001 }
1002 if (checkIfExist) { 1002 if (checkIfExist) {
1003 if (findCategory(category, categoryIndex)) 1003 if (findCategory(category, categoryIndex))
1004 return e_categoryExists; 1004 return e_categoryExists;
1005 } 1005 }
1006 PwMCategoryItem item; 1006 PwMCategoryItem item;
1007 item.name = category.latin1(); 1007 item.name = category.latin1();
1008 dti.dta.push_back(item); 1008 dti.dta.push_back(item);
1009 if (categoryIndex) 1009 if (categoryIndex)
1010 *categoryIndex = dti.dta.size() - 1; 1010 *categoryIndex = dti.dta.size() - 1;
1011 return e_success; 1011 return e_success;
1012} 1012}
1013 1013
1014bool PwMDoc::delEntry(const QString &category, unsigned int index, bool dontFlagDirty) 1014bool PwMDoc::delEntry(const QString &category, unsigned int index, bool dontFlagDirty)
1015{ 1015{
1016 unsigned int cat = 0; 1016 unsigned int cat = 0;
1017 1017
1018 if (!findCategory(category, &cat)) { 1018 if (!findCategory(category, &cat)) {
1019 BUG(); 1019 BUG();
1020 return false; 1020 return false;
1021 } 1021 }
1022 1022
1023 return delEntry(cat, index, dontFlagDirty); 1023 return delEntry(cat, index, dontFlagDirty);
1024} 1024}
1025 1025
1026bool PwMDoc::delEntry(unsigned int category, unsigned int index, bool dontFlagDirty) 1026bool PwMDoc::delEntry(unsigned int category, unsigned int index, bool dontFlagDirty)
1027{ 1027{
1028 if (isDeepLocked()) 1028 if (isDeepLocked())
1029 return false; 1029 return false;
1030 if (index > dti.dta[category].d.size() - 1) 1030 if (index > dti.dta[category].d.size() - 1)
1031 return false; 1031 return false;
1032 getDataChangedLock(); 1032 getDataChangedLock();
1033 if (!lockAt(category, index, false)) { 1033 if (!lockAt(category, index, false)) {
1034 putDataChangedLock(); 1034 putDataChangedLock();
1035 return false; 1035 return false;
1036 } 1036 }
1037 putDataChangedLock(); 1037 putDataChangedLock();
1038 int lvPos = dti.dta[category].d[index].listViewPos; 1038 int lvPos = dti.dta[category].d[index].listViewPos;
1039 1039
1040 // delete entry 1040 // delete entry
1041 dti.dta[category].d.erase(dti.dta[category].d.begin() + index); 1041 dti.dta[category].d.erase(dti.dta[category].d.begin() + index);
1042 1042
1043 unsigned int i, entries = numEntries(category); 1043 unsigned int i, entries = numEntries(category);
1044 if (!entries) { 1044 if (!entries) {
1045 // no more entries in this category, so 1045 // no more entries in this category, so
1046 // we can delete it, too. 1046 // we can delete it, too.
1047 BUG_ON(!delCategory(category)); 1047 BUG_ON(!delCategory(category));
1048 // delCategory() flags it dirty, so we need not to do so. 1048 // delCategory() flags it dirty, so we need not to do so.
1049 return true; 1049 return true;
1050 } 1050 }
1051 for (i = 0; i < entries; ++i) { 1051 for (i = 0; i < entries; ++i) {
1052 // decrement all listViewPositions that are greater than the deleted. 1052 // decrement all listViewPositions that are greater than the deleted.
1053 if (dti.dta[category].d[i].listViewPos > lvPos) 1053 if (dti.dta[category].d[i].listViewPos > lvPos)
1054 --dti.dta[category].d[i].listViewPos; 1054 --dti.dta[category].d[i].listViewPos;
1055 } 1055 }
1056 1056
1057 if (!dontFlagDirty) 1057 if (!dontFlagDirty)
1058 flagDirty(); 1058 flagDirty();
1059 return true; 1059 return true;
1060} 1060}
1061 1061
1062bool PwMDoc::editEntry(const QString &oldCategory, const QString &newCategory, 1062bool PwMDoc::editEntry(const QString &oldCategory, const QString &newCategory,
1063 unsigned int index, PwMDataItem *d, bool updateMeta) 1063 unsigned int index, PwMDataItem *d, bool updateMeta)
1064{ 1064{
1065 PWM_ASSERT(d); 1065 PWM_ASSERT(d);
1066 unsigned int oldCat = 0; 1066 unsigned int oldCat = 0;
1067 1067
1068 if (!findCategory(oldCategory, &oldCat)) { 1068 if (!findCategory(oldCategory, &oldCat)) {
1069 BUG(); 1069 BUG();
1070 return false; 1070 return false;
1071 } 1071 }
1072 1072
1073 return editEntry(oldCat, newCategory, index, d, updateMeta); 1073 return editEntry(oldCat, newCategory, index, d, updateMeta);
1074} 1074}
1075 1075
1076bool PwMDoc::editEntry(unsigned int oldCategory, const QString &newCategory, 1076bool PwMDoc::editEntry(unsigned int oldCategory, const QString &newCategory,
1077 unsigned int index, PwMDataItem *d, bool updateMeta) 1077 unsigned int index, PwMDataItem *d, bool updateMeta)
1078{ 1078{
1079 if (isDeepLocked()) 1079 if (isDeepLocked())
1080 return false; 1080 return false;
1081 if (updateMeta) { 1081 if (updateMeta) {
1082 d->meta.update = QDateTime::currentDateTime(); 1082 d->meta.update = QDateTime::currentDateTime();
1083 if (d->meta.create.isNull()) { 1083 if (d->meta.create.isNull()) {
1084 d->meta.create = d->meta.update; 1084 d->meta.create = d->meta.update;
1085 } 1085 }
1086 } 1086 }
1087 if (dti.dta[oldCategory].name != newCategory.latin1()) { 1087 if (dti.dta[oldCategory].name != newCategory.latin1()) {
1088 // the user changed the category. 1088 // the user changed the category.
1089 PwMerror ret; 1089 PwMerror ret;
1090 d->rev = 0; 1090 d->rev = 0;
1091 ret = addEntry(newCategory, d, true, false); 1091 ret = addEntry(newCategory, d, true, false);
1092 if (ret != e_success) 1092 if (ret != e_success)
1093 return false; 1093 return false;
1094 if (!delEntry(oldCategory, index, true)) 1094 if (!delEntry(oldCategory, index, true))
1095 return false; 1095 return false;
1096 } else { 1096 } else {
1097 d->rev = dti.dta[oldCategory].d[index].rev + 1; // increment revision counter. 1097 d->rev = dti.dta[oldCategory].d[index].rev + 1; // increment revision counter.
1098 dti.dta[oldCategory].d[index] = *d; 1098 dti.dta[oldCategory].d[index] = *d;
1099 } 1099 }
1100 flagDirty(); 1100 flagDirty();
1101 return true; 1101 return true;
1102} 1102}
1103 1103
1104unsigned int PwMDoc::numEntries(const QString &category) 1104unsigned int PwMDoc::numEntries(const QString &category)
1105{ 1105{
1106 unsigned int cat = 0; 1106 unsigned int cat = 0;
1107 1107
1108 if (!findCategory(category, &cat)) { 1108 if (!findCategory(category, &cat)) {
1109 BUG(); 1109 BUG();
1110 return 0; 1110 return 0;
1111 } 1111 }
1112 1112
1113 return numEntries(cat); 1113 return numEntries(cat);
1114} 1114}
1115 1115
1116bool PwMDoc::serializeDta(string *d) 1116bool PwMDoc::serializeDta(string *d)
1117{ 1117{
1118 PWM_ASSERT(d); 1118 PWM_ASSERT(d);
1119 Serializer ser; 1119 Serializer ser;
1120 if (!ser.serialize(dti)) 1120 if (!ser.serialize(dti))
1121 return false; 1121 return false;
1122 d->assign(ser.getXml()); 1122 d->assign(ser.getXml());
1123 if (!d->size()) 1123 if (!d->size())
1124 return false; 1124 return false;
1125 return true; 1125 return true;
1126} 1126}
1127 1127
1128bool PwMDoc::deSerializeDta(const string *d, bool entriesLocked) 1128bool PwMDoc::deSerializeDta(const string *d, bool entriesLocked)
1129{ 1129{
1130 PWM_ASSERT(d); 1130 PWM_ASSERT(d);
1131#ifndef PWM_EMBEDDED 1131#ifndef PWM_EMBEDDED
1132 try { 1132 try {
1133 1133
1134 Serializer ser(d->c_str()); 1134 Serializer ser(d->c_str());
1135 ser.setDefaultLockStat(entriesLocked); 1135 ser.setDefaultLockStat(entriesLocked);
1136 if (!ser.deSerialize(&dti)) 1136 if (!ser.deSerialize(&dti))
1137 return false; 1137 return false;
1138 } catch (PwMException) { 1138 } catch (PwMException) {
1139 return false; 1139 return false;
1140 } 1140 }
1141#else 1141#else
1142 Serializer ser(d->c_str()); 1142 Serializer ser(d->c_str());
1143 ser.setDefaultLockStat(entriesLocked); 1143 ser.setDefaultLockStat(entriesLocked);
1144 if (!ser.deSerialize(&dti)) 1144 if (!ser.deSerialize(&dti))
1145 return false; 1145 return false;
1146#endif 1146#endif
1147 1147
1148 emitDataChanged(this); 1148 emitDataChanged(this);
1149 return true; 1149 return true;
1150} 1150}
1151 1151
1152bool PwMDoc::getEntry(const QString &category, unsigned int index, 1152bool PwMDoc::getEntry(const QString &category, unsigned int index,
1153 PwMDataItem * d, bool unlockIfLocked) 1153 PwMDataItem * d, bool unlockIfLocked)
1154{ 1154{
1155 PWM_ASSERT(d); 1155 PWM_ASSERT(d);
1156 unsigned int cat = 0; 1156 unsigned int cat = 0;
1157 1157
1158 if (!findCategory(category, &cat)) { 1158 if (!findCategory(category, &cat)) {
1159 BUG(); 1159 BUG();
1160 return false; 1160 return false;
1161 } 1161 }
1162 1162
1163 return getEntry(cat, index, d, unlockIfLocked); 1163 return getEntry(cat, index, d, unlockIfLocked);
1164} 1164}
1165 1165
1166bool PwMDoc::getEntry(unsigned int category, unsigned int index, 1166bool PwMDoc::getEntry(unsigned int category, unsigned int index,
1167 PwMDataItem *d, bool unlockIfLocked) 1167 PwMDataItem *d, bool unlockIfLocked)
1168{ 1168{
1169 if (index > dti.dta[category].d.size() - 1) 1169 if (index > dti.dta[category].d.size() - 1)
1170 return false; 1170 return false;
1171 1171
1172 bool locked = isLocked(category, index); 1172 bool locked = isLocked(category, index);
1173 if (locked) { 1173 if (locked) {
1174 /* this entry is locked. We don't return a password, 1174 /* this entry is locked. We don't return a password,
1175 * until it's unlocked by the user by inserting 1175 * until it's unlocked by the user by inserting
1176 * chipcard or entering the mpw 1176 * chipcard or entering the mpw
1177 */ 1177 */
1178 if (unlockIfLocked) { 1178 if (unlockIfLocked) {
1179 if (!lockAt(category, index, false)) { 1179 if (!lockAt(category, index, false)) {
1180 return false; 1180 return false;
1181 } 1181 }
1182 locked = false; 1182 locked = false;
1183 } 1183 }
1184 } 1184 }
1185 1185
1186 *d = dti.dta[category].d[index]; 1186 *d = dti.dta[category].d[index];
1187 if (locked) 1187 if (locked)
1188 d->pw = LOCKED_STRING.latin1(); 1188 d->pw = LOCKED_STRING.latin1();
1189 1189
1190 return true; 1190 return true;
1191} 1191}
1192 1192
1193PwMerror PwMDoc::getCommentByLvp(const QString &category, int listViewPos, 1193PwMerror PwMDoc::getCommentByLvp(const QString &category, int listViewPos,
1194 string *foundComment) 1194 string *foundComment)
1195{ 1195{
1196 PWM_ASSERT(foundComment); 1196 PWM_ASSERT(foundComment);
1197 unsigned int cat = 0; 1197 unsigned int cat = 0;
1198 1198
1199 if (!findCategory(category, &cat)) 1199 if (!findCategory(category, &cat))
1200 return e_invalidArg; 1200 return e_invalidArg;
1201 1201
1202 unsigned int i, entries = numEntries(cat); 1202 unsigned int i, entries = numEntries(cat);
1203 for (i = 0; i < entries; ++i) { 1203 for (i = 0; i < entries; ++i) {
1204 if (dti.dta[cat].d[i].listViewPos == listViewPos) { 1204 if (dti.dta[cat].d[i].listViewPos == listViewPos) {
1205 *foundComment = dti.dta[cat].d[i].comment; 1205 *foundComment = dti.dta[cat].d[i].comment;
1206 if (dti.dta[cat].d[i].binary) 1206 if (dti.dta[cat].d[i].binary)
1207 return e_binEntry; 1207 return e_binEntry;
1208 return e_normalEntry; 1208 return e_normalEntry;
1209 } 1209 }
1210 } 1210 }
1211 BUG(); 1211 BUG();
1212 return e_generic; 1212 return e_generic;
1213} 1213}
1214 1214
1215bool PwMDoc::compressDta(string *d, char algo) 1215bool PwMDoc::compressDta(string *d, char algo)
1216{ 1216{
1217 PWM_ASSERT(d); 1217 PWM_ASSERT(d);
1218 switch (algo) { 1218 switch (algo) {
1219 case PWM_COMPRESS_GZIP: { 1219 case PWM_COMPRESS_GZIP: {
1220 CompressGzip comp; 1220 CompressGzip comp;
1221 return comp.compress(d); 1221 return comp.compress(d);
1222 } case PWM_COMPRESS_BZIP2: { 1222 /*US } case PWM_COMPRESS_BZIP2: {
1223 CompressBzip2 comp; 1223 CompressBzip2 comp;
1224 return comp.compress(d); 1224 return comp.compress(d);
1225*/
1225 } case PWM_COMPRESS_NONE: { 1226 } case PWM_COMPRESS_NONE: {
1226 return true; 1227 return true;
1227 } default: { 1228 } default: {
1228 BUG(); 1229 BUG();
1229 } 1230 }
1230 } 1231 }
1231 return false; 1232 return false;
1232} 1233}
1233 1234
1234bool PwMDoc::decompressDta(string *d, char algo) 1235bool PwMDoc::decompressDta(string *d, char algo)
1235{ 1236{
1236 PWM_ASSERT(d); 1237 PWM_ASSERT(d);
1237 switch (algo) { 1238 switch (algo) {
1238 case PWM_COMPRESS_GZIP: { 1239 case PWM_COMPRESS_GZIP: {
1239 CompressGzip comp; 1240 CompressGzip comp;
1240 return comp.decompress(d); 1241 return comp.decompress(d);
1241 } case PWM_COMPRESS_BZIP2: { 1242 /*US } case PWM_COMPRESS_BZIP2: {
1242 CompressBzip2 comp; 1243 CompressBzip2 comp;
1243 return comp.decompress(d); 1244 return comp.decompress(d);
1245 */
1244 } case PWM_COMPRESS_NONE: { 1246 } case PWM_COMPRESS_NONE: {
1245 return true; 1247 return true;
1246 } 1248 }
1247 } 1249 }
1248 return false; 1250 return false;
1249} 1251}
1250 1252
1251PwMerror PwMDoc::encrypt(string *d, const QString *pw, QFile *f, char algo) 1253PwMerror PwMDoc::encrypt(string *d, const QString *pw, QFile *f, char algo)
1252{ 1254{
1253 PWM_ASSERT(d); 1255 PWM_ASSERT(d);
1254 PWM_ASSERT(pw); 1256 PWM_ASSERT(pw);
1255 PWM_ASSERT(f); 1257 PWM_ASSERT(f);
1256 1258
1257 size_t encSize; 1259 size_t encSize;
1258 byte *encrypted = 0; 1260 byte *encrypted = 0;
1259 1261
1260 switch (algo) { 1262 switch (algo) {
1261 case PWM_CRYPT_BLOWFISH: { 1263 case PWM_CRYPT_BLOWFISH: {
1262 Blowfish::padNull(d); 1264 Blowfish::padNull(d);
1263 encSize = d->length(); 1265 encSize = d->length();
1264 encrypted = new byte[encSize]; 1266 encrypted = new byte[encSize];
1265 Blowfish bf; 1267 Blowfish bf;
1266 if (bf.bf_setkey((byte *) pw->latin1(), pw->length())) { 1268 if (bf.bf_setkey((byte *) pw->latin1(), pw->length())) {
1267 delete [] encrypted; 1269 delete [] encrypted;
1268 return e_weakPw; 1270 return e_weakPw;
1269 } 1271 }
1270 bf.bf_encrypt((byte *) encrypted, (byte *) d->c_str(), encSize); 1272 bf.bf_encrypt((byte *) encrypted, (byte *) d->c_str(), encSize);
1271 break; 1273 break;
1272 } 1274 }
1273 case PWM_CRYPT_AES128: 1275 case PWM_CRYPT_AES128:
1274 /*... fall through */ 1276 /*... fall through */
1275 case PWM_CRYPT_AES192: 1277 case PWM_CRYPT_AES192:
1276 case PWM_CRYPT_AES256: 1278 case PWM_CRYPT_AES256:
1277 case PWM_CRYPT_3DES: 1279 case PWM_CRYPT_3DES:
1278 case PWM_CRYPT_TWOFISH: 1280 case PWM_CRYPT_TWOFISH:
1279 case PWM_CRYPT_TWOFISH128: { 1281 case PWM_CRYPT_TWOFISH128: {
1280 if (!LibGCryptIf::available()) 1282 if (!LibGCryptIf::available())
1281 return e_cryptNotImpl; 1283 return e_cryptNotImpl;
1282 LibGCryptIf gc; 1284 LibGCryptIf gc;
1283 PwMerror err; 1285 PwMerror err;
1284 unsigned char *plain = new unsigned char[d->length() + 1024]; 1286 unsigned char *plain = new unsigned char[d->length() + 1024];
1285 memcpy(plain, d->c_str(), d->length()); 1287 memcpy(plain, d->c_str(), d->length());
1286 err = gc.encrypt(&encrypted, 1288 err = gc.encrypt(&encrypted,
1287 &encSize, 1289 &encSize,
1288 plain, 1290 plain,
1289 d->length(), 1291 d->length(),
1290 reinterpret_cast<const unsigned char *>(pw->latin1()), 1292 reinterpret_cast<const unsigned char *>(pw->latin1()),
1291 pw->length(), 1293 pw->length(),
1292 algo); 1294 algo);
1293 delete [] plain; 1295 delete [] plain;
1294 if (err != e_success) 1296 if (err != e_success)
1295 return e_cryptNotImpl; 1297 return e_cryptNotImpl;
1296 break; 1298 break;
1297 } 1299 }
1298 default: { 1300 default: {
1299 delete_ifnot_null_array(encrypted); 1301 delete_ifnot_null_array(encrypted);
1300 return e_cryptNotImpl; 1302 return e_cryptNotImpl;
1301 } } 1303 } }
1302 1304
1303 // write encrypted data to file 1305 // write encrypted data to file
1304 if (f->writeBlock(reinterpret_cast<const char *>(encrypted), 1306 if (f->writeBlock(reinterpret_cast<const char *>(encrypted),
1305 static_cast<Q_ULONG>(encSize)) 1307 static_cast<Q_ULONG>(encSize))
1306 != static_cast<Q_LONG>(encSize)) { 1308 != static_cast<Q_LONG>(encSize)) {
1307 delete_ifnot_null_array(encrypted); 1309 delete_ifnot_null_array(encrypted);
1308 return e_writeFile; 1310 return e_writeFile;
1309 } 1311 }
1310 delete_ifnot_null_array(encrypted); 1312 delete_ifnot_null_array(encrypted);
1311 return e_success; 1313 return e_success;
1312} 1314}
1313 1315
1314PwMerror PwMDoc::decrypt(string *d, unsigned int pos, const QString *pw, 1316PwMerror PwMDoc::decrypt(string *d, unsigned int pos, const QString *pw,
1315 char algo, QFile *f) 1317 char algo, QFile *f)
1316{ 1318{
1317 PWM_ASSERT(d); 1319 PWM_ASSERT(d);
1318 PWM_ASSERT(pw); 1320 PWM_ASSERT(pw);
1319 PWM_ASSERT(f); 1321 PWM_ASSERT(f);
1320 1322
1321 unsigned int cryptLen = f->size() - pos; 1323 unsigned int cryptLen = f->size() - pos;
1322 byte *encrypted = new byte[cryptLen]; 1324 byte *encrypted = new byte[cryptLen];
1323 byte *decrypted = new byte[cryptLen]; 1325 byte *decrypted = new byte[cryptLen];
1324 1326
1325 f->at(pos); 1327 f->at(pos);
1326#ifndef PWM_EMBEDDED 1328#ifndef PWM_EMBEDDED
1327 if (f->readBlock(reinterpret_cast<char *>(encrypted), 1329 if (f->readBlock(reinterpret_cast<char *>(encrypted),
1328 static_cast<Q_ULONG>(cryptLen)) 1330 static_cast<Q_ULONG>(cryptLen))
1329 != static_cast<Q_LONG>(cryptLen)) { 1331 != static_cast<Q_LONG>(cryptLen)) {
1330 delete [] encrypted; 1332 delete [] encrypted;
1331 delete [] decrypted; 1333 delete [] decrypted;
1332 return e_readFile; 1334 return e_readFile;
1333 } 1335 }
1334#else 1336#else
1335 if (f->readBlock((char *)(encrypted), 1337 if (f->readBlock((char *)(encrypted),
1336 (unsigned long)(cryptLen)) 1338 (unsigned long)(cryptLen))
1337 != (long)(cryptLen)) { 1339 != (long)(cryptLen)) {
1338 delete [] encrypted; 1340 delete [] encrypted;
1339 delete [] decrypted; 1341 delete [] decrypted;
1340 return e_readFile; 1342 return e_readFile;
1341 } 1343 }
1342#endif 1344#endif
1343 switch (algo) { 1345 switch (algo) {
1344 case PWM_CRYPT_BLOWFISH: { 1346 case PWM_CRYPT_BLOWFISH: {
1345 Blowfish bf; 1347 Blowfish bf;
1346 bf.bf_setkey((byte *) pw->latin1(), pw->length()); 1348 bf.bf_setkey((byte *) pw->latin1(), pw->length());
1347 bf.bf_decrypt(decrypted, encrypted, cryptLen); 1349 bf.bf_decrypt(decrypted, encrypted, cryptLen);
1348 break; 1350 break;
1349 } 1351 }
1350 case PWM_CRYPT_AES128: 1352 case PWM_CRYPT_AES128:
1351 /*... fall through */ 1353 /*... fall through */
1352 case PWM_CRYPT_AES192: 1354 case PWM_CRYPT_AES192:
1353 case PWM_CRYPT_AES256: 1355 case PWM_CRYPT_AES256:
1354 case PWM_CRYPT_3DES: 1356 case PWM_CRYPT_3DES:
1355 case PWM_CRYPT_TWOFISH: 1357 case PWM_CRYPT_TWOFISH:
1356 case PWM_CRYPT_TWOFISH128: { 1358 case PWM_CRYPT_TWOFISH128: {
1357 if (!LibGCryptIf::available()) 1359 if (!LibGCryptIf::available())
1358 return e_cryptNotImpl; 1360 return e_cryptNotImpl;
1359 LibGCryptIf gc; 1361 LibGCryptIf gc;
1360 PwMerror err; 1362 PwMerror err;
1361 err = gc.decrypt(&decrypted, 1363 err = gc.decrypt(&decrypted,
1362 &cryptLen, 1364 &cryptLen,
1363 encrypted, 1365 encrypted,
1364 cryptLen, 1366 cryptLen,
1365 reinterpret_cast<const unsigned char *>(pw->latin1()), 1367 reinterpret_cast<const unsigned char *>(pw->latin1()),
1366 pw->length(), 1368 pw->length(),
1367 algo); 1369 algo);
1368 if (err != e_success) { 1370 if (err != e_success) {
1369 delete [] encrypted; 1371 delete [] encrypted;
1370 delete [] decrypted; 1372 delete [] decrypted;
1371 return e_cryptNotImpl; 1373 return e_cryptNotImpl;
1372 } 1374 }
1373 break; 1375 break;
1374 } 1376 }
1375 default: { 1377 default: {
1376 delete [] encrypted; 1378 delete [] encrypted;
1377 delete [] decrypted; 1379 delete [] decrypted;
1378 return e_cryptNotImpl; 1380 return e_cryptNotImpl;
1379 } } 1381 } }
1380 delete [] encrypted; 1382 delete [] encrypted;
1381#ifndef PWM_EMBEDDED 1383#ifndef PWM_EMBEDDED
1382 d->assign(reinterpret_cast<const char *>(decrypted), 1384 d->assign(reinterpret_cast<const char *>(decrypted),
1383 static_cast<string::size_type>(cryptLen)); 1385 static_cast<string::size_type>(cryptLen));
1384#else 1386#else
1385 d->assign((const char *)(decrypted), 1387 d->assign((const char *)(decrypted),
1386 (string::size_type)(cryptLen)); 1388 (string::size_type)(cryptLen));
1387#endif 1389#endif
1388 delete [] decrypted; 1390 delete [] decrypted;
1389 if (algo == PWM_CRYPT_BLOWFISH) { 1391 if (algo == PWM_CRYPT_BLOWFISH) {
1390 if (!Blowfish::unpadNull(d)) { 1392 if (!Blowfish::unpadNull(d)) {
1391 BUG(); 1393 BUG();
1392 return e_readFile; 1394 return e_readFile;
1393 } 1395 }
1394 } 1396 }
1395 return e_success; 1397 return e_success;
1396} 1398}
1397 1399
1398PwMerror PwMDoc::checkDataHash(char dataHashType, const string *dataHash, 1400PwMerror PwMDoc::checkDataHash(char dataHashType, const string *dataHash,
1399 const string *dataStream) 1401 const string *dataStream)
1400{ 1402{
1401 PWM_ASSERT(dataHash); 1403 PWM_ASSERT(dataHash);
1402 PWM_ASSERT(dataStream); 1404 PWM_ASSERT(dataStream);
1403 switch(dataHashType) { 1405 switch(dataHashType) {
1404 case PWM_HASH_SHA1: { 1406 case PWM_HASH_SHA1: {
1405 Sha1 hash; 1407 Sha1 hash;
1406 hash.sha1_write((byte*)dataStream->c_str(), dataStream->length()); 1408 hash.sha1_write((byte*)dataStream->c_str(), dataStream->length());
1407 string ret = hash.sha1_read(); 1409 string ret = hash.sha1_read();
1408 if (ret != *dataHash) 1410 if (ret != *dataHash)
1409 return e_fileCorrupt; 1411 return e_fileCorrupt;
1410 break; 1412 break;
1411 } 1413 }
1412 case PWM_HASH_SHA256: 1414 case PWM_HASH_SHA256:
1413 /*... fall through */ 1415 /*... fall through */
1414 case PWM_HASH_SHA384: 1416 case PWM_HASH_SHA384:
1415 case PWM_HASH_SHA512: 1417 case PWM_HASH_SHA512:
1416 case PWM_HASH_MD5: 1418 case PWM_HASH_MD5:
1417 case PWM_HASH_RMD160: 1419 case PWM_HASH_RMD160:
1418 case PWM_HASH_TIGER: { 1420 case PWM_HASH_TIGER: {
1419 if (!LibGCryptIf::available()) 1421 if (!LibGCryptIf::available())
1420 return e_hashNotImpl; 1422 return e_hashNotImpl;
1421 LibGCryptIf gc; 1423 LibGCryptIf gc;
1422 PwMerror err; 1424 PwMerror err;
1423 unsigned char *buf; 1425 unsigned char *buf;
1424 size_t hashLen; 1426 size_t hashLen;
1425 err = gc.hash(&buf, 1427 err = gc.hash(&buf,
1426 &hashLen, 1428 &hashLen,
1427 reinterpret_cast<const unsigned char *>(dataStream->c_str()), 1429 reinterpret_cast<const unsigned char *>(dataStream->c_str()),
1428 dataStream->length(), 1430 dataStream->length(),
1429 dataHashType); 1431 dataHashType);
1430 if (err != e_success) 1432 if (err != e_success)
1431 return e_hashNotImpl; 1433 return e_hashNotImpl;
1432 string calcHash(reinterpret_cast<const char *>(buf), 1434 string calcHash(reinterpret_cast<const char *>(buf),
1433 static_cast<string::size_type>(hashLen)); 1435 static_cast<string::size_type>(hashLen));
1434 delete [] buf; 1436 delete [] buf;
1435 if (calcHash != *dataHash) 1437 if (calcHash != *dataHash)
1436 return e_fileCorrupt; 1438 return e_fileCorrupt;
1437 break; 1439 break;
1438 } 1440 }
1439 default: 1441 default:
1440 return e_hashNotImpl; 1442 return e_hashNotImpl;
1441 } 1443 }
1442 return e_success; 1444 return e_success;
1443} 1445}
1444 1446
1445bool PwMDoc::lockAt(unsigned int category, unsigned int index, 1447bool PwMDoc::lockAt(unsigned int category, unsigned int index,
1446 bool lock) 1448 bool lock)
1447{ 1449{
1448 if (index >= numEntries(category)) { 1450 if (index >= numEntries(category)) {
1449 BUG(); 1451 BUG();
1450 return false; 1452 return false;
1451 } 1453 }
1452 if (lock == dti.dta[category].d[index].lockStat) 1454 if (lock == dti.dta[category].d[index].lockStat)
1453 return true; 1455 return true;
1454 1456
1455 if (!lock && currentPw != "") { 1457 if (!lock && currentPw != "") {
1456 // "unlocking" and "password is already set" 1458 // "unlocking" and "password is already set"
1457 if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { 1459 if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) {
1458 // unlocking without pw not allowed 1460 // unlocking without pw not allowed
1459 QString pw; 1461 QString pw;
1460 pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); 1462 pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
1461 if (pw != "") { 1463 if (pw != "") {
1462 if (pw != currentPw) { 1464 if (pw != currentPw) {
1463 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); 1465 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
1464 return false; 1466 return false;
1465 } else { 1467 } else {
1466 timer()->start(DocTimer::id_mpwTimer); 1468 timer()->start(DocTimer::id_mpwTimer);
1467 } 1469 }
1468 } else { 1470 } else {
1469 return false; 1471 return false;
1470 } 1472 }
1471 } else { 1473 } else {
1472 timer()->start(DocTimer::id_mpwTimer); 1474 timer()->start(DocTimer::id_mpwTimer);
1473 } 1475 }
1474 } 1476 }
1475 1477
1476 dti.dta[category].d[index].lockStat = lock; 1478 dti.dta[category].d[index].lockStat = lock;
1477 dti.dta[category].d[index].rev++; // increment revision counter. 1479 dti.dta[category].d[index].rev++; // increment revision counter.
1478 1480
1479 emitDataChanged(this); 1481 emitDataChanged(this);
1480 if (!lock) 1482 if (!lock)
1481 timer()->start(DocTimer::id_autoLockTimer); 1483 timer()->start(DocTimer::id_autoLockTimer);
1482 1484
1483 return true; 1485 return true;
1484 1486
1485} 1487}
1486 1488
1487bool PwMDoc::lockAt(const QString &category,unsigned int index, 1489bool PwMDoc::lockAt(const QString &category,unsigned int index,
1488 bool lock) 1490 bool lock)
1489{ 1491{
1490 unsigned int cat = 0; 1492 unsigned int cat = 0;
1491 1493
1492 if (!findCategory(category, &cat)) { 1494 if (!findCategory(category, &cat)) {
1493 BUG(); 1495 BUG();
1494 return false; 1496 return false;
1495 } 1497 }
1496 1498
1497 return lockAt(cat, index, lock); 1499 return lockAt(cat, index, lock);
1498} 1500}
1499 1501