X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fcryptsetup.c;h=c0caf9a93035e38155cf88f0196721471066ee7a;hb=e9816c4859454d341279f1c9e77df4af4bacd534;hp=506ce9b5c9086bf3d4fec4cd0431affc5bc139ba;hpb=b61e476f510999c687d3c76193a98aa5cd1f9a73;p=elogind.git diff --git a/src/cryptsetup.c b/src/cryptsetup.c index 506ce9b5c..c0caf9a93 100644 --- a/src/cryptsetup.c +++ b/src/cryptsetup.c @@ -31,6 +31,7 @@ #include "util.h" #include "strv.h" #include "ask-password-api.h" +#include "def.h" static const char *opt_type = NULL; /* LUKS1 or PLAIN */ static char *opt_cipher = NULL; @@ -39,7 +40,7 @@ static char *opt_hash = NULL; static unsigned opt_tries = 0; static bool opt_readonly = false; static bool opt_verify = false; -static usec_t opt_timeout = 0; +static usec_t opt_timeout = DEFAULT_TIMEOUT_USEC; /* Options Debian's crypttab knows we don't: @@ -207,12 +208,29 @@ finish: return mp; } +static int help(void) { + + printf("%s attach VOLUME SOURCEDEVICE [PASSWORD] [OPTIONS]\n" + "%s detach VOLUME\n\n" + "Attaches or detaches an encrypted block device.\n", + program_invocation_short_name, + program_invocation_short_name); + + return 0; +} + int main(int argc, char *argv[]) { int r = EXIT_FAILURE; struct crypt_device *cd = NULL; 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(); + return EXIT_SUCCESS; + } if (argc < 3) { log_error("This program requires at least two arguments."); @@ -292,7 +310,10 @@ int main(int argc, char *argv[]) { if (opt_readonly) flags |= CRYPT_ACTIVATE_READONLY; - until = now(CLOCK_MONOTONIC) + (opt_timeout > 0 ? opt_timeout : 60 * USEC_PER_SEC); + if (opt_timeout > 0) + until = now(CLOCK_MONOTONIC) + opt_timeout; + else + until = 0; opt_tries = opt_tries > 0 ? opt_tries : 3; opt_key_size = (opt_key_size > 0 ? opt_key_size : 256); @@ -387,6 +408,8 @@ int main(int argc, char *argv[]) { } } + k = 0; + if (!opt_type || streq(opt_type, CRYPT_LUKS1)) k = crypt_load(cd, CRYPT_LUKS1, NULL); @@ -411,6 +434,10 @@ int main(int argc, char *argv[]) { ¶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) { @@ -425,7 +452,7 @@ int main(int argc, char *argv[]) { argv[3]); if (key_file) - k = crypt_activate_by_keyfile(cd, argv[2], CRYPT_ANY_SLOT, key_file, opt_key_size, flags); + k = crypt_activate_by_keyfile(cd, argv[2], CRYPT_ANY_SLOT, key_file, keyfile_size, flags); else { char **p;