Commit c80dbb22 authored by Milan Broz's avatar Milan Broz

Fxi luksKill slot to work in batch mode in non-tty environment.

If there is no TTY on stdin (like nohup or service) then
batch mode should not fail to kill slot.

For more info see Issue#329.
parent ce1e5374
......@@ -302,6 +302,7 @@ int crypt_keyfile_read(struct crypt_device *cd, const char *keyfile,
char_read = read(fd, &pass[i], 1);
if (char_read < 0) {
log_err(cd, _("Error reading passphrase.\n"));
r = -EPIPE;
goto out_err;
}
......
......@@ -933,6 +933,12 @@ static int action_luksKillSlot(void)
_("This is the last keyslot. Device will become unusable after purging this key."),
_("Enter any remaining passphrase: "),
opt_key_file, opt_keyfile_offset, opt_keyfile_size);
if (r == -EPIPE && (!opt_key_file || tools_is_stdin(opt_key_file))) {
log_dbg("Failed read from input, ignoring passphrase.");
r = 0;
}
if (r < 0)
goto out;
}
......
......@@ -354,6 +354,8 @@ prepare "[18] RemoveKey passphrase and keyfile" reuse
$CRYPTSETUP luksRemoveKey $LOOPDEV $KEY1 || fail
$CRYPTSETUP luksDump $LOOPDEV | grep -q "Key Slot 3: DISABLED" || fail
$CRYPTSETUP luksRemoveKey $LOOPDEV $KEY1 2>/dev/null && fail
$CRYPTSETUP luksAddKey $LOOPDEV -i1 -d $KEY2 $KEY1 --key-slot 3 2>/dev/null || fail
$CRYPTSETUP luksDump $LOOPDEV | grep -q "Key Slot 3: ENABLED" || fail
$CRYPTSETUP luksRemoveKey $LOOPDEV $KEY2 --keyfile-size 1 2>/dev/null && fail
$CRYPTSETUP luksRemoveKey $LOOPDEV $KEY2 || fail
$CRYPTSETUP luksDump $LOOPDEV | grep -q "Key Slot 4: DISABLED" || fail
......@@ -366,6 +368,9 @@ $CRYPTSETUP luksDump $LOOPDEV | grep -q "Key Slot 2: ENABLED" || fail
# kill slot using passphrase from 1
echo $PWD2 | $CRYPTSETUP luksKillSlot $LOOPDEV 2 || fail
$CRYPTSETUP luksDump $LOOPDEV | grep -q "Key Slot 2: DISABLED" || fail
# kill slot with redirected stdin
$CRYPTSETUP luksKillSlot $LOOPDEV 3 </dev/null || fail
$CRYPTSETUP luksDump $LOOPDEV | grep -q "Key Slot 3: DISABLED" || fail
# remove key0 / slot 0
echo $PWD1 | $CRYPTSETUP luksRemoveKey $LOOPDEV || fail
$CRYPTSETUP luksDump $LOOPDEV | grep -q "Key Slot 0: DISABLED" || 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