Merge branch 'fixes'

pull/1082/head
Roger A. Light 7 years ago
commit d28834d541

@ -11,7 +11,7 @@ project(mosquitto)
cmake_minimum_required(VERSION 2.8)
# Only for version 3 and up. cmake_policy(SET CMP0042 NEW)
set (VERSION 1.5.4)
set (VERSION 1.5.5)
add_definitions (-DCMAKE -DVERSION=\"${VERSION}\")

@ -1,3 +1,39 @@
1.5.5 - 20181211
================
Security:
- If `per_listener_settings` is set to true, then the `acl_file` setting was
ignored for the "default listener" only. This has been fixed. This does not
affect any listeners defined with the `listener` option. Closes #1073.
Broker:
- Add `socket_domain` option to allow listeners to disable IPv6 support.
This is required to work around a problem in libwebsockets that means
sockets only listen on IPv6 by default if IPv6 support is compiled in.
Closes #1004.
- When using ADNS, don't ask for all network protocols when connecting,
because this can lead to confusing "Protocol not supported" errors if the
network is down. Closes #1062.
- Fix outgoing retained messages not being sent by bridges on initial
connection. Closes #1040.
- Don't reload auth_opt_ options on reload, to match the behaviour of the
other plugin options. Closes #1068.
- Print message on error when installing/uninstalling as a Windows service.
- All non-error connect/disconnect messages are controlled by the
`connection_messages` option. Closes #772. Closes #613. Closes #537.
Library:
- Fix reconnect delay backoff behaviour. Closes #1027.
- Don't call on_disconnect() twice if keepalive tests fail. Closes #1067.
Client:
- Always print leading zeros in mosquitto_sub when output format is hex.
Closes #1066.
Build:
- Fix building where TLS-PSK is not available. Closes #68.
1.5.4 - 20181108
================

@ -151,7 +151,7 @@ void client_config_cleanup(struct mosq_config *cfg)
free(cfg->keyfile);
free(cfg->ciphers);
free(cfg->tls_version);
# ifdef WITH_TLS_PSK
# ifdef FINAL_WITH_TLS_PSK
free(cfg->psk);
free(cfg->psk_identity);
# endif
@ -309,7 +309,7 @@ int client_config_load(struct mosq_config *cfg, int pub_or_sub, int argc, char *
return 1;
}
#endif
#ifdef WITH_TLS_PSK
#ifdef FINAL_WITH_TLS_PSK
if((cfg->cafile || cfg->capath) && cfg->psk){
if(!cfg->quiet) fprintf(stderr, "Error: Only one of --psk or --cafile/--capath may be used at once.\n");
return 1;
@ -673,7 +673,7 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c
i++;
}
#endif
#ifdef WITH_TLS_PSK
#ifdef FINAL_WITH_TLS_PSK
}else if(!strcmp(argv[i], "--psk")){
if(i==argc-1){
fprintf(stderr, "Error: --psk argument given but no key specified.\n\n");
@ -912,7 +912,7 @@ int client_opts_set(struct mosquitto *mosq, struct mosq_config *cfg)
mosquitto_lib_cleanup();
return 1;
}
# ifdef WITH_TLS_PSK
# ifdef FINAL_WITH_TLS_PSK
if(cfg->psk && mosquitto_tls_psk_set(mosq, cfg->psk, cfg->psk_identity, NULL)){
if(!cfg->quiet) fprintf(stderr, "Error: Problem setting TLS-PSK options.\n");
mosquitto_lib_cleanup();
@ -985,7 +985,7 @@ int client_connect(struct mosquitto *mosq, struct mosq_config *cfg)
if(cfg->port < 0){
#ifdef WITH_TLS
if(cfg->cafile || cfg->capath
# ifdef WITH_TLS_PSK
# ifdef FINAL_WITH_TLS_PSK
|| cfg->psk
# endif
){

@ -66,7 +66,7 @@ struct mosq_config {
char *ciphers;
bool insecure;
char *tls_version;
# ifdef WITH_TLS_PSK
# ifdef FINAL_WITH_TLS_PSK
char *psk;
char *psk_identity;
# endif

@ -223,7 +223,7 @@ void print_usage(void)
#ifdef WITH_TLS
printf(" [{--cafile file | --capath dir} [--cert file] [--key file]\n");
printf(" [--ciphers ciphers] [--insecure]]\n");
#ifdef WITH_TLS_PSK
#ifdef FINAL_WITH_TLS_PSK
printf(" [--psk hex-key --psk-identity identity [--ciphers ciphers]]\n");
#endif
#endif
@ -280,7 +280,7 @@ void print_usage(void)
printf(" hostname. Using this option means that you cannot be sure that the\n");
printf(" remote host is the server you wish to connect to and so is insecure.\n");
printf(" Do not use this option in a production environment.\n");
# ifdef WITH_TLS_PSK
# ifdef FINAL_WITH_TLS_PSK
printf(" --psk : pre-shared-key in hexadecimal (no leading 0x) to enable TLS-PSK mode.\n");
printf(" --psk-identity : client identity string for TLS-PSK mode.\n");
# endif

@ -155,7 +155,7 @@ void print_usage(void)
#ifdef WITH_TLS
printf(" [{--cafile file | --capath dir} [--cert file] [--key file]\n");
printf(" [--ciphers ciphers] [--insecure]]\n");
#ifdef WITH_TLS_PSK
#ifdef FINAL_WITH_TLS_PSK
printf(" [--psk hex-key --psk-identity identity [--ciphers ciphers]]\n");
#endif
#endif
@ -218,7 +218,7 @@ void print_usage(void)
printf(" hostname. Using this option means that you cannot be sure that the\n");
printf(" remote host is the server you wish to connect to and so is insecure.\n");
printf(" Do not use this option in a production environment.\n");
#ifdef WITH_TLS_PSK
#ifdef FINAL_WITH_TLS_PSK
printf(" --psk : pre-shared-key in hexadecimal (no leading 0x) to enable TLS-PSK mode.\n");
printf(" --psk-identity : client identity string for TLS-PSK mode.\n");
#endif

@ -85,11 +85,11 @@ static void write_payload(const unsigned char *payload, int payloadlen, int hex)
(void)fwrite(payload, 1, payloadlen, stdout);
}else if(hex == 1){
for(i=0; i<payloadlen; i++){
fprintf(stdout, "%x", payload[i]);
fprintf(stdout, "%02x", payload[i]);
}
}else if(hex == 2){
for(i=0; i<payloadlen; i++){
fprintf(stdout, "%X", payload[i]);
fprintf(stdout, "%02X", payload[i]);
}
}
}

@ -37,4 +37,12 @@
#define uthash_malloc(sz) mosquitto__malloc(sz)
#define uthash_free(ptr,sz) mosquitto__free(ptr)
#ifdef WITH_TLS
# include <openssl/opensslconf.h>
# if defined(WITH_TLS_PSK) && !defined(OPENSSL_NO_PSK)
# define FINAL_WITH_TLS_PSK
# endif
#endif
#endif

@ -105,7 +105,7 @@ WITH_BUNDLED_DEPS:=yes
# Also bump lib/mosquitto.h, CMakeLists.txt,
# installer/mosquitto.nsi, installer/mosquitto64.nsi
VERSION=1.5.4
VERSION=1.5.5
# Client library SO version. Bump if incompatible API/ABI changes are made.
SOVERSION=1

@ -67,8 +67,8 @@ RUN set -x && \
WITH_WEBSOCKETS=yes \
prefix=/usr \
binary && \
addgroup -S mosquitto 2>/dev/null && \
adduser -S -D -H -h /var/empty -s /sbin/nologin -G mosquitto -g mosquitto mosquitto 2>/dev/null && \
addgroup -S -g 1883 mosquitto 2>/dev/null && \
adduser -S -u 1883 -D -H -h /var/empty -s /sbin/nologin -G mosquitto -g mosquitto mosquitto 2>/dev/null && \
mkdir -p /mosquitto/config /mosquitto/data /mosquitto/log && \
install -d /usr/sbin/ && \
install -s -m755 /build/mosq/src/mosquitto /usr/sbin/mosquitto && \

@ -13,6 +13,11 @@ Two docker volumes have been created in the image to be used for persistent stor
/mosquitto/log
```
## User/Group
The image runs mosqutto under the mosquitto user and group, which are created
with a uid and gid of 1883.
## Configuration
When creating a container from the image, the default configuration values are used.
To use a custom configuration file, mount a **local** configuration file to `/mosquitto/config/mosquitto.conf`

@ -9,7 +9,7 @@
!define env_hklm 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
Name "Eclipse Mosquitto"
!define VERSION 1.5.4
!define VERSION 1.5.5
OutFile "mosquitto-${VERSION}-install-windows-x86.exe"
InstallDir "$PROGRAMFILES\mosquitto"
@ -18,8 +18,7 @@ InstallDir "$PROGRAMFILES\mosquitto"
; Installer pages
!insertmacro MUI_PAGE_WELCOME
Page custom DependencyPage
!insertmacro MUI_PAGE_COMPONENTS
;!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
@ -55,8 +54,8 @@ Section "Files" SecInstall
File "..\readme.md"
File "..\readme-windows.txt"
;File "C:\pthreads\Pre-built.2\dll\x86\pthreadVC2.dll"
;File "C:\OpenSSL-Win32\bin\libssl_1-1.dll"
;File "C:\OpenSSL-Win32\bin\libcrypto_1-1.dll"
File "C:\OpenSSL-Win32\bin\libssl-1_1.dll"
File "C:\OpenSSL-Win32\bin\libcrypto-1_1.dll"
File "..\edl-v10"
File "..\epl-v10"
@ -96,8 +95,8 @@ Section "Uninstall"
Delete "$INSTDIR\readme.txt"
Delete "$INSTDIR\readme-windows.txt"
;Delete "$INSTDIR\pthreadVC2.dll"
;Delete "$INSTDIR\libssl_1-1.dll"
;Delete "$INSTDIR\libcrypto_1-1.dll"
Delete "$INSTDIR\libssl-1_1.dll"
Delete "$INSTDIR\libcrypto-1_1.dll"
Delete "$INSTDIR\edl-v10"
Delete "$INSTDIR\epl-v10"
@ -120,28 +119,3 @@ LangString DESC_SecInstall ${LANG_ENGLISH} "The main installation."
!insertmacro MUI_DESCRIPTION_TEXT ${SecInstall} $(DESC_SecInstall)
!insertmacro MUI_FUNCTION_DESCRIPTION_END
Var Dialog
Var OSSLLink
Var PTHLink
Function DependencyPage
nsDialogs::Create 1018
Pop $Dialog
${If} $Dialog == error
Abort
${EndIf}
${NSD_CreateLabel} 0 0 100% 12u "OpenSSL - install 'Win32 OpenSSL v1.1.0* Light' then copy libssl_1-1.dll and libcrypto_1-1.dll to the mosquitto directory"
${NSD_CreateLink} 13u 13u 100% 12u "http://slproweb.com/products/Win32OpenSSL.html"
Pop $OSSLLink
${NSD_OnClick} $OSSLLink OnClick_OSSL
!insertmacro MUI_HEADER_TEXT_PAGE "Dependencies" "This page lists packages that must be installed if not already present"
nsDialogs::Show
FunctionEnd
Function OnClick_OSSL
Pop $0
ExecShell "open" "http://slproweb.com/products/Win32OpenSSL.html"
FunctionEnd

@ -9,7 +9,7 @@
!define env_hklm 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
Name "Eclipse Mosquitto"
!define VERSION 1.5.4
!define VERSION 1.5.5
OutFile "mosquitto-${VERSION}-install-windows-x64.exe"
!include "x64.nsh"
@ -19,8 +19,7 @@ InstallDir "$PROGRAMFILES64\mosquitto"
; Installer pages
!insertmacro MUI_PAGE_WELCOME
Page custom DependencyPage
!insertmacro MUI_PAGE_COMPONENTS
;!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
@ -56,8 +55,8 @@ Section "Files" SecInstall
File "..\readme.md"
File "..\readme-windows.txt"
;File "C:\pthreads\Pre-built.2\dll\x64\pthreadVC2.dll"
;File "C:\OpenSSL-Win64\bin\libssl_1-1-x64.dll"
;File "C:\OpenSSL-Win64\bin\libcrypto_1-1-x64.dll"
File "C:\OpenSSL-Win64\bin\libssl-1_1-x64.dll"
File "C:\OpenSSL-Win64\bin\libcrypto-1_1-x64.dll"
File "..\edl-v10"
File "..\epl-v10"
@ -97,8 +96,8 @@ Section "Uninstall"
Delete "$INSTDIR\readme.txt"
Delete "$INSTDIR\readme-windows.txt"
;Delete "$INSTDIR\pthreadVC2.dll"
;Delete "$INSTDIR\libssl_1-1-x64.dll"
;Delete "$INSTDIR\libcrypto_1-1-x64.dll"
Delete "$INSTDIR\libssl-1_1-x64.dll"
Delete "$INSTDIR\libcrypto-1_1-x64.dll"
Delete "$INSTDIR\edl-v10"
Delete "$INSTDIR\epl-v10"
@ -121,28 +120,3 @@ LangString DESC_SecInstall ${LANG_ENGLISH} "The main installation."
!insertmacro MUI_DESCRIPTION_TEXT ${SecInstall} $(DESC_SecInstall)
!insertmacro MUI_FUNCTION_DESCRIPTION_END
Var Dialog
Var OSSLLink
Var PTHLink
Function DependencyPage
nsDialogs::Create 1018
Pop $Dialog
${If} $Dialog == error
Abort
${EndIf}
${NSD_CreateLabel} 0 0 100% 12u "OpenSSL - install 'Win64 OpenSSL v1.1.0* Light' then copy libssl_1-1-x64.dll and libcrypto_1-1-x64.dll to the mosquitto directory"
${NSD_CreateLink} 13u 13u 100% 12u "http://slproweb.com/products/Win32OpenSSL.html"
Pop $OSSLLink
${NSD_OnClick} $OSSLLink OnClick_OSSL
!insertmacro MUI_HEADER_TEXT_PAGE "Dependencies" "This page lists packages that must be installed if not already present"
nsDialogs::Show
FunctionEnd
Function OnClick_OSSL
Pop $0
ExecShell "open" "http://slproweb.com/products/Win32OpenSSL.html"
FunctionEnd

@ -147,12 +147,10 @@ int mosquitto_loop(struct mosquitto *mosq, int timeout, int max_packets)
}else{
if(mosq->sock != INVALID_SOCKET){
if(FD_ISSET(mosq->sock, &readfds)){
do{
rc = mosquitto_loop_read(mosq, max_packets);
if(rc || mosq->sock == INVALID_SOCKET){
return rc;
}
}while(SSL_DATA_PENDING(mosq));
rc = mosquitto_loop_read(mosq, max_packets);
if(rc || mosq->sock == INVALID_SOCKET){
return rc;
}
}
if(mosq->sockpairR != INVALID_SOCKET && FD_ISSET(mosq->sockpairR, &readfds)){
#ifndef WIN32
@ -245,8 +243,12 @@ int mosquitto_loop_forever(struct mosquitto *mosq, int timeout, int max_packets)
}else{
pthread_mutex_unlock(&mosq->state_mutex);
if(mosq->reconnect_delay > 0 && mosq->reconnect_exponential_backoff){
reconnect_delay = mosq->reconnect_delay*reconnects*reconnects;
if(mosq->reconnect_delay_max > mosq->reconnect_delay){
if(mosq->reconnect_exponential_backoff){
reconnect_delay = mosq->reconnect_delay*(reconnects+1)*(reconnects+1);
}else{
reconnect_delay = mosq->reconnect_delay*(reconnects+1);
}
}else{
reconnect_delay = mosq->reconnect_delay;
}
@ -284,37 +286,10 @@ int mosquitto_loop_forever(struct mosquitto *mosq, int timeout, int max_packets)
int mosquitto_loop_misc(struct mosquitto *mosq)
{
time_t now;
int rc;
if(!mosq) return MOSQ_ERR_INVAL;
if(mosq->sock == INVALID_SOCKET) return MOSQ_ERR_NO_CONN;
mosquitto__check_keepalive(mosq);
now = mosquitto_time();
if(mosq->ping_t && now - mosq->ping_t >= mosq->keepalive){
/* mosq->ping_t != 0 means we are waiting for a pingresp.
* This hasn't happened in the keepalive time so we should disconnect.
*/
net__socket_close(mosq);
pthread_mutex_lock(&mosq->state_mutex);
if(mosq->state == mosq_cs_disconnecting){
rc = MOSQ_ERR_SUCCESS;
}else{
rc = MOSQ_ERR_KEEPALIVE;
}
pthread_mutex_unlock(&mosq->state_mutex);
pthread_mutex_lock(&mosq->callback_mutex);
if(mosq->on_disconnect){
mosq->in_callback = true;
mosq->on_disconnect(mosq, mosq->userdata, rc);
mosq->in_callback = false;
}
pthread_mutex_unlock(&mosq->callback_mutex);
return MOSQ_ERR_CONN_LOST;
}
return MOSQ_ERR_SUCCESS;
return mosquitto__check_keepalive(mosq);
}
@ -364,7 +339,7 @@ int mosquitto_loop_read(struct mosquitto *mosq, int max_packets)
/* Queue len here tells us how many messages are awaiting processing and
* have QoS > 0. We should try to deal with that many in this loop in order
* to keep up. */
for(i=0; i<max_packets; i++){
for(i=0; i<max_packets || SSL_DATA_PENDING(mosq); i++){
#ifdef WITH_SOCKS
if(mosq->socks5_host){
rc = socks5__read(mosq);

@ -47,7 +47,7 @@ extern "C" {
#define LIBMOSQUITTO_MAJOR 1
#define LIBMOSQUITTO_MINOR 5
#define LIBMOSQUITTO_REVISION 4
#define LIBMOSQUITTO_REVISION 5
/* LIBMOSQUITTO_VERSION_NUMBER looks like 1002001 for e.g. version 1.2.1. */
#define LIBMOSQUITTO_VERSION_NUMBER (LIBMOSQUITTO_MAJOR*1000000+LIBMOSQUITTO_MINOR*1000+LIBMOSQUITTO_REVISION)

@ -183,7 +183,7 @@ int net__socket_close(struct mosquitto *mosq)
}
#ifdef WITH_TLS_PSK
#ifdef FINAL_WITH_TLS_PSK
static unsigned int psk_client_callback(SSL *ssl, const char *hint,
char *identity, unsigned int max_identity_len,
unsigned char *psk, unsigned int max_psk_len)
@ -208,21 +208,39 @@ int net__try_connect_step1(struct mosquitto *mosq, const char *host)
{
int s;
void *sevp = NULL;
struct addrinfo *hints;
if(mosq->adns){
gai_cancel(mosq->adns);
mosquitto__free((struct addrinfo *)mosq->adns->ar_request);
mosquitto__free(mosq->adns);
}
mosq->adns = mosquitto__calloc(1, sizeof(struct gaicb));
if(!mosq->adns){
return MOSQ_ERR_NOMEM;
}
hints = mosquitto__calloc(1, sizeof(struct addrinfo));
if(!hints){
mosquitto__free(mosq->adns);
mosq->adns = NULL;
return MOSQ_ERR_NOMEM;
}
hints->ai_family = AF_UNSPEC;
hints->ai_socktype = SOCK_STREAM;
mosq->adns->ar_name = host;
mosq->adns->ar_request = hints;
s = getaddrinfo_a(GAI_NOWAIT, &mosq->adns, 1, sevp);
if(s){
errno = s;
mosquitto__free(mosq->adns);
mosq->adns = NULL;
if(mosq->adns){
mosquitto__free((struct addrinfo *)mosq->adns->ar_request);
mosquitto__free(mosq->adns);
mosq->adns = NULL;
}
return MOSQ_ERR_EAI;
}
@ -278,6 +296,7 @@ int net__try_connect_step2(struct mosquitto *mosq, uint16_t port, mosq_sock_t *s
freeaddrinfo(mosq->adns->ar_result);
mosq->adns->ar_result = NULL;
mosquitto__free((struct addrinfo *)mosq->adns->ar_request);
mosquitto__free(mosq->adns);
mosq->adns = NULL;
@ -575,7 +594,7 @@ static int net__init_ssl_ctx(struct mosquitto *mosq)
return MOSQ_ERR_TLS;
}
}
#ifdef WITH_TLS_PSK
#ifdef FINAL_WITH_TLS_PSK
}else if(mosq->tls_psk){
SSL_CTX_set_psk_client_callback(mosq->ssl_ctx, psk_client_callback);
#endif

@ -76,6 +76,8 @@ int mosquitto_reconnect_delay_set(struct mosquitto *mosq, unsigned int reconnect
{
if(!mosq) return MOSQ_ERR_INVAL;
if(reconnect_delay == 0) reconnect_delay = 1;
mosq->reconnect_delay = reconnect_delay;
mosq->reconnect_delay_max = reconnect_delay_max;
mosq->reconnect_exponential_backoff = reconnect_exponential_backoff;
@ -221,7 +223,7 @@ int mosquitto_tls_insecure_set(struct mosquitto *mosq, bool value)
int mosquitto_tls_psk_set(struct mosquitto *mosq, const char *psk, const char *identity, const char *ciphers)
{
#ifdef WITH_TLS_PSK
#ifdef FINAL_WITH_TLS_PSK
if(!mosq || !psk || !identity) return MOSQ_ERR_INVAL;
/* Check for hex only digits */

@ -46,9 +46,9 @@ Contributors:
#endif
#ifdef WITH_BROKER
void mosquitto__check_keepalive(struct mosquitto_db *db, struct mosquitto *mosq)
int mosquitto__check_keepalive(struct mosquitto_db *db, struct mosquitto *mosq)
#else
void mosquitto__check_keepalive(struct mosquitto *mosq)
int mosquitto__check_keepalive(struct mosquitto *mosq)
#endif
{
time_t next_msg_out;
@ -67,7 +67,7 @@ void mosquitto__check_keepalive(struct mosquitto *mosq)
log__printf(NULL, MOSQ_LOG_NOTICE, "Bridge connection %s has exceeded idle timeout, disconnecting.", mosq->id);
net__socket_close(db, mosq);
return;
return MOSQ_ERR_SUCCESS;
}
#endif
pthread_mutex_lock(&mosq->msgtime_mutex);
@ -108,9 +108,12 @@ void mosquitto__check_keepalive(struct mosquitto *mosq)
mosq->in_callback = false;
}
pthread_mutex_unlock(&mosq->callback_mutex);
return rc;
#endif
}
}
return MOSQ_ERR_SUCCESS;
}
uint16_t mosquitto__mid_generate(struct mosquitto *mosq)
@ -346,7 +349,7 @@ int mosquitto_topic_matches_sub2(const char *sub, size_t sublen, const char *top
return MOSQ_ERR_SUCCESS;
}
#ifdef WITH_TLS_PSK
#ifdef FINAL_WITH_TLS_PSK
int mosquitto__hex2bin(const char *hex, unsigned char *bin, int bin_max_len)
{
BIGNUM *bn = NULL;

@ -26,14 +26,14 @@ Contributors:
#endif
#ifdef WITH_BROKER
void mosquitto__check_keepalive(struct mosquitto_db *db, struct mosquitto *mosq);
int mosquitto__check_keepalive(struct mosquitto_db *db, struct mosquitto *mosq);
#else
void mosquitto__check_keepalive(struct mosquitto *mosq);
int mosquitto__check_keepalive(struct mosquitto *mosq);
#endif
uint16_t mosquitto__mid_generate(struct mosquitto *mosq);
FILE *mosquitto__fopen(const char *path, const char *mode, bool restrict_read);
#ifdef WITH_TLS_PSK
#ifdef FINAL_WITH_TLS_PSK
int mosquitto__hex2bin(const char *hex, unsigned char *bin, int bin_max_len);
#endif

@ -813,6 +813,27 @@
<para>Not reloaded on reload signal.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>socket_domain</option> [ ipv4 | ipv6 ]</term>
<listitem>
<para>By default, a listener will attempt to listen on
all supported IP protocol versions. If you do not
have an IPv4 or IPv6 interface you may wish to
disable support for either of those protocol
versions. In particular, note that due to the
limitations of the websockets library, it will only
ever attempt to open IPv6 sockets if IPv6 support
is compiled in, and so will fail if IPv6 is not
available.</para>
<para>Set to <option>ipv4</option> to force the
listener to only use IPv4, or set to
<option>ipv6</option> to force the listener to only
use IPv6. If you want support for both IPv4 and
IPv6, then do not use the
<option>socket_domain</option> option.</para>
<para>Not reloaded on reload signal.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>use_username_as_clientid</option> [ true | false ]</term>
<listitem>

@ -2,7 +2,7 @@
MAJOR=1
MINOR=5
REVISION=4
REVISION=5
sed -i "s/^VERSION=.*/VERSION=${MAJOR}.${MINOR}.${REVISION}/" config.mk

@ -1,5 +1,5 @@
name: mosquitto
version: 1.5.4
version: 1.5.5
summary: Eclipse Mosquitto MQTT broker
description: This is a message broker that supports version 3.1 and 3.1.1 of the MQTT
protocol.

@ -82,7 +82,7 @@ int bridge__new(struct mosquitto_db *db, struct mosquitto__bridge *bridge)
new_context->tls_cert_reqs = SSL_VERIFY_PEER;
new_context->tls_version = new_context->bridge->tls_version;
new_context->tls_insecure = new_context->bridge->tls_insecure;
#ifdef WITH_TLS_PSK
#ifdef FINAL_WITH_TLS_PSK
new_context->tls_psk_identity = new_context->bridge->tls_psk_identity;
new_context->tls_psk = new_context->bridge->tls_psk;
#endif
@ -141,16 +141,6 @@ int bridge__connect_step1(struct mosquitto_db *db, struct mosquitto *context)
*/
sub__clean_session(db, context);
for(i=0; i<context->bridge->topic_count; i++){
if(context->bridge->topics[i].direction == bd_out || context->bridge->topics[i].direction == bd_both){
log__printf(NULL, MOSQ_LOG_DEBUG, "Bridge %s doing local SUBSCRIBE on topic %s", context->id, context->bridge->topics[i].local_topic);
if(sub__add(db, context, context->bridge->topics[i].local_topic, context->bridge->topics[i].qos, &db->subs)) return 1;
sub__retain_queue(db, context,
context->bridge->topics[i].local_topic,
context->bridge->topics[i].qos);
}
}
if(context->bridge->notifications){
if(context->bridge->notification_topic){
if(!context->bridge->initial_notification_done){

@ -341,7 +341,7 @@ void config__cleanup(struct mosquitto__config *config)
#ifdef WITH_TLS
mosquitto__free(config->bridges[i].tls_version);
mosquitto__free(config->bridges[i].tls_cafile);
#ifdef WITH_TLS_PSK
#ifdef FINAL_WITH_TLS_PSK
mosquitto__free(config->bridges[i].tls_psk_identity);
mosquitto__free(config->bridges[i].tls_psk);
#endif
@ -446,6 +446,7 @@ int config__parse_args(struct mosquitto_db *db, struct mosquitto__config *config
|| config->default_listener.max_connections != -1
|| config->default_listener.mount_point
|| config->default_listener.protocol != mp_mqtt
|| config->default_listener.socket_domain
|| config->default_listener.security_options.password_file
|| config->default_listener.security_options.psk_file
|| config->default_listener.security_options.auth_plugin_config_count
@ -476,6 +477,7 @@ int config__parse_args(struct mosquitto_db *db, struct mosquitto__config *config
}
config->listeners[config->listener_count-1].max_connections = config->default_listener.max_connections;
config->listeners[config->listener_count-1].protocol = config->default_listener.protocol;
config->listeners[config->listener_count-1].socket_domain = config->default_listener.socket_domain;
config->listeners[config->listener_count-1].client_count = 0;
config->listeners[config->listener_count-1].socks = NULL;
config->listeners[config->listener_count-1].sock_count = 0;
@ -495,6 +497,7 @@ int config__parse_args(struct mosquitto_db *db, struct mosquitto__config *config
config->listeners[config->listener_count-1].use_identity_as_username = config->default_listener.use_identity_as_username;
config->listeners[config->listener_count-1].use_subject_as_username = config->default_listener.use_subject_as_username;
#endif
config->listeners[config->listener_count-1].security_options.acl_file = config->default_listener.security_options.acl_file;
config->listeners[config->listener_count-1].security_options.password_file = config->default_listener.security_options.password_file;
config->listeners[config->listener_count-1].security_options.psk_file = config->default_listener.security_options.psk_file;
config->listeners[config->listener_count-1].security_options.auth_plugin_configs = config->default_listener.security_options.auth_plugin_configs;
@ -684,7 +687,7 @@ int config__read(struct mosquitto_db *db, struct mosquitto__config *config, bool
log__printf(NULL, MOSQ_LOG_ERR, "Error: Invalid bridge configuration.");
return MOSQ_ERR_INVAL;
}
#ifdef WITH_TLS_PSK
#ifdef FINAL_WITH_TLS_PSK
if(config->bridges[i].tls_psk && !config->bridges[i].tls_psk_identity){
log__printf(NULL, MOSQ_LOG_ERR, "Error: Invalid bridge configuration: missing bridge_identity.\n");
return MOSQ_ERR_INVAL;
@ -816,6 +819,7 @@ int config__read_file_core(struct mosquitto__config *config, bool reload, struct
conf__set_cur_security_options(config, cur_listener, &cur_security_options);
if(conf__parse_bool(&token, "allow_zero_length_clientid", &cur_security_options->allow_zero_length_clientid, saveptr)) return MOSQ_ERR_INVAL;
}else if(!strncmp(token, "auth_opt_", 9)){
if(reload) continue; // Auth plugin not currently valid for reloading.
if(!cur_auth_plugin_config){
log__printf(NULL, MOSQ_LOG_ERR, "Error: An auth_opt_ option exists in the config file without an auth_plugin.");
return MOSQ_ERR_INVAL;
@ -917,7 +921,7 @@ int config__read_file_core(struct mosquitto__config *config, bool reload, struct
log__printf(NULL, MOSQ_LOG_ERR, "Error: Invalid bridge configuration.");
return MOSQ_ERR_INVAL;
}
#ifdef WITH_TLS_PSK
#ifdef FINAL_WITH_TLS_PSK
if(cur_bridge->tls_psk_identity || cur_bridge->tls_psk){
log__printf(NULL, MOSQ_LOG_ERR, "Error: Cannot use both certificate and psk encryption in a single bridge.");
return MOSQ_ERR_INVAL;
@ -934,7 +938,7 @@ int config__read_file_core(struct mosquitto__config *config, bool reload, struct
log__printf(NULL, MOSQ_LOG_ERR, "Error: Invalid bridge configuration.");
return MOSQ_ERR_INVAL;
}
#ifdef WITH_TLS_PSK
#ifdef FINAL_WITH_TLS_PSK
if(cur_bridge->tls_psk_identity || cur_bridge->tls_psk){
log__printf(NULL, MOSQ_LOG_ERR, "Error: Cannot use both certificate and psk encryption in a single bridge.");
return MOSQ_ERR_INVAL;
@ -951,7 +955,7 @@ int config__read_file_core(struct mosquitto__config *config, bool reload, struct
log__printf(NULL, MOSQ_LOG_ERR, "Error: Invalid bridge configuration.");
return MOSQ_ERR_INVAL;
}
#ifdef WITH_TLS_PSK
#ifdef FINAL_WITH_TLS_PSK
if(cur_bridge->tls_psk_identity || cur_bridge->tls_psk){
log__printf(NULL, MOSQ_LOG_ERR, "Error: Cannot use both certificate and psk encryption in a single bridge.");
return MOSQ_ERR_INVAL;
@ -962,7 +966,7 @@ int config__read_file_core(struct mosquitto__config *config, bool reload, struct
log__printf(NULL, MOSQ_LOG_WARNING, "Warning: Bridge and/or TLS support not available.");
#endif
}else if(!strcmp(token, "bridge_identity")){
#if defined(WITH_BRIDGE) && defined(WITH_TLS_PSK)
#if defined(WITH_BRIDGE) && defined(FINAL_WITH_TLS_PSK)
if(reload) continue; // FIXME
if(!cur_bridge){
log__printf(NULL, MOSQ_LOG_ERR, "Error: Invalid bridge configuration.");
@ -997,7 +1001,7 @@ int config__read_file_core(struct mosquitto__config *config, bool reload, struct
log__printf(NULL, MOSQ_LOG_ERR, "Error: Invalid bridge configuration.");
return MOSQ_ERR_INVAL;
}
#ifdef WITH_TLS_PSK
#ifdef FINAL_WITH_TLS_PSK
if(cur_bridge->tls_psk_identity || cur_bridge->tls_psk){
log__printf(NULL, MOSQ_LOG_ERR, "Error: Cannot use both certificate and psk encryption in a single bridge.");
return MOSQ_ERR_INVAL;
@ -1032,7 +1036,7 @@ int config__read_file_core(struct mosquitto__config *config, bool reload, struct
log__printf(NULL, MOSQ_LOG_WARNING, "Warning: Bridge support not available.");
#endif
}else if(!strcmp(token, "bridge_psk")){
#if defined(WITH_BRIDGE) && defined(WITH_TLS_PSK)
#if defined(WITH_BRIDGE) && defined(FINAL_WITH_TLS_PSK)
if(reload) continue; // FIXME
if(!cur_bridge){
log__printf(NULL, MOSQ_LOG_ERR, "Error: Invalid bridge configuration.");
@ -1688,7 +1692,7 @@ int config__read_file_core(struct mosquitto__config *config, bool reload, struct
log__printf(NULL, MOSQ_LOG_ERR, "Error: Empty protocol value in configuration.");
}
}else if(!strcmp(token, "psk_file")){
#ifdef WITH_TLS_PSK
#ifdef FINAL_WITH_TLS_PSK
conf__set_cur_security_options(config, cur_listener, &cur_security_options);
if(reload){
mosquitto__free(cur_security_options->psk_file);
@ -1699,7 +1703,7 @@ int config__read_file_core(struct mosquitto__config *config, bool reload, struct
log__printf(NULL, MOSQ_LOG_WARNING, "Warning: TLS/TLS-PSK support not available.");
#endif
}else if(!strcmp(token, "psk_hint")){
#ifdef WITH_TLS_PSK
#ifdef FINAL_WITH_TLS_PSK
if(reload) continue; // Listeners not valid for reloading.
if(conf__parse_string(&token, "psk_hint", &cur_listener->psk_hint, saveptr)) return MOSQ_ERR_INVAL;
#else
@ -1773,6 +1777,22 @@ int config__read_file_core(struct mosquitto__config *config, bool reload, struct
#else
log__printf(NULL, MOSQ_LOG_WARNING, "Warning: Bridge support not available.");
#endif
}else if(!strcmp(token, "socket_domain")){
if(reload) continue; // Listeners not valid for reloading.
token = strtok_r(NULL, " ", &saveptr);
if(token){
if(!strcmp(token, "ipv4")){
cur_listener->socket_domain = AF_INET;
}else if(!strcmp(token, "ipv6")){
cur_listener->socket_domain = AF_INET6;
}else{
log__printf(NULL, MOSQ_LOG_ERR, "Error: Invalid socket_domain value \"%s\" in configuration.", token);
return MOSQ_ERR_INVAL;
}
}else{
log__printf(NULL, MOSQ_LOG_ERR, "Error: Empty socket_domain value in configuration.");
return MOSQ_ERR_INVAL;
}
}else if(!strcmp(token, "store_clean_interval")){
log__printf(NULL, MOSQ_LOG_WARNING, "Warning: store_clean_interval is no longer needed.");
}else if(!strcmp(token, "sys_interval")){

@ -197,6 +197,13 @@ void context__cleanup(struct mosquitto_db *db, struct mosquitto *context, bool d
context->queued_msgs = NULL;
context->last_queued_msg = NULL;
}
#if defined(WITH_BROKER) && defined(__GLIBC__) && defined(WITH_ADNS)
if(context->adns){
gai_cancel(context->adns);
mosquitto__free((struct addrinfo *)context->adns->ar_request);
mosquitto__free(context->adns);
}
#endif
if(do_free){
mosquitto__free(context);
}

@ -90,6 +90,15 @@ int handle__connack(struct mosquitto_db *db, struct mosquitto *context)
}
}
}
for(i=0; i<context->bridge->topic_count; i++){
if(context->bridge->topics[i].direction == bd_out || context->bridge->topics[i].direction == bd_both){
log__printf(NULL, MOSQ_LOG_DEBUG, "Bridge %s doing local SUBSCRIBE on topic %s", context->id, context->bridge->topics[i].local_topic);
if(sub__add(db, context, context->bridge->topics[i].local_topic, context->bridge->topics[i].qos, &db->subs)) return 1;
sub__retain_queue(db, context,
context->bridge->topics[i].local_topic,
context->bridge->topics[i].qos);
}
}
}
context->state = mosq_cs_connected;
return MOSQ_ERR_SUCCESS;

@ -420,7 +420,7 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context)
rc = 1;
goto handle_connect_error;
}
#ifdef WITH_TLS_PSK
#ifdef FINAL_WITH_TLS_PSK
if(context->listener->psk_hint){
/* Client should have provided an identity to get this far. */
if(!context->username){
@ -429,7 +429,7 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context)
goto handle_connect_error;
}
}else{
#endif /* WITH_TLS_PSK */
#endif /* FINAL_WITH_TLS_PSK */
client_cert = SSL_get_peer_certificate(context->ssl);
if(!client_cert){
send__connack(context, 0, CONNACK_REFUSED_BAD_USERNAME_PASSWORD);
@ -457,7 +457,11 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context)
rc = 1;
goto handle_connect_error;
}
#if OPENSSL_VERSION_NUMBER < 0x10100000L
context->username = mosquitto__strdup((char *) ASN1_STRING_data(name_asn1));
#else
context->username = mosquitto__strdup((char *) ASN1_STRING_get0_data(name_asn1));
#endif
if(!context->username){
send__connack(context, 0, CONNACK_REFUSED_SERVER_UNAVAILABLE);
rc = MOSQ_ERR_NOMEM;
@ -492,9 +496,9 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context)
}
X509_free(client_cert);
client_cert = NULL;
#ifdef WITH_TLS_PSK
#ifdef FINAL_WITH_TLS_PSK
}
#endif /* WITH_TLS_PSK */
#endif /* FINAL_WITH_TLS_PSK */
}else{
#endif /* WITH_TLS */
if(username_flag){

@ -87,7 +87,9 @@ static void temp__expire_websockets_clients(struct mosquitto_db *db)
}else{
id = "<unknown>";
}
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s has exceeded timeout, disconnecting.", id);
if(db->config->connection_messages == true){
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s has exceeded timeout, disconnecting.", id);
}
}
/* Client has exceeded keepalive*1.5 */
do_disconnect(db, context);
@ -408,6 +410,10 @@ int mosquitto_main_loop(struct mosquitto_db *db, mosq_sock_t *listensock, int li
context->bridge->restart_t = 0;
}
}else{
#ifdef WITH_EPOLL
/* clean any events triggered in previous connection */
context->events = 0;
#endif
rc = bridge__connect_step1(db, context);
if(rc){
context->bridge->cur_address++;
@ -662,7 +668,9 @@ void do_disconnect(struct mosquitto_db *db, struct mosquitto *context)
}
#ifdef WITH_EPOLL
if (context->sock != INVALID_SOCKET && epoll_ctl(db->epollfd, EPOLL_CTL_DEL, context->sock, &ev) == -1) {
log__printf(NULL, MOSQ_LOG_DEBUG, "Error in epoll disconnecting: %s", strerror(errno));
if(db->config->connection_messages == true){
log__printf(NULL, MOSQ_LOG_DEBUG, "Error in epoll disconnecting: %s", strerror(errno));
}
}
#endif
context__disconnect(db, context);

@ -218,6 +218,7 @@ struct mosquitto__listener {
int sock_count;
int client_count;
enum mosquitto_protocol protocol;
int socket_domain;
bool use_username_as_clientid;
#ifdef WITH_TLS
char *cafile;
@ -462,7 +463,7 @@ struct mosquitto__bridge{
char *tls_certfile;
char *tls_keyfile;
char *tls_version;
# ifdef WITH_TLS_PSK
# ifdef FINAL_WITH_TLS_PSK
char *tls_psk_identity;
char *tls_psk;
# endif

@ -152,8 +152,10 @@ int net__socket_accept(struct mosquitto_db *db, mosq_sock_t listensock)
fromhost(&wrap_req);
if(!hosts_access(&wrap_req)){
/* Access is denied */
if(!net__socket_get_address(new_sock, address, 1024)){
log__printf(NULL, MOSQ_LOG_NOTICE, "Client connection from %s denied access by tcpd.", address);
if(db->config->connection_messages == true){
if(!net__socket_get_address(new_sock, address, 1024)){
log__printf(NULL, MOSQ_LOG_NOTICE, "Client connection from %s denied access by tcpd.", address);
}
}
COMPAT_CLOSE(new_sock);
return -1;
@ -187,7 +189,9 @@ int net__socket_accept(struct mosquitto_db *db, mosq_sock_t listensock)
}
if(new_context->listener->max_connections > 0 && new_context->listener->client_count > new_context->listener->max_connections){
log__printf(NULL, MOSQ_LOG_NOTICE, "Client connection from %s denied: max_connections exceeded.", new_context->address);
if(db->config->connection_messages == true){
log__printf(NULL, MOSQ_LOG_NOTICE, "Client connection from %s denied: max_connections exceeded.", new_context->address);
}
context__cleanup(db, new_context, true);
return -1;
}
@ -217,12 +221,14 @@ int net__socket_accept(struct mosquitto_db *db, mosq_sock_t listensock)
}else if(rc == SSL_ERROR_WANT_WRITE){
new_context->want_write = true;
}else{
e = ERR_get_error();
while(e){
log__printf(NULL, MOSQ_LOG_NOTICE,
"Client connection from %s failed: %s.",
new_context->address, ERR_error_string(e, ebuf));
if(db->config->connection_messages == true){
e = ERR_get_error();
while(e){
log__printf(NULL, MOSQ_LOG_NOTICE,
"Client connection from %s failed: %s.",
new_context->address, ERR_error_string(e, ebuf));
e = ERR_get_error();
}
}
context__cleanup(db, new_context, true);
return -1;
@ -234,7 +240,9 @@ int net__socket_accept(struct mosquitto_db *db, mosq_sock_t listensock)
}
#endif
log__printf(NULL, MOSQ_LOG_NOTICE, "New connection from %s on port %d.", new_context->address, new_context->listener->port);
if(db->config->connection_messages == true){
log__printf(NULL, MOSQ_LOG_NOTICE, "New connection from %s on port %d.", new_context->address, new_context->listener->port);
}
return new_sock;
}
@ -247,7 +255,7 @@ static int client_certificate_verify(int preverify_ok, X509_STORE_CTX *ctx)
}
#endif
#ifdef WITH_TLS_PSK
#ifdef FINAL_WITH_TLS_PSK
static unsigned int psk_server_callback(SSL *ssl, const char *identity, unsigned char *psk, unsigned int max_psk_len)
{
struct mosquitto_db *db;
@ -391,7 +399,11 @@ int net__socket_listen(struct mosquitto__listener *listener)
snprintf(service, 10, "%d", listener->port);
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_UNSPEC;
if(listener->socket_domain){
hints.ai_family = listener->socket_domain;
}else{
hints.ai_family = AF_UNSPEC;
}
hints.ai_flags = AI_PASSIVE;
hints.ai_socktype = SOCK_STREAM;
@ -516,7 +528,7 @@ int net__socket_listen(struct mosquitto__listener *listener)
X509_STORE_set_flags(store, X509_V_FLAG_CRL_CHECK);
}
# ifdef WITH_TLS_PSK
# ifdef FINAL_WITH_TLS_PSK
}else if(listener->psk_hint){
if(tls_ex_index_context == -1){
tls_ex_index_context = SSL_get_ex_new_index(0, "client context", NULL, NULL, NULL);
@ -539,7 +551,7 @@ int net__socket_listen(struct mosquitto__listener *listener)
return 1;
}
}
# endif /* WITH_TLS_PSK */
# endif /* FINAL_WITH_TLS_PSK */
}
#endif /* WITH_TLS */
return 0;

@ -287,7 +287,7 @@ static int persist__subs_retain_write(struct mosquitto_db *db, FILE *db_fptr, st
sub = node->subs;
while(sub){
if(sub->context->clean_session == false){
if(sub->context->clean_session == false && sub->context->id){
length = htonl(2+strlen(sub->context->id) + 2+strlen(thistopic) + sizeof(uint8_t));
i16temp = htons(DB_CHUNK_SUB);

@ -27,6 +27,18 @@ SERVICE_STATUS_HANDLE service_handle = 0;
static SERVICE_STATUS service_status;
int main(int argc, char *argv[]);
static void print_error(void)
{
char *buf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, GetLastError(), LANG_NEUTRAL, &buf, 0, NULL);
fprintf(stderr, "Error: %s\n", buf);
LocalFree(buf);
}
/* Service control callback */
void __stdcall service_handler(DWORD fdwControl)
{
@ -112,8 +124,12 @@ void service_install(void)
svc_desc.lpDescription = "MQTT v3.1.1 broker";
ChangeServiceConfig2(svc_handle, SERVICE_CONFIG_DESCRIPTION, &svc_desc);
CloseServiceHandle(svc_handle);
}else{
print_error();
}
CloseServiceHandle(sc_manager);
} else {
print_error();
}
}
@ -132,8 +148,12 @@ void service_uninstall(void)
}
}
CloseServiceHandle(svc_handle);
}else{
print_error();
}
CloseServiceHandle(sc_manager);
}else{
print_error();
}
}

@ -229,7 +229,9 @@ static int callback_mqtt(struct libwebsocket_context *context,
return -1;
}
if(mosq->listener->max_connections > 0 && mosq->listener->client_count > mosq->listener->max_connections){
log__printf(NULL, MOSQ_LOG_NOTICE, "Client connection from %s denied: max_connections exceeded.", mosq->address);
if(db->config->connection_messages == true){
log__printf(NULL, MOSQ_LOG_NOTICE, "Client connection from %s denied: max_connections exceeded.", mosq->address);
}
mosquitto__free(mosq);
u->mosq = NULL;
return -1;
@ -729,6 +731,9 @@ struct libwebsocket_context *mosq_websockets_init(struct mosquitto__listener *li
#if LWS_LIBRARY_VERSION_MAJOR>1
info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
#endif
if(listener->socket_domain == AF_INET){
info.options |= LWS_SERVER_OPTION_DISABLE_IPV6;
}
user = mosquitto__calloc(1, sizeof(struct libws_mqtt_hack));
if(!user){

Loading…
Cancel
Save