Skip to content

Commit 7376e83

Browse files
Andrey Chaserkeszybz
authored andcommitted
1 parent d2f0e78 commit 7376e83

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

man/crypttab.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,18 @@
141141
this option.</para></listitem>
142142
</varlistentry>
143143

144+
<varlistentry>
145+
<term><option>header=</option></term>
146+
147+
<listitem><para>Use a detached (separated)
148+
metadata device or file where the LUKS header
149+
is stored. This option is only relevant for
150+
LUKS devices. See
151+
<citerefentry><refentrytitle>cryptsetup</refentrytitle><manvolnum>8</manvolnum></citerefentry>
152+
for possible values and the default value of
153+
this option.</para></listitem>
154+
</varlistentry>
155+
144156
<varlistentry>
145157
<term><option>keyfile-offset=</option></term>
146158

src/cryptsetup/cryptsetup.c

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ static int arg_key_slot = CRYPT_ANY_SLOT;
4343
static unsigned arg_keyfile_size = 0;
4444
static unsigned arg_keyfile_offset = 0;
4545
static char *arg_hash = NULL;
46+
static char *arg_header = NULL;
4647
static unsigned arg_tries = 3;
4748
static bool arg_readonly = false;
4849
static bool arg_verify = false;
@@ -136,6 +137,23 @@ static int parse_one_option(const char *option) {
136137
free(arg_hash);
137138
arg_hash = t;
138139

140+
} else if (startswith(option, "header=")) {
141+
arg_type = CRYPT_LUKS1;
142+
143+
if (!path_is_absolute(option+7)) {
144+
log_error("Header path '%s' is not absolute, refusing.", option+7);
145+
return -EINVAL;
146+
}
147+
148+
if (arg_header) {
149+
log_error("Duplicate header= options, refusing.");
150+
return -EINVAL;
151+
}
152+
153+
arg_header = strdup(option+7);
154+
if (!arg_header)
155+
return log_oom();
156+
139157
} else if (startswith(option, "tries=")) {
140158

141159
if (safe_atou(option+6, &arg_tries) < 0) {
@@ -375,6 +393,7 @@ static int attach_tcrypt(struct crypt_device *cd,
375393
static int attach_luks_or_plain(struct crypt_device *cd,
376394
const char *name,
377395
const char *key_file,
396+
const char *data_device,
378397
char **passwords,
379398
uint32_t flags) {
380399
int r = 0;
@@ -384,8 +403,16 @@ static int attach_luks_or_plain(struct crypt_device *cd,
384403
assert(name);
385404
assert(key_file || passwords);
386405

387-
if (!arg_type || streq(arg_type, CRYPT_LUKS1))
406+
if (!arg_type || streq(arg_type, CRYPT_LUKS1)) {
388407
r = crypt_load(cd, CRYPT_LUKS1, NULL);
408+
if (r < 0) {
409+
log_error("crypt_load() failed on device %s.\n", crypt_get_device_name(cd));
410+
return r;
411+
}
412+
413+
if (data_device)
414+
r = crypt_set_data_device(cd, data_device);
415+
}
389416

390417
if ((!arg_type && r < 0) || streq_ptr(arg_type, CRYPT_PLAIN)) {
391418
struct crypt_params_plain params = {};
@@ -559,7 +586,12 @@ int main(int argc, char *argv[]) {
559586
}
560587
name = name_buffer ? name_buffer : argv[2];
561588

562-
k = crypt_init(&cd, argv[3]);
589+
if (arg_header) {
590+
log_debug("LUKS header: %s", arg_header);
591+
k = crypt_init(&cd, arg_header);
592+
} else
593+
k = crypt_init(&cd, argv[3]);
594+
563595
if (k) {
564596
log_error_errno(k, "crypt_init() failed: %m");
565597
goto finish;
@@ -610,7 +642,12 @@ int main(int argc, char *argv[]) {
610642
if (streq_ptr(arg_type, CRYPT_TCRYPT))
611643
k = attach_tcrypt(cd, argv[2], key_file, passwords, flags);
612644
else
613-
k = attach_luks_or_plain(cd, argv[2], key_file, passwords, flags);
645+
k = attach_luks_or_plain(cd,
646+
argv[2],
647+
key_file,
648+
arg_header ? argv[3] : NULL,
649+
passwords,
650+
flags);
614651
if (k >= 0)
615652
break;
616653
else if (k == -EAGAIN) {
@@ -661,6 +698,7 @@ int main(int argc, char *argv[]) {
661698

662699
free(arg_cipher);
663700
free(arg_hash);
701+
free(arg_header);
664702
strv_free(arg_tcrypt_keyfiles);
665703

666704
return r;

0 commit comments

Comments
 (0)