Skip to content

Commit

Permalink
[Fix] Sending blank username to ACL in onPublish
Browse files Browse the repository at this point in the history
- Attenmpt to fix VolantMQ#167 partially.
  • Loading branch information
arihantdaga committed Apr 8, 2020
1 parent 99c21c3 commit 0f2968b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion clients/sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,8 @@ func (m *Manager) newSession(cn connection.Initial, params *connection.ConnectPa

if cn.Acknowledge(ack,
connection.KeepAlive(keepAlive),
connection.Permissions(authMngr)) == nil {
connection.Permissions(authMngr),
connection.Username(string(params.Username))) == nil {

ses.start()

Expand Down
4 changes: 3 additions & 1 deletion connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ type SessionCallbacks interface {
type impl struct {
SessionCallbacks
id string
user string
conn transport.Conn
metric metrics.Packets
permissions vlauth.Permissions
Expand Down Expand Up @@ -428,6 +429,7 @@ func (s *impl) onConnect(pkt *mqttp.Connect) error {

params.Username, params.Password = pkt.Credentials()
s.version = params.Version
s.user = string(params.Username)

s.readConnProperties(pkt, params)

Expand Down Expand Up @@ -861,7 +863,7 @@ func (s *impl) onPublish(pkt *mqttp.Publish) (mqttp.IFace, error) {
// - ignore the message but send acks
// - return error leading to disconnect
// TODO: publish permissions
if e := s.permissions.ACL(s.id, "", pkt.Topic(), vlauth.AccessWrite); e != vlauth.StatusAllow {
if e := s.permissions.ACL(s.id, s.user, pkt.Topic(), vlauth.AccessWrite); e != vlauth.StatusAllow {
reason = mqttp.CodeRefusedNotAuthorized
}

Expand Down
7 changes: 7 additions & 0 deletions connection/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,10 @@ func Permissions(val vlauth.Permissions) Option {
return nil
}
}

func Username(val string) Option {
return func(t *impl) error {
t.user = val
return nil
}
}

0 comments on commit 0f2968b

Please sign in to comment.