X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fpostgresqlstorage.cpp;h=acb7f37c922cb6917e36c57fe34b47226bd05968;hp=31f22b9de5c508ba99822d09e6dec61d5154327c;hb=9ad0c72c466afbc98a38b5f57f0ad8ed34d5f4c4;hpb=9c5fd60f6264898a7c0287e3f7d47e181ef39f84 diff --git a/src/core/postgresqlstorage.cpp b/src/core/postgresqlstorage.cpp index 31f22b9d..acb7f37c 100644 --- a/src/core/postgresqlstorage.cpp +++ b/src/core/postgresqlstorage.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2014 by the Quassel Project * + * Copyright (C) 2005-2015 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -136,6 +136,14 @@ bool PostgreSqlStorage::initDbSession(QSqlDatabase &db) return false; break; } + + // Set the PostgreSQL session timezone to UTC, since we want timestamps stored in UTC + QSqlQuery tzQuery = db.exec("SET timezone = 'UTC'"); + if (tzQuery.lastError().isValid()) { + quError() << "Failed to set timezone to UTC!"; + return false; + } + return true; } @@ -207,7 +215,8 @@ UserId PostgreSqlStorage::addUser(const QString &user, const QString &password) QSqlQuery query(logDb()); query.prepare(queryString("insert_quasseluser")); query.bindValue(":username", user); - query.bindValue(":password", cryptedPassword(password)); + query.bindValue(":password", hashPassword(password)); + query.bindValue(":hashversion", Storage::HashVersion::Latest); safeExec(query); if (!watchQuery(query)) return 0; @@ -224,7 +233,8 @@ bool PostgreSqlStorage::updateUser(UserId user, const QString &password) QSqlQuery query(logDb()); query.prepare(queryString("update_userpassword")); query.bindValue(":userid", user.toInt()); - query.bindValue(":password", cryptedPassword(password)); + query.bindValue(":password", hashPassword(password)); + query.bindValue(":hashversion", Storage::HashVersion::Latest); safeExec(query); watchQuery(query); return query.numRowsAffected() != 0; @@ -248,11 +258,10 @@ UserId PostgreSqlStorage::validateUser(const QString &user, const QString &passw QSqlQuery query(logDb()); query.prepare(queryString("select_authuser")); query.bindValue(":username", user); - query.bindValue(":password", cryptedPassword(password)); safeExec(query); watchQuery(query); - if (query.first()) { + if (query.first() && checkHashedPassword(query.value(0).toInt(), password, query.value(1).toString(), static_cast(query.value(2).toInt()))) { return query.value(0).toInt(); } else { @@ -935,7 +944,7 @@ void PostgreSqlStorage::setChannelPersistent(UserId user, const NetworkId &netwo QSqlQuery query(logDb()); query.prepare(queryString("update_buffer_persistent_channel")); query.bindValue(":userid", user.toInt()); - query.bindValue(":networkId", networkId.toInt()); + query.bindValue(":networkid", networkId.toInt()); query.bindValue(":buffercname", channel.toLower()); query.bindValue(":joined", isJoined); safeExec(query); @@ -948,7 +957,7 @@ void PostgreSqlStorage::setPersistentChannelKey(UserId user, const NetworkId &ne QSqlQuery query(logDb()); query.prepare(queryString("update_buffer_set_channel_key")); query.bindValue(":userid", user.toInt()); - query.bindValue(":networkId", networkId.toInt()); + query.bindValue(":networkid", networkId.toInt()); query.bindValue(":buffercname", channel.toLower()); query.bindValue(":key", key); safeExec(query); @@ -1372,8 +1381,7 @@ bool PostgreSqlStorage::logMessage(Message &msg) if (addSenderQuery.lastError().isValid()) { rollbackSavePoint("sender_sp1", db); - getSenderIdQuery.prepare(getSenderIdQuery.lastQuery()); - safeExec(getSenderIdQuery); + getSenderIdQuery = executePreparedQuery("select_senderid", msg.sender(), db); watchQuery(getSenderIdQuery); getSenderIdQuery.first(); senderId = getSenderIdQuery.value(0).toInt(); @@ -1443,8 +1451,7 @@ bool PostgreSqlStorage::logMessages(MessageList &msgs) if (addSenderQuery.lastError().isValid()) { // seems it was inserted meanwhile... by a different thread rollbackSavePoint("sender_sp", db); - selectSenderQuery.prepare(selectSenderQuery.lastQuery()); - safeExec(selectSenderQuery); + selectSenderQuery = executePreparedQuery("select_senderid", sender, db); watchQuery(selectSenderQuery); selectSenderQuery.first(); senderIdList << selectSenderQuery.value(0).toInt(); @@ -1834,6 +1841,7 @@ bool PostgreSqlMigrationWriter::writeMo(const QuasselUserMO &user) bindValue(0, user.id.toInt()); bindValue(1, user.username); bindValue(2, user.password); + bindValue(3, user.hashversion); return exec(); } @@ -1997,7 +2005,7 @@ bool PostgreSqlMigrationWriter::postProcess() << Sequence("quasseluser", "userid") << Sequence("sender", "senderid"); QList::const_iterator iter; - for (iter = sequences.constBegin(); iter != sequences.constEnd(); iter++) { + for (iter = sequences.constBegin(); iter != sequences.constEnd(); ++iter) { resetQuery(); newQuery(QString("SELECT setval('%1_%2_seq', max(%2)) FROM %1").arg(iter->table, iter->field), db); if (!exec())