cryptsetup-generator.c revision 5430f7f2bc7330f3088b894166bf3524a067e3d8
/*-*- 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"
const char *arg_dest = "/tmp";
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;
r = -ENOMEM;
log_error("Failed to allocate unit name.");
goto fail;
}
r = -ENOMEM;
log_error("Failed to allocate unit file name.");
goto fail;
}
if (!(u = fstab_node_to_udev_node(device))) {
r = -ENOMEM;
log_error("Failed to allocate device node.");
goto fail;
}
if (!(d = unit_name_from_path(u, ".device"))) {
r = -ENOMEM;
log_error("Failed to allocate device name.");
goto fail;
}
if (!(f = fopen(p, "wxe"))) {
r = -errno;
log_error("Failed to create unit file: %m");
goto fail;
}
fprintf(f,
"[Unit]\n"
"Description=Cryptography Setup for %%I\n"
"Conflicts=umount.target\n"
"DefaultDependencies=no\n"
"BindTo=%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");
fprintf(f,
"After=systemd-random-seed-load.service\n");
else
fprintf(f,
"Before=local-fs.target\n");
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 = -ENOMEM;
goto fail;
}
if (!noauto) {
r = -ENOMEM;
goto fail;
}
r = -errno;
goto fail;
}
if (!nofail)
else
if (!to) {
r = -ENOMEM;
goto fail;
}
r = -errno;
goto fail;
}
}
e = unit_name_escape(name);
r = -ENOMEM;
goto fail;
}
r = -errno;
goto fail;
}
r = 0;
fail:
free(p);
free(n);
free(d);
free(e);
if (f)
fclose(f);
return r;
}
FILE *f;
int r = EXIT_SUCCESS;
unsigned n = 0;
if (argc > 2) {
log_error("This program takes one or no arguments.");
return EXIT_FAILURE;
}
if (argc > 1)
log_open();
umask(0022);
r = EXIT_SUCCESS;
else {
r = EXIT_FAILURE;
}
goto finish;
}
for (;;) {
int k;
break;
n++;
if (*l == '#' || *l == 0)
continue;
r = EXIT_FAILURE;
goto next;
}
r = EXIT_FAILURE;
next:
}
return r;
}