summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-06-24 23:41:53 (UTC)
committer zautrix <zautrix>2005-06-24 23:41:53 (UTC)
commit6a5f5375a9d2370db7d774b31d299acc81a77f89 (patch) (unidiff)
tree536ac03a132b166596cde3c3a99caa440a3fd609
parent184833db0d1bcb63e7d4bd5945ccdc0e6b92f7b8 (diff)
downloadkdepimpi-6a5f5375a9d2370db7d774b31d299acc81a77f89.zip
kdepimpi-6a5f5375a9d2370db7d774b31d299acc81a77f89.tar.gz
kdepimpi-6a5f5375a9d2370db7d774b31d299acc81a77f89.tar.bz2
fixxxx
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/pwmanager/pwmdoc.cpp2
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
@@ -343,193 +343,193 @@ PwMerror PwMDoc::saveDoc(char compress, const QString *file)
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 &currentPw, &f); 500 &currentPw, &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 }