Commit 6075860a9793299be3d89942a7d139f9e2d74c13
1 parent
e8e10352
Better handling of the allow_anonymous setting
Showing
3 changed files
with
8 additions
and
2 deletions
authplugin.cpp
| @@ -454,7 +454,7 @@ AuthResult Authentication::aclCheckFromMosquittoAclFile(const std::string &clien | @@ -454,7 +454,7 @@ AuthResult Authentication::aclCheckFromMosquittoAclFile(const std::string &clien | ||
| 454 | 454 | ||
| 455 | AuthResult Authentication::unPwdCheckFromMosquittoPasswordFile(const std::string &username, const std::string &password) | 455 | AuthResult Authentication::unPwdCheckFromMosquittoPasswordFile(const std::string &username, const std::string &password) |
| 456 | { | 456 | { |
| 457 | - if (this->mosquittoPasswordFile.empty()) | 457 | + if (this->mosquittoPasswordFile.empty() && settings.allowAnonymous) |
| 458 | return AuthResult::success; | 458 | return AuthResult::success; |
| 459 | 459 | ||
| 460 | if (!this->mosquittoPasswordEntries) | 460 | if (!this->mosquittoPasswordEntries) |
mainapp.cpp
| @@ -434,6 +434,8 @@ void MainApp::start() | @@ -434,6 +434,8 @@ void MainApp::start() | ||
| 434 | // No threads for execution stability/determinism. | 434 | // No threads for execution stability/determinism. |
| 435 | num_threads = 0; | 435 | num_threads = 0; |
| 436 | 436 | ||
| 437 | + settings->allowAnonymous = true; | ||
| 438 | + | ||
| 437 | int fd = open(fuzzFilePath.c_str(), O_RDONLY); | 439 | int fd = open(fuzzFilePath.c_str(), O_RDONLY); |
| 438 | assert(fd > 0); | 440 | assert(fd > 0); |
| 439 | 441 |
mqttpacket.cpp
| @@ -349,7 +349,11 @@ void MqttPacket::handleConnect() | @@ -349,7 +349,11 @@ void MqttPacket::handleConnect() | ||
| 349 | bool accessGranted = false; | 349 | bool accessGranted = false; |
| 350 | std::string denyLogMsg; | 350 | std::string denyLogMsg; |
| 351 | 351 | ||
| 352 | - if (!settings.allowUnsafeUsernameChars && containsDangerousCharacters(username)) | 352 | + if (!user_name_flag && settings.allowAnonymous) |
| 353 | + { | ||
| 354 | + accessGranted = true; | ||
| 355 | + } | ||
| 356 | + else if (!settings.allowUnsafeUsernameChars && containsDangerousCharacters(username)) | ||
| 353 | { | 357 | { |
| 354 | denyLogMsg = formatString("Username '%s' has + or # in the id and 'allow_unsafe_username_chars' is false.", username.c_str()); | 358 | denyLogMsg = formatString("Username '%s' has + or # in the id and 'allow_unsafe_username_chars' is false.", username.c_str()); |
| 355 | sender->setDisconnectReason("Invalid username character"); | 359 | sender->setDisconnectReason("Invalid username character"); |