Skip to content

Commit

Permalink
Fix oper override triggering upon viewing list modes
Browse files Browse the repository at this point in the history
  • Loading branch information
B00mX0r committed Apr 8, 2018
1 parent 1155320 commit cb386fa
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
37 changes: 37 additions & 0 deletions include/modules/hidelist.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* InspIRCd -- Internet Relay Chat Daemon
*
* Copyright (C) 2018 Dylan Frank <b00mx0r@aureus.pw>
*
* This file is part of InspIRCd. InspIRCd 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, version 2.
*
* 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, see <http://www.gnu.org/licenses/>.
*/


#pragma once

#include "event.h"

class HidelistEventListener : public Events::ModuleEventListener
{
public:
HidelistEventListener(Module* mod)
: ModuleEventListener(mod, "event/hidelist")
{
}

/** Called whenever a /WHOIS is performed by a local user.
* @param whois Whois context, can be used to send numerics
*/
virtual ModResult OnListDenied(User* user, Channel* chan, const std::string& modename);
};

8 changes: 8 additions & 0 deletions src/modules/m_hidelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@


#include "inspircd.h"
#include "modules/hidelist.h"

class ListWatcher : public ModeWatcher
{
// Minimum rank required to view the list
const unsigned int minrank;
Events::ModuleEventProvider evprov;

public:
ListWatcher(Module* mod, const std::string& modename, unsigned int rank)
: ModeWatcher(mod, modename, MODETYPE_CHANNEL)
, minrank(rank)
, evprov(mod, "event/hidelist")
{
}

Expand All @@ -46,6 +49,11 @@ class ListWatcher : public ModeWatcher
if (user->HasPrivPermission("channels/auspex"))
return true;

ModResult MOD_RESULT;
FOREACH_MOD_CUSTOM(evprov, HidelistEventListener, OnListDenied, (user, chan, GetModeName()));
if (MOD_RESULT == MOD_RES_ALLOW)
return true;

user->WriteNumeric(ERR_CHANOPRIVSNEEDED, chan->name, InspIRCd::Format("You do not have access to view the %s list", GetModeName().c_str()));
return false;
}
Expand Down
28 changes: 26 additions & 2 deletions src/modules/m_override.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include "inspircd.h"
#include "modules/invite.h"
#include "modules/hidelist.h"

class Override : public SimpleUserModeHandler
{
Expand All @@ -38,7 +39,7 @@ class Override : public SimpleUserModeHandler
}
};

class ModuleOverride : public Module
class ModuleOverride : public Module, public HidelistEventListener
{
bool RequireKey;
bool NoisyOverride;
Expand Down Expand Up @@ -78,7 +79,8 @@ class ModuleOverride : public Module

public:
ModuleOverride()
: UmodeEnabled(false)
: HidelistEventListener(this)
, UmodeEnabled(false)
, ou(this)
, topiclock(this, "topiclock")
, inviteonly(this, "inviteonly")
Expand Down Expand Up @@ -174,7 +176,14 @@ class ModuleOverride : public Module
{
const Modes::Change& item = *i;
if (!item.param.empty())
{
params.append(1, ' ').append(item.param);
}
else if (item.mh->IsListMode())
{
// Listmode overrides are dealt with in OnListDenied
return MOD_RES_PASSTHRU;
}

char wanted_pm = (item.adding ? '+' : '-');
if (wanted_pm != pm)
Expand All @@ -192,6 +201,21 @@ class ModuleOverride : public Module
return MOD_RES_PASSTHRU;
}

ModResult OnListDenied(User* user, Channel* chan, const std::string& modename) CXX11_OVERRIDE
{
if (!user->IsOper() || !IS_LOCAL(user))
return MOD_RES_PASSTHRU;

if (CanOverride(user, "MODE"))
{
const std::string msg = user->nick + " overriding hidelist: " + modename;

ServerInstance->SNO->WriteGlobalSno('v', msg);
return MOD_RES_ALLOW;
}
return MOD_RES_PASSTHRU;
}

ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven) CXX11_OVERRIDE
{
if (user->IsOper())
Expand Down

0 comments on commit cb386fa

Please sign in to comment.