Commit 9ae7b7d1 authored by Milan Broz's avatar Milan Broz

Fix regression in header backup (1.5.1).

Access to backup file must handle write to regular files too.
parent 0bd8b982
......@@ -283,7 +283,7 @@ int LUKS_hdr_restore(
log_dbg("Storing backup of header (%u bytes) and keyslot area (%u bytes) to device %s.",
sizeof(*hdr), buffer_size - LUKS_ALIGN_KEYSLOTS, device_path(device));
devfd = open(device_path(device), O_WRONLY | O_DIRECT | O_SYNC);
devfd = open(device_path(device), O_RDWR | O_DIRECT | O_SYNC);
if (devfd == -1) {
if (errno == EACCES)
log_err(ctx, _("Cannot write to device %s, permission denied.\n"),
......
......@@ -97,9 +97,12 @@ ssize_t write_blockwise(int fd, int bsize, void *orig_buf, size_t count)
goto out;
r = read(fd, hangover_buf, bsize);
if (r < 0 || r != bsize)
if (r < 0 || r < hangover)
goto out;
if (r < bsize)
bsize = r;
r = lseek(fd, -bsize, SEEK_CUR);
if (r < 0)
goto out;
......
......@@ -149,10 +149,12 @@ ORG_SHA1=$(sha1sum -b /dev/mapper/$DEV_NAME | cut -f 1 -d' ')
$CRYPTSETUP -q luksClose $DEV_NAME || fail
# Check it can be opened from header backup as well
$CRYPTSETUP luksHeaderBackup $IMG --header-backup-file $HEADER_IMG
$CRYPTSETUP luksHeaderBackup $IMG --header-backup-file $HEADER_IMG || fail
echo "compatkey" | $CRYPTSETUP luksOpen $IMG10 $DEV_NAME --header $HEADER_IMG || fail
check_exists
$CRYPTSETUP -q luksClose $DEV_NAME || fail
# Check restore
$CRYPTSETUP luksHeaderRestore -q $IMG --header-backup-file $HEADER_IMG || fail
# Repeat for V1.0 header - not aligned first keyslot
echo "compatkey" | $CRYPTSETUP luksOpen $IMG10 $DEV_NAME || fail
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment