From 65ebe7f64a7cc4c2744eb7ef668f2db50647b7bc Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Wed, 18 Mar 2020 05:42:52 -0400 Subject: [PATCH] fix #868 --- docs/MANUAL.md | 6 +++--- irc/client.go | 2 +- irc/commands.go | 4 ++-- irc/config.go | 14 +++++++++----- irc/handlers.go | 10 +++++----- oragono.yaml | 16 ++++++++-------- 6 files changed, 28 insertions(+), 24 deletions(-) diff --git a/docs/MANUAL.md b/docs/MANUAL.md index 72b30dce..cc27ab9e 100644 --- a/docs/MANUAL.md +++ b/docs/MANUAL.md @@ -683,9 +683,9 @@ oper-classes: # capability names capabilities: - - "oper:local_kill" - - "oper:local_ban" - - "oper:local_unban" + - "local_kill" + - "local_ban" + - "local_unban" - "nofakelag" # ircd operators diff --git a/irc/client.go b/irc/client.go index 1b3ed395..999343a2 100644 --- a/irc/client.go +++ b/irc/client.go @@ -973,7 +973,7 @@ func (client *Client) HasRoleCapabs(capabs ...string) bool { } for _, capab := range capabs { - if !oper.Class.Capabilities[capab] { + if !oper.Class.Capabilities.Has(capab) { return false } } diff --git a/irc/commands.go b/irc/commands.go index cdc7804f..f89b55eb 100644 --- a/irc/commands.go +++ b/irc/commands.go @@ -160,7 +160,7 @@ func init() { handler: killHandler, minParams: 1, oper: true, - capabs: []string{"oper:local_kill"}, //TODO(dan): when we have S2S, this will be checked in the command handler itself + capabs: []string{"local_kill"}, //TODO(dan): when we have S2S, this will be checked in the command handler itself }, "KLINE": { handler: klineHandler, @@ -289,7 +289,7 @@ func init() { handler: rehashHandler, minParams: 0, oper: true, - capabs: []string{"oper:rehash"}, + capabs: []string{"rehash"}, }, "TIME": { handler: timeHandler, diff --git a/irc/config.go b/irc/config.go index 9d5e9331..7bd050df 100644 --- a/irc/config.go +++ b/irc/config.go @@ -584,12 +584,16 @@ type Config struct { // OperClass defines an assembled operator class. type OperClass struct { Title string - WhoisLine string `yaml:"whois-line"` - Capabilities map[string]bool // map to make lookups much easier + WhoisLine string `yaml:"whois-line"` + Capabilities StringSet // map to make lookups much easier } // OperatorClasses returns a map of assembled operator classes from the given config. func (conf *Config) OperatorClasses() (map[string]*OperClass, error) { + fixupCapability := func(capab string) string { + return strings.TrimPrefix(capab, "oper:") // #868 + } + ocs := make(map[string]*OperClass) // loop from no extends to most extended, breaking if we can't add any more @@ -619,21 +623,21 @@ func (conf *Config) OperatorClasses() (map[string]*OperClass, error) { // create new operclass var oc OperClass - oc.Capabilities = make(map[string]bool) + oc.Capabilities = make(StringSet) // get inhereted info from other operclasses if len(info.Extends) > 0 { einfo := ocs[info.Extends] for capab := range einfo.Capabilities { - oc.Capabilities[capab] = true + oc.Capabilities.Add(fixupCapability(capab)) } } // add our own info oc.Title = info.Title for _, capab := range info.Capabilities { - oc.Capabilities[capab] = true + oc.Capabilities.Add(fixupCapability(capab)) } if len(info.WhoisLine) > 0 { oc.WhoisLine = info.WhoisLine diff --git a/irc/handlers.go b/irc/handlers.go index 41255995..f00853e5 100644 --- a/irc/handlers.go +++ b/irc/handlers.go @@ -716,7 +716,7 @@ func debugHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Res rb.Notice(fmt.Sprintf("CPU profiling stopped")) case "CRASHSERVER": - if !client.HasRoleCapabs("oper:rehash") { + if !client.HasRoleCapabs("rehash") { rb.Notice(client.t("You must have rehash permissions in order to execute DEBUG CRASHSERVER")) return false } @@ -770,7 +770,7 @@ func formatBanForListing(client *Client, key string, info IPBanInfo) string { func dlineHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool { // check oper permissions oper := client.Oper() - if oper == nil || !oper.Class.Capabilities["oper:local_ban"] { + if oper == nil || !oper.Class.Capabilities.Has("local_ban") { rb.Add(nil, server.name, ERR_NOPRIVS, client.nick, msg.Command, client.t("Insufficient oper privs")) return false } @@ -1229,7 +1229,7 @@ func klineHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Res details := client.Details() // check oper permissions oper := client.Oper() - if oper == nil || !oper.Class.Capabilities["oper:local_ban"] { + if oper == nil || !oper.Class.Capabilities.Has("local_ban") { rb.Add(nil, server.name, ERR_NOPRIVS, details.nick, msg.Command, client.t("Insufficient oper privs")) return false } @@ -2383,7 +2383,7 @@ func topicHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Res func unDLineHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool { // check oper permissions oper := client.Oper() - if oper == nil || !oper.Class.Capabilities["oper:local_unban"] { + if oper == nil || !oper.Class.Capabilities.Has("local_unban") { rb.Add(nil, server.name, ERR_NOPRIVS, client.nick, msg.Command, client.t("Insufficient oper privs")) return false } @@ -2417,7 +2417,7 @@ func unKLineHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *R details := client.Details() // check oper permissions oper := client.Oper() - if oper == nil || !oper.Class.Capabilities["oper:local_unban"] { + if oper == nil || !oper.Class.Capabilities.Has("local_unban") { rb.Add(nil, server.name, ERR_NOPRIVS, details.nick, msg.Command, client.t("Insufficient oper privs")) return false } diff --git a/oragono.yaml b/oragono.yaml index 4df55c55..048fcfc9 100644 --- a/oragono.yaml +++ b/oragono.yaml @@ -484,9 +484,9 @@ oper-classes: # capability names capabilities: - - "oper:local_kill" - - "oper:local_ban" - - "oper:local_unban" + - "local_kill" + - "local_ban" + - "local_unban" - "nofakelag" # network operator @@ -499,9 +499,9 @@ oper-classes: # capability names capabilities: - - "oper:remote_kill" - - "oper:remote_ban" - - "oper:remote_unban" + - "remote_kill" + - "remote_ban" + - "remote_unban" # server admin "server-admin": @@ -513,8 +513,8 @@ oper-classes: # capability names capabilities: - - "oper:rehash" - - "oper:die" + - "rehash" + - "die" - "accreg" - "sajoin" - "samode"