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 `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

View File

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

View File

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

View File

@ -82,6 +82,24 @@ func (clients *ClientLookupSet) Remove(client *Client) error {
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) {
set = make(ClientSet)

View File

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

View File

@ -60,6 +60,7 @@ type ListenerEvent struct {
// Server is the main Oragono server.
type Server struct {
accounts map[string]*ClientAccount
authenticationEnabled bool
channels ChannelNameMap
clients *ClientLookupSet
commands chan Command
@ -110,8 +111,13 @@ func NewServer(configFilename string, config *Config) *Server {
return nil
}
if config.AuthenticationEnabled {
SupportedCapabilities[SASL] = true
}
server := &Server{
accounts: make(map[string]*ClientAccount),
authenticationEnabled: config.AuthenticationEnabled,
channels: make(ChannelNameMap),
clients: NewClientLookupSet(),
commands: make(chan Command),
@ -894,7 +900,45 @@ func (server *Server) rehash() 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
server.limits = Limits{

View File

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