From 8e7736b78ee1f5d518b87bc206e9d23a454faef5 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Fri, 1 Aug 2014 21:34:21 +0100 Subject: [PATCH] Fix incorrect handling of anonymous bridges on the local broker. Thanks to Jan-Piet Mens. --- ChangeLog.txt | 7 +++++++ src/bridge.c | 31 ++++++++++++++++++------------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index fe735351..c797a3e3 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,10 @@ +1.3.3 - 20140801 +================ + +Broker: +- Fix incorrect handling of anonymous bridges on the local broker. + + 1.3.2 - 20140713 ================ diff --git a/src/bridge.c b/src/bridge.c index 095a15ea..49cffbd7 100644 --- a/src/bridge.c +++ b/src/bridge.c @@ -162,19 +162,24 @@ int mqtt3_bridge_connect(struct mosquitto_db *db, struct mosquitto *context) mqtt3_db_messages_delete(context); } - rc = mosquitto_unpwd_check(db, context->bridge->local_username, context->bridge->local_password); - switch(rc){ - case MOSQ_ERR_SUCCESS: - break; - case MOSQ_ERR_AUTH: - _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Bridge %s failed authentication on local broker.", context->id); - return rc; - case MOSQ_ERR_UNKNOWN: - _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Bridge %s returned application error in authorisation.", context->id); - return rc; - default: - _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Unknown error in authentication for bridge %s.", context->id); - return rc; + if(context->bridge->local_username){ + rc = mosquitto_unpwd_check(db, context->bridge->local_username, context->bridge->local_password); + switch(rc){ + case MOSQ_ERR_SUCCESS: + break; + case MOSQ_ERR_AUTH: + _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Bridge %s failed authentication on local broker.", context->id); + return rc; + case MOSQ_ERR_UNKNOWN: + _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Bridge %s returned application error in authorisation.", context->id); + return rc; + default: + _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Unknown error in authentication for bridge %s.", context->id); + return rc; + } + }else if(!db->config->allow_anonymous){ + _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Bridge %s requires a username on local broker.", context->id); + return MOSQ_ERR_AUTH; } /* Delete all local subscriptions even for clean_session==false. We don't