diff --git a/CMakeLists.txt b/CMakeLists.txt index f4a945ad..40040969 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.5) +set (VERSION 2.0.8) list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/") @@ -100,12 +100,15 @@ if (WITH_DLT) add_definitions("-DWITH_DLT") endif (WITH_DLT) -FIND_PACKAGE(cJSON) -if (CJSON_FOUND) - message(STATUS ${CJSON_FOUND}) -else (CJSON_FOUND) - message(STATUS "Optional dependency cJSON not found. Some features will be disabled.") -endif(CJSON_FOUND) +option(WITH_CJSON "Build with cJSON support (required for dynamic security plugin and useful for mosquitto_sub)?" ON) +if (WITH_CJSON) + FIND_PACKAGE(cJSON) + if (CJSON_FOUND) + message(STATUS ${CJSON_FOUND}) + else (CJSON_FOUND) + message(STATUS "Optional dependency cJSON not found. Some features will be disabled.") + endif(CJSON_FOUND) +endif() # ======================================== # Include projects diff --git a/ChangeLog.txt b/ChangeLog.txt index 98488236..fb9d0328 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -20,12 +20,136 @@ Client library: username/password/TLS parameters before an automatic reconnection. -2.0.6 - 2021-01-xx +2.0.9 - 2021-03-xx ================== +Broker: +- Fix `tls_version` behaviour not matching documentation. It was setting the + exact TLS version to use, not the minimium TLS version to use. Closes #2110. +- Fix messages to `$` prefixed topics being rejected. Closes #2111. +- Fix QoS 0 messages not being delivered when max_queued_bytes was configured. + Closes #2123. + + +2.0.8 - 2021-02-25 +================== + +Broker: +- Fix incorrect datatypes in `struct mosquitto_evt_tick`. This changes the + size and offset of two of the members of this struct, and changes the size + of the struct. This is an ABI break, but is considered to be acceptable + because plugins should never be allocating their own instance of this + struct, and currently none of the struct members are used for anything, so a + plugin should not be accessing them. It would also be safe to read/write + from the existing struct parameters. +- Give compile time warning if libwebsockets compiled without external poll + support. Closes #2060. +- Fix memory tracking not being available on FreeBSD or macOS. Closes #2096. + +Client library: +- Fix mosquitto_{pub|sub}_topic_check() functions not returning MOSQ_ERR_INVAL + on topic == NULL. + +Clients: +- Fix possible loss of data in `mosquitto_pub -l` when sending multiple long + lines. Closes #2078. + +Build: +- Provide a mechanism for Docker users to run a broker that doesn't use + authentication, without having to provide their own configuration file. + Closes #2040. + + +2.0.7 - 2021-02-04 +================== + +Broker: +- Fix exporting of executable symbols on BSD when building via makefile. +- Fix some minor memory leaks on exit only. +- Fix possible memory leak on connect. Closes #2057. +- Fix openssl engine not being able to load private key. Closes #2066. + +Clients: +- Fix config files truncating options after the first space. Closes #2059. + +Build: +- Fix man page building to not absolutely require xsltproc when using CMake. + This now handles the case where we are building from the released tar, or + building from git if xsltproc is available, or building from git if xsltproc + is not available. + + +1.6.13 - 2021-02-04 +=================== + +Broker: +- Fix crash on Windows if loading a plugin fails. Closes #1866. +- Fix DH group not being set for TLS connections, which meant ciphers using + DHE couldn't be used. Closes #1925. Closes #1476. +- Fix local bridges being disconnected on SIGHUP. Closes #1942. +- Fix $SYS/broker/publish/messages/+ counters not being updated for QoS 1, 2 + messages. Closes #1968. +- Fix listener not being reassociated with client when reloading a persistence + file and `per_listener_settings true` is set and the client did not set a + username. Closes #1891. +- Fix file logging on Windows. Closes #1880. +- Fix bridge sock not being removed from sock hash on error. Closes #1897. + +Client library: +- Fix build on Mac Big Sur. Closes #1905. +- Fix DH group not being set for TLS connections, which meant ciphers using + DHE couldn't be used. Closes #1925. Closes #1476. + +Clients: +- mosquitto_sub will now quit with an error if the %U option is used on + Windows, rather than just quitting. Closes #1908. +- Fix config files truncating options after the first space. Closes #2059. + +Apps: +- Perform stricter parsing of input username in mosquitto_passwd. Closes + #570126 (Eclipse bugzilla). + +Build: +- Enable epoll support in CMake builds. + + +2.0.6 - 2021-01-28 + Broker: - Fix calculation of remaining length parameter for websockets clients that send fragmented packets. Closes #1974. +Broker: +- Fix potential duplicate Will messages being sent when a will delay interval + has been set. +- Fix message expiry interval property not being honoured in + `mosquitto_broker_publish` and `mosquitto_broker_publish_copy`. +- Fix websockets listeners with TLS not responding. Closes #2020. +- Add notes that libsystemd-dev or similar is needed if building with systemd + support. Closes #2019. +- Improve logging in obscure cases when a client disconnects. Closes #2017. +- Fix reloading of listeners where multiple listeners have been defined with + the same port but different bind addresses. Closes #2029. +- Fix `message_size_limit` not applying to the Will payload. Closes #2022. +- The error topic-alias-invalid was being sent if an MQTT v5 client published + a message with empty topic and topic alias set, but the topic alias hadn't + already been configured on the broker. This has been fixed to send a + protocol error, as per section 3.3.4 of the specification. +- Note in the man pages that SIGHUP reloads TLS certificates. Closes #2037. +- Fix bridges not always connecting on Windows. Closes #2043. + +Apps: +- Allow command line arguments to override config file options in + mosquitto_ctrl. Closes #2010. +- mosquitto_ctrl: produce an error when requesting a new password if both + attempts do not match. Closes #2011. + +Build: +- Fix cmake builds using `WITH_CJSON=no` not working if cJSON not found. + Closes #2026. + +Other: +- The SPDX identifiers for EDL-1.0 have been changed to BSD-3-Clause as per + The Eclipse legal documentation generator. The licenses are identical. 2.0.5 - 2021-01-11 diff --git a/README-compiling.md b/README-compiling.md index f3be9d9a..eb1b11da 100644 --- a/README-compiling.md +++ b/README-compiling.md @@ -7,6 +7,7 @@ are optional. * libwebsockets (optional, disabled by default, version 2.4 and above) * cJSON (optional but recommended, for dynamic-security plugin support, and JSON output from mosquitto_sub/mosquitto_rr) +* libsystemd-dev (optional, if building with systemd support on Linux) * On Windows, a pthreads library is required if threading support is to be included. diff --git a/apps/db_dump/db_dump.c b/apps/db_dump/db_dump.c index c0c1e056..ad6d2f7b 100644 --- a/apps/db_dump/db_dump.c +++ b/apps/db_dump/db_dump.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/apps/db_dump/db_dump.h b/apps/db_dump/db_dump.h index 86294180..f6586aa7 100644 --- a/apps/db_dump/db_dump.h +++ b/apps/db_dump/db_dump.h @@ -12,7 +12,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/apps/db_dump/print.c b/apps/db_dump/print.c index 10ab1d38..84ca2ef0 100644 --- a/apps/db_dump/print.c +++ b/apps/db_dump/print.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/apps/db_dump/stubs.c b/apps/db_dump/stubs.c index 5fb08a8c..af00f706 100644 --- a/apps/db_dump/stubs.c +++ b/apps/db_dump/stubs.c @@ -6,74 +6,113 @@ struct mosquitto *context__init(mosq_sock_t sock) { + UNUSED(sock); + return NULL; } int db__message_store(const struct mosquitto *source, struct mosquitto_msg_store *stored, uint32_t message_expiry_interval, dbid_t store_id, enum mosquitto_msg_origin origin) { + UNUSED(source); + UNUSED(stored); + UNUSED(message_expiry_interval); + UNUSED(store_id); + UNUSED(origin); return 0; } void db__msg_store_ref_inc(struct mosquitto_msg_store *store) { + UNUSED(store); } int handle__packet(struct mosquitto *context) { + UNUSED(context); return 0; } int log__printf(struct mosquitto *mosq, unsigned int level, const char *fmt, ...) { + UNUSED(mosq); + UNUSED(level); + UNUSED(fmt); return 0; } FILE *mosquitto__fopen(const char *path, const char *mode, bool restrict_read) { + UNUSED(path); + UNUSED(mode); + UNUSED(restrict_read); return NULL; } enum mosquitto_client_state mosquitto__get_state(struct mosquitto *mosq) { + UNUSED(mosq); return mosq_cs_new; } int mux__add_out(struct mosquitto *mosq) { + UNUSED(mosq); return 0; } int mux__remove_out(struct mosquitto *mosq) { + UNUSED(mosq); return 0; } ssize_t net__read(struct mosquitto *mosq, void *buf, size_t count) { + UNUSED(mosq); + UNUSED(buf); + UNUSED(count); return 0; } ssize_t net__write(struct mosquitto *mosq, const void *buf, size_t count) { + UNUSED(mosq); + UNUSED(buf); + UNUSED(count); return 0; } int retain__store(const char *topic, struct mosquitto_msg_store *stored, char **split_topics) { + UNUSED(topic); + UNUSED(stored); + UNUSED(split_topics); return 0; } int sub__add(struct mosquitto *context, const char *sub, uint8_t qos, uint32_t identifier, int options, struct mosquitto__subhier **root) { + UNUSED(context); + UNUSED(sub); + UNUSED(qos); + UNUSED(identifier); + UNUSED(options); + UNUSED(root); return 0; } int sub__messages_queue(const char *source_id, const char *topic, uint8_t qos, int retain, struct mosquitto_msg_store **stored) { + UNUSED(source_id); + UNUSED(topic); + UNUSED(qos); + UNUSED(retain); + UNUSED(stored); return 0; } int keepalive__update(struct mosquitto *context) { + UNUSED(context); return 0; } diff --git a/apps/mosquitto_ctrl/Makefile b/apps/mosquitto_ctrl/Makefile index c351f9b9..286eb449 100644 --- a/apps/mosquitto_ctrl/Makefile +++ b/apps/mosquitto_ctrl/Makefile @@ -5,8 +5,12 @@ include ../../config.mk ifeq ($(WITH_SHARED_LIBRARIES),yes) LIBMOSQ:=../../lib/libmosquitto.so.${SOVERSION} else +ifeq ($(WITH_THREADING),yes) +LIBMOSQ:=../../lib/libmosquitto.a -lpthread -lssl -lcrypto +else LIBMOSQ:=../../lib/libmosquitto.a endif +endif LOCAL_CPPFLAGS:=-I../mosquitto_passwd @@ -25,7 +29,6 @@ OBJS= mosquitto_ctrl.o \ EXAMPLE_OBJS= example.o ifeq ($(WITH_TLS),yes) - ifeq ($(WITH_CJSON),yes) TARGET:=mosquitto_ctrl mosquitto_ctrl_example.so else diff --git a/apps/mosquitto_ctrl/client.c b/apps/mosquitto_ctrl/client.c index ea04e2e3..4464ce16 100644 --- a/apps/mosquitto_ctrl/client.c +++ b/apps/mosquitto_ctrl/client.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/apps/mosquitto_ctrl/dynsec.c b/apps/mosquitto_ctrl/dynsec.c index 796207e6..fae86f43 100644 --- a/apps/mosquitto_ctrl/dynsec.c +++ b/apps/mosquitto_ctrl/dynsec.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. @@ -386,6 +386,7 @@ static void dynsec__payload_callback(struct mosq_ctrl *ctrl, long payloadlen, co UNUSED(ctrl); #if CJSON_VERSION_FULL < 1007013 + UNUSED(payloadlen); tree = cJSON_Parse(payload); #else tree = cJSON_ParseWithLength(payload, payloadlen); @@ -720,9 +721,8 @@ int dynsec_init(int argc, char *argv[]) snprintf(verify_prompt, sizeof(verify_prompt), "Reenter password for %s: ", admin_user); rc = get_password(prompt, verify_prompt, false, password, sizeof(password)); if(rc){ - fprintf(stderr, "Error getting password.\n"); mosquitto_lib_cleanup(); - return 1; + return -1; } admin_password = password; } diff --git a/apps/mosquitto_ctrl/dynsec_client.c b/apps/mosquitto_ctrl/dynsec_client.c index 45b6d6af..ed900eff 100644 --- a/apps/mosquitto_ctrl/dynsec_client.c +++ b/apps/mosquitto_ctrl/dynsec_client.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. @@ -65,6 +65,9 @@ int dynsec_client__create(int argc, char *argv[], cJSON *j_command) rc = get_password(prompt, verify_prompt, true, password_buf, sizeof(password_buf)); if(rc == 0){ password = password_buf; + }else if(rc == 2){ + fprintf(stderr, "Error: Passwords do not match.\n"); + return -1; }else{ password = NULL; printf("\n"); @@ -163,7 +166,7 @@ int dynsec_client__set_password(int argc, char *argv[], cJSON *j_command) snprintf(verify_prompt, sizeof(verify_prompt), "Reenter password for %s: ", username); rc = get_password(prompt, verify_prompt, false, password_buf, sizeof(password_buf)); if(rc){ - return MOSQ_ERR_INVAL; + return -1; } password = password_buf; }else{ diff --git a/apps/mosquitto_ctrl/dynsec_group.c b/apps/mosquitto_ctrl/dynsec_group.c index 5fc31b84..742e9418 100644 --- a/apps/mosquitto_ctrl/dynsec_group.c +++ b/apps/mosquitto_ctrl/dynsec_group.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/apps/mosquitto_ctrl/dynsec_role.c b/apps/mosquitto_ctrl/dynsec_role.c index 2bc5a03d..14eebcaa 100644 --- a/apps/mosquitto_ctrl/dynsec_role.c +++ b/apps/mosquitto_ctrl/dynsec_role.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/apps/mosquitto_ctrl/example.c b/apps/mosquitto_ctrl/example.c index 1027fb60..01b8d580 100644 --- a/apps/mosquitto_ctrl/example.c +++ b/apps/mosquitto_ctrl/example.c @@ -10,11 +10,13 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. */ +#include "config.h" + #include #include #include @@ -31,6 +33,9 @@ void ctrl_help(void) int ctrl_main(int argc, char *argv[], struct mosq_ctrl *ctrl) { + UNUSED(argc); + UNUSED(ctrl); + if(!strcasecmp(argv[0], "help")){ ctrl_help(); return -1; diff --git a/apps/mosquitto_ctrl/mosquitto_ctrl.c b/apps/mosquitto_ctrl/mosquitto_ctrl.c index 6ee729c2..bda95902 100644 --- a/apps/mosquitto_ctrl/mosquitto_ctrl.c +++ b/apps/mosquitto_ctrl/mosquitto_ctrl.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/apps/mosquitto_ctrl/mosquitto_ctrl.h b/apps/mosquitto_ctrl/mosquitto_ctrl.h index 0c9c931a..fce2a78d 100644 --- a/apps/mosquitto_ctrl/mosquitto_ctrl.h +++ b/apps/mosquitto_ctrl/mosquitto_ctrl.h @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/apps/mosquitto_ctrl/options.c b/apps/mosquitto_ctrl/options.c index 8d8d3bc9..5c36e5db 100644 --- a/apps/mosquitto_ctrl/options.c +++ b/apps/mosquitto_ctrl/options.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. @@ -89,11 +89,11 @@ int ctrl_config_parse(struct mosq_config *cfg, int *argc, char **argv[]) init_config(cfg); - /* Deal with real argc/argv */ - rc = client_config_line_proc(cfg, argc, argv); + rc = client_config_load(cfg); if(rc) return rc; - rc = client_config_load(cfg); + /* Deal with real argc/argv */ + rc = client_config_line_proc(cfg, argc, argv); if(rc) return rc; #ifdef WITH_TLS diff --git a/apps/mosquitto_passwd/get_password.c b/apps/mosquitto_passwd/get_password.c index a3113d1a..a62a76cd 100644 --- a/apps/mosquitto_passwd/get_password.c +++ b/apps/mosquitto_passwd/get_password.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. @@ -135,7 +135,7 @@ int get_password(const char *prompt, const char *verify_prompt, bool quiet, char if(!quiet){ fprintf(stderr, "Error: Passwords do not match.\n"); } - return 1; + return 2; } } diff --git a/apps/mosquitto_passwd/get_password.h b/apps/mosquitto_passwd/get_password.h index f62afd0d..3cada7c6 100644 --- a/apps/mosquitto_passwd/get_password.h +++ b/apps/mosquitto_passwd/get_password.h @@ -12,7 +12,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/apps/mosquitto_passwd/mosquitto_passwd.c b/apps/mosquitto_passwd/mosquitto_passwd.c index 26846881..628bcc71 100644 --- a/apps/mosquitto_passwd/mosquitto_passwd.c +++ b/apps/mosquitto_passwd/mosquitto_passwd.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. @@ -392,7 +392,7 @@ void handle_sigint(int signal) static bool is_username_valid(const char *username) { - int i; + size_t i; size_t slen; if(username){ diff --git a/client/client_props.c b/client/client_props.c index 0c34e3a5..45d5052d 100644 --- a/client/client_props.c +++ b/client/client_props.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/client/client_shared.c b/client/client_shared.c index 03d518c1..26755b7b 100644 --- a/client/client_shared.c +++ b/client/client_shared.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. @@ -46,7 +46,7 @@ static int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int static int check_format(const char *str) { - int i; + size_t i; size_t len; len = strlen(str); @@ -357,7 +357,7 @@ int client_config_load(struct mosq_config *cfg, int pub_or_sub, int argc, char * * program name as the first entry. */ args[1] = strtok(line, " "); if(args[1]){ - args[2] = strtok(NULL, " "); + args[2] = strtok(NULL, ""); if(args[2]){ count = 3; }else{ @@ -1395,7 +1395,7 @@ int client_connect(struct mosquitto *mosq, struct mosq_config *cfg) /* Convert %25 -> %, %3a, %3A -> :, %40 -> @ */ static int mosquitto__urldecode(char *str) { - int i, j; + size_t i, j; size_t len; if(!str) return 0; diff --git a/client/client_shared.h b/client/client_shared.h index 8fb9c624..156c7f68 100644 --- a/client/client_shared.h +++ b/client/client_shared.h @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/client/pub_client.c b/client/pub_client.c index 9f276c63..8049de6e 100644 --- a/client/pub_client.c +++ b/client/pub_client.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. @@ -275,7 +275,7 @@ int pub_stdin_line_loop(struct mosquitto *mosq) break; }else{ line_buf_len += 1024; - pos += 1023; + pos += read_len-1; read_len = 1024; buf2 = realloc(line_buf, (size_t )line_buf_len); if(!buf2){ diff --git a/client/pub_shared.c b/client/pub_shared.c index 2718c4eb..0b9323c9 100644 --- a/client/pub_shared.c +++ b/client/pub_shared.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. @@ -125,7 +125,7 @@ int load_file(const char *filename) return 1; } pos = 0; - while(pos < cfg.msglen){ + while(pos < (size_t)cfg.msglen){ rlen = fread(&(cfg.message[pos]), sizeof(char), (size_t )cfg.msglen-pos, fptr); pos += rlen; } diff --git a/client/pub_shared.h b/client/pub_shared.h index 023d91a9..9f657de4 100644 --- a/client/pub_shared.h +++ b/client/pub_shared.h @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/client/rr_client.c b/client/rr_client.c index 464d735e..2331a4ed 100644 --- a/client/rr_client.c +++ b/client/rr_client.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/client/sub_client.c b/client/sub_client.c index 352c4694..e2cebcdc 100644 --- a/client/sub_client.c +++ b/client/sub_client.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/client/sub_client_output.c b/client/sub_client_output.c index 0163b0e2..adb432ce 100644 --- a/client/sub_client_output.c +++ b/client/sub_client_output.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. @@ -96,6 +96,8 @@ static void write_payload(const unsigned char *payload, int payloadlen, int hex, int i; int padlen; + UNUSED(precision); /* FIXME - use or remove */ + if(field_width > 0){ if(payloadlen > field_width){ payloadlen = field_width; @@ -357,6 +359,9 @@ static int json_print(const struct mosquitto_message *message, const mosquitto_p return MOSQ_ERR_SUCCESS; #else + UNUSED(properties); + UNUSED(pretty); + strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S.000000Z%z", ti); snprintf(&buf[strlen("2020-05-06T21:48:00.")], 9, "%06d", ns/1000); buf[strlen("2020-05-06T21:48:00.000000")] = 'Z'; @@ -625,7 +630,7 @@ static void formatted_print_percent(const struct mosq_config *lcfg, const struct static void formatted_print(const struct mosq_config *lcfg, const struct mosquitto_message *message, const mosquitto_property *properties) { size_t len; - int i; + size_t i; struct tm *ti = NULL; long ns = 0; char strf[3] = {0, 0 ,0}; diff --git a/client/sub_client_output.h b/client/sub_client_output.h index 17abb1dc..9bca8b67 100644 --- a/client/sub_client_output.h +++ b/client/sub_client_output.h @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/config.mk b/config.mk index 178c8baa..73e5cc39 100644 --- a/config.mk +++ b/config.mk @@ -59,6 +59,8 @@ WITH_SYS_TREE:=yes # Build with systemd support. If enabled, mosquitto will notify systemd after # initialization. See README in service/systemd/ for more information. +# Setting to yes means the libsystemd-dev or similar package will need to be +# installed. WITH_SYSTEMD:=no # Build with SRV lookup support. @@ -125,7 +127,7 @@ WITH_XTREPORT=no # Also bump lib/mosquitto.h, CMakeLists.txt, # installer/mosquitto.nsi, installer/mosquitto64.nsi -VERSION=2.0.5 +VERSION=2.0.8 # Client library SO version. Bump if incompatible API/ABI changes are made. SOVERSION=1 @@ -179,6 +181,7 @@ PLUGIN_LDFLAGS:=$(LDFLAGS) ifneq ($(or $(findstring $(UNAME),FreeBSD), $(findstring $(UNAME),OpenBSD), $(findstring $(UNAME),NetBSD)),) BROKER_LDADD:=$(BROKER_LDADD) -lm + BROKER_LDFLAGS:=$(BROKER_LDFLAGS) -Wl,--dynamic-list=linker.syms SEDINPLACE:=-i "" else BROKER_LDADD:=$(BROKER_LDADD) -ldl -lm diff --git a/docker/1.6-openssl/Dockerfile b/docker/1.6-openssl/Dockerfile index 46e0bc83..c26c07e6 100644 --- a/docker/1.6-openssl/Dockerfile +++ b/docker/1.6-openssl/Dockerfile @@ -3,8 +3,8 @@ FROM alpine:3.12 LABEL maintainer="Roger Light " \ description="Eclipse Mosquitto MQTT Broker" -ENV VERSION=1.6.12 \ - DOWNLOAD_SHA256=548d73d19fb787dd0530334e398fd256ef3a581181678488a741a995c4f007fb \ +ENV VERSION=1.6.13 \ + DOWNLOAD_SHA256=ce205248dd323e4e562ff83e9e84d0f9a16f4bda87183c367c66a7163c0fc287 \ GPG_KEYS=A0D6EEA1DCAE49A635A3B2F0779B22DFB3E717B7 \ LWS_VERSION=2.4.2 \ LWS_SHA256=73012d7fcf428dedccc816e83a63a01462e27819d5537b8e0d0c7264bfacfad6 diff --git a/docker/1.6/Dockerfile b/docker/1.6/Dockerfile index 63083ec2..f8fa4fd9 100644 --- a/docker/1.6/Dockerfile +++ b/docker/1.6/Dockerfile @@ -3,8 +3,8 @@ FROM alpine:3.12 LABEL maintainer="Roger Light " \ description="Eclipse Mosquitto MQTT Broker" -ENV VERSION=1.6.12 \ - DOWNLOAD_SHA256=548d73d19fb787dd0530334e398fd256ef3a581181678488a741a995c4f007fb \ +ENV VERSION=1.6.13 \ + DOWNLOAD_SHA256=ce205248dd323e4e562ff83e9e84d0f9a16f4bda87183c367c66a7163c0fc287 \ GPG_KEYS=A0D6EEA1DCAE49A635A3B2F0779B22DFB3E717B7 \ LWS_VERSION=2.4.2 \ LWS_SHA256=73012d7fcf428dedccc816e83a63a01462e27819d5537b8e0d0c7264bfacfad6 diff --git a/docker/2.0-openssl/Dockerfile b/docker/2.0-openssl/Dockerfile index fdb2c7da..85e0ee2c 100644 --- a/docker/2.0-openssl/Dockerfile +++ b/docker/2.0-openssl/Dockerfile @@ -3,8 +3,8 @@ FROM alpine:3.12 LABEL maintainer="Roger Light " \ description="Eclipse Mosquitto MQTT Broker" -ENV VERSION=2.0.5 \ - DOWNLOAD_SHA256=67eaeb4160e5793715c017f53c4f42808d76129b7ad131d765a6a23792e58d5d \ +ENV VERSION=2.0.8 \ + DOWNLOAD_SHA256=b15da8fc4edcb91d554e1259e220ea0173ef639ceaa4b465e06feb7e125b84bf \ GPG_KEYS=A0D6EEA1DCAE49A635A3B2F0779B22DFB3E717B7 \ LWS_VERSION=2.4.2 \ LWS_SHA256=73012d7fcf428dedccc816e83a63a01462e27819d5537b8e0d0c7264bfacfad6 \ @@ -106,7 +106,7 @@ RUN set -x && \ VOLUME ["/mosquitto/data", "/mosquitto/log"] # Set up the entry point script and default command -COPY docker-entrypoint.sh / +COPY docker-entrypoint.sh mosquitto-no-auth.conf / EXPOSE 1883 ENTRYPOINT ["/docker-entrypoint.sh"] CMD ["/usr/sbin/mosquitto", "-c", "/mosquitto/config/mosquitto.conf"] diff --git a/docker/2.0-openssl/README.md b/docker/2.0-openssl/README.md index 8a54a86b..8ec812ed 100644 --- a/docker/2.0-openssl/README.md +++ b/docker/2.0-openssl/README.md @@ -18,13 +18,51 @@ Two docker volumes have been created in the image to be used for persistent stor The image runs mosquitto under the mosquitto user and group, which are created with a uid and gid of 1883. +## Running without a configuration file +Mosquitto 2.0 requires you to configure listeners and authentication before it +will allow connections from anything other than the loopback interface. In the +context of a container, this means you would normally need to provide a +configuration file with your settings. + +If you wish to run mosquitto without any authentication, and without setting +any other configuration options, you can do so by using a configuration +provided in the container for this purpose: +``` +docker run -it -p 1883:1883 eclipse-mosquitto: mosquitto -c /mosquitto-no-auth.conf +``` + ## Configuration -When creating a container from the image, the default configuration values are used. To use a custom configuration file, mount a **local** configuration file to `/mosquitto/config/mosquitto.conf` + ``` docker run -it -p 1883:1883 -v :/mosquitto/config/mosquitto.conf eclipse-mosquitto: ``` +Your configuration file must include a `listener`, and you must configure some +form of authentication or allow unauthenticated access. If you do not do this, +clients will be unable to connect. + + +File based authentication and authorisation: +``` +listener 1883 +password_file /mosquitto/data/mosquitto.password_file +acl_file /mosquitto/data/mosquitto.aclfile +``` + +Plugin based authentication and authorisation: +``` +listener 1883 +plugin /usr/lib/mosquitto_dynamic_security.so +plugin_opt_config_file /mosquitto/data/mosquitto-dynsec.json +``` + +Unauthenticated access: +``` +listener 1883 +allow_anonymous true +``` + :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, for example: diff --git a/docker/2.0-openssl/mosquitto-no-auth.conf b/docker/2.0-openssl/mosquitto-no-auth.conf new file mode 100644 index 00000000..40dd92b9 --- /dev/null +++ b/docker/2.0-openssl/mosquitto-no-auth.conf @@ -0,0 +1,5 @@ +# This is a Mosquitto configuration file that creates a listener on port 1883 +# that allows unauthenticated access. + +listener 1883 +allow_anonymous true diff --git a/docker/2.0/Dockerfile b/docker/2.0/Dockerfile index 09f22301..1111687b 100644 --- a/docker/2.0/Dockerfile +++ b/docker/2.0/Dockerfile @@ -3,8 +3,8 @@ FROM alpine:3.12 LABEL maintainer="Roger Light " \ description="Eclipse Mosquitto MQTT Broker" -ENV VERSION=2.0.5 \ - DOWNLOAD_SHA256=67eaeb4160e5793715c017f53c4f42808d76129b7ad131d765a6a23792e58d5d \ +ENV VERSION=2.0.8 \ + DOWNLOAD_SHA256=b15da8fc4edcb91d554e1259e220ea0173ef639ceaa4b465e06feb7e125b84bf \ GPG_KEYS=A0D6EEA1DCAE49A635A3B2F0779B22DFB3E717B7 \ LWS_VERSION=2.4.2 \ LWS_SHA256=73012d7fcf428dedccc816e83a63a01462e27819d5537b8e0d0c7264bfacfad6 \ @@ -108,7 +108,7 @@ RUN set -x && \ VOLUME ["/mosquitto/data", "/mosquitto/log"] # Set up the entry point script and default command -COPY docker-entrypoint.sh / +COPY docker-entrypoint.sh mosquitto-no-auth.conf / EXPOSE 1883 ENTRYPOINT ["/docker-entrypoint.sh"] CMD ["/usr/sbin/mosquitto", "-c", "/mosquitto/config/mosquitto.conf"] diff --git a/docker/2.0/README.md b/docker/2.0/README.md index 8a54a86b..8ec812ed 100644 --- a/docker/2.0/README.md +++ b/docker/2.0/README.md @@ -18,13 +18,51 @@ Two docker volumes have been created in the image to be used for persistent stor The image runs mosquitto under the mosquitto user and group, which are created with a uid and gid of 1883. +## Running without a configuration file +Mosquitto 2.0 requires you to configure listeners and authentication before it +will allow connections from anything other than the loopback interface. In the +context of a container, this means you would normally need to provide a +configuration file with your settings. + +If you wish to run mosquitto without any authentication, and without setting +any other configuration options, you can do so by using a configuration +provided in the container for this purpose: +``` +docker run -it -p 1883:1883 eclipse-mosquitto: mosquitto -c /mosquitto-no-auth.conf +``` + ## Configuration -When creating a container from the image, the default configuration values are used. To use a custom configuration file, mount a **local** configuration file to `/mosquitto/config/mosquitto.conf` + ``` docker run -it -p 1883:1883 -v :/mosquitto/config/mosquitto.conf eclipse-mosquitto: ``` +Your configuration file must include a `listener`, and you must configure some +form of authentication or allow unauthenticated access. If you do not do this, +clients will be unable to connect. + + +File based authentication and authorisation: +``` +listener 1883 +password_file /mosquitto/data/mosquitto.password_file +acl_file /mosquitto/data/mosquitto.aclfile +``` + +Plugin based authentication and authorisation: +``` +listener 1883 +plugin /usr/lib/mosquitto_dynamic_security.so +plugin_opt_config_file /mosquitto/data/mosquitto-dynsec.json +``` + +Unauthenticated access: +``` +listener 1883 +allow_anonymous true +``` + :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, for example: diff --git a/docker/2.0/mosquitto-no-auth.conf b/docker/2.0/mosquitto-no-auth.conf new file mode 100644 index 00000000..40dd92b9 --- /dev/null +++ b/docker/2.0/mosquitto-no-auth.conf @@ -0,0 +1,5 @@ +# This is a Mosquitto configuration file that creates a listener on port 1883 +# that allows unauthenticated access. + +listener 1883 +allow_anonymous true diff --git a/include/mosquitto.h b/include/mosquitto.h index afdb59ca..cb75a1c6 100644 --- a/include/mosquitto.h +++ b/include/mosquitto.h @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. @@ -66,7 +66,7 @@ extern "C" { #define LIBMOSQUITTO_MAJOR 2 #define LIBMOSQUITTO_MINOR 0 -#define LIBMOSQUITTO_REVISION 5 +#define LIBMOSQUITTO_REVISION 8 /* 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) @@ -1613,40 +1613,6 @@ libmosq_EXPORT int mosquitto_string_option(struct mosquitto *mosq, enum mosq_opt */ libmosq_EXPORT int mosquitto_void_option(struct mosquitto *mosq, enum mosq_opt_t option, void *value); -/* - * Function: mosquitto_string_option - * - * Used to set const char* options for the client. - * - * Parameters: - * mosq - a valid mosquitto instance. - * option - the option to set. - * value - the option specific value. - * - * Options: - * MOSQ_OPT_TLS_ENGINE - * Configure the client for TLS Engine support. Pass a TLS Engine ID - * to be used when creating TLS connections. - * Must be set before . - * MOSQ_OPT_TLS_KEYFORM - * Configure the client to treat the keyfile differently depending - * on its type. Must be set before . - * Set as either "pem" or "engine", to determine from where the - * private key for a TLS connection will be obtained. Defaults to - * "pem", a normal private key file. - * MOSQ_OPT_TLS_KPASS_SHA1 - * Where the TLS Engine requires the use of a password to be - * accessed, this option allows a hex encoded SHA1 hash of the - * private key password to be passed to the engine directly. - * Must be set before . - * MOSQ_OPT_TLS_ALPN - * If the broker being connected to has multiple services available - * on a single TLS port, such as both MQTT and WebSockets, use this - * option to configure the ALPN option for the connection. - */ -libmosq_EXPORT int mosquitto_string_option(struct mosquitto *mosq, enum mosq_opt_t option, const char *value); - - /* * Function: mosquitto_reconnect_delay_set * diff --git a/include/mosquitto_broker.h b/include/mosquitto_broker.h index f8c473e6..631dc34f 100644 --- a/include/mosquitto_broker.h +++ b/include/mosquitto_broker.h @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. @@ -37,6 +37,7 @@ extern "C" { #include #include #include +#include struct mosquitto; typedef struct mqtt5__property mosquitto_property; @@ -158,8 +159,8 @@ struct mosquitto_evt_tick { void *future; long now_ns; long next_ns; - int now_s; - int next_s; + time_t now_s; + time_t next_s; void *future2[4]; }; diff --git a/include/mosquitto_plugin.h b/include/mosquitto_plugin.h index 4199c7b3..d8a6c72c 100644 --- a/include/mosquitto_plugin.h +++ b/include/mosquitto_plugin.h @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/include/mqtt_protocol.h b/include/mqtt_protocol.h index 86d7dc99..15c4c3ef 100644 --- a/include/mqtt_protocol.h +++ b/include/mqtt_protocol.h @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/installer/mosquitto.nsi b/installer/mosquitto.nsi index 0ad72cd4..e34c7847 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.5 +!define VERSION 2.0.8 OutFile "mosquitto-${VERSION}-install-windows-x86.exe" InstallDir "$PROGRAMFILES\mosquitto" diff --git a/installer/mosquitto64.nsi b/installer/mosquitto64.nsi index 4bf999ee..4bd80f54 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.5 +!define VERSION 2.0.8 OutFile "mosquitto-${VERSION}-install-windows-x64.exe" !include "x64.nsh" diff --git a/lib/actions.c b/lib/actions.c index 4f7ff012..f260eaba 100644 --- a/lib/actions.c +++ b/lib/actions.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. @@ -92,7 +92,7 @@ int mosquitto_publish_v5(struct mosquitto *mosq, int *mid, const char *topic, in }else{ tlen = strlen(topic); if(mosquitto_validate_utf8(topic, (int)tlen)) return MOSQ_ERR_MALFORMED_UTF8; - if(payloadlen < 0 || payloadlen > MQTT_MAX_PAYLOAD) return MOSQ_ERR_PAYLOAD_SIZE; + if(payloadlen < 0 || payloadlen > (int)MQTT_MAX_PAYLOAD) return MOSQ_ERR_PAYLOAD_SIZE; if(mosquitto_pub_topic_check(topic) != MOSQ_ERR_SUCCESS){ return MOSQ_ERR_INVAL; } diff --git a/lib/alias_mosq.c b/lib/alias_mosq.c index 522a3650..95fbc969 100644 --- a/lib/alias_mosq.c +++ b/lib/alias_mosq.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/alias_mosq.h b/lib/alias_mosq.h index 67e2520c..7df41497 100644 --- a/lib/alias_mosq.h +++ b/lib/alias_mosq.h @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/callbacks.c b/lib/callbacks.c index a29f5fde..8e74968e 100644 --- a/lib/callbacks.c +++ b/lib/callbacks.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/connect.c b/lib/connect.c index 8d4b1710..5249d46e 100644 --- a/lib/connect.c +++ b/lib/connect.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/handle_auth.c b/lib/handle_auth.c index 33130ca3..e33d085d 100644 --- a/lib/handle_auth.c +++ b/lib/handle_auth.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/handle_connack.c b/lib/handle_connack.c index 7cf50952..6dca1395 100644 --- a/lib/handle_connack.c +++ b/lib/handle_connack.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/handle_disconnect.c b/lib/handle_disconnect.c index 4d1ac479..a0a638db 100644 --- a/lib/handle_disconnect.c +++ b/lib/handle_disconnect.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/handle_ping.c b/lib/handle_ping.c index 9009b720..24a9e4e5 100644 --- a/lib/handle_ping.c +++ b/lib/handle_ping.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/handle_pubackcomp.c b/lib/handle_pubackcomp.c index ed0c5dca..5755708e 100644 --- a/lib/handle_pubackcomp.c +++ b/lib/handle_pubackcomp.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/handle_publish.c b/lib/handle_publish.c index 12cced6f..40644ef3 100644 --- a/lib/handle_publish.c +++ b/lib/handle_publish.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/handle_pubrec.c b/lib/handle_pubrec.c index fc5b7cf4..b741a076 100644 --- a/lib/handle_pubrec.c +++ b/lib/handle_pubrec.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/handle_pubrel.c b/lib/handle_pubrel.c index 1cd2864a..b52e631c 100644 --- a/lib/handle_pubrel.c +++ b/lib/handle_pubrel.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/handle_suback.c b/lib/handle_suback.c index 93a64e8a..91a40e26 100644 --- a/lib/handle_suback.c +++ b/lib/handle_suback.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/handle_unsuback.c b/lib/handle_unsuback.c index fdd255c1..fd32d486 100644 --- a/lib/handle_unsuback.c +++ b/lib/handle_unsuback.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/helpers.c b/lib/helpers.c index 05149201..3f076925 100644 --- a/lib/helpers.c +++ b/lib/helpers.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/logging_mosq.c b/lib/logging_mosq.c index adddc28b..16e9e949 100644 --- a/lib/logging_mosq.c +++ b/lib/logging_mosq.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/logging_mosq.h b/lib/logging_mosq.h index 17b49a60..580edb8b 100644 --- a/lib/logging_mosq.h +++ b/lib/logging_mosq.h @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/loop.c b/lib/loop.c index 00b99ee3..bc2ba7f4 100644 --- a/lib/loop.c +++ b/lib/loop.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/memory_mosq.c b/lib/memory_mosq.c index 73f9901a..4367197e 100644 --- a/lib/memory_mosq.c +++ b/lib/memory_mosq.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/memory_mosq.h b/lib/memory_mosq.h index 85d77492..48fadf8c 100644 --- a/lib/memory_mosq.h +++ b/lib/memory_mosq.h @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. @@ -22,8 +22,10 @@ Contributors: #include #include -#if defined(WITH_MEMORY_TRACKING) && defined(WITH_BROKER) && defined(__GLIBC__) -#define REAL_WITH_MEMORY_TRACKING +#if defined(WITH_MEMORY_TRACKING) && defined(WITH_BROKER) +# if defined(__APPLE__) || defined(__FreeBSD__) || defined(__GLIBC__) +# define REAL_WITH_MEMORY_TRACKING +# endif #endif void *mosquitto__calloc(size_t nmemb, size_t size); diff --git a/lib/messages_mosq.c b/lib/messages_mosq.c index e0dfb3f9..ff28a915 100644 --- a/lib/messages_mosq.c +++ b/lib/messages_mosq.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/messages_mosq.h b/lib/messages_mosq.h index 6a66a50c..5689b49e 100644 --- a/lib/messages_mosq.h +++ b/lib/messages_mosq.h @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/misc_mosq.c b/lib/misc_mosq.c index 75b2eaac..e7bf0784 100644 --- a/lib/misc_mosq.c +++ b/lib/misc_mosq.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/misc_mosq.h b/lib/misc_mosq.h index 6456c02b..233071e6 100644 --- a/lib/misc_mosq.h +++ b/lib/misc_mosq.h @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/mosquitto.c b/lib/mosquitto.c index daa9ce75..50645892 100644 --- a/lib/mosquitto.c +++ b/lib/mosquitto.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/mosquitto_internal.h b/lib/mosquitto_internal.h index fc6eab16..fdf0dcb4 100644 --- a/lib/mosquitto_internal.h +++ b/lib/mosquitto_internal.h @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. @@ -190,8 +190,8 @@ struct mosquitto_msg_data{ #ifdef WITH_BROKER struct mosquitto_client_msg *inflight; struct mosquitto_client_msg *queued; - unsigned long msg_bytes; - unsigned long msg_bytes12; + long msg_bytes; + long msg_bytes12; int msg_count; int msg_count12; #else diff --git a/lib/net_mosq.c b/lib/net_mosq.c index f1da60f8..d42d83a7 100644 --- a/lib/net_mosq.c +++ b/lib/net_mosq.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. @@ -942,7 +942,7 @@ int net__socket_connect(struct mosquitto *mosq, const char *host, uint16_t port, if(rc2) return rc2; } - return MOSQ_ERR_SUCCESS; + return rc; } diff --git a/lib/net_mosq.h b/lib/net_mosq.h index 6dc2a1a4..30342179 100644 --- a/lib/net_mosq.h +++ b/lib/net_mosq.h @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/net_mosq_ocsp.c b/lib/net_mosq_ocsp.c index 0f6c3002..84b818c8 100644 --- a/lib/net_mosq_ocsp.c +++ b/lib/net_mosq_ocsp.c @@ -11,7 +11,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Dr. Lars Voelker, BMW AG diff --git a/lib/options.c b/lib/options.c index a150dd0e..deb7c01f 100644 --- a/lib/options.c +++ b/lib/options.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/packet_datatypes.c b/lib/packet_datatypes.c index 7a195d19..e13d9489 100644 --- a/lib/packet_datatypes.c +++ b/lib/packet_datatypes.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/packet_mosq.c b/lib/packet_mosq.c index e576c67c..ebe6b6b8 100644 --- a/lib/packet_mosq.c +++ b/lib/packet_mosq.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. @@ -215,10 +215,6 @@ int packet__write(struct mosquitto *mosq) if(!mosq) return MOSQ_ERR_INVAL; if(mosq->sock == INVALID_SOCKET) return MOSQ_ERR_NO_CONN; -#ifdef WITH_BROKER - mux__add_out(mosq); -#endif - pthread_mutex_lock(&mosq->current_out_packet_mutex); pthread_mutex_lock(&mosq->out_packet_mutex); if(mosq->out_packet && !mosq->current_out_packet){ @@ -230,6 +226,12 @@ int packet__write(struct mosquitto *mosq) } pthread_mutex_unlock(&mosq->out_packet_mutex); +#ifdef WITH_BROKER + if(mosq->current_out_packet){ + mux__add_out(mosq); + } +#endif + state = mosquitto__get_state(mosq); #if defined(WITH_TLS) && !defined(WITH_BROKER) if(state == mosq_cs_connect_pending || mosq->want_connect){ diff --git a/lib/packet_mosq.h b/lib/packet_mosq.h index cbdbb68e..38921794 100644 --- a/lib/packet_mosq.h +++ b/lib/packet_mosq.h @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/property_mosq.c b/lib/property_mosq.c index ef8ffc80..8a77dbe6 100644 --- a/lib/property_mosq.c +++ b/lib/property_mosq.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/property_mosq.h b/lib/property_mosq.h index c0110909..c913c051 100644 --- a/lib/property_mosq.h +++ b/lib/property_mosq.h @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/read_handle.c b/lib/read_handle.c index 72ff7555..dd6a06bd 100644 --- a/lib/read_handle.c +++ b/lib/read_handle.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/read_handle.h b/lib/read_handle.h index b687fea3..3f97f90d 100644 --- a/lib/read_handle.h +++ b/lib/read_handle.h @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/send_connect.c b/lib/send_connect.c index 29b29c69..d35cd80e 100644 --- a/lib/send_connect.c +++ b/lib/send_connect.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/send_disconnect.c b/lib/send_disconnect.c index 2d2d7932..db2efe08 100644 --- a/lib/send_disconnect.c +++ b/lib/send_disconnect.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/send_mosq.c b/lib/send_mosq.c index da348c89..059e7604 100644 --- a/lib/send_mosq.c +++ b/lib/send_mosq.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/send_mosq.h b/lib/send_mosq.h index 90274c67..7ab48f11 100644 --- a/lib/send_mosq.h +++ b/lib/send_mosq.h @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/send_publish.c b/lib/send_publish.c index e2cec9cf..1d1842a0 100644 --- a/lib/send_publish.c +++ b/lib/send_publish.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. @@ -42,8 +42,8 @@ Contributors: int send__publish(struct mosquitto *mosq, uint16_t mid, const char *topic, uint32_t payloadlen, const void *payload, uint8_t qos, bool retain, bool dup, const mosquitto_property *cmsg_props, const mosquitto_property *store_props, uint32_t expiry_interval) { #ifdef WITH_BROKER - size_t len; #ifdef WITH_BRIDGE + size_t len; int i; struct mosquitto__bridge_topic *cur_topic; bool match; diff --git a/lib/send_subscribe.c b/lib/send_subscribe.c index c030ee10..a8e77545 100644 --- a/lib/send_subscribe.c +++ b/lib/send_subscribe.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/send_unsubscribe.c b/lib/send_unsubscribe.c index 27e612cf..654f0ebe 100644 --- a/lib/send_unsubscribe.c +++ b/lib/send_unsubscribe.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/socks_mosq.c b/lib/socks_mosq.c index 68ef72a6..a360d64b 100644 --- a/lib/socks_mosq.c +++ b/lib/socks_mosq.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/socks_mosq.h b/lib/socks_mosq.h index 6a1f3368..d08c3c52 100644 --- a/lib/socks_mosq.h +++ b/lib/socks_mosq.h @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/srv_mosq.c b/lib/srv_mosq.c index 049b6cff..412fc1eb 100644 --- a/lib/srv_mosq.c +++ b/lib/srv_mosq.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/strings_mosq.c b/lib/strings_mosq.c index b3a75bd1..3688650d 100644 --- a/lib/strings_mosq.c +++ b/lib/strings_mosq.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/thread_mosq.c b/lib/thread_mosq.c index a8e5747a..dbbda85e 100644 --- a/lib/thread_mosq.c +++ b/lib/thread_mosq.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/time_mosq.c b/lib/time_mosq.c index de8679b2..e8eb0755 100644 --- a/lib/time_mosq.c +++ b/lib/time_mosq.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/time_mosq.h b/lib/time_mosq.h index 8300289b..175d9732 100644 --- a/lib/time_mosq.h +++ b/lib/time_mosq.h @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/tls_mosq.c b/lib/tls_mosq.c index 96f444d5..bddf2ec0 100644 --- a/lib/tls_mosq.c +++ b/lib/tls_mosq.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/tls_mosq.h b/lib/tls_mosq.h index 61020d4a..479741d2 100644 --- a/lib/tls_mosq.h +++ b/lib/tls_mosq.h @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/utf8_mosq.c b/lib/utf8_mosq.c index e0c841d5..4a79cbd8 100644 --- a/lib/utf8_mosq.c +++ b/lib/utf8_mosq.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation. diff --git a/lib/util_mosq.c b/lib/util_mosq.c index 05b29ff7..fda69801 100644 --- a/lib/util_mosq.c +++ b/lib/util_mosq.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/util_mosq.h b/lib/util_mosq.h index abb197d1..6fa60cfc 100644 --- a/lib/util_mosq.h +++ b/lib/util_mosq.h @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/lib/util_topic.c b/lib/util_topic.c index 03917b10..62b53112 100644 --- a/lib/util_topic.c +++ b/lib/util_topic.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. @@ -54,6 +54,11 @@ int mosquitto_pub_topic_check(const char *str) #ifdef WITH_BROKER int hier_count = 0; #endif + + if(str == NULL){ + return MOSQ_ERR_INVAL; + } + while(str && str[0]){ if(str[0] == '+' || str[0] == '#'){ return MOSQ_ERR_INVAL; @@ -81,7 +86,9 @@ int mosquitto_pub_topic_check2(const char *str, size_t len) int hier_count = 0; #endif - if(len > 65535) return MOSQ_ERR_INVAL; + if(str == NULL || len > 65535){ + return MOSQ_ERR_INVAL; + } for(i=0; i 65535) return MOSQ_ERR_INVAL; + if(str == NULL || len > 65535){ + return MOSQ_ERR_INVAL; + } for(i=0; i MQTT_MAX_PAYLOAD) return MOSQ_ERR_PAYLOAD_SIZE; + if(payloadlen < 0 || payloadlen > (int)MQTT_MAX_PAYLOAD) return MOSQ_ERR_PAYLOAD_SIZE; if(payloadlen > 0 && !payload) return MOSQ_ERR_INVAL; if(mosquitto_pub_topic_check(topic)) return MOSQ_ERR_INVAL; diff --git a/lib/will_mosq.h b/lib/will_mosq.h index d7c8a199..9bfdc572 100644 --- a/lib/will_mosq.h +++ b/lib/will_mosq.h @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/man/CMakeLists.txt b/man/CMakeLists.txt index 98a457d1..2c8b0955 100644 --- a/man/CMakeLists.txt +++ b/man/CMakeLists.txt @@ -1,31 +1,47 @@ +# If we are building from a release tarball, the man pages should already be built, so them. +# If we are building from git, then the man pages will not be built. In this +# case, attempt to find xsltproc, and if found build the man pages. If xsltproc +# could not be found, then the man pages will not be built or installed - +# because the install is optional. + if(NOT WIN32) - find_program(XSLTPROC xsltproc REQUIRED) - if(NOT XSLTPROC) + find_program(XSLTPROC xsltproc OPTIONAL) + if(XSLTPROC) + function(compile_manpage page) + add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/man/${page} + COMMAND xsltproc ${CMAKE_SOURCE_DIR}/man/${page}.xml -o ${CMAKE_SOURCE_DIR}/man/ + MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/man/${page}.xml) + add_custom_target(${page} ALL DEPENDS ${CMAKE_SOURCE_DIR}/man/${page}) + endfunction() + + compile_manpage("mosquitto_ctrl.1") + compile_manpage("mosquitto_ctrl_dynsec.1") + compile_manpage("mosquitto_passwd.1") + compile_manpage("mosquitto_pub.1") + compile_manpage("mosquitto_sub.1") + compile_manpage("mosquitto_rr.1") + compile_manpage("libmosquitto.3") + compile_manpage("mosquitto.conf.5") + compile_manpage("mosquitto-tls.7") + compile_manpage("mqtt.7") + compile_manpage("mosquitto.8") + else() message(FATAL_ERROR "xsltproc not found: manpages cannot be built") endif() - function(compile_manpage page) - add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/man/${page} - COMMAND xsltproc ${CMAKE_SOURCE_DIR}/man/${page}.xml -o ${CMAKE_SOURCE_DIR}/man/ - MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/man/${page}.xml) - add_custom_target(${page} ALL DEPENDS ${CMAKE_SOURCE_DIR}/man/${page}) - endfunction() - - compile_manpage("mosquitto_ctrl.1") - compile_manpage("mosquitto_ctrl_dynsec.1") - compile_manpage("mosquitto_passwd.1") - compile_manpage("mosquitto_pub.1") - compile_manpage("mosquitto_sub.1") - compile_manpage("mosquitto_rr.1") - compile_manpage("libmosquitto.3") - compile_manpage("mosquitto.conf.5") - compile_manpage("mosquitto-tls.7") - compile_manpage("mqtt.7") - compile_manpage("mosquitto.8") endif() -install(FILES mosquitto_ctrl.1 mosquitto_ctrl_dynsec.1 mosquitto_passwd.1 mosquitto_pub.1 mosquitto_sub.1 mosquitto_rr.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) -install(FILES libmosquitto.3 DESTINATION ${CMAKE_INSTALL_MANDIR}/man3) -install(FILES mosquitto.conf.5 DESTINATION ${CMAKE_INSTALL_MANDIR}/man5) -install(FILES mosquitto-tls.7 mqtt.7 DESTINATION ${CMAKE_INSTALL_MANDIR}/man7) -install(FILES mosquitto.8 DESTINATION ${CMAKE_INSTALL_MANDIR}/man8) +install(FILES + mosquitto_ctrl.1 + mosquitto_ctrl_dynsec.1 + mosquitto_passwd.1 + mosquitto_pub.1 + mosquitto_sub.1 + mosquitto_rr.1 + DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 + OPTIONAL) + +install(FILES libmosquitto.3 DESTINATION ${CMAKE_INSTALL_MANDIR}/man3 OPTIONAL) +install(FILES mosquitto.conf.5 DESTINATION ${CMAKE_INSTALL_MANDIR}/man5 OPTIONAL) +install(FILES mosquitto-tls.7 mqtt.7 DESTINATION ${CMAKE_INSTALL_MANDIR}/man7 OPTIONAL) +install(FILES mosquitto.8 DESTINATION ${CMAKE_INSTALL_MANDIR}/man8 OPTIONAL) diff --git a/man/mosquitto.8.xml b/man/mosquitto.8.xml index e00bdd6d..fe2b2d9d 100644 --- a/man/mosquitto.8.xml +++ b/man/mosquitto.8.xml @@ -431,6 +431,8 @@ be reloaded without restarting. See mosquitto.conf5 for details. + If TLS certificates are in use, then mosquitto will + also reload certificate on receiving a SIGHUP. diff --git a/man/mosquitto.conf.5.xml b/man/mosquitto.conf.5.xml index d106a954..c3d8193c 100644 --- a/man/mosquitto.conf.5.xml +++ b/man/mosquitto.conf.5.xml @@ -1275,6 +1275,12 @@ log_timestamp_format %Y-%m-%dT%H:%M:%S option and must be present to enable certificate based TLS encryption. + + The certificate pointed to by this option will be + reloaded when Mosquitto receives a SIGHUP signal. + This can be used to load new certificates prior to + the existing ones expiring. + @@ -1328,6 +1334,12 @@ openssl dhparam -out dhparam.pem 2048 option and must be present to enable certificate based TLS encryption. + + The private key pointed to by this option will be + reloaded when Mosquitto receives a SIGHUP signal. + This can be used to load new keys prior to + the existing ones expiring. + diff --git a/misc/letsencrypt/mosquitto-copy.sh b/misc/letsencrypt/mosquitto-copy.sh index c2a69470..5c7fb7d0 100755 --- a/misc/letsencrypt/mosquitto-copy.sh +++ b/misc/letsencrypt/mosquitto-copy.sh @@ -12,7 +12,7 @@ # Place this script in /etc/letsencrypt/renewal-hooks/deploy/ and make it # executable after editing it to your needs. -if [ ${RENEWED_DOMAINS} == "my-mosquitto-domain" ]; then +if [ ${RENEWED_DOMAINS} = "my-mosquitto-domain" ]; then # Copy new certificate to Mosquitto directory cp ${RENEWED_LINEAGE}/fullchain.pem /etc/mosquitto/certs/server.pem cp ${RENEWED_LINEAGE}/privkey.pem /etc/mosquitto/certs/server.key diff --git a/plugins/dynamic-security/acl.c b/plugins/dynamic-security/acl.c index 7aaf3f8c..8a57f7a9 100644 --- a/plugins/dynamic-security/acl.c +++ b/plugins/dynamic-security/acl.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/plugins/dynamic-security/auth.c b/plugins/dynamic-security/auth.c index 9ca9b132..1f62e1fb 100644 --- a/plugins/dynamic-security/auth.c +++ b/plugins/dynamic-security/auth.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/plugins/dynamic-security/clientlist.c b/plugins/dynamic-security/clientlist.c index d362a9b8..779c774c 100644 --- a/plugins/dynamic-security/clientlist.c +++ b/plugins/dynamic-security/clientlist.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/plugins/dynamic-security/clients.c b/plugins/dynamic-security/clients.c index de9092dd..50eba278 100644 --- a/plugins/dynamic-security/clients.c +++ b/plugins/dynamic-security/clients.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/plugins/dynamic-security/dynamic_security.h b/plugins/dynamic-security/dynamic_security.h index 57c814b8..561af50a 100644 --- a/plugins/dynamic-security/dynamic_security.h +++ b/plugins/dynamic-security/dynamic_security.h @@ -12,7 +12,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/plugins/dynamic-security/grouplist.c b/plugins/dynamic-security/grouplist.c index afdc0186..2d4cf13b 100644 --- a/plugins/dynamic-security/grouplist.c +++ b/plugins/dynamic-security/grouplist.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/plugins/dynamic-security/groups.c b/plugins/dynamic-security/groups.c index d66e4dba..c4bdda14 100644 --- a/plugins/dynamic-security/groups.c +++ b/plugins/dynamic-security/groups.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/plugins/dynamic-security/json_help.c b/plugins/dynamic-security/json_help.c index dd8379c9..e0c8178b 100644 --- a/plugins/dynamic-security/json_help.c +++ b/plugins/dynamic-security/json_help.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/plugins/dynamic-security/json_help.h b/plugins/dynamic-security/json_help.h index b1b6aed0..1bb6623a 100644 --- a/plugins/dynamic-security/json_help.h +++ b/plugins/dynamic-security/json_help.h @@ -12,7 +12,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/plugins/dynamic-security/plugin.c b/plugins/dynamic-security/plugin.c index 1ee89890..d5a8cf06 100644 --- a/plugins/dynamic-security/plugin.c +++ b/plugins/dynamic-security/plugin.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/plugins/dynamic-security/rolelist.c b/plugins/dynamic-security/rolelist.c index 6df19d21..a8c93a96 100644 --- a/plugins/dynamic-security/rolelist.c +++ b/plugins/dynamic-security/rolelist.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/plugins/dynamic-security/roles.c b/plugins/dynamic-security/roles.c index 5ffc911b..fb116770 100644 --- a/plugins/dynamic-security/roles.c +++ b/plugins/dynamic-security/roles.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/plugins/dynamic-security/sub_matches_sub.c b/plugins/dynamic-security/sub_matches_sub.c index 79701879..fb913902 100644 --- a/plugins/dynamic-security/sub_matches_sub.c +++ b/plugins/dynamic-security/sub_matches_sub.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/plugins/message-timestamp/mosquitto_message_timestamp.c b/plugins/message-timestamp/mosquitto_message_timestamp.c index 86132f42..ae35ff87 100644 --- a/plugins/message-timestamp/mosquitto_message_timestamp.c +++ b/plugins/message-timestamp/mosquitto_message_timestamp.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. @@ -28,7 +28,7 @@ Contributors: * * Note that this only works on Mosquitto 2.0 or later. */ - +#include "config.h" #include #include @@ -47,6 +47,9 @@ static int callback_message(int event, void *event_data, void *userdata) struct tm *ti; char time_buf[25]; + UNUSED(event); + UNUSED(userdata); + clock_gettime(CLOCK_REALTIME, &ts); ti = gmtime(&ts.tv_sec); strftime(time_buf, sizeof(time_buf), "%Y-%m-%dT%H:%M:%SZ", ti); @@ -68,11 +71,19 @@ int mosquitto_plugin_version(int supported_version_count, const int *supported_v int mosquitto_plugin_init(mosquitto_plugin_id_t *identifier, void **user_data, struct mosquitto_opt *opts, int opt_count) { + UNUSED(user_data); + UNUSED(opts); + UNUSED(opt_count); + mosq_pid = identifier; return mosquitto_callback_register(mosq_pid, MOSQ_EVT_MESSAGE, callback_message, NULL, NULL); } int mosquitto_plugin_cleanup(void *user_data, struct mosquitto_opt *opts, int opt_count) { + UNUSED(user_data); + UNUSED(opts); + UNUSED(opt_count); + return mosquitto_callback_unregister(mosq_pid, MOSQ_EVT_MESSAGE, callback_message, NULL); } diff --git a/plugins/payload-modification/mosquitto_payload_modification.c b/plugins/payload-modification/mosquitto_payload_modification.c index ac11e1c1..6af83ef5 100644 --- a/plugins/payload-modification/mosquitto_payload_modification.c +++ b/plugins/payload-modification/mosquitto_payload_modification.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/set-version.sh b/set-version.sh index dc6cf349..a96b6a77 100755 --- a/set-version.sh +++ b/set-version.sh @@ -2,7 +2,7 @@ MAJOR=2 MINOR=0 -REVISION=5 +REVISION=8 sed -i "s/^VERSION=.*/VERSION=${MAJOR}.${MINOR}.${REVISION}/" config.mk diff --git a/snap/local/default_config.conf b/snap/local/default_config.conf index be2071c6..c1156f27 100644 --- a/snap/local/default_config.conf +++ b/snap/local/default_config.conf @@ -1,3 +1,2 @@ -port 1883 persistence false user root diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 41495ef2..0099409a 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,5 +1,5 @@ name: mosquitto -version: 2.0.5 +version: 2.0.8 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/src/bridge.c b/src/bridge.c index 4702bfea..084d6820 100644 --- a/src/bridge.c +++ b/src/bridge.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/bridge_topic.c b/src/bridge_topic.c index fd4bd133..dc19fda1 100644 --- a/src/bridge_topic.c +++ b/src/bridge_topic.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/conf.c b/src/conf.c index e637fe24..5d8c701d 100644 --- a/src/conf.c +++ b/src/conf.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. @@ -1484,8 +1484,21 @@ int config__read_file_core(struct mosquitto__config *config, bool reload, struct { for(i=0; ilistener_count; i++){ if(config->listeners[i].port == tmp_int){ - cur_listener = &config->listeners[i]; - break; + /* Now check we have a matching bind address, if defined */ + if(config->listeners[i].host){ + if(token && !strcmp(config->listeners[i].host, token)){ + /* They both have a bind address, and they match */ + cur_listener = &config->listeners[i]; + break; + } + }else{ + if(token == NULL){ + /* Neither this config nor the new config have a bind address, + * so they match. */ + cur_listener = &config->listeners[i]; + break; + } + } } } } @@ -1747,6 +1760,7 @@ int config__read_file_core(struct mosquitto__config *config, bool reload, struct } memory__set_limit((size_t)lim); }else if(!strcmp(token, "message_size_limit")){ + log__printf(NULL, MOSQ_LOG_NOTICE, "Note: It is recommended to replace `message_size_limit` with `max_packet_size`."); if(conf__parse_int(&token, "message_size_limit", (int *)&config->message_size_limit, &saveptr)) return MOSQ_ERR_INVAL; if(config->message_size_limit > MQTT_MAX_PAYLOAD){ log__printf(NULL, MOSQ_LOG_ERR, "Error: Invalid message_size_limit value (%u).", config->message_size_limit); diff --git a/src/conf_includedir.c b/src/conf_includedir.c index 4a082c23..5dda0a1e 100644 --- a/src/conf_includedir.c +++ b/src/conf_includedir.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/context.c b/src/context.c index 5a48f5c0..83cb165f 100644 --- a/src/context.c +++ b/src/context.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/control.c b/src/control.c index b6fcf423..9cef197c 100644 --- a/src/control.c +++ b/src/control.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/database.c b/src/database.c index ebdf6ecd..77eb4520 100644 --- a/src/database.c +++ b/src/database.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. @@ -53,7 +53,7 @@ bool db__ready_for_flight(struct mosquitto_msg_data *msgs, int qos) 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_bytes = ((msgs->msg_bytes - (ssize_t)db.config->max_inflight_bytes) < (ssize_t)db.config->max_queued_bytes); valid_count = msgs->msg_count - msgs->inflight_maximum < db.config->max_queued_messages; if(db.config->max_queued_messages == 0){ @@ -90,8 +90,8 @@ bool db__ready_for_queue(struct mosquitto *context, int qos, struct mosquitto_ms { int source_count; int adjust_count; - size_t source_bytes; - size_t adjust_bytes = db.config->max_inflight_bytes; + long source_bytes; + ssize_t adjust_bytes = (ssize_t)db.config->max_inflight_bytes; bool valid_bytes; bool valid_count; diff --git a/src/handle_auth.c b/src/handle_auth.c index 36c3091a..299e0a64 100644 --- a/src/handle_auth.c +++ b/src/handle_auth.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/handle_connack.c b/src/handle_connack.c index 632212b9..6aacb592 100644 --- a/src/handle_connack.c +++ b/src/handle_connack.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/handle_connect.c b/src/handle_connect.c index ed0a9730..041f5a2e 100644 --- a/src/handle_connect.c +++ b/src/handle_connect.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. @@ -295,7 +295,7 @@ error: } -static int will__read(struct mosquitto *context, struct mosquitto_message_all **will, uint8_t will_qos, int will_retain) +static int will__read(struct mosquitto *context, const char *client_id, struct mosquitto_message_all **will, uint8_t will_qos, int will_retain) { int rc = MOSQ_ERR_SUCCESS; size_t slen; @@ -348,6 +348,16 @@ static int will__read(struct mosquitto *context, struct mosquitto_message_all ** will_struct->msg.payloadlen = payloadlen; if(will_struct->msg.payloadlen > 0){ + if(db.config->message_size_limit && will_struct->msg.payloadlen > (int)db.config->message_size_limit){ + log__printf(NULL, MOSQ_LOG_DEBUG, "Client %s connected with too large Will payload", client_id); + if(context->protocol == mosq_p_mqtt5){ + send__connack(context, 0, MQTT_RC_PACKET_TOO_LARGE, NULL); + }else{ + send__connack(context, 0, CONNACK_REFUSED_NOT_AUTHORIZED, NULL); + } + rc = MOSQ_ERR_PAYLOAD_SIZE; + goto error_cleanup; + } will_struct->msg.payload = mosquitto__malloc((size_t)will_struct->msg.payloadlen); if(!will_struct->msg.payload){ rc = MOSQ_ERR_NOMEM; @@ -606,7 +616,7 @@ int handle__connect(struct mosquitto *context) } if(will){ - rc = will__read(context, &will_struct, will_qos, will_retain); + rc = will__read(context, client_id, &will_struct, will_qos, will_retain); if(rc) goto handle_connect_error; }else{ if(context->protocol == mosq_p_mqtt311 || context->protocol == mosq_p_mqtt5){ @@ -828,6 +838,7 @@ int handle__connect(struct mosquitto *context) if(context->auth_method){ rc = mosquitto_security_auth_start(context, false, auth_data, auth_data_len, &auth_data_out, &auth_data_out_len); mosquitto__free(auth_data); + auth_data = NULL; if(rc == MOSQ_ERR_SUCCESS){ return connect__on_authorised(context, auth_data_out, auth_data_out_len); }else if(rc == MOSQ_ERR_AUTH_CONTINUE){ @@ -837,22 +848,23 @@ int handle__connect(struct mosquitto *context) return rc; }else{ free(auth_data_out); + auth_data_out = NULL; will__clear(context); if(rc == MOSQ_ERR_AUTH){ send__connack(context, 0, MQTT_RC_NOT_AUTHORIZED, NULL); mosquitto__free(context->id); context->id = NULL; - return MOSQ_ERR_PROTOCOL; + goto handle_connect_error; }else if(rc == MOSQ_ERR_NOT_SUPPORTED){ /* Client has requested extended authentication, but we don't support it. */ send__connack(context, 0, MQTT_RC_BAD_AUTHENTICATION_METHOD, NULL); mosquitto__free(context->id); context->id = NULL; - return MOSQ_ERR_PROTOCOL; + goto handle_connect_error; }else{ mosquitto__free(context->id); context->id = NULL; - return rc; + goto handle_connect_error; } } }else{ @@ -878,12 +890,11 @@ int handle__connect(struct mosquitto *context) }else{ send__connack(context, 0, CONNACK_REFUSED_NOT_AUTHORIZED, NULL); } - context__disconnect(context); rc = MOSQ_ERR_AUTH; goto handle_connect_error; break; default: - context__disconnect(context); + rc = MOSQ_ERR_UNKNOWN; goto handle_connect_error; break; } diff --git a/src/handle_disconnect.c b/src/handle_disconnect.c index 7c89f53a..2beb676a 100644 --- a/src/handle_disconnect.c +++ b/src/handle_disconnect.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/handle_publish.c b/src/handle_publish.c index c5843832..68359b69 100644 --- a/src/handle_publish.c +++ b/src/handle_publish.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. @@ -186,7 +186,7 @@ int handle__publish(struct mosquitto *context) rc = alias__find(context, &msg->topic, (uint16_t)topic_alias); if(rc){ db__msg_store_free(msg); - return MOSQ_ERR_TOPIC_ALIAS_INVALID; + return MOSQ_ERR_PROTOCOL; } } } @@ -224,7 +224,7 @@ int handle__publish(struct mosquitto *context) if(msg->payloadlen){ if(db.config->message_size_limit && msg->payloadlen > db.config->message_size_limit){ log__printf(NULL, MOSQ_LOG_DEBUG, "Dropped too large PUBLISH from %s (d%d, q%d, r%d, m%d, '%s', ... (%ld bytes))", context->id, dup, msg->qos, msg->retain, msg->source_mid, msg->topic, (long)msg->payloadlen); - reason_code = MQTT_RC_IMPLEMENTATION_SPECIFIC; + reason_code = MQTT_RC_PACKET_TOO_LARGE; goto process_bad_message; } msg->payload = mosquitto__malloc(msg->payloadlen+1); diff --git a/src/handle_subscribe.c b/src/handle_subscribe.c index e6e90a7b..2a72c597 100644 --- a/src/handle_subscribe.c +++ b/src/handle_subscribe.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/handle_unsubscribe.c b/src/handle_unsubscribe.c index 8e336f09..2162b465 100644 --- a/src/handle_unsubscribe.c +++ b/src/handle_unsubscribe.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/keepalive.c b/src/keepalive.c index 38ff4ff1..89d5c50b 100644 --- a/src/keepalive.c +++ b/src/keepalive.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/lib_load.h b/src/lib_load.h index b3704e7c..82ecc9c8 100644 --- a/src/lib_load.h +++ b/src/lib_load.h @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/logging.c b/src/logging.c index acee3a8a..ff1a5b4d 100644 --- a/src/logging.c +++ b/src/logging.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/loop.c b/src/loop.c index 820d4923..e17bae69 100644 --- a/src/loop.c +++ b/src/loop.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. @@ -48,6 +48,7 @@ Contributors: #include "mosquitto_broker_internal.h" #include "memory_mosq.h" +#include "mqtt_protocol.h" #include "packet_mosq.h" #include "send_mosq.h" #include "sys_tree.h" @@ -69,7 +70,7 @@ void lws__sul_callback(struct lws_sorted_usec_list *l) static struct lws_sorted_usec_list sul; #endif -static int single_publish(struct mosquitto *context, struct mosquitto_message_v5 *msg) +static int single_publish(struct mosquitto *context, struct mosquitto_message_v5 *msg, uint32_t message_expiry) { struct mosquitto_msg_store *stored; uint16_t mid; @@ -95,7 +96,7 @@ static int single_publish(struct mosquitto *context, struct mosquitto_message_v5 msg->properties = NULL; } - if(db__message_store(context, stored, 0, 0, mosq_mo_broker)) return 1; + if(db__message_store(context, stored, message_expiry, 0, mosq_mo_broker)) return 1; if(msg->qos){ mid = mosquitto__mid_generate(context); @@ -106,20 +107,50 @@ static int single_publish(struct mosquitto *context, struct mosquitto_message_v5 } +static void read_message_expiry_interval(mosquitto_property **proplist, uint32_t *message_expiry) +{ + mosquitto_property *p, *previous = NULL; + + *message_expiry = 0; + + if(!proplist) return; + + p = *proplist; + while(p){ + if(p->identifier == MQTT_PROP_MESSAGE_EXPIRY_INTERVAL){ + *message_expiry = p->value.i32; + if(p == *proplist){ + *proplist = p->next; + }else{ + previous->next = p->next; + } + property__free(&p); + return; + + } + previous = p; + p = p->next; + } +} + void queue_plugin_msgs(void) { struct mosquitto_message_v5 *msg, *tmp; struct mosquitto *context; + uint32_t message_expiry; DL_FOREACH_SAFE(db.plugin_msgs, msg, tmp){ DL_DELETE(db.plugin_msgs, msg); + + read_message_expiry_interval(&msg->properties, &message_expiry); + if(msg->clientid){ HASH_FIND(hh_id, db.contexts_by_id, msg->clientid, strlen(msg->clientid), context); if(context){ - single_publish(context, msg); + single_publish(context, msg, message_expiry); } }else{ - db__messages_easy_queue(NULL, msg->topic, (uint8_t)msg->qos, (uint32_t)msg->payloadlen, msg->payload, msg->retain, 0, &msg->properties); + db__messages_easy_queue(NULL, msg->topic, (uint8_t)msg->qos, (uint32_t)msg->payloadlen, msg->payload, msg->retain, message_expiry, &msg->properties); } mosquitto__free(msg->topic); mosquitto__free(msg->payload); @@ -316,6 +347,9 @@ void do_disconnect(struct mosquitto *context, int reason) case MOSQ_ERR_OVERSIZE_PACKET: log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s disconnected due to oversize packet.", id); break; + case MOSQ_ERR_PAYLOAD_SIZE: + log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s disconnected due to oversize payload.", id); + break; case MOSQ_ERR_NOMEM: log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s disconnected due to out of memory.", id); break; @@ -325,8 +359,11 @@ void do_disconnect(struct mosquitto *context, int reason) case MOSQ_ERR_ADMINISTRATIVE_ACTION: log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s been disconnected by administrative action.", id); break; + case MOSQ_ERR_ERRNO: + log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s disconnected: %s.", id, strerror(errno)); + break; default: - log__printf(NULL, MOSQ_LOG_NOTICE, "Bad socket read/write on client %s, disconnecting.", id); + log__printf(NULL, MOSQ_LOG_NOTICE, "Bad socket read/write on client %s: %s", id, mosquitto_strerror(reason)); break; } }else{ diff --git a/src/memory_public.c b/src/memory_public.c index 198d0f14..e1f791e0 100644 --- a/src/memory_public.c +++ b/src/memory_public.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/mosquitto.c b/src/mosquitto.c index 0df3afdb..704ddc5a 100644 --- a/src/mosquitto.c +++ b/src/mosquitto.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/mosquitto_broker_internal.h b/src/mosquitto_broker_internal.h index 6936aba2..3c60ccda 100644 --- a/src/mosquitto_broker_internal.h +++ b/src/mosquitto_broker_internal.h @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. @@ -25,6 +25,9 @@ Contributors: #ifdef WITH_WEBSOCKETS # include +# if LWS_LIBRARY_VERSION_NUMBER >= 3002000 && !defined(LWS_WITH_EXTERNAL_POLL) +# warning "libwebsockets is not compiled with LWS_WITH_EXTERNAL_POLL support. Websocket performance will be unusable." +# endif #endif #include "mosquitto_internal.h" diff --git a/src/mux.c b/src/mux.c index 672a56ec..0f7354ef 100644 --- a/src/mux.c +++ b/src/mux.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. @@ -81,9 +81,11 @@ int mux__delete(struct mosquitto *context) int mux__handle(struct mosquitto__listener_sock *listensock, int listensock_count) { #ifdef WITH_EPOLL - return mux_epoll__handle(listensock, listensock_count); + UNUSED(listensock); + UNUSED(listensock_count); + return mux_epoll__handle(); #elif defined(WITH_KQUEUE) - return mux_kqueue__handle(listensock, listensock_count); + return mux_kqueue__handle(); #else return mux_poll__handle(listensock, listensock_count); #endif diff --git a/src/mux.h b/src/mux.h index c3ad04f4..9384c839 100644 --- a/src/mux.h +++ b/src/mux.h @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. @@ -26,7 +26,7 @@ int mux_epoll__add_out(struct mosquitto *context); int mux_epoll__remove_out(struct mosquitto *context); int mux_epoll__add_in(struct mosquitto *context); int mux_epoll__delete(struct mosquitto *context); -int mux_epoll__handle(struct mosquitto__listener_sock *listensock, int listensock_count); +int mux_epoll__handle(void); int mux_epoll__cleanup(void); int mux_kqueue__init(struct mosquitto__listener_sock *listensock, int listensock_count); @@ -34,7 +34,7 @@ int mux_kqueue__add_out(struct mosquitto *context); int mux_kqueue__remove_out(struct mosquitto *context); int mux_kqueue__add_in(struct mosquitto *context); int mux_kqueue__delete(struct mosquitto *context); -int mux_kqueue__handle(struct mosquitto__listener_sock *listensock, int listensock_count); +int mux_kqueue__handle(void); int mux_kqueue__cleanup(void); int mux_poll__init(struct mosquitto__listener_sock *listensock, int listensock_count); diff --git a/src/mux_epoll.c b/src/mux_epoll.c index 6079ec98..7fdb726f 100644 --- a/src/mux_epoll.c +++ b/src/mux_epoll.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. @@ -28,6 +28,7 @@ Contributors: #include #include "mosquitto_broker_internal.h" +#include "mux.h" #include "packet_mosq.h" #include "util_mosq.h" diff --git a/src/mux_poll.c b/src/mux_poll.c index 875c4e3e..e977c209 100644 --- a/src/mux_poll.c +++ b/src/mux_poll.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. @@ -94,7 +94,7 @@ int mux_poll__init(struct mosquitto__listener_sock *listensock, int listensock_c pollfds[i].fd = INVALID_SOCKET; } - for(i=0; ievents & POLLOUT)) { if(context->pollfd_index != -1){ @@ -121,9 +121,9 @@ int mux_poll__add_out(struct mosquitto *context) pollfds[i].fd = context->sock; pollfds[i].events = POLLIN | POLLOUT; pollfds[i].revents = 0; - context->pollfd_index = i; + context->pollfd_index = (int )i; if(i > pollfd_current_max){ - pollfd_current_max = (size_t )i; + pollfd_current_max = i; } break; } @@ -148,7 +148,7 @@ int mux_poll__remove_out(struct mosquitto *context) int mux_poll__add_in(struct mosquitto *context) { - int i; + size_t i; if(context->pollfd_index != -1){ pollfds[context->pollfd_index].fd = context->sock; @@ -160,9 +160,9 @@ int mux_poll__add_in(struct mosquitto *context) pollfds[i].fd = context->sock; pollfds[i].events = POLLIN; pollfds[i].revents = 0; - context->pollfd_index = i; + context->pollfd_index = (int )i; if(i > pollfd_current_max){ - pollfd_current_max = (size_t )i; + pollfd_current_max = i; } break; } diff --git a/src/net.c b/src/net.c index b18a401b..2c7b0cf8 100644 --- a/src/net.c +++ b/src/net.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. @@ -335,14 +335,14 @@ int net__tls_server_ctx(struct mosquitto__listener *listener) }else if(!strcmp(listener->tls_version, "tlsv1.3")){ SSL_CTX_set_options(listener->ssl_ctx, SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1 | SSL_OP_NO_TLSv1_2); }else if(!strcmp(listener->tls_version, "tlsv1.2")){ - SSL_CTX_set_options(listener->ssl_ctx, SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1 | SSL_OP_NO_TLSv1_3); + SSL_CTX_set_options(listener->ssl_ctx, SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1); }else if(!strcmp(listener->tls_version, "tlsv1.1")){ - SSL_CTX_set_options(listener->ssl_ctx, SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_2 | SSL_OP_NO_TLSv1_3); + SSL_CTX_set_options(listener->ssl_ctx, SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1); #else }else if(!strcmp(listener->tls_version, "tlsv1.2")){ SSL_CTX_set_options(listener->ssl_ctx, SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1); }else if(!strcmp(listener->tls_version, "tlsv1.1")){ - SSL_CTX_set_options(listener->ssl_ctx, SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_2); + SSL_CTX_set_options(listener->ssl_ctx, SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1); #endif }else{ log__printf(NULL, MOSQ_LOG_ERR, "Error: Unsupported tls_version \"%s\".", listener->tls_version); @@ -458,11 +458,6 @@ int net__load_crl_file(struct mosquitto__listener *listener) int net__load_certificates(struct mosquitto__listener *listener) { #ifdef WITH_TLS - ENGINE *engine = NULL; -# if !defined(OPENSSL_NO_ENGINE) - UI_METHOD *ui_method; - EVP_PKEY *pkey; -# endif int rc; if(listener->require_certificate){ @@ -474,25 +469,69 @@ int net__load_certificates(struct mosquitto__listener *listener) if(rc != 1){ log__printf(NULL, MOSQ_LOG_ERR, "Error: Unable to load server certificate \"%s\". Check certfile.", listener->certfile); net__print_ssl_error(NULL); -#if !defined(OPENSSL_NO_ENGINE) - ENGINE_FINISH(engine); + return MOSQ_ERR_TLS; + } + if(listener->tls_engine == NULL){ + rc = SSL_CTX_use_PrivateKey_file(listener->ssl_ctx, listener->keyfile, SSL_FILETYPE_PEM); + if(rc != 1){ + log__printf(NULL, MOSQ_LOG_ERR, "Error: Unable to load server key file \"%s\". Check keyfile.", listener->keyfile); + net__print_ssl_error(NULL); + return MOSQ_ERR_TLS; + } + } + rc = SSL_CTX_check_private_key(listener->ssl_ctx); + if(rc != 1){ + log__printf(NULL, MOSQ_LOG_ERR, "Error: Server certificate/key are inconsistent."); + net__print_ssl_error(NULL); + return MOSQ_ERR_TLS; + } + /* Load CRLs if they exist. */ + if(listener->crlfile){ + rc = net__load_crl_file(listener); + if(rc){ + return rc; + } + } #endif + return MOSQ_ERR_SUCCESS; +} + + +static int net__load_engine(struct mosquitto__listener *listener) +{ +#if defined(WITH_TLS) && !defined(OPENSSL_NO_ENGINE) + ENGINE *engine = NULL; + UI_METHOD *ui_method; + EVP_PKEY *pkey; + + if(!listener->tls_engine){ + return MOSQ_ERR_SUCCESS; + } + + engine = ENGINE_by_id(listener->tls_engine); + if(!engine){ + log__printf(NULL, MOSQ_LOG_ERR, "Error loading %s engine\n", listener->tls_engine); + net__print_ssl_error(NULL); return MOSQ_ERR_TLS; } - if(listener->tls_engine && listener->tls_keyform == mosq_k_engine){ -#if !defined(OPENSSL_NO_ENGINE) + if(!ENGINE_init(engine)){ + log__printf(NULL, MOSQ_LOG_ERR, "Failed engine initialisation\n"); + net__print_ssl_error(NULL); + return MOSQ_ERR_TLS; + } + ENGINE_set_default(engine, ENGINE_METHOD_ALL); + + if(listener->tls_keyform == mosq_k_engine){ ui_method = net__get_ui_method(); if(listener->tls_engine_kpass_sha1){ if(!ENGINE_ctrl_cmd(engine, ENGINE_SECRET_MODE, ENGINE_SECRET_MODE_SHA, NULL, NULL, 0)){ log__printf(NULL, MOSQ_LOG_ERR, "Error: Unable to set engine secret mode sha"); net__print_ssl_error(NULL); - ENGINE_FINISH(engine); return MOSQ_ERR_TLS; } if(!ENGINE_ctrl_cmd(engine, ENGINE_PIN, 0, listener->tls_engine_kpass_sha1, NULL, 0)){ log__printf(NULL, MOSQ_LOG_ERR, "Error: Unable to set engine pin"); net__print_ssl_error(NULL); - ENGINE_FINISH(engine); return MOSQ_ERR_TLS; } ui_method = NULL; @@ -501,47 +540,17 @@ int net__load_certificates(struct mosquitto__listener *listener) if(!pkey){ log__printf(NULL, MOSQ_LOG_ERR, "Error: Unable to load engine private key file \"%s\".", listener->keyfile); net__print_ssl_error(NULL); - ENGINE_FINISH(engine); return MOSQ_ERR_TLS; } if(SSL_CTX_use_PrivateKey(listener->ssl_ctx, pkey) <= 0){ log__printf(NULL, MOSQ_LOG_ERR, "Error: Unable to use engine private key file \"%s\".", listener->keyfile); net__print_ssl_error(NULL); - ENGINE_FINISH(engine); - return MOSQ_ERR_TLS; - } -#endif - }else{ - rc = SSL_CTX_use_PrivateKey_file(listener->ssl_ctx, listener->keyfile, SSL_FILETYPE_PEM); - if(rc != 1){ - log__printf(NULL, MOSQ_LOG_ERR, "Error: Unable to load server key file \"%s\". Check keyfile.", listener->keyfile); - net__print_ssl_error(NULL); -#if !defined(OPENSSL_NO_ENGINE) - ENGINE_FINISH(engine); -#endif return MOSQ_ERR_TLS; } } - rc = SSL_CTX_check_private_key(listener->ssl_ctx); - if(rc != 1){ - log__printf(NULL, MOSQ_LOG_ERR, "Error: Server certificate/key are inconsistent."); - net__print_ssl_error(NULL); -#if !defined(OPENSSL_NO_ENGINE) - ENGINE_FINISH(engine); -#endif - return MOSQ_ERR_TLS; - } - /* Load CRLs if they exist. */ - if(listener->crlfile){ - rc = net__load_crl_file(listener); - if(rc){ -#if !defined(OPENSSL_NO_ENGINE) - ENGINE_FINISH(engine); -#endif - return rc; - } - } + ENGINE_free(engine); /* release the structural reference from ENGINE_by_id() */ #endif + return MOSQ_ERR_SUCCESS; } @@ -549,7 +558,6 @@ int net__load_certificates(struct mosquitto__listener *listener) int net__tls_load_verify(struct mosquitto__listener *listener) { #ifdef WITH_TLS - ENGINE *engine = NULL; int rc; #if OPENSSL_VERSION_NUMBER < 0x30000000L @@ -584,23 +592,8 @@ int net__tls_load_verify(struct mosquitto__listener *listener) } #endif - if(listener->tls_engine){ -#if !defined(OPENSSL_NO_ENGINE) - engine = ENGINE_by_id(listener->tls_engine); - if(!engine){ - log__printf(NULL, MOSQ_LOG_ERR, "Error loading %s engine\n", listener->tls_engine); - net__print_ssl_error(NULL); - return MOSQ_ERR_TLS; - } - if(!ENGINE_init(engine)){ - log__printf(NULL, MOSQ_LOG_ERR, "Failed engine initialisation\n"); - net__print_ssl_error(NULL); - ENGINE_free(engine); - return MOSQ_ERR_TLS; - } - ENGINE_set_default(engine, ENGINE_METHOD_ALL); - ENGINE_free(engine); /* release the structural reference from ENGINE_by_id() */ -#endif + if(net__load_engine(listener)){ + return MOSQ_ERR_TLS; } #endif return net__load_certificates(listener); @@ -608,13 +601,13 @@ int net__tls_load_verify(struct mosquitto__listener *listener) #ifndef WIN32 -static int net__bind_interface(struct mosquitto__listener *listener, mosq_sock_t sock, struct addrinfo *rp) +static int net__bind_interface(struct mosquitto__listener *listener, struct addrinfo *rp) { /* * This binds the listener sock to a network interface. * The use of SO_BINDTODEVICE requires root access, which we don't have, so instead - * use getifaddrs to find the interface addresses, and attempt to bind to - * the IP of the matching interface. + * use getifaddrs to find the interface addresses, and use IP of the + * matching interface in the later bind(). */ struct ifaddrs *ifaddr, *ifa; if(getifaddrs(&ifaddr) < 0){ @@ -725,7 +718,7 @@ static int net__socket_listen_tcp(struct mosquitto__listener *listener) #ifndef WIN32 if(listener->bind_interface){ - if(net__bind_interface(listener, sock, rp)){ + if(net__bind_interface(listener, rp)){ COMPAT_CLOSE(sock); freeaddrinfo(ainfo); mosquitto__free(listener->socks); diff --git a/src/password_mosq.c b/src/password_mosq.c index 62e06925..b8836f45 100644 --- a/src/password_mosq.c +++ b/src/password_mosq.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/password_mosq.h b/src/password_mosq.h index 4c5b20f9..3a9362a3 100644 --- a/src/password_mosq.h +++ b/src/password_mosq.h @@ -12,7 +12,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/persist.h b/src/persist.h index 80358aad..21c0e679 100644 --- a/src/persist.h +++ b/src/persist.h @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/persist_read.c b/src/persist_read.c index 8d17024f..4fedfeaa 100644 --- a/src/persist_read.c +++ b/src/persist_read.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/persist_read_v234.c b/src/persist_read_v234.c index 933da7df..7f7a64f9 100644 --- a/src/persist_read_v234.c +++ b/src/persist_read_v234.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/persist_read_v5.c b/src/persist_read_v5.c index f5e0cc57..a6e66351 100644 --- a/src/persist_read_v5.c +++ b/src/persist_read_v5.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/persist_write.c b/src/persist_write.c index d07c30b5..3ac4f4a5 100644 --- a/src/persist_write.c +++ b/src/persist_write.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/persist_write_v5.c b/src/persist_write_v5.c index 75d99ade..3d1d8e81 100644 --- a/src/persist_write_v5.c +++ b/src/persist_write_v5.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/plugin.c b/src/plugin.c index 5c40770d..d45ed78c 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/plugin_debug.c b/src/plugin_debug.c index 16bdf3d5..2e88b961 100644 --- a/src/plugin_debug.c +++ b/src/plugin_debug.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/plugin_defer.c b/src/plugin_defer.c index 1c6c7728..05f664fa 100644 --- a/src/plugin_defer.c +++ b/src/plugin_defer.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/plugin_public.c b/src/plugin_public.c index 97bda323..5df56fec 100644 --- a/src/plugin_public.c +++ b/src/plugin_public.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. @@ -91,6 +91,8 @@ int mosquitto_client_protocol(const struct mosquitto *client) if(client && client->wsi){ return mp_websockets; }else +#else + UNUSED(client); #endif { return mp_mqtt; diff --git a/src/property_broker.c b/src/property_broker.c index 4dc8a82d..1a38c204 100644 --- a/src/property_broker.c +++ b/src/property_broker.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/read_handle.c b/src/read_handle.c index dbebc1ce..416c32ab 100644 --- a/src/read_handle.c +++ b/src/read_handle.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/retain.c b/src/retain.c index 40045401..ee8ad609 100644 --- a/src/retain.c +++ b/src/retain.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. @@ -83,7 +83,10 @@ int retain__store(const char *topic, struct mosquitto_msg_store *stored, char ** assert(split_topics); HASH_FIND(hh, db.retains, split_topics[0], strlen(split_topics[0]), retainhier); - if(retainhier == NULL) return MOSQ_ERR_NOT_FOUND; + if(retainhier == NULL){ + retainhier = retain__add_hier_entry(NULL, &db.retains, split_topics[0], (uint16_t)strlen(split_topics[0])); + if(!retainhier) return MOSQ_ERR_NOMEM; + } for(i=0; split_topics[i] != NULL; i++){ slen = strlen(split_topics[i]); diff --git a/src/security.c b/src/security.c index 9bf46059..839ec31e 100644 --- a/src/security.c +++ b/src/security.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/security_default.c b/src/security_default.c index 6bbe70af..ec96e319 100644 --- a/src/security_default.c +++ b/src/security_default.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. @@ -182,6 +182,8 @@ int mosquitto_security_cleanup_default(bool reload) if(db.config->listeners[i].security_options.pid){ mosquitto_callback_unregister(db.config->listeners[i].security_options.pid, MOSQ_EVT_BASIC_AUTH, mosquitto_unpwd_check_default, NULL); + mosquitto_callback_unregister(db.config->listeners[i].security_options.pid, + MOSQ_EVT_ACL_CHECK, mosquitto_acl_check_default, NULL); mosquitto__free(db.config->listeners[i].security_options.pid); } @@ -190,6 +192,8 @@ int mosquitto_security_cleanup_default(bool reload) if(db.config->security_options.pid){ mosquitto_callback_unregister(db.config->security_options.pid, MOSQ_EVT_BASIC_AUTH, mosquitto_unpwd_check_default, NULL); + mosquitto_callback_unregister(db.config->security_options.pid, + MOSQ_EVT_ACL_CHECK, mosquitto_acl_check_default, NULL); mosquitto__free(db.config->security_options.pid); } @@ -367,7 +371,7 @@ static int mosquitto_acl_check_default(int event, void *event_data, void *userda char *local_acl; struct mosquitto__acl *acl_root; bool result; - int i; + size_t i; size_t len, tlen, clen, ulen; char *s; struct mosquitto__security_options *security_opts = NULL; diff --git a/src/send_auth.c b/src/send_auth.c index 5a42de4f..dbd0b8e8 100644 --- a/src/send_auth.c +++ b/src/send_auth.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/send_connack.c b/src/send_connack.c index b4c8e29d..a4d36f70 100644 --- a/src/send_connack.c +++ b/src/send_connack.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/send_suback.c b/src/send_suback.c index 3f4726bd..fb0b1409 100644 --- a/src/send_suback.c +++ b/src/send_suback.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/send_unsuback.c b/src/send_unsuback.c index 8e6a3880..5f59a066 100644 --- a/src/send_unsuback.c +++ b/src/send_unsuback.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/service.c b/src/service.c index 86b74c8e..2a438abd 100644 --- a/src/service.c +++ b/src/service.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/session_expiry.c b/src/session_expiry.c index 03aed565..1d2beb57 100644 --- a/src/session_expiry.c +++ b/src/session_expiry.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/signals.c b/src/signals.c index 71b58677..9938996f 100644 --- a/src/signals.c +++ b/src/signals.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/subs.c b/src/subs.c index d96cacb4..58684924 100644 --- a/src/subs.c +++ b/src/subs.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/sys_tree.c b/src/sys_tree.c index 14eb71fb..5aee42db 100644 --- a/src/sys_tree.c +++ b/src/sys_tree.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/sys_tree.h b/src/sys_tree.h index 71adec50..72f1da87 100644 --- a/src/sys_tree.h +++ b/src/sys_tree.h @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/topic_tok.c b/src/topic_tok.c index 4e16c446..340e0b6f 100644 --- a/src/topic_tok.c +++ b/src/topic_tok.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/src/websockets.c b/src/websockets.c index 66d6edd3..03dae1c9 100644 --- a/src/websockets.c +++ b/src/websockets.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. @@ -625,8 +625,6 @@ static int callback_http( HASH_FIND(hh_sock, db.contexts_by_sock, &pollargs->fd, sizeof(pollargs->fd), mosq); if(mosq){ mux__delete(mosq); - }else{ - return 1; } break; @@ -641,8 +639,6 @@ static int callback_http( }else{ mux__remove_out(mosq); } - }else{ - return 1; } break; diff --git a/src/will_delay.c b/src/will_delay.c index 2fc6eb54..aca3b931 100644 --- a/src/will_delay.c +++ b/src/will_delay.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. @@ -40,6 +40,10 @@ int will_delay__add(struct mosquitto *context) { struct will_delay_list *item; + if(context->will_delay_entry){ + return MOSQ_ERR_SUCCESS; + } + item = mosquitto__calloc(1, sizeof(struct will_delay_list)); if(!item) return MOSQ_ERR_NOMEM; diff --git a/src/xtreport.c b/src/xtreport.c index a3f99511..08750052 100644 --- a/src/xtreport.c +++ b/src/xtreport.c @@ -10,7 +10,7 @@ The Eclipse Public License is available at and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. -SPDX-License-Identifier: EPL-2.0 OR EDL-1.0 +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. diff --git a/test/broker/02-subpub-qos0-oversize-payload.py b/test/broker/02-subpub-qos0-oversize-payload.py new file mode 100755 index 00000000..4e78dacf --- /dev/null +++ b/test/broker/02-subpub-qos0-oversize-payload.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python3 + +# Test whether message size limits apply. + +from mosq_test_helper import * + +def write_config(filename, port): + with open(filename, 'w') as f: + f.write("listener %d\n" % (port)) + f.write("allow_anonymous true\n") + f.write("message_size_limit 1\n") + +def do_test(proto_ver): + rc = 1 + mid = 53 + keepalive = 60 + connect_packet = mosq_test.gen_connect("subpub-qos0-test", keepalive=keepalive, proto_ver=proto_ver) + connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver) + + subscribe_packet = mosq_test.gen_subscribe(mid, "subpub/qos0", 0, proto_ver=proto_ver) + suback_packet = mosq_test.gen_suback(mid, 0, proto_ver=proto_ver) + + connect2_packet = mosq_test.gen_connect("subpub-qos0-helper", keepalive=keepalive, proto_ver=proto_ver) + connack2_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver) + + publish_packet_ok = mosq_test.gen_publish("subpub/qos0", qos=0, payload="A", proto_ver=proto_ver) + publish_packet_bad = mosq_test.gen_publish("subpub/qos0", qos=0, payload="AB", proto_ver=proto_ver) + + port = mosq_test.get_port() + conf_file = os.path.basename(__file__).replace('.py', '.conf') + write_config(conf_file, port) + + broker = mosq_test.start_broker(filename=os.path.basename(__file__), use_conf=True, port=port) + + try: + sock = mosq_test.do_client_connect(connect_packet, connack_packet, timeout=20, port=port) + mosq_test.do_send_receive(sock, subscribe_packet, suback_packet, "suback") + + sock2 = mosq_test.do_client_connect(connect2_packet, connack2_packet, timeout=20, port=port) + sock2.send(publish_packet_ok) + mosq_test.expect_packet(sock, "publish 1", publish_packet_ok) + + # Check all is still well on the publishing client + mosq_test.do_ping(sock2) + + sock2.send(publish_packet_bad) + + # Check all is still well on the publishing client + mosq_test.do_ping(sock2) + + # The subscribing client shouldn't have received a PUBLISH + mosq_test.do_ping(sock) + rc = 0 + + sock.close() + except SyntaxError: + raise + except TypeError: + raise + except mosq_test.TestError: + pass + finally: + os.remove(conf_file) + broker.terminate() + broker.wait() + (stdo, stde) = broker.communicate() + if rc: + print(stde.decode('utf-8')) + print("proto_ver=%d" % (proto_ver)) + exit(rc) + + +do_test(proto_ver=4) +do_test(proto_ver=5) +exit(0) diff --git a/test/broker/02-subpub-qos0-queued-bytes.py b/test/broker/02-subpub-qos0-queued-bytes.py new file mode 100755 index 00000000..7ca08e80 --- /dev/null +++ b/test/broker/02-subpub-qos0-queued-bytes.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 + +from mosq_test_helper import * + +def write_config(filename, port): + with open(filename, 'w') as f: + f.write("listener %d\n" % (port)) + f.write("allow_anonymous true\n") + f.write("max_inflight_messages 20\n") + f.write("max_inflight_bytes 1000000\n") + f.write("max_queued_messages 20\n") + f.write("max_queued_bytes 1000000\n") + +def do_test(proto_ver): + rc = 1 + keepalive = 60 + connect_packet = mosq_test.gen_connect("subpub-qos0-bytes", keepalive=keepalive, proto_ver=proto_ver) + connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver) + + connect_packet_helper = mosq_test.gen_connect("qos0-bytes-helper", keepalive=keepalive, proto_ver=proto_ver) + + mid = 1 + subscribe_packet = mosq_test.gen_subscribe(mid, "subpub/qos0/queued/bytes", 1, proto_ver=proto_ver) + suback_packet = mosq_test.gen_suback(mid, 1, proto_ver=proto_ver) + + publish_packet0 = mosq_test.gen_publish("subpub/qos0/queued/bytes", qos=0, payload="message", proto_ver=proto_ver) + + + port = mosq_test.get_port() + conf_file = os.path.basename(__file__).replace('.py', '.conf') + write_config(conf_file, port) + broker = mosq_test.start_broker(filename=os.path.basename(__file__), use_conf=True, port=port) + + try: + sock = mosq_test.do_client_connect(connect_packet, connack_packet, timeout=4, port=port, connack_error="connack 1") + + mosq_test.do_send_receive(sock, subscribe_packet, suback_packet, "suback") + + helper = mosq_test.do_client_connect(connect_packet_helper, connack_packet, timeout=4, port=port, connack_error="connack helper") + + helper.send(publish_packet0) + mosq_test.expect_packet(sock, "publish0", publish_packet0) + rc = 0 + + sock.close() + except mosq_test.TestError: + pass + finally: + os.remove(conf_file) + broker.terminate() + broker.wait() + (stdo, stde) = broker.communicate() + if rc: + print(stde.decode('utf-8')) + print("proto_ver=%d" % (proto_ver)) + exit(rc) + + +do_test(proto_ver=4) +do_test(proto_ver=5) +exit(0) diff --git a/test/broker/02-subpub-qos0-topic-alias-unknown.py b/test/broker/02-subpub-qos0-topic-alias-unknown.py index cdce33ce..62227127 100755 --- a/test/broker/02-subpub-qos0-topic-alias-unknown.py +++ b/test/broker/02-subpub-qos0-topic-alias-unknown.py @@ -14,7 +14,7 @@ def do_test(): props = mqtt5_props.gen_uint16_prop(mqtt5_props.PROP_TOPIC_ALIAS, 3) publish1_packet = mosq_test.gen_publish("", qos=0, payload="message", proto_ver=5, properties=props) - disconnect_packet = mosq_test.gen_disconnect(reason_code=148, proto_ver=5) + disconnect_packet = mosq_test.gen_disconnect(reason_code=mqtt5_rc.MQTT_RC_PROTOCOL_ERROR, proto_ver=5) port = mosq_test.get_port() broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port) diff --git a/test/broker/02-subpub-qos1-oversize-payload.py b/test/broker/02-subpub-qos1-oversize-payload.py new file mode 100755 index 00000000..17878004 --- /dev/null +++ b/test/broker/02-subpub-qos1-oversize-payload.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python3 + +# Test whether message size limits apply. + +from mosq_test_helper import * + +def write_config(filename, port): + with open(filename, 'w') as f: + f.write("listener %d\n" % (port)) + f.write("allow_anonymous true\n") + f.write("message_size_limit 1\n") + +def do_test(proto_ver): + rc = 1 + mid = 53 + keepalive = 60 + connect_packet = mosq_test.gen_connect("subpub-qos1-test", keepalive=keepalive, proto_ver=proto_ver) + connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver) + + subscribe_packet = mosq_test.gen_subscribe(mid, "subpub/qos1", 1, proto_ver=proto_ver) + suback_packet = mosq_test.gen_suback(mid, 1, proto_ver=proto_ver) + + connect2_packet = mosq_test.gen_connect("subpub-qos1-helper", keepalive=keepalive, proto_ver=proto_ver) + connack2_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver) + + mid = 1 + publish_packet_ok = mosq_test.gen_publish("subpub/qos1", mid=mid, qos=1, payload="A", proto_ver=proto_ver) + puback_packet_ok = mosq_test.gen_puback(mid=mid, proto_ver=proto_ver) + + mid = 2 + publish_packet_bad = mosq_test.gen_publish("subpub/qos1", mid=mid, qos=1, payload="AB", proto_ver=proto_ver) + if proto_ver == 5: + puback_packet_bad = mosq_test.gen_puback(reason_code=mqtt5_rc.MQTT_RC_PACKET_TOO_LARGE, mid=mid, proto_ver=proto_ver) + else: + puback_packet_bad = mosq_test.gen_puback(mid=mid, proto_ver=proto_ver) + + port = mosq_test.get_port() + conf_file = os.path.basename(__file__).replace('.py', '.conf') + write_config(conf_file, port) + + broker = mosq_test.start_broker(filename=os.path.basename(__file__), use_conf=True, port=port) + + try: + sock = mosq_test.do_client_connect(connect_packet, connack_packet, timeout=20, port=port) + mosq_test.do_send_receive(sock, subscribe_packet, suback_packet, "suback") + + sock2 = mosq_test.do_client_connect(connect2_packet, connack2_packet, timeout=20, port=port) + mosq_test.do_send_receive(sock2, publish_packet_ok, puback_packet_ok, "puback 1") + mosq_test.expect_packet(sock, "publish 1", publish_packet_ok) + sock.send(puback_packet_ok) + + # Check all is still well on the publishing client + mosq_test.do_ping(sock2) + + mosq_test.do_send_receive(sock2, publish_packet_bad, puback_packet_bad, "puback 2") + + # The subscribing client shouldn't have received a PUBLISH + mosq_test.do_ping(sock) + rc = 0 + + sock.close() + except SyntaxError: + raise + except TypeError: + raise + except mosq_test.TestError: + pass + finally: + os.remove(conf_file) + broker.terminate() + broker.wait() + (stdo, stde) = broker.communicate() + if rc: + print(stde.decode('utf-8')) + print("proto_ver=%d" % (proto_ver)) + exit(rc) + + +do_test(proto_ver=4) +do_test(proto_ver=5) +exit(0) diff --git a/test/broker/03-publish-b2c-timeout-qos1.py b/test/broker/03-publish-b2c-timeout-qos1.py deleted file mode 100755 index a30d1af8..00000000 --- a/test/broker/03-publish-b2c-timeout-qos1.py +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/env python3 - -# Test whether a SUBSCRIBE to a topic with QoS 2 results in the correct SUBACK packet. - -from mosq_test_helper import * - - -def helper(port): - connect_packet = mosq_test.gen_connect("test-helper", keepalive=60) - connack_packet = mosq_test.gen_connack(rc=0) - - mid = 128 - publish_packet = mosq_test.gen_publish("qos1/timeout/test", qos=1, mid=mid, payload="timeout-message") - puback_packet = mosq_test.gen_puback(mid) - - sock = mosq_test.do_client_connect(connect_packet, connack_packet, connack_error="helper connack") - mosq_test.do_send_receive(sock, publish_packet, puback_packet, "helper puback") - sock.close() - - -def do_test(proto_ver): - rc = 1 - mid = 3265 - keepalive = 60 - connect_packet = mosq_test.gen_connect("pub-qos1-timeout-test", keepalive=keepalive, proto_ver=proto_ver) - connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver) - - subscribe_packet = mosq_test.gen_subscribe(mid, "qos1/timeout/test", 1, proto_ver=proto_ver) - suback_packet = mosq_test.gen_suback(mid, 1, proto_ver=proto_ver) - - mid = 1 - publish_packet = mosq_test.gen_publish("qos1/timeout/test", qos=1, mid=mid, payload="timeout-message", proto_ver=proto_ver) - publish_dup_packet = mosq_test.gen_publish("qos1/timeout/test", qos=1, mid=mid, payload="timeout-message", dup=True, proto_ver=proto_ver) - puback_packet = mosq_test.gen_puback(mid, proto_ver=proto_ver) - - port = mosq_test.get_port() - broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port) - - try: - sock = mosq_test.do_client_connect(connect_packet, connack_packet) - mosq_test.do_send_receive(sock, subscribe_packet, suback_packet, "suback") - - helper(port) - # Should have now received a publish command - - mosq_test.expect_packet(sock, "publish", publish_packet) - # Wait for longer than 5 seconds to get republish with dup set - # This is covered by the 8 second timeout - - mosq_test.expect_packet(sock, "dup publish", publish_dup_packet) - sock.send(puback_packet) - rc = 0 - - sock.close() - except mosq_test.TestError: - pass - finally: - broker.terminate() - broker.wait() - (stdo, stde) = broker.communicate() - if rc: - print(stde.decode('utf-8')) - print("proto_ver=%d" % (proto_ver)) - exit(rc) - - -do_test(proto_ver=4) -do_test(proto_ver=5) - -exit(0) - diff --git a/test/broker/03-publish-b2c-timeout-qos2.py b/test/broker/03-publish-b2c-timeout-qos2.py deleted file mode 100755 index 6b80bf18..00000000 --- a/test/broker/03-publish-b2c-timeout-qos2.py +++ /dev/null @@ -1,81 +0,0 @@ -#!/usr/bin/env python3 - -# Test whether a SUBSCRIBE to a topic with QoS 2 results in the correct SUBACK packet. - -from mosq_test_helper import * - - -def helper(port): - connect_packet = mosq_test.gen_connect("test-helper", keepalive=60) - connack_packet = mosq_test.gen_connack(rc=0) - - mid = 312 - publish_packet = mosq_test.gen_publish("qos2/timeout/test", qos=2, mid=mid, payload="timeout-message") - pubrec_packet = mosq_test.gen_pubrec(mid) - pubrel_packet = mosq_test.gen_pubrel(mid) - pubcomp_packet = mosq_test.gen_pubcomp(mid) - - sock = mosq_test.do_client_connect(connect_packet, connack_packet, connack_error="helper connack") - mosq_test.do_send_receive(sock, publish_packet, pubrec_packet, "helper pubrec") - mosq_test.do_send_receive(sock, pubrel_packet, pubcomp_packet, "helper pubcomp") - sock.close() - - -def do_test(proto_ver): - rc = 1 - mid = 3265 - keepalive = 60 - connect_packet = mosq_test.gen_connect("pub-qo2-timeout-test", keepalive=keepalive, proto_ver=proto_ver) - connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver) - - subscribe_packet = mosq_test.gen_subscribe(mid, "qos2/timeout/test", 2, proto_ver=proto_ver) - suback_packet = mosq_test.gen_suback(mid, 2, proto_ver=proto_ver) - - mid = 1 - publish_packet = mosq_test.gen_publish("qos2/timeout/test", qos=2, mid=mid, payload="timeout-message", proto_ver=proto_ver) - publish_dup_packet = mosq_test.gen_publish("qos2/timeout/test", qos=2, mid=mid, payload="timeout-message", dup=True, proto_ver=proto_ver) - pubrec_packet = mosq_test.gen_pubrec(mid, proto_ver=proto_ver) - pubrel_packet = mosq_test.gen_pubrel(mid, proto_ver=proto_ver) - pubcomp_packet = mosq_test.gen_pubcomp(mid, proto_ver=proto_ver) - - port = mosq_test.get_port() - broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port) - - try: - sock = mosq_test.do_client_connect(connect_packet, connack_packet) - mosq_test.do_send_receive(sock, subscribe_packet, suback_packet, "suback") - - helper(port) - # Should have now received a publish command - - mosq_test.expect_packet(sock, "publish", publish_packet) - # Wait for longer than 5 seconds to get republish with dup set - # This is covered by the 8 second timeout - - mosq_test.expect_packet(sock, "dup publish", publish_dup_packet) - mosq_test.do_send_receive(sock, pubrec_packet, pubrel_packet, "pubrel") - - # Wait for longer than 5 seconds to get republish with dup set - # This is covered by the 8 second timeout - - mosq_test.expect_packet(sock, "dup pubrel", pubrel_packet) - sock.send(pubcomp_packet) - rc = 0 - - sock.close() - except mosq_test.TestError: - pass - finally: - broker.terminate() - broker.wait() - (stdo, stde) = broker.communicate() - if rc: - print(stde.decode('utf-8')) - print("proto_ver=%d" % (proto_ver)) - exit(rc) - - -do_test(proto_ver=4) -do_test(proto_ver=5) -exit(0) - diff --git a/test/broker/03-publish-c2b-timeout-qos2.py b/test/broker/03-publish-c2b-timeout-qos2.py deleted file mode 100755 index 54538fe2..00000000 --- a/test/broker/03-publish-c2b-timeout-qos2.py +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env python3 - -# Test whether a PUBLISH to a topic with QoS 2 results in the correct packet -# flow. This test introduces delays into the flow in order to force the broker -# to send duplicate PUBREC and PUBCOMP messages. - -from mosq_test_helper import * - - -def do_test(port): - rc = 1 - keepalive = 600 - connect_packet = mosq_test.gen_connect("pub-qos2-timeout-test", keepalive=keepalive, proto_ver=proto_ver) - connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver) - - mid = 1926 - publish_packet = mosq_test.gen_publish("pub/qos2/test", qos=2, mid=mid, payload="timeout-message", proto_ver=proto_ver) - pubrec_packet = mosq_test.gen_pubrec(mid, proto_ver=proto_ver) - pubrel_packet = mosq_test.gen_pubrel(mid, proto_ver=proto_ver) - pubcomp_packet = mosq_test.gen_pubcomp(mid, proto_ver=proto_ver) - - port = mosq_test.get_port() - broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port) - - try: - sock = mosq_test.do_client_connect(connect_packet, connack_packet) - mosq_test.do_send_receive(sock, publish_packet, pubrec_packet, "pubrec") - - # Timeout is 8 seconds which means the broker should repeat the PUBREC. - - mosq_test.expect_packet(sock, "pubrec", pubrec_packet) - mosq_test.do_send_receive(sock, pubrel_packet, pubcomp_packet, "pubcomp") - - rc = 0 - - sock.close() - except mosq_test.TestError: - pass - finally: - broker.terminate() - broker.wait() - (stdo, stde) = broker.communicate() - if rc: - print(stde.decode('utf-8')) - print("proto_ver=%d" % (proto_ver)) - exit(rc) - - -do_test(proto_ver=4) -do_test(proto_ver=5) -exit(0) - diff --git a/test/broker/07-will-oversize-payload.py b/test/broker/07-will-oversize-payload.py new file mode 100755 index 00000000..319ec509 --- /dev/null +++ b/test/broker/07-will-oversize-payload.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python3 + +# Test whether a client will that is too large is handled + +from mosq_test_helper import * + +def write_config(filename, port): + with open(filename, 'w') as f: + f.write("listener %d\n" % (port)) + f.write("allow_anonymous true\n") + f.write("message_size_limit 1\n") + +def do_test(proto_ver, clean_session): + rc = 1 + mid = 53 + keepalive = 60 + connect_packet = mosq_test.gen_connect("will-test", keepalive=keepalive, proto_ver=proto_ver) + connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver) + + connect_packet_ok = mosq_test.gen_connect("test-helper", keepalive=keepalive, will_topic="will/qos0/test", will_payload=b"A", clean_session=clean_session, proto_ver=proto_ver, session_expiry=60) + connack_packet_ok = mosq_test.gen_connack(rc=0, proto_ver=proto_ver) + + connect_packet_bad = mosq_test.gen_connect("test-helper", keepalive=keepalive, will_topic="will/qos0/test", will_payload=b"AB", clean_session=clean_session, proto_ver=proto_ver, session_expiry=60) + if proto_ver == 5: + connack_packet_bad = mosq_test.gen_connack(rc=mqtt5_rc.MQTT_RC_PACKET_TOO_LARGE, proto_ver=proto_ver, property_helper=False) + else: + connack_packet_bad = mosq_test.gen_connack(rc=5, proto_ver=proto_ver) + + subscribe_packet = mosq_test.gen_subscribe(mid, "will/qos0/test", 0, proto_ver=proto_ver) + suback_packet = mosq_test.gen_suback(mid, 0, proto_ver=proto_ver) + + publish_packet = mosq_test.gen_publish("will/qos0/test", qos=0, payload="A", proto_ver=proto_ver) + + port = mosq_test.get_port() + conf_file = os.path.basename(__file__).replace('.py', '.conf') + write_config(conf_file, port) + + broker = mosq_test.start_broker(filename=os.path.basename(__file__), use_conf=True, port=port) + + try: + sock = mosq_test.do_client_connect(connect_packet, connack_packet, timeout=5, port=port) + mosq_test.do_send_receive(sock, subscribe_packet, suback_packet, "suback") + + sock2 = mosq_test.do_client_connect(connect_packet_bad, connack_packet_bad, port=port, timeout=5) + sock2.close() + + sock2 = mosq_test.do_client_connect(connect_packet_ok, connack_packet_ok, port=port, timeout=5) + sock2.close() + + mosq_test.expect_packet(sock, "publish", publish_packet) + # Check there are no more messages + mosq_test.do_ping(sock) + rc = 0 + + sock.close() + except mosq_test.TestError: + pass + finally: + os.remove(conf_file) + broker.terminate() + broker.wait() + (stdo, stde) = broker.communicate() + if rc: + print(stde.decode('utf-8')) + exit(rc) + +do_test(4, True) +do_test(4, False) +do_test(5, True) +do_test(5, False) +exit(0) diff --git a/test/broker/Makefile b/test/broker/Makefile index 89fd91f2..d74b311b 100644 --- a/test/broker/Makefile +++ b/test/broker/Makefile @@ -44,6 +44,8 @@ test : test-compile 01 02 03 04 05 06 07 08 09 10 11 12 13 14 ./02-shared-qos0-v5.py ./02-subhier-crash.py ./02-subpub-qos0-long-topic.py + ./02-subpub-qos0-oversize-payload.py + ./02-subpub-qos0-queued-bytes.py ./02-subpub-qos0-retain-as-publish.py ./02-subpub-qos0-send-retain.py ./02-subpub-qos0-subscription-id.py @@ -56,6 +58,7 @@ test : test-compile 01 02 03 04 05 06 07 08 09 10 11 12 13 14 ./02-subpub-qos1-message-expiry-will.py ./02-subpub-qos1-message-expiry.py ./02-subpub-qos1-nolocal.py + ./02-subpub-qos1-oversize-payload.py ./02-subpub-qos1.py ./02-subpub-qos2-1322.py ./02-subpub-qos2-bad-puback-1.py @@ -142,6 +145,7 @@ test : test-compile 01 02 03 04 05 06 07 08 09 10 11 12 13 14 ./07-will-no-flag.py ./07-will-null-topic.py ./07-will-null.py + ./07-will-oversize-payload.py ./07-will-properties.py ./07-will-qos0.py ./07-will-reconnect-1273.py diff --git a/test/broker/test.py b/test/broker/test.py index c0b60c17..2cf8a2b9 100755 --- a/test/broker/test.py +++ b/test/broker/test.py @@ -27,6 +27,8 @@ tests = [ (1, './02-shared-qos0-v5.py'), (1, './02-subhier-crash.py'), (1, './02-subpub-qos0-long-topic.py'), + (1, './02-subpub-qos0-oversize-payload.py'), + (1, './02-subpub-qos0-queued-bytes.py'), (1, './02-subpub-qos0-retain-as-publish.py'), (1, './02-subpub-qos0-send-retain.py'), (1, './02-subpub-qos0-subscription-id.py'), @@ -39,6 +41,7 @@ tests = [ (1, './02-subpub-qos1-message-expiry-will.py'), (1, './02-subpub-qos1-message-expiry.py'), (1, './02-subpub-qos1-nolocal.py'), + (1, './02-subpub-qos1-oversize-payload.py'), (1, './02-subpub-qos1.py'), (1, './02-subpub-qos2-1322.py'), (1, './02-subpub-qos2-bad-puback-1.py'), @@ -121,6 +124,7 @@ tests = [ (1, './07-will-no-flag.py'), (1, './07-will-null-topic.py'), (1, './07-will-null.py'), + (1, './07-will-oversize-payload.py'), (1, './07-will-properties.py'), (1, './07-will-qos0.py'), (1, './07-will-reconnect-1273.py'), diff --git a/test/mosq_test.py b/test/mosq_test.py index 901ece55..52dcca0c 100644 --- a/test/mosq_test.py +++ b/test/mosq_test.py @@ -284,12 +284,20 @@ def to_string(packet): return s elif cmd == 0x40: # PUBACK - (cmd, rl, mid) = struct.unpack('!BBH', packet) - return "PUBACK, rl="+str(rl)+", mid="+str(mid) + if len(packet) == 5: + (cmd, rl, mid, reason_code) = struct.unpack('!BBHB', packet) + return "PUBACK, rl="+str(rl)+", mid="+str(mid)+", reason_code="+str(reason_code) + else: + (cmd, rl, mid) = struct.unpack('!BBH', packet) + return "PUBACK, rl="+str(rl)+", mid="+str(mid) elif cmd == 0x50: # PUBREC - (cmd, rl, mid) = struct.unpack('!BBH', packet) - return "PUBREC, rl="+str(rl)+", mid="+str(mid) + if len(packet) == 5: + (cmd, rl, mid, reason_code) = struct.unpack('!BBHB', packet) + return "PUBREC, rl="+str(rl)+", mid="+str(mid)+", reason_code="+str(reason_code) + else: + (cmd, rl, mid) = struct.unpack('!BBH', packet) + return "PUBREC, rl="+str(rl)+", mid="+str(mid) elif cmd == 0x60: # PUBREL dup = (packet0 & 0x08)>>3 @@ -353,8 +361,12 @@ def to_string(packet): return "PINGRESP, rl="+str(rl) elif cmd == 0xE0: # DISCONNECT - (cmd, rl) = struct.unpack('!BB', packet) - return "DISCONNECT, rl="+str(rl) + if len(packet) == 3: + (cmd, rl, reason_code) = struct.unpack('!BBB', packet) + return "DISCONNECT, rl="+str(rl)+", reason_code="+str(reason_code) + else: + (cmd, rl) = struct.unpack('!BB', packet) + return "DISCONNECT, rl="+str(rl) elif cmd == 0xF0: # AUTH (cmd, rl) = struct.unpack('!BB', packet) diff --git a/test/unit/bridge_topic_test.c b/test/unit/bridge_topic_test.c index 14992af8..03907ba4 100644 --- a/test/unit/bridge_topic_test.c +++ b/test/unit/bridge_topic_test.c @@ -101,6 +101,9 @@ int main(int argc, char *argv[]) { unsigned int fails; + UNUSED(argc); + UNUSED(argv); + if(CU_initialize_registry() != CUE_SUCCESS){ printf("Error initializing CUnit registry.\n"); return 1; diff --git a/test/unit/persist_read_stubs.c b/test/unit/persist_read_stubs.c index afe75986..62b03567 100644 --- a/test/unit/persist_read_stubs.c +++ b/test/unit/persist_read_stubs.c @@ -18,6 +18,8 @@ struct mosquitto *context__init(mosq_sock_t sock) { struct mosquitto *m; + UNUSED(sock); + m = mosquitto__calloc(1, sizeof(struct mosquitto)); if(m){ m->msgs_in.inflight_maximum = 20; @@ -50,6 +52,8 @@ int db__message_store(const struct mosquitto *source, struct mosquitto_msg_store { int rc = MOSQ_ERR_SUCCESS; + UNUSED(origin); + if(source && source->id){ stored->source_id = mosquitto__strdup(source->id); }else{ @@ -98,6 +102,10 @@ error: int log__printf(struct mosquitto *mosq, unsigned int priority, const char *fmt, ...) { + UNUSED(mosq); + UNUSED(priority); + UNUSED(fmt); + return 0; } @@ -108,27 +116,45 @@ time_t mosquitto_time(void) int net__socket_close(struct mosquitto *mosq) { + UNUSED(mosq); + return MOSQ_ERR_SUCCESS; } int send__pingreq(struct mosquitto *mosq) { + UNUSED(mosq); + return MOSQ_ERR_SUCCESS; } int mosquitto_acl_check(struct mosquitto *context, const char *topic, uint32_t payloadlen, void* payload, uint8_t qos, bool retain, int access) { + UNUSED(context); + UNUSED(topic); + UNUSED(payloadlen); + UNUSED(payload); + UNUSED(qos); + UNUSED(retain); + UNUSED(access); + return MOSQ_ERR_SUCCESS; } int acl__find_acls(struct mosquitto *context) { + UNUSED(context); + return MOSQ_ERR_SUCCESS; } int sub__add(struct mosquitto *context, const char *sub, uint8_t qos, uint32_t identifier, int options, struct mosquitto__subhier **root) { + UNUSED(context); + UNUSED(options); + UNUSED(root); + last_sub = strdup(sub); last_qos = qos; last_identifier = identifier; @@ -138,11 +164,21 @@ int sub__add(struct mosquitto *context, const char *sub, uint8_t qos, uint32_t i int db__message_insert(struct mosquitto *context, uint16_t mid, enum mosquitto_msg_direction dir, uint8_t qos, bool retain, struct mosquitto_msg_store *stored, mosquitto_property *properties, bool update) { + UNUSED(context); + UNUSED(mid); + UNUSED(dir); + UNUSED(qos); + UNUSED(retain); + UNUSED(stored); + UNUSED(properties); + UNUSED(update); + return MOSQ_ERR_SUCCESS; } void db__msg_store_ref_dec(struct mosquitto_msg_store **store) { + UNUSED(store); } void db__msg_store_ref_inc(struct mosquitto_msg_store *store) diff --git a/test/unit/persist_read_test.c b/test/unit/persist_read_test.c index 0055ba94..2bac2d44 100644 --- a/test/unit/persist_read_test.c +++ b/test/unit/persist_read_test.c @@ -832,6 +832,9 @@ int main(int argc, char *argv[]) { unsigned int fails; + UNUSED(argc); + UNUSED(argv); + if(CU_initialize_registry() != CUE_SUCCESS){ printf("Error initializing CUnit registry.\n"); return 1; diff --git a/test/unit/persist_write_stubs.c b/test/unit/persist_write_stubs.c index 59eb9d6c..173cd4ea 100644 --- a/test/unit/persist_write_stubs.c +++ b/test/unit/persist_write_stubs.c @@ -15,11 +15,17 @@ extern int last_qos; struct mosquitto *context__init(mosq_sock_t sock) { + UNUSED(sock); + return mosquitto__calloc(1, sizeof(struct mosquitto)); } int log__printf(struct mosquitto *mosq, unsigned int priority, const char *fmt, ...) { + UNUSED(mosq); + UNUSED(priority); + UNUSED(fmt); + return 0; } @@ -30,41 +36,80 @@ time_t mosquitto_time(void) int net__socket_close(struct mosquitto *mosq) { + UNUSED(mosq); + return MOSQ_ERR_SUCCESS; } int send__pingreq(struct mosquitto *mosq) { + UNUSED(mosq); + return MOSQ_ERR_SUCCESS; } int mosquitto_acl_check(struct mosquitto *context, const char *topic, uint32_t payloadlen, void* payload, uint8_t qos, bool retain, int access) { + UNUSED(context); + UNUSED(topic); + UNUSED(payloadlen); + UNUSED(payload); + UNUSED(qos); + UNUSED(retain); + UNUSED(access); + return MOSQ_ERR_SUCCESS; } int acl__find_acls(struct mosquitto *context) { + UNUSED(context); + return MOSQ_ERR_SUCCESS; } int send__publish(struct mosquitto *mosq, uint16_t mid, const char *topic, uint32_t payloadlen, const void *payload, uint8_t qos, bool retain, bool dup, const mosquitto_property *cmsg_props, const mosquitto_property *store_props, uint32_t expiry_interval) { + UNUSED(mosq); + UNUSED(mid); + UNUSED(topic); + UNUSED(payloadlen); + UNUSED(payload); + UNUSED(qos); + UNUSED(retain); + UNUSED(dup); + UNUSED(cmsg_props); + UNUSED(store_props); + UNUSED(expiry_interval); + return MOSQ_ERR_SUCCESS; } int send__pubcomp(struct mosquitto *mosq, uint16_t mid, const mosquitto_property *properties) { + UNUSED(mosq); + UNUSED(mid); + UNUSED(properties); + return MOSQ_ERR_SUCCESS; } int send__pubrec(struct mosquitto *mosq, uint16_t mid, uint8_t reason_code, const mosquitto_property *properties) { + UNUSED(mosq); + UNUSED(mid); + UNUSED(reason_code); + UNUSED(properties); + return MOSQ_ERR_SUCCESS; } int send__pubrel(struct mosquitto *mosq, uint16_t mid, const mosquitto_property *properties) { + UNUSED(mosq); + UNUSED(mid); + UNUSED(properties); + return MOSQ_ERR_SUCCESS; } diff --git a/test/unit/persist_write_test.c b/test/unit/persist_write_test.c index 099027b7..abdc455f 100644 --- a/test/unit/persist_write_test.c +++ b/test/unit/persist_write_test.c @@ -349,6 +349,9 @@ int main(int argc, char *argv[]) CU_pSuite test_suite = NULL; unsigned int fails; + UNUSED(argc); + UNUSED(argv); + if(CU_initialize_registry() != CUE_SUCCESS){ printf("Error initializing CUnit registry.\n"); return 1; diff --git a/test/unit/property_write.c b/test/unit/property_write.c index bbda06d4..ad037316 100644 --- a/test/unit/property_write.c +++ b/test/unit/property_write.c @@ -317,6 +317,8 @@ static void varint_prop_write_helper( memset(&packet, 0, sizeof(struct mosquitto__packet)); packet.remaining_length = property__get_length_all(&property)+1; + CU_ASSERT_EQUAL(packet.remaining_length, remaining_length); + packet.packet_length = packet.remaining_length+10; packet.payload = calloc(packet.remaining_length+10, 1); diff --git a/test/unit/stubs.c b/test/unit/stubs.c index 897cd77b..23fa36fd 100644 --- a/test/unit/stubs.c +++ b/test/unit/stubs.c @@ -1,3 +1,5 @@ +#include "config.h" + #include #include @@ -7,6 +9,10 @@ struct mosquitto_db{ int log__printf(struct mosquitto *mosq, unsigned int priority, const char *fmt, ...) { + UNUSED(mosq); + UNUSED(priority); + UNUSED(fmt); + return 0; } @@ -17,11 +23,16 @@ time_t mosquitto_time(void) int net__socket_close(struct mosquitto_db *db, struct mosquitto *mosq) { + UNUSED(db); + UNUSED(mosq); + return MOSQ_ERR_SUCCESS; } int send__pingreq(struct mosquitto *mosq) { + UNUSED(mosq); + return MOSQ_ERR_SUCCESS; } diff --git a/test/unit/subs_stubs.c b/test/unit/subs_stubs.c index b7563745..0815e4a9 100644 --- a/test/unit/subs_stubs.c +++ b/test/unit/subs_stubs.c @@ -37,6 +37,10 @@ void db__msg_store_ref_inc(struct mosquitto_msg_store *store) int log__printf(struct mosquitto *mosq, unsigned int priority, const char *fmt, ...) { + UNUSED(mosq); + UNUSED(priority); + UNUSED(fmt); + return 0; } @@ -70,26 +74,59 @@ int acl__find_acls(struct mosquitto *context) int send__publish(struct mosquitto *mosq, uint16_t mid, const char *topic, uint32_t payloadlen, const void *payload, uint8_t qos, bool retain, bool dup, const mosquitto_property *cmsg_props, const mosquitto_property *store_props, uint32_t expiry_interval) { + UNUSED(mosq); + UNUSED(mid); + UNUSED(topic); + UNUSED(payloadlen); + UNUSED(payload); + UNUSED(qos); + UNUSED(retain); + UNUSED(dup); + UNUSED(cmsg_props); + UNUSED(store_props); + UNUSED(expiry_interval); + return MOSQ_ERR_SUCCESS; } int send__pubcomp(struct mosquitto *mosq, uint16_t mid, const mosquitto_property *properties) { + UNUSED(mosq); + UNUSED(mid); + UNUSED(properties); + return MOSQ_ERR_SUCCESS; } int send__pubrec(struct mosquitto *mosq, uint16_t mid, uint8_t reason_code, const mosquitto_property *properties) { + UNUSED(mosq); + UNUSED(mid); + UNUSED(reason_code); + UNUSED(properties); + return MOSQ_ERR_SUCCESS; } int send__pubrel(struct mosquitto *mosq, uint16_t mid, const mosquitto_property *properties) { + UNUSED(mosq); + UNUSED(mid); + UNUSED(properties); + return MOSQ_ERR_SUCCESS; } int mosquitto_acl_check(struct mosquitto *context, const char *topic, uint32_t payloadlen, void* payload, uint8_t qos, bool retain, int access) { + UNUSED(context); + UNUSED(topic); + UNUSED(payloadlen); + UNUSED(payload); + UNUSED(qos); + UNUSED(retain); + UNUSED(access); + return MOSQ_ERR_SUCCESS; } @@ -97,16 +134,24 @@ uint16_t mosquitto__mid_generate(struct mosquitto *mosq) { static uint16_t mid = 1; + UNUSED(mosq); + return ++mid; } int mosquitto_property_add_varint(mosquitto_property **proplist, int identifier, uint32_t value) { + UNUSED(proplist); + UNUSED(identifier); + UNUSED(value); + return MOSQ_ERR_SUCCESS; } int persist__backup(bool shutdown) { + UNUSED(shutdown); + return MOSQ_ERR_SUCCESS; } @@ -117,6 +162,7 @@ int persist__restore(void) void mosquitto_property_free_all(mosquitto_property **properties) { + UNUSED(properties); } int retain__init(void) @@ -126,15 +172,25 @@ int retain__init(void) void retain__clean(struct mosquitto__retainhier **retainhier) { + UNUSED(retainhier); } int retain__queue(struct mosquitto *context, const char *sub, uint8_t sub_qos, uint32_t subscription_identifier) { + UNUSED(context); + UNUSED(sub); + UNUSED(sub_qos); + UNUSED(subscription_identifier); + return MOSQ_ERR_SUCCESS; } int retain__store(const char *topic, struct mosquitto_msg_store *stored, char **split_topics) { + UNUSED(topic); + UNUSED(stored); + UNUSED(split_topics); + return MOSQ_ERR_SUCCESS; } diff --git a/test/unit/subs_test.c b/test/unit/subs_test.c index 527f4991..a596e8bc 100644 --- a/test/unit/subs_test.c +++ b/test/unit/subs_test.c @@ -88,6 +88,9 @@ int main(int argc, char *argv[]) CU_pSuite test_suite = NULL; unsigned int fails; + UNUSED(argc); + UNUSED(argv); + if(CU_initialize_registry() != CUE_SUCCESS){ printf("Error initializing CUnit registry.\n"); return 1; diff --git a/test/unit/test.c b/test/unit/test.c index 97258c49..c59a7461 100644 --- a/test/unit/test.c +++ b/test/unit/test.c @@ -18,6 +18,9 @@ int main(int argc, char *argv[]) { unsigned int fails; + UNUSED(argc); + UNUSED(argv); + if(CU_initialize_registry() != CUE_SUCCESS){ printf("Error initializing CUnit registry.\n"); return 1; diff --git a/www/pages/documentation.md b/www/pages/documentation.md index 49b786a3..cc728dc8 100644 --- a/www/pages/documentation.md +++ b/www/pages/documentation.md @@ -26,8 +26,9 @@ # Other -* [Using the snap package] - specific instructions on installing and configuring the Mosquitto snap package. +* [Authentication methods] - details on the different authentication options available. * [Dynamic Security plugin] - details of using the Dynamic Security authentication and access control plugin. +* [Using the snap package] - specific instructions on installing and configuring the Mosquitto snap package. * [Migrating from 1.x to 2.0] - details of changes needed to migrate to version 2.0. [mosquitto]:/man/mosquitto-8.html @@ -41,6 +42,7 @@ [libmosquitto API documentation]:/api/ +[Authentication methods]:/documentation/authentication-methods/ [Using the snap package]:/documentation/using-the-snap/ [Dynamic Security plugin]:/documentation/dynamic-security/ [Migrating from 1.x to 2.0]:/documentation/migrating-to-2-0/ diff --git a/www/pages/documentation/authentication-methods.md b/www/pages/documentation/authentication-methods.md new file mode 100644 index 00000000..f516956d --- /dev/null +++ b/www/pages/documentation/authentication-methods.md @@ -0,0 +1,147 @@ + + +It is important to configure authentication on your Mosquitto instance, so +unauthorised clients cannot connect. + +In Mosquitto 2.0 and up, you must choose your authentication options explicitly +before clients can connect. In earlier versions the default is to allow clients +to connect without authentication. + +There are three choices for authentication: password files, authentication +plugins, and unauthorised/anonymous access. It is possible to use a combination +of all three choices. + +It is possible to have different listeners use different authentication methods +by setting `per_listener_settings true` in your configuration file. + +As well as authentication you should also consider some form of access control +to determine what clients can access which topics. + +## Password files + +Password files are a simple mechanism of storing usernames and passwords in a +single file. They are good if you have a relatively small number of fairly +static users. + +If you make changes to the password file you must trigger the broker to reload +the file by sending a SIGHUP message: + +``` +kill -HUP +``` + +### Creating a password file + +To create a password file, use the `mosquitto_passwd` utility, use the line +below. You will be asked for the password. Note that `-c` means an existing +file will be overwritten: + +``` +mosquitto_passwd -c +``` + +To add more users to an existing password file, or to change the password for +an existing user, leave out the `-c` argument: + +``` +mosquitto_passwd +``` + +To remove a user from a password file: + +``` +mosquitto_passwd -D +``` + +You can also add/update a username and password in a single line, but be aware +that this means the password is visible on the command line and in any command +history: + +``` +mosquitto_passwd +``` + +### Configuring the broker + +To start using your password file you must add the `password_file` option to +your configuration file: + +``` +password_file +``` + +The password file must be able to be read by whatever user Mosquitto is running +as. On Linux/POSIX systems this will typically be the `mosquitto` user, and +`/etc/mosquitto/password_file` is a good place for the file itself. + +If you are using the `per_listener_settings true` option to have separate +security settings per listener, you must place the password file option *after* +the listener it is for: + +``` +listener 1883 +password_file /etc/mosquitto/password_file +``` + +## Authentication plugins + +If you want more control over authentication of your users than is offered by a +password file, then an authentication plugin may be suitable for you. The +features offered depend on which plugin you use. + +### Configuring the plugin + +Configuring a plugin varies depending on the version of Mosquitto plugin +interface the plugin was written for, either version 2.0 and up, or 1.6.x and +earlier. + +For 1.6.x and below, use the `auth_plugin` option. These plugins are also +supported by version 2.0: + +``` +listener 1883 +auth_plugin +``` + +Some plugins require extra configuration which will be described in their +documentation. + +For 2.0 and up, use the `plugin` option: + +``` +listener 1883 +plugin +``` + +### Available plugins + +* [Dynamic security](https://mosquitto.org/documentation/dynamic-security/), + for 2.0 and up only, provided by the Mosquitto project to give flexible + in-broker clients, groups, and roles that can be administered remotely. +* [mosquitto-go-auth](https://github.com/iegomez/mosquitto-go-auth), which + offers the use of a variety of backends to store user data, such as mysql, + jwt, or redis. + + +## Unauthenticated access + +To configure unauthenticated access, use the `allow_anonymous` option: + +``` +listener 1883 +allow_anonymous true +``` + +It is valid to allow anonmous and authenticated access on the same broker. In +particular the dynamic security plugin allows you to assign different rights to +anonymous users than to authenticated users, which may be useful for read-only +access to data for example. diff --git a/www/pages/documentation/using-the-snap.md b/www/pages/documentation/using-the-snap.md index d9926b20..41d6f3d4 100644 --- a/www/pages/documentation/using-the-snap.md +++ b/www/pages/documentation/using-the-snap.md @@ -14,7 +14,8 @@ graphical software installer, or with `snap install mosquitto`. After installing the Mosquitto snap, the Mosquitto broker will be running with the default configuration, which means it is listening for connections on port -1883. +1883 on the local computer only. If you want to allow connections from other +computers you must configure a listener and an [authentication method]. To test the broker, you can use the `mosquitto_pub` and `mosquitto_sub` command line utilities, which are also provided in the snap. `mosquitto_pub` allows you @@ -75,3 +76,5 @@ running as a snap. All other aspects of running Mosquitto are the same as with any other installation methods. + +[authentication method]:/documentation/authentication-methods diff --git a/www/pages/download.md b/www/pages/download.md index 526847b8..0d16e248 100644 --- a/www/pages/download.md +++ b/www/pages/download.md @@ -1,7 +1,7 @@ + +Version 2.0.6 of Mosquitto has been released. This is a bugfix release. + +# Broker +- Fix calculation of remaining length parameter for websockets clients that + send fragmented packets. Closes [#1974]. +- Fix potential duplicate Will messages being sent when a will delay interval + has been set. +- Fix message expiry interval property not being honoured in + `mosquitto_broker_publish` and `mosquitto_broker_publish_copy`. +- Fix websockets listeners with TLS not responding. Closes [#2020]. +- Add notes that libsystemd-dev or similar is needed if building with systemd + support. Closes [#2019]. +- Improve logging in obscure cases when a client disconnects. Closes [#2017]. +- Fix reloading of listeners where multiple listeners have been defined with + the same port but different bind addresses. Closes [#2029]. +- Fix `message_size_limit` not applying to the Will payload. Closes [#2022]. +- The error topic-alias-invalid was being sent if an MQTT v5 client published + a message with empty topic and topic alias set, but the topic alias hadn't + already been configured on the broker. This has been fixed to send a + protocol error, as per section 3.3.4 of the specification. +- Note in the man pages that SIGHUP reloads TLS certificates. Closes [#2037]. +- Fix bridges not always connecting on Windows. Closes [#2043]. + +# Apps +- Allow command line arguments to override config file options in + mosquitto_ctrl. Closes [#2010]. +- mosquitto_ctrl: produce an error when requesting a new password if both + attempts do not match. Closes [#2011]. + +# Build +- Fix cmake builds using `WITH_CJSON=no` not working if cJSON not found. + Closes [#2026]. + +# Other +- The SPDX identifiers for EDL-1.0 have been changed to BSD-3-Clause as per + The Eclipse legal documentation generator. The licenses are identical. + +[#1974]: https://github.com/eclipse/mosquitto/issues/1974 +[#2010]: https://github.com/eclipse/mosquitto/issues/2010 +[#2011]: https://github.com/eclipse/mosquitto/issues/2011 +[#2017]: https://github.com/eclipse/mosquitto/issues/2017 +[#2019]: https://github.com/eclipse/mosquitto/issues/2019 +[#2020]: https://github.com/eclipse/mosquitto/issues/2020 +[#2022]: https://github.com/eclipse/mosquitto/issues/2022 +[#2026]: https://github.com/eclipse/mosquitto/issues/2026 +[#2029]: https://github.com/eclipse/mosquitto/issues/2029 +[#2037]: https://github.com/eclipse/mosquitto/issues/2037 +[#2043]: https://github.com/eclipse/mosquitto/issues/2043 diff --git a/www/posts/2021/02/version-2-0-7-released.md b/www/posts/2021/02/version-2-0-7-released.md new file mode 100644 index 00000000..4e9190c7 --- /dev/null +++ b/www/posts/2021/02/version-2-0-7-released.md @@ -0,0 +1,77 @@ + + +Version 2.0.7 and 1.6.13 of Mosquitto have been released. These are bugfix releases. + +# 2.0.7 + +## Broker +- Fix exporting of executable symbols on BSD when building via makefile. +- Fix some minor memory leaks on exit only. +- Fix possible memory leak on connect. Closes [#2057]. +- Fix openssl engine not being able to load private key. Closes [#2066]. + +## Clients +- Fix config files truncating options after the first space. Closes [#2059]. + +## Build +- Fix man page building to not absolutely require xsltproc when using CMake. + This now handles the case where we are building from the released tar, or + building from git if xsltproc is available, or building from git if xsltproc + is not available. + + +# 1.6.13 + +## Broker: +- Fix crash on Windows if loading a plugin fails. Closes [#1866]. +- Fix DH group not being set for TLS connections, which meant ciphers using + DHE couldn't be used. Closes [#1925]. Closes [#1476]. +- Fix local bridges being disconnected on SIGHUP. Closes [#1942]. +- Fix $SYS/broker/publish/messages/+ counters not being updated for QoS 1, 2 + messages. Closes [#1968]. +- Fix listener not being reassociated with client when reloading a persistence + file and `per_listener_settings true` is set and the client did not set a + username. Closes [#1891]. +- Fix file logging on Windows. Closes [#1880]. +- Fix bridge sock not being removed from sock hash on error. Closes [#1897]. + +## Client library: +- Fix build on Mac Big Sur. Closes [#1905]. +- Fix DH group not being set for TLS connections, which meant ciphers using + DHE couldn't be used. Closes [#1925]. Closes [#1476]. + +## Clients: +- mosquitto_sub will now quit with an error if the %U option is used on + Windows, rather than just quitting. Closes [#1908]. +- Fix config files truncating options after the first space. Closes [#2059]. + +## Apps: +- Perform stricter parsing of input username in mosquitto_passwd. Closes + [#570126] (Eclipse bugzilla). + +## Build: +- Enable epoll support in CMake builds. + +[#1476]: https://github.com/eclipse/mosquitto/issues/1476 +[#1866]: https://github.com/eclipse/mosquitto/issues/1866 +[#1880]: https://github.com/eclipse/mosquitto/issues/1880 +[#1891]: https://github.com/eclipse/mosquitto/issues/1891 +[#1897]: https://github.com/eclipse/mosquitto/issues/1897 +[#1905]: https://github.com/eclipse/mosquitto/issues/1905 +[#1908]: https://github.com/eclipse/mosquitto/issues/1908 +[#1925]: https://github.com/eclipse/mosquitto/issues/1925 +[#1942]: https://github.com/eclipse/mosquitto/issues/1942 +[#1968]: https://github.com/eclipse/mosquitto/issues/1968 +[#2057]: https://github.com/eclipse/mosquitto/issues/2057 +[#2059]: https://github.com/eclipse/mosquitto/issues/2059 +[#2066]: https://github.com/eclipse/mosquitto/issues/2066 +[#570126]: https://bugs.eclipse.org/bugs/show_bug.cgi?id=570126 diff --git a/www/posts/2021/02/version-2-0-8-released.md b/www/posts/2021/02/version-2-0-8-released.md new file mode 100644 index 00000000..cedb9ddb --- /dev/null +++ b/www/posts/2021/02/version-2-0-8-released.md @@ -0,0 +1,42 @@ + + +Version 2.0.8 of Mosquitto has been released. This is a bugfix release. + +# Broker +- Fix incorrect datatypes in `struct mosquitto_evt_tick`. This changes the + size and offset of two of the members of this struct, and changes the size + of the struct. This is an ABI break, but is considered to be acceptable + because plugins should never be allocating their own instance of this + struct, and currently none of the struct members are used for anything, so a + plugin should not be accessing them. It would also be safe to read/write + from the existing struct parameters. +- Give compile time warning if libwebsockets compiled without external poll + support. Closes [#2060]. +- Fix memory tracking not being available on FreeBSD or macOS. Closes [#2096]. + +# Client library +- Fix `mosquitto_{pub|sub}_topic_check()` functions not returning `MOSQ_ERR_INVAL` + on topic == NULL. + +# Clients +- Fix possible loss of data in `mosquitto_pub -l` when sending multiple long + lines. Closes [#2078]. + +# Build +- Provide a mechanism for Docker users to run a broker that doesn't use + authentication, without having to provide their own configuration file. + Closes [#2040]. + +[#2040]: https://github.com/eclipse/mosquitto/issues/2040 +[#2060]: https://github.com/eclipse/mosquitto/issues/2060 +[#2078]: https://github.com/eclipse/mosquitto/issues/2078 +[#2096]: https://github.com/eclipse/mosquitto/issues/2096