From 5d96c3d7ba16bdfe3c4ed6320497974e9493b253 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Mon, 6 Jun 2016 15:53:05 +0100 Subject: [PATCH 01/62] [186] Fix TLS operation with websockets listeners and libwebsockts 2.x. Bug: https://github.com/eclipse/mosquitto/issues/186 --- ChangeLog.txt | 8 ++++++++ src/websockets.c | 3 +++ 2 files changed, 11 insertions(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index 88513ab6..1c73526c 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,11 @@ +1.x.x - 2016xxxx +================ + +Broker: +- Fix TLS operation with websockets listeners and libwebsockts 2.x. Closes + #186. + + 1.4.9 - 20160603 ================ diff --git a/src/websockets.c b/src/websockets.c index ee7c5a25..b548b47f 100644 --- a/src/websockets.c +++ b/src/websockets.c @@ -603,6 +603,9 @@ struct libwebsocket_context *mosq_websockets_init(struct _mqtt3_listener *listen #ifndef LWS_IS_OLD info.options |= LWS_SERVER_OPTION_DISABLE_IPV6; #endif +#if LWS_LIBRARY_VERSION_MAJOR>1 + info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT +#endif user = _mosquitto_calloc(1, sizeof(struct libws_mqtt_hack)); if(!user){ From 63416e65478971b001ed2233630c48a7b4b6a180 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Mon, 6 Jun 2016 16:02:55 +0100 Subject: [PATCH 02/62] ; --- src/websockets.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/websockets.c b/src/websockets.c index b548b47f..fbf1bc5c 100644 --- a/src/websockets.c +++ b/src/websockets.c @@ -604,7 +604,7 @@ struct libwebsocket_context *mosq_websockets_init(struct _mqtt3_listener *listen info.options |= LWS_SERVER_OPTION_DISABLE_IPV6; #endif #if LWS_LIBRARY_VERSION_MAJOR>1 - info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT + info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; #endif user = _mosquitto_calloc(1, sizeof(struct libws_mqtt_hack)); From 1cd40925b86ca5de1d4f2c694a1cdf0dc4619350 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Mon, 6 Jun 2016 16:11:42 +0100 Subject: [PATCH 03/62] [184] Don't attempt to install docs when WITH_DOCS=no. Thanks to minghuadev. Bug: https://github.com/eclipse/mosquitto/issues/184 --- ChangeLog.txt | 3 +++ Makefile | 2 ++ src/Makefile | 2 ++ 3 files changed, 7 insertions(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index 1c73526c..6ddcdcee 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -5,6 +5,9 @@ Broker: - Fix TLS operation with websockets listeners and libwebsockts 2.x. Closes #186. +Build: +- Don't attempt to install docs when WITH_DOCS=no. Closes #184. + 1.4.9 - 20160603 ================ diff --git a/Makefile b/Makefile index 967ba266..1fc0805d 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,9 @@ test : mosquitto install : mosquitto set -e; for d in ${DIRS}; do $(MAKE) -C $${d} install; done +ifeq ($(WITH_DOCS),yes) set -e; for d in ${DOCDIRS}; do $(MAKE) -C $${d} install; done +endif $(INSTALL) -d ${DESTDIR}/etc/mosquitto $(INSTALL) -m 644 mosquitto.conf ${DESTDIR}/etc/mosquitto/mosquitto.conf.example $(INSTALL) -m 644 aclfile.example ${DESTDIR}/etc/mosquitto/aclfile.example diff --git a/src/Makefile b/src/Makefile index 2bc70dec..52dc02c5 100644 --- a/src/Makefile +++ b/src/Makefile @@ -104,8 +104,10 @@ mosquitto_passwd.o : mosquitto_passwd.c install : all $(INSTALL) -d ${DESTDIR}$(prefix)/sbin $(INSTALL) -s --strip-program=${CROSS_COMPILE}${STRIP} mosquitto ${DESTDIR}${prefix}/sbin/mosquitto + $(INSTALL) -d ${DESTDIR}$(prefix)/include $(INSTALL) mosquitto_plugin.h ${DESTDIR}${prefix}/include/mosquitto_plugin.h ifeq ($(WITH_TLS),yes) + $(INSTALL) -d ${DESTDIR}$(prefix)/bin $(INSTALL) -s --strip-program=${CROSS_COMPILE}${STRIP} mosquitto_passwd ${DESTDIR}${prefix}/bin/mosquitto_passwd endif From 6459bc026ebf04c892f532031ce494b687df9d4c Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Tue, 7 Jun 2016 16:44:52 +0100 Subject: [PATCH 04/62] Bump appveyor openssl version. --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 590ad265..65683db2 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -3,7 +3,7 @@ os: Visual Studio 2013 environment: CMAKE_ARGS: -DCMAKE_BUILD_TYPE=Release NSIS_ROOT: C:\nsis - SSL_VER: 1_0_2e + SSL_VER: 1_0_2h configuration: - Release From 23113bb5f5c07523dac3a392002c173a1fee5371 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Mon, 13 Jun 2016 17:13:44 +0100 Subject: [PATCH 05/62] [7] Don't disconnect client on HUP before reading the pending data. Closes #7. Bug: https://github.com/eclipse/mosquitto/issues/7 --- ChangeLog.txt | 1 + src/loop.c | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 6ddcdcee..e1dd2f1f 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -4,6 +4,7 @@ Broker: - Fix TLS operation with websockets listeners and libwebsockts 2.x. Closes #186. +- Don't disconnect client on HUP before reading the pending data. Closes #7. Build: - Don't attempt to install docs when WITH_DOCS=no. Closes #184. diff --git a/src/loop.c b/src/loop.c index 2a99ae7d..4470323d 100644 --- a/src/loop.c +++ b/src/loop.c @@ -449,10 +449,6 @@ static void loop_handle_reads_writes(struct mosquitto_db *db, struct pollfd *pol } assert(pollfds[context->pollfd_index].fd == context->sock); - if(pollfds[context->pollfd_index].revents & (POLLERR | POLLNVAL | POLLHUP)){ - do_disconnect(db, context); - continue; - } #ifdef WITH_TLS if(pollfds[context->pollfd_index].revents & POLLOUT || context->want_write || @@ -496,6 +492,10 @@ static void loop_handle_reads_writes(struct mosquitto_db *db, struct pollfd *pol } }while(SSL_DATA_PENDING(context)); } + if(pollfds[context->pollfd_index].revents & (POLLERR | POLLNVAL | POLLHUP)){ + do_disconnect(db, context); + continue; + } } } From 2c54104ce3b12ad0213a374103bacd04e4f673d8 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Tue, 21 Jun 2016 17:17:23 +0100 Subject: [PATCH 06/62] [191] Fix some $SYS messages being incorrectly persisted. Closes #191. Bug: https://github.com/eclipse/mosquitto/issues/191 --- ChangeLog.txt | 1 + src/persist.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index e1dd2f1f..7821e570 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -5,6 +5,7 @@ Broker: - Fix TLS operation with websockets listeners and libwebsockts 2.x. Closes #186. - Don't disconnect client on HUP before reading the pending data. Closes #7. +- Fix some $SYS messages being incorrectly persisted. Closes #191. Build: - Don't attempt to install docs when WITH_DOCS=no. Closes #184. diff --git a/src/persist.c b/src/persist.c index d71fc04b..f416aeab 100644 --- a/src/persist.c +++ b/src/persist.c @@ -140,7 +140,7 @@ static int mqtt3_db_message_store_write(struct mosquitto_db *db, FILE *db_fptr) stored = db->msg_store; while(stored){ if(stored->topic && !strncmp(stored->topic, "$SYS", 4)){ - if(stored->ref_count == 1 && stored->dest_id_count == 0){ + if(stored->ref_count <= 1 && stored->dest_id_count == 0){ /* $SYS messages that are only retained shouldn't be persisted. */ stored = stored->next; continue; From fff741613eb9dbf462ba7eafe9d9f15f80a9c623 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Sun, 26 Jun 2016 22:00:43 +0100 Subject: [PATCH 07/62] Support for openssl 1.1.0. --- ChangeLog.txt | 4 ++++ src/mosquitto_passwd.c | 13 +++++++++++++ src/net.c | 2 +- src/read_handle_server.c | 2 +- src/security_default.c | 18 ++++++++++++++++++ 5 files changed, 37 insertions(+), 2 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 7821e570..9e652ad5 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -6,6 +6,10 @@ Broker: #186. - Don't disconnect client on HUP before reading the pending data. Closes #7. - Fix some $SYS messages being incorrectly persisted. Closes #191. +- Support OpenSSL 1.1.0. + +Client library: +- Support OpenSSL 1.1.0. Build: - Don't attempt to install docs when WITH_DOCS=no. Closes #184. diff --git a/src/mosquitto_passwd.c b/src/mosquitto_passwd.c index a7ad1cca..de9a719a 100644 --- a/src/mosquitto_passwd.c +++ b/src/mosquitto_passwd.c @@ -90,7 +90,11 @@ int output_new_password(FILE *fptr, const char *username, const char *password) unsigned char hash[EVP_MAX_MD_SIZE]; unsigned int hash_len; const EVP_MD *digest; +#if OPENSSL_VERSION_NUMBER < 0x10100000L EVP_MD_CTX context; +#else + EVP_MD_CTX *context; +#endif rc = RAND_bytes(salt, SALT_LEN); if(!rc){ @@ -113,12 +117,21 @@ int output_new_password(FILE *fptr, const char *username, const char *password) return 1; } +#if OPENSSL_VERSION_NUMBER < 0x10100000L EVP_MD_CTX_init(&context); EVP_DigestInit_ex(&context, digest, NULL); EVP_DigestUpdate(&context, password, strlen(password)); EVP_DigestUpdate(&context, salt, SALT_LEN); EVP_DigestFinal_ex(&context, hash, &hash_len); EVP_MD_CTX_cleanup(&context); +#else + context = EVP_MD_CTX_new(); + EVP_DigestInit_ex(context, digest, NULL); + EVP_DigestUpdate(context, password, strlen(password)); + EVP_DigestUpdate(context, salt, SALT_LEN); + EVP_DigestFinal_ex(context, hash, &hash_len); + EVP_MD_CTX_free(context); +#endif rc = base64_encode(hash, hash_len, &hash64); if(rc){ diff --git a/src/net.c b/src/net.c index 5c322df5..ac8c055b 100644 --- a/src/net.c +++ b/src/net.c @@ -302,7 +302,7 @@ static int _mosquitto_tls_server_ctx(struct _mqtt3_listener *listener) #endif #ifdef WITH_EC -#if OPENSSL_VERSION_NUMBER >= 0x10002000L +#if OPENSSL_VERSION_NUMBER >= 0x10002000L && OPENSSL_VERSION_NUMBER < 0x10100000L SSL_CTX_set_ecdh_auto(listener->ssl_ctx, 1); #elif OPENSSL_VERSION_NUMBER >= 0x10000000L && OPENSSL_VERSION_NUMBER < 0x10002000L ecdh = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1); diff --git a/src/read_handle_server.c b/src/read_handle_server.c index d7122193..558adb0c 100644 --- a/src/read_handle_server.c +++ b/src/read_handle_server.c @@ -364,7 +364,7 @@ int mqtt3_handle_connect(struct mosquitto_db *db, struct mosquitto *context) goto handle_connect_error; } name_entry = X509_NAME_get_entry(name, i); - context->username = _mosquitto_strdup((char *)ASN1_STRING_data(name_entry->value)); + context->username = _mosquitto_strdup((char *)ASN1_STRING_data(X509_NAME_ENTRY_get_data(name_entry))); if(!context->username){ rc = 1; goto handle_connect_error; diff --git a/src/security_default.c b/src/security_default.c index c64e4568..64ca846b 100644 --- a/src/security_default.c +++ b/src/security_default.c @@ -770,6 +770,7 @@ int mosquitto_psk_key_get_default(struct mosquitto_db *db, const char *hint, con int _pw_digest(const char *password, const unsigned char *salt, unsigned int salt_len, unsigned char *hash, unsigned int *hash_len) { const EVP_MD *digest; +#if OPENSSL_VERSION_NUMBER < 0x10100000L EVP_MD_CTX context; digest = EVP_get_digestbyname("sha512"); @@ -785,6 +786,23 @@ int _pw_digest(const char *password, const unsigned char *salt, unsigned int sal /* hash is assumed to be EVP_MAX_MD_SIZE bytes long. */ EVP_DigestFinal_ex(&context, hash, hash_len); EVP_MD_CTX_cleanup(&context); +#else + EVP_MD_CTX *context; + + digest = EVP_get_digestbyname("sha512"); + if(!digest){ + // FIXME fprintf(stderr, "Error: Unable to create openssl digest.\n"); + return 1; + } + + context = EVP_MD_CTX_new(); + EVP_DigestInit_ex(context, digest, NULL); + EVP_DigestUpdate(context, password, strlen(password)); + EVP_DigestUpdate(context, salt, salt_len); + /* hash is assumed to be EVP_MAX_MD_SIZE bytes long. */ + EVP_DigestFinal_ex(context, hash, hash_len); + EVP_MD_CTX_free(context); +#endif return MOSQ_ERR_SUCCESS; } From 84df2bb9237611221c7962814ac0567c8519cf50 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Sun, 26 Jun 2016 22:48:16 +0100 Subject: [PATCH 08/62] [189] Call fsync after persisting data. To ensure it is correctly written. Closes #189. Thanks to thanhvtruong. Bug: https://github.com/eclipse/mosquitto/issues/189 --- ChangeLog.txt | 2 ++ src/persist.c | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index 9e652ad5..64459fa2 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -7,6 +7,8 @@ Broker: - Don't disconnect client on HUP before reading the pending data. Closes #7. - Fix some $SYS messages being incorrectly persisted. Closes #191. - Support OpenSSL 1.1.0. +- Call fsync after persisting data to ensure it is correctly written. Closes + #189. Client library: - Support OpenSSL 1.1.0. diff --git a/src/persist.c b/src/persist.c index f416aeab..406675f9 100644 --- a/src/persist.c +++ b/src/persist.c @@ -350,6 +350,9 @@ int mqtt3_db_backup(struct mosquitto_db *db, bool shutdown) char err[256]; char *outfile = NULL; int len; +#ifndef WIN32 + int dir_fd; +#endif if(!db || !db->config || !db->config->persistence_filepath) return MOSQ_ERR_INVAL; _mosquitto_log_printf(NULL, MOSQ_LOG_INFO, "Saving in-memory database to %s.", db->config->persistence_filepath); @@ -395,6 +398,19 @@ int mqtt3_db_backup(struct mosquitto_db *db, bool shutdown) mqtt3_db_client_write(db, db_fptr); mqtt3_db_subs_retain_write(db, db_fptr); +#ifndef WIN32 + fsync(fileno(db_fptr)); + + if(db->config->persistence_location){ + dir_fd = open(db->config->persistence_location, O_DIRECTORY); + }else{ + dir_fd = open(".", O_DIRECTORY); + } + if(dir_fd > 0){ + fsync(dir_fd); + close(dir_fd); + } +#endif fclose(db_fptr); #ifdef WIN32 From eaef3db142494966b4e3b194f4a844b3748efabf Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Mon, 27 Jun 2016 20:58:25 +0100 Subject: [PATCH 09/62] O_DIRECTORY not supported everywhere, use O_RDONLY. --- src/persist.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/persist.c b/src/persist.c index 406675f9..5ec4fe11 100644 --- a/src/persist.c +++ b/src/persist.c @@ -402,9 +402,9 @@ int mqtt3_db_backup(struct mosquitto_db *db, bool shutdown) fsync(fileno(db_fptr)); if(db->config->persistence_location){ - dir_fd = open(db->config->persistence_location, O_DIRECTORY); + dir_fd = open(db->config->persistence_location, O_RDONLY); }else{ - dir_fd = open(".", O_DIRECTORY); + dir_fd = open(".", O_RDONLY); } if(dir_fd > 0){ fsync(dir_fd); From 1c90a4487c0eb2245a5247bd201047eb3407639a Mon Sep 17 00:00:00 2001 From: jbwdevries Date: Wed, 29 Jun 2016 18:12:20 +0200 Subject: [PATCH 10/62] Fixes a bug where the C++ wrapper would always claim SOCKS was not supported. (#198) The WITH_* flags are not handed over to the C++ wrapper, instead it relies on the actual library to check status. Signed-off-by: Johan de Vries (Ubuntu VM) --- lib/cpp/mosquittopp.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/cpp/mosquittopp.cpp b/lib/cpp/mosquittopp.cpp index 03301812..0a22b80f 100644 --- a/lib/cpp/mosquittopp.cpp +++ b/lib/cpp/mosquittopp.cpp @@ -281,11 +281,7 @@ void mosquittopp::user_data_set(void *userdata) int mosquittopp::socks5_set(const char *host, int port, const char *username, const char *password) { -#ifdef WITH_SOCKS return mosquitto_socks5_set(m_mosq, host, port, username, password); -#else - return MOSQ_ERR_NOT_SUPPORTED; -#endif } From b6385d347ae2bd664661167d9351509815886081 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Wed, 29 Jun 2016 17:14:33 +0100 Subject: [PATCH 11/62] [198] Update Changelog. Closes #198. Bug: https://github.com/eclipse/mosquitto/pull/198 --- ChangeLog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index 64459fa2..24cafe5b 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -12,6 +12,7 @@ Broker: Client library: - Support OpenSSL 1.1.0. +- Fixed the C++ library not allowing SOCKS support to be used. Closes #198. Build: - Don't attempt to install docs when WITH_DOCS=no. Closes #184. From 50b26347d408e539042a40836c6696f47d404a45 Mon Sep 17 00:00:00 2001 From: tucic Date: Tue, 12 Jul 2016 13:34:59 +0200 Subject: [PATCH 12/62] Writing least significant byte of subscription QoS (#210) Signed-off-by: Milan Tucic --- src/persist.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/persist.c b/src/persist.c index 5ec4fe11..5b633f28 100644 --- a/src/persist.c +++ b/src/persist.c @@ -261,6 +261,7 @@ static int _db_subs_retain_write(struct mosquitto_db *db, FILE *db_fptr, struct char *thistopic; uint32_t length; uint16_t i16temp; + uint8_t i8temp; dbid_t i64temp; size_t slen; @@ -292,7 +293,8 @@ static int _db_subs_retain_write(struct mosquitto_db *db, FILE *db_fptr, struct write_e(db_fptr, &i16temp, sizeof(uint16_t)); write_e(db_fptr, thistopic, slen); - write_e(db_fptr, &sub->qos, sizeof(uint8_t)); + i8temp = (uint8_t )sub->qos; + write_e(db_fptr, &i8temp, sizeof(uint8_t)); } sub = sub->next; } From 3261b307e34aeb9806d59dc4b3c80ade093d5e32 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Tue, 5 Jul 2016 21:38:57 +0100 Subject: [PATCH 13/62] Updated readme.md. --- readme-windows.txt | 7 +++--- readme.md | 62 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 62 insertions(+), 7 deletions(-) diff --git a/readme-windows.txt b/readme-windows.txt index 7917a90a..d8cd5696 100644 --- a/readme-windows.txt +++ b/readme-windows.txt @@ -11,8 +11,9 @@ separately in the case that they are not already available. Capabilities ------------ -The network support in Windows is severely limited. The broker is limited to approximately -1024 MQTT connections. +Some versions of Windows have limitations on the number of concurrent +connections. Non-server versions have been reported to be limited to +approximately 1024 connections. Websockets @@ -20,7 +21,7 @@ Websockets The broker executables provided in the installers do not have Websockets support enabled. If you wish to have a version of the broker with Websockets support, you will need to compile -libwebsockets version v1.3-chrome37-firefox30 yourself and mosquitto version 1.4 yourself. +libwebsockets version v1.7 onwards because no Windows binaries are provided. Please note that on Windows, libwebsockets limits connections to a maximum of 64 clients. diff --git a/readme.md b/readme.md index 20e20d0d..3f420632 100644 --- a/readme.md +++ b/readme.md @@ -2,7 +2,11 @@ Mosquitto ========= Mosquitto is an open source implementation of a server for version 3.1 and -3.1.1 of the MQTT protocol. +3.1.1 of the MQTT protocol. It also includes a C and C++ client library, and +the `mosquitto_pub` and `mosquitto_sub` utilities for publishing and +subscribing. + +## Links See the following links for more information on MQTT: @@ -12,10 +16,60 @@ See the following links for more information on MQTT: Mosquitto project information is available at the following locations: - Main homepage: -- Find existing bugs: -- Submit a bug: -- Source code repository: +- Bug reports: +- Source code repository: There is also a public test server available at +## Installing + +See for details on installing binaries for +various platforms. + +## Quick start + +If you have installed a binary package the broker should have been started +automatically. If not, it can be started with a basic configuration: + + mosquitto + +Then use `mosquitto_sub` to subscribe to a topic: + + mosquitto_sub -t 'test/topic' -v + +And to publish a message: + + mosquitto_pub -t 'test/topic' -m 'hello world' + +## Documentation + +Documentation for the broker, clients and client library API can be found in +the man pages, which are available online at . There +are also pages with an introduction to the features of MQTT, the +`mosquitto_passwd` utility for dealing with username/passwords, and a +description of the configuration file options available for the broker. + +Detailed client library API documentation can be found at + +## Building from source + +To build from source the recommended route for end users is to download the +archive from . + +On Windows and Mac, use `cmake` to build. On other platforms, just run `make` +to build. For Windows, see also `readme-windows.md`. + +If you are building from the git repository then the documentation will not +already be built. Use `make binary` to skip building the man pages, or install +`docbook-xsl` on Debian/Ubuntu systems. + +### Build Dependencies + +* c-ares (libc-ares2-dev on Debian based systems) - disable with `make WITH_DNS_SRV=no` +* libuuid (uuid-dev) - disable with `make WITH_UUID=no` +* libwebsockets (libwebsockets-dev) - enable with `make WITH_LIBWEBSOCKETS=yes` +* openssl (libssl-dev on Debian based systems) - disable with `make WITH_TLS=no` + +## Credits + Mosquitto was written by Roger Light From f06a947df2a13eb846f33010f0880c49631b8450 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Tue, 12 Jul 2016 12:36:41 +0100 Subject: [PATCH 14/62] Update changelog. --- ChangeLog.txt | 1 + THANKS.txt | 1 + 2 files changed, 2 insertions(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index 24cafe5b..34ccbfb5 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -9,6 +9,7 @@ Broker: - Support OpenSSL 1.1.0. - Call fsync after persisting data to ensure it is correctly written. Closes #189. +- Fix persistence saving of subscription QoS on big-endian machines. Client library: - Support OpenSSL 1.1.0. diff --git a/THANKS.txt b/THANKS.txt index 42faea28..7bb1e47e 100644 --- a/THANKS.txt +++ b/THANKS.txt @@ -55,6 +55,7 @@ Michael Hekel Michael Laing Michael Rushton Mike Bush +Milan Tucic Neil Bothwick Nicholas Humfrey Nicholas O'Leary From bcfa29cbd16d338c3a9181d5c916f3be50560349 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Fri, 22 Jul 2016 10:37:30 +0100 Subject: [PATCH 15/62] [222] Fix will retained flag handling on Windows. Thanks to codami. Bug: https://github.com/eclipse/mosquitto/issues/222 --- ChangeLog.txt | 1 + src/read_handle_server.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 34ccbfb5..6a2466cb 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -10,6 +10,7 @@ Broker: - Call fsync after persisting data to ensure it is correctly written. Closes #189. - Fix persistence saving of subscription QoS on big-endian machines. +- Fix will retained flag handling on Windows. Closes #222. Client library: - Support OpenSSL 1.1.0. diff --git a/src/read_handle_server.c b/src/read_handle_server.c index 558adb0c..02fbc974 100644 --- a/src/read_handle_server.c +++ b/src/read_handle_server.c @@ -180,7 +180,7 @@ int mqtt3_handle_connect(struct mosquitto_db *db, struct mosquitto *context) rc = MOSQ_ERR_PROTOCOL; goto handle_connect_error; } - will_retain = connect_flags & 0x20; + will_retain = ((connect_flags & 0x20) == 0x20); // Temporary hack because MSVC<1800 doesn't have stdbool.h. password_flag = connect_flags & 0x40; username_flag = connect_flags & 0x80; From 79cc06b1801cad4700aa5eabf1e6ed6f5c9786bf Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Mon, 8 Aug 2016 21:49:32 +0100 Subject: [PATCH 16/62] [237] Fix memory leak when verifying a server certificate. Only for certificates with a subjectAltName. Closes #237. Thanks to MrSaturday. Bug: https://github.com/eclipse/mosquitto/issues/237 --- ChangeLog.txt | 2 ++ lib/tls_mosq.c | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index 6a2466cb..696c25e4 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -15,6 +15,8 @@ Broker: Client library: - Support OpenSSL 1.1.0. - Fixed the C++ library not allowing SOCKS support to be used. Closes #198. +- Fix memory leak when verifying a server certificate with a subjectAltName + section. Closes #237. Build: - Don't attempt to install docs when WITH_DOCS=no. Closes #184. diff --git a/lib/tls_mosq.c b/lib/tls_mosq.c index 7fd78a59..20f0d3ae 100644 --- a/lib/tls_mosq.c +++ b/lib/tls_mosq.c @@ -129,6 +129,7 @@ int _mosquitto_verify_certificate_hostname(X509 *cert, const char *hostname) if(nval->type == GEN_DNS){ data = ASN1_STRING_data(nval->d.dNSName); if(data && !mosquitto__cmp_hostname_wildcard((char *)data, hostname)){ + sk_GENERAL_NAME_pop_free(san, GENERAL_NAME_free); return 1; } have_san_dns = true; @@ -136,20 +137,24 @@ int _mosquitto_verify_certificate_hostname(X509 *cert, const char *hostname) data = ASN1_STRING_data(nval->d.iPAddress); if(nval->d.iPAddress->length == 4 && ipv4_ok){ if(!memcmp(ipv4_addr, data, 4)){ + sk_GENERAL_NAME_pop_free(san, GENERAL_NAME_free); return 1; } }else if(nval->d.iPAddress->length == 16 && ipv6_ok){ if(!memcmp(ipv6_addr, data, 16)){ + sk_GENERAL_NAME_pop_free(san, GENERAL_NAME_free); return 1; } } } } + sk_GENERAL_NAME_pop_free(san, GENERAL_NAME_free); if(have_san_dns){ /* Only check CN if subjectAltName DNS entry does not exist. */ return 0; } } + subj = X509_get_subject_name(cert); if(X509_NAME_get_text_by_NID(subj, NID_commonName, name, sizeof(name)) > 0){ name[sizeof(name) - 1] = '\0'; From a0d6da16047fa037436d7bc979b3a497ad092825 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Mon, 8 Aug 2016 22:14:35 +0100 Subject: [PATCH 17/62] [225] Fix typo in man page. Closes #225. Thanks to Nabytovych. Bug: https://github.com/eclipse/mosquitto/issues/225 --- man/mosquitto_passwd.1.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/mosquitto_passwd.1.xml b/man/mosquitto_passwd.1.xml index 6a75b8d4..087ed166 100644 --- a/man/mosquitto_passwd.1.xml +++ b/man/mosquitto_passwd.1.xml @@ -41,7 +41,7 @@ Description mosquitto_passwd is a tool for managing - password files the the mosquitto MQTT broker. + password files the mosquitto MQTT broker. Usernames must not contain ":". Passwords are stored in a similar format to crypt3. From 00aa18174915dc48c42910e979dcb83eaa97c782 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Fri, 12 Aug 2016 08:00:34 +0100 Subject: [PATCH 18/62] [244] Add note on compiling auth plugin on OSX. Closes #244. Bug: https://github.com/eclipse/mosquitto/issues/244 --- src/mosquitto_plugin.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/mosquitto_plugin.h b/src/mosquitto_plugin.h index e6ec5c0b..5b6449c0 100644 --- a/src/mosquitto_plugin.h +++ b/src/mosquitto_plugin.h @@ -34,6 +34,11 @@ struct mosquitto_auth_opt { * shared library. Using gcc this can be achieved as follows: * * gcc -I -fPIC -shared plugin.c -o plugin.so + * + * On Mac OS X: + * + * gcc -I -fPIC -shared plugin.c -undefined dynamic_lookup -o plugin.so + * */ /* ========================================================================= From 477cd3e39911f639da691f321ce12fd306fc6a4b Mon Sep 17 00:00:00 2001 From: Pierre Fersing Date: Tue, 16 Aug 2016 23:10:41 +0200 Subject: [PATCH 19/62] Fix missing context->listener for websocket client (#239) The context associated with websocket client didn't had listener filled, which caused use_username_as_clientid to be ignored. Signed-off-by: Pierre Fersing --- src/mosquitto_broker.h | 1 + src/websockets.c | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/mosquitto_broker.h b/src/mosquitto_broker.h index 8d197901..7d29e927 100644 --- a/src/mosquitto_broker.h +++ b/src/mosquitto_broker.h @@ -31,6 +31,7 @@ Contributors: # define libwebsocket_write(A, B, C, D) lws_write((A), (B), (C), (D)) # define libwebsocket_get_socket_fd(A) lws_get_socket_fd((A)) # define libwebsockets_return_http_status(A, B, C, D) lws_return_http_status((B), (C), (D)) +# define libwebsocket_get_protocol(A) lws_get_protocol((A)) # define libwebsocket_context lws_context # define libwebsocket_protocols lws_protocols diff --git a/src/websockets.c b/src/websockets.c index fbf1bc5c..c16bde7a 100644 --- a/src/websockets.c +++ b/src/websockets.c @@ -168,7 +168,8 @@ static int callback_mqtt(struct libwebsocket_context *context, struct mosquitto_db *db; struct mosquitto *mosq = NULL; struct _mosquitto_packet *packet; - int count; + int count, i, j; + const struct libwebsocket_protocols *p; struct libws_mqtt_data *u = (struct libws_mqtt_data *)user; size_t pos; uint8_t *buf; @@ -181,6 +182,18 @@ static int callback_mqtt(struct libwebsocket_context *context, case LWS_CALLBACK_ESTABLISHED: mosq = mqtt3_context_init(db, WEBSOCKET_CLIENT); if(mosq){ + p = libwebsocket_get_protocol(wsi); + for (i=0; iconfig->listener_count; i++){ + if (db->config->listeners[i].protocol == mp_websockets) { + for (j=0; db->config->listeners[i].ws_protocol[j].name; j++){ + if (p == &db->config->listeners[i].ws_protocol[j]){ + mosq->listener = &db->config->listeners[i]; + mosq->listener->client_count++; + } + } + } + } + #if !defined(LWS_LIBRARY_VERSION_NUMBER) mosq->ws_context = context; #endif From ba2de8879008f6df90a0d6af5902926483051124 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Tue, 16 Aug 2016 22:31:36 +0100 Subject: [PATCH 20/62] Display error if broker unable to open the log file. Thanks to Matthew Treinish. Bug: https://github.com/eclipse/mosquitto/issues/234 --- ChangeLog.txt | 2 ++ src/logging.c | 2 ++ src/mosquitto.c | 5 ++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 696c25e4..f09e2135 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -11,6 +11,8 @@ Broker: #189. - Fix persistence saving of subscription QoS on big-endian machines. - Fix will retained flag handling on Windows. Closes #222. +- Broker now displays an error if it is unable to open the log file. Closes + #234. Client library: - Support OpenSSL 1.1.0. diff --git a/src/logging.c b/src/logging.c index 79169f90..f1a58111 100644 --- a/src/logging.c +++ b/src/logging.c @@ -71,6 +71,8 @@ int mqtt3_log_init(struct mqtt3_config *config) } config->log_fptr = _mosquitto_fopen(config->log_file, "at"); if(!config->log_fptr){ + log_destinations = MQTT3_LOG_STDERR; + log_priorities = MOSQ_LOG_ERR; _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error: Unable to open log file %s for writing.", config->log_file); return MOSQ_ERR_INVAL; } diff --git a/src/mosquitto.c b/src/mosquitto.c index 55ff678c..9777ad80 100644 --- a/src/mosquitto.c +++ b/src/mosquitto.c @@ -287,7 +287,10 @@ int main(int argc, char *argv[]) /* Initialise logging only after initialising the database in case we're * logging to topics */ - mqtt3_log_init(&config); + if(mqtt3_log_init(&config)){ + rc = 1; + return rc; + } _mosquitto_log_printf(NULL, MOSQ_LOG_INFO, "mosquitto version %s (build date %s) starting", VERSION, TIMESTAMP); if(config.config_file){ _mosquitto_log_printf(NULL, MOSQ_LOG_INFO, "Config loaded from %s.", config.config_file); From 7ba3f3d33b5b7de2e7cdb2e207782808f23e9855 Mon Sep 17 00:00:00 2001 From: kcallin Date: Tue, 16 Aug 2016 15:36:58 -0600 Subject: [PATCH 21/62] [189] Mosquitto database corrupted on power-loss. (#206) Mosquitto database writes are not atomic and if power is lost during a write the file will be permanently lost. This commit makes writes as atomic as possible. Signed-off-by: Keegan Callin Bug: https://github.com/eclipse/mosquitto/issues/189 --- src/persist.c | 66 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 53 insertions(+), 13 deletions(-) diff --git a/src/persist.c b/src/persist.c index 5b633f28..47c27ae7 100644 --- a/src/persist.c +++ b/src/persist.c @@ -352,9 +352,6 @@ int mqtt3_db_backup(struct mosquitto_db *db, bool shutdown) char err[256]; char *outfile = NULL; int len; -#ifndef WIN32 - int dir_fd; -#endif if(!db || !db->config || !db->config->persistence_filepath) return MOSQ_ERR_INVAL; _mosquitto_log_printf(NULL, MOSQ_LOG_INFO, "Saving in-memory database to %s.", db->config->persistence_filepath); @@ -367,6 +364,36 @@ int mqtt3_db_backup(struct mosquitto_db *db, bool shutdown) } snprintf(outfile, len, "%s.new", db->config->persistence_filepath); outfile[len] = '\0'; + +#ifndef WIN32 + /** + * + * If a system lost power during the rename operation at the + * end of this file the filesystem could potentially be left + * with a directory that looks like this after powerup: + * + * 24094 -rw-r--r-- 2 root root 4099 May 30 16:27 mosquitto.db + * 24094 -rw-r--r-- 2 root root 4099 May 30 16:27 mosquitto.db.new + * + * The 24094 shows that mosquitto.db.new is hard-linked to the + * same file as mosquitto.db. If fopen(outfile, "wb") is naively + * called then mosquitto.db will be truncated and the database + * potentially corrupted. + * + * Any existing mosquitto.db.new file must be removed prior to + * opening to guarantee that it is not hard-linked to + * mosquitto.db. + * + */ + rc = unlink(outfile); + if (rc != 0) { + if (errno != ENOENT) { + _mosquitto_log_printf(NULL, MOSQ_LOG_INFO, "Error saving in-memory database, unable to remove %s.", outfile); + goto error; + } + } +#endif + db_fptr = _mosquitto_fopen(outfile, "wb"); if(db_fptr == NULL){ _mosquitto_log_printf(NULL, MOSQ_LOG_INFO, "Error saving in-memory database, unable to open %s for writing.", outfile); @@ -401,17 +428,30 @@ int mqtt3_db_backup(struct mosquitto_db *db, bool shutdown) mqtt3_db_subs_retain_write(db, db_fptr); #ifndef WIN32 + /** + * + * Closing a file does not guarantee that the contents are + * written to disk. Need to flush to send data from app to OS + * buffers, then fsync to deliver data from OS buffers to disk + * (as well as disk hardware permits). + * + * man close (http://linux.die.net/man/2/close, 2016-06-20): + * + * "successful close does not guarantee that the data has + * been successfully saved to disk, as the kernel defers + * writes. It is not common for a filesystem to flush + * the buffers when the stream is closed. If you need + * to be sure that the data is physically stored, use + * fsync(2). (It will depend on the disk hardware at this + * point." + * + * This guarantees that the new state file will not overwrite + * the old state file before its contents are valid. + * + */ + + fflush(db_fptr); fsync(fileno(db_fptr)); - - if(db->config->persistence_location){ - dir_fd = open(db->config->persistence_location, O_RDONLY); - }else{ - dir_fd = open(".", O_RDONLY); - } - if(dir_fd > 0){ - fsync(dir_fd); - close(dir_fd); - } #endif fclose(db_fptr); From 87b6a746fd63e9919e93ee4365a7275f67033867 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Tue, 16 Aug 2016 22:52:22 +0100 Subject: [PATCH 22/62] Bump version number. --- CMakeLists.txt | 2 +- ChangeLog.txt | 4 ++-- config.mk | 2 +- installer/mosquitto-cygwin.nsi | 2 +- installer/mosquitto.nsi | 2 +- lib/mosquitto.h | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bd903e7f..29fb4b45 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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.4.9) +set (VERSION 1.4.10) if (WIN32) execute_process(COMMAND cmd /c echo %DATE% %TIME% OUTPUT_VARIABLE TIMESTAMP diff --git a/ChangeLog.txt b/ChangeLog.txt index f09e2135..bec39d77 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,5 +1,5 @@ -1.x.x - 2016xxxx -================ +1.4.10 - 20160816 +================= Broker: - Fix TLS operation with websockets listeners and libwebsockts 2.x. Closes diff --git a/config.mk b/config.mk index be86df2c..087766c5 100644 --- a/config.mk +++ b/config.mk @@ -83,7 +83,7 @@ WITH_SOCKS:=yes # Also bump lib/mosquitto.h, CMakeLists.txt, # installer/mosquitto.nsi, installer/mosquitto-cygwin.nsi -VERSION=1.4.9 +VERSION=1.4.10 TIMESTAMP:=$(shell date "+%F %T%z") # Client library SO version. Bump if incompatible API/ABI changes are made. diff --git a/installer/mosquitto-cygwin.nsi b/installer/mosquitto-cygwin.nsi index 2ce9d8d6..eea6ae42 100644 --- a/installer/mosquitto-cygwin.nsi +++ b/installer/mosquitto-cygwin.nsi @@ -7,7 +7,7 @@ !define env_hklm 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"' Name "mosquitto" -!define VERSION 1.4.9 +!define VERSION 1.4.10 OutFile "mosquitto-${VERSION}-install-cygwin.exe" InstallDir "$PROGRAMFILES\mosquitto" diff --git a/installer/mosquitto.nsi b/installer/mosquitto.nsi index 44f59b19..7dc4d1f8 100644 --- a/installer/mosquitto.nsi +++ b/installer/mosquitto.nsi @@ -9,7 +9,7 @@ !define env_hklm 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"' Name "mosquitto" -!define VERSION 1.4.9 +!define VERSION 1.4.10 OutFile "mosquitto-${VERSION}-install-win32.exe" InstallDir "$PROGRAMFILES\mosquitto" diff --git a/lib/mosquitto.h b/lib/mosquitto.h index 8362065b..a7de2922 100644 --- a/lib/mosquitto.h +++ b/lib/mosquitto.h @@ -45,7 +45,7 @@ extern "C" { #define LIBMOSQUITTO_MAJOR 1 #define LIBMOSQUITTO_MINOR 4 -#define LIBMOSQUITTO_REVISION 9 +#define LIBMOSQUITTO_REVISION 10 /* 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) From 5487395fb67ad2e2b6dac1ff67bd0ac289383f09 Mon Sep 17 00:00:00 2001 From: David Audet Date: Wed, 21 Sep 2016 13:35:05 -0700 Subject: [PATCH 23/62] Adding Dockerfiles to build versioned Docker images (#226) * Adding Dockerfiles to build versioned Docker images Dockerfiles have been added to create Docker images for Mosquitto v1.4.4 and v1.4.8 using Alpine Linux as a base. Different directories have been added for each version to decouple the configuration and entrypoint scripts. Currently they contain the same content, but this could change in the future. Docker Hub will also need to pull from specific directories when official docker images will be built and hosted on Docker Hub. * Removing unnecessary default config and volumes Mount points are created in the image, but volumes are not automatically created. The user can still create volumes for these mount points, but is not required to. The default configuration file is now copied from /etc/mosquitto/mosquitto.conf to /mosquitto/config/mosquitto.conf. The user can override this file by mounting a local configuration file to /mosquitto/config. Signed-off-by: David Audet --- docker/1.4.4/Dockerfile | 13 ++++++++ docker/1.4.4/README.md | 49 +++++++++++++++++++++++++++++++ docker/1.4.4/docker-entrypoint.sh | 5 ++++ docker/1.4.8/Dockerfile | 13 ++++++++ docker/1.4.8/README.md | 49 +++++++++++++++++++++++++++++++ docker/1.4.8/docker-entrypoint.sh | 5 ++++ docker/README.md | 4 +++ 7 files changed, 138 insertions(+) create mode 100644 docker/1.4.4/Dockerfile create mode 100644 docker/1.4.4/README.md create mode 100755 docker/1.4.4/docker-entrypoint.sh create mode 100644 docker/1.4.8/Dockerfile create mode 100644 docker/1.4.8/README.md create mode 100755 docker/1.4.8/docker-entrypoint.sh create mode 100644 docker/README.md diff --git a/docker/1.4.4/Dockerfile b/docker/1.4.4/Dockerfile new file mode 100644 index 00000000..b568aeda --- /dev/null +++ b/docker/1.4.4/Dockerfile @@ -0,0 +1,13 @@ +FROM alpine:3.3 +MAINTAINER David Audet + +LABEL Description="Eclipse Mosquitto MQTT Broker" + +RUN apk --no-cache --update add mosquitto=1.4.4-r0 && \ + mkdir -p /mosquitto/config /mosquitto/data /mosquitto/log && \ + cp /etc/mosquitto/mosquitto.conf /mosquitto/config && \ + chown -R mosquitto:mosquitto /mosquitto + +COPY docker-entrypoint.sh / +ENTRYPOINT ["/docker-entrypoint.sh"] +CMD ["/usr/sbin/mosquitto", "-c", "/mosquitto/config/mosquitto.conf"] diff --git a/docker/1.4.4/README.md b/docker/1.4.4/README.md new file mode 100644 index 00000000..795dd2b1 --- /dev/null +++ b/docker/1.4.4/README.md @@ -0,0 +1,49 @@ +#Eclipse Mosquitto v1.4.4 Docker Image + +##Mount Points + +Three mount points have been created in the image to be used for configuration, persistent storage and logs. +``` +/mosquitto/config +/mosquitto/data +/mosquitto/log +``` + + +##Configuration + +When running the image, the default configuration values are used. +To use a custom configuration file, mount a **local** configuration file to `/mosquitto/conf/mosquitto.conf` +``` +docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/data/mosquitto.conf mosquitto:1.4.4 +``` + +Configuration can be changed to: + +* persist data to `/mosquitto/data` +* log to `/mosquitto/log/mosquitto.log` + +i.e. add the following to `mosquitto.conf`: +``` +persistence true +persistence_location /mosquitto/data/ + +log_dest file /mosquitto/log/mosquitto.log +``` + +**Note**: If a volume is used, the data will persist between containers. + +##Build +Build the image: +``` +docker build -t mosquitto:1.4.4 . +``` + +##Run +Run a container using the new image: +``` +docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/data/mosquitto.conf -v /mosquitto/data -v /mosquitto/log mosquitto:1.4.4 +``` +:boom: if the mosquitto configuration (mosquitto.conf) was modified +to use non-default ports, the docker run command will need to be updated +to expose the ports that have been configured. \ No newline at end of file diff --git a/docker/1.4.4/docker-entrypoint.sh b/docker/1.4.4/docker-entrypoint.sh new file mode 100755 index 00000000..1a9fc8d0 --- /dev/null +++ b/docker/1.4.4/docker-entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/ash + +set -e +exec "$@" + diff --git a/docker/1.4.8/Dockerfile b/docker/1.4.8/Dockerfile new file mode 100644 index 00000000..b005b530 --- /dev/null +++ b/docker/1.4.8/Dockerfile @@ -0,0 +1,13 @@ +FROM alpine:3.4 +MAINTAINER David Audet + +LABEL Description="Eclipse Mosquitto MQTT Broker" + +RUN apk --no-cache --update add mosquitto=1.4.8-r2 && \ + mkdir -p /mosquitto/config /mosquitto/data /mosquitto/log && \ + cp /etc/mosquitto/mosquitto.conf /mosquitto/config && \ + chown -R mosquitto:mosquitto /mosquitto + +COPY docker-entrypoint.sh / +ENTRYPOINT ["/docker-entrypoint.sh"] +CMD ["/usr/sbin/mosquitto", "-c", "/mosquitto/config/mosquitto.conf"] diff --git a/docker/1.4.8/README.md b/docker/1.4.8/README.md new file mode 100644 index 00000000..fd8ae40a --- /dev/null +++ b/docker/1.4.8/README.md @@ -0,0 +1,49 @@ +#Eclipse Mosquitto v1.4.8 Docker Image + +##Mount Points + +Three mount points have been created in the image to be used for configuration, persistent storage and logs. +``` +/mosquitto/config +/mosquitto/data +/mosquitto/log +``` + + +##Configuration + +When running the image, the default configuration values are used. +To use a custom configuration file, mount a **local** configuration file to `/mosquitto/conf/mosquitto.conf` +``` +docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/data/mosquitto.conf mosquitto:1.4.8 +``` + +Configuration can be changed to: + +* persist data to `/mosquitto/data` +* log to `/mosquitto/log/mosquitto.log` + +i.e. add the following to `mosquitto.conf`: +``` +persistence true +persistence_location /mosquitto/data/ + +log_dest file /mosquitto/log/mosquitto.log +``` + +**Note**: If a volume is used, the data will persist between containers. + +##Build +Build the image: +``` +docker build -t mosquitto:1.4.8 . +``` + +##Run +Run a container using the new image: +``` +docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/data/mosquitto.conf -v /mosquitto/data -v /mosquitto/log mosquitto:1.4.8 +``` +:boom: if the mosquitto configuration (mosquitto.conf) was modified +to use non-default ports, the docker run command will need to be updated +to expose the ports that have been configured. diff --git a/docker/1.4.8/docker-entrypoint.sh b/docker/1.4.8/docker-entrypoint.sh new file mode 100755 index 00000000..1a9fc8d0 --- /dev/null +++ b/docker/1.4.8/docker-entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/ash + +set -e +exec "$@" + diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 00000000..6fe5506c --- /dev/null +++ b/docker/README.md @@ -0,0 +1,4 @@ +# Docker Images + +This directory contains the required files to build Mosquitto Docker images. + From 51bfdc9ed48ec3317280fe17d8b2b7dc66a1c349 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Wed, 5 Oct 2016 15:52:09 +0100 Subject: [PATCH 24/62] Improve logo files. Make mosquitto-logo-only.svg square. Add mosquitto-logo-min.svg which is more suitable for very small images. --- logo/mosquitto-logo-min.svg | 65 ++++++++++++++++++++++++++++++++++++ logo/mosquitto-logo-only.svg | 34 ++++++++++--------- 2 files changed, 83 insertions(+), 16 deletions(-) create mode 100644 logo/mosquitto-logo-min.svg diff --git a/logo/mosquitto-logo-min.svg b/logo/mosquitto-logo-min.svg new file mode 100644 index 00000000..5438312b --- /dev/null +++ b/logo/mosquitto-logo-min.svg @@ -0,0 +1,65 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/logo/mosquitto-logo-only.svg b/logo/mosquitto-logo-only.svg index 90304382..e43167d7 100644 --- a/logo/mosquitto-logo-only.svg +++ b/logo/mosquitto-logo-only.svg @@ -14,8 +14,8 @@ inkscape:version="0.91 r13725" xml:space="preserve" width="278.23288" - height="212.13112" - viewBox="0 0 278.23288 212.13112" + height="278.23288" + viewBox="0 0 278.23288 278.23288" sodipodi:docname="mosquitto-logo-only.svg">image/svg+xml \ No newline at end of file + transform="matrix(1.25,0,0,-1.25,-387.06488,575.71439)"> \ No newline at end of file From 25a1f7d1994fd4b8d1d25ab0275f7a8f071abfb1 Mon Sep 17 00:00:00 2001 From: David Audet Date: Tue, 20 Dec 2016 13:48:19 -0800 Subject: [PATCH 25/62] Update Dockerfiles to not save the apk cache When installing the Mosquitto package from Alpine Linux, we don't need to save the latest package index to the cache. We are specifically requesting the latest package index each time we install Mosquitto and not using the local cache at all (--no-cache). Signed-off-by: David Audet --- docker/1.4.4/Dockerfile | 2 +- docker/1.4.8/Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/1.4.4/Dockerfile b/docker/1.4.4/Dockerfile index b568aeda..bd757e3b 100644 --- a/docker/1.4.4/Dockerfile +++ b/docker/1.4.4/Dockerfile @@ -3,7 +3,7 @@ MAINTAINER David Audet LABEL Description="Eclipse Mosquitto MQTT Broker" -RUN apk --no-cache --update add mosquitto=1.4.4-r0 && \ +RUN apk --no-cache add mosquitto=1.4.4-r0 && \ mkdir -p /mosquitto/config /mosquitto/data /mosquitto/log && \ cp /etc/mosquitto/mosquitto.conf /mosquitto/config && \ chown -R mosquitto:mosquitto /mosquitto diff --git a/docker/1.4.8/Dockerfile b/docker/1.4.8/Dockerfile index b005b530..a9027a78 100644 --- a/docker/1.4.8/Dockerfile +++ b/docker/1.4.8/Dockerfile @@ -3,7 +3,7 @@ MAINTAINER David Audet LABEL Description="Eclipse Mosquitto MQTT Broker" -RUN apk --no-cache --update add mosquitto=1.4.8-r2 && \ +RUN apk --no-cache add mosquitto=1.4.8-r2 && \ mkdir -p /mosquitto/config /mosquitto/data /mosquitto/log && \ cp /etc/mosquitto/mosquitto.conf /mosquitto/config && \ chown -R mosquitto:mosquitto /mosquitto From 37cbadc3116d2a0645f4924a617165901c5dc10b Mon Sep 17 00:00:00 2001 From: Adam Giemza Date: Thu, 5 Jan 2017 22:23:58 +0100 Subject: [PATCH 26/62] added docker support for version 1.4.10-r2 based on alpine 3.5 (#346) Signed-off-by: Adam Giemza --- docker/1.4.10/Dockerfile | 13 ++++++++ docker/1.4.10/README.md | 49 ++++++++++++++++++++++++++++++ docker/1.4.10/docker-entrypoint.sh | 5 +++ 3 files changed, 67 insertions(+) create mode 100644 docker/1.4.10/Dockerfile create mode 100644 docker/1.4.10/README.md create mode 100755 docker/1.4.10/docker-entrypoint.sh diff --git a/docker/1.4.10/Dockerfile b/docker/1.4.10/Dockerfile new file mode 100644 index 00000000..ee55de18 --- /dev/null +++ b/docker/1.4.10/Dockerfile @@ -0,0 +1,13 @@ +FROM alpine:3.5 +MAINTAINER David Audet + +LABEL Description="Eclipse Mosquitto MQTT Broker" + +RUN apk --no-cache --update add mosquitto=1.4.10-r2 && \ + mkdir -p /mosquitto/config /mosquitto/data /mosquitto/log && \ + cp /etc/mosquitto/mosquitto.conf /mosquitto/config && \ + chown -R mosquitto:mosquitto /mosquitto + +COPY docker-entrypoint.sh / +ENTRYPOINT ["/docker-entrypoint.sh"] +CMD ["/usr/sbin/mosquitto", "-c", "/mosquitto/config/mosquitto.conf"] diff --git a/docker/1.4.10/README.md b/docker/1.4.10/README.md new file mode 100644 index 00000000..fd8ae40a --- /dev/null +++ b/docker/1.4.10/README.md @@ -0,0 +1,49 @@ +#Eclipse Mosquitto v1.4.8 Docker Image + +##Mount Points + +Three mount points have been created in the image to be used for configuration, persistent storage and logs. +``` +/mosquitto/config +/mosquitto/data +/mosquitto/log +``` + + +##Configuration + +When running the image, the default configuration values are used. +To use a custom configuration file, mount a **local** configuration file to `/mosquitto/conf/mosquitto.conf` +``` +docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/data/mosquitto.conf mosquitto:1.4.8 +``` + +Configuration can be changed to: + +* persist data to `/mosquitto/data` +* log to `/mosquitto/log/mosquitto.log` + +i.e. add the following to `mosquitto.conf`: +``` +persistence true +persistence_location /mosquitto/data/ + +log_dest file /mosquitto/log/mosquitto.log +``` + +**Note**: If a volume is used, the data will persist between containers. + +##Build +Build the image: +``` +docker build -t mosquitto:1.4.8 . +``` + +##Run +Run a container using the new image: +``` +docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/data/mosquitto.conf -v /mosquitto/data -v /mosquitto/log mosquitto:1.4.8 +``` +:boom: if the mosquitto configuration (mosquitto.conf) was modified +to use non-default ports, the docker run command will need to be updated +to expose the ports that have been configured. diff --git a/docker/1.4.10/docker-entrypoint.sh b/docker/1.4.10/docker-entrypoint.sh new file mode 100755 index 00000000..1a9fc8d0 --- /dev/null +++ b/docker/1.4.10/docker-entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/ash + +set -e +exec "$@" + From 53616be0e296f6186f52c791e241c76d53380078 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 5 Jan 2017 21:32:41 +0000 Subject: [PATCH 27/62] Fix 1.4.10 docker files. --- docker/1.4.10/Dockerfile | 2 +- docker/1.4.10/README.md | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docker/1.4.10/Dockerfile b/docker/1.4.10/Dockerfile index ee55de18..3101650b 100644 --- a/docker/1.4.10/Dockerfile +++ b/docker/1.4.10/Dockerfile @@ -3,7 +3,7 @@ MAINTAINER David Audet LABEL Description="Eclipse Mosquitto MQTT Broker" -RUN apk --no-cache --update add mosquitto=1.4.10-r2 && \ +RUN apk --no-cache add mosquitto=1.4.10-r2 && \ mkdir -p /mosquitto/config /mosquitto/data /mosquitto/log && \ cp /etc/mosquitto/mosquitto.conf /mosquitto/config && \ chown -R mosquitto:mosquitto /mosquitto diff --git a/docker/1.4.10/README.md b/docker/1.4.10/README.md index fd8ae40a..537d8c2e 100644 --- a/docker/1.4.10/README.md +++ b/docker/1.4.10/README.md @@ -1,4 +1,4 @@ -#Eclipse Mosquitto v1.4.8 Docker Image +#Eclipse Mosquitto v1.4.10 Docker Image ##Mount Points @@ -15,7 +15,7 @@ Three mount points have been created in the image to be used for configuration, When running the image, the default configuration values are used. To use a custom configuration file, mount a **local** configuration file to `/mosquitto/conf/mosquitto.conf` ``` -docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/data/mosquitto.conf mosquitto:1.4.8 +docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/data/mosquitto.conf mosquitto:1.4.10 ``` Configuration can be changed to: @@ -36,13 +36,13 @@ log_dest file /mosquitto/log/mosquitto.log ##Build Build the image: ``` -docker build -t mosquitto:1.4.8 . +docker build -t mosquitto:1.4.10 . ``` ##Run Run a container using the new image: ``` -docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/data/mosquitto.conf -v /mosquitto/data -v /mosquitto/log mosquitto:1.4.8 +docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/data/mosquitto.conf -v /mosquitto/data -v /mosquitto/log mosquitto:1.4.10 ``` :boom: if the mosquitto configuration (mosquitto.conf) was modified to use non-default ports, the docker run command will need to be updated From a8194f0c2d0b005724a33cd7d8c7b54ef39eaa8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Bogda=C5=82?= Date: Sat, 21 Jan 2017 09:22:13 +0100 Subject: [PATCH 28/62] Update docker config path (#349) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Adam BogdaƂ --- docker/1.4.10/README.md | 6 +++--- docker/1.4.4/README.md | 6 +++--- docker/1.4.8/README.md | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docker/1.4.10/README.md b/docker/1.4.10/README.md index 537d8c2e..bc8dfb72 100644 --- a/docker/1.4.10/README.md +++ b/docker/1.4.10/README.md @@ -13,9 +13,9 @@ Three mount points have been created in the image to be used for configuration, ##Configuration When running the image, the default configuration values are used. -To use a custom configuration file, mount a **local** configuration file to `/mosquitto/conf/mosquitto.conf` +To use a custom configuration file, mount a **local** configuration file to `/mosquitto/config/mosquitto.conf` ``` -docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/data/mosquitto.conf mosquitto:1.4.10 +docker run -it -p 1883:1883 -p 9001:9001 -v :/mosquitto/config/mosquitto.conf mosquitto:1.4.10 ``` Configuration can be changed to: @@ -42,7 +42,7 @@ docker build -t mosquitto:1.4.10 . ##Run Run a container using the new image: ``` -docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/data/mosquitto.conf -v /mosquitto/data -v /mosquitto/log mosquitto:1.4.10 +docker run -it -p 1883:1883 -p 9001:9001 -v :/mosquitto/config/mosquitto.conf -v /mosquitto/data -v /mosquitto/log mosquitto:1.4.10 ``` :boom: if the mosquitto configuration (mosquitto.conf) was modified to use non-default ports, the docker run command will need to be updated diff --git a/docker/1.4.4/README.md b/docker/1.4.4/README.md index 795dd2b1..dd4fbbb8 100644 --- a/docker/1.4.4/README.md +++ b/docker/1.4.4/README.md @@ -13,9 +13,9 @@ Three mount points have been created in the image to be used for configuration, ##Configuration When running the image, the default configuration values are used. -To use a custom configuration file, mount a **local** configuration file to `/mosquitto/conf/mosquitto.conf` +To use a custom configuration file, mount a **local** configuration file to `/mosquitto/config/mosquitto.conf` ``` -docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/data/mosquitto.conf mosquitto:1.4.4 +docker run -it -p 1883:1883 -p 9001:9001 -v :/mosquitto/config/mosquitto.conf mosquitto:1.4.4 ``` Configuration can be changed to: @@ -42,7 +42,7 @@ docker build -t mosquitto:1.4.4 . ##Run Run a container using the new image: ``` -docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/data/mosquitto.conf -v /mosquitto/data -v /mosquitto/log mosquitto:1.4.4 +docker run -it -p 1883:1883 -p 9001:9001 -v :/mosquitto/config/mosquitto.conf -v /mosquitto/data -v /mosquitto/log mosquitto:1.4.4 ``` :boom: if the mosquitto configuration (mosquitto.conf) was modified to use non-default ports, the docker run command will need to be updated diff --git a/docker/1.4.8/README.md b/docker/1.4.8/README.md index fd8ae40a..811d01f7 100644 --- a/docker/1.4.8/README.md +++ b/docker/1.4.8/README.md @@ -13,9 +13,9 @@ Three mount points have been created in the image to be used for configuration, ##Configuration When running the image, the default configuration values are used. -To use a custom configuration file, mount a **local** configuration file to `/mosquitto/conf/mosquitto.conf` +To use a custom configuration file, mount a **local** configuration file to `/mosquitto/config/mosquitto.conf` ``` -docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/data/mosquitto.conf mosquitto:1.4.8 +docker run -it -p 1883:1883 -p 9001:9001 -v :/mosquitto/config/mosquitto.conf mosquitto:1.4.8 ``` Configuration can be changed to: @@ -42,7 +42,7 @@ docker build -t mosquitto:1.4.8 . ##Run Run a container using the new image: ``` -docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/data/mosquitto.conf -v /mosquitto/data -v /mosquitto/log mosquitto:1.4.8 +docker run -it -p 1883:1883 -p 9001:9001 -v :/mosquitto/config/mosquitto.conf -v /mosquitto/data -v /mosquitto/log mosquitto:1.4.8 ``` :boom: if the mosquitto configuration (mosquitto.conf) was modified to use non-default ports, the docker run command will need to be updated From 20197e24967a623a31b221d88296601fbe7e2752 Mon Sep 17 00:00:00 2001 From: Karl Palsson Date: Thu, 8 Sep 2016 11:24:29 +0000 Subject: [PATCH 29/62] websockets: fix compatibility with older lws versions (#260) In 1.3, 1.4 and 1.5, the function was "libwebsockets_get_protocol" not "libwebsocket_get_protocol" While the #define name doesn't matter on newer libwebsockets, where it redirects to lws_get_protocol, the naming is critical for older versions. Fixes: 477cd3e39911 (Fix missing context->listener for websocket client) Signed-off-by: Karl Palsson --- src/mosquitto_broker.h | 2 +- src/websockets.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mosquitto_broker.h b/src/mosquitto_broker.h index 7d29e927..bd6a0ef7 100644 --- a/src/mosquitto_broker.h +++ b/src/mosquitto_broker.h @@ -31,7 +31,7 @@ Contributors: # define libwebsocket_write(A, B, C, D) lws_write((A), (B), (C), (D)) # define libwebsocket_get_socket_fd(A) lws_get_socket_fd((A)) # define libwebsockets_return_http_status(A, B, C, D) lws_return_http_status((B), (C), (D)) -# define libwebsocket_get_protocol(A) lws_get_protocol((A)) +# define libwebsockets_get_protocol(A) lws_get_protocol((A)) # define libwebsocket_context lws_context # define libwebsocket_protocols lws_protocols diff --git a/src/websockets.c b/src/websockets.c index c16bde7a..231cb72b 100644 --- a/src/websockets.c +++ b/src/websockets.c @@ -182,7 +182,7 @@ static int callback_mqtt(struct libwebsocket_context *context, case LWS_CALLBACK_ESTABLISHED: mosq = mqtt3_context_init(db, WEBSOCKET_CLIENT); if(mosq){ - p = libwebsocket_get_protocol(wsi); + p = libwebsockets_get_protocol(wsi); for (i=0; iconfig->listener_count; i++){ if (db->config->listeners[i].protocol == mp_websockets) { for (j=0; db->config->listeners[i].ws_protocol[j].name; j++){ From 6b68371dbe7ec7d77ca4dc2aa3b4fe403d782ab7 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Tue, 20 Sep 2016 23:26:14 +0100 Subject: [PATCH 30/62] [259] Fix crash when "lazy" type bridge attempts to reconnect. Thanks to hakofugu41. Bug: https://github.com/eclipse/mosquitto/issues/259 --- ChangeLog.txt | 3 +++ src/loop.c | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index bec39d77..0899f8a7 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,6 @@ +Broker: +- Fix crash when "lazy" type bridge attempts to reconnect. Closes #259. + 1.4.10 - 20160816 ================= diff --git a/src/loop.c b/src/loop.c index 4470323d..07e02c5b 100644 --- a/src/loop.c +++ b/src/loop.c @@ -246,7 +246,16 @@ int mosquitto_main_loop(struct mosquitto_db *db, mosq_sock_t *listensock, int li }else{ if(context->bridge->start_type == bst_lazy && context->bridge->lazy_reconnect){ rc = mqtt3_bridge_connect(db, context); - if(rc){ + if(rc == MOSQ_ERR_SUCCESS){ + pollfds[pollfd_index].fd = context->sock; + pollfds[pollfd_index].events = POLLIN; + pollfds[pollfd_index].revents = 0; + if(context->current_out_packet){ + pollfds[pollfd_index].events |= POLLOUT; + } + context->pollfd_index = pollfd_index; + pollfd_index++; + }else{ context->bridge->cur_address++; if(context->bridge->cur_address == context->bridge->address_count){ context->bridge->cur_address = 0; From 9f743d597268f52dcafcd5c5a936526a6ab93d80 Mon Sep 17 00:00:00 2001 From: tucic Date: Thu, 29 Sep 2016 19:51:31 +0200 Subject: [PATCH 31/62] Maximum connections for websockets listener (#271) Check current number of connections before accepting new websockets clients. Signed-off-by: tucic --- src/websockets.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/websockets.c b/src/websockets.c index 231cb72b..975a10c0 100644 --- a/src/websockets.c +++ b/src/websockets.c @@ -193,7 +193,10 @@ static int callback_mqtt(struct libwebsocket_context *context, } } } - + if(!mosq->listener){ + _mosquitto_free(mosq); + return -1; + } #if !defined(LWS_LIBRARY_VERSION_NUMBER) mosq->ws_context = context; #endif @@ -209,6 +212,12 @@ static int callback_mqtt(struct libwebsocket_context *context, u->mosq = NULL; return -1; } + if(mosq->listener->max_connections > 0 && mosq->listener->client_count > mosq->listener->max_connections){ + _mosquitto_log_printf(NULL, MOSQ_LOG_NOTICE, "Client connection from %s denied: max_connections exceeded.", mosq->address); + _mosquitto_free(mosq); + u->mosq = NULL; + return -1; + } break; case LWS_CALLBACK_CLOSED: From 2c5785376ba12a4c34a113e2322984e30f3d9c06 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 29 Sep 2016 21:08:02 +0100 Subject: [PATCH 32/62] Update changelog. --- ChangeLog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index 0899f8a7..57eb6af1 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,5 +1,6 @@ Broker: - Fix crash when "lazy" type bridge attempts to reconnect. Closes #259. +- maximum_connections now applies to websockets listeners. Closes #271. 1.4.10 - 20160816 ================= From ed80a9a5261e0ca667dfb4c5609364066ec7b869 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 20 Oct 2016 13:47:41 +0100 Subject: [PATCH 33/62] [295] Usage should say we support 3.1.1 as well as 3.1. Closes #295. Bug: https://github.com/eclipse/mosquitto/issues/295 --- src/conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/conf.c b/src/conf.c index 587e970b..4f4732f2 100644 --- a/src/conf.c +++ b/src/conf.c @@ -309,7 +309,7 @@ void mqtt3_config_cleanup(struct mqtt3_config *config) static void print_usage(void) { printf("mosquitto version %s (build date %s)\n\n", VERSION, TIMESTAMP); - printf("mosquitto is an MQTT v3.1 broker.\n\n"); + printf("mosquitto is an MQTT v3.1.1/v3.1 broker.\n\n"); printf("Usage: mosquitto [-c config_file] [-d] [-h] [-p port]\n\n"); printf(" -c : specify the broker config file.\n"); printf(" -d : put the broker into the background after starting.\n"); From 98ea68490626b1d18aee2004b411294c85e62212 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Wed, 30 Nov 2016 11:31:30 +0000 Subject: [PATCH 34/62] [323] Allow outgoing IPv6 connections to use TLS. Bug: https://github.com/eclipse/mosquitto/issues/323 --- ChangeLog.txt | 5 +++++ lib/net_mosq.c | 10 ++-------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 57eb6af1..7cb1a5fb 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,6 +1,11 @@ Broker: - Fix crash when "lazy" type bridge attempts to reconnect. Closes #259. - maximum_connections now applies to websockets listeners. Closes #271. +- Allow bridges to use TLS with IPv6. + +Client library: +- Clients can now use TLS with IPv6. + 1.4.10 - 20160816 ================= diff --git a/lib/net_mosq.c b/lib/net_mosq.c index f18d41b2..26f98554 100644 --- a/lib/net_mosq.c +++ b/lib/net_mosq.c @@ -281,14 +281,7 @@ int _mosquitto_try_connect(struct mosquitto *mosq, const char *host, uint16_t po *sock = INVALID_SOCKET; memset(&hints, 0, sizeof(struct addrinfo)); -#ifdef WITH_TLS - if(mosq->tls_cafile || mosq->tls_capath || mosq->tls_psk){ - hints.ai_family = PF_INET; - }else -#endif - { - hints.ai_family = PF_UNSPEC; - } + hints.ai_family = PF_UNSPEC; hints.ai_flags = AI_ADDRCONFIG; hints.ai_socktype = SOCK_STREAM; @@ -542,6 +535,7 @@ int _mosquitto_socket_connect(struct mosquitto *mosq, const char *host, uint16_t COMPAT_CLOSE(sock); return MOSQ_ERR_TLS; } + SSL_set_ex_data(mosq->ssl, tls_ex_index_mosq, mosq); bio = BIO_new_socket(sock, BIO_NOCLOSE); if(!bio){ From 4dc96a253316a643379f54f5c292690e8c7998dc Mon Sep 17 00:00:00 2001 From: Teun Lassche Date: Mon, 7 Nov 2016 20:28:17 +0100 Subject: [PATCH 35/62] Fix #304 Socket leakage Signed-off-by: Teun Lassche --- lib/mosquitto.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/mosquitto.c b/lib/mosquitto.c index 880657df..732e18f3 100644 --- a/lib/mosquitto.c +++ b/lib/mosquitto.c @@ -520,6 +520,10 @@ static int _mosquitto_reconnect(struct mosquitto *mosq, bool blocking) _mosquitto_messages_reconnect_reset(mosq); + if(mosq->sock != INVALID_SOCKET){ + _mosquitto_socket_close(mosq); //close socket + } + #ifdef WITH_SOCKS if(mosq->socks5_host){ rc = _mosquitto_socket_connect(mosq, mosq->socks5_host, mosq->socks5_port, mosq->bind_address, blocking); From 66683b96b0b45c690f009bf4c0fcea7f374d2a8c Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Sun, 4 Dec 2016 22:01:20 +0000 Subject: [PATCH 36/62] Fix potential socket leakage when reconnecting. Bug: https://github.com/eclipse/mosquitto/issues/304 --- ChangeLog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index 7cb1a5fb..d7cdf92c 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -5,6 +5,7 @@ Broker: Client library: - Clients can now use TLS with IPv6. +- Fix potential socket leakage when reconnecting. Closes #304. 1.4.10 - 20160816 From 8e4a80a92802fc5b5fb0ef774caeb424536e3f16 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 8 Dec 2016 21:06:45 +0000 Subject: [PATCH 37/62] [329] Fix potential negative timeout being passed to pselect. Thanks to Dollars. Bug: https://github.com/eclipse/mosquitto/issues/329 --- ChangeLog.txt | 1 + lib/mosquitto.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index d7cdf92c..45fbd33d 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -6,6 +6,7 @@ Broker: Client library: - Clients can now use TLS with IPv6. - Fix potential socket leakage when reconnecting. Closes #304. +- Fix potential negative timeout being passed to pselect. Closes #329. 1.4.10 - 20160816 diff --git a/lib/mosquitto.c b/lib/mosquitto.c index 732e18f3..afd7e375 100644 --- a/lib/mosquitto.c +++ b/lib/mosquitto.c @@ -916,6 +916,12 @@ int mosquitto_loop(struct mosquitto *mosq, int timeout, int max_packets) timeout = (mosq->next_msg_out - now)*1000; } + if(timeout < 0){ + /* There has been a delay somewhere which means we should have already + * sent a message. */ + timeout = 0; + } + local_timeout.tv_sec = timeout/1000; #ifdef HAVE_PSELECT local_timeout.tv_nsec = (timeout-local_timeout.tv_sec*1000)*1e6; From b9d4ebfba38095614349b20b8837ab4f970b224b Mon Sep 17 00:00:00 2001 From: Jens Breitbart Date: Sat, 10 Dec 2016 19:41:38 +0100 Subject: [PATCH 38/62] Fix compiler warnings (unused parameter, additional semicolon). A modern version of the clang compiler complained about: * unused parameters * additional semicolon . This commit fixes these warnings. Signed-off-by: Jens Breitbart --- lib/cpp/mosquittopp.h | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/cpp/mosquittopp.h b/lib/cpp/mosquittopp.h index d3d6f13e..e54805d3 100644 --- a/lib/cpp/mosquittopp.h +++ b/lib/cpp/mosquittopp.h @@ -4,12 +4,12 @@ Copyright (c) 2010-2013 Roger Light All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 and Eclipse Distribution License v1.0 which accompany this distribution. - + The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. - + Contributors: Roger Light - initial implementation and documentation. */ @@ -28,8 +28,8 @@ Contributors: #endif #include -#include #include +#include namespace mosqpp { @@ -90,15 +90,16 @@ class mosqpp_EXPORT mosquittopp { bool want_write(); int threaded_set(bool threaded=true); int socks5_set(const char *host, int port=1080, const char *username=NULL, const char *password=NULL); - - virtual void on_connect(int rc) {return;}; - virtual void on_disconnect(int rc) {return;}; - virtual void on_publish(int mid) {return;}; - virtual void on_message(const struct mosquitto_message *message) {return;}; - virtual void on_subscribe(int mid, int qos_count, const int *granted_qos) {return;}; - virtual void on_unsubscribe(int mid) {return;}; - virtual void on_log(int level, const char *str) {return;}; - virtual void on_error() {return;}; + + // names in the functions commented to prevent unused parameter warning + virtual void on_connect(int /*rc*/) {return;} + virtual void on_disconnect(int /*rc*/) {return;} + virtual void on_publish(int /*mid*/) {return;} + virtual void on_message(const struct mosquitto_message * /*message*/) {return;} + virtual void on_subscribe(int /*mid*/, int /*qos_count*/, const int * /*granted_qos*/) {return;} + virtual void on_unsubscribe(int /*mid*/) {return;} + virtual void on_log(int /*level*/, const char * /*str*/) {return;} + virtual void on_error() {return;} }; } From b5b5e6f27db2722a5482e754946f8d1eee3bd902 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 5 Jan 2017 21:42:24 +0000 Subject: [PATCH 39/62] Don't use reserved identifiers in public headers. --- lib/cpp/mosquittopp.h | 4 ++-- lib/mosquitto.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/cpp/mosquittopp.h b/lib/cpp/mosquittopp.h index e54805d3..9b0cb694 100644 --- a/lib/cpp/mosquittopp.h +++ b/lib/cpp/mosquittopp.h @@ -14,8 +14,8 @@ Contributors: Roger Light - initial implementation and documentation. */ -#ifndef _MOSQUITTOPP_H_ -#define _MOSQUITTOPP_H_ +#ifndef MOSQUITTOPP_H +#define MOSQUITTOPP_H #ifdef _WIN32 # ifdef mosquittopp_EXPORTS diff --git a/lib/mosquitto.h b/lib/mosquitto.h index a7de2922..2058d59a 100644 --- a/lib/mosquitto.h +++ b/lib/mosquitto.h @@ -14,8 +14,8 @@ Contributors: Roger Light - initial implementation and documentation. */ -#ifndef _MOSQUITTO_H_ -#define _MOSQUITTO_H_ +#ifndef MOSQUITTO_H +#define MOSQUITTO_H #ifdef __cplusplus extern "C" { From 7279e481911f282b06e095b84144f1e1570e6947 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Fri, 6 Jan 2017 00:44:17 +0000 Subject: [PATCH 40/62] [316] Don't error on zero length persistence files. Closes #316. Bug: https://github.com/eclipse/mosquitto/issues/316 --- ChangeLog.txt | 1 + src/persist.c | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 45fbd33d..c1d6cbfc 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -2,6 +2,7 @@ Broker: - Fix crash when "lazy" type bridge attempts to reconnect. Closes #259. - maximum_connections now applies to websockets listeners. Closes #271. - Allow bridges to use TLS with IPv6. +- Don't error on zero length persistence files. Closes #316. Client library: - Clients can now use TLS with IPv6. diff --git a/src/persist.c b/src/persist.c index 47c27ae7..dad6830f 100644 --- a/src/persist.c +++ b/src/persist.c @@ -813,7 +813,14 @@ int mqtt3_db_restore(struct mosquitto_db *db) fptr = _mosquitto_fopen(db->config->persistence_filepath, "rb"); if(fptr == NULL) return MOSQ_ERR_SUCCESS; - read_e(fptr, &header, 15); + rlen = fread(&header, 1, 15, fptr); + if(rlen == 0){ + fclose(fptr); + _mosquitto_log_printf(NULL, MOSQ_LOG_WARNING, "Warning: Persistence file is empty."); + return 0; + }else if(rlen != 15){ + goto error; + } if(!memcmp(header, magic, 15)){ // Restore DB as normal read_e(fptr, &crc, sizeof(uint32_t)); From b01e32bd8b67802ba9f0b3533d4769755a538b33 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Fri, 20 Jan 2017 18:25:04 +0000 Subject: [PATCH 41/62] [354] Close http files even on bad clients. Thanks to jbwdevries. Bug: https://github.com/eclipse/mosquitto/issues/354 --- ChangeLog.txt | 2 ++ src/websockets.c | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index c1d6cbfc..9c9f6cd8 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -3,6 +3,8 @@ Broker: - maximum_connections now applies to websockets listeners. Closes #271. - Allow bridges to use TLS with IPv6. - Don't error on zero length persistence files. Closes #316. +- For http only websockets clients, close files served over http in all cases + when the client disconnects. Closes #354. Client library: - Clients can now use TLS with IPv6. diff --git a/src/websockets.c b/src/websockets.c index 975a10c0..529aaff4 100644 --- a/src/websockets.c +++ b/src/websockets.c @@ -521,6 +521,7 @@ static int callback_http(struct libwebsocket_context *context, (unsigned int)filestat.st_size); if(libwebsocket_write(wsi, buf, buflen, LWS_WRITE_HTTP) < 0){ fclose(u->fptr); + u->fptr = NULL; return -1; } libwebsocket_callback_on_writable(context, wsi); @@ -546,6 +547,7 @@ static int callback_http(struct libwebsocket_context *context, buflen = fread(buf, 1, sizeof(buf), u->fptr); if(buflen < 1){ fclose(u->fptr); + u->fptr = NULL; return -1; } wlen = libwebsocket_write(wsi, buf, buflen, LWS_WRITE_HTTP); @@ -566,6 +568,15 @@ static int callback_http(struct libwebsocket_context *context, }else{ return -1; } + + case LWS_CALLBACK_CLOSED: + case LWS_CALLBACK_CLOSED_HTTP: + case LWS_CALLBACK_HTTP_FILE_COMPLETION: + if(u && u->fptr){ + fclose(u->fptr); + u->fptr = NULL; + } + break; #endif default: From e7c1507f889d6b158568e43a3bfa6a4a4e0105c3 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Fri, 20 Jan 2017 21:18:18 +0000 Subject: [PATCH 42/62] Fix error message when websockets http_dir directory does not exist. --- ChangeLog.txt | 1 + src/websockets.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 9c9f6cd8..00dd0704 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -5,6 +5,7 @@ Broker: - Don't error on zero length persistence files. Closes #316. - For http only websockets clients, close files served over http in all cases when the client disconnects. Closes #354. +- Fix error message when websockets http_dir directory does not exist. Client library: - Clients can now use TLS with IPv6. diff --git a/src/websockets.c b/src/websockets.c index 529aaff4..bae69e03 100644 --- a/src/websockets.c +++ b/src/websockets.c @@ -656,7 +656,7 @@ struct libwebsocket_context *mosq_websockets_init(struct _mqtt3_listener *listen if(!user->http_dir){ _mosquitto_free(user); _mosquitto_free(p); - _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error: Unable to open http dir \"%s\".", user->http_dir); + _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error: Unable to open http dir \"%s\".", listener->http_dir); return NULL; } } From 2c92d3b8371af70e5f10e74f26c321763fb9006d Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Sat, 21 Jan 2017 07:50:07 +0000 Subject: [PATCH 43/62] More file closing fixes. --- src/websockets.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/websockets.c b/src/websockets.c index bae69e03..b44943d3 100644 --- a/src/websockets.c +++ b/src/websockets.c @@ -504,6 +504,7 @@ static int callback_http(struct libwebsocket_context *context, if(fstat(fileno(u->fptr), &filestat) < 0){ libwebsockets_return_http_status(context, wsi, HTTP_STATUS_INTERNAL_SERVER_ERROR, NULL); fclose(u->fptr); + u->fptr = NULL; return -1; } #ifdef WIN32 @@ -512,6 +513,8 @@ static int callback_http(struct libwebsocket_context *context, if(!S_ISREG(filestat.st_mode)){ #endif libwebsockets_return_http_status(context, wsi, HTTP_STATUS_FORBIDDEN, NULL); + fclose(u->fptr); + u->fptr = NULL; return -1; } @@ -568,6 +571,7 @@ static int callback_http(struct libwebsocket_context *context, }else{ return -1; } + break; case LWS_CALLBACK_CLOSED: case LWS_CALLBACK_CLOSED_HTTP: From 35cc1eb21e94f57d50740bdcdd062f6d2ca49791 Mon Sep 17 00:00:00 2001 From: Fredrik Fornwall Date: Tue, 24 Jan 2017 23:01:16 +0100 Subject: [PATCH 44/62] Check for rt and pthread libraries before linking This fixes building on Android which does not have separate librt or libpthread libraries. Signed-off-by: Fredrik Fornwall --- lib/CMakeLists.txt | 12 ++++++++++-- src/CMakeLists.txt | 6 +++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index d9163991..07be5d93 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -7,7 +7,12 @@ if (${WITH_THREADING} STREQUAL ON) set (PTHREAD_LIBRARIES C:\\pthreads\\Pre-built.2\\lib\\x86\\pthreadVC2.lib) set (PTHREAD_INCLUDE_DIR C:\\pthreads\\Pre-built.2\\include) else (WIN32) - set (PTHREAD_LIBRARIES pthread) + find_library(LIBPTHREAD pthread) + if (LIBPTHREAD) + set (PTHREAD_LIBRARIES pthread) + else (LIBPTHREAD) + set (PTHREAD_LIBRARIES "") + endif() set (PTHREAD_INCLUDE_DIR "") endif (WIN32) else (${WITH_THREADING} STREQUAL ON) @@ -44,7 +49,10 @@ add_library(libmosquitto SHARED set (LIBRARIES ${OPENSSL_LIBRARIES} ${PTHREAD_LIBRARIES}) if (UNIX AND NOT APPLE) - set (LIBRARIES ${LIBRARIES} rt) + find_library(LIBRT rt) + if (LIBRT) + set (LIBRARIES ${LIBRARIES} rt) + endif (LIBRT) endif (UNIX AND NOT APPLE) if (WIN32) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0008e555..9d615636 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -86,7 +86,11 @@ if (UNIX) if (APPLE) set (MOSQ_LIBS ${MOSQ_LIBS} dl m) else (APPLE) - set (MOSQ_LIBS ${MOSQ_LIBS} rt dl m) + set (MOSQ_LIBS ${MOSQ_LIBS} dl m) + find_library(LIBRT rt) + if (LIBRT) + set (MOSQ_LIBS ${MOSQ_LIBS} rt) + endif (LIBRT) endif (APPLE) endif (UNIX) From 54a467d7828394dd76645d40ff5c58b67cc16e59 Mon Sep 17 00:00:00 2001 From: Fredrik Fornwall Date: Tue, 24 Jan 2017 23:24:22 +0100 Subject: [PATCH 45/62] Include instead of Using the standard header instead of makes it consistent with other source files and fixes compilation on Android. Signed-off-by: Fredrik Fornwall --- src/conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/conf.c b/src/conf.c index 4f4732f2..9792b2ea 100644 --- a/src/conf.c +++ b/src/conf.c @@ -36,7 +36,7 @@ Contributors: #endif #if !defined(WIN32) && !defined(__CYGWIN__) -# include +# include #endif #include From e2edba054e880bcf94335468468fb3de5b4439b3 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 2 Feb 2017 14:12:59 +0000 Subject: [PATCH 46/62] Fix build dep typo. --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index a00fe0d4..9515380d 100644 --- a/readme.md +++ b/readme.md @@ -65,7 +65,7 @@ already be built. Use `make binary` to skip building the man pages, or install ### Build Dependencies -* c-ares (libc-ares2-dev on Debian based systems) - disable with `make WITH_DNS_SRV=no` +* c-ares (libc-ares-dev on Debian based systems) - disable with `make WITH_DNS_SRV=no` * libuuid (uuid-dev) - disable with `make WITH_UUID=no` * libwebsockets (libwebsockets-dev) - enable with `make WITH_LIBWEBSOCKETS=yes` * openssl (libssl-dev on Debian based systems) - disable with `make WITH_TLS=no` From e13af18ed9c527b8152697c9ede62f0e4e81bdd6 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Mon, 6 Feb 2017 22:39:39 +0000 Subject: [PATCH 47/62] Start of fix for [344]. --- config.mk | 4 ++ lib/mosquitto_internal.h | 6 ++ lib/net_mosq.c | 140 ++++++++++++++++++++++++++++++++------- lib/net_mosq.h | 2 + src/bridge.c | 44 +++++++++++- src/loop.c | 78 +++++++++++++--------- src/mosquitto_broker.h | 2 + 7 files changed, 217 insertions(+), 59 deletions(-) diff --git a/config.mk b/config.mk index 087766c5..3d2aa499 100644 --- a/config.mk +++ b/config.mk @@ -156,6 +156,10 @@ ifeq ($(UNAME),QNX) LIB_LIBS:=$(LIB_LIBS) -lsocket endif +ifeq ($(UNAME),Linux) + BROKER_LIBS:=$(BROKER_LIBS) -lanl +endif + ifeq ($(WITH_WRAP),yes) BROKER_LIBS:=$(BROKER_LIBS) -lwrap BROKER_CFLAGS:=$(BROKER_CFLAGS) -DWITH_WRAP diff --git a/lib/mosquitto_internal.h b/lib/mosquitto_internal.h index 4b4cf858..640de160 100644 --- a/lib/mosquitto_internal.h +++ b/lib/mosquitto_internal.h @@ -56,6 +56,9 @@ Contributors: #include "mosquitto.h" #include "time_mosq.h" #ifdef WITH_BROKER +# ifdef __linux__ +# include +# endif # include "uthash.h" struct mosquitto_client_msg; #endif @@ -151,6 +154,9 @@ struct mosquitto { mosq_sock_t sock; #ifndef WITH_BROKER mosq_sock_t sockpairR, sockpairW; +#endif +#ifdef __linux__ + struct gaicb *adns; /* For getaddrinfo_a */ #endif enum _mosquitto_protocol protocol; char *address; diff --git a/lib/net_mosq.c b/lib/net_mosq.c index 26f98554..24174f09 100644 --- a/lib/net_mosq.c +++ b/lib/net_mosq.c @@ -14,12 +14,15 @@ Contributors: Roger Light - initial implementation and documentation. */ +#define _GNU_SOURCE + #include #include #include #include #include #ifndef WIN32 +#define _GNU_SOURCE #include #include #include @@ -268,6 +271,88 @@ static unsigned int psk_client_callback(SSL *ssl, const char *hint, } #endif +#if defined(WITH_BROKER) && defined(__linux__) +/* Async connect, part 1 (dns lookup) */ +int _mosquitto_try_connect_step1(struct mosquitto *mosq, const char *host) +{ + int s; + void *sevp = NULL; + + if(mosq->adns){ + _mosquitto_free(mosq->adns); + } + mosq->adns = _mosquitto_calloc(1, sizeof(struct gaicb)); + if(!mosq->adns){ + return MOSQ_ERR_NOMEM; + } + mosq->adns->ar_name = host; + + s = getaddrinfo_a(GAI_NOWAIT, &mosq->adns, 1, sevp); + if(s){ + errno = s; + return MOSQ_ERR_EAI; + } + + return MOSQ_ERR_SUCCESS; +} + +/* Async connect part 2, the connection. */ +int _mosquitto_try_connect_step2(struct mosquitto *mosq, uint16_t port, mosq_sock_t *sock) +{ + struct addrinfo *ainfo, *rp; + int rc; + + ainfo = mosq->adns->ar_result; + + for(rp = ainfo; rp != NULL; rp = rp->ai_next){ + *sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); + if(*sock == INVALID_SOCKET) continue; + + if(rp->ai_family == PF_INET){ + ((struct sockaddr_in *)rp->ai_addr)->sin_port = htons(port); + }else if(rp->ai_family == PF_INET6){ + ((struct sockaddr_in6 *)rp->ai_addr)->sin6_port = htons(port); + }else{ + COMPAT_CLOSE(*sock); + continue; + } + + /* Set non-blocking */ + if(_mosquitto_socket_nonblock(*sock)){ + COMPAT_CLOSE(*sock); + continue; + } + + rc = connect(*sock, rp->ai_addr, rp->ai_addrlen); +#ifdef WIN32 + errno = WSAGetLastError(); +#endif + if(rc == 0 || errno == EINPROGRESS || errno == COMPAT_EWOULDBLOCK){ + if(rc < 0 && (errno == EINPROGRESS || errno == COMPAT_EWOULDBLOCK)){ + rc = MOSQ_ERR_CONN_PENDING; + } + + /* Set non-blocking */ + if(_mosquitto_socket_nonblock(*sock)){ + COMPAT_CLOSE(*sock); + continue; + } + break; + } + + COMPAT_CLOSE(*sock); + *sock = INVALID_SOCKET; + } + freeaddrinfo(ainfo); + if(!rp){ + return MOSQ_ERR_ERRNO; + } + return rc; +} + +#endif + + int _mosquitto_try_connect(struct mosquitto *mosq, const char *host, uint16_t port, mosq_sock_t *sock, const char *bind_address, bool blocking) { struct addrinfo hints; @@ -303,7 +388,7 @@ int _mosquitto_try_connect(struct mosquitto *mosq, const char *host, uint16_t po for(rp = ainfo; rp != NULL; rp = rp->ai_next){ *sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); if(*sock == INVALID_SOCKET) continue; - + if(rp->ai_family == PF_INET){ ((struct sockaddr_in *)rp->ai_addr)->sin_port = htons(port); }else if(rp->ai_family == PF_INET6){ @@ -396,24 +481,13 @@ int mosquitto__socket_connect_tls(struct mosquitto *mosq) } #endif -/* Create a socket and connect it to 'ip' on port 'port'. - * Returns -1 on failure (ip is NULL, socket creation/connection error) - * Returns sock number on success. - */ -int _mosquitto_socket_connect(struct mosquitto *mosq, const char *host, uint16_t port, const char *bind_address, bool blocking) +int _mosquitto_socket_connect_step3(struct mosquitto *mosq, const char *host, uint16_t port, const char *bind_address, bool blocking) { - mosq_sock_t sock = INVALID_SOCKET; - int rc; #ifdef WITH_TLS int ret; BIO *bio; #endif - if(!mosq || !host || !port) return MOSQ_ERR_INVAL; - - rc = _mosquitto_try_connect(mosq, host, port, &sock, bind_address, blocking); - if(rc > 0) return rc; - #ifdef WITH_TLS if(mosq->tls_cafile || mosq->tls_capath || mosq->tls_psk){ #if OPENSSL_VERSION_NUMBER >= 0x10001000L @@ -425,7 +499,7 @@ int _mosquitto_socket_connect(struct mosquitto *mosq, const char *host, uint16_t mosq->ssl_ctx = SSL_CTX_new(TLSv1_client_method()); }else{ _mosquitto_log_printf(mosq, MOSQ_LOG_ERR, "Error: Protocol %s not supported.", mosq->tls_version); - COMPAT_CLOSE(sock); + COMPAT_CLOSE(mosq->sock); return MOSQ_ERR_INVAL; } #else @@ -433,13 +507,13 @@ int _mosquitto_socket_connect(struct mosquitto *mosq, const char *host, uint16_t mosq->ssl_ctx = SSL_CTX_new(TLSv1_client_method()); }else{ _mosquitto_log_printf(mosq, MOSQ_LOG_ERR, "Error: Protocol %s not supported.", mosq->tls_version); - COMPAT_CLOSE(sock); + COMPAT_CLOSE(mosq->sock); return MOSQ_ERR_INVAL; } #endif if(!mosq->ssl_ctx){ _mosquitto_log_printf(mosq, MOSQ_LOG_ERR, "Error: Unable to create TLS context."); - COMPAT_CLOSE(sock); + COMPAT_CLOSE(mosq->sock); return MOSQ_ERR_TLS; } @@ -456,7 +530,7 @@ int _mosquitto_socket_connect(struct mosquitto *mosq, const char *host, uint16_t ret = SSL_CTX_set_cipher_list(mosq->ssl_ctx, mosq->tls_ciphers); if(ret == 0){ _mosquitto_log_printf(mosq, MOSQ_LOG_ERR, "Error: Unable to set TLS ciphers. Check cipher list \"%s\".", mosq->tls_ciphers); - COMPAT_CLOSE(sock); + COMPAT_CLOSE(mosq->sock); return MOSQ_ERR_TLS; } } @@ -480,7 +554,7 @@ int _mosquitto_socket_connect(struct mosquitto *mosq, const char *host, uint16_t _mosquitto_log_printf(mosq, MOSQ_LOG_ERR, "Error: Unable to load CA certificates, check capath \"%s\".", mosq->tls_capath); } #endif - COMPAT_CLOSE(sock); + COMPAT_CLOSE(mosq->sock); return MOSQ_ERR_TLS; } if(mosq->tls_cert_reqs == 0){ @@ -502,7 +576,7 @@ int _mosquitto_socket_connect(struct mosquitto *mosq, const char *host, uint16_t #else _mosquitto_log_printf(mosq, MOSQ_LOG_ERR, "Error: Unable to load client certificate \"%s\".", mosq->tls_certfile); #endif - COMPAT_CLOSE(sock); + COMPAT_CLOSE(mosq->sock); return MOSQ_ERR_TLS; } } @@ -514,13 +588,13 @@ int _mosquitto_socket_connect(struct mosquitto *mosq, const char *host, uint16_t #else _mosquitto_log_printf(mosq, MOSQ_LOG_ERR, "Error: Unable to load client key file \"%s\".", mosq->tls_keyfile); #endif - COMPAT_CLOSE(sock); + COMPAT_CLOSE(mosq->sock); return MOSQ_ERR_TLS; } ret = SSL_CTX_check_private_key(mosq->ssl_ctx); if(ret != 1){ _mosquitto_log_printf(mosq, MOSQ_LOG_ERR, "Error: Client certificate/key are inconsistent."); - COMPAT_CLOSE(sock); + COMPAT_CLOSE(mosq->sock); return MOSQ_ERR_TLS; } } @@ -532,27 +606,43 @@ int _mosquitto_socket_connect(struct mosquitto *mosq, const char *host, uint16_t mosq->ssl = SSL_new(mosq->ssl_ctx); if(!mosq->ssl){ - COMPAT_CLOSE(sock); + COMPAT_CLOSE(mosq->sock); return MOSQ_ERR_TLS; } SSL_set_ex_data(mosq->ssl, tls_ex_index_mosq, mosq); - bio = BIO_new_socket(sock, BIO_NOCLOSE); + bio = BIO_new_socket(mosq->sock, BIO_NOCLOSE); if(!bio){ - COMPAT_CLOSE(sock); + COMPAT_CLOSE(mosq->sock); return MOSQ_ERR_TLS; } SSL_set_bio(mosq->ssl, bio, bio); - mosq->sock = sock; if(mosquitto__socket_connect_tls(mosq)){ return MOSQ_ERR_TLS; } } #endif + return MOSQ_ERR_SUCCESS; +} + +/* Create a socket and connect it to 'ip' on port 'port'. + * Returns -1 on failure (ip is NULL, socket creation/connection error) + * Returns sock number on success. + */ +int _mosquitto_socket_connect(struct mosquitto *mosq, const char *host, uint16_t port, const char *bind_address, bool blocking) +{ + mosq_sock_t sock = INVALID_SOCKET; + int rc; + + if(!mosq || !host || !port) return MOSQ_ERR_INVAL; + + rc = _mosquitto_try_connect(mosq, host, port, &sock, bind_address, blocking); + if(rc > 0) return rc; mosq->sock = sock; + rc = _mosquitto_socket_connect_step3(mosq, host, port, bind_address, blocking); return rc; } diff --git a/lib/net_mosq.h b/lib/net_mosq.h index b101746d..569e9452 100644 --- a/lib/net_mosq.h +++ b/lib/net_mosq.h @@ -61,6 +61,8 @@ int _mosquitto_socket_close(struct mosquitto_db *db, struct mosquitto *mosq); int _mosquitto_socket_close(struct mosquitto *mosq); #endif int _mosquitto_try_connect(struct mosquitto *mosq, const char *host, uint16_t port, mosq_sock_t *sock, const char *bind_address, bool blocking); +int _mosquitto_try_connect_step1(struct mosquitto *mosq, const char *host); +int _mosquitto_try_connect_step2(struct mosquitto *mosq, uint16_t port, mosq_sock_t *sock); int _mosquitto_socket_nonblock(mosq_sock_t sock); int _mosquitto_socketpair(mosq_sock_t *sp1, mosq_sock_t *sp2); diff --git a/src/bridge.c b/src/bridge.c index a7d5ad09..e9a3d0ee 100644 --- a/src/bridge.c +++ b/src/bridge.c @@ -131,10 +131,15 @@ int mqtt3_bridge_new(struct mosquitto_db *db, struct _mqtt3_bridge *bridge) return MOSQ_ERR_NOMEM; } +#ifdef __linux__ + new_context->bridge->restart_t = 1; /* force quick restart of bridge */ + return mqtt3_bridge_connect_step1(db, new_context); +#else return mqtt3_bridge_connect(db, new_context); +#endif } -int mqtt3_bridge_connect(struct mosquitto_db *db, struct mosquitto *context) +int mqtt3_bridge_connect_step1(struct mosquitto_db *db, struct mosquitto *context) { int rc; int i; @@ -207,6 +212,31 @@ int mqtt3_bridge_connect(struct mosquitto_db *db, struct mosquitto *context) } } + _mosquitto_log_printf(NULL, MOSQ_LOG_NOTICE, "Connecting bridge %s (%s:%d)", context->bridge->name, context->bridge->addresses[context->bridge->cur_address].address, context->bridge->addresses[context->bridge->cur_address].port); + rc = _mosquitto_try_connect_step1(context, context->bridge->addresses[context->bridge->cur_address].address); + if(rc > 0 ){ + if(rc == MOSQ_ERR_TLS){ + _mosquitto_socket_close(db, context); + return rc; /* Error already printed */ + }else if(rc == MOSQ_ERR_ERRNO){ + _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error creating bridge: %s.", strerror(errno)); + }else if(rc == MOSQ_ERR_EAI){ + _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error creating bridge: %s.", gai_strerror(errno)); + } + + return rc; + } + + return MOSQ_ERR_SUCCESS; +} + + +int mqtt3_bridge_connect_step2(struct mosquitto_db *db, struct mosquitto *context) +{ + int rc; + + if(!context || !context->bridge) return MOSQ_ERR_INVAL; + _mosquitto_log_printf(NULL, MOSQ_LOG_NOTICE, "Connecting bridge %s (%s:%d)", context->bridge->name, context->bridge->addresses[context->bridge->cur_address].address, context->bridge->addresses[context->bridge->cur_address].port); rc = _mosquitto_socket_connect(context, context->bridge->addresses[context->bridge->cur_address].address, context->bridge->addresses[context->bridge->cur_address].port, NULL, false); if(rc > 0 ){ @@ -245,6 +275,18 @@ int mqtt3_bridge_connect(struct mosquitto_db *db, struct mosquitto *context) } } + +int mqtt3_bridge_connect(struct mosquitto_db *db, struct mosquitto *context) +{ + int rc; + + rc = mqtt3_bridge_connect_step1(db, context); + if(rc) return rc; + + return mqtt3_bridge_connect_step2(db, context); +} + + void mqtt3_bridge_packet_cleanup(struct mosquitto *context) { struct _mosquitto_packet *packet; diff --git a/src/loop.c b/src/loop.c index 07e02c5b..d3d5e6a8 100644 --- a/src/loop.c +++ b/src/loop.c @@ -244,45 +244,57 @@ int mosquitto_main_loop(struct mosquitto_db *db, mosq_sock_t *listensock, int li context->bridge->primary_retry = now + 5; } }else{ - if(context->bridge->start_type == bst_lazy && context->bridge->lazy_reconnect){ - rc = mqtt3_bridge_connect(db, context); - if(rc == MOSQ_ERR_SUCCESS){ - pollfds[pollfd_index].fd = context->sock; - pollfds[pollfd_index].events = POLLIN; - pollfds[pollfd_index].revents = 0; - if(context->current_out_packet){ - pollfds[pollfd_index].events |= POLLOUT; + if((context->bridge->start_type == bst_lazy && context->bridge->lazy_reconnect) + || (context->bridge->start_type == bst_automatic && now > context->bridge->restart_t)){ + +#ifdef __linux__ + if(context->adns){ + /* Waiting on DNS lookup */ + rc = mqtt3_bridge_connect_step2(db, context); + if(rc == MOSQ_ERR_SUCCESS){ + pollfds[pollfd_index].fd = context->sock; + pollfds[pollfd_index].events = POLLIN; + pollfds[pollfd_index].revents = 0; + if(context->current_out_packet){ + pollfds[pollfd_index].events |= POLLOUT; + } + context->pollfd_index = pollfd_index; + pollfd_index++; + }else{ + context->bridge->cur_address++; + if(context->bridge->cur_address == context->bridge->address_count){ + context->bridge->cur_address = 0; + } } - context->pollfd_index = pollfd_index; - pollfd_index++; }else{ - context->bridge->cur_address++; - if(context->bridge->cur_address == context->bridge->address_count){ - context->bridge->cur_address = 0; + rc = mqtt3_bridge_connect_step1(db, context); + if(rc){ + context->bridge->cur_address++; + if(context->bridge->cur_address == context->bridge->address_count){ + context->bridge->cur_address = 0; + } } } - } - if(context->bridge->start_type == bst_automatic && now > context->bridge->restart_t){ - context->bridge->restart_t = 0; - rc = mqtt3_bridge_connect(db, context); - if(rc == MOSQ_ERR_SUCCESS){ - pollfds[pollfd_index].fd = context->sock; - pollfds[pollfd_index].events = POLLIN; - pollfds[pollfd_index].revents = 0; - if(context->current_out_packet){ - pollfds[pollfd_index].events |= POLLOUT; - } - context->pollfd_index = pollfd_index; - pollfd_index++; - }else{ - /* Retry later. */ - context->bridge->restart_t = now+context->bridge->restart_timeout; - - context->bridge->cur_address++; - if(context->bridge->cur_address == context->bridge->address_count){ - context->bridge->cur_address = 0; +#else + { + rc = mqtt3_bridge_connect(db, context); + if(rc == MOSQ_ERR_SUCCESS){ + pollfds[pollfd_index].fd = context->sock; + pollfds[pollfd_index].events = POLLIN; + pollfds[pollfd_index].revents = 0; + if(context->current_out_packet){ + pollfds[pollfd_index].events |= POLLOUT; + } + context->pollfd_index = pollfd_index; + pollfd_index++; + }else{ + context->bridge->cur_address++; + if(context->bridge->cur_address == context->bridge->address_count){ + context->bridge->cur_address = 0; + } } } +#endif } } } diff --git a/src/mosquitto_broker.h b/src/mosquitto_broker.h index bd6a0ef7..c89489b6 100644 --- a/src/mosquitto_broker.h +++ b/src/mosquitto_broker.h @@ -466,6 +466,8 @@ int _mosquitto_log_printf(struct mosquitto *mosq, int level, const char *fmt, .. #ifdef WITH_BRIDGE int mqtt3_bridge_new(struct mosquitto_db *db, struct _mqtt3_bridge *bridge); int mqtt3_bridge_connect(struct mosquitto_db *db, struct mosquitto *context); +int mqtt3_bridge_connect_step1(struct mosquitto_db *db, struct mosquitto *context); +int mqtt3_bridge_connect_step2(struct mosquitto_db *db, struct mosquitto *context); void mqtt3_bridge_packet_cleanup(struct mosquitto *context); #endif From e0e8cc9f3e7c3b3d1e283250725a174ad3670ef7 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Mon, 6 Feb 2017 23:10:43 +0000 Subject: [PATCH 48/62] [344] Fix leaks and incorrect connect call. --- lib/net_mosq.h | 1 + src/bridge.c | 16 +++++++++++++++- src/loop.c | 36 ++++++++++++++++++++++++------------ 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/lib/net_mosq.h b/lib/net_mosq.h index 569e9452..b504ebc0 100644 --- a/lib/net_mosq.h +++ b/lib/net_mosq.h @@ -63,6 +63,7 @@ int _mosquitto_socket_close(struct mosquitto *mosq); int _mosquitto_try_connect(struct mosquitto *mosq, const char *host, uint16_t port, mosq_sock_t *sock, const char *bind_address, bool blocking); int _mosquitto_try_connect_step1(struct mosquitto *mosq, const char *host); int _mosquitto_try_connect_step2(struct mosquitto *mosq, uint16_t port, mosq_sock_t *sock); +int _mosquitto_socket_connect_step3(struct mosquitto *mosq, const char *host, uint16_t port, const char *bind_address, bool blocking); int _mosquitto_socket_nonblock(mosq_sock_t sock); int _mosquitto_socketpair(mosq_sock_t *sp1, mosq_sock_t *sp2); diff --git a/src/bridge.c b/src/bridge.c index e9a3d0ee..5f5eb1b3 100644 --- a/src/bridge.c +++ b/src/bridge.c @@ -238,7 +238,21 @@ int mqtt3_bridge_connect_step2(struct mosquitto_db *db, struct mosquitto *contex if(!context || !context->bridge) return MOSQ_ERR_INVAL; _mosquitto_log_printf(NULL, MOSQ_LOG_NOTICE, "Connecting bridge %s (%s:%d)", context->bridge->name, context->bridge->addresses[context->bridge->cur_address].address, context->bridge->addresses[context->bridge->cur_address].port); - rc = _mosquitto_socket_connect(context, context->bridge->addresses[context->bridge->cur_address].address, context->bridge->addresses[context->bridge->cur_address].port, NULL, false); + rc = _mosquitto_try_connect_step2(context, context->bridge->addresses[context->bridge->cur_address].port, &context->sock); + if(rc > 0 ){ + if(rc == MOSQ_ERR_TLS){ + _mosquitto_socket_close(db, context); + return rc; /* Error already printed */ + }else if(rc == MOSQ_ERR_ERRNO){ + _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error creating bridge: %s.", strerror(errno)); + }else if(rc == MOSQ_ERR_EAI){ + _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error creating bridge: %s.", gai_strerror(errno)); + } + + return rc; + } + + rc = _mosquitto_socket_connect_step3(context, context->bridge->addresses[context->bridge->cur_address].address, context->bridge->addresses[context->bridge->cur_address].port, NULL, false); if(rc > 0 ){ if(rc == MOSQ_ERR_TLS){ _mosquitto_socket_close(db, context); diff --git a/src/loop.c b/src/loop.c index d3d5e6a8..a4014f0c 100644 --- a/src/loop.c +++ b/src/loop.c @@ -250,21 +250,33 @@ int mosquitto_main_loop(struct mosquitto_db *db, mosq_sock_t *listensock, int li #ifdef __linux__ if(context->adns){ /* Waiting on DNS lookup */ - rc = mqtt3_bridge_connect_step2(db, context); - if(rc == MOSQ_ERR_SUCCESS){ - pollfds[pollfd_index].fd = context->sock; - pollfds[pollfd_index].events = POLLIN; - pollfds[pollfd_index].revents = 0; - if(context->current_out_packet){ - pollfds[pollfd_index].events |= POLLOUT; + rc = gai_error(context->adns); + if(rc == EAI_INPROGRESS){ + /* Just keep on waiting */ + }else if(rc == 0){ + rc = mqtt3_bridge_connect_step2(db, context); + if(rc == MOSQ_ERR_SUCCESS){ + pollfds[pollfd_index].fd = context->sock; + pollfds[pollfd_index].events = POLLIN; + pollfds[pollfd_index].revents = 0; + if(context->current_out_packet){ + pollfds[pollfd_index].events |= POLLOUT; + } + context->pollfd_index = pollfd_index; + pollfd_index++; + }else{ + context->bridge->cur_address++; + if(context->bridge->cur_address == context->bridge->address_count){ + context->bridge->cur_address = 0; + } } - context->pollfd_index = pollfd_index; - pollfd_index++; }else{ - context->bridge->cur_address++; - if(context->bridge->cur_address == context->bridge->address_count){ - context->bridge->cur_address = 0; + /* Need to retry */ + if(context->adns->ar_result){ + freeaddrinfo(context->adns->ar_result); } + _mosquitto_free(context->adns); + context->adns = NULL; } }else{ rc = mqtt3_bridge_connect_step1(db, context); From 5eae4b56d6c738aa72da90689d21d013348fb76d Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Tue, 7 Feb 2017 16:11:57 +0000 Subject: [PATCH 49/62] [344] More leak fixes. --- lib/net_mosq.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/net_mosq.c b/lib/net_mosq.c index 24174f09..c8776c1a 100644 --- a/lib/net_mosq.c +++ b/lib/net_mosq.c @@ -290,6 +290,8 @@ int _mosquitto_try_connect_step1(struct mosquitto *mosq, const char *host) s = getaddrinfo_a(GAI_NOWAIT, &mosq->adns, 1, sevp); if(s){ errno = s; + _mosquitto_free(mosq->adns); + mosq->adns = NULL; return MOSQ_ERR_EAI; } @@ -343,10 +345,16 @@ int _mosquitto_try_connect_step2(struct mosquitto *mosq, uint16_t port, mosq_soc COMPAT_CLOSE(*sock); *sock = INVALID_SOCKET; } - freeaddrinfo(ainfo); + freeaddrinfo(mosq->adns->ar_result); + mosq->adns->ar_result = NULL; + + _mosquitto_free(mosq->adns); + mosq->adns = NULL; + if(!rp){ return MOSQ_ERR_ERRNO; } + return rc; } From 6f45ab9624c93ac0fe1929dc9f5f440f693bcf54 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Wed, 8 Feb 2017 15:40:44 +0000 Subject: [PATCH 50/62] [344] Only do async dns on glibc. --- lib/mosquitto_internal.h | 2 +- lib/net_mosq.c | 2 +- src/bridge.c | 2 +- src/loop.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/mosquitto_internal.h b/lib/mosquitto_internal.h index 640de160..e401a2fb 100644 --- a/lib/mosquitto_internal.h +++ b/lib/mosquitto_internal.h @@ -155,7 +155,7 @@ struct mosquitto { #ifndef WITH_BROKER mosq_sock_t sockpairR, sockpairW; #endif -#ifdef __linux__ +#ifdef __GLIBC__ struct gaicb *adns; /* For getaddrinfo_a */ #endif enum _mosquitto_protocol protocol; diff --git a/lib/net_mosq.c b/lib/net_mosq.c index c8776c1a..c98b2746 100644 --- a/lib/net_mosq.c +++ b/lib/net_mosq.c @@ -271,7 +271,7 @@ static unsigned int psk_client_callback(SSL *ssl, const char *hint, } #endif -#if defined(WITH_BROKER) && defined(__linux__) +#if defined(WITH_BROKER) && defined(__GLIBC__) /* Async connect, part 1 (dns lookup) */ int _mosquitto_try_connect_step1(struct mosquitto *mosq, const char *host) { diff --git a/src/bridge.c b/src/bridge.c index 5f5eb1b3..ad9ef1d8 100644 --- a/src/bridge.c +++ b/src/bridge.c @@ -131,7 +131,7 @@ int mqtt3_bridge_new(struct mosquitto_db *db, struct _mqtt3_bridge *bridge) return MOSQ_ERR_NOMEM; } -#ifdef __linux__ +#ifdef __GLIBC__ new_context->bridge->restart_t = 1; /* force quick restart of bridge */ return mqtt3_bridge_connect_step1(db, new_context); #else diff --git a/src/loop.c b/src/loop.c index a4014f0c..dba3c5ea 100644 --- a/src/loop.c +++ b/src/loop.c @@ -247,7 +247,7 @@ int mosquitto_main_loop(struct mosquitto_db *db, mosq_sock_t *listensock, int li if((context->bridge->start_type == bst_lazy && context->bridge->lazy_reconnect) || (context->bridge->start_type == bst_automatic && now > context->bridge->restart_t)){ -#ifdef __linux__ +#ifdef __GLIBC__ if(context->adns){ /* Waiting on DNS lookup */ rc = gai_error(context->adns); From 8406c08124a6984053c95b41cceff87878278a32 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Wed, 8 Feb 2017 16:24:50 +0000 Subject: [PATCH 51/62] [344] Detect libanl in cmake. --- src/CMakeLists.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9d615636..6918ac26 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -82,6 +82,16 @@ add_executable(mosquitto ${MOSQ_SRCS}) set (MOSQ_LIBS ${MOSQ_LIBS} ${OPENSSL_LIBRARIES}) +# Check for getaddrinfo_a +include(CheckLibraryExists) +check_library_exists(anl getaddrinfo_a "" HAVE_GETADDRINFO_A) +if (HAVE_GETADDRINFO_A) + add_definitions(-DHAVE_GETADDRINFO_A) + set (MOSQ_LIBS ${MOSQ_LIBS} anl) +endif (HAVE_GETADDRINFO_A) + + + if (UNIX) if (APPLE) set (MOSQ_LIBS ${MOSQ_LIBS} dl m) From 433ee5c4d6852b507b43eae9c9a2c9028c6b48e5 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Wed, 8 Feb 2017 22:30:00 +0000 Subject: [PATCH 52/62] [344] Don't compile in async dns support by default for makefiles. --- config.mk | 8 ++++++++ lib/mosquitto_internal.h | 2 +- lib/net_mosq.c | 2 +- src/bridge.c | 2 +- src/loop.c | 2 +- 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/config.mk b/config.mk index 3d2aa499..02df80b2 100644 --- a/config.mk +++ b/config.mk @@ -76,6 +76,9 @@ WITH_DOCS:=yes # Build with client support for SOCK5 proxy. WITH_SOCKS:=yes +# Build with async dns lookup support for bridges (temporary). Requires glibc. +#WITH_ADNS:=yes + # ============================================================================= # End of user configuration # ============================================================================= @@ -239,6 +242,11 @@ ifeq ($(WITH_EC),yes) BROKER_CFLAGS:=$(BROKER_CFLAGS) -DWITH_EC endif +ifeq ($(WITH_ADNS),yes) + BROKER_LIBS:=$(BROKER_LIBS) -lanl + BROKER_CFLAGS:=$(BROKER_CFLAGS) -DWITH_ADNS +endif + MAKE_ALL:=mosquitto ifeq ($(WITH_DOCS),yes) MAKE_ALL:=$(MAKE_ALL) docs diff --git a/lib/mosquitto_internal.h b/lib/mosquitto_internal.h index e401a2fb..ac925738 100644 --- a/lib/mosquitto_internal.h +++ b/lib/mosquitto_internal.h @@ -155,7 +155,7 @@ struct mosquitto { #ifndef WITH_BROKER mosq_sock_t sockpairR, sockpairW; #endif -#ifdef __GLIBC__ +#if defined(__GLIBC__) && defined(WITH_ADNS) struct gaicb *adns; /* For getaddrinfo_a */ #endif enum _mosquitto_protocol protocol; diff --git a/lib/net_mosq.c b/lib/net_mosq.c index c98b2746..06c9bce2 100644 --- a/lib/net_mosq.c +++ b/lib/net_mosq.c @@ -271,7 +271,7 @@ static unsigned int psk_client_callback(SSL *ssl, const char *hint, } #endif -#if defined(WITH_BROKER) && defined(__GLIBC__) +#if defined(WITH_BROKER) && defined(__GLIBC__) && defined(WITH_ADNS) /* Async connect, part 1 (dns lookup) */ int _mosquitto_try_connect_step1(struct mosquitto *mosq, const char *host) { diff --git a/src/bridge.c b/src/bridge.c index ad9ef1d8..869b3db1 100644 --- a/src/bridge.c +++ b/src/bridge.c @@ -131,7 +131,7 @@ int mqtt3_bridge_new(struct mosquitto_db *db, struct _mqtt3_bridge *bridge) return MOSQ_ERR_NOMEM; } -#ifdef __GLIBC__ +#if defined(__GLIBC__) && defined(WITH_ADNS) new_context->bridge->restart_t = 1; /* force quick restart of bridge */ return mqtt3_bridge_connect_step1(db, new_context); #else diff --git a/src/loop.c b/src/loop.c index dba3c5ea..b7e8b752 100644 --- a/src/loop.c +++ b/src/loop.c @@ -247,7 +247,7 @@ int mosquitto_main_loop(struct mosquitto_db *db, mosq_sock_t *listensock, int li if((context->bridge->start_type == bst_lazy && context->bridge->lazy_reconnect) || (context->bridge->start_type == bst_automatic && now > context->bridge->restart_t)){ -#ifdef __GLIBC__ +#if defined(__GLIBC__) && defined(WITH_ADNS) if(context->adns){ /* Waiting on DNS lookup */ rc = gai_error(context->adns); From b55e7035ffcc0f942e77bdcb25750d711a79dfdb Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 9 Feb 2017 16:41:48 +0000 Subject: [PATCH 53/62] [344] Fix non-async case. --- src/bridge.c | 111 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 107 insertions(+), 4 deletions(-) diff --git a/src/bridge.c b/src/bridge.c index 869b3db1..dc5f9c44 100644 --- a/src/bridge.c +++ b/src/bridge.c @@ -139,6 +139,7 @@ int mqtt3_bridge_new(struct mosquitto_db *db, struct _mqtt3_bridge *bridge) #endif } +#if defined(__GLIBC__) && defined(WITH_ADNS) int mqtt3_bridge_connect_step1(struct mosquitto_db *db, struct mosquitto *context) { int rc; @@ -288,17 +289,119 @@ int mqtt3_bridge_connect_step2(struct mosquitto_db *db, struct mosquitto *contex return rc; } } - +#else int mqtt3_bridge_connect(struct mosquitto_db *db, struct mosquitto *context) { int rc; + int i; + char *notification_topic; + int notification_topic_len; + uint8_t notification_payload; + + if(!context || !context->bridge) return MOSQ_ERR_INVAL; + + context->state = mosq_cs_new; + context->sock = INVALID_SOCKET; + context->last_msg_in = mosquitto_time(); + context->next_msg_out = mosquitto_time() + context->bridge->keepalive; + context->keepalive = context->bridge->keepalive; + context->clean_session = context->bridge->clean_session; + context->in_packet.payload = NULL; + context->ping_t = 0; + context->bridge->lazy_reconnect = false; + mqtt3_bridge_packet_cleanup(context); + mqtt3_db_message_reconnect_reset(db, context); + + if(context->clean_session){ + mqtt3_db_messages_delete(db, context); + } + + /* Delete all local subscriptions even for clean_session==false. We don't + * remove any messages and the next loop carries out the resubscription + * anyway. This means any unwanted subs will be removed. + */ + mqtt3_subs_clean_session(db, context); + + for(i=0; ibridge->topic_count; i++){ + if(context->bridge->topics[i].direction == bd_out || context->bridge->topics[i].direction == bd_both){ + _mosquitto_log_printf(NULL, MOSQ_LOG_DEBUG, "Bridge %s doing local SUBSCRIBE on topic %s", context->id, context->bridge->topics[i].local_topic); + if(mqtt3_sub_add(db, context, context->bridge->topics[i].local_topic, context->bridge->topics[i].qos, &db->subs)) return 1; + } + } - rc = mqtt3_bridge_connect_step1(db, context); - if(rc) return rc; + if(context->bridge->notifications){ + if(context->bridge->notification_topic){ + if(!context->bridge->initial_notification_done){ + notification_payload = '0'; + mqtt3_db_messages_easy_queue(db, context, context->bridge->notification_topic, 1, 1, ¬ification_payload, 1); + context->bridge->initial_notification_done = true; + } + notification_payload = '0'; + rc = _mosquitto_will_set(context, context->bridge->notification_topic, 1, ¬ification_payload, 1, true); + if(rc != MOSQ_ERR_SUCCESS){ + return rc; + } + }else{ + notification_topic_len = strlen(context->bridge->remote_clientid)+strlen("$SYS/broker/connection//state"); + notification_topic = _mosquitto_malloc(sizeof(char)*(notification_topic_len+1)); + if(!notification_topic) return MOSQ_ERR_NOMEM; - return mqtt3_bridge_connect_step2(db, context); + snprintf(notification_topic, notification_topic_len+1, "$SYS/broker/connection/%s/state", context->bridge->remote_clientid); + + if(!context->bridge->initial_notification_done){ + notification_payload = '0'; + mqtt3_db_messages_easy_queue(db, context, notification_topic, 1, 1, ¬ification_payload, 1); + context->bridge->initial_notification_done = true; + } + + notification_payload = '0'; + rc = _mosquitto_will_set(context, notification_topic, 1, ¬ification_payload, 1, true); + _mosquitto_free(notification_topic); + if(rc != MOSQ_ERR_SUCCESS){ + return rc; + } + } + } + + _mosquitto_log_printf(NULL, MOSQ_LOG_NOTICE, "Connecting bridge %s (%s:%d)", context->bridge->name, context->bridge->addresses[context->bridge->cur_address].address, context->bridge->addresses[context->bridge->cur_address].port); + rc = _mosquitto_socket_connect(context, context->bridge->addresses[context->bridge->cur_address].address, context->bridge->addresses[context->bridge->cur_address].port, NULL, false); + if(rc > 0 ){ + if(rc == MOSQ_ERR_TLS){ + _mosquitto_socket_close(db, context); + return rc; /* Error already printed */ + }else if(rc == MOSQ_ERR_ERRNO){ + _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error creating bridge: %s.", strerror(errno)); + }else if(rc == MOSQ_ERR_EAI){ + _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error creating bridge: %s.", gai_strerror(errno)); + } + + return rc; + } + + HASH_ADD(hh_sock, db->contexts_by_sock, sock, sizeof(context->sock), context); + + if(rc == MOSQ_ERR_CONN_PENDING){ + context->state = mosq_cs_connect_pending; + } + rc = _mosquitto_send_connect(context, context->keepalive, context->clean_session); + if(rc == MOSQ_ERR_SUCCESS){ + return MOSQ_ERR_SUCCESS; + }else if(rc == MOSQ_ERR_ERRNO && errno == ENOTCONN){ + return MOSQ_ERR_SUCCESS; + }else{ + if(rc == MOSQ_ERR_TLS){ + return rc; /* Error already printed */ + }else if(rc == MOSQ_ERR_ERRNO){ + _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error creating bridge: %s.", strerror(errno)); + }else if(rc == MOSQ_ERR_EAI){ + _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error creating bridge: %s.", gai_strerror(errno)); + } + _mosquitto_socket_close(db, context); + return rc; + } } +#endif void mqtt3_bridge_packet_cleanup(struct mosquitto *context) From 1a0240b5d5c3db14e83e1dfa2c81acad5052def8 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Sun, 12 Feb 2017 21:22:58 +0000 Subject: [PATCH 54/62] [379] Improve mosquitto_passwd error messages. Thanks to Jaimyn Mayer. Closes #379. Bug: https://github.com/eclipse/mosquitto/issues/379 --- ChangeLog.txt | 1 + src/mosquitto_passwd.c | 57 ++++++++++++++++++++++++++---------------- 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 00dd0704..c03ad2bc 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -6,6 +6,7 @@ Broker: - For http only websockets clients, close files served over http in all cases when the client disconnects. Closes #354. - Fix error message when websockets http_dir directory does not exist. +- Improve password utility error message. Closes #379. Client library: - Clients can now use TLS with IPv6. diff --git a/src/mosquitto_passwd.c b/src/mosquitto_passwd.c index de9a719a..aa7a8101 100644 --- a/src/mosquitto_passwd.c +++ b/src/mosquitto_passwd.c @@ -377,35 +377,50 @@ int main(int argc, char *argv[]) OpenSSL_add_all_digests(); - if(argc == 5){ - if(!strcmp(argv[1], "-b")){ - batch_mode = true; - }else{ - fprintf(stderr, "Error: Unknown option '%s'\n", argv[1]); + if(argc == 1){ + print_usage(); + return 1; + } + + if(!strcmp(argv[1], "-c")){ + create_new = true; + if(argc != 4){ + fprintf(stderr, "Error: -c argument given but password file or username missing.\n"); return 1; + }else{ + password_file_tmp = argv[2]; + username = argv[3]; } - password_file_tmp = argv[2]; - username = argv[3]; - password_cmd = argv[4]; - }else if(argc == 4){ - if(!strcmp(argv[1], "-c")){ - create_new = true; - }else if(!strcmp(argv[1], "-D")){ - delete_user = true; + }else if(!strcmp(argv[1], "-D")){ + delete_user = true; + if(argc != 4){ + fprintf(stderr, "Error: -D argument given but password file or username missing.\n"); + return 1; }else{ - fprintf(stderr, "Error: Unknown option '%s'\n", argv[1]); + password_file_tmp = argv[2]; + username = argv[3]; + } + }else if(!strcmp(argv[1], "-b")){ + batch_mode = true; + if(argc != 5){ + fprintf(stderr, "Error: -b argument given but password file, username or password missing.\n"); return 1; + }else{ + password_file_tmp = argv[2]; + username = argv[3]; + password_cmd = argv[4]; } - password_file_tmp = argv[2]; - username = argv[3]; - }else if(argc == 3){ - if(!strcmp(argv[1], "-U")){ + }else if(!strcmp(argv[1], "-U")){ + if(argc != 3){ + fprintf(stderr, "Error: -U argument given but password file missing.\n"); + return 1; + }else{ do_update_file = true; password_file_tmp = argv[2]; - }else{ - password_file_tmp = argv[1]; - username = argv[2]; } + }else if(argc == 3){ + password_file_tmp = argv[1]; + username = argv[2]; }else{ print_usage(); return 1; From cac5464f7f2843beb0d4dd65b7766b6e5e8c7c23 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Wed, 15 Feb 2017 21:01:49 +0000 Subject: [PATCH 55/62] Use of --ciphers no longer requires you to also pass --tls-version. Closes #380. Bug: https://github.com/eclipse/mosquitto/issues/380 --- ChangeLog.txt | 4 ++++ client/client_shared.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index c03ad2bc..c3e05be7 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -8,6 +8,10 @@ Broker: - Fix error message when websockets http_dir directory does not exist. - Improve password utility error message. Closes #379. +Clients: +- Use of --ciphers no longer requires you to also pass --tls-version. + Closes #380. + Client library: - Clients can now use TLS with IPv6. - Fix potential socket leakage when reconnecting. Closes #304. diff --git a/client/client_shared.c b/client/client_shared.c index cecc5ab5..b82d6c24 100644 --- a/client/client_shared.c +++ b/client/client_shared.c @@ -690,7 +690,7 @@ int client_opts_set(struct mosquitto *mosq, struct mosq_config *cfg) return 1; } # endif - if(cfg->tls_version && mosquitto_tls_opts_set(mosq, 1, cfg->tls_version, cfg->ciphers)){ + if((cfg->tls_version || cfg->ciphers) && mosquitto_tls_opts_set(mosq, 1, cfg->tls_version, cfg->ciphers)){ if(!cfg->quiet) fprintf(stderr, "Error: Problem setting TLS options.\n"); mosquitto_lib_cleanup(); return 1; From 92f3d50b8e48598f77e50062e4ed7844209f5e00 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Mon, 20 Feb 2017 21:20:00 +0000 Subject: [PATCH 56/62] EPROTO is defined on MSVC 2015. --- config.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/config.h b/config.h index fbe4babb..6af5c283 100644 --- a/config.h +++ b/config.h @@ -13,6 +13,7 @@ * ============================================================ */ #if defined(_MSC_VER) && _MSC_VER < 1900 # define snprintf sprintf_s +# define EPROTO ECONNABORTED #endif #ifdef WIN32 @@ -27,6 +28,3 @@ #define uthash_malloc(sz) _mosquitto_malloc(sz) #define uthash_free(ptr,sz) _mosquitto_free(ptr) -#ifndef EPROTO -# define EPROTO ECONNABORTED -#endif From 9a2987c145b797cfcd1bbcfb506327de13f8f50f Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Mon, 20 Feb 2017 21:48:25 +0000 Subject: [PATCH 57/62] Missing malloc check. --- client/client_shared.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/client/client_shared.c b/client/client_shared.c index b82d6c24..caa33e18 100644 --- a/client/client_shared.c +++ b/client/client_shared.c @@ -924,6 +924,10 @@ static int mosquitto__parse_socks_url(struct mosq_config *cfg, char *url) port[len] = '\0'; }else{ host = malloc(len + 1); + if(!host){ + fprintf(stderr, "Error: Out of memory.\n"); + goto cleanup; + } memcpy(host, &(str[start]), len); host[len] = '\0'; } From bda989371312780cc544ee246b107d3b42afa669 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Mon, 20 Feb 2017 21:57:45 +0000 Subject: [PATCH 58/62] Version bump. --- CMakeLists.txt | 2 +- ChangeLog.txt | 3 +++ config.mk | 2 +- installer/mosquitto-cygwin.nsi | 2 +- installer/mosquitto.nsi | 2 +- lib/mosquitto.h | 2 +- set-version.sh | 2 +- 7 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 29fb4b45..b0f29a2d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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.4.10) +set (VERSION 1.4.11) if (WIN32) execute_process(COMMAND cmd /c echo %DATE% %TIME% OUTPUT_VARIABLE TIMESTAMP diff --git a/ChangeLog.txt b/ChangeLog.txt index c3e05be7..57f9ee2c 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,6 @@ +1.4.11 - 20170220 +================= + Broker: - Fix crash when "lazy" type bridge attempts to reconnect. Closes #259. - maximum_connections now applies to websockets listeners. Closes #271. diff --git a/config.mk b/config.mk index 02df80b2..6e369c23 100644 --- a/config.mk +++ b/config.mk @@ -86,7 +86,7 @@ WITH_SOCKS:=yes # Also bump lib/mosquitto.h, CMakeLists.txt, # installer/mosquitto.nsi, installer/mosquitto-cygwin.nsi -VERSION=1.4.10 +VERSION=1.4.11 TIMESTAMP:=$(shell date "+%F %T%z") # Client library SO version. Bump if incompatible API/ABI changes are made. diff --git a/installer/mosquitto-cygwin.nsi b/installer/mosquitto-cygwin.nsi index eea6ae42..1567c73b 100644 --- a/installer/mosquitto-cygwin.nsi +++ b/installer/mosquitto-cygwin.nsi @@ -7,7 +7,7 @@ !define env_hklm 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"' Name "mosquitto" -!define VERSION 1.4.10 +!define VERSION 1.4.11 OutFile "mosquitto-${VERSION}-install-cygwin.exe" InstallDir "$PROGRAMFILES\mosquitto" diff --git a/installer/mosquitto.nsi b/installer/mosquitto.nsi index 7dc4d1f8..4afe737b 100644 --- a/installer/mosquitto.nsi +++ b/installer/mosquitto.nsi @@ -9,7 +9,7 @@ !define env_hklm 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"' Name "mosquitto" -!define VERSION 1.4.10 +!define VERSION 1.4.11 OutFile "mosquitto-${VERSION}-install-win32.exe" InstallDir "$PROGRAMFILES\mosquitto" diff --git a/lib/mosquitto.h b/lib/mosquitto.h index 2058d59a..43e1f15f 100644 --- a/lib/mosquitto.h +++ b/lib/mosquitto.h @@ -45,7 +45,7 @@ extern "C" { #define LIBMOSQUITTO_MAJOR 1 #define LIBMOSQUITTO_MINOR 4 -#define LIBMOSQUITTO_REVISION 10 +#define LIBMOSQUITTO_REVISION 11 /* 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) diff --git a/set-version.sh b/set-version.sh index 71631010..75c0b529 100755 --- a/set-version.sh +++ b/set-version.sh @@ -2,7 +2,7 @@ MAJOR=1 MINOR=4 -REVISION=9 +REVISION=11 sed -i "s/^VERSION=.*/VERSION=${MAJOR}.${MINOR}.${REVISION}/" config.mk From 81340aa5bb5c46f40ebe4c3b8a1cfbc09e5ee009 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Tue, 21 Feb 2017 12:02:02 +0000 Subject: [PATCH 59/62] Add snap support. --- snap/mosquitto.conf | 3 +++ snap/snapcraft.yaml | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 snap/mosquitto.conf create mode 100644 snap/snapcraft.yaml diff --git a/snap/mosquitto.conf b/snap/mosquitto.conf new file mode 100644 index 00000000..43396eb7 --- /dev/null +++ b/snap/mosquitto.conf @@ -0,0 +1,3 @@ +port 1883 +persistence true +user root diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml new file mode 100644 index 00000000..261b9fa7 --- /dev/null +++ b/snap/snapcraft.yaml @@ -0,0 +1,45 @@ +name: mosquitto-simple +version: 1.4.11 +summary: Eclipse Mosquitto MQTT broker +description: This is a message broker that supports version 3.1 and 3.1.1 of the MQTT + protocol. + MQTT provides a method of carrying out messaging using a publish/subscribe + model. It is lightweight, both in terms of bandwidth usage and ease of + implementation. This makes it particularly useful at the edge of the network + where a sensor or other simple device may be implemented using an arduino for + example. +confinement: strict + +apps: + mosquitto: + command: usr/local/sbin/mosquitto -c $SNAP/mosquitto.conf + daemon: simple + restart-condition: always + plugs: [network, network-bind] + + +parts: + script: + plugin: dump + source: snap/ + prime: + - mosquitto.conf + + + mosquitto: + plugin: make + source: https://github.com/eclipse/mosquitto + source-type: git + + build-packages: + - libssl-dev + - uuid-dev + stage-packages: + - libssl1.0.0 + - libuuid1 + prime: + - usr/local/sbin/mosquitto + - lib/*-linux-gnu/libcrypto.so* + - lib/*-linux-gnu/libssl.so* + - lib/*-linux-gnu/libuuid.so* + From 7cd2119db47a584f70446d2bd359d739791fd0dc Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Tue, 21 Feb 2017 13:25:51 +0000 Subject: [PATCH 60/62] Need libc-ares. --- snap/snapcraft.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 261b9fa7..d9053f7d 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -34,9 +34,11 @@ parts: build-packages: - libssl-dev - uuid-dev + - libc-ares-dev stage-packages: - libssl1.0.0 - libuuid1 + - libc-ares2 prime: - usr/local/sbin/mosquitto - lib/*-linux-gnu/libcrypto.so* From cac1724bff5da2cae739f6bc67f4a7258e172f87 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Tue, 21 Feb 2017 19:38:52 +0000 Subject: [PATCH 61/62] xsltproc dep for building from git. --- snap/snapcraft.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index d9053f7d..5c30ff0f 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -35,6 +35,7 @@ parts: - libssl-dev - uuid-dev - libc-ares-dev + - xsltproc stage-packages: - libssl1.0.0 - libuuid1 From 4c43f4ce6458a111354d390729102364293bc3b9 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Wed, 22 Feb 2017 07:49:39 +0000 Subject: [PATCH 62/62] Snaps also need docbook-xsl. --- snap/snapcraft.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 5c30ff0f..b5925130 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -36,6 +36,7 @@ parts: - uuid-dev - libc-ares-dev - xsltproc + - docbook-xsl stage-packages: - libssl1.0.0 - libuuid1