cryptsetup-generator.c revision 2b68185ac97a98bf9d6f31b2ac1fddbaaffaa887
0fdda69ce3627d501e4bb3103765f676bb1ab061Laszlo Hordos/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
963cc96f97623aac2218f625e558cff1ddaea8c1Laszlo Hordos This file is part of systemd.
0fdda69ce3627d501e4bb3103765f676bb1ab061Laszlo Hordos Copyright 2010 Lennart Poettering
0fdda69ce3627d501e4bb3103765f676bb1ab061Laszlo Hordos systemd is free software; you can redistribute it and/or modify it
0fdda69ce3627d501e4bb3103765f676bb1ab061Laszlo Hordos under the terms of the GNU Lesser General Public License as published by
0fdda69ce3627d501e4bb3103765f676bb1ab061Laszlo Hordos the Free Software Foundation; either version 2.1 of the License, or
0fdda69ce3627d501e4bb3103765f676bb1ab061Laszlo Hordos (at your option) any later version.
0fdda69ce3627d501e4bb3103765f676bb1ab061Laszlo Hordos systemd is distributed in the hope that it will be useful, but
0fdda69ce3627d501e4bb3103765f676bb1ab061Laszlo Hordos WITHOUT ANY WARRANTY; without even the implied warranty of
0fdda69ce3627d501e4bb3103765f676bb1ab061Laszlo Hordos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0fdda69ce3627d501e4bb3103765f676bb1ab061Laszlo Hordos Lesser General Public License for more details.
0fdda69ce3627d501e4bb3103765f676bb1ab061Laszlo Hordos You should have received a copy of the GNU Lesser General Public License
0fdda69ce3627d501e4bb3103765f676bb1ab061Laszlo Hordos along with systemd; If not, see <http://www.gnu.org/licenses/>.
0fdda69ce3627d501e4bb3103765f676bb1ab061Laszlo Hordosstatic bool arg_enabled = true;
0fdda69ce3627d501e4bb3103765f676bb1ab061Laszlo Hordosstatic bool arg_read_crypttab = true;
f2f8138695e157f9ce4a11fa2f93d7d44a36d243Laszlo Hordosstatic bool has_option(const char *haystack, const char *needle) {
0fdda69ce3627d501e4bb3103765f676bb1ab061Laszlo Hordos const char *f = haystack;
b1ad84aa02aa5c8ee457e35d790d2e91691da517Laszlo Hordos return false;
b1ad84aa02aa5c8ee457e35d790d2e91691da517Laszlo Hordos if (f[l] != 0 && f[l] != ',') {
7cffd25e51581b0461c6cf208995b8c5d66cb166Jon Branch return true;
7cffd25e51581b0461c6cf208995b8c5d66cb166Jon Branch return false;
b1ad84aa02aa5c8ee457e35d790d2e91691da517Laszlo Hordos const char *options) {
0fdda69ce3627d501e4bb3103765f676bb1ab061Laszlo Hordos _cleanup_free_ char *p = NULL, *n = NULL, *d = NULL, *u = NULL, *from = NULL, *to = NULL, *e = NULL;
0fdda69ce3627d501e4bb3103765f676bb1ab061Laszlo Hordos n = unit_name_from_path_instance("systemd-cryptsetup", name, ".service");
b1ad84aa02aa5c8ee457e35d790d2e91691da517Laszlo Hordos log_error("Failed to create unit file %s: %m", p);
0fdda69ce3627d501e4bb3103765f676bb1ab061Laszlo Hordos "# Automatically generated by systemd-cryptsetup-generator\n\n"
521378a7df33486a3b37e90752117143cd7bd2a8Alin Brici "Description=Cryptography Setup for %I\n"
0fdda69ce3627d501e4bb3103765f676bb1ab061Laszlo Hordos "Documentation=man:systemd-cryptsetup@.service(8) man:crypttab(5)\n"
0fdda69ce3627d501e4bb3103765f676bb1ab061Laszlo Hordos "SourcePath=/etc/crypttab\n"
0fdda69ce3627d501e4bb3103765f676bb1ab061Laszlo Hordos "Conflicts=umount.target\n"
0fdda69ce3627d501e4bb3103765f676bb1ab061Laszlo Hordos "DefaultDependencies=no\n"
0fdda69ce3627d501e4bb3103765f676bb1ab061Laszlo Hordos "BindsTo=dev-mapper-%i.device\n"
0fdda69ce3627d501e4bb3103765f676bb1ab061Laszlo Hordos "After=systemd-readahead-collect.service systemd-readahead-replay.service\n",
963cc96f97623aac2218f625e558cff1ddaea8c1Laszlo Hordos "Before=cryptsetup.target\n");
0fdda69ce3627d501e4bb3103765f676bb1ab061Laszlo Hordos fputs("After=systemd-random-seed-load.service\n", f);
521378a7df33486a3b37e90752117143cd7bd2a8Alin Brici "RequiresMountsFor=%s\n",
521378a7df33486a3b37e90752117143cd7bd2a8Alin Brici "BindsTo=%s\n"
521378a7df33486a3b37e90752117143cd7bd2a8Alin Brici "After=%s\n"
521378a7df33486a3b37e90752117143cd7bd2a8Alin Brici "Before=umount.target\n",
963cc96f97623aac2218f625e558cff1ddaea8c1Laszlo Hordos "RequiresMountsFor=%s\n",
fprintf(f,
name);
fprintf(f,
name);
fprintf(f,
name);
fflush(f);
if (ferror(f)) {
return -errno;
return log_oom();
if (!noauto) {
if (!to)
return log_oom();
return -errno;
if (!nofail)
if (!to)
return log_oom();
return -errno;
return log_oom();
if (!to)
return log_oom();
return -errno;
free(p);
return log_oom();
r = write_string_file(p,
size_t l;
if (!word)
return log_oom();
arg_enabled = r;
if (in_initrd()) {
arg_enabled = r;
arg_read_crypttab = r;
if (in_initrd()) {
arg_read_crypttab = r;
return log_oom();
if (in_initrd()) {
return log_oom();
if (!*arg_proc_cmdline_keyfile)
return log_oom();
if (in_initrd()) {
if (*arg_proc_cmdline_keyfile)
if (!*arg_proc_cmdline_keyfile)
return log_oom();
int r = EXIT_SUCCESS;
return EXIT_FAILURE;
log_open();
return EXIT_FAILURE;
if (!arg_enabled)
return EXIT_SUCCESS;
if (arg_read_crypttab) {
r = EXIT_SUCCESS;
r = EXIT_FAILURE;
goto next;
r = EXIT_FAILURE;
goto next;
r = EXIT_FAILURE;
if (arg_proc_cmdline_disks) {
return log_oom();
r = EXIT_FAILURE;
return log_oom();
r = EXIT_FAILURE;
next:
return log_oom();
r = EXIT_FAILURE;