cryptsetup-generator.c revision 74576bea7a50740f1aec423bac5e20f8ca7a8592
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2010 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include "log.h"
#include "util.h"
#include "unit-name.h"
#include "mkdir.h"
#include "virt.h"
#include "strv.h"
static const char *arg_dest = "/tmp";
static bool arg_enabled = true;
static bool arg_read_crypttab = true;
static char **arg_proc_cmdline_disks = NULL;
const char *f = haystack;
size_t l;
if (!haystack)
return false;
f++;
continue;
}
if (f[l] != 0 && f[l] != ',') {
f++;
continue;
}
return true;
}
return false;
}
static int create_disk(
const char *name,
const char *device,
const char *password,
const char *options) {
int r;
if (!n) {
r = log_oom();
goto fail;
}
if (!p) {
r = log_oom();
goto fail;
}
if (!u) {
r = log_oom();
goto fail;
}
d = unit_name_from_path(u, ".device");
if (!d) {
r = log_oom();
goto fail;
}
f = fopen(p, "wxe");
if (!f) {
r = -errno;
log_error("Failed to create unit file: %m");
goto fail;
}
fprintf(f,
"# Automatically generated by systemd-cryptsetup-generator\n\n"
"[Unit]\n"
"Description=Cryptography Setup for %%I\n"
"Documentation=man:systemd-cryptsetup@.service(8) man:crypttab(5)\n"
"Conflicts=umount.target\n"
"DefaultDependencies=no\n"
"BindsTo=%s dev-mapper-%%i.device\n"
"After=systemd-readahead-collect.service systemd-readahead-replay.service %s\n"
"Before=umount.target\n",
d, d);
if (!nofail)
fprintf(f,
"Before=cryptsetup.target\n");
fputs("After=systemd-random-seed-load.service\n", f);
else
fputs("Before=local-fs.target\n", f);
fprintf(f,
"\n[Service]\n"
"Type=oneshot\n"
"RemainAfterExit=yes\n"
"TimeoutSec=0\n" /* the binary handles timeouts anyway */
name);
fprintf(f,
name);
fprintf(f,
name);
fflush(f);
if (ferror(f)) {
r = -errno;
log_error("Failed to write file: %m");
goto fail;
}
r = log_oom();
goto fail;
}
if (!noauto) {
if (!to) {
r = log_oom();
goto fail;
}
r = -errno;
goto fail;
}
if (!nofail)
else
if (!to) {
r = log_oom();
goto fail;
}
r = -errno;
goto fail;
}
}
e = unit_name_escape(name);
if (!to) {
r = log_oom();
goto fail;
}
r = -errno;
goto fail;
}
r = 0;
fail:
free(p);
free(n);
free(d);
free(e);
if (f)
fclose(f);
return r;
}
static int parse_proc_cmdline(void) {
int r;
size_t l;
if (detect_container(NULL) > 0)
return 0;
if (r < 0) {
return 0;
}
char *word;
if (!word) {
r = log_oom();
goto finish;
}
if (r < 0)
else
arg_enabled = r;
if (in_initrd()) {
if (r < 0)
else
arg_enabled = r;
}
if (r < 0)
else
arg_read_crypttab = r;
if (in_initrd()) {
if (r < 0)
else
arg_read_crypttab = r;
}
char **t;
if (!t) {
r = log_oom();
goto finish;
}
if (in_initrd()) {
char **t;
if (!t) {
r = log_oom();
goto finish;
}
}
}
}
r = 0;
return r;
}
int r = EXIT_SUCCESS;
unsigned n = 0;
char **i;
log_error("This program takes three or no arguments.");
return EXIT_FAILURE;
}
if (argc > 1)
log_open();
umask(0022);
if (parse_proc_cmdline() < 0)
return EXIT_FAILURE;
if (!arg_enabled) {
r = EXIT_SUCCESS;
goto finish;
}
const char *p = *i;
if (startswith(p, "luks-"))
p += 5;
log_oom();
r = EXIT_FAILURE;
goto finish;
}
r = EXIT_FAILURE;
}
if (!arg_read_crypttab)
return r;
if (!f) {
r = EXIT_SUCCESS;
else {
r = EXIT_FAILURE;
}
goto finish;
}
for (;;) {
int k;
break;
n++;
if (*l == '#' || *l == 0)
continue;
if (k < 2 || k > 4) {
r = EXIT_FAILURE;
goto next;
}
r = EXIT_FAILURE;
next:
}
if (f)
fclose(f);
return r;
}