summaryrefslogtreecommitdiffabout
path: root/pwmanager/pwmanager/pwmdoc.cpp
Side-by-side diff
Diffstat (limited to 'pwmanager/pwmanager/pwmdoc.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/pwmanager/pwmdoc.cpp26
1 files changed, 14 insertions, 12 deletions
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp
index b58d7e2..9213360 100644
--- a/pwmanager/pwmanager/pwmdoc.cpp
+++ b/pwmanager/pwmanager/pwmdoc.cpp
@@ -39,24 +39,25 @@
#include <kglobalsettings.h>
#include <libkcal/syncdefines.h>
#ifdef CONFIG_KWALLETIF
# include "kwalletemu.h"
#endif // CONFIG_KWALLETIF
#include <qdatetime.h>
#include <qsize.h>
#include <qfileinfo.h>
#include <qfile.h>
+#include <QDesktopWidget>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
//US#include <iostream>
#include <algorithm>
#include <sys/types.h>
#include <sys/stat.h>
#ifndef _WIN32_
#include <unistd.h>
#include <stdint.h>
@@ -472,35 +473,36 @@ PwMerror PwMDoc::saveDoc(char compress, const QString *file)
}
}
}
if (QFile::exists(filename)) {
/* Move the existing file to some tmp file.
* When saving file succeeds, delete tmp file. Otherwise
* move tmp file back. See below.
*/
Randomizer *rnd = Randomizer::obj();
char rnd_buf[5];
sprintf(rnd_buf, "%X%X%X%X", rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF,
rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF);
- tmpFileMoved = filename + "." + rnd_buf + ".mv";
+ tmpFileMoved = filename; tmpFileMoved += '.';
+ tmpFileMoved += rnd_buf; tmpFileMoved += ".mv";
if (!copyFile(filename, tmpFileMoved))
return e_openFile;
if (!QFile::remove(filename)) {
printWarn(string("removing orig file ")
+ filename.latin1()
+ " failed!");
}
}
f.setName(filename);
- if (!f.open(IO_ReadWrite)) {
+ if (!f.open(QIODevice::ReadWrite)) {
ret = e_openFile;
goto out_moveback;
}
e = writeFileHeader(hashAlgo, hashAlgo,
cryptAlgo, compress,
&currentPw, &f);
if (e == e_hashNotImpl) {
printDebug("PwMDoc::saveDoc(): writeFileHeader() failed: e_hashNotImpl");
f.close();
ret = e_hashNotImpl;
goto out_moveback;
} else if (e != e_success) {
@@ -625,25 +627,25 @@ PwMerror PwMDoc::openDoc(const QString *file, int openLocked)
}
QFile f(filename);
if (openLocked == 2) {
// open deep-locked
if (!QFile::exists(filename))
return e_openFile;
if (deepLock(true, false) != e_success)
return e_openFile;
goto out_success;
}
- if (!f.open(IO_ReadOnly))
+ if (!f.open(QIODevice::ReadOnly))
return e_openFile;
ret = checkHeader(&cryptAlgo, &currentPw, &compress, &headerLen,
&dataHashType, &dataHash, &f);
if (ret != e_success) {
printDebug("PwMDoc::openDoc(): checkHeader() failed");
f.close();
if (ret == e_wrongPw) {
wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
return ret;
} else if (ret == e_noPw ||
ret == e_fileVer ||
@@ -994,28 +996,28 @@ bool PwMDoc::backupFile(const QString &filePath)
}
bool PwMDoc::copyFile(const QString &src, const QString &dst)
{
QFileInfo fi(src);
if (!fi.exists())
return false;
if (QFile::exists(dst)) {
if (!QFile::remove(dst))
return false;
}
QFile srcFd(src);
- if (!srcFd.open(IO_ReadOnly))
+ if (!srcFd.open(QIODevice::ReadOnly))
return false;
QFile dstFd(dst);
- if (!dstFd.open(IO_ReadWrite)) {
+ if (!dstFd.open(QIODevice::ReadWrite)) {
srcFd.close();
return false;
}
const int tmpBuf_size = 512;
char tmpBuf[tmpBuf_size];
Q_LONG bytesRead, bytesWritten;
while (!srcFd.atEnd()) {
bytesRead = srcFd.readBlock(tmpBuf,
static_cast<Q_ULONG>(tmpBuf_size));
if (bytesRead == -1) {
srcFd.close();
@@ -1476,25 +1478,25 @@ PwMerror PwMDoc::encrypt(string *d, const QString *pw, QFile *f, char algo,
return e_success;
}
PwMerror PwMDoc::decrypt(string *d, unsigned int pos, const QString *pw,
char algo,
char hashalgo, //US BUG: pass _hashalgo because we need it in hashPassphrase
QFile *f)
{
PWM_ASSERT(d);
PWM_ASSERT(pw);
PWM_ASSERT(f);
- unsigned int cryptLen = f->size() - pos;
+ size_t cryptLen = f->size() - pos;
byte *encrypted = new byte[cryptLen];
byte *decrypted = new byte[cryptLen];
f->at(pos);
#ifndef PWM_EMBEDDED
if (f->readBlock(reinterpret_cast<char *>(encrypted),
static_cast<Q_ULONG>(cryptLen))
!= static_cast<Q_LONG>(cryptLen)) {
delete [] encrypted;
delete [] decrypted;
return e_readFile;
}
@@ -1516,27 +1518,27 @@ PwMerror PwMDoc::decrypt(string *d, unsigned int pos, const QString *pw,
}
case PWM_CRYPT_AES128:
/*... fall through */
case PWM_CRYPT_AES192:
case PWM_CRYPT_AES256:
case PWM_CRYPT_3DES:
case PWM_CRYPT_TWOFISH:
case PWM_CRYPT_TWOFISH128: {
if (!LibGCryptIf::available())
return e_cryptNotImpl;
LibGCryptIf gc;
PwMerror err;
- err = gc.decrypt(&decrypted,
+ err = gc.decrypt((unsigned char **)&decrypted,
&cryptLen,
- encrypted,
+ (unsigned char*)encrypted,
cryptLen,
reinterpret_cast<const unsigned char *>(pw->latin1()),
pw->length(),
algo,
hashalgo //US BUG: pass _hashalgo because we need it in hashPassphrase
);
if (err != e_success) {
delete [] encrypted;
delete [] decrypted;
return e_cryptNotImpl;
}
break;
@@ -2424,25 +2426,25 @@ bool PwMDoc::goToURL(unsigned int category, unsigned int entryIndex)
return true;
return false;
}
PwMerror PwMDoc::exportToText(const QString *file)
{
PWM_ASSERT(file);
if (QFile::exists(*file)) {
if (!QFile::remove(*file))
return e_accessFile;
}
QFile f(*file);
- if (!f.open(IO_ReadWrite))
+ if (!f.open(QIODevice::ReadWrite))
return e_openFile;
if (!unlockAll_tempoary()) {
f.close();
return e_lock;
}
// write header
string header = i18n("Password table generated by\nPwM v").latin1();
header += PACKAGE_VER;
header += i18n("\non ").latin1();
QDate currDate = QDate::currentDate();
@@ -2698,25 +2700,25 @@ PwMerror PwMDoc::importText_PwM(const QString *file)
formatError:
free(ch_tmp);
fclose(f);
return e_fileFormat;
#else
PWM_ASSERT(file);
QFile f(file->latin1());
int tmp;
ssize_t ret;
string curCat;
unsigned int entriesRead = 0;
PwMDataItem currItem;
- bool res = f.open(IO_ReadOnly);
+ bool res = f.open(QIODevice::ReadOnly);
if (res == false)
return e_openFile;
unsigned int ch_tmp_size = 1024;
char *ch_tmp = (char*)malloc(ch_tmp_size);
if (!ch_tmp) {
f.close();
return e_outOfMem;
}
// - check header
if (f.readLine(ch_tmp, ch_tmp_size) == -1) // skip first line.
@@ -3620,15 +3622,15 @@ QStringList PwMDoc::getIDEntryList()
++entrI;
}
++catcounter;
}
return results;
}
-#ifndef PWM_EMBEDDED
-#include "pwmdoc.moc"
+#ifndef PWM_EMBEDDED_
+#include "moc_pwmdoc.cpp"
#endif