author | zautrix <zautrix> | 2005-06-24 23:41:53 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-06-24 23:41:53 (UTC) |
commit | 6a5f5375a9d2370db7d774b31d299acc81a77f89 (patch) (unidiff) | |
tree | 536ac03a132b166596cde3c3a99caa440a3fd609 | |
parent | 184833db0d1bcb63e7d4bd5945ccdc0e6b92f7b8 (diff) | |
download | kdepimpi-6a5f5375a9d2370db7d774b31d299acc81a77f89.zip kdepimpi-6a5f5375a9d2370db7d774b31d299acc81a77f89.tar.gz kdepimpi-6a5f5375a9d2370db7d774b31d299acc81a77f89.tar.bz2 |
fixxxx
-rw-r--r-- | pwmanager/pwmanager/pwmdoc.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp index 36b0df5..1f3c58b 100644 --- a/pwmanager/pwmanager/pwmdoc.cpp +++ b/pwmanager/pwmanager/pwmdoc.cpp | |||
@@ -183,513 +183,513 @@ void DocTimer::start(TimerIDs timer) | |||
183 | case id_autoLockTimer: | 183 | case id_autoLockTimer: |
184 | if (autoLockTimer->isActive()) | 184 | if (autoLockTimer->isActive()) |
185 | autoLockTimer->stop(); | 185 | autoLockTimer->stop(); |
186 | if (conf()->confGlobLockTimeout() > 0) | 186 | if (conf()->confGlobLockTimeout() > 0) |
187 | autoLockTimer->start(conf()->confGlobLockTimeout() * 1000, true); | 187 | autoLockTimer->start(conf()->confGlobLockTimeout() * 1000, true); |
188 | break; | 188 | break; |
189 | case id_metaCheckTimer: | 189 | case id_metaCheckTimer: |
190 | if (metaCheckTimer->isActive()) | 190 | if (metaCheckTimer->isActive()) |
191 | metaCheckTimer->stop(); | 191 | metaCheckTimer->stop(); |
192 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); | 192 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); |
193 | break; | 193 | break; |
194 | } | 194 | } |
195 | } | 195 | } |
196 | 196 | ||
197 | void DocTimer::stop(TimerIDs timer) | 197 | void DocTimer::stop(TimerIDs timer) |
198 | { | 198 | { |
199 | switch (timer) { | 199 | switch (timer) { |
200 | case id_mpwTimer: | 200 | case id_mpwTimer: |
201 | mpwTimer->stop(); | 201 | mpwTimer->stop(); |
202 | break; | 202 | break; |
203 | case id_autoLockTimer: | 203 | case id_autoLockTimer: |
204 | autoLockTimer->stop(); | 204 | autoLockTimer->stop(); |
205 | break; | 205 | break; |
206 | case id_metaCheckTimer: | 206 | case id_metaCheckTimer: |
207 | metaCheckTimer->stop(); | 207 | metaCheckTimer->stop(); |
208 | break; | 208 | break; |
209 | } | 209 | } |
210 | } | 210 | } |
211 | 211 | ||
212 | void DocTimer::getLock(TimerIDs timer) | 212 | void DocTimer::getLock(TimerIDs timer) |
213 | { | 213 | { |
214 | switch (timer) { | 214 | switch (timer) { |
215 | case id_mpwTimer: | 215 | case id_mpwTimer: |
216 | ++mpwLock; | 216 | ++mpwLock; |
217 | break; | 217 | break; |
218 | case id_autoLockTimer: | 218 | case id_autoLockTimer: |
219 | ++autoLockLock; | 219 | ++autoLockLock; |
220 | break; | 220 | break; |
221 | case id_metaCheckTimer: | 221 | case id_metaCheckTimer: |
222 | ++metaCheckLock; | 222 | ++metaCheckLock; |
223 | break; | 223 | break; |
224 | } | 224 | } |
225 | } | 225 | } |
226 | 226 | ||
227 | void DocTimer::putLock(TimerIDs timer) | 227 | void DocTimer::putLock(TimerIDs timer) |
228 | { | 228 | { |
229 | switch (timer) { | 229 | switch (timer) { |
230 | case id_mpwTimer: | 230 | case id_mpwTimer: |
231 | if (mpwLock) | 231 | if (mpwLock) |
232 | --mpwLock; | 232 | --mpwLock; |
233 | break; | 233 | break; |
234 | case id_autoLockTimer: | 234 | case id_autoLockTimer: |
235 | if (autoLockLock) | 235 | if (autoLockLock) |
236 | --autoLockLock; | 236 | --autoLockLock; |
237 | break; | 237 | break; |
238 | case id_metaCheckTimer: | 238 | case id_metaCheckTimer: |
239 | if (metaCheckLock) | 239 | if (metaCheckLock) |
240 | --metaCheckLock; | 240 | --metaCheckLock; |
241 | break; | 241 | break; |
242 | } | 242 | } |
243 | } | 243 | } |
244 | 244 | ||
245 | void DocTimer::mpwTimeout() | 245 | void DocTimer::mpwTimeout() |
246 | { | 246 | { |
247 | if (mpwLock) { | 247 | if (mpwLock) { |
248 | mpwTimer->start(1000, true); | 248 | mpwTimer->start(1000, true); |
249 | return; | 249 | return; |
250 | } | 250 | } |
251 | doc->unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); | 251 | doc->unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); |
252 | } | 252 | } |
253 | 253 | ||
254 | void DocTimer::autoLockTimeout() | 254 | void DocTimer::autoLockTimeout() |
255 | { | 255 | { |
256 | if (autoLockLock) { | 256 | if (autoLockLock) { |
257 | autoLockTimer->start(1000, true); | 257 | autoLockTimer->start(1000, true); |
258 | return; | 258 | return; |
259 | } | 259 | } |
260 | if (conf()->confGlobAutoDeepLock() && | 260 | if (conf()->confGlobAutoDeepLock() && |
261 | doc->filename != QString::null && | 261 | doc->filename != QString::null && |
262 | doc->filename != "") { | 262 | doc->filename != "") { |
263 | doc->deepLock(true); | 263 | doc->deepLock(true); |
264 | } else { | 264 | } else { |
265 | doc->lockAll(true); | 265 | doc->lockAll(true); |
266 | } | 266 | } |
267 | } | 267 | } |
268 | 268 | ||
269 | void DocTimer::metaCheckTimeout() | 269 | void DocTimer::metaCheckTimeout() |
270 | { | 270 | { |
271 | if (metaCheckLock) { | 271 | if (metaCheckLock) { |
272 | // check again in one second. | 272 | // check again in one second. |
273 | metaCheckTimer->start(1000, true); | 273 | metaCheckTimer->start(1000, true); |
274 | return; | 274 | return; |
275 | } | 275 | } |
276 | if (doc->isDeepLocked()) { | 276 | if (doc->isDeepLocked()) { |
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 | if (doc->isDocEmpty()) { | 280 | if (doc->isDocEmpty()) { |
281 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); | 281 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); |
282 | return; | 282 | return; |
283 | } | 283 | } |
284 | #ifdef CONFIG_KWALLETIF | 284 | #ifdef CONFIG_KWALLETIF |
285 | KWalletEmu *kwlEmu = doc->init->kwalletEmu(); | 285 | KWalletEmu *kwlEmu = doc->init->kwalletEmu(); |
286 | if (kwlEmu) | 286 | if (kwlEmu) |
287 | kwlEmu->suspendDocSignals(); | 287 | kwlEmu->suspendDocSignals(); |
288 | #endif // CONFIG_KWALLETIF | 288 | #endif // CONFIG_KWALLETIF |
289 | /* We simply trigger all views to update their | 289 | /* We simply trigger all views to update their |
290 | * displayed values. This way they have a chance | 290 | * displayed values. This way they have a chance |
291 | * to get notified when some meta changes over time. | 291 | * to get notified when some meta changes over time. |
292 | * (for example an entry expired). | 292 | * (for example an entry expired). |
293 | * The _view_ is responsive for not updating its | 293 | * The _view_ is responsive for not updating its |
294 | * contents if nothing really changed! | 294 | * contents if nothing really changed! |
295 | */ | 295 | */ |
296 | emit doc->dataChanged(doc); | 296 | emit doc->dataChanged(doc); |
297 | #ifdef CONFIG_KWALLETIF | 297 | #ifdef CONFIG_KWALLETIF |
298 | if (kwlEmu) | 298 | if (kwlEmu) |
299 | kwlEmu->resumeDocSignals(); | 299 | kwlEmu->resumeDocSignals(); |
300 | #endif // CONFIG_KWALLETIF | 300 | #endif // CONFIG_KWALLETIF |
301 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); | 301 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); |
302 | } | 302 | } |
303 | 303 | ||
304 | 304 | ||
305 | 305 | ||
306 | PwMDocList PwMDoc::openDocList; | 306 | PwMDocList PwMDoc::openDocList; |
307 | unsigned int PwMDocList::unnamedDocCnt = 1; | 307 | unsigned int PwMDocList::unnamedDocCnt = 1; |
308 | 308 | ||
309 | PwMDoc::PwMDoc(QObject *parent, const char *name) | 309 | PwMDoc::PwMDoc(QObject *parent, const char *name) |
310 | : PwMDocUi(parent, name) | 310 | : PwMDocUi(parent, name) |
311 | , dataChangedLock (0) | 311 | , dataChangedLock (0) |
312 | { | 312 | { |
313 | deleted = false; | 313 | deleted = false; |
314 | unnamedNum = 0; | 314 | unnamedNum = 0; |
315 | getOpenDocList()->add(this, getTitle().latin1()); | 315 | getOpenDocList()->add(this, getTitle().latin1()); |
316 | curDocStat = 0; | 316 | curDocStat = 0; |
317 | setMaxNumEntries(); | 317 | setMaxNumEntries(); |
318 | _timer = new DocTimer(this); | 318 | _timer = new DocTimer(this); |
319 | timer()->start(DocTimer::id_mpwTimer); | 319 | timer()->start(DocTimer::id_mpwTimer); |
320 | timer()->start(DocTimer::id_autoLockTimer); | 320 | timer()->start(DocTimer::id_autoLockTimer); |
321 | timer()->start(DocTimer::id_metaCheckTimer); | 321 | timer()->start(DocTimer::id_metaCheckTimer); |
322 | addCategory(DEFAULT_CATEGORY, 0, false); | 322 | addCategory(DEFAULT_CATEGORY, 0, false); |
323 | listView = 0; | 323 | listView = 0; |
324 | emit docCreated(this); | 324 | emit docCreated(this); |
325 | } | 325 | } |
326 | 326 | ||
327 | PwMDoc::~PwMDoc() | 327 | PwMDoc::~PwMDoc() |
328 | { | 328 | { |
329 | emit docClosed(this); | 329 | emit docClosed(this); |
330 | getOpenDocList()->del(this); | 330 | getOpenDocList()->del(this); |
331 | delete _timer; | 331 | delete _timer; |
332 | } | 332 | } |
333 | 333 | ||
334 | PwMerror PwMDoc::saveDoc(char compress, const QString *file) | 334 | PwMerror PwMDoc::saveDoc(char compress, const QString *file) |
335 | { | 335 | { |
336 | PwMerror ret, e; | 336 | PwMerror ret, e; |
337 | string serialized; | 337 | string serialized; |
338 | QFile f; | 338 | QFile f; |
339 | QString tmpFileMoved(QString::null); | 339 | QString tmpFileMoved(QString::null); |
340 | bool wasDeepLocked; | 340 | bool wasDeepLocked; |
341 | QString savedFilename(filename); | 341 | QString savedFilename(filename); |
342 | 342 | ||
343 | if (!file) { | 343 | if (!file) { |
344 | if (filename == "") | 344 | if (filename == "") |
345 | return e_filename; | 345 | return e_filename; |
346 | if (isDeepLocked()) { | 346 | if (isDeepLocked()) { |
347 | /* We don't need to save any data. | 347 | /* We don't need to save any data. |
348 | * It's already all on disk, because | 348 | * It's already all on disk, because |
349 | * we are deeplocked. | 349 | * we are deeplocked. |
350 | */ | 350 | */ |
351 | unsetDocStatFlag(DOC_STAT_DISK_DIRTY); | 351 | unsetDocStatFlag(DOC_STAT_DISK_DIRTY); |
352 | ret = e_success; | 352 | ret = e_success; |
353 | return ret; | 353 | return ret; |
354 | } | 354 | } |
355 | } else { | 355 | } else { |
356 | if (*file == "" && filename == "") | 356 | if (*file == "" && filename == "") |
357 | return e_filename; | 357 | return e_filename; |
358 | if (*file != "") | 358 | if (*file != "") |
359 | filename = *file; | 359 | filename = *file; |
360 | } | 360 | } |
361 | 361 | ||
362 | wasDeepLocked = isDeepLocked(); | 362 | wasDeepLocked = isDeepLocked(); |
363 | if (wasDeepLocked) { | 363 | if (wasDeepLocked) { |
364 | /* We are deeplocked. That means all data is already | 364 | /* We are deeplocked. That means all data is already |
365 | * on disk. BUT we need to do saving procedure, | 365 | * on disk. BUT we need to do saving procedure, |
366 | * because *file != savedFilename. | 366 | * because *file != savedFilename. |
367 | * Additionally we need to tempoarly restore | 367 | * Additionally we need to tempoarly restore |
368 | * the old "filename", because deepLock() references it. | 368 | * the old "filename", because deepLock() references it. |
369 | */ | 369 | */ |
370 | QString newFilename(filename); | 370 | QString newFilename(filename); |
371 | filename = savedFilename; | 371 | filename = savedFilename; |
372 | getDataChangedLock(); | 372 | getDataChangedLock(); |
373 | e = deepLock(false); | 373 | e = deepLock(false); |
374 | putDataChangedLock(); | 374 | putDataChangedLock(); |
375 | filename = newFilename; | 375 | filename = newFilename; |
376 | switch (e) { | 376 | switch (e) { |
377 | case e_success: | 377 | case e_success: |
378 | break; | 378 | break; |
379 | case e_wrongPw: | 379 | case e_wrongPw: |
380 | case e_noPw: | 380 | case e_noPw: |
381 | emitDataChanged(this); | 381 | emitDataChanged(this); |
382 | return e; | 382 | return e; |
383 | default: | 383 | default: |
384 | emitDataChanged(this); | 384 | emitDataChanged(this); |
385 | return e_openFile; | 385 | return e_openFile; |
386 | } | 386 | } |
387 | } | 387 | } |
388 | 388 | ||
389 | if (!isPwAvailable()) { | 389 | if (!isPwAvailable()) { |
390 | /* password is not available. This means, the | 390 | /* password is not available. This means, the |
391 | * document wasn't saved, yet. | 391 | * document wasn't saved, yet. |
392 | */ | 392 | */ |
393 | bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD); | 393 | bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD); |
394 | QString pw(requestNewMpw(&useChipcard)); | 394 | QString pw(requestNewMpw(&useChipcard)); |
395 | if (pw != "") { | 395 | if (pw != "") { |
396 | currentPw = pw; | 396 | currentPw = pw; |
397 | } else { | 397 | } else { |
398 | return e_noPw; | 398 | return e_noPw; |
399 | } | 399 | } |
400 | if (useChipcard) { | 400 | if (useChipcard) { |
401 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); | 401 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); |
402 | } else { | 402 | } else { |
403 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); | 403 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); |
404 | } | 404 | } |
405 | } | 405 | } |
406 | 406 | ||
407 | int _cryptAlgo = conf()->confGlobCryptAlgo(); | 407 | int _cryptAlgo = conf()->confGlobCryptAlgo(); |
408 | int _hashAlgo = conf()->confGlobHashAlgo(); | 408 | int _hashAlgo = conf()->confGlobHashAlgo(); |
409 | 409 | ||
410 | // sanity check for the selected algorithms | 410 | // sanity check for the selected algorithms |
411 | if (_cryptAlgo < PWM_CRYPT_BLOWFISH || | 411 | if (_cryptAlgo < PWM_CRYPT_BLOWFISH || |
412 | _cryptAlgo > PWM_CRYPT_TWOFISH128) { | 412 | _cryptAlgo > PWM_CRYPT_TWOFISH128) { |
413 | printWarn("Invalid Crypto-Algorithm selected! " | 413 | printWarn("Invalid Crypto-Algorithm selected! " |
414 | "Config-file seems to be corrupt. " | 414 | "Config-file seems to be corrupt. " |
415 | "Falling back to Blowfish."); | 415 | "Falling back to Blowfish."); |
416 | _cryptAlgo = PWM_CRYPT_BLOWFISH; | 416 | _cryptAlgo = PWM_CRYPT_BLOWFISH; |
417 | } | 417 | } |
418 | if (_hashAlgo < PWM_HASH_SHA1 || | 418 | if (_hashAlgo < PWM_HASH_SHA1 || |
419 | _hashAlgo > PWM_HASH_TIGER) { | 419 | _hashAlgo > PWM_HASH_TIGER) { |
420 | printWarn("Invalid Hash-Algorithm selected! " | 420 | printWarn("Invalid Hash-Algorithm selected! " |
421 | "Config-file seems to be corrupt. " | 421 | "Config-file seems to be corrupt. " |
422 | "Falling back to SHA1."); | 422 | "Falling back to SHA1."); |
423 | _hashAlgo = PWM_HASH_SHA1; | 423 | _hashAlgo = PWM_HASH_SHA1; |
424 | } | 424 | } |
425 | char cryptAlgo = static_cast<char>(_cryptAlgo); | 425 | char cryptAlgo = static_cast<char>(_cryptAlgo); |
426 | char hashAlgo = static_cast<char>(_hashAlgo); | 426 | char hashAlgo = static_cast<char>(_hashAlgo); |
427 | 427 | ||
428 | if (conf()->confGlobMakeFileBackup()) { | 428 | if (conf()->confGlobMakeFileBackup()) { |
429 | if (!backupFile(filename)) | 429 | if (!backupFile(filename)) |
430 | return e_fileBackup; | 430 | return e_fileBackup; |
431 | } | 431 | } |
432 | int mLastBackupDate = 0; | 432 | int mLastBackupDate = 0; |
433 | KConfig configGlobal (locateLocal("config","pwmanagerbuprc")); | 433 | KConfig configGlobal (locateLocal("config","pwmanagerbuprc")); |
434 | QFileInfo fileInfo ( filename ); | 434 | QFileInfo fileInfo ( filename ); |
435 | mLastBackupDate = configGlobal.readNumEntry( "LastBackupDate-"+ fileInfo.fileName (), 0 ); | 435 | mLastBackupDate = configGlobal.readNumEntry( "LastBackupDate-"+ fileInfo.fileName (), 0 ); |
436 | KConfig config (locateLocal("config","microkdeglobalrc")); | 436 | KConfig config (locateLocal("config","microkdeglobalrc")); |
437 | config.setGroup( "BackupSettings" ); | 437 | config.setGroup( "BackupSettings" ); |
438 | bool b_enabled = config.readBoolEntry( "BackupEnabled" ); | 438 | bool b_enabled = config.readBoolEntry( "BackupEnabled" ); |
439 | if ( b_enabled ) { | 439 | if ( b_enabled && QFile::exists(filename)) { |
440 | int num = config.readNumEntry( "BackupNumbers" ); | 440 | int num = config.readNumEntry( "BackupNumbers" ); |
441 | int d_count = config.readNumEntry( "BackupDayCount" ); | 441 | int d_count = config.readNumEntry( "BackupDayCount" ); |
442 | bool stdDir = config.readBoolEntry( "BackupUseDefaultDir" ); | 442 | bool stdDir = config.readBoolEntry( "BackupUseDefaultDir" ); |
443 | QString bupDir = config.readEntry( "BackupDatadir" ); | 443 | QString bupDir = config.readEntry( "BackupDatadir" ); |
444 | QDate reference ( 2000,1,1 ); | 444 | QDate reference ( 2000,1,1 ); |
445 | int daysTo = reference.daysTo ( QDate::currentDate() ); | 445 | int daysTo = reference.daysTo ( QDate::currentDate() ); |
446 | bool saveDate = false; | 446 | bool saveDate = false; |
447 | if ( daysTo - d_count >= mLastBackupDate ) { | 447 | if ( daysTo - d_count >= mLastBackupDate ) { |
448 | qDebug("KA: Last backup was %d days ago ", daysTo - mLastBackupDate ); | 448 | qDebug("KA: Last backup was %d days ago ", daysTo - mLastBackupDate ); |
449 | if ( stdDir ) | 449 | if ( stdDir ) |
450 | bupDir = KGlobalSettings::backupDataDir(); | 450 | bupDir = KGlobalSettings::backupDataDir(); |
451 | int retval = KApplication::createBackup( filename, bupDir, num ); | 451 | int retval = KApplication::createBackup( filename, bupDir, num ); |
452 | if ( retval == 0 ) { | 452 | if ( retval == 0 ) { |
453 | qDebug("KO: Backup cancelled. Will try again tomorrow "); | 453 | qDebug("KO: Backup cancelled. Will try again tomorrow "); |
454 | // retval == 0 : backup skipped for today, try again tomorrow | 454 | // retval == 0 : backup skipped for today, try again tomorrow |
455 | mLastBackupDate = daysTo - d_count+1; | 455 | mLastBackupDate = daysTo - d_count+1; |
456 | saveDate = true; | 456 | saveDate = true; |
457 | } else if ( retval == 1 ){ | 457 | } else if ( retval == 1 ){ |
458 | qDebug("KO: Backup created."); | 458 | qDebug("KO: Backup created."); |
459 | // backup ok | 459 | // backup ok |
460 | mLastBackupDate = daysTo; | 460 | mLastBackupDate = daysTo; |
461 | saveDate = true; | 461 | saveDate = true; |
462 | } else if ( retval == 2 ){ | 462 | } else if ( retval == 2 ){ |
463 | qDebug("KO: Backup globally cancelled."); | 463 | qDebug("KO: Backup globally cancelled."); |
464 | // backup globally cancelled | 464 | // backup globally cancelled |
465 | b_enabled = false; | 465 | b_enabled = false; |
466 | } | 466 | } |
467 | if ( !b_enabled ) { | 467 | if ( !b_enabled ) { |
468 | config.writeEntry( "mBackupEnabled", false ); | 468 | config.writeEntry( "mBackupEnabled", false ); |
469 | } | 469 | } |
470 | if ( saveDate ) { | 470 | if ( saveDate ) { |
471 | configGlobal.writeEntry( "LastBackupDate-"+ fileInfo.fileName (), mLastBackupDate ); | 471 | configGlobal.writeEntry( "LastBackupDate-"+ fileInfo.fileName (), mLastBackupDate ); |
472 | } | 472 | } |
473 | } | 473 | } |
474 | } | 474 | } |
475 | if (QFile::exists(filename)) { | 475 | if (QFile::exists(filename)) { |
476 | /* Move the existing file to some tmp file. | 476 | /* Move the existing file to some tmp file. |
477 | * When saving file succeeds, delete tmp file. Otherwise | 477 | * When saving file succeeds, delete tmp file. Otherwise |
478 | * move tmp file back. See below. | 478 | * move tmp file back. See below. |
479 | */ | 479 | */ |
480 | Randomizer *rnd = Randomizer::obj(); | 480 | Randomizer *rnd = Randomizer::obj(); |
481 | char rnd_buf[5]; | 481 | char rnd_buf[5]; |
482 | sprintf(rnd_buf, "%X%X%X%X", rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF, | 482 | sprintf(rnd_buf, "%X%X%X%X", rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF, |
483 | rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF); | 483 | rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF); |
484 | tmpFileMoved = filename + "." + rnd_buf + ".mv"; | 484 | tmpFileMoved = filename + "." + rnd_buf + ".mv"; |
485 | if (!copyFile(filename, tmpFileMoved)) | 485 | if (!copyFile(filename, tmpFileMoved)) |
486 | return e_openFile; | 486 | return e_openFile; |
487 | if (!QFile::remove(filename)) { | 487 | if (!QFile::remove(filename)) { |
488 | printWarn(string("removing orig file ") | 488 | printWarn(string("removing orig file ") |
489 | + filename.latin1() | 489 | + filename.latin1() |
490 | + " failed!"); | 490 | + " failed!"); |
491 | } | 491 | } |
492 | } | 492 | } |
493 | f.setName(filename); | 493 | f.setName(filename); |
494 | if (!f.open(IO_ReadWrite)) { | 494 | if (!f.open(IO_ReadWrite)) { |
495 | ret = e_openFile; | 495 | ret = e_openFile; |
496 | goto out_moveback; | 496 | goto out_moveback; |
497 | } | 497 | } |
498 | e = writeFileHeader(hashAlgo, hashAlgo, | 498 | e = writeFileHeader(hashAlgo, hashAlgo, |
499 | cryptAlgo, compress, | 499 | cryptAlgo, compress, |
500 | ¤tPw, &f); | 500 | ¤tPw, &f); |
501 | if (e == e_hashNotImpl) { | 501 | if (e == e_hashNotImpl) { |
502 | printDebug("PwMDoc::saveDoc(): writeFileHeader() failed: e_hashNotImpl"); | 502 | printDebug("PwMDoc::saveDoc(): writeFileHeader() failed: e_hashNotImpl"); |
503 | f.close(); | 503 | f.close(); |
504 | ret = e_hashNotImpl; | 504 | ret = e_hashNotImpl; |
505 | goto out_moveback; | 505 | goto out_moveback; |
506 | } else if (e != e_success) { | 506 | } else if (e != e_success) { |
507 | printDebug("PwMDoc::saveDoc(): writeFileHeader() failed"); | 507 | printDebug("PwMDoc::saveDoc(): writeFileHeader() failed"); |
508 | f.close(); | 508 | f.close(); |
509 | ret = e_writeHeader; | 509 | ret = e_writeHeader; |
510 | goto out_moveback; | 510 | goto out_moveback; |
511 | } | 511 | } |
512 | if (!serializeDta(&serialized)) { | 512 | if (!serializeDta(&serialized)) { |
513 | printDebug("PwMDoc::saveDoc(): serializeDta() failed"); | 513 | printDebug("PwMDoc::saveDoc(): serializeDta() failed"); |
514 | f.close(); | 514 | f.close(); |
515 | ret = e_serializeDta; | 515 | ret = e_serializeDta; |
516 | goto out_moveback; | 516 | goto out_moveback; |
517 | } | 517 | } |
518 | e = writeDataHash(hashAlgo, &serialized, &f); | 518 | e = writeDataHash(hashAlgo, &serialized, &f); |
519 | if (e == e_hashNotImpl) { | 519 | if (e == e_hashNotImpl) { |
520 | printDebug("PwMDoc::saveDoc(): writeDataHash() failed: e_hashNotImpl"); | 520 | printDebug("PwMDoc::saveDoc(): writeDataHash() failed: e_hashNotImpl"); |
521 | f.close(); | 521 | f.close(); |
522 | ret = e_hashNotImpl; | 522 | ret = e_hashNotImpl; |
523 | goto out_moveback; | 523 | goto out_moveback; |
524 | } else if (e != e_success) { | 524 | } else if (e != e_success) { |
525 | printDebug("PwMDoc::saveDoc(): writeDataHash() failed"); | 525 | printDebug("PwMDoc::saveDoc(): writeDataHash() failed"); |
526 | f.close(); | 526 | f.close(); |
527 | ret = e_writeHeader; | 527 | ret = e_writeHeader; |
528 | goto out_moveback; | 528 | goto out_moveback; |
529 | } | 529 | } |
530 | if (!compressDta(&serialized, compress)) { | 530 | if (!compressDta(&serialized, compress)) { |
531 | printDebug("PwMDoc::saveDoc(): compressDta() failed"); | 531 | printDebug("PwMDoc::saveDoc(): compressDta() failed"); |
532 | f.close(); | 532 | f.close(); |
533 | ret = e_enc; | 533 | ret = e_enc; |
534 | goto out_moveback; | 534 | goto out_moveback; |
535 | } | 535 | } |
536 | e = encrypt(&serialized, ¤tPw, &f, cryptAlgo, hashAlgo); | 536 | e = encrypt(&serialized, ¤tPw, &f, cryptAlgo, hashAlgo); |
537 | if (e == e_weakPw) { | 537 | if (e == e_weakPw) { |
538 | printDebug("PwMDoc::saveDoc(): encrypt() failed: e_weakPw"); | 538 | printDebug("PwMDoc::saveDoc(): encrypt() failed: e_weakPw"); |
539 | f.close(); | 539 | f.close(); |
540 | ret = e_weakPw; | 540 | ret = e_weakPw; |
541 | goto out_moveback; | 541 | goto out_moveback; |
542 | } else if (e == e_cryptNotImpl) { | 542 | } else if (e == e_cryptNotImpl) { |
543 | printDebug("PwMDoc::saveDoc(): encrypt() failed: e_cryptNotImpl"); | 543 | printDebug("PwMDoc::saveDoc(): encrypt() failed: e_cryptNotImpl"); |
544 | f.close(); | 544 | f.close(); |
545 | ret = e_cryptNotImpl; | 545 | ret = e_cryptNotImpl; |
546 | goto out_moveback; | 546 | goto out_moveback; |
547 | } else if (e != e_success) { | 547 | } else if (e != e_success) { |
548 | printDebug("PwMDoc::saveDoc(): encrypt() failed"); | 548 | printDebug("PwMDoc::saveDoc(): encrypt() failed"); |
549 | f.close(); | 549 | f.close(); |
550 | ret = e_enc; | 550 | ret = e_enc; |
551 | goto out_moveback; | 551 | goto out_moveback; |
552 | } | 552 | } |
553 | unsetDocStatFlag(DOC_STAT_DISK_DIRTY); | 553 | unsetDocStatFlag(DOC_STAT_DISK_DIRTY); |
554 | f.close(); | 554 | f.close(); |
555 | #ifndef _WIN32_ | 555 | #ifndef _WIN32_ |
556 | if (chmod(filename.latin1(), | 556 | if (chmod(filename.latin1(), |
557 | conf()->confGlobFilePermissions())) { | 557 | conf()->confGlobFilePermissions())) { |
558 | printWarn(string("chmod failed: ") + strerror(errno)); | 558 | printWarn(string("chmod failed: ") + strerror(errno)); |
559 | } | 559 | } |
560 | #endif | 560 | #endif |
561 | openDocList.edit(this, getTitle().latin1()); | 561 | openDocList.edit(this, getTitle().latin1()); |
562 | if (wasDeepLocked) { | 562 | if (wasDeepLocked) { |
563 | /* Do _not_ save the data with the deepLock() | 563 | /* Do _not_ save the data with the deepLock() |
564 | * call, because this will recurse | 564 | * call, because this will recurse |
565 | * into saveDoc() | 565 | * into saveDoc() |
566 | */ | 566 | */ |
567 | deepLock(true, false); | 567 | deepLock(true, false); |
568 | /* We don't check return value here, because | 568 | /* We don't check return value here, because |
569 | * it won't fail. See NOTE in deepLock() | 569 | * it won't fail. See NOTE in deepLock() |
570 | */ | 570 | */ |
571 | } | 571 | } |
572 | if (tmpFileMoved != QString::null) { | 572 | if (tmpFileMoved != QString::null) { |
573 | // now remove the moved file. | 573 | // now remove the moved file. |
574 | if (!QFile::remove(tmpFileMoved)) { | 574 | if (!QFile::remove(tmpFileMoved)) { |
575 | printWarn(string("removing file ") | 575 | printWarn(string("removing file ") |
576 | + tmpFileMoved.latin1() | 576 | + tmpFileMoved.latin1() |
577 | + " failed!"); | 577 | + " failed!"); |
578 | } | 578 | } |
579 | } | 579 | } |
580 | ret = e_success; | 580 | ret = e_success; |
581 | printDebug(string("writing file { name: ") | 581 | printDebug(string("writing file { name: ") |
582 | + filename.latin1() + " compress: " | 582 | + filename.latin1() + " compress: " |
583 | + tostr(static_cast<int>(compress)) + " cryptAlgo: " | 583 | + tostr(static_cast<int>(compress)) + " cryptAlgo: " |
584 | + tostr(static_cast<int>(cryptAlgo)) + " hashAlgo: " | 584 | + tostr(static_cast<int>(cryptAlgo)) + " hashAlgo: " |
585 | + tostr(static_cast<int>(hashAlgo)) | 585 | + tostr(static_cast<int>(hashAlgo)) |
586 | + " }"); | 586 | + " }"); |
587 | goto out; | 587 | goto out; |
588 | out_moveback: | 588 | out_moveback: |
589 | if (tmpFileMoved != QString::null) { | 589 | if (tmpFileMoved != QString::null) { |
590 | if (copyFile(tmpFileMoved, filename)) { | 590 | if (copyFile(tmpFileMoved, filename)) { |
591 | if (!QFile::remove(tmpFileMoved)) { | 591 | if (!QFile::remove(tmpFileMoved)) { |
592 | printWarn(string("removing tmp file ") | 592 | printWarn(string("removing tmp file ") |
593 | + filename.latin1() | 593 | + filename.latin1() |
594 | + " failed!"); | 594 | + " failed!"); |
595 | } | 595 | } |
596 | } else { | 596 | } else { |
597 | printWarn(string("couldn't copy file ") | 597 | printWarn(string("couldn't copy file ") |
598 | + tmpFileMoved.latin1() | 598 | + tmpFileMoved.latin1() |
599 | + " back to " | 599 | + " back to " |
600 | + filename.latin1()); | 600 | + filename.latin1()); |
601 | } | 601 | } |
602 | } | 602 | } |
603 | out: | 603 | out: |
604 | return ret; | 604 | return ret; |
605 | } | 605 | } |
606 | 606 | ||
607 | PwMerror PwMDoc::openDoc(const QString *file, int openLocked) | 607 | PwMerror PwMDoc::openDoc(const QString *file, int openLocked) |
608 | { | 608 | { |
609 | PWM_ASSERT(file); | 609 | PWM_ASSERT(file); |
610 | PWM_ASSERT(openLocked == 0 || openLocked == 1 || openLocked == 2); | 610 | PWM_ASSERT(openLocked == 0 || openLocked == 1 || openLocked == 2); |
611 | string decrypted, dataHash; | 611 | string decrypted, dataHash; |
612 | PwMerror ret; | 612 | PwMerror ret; |
613 | char cryptAlgo, dataHashType, compress; | 613 | char cryptAlgo, dataHashType, compress; |
614 | unsigned int headerLen; | 614 | unsigned int headerLen; |
615 | 615 | ||
616 | if (*file == "") | 616 | if (*file == "") |
617 | return e_readFile; | 617 | return e_readFile; |
618 | filename = *file; | 618 | filename = *file; |
619 | /* check if this file is already open. | 619 | /* check if this file is already open. |
620 | * This does not catch symlinks! | 620 | * This does not catch symlinks! |
621 | */ | 621 | */ |
622 | if (!isDeepLocked()) { | 622 | if (!isDeepLocked()) { |
623 | if (getOpenDocList()->find(filename.latin1())) | 623 | if (getOpenDocList()->find(filename.latin1())) |
624 | return e_alreadyOpen; | 624 | return e_alreadyOpen; |
625 | } | 625 | } |
626 | QFile f(filename); | 626 | QFile f(filename); |
627 | 627 | ||
628 | if (openLocked == 2) { | 628 | if (openLocked == 2) { |
629 | // open deep-locked | 629 | // open deep-locked |
630 | if (!QFile::exists(filename)) | 630 | if (!QFile::exists(filename)) |
631 | return e_openFile; | 631 | return e_openFile; |
632 | if (deepLock(true, false) != e_success) | 632 | if (deepLock(true, false) != e_success) |
633 | return e_openFile; | 633 | return e_openFile; |
634 | goto out_success; | 634 | goto out_success; |
635 | } | 635 | } |
636 | 636 | ||
637 | if (!f.open(IO_ReadOnly)) | 637 | if (!f.open(IO_ReadOnly)) |
638 | return e_openFile; | 638 | return e_openFile; |
639 | 639 | ||
640 | ret = checkHeader(&cryptAlgo, ¤tPw, &compress, &headerLen, | 640 | ret = checkHeader(&cryptAlgo, ¤tPw, &compress, &headerLen, |
641 | &dataHashType, &dataHash, &f); | 641 | &dataHashType, &dataHash, &f); |
642 | if (ret != e_success) { | 642 | if (ret != e_success) { |
643 | printDebug("PwMDoc::openDoc(): checkHeader() failed"); | 643 | printDebug("PwMDoc::openDoc(): checkHeader() failed"); |
644 | f.close(); | 644 | f.close(); |
645 | if (ret == e_wrongPw) { | 645 | if (ret == e_wrongPw) { |
646 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 646 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
647 | return ret; | 647 | return ret; |
648 | } else if (ret == e_noPw || | 648 | } else if (ret == e_noPw || |
649 | ret == e_fileVer || | 649 | ret == e_fileVer || |
650 | ret == e_fileFormat || | 650 | ret == e_fileFormat || |
651 | ret == e_hashNotImpl) { | 651 | ret == e_hashNotImpl) { |
652 | return ret; | 652 | return ret; |
653 | } else | 653 | } else |
654 | return e_readFile; | 654 | return e_readFile; |
655 | } | 655 | } |
656 | ret = decrypt(&decrypted, headerLen, ¤tPw, cryptAlgo, dataHashType, &f); | 656 | ret = decrypt(&decrypted, headerLen, ¤tPw, cryptAlgo, dataHashType, &f); |
657 | if (ret == e_cryptNotImpl) { | 657 | if (ret == e_cryptNotImpl) { |
658 | printDebug("PwMDoc::openDoc(): decrypt() failed: e_cryptNotImpl"); | 658 | printDebug("PwMDoc::openDoc(): decrypt() failed: e_cryptNotImpl"); |
659 | f.close(); | 659 | f.close(); |
660 | return e_cryptNotImpl; | 660 | return e_cryptNotImpl; |
661 | } else if (ret != e_success) { | 661 | } else if (ret != e_success) { |
662 | printDebug("PwMDoc::openDoc(): decrypt() failed"); | 662 | printDebug("PwMDoc::openDoc(): decrypt() failed"); |
663 | f.close(); | 663 | f.close(); |
664 | return e_readFile; | 664 | return e_readFile; |
665 | } | 665 | } |
666 | if (!decompressDta(&decrypted, compress)) { | 666 | if (!decompressDta(&decrypted, compress)) { |
667 | printDebug("PwMDoc::openDoc(): decompressDta() failed"); | 667 | printDebug("PwMDoc::openDoc(): decompressDta() failed"); |
668 | f.close(); | 668 | f.close(); |
669 | return e_fileCorrupt; | 669 | return e_fileCorrupt; |
670 | } | 670 | } |
671 | ret = checkDataHash(dataHashType, &dataHash, &decrypted); | 671 | ret = checkDataHash(dataHashType, &dataHash, &decrypted); |
672 | if (ret == e_hashNotImpl) { | 672 | if (ret == e_hashNotImpl) { |
673 | printDebug("PwMDoc::openDoc(): checkDataHash() failed: e_hashNotImpl"); | 673 | printDebug("PwMDoc::openDoc(): checkDataHash() failed: e_hashNotImpl"); |
674 | f.close(); | 674 | f.close(); |
675 | return e_hashNotImpl; | 675 | return e_hashNotImpl; |
676 | } else if (ret != e_success) { | 676 | } else if (ret != e_success) { |
677 | printDebug("PwMDoc::openDoc(): checkDataHash() failed"); | 677 | printDebug("PwMDoc::openDoc(): checkDataHash() failed"); |
678 | f.close(); | 678 | f.close(); |
679 | return e_fileCorrupt; | 679 | return e_fileCorrupt; |
680 | } | 680 | } |
681 | if (!deSerializeDta(&decrypted, openLocked == 1)) { | 681 | if (!deSerializeDta(&decrypted, openLocked == 1)) { |
682 | printDebug("PwMDoc::openDoc(): deSerializeDta() failed"); | 682 | printDebug("PwMDoc::openDoc(): deSerializeDta() failed"); |
683 | f.close(); | 683 | f.close(); |
684 | return e_readFile; | 684 | return e_readFile; |
685 | } | 685 | } |
686 | f.close(); | 686 | f.close(); |
687 | timer()->start(DocTimer::id_mpwTimer); | 687 | timer()->start(DocTimer::id_mpwTimer); |
688 | timer()->start(DocTimer::id_autoLockTimer); | 688 | timer()->start(DocTimer::id_autoLockTimer); |
689 | out_success: | 689 | out_success: |
690 | openDocList.edit(this, getTitle().latin1()); | 690 | openDocList.edit(this, getTitle().latin1()); |
691 | emit docOpened(this); | 691 | emit docOpened(this); |
692 | return e_success; | 692 | return e_success; |
693 | } | 693 | } |
694 | 694 | ||
695 | PwMerror PwMDoc::writeFileHeader(char keyHash, char dataHash, char crypt, char compress, | 695 | PwMerror PwMDoc::writeFileHeader(char keyHash, char dataHash, char crypt, char compress, |