Fail if only one of SSH host and SSH user is set

Remote backup needs both, but if only one was set the program silently
ran a local backup instead, and a missing ssh_user in the config also
dropped ssh_host. Exit with an error (code 6) instead.
This commit is contained in:
Fuxino
2026-10-08 20:31:39 +02:00
parent 9a68a8660d
commit 1dca989310
2 changed files with 10 additions and 10 deletions
+1 -1
View File
@@ -207,7 +207,7 @@ rsync error (rsync returned a value other than 0 or 24).
SSH connection failed.
.TP
.B 6
Bad configuration file.
Bad configuration file or options (for example, only one of SSH host and SSH user specified).
.SH SEE ALSO
.BR rsync (1)
.SH AUTHORS
+9 -9
View File
@@ -806,15 +806,10 @@ def _read_config(config_file, user: Optional[str] = None):
config_args['keep'] = keep
try:
ssh_host = config.get('server', 'ssh_host')
ssh_user = config.get('server', 'ssh_user')
except (configparser.NoSectionError, configparser.NoOptionError):
ssh_host = None
ssh_user = None
config_args['ssh_host'] = ssh_host
config_args['ssh_user'] = ssh_user
# Read host and user separately, so that a missing one is reported instead of silently
# disabling remote backup. Empty values count as not set
config_args['ssh_host'] = config.get('server', 'ssh_host', fallback='').strip() or None
config_args['ssh_user'] = config.get('server', 'ssh_user', fallback='').strip() or None
try:
ssh_keyfile = config.get('server', 'ssh_keyfile')
@@ -947,6 +942,11 @@ def simple_backup() -> int:
ssh_host = args.ssh_host if args.ssh_host is not None else config_args['ssh_host']
ssh_user = args.ssh_user if args.ssh_user is not None else config_args['ssh_user']
if (ssh_host is None) != (ssh_user is None):
logger.critical('Both SSH host and SSH user are needed for remote backup')
return 6
if args.output is not None:
output = args.output
else: