X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fcryptsetup%2Fcryptsetup.c;h=916509ab93481b17b3ddd30077f89e759f12c113;hb=dfcc5c33f42554a5293e68e7093da2403e363997;hp=b26fcca836993c73019f56f351793bf8f8ad3354;hpb=2a2aab602e1d8b6bf0b440730e379f9dd6586b80;p=elogind.git diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c index b26fcca83..916509ab9 100644 --- a/src/cryptsetup/cryptsetup.c +++ b/src/cryptsetup/cryptsetup.c @@ -37,6 +37,8 @@ static const char *opt_type = NULL; /* LUKS1 or PLAIN */ static char *opt_cipher = NULL; static unsigned opt_key_size = 0; +static unsigned opt_keyfile_size = 0; +static unsigned opt_keyfile_offset = 0; static char *opt_hash = NULL; static unsigned opt_tries = 0; static bool opt_readonly = false; @@ -79,6 +81,20 @@ static int parse_one_option(const char *option) { return 0; } + } else if (startswith(option, "keyfile-size=")) { + + if (safe_atou(option+13, &opt_keyfile_size) < 0) { + log_error("keyfile-size= parse failure, ignoring."); + return 0; + } + + } else if (startswith(option, "keyfile-offset=")) { + + if (safe_atou(option+15, &opt_keyfile_offset) < 0) { + log_error("keyfile-offset= parse failure, ignoring."); + return 0; + } + } else if (startswith(option, "hash=")) { char *t; @@ -230,7 +246,6 @@ int main(int argc, char *argv[]) { char **passwords = NULL, *truncated_cipher = NULL; const char *cipher = NULL, *cipher_mode = NULL, *hash = NULL, *name = NULL; char *description = NULL, *name_buffer = NULL, *mount_point = NULL; - unsigned keyfile_size = 0; if (argc <= 1) { help(); @@ -335,7 +350,7 @@ int main(int argc, char *argv[]) { l = strcspn(opt_cipher, "-"); if (!(truncated_cipher = strndup(opt_cipher, l))) { - log_error("Out of memory"); + log_oom(); goto finish; } @@ -357,7 +372,7 @@ int main(int argc, char *argv[]) { char **p; if (asprintf(&text, "Please enter passphrase for disk %s!", name) < 0) { - log_error("Out of memory"); + log_oom(); goto finish; } @@ -375,7 +390,7 @@ int main(int argc, char *argv[]) { assert(strv_length(passwords) == 1); if (asprintf(&text, "Please enter passphrase for disk %s! (verification)", name) < 0) { - log_error("Out of memory"); + log_oom(); goto finish; } @@ -408,7 +423,7 @@ int main(int argc, char *argv[]) { /* Pad password if necessary */ if (!(c = new(char, opt_key_size))) { - log_error("Out of memory."); + log_oom(); goto finish; } @@ -429,6 +444,11 @@ int main(int argc, char *argv[]) { zero(params); params.hash = hash; + /* for CRYPT_PLAIN limit reads + * from keyfile to key length, and + * ignore keyfile-size */ + opt_keyfile_size = opt_key_size / 8; + /* In contrast to what the name * crypt_setup() might suggest this * doesn't actually format anything, @@ -440,14 +460,10 @@ int main(int argc, char *argv[]) { cipher_mode, NULL, NULL, - opt_key_size / 8, + opt_keyfile_size, ¶ms); pass_volume_key = streq(hash, "plain"); - - /* for CRYPT_PLAIN limit reads - * from keyfile to key length */ - keyfile_size = opt_key_size / 8; } if (k < 0) { @@ -462,7 +478,8 @@ int main(int argc, char *argv[]) { argv[3]); if (key_file) - k = crypt_activate_by_keyfile(cd, argv[2], CRYPT_ANY_SLOT, key_file, keyfile_size, flags); + k = crypt_activate_by_keyfile_offset(cd, argv[2], CRYPT_ANY_SLOT, key_file, opt_keyfile_size, + opt_keyfile_offset, flags); else { char **p;