summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/opertype.h2
-rw-r--r--include/protocol.h5
-rw-r--r--modules/extra/m_sql_oper.cpp135
-rw-r--r--modules/protocol/inspircd-ts6.h4
-rw-r--r--src/protocol.cpp6
-rw-r--r--src/users.cpp3
6 files changed, 154 insertions, 1 deletions
diff --git a/include/opertype.h b/include/opertype.h
index 3f0b8d157..4e3f01e28 100644
--- a/include/opertype.h
+++ b/include/opertype.h
@@ -23,7 +23,7 @@ struct CoreExport Oper
std::vector<Anope::string> hosts;
Anope::string vhost;
- Oper(const Anope::string &n, OperType *o) : name(n), ot(o) { this->config = false; }
+ Oper(const Anope::string &n, OperType *o) : name(n), ot(o), require_oper(false), config(false) { }
virtual ~Oper() { }
diff --git a/include/protocol.h b/include/protocol.h
index d4ff79082..4da0b5b3a 100644
--- a/include/protocol.h
+++ b/include/protocol.h
@@ -120,6 +120,11 @@ class CoreExport IRCDProto
* On most TS6 IRCds this is a SJOIN with no nick
*/
virtual void SendChannel(Channel *c) { }
+
+ /** Make the user an IRC operator
+ * Normally this is a simple +o, though some IRCds require us to send the oper type
+ */
+ virtual void SendOper(User *u);
};
enum IRCDMessageFlag
diff --git a/modules/extra/m_sql_oper.cpp b/modules/extra/m_sql_oper.cpp
new file mode 100644
index 000000000..b834e26ca
--- /dev/null
+++ b/modules/extra/m_sql_oper.cpp
@@ -0,0 +1,135 @@
+#include "module.h"
+#include "sql.h"
+
+class SQLOperResult : public SQLInterface
+{
+ dynamic_reference<User> user;
+
+ struct SQLOperResultDeleter
+ {
+ SQLOperResult *res;
+ SQLOperResultDeleter(SQLOperResult *r) : res(r) { }
+ ~SQLOperResultDeleter() { delete res; }
+ };
+
+ public:
+ SQLOperResult(Module *m, User *u) : SQLInterface(m), user(u) { }
+
+ void OnResult(const SQLResult &r) anope_override
+ {
+ SQLOperResultDeleter d(this);
+
+ if (!user || !user->Account() || r.Rows() == 0)
+ return;
+
+ Anope::string opertype;
+ try
+ {
+ opertype = r.Get(0, "opertype");
+ }
+ catch (const SQLException &)
+ {
+ return;
+ }
+
+ Log(LOG_DEBUG) << "m_sql_oper: Got result for " << user->nick << ", opertype " << opertype;
+
+ Anope::string modes;
+ try
+ {
+ modes = r.Get(0, "modes");
+ }
+ catch (const SQLException &) { }
+
+ if (opertype.empty())
+ {
+ if (user->Account() && user->Account()->o && !user->Account()->o->config)
+ {
+ std::vector<Oper *>::iterator it = std::find(Config->Opers.begin(), Config->Opers.end(), user->Account()->o);
+ if (it != Config->Opers.end())
+ Config->Opers.erase(it);
+ delete user->Account()->o;
+ user->Account()->o = NULL;
+ Log() << "m_sql_oper: Removed services operator from " << user->nick << " (" << user->Account()->display << ")";
+ user->RemoveMode(findbot(Config->OperServ), UMODE_OPER); // Probably not set, just incase
+ }
+ return;
+ }
+
+ OperType *ot = OperType::Find(opertype);
+ if (ot == NULL)
+ {
+ Log() << "m_sql_oper: Oper " << user->nick << " has type " << opertype << ", but this opertype does not exist?";
+ return;
+ }
+
+ if (!user->Account()->o || user->Account()->o->ot != ot)
+ {
+ Log() << "m_sql_oper: Tieing oper " << user->nick << " to type " << opertype;
+ user->Account()->o = new Oper(user->Account()->display, ot);
+ Config->Opers.push_back(user->Account()->o);
+ }
+
+ if (!user->HasMode(UMODE_OPER))
+ {
+ ircdproto->SendOper(user);
+
+ if (!modes.empty())
+ user->SetModes(findbot(Config->OperServ), "%s", modes.c_str());
+ }
+ }
+
+ void OnError(const SQLResult &r) anope_override
+ {
+ SQLOperResultDeleter d(this);
+ Log() << "m_sql_oper: Error executing query " << r.GetQuery().query << ": " << r.GetError();
+ }
+};
+
+class ModuleSQLOper : public Module
+{
+ Anope::string engine;
+ Anope::string query;
+
+ service_reference<SQLProvider> SQL;
+
+ public:
+ ModuleSQLOper(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, SUPPORTED)
+ {
+ this->SetAuthor("Anope");
+
+ Implementation i[] = { I_OnReload, I_OnNickIdentify };
+ ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation));
+
+ this->OnReload();
+ }
+
+ void OnReload() anope_override
+ {
+ ConfigReader config;
+
+ this->engine = config.ReadValue("m_sql_oper", "engine", "", 0);
+ this->query = config.ReadValue("m_sql_oper", "query", "", 0);
+
+ this->SQL = service_reference<SQLProvider>("SQLProvider", this->engine);
+ }
+
+ void OnNickIdentify(User *u) anope_override
+ {
+ if (!this->SQL)
+ {
+ Log() << "m_sql_oper: Unable to find SQL engine";
+ return;
+ }
+
+ SQLQuery q(this->query);
+ q.setValue("a", u->Account()->display);
+ q.setValue("i", u->ip);
+
+ this->SQL->Run(new SQLOperResult(this, u), q);
+
+ Log(LOG_DEBUG) << "m_sql_oper: Checking authentication for " << u->Account()->display;
+ }
+};
+
+MODULE_INIT(ModuleSQLOper)
diff --git a/modules/protocol/inspircd-ts6.h b/modules/protocol/inspircd-ts6.h
index e1a1dfc2a..38dd7e15e 100644
--- a/modules/protocol/inspircd-ts6.h
+++ b/modules/protocol/inspircd-ts6.h
@@ -361,6 +361,10 @@ class InspIRCdTS6Proto : public IRCDProto
return true;
}
+
+ void SendOper(User *u) anope_override
+ {
+ }
};
struct IRCDMessageEndburst : IRCDMessage
diff --git a/src/protocol.cpp b/src/protocol.cpp
index 14fe249ed..5d836b7f4 100644
--- a/src/protocol.cpp
+++ b/src/protocol.cpp
@@ -316,6 +316,12 @@ bool IRCDProto::IsChannelValid(const Anope::string &chan)
return true;
}
+void IRCDProto::SendOper(User *u)
+{
+ SendNumericInternal(381, u->GetUID(), ":You are now an IRC operator (set by services)");
+ u->SetMode(findbot(Config->OperServ), UMODE_OPER);
+}
+
MessageSource::MessageSource(const Anope::string &src) : source(src), u(NULL), s(NULL)
{
if (src.empty())
diff --git a/src/users.cpp b/src/users.cpp
index 603c22745..28b2c413c 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -431,6 +431,9 @@ void User::Identify(NickAlias *na)
this->SetModes(bi, "%s", this->nc->o->ot->modes.c_str());
if (bi != NULL)
this->SendMessage(bi, "Changing your usermodes to \002%s\002", this->nc->o->ot->modes.c_str());
+ UserMode *um = ModeManager::FindUserModeByName(UMODE_OPER);
+ if (um && !this->HasMode(UMODE_OPER) && this->nc->o->ot->modes.find(um->ModeChar) != Anope::string::npos)
+ ircdproto->SendOper(this);
}
if (ircdproto->CanSetVHost && !this->nc->o->vhost.empty())
{