]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/cryptsetup/cryptsetup.c
Merge pull request #9832 from yuwata/fix-9831
[thirdparty/systemd.git] / src / cryptsetup / cryptsetup.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include <errno.h>
4 #include <mntent.h>
5 #include <string.h>
6 #include <sys/mman.h>
7
8 #include "sd-device.h"
9
10 #include "alloc-util.h"
11 #include "ask-password-api.h"
12 #include "crypt-util.h"
13 #include "device-util.h"
14 #include "escape.h"
15 #include "fileio.h"
16 #include "log.h"
17 #include "mount-util.h"
18 #include "parse-util.h"
19 #include "path-util.h"
20 #include "string-util.h"
21 #include "strv.h"
22 #include "terminal-util.h"
23 #include "util.h"
24
25 /* internal helper */
26 #define ANY_LUKS "LUKS"
27 /* as in src/cryptsetup.h */
28 #define CRYPT_SECTOR_SIZE 512
29 #define CRYPT_MAX_SECTOR_SIZE 4096
30
31 static const char *arg_type = NULL; /* ANY_LUKS, CRYPT_LUKS1, CRYPT_LUKS2, CRYPT_TCRYPT or CRYPT_PLAIN */
32 static char *arg_cipher = NULL;
33 static unsigned arg_key_size = 0;
34 #if HAVE_LIBCRYPTSETUP_SECTOR_SIZE
35 static unsigned arg_sector_size = CRYPT_SECTOR_SIZE;
36 #endif
37 static int arg_key_slot = CRYPT_ANY_SLOT;
38 static unsigned arg_keyfile_size = 0;
39 static uint64_t arg_keyfile_offset = 0;
40 static char *arg_hash = NULL;
41 static char *arg_header = NULL;
42 static unsigned arg_tries = 3;
43 static bool arg_readonly = false;
44 static bool arg_verify = false;
45 static bool arg_discards = false;
46 static bool arg_tcrypt_hidden = false;
47 static bool arg_tcrypt_system = false;
48 #ifdef CRYPT_TCRYPT_VERA_MODES
49 static bool arg_tcrypt_veracrypt = false;
50 #endif
51 static char **arg_tcrypt_keyfiles = NULL;
52 static uint64_t arg_offset = 0;
53 static uint64_t arg_skip = 0;
54 static usec_t arg_timeout = USEC_INFINITY;
55
56 /* Options Debian's crypttab knows we don't:
57
58 precheck=
59 check=
60 checkargs=
61 noearly=
62 loud=
63 keyscript=
64 */
65
66 static int parse_one_option(const char *option) {
67 const char *val;
68 int r;
69
70 assert(option);
71
72 /* Handled outside of this tool */
73 if (STR_IN_SET(option, "noauto", "auto", "nofail", "fail", "_netdev"))
74 return 0;
75
76 if ((val = startswith(option, "cipher="))) {
77 r = free_and_strdup(&arg_cipher, val);
78 if (r < 0)
79 return log_oom();
80
81 } else if ((val = startswith(option, "size="))) {
82
83 r = safe_atou(val, &arg_key_size);
84 if (r < 0) {
85 log_error_errno(r, "Failed to parse %s, ignoring: %m", option);
86 return 0;
87 }
88
89 if (arg_key_size % 8) {
90 log_error("size= not a multiple of 8, ignoring.");
91 return 0;
92 }
93
94 arg_key_size /= 8;
95
96 } else if ((val = startswith(option, "sector-size="))) {
97
98 #if HAVE_LIBCRYPTSETUP_SECTOR_SIZE
99 r = safe_atou(val, &arg_sector_size);
100 if (r < 0) {
101 log_error_errno(r, "Failed to parse %s, ignoring: %m", option);
102 return 0;
103 }
104
105 if (arg_sector_size % 2) {
106 log_error("sector-size= not a multiple of 2, ignoring.");
107 return 0;
108 }
109
110 if (arg_sector_size < CRYPT_SECTOR_SIZE || arg_sector_size > CRYPT_MAX_SECTOR_SIZE) {
111 log_error("sector-size= is outside of %u and %u, ignoring.", CRYPT_SECTOR_SIZE, CRYPT_MAX_SECTOR_SIZE);
112 return 0;
113 }
114 #else
115 log_error("sector-size= is not supported, compiled with old libcryptsetup.");
116 return 0;
117 #endif
118
119 } else if ((val = startswith(option, "key-slot="))) {
120
121 arg_type = ANY_LUKS;
122 r = safe_atoi(val, &arg_key_slot);
123 if (r < 0) {
124 log_error_errno(r, "Failed to parse %s, ignoring: %m", option);
125 return 0;
126 }
127
128 } else if ((val = startswith(option, "tcrypt-keyfile="))) {
129
130 arg_type = CRYPT_TCRYPT;
131 if (path_is_absolute(val)) {
132 if (strv_extend(&arg_tcrypt_keyfiles, val) < 0)
133 return log_oom();
134 } else
135 log_error("Key file path \"%s\" is not absolute. Ignoring.", val);
136
137 } else if ((val = startswith(option, "keyfile-size="))) {
138
139 r = safe_atou(val, &arg_keyfile_size);
140 if (r < 0) {
141 log_error_errno(r, "Failed to parse %s, ignoring: %m", option);
142 return 0;
143 }
144
145 } else if ((val = startswith(option, "keyfile-offset="))) {
146 uint64_t off;
147
148 r = safe_atou64(val, &off);
149 if (r < 0) {
150 log_error_errno(r, "Failed to parse %s, ignoring: %m", option);
151 return 0;
152 }
153
154 if ((size_t) off != off) {
155 /* https://gitlab.com/cryptsetup/cryptsetup/issues/359 */
156 log_error("keyfile-offset= value would truncated to %zu, ignoring.", (size_t) off);
157 return 0;
158 }
159
160 arg_keyfile_offset = off;
161
162 } else if ((val = startswith(option, "hash="))) {
163 r = free_and_strdup(&arg_hash, val);
164 if (r < 0)
165 return log_oom();
166
167 } else if ((val = startswith(option, "header="))) {
168 arg_type = ANY_LUKS;
169
170 if (!path_is_absolute(val)) {
171 log_error("Header path \"%s\" is not absolute, refusing.", val);
172 return -EINVAL;
173 }
174
175 if (arg_header) {
176 log_error("Duplicate header= option, refusing.");
177 return -EINVAL;
178 }
179
180 arg_header = strdup(val);
181 if (!arg_header)
182 return log_oom();
183
184 } else if ((val = startswith(option, "tries="))) {
185
186 r = safe_atou(val, &arg_tries);
187 if (r < 0) {
188 log_error_errno(r, "Failed to parse %s, ignoring: %m", option);
189 return 0;
190 }
191
192 } else if (STR_IN_SET(option, "readonly", "read-only"))
193 arg_readonly = true;
194 else if (streq(option, "verify"))
195 arg_verify = true;
196 else if (STR_IN_SET(option, "allow-discards", "discard"))
197 arg_discards = true;
198 else if (streq(option, "luks"))
199 arg_type = ANY_LUKS;
200 else if (streq(option, "tcrypt"))
201 arg_type = CRYPT_TCRYPT;
202 else if (streq(option, "tcrypt-hidden")) {
203 arg_type = CRYPT_TCRYPT;
204 arg_tcrypt_hidden = true;
205 } else if (streq(option, "tcrypt-system")) {
206 arg_type = CRYPT_TCRYPT;
207 arg_tcrypt_system = true;
208 } else if (streq(option, "tcrypt-veracrypt")) {
209 #ifdef CRYPT_TCRYPT_VERA_MODES
210 arg_type = CRYPT_TCRYPT;
211 arg_tcrypt_veracrypt = true;
212 #else
213 log_error("This version of cryptsetup does not support tcrypt-veracrypt; refusing.");
214 return -EINVAL;
215 #endif
216 } else if (STR_IN_SET(option, "plain", "swap", "tmp"))
217 arg_type = CRYPT_PLAIN;
218 else if ((val = startswith(option, "timeout="))) {
219
220 r = parse_sec_fix_0(val, &arg_timeout);
221 if (r < 0) {
222 log_error_errno(r, "Failed to parse %s, ignoring: %m", option);
223 return 0;
224 }
225
226 } else if ((val = startswith(option, "offset="))) {
227
228 r = safe_atou64(val, &arg_offset);
229 if (r < 0)
230 return log_error_errno(r, "Failed to parse %s: %m", option);
231
232 } else if ((val = startswith(option, "skip="))) {
233
234 r = safe_atou64(val, &arg_skip);
235 if (r < 0)
236 return log_error_errno(r, "Failed to parse %s: %m", option);
237
238 } else if (!streq(option, "none"))
239 log_warning("Encountered unknown /etc/crypttab option '%s', ignoring.", option);
240
241 return 0;
242 }
243
244 static int parse_options(const char *options) {
245 const char *word, *state;
246 size_t l;
247 int r;
248
249 assert(options);
250
251 FOREACH_WORD_SEPARATOR(word, l, options, ",", state) {
252 _cleanup_free_ char *o;
253
254 o = strndup(word, l);
255 if (!o)
256 return -ENOMEM;
257 r = parse_one_option(o);
258 if (r < 0)
259 return r;
260 }
261
262 /* sanity-check options */
263 if (arg_type != NULL && !streq(arg_type, CRYPT_PLAIN)) {
264 if (arg_offset)
265 log_warning("offset= ignored with type %s", arg_type);
266 if (arg_skip)
267 log_warning("skip= ignored with type %s", arg_type);
268 }
269
270 return 0;
271 }
272
273 static char* disk_description(const char *path) {
274
275 static const char name_fields[] =
276 "ID_PART_ENTRY_NAME\0"
277 "DM_NAME\0"
278 "ID_MODEL_FROM_DATABASE\0"
279 "ID_MODEL\0";
280
281 _cleanup_(sd_device_unrefp) sd_device *device = NULL;
282 struct stat st;
283 const char *i;
284 int r;
285
286 assert(path);
287
288 if (stat(path, &st) < 0)
289 return NULL;
290
291 if (!S_ISBLK(st.st_mode))
292 return NULL;
293
294 r = sd_device_new_from_devnum(&device, 'b', st.st_rdev);
295 if (r < 0)
296 return NULL;
297
298 NULSTR_FOREACH(i, name_fields) {
299 const char *name;
300
301 r = sd_device_get_property_value(device, i, &name);
302 if (r >= 0 && !isempty(name))
303 return strdup(name);
304 }
305
306 return NULL;
307 }
308
309 static char *disk_mount_point(const char *label) {
310 _cleanup_free_ char *device = NULL;
311 _cleanup_endmntent_ FILE *f = NULL;
312 struct mntent *m;
313
314 /* Yeah, we don't support native systemd unit files here for now */
315
316 if (asprintf(&device, "/dev/mapper/%s", label) < 0)
317 return NULL;
318
319 f = setmntent("/etc/fstab", "re");
320 if (!f)
321 return NULL;
322
323 while ((m = getmntent(f)))
324 if (path_equal(m->mnt_fsname, device))
325 return strdup(m->mnt_dir);
326
327 return NULL;
328 }
329
330 static int get_password(const char *vol, const char *src, usec_t until, bool accept_cached, char ***ret) {
331 _cleanup_free_ char *description = NULL, *name_buffer = NULL, *mount_point = NULL, *text = NULL, *disk_path = NULL;
332 _cleanup_strv_free_erase_ char **passwords = NULL;
333 const char *name = NULL;
334 char **p, *id;
335 int r = 0;
336
337 assert(vol);
338 assert(src);
339 assert(ret);
340
341 description = disk_description(src);
342 mount_point = disk_mount_point(vol);
343
344 disk_path = cescape(src);
345 if (!disk_path)
346 return log_oom();
347
348 if (description && streq(vol, description))
349 /* If the description string is simply the
350 * volume name, then let's not show this
351 * twice */
352 description = mfree(description);
353
354 if (mount_point && description)
355 r = asprintf(&name_buffer, "%s (%s) on %s", description, vol, mount_point);
356 else if (mount_point)
357 r = asprintf(&name_buffer, "%s on %s", vol, mount_point);
358 else if (description)
359 r = asprintf(&name_buffer, "%s (%s)", description, vol);
360
361 if (r < 0)
362 return log_oom();
363
364 name = name_buffer ? name_buffer : vol;
365
366 if (asprintf(&text, "Please enter passphrase for disk %s!", name) < 0)
367 return log_oom();
368
369 id = strjoina("cryptsetup:", disk_path);
370
371 r = ask_password_auto(text, "drive-harddisk", id, "cryptsetup", until,
372 ASK_PASSWORD_PUSH_CACHE | (accept_cached*ASK_PASSWORD_ACCEPT_CACHED),
373 &passwords);
374 if (r < 0)
375 return log_error_errno(r, "Failed to query password: %m");
376
377 if (arg_verify) {
378 _cleanup_strv_free_erase_ char **passwords2 = NULL;
379
380 assert(strv_length(passwords) == 1);
381
382 if (asprintf(&text, "Please enter passphrase for disk %s! (verification)", name) < 0)
383 return log_oom();
384
385 id = strjoina("cryptsetup-verification:", disk_path);
386
387 r = ask_password_auto(text, "drive-harddisk", id, "cryptsetup", until, ASK_PASSWORD_PUSH_CACHE, &passwords2);
388 if (r < 0)
389 return log_error_errno(r, "Failed to query verification password: %m");
390
391 assert(strv_length(passwords2) == 1);
392
393 if (!streq(passwords[0], passwords2[0])) {
394 log_warning("Passwords did not match, retrying.");
395 return -EAGAIN;
396 }
397 }
398
399 strv_uniq(passwords);
400
401 STRV_FOREACH(p, passwords) {
402 char *c;
403
404 if (strlen(*p)+1 >= arg_key_size)
405 continue;
406
407 /* Pad password if necessary */
408 c = new(char, arg_key_size);
409 if (!c)
410 return log_oom();
411
412 strncpy(c, *p, arg_key_size);
413 free(*p);
414 *p = c;
415 }
416
417 *ret = TAKE_PTR(passwords);
418
419 return 0;
420 }
421
422 static int attach_tcrypt(
423 struct crypt_device *cd,
424 const char *name,
425 const char *key_file,
426 char **passwords,
427 uint32_t flags) {
428
429 int r = 0;
430 _cleanup_free_ char *passphrase = NULL;
431 struct crypt_params_tcrypt params = {
432 .flags = CRYPT_TCRYPT_LEGACY_MODES,
433 .keyfiles = (const char **)arg_tcrypt_keyfiles,
434 .keyfiles_count = strv_length(arg_tcrypt_keyfiles)
435 };
436
437 assert(cd);
438 assert(name);
439 assert(key_file || (passwords && passwords[0]));
440
441 if (arg_tcrypt_hidden)
442 params.flags |= CRYPT_TCRYPT_HIDDEN_HEADER;
443
444 if (arg_tcrypt_system)
445 params.flags |= CRYPT_TCRYPT_SYSTEM_HEADER;
446
447 #ifdef CRYPT_TCRYPT_VERA_MODES
448 if (arg_tcrypt_veracrypt)
449 params.flags |= CRYPT_TCRYPT_VERA_MODES;
450 #endif
451
452 if (key_file) {
453 r = read_one_line_file(key_file, &passphrase);
454 if (r < 0) {
455 log_error_errno(r, "Failed to read password file '%s': %m", key_file);
456 return -EAGAIN;
457 }
458
459 params.passphrase = passphrase;
460 } else
461 params.passphrase = passwords[0];
462 params.passphrase_size = strlen(params.passphrase);
463
464 r = crypt_load(cd, CRYPT_TCRYPT, &params);
465 if (r < 0) {
466 if (key_file && r == -EPERM) {
467 log_error("Failed to activate using password file '%s'.", key_file);
468 return -EAGAIN;
469 }
470 return r;
471 }
472
473 return crypt_activate_by_volume_key(cd, name, NULL, 0, flags);
474 }
475
476 static int attach_luks_or_plain(struct crypt_device *cd,
477 const char *name,
478 const char *key_file,
479 const char *data_device,
480 char **passwords,
481 uint32_t flags) {
482 int r = 0;
483 bool pass_volume_key = false;
484
485 assert(cd);
486 assert(name);
487 assert(key_file || passwords);
488
489 if (!arg_type || STR_IN_SET(arg_type, ANY_LUKS, CRYPT_LUKS1)) {
490 r = crypt_load(cd, CRYPT_LUKS, NULL);
491 if (r < 0) {
492 log_error("crypt_load() failed on device %s.\n", crypt_get_device_name(cd));
493 return r;
494 }
495
496 if (data_device)
497 r = crypt_set_data_device(cd, data_device);
498 }
499
500 if ((!arg_type && r < 0) || streq_ptr(arg_type, CRYPT_PLAIN)) {
501 struct crypt_params_plain params = {
502 .offset = arg_offset,
503 .skip = arg_skip,
504 #if HAVE_LIBCRYPTSETUP_SECTOR_SIZE
505 .sector_size = arg_sector_size,
506 #endif
507 };
508 const char *cipher, *cipher_mode;
509 _cleanup_free_ char *truncated_cipher = NULL;
510
511 if (arg_hash) {
512 /* plain isn't a real hash type. it just means "use no hash" */
513 if (!streq(arg_hash, "plain"))
514 params.hash = arg_hash;
515 } else if (!key_file)
516 /* for CRYPT_PLAIN, the behaviour of cryptsetup
517 * package is to not hash when a key file is provided */
518 params.hash = "ripemd160";
519
520 if (arg_cipher) {
521 size_t l;
522
523 l = strcspn(arg_cipher, "-");
524 truncated_cipher = strndup(arg_cipher, l);
525 if (!truncated_cipher)
526 return log_oom();
527
528 cipher = truncated_cipher;
529 cipher_mode = arg_cipher[l] ? arg_cipher+l+1 : "plain";
530 } else {
531 cipher = "aes";
532 cipher_mode = "cbc-essiv:sha256";
533 }
534
535 /* for CRYPT_PLAIN limit reads
536 * from keyfile to key length, and
537 * ignore keyfile-size */
538 arg_keyfile_size = arg_key_size;
539
540 /* In contrast to what the name
541 * crypt_setup() might suggest this
542 * doesn't actually format anything,
543 * it just configures encryption
544 * parameters when used for plain
545 * mode. */
546 r = crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode, NULL, NULL, arg_keyfile_size, &params);
547
548 /* hash == NULL implies the user passed "plain" */
549 pass_volume_key = (params.hash == NULL);
550 }
551
552 if (r < 0)
553 return log_error_errno(r, "Loading of cryptographic parameters failed: %m");
554
555 log_info("Set cipher %s, mode %s, key size %i bits for device %s.",
556 crypt_get_cipher(cd),
557 crypt_get_cipher_mode(cd),
558 crypt_get_volume_key_size(cd)*8,
559 crypt_get_device_name(cd));
560
561 if (key_file) {
562 r = crypt_activate_by_keyfile_offset(cd, name, arg_key_slot, key_file, arg_keyfile_size, arg_keyfile_offset, flags);
563 if (r < 0) {
564 log_error_errno(r, "Failed to activate with key file '%s': %m", key_file);
565 return -EAGAIN;
566 }
567 } else {
568 char **p;
569
570 STRV_FOREACH(p, passwords) {
571 if (pass_volume_key)
572 r = crypt_activate_by_volume_key(cd, name, *p, arg_key_size, flags);
573 else
574 r = crypt_activate_by_passphrase(cd, name, arg_key_slot, *p, strlen(*p), flags);
575
576 if (r >= 0)
577 break;
578 }
579 }
580
581 return r;
582 }
583
584 static int help(void) {
585 _cleanup_free_ char *link = NULL;
586 int r;
587
588 r = terminal_urlify_man("systemd-cryptsetup@.service", "8", &link);
589 if (r < 0)
590 return log_oom();
591
592 printf("%s attach VOLUME SOURCEDEVICE [PASSWORD] [OPTIONS]\n"
593 "%s detach VOLUME\n\n"
594 "Attaches or detaches an encrypted block device.\n"
595 "\nSee the %s for details.\n"
596 , program_invocation_short_name
597 , program_invocation_short_name
598 , link
599 );
600
601 return 0;
602 }
603
604 int main(int argc, char *argv[]) {
605 _cleanup_(crypt_freep) struct crypt_device *cd = NULL;
606 int r = -EINVAL;
607
608 if (argc <= 1) {
609 r = help();
610 goto finish;
611 }
612
613 if (argc < 3) {
614 log_error("This program requires at least two arguments.");
615 goto finish;
616 }
617
618 log_set_target(LOG_TARGET_AUTO);
619 log_parse_environment();
620 log_open();
621
622 umask(0022);
623
624 if (streq(argv[1], "attach")) {
625 uint32_t flags = 0;
626 unsigned tries;
627 usec_t until;
628 crypt_status_info status;
629 const char *key_file = NULL;
630
631 /* Arguments: systemd-cryptsetup attach VOLUME SOURCE-DEVICE [PASSWORD] [OPTIONS] */
632
633 if (argc < 4) {
634 log_error("attach requires at least two arguments.");
635 goto finish;
636 }
637
638 if (argc >= 5 &&
639 argv[4][0] &&
640 !streq(argv[4], "-") &&
641 !streq(argv[4], "none")) {
642
643 if (!path_is_absolute(argv[4]))
644 log_error("Password file path '%s' is not absolute. Ignoring.", argv[4]);
645 else
646 key_file = argv[4];
647 }
648
649 if (argc >= 6 && argv[5][0] && !streq(argv[5], "-")) {
650 if (parse_options(argv[5]) < 0)
651 goto finish;
652 }
653
654 /* A delicious drop of snake oil */
655 mlockall(MCL_FUTURE);
656
657 if (arg_header) {
658 log_debug("LUKS header: %s", arg_header);
659 r = crypt_init(&cd, arg_header);
660 } else
661 r = crypt_init(&cd, argv[3]);
662 if (r < 0) {
663 log_error_errno(r, "crypt_init() failed: %m");
664 goto finish;
665 }
666
667 crypt_set_log_callback(cd, cryptsetup_log_glue, NULL);
668
669 status = crypt_status(cd, argv[2]);
670 if (IN_SET(status, CRYPT_ACTIVE, CRYPT_BUSY)) {
671 log_info("Volume %s already active.", argv[2]);
672 r = 0;
673 goto finish;
674 }
675
676 if (arg_readonly)
677 flags |= CRYPT_ACTIVATE_READONLY;
678
679 if (arg_discards)
680 flags |= CRYPT_ACTIVATE_ALLOW_DISCARDS;
681
682 if (arg_timeout == USEC_INFINITY)
683 until = 0;
684 else
685 until = now(CLOCK_MONOTONIC) + arg_timeout;
686
687 arg_key_size = (arg_key_size > 0 ? arg_key_size : (256 / 8));
688
689 if (key_file) {
690 struct stat st;
691
692 /* Ideally we'd do this on the open fd, but since this is just a
693 * warning it's OK to do this in two steps. */
694 if (stat(key_file, &st) >= 0 && S_ISREG(st.st_mode) && (st.st_mode & 0005))
695 log_warning("Key file %s is world-readable. This is not a good idea!", key_file);
696 }
697
698 for (tries = 0; arg_tries == 0 || tries < arg_tries; tries++) {
699 _cleanup_strv_free_erase_ char **passwords = NULL;
700
701 if (!key_file) {
702 r = get_password(argv[2], argv[3], until, tries == 0 && !arg_verify, &passwords);
703 if (r == -EAGAIN)
704 continue;
705 if (r < 0)
706 goto finish;
707 }
708
709 if (streq_ptr(arg_type, CRYPT_TCRYPT))
710 r = attach_tcrypt(cd, argv[2], key_file, passwords, flags);
711 else
712 r = attach_luks_or_plain(cd,
713 argv[2],
714 key_file,
715 arg_header ? argv[3] : NULL,
716 passwords,
717 flags);
718 if (r >= 0)
719 break;
720 if (r == -EAGAIN) {
721 key_file = NULL;
722 continue;
723 }
724 if (r != -EPERM) {
725 log_error_errno(r, "Failed to activate: %m");
726 goto finish;
727 }
728
729 log_warning("Invalid passphrase.");
730 }
731
732 if (arg_tries != 0 && tries >= arg_tries) {
733 log_error("Too many attempts; giving up.");
734 r = -EPERM;
735 goto finish;
736 }
737
738 } else if (streq(argv[1], "detach")) {
739
740 r = crypt_init_by_name(&cd, argv[2]);
741 if (r == -ENODEV) {
742 log_info("Volume %s already inactive.", argv[2]);
743 r = 0;
744 goto finish;
745 }
746 if (r < 0) {
747 log_error_errno(r, "crypt_init_by_name() failed: %m");
748 goto finish;
749 }
750
751 crypt_set_log_callback(cd, cryptsetup_log_glue, NULL);
752
753 r = crypt_deactivate(cd, argv[2]);
754 if (r < 0) {
755 log_error_errno(r, "Failed to deactivate: %m");
756 goto finish;
757 }
758
759 } else {
760 log_error("Unknown verb %s.", argv[1]);
761 goto finish;
762 }
763
764 r = 0;
765
766 finish:
767 free(arg_cipher);
768 free(arg_hash);
769 free(arg_header);
770 strv_free(arg_tcrypt_keyfiles);
771
772 return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
773 }