mirror of
https://github.com/ergochat/ergo.git
synced 2024-12-22 10:42:52 +01:00
Support cap-notify and enabling/disabling SASL
This commit is contained in:
parent
1f2cfbee6f
commit
b84dbb1a06
@ -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
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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"
|
||||
@ -28,14 +29,15 @@ const (
|
||||
|
||||
var (
|
||||
SupportedCapabilities = CapabilitySet{
|
||||
AccountTag: true,
|
||||
AccountNotify: true,
|
||||
AwayNotify: true,
|
||||
ExtendedJoin: true,
|
||||
InviteNotify: true,
|
||||
MessageTags: true,
|
||||
MultiPrefix: true,
|
||||
SASL: true,
|
||||
AccountTag: true,
|
||||
AccountNotify: true,
|
||||
AwayNotify: true,
|
||||
CapNotify: true,
|
||||
ExtendedJoin: true,
|
||||
InviteNotify: true,
|
||||
MessageTags: true,
|
||||
MultiPrefix: true,
|
||||
// SASL is set during server startup
|
||||
ServerTime: true,
|
||||
UserhostInNames: true,
|
||||
}
|
||||
|
@ -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)
|
||||
|
||||
|
@ -86,6 +86,8 @@ type Config struct {
|
||||
Path string
|
||||
}
|
||||
|
||||
AuthenticationEnabled bool `yaml:"authentication-enabled"`
|
||||
|
||||
Registration struct {
|
||||
Accounts AccountRegistrationConfig
|
||||
}
|
||||
|
@ -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,14 +111,19 @@ func NewServer(configFilename string, config *Config) *Server {
|
||||
return nil
|
||||
}
|
||||
|
||||
if config.AuthenticationEnabled {
|
||||
SupportedCapabilities[SASL] = true
|
||||
}
|
||||
|
||||
server := &Server{
|
||||
accounts: make(map[string]*ClientAccount),
|
||||
channels: make(ChannelNameMap),
|
||||
clients: NewClientLookupSet(),
|
||||
commands: make(chan Command),
|
||||
configFilename: configFilename,
|
||||
ctime: time.Now(),
|
||||
idle: make(chan *Client),
|
||||
accounts: make(map[string]*ClientAccount),
|
||||
authenticationEnabled: config.AuthenticationEnabled,
|
||||
channels: make(ChannelNameMap),
|
||||
clients: NewClientLookupSet(),
|
||||
commands: make(chan Command),
|
||||
configFilename: configFilename,
|
||||
ctime: time.Now(),
|
||||
idle: make(chan *Client),
|
||||
limits: Limits{
|
||||
AwayLen: int(config.Limits.AwayLen),
|
||||
ChannelLen: int(config.Limits.ChannelLen),
|
||||
@ -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{
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user