3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-29 07:29:31 +01:00
This commit is contained in:
Shivaram Lingamneni 2020-03-18 05:42:52 -04:00
parent 39d3194104
commit 65ebe7f64a
6 changed files with 28 additions and 24 deletions

View File

@ -683,9 +683,9 @@ oper-classes:
# capability names # capability names
capabilities: capabilities:
- "oper:local_kill" - "local_kill"
- "oper:local_ban" - "local_ban"
- "oper:local_unban" - "local_unban"
- "nofakelag" - "nofakelag"
# ircd operators # ircd operators

View File

@ -973,7 +973,7 @@ func (client *Client) HasRoleCapabs(capabs ...string) bool {
} }
for _, capab := range capabs { for _, capab := range capabs {
if !oper.Class.Capabilities[capab] { if !oper.Class.Capabilities.Has(capab) {
return false return false
} }
} }

View File

@ -160,7 +160,7 @@ func init() {
handler: killHandler, handler: killHandler,
minParams: 1, minParams: 1,
oper: true, 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": { "KLINE": {
handler: klineHandler, handler: klineHandler,
@ -289,7 +289,7 @@ func init() {
handler: rehashHandler, handler: rehashHandler,
minParams: 0, minParams: 0,
oper: true, oper: true,
capabs: []string{"oper:rehash"}, capabs: []string{"rehash"},
}, },
"TIME": { "TIME": {
handler: timeHandler, handler: timeHandler,

View File

@ -585,11 +585,15 @@ type Config struct {
type OperClass struct { type OperClass struct {
Title string Title string
WhoisLine string `yaml:"whois-line"` WhoisLine string `yaml:"whois-line"`
Capabilities map[string]bool // map to make lookups much easier Capabilities StringSet // map to make lookups much easier
} }
// OperatorClasses returns a map of assembled operator classes from the given config. // OperatorClasses returns a map of assembled operator classes from the given config.
func (conf *Config) OperatorClasses() (map[string]*OperClass, error) { func (conf *Config) OperatorClasses() (map[string]*OperClass, error) {
fixupCapability := func(capab string) string {
return strings.TrimPrefix(capab, "oper:") // #868
}
ocs := make(map[string]*OperClass) ocs := make(map[string]*OperClass)
// loop from no extends to most extended, breaking if we can't add any more // 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 // create new operclass
var oc OperClass var oc OperClass
oc.Capabilities = make(map[string]bool) oc.Capabilities = make(StringSet)
// get inhereted info from other operclasses // get inhereted info from other operclasses
if len(info.Extends) > 0 { if len(info.Extends) > 0 {
einfo := ocs[info.Extends] einfo := ocs[info.Extends]
for capab := range einfo.Capabilities { for capab := range einfo.Capabilities {
oc.Capabilities[capab] = true oc.Capabilities.Add(fixupCapability(capab))
} }
} }
// add our own info // add our own info
oc.Title = info.Title oc.Title = info.Title
for _, capab := range info.Capabilities { for _, capab := range info.Capabilities {
oc.Capabilities[capab] = true oc.Capabilities.Add(fixupCapability(capab))
} }
if len(info.WhoisLine) > 0 { if len(info.WhoisLine) > 0 {
oc.WhoisLine = info.WhoisLine oc.WhoisLine = info.WhoisLine

View File

@ -716,7 +716,7 @@ func debugHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Res
rb.Notice(fmt.Sprintf("CPU profiling stopped")) rb.Notice(fmt.Sprintf("CPU profiling stopped"))
case "CRASHSERVER": 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")) rb.Notice(client.t("You must have rehash permissions in order to execute DEBUG CRASHSERVER"))
return false 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 { func dlineHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool {
// check oper permissions // check oper permissions
oper := client.Oper() 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")) rb.Add(nil, server.name, ERR_NOPRIVS, client.nick, msg.Command, client.t("Insufficient oper privs"))
return false return false
} }
@ -1229,7 +1229,7 @@ func klineHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Res
details := client.Details() details := client.Details()
// check oper permissions // check oper permissions
oper := client.Oper() 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")) rb.Add(nil, server.name, ERR_NOPRIVS, details.nick, msg.Command, client.t("Insufficient oper privs"))
return false 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 { func unDLineHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool {
// check oper permissions // check oper permissions
oper := client.Oper() 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")) rb.Add(nil, server.name, ERR_NOPRIVS, client.nick, msg.Command, client.t("Insufficient oper privs"))
return false return false
} }
@ -2417,7 +2417,7 @@ func unKLineHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *R
details := client.Details() details := client.Details()
// check oper permissions // check oper permissions
oper := client.Oper() 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")) rb.Add(nil, server.name, ERR_NOPRIVS, details.nick, msg.Command, client.t("Insufficient oper privs"))
return false return false
} }

View File

@ -484,9 +484,9 @@ oper-classes:
# capability names # capability names
capabilities: capabilities:
- "oper:local_kill" - "local_kill"
- "oper:local_ban" - "local_ban"
- "oper:local_unban" - "local_unban"
- "nofakelag" - "nofakelag"
# network operator # network operator
@ -499,9 +499,9 @@ oper-classes:
# capability names # capability names
capabilities: capabilities:
- "oper:remote_kill" - "remote_kill"
- "oper:remote_ban" - "remote_ban"
- "oper:remote_unban" - "remote_unban"
# server admin # server admin
"server-admin": "server-admin":
@ -513,8 +513,8 @@ oper-classes:
# capability names # capability names
capabilities: capabilities:
- "oper:rehash" - "rehash"
- "oper:die" - "die"
- "accreg" - "accreg"
- "sajoin" - "sajoin"
- "samode" - "samode"