X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fcore%2Foidentdconfiggenerator.cpp;h=a235eb8807bef26063ecfd0640baa1268943f1e1;hb=145a52eb79fed146731f85c23b60f0609e40e785;hp=bd4350dac215ba6da4fef84c92ca0be894c311d9;hpb=6422c61b11d97f905b6a27f2d280e9ec0d8bb3e2;p=quassel.git diff --git a/src/core/oidentdconfiggenerator.cpp b/src/core/oidentdconfiggenerator.cpp index bd4350da..a235eb88 100644 --- a/src/core/oidentdconfiggenerator.cpp +++ b/src/core/oidentdconfiggenerator.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2018 by the Quassel Project * + * Copyright (C) 2005-2020 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -18,21 +18,23 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ +#ifdef HAVE_UMASK +# include +# include +#endif /* HAVE_UMASK */ + #include #include "corenetwork.h" #include "oidentdconfiggenerator.h" -OidentdConfigGenerator::OidentdConfigGenerator(bool strict, QObject *parent) : - QObject(parent), - _initialized(false), - _strict(strict) +OidentdConfigGenerator::OidentdConfigGenerator(QObject* parent) + : QObject(parent) { if (!_initialized) init(); } - OidentdConfigGenerator::~OidentdConfigGenerator() { _quasselConfig.clear(); @@ -40,10 +42,9 @@ OidentdConfigGenerator::~OidentdConfigGenerator() _configFile->deleteLater(); } - bool OidentdConfigGenerator::init() { - _configDir = QDir::homePath(); + _configDir.setPath(QDir::homePath()); _configFileName = ".oidentd.conf"; if (Quassel::isOptionSet("oidentd-conffile")) @@ -60,7 +61,7 @@ bool OidentdConfigGenerator::init() // the ability to bind to an IP on client sockets. _quasselStanzaTemplate = QString("lport %1 { reply \"%2\" } #%3\n"); - _quasselStanzaRx = QRegExp(QString("^lport .* \\{ .* \\} #%1\\r?\\n").arg(_configTag)); + _quasselStanzaRx = QRegExp(QString(R"(^lport .* \{ .* \} #%1\r?\n)").arg(_configTag)); // initially remove all Quassel stanzas that might be present if (parseConfig(false) && writeConfig()) @@ -69,19 +70,25 @@ bool OidentdConfigGenerator::init() return _initialized; } - -QString OidentdConfigGenerator::sysIdentForIdentity(const CoreIdentity *identity) const { - if (!_strict) { - return identity->ident(); - } - const CoreNetwork *network = qobject_cast(sender()); - return network->coreSession()->strictSysident(); +QString OidentdConfigGenerator::sysIdentForIdentity(const CoreIdentity* identity) const +{ + // Make sure the identity's ident complies with strict mode if enabled + const CoreNetwork* network = qobject_cast(sender()); + return network->coreSession()->strictCompliantIdent(identity); } - -bool OidentdConfigGenerator::addSocket(const CoreIdentity *identity, const QHostAddress &localAddress, quint16 localPort, const QHostAddress &peerAddress, quint16 peerPort) +bool OidentdConfigGenerator::addSocket(const CoreIdentity* identity, + const QHostAddress& localAddress, + quint16 localPort, + const QHostAddress& peerAddress, + quint16 peerPort, + qint64 socketId) { - Q_UNUSED(localAddress) Q_UNUSED(peerAddress) Q_UNUSED(peerPort) + Q_UNUSED(localAddress) + Q_UNUSED(peerAddress) + Q_UNUSED(peerPort) + Q_UNUSED(socketId) + const QString ident = sysIdentForIdentity(identity); _quasselConfig.append(_quasselStanzaTemplate.arg(localPort).arg(ident).arg(_configTag).toLatin1()); @@ -91,15 +98,24 @@ bool OidentdConfigGenerator::addSocket(const CoreIdentity *identity, const QHost return ret; } - //! not yet implemented -bool OidentdConfigGenerator::removeSocket(const CoreIdentity *identity, const QHostAddress &localAddress, quint16 localPort, const QHostAddress &peerAddress, quint16 peerPort) +bool OidentdConfigGenerator::removeSocket(const CoreIdentity* identity, + const QHostAddress& localAddress, + quint16 localPort, + const QHostAddress& peerAddress, + quint16 peerPort, + qint64 socketId) { - Q_UNUSED(identity) Q_UNUSED(localAddress) Q_UNUSED(localPort) Q_UNUSED(peerAddress) Q_UNUSED(peerPort) + Q_UNUSED(identity) + Q_UNUSED(localAddress) + Q_UNUSED(localPort) + Q_UNUSED(peerAddress) + Q_UNUSED(peerPort) + Q_UNUSED(socketId) + return true; } - bool OidentdConfigGenerator::parseConfig(bool readQuasselStanzas) { if (!_configFile->exists()) @@ -125,11 +141,10 @@ bool OidentdConfigGenerator::parseConfig(bool readQuasselStanzas) return true; } - bool OidentdConfigGenerator::writeConfig() { #ifdef HAVE_UMASK - mode_t prev_umask = umask(S_IXUSR | S_IWGRP | S_IXGRP | S_IWOTH | S_IXOTH); // == 0133, rw-r--r-- + mode_t prev_umask = umask(S_IXUSR | S_IWGRP | S_IXGRP | S_IWOTH | S_IXOTH); // == 0133, rw-r--r-- #endif bool not_open = (!_configFile->isOpen() && !_configFile->open(QIODevice::ReadWrite | QIODevice::Text)); #ifdef HAVE_UMASK @@ -151,8 +166,7 @@ bool OidentdConfigGenerator::writeConfig() return true; } - -bool OidentdConfigGenerator::lineByUs(const QByteArray &line) +bool OidentdConfigGenerator::lineByUs(const QByteArray& line) { return _quasselStanzaRx.exactMatch(line); }