1
1
#define _GNU_SOURCE /* asprintf() */
2
2
#include <signal.h> /* sig_atomic_t, struct sigaction,
3
sigemptyset(), sigaddset(), SIGINT,
4
SIGHUP, SIGTERM, sigaction,
5
SIG_IGN, kill(), SIGKILL */
3
sigemptyset(), sigaddset(),
4
sigaction, SIGINT, SIG_IGN, SIGHUP,
5
SIGTERM, kill(), SIGKILL */
6
6
#include <stddef.h> /* NULL */
7
7
#include <stdlib.h> /* getenv() */
8
8
#include <stdio.h> /* asprintf(), perror() */
9
#include <stdlib.h> /* EXIT_FAILURE, free(), strtoul(),
9
#include <stdlib.h> /* EXIT_FAILURE, EXIT_SUCCESS,
11
11
#include <sys/types.h> /* pid_t, DIR, struct dirent,
13
13
#include <dirent.h> /* opendir(), readdir(), closedir() */
14
#include <sys/stat.h> /* struct stat, lstat(), S_ISLNK */
15
#include <iso646.h> /* not, or, and */
16
14
#include <unistd.h> /* readlink(), fork(), execl(),
17
sleep(), dup2() STDERR_FILENO,
18
STDOUT_FILENO, _exit() */
19
16
#include <string.h> /* memcmp() */
17
#include <iso646.h> /* and */
20
18
#include <errno.h> /* errno */
21
19
#include <sys/wait.h> /* waitpid(), WIFEXITED(),
27
25
interrupted_by_signal = 1;
30
int main(__attribute__((unused))int argc,
31
__attribute__((unused))char **argv){
28
int main(__attribute__((unused))int argc, char **argv){
34
31
/* Create prompt string */
80
77
/* Find the executable name by doing readlink() on the
81
78
/proc/<pid>/exe link */
80
ret = asprintf(&exe_link, "/proc/%s/exe", proc_ent->d_name);
82
87
char exe_target[sizeof(splashy_name)];
86
ret = asprintf(&exe_link, "/proc/%s/exe", proc_ent->d_name);
94
/* Check that it refers to a symlink owned by root:root */
96
ret = lstat(exe_link, &exe_stat);
104
if(not S_ISLNK(exe_stat.st_mode)
105
or exe_stat.st_uid != 0
106
or exe_stat.st_gid != 0){
111
sret = readlink(exe_link, exe_target, sizeof(exe_target));
88
ssize_t sret = readlink(exe_link, exe_target,
114
91
if((sret == ((ssize_t)sizeof(exe_target)-1))
115
92
and (memcmp(splashy_name, exe_target,
116
93
sizeof(exe_target)-1) == 0)){
193
170
const char splashy_command[] = "/sbin/splashy_update";
194
171
ret = execl(splashy_command, splashy_command, prompt,
196
if(not interrupted_by_signal){
173
if(not interrupted_by_signal and errno != ENOENT){
174
/* Don't report "File not found", since splashy might not be
207
186
/* Wait for command to complete */
208
if(not interrupted_by_signal and splashy_command_pid != 0){
210
ret = waitpid(splashy_command_pid, &status, 0);
216
splashy_command_pid = 0;
219
/* The child process has exited */
220
splashy_command_pid = 0;
221
if(not interrupted_by_signal and WIFEXITED(status)
222
and WEXITSTATUS(status)==0){
188
while(not interrupted_by_signal){
189
waitpid(splashy_command_pid, &status, 0);
190
if(not interrupted_by_signal
191
and WIFEXITED(status) and WEXITSTATUS(status)==0){
227
195
kill(splashy_pid, SIGTERM);
228
if(interrupted_by_signal and splashy_command_pid != 0){
196
if(interrupted_by_signal){
229
197
kill(splashy_command_pid, SIGTERM);
232
while(kill(splashy_pid, 0) == 0){
233
kill(splashy_pid, SIGKILL);
236
200
pid_t new_splashy_pid = fork();
237
201
if(new_splashy_pid == 0){
238
202
/* Child; will become new splashy process */
240
/* Make the effective user ID (root) the only user ID instead of
241
the real user ID (mandos) */
242
ret = setuid(geteuid());
203
while(kill(splashy_pid, 0)){
205
kill(splashy_pid, SIGKILL);
249
/* if(fork() != 0){ */
250
/* _exit(EXIT_SUCCESS); */
252
208
ret = dup2(STDERR_FILENO, STDOUT_FILENO); /* replace our stdout */
255
211
_exit(EXIT_FAILURE);
258
213
execl("/sbin/splashy", "/sbin/splashy", "boot", (char *)NULL);
259
if(not interrupted_by_signal){
265
216
return EXIT_FAILURE;