3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-29 15:40:02 +01:00

modes: Add TLS umode (+Z)

This commit is contained in:
Daniel Oaks 2016-06-29 01:09:07 +10:00
parent a4236fcddd
commit b820559050
4 changed files with 30 additions and 8 deletions

View File

@ -18,6 +18,7 @@ Initial release of Oragono!
* Added ability to generate certificates from the command line. * Added ability to generate certificates from the command line.
* We now advertise the [`RPL_ISUPPORT`](http://modern.ircdocs.horse/#rplisupport-005) numeric. * We now advertise the [`RPL_ISUPPORT`](http://modern.ircdocs.horse/#rplisupport-005) numeric.
* Parse new mode change syntax commonly used these days (i.e. `+h-ov dan dan dan`). * Parse new mode change syntax commonly used these days (i.e. `+h-ov dan dan dan`).
* User mode for clients connected via TLS (`+Z`).
### Changed ### Changed
* Added channel Founder/Admin/Halfops (`qah`) privileges, and removed channel creator (`O`) privilege (from RFC2812, not used in the real world). * Added channel Founder/Admin/Halfops (`qah`) privileges, and removed channel creator (`O`) privilege (from RFC2812, not used in the real world).

View File

@ -44,7 +44,7 @@ type Client struct {
isDestroyed bool isDestroyed bool
} }
func NewClient(server *Server, conn net.Conn) *Client { func NewClient(server *Server, conn net.Conn, isTLS bool) *Client {
now := time.Now() now := time.Now()
socket := NewSocket(conn) socket := NewSocket(conn)
client := &Client{ client := &Client{
@ -59,6 +59,9 @@ func NewClient(server *Server, conn net.Conn) *Client {
socket: &socket, socket: &socket,
nickString: "*", // * is used until actual nick is given nickString: "*", // * is used until actual nick is given
} }
if isTLS {
client.flags[TLS] = true
}
client.Touch() client.Touch()
go client.run() go client.run()

View File

@ -143,6 +143,7 @@ const (
Operator UserMode = 'o' Operator UserMode = 'o'
Restricted UserMode = 'r' Restricted UserMode = 'r'
ServerNotice UserMode = 's' // deprecated ServerNotice UserMode = 's' // deprecated
TLS UserMode = 'Z'
WallOps UserMode = 'w' WallOps UserMode = 'w'
) )
@ -292,11 +293,13 @@ func umodeHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
applied = append(applied, change) applied = append(applied, change)
} }
} }
// can't do anything to TLS mode
} }
} }
if len(changes) > 0 { if len(applied) > 0 {
client.Send(nil, client.nickMaskString, "MODE", target.nickString, changes.String()) client.Send(nil, client.nickMaskString, "MODE", target.nickString, applied.String())
} else if client == target { } else if client == target {
client.Send(nil, target.nickMaskString, RPL_UMODEIS, target.nickString, target.ModeString()) client.Send(nil, target.nickMaskString, RPL_UMODEIS, target.nickString, target.ModeString())
} }

View File

@ -33,7 +33,7 @@ type Server struct {
motdLines []string motdLines []string
name Name name Name
nameString string // cache for server name string since it's used with almost every reply nameString string // cache for server name string since it's used with almost every reply
newConns chan net.Conn newConns chan clientConn
operators map[Name][]byte operators map[Name][]byte
password []byte password []byte
signals chan os.Signal signals chan os.Signal
@ -48,6 +48,11 @@ var (
syscall.SIGTERM, syscall.SIGQUIT} syscall.SIGTERM, syscall.SIGQUIT}
) )
type clientConn struct {
Conn net.Conn
IsTLS bool
}
func NewServer(config *Config) *Server { func NewServer(config *Config) *Server {
server := &Server{ server := &Server{
channels: make(ChannelNameMap), channels: make(ChannelNameMap),
@ -58,7 +63,7 @@ func NewServer(config *Config) *Server {
idle: make(chan *Client), idle: make(chan *Client),
name: NewName(config.Server.Name), name: NewName(config.Server.Name),
nameString: NewName(config.Server.Name).String(), nameString: NewName(config.Server.Name).String(),
newConns: make(chan net.Conn), newConns: make(chan clientConn),
operators: config.Operators(), operators: config.Operators(),
signals: make(chan os.Signal, len(SERVER_SIGNALS)), signals: make(chan os.Signal, len(SERVER_SIGNALS)),
proxyAllowedFrom: config.Server.ProxyAllowedFrom, proxyAllowedFrom: config.Server.ProxyAllowedFrom,
@ -180,7 +185,7 @@ func (server *Server) Run() {
done = true done = true
case conn := <-server.newConns: case conn := <-server.newConns:
NewClient(server, conn) NewClient(server, conn.Conn, conn.IsTLS)
/*TODO(dan): LOOK AT THIS MORE CLOSELY /*TODO(dan): LOOK AT THIS MORE CLOSELY
case cmd := <-server.commands: case cmd := <-server.commands:
@ -221,7 +226,12 @@ func (s *Server) listen(addr string, tlsMap map[Name]*tls.Config) {
} }
Log.debug.Printf("%s accept: %s", s, conn.RemoteAddr()) Log.debug.Printf("%s accept: %s", s, conn.RemoteAddr())
s.newConns <- conn newConn := clientConn{
Conn: conn,
IsTLS: listenTLS,
}
s.newConns <- newConn
} }
}() }()
} }
@ -250,7 +260,11 @@ func (s *Server) wslisten(addr string, tlsMap map[string]*TLSListenConfig) {
return return
} }
s.newConns <- WSContainer{ws} newConn := clientConn{
Conn: WSContainer{ws},
IsTLS: false, //TODO(dan): track TLS or not here properly
}
s.newConns <- newConn
}) })
go func() { go func() {
config, listenTLS := tlsMap[addr] config, listenTLS := tlsMap[addr]
@ -294,6 +308,7 @@ func (s *Server) tryRegister(c *Client) {
c.Send(nil, s.nameString, RPL_MYINFO, c.nickString, s.nameString, SEM_VER, supportedUserModesString, supportedChannelModesString) c.Send(nil, s.nameString, RPL_MYINFO, c.nickString, s.nameString, SEM_VER, supportedUserModesString, supportedChannelModesString)
c.RplISupport() c.RplISupport()
s.MOTD(c) s.MOTD(c)
c.Send(nil, c.nickMaskString, RPL_UMODEIS, c.nickString, c.ModeString())
} }
func (server *Server) MOTD(client *Client) { func (server *Server) MOTD(client *Client) {