]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/cryptsetup/cryptsetup.c
Merge pull request #10850 from poettering/log-setup
[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 static const char name_fields[] =
275 "ID_PART_ENTRY_NAME\0"
276 "DM_NAME\0"
277 "ID_MODEL_FROM_DATABASE\0"
278 "ID_MODEL\0";
279
280 _cleanup_(sd_device_unrefp) sd_device *device = NULL;
281 const char *i, *name;
282 struct stat st;
283
284 assert(path);
285
286 if (stat(path, &st) < 0)
287 return NULL;
288
289 if (!S_ISBLK(st.st_mode))
290 return NULL;
291
292 if (sd_device_new_from_devnum(&device, 'b', st.st_rdev) < 0)
293 return NULL;
294
295 NULSTR_FOREACH(i, name_fields)
296 if (sd_device_get_property_value(device, i, &name) >= 0 &&
297 !isempty(name))
298 return strdup(name);
299
300 return NULL;
301 }
302
303 static char *disk_mount_point(const char *label) {
304 _cleanup_free_ char *device = NULL;
305 _cleanup_endmntent_ FILE *f = NULL;
306 struct mntent *m;
307
308 /* Yeah, we don't support native systemd unit files here for now */
309
310 if (asprintf(&device, "/dev/mapper/%s", label) < 0)
311 return NULL;
312
313 f = setmntent("/etc/fstab", "re");
314 if (!f)
315 return NULL;
316
317 while ((m = getmntent(f)))
318 if (path_equal(m->mnt_fsname, device))
319 return strdup(m->mnt_dir);
320
321 return NULL;
322 }
323
324 static int get_password(const char *vol, const char *src, usec_t until, bool accept_cached, char ***ret) {
325 _cleanup_free_ char *description = NULL, *name_buffer = NULL, *mount_point = NULL, *text = NULL, *disk_path = NULL;
326 _cleanup_strv_free_erase_ char **passwords = NULL;
327 const char *name = NULL;
328 char **p, *id;
329 int r = 0;
330
331 assert(vol);
332 assert(src);
333 assert(ret);
334
335 description = disk_description(src);
336 mount_point = disk_mount_point(vol);
337
338 disk_path = cescape(src);
339 if (!disk_path)
340 return log_oom();
341
342 if (description && streq(vol, description))
343 /* If the description string is simply the
344 * volume name, then let's not show this
345 * twice */
346 description = mfree(description);
347
348 if (mount_point && description)
349 r = asprintf(&name_buffer, "%s (%s) on %s", description, vol, mount_point);
350 else if (mount_point)
351 r = asprintf(&name_buffer, "%s on %s", vol, mount_point);
352 else if (description)
353 r = asprintf(&name_buffer, "%s (%s)", description, vol);
354
355 if (r < 0)
356 return log_oom();
357
358 name = name_buffer ? name_buffer : vol;
359
360 if (asprintf(&text, "Please enter passphrase for disk %s:", name) < 0)
361 return log_oom();
362
363 id = strjoina("cryptsetup:", disk_path);
364
365 r = ask_password_auto(text, "drive-harddisk", id, "cryptsetup", until,
366 ASK_PASSWORD_PUSH_CACHE | (accept_cached*ASK_PASSWORD_ACCEPT_CACHED),
367 &passwords);
368 if (r < 0)
369 return log_error_errno(r, "Failed to query password: %m");
370
371 if (arg_verify) {
372 _cleanup_strv_free_erase_ char **passwords2 = NULL;
373
374 assert(strv_length(passwords) == 1);
375
376 if (asprintf(&text, "Please enter passphrase for disk %s (verification):", name) < 0)
377 return log_oom();
378
379 id = strjoina("cryptsetup-verification:", disk_path);
380
381 r = ask_password_auto(text, "drive-harddisk", id, "cryptsetup", until, ASK_PASSWORD_PUSH_CACHE, &passwords2);
382 if (r < 0)
383 return log_error_errno(r, "Failed to query verification password: %m");
384
385 assert(strv_length(passwords2) == 1);
386
387 if (!streq(passwords[0], passwords2[0])) {
388 log_warning("Passwords did not match, retrying.");
389 return -EAGAIN;
390 }
391 }
392
393 strv_uniq(passwords);
394
395 STRV_FOREACH(p, passwords) {
396 char *c;
397
398 if (strlen(*p)+1 >= arg_key_size)
399 continue;
400
401 /* Pad password if necessary */
402 c = new(char, arg_key_size);
403 if (!c)
404 return log_oom();
405
406 strncpy(c, *p, arg_key_size);
407 free(*p);
408 *p = c;
409 }
410
411 *ret = TAKE_PTR(passwords);
412
413 return 0;
414 }
415
416 static int attach_tcrypt(
417 struct crypt_device *cd,
418 const char *name,
419 const char *key_file,
420 char **passwords,
421 uint32_t flags) {
422
423 int r = 0;
424 _cleanup_free_ char *passphrase = NULL;
425 struct crypt_params_tcrypt params = {
426 .flags = CRYPT_TCRYPT_LEGACY_MODES,
427 .keyfiles = (const char **)arg_tcrypt_keyfiles,
428 .keyfiles_count = strv_length(arg_tcrypt_keyfiles)
429 };
430
431 assert(cd);
432 assert(name);
433 assert(key_file || (passwords && passwords[0]));
434
435 if (arg_tcrypt_hidden)
436 params.flags |= CRYPT_TCRYPT_HIDDEN_HEADER;
437
438 if (arg_tcrypt_system)
439 params.flags |= CRYPT_TCRYPT_SYSTEM_HEADER;
440
441 #ifdef CRYPT_TCRYPT_VERA_MODES
442 if (arg_tcrypt_veracrypt)
443 params.flags |= CRYPT_TCRYPT_VERA_MODES;
444 #endif
445
446 if (key_file) {
447 r = read_one_line_file(key_file, &passphrase);
448 if (r < 0) {
449 log_error_errno(r, "Failed to read password file '%s': %m", key_file);
450 return -EAGAIN;
451 }
452
453 params.passphrase = passphrase;
454 } else
455 params.passphrase = passwords[0];
456 params.passphrase_size = strlen(params.passphrase);
457
458 r = crypt_load(cd, CRYPT_TCRYPT, &params);
459 if (r < 0) {
460 if (key_file && r == -EPERM) {
461 log_error("Failed to activate using password file '%s'.", key_file);
462 return -EAGAIN;
463 }
464 return r;
465 }
466
467 return crypt_activate_by_volume_key(cd, name, NULL, 0, flags);
468 }
469
470 static int attach_luks_or_plain(struct crypt_device *cd,
471 const char *name,
472 const char *key_file,
473 const char *data_device,
474 char **passwords,
475 uint32_t flags) {
476 int r = 0;
477 bool pass_volume_key = false;
478
479 assert(cd);
480 assert(name);
481 assert(key_file || passwords);
482
483 if (!arg_type || STR_IN_SET(arg_type, ANY_LUKS, CRYPT_LUKS1)) {
484 r = crypt_load(cd, CRYPT_LUKS, NULL);
485 if (r < 0) {
486 log_error("crypt_load() failed on device %s.\n", crypt_get_device_name(cd));
487 return r;
488 }
489
490 if (data_device)
491 r = crypt_set_data_device(cd, data_device);
492 }
493
494 if ((!arg_type && r < 0) || streq_ptr(arg_type, CRYPT_PLAIN)) {
495 struct crypt_params_plain params = {
496 .offset = arg_offset,
497 .skip = arg_skip,
498 #if HAVE_LIBCRYPTSETUP_SECTOR_SIZE
499 .sector_size = arg_sector_size,
500 #endif
501 };
502 const char *cipher, *cipher_mode;
503 _cleanup_free_ char *truncated_cipher = NULL;
504
505 if (arg_hash) {
506 /* plain isn't a real hash type. it just means "use no hash" */
507 if (!streq(arg_hash, "plain"))
508 params.hash = arg_hash;
509 } else if (!key_file)
510 /* for CRYPT_PLAIN, the behaviour of cryptsetup
511 * package is to not hash when a key file is provided */
512 params.hash = "ripemd160";
513
514 if (arg_cipher) {
515 size_t l;
516
517 l = strcspn(arg_cipher, "-");
518 truncated_cipher = strndup(arg_cipher, l);
519 if (!truncated_cipher)
520 return log_oom();
521
522 cipher = truncated_cipher;
523 cipher_mode = arg_cipher[l] ? arg_cipher+l+1 : "plain";
524 } else {
525 cipher = "aes";
526 cipher_mode = "cbc-essiv:sha256";
527 }
528
529 /* for CRYPT_PLAIN limit reads
530 * from keyfile to key length, and
531 * ignore keyfile-size */
532 arg_keyfile_size = arg_key_size;
533
534 /* In contrast to what the name
535 * crypt_setup() might suggest this
536 * doesn't actually format anything,
537 * it just configures encryption
538 * parameters when used for plain
539 * mode. */
540 r = crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode, NULL, NULL, arg_keyfile_size, &params);
541
542 /* hash == NULL implies the user passed "plain" */
543 pass_volume_key = (params.hash == NULL);
544 }
545
546 if (r < 0)
547 return log_error_errno(r, "Loading of cryptographic parameters failed: %m");
548
549 log_info("Set cipher %s, mode %s, key size %i bits for device %s.",
550 crypt_get_cipher(cd),
551 crypt_get_cipher_mode(cd),
552 crypt_get_volume_key_size(cd)*8,
553 crypt_get_device_name(cd));
554
555 if (key_file) {
556 r = crypt_activate_by_keyfile_offset(cd, name, arg_key_slot, key_file, arg_keyfile_size, arg_keyfile_offset, flags);
557 if (r < 0) {
558 log_error_errno(r, "Failed to activate with key file '%s': %m", key_file);
559 return -EAGAIN;
560 }
561 } else {
562 char **p;
563
564 STRV_FOREACH(p, passwords) {
565 if (pass_volume_key)
566 r = crypt_activate_by_volume_key(cd, name, *p, arg_key_size, flags);
567 else
568 r = crypt_activate_by_passphrase(cd, name, arg_key_slot, *p, strlen(*p), flags);
569
570 if (r >= 0)
571 break;
572 }
573 }
574
575 return r;
576 }
577
578 static int help(void) {
579 _cleanup_free_ char *link = NULL;
580 int r;
581
582 r = terminal_urlify_man("systemd-cryptsetup@.service", "8", &link);
583 if (r < 0)
584 return log_oom();
585
586 printf("%s attach VOLUME SOURCEDEVICE [PASSWORD] [OPTIONS]\n"
587 "%s detach VOLUME\n\n"
588 "Attaches or detaches an encrypted block device.\n"
589 "\nSee the %s for details.\n"
590 , program_invocation_short_name
591 , program_invocation_short_name
592 , link
593 );
594
595 return 0;
596 }
597
598 int main(int argc, char *argv[]) {
599 _cleanup_(crypt_freep) struct crypt_device *cd = NULL;
600 int r = -EINVAL;
601
602 if (argc <= 1) {
603 r = help();
604 goto finish;
605 }
606
607 if (argc < 3) {
608 log_error("This program requires at least two arguments.");
609 goto finish;
610 }
611
612 log_setup_service();
613
614 umask(0022);
615
616 if (streq(argv[1], "attach")) {
617 uint32_t flags = 0;
618 unsigned tries;
619 usec_t until;
620 crypt_status_info status;
621 const char *key_file = NULL;
622
623 /* Arguments: systemd-cryptsetup attach VOLUME SOURCE-DEVICE [PASSWORD] [OPTIONS] */
624
625 if (argc < 4) {
626 log_error("attach requires at least two arguments.");
627 goto finish;
628 }
629
630 if (argc >= 5 &&
631 argv[4][0] &&
632 !streq(argv[4], "-") &&
633 !streq(argv[4], "none")) {
634
635 if (!path_is_absolute(argv[4]))
636 log_error("Password file path '%s' is not absolute. Ignoring.", argv[4]);
637 else
638 key_file = argv[4];
639 }
640
641 if (argc >= 6 && argv[5][0] && !streq(argv[5], "-")) {
642 if (parse_options(argv[5]) < 0)
643 goto finish;
644 }
645
646 /* A delicious drop of snake oil */
647 mlockall(MCL_FUTURE);
648
649 if (arg_header) {
650 log_debug("LUKS header: %s", arg_header);
651 r = crypt_init(&cd, arg_header);
652 } else
653 r = crypt_init(&cd, argv[3]);
654 if (r < 0) {
655 log_error_errno(r, "crypt_init() failed: %m");
656 goto finish;
657 }
658
659 crypt_set_log_callback(cd, cryptsetup_log_glue, NULL);
660
661 status = crypt_status(cd, argv[2]);
662 if (IN_SET(status, CRYPT_ACTIVE, CRYPT_BUSY)) {
663 log_info("Volume %s already active.", argv[2]);
664 r = 0;
665 goto finish;
666 }
667
668 if (arg_readonly)
669 flags |= CRYPT_ACTIVATE_READONLY;
670
671 if (arg_discards)
672 flags |= CRYPT_ACTIVATE_ALLOW_DISCARDS;
673
674 if (arg_timeout == USEC_INFINITY)
675 until = 0;
676 else
677 until = now(CLOCK_MONOTONIC) + arg_timeout;
678
679 arg_key_size = (arg_key_size > 0 ? arg_key_size : (256 / 8));
680
681 if (key_file) {
682 struct stat st;
683
684 /* Ideally we'd do this on the open fd, but since this is just a
685 * warning it's OK to do this in two steps. */
686 if (stat(key_file, &st) >= 0 && S_ISREG(st.st_mode) && (st.st_mode & 0005))
687 log_warning("Key file %s is world-readable. This is not a good idea!", key_file);
688 }
689
690 for (tries = 0; arg_tries == 0 || tries < arg_tries; tries++) {
691 _cleanup_strv_free_erase_ char **passwords = NULL;
692
693 if (!key_file) {
694 r = get_password(argv[2], argv[3], until, tries == 0 && !arg_verify, &passwords);
695 if (r == -EAGAIN)
696 continue;
697 if (r < 0)
698 goto finish;
699 }
700
701 if (streq_ptr(arg_type, CRYPT_TCRYPT))
702 r = attach_tcrypt(cd, argv[2], key_file, passwords, flags);
703 else
704 r = attach_luks_or_plain(cd,
705 argv[2],
706 key_file,
707 arg_header ? argv[3] : NULL,
708 passwords,
709 flags);
710 if (r >= 0)
711 break;
712 if (r == -EAGAIN) {
713 key_file = NULL;
714 continue;
715 }
716 if (r != -EPERM) {
717 log_error_errno(r, "Failed to activate: %m");
718 goto finish;
719 }
720
721 log_warning("Invalid passphrase.");
722 }
723
724 if (arg_tries != 0 && tries >= arg_tries) {
725 log_error("Too many attempts; giving up.");
726 r = -EPERM;
727 goto finish;
728 }
729
730 } else if (streq(argv[1], "detach")) {
731
732 r = crypt_init_by_name(&cd, argv[2]);
733 if (r == -ENODEV) {
734 log_info("Volume %s already inactive.", argv[2]);
735 r = 0;
736 goto finish;
737 }
738 if (r < 0) {
739 log_error_errno(r, "crypt_init_by_name() failed: %m");
740 goto finish;
741 }
742
743 crypt_set_log_callback(cd, cryptsetup_log_glue, NULL);
744
745 r = crypt_deactivate(cd, argv[2]);
746 if (r < 0) {
747 log_error_errno(r, "Failed to deactivate: %m");
748 goto finish;
749 }
750
751 } else {
752 log_error("Unknown verb %s.", argv[1]);
753 goto finish;
754 }
755
756 r = 0;
757
758 finish:
759 free(arg_cipher);
760 free(arg_hash);
761 free(arg_header);
762 strv_free(arg_tcrypt_keyfiles);
763
764 return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
765 }