+ if (!arg_enabled)
+ return EXIT_SUCCESS;
+
+ if (arg_read_crypttab) {
+ f = fopen("/etc/crypttab", "re");
+
+ if (!f) {
+ if (errno == ENOENT)
+ r = EXIT_SUCCESS;
+ else {
+ r = EXIT_FAILURE;
+ log_error("Failed to open /etc/crypttab: %m");
+ }
+ } else for (;;) {
+ char line[LINE_MAX], *l;
+ char _cleanup_free_ *name = NULL, *device = NULL, *password = NULL, *options = NULL;
+ int k;
+
+ if (!fgets(line, sizeof(line), f))
+ break;
+
+ n++;
+
+ l = strstrip(line);
+ if (*l == '#' || *l == 0)
+ continue;
+
+ k = sscanf(l, "%ms %ms %ms %ms", &name, &device, &password, &options);
+ if (k < 2 || k > 4) {
+ log_error("Failed to parse /etc/crypttab:%u, ignoring.", n);
+ r = EXIT_FAILURE;
+ continue;
+ }
+
+ if (arg_proc_cmdline_disks) {
+ /*
+ If luks UUIDs are specified on the kernel command line, use them as a filter
+ for /etc/crypttab and only generate units for those.
+ */
+ STRV_FOREACH(i, arg_proc_cmdline_disks) {
+ char _cleanup_free_ *proc_device = NULL, *proc_name = NULL;
+ const char *p = *i;
+
+ if (startswith(p, "luks-"))
+ p += 5;
+
+ proc_name = strappend("luks-", p);
+ proc_device = strappend("UUID=", p);
+
+ if (!proc_name || !proc_device)
+ return log_oom();
+
+ if (streq(proc_device, device) || streq(proc_name, name)) {
+ if (create_disk(name, device, password, options) < 0)
+ r = EXIT_FAILURE;
+
+ if (strv_extend(&arg_proc_cmdline_disks_done, p) < 0)
+ return log_oom();
+ }
+ }
+ } else {
+ if (create_disk(name, device, password, options) < 0)
+ r = EXIT_FAILURE;
+ }