3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-14 07:59:31 +01:00

Support cap-notify and enabling/disabling SASL

This commit is contained in:
Daniel Oaks 2016-10-22 22:18:41 +10:00
parent 1f2cfbee6f
commit b84dbb1a06
7 changed files with 88 additions and 17 deletions

View File

@ -12,6 +12,8 @@ New release of Oragono!
### Added ### Added
* Added `REHASH` command. * Added `REHASH` command.
* Added ability to enable and disable SASL.
* Added support for IRCv3 capability [`cap-notify`](http://ircv3.net/specs/extensions/cap-notify-3.2.html).
### Changed ### Changed

View File

@ -78,7 +78,7 @@ func loadAccount(server *Server, tx *buntdb.Tx, accountKey string) *ClientAccoun
// authenticateHandler parses the AUTHENTICATE command (for SASL authentication). // authenticateHandler parses the AUTHENTICATE command (for SASL authentication).
func authenticateHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool { func authenticateHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
// sasl abort // sasl abort
if len(msg.Params) == 1 && msg.Params[0] == "*" { if !server.authenticationEnabled || len(msg.Params) == 1 && msg.Params[0] == "*" {
if client.saslInProgress { if client.saslInProgress {
client.Send(nil, server.name, ERR_SASLABORTED, client.nick, "SASL authentication aborted") client.Send(nil, server.name, ERR_SASLABORTED, client.nick, "SASL authentication aborted")
} else { } else {

View File

@ -17,6 +17,7 @@ const (
AccountTag Capability = "account-tag" AccountTag Capability = "account-tag"
AccountNotify Capability = "account-notify" AccountNotify Capability = "account-notify"
AwayNotify Capability = "away-notify" AwayNotify Capability = "away-notify"
CapNotify Capability = "cap-notify"
ExtendedJoin Capability = "extended-join" ExtendedJoin Capability = "extended-join"
InviteNotify Capability = "invite-notify" InviteNotify Capability = "invite-notify"
MessageTags Capability = "draft/message-tags" MessageTags Capability = "draft/message-tags"
@ -28,14 +29,15 @@ const (
var ( var (
SupportedCapabilities = CapabilitySet{ SupportedCapabilities = CapabilitySet{
AccountTag: true, AccountTag: true,
AccountNotify: true, AccountNotify: true,
AwayNotify: true, AwayNotify: true,
ExtendedJoin: true, CapNotify: true,
InviteNotify: true, ExtendedJoin: true,
MessageTags: true, InviteNotify: true,
MultiPrefix: true, MessageTags: true,
SASL: true, MultiPrefix: true,
// SASL is set during server startup
ServerTime: true, ServerTime: true,
UserhostInNames: true, UserhostInNames: true,
} }

View File

@ -82,6 +82,24 @@ func (clients *ClientLookupSet) Remove(client *Client) error {
return nil return nil
} }
func (clients *ClientLookupSet) AllWithCaps(caps ...Capability) (set ClientSet) {
set = make(ClientSet)
var client *Client
for _, client = range clients.ByNick {
// make sure they have all the required caps
for _, Cap := range caps {
if !client.capabilities[Cap] {
continue
}
}
set.Add(client)
}
return set
}
func (clients *ClientLookupSet) FindAll(userhost string) (set ClientSet) { func (clients *ClientLookupSet) FindAll(userhost string) (set ClientSet) {
set = make(ClientSet) set = make(ClientSet)

View File

@ -86,6 +86,8 @@ type Config struct {
Path string Path string
} }
AuthenticationEnabled bool `yaml:"authentication-enabled"`
Registration struct { Registration struct {
Accounts AccountRegistrationConfig Accounts AccountRegistrationConfig
} }

View File

@ -60,6 +60,7 @@ type ListenerEvent struct {
// Server is the main Oragono server. // Server is the main Oragono server.
type Server struct { type Server struct {
accounts map[string]*ClientAccount accounts map[string]*ClientAccount
authenticationEnabled bool
channels ChannelNameMap channels ChannelNameMap
clients *ClientLookupSet clients *ClientLookupSet
commands chan Command commands chan Command
@ -110,14 +111,19 @@ func NewServer(configFilename string, config *Config) *Server {
return nil return nil
} }
if config.AuthenticationEnabled {
SupportedCapabilities[SASL] = true
}
server := &Server{ server := &Server{
accounts: make(map[string]*ClientAccount), accounts: make(map[string]*ClientAccount),
channels: make(ChannelNameMap), authenticationEnabled: config.AuthenticationEnabled,
clients: NewClientLookupSet(), channels: make(ChannelNameMap),
commands: make(chan Command), clients: NewClientLookupSet(),
configFilename: configFilename, commands: make(chan Command),
ctime: time.Now(), configFilename: configFilename,
idle: make(chan *Client), ctime: time.Now(),
idle: make(chan *Client),
limits: Limits{ limits: Limits{
AwayLen: int(config.Limits.AwayLen), AwayLen: int(config.Limits.AwayLen),
ChannelLen: int(config.Limits.ChannelLen), ChannelLen: int(config.Limits.ChannelLen),
@ -894,7 +900,45 @@ func (server *Server) rehash() error {
return fmt.Errorf("Error rehashing config file: %s", err.Error()) return fmt.Errorf("Error rehashing config file: %s", err.Error())
} }
//TODO(dan): burst CAP DEL for sasl // setup new and removed caps
addedCaps := make(CapabilitySet)
removedCaps := make(CapabilitySet)
// SASL
if config.AuthenticationEnabled && !server.authenticationEnabled {
// enabling SASL
SupportedCapabilities[SASL] = true
addedCaps[SASL] = true
}
if !config.AuthenticationEnabled && server.authenticationEnabled {
// disabling SASL
SupportedCapabilities[SASL] = false
removedCaps[SASL] = true
}
server.authenticationEnabled = config.AuthenticationEnabled
// burst new and removed caps
var capBurstClients ClientSet
added := make(map[CapVersion]string)
var removed string
if len(addedCaps) > 0 || len(removedCaps) > 0 {
capBurstClients = server.clients.AllWithCaps(CapNotify)
added[Cap301] = addedCaps.String(Cap301)
added[Cap302] = addedCaps.String(Cap302)
// removed never has values
removed = removedCaps.String(Cap301)
}
for sClient := range capBurstClients {
if len(addedCaps) > 0 {
sClient.Send(nil, server.name, "CAP", sClient.nick, "NEW", added[sClient.capVersion])
}
if len(removedCaps) > 0 {
sClient.Send(nil, server.name, "CAP", sClient.nick, "DEL", removed)
}
}
// set server options // set server options
server.limits = Limits{ server.limits = Limits{

View File

@ -41,6 +41,9 @@ server:
# if you change the motd, you should move it to ircd.motd # if you change the motd, you should move it to ircd.motd
motd: oragono.motd motd: oragono.motd
# whether account authentication is enabled
authentication-enabled: true
# account/channel registration # account/channel registration
registration: registration:
# account registration # account registration