diff options
author | Milan Broz <gmazyland@gmail.com> | 2015-08-26 10:51:42 +0200 |
---|---|---|
committer | Milan Broz <gmazyland@gmail.com> | 2015-08-26 10:54:33 +0200 |
commit | ab62f45d570130bdd9f17a917e8ec49c004bc17d (patch) | |
tree | 5b59c0267a8fff1e8822524ff107028319285f39 | |
parent | e521edd6ca0a0a4f371abdc96bf167c76c4e8d89 (diff) | |
download | cryptsetup-ab62f45d570130bdd9f17a917e8ec49c004bc17d.tar.gz |
Use stdin and "-" file check wrapper.
-rw-r--r-- | src/cryptsetup.c | 14 | ||||
-rw-r--r-- | src/cryptsetup.h | 1 | ||||
-rw-r--r-- | src/utils_password.c | 11 |
3 files changed, 17 insertions, 9 deletions
diff --git a/src/cryptsetup.c b/src/cryptsetup.c index 78f7313..e8c0a3b 100644 --- a/src/cryptsetup.c +++ b/src/cryptsetup.c @@ -124,7 +124,6 @@ static int action_open_plain(void) size_t passwordLen; size_t key_size = (opt_key_size ?: DEFAULT_PLAIN_KEYBITS) / 8; uint32_t activate_flags = 0; - int keyfile_limited = 0; int r; r = crypt_parse_name_and_mode(opt_cipher ?: DEFAULT_CIPHER(PLAIN), @@ -134,11 +133,8 @@ static int action_open_plain(void) goto out; } - if (opt_key_file && strcmp(opt_key_file, "-") != 0) - keyfile_limited = 1; - /* FIXME: temporary hack, no hashing for keyfiles in plain mode */ - if (opt_key_file && keyfile_limited) { + if (opt_key_file && !tools_is_stdin(opt_key_file)) { params.hash = NULL; if (!opt_batch_mode && opt_hash) log_std(_("WARNING: The --hash parameter is being ignored " @@ -148,7 +144,7 @@ static int action_open_plain(void) if (params.hash && !strcmp(params.hash, "plain")) params.hash = NULL; - if (!opt_batch_mode && !params.hash && opt_key_file && keyfile_limited && opt_keyfile_size) + if (!opt_batch_mode && !params.hash && opt_key_file && !tools_is_stdin(opt_key_file) && opt_keyfile_size) log_std(_("WARNING: The --keyfile-size option is being ignored, " "the read size is the same as the encryption key size.\n")); @@ -172,7 +168,7 @@ static int action_open_plain(void) _set_activation_flags(&activate_flags); - if (opt_key_file) { + if (!tools_is_stdin(opt_key_file)) { /* If no hash, key is read directly, read size is always key_size * (possible opt_keyfile_size is ignored. * If hash is specified, opt_keyfile_size is applied. @@ -185,8 +181,8 @@ static int action_open_plain(void) } else { r = tools_get_key(_("Enter passphrase: "), &password, &passwordLen, - opt_keyfile_offset, opt_keyfile_size, - NULL, opt_timeout, + opt_keyfile_offset, (opt_key_file && !params.hash) ? key_size : opt_keyfile_size, + opt_key_file, opt_timeout, _verify_passphrase(0), 0, cd); if (r < 0) diff --git a/src/cryptsetup.h b/src/cryptsetup.h index 5d322cf..fd73d55 100644 --- a/src/cryptsetup.h +++ b/src/cryptsetup.h @@ -81,6 +81,7 @@ int tools_get_key(const char *prompt, const char *key_file, int timeout, int verify, int pwquality, struct crypt_device *cd); +int tools_is_stdin(const char *key_file); /* Log */ #define log_dbg(x...) clogger(NULL, CRYPT_LOG_DEBUG, __FILE__, __LINE__, x) diff --git a/src/utils_password.c b/src/utils_password.c index 541806c..8ea07df 100644 --- a/src/utils_password.c +++ b/src/utils_password.c @@ -65,6 +65,17 @@ static int tools_check_pwquality(const char *password) } #endif /* ENABLE_PWQUALITY */ +/* + * Keyfile - is standard input treated as a binary file (no EOL handling). + */ +int tools_is_stdin(const char *key_file) +{ + if (!key_file) + return 1; + + return strcmp(key_file, "-") ? 0 : 1; +} + int tools_get_key(const char *prompt, char **key, size_t *key_size, size_t keyfile_offset, size_t keyfile_size_max, |