Merge pull request #9124 from JimMoen/sub-acl-warning-log

Sub acl warning log
This commit is contained in:
JimMoen 2022-10-11 10:04:26 +08:00 committed by GitHub
commit f51e2c7f95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -39,6 +39,8 @@ File format:
- Added a test to prevent a last will testament message to be
published when a client is denied connection. [#8894](https://github.com/emqx/emqx/pull/8894)
- Add warning log if the acl check of a subscribed topic failed. [#9124](https://github.com/emqx/emqx/pull/9124)
### Bug fixes
- Fix delayed publish inaccurate caused by os time change. [#8908](https://github.com/emqx/emqx/pull/8908)

View File

@ -1501,12 +1501,15 @@ check_pub_caps(#mqtt_packet{header = #mqtt_packet_header{qos = QoS,
check_sub_acls(TopicFilters, Channel) ->
check_sub_acls(TopicFilters, Channel, []).
check_sub_acls([ TopicFilter = {Topic, _} | More] , Channel, Acc) ->
check_sub_acls([ TopicFilter = {Topic, SubOpts} | More] , Channel, Acc) ->
case check_sub_acl(Topic, Channel) of
allow ->
check_sub_acls(More, Channel, [ {TopicFilter, 0} | Acc]);
deny ->
check_sub_acls(More, Channel, [ {TopicFilter, ?RC_NOT_AUTHORIZED} | Acc])
ReasonCode = ?RC_NOT_AUTHORIZED,
?LOG(warning, "Cannot subscribe ~s with options ~p due to ~s.",
[Topic, SubOpts, emqx_reason_codes:text(ReasonCode)]),
check_sub_acls(More, Channel, [ {TopicFilter, ReasonCode} | Acc])
end;
check_sub_acls([], _Channel, Acc) ->
lists:reverse(Acc).