Merge branch 'master' into develop

This commit is contained in:
Roger A. Light 2017-07-19 00:15:42 +01:00
commit 5a267368d7
8 changed files with 64 additions and 17 deletions

View File

@ -74,6 +74,13 @@ Build:
build and install static versions of the client libraries.
1.4.14 - 20170710
=================
Broker:
- Fix regression from 1.4.13 where persistence data was not being saved.
1.4.13 - 20170627
=================

View File

@ -950,9 +950,10 @@ int mosquitto_loop(struct mosquitto *mosq, int timeout, int max_packets)
/* Fake write possible, to stimulate output write even though
* we didn't ask for it, because at that point the publish or
* other command wasn't present. */
if(mosq->sock != INVALID_SOCKET)
FD_SET(mosq->sock, &writefds);
}
if(FD_ISSET(mosq->sock, &writefds)){
if(mosq->sock != INVALID_SOCKET && FD_ISSET(mosq->sock, &writefds)){
#ifdef WITH_TLS
if(mosq->want_connect){
rc = net__socket_connect_tls(mosq);

View File

@ -288,19 +288,33 @@ int mosquitto__hex2bin(const char *hex, unsigned char *bin, int bin_max_len)
{
BIGNUM *bn = NULL;
int len;
int leading_zero = 0;
int start = 0;
int i = 0;
/* Count the number of leading zero */
for(i=0; i<strlen(hex); i=i+2) {
if(strncmp(hex + i, "00", 2) == 0) {
leading_zero++;
/* output leading zero to bin */
bin[start++] = 0;
}else{
break;
}
}
if(BN_hex2bn(&bn, hex) == 0){
if(bn) BN_free(bn);
return 0;
}
if(BN_num_bytes(bn) > bin_max_len){
if(BN_num_bytes(bn) + leading_zero > bin_max_len){
BN_free(bn);
return 0;
}
len = BN_bn2bin(bn, bin);
len = BN_bn2bin(bn, bin + leading_zero);
BN_free(bn);
return len;
return len + leading_zero;
}
#endif

View File

@ -5,6 +5,9 @@ include ../config.mk
all : mosquitto.8 mosquitto-tls.7 mosquitto.conf.5 mosquitto_passwd.1 mosquitto_pub.1 mosquitto_sub.1 mqtt.7 libmosquitto.3
clean :
reallyclean : clean
-rm -f *.orig
-rm -f libmosquitto.3
-rm -f mosquitto.8
-rm -f mosquitto.conf.5
@ -14,9 +17,6 @@ clean :
-rm -f mosquitto-tls.7
-rm -f mqtt.7
reallyclean : clean
-rm -f *.orig
dist : mosquitto.8 mosquitto-tls.7 mosquitto.conf.5 mosquitto_passwd.1 mosquitto_pub.1 mosquitto_sub.1 mqtt.7 libmosquitto.3
install :

View File

@ -2,7 +2,7 @@
MAJOR=1
MINOR=4
REVISION=13
REVISION=14
sed -i "s/^VERSION=.*/VERSION=${MAJOR}.${MINOR}.${REVISION}/" config.mk

View File

@ -21,6 +21,7 @@ Contributors:
#include <assert.h>
#ifndef WIN32
#include <poll.h>
#include <unistd.h>
#else
#include <process.h>
#include <winsock2.h>
@ -126,7 +127,7 @@ int mosquitto_main_loop(struct mosquitto_db *db, mosq_sock_t *listensock, int li
#ifdef WIN32
pollfd_max = _getmaxstdio();
#else
pollfd_max = getdtablesize();
pollfd_max = sysconf(_SC_OPEN_MAX);
#endif
pollfds = mosquitto__malloc(sizeof(struct pollfd)*pollfd_max);

View File

@ -374,6 +374,16 @@ int main(int argc, char *argv[])
}
#endif
HASH_ITER(hh_id, int_db.contexts_by_id, ctxt, ctxt_tmp){
mqtt3_context_send_will(&int_db, ctxt);
}
#ifdef WITH_PERSISTENCE
if(config.persistence){
mqtt3_db_backup(&int_db, true);
}
#endif
HASH_ITER(hh_id, int_db.contexts_by_id, ctxt, ctxt_tmp){
#ifdef WITH_WEBSOCKETS
if(!ctxt->wsi){
@ -396,12 +406,6 @@ int main(int argc, char *argv[])
#endif
context__free_disused(&int_db);
#ifdef WITH_PERSISTENCE
if(config.persistence){
persist__backup(&int_db, true);
}
#endif
db__close(&int_db);
if(listensock){

View File

@ -33,6 +33,9 @@ static int pw__digest(const char *password, const unsigned char *salt, unsigned
static int base64__decode(char *in, unsigned char **decoded, unsigned int *decoded_len);
#endif
static int mosquitto__memcmp_const(const void *ptr1, const void *b, size_t len);
int mosquitto_security_init_default(struct mosquitto_db *db, bool reload)
{
int rc;
@ -648,6 +651,23 @@ static int psk__file_parse(struct mosquitto_db *db)
return MOSQ_ERR_SUCCESS;
}
static int mosquitto__memcmp_const(const void *a, const void *b, size_t len)
{
int i;
int rc = 0;
if(!a || !b) return 1;
for(i=0; i<len; i++){
if( ((char *)a)[i] != ((char *)b)[i] ){
rc = 1;
}
}
return rc;
}
int mosquitto_unpwd_check_default(struct mosquitto_db *db, const char *username, const char *password)
{
struct mosquitto__unpwd *u, *tmp;
@ -668,7 +688,7 @@ int mosquitto_unpwd_check_default(struct mosquitto_db *db, const char *username,
#ifdef WITH_TLS
rc = pw__digest(password, u->salt, u->salt_len, hash, &hash_len);
if(rc == MOSQ_ERR_SUCCESS){
if(hash_len == u->password_len && !memcmp(u->password, hash, hash_len)){
if(hash_len == u->password_len && !mosquitto__memcmp_const(u->password, hash, hash_len)){
return MOSQ_ERR_SUCCESS;
}else{
return MOSQ_ERR_AUTH;