]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/cryptsetup/cryptsetup.c
8afff739907fdff6ed1924554619e378199b4403
[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 "main-func.h"
18 #include "mount-util.h"
19 #include "parse-util.h"
20 #include "path-util.h"
21 #include "string-util.h"
22 #include "strv.h"
23 #include "pretty-print.h"
24 #include "util.h"
25
26 /* internal helper */
27 #define ANY_LUKS "LUKS"
28 /* as in src/cryptsetup.h */
29 #define CRYPT_SECTOR_SIZE 512
30 #define CRYPT_MAX_SECTOR_SIZE 4096
31
32 static const char *arg_type = NULL; /* ANY_LUKS, CRYPT_LUKS1, CRYPT_LUKS2, CRYPT_TCRYPT or CRYPT_PLAIN */
33 static char *arg_cipher = NULL;
34 static unsigned arg_key_size = 0;
35 #if HAVE_LIBCRYPTSETUP_SECTOR_SIZE
36 static unsigned arg_sector_size = CRYPT_SECTOR_SIZE;
37 #endif
38 static int arg_key_slot = CRYPT_ANY_SLOT;
39 static unsigned arg_keyfile_size = 0;
40 static uint64_t arg_keyfile_offset = 0;
41 static char *arg_hash = NULL;
42 static char *arg_header = NULL;
43 static unsigned arg_tries = 3;
44 static bool arg_readonly = false;
45 static bool arg_verify = false;
46 static bool arg_discards = false;
47 static bool arg_tcrypt_hidden = false;
48 static bool arg_tcrypt_system = false;
49 #ifdef CRYPT_TCRYPT_VERA_MODES
50 static bool arg_tcrypt_veracrypt = false;
51 #endif
52 static char **arg_tcrypt_keyfiles = NULL;
53 static uint64_t arg_offset = 0;
54 static uint64_t arg_skip = 0;
55 static usec_t arg_timeout = USEC_INFINITY;
56
57 STATIC_DESTRUCTOR_REGISTER(arg_cipher, freep);
58 STATIC_DESTRUCTOR_REGISTER(arg_hash, freep);
59 STATIC_DESTRUCTOR_REGISTER(arg_header, freep);
60 STATIC_DESTRUCTOR_REGISTER(arg_tcrypt_keyfiles, strv_freep);
61
62 /* Options Debian's crypttab knows we don't:
63
64 precheck=
65 check=
66 checkargs=
67 noearly=
68 loud=
69 keyscript=
70 */
71
72 static int parse_one_option(const char *option) {
73 const char *val;
74 int r;
75
76 assert(option);
77
78 /* Handled outside of this tool */
79 if (STR_IN_SET(option, "noauto", "auto", "nofail", "fail", "_netdev"))
80 return 0;
81
82 if ((val = startswith(option, "cipher="))) {
83 r = free_and_strdup(&arg_cipher, val);
84 if (r < 0)
85 return log_oom();
86
87 } else if ((val = startswith(option, "size="))) {
88
89 r = safe_atou(val, &arg_key_size);
90 if (r < 0) {
91 log_error_errno(r, "Failed to parse %s, ignoring: %m", option);
92 return 0;
93 }
94
95 if (arg_key_size % 8) {
96 log_error("size= not a multiple of 8, ignoring.");
97 return 0;
98 }
99
100 arg_key_size /= 8;
101
102 } else if ((val = startswith(option, "sector-size="))) {
103
104 #if HAVE_LIBCRYPTSETUP_SECTOR_SIZE
105 r = safe_atou(val, &arg_sector_size);
106 if (r < 0) {
107 log_error_errno(r, "Failed to parse %s, ignoring: %m", option);
108 return 0;
109 }
110
111 if (arg_sector_size % 2) {
112 log_error("sector-size= not a multiple of 2, ignoring.");
113 return 0;
114 }
115
116 if (arg_sector_size < CRYPT_SECTOR_SIZE || arg_sector_size > CRYPT_MAX_SECTOR_SIZE) {
117 log_error("sector-size= is outside of %u and %u, ignoring.", CRYPT_SECTOR_SIZE, CRYPT_MAX_SECTOR_SIZE);
118 return 0;
119 }
120 #else
121 log_error("sector-size= is not supported, compiled with old libcryptsetup.");
122 return 0;
123 #endif
124
125 } else if ((val = startswith(option, "key-slot="))) {
126
127 arg_type = ANY_LUKS;
128 r = safe_atoi(val, &arg_key_slot);
129 if (r < 0) {
130 log_error_errno(r, "Failed to parse %s, ignoring: %m", option);
131 return 0;
132 }
133
134 } else if ((val = startswith(option, "tcrypt-keyfile="))) {
135
136 arg_type = CRYPT_TCRYPT;
137 if (path_is_absolute(val)) {
138 if (strv_extend(&arg_tcrypt_keyfiles, val) < 0)
139 return log_oom();
140 } else
141 log_error("Key file path \"%s\" is not absolute. Ignoring.", val);
142
143 } else if ((val = startswith(option, "keyfile-size="))) {
144
145 r = safe_atou(val, &arg_keyfile_size);
146 if (r < 0) {
147 log_error_errno(r, "Failed to parse %s, ignoring: %m", option);
148 return 0;
149 }
150
151 } else if ((val = startswith(option, "keyfile-offset="))) {
152 uint64_t off;
153
154 r = safe_atou64(val, &off);
155 if (r < 0) {
156 log_error_errno(r, "Failed to parse %s, ignoring: %m", option);
157 return 0;
158 }
159
160 if ((size_t) off != off) {
161 /* https://gitlab.com/cryptsetup/cryptsetup/issues/359 */
162 log_error("keyfile-offset= value would truncated to %zu, ignoring.", (size_t) off);
163 return 0;
164 }
165
166 arg_keyfile_offset = off;
167
168 } else if ((val = startswith(option, "hash="))) {
169 r = free_and_strdup(&arg_hash, val);
170 if (r < 0)
171 return log_oom();
172
173 } else if ((val = startswith(option, "header="))) {
174 arg_type = ANY_LUKS;
175
176 if (!path_is_absolute(val)) {
177 log_error("Header path \"%s\" is not absolute, refusing.", val);
178 return -EINVAL;
179 }
180
181 if (arg_header) {
182 log_error("Duplicate header= option, refusing.");
183 return -EINVAL;
184 }
185
186 arg_header = strdup(val);
187 if (!arg_header)
188 return log_oom();
189
190 } else if ((val = startswith(option, "tries="))) {
191
192 r = safe_atou(val, &arg_tries);
193 if (r < 0) {
194 log_error_errno(r, "Failed to parse %s, ignoring: %m", option);
195 return 0;
196 }
197
198 } else if (STR_IN_SET(option, "readonly", "read-only"))
199 arg_readonly = true;
200 else if (streq(option, "verify"))
201 arg_verify = true;
202 else if (STR_IN_SET(option, "allow-discards", "discard"))
203 arg_discards = true;
204 else if (streq(option, "luks"))
205 arg_type = ANY_LUKS;
206 else if (streq(option, "tcrypt"))
207 arg_type = CRYPT_TCRYPT;
208 else if (streq(option, "tcrypt-hidden")) {
209 arg_type = CRYPT_TCRYPT;
210 arg_tcrypt_hidden = true;
211 } else if (streq(option, "tcrypt-system")) {
212 arg_type = CRYPT_TCRYPT;
213 arg_tcrypt_system = true;
214 } else if (streq(option, "tcrypt-veracrypt")) {
215 #ifdef CRYPT_TCRYPT_VERA_MODES
216 arg_type = CRYPT_TCRYPT;
217 arg_tcrypt_veracrypt = true;
218 #else
219 log_error("This version of cryptsetup does not support tcrypt-veracrypt; refusing.");
220 return -EINVAL;
221 #endif
222 } else if (STR_IN_SET(option, "plain", "swap", "tmp"))
223 arg_type = CRYPT_PLAIN;
224 else if ((val = startswith(option, "timeout="))) {
225
226 r = parse_sec_fix_0(val, &arg_timeout);
227 if (r < 0) {
228 log_error_errno(r, "Failed to parse %s, ignoring: %m", option);
229 return 0;
230 }
231
232 } else if ((val = startswith(option, "offset="))) {
233
234 r = safe_atou64(val, &arg_offset);
235 if (r < 0)
236 return log_error_errno(r, "Failed to parse %s: %m", option);
237
238 } else if ((val = startswith(option, "skip="))) {
239
240 r = safe_atou64(val, &arg_skip);
241 if (r < 0)
242 return log_error_errno(r, "Failed to parse %s: %m", option);
243
244 } else if (!streq(option, "none"))
245 log_warning("Encountered unknown /etc/crypttab option '%s', ignoring.", option);
246
247 return 0;
248 }
249
250 static int parse_options(const char *options) {
251 const char *word, *state;
252 size_t l;
253 int r;
254
255 assert(options);
256
257 FOREACH_WORD_SEPARATOR(word, l, options, ",", state) {
258 _cleanup_free_ char *o;
259
260 o = strndup(word, l);
261 if (!o)
262 return -ENOMEM;
263 r = parse_one_option(o);
264 if (r < 0)
265 return r;
266 }
267
268 /* sanity-check options */
269 if (arg_type != NULL && !streq(arg_type, CRYPT_PLAIN)) {
270 if (arg_offset)
271 log_warning("offset= ignored with type %s", arg_type);
272 if (arg_skip)
273 log_warning("skip= ignored with type %s", arg_type);
274 }
275
276 return 0;
277 }
278
279 static char* disk_description(const char *path) {
280 static const char name_fields[] =
281 "ID_PART_ENTRY_NAME\0"
282 "DM_NAME\0"
283 "ID_MODEL_FROM_DATABASE\0"
284 "ID_MODEL\0";
285
286 _cleanup_(sd_device_unrefp) sd_device *device = NULL;
287 const char *i, *name;
288 struct stat st;
289
290 assert(path);
291
292 if (stat(path, &st) < 0)
293 return NULL;
294
295 if (!S_ISBLK(st.st_mode))
296 return NULL;
297
298 if (sd_device_new_from_devnum(&device, 'b', st.st_rdev) < 0)
299 return NULL;
300
301 NULSTR_FOREACH(i, name_fields)
302 if (sd_device_get_property_value(device, i, &name) >= 0 &&
303 !isempty(name))
304 return strdup(name);
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 static int run(int argc, char *argv[]) {
605 _cleanup_(crypt_freep) struct crypt_device *cd = NULL;
606 int r;
607
608 if (argc <= 1)
609 return help();
610
611 if (argc < 3) {
612 log_error("This program requires at least two arguments.");
613 return -EINVAL;
614 }
615
616 log_setup_service();
617
618 umask(0022);
619
620 if (streq(argv[1], "attach")) {
621 uint32_t flags = 0;
622 unsigned tries;
623 usec_t until;
624 crypt_status_info status;
625 const char *key_file = NULL;
626
627 /* Arguments: systemd-cryptsetup attach VOLUME SOURCE-DEVICE [PASSWORD] [OPTIONS] */
628
629 if (argc < 4) {
630 log_error("attach requires at least two arguments.");
631 return -EINVAL;
632 }
633
634 if (argc >= 5 &&
635 argv[4][0] &&
636 !streq(argv[4], "-") &&
637 !streq(argv[4], "none")) {
638
639 if (!path_is_absolute(argv[4]))
640 log_error("Password file path '%s' is not absolute. Ignoring.", argv[4]);
641 else
642 key_file = argv[4];
643 }
644
645 if (argc >= 6 && argv[5][0] && !streq(argv[5], "-")) {
646 r = parse_options(argv[5]);
647 if (r < 0)
648 return r;
649 }
650
651 /* A delicious drop of snake oil */
652 mlockall(MCL_FUTURE);
653
654 if (arg_header) {
655 log_debug("LUKS header: %s", arg_header);
656 r = crypt_init(&cd, arg_header);
657 } else
658 r = crypt_init(&cd, argv[3]);
659 if (r < 0)
660 return log_error_errno(r, "crypt_init() failed: %m");
661
662 crypt_set_log_callback(cd, cryptsetup_log_glue, NULL);
663
664 status = crypt_status(cd, argv[2]);
665 if (IN_SET(status, CRYPT_ACTIVE, CRYPT_BUSY)) {
666 log_info("Volume %s already active.", argv[2]);
667 return 0;
668 }
669
670 if (arg_readonly)
671 flags |= CRYPT_ACTIVATE_READONLY;
672
673 if (arg_discards)
674 flags |= CRYPT_ACTIVATE_ALLOW_DISCARDS;
675
676 if (arg_timeout == USEC_INFINITY)
677 until = 0;
678 else
679 until = now(CLOCK_MONOTONIC) + arg_timeout;
680
681 arg_key_size = (arg_key_size > 0 ? arg_key_size : (256 / 8));
682
683 if (key_file) {
684 struct stat st;
685
686 /* Ideally we'd do this on the open fd, but since this is just a
687 * warning it's OK to do this in two steps. */
688 if (stat(key_file, &st) >= 0 && S_ISREG(st.st_mode) && (st.st_mode & 0005))
689 log_warning("Key file %s is world-readable. This is not a good idea!", key_file);
690 }
691
692 for (tries = 0; arg_tries == 0 || tries < arg_tries; tries++) {
693 _cleanup_strv_free_erase_ char **passwords = NULL;
694
695 if (!key_file) {
696 r = get_password(argv[2], argv[3], until, tries == 0 && !arg_verify, &passwords);
697 if (r == -EAGAIN)
698 continue;
699 if (r < 0)
700 return r;
701 }
702
703 if (streq_ptr(arg_type, CRYPT_TCRYPT))
704 r = attach_tcrypt(cd, argv[2], key_file, passwords, flags);
705 else
706 r = attach_luks_or_plain(cd,
707 argv[2],
708 key_file,
709 arg_header ? argv[3] : NULL,
710 passwords,
711 flags);
712 if (r >= 0)
713 break;
714 if (r == -EAGAIN) {
715 key_file = NULL;
716 continue;
717 }
718 if (r != -EPERM)
719 return log_error_errno(r, "Failed to activate: %m");
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 return -EPERM;
727 }
728
729 } else if (streq(argv[1], "detach")) {
730
731 r = crypt_init_by_name(&cd, argv[2]);
732 if (r == -ENODEV) {
733 log_info("Volume %s already inactive.", argv[2]);
734 return 0;
735 }
736 if (r < 0)
737 return log_error_errno(r, "crypt_init_by_name() failed: %m");
738
739 crypt_set_log_callback(cd, cryptsetup_log_glue, NULL);
740
741 r = crypt_deactivate(cd, argv[2]);
742 if (r < 0)
743 return log_error_errno(r, "Failed to deactivate: %m");
744
745 } else {
746 log_error("Unknown verb %s.", argv[1]);
747 return -EINVAL;
748 }
749
750 return 0;
751 }
752
753 DEFINE_MAIN_FUNCTION(run);