From: Daniel Albers Date: Mon, 6 Feb 2012 01:28:56 +0000 (+0100) Subject: oidentd support - WIP X-Git-Tag: 0.8-beta1~22 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=03eb5a574ec55546c62336428c7a9caa63b45a7a oidentd support - WIP --- diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index a7eaf0b0..a6d3f206 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -24,6 +24,7 @@ set(SOURCES coreircuser.cpp corenetwork.cpp corenetworkconfig.cpp + oidentdconfiggenerator.cpp coresession.cpp coresessioneventprocessor.cpp coresettings.cpp @@ -56,6 +57,7 @@ set(MOC_HDRS coreircuser.h corenetwork.h corenetworkconfig.h + oidentdconfiggenerator.h coresession.h coresessioneventprocessor.h coreuserinputhandler.h diff --git a/src/core/core.cpp b/src/core/core.cpp index c894820c..2a2e5ebe 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -169,6 +169,8 @@ Core::Core() } void Core::init() { + _oidentdConfigGenerator = new OidentdConfigGenerator(); + CoreSettings cs; _configured = initStorage(cs.storageSettings().toMap()); @@ -240,6 +242,7 @@ void Core::restoreState() { return; } */ + QVariantList activeSessions = s.coreState().toMap()["ActiveSessions"].toList(); if(activeSessions.count() > 0) { quInfo() << "Restoring previous core state..."; diff --git a/src/core/core.h b/src/core/core.h index d3f2fab3..8ee11296 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -33,6 +33,7 @@ # include # include #endif +#include "oidentdconfiggenerator.h" #include "storage.h" #include "bufferinfo.h" @@ -404,6 +405,8 @@ public: static inline QTimer &syncTimer() { return instance()->_storageSyncTimer; } + inline OidentdConfigGenerator *oidentdConfigGenerator() { return _oidentdConfigGenerator; } + static const int AddClientEventId; public slots: @@ -472,6 +475,8 @@ private: QTcpServer _server, _v6server; #endif + OidentdConfigGenerator *_oidentdConfigGenerator; + QHash blocksizes; QHash clientInfo; diff --git a/src/core/coreapplication.cpp b/src/core/coreapplication.cpp index f7f36c54..f881d9ec 100644 --- a/src/core/coreapplication.cpp +++ b/src/core/coreapplication.cpp @@ -22,6 +22,7 @@ #include "core.h" #include "logger.h" +#include CoreApplicationInternal::CoreApplicationInternal() : _coreCreated(false) diff --git a/src/core/corenetwork.cpp b/src/core/corenetwork.cpp index d18ddca5..8ea229f6 100644 --- a/src/core/corenetwork.cpp +++ b/src/core/corenetwork.cpp @@ -68,6 +68,7 @@ CoreNetwork::CoreNetwork(const NetworkId &networkid, CoreSession *session) connect(&_autoWhoCycleTimer, SIGNAL(timeout()), this, SLOT(startAutoWhoCycle())); connect(&_tokenBucketTimer, SIGNAL(timeout()), this, SLOT(fillBucketAndProcessQueue())); + connect(&socket, SIGNAL(connected()), Core::instance()->oidentdConfigGenerator(), SLOT(update())); connect(&socket, SIGNAL(connected()), this, SLOT(socketInitialized())); connect(&socket, SIGNAL(disconnected()), this, SLOT(socketDisconnected())); connect(&socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketError(QAbstractSocket::SocketError))); diff --git a/src/core/corenetwork.h b/src/core/corenetwork.h index 0f6559a8..2dbd6a9e 100644 --- a/src/core/corenetwork.h +++ b/src/core/corenetwork.h @@ -26,6 +26,7 @@ #include "coreircuser.h" #include +#include #ifdef HAVE_SSL # include @@ -33,6 +34,7 @@ #else # include #endif +#include #ifdef HAVE_QCA2 # include "cipher.h" diff --git a/src/core/oidentdconfiggenerator.cpp b/src/core/oidentdconfiggenerator.cpp new file mode 100644 index 00000000..779a50c9 --- /dev/null +++ b/src/core/oidentdconfiggenerator.cpp @@ -0,0 +1,84 @@ +/*************************************************************************** + * Copyright (C) 2012 by the Quassel Project * + * devel@quassel-irc.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) version 3. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "oidentdconfiggenerator.h" + +OidentdConfigGenerator::OidentdConfigGenerator(QObject *parent) : + QObject(parent), + _initialized(false) +{ + qDebug() << "OidentdConfigGenerator() checking for being initialized"; + if (!_initialized) + init(); +} + +bool OidentdConfigGenerator::init() { + configDir = QDir::homePath(); + configFileName = ".oidentd.conf"; + configTag = " stanza created by Quassel"; + + _configFile = new QFile(configDir.absoluteFilePath(configFileName)); + qDebug() << "1: _configFile" << _configFile->fileName(); + + quasselStanza = QRegExp(QString("^lport .* { .* } #%1$").arg(configTag)); + + if (update()) + _initialized = true; + + qDebug() << "konichi wa °-°"; + + return _initialized; +} + +bool OidentdConfigGenerator::update() { + if (parseConfig()) + qDebug() << "oidentd config parsed successfully"; + else + qDebug() << QString("parsing oidentd config failed (%1 [%2])").arg(_configFile->errorString()).arg(_configFile->error()); + + return writeConfig(); +} + +bool OidentdConfigGenerator::parseConfig() { + qDebug() << "_configFile name" << _configFile->fileName(); + qDebug() << "open?" << _configFile->isOpen(); + if (!_configFile->isOpen() && !_configFile->open(QIODevice::ReadWrite)) + return false; + + QByteArray parsedConfig; + while (!_configFile->atEnd()) { + QByteArray line = _configFile->readLine(); + + if (checkLine(line)) + parsedConfig.append(line); + } + + _config = parsedConfig; + + return true; +} + +bool OidentdConfigGenerator::writeConfig() { + return true; +} + +bool OidentdConfigGenerator::checkLine(const QByteArray &line) { + return !quasselStanza.exactMatch(line); +} diff --git a/src/core/oidentdconfiggenerator.h b/src/core/oidentdconfiggenerator.h new file mode 100644 index 00000000..db4016c1 --- /dev/null +++ b/src/core/oidentdconfiggenerator.h @@ -0,0 +1,61 @@ +/*************************************************************************** + * Copyright (C) 2012 by the Quassel Project * + * devel@quassel-irc.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) version 3. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef OIDENTDCONFIGGENERATOR_H +#define OIDENTDCONFIGGENERATOR_H + +#include +#include +#include +#include + +#include + +class OidentdConfigGenerator : public QObject +{ + Q_OBJECT +public: + explicit OidentdConfigGenerator(QObject *parent = 0); + + QDir configDir; + QString configFileName; + +signals: + +public slots: + bool update(); + +private: + bool init(); + bool writeConfig(); + bool parseConfig(); + bool checkLine(const QByteArray &line); + + bool _initialized; + QDateTime _lastSync; + QFile *_configFile; + QByteArray _config; + + QString configTag; + + QRegExp quasselStanza; +}; + +#endif // OIDENTDCONFIGGENERATOR_H