Skip to content

Commit

Permalink
More allow_zero_length_clientid fixes.
Browse files Browse the repository at this point in the history
Closes #1429. Thanks to Dustin Sallings.
  • Loading branch information
ralight committed Sep 26, 2019
1 parent 539c1b9 commit 4db1e80
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
5 changes: 3 additions & 2 deletions ChangeLog.txt
@@ -1,6 +1,7 @@
Broker:
- allow_zero_length_clientid wasn't being used by the default listener, making
it impossible to turn this option off.
- Various fixes for `allow_zero_length_clientid` config, where this option was
not being set correctly. Closes #1429.


1.6.7 - 20190925
================
Expand Down
3 changes: 3 additions & 0 deletions src/conf.c
Expand Up @@ -271,6 +271,7 @@ void config__init(struct mosquitto_db *db, struct mosquitto__config *config)
config->default_listener.max_connections = -1;
config->default_listener.protocol = mp_mqtt;
config->default_listener.security_options.allow_anonymous = -1;
config->default_listener.security_options.allow_zero_length_clientid = true;
config->default_listener.maximum_qos = 2;
config->default_listener.max_topic_alias = 10;
}
Expand Down Expand Up @@ -471,6 +472,7 @@ int config__parse_args(struct mosquitto_db *db, struct mosquitto__config *config
|| config->default_listener.security_options.psk_file
|| config->default_listener.security_options.auth_plugin_config_count
|| config->default_listener.security_options.allow_anonymous != -1
|| config->default_listener.security_options.allow_zero_length_clientid != true
){

config->listener_count++;
Expand Down Expand Up @@ -1389,6 +1391,7 @@ int config__read_file_core(struct mosquitto__config *config, bool reload, struct
}

cur_listener->security_options.allow_anonymous = -1;
cur_listener->security_options.allow_zero_length_clientid = true;
cur_listener->protocol = mp_mqtt;
cur_listener->port = tmp_int;
cur_listener->maximum_qos = 2;
Expand Down
27 changes: 25 additions & 2 deletions test/broker/01-connect-zero-length-id.py
Expand Up @@ -11,9 +11,11 @@ def write_config(filename, port1, port2, per_listener, allow_zero):
with open(filename, 'w') as f:
f.write("per_listener_settings %s\n" % (per_listener))
f.write("port %d\n" % (port2))
f.write("allow_zero_length_clientid %s\n" % (allow_zero))
if allow_zero != "":
f.write("allow_zero_length_clientid %s\n" % (allow_zero))
f.write("listener %d\n" % (port1))
f.write("allow_zero_length_clientid %s\n" % (allow_zero))
if allow_zero != "":
f.write("allow_zero_length_clientid %s\n" % (allow_zero))


def do_test(per_listener, proto_ver, clean_start, allow_zero, client_port, expect_fail):
Expand Down Expand Up @@ -53,6 +55,7 @@ def do_test(per_listener, proto_ver, clean_start, allow_zero, client_port, expec
if rc:
print(stde.decode('utf-8'))
print("per_listener:%s proto_ver:%d client_port:%d clean_start:%d allow_zero:%s" % (per_listener, proto_ver, client_port, clean_start, allow_zero))
print("port1:%d port2:%d" % (port1, port2))
exit(rc)


Expand Down Expand Up @@ -80,6 +83,16 @@ def do_test(per_listener, proto_ver, clean_start, allow_zero, client_port, expec
do_test(per_listener="true", proto_ver=4, client_port=port2, clean_start=False, allow_zero="true", expect_fail=True)
do_test(per_listener="true", proto_ver=4, client_port=port2, clean_start=False, allow_zero="false", expect_fail=True)

do_test(per_listener="false", proto_ver=4, client_port=port1, clean_start=True, allow_zero="", expect_fail=False)
do_test(per_listener="false", proto_ver=4, client_port=port1, clean_start=False, allow_zero="", expect_fail=True)
do_test(per_listener="true", proto_ver=4, client_port=port1, clean_start=True, allow_zero="", expect_fail=False)
do_test(per_listener="true", proto_ver=4, client_port=port1, clean_start=False, allow_zero="", expect_fail=True)

do_test(per_listener="false", proto_ver=4, client_port=port2, clean_start=True, allow_zero="", expect_fail=False)
do_test(per_listener="false", proto_ver=4, client_port=port2, clean_start=False, allow_zero="", expect_fail=True)
do_test(per_listener="true", proto_ver=4, client_port=port2, clean_start=True, allow_zero="", expect_fail=False)
do_test(per_listener="true", proto_ver=4, client_port=port2, clean_start=False, allow_zero="", expect_fail=True)

if test_v5 == True:
do_test(per_listener="false", proto_ver=5, client_port=port1, clean_start=True, allow_zero="true", expect_fail=False)
do_test(per_listener="false", proto_ver=5, client_port=port1, clean_start=True, allow_zero="false", expect_fail=True)
Expand All @@ -99,4 +112,14 @@ def do_test(per_listener, proto_ver, clean_start, allow_zero, client_port, expec
do_test(per_listener="true", proto_ver=5, client_port=port2, clean_start=False, allow_zero="true", expect_fail=False)
do_test(per_listener="true", proto_ver=5, client_port=port2, clean_start=False, allow_zero="false", expect_fail=True)

do_test(per_listener="false", proto_ver=5, client_port=port1, clean_start=True, allow_zero="", expect_fail=False)
do_test(per_listener="false", proto_ver=5, client_port=port1, clean_start=False, allow_zero="", expect_fail=False)
do_test(per_listener="true", proto_ver=5, client_port=port1, clean_start=True, allow_zero="", expect_fail=False)
do_test(per_listener="true", proto_ver=5, client_port=port1, clean_start=False, allow_zero="", expect_fail=False)

do_test(per_listener="false", proto_ver=5, client_port=port2, clean_start=True, allow_zero="", expect_fail=False)
do_test(per_listener="false", proto_ver=5, client_port=port2, clean_start=False, allow_zero="", expect_fail=False)
do_test(per_listener="true", proto_ver=5, client_port=port2, clean_start=True, allow_zero="", expect_fail=False)
do_test(per_listener="true", proto_ver=5, client_port=port2, clean_start=False, allow_zero="", expect_fail=False)

exit(0)

0 comments on commit 4db1e80

Please sign in to comment.