Commit 6075860a9793299be3d89942a7d139f9e2d74c13

Authored by Wiebe Cazemier
1 parent e8e10352

Better handling of the allow_anonymous setting

authplugin.cpp
... ... @@ -454,7 +454,7 @@ AuthResult Authentication::aclCheckFromMosquittoAclFile(const std::string &clien
454 454  
455 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 458 return AuthResult::success;
459 459  
460 460 if (!this->mosquittoPasswordEntries)
... ...
mainapp.cpp
... ... @@ -434,6 +434,8 @@ void MainApp::start()
434 434 // No threads for execution stability/determinism.
435 435 num_threads = 0;
436 436  
  437 + settings->allowAnonymous = true;
  438 +
437 439 int fd = open(fuzzFilePath.c_str(), O_RDONLY);
438 440 assert(fd > 0);
439 441  
... ...
mqttpacket.cpp
... ... @@ -349,7 +349,11 @@ void MqttPacket::handleConnect()
349 349 bool accessGranted = false;
350 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 358 denyLogMsg = formatString("Username '%s' has + or # in the id and 'allow_unsafe_username_chars' is false.", username.c_str());
355 359 sender->setDisconnectReason("Invalid username character");
... ...