diff -Nru mosquitto-1.1.2/CMakeLists.txt mosquitto-1.1.3/CMakeLists.txt --- mosquitto-1.1.2/CMakeLists.txt 2013-01-30 20:29:50.000000000 +0000 +++ mosquitto-1.1.3/CMakeLists.txt 2013-02-11 09:00:03.000000000 +0000 @@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 2.6) -set (VERSION 1.1.2) +set (VERSION 1.1.3) if (WIN32) execute_process(COMMAND cmd /c echo %DATE% %TIME% OUTPUT_VARIABLE TIMESTAMP diff -Nru mosquitto-1.1.2/ChangeLog.txt mosquitto-1.1.3/ChangeLog.txt --- mosquitto-1.1.2/ChangeLog.txt 2013-01-30 20:29:50.000000000 +0000 +++ mosquitto-1.1.3/ChangeLog.txt 2013-02-11 09:00:03.000000000 +0000 @@ -1,3 +1,14 @@ +1.1.3 - 20130211 +================ + +Broker: +- mosquitto_passwd utility now uses tmpfile() to generate its temporary data + storage file. It also creates a backup file that can be used to recover data + if an errors occur. + +Other: +- Build script fixes to help packaging on Debian. + 1.1.2 - 20130130 ================ diff -Nru mosquitto-1.1.2/Makefile mosquitto-1.1.3/Makefile --- mosquitto-1.1.2/Makefile 2013-01-30 20:29:50.000000000 +0000 +++ mosquitto-1.1.3/Makefile 2013-02-11 09:00:03.000000000 +0000 @@ -9,21 +9,21 @@ all : mosquitto docs docs : - for d in ${DOCDIRS}; do $(MAKE) -C $${d}; done + set -e; for d in ${DOCDIRS}; do $(MAKE) -C $${d}; done binary : mosquitto mosquitto : - for d in ${DIRS}; do $(MAKE) -C $${d}; done + set -e; for d in ${DIRS}; do $(MAKE) -C $${d}; done clean : - for d in ${DIRS}; do $(MAKE) -C $${d} clean; done - for d in ${DOCDIRS}; do $(MAKE) -C $${d} clean; done + set -e; for d in ${DIRS}; do $(MAKE) -C $${d} clean; done + set -e; for d in ${DOCDIRS}; do $(MAKE) -C $${d} clean; done $(MAKE) -C test clean reallyclean : - for d in ${DIRS}; do $(MAKE) -C $${d} reallyclean; done - for d in ${DOCDIRS}; do $(MAKE) -C $${d} reallyclean; done + set -e; for d in ${DIRS}; do $(MAKE) -C $${d} reallyclean; done + set -e; for d in ${DOCDIRS}; do $(MAKE) -C $${d} reallyclean; done $(MAKE) -C test reallyclean -rm -f *.orig @@ -31,8 +31,8 @@ $(MAKE) -C test test install : mosquitto - @for d in ${DIRS}; do $(MAKE) -C $${d} install; done - @for d in ${DOCDIRS}; do $(MAKE) -C $${d} install; done + set -e; for d in ${DIRS}; do $(MAKE) -C $${d} install; done + set -e; for d in ${DOCDIRS}; do $(MAKE) -C $${d} install; done $(INSTALL) -d ${DESTDIR}/etc/mosquitto $(INSTALL) -m 644 mosquitto.conf ${DESTDIR}/etc/mosquitto/mosquitto.conf $(INSTALL) -m 644 aclfile.example ${DESTDIR}/etc/mosquitto/aclfile.example @@ -40,19 +40,19 @@ $(INSTALL) -m 644 pskfile.example ${DESTDIR}/etc/mosquitto/pskfile.example uninstall : - @for d in ${DIRS}; do $(MAKE) -C $${d} uninstall; done + set -e; for d in ${DIRS}; do $(MAKE) -C $${d} uninstall; done rm -f ${DESTDIR}/etc/mosquitto/mosquitto.conf rm -f ${DESTDIR}/etc/mosquitto/aclfile.example rm -f ${DESTDIR}/etc/mosquitto/pwfile.example rm -f ${DESTDIR}/etc/mosquitto/pskfile.example dist : reallyclean - @for d in ${DISTDIRS}; do $(MAKE) -C $${d} dist; done + set -e; for d in ${DISTDIRS}; do $(MAKE) -C $${d} dist; done mkdir -p dist/mosquitto-${VERSION} cp -r client examples installer lib logo man misc security service src test ChangeLog.txt CMakeLists.txt LICENSE.txt LICENSE-3rd-party.txt Makefile compiling.txt config.h config.mk readme.txt readme-windows.txt mosquitto.conf aclfile.example pskfile.example pwfile.example dist/mosquitto-${VERSION}/ cd dist; tar -zcf mosquitto-${VERSION}.tar.gz mosquitto-${VERSION}/ - for m in man/*.xml; \ + set -e; for m in man/*.xml; \ do \ hfile=$$(echo $${m} | sed -e 's#man/\(.*\)\.xml#\1#' | sed -e 's/\./-/g'); \ $(XSLTPROC) $(DB_HTML_XSL) $${m} > dist/$${hfile}.html; \ diff -Nru mosquitto-1.1.2/config.mk mosquitto-1.1.3/config.mk --- mosquitto-1.1.2/config.mk 2013-01-30 20:29:50.000000000 +0000 +++ mosquitto-1.1.3/config.mk 2013-02-11 09:00:03.000000000 +0000 @@ -66,7 +66,7 @@ # Also bump lib/mosquitto.h, lib/python/setup.py, CMakeLists.txt, # installer/mosquitto.nsi, installer/mosquitto-cygwin.nsi -VERSION=1.1.2 +VERSION=1.1.3 TIMESTAMP:=$(shell date "+%F %T%z") # Client library SO version. Bump if incompatible API/ABI changes are made. @@ -90,11 +90,12 @@ CFLAGS?=-Wall -ggdb -O2 endif -LIB_CFLAGS:=${CFLAGS} -I. -I.. -I../lib +LIB_CFLAGS:=${CFLAGS} ${CPPFLAGS} -I. -I.. -I../lib LIB_CXXFLAGS:=$(LIB_CFLAGS) +LIB_LDFLAGS:=${LDFLAGS} -BROKER_CFLAGS:=${LIB_CFLAGS} -DVERSION="\"${VERSION}\"" -DTIMESTAMP="\"${TIMESTAMP}\"" -DWITH_BROKER -CLIENT_CFLAGS:=${CFLAGS} -I../lib -DVERSION="\"${VERSION}\"" +BROKER_CFLAGS:=${LIB_CFLAGS} ${CPPFLAGS} -DVERSION="\"${VERSION}\"" -DTIMESTAMP="\"${TIMESTAMP}\"" -DWITH_BROKER +CLIENT_CFLAGS:=${CFLAGS} ${CPPFLAGS} -I../lib -DVERSION="\"${VERSION}\"" ifeq ($(UNAME),FreeBSD) BROKER_LIBS:=-lm diff -Nru mosquitto-1.1.2/debian/changelog mosquitto-1.1.3/debian/changelog --- mosquitto-1.1.2/debian/changelog 2013-01-30 20:36:02.000000000 +0000 +++ mosquitto-1.1.3/debian/changelog 2013-02-11 09:22:46.000000000 +0000 @@ -1,12 +1,12 @@ -mosquitto (1.1.2-0ppa1~lucid) lucid; urgency=low +mosquitto (1.1.3-0ppa1~lucid) lucid; urgency=low - * New upstream release: http://mosquitto.org/2013/01/version-1-1-2-released/ - * Bumped standards release to 3.9.3. No changes needed. + * New upstream release: http://mosquitto.org/2013/02/version-1-1-3-released/ + * Bumped standards release to 3.9.4. No changes needed. * Added mosquitto-dbg package for binary debug information. * Added python3-mosquitto binary package. * Use dh_python2 (and dh_python3) instead of python-support. - -- Roger A. Light Wed, 16 Jan 2013 23:16:11 +0000 + -- Roger A. Light Mon, 11 Feb 2013 08:55:23 +0000 mosquitto (0.15-1) unstable; urgency=low diff -Nru mosquitto-1.1.2/debian/control mosquitto-1.1.3/debian/control --- mosquitto-1.1.2/debian/control 2013-01-30 20:35:09.000000000 +0000 +++ mosquitto-1.1.3/debian/control 2013-02-11 09:26:23.000000000 +0000 @@ -2,7 +2,7 @@ Section: net Priority: optional Maintainer: Roger A. Light -Build-Depends: debhelper (>= 7), libssl-dev (>=0.9.8), libwrap0-dev, python-setuptools, python, python3 +Build-Depends: debhelper (>= 7), libssl-dev (>=0.9.8), libwrap0-dev, python-all, python3-all Standards-Version: 3.9.3 Homepage: http://mosquitto.org/ Vcs-Hg: http://bitbucket.org/oojah/mosquitto-packaging @@ -34,7 +34,7 @@ where a sensor or other simple device may be implemented using an arduino for example. -Package: libmosquitto1-dev +Package: libmosquitto-dev Section: libdevel Architecture: all Depends: ${misc:Depends}, libmosquitto1 (>= ${source:Version}), libmosquitto1 (<< ${source:Version}.1~) @@ -56,7 +56,7 @@ where a sensor or other simple device may be implemented using an arduino for example. -Package: libmosquittopp1-dev +Package: libmosquittopp-dev Section: libdevel Architecture: all Depends: ${misc:Depends}, libmosquittopp1 (>= ${source:Version}), libmosquittopp1 (<< ${source:Version}.1~) diff -Nru mosquitto-1.1.2/debian/patches/disable-tests.patch mosquitto-1.1.3/debian/patches/disable-tests.patch --- mosquitto-1.1.2/debian/patches/disable-tests.patch 2013-01-30 20:35:09.000000000 +0000 +++ mosquitto-1.1.3/debian/patches/disable-tests.patch 2013-02-11 09:24:16.000000000 +0000 @@ -8,4 +8,4 @@ + #$(MAKE) -C test test install : mosquitto - @for d in ${DIRS}; do $(MAKE) -C $${d} install; done + set -e; for d in ${DIRS}; do $(MAKE) -C $${d} install; done diff -Nru mosquitto-1.1.2/debian/patches/fix-prefix.patch mosquitto-1.1.3/debian/patches/fix-prefix.patch --- mosquitto-1.1.2/debian/patches/fix-prefix.patch 2013-01-30 20:35:09.000000000 +0000 +++ mosquitto-1.1.3/debian/patches/fix-prefix.patch 2013-02-11 09:24:25.000000000 +0000 @@ -3,7 +3,7 @@ Forwarded: not-needed --- a/config.mk +++ b/config.mk -@@ -183,6 +183,6 @@ +@@ -188,6 +188,6 @@ INSTALL?=install diff -Nru mosquitto-1.1.2/debian/patches/mosquitto.conf.patch mosquitto-1.1.3/debian/patches/mosquitto.conf.patch --- mosquitto-1.1.2/debian/patches/mosquitto.conf.patch 2013-01-30 20:35:09.000000000 +0000 +++ mosquitto-1.1.3/debian/patches/mosquitto.conf.patch 2013-02-11 09:24:18.000000000 +0000 @@ -16,7 +16,7 @@ # When run as root, drop privileges to this user and its primary # group. -@@ -327,7 +330,7 @@ +@@ -341,7 +344,7 @@ # subscriptions, currently in-flight messages and retained # messages. # retained_persistence is a synonym for this option. @@ -25,7 +25,7 @@ # The filename to use for the persistent database, not including # the path. -@@ -336,7 +339,7 @@ +@@ -350,7 +353,7 @@ # Location for persistent database. Must include trailing / # Default is an empty string (current directory). # Set to /var/lib/mosquitto/ if running as a proper service. @@ -34,7 +34,7 @@ # ================================================================= # Logging -@@ -354,7 +357,7 @@ +@@ -368,7 +371,7 @@ # Note that if the broker is running as a Windows service it will default to # "log_dest none" and neither stdout nor stderr logging is available. # Use "log_dest none" if you wish to disable logging. @@ -43,7 +43,7 @@ # Types of messages to log. Use multiple log_type lines for logging # multiple types of messages. -@@ -647,3 +650,5 @@ +@@ -672,3 +675,5 @@ #max_log_entries #trace_level #trace_output diff -Nru mosquitto-1.1.2/installer/mosquitto-cygwin.nsi mosquitto-1.1.3/installer/mosquitto-cygwin.nsi --- mosquitto-1.1.2/installer/mosquitto-cygwin.nsi 2013-01-30 20:29:50.000000000 +0000 +++ mosquitto-1.1.3/installer/mosquitto-cygwin.nsi 2013-02-11 09:00:02.000000000 +0000 @@ -7,7 +7,7 @@ !define env_hklm 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"' Name "mosquitto" -!define VERSION 1.1.2 +!define VERSION 1.1.3 OutFile "mosquitto-${VERSION}-install-cygwin.exe" InstallDir "$PROGRAMFILES\mosquitto" diff -Nru mosquitto-1.1.2/installer/mosquitto.nsi mosquitto-1.1.3/installer/mosquitto.nsi --- mosquitto-1.1.2/installer/mosquitto.nsi 2013-01-30 20:29:50.000000000 +0000 +++ mosquitto-1.1.3/installer/mosquitto.nsi 2013-02-11 09:00:02.000000000 +0000 @@ -7,7 +7,7 @@ !define env_hklm 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"' Name "mosquitto" -!define VERSION 1.1.2 +!define VERSION 1.1.3 OutFile "mosquitto-${VERSION}-install-win32.exe" InstallDir "$PROGRAMFILES\mosquitto" diff -Nru mosquitto-1.1.2/lib/mosquitto.h mosquitto-1.1.3/lib/mosquitto.h --- mosquitto-1.1.2/lib/mosquitto.h 2013-01-30 20:29:50.000000000 +0000 +++ mosquitto-1.1.3/lib/mosquitto.h 2013-02-11 09:00:02.000000000 +0000 @@ -58,7 +58,7 @@ #define LIBMOSQUITTO_MAJOR 1 #define LIBMOSQUITTO_MINOR 1 -#define LIBMOSQUITTO_REVISION 2 +#define LIBMOSQUITTO_REVISION 3 #define LIBMOSQUITTO_VERSION_NUMBER (LIBMOSQUITTO_MAJOR*1000000+LIBMOSQUITTO_MINOR*1000+LIBMOSQUITTO_REVISION) /* Log types */ diff -Nru mosquitto-1.1.2/lib/python/setup.py mosquitto-1.1.3/lib/python/setup.py --- mosquitto-1.1.2/lib/python/setup.py 2013-01-30 20:29:50.000000000 +0000 +++ mosquitto-1.1.3/lib/python/setup.py 2013-02-11 09:00:02.000000000 +0000 @@ -2,7 +2,7 @@ from distutils.core import setup setup(name='mosquitto', - version='1.1.2', + version='1.1.3', description='MQTT version 3.1 client class', author='Roger Light', author_email='roger@atchoo.org', diff -Nru mosquitto-1.1.2/man/libmosquitto.3 mosquitto-1.1.3/man/libmosquitto.3 --- mosquitto-1.1.2/man/libmosquitto.3 2013-01-30 20:29:50.000000000 +0000 +++ mosquitto-1.1.3/man/libmosquitto.3 2013-02-11 09:00:02.000000000 +0000 @@ -2,12 +2,12 @@ .\" Title: libmosquitto .\" Author: [see the "Author" section] .\" Generator: DocBook XSL Stylesheets v1.76.1 -.\" Date: 01/30/2013 +.\" Date: 02/11/2013 .\" Manual: Library calls .\" Source: Mosquitto Project .\" Language: English .\" -.TH "LIBMOSQUITTO" "3" "01/30/2013" "Mosquitto Project" "Library calls" +.TH "LIBMOSQUITTO" "3" "02/11/2013" "Mosquitto Project" "Library calls" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- diff -Nru mosquitto-1.1.2/man/mosquitto-tls.7 mosquitto-1.1.3/man/mosquitto-tls.7 --- mosquitto-1.1.2/man/mosquitto-tls.7 2013-01-30 20:29:50.000000000 +0000 +++ mosquitto-1.1.3/man/mosquitto-tls.7 2013-02-11 09:00:02.000000000 +0000 @@ -2,12 +2,12 @@ .\" Title: mosquitto-tls .\" Author: [see the "Author" section] .\" Generator: DocBook XSL Stylesheets v1.76.1 -.\" Date: 01/30/2013 +.\" Date: 02/11/2013 .\" Manual: Conventions and miscellaneous .\" Source: Mosquitto Project .\" Language: English .\" -.TH "MOSQUITTO\-TLS" "7" "01/30/2013" "Mosquitto Project" "Conventions and miscellaneous" +.TH "MOSQUITTO\-TLS" "7" "02/11/2013" "Mosquitto Project" "Conventions and miscellaneous" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- diff -Nru mosquitto-1.1.2/man/mosquitto.8 mosquitto-1.1.3/man/mosquitto.8 --- mosquitto-1.1.2/man/mosquitto.8 2013-01-30 20:29:50.000000000 +0000 +++ mosquitto-1.1.3/man/mosquitto.8 2013-02-11 09:00:02.000000000 +0000 @@ -2,12 +2,12 @@ .\" Title: mosquitto .\" Author: [see the "Author" section] .\" Generator: DocBook XSL Stylesheets v1.76.1 -.\" Date: 01/30/2013 +.\" Date: 02/11/2013 .\" Manual: System management commands .\" Source: Mosquitto Project .\" Language: English .\" -.TH "MOSQUITTO" "8" "01/30/2013" "Mosquitto Project" "System management commands" +.TH "MOSQUITTO" "8" "02/11/2013" "Mosquitto Project" "System management commands" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- diff -Nru mosquitto-1.1.2/man/mosquitto.conf.5 mosquitto-1.1.3/man/mosquitto.conf.5 --- mosquitto-1.1.2/man/mosquitto.conf.5 2013-01-30 20:29:50.000000000 +0000 +++ mosquitto-1.1.3/man/mosquitto.conf.5 2013-02-11 09:00:02.000000000 +0000 @@ -2,12 +2,12 @@ .\" Title: mosquitto.conf .\" Author: [see the "Author" section] .\" Generator: DocBook XSL Stylesheets v1.76.1 -.\" Date: 01/30/2013 +.\" Date: 02/11/2013 .\" Manual: File formats and conventions .\" Source: Mosquitto Project .\" Language: English .\" -.TH "MOSQUITTO\&.CONF" "5" "01/30/2013" "Mosquitto Project" "File formats and conventions" +.TH "MOSQUITTO\&.CONF" "5" "02/11/2013" "Mosquitto Project" "File formats and conventions" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- diff -Nru mosquitto-1.1.2/man/mosquitto_passwd.1 mosquitto-1.1.3/man/mosquitto_passwd.1 --- mosquitto-1.1.2/man/mosquitto_passwd.1 2013-01-30 20:29:50.000000000 +0000 +++ mosquitto-1.1.3/man/mosquitto_passwd.1 2013-02-11 09:00:02.000000000 +0000 @@ -2,12 +2,12 @@ .\" Title: mosquitto_passwd .\" Author: [see the "Author" section] .\" Generator: DocBook XSL Stylesheets v1.76.1 -.\" Date: 01/30/2013 +.\" Date: 02/11/2013 .\" Manual: Commands .\" Source: Mosquitto Project .\" Language: English .\" -.TH "MOSQUITTO_PASSWD" "1" "01/30/2013" "Mosquitto Project" "Commands" +.TH "MOSQUITTO_PASSWD" "1" "02/11/2013" "Mosquitto Project" "Commands" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- diff -Nru mosquitto-1.1.2/man/mosquitto_pub.1 mosquitto-1.1.3/man/mosquitto_pub.1 --- mosquitto-1.1.2/man/mosquitto_pub.1 2013-01-30 20:29:50.000000000 +0000 +++ mosquitto-1.1.3/man/mosquitto_pub.1 2013-02-11 09:00:02.000000000 +0000 @@ -2,12 +2,12 @@ .\" Title: mosquitto_pub .\" Author: [see the "Author" section] .\" Generator: DocBook XSL Stylesheets v1.76.1 -.\" Date: 01/30/2013 +.\" Date: 02/11/2013 .\" Manual: Commands .\" Source: Mosquitto Project .\" Language: English .\" -.TH "MOSQUITTO_PUB" "1" "01/30/2013" "Mosquitto Project" "Commands" +.TH "MOSQUITTO_PUB" "1" "02/11/2013" "Mosquitto Project" "Commands" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- diff -Nru mosquitto-1.1.2/man/mosquitto_sub.1 mosquitto-1.1.3/man/mosquitto_sub.1 --- mosquitto-1.1.2/man/mosquitto_sub.1 2013-01-30 20:29:50.000000000 +0000 +++ mosquitto-1.1.3/man/mosquitto_sub.1 2013-02-11 09:00:02.000000000 +0000 @@ -2,12 +2,12 @@ .\" Title: mosquitto_sub .\" Author: [see the "Author" section] .\" Generator: DocBook XSL Stylesheets v1.76.1 -.\" Date: 01/30/2013 +.\" Date: 02/11/2013 .\" Manual: Commands .\" Source: Mosquitto Project .\" Language: English .\" -.TH "MOSQUITTO_SUB" "1" "01/30/2013" "Mosquitto Project" "Commands" +.TH "MOSQUITTO_SUB" "1" "02/11/2013" "Mosquitto Project" "Commands" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- diff -Nru mosquitto-1.1.2/man/mqtt.7 mosquitto-1.1.3/man/mqtt.7 --- mosquitto-1.1.2/man/mqtt.7 2013-01-30 20:29:50.000000000 +0000 +++ mosquitto-1.1.3/man/mqtt.7 2013-02-11 09:00:02.000000000 +0000 @@ -2,12 +2,12 @@ .\" Title: mqtt .\" Author: [see the "Author" section] .\" Generator: DocBook XSL Stylesheets v1.76.1 -.\" Date: 01/30/2013 +.\" Date: 02/11/2013 .\" Manual: Conventions and miscellaneous .\" Source: Mosquitto Project .\" Language: English .\" -.TH "MQTT" "7" "01/30/2013" "Mosquitto Project" "Conventions and miscellaneous" +.TH "MQTT" "7" "02/11/2013" "Mosquitto Project" "Conventions and miscellaneous" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- diff -Nru mosquitto-1.1.2/src/Makefile mosquitto-1.1.3/src/Makefile --- mosquitto-1.1.2/src/Makefile 2013-01-30 20:29:50.000000000 +0000 +++ mosquitto-1.1.3/src/Makefile 2013-02-11 09:00:02.000000000 +0000 @@ -87,7 +87,7 @@ ${CC} $^ -o $@ ${LDFLAGS} $(PASSWD_LIBS) mosquitto_passwd.o : mosquitto_passwd.c - ${CC} $(CFLAGS) -c $< -o $@ + ${CC} $(CFLAGS) ${CPPFLAGS} -c $< -o $@ install : all $(INSTALL) -d ${DESTDIR}$(prefix)/sbin diff -Nru mosquitto-1.1.2/src/mosquitto_passwd.c mosquitto-1.1.3/src/mosquitto_passwd.c --- mosquitto-1.1.2/src/mosquitto_passwd.c 2013-01-30 20:29:50.000000000 +0000 +++ mosquitto-1.1.3/src/mosquitto_passwd.c 2013-02-11 09:00:02.000000000 +0000 @@ -43,6 +43,7 @@ # define false 0 # endif # define snprintf sprintf_s +# include #else # include # include @@ -52,8 +53,6 @@ #define MAX_BUFFER_LEN 1024 #define SALT_LEN 12 -static char temp_file[100]; - int base64_encode(unsigned char *in, unsigned int in_len, char **encoded) { BIO *bmem, *b64; @@ -157,7 +156,7 @@ return 0; } -int delete_pwuser(FILE *fptr, FILE *fnew, const char *username) +int delete_pwuser(FILE *fptr, FILE *ftmp, const char *username) { char buf[MAX_BUFFER_LEN]; char lbuf[MAX_BUFFER_LEN], *token; @@ -167,7 +166,7 @@ memcpy(lbuf, buf, MAX_BUFFER_LEN); token = strtok(lbuf, ":"); if(strcmp(username, token)){ - fprintf(fnew, "%s", buf); + fprintf(ftmp, "%s", buf); }else{ found = true; } @@ -178,7 +177,7 @@ return 0; } -int update_file(FILE *fptr, FILE *fnew) +int update_file(FILE *fptr, FILE *ftmp) { char buf[MAX_BUFFER_LEN]; char lbuf[MAX_BUFFER_LEN]; @@ -190,16 +189,16 @@ username = strtok(lbuf, ":"); password = strtok(NULL, ":"); if(password){ - rc = output_new_password(fnew, username, password); + rc = output_new_password(ftmp, username, password); if(rc) return rc; }else{ - fprintf(fnew, "%s", username); + fprintf(ftmp, "%s", username); } } return 0; } -int update_pwuser(FILE *fptr, FILE *fnew, const char *username, const char *password) +int update_pwuser(FILE *fptr, FILE *ftmp, const char *username, const char *password) { char buf[MAX_BUFFER_LEN]; char lbuf[MAX_BUFFER_LEN], *token; @@ -210,16 +209,16 @@ memcpy(lbuf, buf, MAX_BUFFER_LEN); token = strtok(lbuf, ":"); if(strcmp(username, token)){ - fprintf(fnew, "%s", buf); + fprintf(ftmp, "%s", buf); }else{ - rc = output_new_password(fnew, username, password); + rc = output_new_password(ftmp, username, password); found = true; } } if(found){ return rc; }else{ - return output_new_password(fnew, username, password); + return output_new_password(ftmp, username, password); } } @@ -303,6 +302,51 @@ return 0; } +int copy_contents(FILE *src, FILE *dest) +{ + char buf[MAX_BUFFER_LEN]; + int len; + + rewind(src); + rewind(dest); + +#ifdef WIN32 + _chsize(fileno(dest), 0); +#else + if(ftruncate(fileno(dest), 0)) return 1; +#endif + + while(!feof(src)){ + len = fread(buf, 1, MAX_BUFFER_LEN, src); + if(len > 0){ + if(fwrite(buf, 1, len, dest) != len){ + return 1; + } + }else{ + return !feof(src); + } + } + return 0; +} + +int create_backup(const char *backup_file, FILE *fptr) +{ + FILE *fbackup; + + fbackup = fopen(backup_file, "wt"); + if(!fbackup){ + fprintf(stderr, "Error creating backup password file \"%s\", not continuing.\n", backup_file); + return 1; + } + if(copy_contents(fptr, fbackup)){ + fprintf(stderr, "Error copying data to backup password file \"%s\", not continuing.\n", backup_file); + fclose(fbackup); + return 1; + } + fclose(fbackup); + rewind(fptr); + return 0; +} void handle_sigint(int signal) { #ifndef WIN32 @@ -312,10 +356,6 @@ ts.c_lflag |= ECHO | ICANON; tcsetattr(0, TCSANOW, &ts); #endif - if(temp_file[0] != '\0'){ - /* Temp file may have been created, so delete it. */ - unlink(temp_file); - } exit(0); } @@ -325,12 +365,12 @@ char *username = NULL; bool create_new = false; bool delete_user = false; - FILE *fptr, *fnew; + FILE *fptr, *ftmp; char password[MAX_BUFFER_LEN]; int rc; bool do_update_file = false; + char *backup_file; - memset(temp_file, 0, 100); signal(SIGINT, handle_sigint); signal(SIGTERM, handle_sigint); @@ -367,36 +407,69 @@ } rc = output_new_password(fptr, username, password); fclose(fptr); + return rc; }else{ - snprintf(temp_file, 100, "mosquitto_passwd_tmp.%d", getpid()); - fptr = fopen(password_file, "rt"); + fptr = fopen(password_file, "r+t"); if(!fptr){ - fprintf(stderr, "Error: Unable to open file %s for reading.\n", password_file); + fprintf(stderr, "Error: Unable to open password file %s.\n", password_file); + return 1; + } + + backup_file = malloc(strlen(password_file)+5); + snprintf(backup_file, strlen(password_file)+5, "%s.tmp", password_file); + + if(create_backup(backup_file, fptr)){ + fclose(fptr); + free(backup_file); return 1; } - fnew = fopen(temp_file, "wt"); - if(!fnew){ - fprintf(stderr, "Error: Unable to open file %s for writing.\n", temp_file); + + ftmp = tmpfile(); + if(!ftmp){ + fprintf(stderr, "Error: Unable to open temporary file.\n"); fclose(fptr); + free(backup_file); return 1; } if(delete_user){ - rc = delete_pwuser(fptr, fnew, username); + rc = delete_pwuser(fptr, ftmp, username); }else if(do_update_file){ - rc = update_file(fptr, fnew); + rc = update_file(fptr, ftmp); }else{ rc = get_password(password, 1024); - if(rc) return rc; + if(rc){ + fclose(fptr); + fclose(ftmp); + unlink(backup_file); + free(backup_file); + return rc; + } /* Update password for individual user */ - rc = update_pwuser(fptr, fnew, username, password); + rc = update_pwuser(fptr, ftmp, username, password); } - fclose(fptr); - fclose(fnew); - if(!rc){ - rename(temp_file, password_file); - }else{ - fprintf(stderr, "Error occurred, not updating password file.\n"); + if(rc){ + fclose(fptr); + fclose(ftmp); + unlink(backup_file); + free(backup_file); + return rc; + } + + if(copy_contents(ftmp, fptr)){ + fclose(fptr); + fclose(ftmp); + fprintf(stderr, "Error occurred updating password file.\n"); + fprintf(stderr, "Password file may be corrupt, check the backup file: %s.\n", backup_file); + free(backup_file); + return 1; } + fclose(fptr); + fclose(ftmp); + + /* Everything was ok so backup no longer needed. May contain old + * passwords so shouldn't be kept around. */ + unlink(backup_file); + free(backup_file); } return 0;