X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fcore.cpp;h=7fbd4e71f300b2eb3b7291bada74ffda2f7d150f;hp=1a418f1d08ddce65ece600e5393c608bacd3cf7d;hb=436cb365db846985ef5ce508cb5bf925cd903480;hpb=cfbd4daee17dbb3c4052d938bf33edd08711d728 diff --git a/src/core/core.cpp b/src/core/core.cpp index 1a418f1d..7fbd4e71 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2016 by the Quassel Project * + * Copyright (C) 2005-2018 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -236,8 +236,12 @@ void Core::init() connect(&_v6server, SIGNAL(newConnection()), this, SLOT(incomingConnection())); if (!startListening()) exit(1); // TODO make this less brutal - if (Quassel::isOptionSet("oidentd")) - _oidentdConfigGenerator = new OidentdConfigGenerator(this); + if (Quassel::isOptionSet("oidentd")) { + _oidentdConfigGenerator = new OidentdConfigGenerator(Quassel::isOptionSet("oidentd-strict"), this); + if (Quassel::isOptionSet("oidentd-strict")) { + cacheSysIdent(); + } + } } @@ -255,14 +259,10 @@ Core::~Core() void Core::saveState() { - CoreSettings s; - QVariantMap state; QVariantList activeSessions; foreach(UserId user, instance()->_sessions.keys()) activeSessions << QVariant::fromValue(user); - state["CoreStateVersion"] = 1; - state["ActiveSessions"] = activeSessions; - s.setCoreState(state); + instance()->_storage->setCoreState(activeSessions); } @@ -285,7 +285,9 @@ void Core::restoreState() } */ - QVariantList activeSessions = s.coreState().toMap()["ActiveSessions"].toList(); + const QList &activeSessionsFallback = s.coreState().toMap()["ActiveSessions"].toList(); + QVariantList activeSessions = instance()->_storage->getCoreState(activeSessionsFallback); + if (activeSessions.count() > 0) { quInfo() << "Restoring previous core state..."; foreach(QVariant v, activeSessions) { @@ -329,6 +331,7 @@ QString Core::setupCore(const QString &adminUser, const QString &adminPassword, quInfo() << qPrintable(tr("Creating admin user...")); _storage->addUser(adminUser, adminPassword); + cacheSysIdent(); startListening(); // TODO check when we need this return QString(); } @@ -403,10 +406,15 @@ bool Core::initStorage(const QString &backend, const QVariantMap &settings, bool return false; // trigger setup process if (storage->setup(settings)) return initStorage(backend, settings, false); + return false; + // if initialization wasn't successful, we quit to keep from coming up unconfigured case Storage::NotAvailable: qCritical() << "FATAL: Selected storage backend is not available:" << backend; - exit(EXIT_FAILURE); + if (!setup) + exit(EXIT_FAILURE); + return false; + case Storage::IsReady: // delete all other backends _registeredStorageBackends.clear(); @@ -495,10 +503,15 @@ bool Core::initAuthenticator(const QString &backend, const QVariantMap &settings return false; // trigger setup process if (auth->setup(settings)) return initAuthenticator(backend, settings, false); + return false; + // if initialization wasn't successful, we quit to keep from coming up unconfigured case Authenticator::NotAvailable: qCritical() << "FATAL: Selected auth backend is not available:" << backend; - exit(EXIT_FAILURE); + if (!setup) + exit(EXIT_FAILURE); + return false; + case Authenticator::IsReady: // delete all other backends _registeredAuthenticators.clear(); @@ -539,6 +552,34 @@ bool Core::reloadCerts() } +void Core::cacheSysIdent() +{ + if (isConfigured()) { + instance()->_authUserNames = instance()->_storage->getAllAuthUserNames(); + } +} + + +QString Core::strictSysIdent(UserId user) const +{ + if (_authUserNames.contains(user)) { + return _authUserNames[user]; + } + + // A new user got added since we last pulled our cache from the database. + // There's no way to avoid a database hit - we don't even know the authname! + cacheSysIdent(); + + if (_authUserNames.contains(user)) { + return _authUserNames[user]; + } + + // ...something very weird is going on if we ended up here (an active CoreSession without a corresponding database entry?) + qWarning().nospace() << "Unable to find authusername for UserId " << user << ", this should never happen!"; + return "unknown"; // Should we just terminate the program instead? +} + + bool Core::startListening() { // in mono mode we only start a local port if a port is specified in the cli call @@ -862,7 +903,7 @@ bool Core::selectBackend(const QString &backend) qDebug() << qPrintable(tr("Migrating storage backend %1 to %2...").arg(_storage->displayName(), storage->displayName())); _storage.reset(); storage.reset(); - if (reader->migrateTo(writer)) { + if (reader->migrateTo(writer.get())) { qDebug() << "Migration finished!"; qDebug() << qPrintable(tr("Migration finished!")); if (!saveBackendSettings(backend, settings)) {