From 04fd9b3208e4e8d9697594477ad15d2bf648ee0a Mon Sep 17 00:00:00 2001 From: Clemens Fruhwirth Date: Sun, 5 Apr 2009 17:21:03 +0000 Subject: [PATCH] Should fix Issue 5. git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@49 36d66b0a-2a48-0410-832c-cd162a569da5 --- lib/setup.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/setup.c b/lib/setup.c index e8aca8a..be39f13 100644 --- a/lib/setup.c +++ b/lib/setup.c @@ -256,13 +256,13 @@ static int parse_into_name_and_mode(const char *nameAndMode, char *name, } /* Select free keyslot or verifies that the one specified is empty */ -static int keyslot_from_option(int keySlotOption, struct luks_phdr *hdr) { - if(keySlotOption != -1) { +static int keyslot_from_option(int keySlotOption, struct luks_phdr *hdr, struct crypt_options *options) { + if(keySlotOption >= 0) { if(keySlotOption >= LUKS_NUMKEYS) { - set_error("slot %d too high, please pick between 0 and %d", keySlotOption, LUKS_NUMKEYS); + logger(options,CRYPT_LOG_ERROR,"slot %d too high, please pick between 0 and %d", keySlotOption, LUKS_NUMKEYS); return -EINVAL; } else if(hdr->keyblock[keySlotOption].active != LUKS_KEY_DISABLED) { - set_error("slot %d full, please pick another one", keySlotOption); + logger(options,CRYPT_LOG_ERROR,"slot %d full, please pick another one", keySlotOption); return -EINVAL; } else { return keySlotOption; @@ -274,7 +274,7 @@ static int keyslot_from_option(int keySlotOption, struct luks_phdr *hdr) { if(hdr->keyblock[i].active == LUKS_KEY_DISABLED) break; } if(i==LUKS_NUMKEYS) { - set_error("All slots full"); + logger(options,CRYPT_LOG_ERROR,"All slots full"); return -EINVAL; } return i; @@ -475,7 +475,10 @@ static int __crypt_luks_format(int arg, struct setup_backend *backend, struct cr return r; } - keyIndex = keyslot_from_option(options->key_slot, &header); + keyIndex = keyslot_from_option(options->key_slot, &header, options); + if(keyIndex == -EINVAL) { + r = -EINVAL; goto out; + } PBKDF2perSecond = LUKS_benchmarkt_iterations(); header.keyblock[keyIndex].passwordIterations = at_least_one(PBKDF2perSecond * ((float)options->iteration_time / 1000.0)); @@ -608,7 +611,10 @@ static int __crypt_luks_add_key(int arg, struct setup_backend *backend, struct c if(r < 0) return r; - keyIndex = keyslot_from_option(options->key_slot, &hdr); + keyIndex = keyslot_from_option(options->key_slot, &hdr, options); + if(keyIndex == -EINVAL) { + r = -EINVAL; goto out; + } get_key("Enter any LUKS passphrase: ", &password, -- 2.7.4