Merge pull request #1317 from slingamn/hidden_userhost

USERHOST needs to respect hidden operators as well
This commit is contained in:
Shivaram Lingamneni 2020-10-09 11:34:35 -07:00 committed by GitHub
commit 4336f56204
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 10 deletions

View File

@ -728,11 +728,6 @@ type Oper struct {
Modes []modes.ModeChange Modes []modes.ModeChange
} }
// returns whether this is a publicly visible operator, for WHO/WHOIS purposes
func (oper *Oper) Visible(hasPrivs bool) bool {
return oper != nil && (hasPrivs || !oper.Hidden)
}
// Operators returns a map of operator configs from the given OperClass and config. // Operators returns a map of operator configs from the given OperClass and config.
func (conf *Config) Operators(oc map[string]*OperClass) (map[string]*Oper, error) { func (conf *Config) Operators(oc map[string]*OperClass) (map[string]*Oper, error) {
operators := make(map[string]*Oper) operators := make(map[string]*Oper)

View File

@ -2878,8 +2878,21 @@ func userHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Resp
return false return false
} }
// does `target` have an operator status that is visible to `client`?
func operStatusVisible(client, target *Client, hasPrivs bool) bool {
targetOper := target.Oper()
if targetOper == nil {
return false
}
if client == target || hasPrivs {
return true
}
return !targetOper.Hidden
}
// USERHOST <nickname>{ <nickname>} // USERHOST <nickname>{ <nickname>}
func userhostHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool { func userhostHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool {
hasPrivs := client.HasMode(modes.Operator) // TODO(#1176) figure out the right capab for this
returnedClients := make(ClientSet) returnedClients := make(ClientSet)
var tl utils.TokenLineBuilder var tl utils.TokenLineBuilder
@ -2901,7 +2914,7 @@ func userhostHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *
var isOper, isAway string var isOper, isAway string
if target.HasMode(modes.Operator) { if operStatusVisible(client, target, hasPrivs) {
isOper = "*" isOper = "*"
} }
if away, _ := target.Away(); away { if away, _ := target.Away(); away {
@ -3061,7 +3074,7 @@ func (client *Client) rplWhoReply(channel *Channel, target *Client, rb *Response
flags.WriteRune('H') // Here flags.WriteRune('H') // Here
} }
if target.HasMode(modes.Operator) && target.Oper().Visible(hasPrivs) { if target.HasMode(modes.Operator) && operStatusVisible(client, target, hasPrivs) {
flags.WriteRune('*') flags.WriteRune('*')
} }

View File

@ -439,10 +439,12 @@ func (client *Client) getWhoisOf(target *Client, hasPrivs bool, rb *ResponseBuff
if whoischannels != nil { if whoischannels != nil {
rb.Add(nil, client.server.name, RPL_WHOISCHANNELS, cnick, tnick, strings.Join(whoischannels, " ")) rb.Add(nil, client.server.name, RPL_WHOISCHANNELS, cnick, tnick, strings.Join(whoischannels, " "))
} }
if target.HasMode(modes.Operator) && operStatusVisible(client, target, hasPrivs) {
tOper := target.Oper() tOper := target.Oper()
if tOper.Visible(hasPrivs) { if tOper != nil {
rb.Add(nil, client.server.name, RPL_WHOISOPERATOR, cnick, tnick, tOper.WhoisLine) rb.Add(nil, client.server.name, RPL_WHOISOPERATOR, cnick, tnick, tOper.WhoisLine)
} }
}
if client == target || hasPrivs { if client == target || hasPrivs {
rb.Add(nil, client.server.name, RPL_WHOISACTUALLY, cnick, tnick, fmt.Sprintf("%s@%s", targetInfo.username, target.RawHostname()), target.IPString(), client.t("Actual user@host, Actual IP")) rb.Add(nil, client.server.name, RPL_WHOISACTUALLY, cnick, tnick, fmt.Sprintf("%s@%s", targetInfo.username, target.RawHostname()), target.IPString(), client.t("Actual user@host, Actual IP"))
} }