if (Quassel::isOptionSet("oidentd")) {
_oidentdConfigGenerator = new OidentdConfigGenerator(Quassel::isOptionSet("oidentd-strict"), this);
if (Quassel::isOptionSet("oidentd-strict")) {
- cacheSysident();
+ cacheSysIdent();
}
}
}
quInfo() << qPrintable(tr("Creating admin user..."));
_storage->addUser(adminUser, adminPassword);
- cacheSysident();
+ cacheSysIdent();
startListening(); // TODO check when we need this
return QString();
}
#endif
}
-void Core::cacheSysident() {
- if(isConfigured()) {
- instance()->_authusernames = instance()->_storage->getAllAuthusernames();
+
+void Core::cacheSysIdent()
+{
+ if (isConfigured()) {
+ instance()->_authUserNames = instance()->_storage->getAllAuthUserNames();
}
}
-QString Core::strictSysident(UserId user) {
- QMap<UserId, QString> *allAuthusernames = &instance()->_authusernames;
- auto authusername = allAuthusernames->find(user);
- if (authusername == allAuthusernames->end()) {
- // 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();
- authusername = allAuthusernames->find(user);
- if (authusername == allAuthusernames->end()) {
- // ...something very weird is going on if we ended up here (an active CoreSession without a corresponding database entry?)
- QDebug d = qWarning();
- d << "Unable to find authusername for UserId" << user;
- d.nospace();
- d << ", this should never happen!";
- return "unknown"; // Should we just terminate the program instead?
- }
+
+QString Core::strictSysIdent(UserId user) const
+{
+ if (_authUserNames.contains(user)) {
+ return _authUserNames[user];
}
- return *authusername;
+
+ // 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
/** \param user The user to retrieve the username for
* \return The username for the user
*/
- static inline const QString getAuthusername(UserId user) {
- return instance()->_storage->getAuthusername(user);
+ static inline QString getAuthUserName(UserId user) {
+ return instance()->_storage->getAuthUserName(user);
}
//! Get a usable sysident for the given user in oidentd-strict mode
/** \param user The user to retrieve the sysident for
* \return The authusername
*/
- QString strictSysident(UserId user);
+ QString strictSysIdent(UserId user) const;
//! Get a Hash of all last seen message ids
*/
static bool reloadCerts();
- static void cacheSysident();
+ static void cacheSysIdent();
static QVariantList backendInfo();
static QVariantList authenticatorInfo();
DeferredSharedPtr<Storage> _storage; ///< Active storage backend
DeferredSharedPtr<Authenticator> _authenticator; ///< Active authenticator
QTimer _storageSyncTimer;
- QMap<UserId, QString> _authusernames;
+ QMap<UserId, QString> _authUserNames;
#ifdef HAVE_SSL
SslServer _server, _v6server;
Quassel::registerReloadHandler([]() {
// Currently, only reloading SSL certificates and the sysident cache is supported
- Core::cacheSysident();
+ Core::cacheSysIdent();
return Core::reloadCerts();
});
}
const QString CoreSession::strictSysident() {
- return Core::instance()->strictSysident(_user);
+ return Core::instance()->strictSysIdent(_user);
}
void CoreSession::createIdentity(const CoreIdentity &identity)
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
-#include "oidentdconfiggenerator.h"
-#include "corenetwork.h"
-
#include <QString>
+#include "corenetwork.h"
+#include "oidentdconfiggenerator.h"
+
OidentdConfigGenerator::OidentdConfigGenerator(bool strict, QObject *parent) :
QObject(parent),
_initialized(false),
return _initialized;
}
-const QString OidentdConfigGenerator::sysidentForIdentity(const CoreIdentity *identity) {
+
+QString OidentdConfigGenerator::sysIdentForIdentity(const CoreIdentity *identity) const {
if (!_strict) {
return identity->ident();
}
return network->coreSession()->strictSysident();
}
+
bool OidentdConfigGenerator::addSocket(const CoreIdentity *identity, const QHostAddress &localAddress, quint16 localPort, const QHostAddress &peerAddress, quint16 peerPort)
{
Q_UNUSED(localAddress) Q_UNUSED(peerAddress) Q_UNUSED(peerPort)
- const QString ident = sysidentForIdentity(identity);
+ const QString ident = sysIdentForIdentity(identity);
_quasselConfig.append(_quasselStanzaTemplate.arg(localPort).arg(ident).arg(_configTag).toLatin1());
bool removeSocket(const CoreIdentity *identity, const QHostAddress &localAddress, quint16 localPort, const QHostAddress &peerAddress, quint16 peerPort);
private:
- const QString sysidentForIdentity(const CoreIdentity *identity);
+ QString sysIdentForIdentity(const CoreIdentity *identity) const;
bool init();
bool writeConfig();
bool parseConfig(bool readQuasselStanzas = false);
return messagelist;
}
-QMap<UserId, QString> PostgreSqlStorage::getAllAuthusernames() {
+
+QMap<UserId, QString> PostgreSqlStorage::getAllAuthUserNames()
+{
QMap<UserId, QString> authusernames;
QSqlQuery query(logDb());
query.prepare(queryString("select_all_authusernames"));
return authusernames;
}
-const QString PostgreSqlStorage::getAuthusername(UserId user) {
+
+QString PostgreSqlStorage::getAuthUserName(UserId user)
+{
QString authusername;
QSqlQuery query(logDb());
query.prepare(queryString("select_authusername"));
QList<Message> requestAllMsgs(UserId user, MsgId first = -1, MsgId last = -1, int limit = -1) override;
/* Sysident handling */
- virtual QMap<UserId, QString> getAllAuthusernames();
- virtual const QString getAuthusername(UserId user);
+ QMap<UserId, QString> getAllAuthUserNames() override;
+ QString getAuthUserName(UserId user) override;
protected:
bool initDbSession(QSqlDatabase &db) override;
return messagelist;
}
-QMap<UserId, QString> SqliteStorage::getAllAuthusernames()
+
+QMap<UserId, QString> SqliteStorage::getAllAuthUserNames()
{
QMap<UserId, QString> authusernames;
return authusernames;
}
-const QString SqliteStorage::getAuthusername(UserId user) {
+
+QString SqliteStorage::getAuthUserName(UserId user) {
QString authusername;
QSqlQuery query(logDb());
query.prepare(queryString("select_authusername"));
return authusername;
}
+
QString SqliteStorage::backlogFile()
{
return Quassel::configDirPath() + "quassel-storage.sqlite";
QList<Message> requestAllMsgs(UserId user, MsgId first = -1, MsgId last = -1, int limit = -1) override;
/* Sysident handling */
- virtual QMap<UserId, QString> getAllAuthusernames();
- virtual const QString getAuthusername(UserId user);
+ QMap<UserId, QString> getAllAuthUserNames() override;
+ QString getAuthUserName(UserId user) override;
protected:
void setConnectionProperties(const QVariantMap & /* properties */) override {}
//! Fetch all authusernames
/** \return Map of all current UserIds to permitted idents
*/
- virtual QMap<UserId, QString> getAllAuthusernames() = 0;
+ virtual QMap<UserId, QString> getAllAuthUserNames() = 0;
//! Get the auth username associated with a userId
/** \param user The user to retrieve the username for
* \return The username for the user
*/
- virtual const QString getAuthusername(UserId user) = 0;
+ virtual QString getAuthUserName(UserId user) = 0;
signals:
//! Sent when a new BufferInfo is created, or an existing one changed somehow.