X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Foidentdconfiggenerator.cpp;h=fac6dcd91197771f25c11c4810175e6d7b70187d;hp=df3f8c48b6919a761bd8383ada2058808f87c95f;hb=9c15e81b15a20e861c707e240c2cfee56bdf4bc9;hpb=da885f3c8e152e9bdf573290adcf53bed58d95d1 diff --git a/src/core/oidentdconfiggenerator.cpp b/src/core/oidentdconfiggenerator.cpp index df3f8c48..fac6dcd9 100644 --- a/src/core/oidentdconfiggenerator.cpp +++ b/src/core/oidentdconfiggenerator.cpp @@ -31,27 +31,28 @@ OidentdConfigGenerator::OidentdConfigGenerator(QObject *parent) : OidentdConfigGenerator::~OidentdConfigGenerator() { _quasselConfig.clear(); writeConfig(); + _configFile->deleteLater(); } bool OidentdConfigGenerator::init() { - configDir = QDir::homePath(); - configFileName = ".oidentd.conf"; + _configDir = QDir::homePath(); + _configFileName = ".oidentd.conf"; if(Quassel::isOptionSet("oidentd-conffile")) - configPath = Quassel::optionValue("oidentd-conffile"); + _configPath = Quassel::optionValue("oidentd-conffile"); else - configPath = configDir.absoluteFilePath(configFileName); + _configPath = _configDir.absoluteFilePath(_configFileName); - configTag = " stanza created by Quassel"; + _configTag = " stanza created by Quassel"; - _configFile = new QFile(configPath); + _configFile = new QFile(_configPath); // Rx has to match Template in order for cleanup to work. // Template should be enhanced with the "from" parameter as soon as Quassel gains // 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)); + _quasselStanzaTemplate = QString("lport %1 { reply \"%2\" } #%3\n"); + _quasselStanzaRx = QRegExp(QString("^lport .* \\{ .* \\} #%1\\r?\\n").arg(_configTag)); // initially remove all Quassel stanzas that might be present if (parseConfig(false) && writeConfig()) @@ -64,21 +65,24 @@ bool OidentdConfigGenerator::addSocket(const CoreIdentity *identity, const QHost Q_UNUSED(localAddress) Q_UNUSED(peerAddress) Q_UNUSED(peerPort) QString ident = identity->ident(); - _quasselConfig.append(quasselStanzaTemplate.arg(localPort).arg(ident).arg(configTag)); + _quasselConfig.append(_quasselStanzaTemplate.arg(localPort).arg(ident).arg(_configTag).toAscii()); bool ret = writeConfig(); return ret; } -// not yet implemented +//! not yet implemented bool OidentdConfigGenerator::removeSocket(const CoreIdentity *identity, const QHostAddress &localAddress, quint16 localPort, const QHostAddress &peerAddress, quint16 peerPort) { Q_UNUSED(identity) Q_UNUSED(localAddress) Q_UNUSED(localPort) Q_UNUSED(peerAddress) Q_UNUSED(peerPort) return true; } bool OidentdConfigGenerator::parseConfig(bool readQuasselStanzas) { - if (!_configFile->isOpen() && !_configFile->open(QIODevice::ReadWrite)) + if (!_configFile->exists()) + return true; + + if (!_configFile->isOpen() && !_configFile->open(QIODevice::ReadOnly)) return false; _mutex.lock(); @@ -99,8 +103,13 @@ bool OidentdConfigGenerator::parseConfig(bool readQuasselStanzas) { } bool OidentdConfigGenerator::writeConfig() { - if (!_configFile->isOpen() && !_configFile->open(QIODevice::ReadWrite | QIODevice::Text)) + mode_t prev_umask = umask(S_IXUSR | S_IWGRP | S_IXGRP | S_IWOTH | S_IXOTH); // == 0133, rw-r--r-- + bool not_open = (!_configFile->isOpen() && !_configFile->open(QIODevice::ReadWrite | QIODevice::Text)); + umask(prev_umask); + + if (not_open) return false; + _mutex.lock(); _configFile->seek(0); @@ -114,5 +123,5 @@ bool OidentdConfigGenerator::writeConfig() { } bool OidentdConfigGenerator::lineByUs(const QByteArray &line) { - return quasselStanzaRx.exactMatch(line); + return _quasselStanzaRx.exactMatch(line); }