diff --git a/apps/mosquitto_passwd/get_password.c b/apps/mosquitto_passwd/get_password.c index b25cdf09a..e2539733b 100644 --- a/apps/mosquitto_passwd/get_password.c +++ b/apps/mosquitto_passwd/get_password.c @@ -79,17 +79,16 @@ static int gets_quiet(char *s, int len) return 0; #else - struct termios ts_quiet, ts_orig; + struct termios ts_quiet; char *rs; memset(s, 0, (size_t)len); - tcgetattr(0, &ts_orig); - ts_quiet = ts_orig; + tcgetattr(0, &ts_quiet); ts_quiet.c_lflag &= (unsigned int)(~(ECHO | ICANON)); tcsetattr(0, TCSANOW, &ts_quiet); rs = fgets(s, len, stdin); - tcsetattr(0, TCSANOW, &ts_orig); + get_password__reset_term(); if(!rs){ return 1; diff --git a/apps/mosquitto_passwd/mosquitto_passwd.c b/apps/mosquitto_passwd/mosquitto_passwd.c index bfba5bd6e..7ffe37d48 100644 --- a/apps/mosquitto_passwd/mosquitto_passwd.c +++ b/apps/mosquitto_passwd/mosquitto_passwd.c @@ -107,13 +107,6 @@ static FILE *mpw_tmpfile(void) } #endif -int log__printf(void *mosq, unsigned int level, const char *fmt, ...) -{ - /* Stub for misc_mosq.c */ - UNUSED(mosq); UNUSED(level); UNUSED(fmt); return 0; -} - - static void print_usage(void) { printf("mosquitto_passwd is a tool for managing password files for mosquitto.\n\n"); @@ -205,16 +198,14 @@ static int pwfile_iterate(FILE *fptr, FILE *ftmp, line++; username = strtok(buf, ":"); password = strtok(NULL, ":"); - if(username == NULL || password == NULL){ - fprintf(stderr, "Error: Corrupt password file at line %d.\n", line); - free(lbuf); - free(buf); - return 1; + if(username && password){ + username = misc__trimblanks(username); + password = misc__trimblanks(password); } - username = misc__trimblanks(username); - password = misc__trimblanks(password); - if(strlen(username) == 0 || strlen(password) == 0){ + if(username == NULL || strlen(username) == 0 + || password == NULL || strlen(password) == 0){ + fprintf(stderr, "Error: Corrupt password file at line %d.\n", line); free(lbuf); free(buf); @@ -370,10 +361,6 @@ static int create_backup(char *backup_file, FILE *fptr) int fd; umask(077); fd = mkstemp(backup_file); - if(fd < 0){ - fprintf(stderr, "Error creating backup password file \"%s\", not continuing.\n", backup_file); - return 1; - } fbackup = fdopen(fd, "wt"); #endif if(!fbackup){ @@ -660,15 +647,10 @@ int main(int argc, char *argv[]) rc = update_pwuser(fptr, ftmp, username, password_cmd, iterations); }else{ rc = get_password("Password: ", "Reenter password: ", false, password, MAX_BUFFER_LEN); - if(rc){ - fclose(fptr); - fclose(ftmp); - unlink(backup_file); - free(backup_file); - return rc; + if(rc == 0){ + /* Update password for individual user */ + rc = update_pwuser(fptr, ftmp, username, password, iterations); } - /* Update password for individual user */ - rc = update_pwuser(fptr, ftmp, username, password, iterations); } } if(rc){ @@ -680,19 +662,18 @@ int main(int argc, char *argv[]) } 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; + rc = 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); + if(rc == 0){ + /* Everything was ok so backup no longer needed. May contain old + * passwords so shouldn't be kept around. */ + unlink(backup_file); + } free(backup_file); } diff --git a/client/client_props.c b/client/client_props.c index 7a5406438..59091bf04 100644 --- a/client/client_props.c +++ b/client/client_props.c @@ -125,10 +125,6 @@ int cfg_parse_property(struct mosq_config *cfg, int argc, char *argv[], int *idx break; case CMD_SUBSCRIBE: - if(identifier != MQTT_PROP_SUBSCRIPTION_IDENTIFIER && identifier != MQTT_PROP_USER_PROPERTY){ - fprintf(stderr, "Error: %s property not supported for %s in --property argument.\n\n", propname, cmdname); - return MOSQ_ERR_NOT_SUPPORTED; - } proplist = &cfg->subscribe_props; break; diff --git a/client/client_shared.c b/client/client_shared.c index 106731b7f..ff94e9968 100644 --- a/client/client_shared.c +++ b/client/client_shared.c @@ -511,37 +511,6 @@ int client_config_load(struct mosq_config *cfg, int pub_or_sub, int argc, char * } } - rc = mosquitto_property_check_all(CMD_CONNECT, cfg->connect_props); - if(rc){ - err_printf(cfg, "Error in CONNECT properties: %s\n", mosquitto_strerror(rc)); - return 1; - } - rc = mosquitto_property_check_all(CMD_PUBLISH, cfg->publish_props); - if(rc){ - err_printf(cfg, "Error in PUBLISH properties: %s\n", mosquitto_strerror(rc)); - return 1; - } - rc = mosquitto_property_check_all(CMD_SUBSCRIBE, cfg->subscribe_props); - if(rc){ - err_printf(cfg, "Error in SUBSCRIBE properties: %s\n", mosquitto_strerror(rc)); - return 1; - } - rc = mosquitto_property_check_all(CMD_UNSUBSCRIBE, cfg->unsubscribe_props); - if(rc){ - err_printf(cfg, "Error in UNSUBSCRIBE properties: %s\n", mosquitto_strerror(rc)); - return 1; - } - rc = mosquitto_property_check_all(CMD_DISCONNECT, cfg->disconnect_props); - if(rc){ - err_printf(cfg, "Error in DISCONNECT properties: %s\n", mosquitto_strerror(rc)); - return 1; - } - rc = mosquitto_property_check_all(CMD_WILL, cfg->will_props); - if(rc){ - err_printf(cfg, "Error in Will properties: %s\n", mosquitto_strerror(rc)); - return 1; - } - return MOSQ_ERR_SUCCESS; } @@ -920,12 +889,7 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c } cfg->eol = false; }else if(!strcmp(argv[i], "-o")){ - if(i==argc-1){ - fprintf(stderr, "Error: -o argument given but no options file specified.\n\n"); - return 1; - }else{ - /* Already handled */ - } + /* Already handled */ i++; }else if(!strcmp(argv[i], "-p") || !strcmp(argv[i], "--port")){ if(i==argc-1){ diff --git a/client/rr_client.c b/client/rr_client.c index aec0e69e6..ffb432be8 100644 --- a/client/rr_client.c +++ b/client/rr_client.c @@ -136,18 +136,6 @@ static void my_subscribe_callback(struct mosquitto *mosq, void *obj, int mid, in } -void my_publish_callback(struct mosquitto *mosq, void *obj, int mid, int reason_code, const mosquitto_property *properties) -{ - UNUSED(mosq); - UNUSED(obj); - UNUSED(mid); - UNUSED(reason_code); - UNUSED(properties); - - client_state = rr_s_wait_for_response; -} - - static void print_version(void) { int major, minor, revision; diff --git a/test/apps/passwd/passwd-changes.py b/test/apps/passwd/passwd-changes.py index eab4d6984..6edd14cf2 100755 --- a/test/apps/passwd/passwd-changes.py +++ b/test/apps/passwd/passwd-changes.py @@ -18,18 +18,19 @@ def client_check(port, username, password, rc): sock.close() -def passwd_cmd(args, port, response=None, input=None): +def passwd_cmd(args, port, response=None, input=None, expected_rc=0): proc = subprocess.run([mosq_test.get_build_root()+"/apps/mosquitto_passwd/mosquitto_passwd"] + args, capture_output=True, encoding='utf-8', timeout=2, input=input) if response is not None: - if proc.stdout != response: - print(len(proc.stdout)) - print(len(response)) + if proc.stdout != response and proc.stderr != response: + print(f"stdout: {proc.stdout}") + print(f"stderr: {proc.stderr}") + print(f"expected: {response}") raise ValueError(proc.stdout) - if proc.returncode != 0: + if proc.returncode != expected_rc: raise ValueError(args) @@ -91,6 +92,7 @@ try: # Delete user passwd_cmd(["-D", pw_file, "user2"], port) + passwd_cmd(["-D", pw_file, "user2"], port, response="Warning: User user2 not found in password file.\n", expected_rc=1) broker.send_signal(signal.SIGHUP) client_check(port, "user1", "badpass", 5) diff --git a/test/client/02-subscribe-argv-errors-without-tls.py b/test/client/02-subscribe-argv-errors-without-tls.py index 54247cd38..5e5a68016 100755 --- a/test/client/02-subscribe-argv-errors-without-tls.py +++ b/test/client/02-subscribe-argv-errors-without-tls.py @@ -104,6 +104,8 @@ if __name__ == '__main__': do_test(['-V', '5', '-D', 'subscribe', 'subscription-identifier', '-1'], "Error: Property value (-1) out of range for property subscription-identifier.\n\n" + helps, 1) do_test(['-V', '5', '-D', 'subscribe', 'subscription-identifier', '4294967296'], "Error: Property value (4294967296) out of range for property subscription-identifier.\n\n" + helps, 1) do_test(['-V', '5', '-D', 'subscribe', 'topic-alias', '1'], "Error: topic-alias property not allowed for subscribe in --property argument.\n\n" + helps, 1) + do_test(['-V', '5', '-D', 'auth', 'authentication-method', '1'], "Error: authentication-method property not supported for auth in --property argument.\n\n" + helps, 1) + do_test(['-V', '5', '-D', 'puback', 'reason-string', '1'], "Error: reason-string property not supported for puback in --property argument.\n\n" + helps, 1) do_test(['-T', '++'], "Error: Invalid filter topic '++', are all '+' and '#' wildcards correct?\n" + helps, 1) do_test(['-U', '++'], "Error: Invalid unsubscribe topic '++', are all '+' and '#' wildcards correct?\n" + helps, 1) do_test(['-V', '0'], "Error: Invalid protocol version argument given.\n\n" + helps, 1) diff --git a/test/client/03-publish-argv-errors-without-tls.py b/test/client/03-publish-argv-errors-without-tls.py index 5a1dac55a..4a2b1fe5a 100755 --- a/test/client/03-publish-argv-errors-without-tls.py +++ b/test/client/03-publish-argv-errors-without-tls.py @@ -101,6 +101,7 @@ if __name__ == '__main__': do_test(['-V', '5', '-D', 'connect', 'receive-maximum', '65536'], "Error: Property value (65536) out of range for property receive-maximum.\n\n" + helps, 1) do_test(['-V', '5', '-D', 'connect', 'session-expiry-interval', '-1'], "Error: Property value (-1) out of range for property session-expiry-interval.\n\n" + helps, 1) do_test(['-V', '5', '-D', 'connect', 'session-expiry-interval', '4294967296'], "Error: Property value (4294967296) out of range for property session-expiry-interval.\n\n" + helps, 1) + do_test(['-V', '5', '-D', 'connect', 'subscription-identifier', '1'], "Error: subscription-identifier property not allowed for connect in --property argument.\n\n" + helps, 1) do_test(['-V', '5', '-D', 'publish', 'subscription-identifier', '1'], "Error: subscription-identifier property not supported for publish in --property argument.\n\n" + helps, 1) # Unknown options diff --git a/test/client/03-publish-socks.py b/test/client/03-publish-socks.py index 449485c55..4f787bba5 100755 --- a/test/client/03-publish-socks.py +++ b/test/client/03-publish-socks.py @@ -16,7 +16,7 @@ def do_test(proto_ver, host): print("microsocks not found, skipping test") sys.exit(0) - cmd = ['microsocks', '-1', '-i', host, '-u', 'user', '-P', 'password', '-p', str(port1)] + cmd = ['microsocks', '-1', '-i', host, '-u', 'user', '-P', 'pass:word', '-p', str(port1)] if b"bindaddr" in proxy.stderr: cmd += ['-b', host] else: @@ -47,7 +47,7 @@ def do_test(proto_ver, host): '-t', '03/pub/proxy/test', '-m', 'message', '-V', V, - '--proxy', f'socks5h://user:password@{host}:{port1}' + '--proxy', f'socks5h://user:pass%3Aword@{host}:{port1}' ] mid = 1