3
3
* Plymouth - Read a password from Plymouth and output it
5
* Copyright © 2010-2012 Teddy Hogeborn
6
* Copyright © 2010-2012 Björn Påhlsson
8
* This program is free software: you can redistribute it and/or
9
* modify it under the terms of the GNU General Public License as
10
* published by the Free Software Foundation, either version 3 of the
11
* License, or (at your option) any later version.
13
* This program is distributed in the hope that it will be useful, but
5
* Copyright © 2010-2021 Teddy Hogeborn
6
* Copyright © 2010-2021 Björn Påhlsson
8
* This file is part of Mandos.
10
* Mandos is free software: you can redistribute it and/or modify it
11
* under the terms of the GNU General Public License as published by
12
* the Free Software Foundation, either version 3 of the License, or
13
* (at your option) any later version.
15
* Mandos is distributed in the hope that it will be useful, but
14
16
* WITHOUT ANY WARRANTY; without even the implied warranty of
15
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
18
* General Public License for more details.
18
20
* You should have received a copy of the GNU General Public License
19
* along with this program. If not, see
20
* <http://www.gnu.org/licenses/>.
21
* along with Mandos. If not, see <http://www.gnu.org/licenses/>.
22
23
* Contact the authors at <mandos@recompile.se>.
25
#define _GNU_SOURCE /* asprintf(), TEMP_FAILURE_RETRY() */
26
#include <signal.h> /* sig_atomic_t, struct sigaction,
27
sigemptyset(), sigaddset(), SIGINT,
28
SIGHUP, SIGTERM, sigaction(),
26
#define _GNU_SOURCE /* program_invocation_short_name,
27
vasprintf(), asprintf(),
28
TEMP_FAILURE_RETRY() */
29
#include <sys/types.h> /* sig_atomic_t, pid_t, setuid(),
30
geteuid(), setsid() */
31
#include <argp.h> /* argp_program_version,
32
argp_program_bug_address,
35
ARGP_ERR_UNKNOWN, struct argp,
36
argp_parse(), ARGP_IN_ORDER */
37
#include <stddef.h> /* NULL, size_t */
30
38
#include <stdbool.h> /* bool, false, true */
39
#include <stdio.h> /* FILE, fprintf(), vfprintf(),
40
vasprintf(), stderr, asprintf(),
41
fopen(), fscanf(), fclose(),
43
#include <stdarg.h> /* va_list, va_start(), vfprintf() */
44
#include <errno.h> /* program_invocation_short_name,
45
errno, ENOMEM, EINTR, ENOENT,
47
#include <string.h> /* strerror(), strdup(), memcmp() */
48
#include <error.h> /* error() */
49
#include <stdlib.h> /* free(), getenv(), malloc(),
50
reallocarray(), realloc(),
51
EXIT_FAILURE, EXIT_SUCCESS */
52
#include <unistd.h> /* TEMP_FAILURE_RETRY(), setuid(),
53
geteuid(), setsid(), chdir(),
54
dup2(), STDERR_FILENO,
55
STDOUT_FILENO, fork(), _exit(),
56
execv(), ssize_t, readlink(),
57
close(), read(), access(), X_OK */
58
#include <signal.h> /* kill(), SIGTERM, struct sigaction,
59
sigemptyset(), SIGINT, SIGHUP,
60
sigaddset(), SIG_IGN */
61
#include <sys/wait.h> /* waitpid(), WIFEXITED(),
62
WEXITSTATUS(), WIFSIGNALED(),
64
#include <iso646.h> /* not, and, or */
65
#include <sysexits.h> /* EX_OSERR, EX_USAGE,
67
#include <stdint.h> /* SIZE_MAX */
68
#include <dirent.h> /* struct dirent, scandir(),
70
#include <inttypes.h> /* uintmax_t, strtoumax(), SCNuMAX,
72
#include <sys/stat.h> /* struct stat, lstat(), S_ISLNK() */
31
73
#include <fcntl.h> /* open(), O_RDONLY */
32
#include <iso646.h> /* and, or, not*/
33
#include <sys/types.h> /* size_t, ssize_t, pid_t, struct
35
#include <sys/wait.h> /* waitpid() */
36
#include <stddef.h> /* NULL */
37
#include <string.h> /* strchr(), memcmp() */
38
#include <stdio.h> /* asprintf(), perror(), fopen(),
39
fscanf(), vasprintf(), fprintf(),
41
#include <unistd.h> /* close(), readlink(), read(),
42
fork(), setsid(), chdir(), dup2(),
43
STDERR_FILENO, execv(), access() */
44
#include <stdlib.h> /* free(), EXIT_FAILURE, realloc(),
45
EXIT_SUCCESS, malloc(), _exit(),
47
#include <dirent.h> /* scandir(), alphasort() */
48
#include <inttypes.h> /* intmax_t, strtoumax(), SCNuMAX */
49
#include <sys/stat.h> /* struct stat, lstat() */
50
#include <sysexits.h> /* EX_OSERR, EX_UNAVAILABLE */
51
#include <error.h> /* error() */
52
#include <errno.h> /* TEMP_FAILURE_RETRY */
53
74
#include <argz.h> /* argz_count(), argz_extract() */
54
#include <stdarg.h> /* va_list, va_start(), ... */
56
76
sig_atomic_t interrupted_by_signal = 0;
77
const char *argp_program_version = "plymouth " VERSION;
78
const char *argp_program_bug_address = "<mandos@recompile.se>";
58
80
/* Used by Ubuntu 11.04 (Natty Narwahl) */
59
const char plymouth_old_pid[] = "/dev/.initramfs/plymouth.pid";
81
const char plymouth_old_old_pid[] = "/dev/.initramfs/plymouth.pid";
60
82
/* Used by Ubuntu 11.10 (Oneiric Ocelot) */
61
const char plymouth_pid[] = "/run/initramfs/plymouth.pid";
83
const char plymouth_old_pid[] = "/run/initramfs/plymouth.pid";
84
/* Used by Debian 9 (stretch) */
85
const char plymouth_pid[] = "/run/plymouth/pid";
63
87
const char plymouth_path[] = "/bin/plymouth";
64
88
const char plymouthd_path[] = "/sbin/plymouthd";
381
464
argz_extract(cmdline, cmdline_len, argv); /* Create argv */
382
return (const char **)argv;
385
468
int main(__attribute__((unused))int argc,
386
469
__attribute__((unused))char **argv){
388
471
char *prompt_arg;
389
472
pid_t plymouth_command_pid;
477
struct argp_option options[] = {
478
{ .name = "prompt", .key = 128, .arg = "PROMPT",
479
.doc = "The prompt to show" },
480
{ .name = "debug", .key = 129,
481
.doc = "Debug mode" },
485
__attribute__((nonnull(3)))
486
error_t parse_opt (int key, char *arg, __attribute__((unused))
487
struct argp_state *state){
490
case 128: /* --prompt */
493
fprintf_plus(stderr, "Custom prompt \"%s\"\n", prompt);
496
case 129: /* --debug */
500
return ARGP_ERR_UNKNOWN;
505
struct argp argp = { .options = options, .parser = parse_opt,
507
.doc = "Mandos plymouth -- Read and"
508
" output a password" };
509
ret = argp_parse(&argp, argc, argv, ARGP_IN_ORDER, NULL, NULL);
516
error_plus(0, errno, "argp_parse");
519
error_plus(0, errno, "argp_parse");
393
524
/* test -x /bin/plymouth */
394
525
ret = access(plymouth_path, X_OK);
396
527
/* Plymouth is probably not installed. Don't print an error
397
528
message, just exit. */
530
fprintf_plus(stderr, "Plymouth (%s) not found\n",
398
533
exit(EX_UNAVAILABLE);