From 95469fde3055e1a257fd4e1027617892b912d07c Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 12 Mar 2011 02:40:08 -0500 Subject: [PATCH] Added some access checks to cs_mode and fixed some language strings --- modules/core/cs_mode.cpp | 55 ++++++++++++++++++++++++++- modules/core/cs_set_keeptopic.cpp | 4 +- modules/core/cs_set_opnotice.cpp | 4 +- modules/core/cs_set_peace.cpp | 4 +- modules/core/cs_set_private.cpp | 4 +- modules/core/cs_set_restricted.cpp | 4 +- modules/core/cs_set_secure.cpp | 4 +- modules/core/cs_set_securefounder.cpp | 4 +- modules/core/cs_set_secureops.cpp | 4 +- modules/core/cs_set_signkick.cpp | 4 +- modules/core/cs_set_topiclock.cpp | 4 +- modules/core/cs_set_xop.cpp | 4 +- modules/core/ns_set_kill.cpp | 8 ++-- modules/core/ns_set_private.cpp | 4 +- modules/core/ns_set_secure.cpp | 4 +- modules/core/os_set.cpp | 6 +-- 16 files changed, 87 insertions(+), 34 deletions(-) diff --git a/modules/core/cs_mode.cpp b/modules/core/cs_mode.cpp index ad43baf70..209ee751f 100644 --- a/modules/core/cs_mode.cpp +++ b/modules/core/cs_mode.cpp @@ -15,6 +15,27 @@ class CommandCSMode : public Command { + bool CanSet(User *u, ChannelInfo *ci, ChannelModeName mode) + { + switch (mode) + { + case CMODE_OWNER: + return check_access(u, ci, CA_OWNER); + case CMODE_PROTECT: + return check_access(u, ci, CA_PROTECT); + case CMODE_OP: + return check_access(u, ci, CA_OPDEOP); + case CMODE_HALFOP: + return check_access(u, ci, CA_HALFOP); + case CMODE_VOICE: + return check_access(u, ci, CA_VOICE); + default: + break; + } + + return false; + } + void DoLock(CommandSource &source, const std::vector ¶ms) { User *u = source.u; @@ -199,15 +220,35 @@ class CommandCSMode : public Command ci->c->RemoveMode(NULL, cm); break; case MODE_STATUS: + { if (!sep.GetToken(param)) break; + + if (!this->CanSet(u, ci, cm->Name)) + { + source.Reply(_("You do not have access to set mode %c."), cm->ModeChar); + break; + } + + ChanAccess *u_access = ci->GetAccess(u); + int16 u_level = u_access ? u_access->level : 0; + if (str_is_wildcard(param)) { for (CUserList::const_iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) { UserContainer *uc = *it; - if (Anope::Match(u->GetMask(), param)) + ChanAccess *targ_access = ci->GetAccess(uc->user); + int16 t_level = targ_access ? targ_access->level : 0; + + if (t_level > u_level) + { + source.Reply(_("You do not have the access to change %s's modes."), uc->user->nick.c_str()); + continue; + } + + if (Anope::Match(uc->user->GetMask(), param)) { if (adding) ci->c->SetMode(NULL, cm, uc->user->nick); @@ -218,12 +259,24 @@ class CommandCSMode : public Command } else { + User *target = finduser(param); + if (target != NULL) + { + ChanAccess *targ_access = ci->GetAccess(target); + int16 t_level = targ_access ? targ_access->level : 0; + if (t_level > u_level) + { + source.Reply(_("You do not have the access to change %s's modes."), target->nick.c_str()); + break; + } + } if (adding) ci->c->SetMode(NULL, cm, param); else ci->c->RemoveMode(NULL, cm, param); } break; + } case MODE_LIST: if (!sep.GetToken(param)) break; diff --git a/modules/core/cs_set_keeptopic.cpp b/modules/core/cs_set_keeptopic.cpp index 3aa290cb7..049ff1b5f 100644 --- a/modules/core/cs_set_keeptopic.cpp +++ b/modules/core/cs_set_keeptopic.cpp @@ -30,12 +30,12 @@ class CommandCSSetKeepTopic : public Command if (params[1].equals_ci("ON")) { ci->SetFlag(CI_KEEPTOPIC); - source.Reply(_("Topic retention option for %s is now \002\002."), ci->name.c_str()); + source.Reply(_("Topic retention option for %s is now \002on\002."), ci->name.c_str()); } else if (params[1].equals_ci("OFF")) { ci->UnsetFlag(CI_KEEPTOPIC); - source.Reply(_("Topic retention option for %s is now \002\002."), ci->name.c_str()); + source.Reply(_("Topic retention option for %s is now \002off\002."), ci->name.c_str()); } else this->OnSyntaxError(source, "KEEPTOPIC"); diff --git a/modules/core/cs_set_opnotice.cpp b/modules/core/cs_set_opnotice.cpp index 3178e07af..6e0a5d49b 100644 --- a/modules/core/cs_set_opnotice.cpp +++ b/modules/core/cs_set_opnotice.cpp @@ -30,12 +30,12 @@ class CommandCSSetOpNotice : public Command if (params[1].equals_ci("ON")) { ci->SetFlag(CI_OPNOTICE); - source.Reply(_("Op-notice option for %s is now \002\002."), ci->name.c_str()); + source.Reply(_("Op-notice option for %s is now \002on\002."), ci->name.c_str()); } else if (params[1].equals_ci("OFF")) { ci->UnsetFlag(CI_OPNOTICE); - source.Reply(_("Op-notice option for %s is now \002\002."), ci->name.c_str()); + source.Reply(_("Op-notice option for %s is now \002off\002."), ci->name.c_str()); } else this->OnSyntaxError(source, "OPNOTICE"); diff --git a/modules/core/cs_set_peace.cpp b/modules/core/cs_set_peace.cpp index 2039256ac..4b89338ee 100644 --- a/modules/core/cs_set_peace.cpp +++ b/modules/core/cs_set_peace.cpp @@ -30,12 +30,12 @@ class CommandCSSetPeace : public Command if (params[1].equals_ci("ON")) { ci->SetFlag(CI_PEACE); - source.Reply(_("Peace option for %s is now \002\002."), ci->name.c_str()); + source.Reply(_("Peace option for %s is now \002on\002."), ci->name.c_str()); } else if (params[1].equals_ci("OFF")) { ci->UnsetFlag(CI_PEACE); - source.Reply(_("Peace option for %s is now \002\002."), ci->name.c_str()); + source.Reply(_("Peace option for %s is now \002off\002."), ci->name.c_str()); } else this->OnSyntaxError(source, "PEACE"); diff --git a/modules/core/cs_set_private.cpp b/modules/core/cs_set_private.cpp index be75ae4e4..3d1770e2e 100644 --- a/modules/core/cs_set_private.cpp +++ b/modules/core/cs_set_private.cpp @@ -30,12 +30,12 @@ class CommandCSSetPrivate : public Command if (params[1].equals_ci("ON")) { ci->SetFlag(CI_PRIVATE); - source.Reply(_("Private option for %s is now \002\002."), ci->name.c_str()); + source.Reply(_("Private option for %s is now \002on\002."), ci->name.c_str()); } else if (params[1].equals_ci("OFF")) { ci->UnsetFlag(CI_PRIVATE); - source.Reply(_("Private option for %s is now \002\002."), ci->name.c_str()); + source.Reply(_("Private option for %s is now \002off\002."), ci->name.c_str()); } else this->OnSyntaxError(source, "PRIVATE"); diff --git a/modules/core/cs_set_restricted.cpp b/modules/core/cs_set_restricted.cpp index 6632fef4f..cc149449c 100644 --- a/modules/core/cs_set_restricted.cpp +++ b/modules/core/cs_set_restricted.cpp @@ -31,14 +31,14 @@ class CommandCSSetRestricted : public Command ci->SetFlag(CI_RESTRICTED); if (ci->levels[CA_NOJOIN] < 0) ci->levels[CA_NOJOIN] = 0; - source.Reply(_("Restricted access option for %s is now \002\002."), ci->name.c_str()); + source.Reply(_("Restricted access option for %s is now \002on\002."), ci->name.c_str()); } else if (params[1].equals_ci("OFF")) { ci->UnsetFlag(CI_RESTRICTED); if (ci->levels[CA_NOJOIN] >= 0) ci->levels[CA_NOJOIN] = -2; - source.Reply(_("Restricted access option for %s is now \002\002."), ci->name.c_str()); + source.Reply(_("Restricted access option for %s is now \002off\002."), ci->name.c_str()); } else this->OnSyntaxError(source, "RESTRICTED"); diff --git a/modules/core/cs_set_secure.cpp b/modules/core/cs_set_secure.cpp index 1e4c1735e..25977285c 100644 --- a/modules/core/cs_set_secure.cpp +++ b/modules/core/cs_set_secure.cpp @@ -30,12 +30,12 @@ class CommandCSSetSecure : public Command if (params[1].equals_ci("ON")) { ci->SetFlag(CI_SECURE); - source.Reply(_("Secure option for %s is now \002\002."), ci->name.c_str()); + source.Reply(_("Secure option for %s is now \002on\002."), ci->name.c_str()); } else if (params[1].equals_ci("OFF")) { ci->UnsetFlag(CI_SECURE); - source.Reply(_("Secure option for %s is now \002\002."), ci->name.c_str()); + source.Reply(_("Secure option for %s is now \002off\002."), ci->name.c_str()); } else this->OnSyntaxError(source, "SECURE"); diff --git a/modules/core/cs_set_securefounder.cpp b/modules/core/cs_set_securefounder.cpp index c71a7e3e8..44ac0528d 100644 --- a/modules/core/cs_set_securefounder.cpp +++ b/modules/core/cs_set_securefounder.cpp @@ -37,12 +37,12 @@ class CommandCSSetSecureFounder : public Command if (params[1].equals_ci("ON")) { ci->SetFlag(CI_SECUREFOUNDER); - source.Reply(_("Secure founder option for %s is now \002\002."), ci->name.c_str()); + source.Reply(_("Secure founder option for %s is now \002on\002."), ci->name.c_str()); } else if (params[1].equals_ci("OFF")) { ci->UnsetFlag(CI_SECUREFOUNDER); - source.Reply(_("Secure founder option for %s is now \002\002."), ci->name.c_str()); + source.Reply(_("Secure founder option for %s is now \002off\002."), ci->name.c_str()); } else this->OnSyntaxError(source, "SECUREFOUNDER"); diff --git a/modules/core/cs_set_secureops.cpp b/modules/core/cs_set_secureops.cpp index 7b6606922..21fefdb61 100644 --- a/modules/core/cs_set_secureops.cpp +++ b/modules/core/cs_set_secureops.cpp @@ -30,12 +30,12 @@ class CommandCSSetSecureOps : public Command if (params[1].equals_ci("ON")) { ci->SetFlag(CI_SECUREOPS); - source.Reply(_("Secure ops option for %s is now \002\002."), ci->name.c_str()); + source.Reply(_("Secure ops option for %s is now \002on\002."), ci->name.c_str()); } else if (params[1].equals_ci("OFF")) { ci->UnsetFlag(CI_SECUREOPS); - source.Reply(_("Secure ops option for %s is now \002\002."), ci->name.c_str()); + source.Reply(_("Secure ops option for %s is now \002off\002."), ci->name.c_str()); } else this->OnSyntaxError(source, "SECUREOPS"); diff --git a/modules/core/cs_set_signkick.cpp b/modules/core/cs_set_signkick.cpp index 15c56ab09..82f99b6bf 100644 --- a/modules/core/cs_set_signkick.cpp +++ b/modules/core/cs_set_signkick.cpp @@ -31,7 +31,7 @@ class CommandCSSetSignKick : public Command { ci->SetFlag(CI_SIGNKICK); ci->UnsetFlag(CI_SIGNKICK_LEVEL); - source.Reply(_("Signed kick option for %s is now \002\002."), ci->name.c_str()); + source.Reply(_("Signed kick option for %s is now \002on\002."), ci->name.c_str()); } else if (params[1].equals_ci("LEVEL")) { @@ -44,7 +44,7 @@ class CommandCSSetSignKick : public Command { ci->UnsetFlag(CI_SIGNKICK); ci->UnsetFlag(CI_SIGNKICK_LEVEL); - source.Reply(_("Signed kick option for %s is now \002\002."), ci->name.c_str()); + source.Reply(_("Signed kick option for %s is now \002off\002."), ci->name.c_str()); } else this->OnSyntaxError(source, "SIGNKICK"); diff --git a/modules/core/cs_set_topiclock.cpp b/modules/core/cs_set_topiclock.cpp index d47351a50..434d9961d 100644 --- a/modules/core/cs_set_topiclock.cpp +++ b/modules/core/cs_set_topiclock.cpp @@ -30,12 +30,12 @@ class CommandCSSetTopicLock : public Command if (params[1].equals_ci("ON")) { ci->SetFlag(CI_TOPICLOCK); - source.Reply(_("Topic lock option for %s is now \002\002."), ci->name.c_str()); + source.Reply(_("Topic lock option for %s is now \002on\002."), ci->name.c_str()); } else if (params[1].equals_ci("OFF")) { ci->UnsetFlag(CI_TOPICLOCK); - source.Reply(_("Topic lock option for %s is now \002\002."), ci->name.c_str()); + source.Reply(_("Topic lock option for %s is now \002off\002."), ci->name.c_str()); } else this->OnSyntaxError(source, "TOPICLOCK"); diff --git a/modules/core/cs_set_xop.cpp b/modules/core/cs_set_xop.cpp index b7a466583..b4c2657d6 100644 --- a/modules/core/cs_set_xop.cpp +++ b/modules/core/cs_set_xop.cpp @@ -68,14 +68,14 @@ class CommandCSSetXOP : public Command } Log(LOG_COMMAND, u, this, ci) << "to enable XOP"; - source.Reply(_("xOP lists system for %s is now \002\002."), ci->name.c_str()); + source.Reply(_("xOP lists system for %s is now \002on\002."), ci->name.c_str()); } else if (params[1].equals_ci("OFF")) { ci->UnsetFlag(CI_XOP); Log(LOG_COMMAND, u, this, ci) << "to disable XOP"; - source.Reply(_("xOP lists system for %s is now \002\002."), ci->name.c_str()); + source.Reply(_("xOP lists system for %s is now \002off\002."), ci->name.c_str()); } else this->OnSyntaxError(source, "XOP"); diff --git a/modules/core/ns_set_kill.cpp b/modules/core/ns_set_kill.cpp index 2aa9de7aa..c09228992 100644 --- a/modules/core/ns_set_kill.cpp +++ b/modules/core/ns_set_kill.cpp @@ -36,14 +36,14 @@ class CommandNSSetKill : public Command nc->SetFlag(NI_KILLPROTECT); nc->UnsetFlag(NI_KILL_QUICK); nc->UnsetFlag(NI_KILL_IMMED); - source.Reply(_("Protection is now \002\002 for \002%s\002."), nc->display.c_str()); + source.Reply(_("Protection is now \002on\002 for \002%s\002."), nc->display.c_str()); } else if (param.equals_ci("QUICK")) { nc->SetFlag(NI_KILLPROTECT); nc->SetFlag(NI_KILL_QUICK); nc->UnsetFlag(NI_KILL_IMMED); - source.Reply(_("Protection is now \002\002 for \002%s\002, with a reduced delay."), nc->display.c_str()); + source.Reply(_("Protection is now \002on\002 for \002%s\002, with a reduced delay."), nc->display.c_str()); } else if (param.equals_ci("IMMED")) { @@ -52,7 +52,7 @@ class CommandNSSetKill : public Command nc->SetFlag(NI_KILLPROTECT); nc->SetFlag(NI_KILL_IMMED); nc->UnsetFlag(NI_KILL_QUICK); - source.Reply(_("Protection is now \002\002 for \002%s\002, with no delay."), nc->display.c_str()); + source.Reply(_("Protection is now \002on\002 for \002%s\002, with no delay."), nc->display.c_str()); } else source.Reply(_("The \002IMMED\002 option is not available on this network.")); @@ -62,7 +62,7 @@ class CommandNSSetKill : public Command nc->UnsetFlag(NI_KILLPROTECT); nc->UnsetFlag(NI_KILL_QUICK); nc->UnsetFlag(NI_KILL_IMMED); - source.Reply(_("Protection is now \002\002 for \002%s\002."), nc->display.c_str()); + source.Reply(_("Protection is now \002off\002 for \002%s\002."), nc->display.c_str()); } else this->OnSyntaxError(source, "KILL"); diff --git a/modules/core/ns_set_private.cpp b/modules/core/ns_set_private.cpp index 4b8a5fd91..6831d00e1 100644 --- a/modules/core/ns_set_private.cpp +++ b/modules/core/ns_set_private.cpp @@ -33,12 +33,12 @@ class CommandNSSetPrivate : public Command if (param.equals_ci("ON")) { nc->SetFlag(NI_PRIVATE); - source.Reply(_("Private option is now \002\002 for \002%s\002."), nc->display.c_str()); + source.Reply(_("Private option is now \002on\002 for \002%s\002."), nc->display.c_str()); } else if (param.equals_ci("OFF")) { nc->UnsetFlag(NI_PRIVATE); - source.Reply(_("Private option is now \002\002 for \002%s\002."), nc->display.c_str()); + source.Reply(_("Private option is now \002off\002 for \002%s\002."), nc->display.c_str()); } else this->OnSyntaxError(source, "PRIVATE"); diff --git a/modules/core/ns_set_secure.cpp b/modules/core/ns_set_secure.cpp index f9ae1e906..62e7f88a9 100644 --- a/modules/core/ns_set_secure.cpp +++ b/modules/core/ns_set_secure.cpp @@ -33,12 +33,12 @@ class CommandNSSetSecure : public Command if (param.equals_ci("ON")) { nc->SetFlag(NI_SECURE); - source.Reply(_("Secure option is now \002\002 for \002%s\002."), nc->display.c_str()); + source.Reply(_("Secure option is now \002on\002 for \002%s\002."), nc->display.c_str()); } else if (param.equals_ci("OFF")) { nc->UnsetFlag(NI_SECURE); - source.Reply(_("Secure option is now \002\002 for \002%s\002."), nc->display.c_str()); + source.Reply(_("Secure option is now \002off\002 for \002%s\002."), nc->display.c_str()); } else this->OnSyntaxError(source, "SECURE"); diff --git a/modules/core/os_set.cpp b/modules/core/os_set.cpp index c83a3a8b2..cb50aa8fe 100644 --- a/modules/core/os_set.cpp +++ b/modules/core/os_set.cpp @@ -56,7 +56,7 @@ class CommandOSSet : public Command source.Reply(_("Services are now in \002read-write\002 mode.")); } else - source.Reply(_("Setting for READONLY must be \002\002 or \002\002.")); + source.Reply(_("Setting for READONLY must be \002on\002 or \002off\002.")); return MOD_CONT; } @@ -94,7 +94,7 @@ class CommandOSSet : public Command ircdproto->SendGlobops(OperServ, GetString(NULL, _("%s is no longer a Super-Admin")).c_str(), u->nick.c_str()); } else - source.Reply(_("Setting for SuperAdmin must be \002\002 or \002\002 (must be enabled in services.conf)")); + source.Reply(_("Setting for SuperAdmin must be \002on\002 or \002off\002 (must be enabled in services.conf)")); return MOD_CONT; } @@ -163,7 +163,7 @@ class CommandOSSet : public Command source.Reply(_("Services are now in \002expire\002 mode.")); } else - source.Reply(_("Setting for NOEXPIRE must be \002\002 or \002\002.")); + source.Reply(_("Setting for NOEXPIRE must be \002on\002 or \002off\002.")); return MOD_CONT; }