Fix listener not being reassociated with client.

This occurred when reloading a persistence file and
`per_listener_settings true` is set and the client did not set a
username.

Closes #1891. Thanks to Mikkel Nepper-Christensen.
This commit is contained in:
Roger A. Light 2020-11-12 17:36:49 +00:00
parent 4e13bdec04
commit e7a4e73cd8
3 changed files with 13 additions and 10 deletions

View File

@ -78,6 +78,9 @@ Broker:
- Add the `bridge_bind_address` option. Closes #1311. - Add the `bridge_bind_address` option. Closes #1311.
- Fix crash on Windows if loading a plugin fails. Closes #1866. - Fix crash on Windows if loading a plugin fails. Closes #1866.
- TLS certificates for the server are now reloaded on SIGHUP. - TLS certificates for the server are now reloaded on SIGHUP.
- 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.
Client library: Client library:
- Client no longer generates random client ids for v3.1.1 clients, these are - Client no longer generates random client ids for v3.1.1 clients, these are

View File

@ -202,13 +202,13 @@ static int persist__client_chunk_restore(FILE *db_fptr)
/* username is not freed here, it is now owned by context */ /* username is not freed here, it is now owned by context */
context->username = chunk.username; context->username = chunk.username;
chunk.username = NULL; chunk.username = NULL;
/* in per_listener_settings mode, try to find the listener by persisted port */ }
if(db.config->per_listener_settings && !context->listener && chunk.F.listener_port > 0){ /* in per_listener_settings mode, try to find the listener by persisted port */
for(i=0; i < db.config->listener_count; i++){ if(db.config->per_listener_settings && !context->listener && chunk.F.listener_port > 0){
if(db.config->listeners[i].port == chunk.F.listener_port){ for(i=0; i < db.config->listener_count; i++){
context->listener = &db.config->listeners[i]; if(db.config->listeners[i].port == chunk.F.listener_port){
break; context->listener = &db.config->listeners[i];
} break;
} }
} }
} }

View File

@ -174,9 +174,9 @@ static int persist__client_save(FILE *db_fptr)
if(context->username){ if(context->username){
chunk.F.username_len = (uint16_t)strlen(context->username); chunk.F.username_len = (uint16_t)strlen(context->username);
chunk.username = context->username; chunk.username = context->username;
if(context->listener){ }
chunk.F.listener_port = context->listener->port; if(context->listener){
} chunk.F.listener_port = context->listener->port;
} }
if(chunk.F.id_len == 0){ if(chunk.F.id_len == 0){