From f7dc138157ca2252d7ed58b61daad19b63fcfe4c Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Fri, 11 Dec 2020 00:02:43 +0000 Subject: [PATCH 01/18] Fix `install` target when using WITH_CJSON=no. Closes #1938. Thanks to apple3306 and JulianCaruso. --- ChangeLog.txt | 4 ++++ apps/mosquitto_ctrl/Makefile | 6 +++++- plugins/dynamic-security/Makefile | 6 +++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 14bc5086..2923806f 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,7 @@ +Build: +- Fix `install` target when using WITH_CJSON=no. Closes #1938. + + 2.0.2 - 2020-12-10 ================== diff --git a/apps/mosquitto_ctrl/Makefile b/apps/mosquitto_ctrl/Makefile index 3a4843bf..d2122abc 100644 --- a/apps/mosquitto_ctrl/Makefile +++ b/apps/mosquitto_ctrl/Makefile @@ -36,7 +36,7 @@ else TARGET:= endif -all : $(TARGET) +all : ${TARGET} mosquitto_ctrl : ${OBJS} ${CROSS_COMPILE}${CC} ${APP_LDFLAGS} $^ -o $@ $(PASSWD_LDADD) $(LOCAL_LDFLAGS) $(LIBMOSQ) -lcjson -ldl @@ -84,8 +84,12 @@ password_mosq.o : ../../src/password_mosq.c ../../src/password_mosq.h ${CROSS_COMPILE}${CC} $(APP_CPPFLAGS) $(APP_CFLAGS) -c $< -o $@ install : all +ifeq ($(WITH_TLS),yes) +ifeq ($(WITH_CJSON),yes) $(INSTALL) -d "${DESTDIR}$(prefix)/bin" $(INSTALL) ${STRIP_OPTS} mosquitto_ctrl "${DESTDIR}${prefix}/bin/mosquitto_ctrl" +endif +endif uninstall : -rm -f "${DESTDIR}${prefix}/bin/mosquitto_ctrl" diff --git a/plugins/dynamic-security/Makefile b/plugins/dynamic-security/Makefile index 203fbc3e..810a17ba 100644 --- a/plugins/dynamic-security/Makefile +++ b/plugins/dynamic-security/Makefile @@ -74,9 +74,13 @@ clean: check: test test: -install: ${PLUGIN_NAME}.so +install: all +ifeq ($(WITH_CJSON),yes) +ifeq ($(WITH_TLS),yes) $(INSTALL) -d "${DESTDIR}$(prefix)/lib" $(INSTALL) ${STRIP_OPTS} ${PLUGIN_NAME}.so "${DESTDIR}${prefix}/lib/${PLUGIN_NAME}.so" +endif +endif uninstall : -rm -f "${DESTDIR}${prefix}/lib/${PLUGIN_NAME}.so" From abac67299f00e20bf645f8c9bfcc3e28fa8cd99f Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Sat, 12 Dec 2020 21:53:28 +0000 Subject: [PATCH 02/18] Fix excessive CPU use on non-Linux systems when the open file limit is set high. Closes #1947. Thanks to Patrick TJ McPhee. --- ChangeLog.txt | 4 ++++ src/mux_poll.c | 30 +++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 2923806f..817f99ec 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,7 @@ +Broker: +- Fix excessive CPU use on non-Linux systems when the open file limit is set + high. Closes #1947. + Build: - Fix `install` target when using WITH_CJSON=no. Closes #1938. diff --git a/src/mux_poll.c b/src/mux_poll.c index 7f256916..79926641 100644 --- a/src/mux_poll.c +++ b/src/mux_poll.c @@ -59,15 +59,15 @@ Contributors: static void loop_handle_reads_writes(struct pollfd *pollfds); static struct pollfd *pollfds = NULL; -static size_t pollfd_max; +static size_t pollfd_max, pollfd_current_max; #ifndef WIN32 static sigset_t my_sigblock; #endif int mux_poll__init(struct mosquitto__listener_sock *listensock, int listensock_count) { - int i; - int pollfd_index = 0; + size_t i; + size_t pollfd_index = 0; #ifndef WIN32 sigemptyset(&my_sigblock); @@ -101,6 +101,7 @@ int mux_poll__init(struct mosquitto__listener_sock *listensock, int listensock_c pollfd_index++; } + pollfd_current_max = pollfd_index-1; return MOSQ_ERR_SUCCESS; } @@ -120,6 +121,9 @@ int mux_poll__add_out(struct mosquitto *context) pollfds[i].events = POLLIN | POLLOUT; pollfds[i].revents = 0; context->pollfd_index = i; + if(i > pollfd_current_max){ + pollfd_current_max = (size_t )i; + } break; } } @@ -150,6 +154,9 @@ int mux_poll__add_in(struct mosquitto *context) pollfds[i].events = POLLIN; pollfds[i].revents = 0; context->pollfd_index = i; + if(i > pollfd_current_max){ + pollfd_current_max = (size_t )i; + } break; } } @@ -160,11 +167,24 @@ int mux_poll__add_in(struct mosquitto *context) int mux_poll__delete(struct mosquitto *context) { + size_t pollfd_index; + if(context->pollfd_index != -1){ pollfds[context->pollfd_index].fd = INVALID_SOCKET; pollfds[context->pollfd_index].events = 0; pollfds[context->pollfd_index].revents = 0; + pollfd_index = (size_t )context->pollfd_index; context->pollfd_index = -1; + + /* If this is the highest index, reduce the current max until we find + * the next highest in use index. */ + while(pollfd_index == pollfd_current_max + && pollfd_index > 0 + && pollfds[pollfd_index].fd == INVALID_SOCKET){ + + pollfd_index--; + pollfd_current_max--; + } } return MOSQ_ERR_SUCCESS; @@ -184,10 +204,10 @@ int mux_poll__handle(struct mosquitto__listener_sock *listensock, int listensock #ifndef WIN32 sigprocmask(SIG_SETMASK, &my_sigblock, &origsig); - fdcount = poll(pollfds, pollfd_max, 100); + fdcount = poll(pollfds, pollfd_current_max+1, 100); sigprocmask(SIG_SETMASK, &origsig, NULL); #else - fdcount = WSAPoll(pollfds, pollfd_max, 100); + fdcount = WSAPoll(pollfds, pollfd_current_max+1, 100); #endif db.now_s = mosquitto_time(); From f63386bf4a8a6e07621a3f4ecae2897b4ea01294 Mon Sep 17 00:00:00 2001 From: Roger Light Date: Sun, 13 Dec 2020 20:32:30 +0000 Subject: [PATCH 03/18] Fix `mosquitto_passwd -b` using username as password. Only applies if if `-c` is not also used. Closes #1949. Thanks to J. Augusto de Oliveira. --- ChangeLog.txt | 4 ++++ apps/mosquitto_passwd/mosquitto_passwd.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 817f99ec..d0d83917 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -2,6 +2,10 @@ Broker: - Fix excessive CPU use on non-Linux systems when the open file limit is set high. Closes #1947. +Apps: +- Fix `mosquitto_passwd -b` using username as password (not if `-c` is also + used). Closes #1949. + Build: - Fix `install` target when using WITH_CJSON=no. Closes #1938. diff --git a/apps/mosquitto_passwd/mosquitto_passwd.c b/apps/mosquitto_passwd/mosquitto_passwd.c index 92613f0f..9495c3c5 100644 --- a/apps/mosquitto_passwd/mosquitto_passwd.c +++ b/apps/mosquitto_passwd/mosquitto_passwd.c @@ -505,7 +505,7 @@ int main(int argc, char *argv[]) }else if(batch_mode == true && idx+3 == argc){ password_file_tmp = argv[idx]; username = argv[idx+1]; - password_cmd = argv[idx+1]; + password_cmd = argv[idx+2]; }else if(batch_mode == false && idx+2 == argc){ password_file_tmp = argv[idx]; username = argv[idx+1]; From 74f3285cf833d57813203f16e20db2eb7707c208 Mon Sep 17 00:00:00 2001 From: Roger Light Date: Sun, 13 Dec 2020 21:11:15 +0000 Subject: [PATCH 04/18] Fix `generic` docker build. Closes #1945. Thanks to Andreas Schildbach. --- ChangeLog.txt | 1 + docker/generic/Dockerfile | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index d0d83917..3255c430 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -8,6 +8,7 @@ Apps: Build: - Fix `install` target when using WITH_CJSON=no. Closes #1938. +- Fix `generic` docker build. Closes #1945. 2.0.2 - 2020-12-10 diff --git a/docker/generic/Dockerfile b/docker/generic/Dockerfile index cc467946..bdda597b 100644 --- a/docker/generic/Dockerfile +++ b/docker/generic/Dockerfile @@ -1,4 +1,4 @@ -FROM alpine:latest AS build +FROM alpine:edge AS build # A released dist version, like "1.2.3" ARG VERSION @@ -6,14 +6,15 @@ RUN test -n "${VERSION}" RUN apk --no-cache add \ build-base \ - openssl-dev \ c-ares-dev \ + ca-certificates \ + cjson-dev \ curl \ - util-linux-dev \ libwebsockets-dev \ libxslt \ + openssl-dev \ python2 \ - ca-certificates + util-linux-dev # This build procedure is based on: # https://github.com/alpinelinux/aports/blob/master/main/mosquitto/APKBUILD @@ -48,6 +49,7 @@ LABEL maintainer="Jonathan Hanson " \ RUN apk --no-cache add \ busybox \ ca-certificates \ + cjson \ openssl \ libuuid \ libwebsockets \ From 113603168bb644715395f86b78e0803f1e6b67a0 Mon Sep 17 00:00:00 2001 From: Roger Light Date: Sun, 13 Dec 2020 23:11:02 +0000 Subject: [PATCH 05/18] Fix LWT not being sent on client takeover. This was not happening for the case when the existing session wasn't being continued. Closes #1946. Thanks to Rory Piper. --- ChangeLog.txt | 2 ++ src/handle_connect.c | 8 +++++ test/broker/07-will-takeover.py | 53 ++++++++++++++++++++++++--------- 3 files changed, 49 insertions(+), 14 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 3255c430..bfdf3d9e 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,6 +1,8 @@ Broker: - Fix excessive CPU use on non-Linux systems when the open file limit is set high. Closes #1947. +- Fix LWT not being sent on client takeover when the existing session wasn't + being continued. Closes #1946. Apps: - Fix `mosquitto_passwd -b` using username as password (not if `-c` is also diff --git a/src/handle_connect.c b/src/handle_connect.c index 7be9833a..5a33fdde 100644 --- a/src/handle_connect.c +++ b/src/handle_connect.c @@ -165,6 +165,14 @@ int connect__on_authorised(struct mosquitto *context, void *auth_data_out, uint1 if(context->clean_start == true){ sub__clean_session(found_context); } + if((found_context->protocol == mosq_p_mqtt5 && found_context->session_expiry_interval == 0) + || (found_context->protocol != mosq_p_mqtt5 && found_context->clean_start == true) + || (context->clean_start == true) + ){ + + context__send_will(found_context); + } + session_expiry__remove(found_context); will_delay__remove(found_context); will__clear(found_context); diff --git a/test/broker/07-will-takeover.py b/test/broker/07-will-takeover.py index 8e04b423..1024a46a 100755 --- a/test/broker/07-will-takeover.py +++ b/test/broker/07-will-takeover.py @@ -5,7 +5,7 @@ from mosq_test_helper import * -def do_test(proto_ver, clean_session): +def do_test(proto_ver, clean_session1, clean_session2): rc = 1 keepalive = 60 @@ -13,17 +13,34 @@ def do_test(proto_ver, clean_session): connect1_packet = mosq_test.gen_connect("will-helper", keepalive=keepalive, proto_ver=proto_ver) connack1_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver) - connect2_packet = mosq_test.gen_connect("will-test", keepalive=keepalive, proto_ver=proto_ver, will_topic="will/test", will_payload=b"LWT", clean_session=clean_session) - connack2a_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver) - if clean_session == False and proto_ver == 4: - connack2b_packet = mosq_test.gen_connack(rc=0, flags=1, proto_ver=proto_ver) + if proto_ver == 5: + if clean_session1 == False: + connect_props1 = mqtt5_props.gen_uint32_prop(mqtt5_props.PROP_SESSION_EXPIRY_INTERVAL, 60) + else: + connect_props1 = mqtt5_props.gen_uint32_prop(mqtt5_props.PROP_SESSION_EXPIRY_INTERVAL, 0) + + if clean_session2 == False: + connect_props2 = mqtt5_props.gen_uint32_prop(mqtt5_props.PROP_SESSION_EXPIRY_INTERVAL, 60) + else: + connect_props2 = mqtt5_props.gen_uint32_prop(mqtt5_props.PROP_SESSION_EXPIRY_INTERVAL, 0) else: - connack2b_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver) + connect_props1 = b"" + connect_props2 = b"" + + connect2_packet = mosq_test.gen_connect("will-test", keepalive=keepalive, proto_ver=proto_ver, will_topic="will/test", will_payload=b"LWT", clean_session=clean_session1, properties=connect_props1) + connack2_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver) + + connect3_packet = mosq_test.gen_connect("will-test", keepalive=keepalive, proto_ver=proto_ver, clean_session=clean_session2, properties=connect_props2) + if clean_session1 == False and clean_session2 == False: + connack3_packet = mosq_test.gen_connack(rc=0, flags=1, proto_ver=proto_ver) + else: + connack3_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver) subscribe_packet = mosq_test.gen_subscribe(mid, "will/test", 0, proto_ver=proto_ver) suback_packet = mosq_test.gen_suback(mid, 0, proto_ver=proto_ver) publish_packet = mosq_test.gen_publish(topic="will/test", qos=0, payload="Client ready", proto_ver=proto_ver) + publish_lwt_packet = mosq_test.gen_publish(topic="will/test", qos=0, payload="LWT", proto_ver=proto_ver) port = mosq_test.get_port() broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port) @@ -34,17 +51,21 @@ def do_test(proto_ver, clean_session): mosq_test.do_send_receive(sock1, subscribe_packet, suback_packet, "suback") # Connect client with will - sock2 = mosq_test.do_client_connect(connect2_packet, connack2a_packet, timeout=5, port=port) + sock2 = mosq_test.do_client_connect(connect2_packet, connack2_packet, timeout=5, port=port) # Send a "ready" message sock2.send(publish_packet) mosq_test.expect_packet(sock1, "publish 1", publish_packet) # Connect client with will again as a separate connection, this should - # take over from the previous one but not trigger a Will. - sock3 = mosq_test.do_client_connect(connect2_packet, connack2b_packet, timeout=5, port=port) + # take over from the previous one but only trigger a Will if we are taking + # over a clean session/session-expiry-interval==0 client + sock3 = mosq_test.do_client_connect(connect3_packet, connack3_packet, timeout=5, port=port) sock2.close() + if clean_session1 == True or clean_session2 == True: + mosq_test.expect_packet(sock1, "publish LWT", publish_lwt_packet) + # Send the "ready" message again sock3.send(publish_packet) mosq_test.expect_packet(sock1, "publish 2", publish_packet) @@ -63,11 +84,15 @@ def do_test(proto_ver, clean_session): (stdo, stde) = broker.communicate() if rc: print(stde.decode('utf-8')) - print("proto_ver=%d clean_session=%d" % (proto_ver, clean_session)) + print("proto_ver=%d clean_session1=%d clean_session2=%d" % (proto_ver, clean_session1, clean_session2)) exit(rc) -do_test(proto_ver=4, clean_session=True) -do_test(proto_ver=4, clean_session=False) -do_test(proto_ver=5, clean_session=True) -do_test(proto_ver=5, clean_session=False) +do_test(proto_ver=4, clean_session1=True, clean_session2=True) +do_test(proto_ver=4, clean_session1=False, clean_session2=True) +do_test(proto_ver=4, clean_session1=True, clean_session2=False) +do_test(proto_ver=4, clean_session1=False, clean_session2=False) +do_test(proto_ver=5, clean_session1=True, clean_session2=True) +do_test(proto_ver=5, clean_session1=False, clean_session2=True) +do_test(proto_ver=5, clean_session1=True, clean_session2=False) +do_test(proto_ver=5, clean_session1=False, clean_session2=False) From 4dcfe5424f6932e6a3890df4cb049eb08702e3d9 Mon Sep 17 00:00:00 2001 From: Pierre Hallot Date: Mon, 7 Dec 2020 10:34:29 +0100 Subject: [PATCH 06/18] Remove CMAKE_LEGACY_CYGWIN_WIN32 which is not needed anymore According to this from the mailing list, it is no longer required since the minimum cmake required is 3.0. https://cmake.org/pipermail/cmake/2014-July/058048.html "The code that emits the warning is run by "project()". Since you do not have an explicit project() call in your top-level CMakeLists.txt CMake adds one to the top implicitly. [1] A project file that explicitly calls project() after requiring CMake >= 2.8.4 should make the warning go away." Signed-off-by: Pierre Hallot --- CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 71da9768..7cf0c1c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,8 +4,6 @@ # To configure the build options either use the CMake gui, or run the command # line utility including the "-i" option. -set(CMAKE_LEGACY_CYGWIN_WIN32 0) - project(mosquitto) cmake_minimum_required(VERSION 3.0) From ddb0f21ab503ae8c772cc61333d7a6343b3cbaf7 Mon Sep 17 00:00:00 2001 From: Pierre Hallot Date: Mon, 7 Dec 2020 10:29:43 +0100 Subject: [PATCH 07/18] Set cmake_minimum_required first as recommended in the documentation https://cmake.org/cmake/help/latest/command/cmake_minimum_required.html "Note Call the cmake_minimum_required() command at the beginning of the top-level CMakeLists.txt file even before calling the project() command. It is important to establish version and policy settings before invoking other commands whose behavior they may affect." Signed-off-by: Pierre Hallot --- CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7cf0c1c8..a7910ae9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,11 +4,10 @@ # To configure the build options either use the CMake gui, or run the command # line utility including the "-i" option. -project(mosquitto) - cmake_minimum_required(VERSION 3.0) cmake_policy(SET CMP0042 NEW) +project(mosquitto) set (VERSION 2.0.2) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/") From 57d2818a3d84369e77fe39babc452f19ff5155cf Mon Sep 17 00:00:00 2001 From: Pierre Hallot Date: Mon, 7 Dec 2020 10:30:46 +0100 Subject: [PATCH 08/18] Fix appending CMake module path to existing path The code would simply append the folder with no separator, resulting in an invalid path if the variable was not empty. Now properly append it. Signed-off-by: Pierre Hallot --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a7910ae9..f430eeeb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ cmake_policy(SET CMP0042 NEW) project(mosquitto) set (VERSION 2.0.2) -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/") +list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/") add_definitions (-DCMAKE -DVERSION=\"${VERSION}\") From 8a44e5940ce8445c2c8b98ccba983398b1a40c20 Mon Sep 17 00:00:00 2001 From: Peter Stevenson Date: Wed, 16 Dec 2020 23:39:16 +0000 Subject: [PATCH 09/18] Systemd service changes for updated pid path. Signed-off-by: Peter Stevenson --- man/mosquitto.conf.5.xml | 2 +- mosquitto.conf | 2 +- service/systemd/mosquitto.service.notify | 2 ++ service/systemd/mosquitto.service.simple | 2 ++ 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/man/mosquitto.conf.5.xml b/man/mosquitto.conf.5.xml index 3af551c5..38affc75 100644 --- a/man/mosquitto.conf.5.xml +++ b/man/mosquitto.conf.5.xml @@ -869,7 +869,7 @@ log_timestamp_format %Y-%m-%dT%H:%M:%S If mosquitto is being automatically started by an init script it will usually be required to write a pid file. This should then be configured as e.g. - /var/run/mosquitto.pid + /var/run/mosquitto/mosquitto.pid Not reloaded on reload signal. diff --git a/mosquitto.conf b/mosquitto.conf index 216b8c7d..ef390cb5 100644 --- a/mosquitto.conf +++ b/mosquitto.conf @@ -145,7 +145,7 @@ # Write process id to a file. Default is a blank string which means # a pid file shouldn't be written. -# This should be set to /var/run/mosquitto.pid if mosquitto is +# This should be set to /var/run/mosquitto/mosquitto.pid if mosquitto is # being run automatically on boot with an init script and # start-stop-daemon or similar. #pid_file diff --git a/service/systemd/mosquitto.service.notify b/service/systemd/mosquitto.service.notify index 84b08f84..f4a15bbf 100644 --- a/service/systemd/mosquitto.service.notify +++ b/service/systemd/mosquitto.service.notify @@ -12,6 +12,8 @@ ExecReload=/bin/kill -HUP $MAINPID Restart=on-failure ExecStartPre=/bin/mkdir -m 740 -p /var/log/mosquitto ExecStartPre=/bin/chown mosquitto: /var/log/mosquitto +ExecStartPre=/bin/mkdir -m 740 -p /var/run/mosquitto +ExecStartPre=/bin/chown mosquitto: /var/run/mosquitto [Install] WantedBy=multi-user.target diff --git a/service/systemd/mosquitto.service.simple b/service/systemd/mosquitto.service.simple index d0e657e6..ebdbeed2 100644 --- a/service/systemd/mosquitto.service.simple +++ b/service/systemd/mosquitto.service.simple @@ -10,6 +10,8 @@ ExecReload=/bin/kill -HUP $MAINPID Restart=on-failure ExecStartPre=/bin/mkdir -m 740 -p /var/log/mosquitto ExecStartPre=/bin/chown mosquitto: /var/log/mosquitto +ExecStartPre=/bin/mkdir -m 740 -p /var/run/mosquitto +ExecStartPre=/bin/chown mosquitto: /var/run/mosquitto [Install] WantedBy=multi-user.target From de141540fbb139680e13ad28ab96e7ad49c5bafd Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 17 Dec 2020 10:40:58 +0000 Subject: [PATCH 10/18] Fix mosquitto_sub being unable to terminate with Ctrl-C. This occured if a successful connection was not made. Closes #1957. Thanks to Peoh. --- ChangeLog.txt | 4 ++++ client/sub_client.c | 11 +++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index bfdf3d9e..b2f69d74 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -4,6 +4,10 @@ Broker: - Fix LWT not being sent on client takeover when the existing session wasn't being continued. Closes #1946. +Clients: +- Fix mosquitto_sub being unable to terminate with Ctrl-C if a successful + connection is not made. Closes #1957. + Apps: - Fix `mosquitto_passwd -b` using username as password (not if `-c` is also used). Closes #1949. diff --git a/client/sub_client.c b/client/sub_client.c index 23cdd773..02f98ad4 100644 --- a/client/sub_client.c +++ b/client/sub_client.c @@ -45,13 +45,18 @@ struct mosquitto *mosq = NULL; int last_mid = 0; static bool timed_out = false; static int connack_result = 0; +bool connack_received = false; #ifndef WIN32 void my_signal_handler(int signum) { if(signum == SIGALRM || signum == SIGTERM || signum == SIGINT){ - process_messages = false; - mosquitto_disconnect_v5(mosq, MQTT_RC_DISCONNECT_WITH_WILL_MSG, cfg.disconnect_props); + if(connack_received){ + process_messages = false; + mosquitto_disconnect_v5(mosq, MQTT_RC_DISCONNECT_WITH_WILL_MSG, cfg.disconnect_props); + }else{ + exit(-1); + } } if(signum == SIGALRM){ timed_out = true; @@ -123,6 +128,8 @@ void my_connect_callback(struct mosquitto *mosq, void *obj, int result, int flag UNUSED(flags); UNUSED(properties); + connack_received = true; + connack_result = result; if(!result){ mosquitto_subscribe_multiple(mosq, NULL, cfg.topic_count, cfg.topics, cfg.qos, cfg.sub_opts, cfg.subscribe_props); From d05a49a2cf9f2d812a11ecca37dff6cae927f040 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 17 Dec 2020 11:31:38 +0000 Subject: [PATCH 11/18] Fix bridges possibly not completing connections when WITH_ADNS is in use. Closes #1960. Thanks to twegener-embertec. --- ChangeLog.txt | 2 ++ src/bridge.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index b2f69d74..d4c0d003 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -3,6 +3,8 @@ Broker: high. Closes #1947. - Fix LWT not being sent on client takeover when the existing session wasn't being continued. Closes #1946. +- Fix bridges possibly not completing connections when WITH_ADNS is in use. + Closes #1960. Clients: - Fix mosquitto_sub being unable to terminate with Ctrl-C if a successful diff --git a/src/bridge.c b/src/bridge.c index e7e11202..1124dee2 100644 --- a/src/bridge.c +++ b/src/bridge.c @@ -776,6 +776,8 @@ void bridge_check(void) mux__add_out(context); } }else if(rc == MOSQ_ERR_CONN_PENDING){ + mux__add_in(context); + mux__add_out(context); context->bridge->restart_t = 0; }else{ context->bridge->cur_address++; From 00c68203b87b2a1f4d5e8a7d2efc603e3109f1e0 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 17 Dec 2020 11:57:15 +0000 Subject: [PATCH 12/18] Fix QoS 0 messages not being delivered if max_queued_messages was set to 0. Closes #1956. Thanks to nduhme. --- ChangeLog.txt | 2 ++ src/database.c | 3 +++ 2 files changed, 5 insertions(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index d4c0d003..9b887b68 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -5,6 +5,8 @@ Broker: being continued. Closes #1946. - Fix bridges possibly not completing connections when WITH_ADNS is in use. Closes #1960. +- Fix QoS 0 messages not being delivered if max_queued_messages was set to 0. + Closes #1956. Clients: - Fix mosquitto_sub being unable to terminate with Ctrl-C if a successful diff --git a/src/database.c b/src/database.c index 120e3a5d..eec4f157 100644 --- a/src/database.c +++ b/src/database.c @@ -50,6 +50,9 @@ bool db__ready_for_flight(struct mosquitto_msg_data *msgs, int qos) * There is no queueing option, unless the client is offline and * queue_qos0_messages is enabled. */ + if(db.config->max_queued_messages == 0 && db.config->max_inflight_bytes == 0){ + return true; + } valid_bytes = msgs->msg_bytes - db.config->max_inflight_bytes < db.config->max_queued_bytes; valid_count = msgs->msg_count - msgs->inflight_maximum < db.config->max_queued_messages; From 1d92184b2f065d8ada2681c8a063020f7ec2d777 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 17 Dec 2020 14:00:50 +0000 Subject: [PATCH 13/18] Fix local bridges being disconnected on SIGHUP. Closes #1942. Thanks to charlemagnelasse. --- ChangeLog.txt | 1 + src/security_default.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index 9b887b68..9a92de81 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -7,6 +7,7 @@ Broker: Closes #1960. - Fix QoS 0 messages not being delivered if max_queued_messages was set to 0. Closes #1956. +- Fix local bridges being disconnected on SIGHUP. Closes #1942. Clients: - Fix mosquitto_sub being unable to terminate with Ctrl-C if a successful diff --git a/src/security_default.c b/src/security_default.c index cc7e1f1b..d732e774 100644 --- a/src/security_default.c +++ b/src/security_default.c @@ -1112,6 +1112,10 @@ int mosquitto_security_apply_default(void) #endif HASH_ITER(hh_id, db.contexts_by_id, context, ctxt_tmp){ + if(context->bridge){ + continue; + } + /* Check for anonymous clients when allow_anonymous is false */ if(db.config->per_listener_settings){ if(context->listener){ From f10de9831ada494e8ae4a3acfd808028df7e0bc6 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 17 Dec 2020 14:08:51 +0000 Subject: [PATCH 14/18] Fix slow initial bridge connections for WITH_ADNS=no. --- ChangeLog.txt | 1 + src/bridge.c | 1 + 2 files changed, 2 insertions(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index 9a92de81..6755e182 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -8,6 +8,7 @@ Broker: - Fix QoS 0 messages not being delivered if max_queued_messages was set to 0. Closes #1956. - Fix local bridges being disconnected on SIGHUP. Closes #1942. +- Fix slow initial bridge connections for WITH_ADNS=no. Clients: - Fix mosquitto_sub being unable to terminate with Ctrl-C if a successful diff --git a/src/bridge.c b/src/bridge.c index 1124dee2..6379c1a4 100644 --- a/src/bridge.c +++ b/src/bridge.c @@ -577,6 +577,7 @@ int bridge__register_local_connections(void) log__printf(NULL, MOSQ_LOG_ERR, "Error in epoll initial registering bridge: %s", strerror(errno)); return MOSQ_ERR_UNKNOWN; } + mux__add_out(context); } } #endif From 2d9d1beee41314be4727cdafdf3cea36cf37703e Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 17 Dec 2020 14:12:22 +0000 Subject: [PATCH 15/18] Fix ChangeLog error. Closes #1941. --- ChangeLog.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 6755e182..3e44696f 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -126,8 +126,8 @@ Broker features: to a v3.x only broker. - DLT logging is now configurable at runtime with `log_dest dlt`. Closes #1735. -- Add `mosquitto_plugin_publish()` function, which can be used by plugins to - publish messages. +- Add `mosquitto_broker_publish()` and `mosquitto_broker_publish_copy()` + functions, which can be used by plugins to publish messages. - Add `mosquitto_client_protocol_version()` function which can be used by plugins to determine which version of MQTT a client has connected with. - Add `mosquitto_kick_client_by_clientid()` and `mosquitto_kick_client_by_username()` From 99e8c8001d3c45a190d204e15254cd25c6c0d6b8 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 17 Dec 2020 15:04:35 +0000 Subject: [PATCH 16/18] Build lib from in mosquitto_ctrl directory. --- apps/mosquitto_ctrl/Makefile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/mosquitto_ctrl/Makefile b/apps/mosquitto_ctrl/Makefile index d2122abc..c351f9b9 100644 --- a/apps/mosquitto_ctrl/Makefile +++ b/apps/mosquitto_ctrl/Makefile @@ -38,7 +38,7 @@ endif all : ${TARGET} -mosquitto_ctrl : ${OBJS} +mosquitto_ctrl : ${OBJS} ${LIBMOSQ} ${CROSS_COMPILE}${CC} ${APP_LDFLAGS} $^ -o $@ $(PASSWD_LDADD) $(LOCAL_LDFLAGS) $(LIBMOSQ) -lcjson -ldl mosquitto_ctrl_example.so : ${EXAMPLE_OBJS} @@ -83,6 +83,12 @@ misc_mosq.o : ../../lib/misc_mosq.c ../../lib/misc_mosq.h password_mosq.o : ../../src/password_mosq.c ../../src/password_mosq.h ${CROSS_COMPILE}${CC} $(APP_CPPFLAGS) $(APP_CFLAGS) -c $< -o $@ +../../lib/libmosquitto.so.${SOVERSION} : + $(MAKE) -C ../../lib + +../../lib/libmosquitto.a : + $(MAKE) -C ../../lib libmosquitto.a + install : all ifeq ($(WITH_TLS),yes) ifeq ($(WITH_CJSON),yes) From f930970008707602ec8d32a453a87078afb6d928 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 17 Dec 2020 15:09:09 +0000 Subject: [PATCH 17/18] Fix persistence_location not appending a '/'. --- ChangeLog.txt | 1 + src/conf.c | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 3e44696f..366afe74 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -9,6 +9,7 @@ Broker: Closes #1956. - Fix local bridges being disconnected on SIGHUP. Closes #1942. - Fix slow initial bridge connections for WITH_ADNS=no. +- Fix persistence_location not appending a '/'. Clients: - Fix mosquitto_sub being unable to terminate with Ctrl-C if a successful diff --git a/src/conf.c b/src/conf.c index d6918d30..4eb70432 100644 --- a/src/conf.c +++ b/src/conf.c @@ -664,7 +664,11 @@ int config__read(struct mosquitto__config *config, bool reload) len = strlen(config->persistence_location) + strlen(config->persistence_file) + 1; config->persistence_filepath = mosquitto__malloc(len); if(!config->persistence_filepath) return MOSQ_ERR_NOMEM; - snprintf(config->persistence_filepath, len, "%s%s", config->persistence_location, config->persistence_file); +#ifdef WIN32 + snprintf(config->persistence_filepath, len, "%s\\%s", config->persistence_location, config->persistence_file); +#else + snprintf(config->persistence_filepath, len, "%s/%s", config->persistence_location, config->persistence_file); +#endif }else{ config->persistence_filepath = mosquitto__strdup(config->persistence_file); if(!config->persistence_filepath) return MOSQ_ERR_NOMEM; From d02bc03ed8c48fc47ace4c1679b82b245208b0bc Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 17 Dec 2020 14:28:23 +0000 Subject: [PATCH 18/18] Bump version, changelog and webpage. --- CMakeLists.txt | 2 +- ChangeLog.txt | 8 ++++ config.mk | 2 +- include/mosquitto.h | 2 +- installer/mosquitto.nsi | 2 +- installer/mosquitto64.nsi | 2 +- set-version.sh | 2 +- snap/snapcraft.yaml | 2 +- www/pages/download.md | 8 ++-- www/pages/security.md | 4 ++ www/posts/2020/12/version-2-0-3-released.md | 51 +++++++++++++++++++++ 11 files changed, 74 insertions(+), 11 deletions(-) create mode 100644 www/posts/2020/12/version-2-0-3-released.md diff --git a/CMakeLists.txt b/CMakeLists.txt index f430eeeb..9167f9e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ cmake_minimum_required(VERSION 3.0) cmake_policy(SET CMP0042 NEW) project(mosquitto) -set (VERSION 2.0.2) +set (VERSION 2.0.3) list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/") diff --git a/ChangeLog.txt b/ChangeLog.txt index 366afe74..1d6ae289 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,11 @@ +2.0.3 - 2020-12-17 +================== + +Security: +- Running mosquitto_passwd with the following arguments only + `mosquitto_passwd -b password_file username password` would cause the + username to be used as the password. + Broker: - Fix excessive CPU use on non-Linux systems when the open file limit is set high. Closes #1947. diff --git a/config.mk b/config.mk index d64e2d00..de328ea3 100644 --- a/config.mk +++ b/config.mk @@ -125,7 +125,7 @@ WITH_XTREPORT=no # Also bump lib/mosquitto.h, CMakeLists.txt, # installer/mosquitto.nsi, installer/mosquitto64.nsi -VERSION=2.0.2 +VERSION=2.0.3 # Client library SO version. Bump if incompatible API/ABI changes are made. SOVERSION=1 diff --git a/include/mosquitto.h b/include/mosquitto.h index abbc8c2d..ef667693 100644 --- a/include/mosquitto.h +++ b/include/mosquitto.h @@ -59,7 +59,7 @@ extern "C" { #define LIBMOSQUITTO_MAJOR 2 #define LIBMOSQUITTO_MINOR 0 -#define LIBMOSQUITTO_REVISION 2 +#define LIBMOSQUITTO_REVISION 3 /* 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/installer/mosquitto.nsi b/installer/mosquitto.nsi index 1fa75ffb..702a0a98 100644 --- a/installer/mosquitto.nsi +++ b/installer/mosquitto.nsi @@ -9,7 +9,7 @@ !define env_hklm 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"' Name "Eclipse Mosquitto" -!define VERSION 2.0.2 +!define VERSION 2.0.3 OutFile "mosquitto-${VERSION}-install-windows-x86.exe" InstallDir "$PROGRAMFILES\mosquitto" diff --git a/installer/mosquitto64.nsi b/installer/mosquitto64.nsi index 274dd7d6..b40ef29e 100644 --- a/installer/mosquitto64.nsi +++ b/installer/mosquitto64.nsi @@ -9,7 +9,7 @@ !define env_hklm 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"' Name "Eclipse Mosquitto" -!define VERSION 2.0.2 +!define VERSION 2.0.3 OutFile "mosquitto-${VERSION}-install-windows-x64.exe" !include "x64.nsh" diff --git a/set-version.sh b/set-version.sh index e01b89df..11de2bda 100755 --- a/set-version.sh +++ b/set-version.sh @@ -2,7 +2,7 @@ MAJOR=2 MINOR=0 -REVISION=2 +REVISION=3 sed -i "s/^VERSION=.*/VERSION=${MAJOR}.${MINOR}.${REVISION}/" config.mk diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index c0155181..3e7257bc 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,5 +1,5 @@ name: mosquitto -version: 2.0.2 +version: 2.0.3 summary: Eclipse Mosquitto MQTT broker description: This is a message broker that supports version 5.0, 3.1.1, and 3.1 of the MQTT protocol. diff --git a/www/pages/download.md b/www/pages/download.md index d015405f..7436afda 100644 --- a/www/pages/download.md +++ b/www/pages/download.md @@ -1,7 +1,7 @@ + +Version 2.0.3 of Mosquitto has been released. This is a bugfix release. + +# Security +- Running mosquitto_passwd with the following arguments only + `mosquitto_passwd -b password_file username password` would cause the + username to be used as the password. + +# Broker +- Fix excessive CPU use on non-Linux systems when the open file limit is set + high. Closes [#1947]. +- Fix LWT not being sent on client takeover when the existing session wasn't + being continued. Closes [#1946]. +- Fix bridges possibly not completing connections when WITH_ADNS is in use. + Closes [#1960]. +- Fix QoS 0 messages not being delivered if max_queued_messages was set to 0. + Closes [#1956]. +- Fix local bridges being disconnected on SIGHUP. Closes [#1942]. +- Fix slow initial bridge connections for WITH_ADNS=no. + +# Clients +- Fix mosquitto_sub being unable to terminate with Ctrl-C if a successful + connection is not made. Closes [#1957]. + +# Apps +- Fix `mosquitto_passwd -b` using username as password (not if `-c` is also + used). Closes [#1949]. + +# Build +- Fix `install` target when using WITH_CJSON=no. Closes [#1938]. +- Fix `generic` docker build. Closes [#1945]. + +[#1938]: https://github.com/eclipse/mosquitto/issues/1938 +[#1942]: https://github.com/eclipse/mosquitto/issues/1942 +[#1945]: https://github.com/eclipse/mosquitto/issues/1945 +[#1946]: https://github.com/eclipse/mosquitto/issues/1946 +[#1947]: https://github.com/eclipse/mosquitto/issues/1947 +[#1949]: https://github.com/eclipse/mosquitto/issues/1949 +[#1956]: https://github.com/eclipse/mosquitto/issues/1956 +[#1957]: https://github.com/eclipse/mosquitto/issues/1957 +[#1960]: https://github.com/eclipse/mosquitto/issues/1960