cryptsetup-generator.c revision 4469ff4adebbed4778e7fe767f0165776c1ba62a
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering This file is part of systemd.
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering Copyright 2010 Lennart Poettering
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering systemd is free software; you can redistribute it and/or modify it
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering under the terms of the GNU Lesser General Public License as published by
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering the Free Software Foundation; either version 2.1 of the License, or
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering (at your option) any later version.
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering systemd is distributed in the hope that it will be useful, but
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering Lesser General Public License for more details.
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering You should have received a copy of the GNU Lesser General Public License
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
31885cd5e38ec9807a6a7ab32660cf8c2fcf48f7Zbigniew Jędrzejewski-Szmekstatic bool arg_enabled = true;
b68fa010f72599e6da5822feda5ae3a47a4e63d8Simon Peetersstatic bool arg_read_crypttab = true;
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poetteringstatic bool has_option(const char *haystack, const char *needle) {
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering const char *f = haystack;
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering if (f[l] != 0 && f[l] != ',') {
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering _cleanup_free_ char *p = NULL, *n = NULL, *d = NULL, *u = NULL, *from = NULL, *to = NULL, *e = NULL;
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering log_error("Device '%s' cannot be both 'tmp' and 'swap'. Ignoring.", name);
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering n = unit_name_from_path_instance("systemd-cryptsetup", name, ".service");
aaf7eb81be912e7bed939f31e3bc4c631b2552b3Lennart Poettering log_error("Failed to create unit file %s: %m", p);
aaf7eb81be912e7bed939f31e3bc4c631b2552b3Lennart Poettering "# Automatically generated by systemd-cryptsetup-generator\n\n"
aaf7eb81be912e7bed939f31e3bc4c631b2552b3Lennart Poettering "Description=Cryptography Setup for %I\n"
aaf7eb81be912e7bed939f31e3bc4c631b2552b3Lennart Poettering "Documentation=man:systemd-cryptsetup@.service(8) man:crypttab(5)\n"
aaf7eb81be912e7bed939f31e3bc4c631b2552b3Lennart Poettering "SourcePath=/etc/crypttab\n"
aaf7eb81be912e7bed939f31e3bc4c631b2552b3Lennart Poettering "Conflicts=umount.target\n"
aaf7eb81be912e7bed939f31e3bc4c631b2552b3Lennart Poettering "DefaultDependencies=no\n"
aaf7eb81be912e7bed939f31e3bc4c631b2552b3Lennart Poettering "BindsTo=dev-mapper-%i.device\n"
aaf7eb81be912e7bed939f31e3bc4c631b2552b3Lennart Poettering "IgnoreOnIsolate=true\n"
aaf7eb81be912e7bed939f31e3bc4c631b2552b3Lennart Poettering "After=systemd-readahead-collect.service systemd-readahead-replay.service\n",
aaf7eb81be912e7bed939f31e3bc4c631b2552b3Lennart Poettering "Before=cryptsetup.target\n");
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering fputs("After=systemd-random-seed.service\n", f);
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering "RequiresMountsFor=%s\n",
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering "BindsTo=%s\n"
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering "Before=umount.target\n",
0bee65f0622c4faa8ac8ae771cc0c8a936dfa284Lennart Poettering "RequiresMountsFor=%s\n",
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering "\n[Service]\n"
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering "Type=oneshot\n"
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering "RemainAfterExit=yes\n"
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering "TimeoutSec=0\n" /* the binary handles timeouts anyway */
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering "ExecStart=" SYSTEMD_CRYPTSETUP_PATH " attach '%s' '%s' '%s' '%s'\n"
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering "ExecStop=" SYSTEMD_CRYPTSETUP_PATH " detach '%s'\n",
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering name, u, strempty(password), strempty(options),
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering "ExecStartPost=/sbin/mke2fs '/dev/mapper/%s'\n",
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering "ExecStartPost=/sbin/mkswap '/dev/mapper/%s'\n",
ccd06097c79218f7d5ea4c21721bbcbc7c467dcaZbigniew Jędrzejewski-Szmek if (asprintf(&from, "../%s", n) < 0)
0bee65f0622c4faa8ac8ae771cc0c8a936dfa284Lennart Poettering to = strjoin(arg_dest, "/", d, ".wants/", n, NULL);
0bee65f0622c4faa8ac8ae771cc0c8a936dfa284Lennart Poettering log_error("Failed to create symlink %s: %m", to);
0bee65f0622c4faa8ac8ae771cc0c8a936dfa284Lennart Poettering to = strjoin(arg_dest, "/cryptsetup.target.requires/", n, NULL);
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering to = strjoin(arg_dest, "/cryptsetup.target.wants/", n, NULL);
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering log_error("Failed to create symlink %s: %m", to);
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering to = strjoin(arg_dest, "/dev-mapper-", e, ".device.requires/", n, NULL);
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering log_error("Failed to create symlink %s: %m", to);
aaf7eb81be912e7bed939f31e3bc4c631b2552b3Lennart Poettering p = strjoin(arg_dest, "/dev-mapper-", e, ".device.d/50-job-timeout-sec-0.conf", NULL);
return log_oom();
r = write_string_file(p,
static int parse_proc_cmdline(char ***arg_proc_cmdline_disks, char ***arg_proc_cmdline_options, char **arg_proc_cmdline_keyfile) {
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();
return log_oom();
if (in_initrd()) {
return log_oom();
if (*arg_proc_cmdline_keyfile)
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();
if (parse_proc_cmdline(&arg_proc_cmdline_disks, &arg_proc_cmdline_options, &arg_proc_cmdline_keyfile) < 0)
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_options) {
if (options)
if (!proc_options)
return log_oom();
if (arg_proc_cmdline_disks) {
return log_oom();
r = EXIT_FAILURE;
return log_oom();
r = EXIT_FAILURE;
next:
return log_oom();
if (arg_proc_cmdline_options) {
if (options)
if (!options)
return log_oom();
} else if (!options) {
if (!options)
return log_oom();
if (!options) {
if (!options)
return log_oom();
r = EXIT_FAILURE;