#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;
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:
return 0;
}
- } else
+ } else if (!streq(option, "none"))
log_error("Encountered unknown /etc/crypttab option '%s', ignoring.", option);
return 0;
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.");
log_parse_environment();
log_open();
+ umask(0022);
+
if (streq(argv[1], "attach")) {
uint32_t flags = 0;
int k;
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);
}
}
+ k = 0;
+
if (!opt_type || streq(opt_type, CRYPT_LUKS1))
k = crypt_load(cd, CRYPT_LUKS1, NULL);
¶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) {
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;