Skip to content

Commit

Permalink
Fix xclient allowproxy.
Browse files Browse the repository at this point in the history
  • Loading branch information
linanh committed Aug 30, 2021
1 parent e8702fe commit ed924a1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ type ProxySession interface {
// This is similar to ProxyBackend.AllowProxy but called instead of it if
// Session is already created for the user. Session.Logout will be
// called if this function returns true.
AllowProxy(asserted ConnectionState, sid string) bool
AllowProxy(asserted ConnectionState) bool
}

// LMTPSession is an add-on interface for Session. It can be implemented by
Expand Down
24 changes: 12 additions & 12 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -1279,20 +1279,20 @@ func (c *Conn) handleXclient(arg string) {
c.locker.Lock()
defer c.locker.Unlock()

sessCheckAllowProxy := false
if c.session != nil {
// We safely check ProxyBackend before and require backends to implement both or none.
se := c.session.(ProxySession)

if !se.AllowProxy(*connState, c.sid) {
c.server.Logger.Infof("smtp/server sid=%s reject: addr=%s xclient-addr=%s not permitted",
c.sid, c.conn.RemoteAddr().String(), connState.RemoteAddr.String())
c.WriteResponse(550, EnhancedCode{5, 7, 0}, "XCLIENT not permitted")
return
se, ok := c.session.(ProxySession)
if ok {
sessCheckAllowProxy = true
if !se.AllowProxy(*connState) {
c.server.Logger.Infof("smtp/server sid=%s reject: addr=%s xclient-addr=%s not permitted",
c.sid, c.conn.RemoteAddr().String(), connState.RemoteAddr.String())
c.WriteResponse(550, EnhancedCode{5, 7, 0}, "XCLIENT not permitted")
return
}
}

c.session.Logout()
c.session = nil
} else {
}
if !sessCheckAllowProxy {
if !be.AllowProxy(c.State(), *connState, c.sid) {
c.server.Logger.Infof("smtp/server sid=%s reject: addr=%s xclient-addr=%s not permitted",
c.sid, c.conn.RemoteAddr().String(), connState.RemoteAddr.String())
Expand Down

0 comments on commit ed924a1

Please sign in to comment.