Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix oper override message when viewing a list mode #1418

Open
wants to merge 1 commit into
base: insp3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 38 additions & 0 deletions include/modules/hidelist.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* InspIRCd -- Internet Relay Chat Daemon
*
* Copyright (C) 2019 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 when an attempt to display a listmode will be denied
* @param user The user executing the list
* @param chan The channel the list is being requested on
* @param modename The name of the mode being listed
*/
virtual ModResult OnListDeny(User* user, Channel* chan, const std::string& modename) = 0;
};
9 changes: 9 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,12 @@ class ListWatcher : public ModeWatcher
if (user->HasPrivPermission("channels/auspex"))
return true;

ModResult MOD_RESULT;
FOREACH_MOD_CUSTOM(evprov, HideListEventListener, OnListDeny, (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
29 changes: 26 additions & 3 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,8 +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 OnListDeny
return MOD_RES_PASSTHRU;
}
char wanted_pm = (item.adding ? '+' : '-');
if (wanted_pm != pm)
{
Expand All @@ -192,6 +200,21 @@ class ModuleOverride : public Module
return MOD_RES_PASSTHRU;
}

ModResult OnListDeny(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