/mandos/release

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/release
237.1.2 by Teddy Hogeborn
Further steps towards a D-Bus server interface, plus minor syntax
1
/*  -*- coding: utf-8 -*- */
2
/*
237.2.24 by Teddy Hogeborn
* plugins.d/askpass-fifo.c: Fix name in header.
3
 * Splashy - Read a password from splashy and output it
237.1.2 by Teddy Hogeborn
Further steps towards a D-Bus server interface, plus minor syntax
4
 * 
237.2.9 by Teddy Hogeborn
* README: Update copyright year; add "2009".
5
 * Copyright © 2008,2009 Teddy Hogeborn
6
 * Copyright © 2008,2009 Björn Påhlsson
237.1.2 by Teddy Hogeborn
Further steps towards a D-Bus server interface, plus minor syntax
7
 * 
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.
12
 * 
13
 * This program is distributed in the hope that it will be useful, but
14
 * WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 * General Public License for more details.
17
 * 
18
 * 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
 * 
237.2.126 by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes.
22
 * Contact the authors at <mandos@fukt.bsnet.se>.
237.1.2 by Teddy Hogeborn
Further steps towards a D-Bus server interface, plus minor syntax
23
 */
24
237.2.126 by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes.
25
#define _GNU_SOURCE		/* TEMP_FAILURE_RETRY(), asprintf() */
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
26
#include <signal.h>		/* sig_atomic_t, struct sigaction,
223 by Teddy Hogeborn
* .bzrignore (plugins.d/askpass-fifo): Added.
27
				   sigemptyset(), sigaddset(), SIGINT,
28
				   SIGHUP, SIGTERM, sigaction,
29
				   SIG_IGN, kill(), SIGKILL */
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
30
#include <stddef.h>		/* NULL */
31
#include <stdlib.h>		/* getenv() */
237.2.74 by Teddy Hogeborn
Overflows are not detected by sscanf(), so stop using it:
32
#include <stdio.h>		/* asprintf(), perror() */
237.2.27 by Teddy Hogeborn
* plugin-runner.c (main): Use "sscanf" instead of "strtol"; using the
33
#include <stdlib.h>		/* EXIT_FAILURE, free(),
223 by Teddy Hogeborn
* .bzrignore (plugins.d/askpass-fifo): Added.
34
				   EXIT_SUCCESS */
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
35
#include <sys/types.h>		/* pid_t, DIR, struct dirent,
36
				   ssize_t */
37
#include <dirent.h>		/* opendir(), readdir(), closedir() */
237.2.74 by Teddy Hogeborn
Overflows are not detected by sscanf(), so stop using it:
38
#include <inttypes.h>		/* intmax_t, strtoimax() */
223 by Teddy Hogeborn
* .bzrignore (plugins.d/askpass-fifo): Added.
39
#include <sys/stat.h>		/* struct stat, lstat(), S_ISLNK */
40
#include <iso646.h>		/* not, or, and */
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
41
#include <unistd.h>		/* readlink(), fork(), execl(),
223 by Teddy Hogeborn
* .bzrignore (plugins.d/askpass-fifo): Added.
42
				   sleep(), dup2() STDERR_FILENO,
237.2.126 by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes.
43
				   STDOUT_FILENO, _exit(),
44
				   pause() */
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
45
#include <string.h>		/* memcmp() */
46
#include <errno.h>		/* errno */
47
#include <sys/wait.h>		/* waitpid(), WIFEXITED(),
48
				   WEXITSTATUS() */
49
237.2.152 by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>.
50
#include <sysexits.h>		/* EX_OSERR, EX_OSFILE,
51
				   EX_UNAVAILABLE */
52
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
53
sig_atomic_t interrupted_by_signal = 0;
237.2.125 by Teddy Hogeborn
* plugin-runner.c (getplugin, add_environment, main): Handle EINTR
54
int signal_received;
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
55
237.2.125 by Teddy Hogeborn
* plugin-runner.c (getplugin, add_environment, main): Handle EINTR
56
static void termination_handler(int signum){
57
  if(interrupted_by_signal){
58
    return;
59
  }
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
60
  interrupted_by_signal = 1;
237.2.125 by Teddy Hogeborn
* plugin-runner.c (getplugin, add_environment, main): Handle EINTR
61
  signal_received = signum;
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
62
}
63
208 by Teddy Hogeborn
* Makefile (PLUGINS): Added "plugins.d/usplash".
64
int main(__attribute__((unused))int argc,
65
	 __attribute__((unused))char **argv){
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
66
  int ret = 0;
237.2.126 by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes.
67
  char *prompt = NULL;
68
  DIR *proc_dir = NULL;
69
  pid_t splashy_pid = 0;
70
  pid_t splashy_command_pid = 0;
237.2.152 by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>.
71
  int exitstatus = EXIT_FAILURE;
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
72
  
73
  /* Create prompt string */
74
  {
75
    const char *const cryptsource = getenv("cryptsource");
76
    const char *const crypttarget = getenv("crypttarget");
77
    const char *const prompt_start = "getpass "
78
      "Enter passphrase to unlock the disk";
79
    
80
    if(cryptsource == NULL){
81
      if(crypttarget == NULL){
82
	ret = asprintf(&prompt, "%s: ", prompt_start);
83
      } else {
84
	ret = asprintf(&prompt, "%s (%s): ", prompt_start,
85
		       crypttarget);
86
      }
87
    } else {
88
      if(crypttarget == NULL){
89
	ret = asprintf(&prompt, "%s %s: ", prompt_start, cryptsource);
90
      } else {
91
	ret = asprintf(&prompt, "%s %s (%s): ", prompt_start,
92
		       cryptsource, crypttarget);
93
      }
94
    }
95
    if(ret == -1){
237.2.126 by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes.
96
      prompt = NULL;
237.2.152 by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>.
97
      exitstatus = EX_OSERR;
237.2.126 by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes.
98
      goto failure;
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
99
    }
100
  }
101
  
102
  /* Find splashy process */
103
  {
104
    const char splashy_name[] = "/sbin/splashy";
237.2.126 by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes.
105
    proc_dir = opendir("/proc");
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
106
    if(proc_dir == NULL){
237.2.152 by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>.
107
      int e = errno;
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
108
      perror("opendir");
237.2.152 by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>.
109
      switch(e){
110
      case EACCES:
111
      case ENOTDIR:
112
      case ELOOP:
113
      case ENOENT:
114
      default:
115
	exitstatus = EX_OSFILE;
116
	break;
117
      case ENAMETOOLONG:
118
      case EMFILE:
119
      case ENFILE:
120
      case ENOMEM:
121
	exitstatus = EX_OSERR;
122
	break;
123
      }
237.2.126 by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes.
124
      goto failure;
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
125
    }
126
    for(struct dirent *proc_ent = readdir(proc_dir);
127
	proc_ent != NULL;
128
	proc_ent = readdir(proc_dir)){
237.2.27 by Teddy Hogeborn
* plugin-runner.c (main): Use "sscanf" instead of "strtol"; using the
129
      pid_t pid;
237.2.31 by Teddy Hogeborn
Fixes for sscanf usage:
130
      {
131
	intmax_t tmpmax;
237.2.74 by Teddy Hogeborn
Overflows are not detected by sscanf(), so stop using it:
132
	char *tmp;
133
	errno = 0;
134
	tmpmax = strtoimax(proc_ent->d_name, &tmp, 10);
135
	if(errno != 0 or tmp == proc_ent->d_name or *tmp != '\0'
136
	   or tmpmax != (pid_t)tmpmax){
237.2.31 by Teddy Hogeborn
Fixes for sscanf usage:
137
	  /* Not a process */
138
	  continue;
139
	}
140
	pid = (pid_t)tmpmax;
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
141
      }
142
      /* Find the executable name by doing readlink() on the
143
	 /proc/<pid>/exe link */
144
      char exe_target[sizeof(splashy_name)];
208 by Teddy Hogeborn
* Makefile (PLUGINS): Added "plugins.d/usplash".
145
      ssize_t sret;
146
      {
147
	char *exe_link;
148
	ret = asprintf(&exe_link, "/proc/%s/exe", proc_ent->d_name);
149
	if(ret == -1){
150
	  perror("asprintf");
237.2.152 by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>.
151
	  exitstatus = EX_OSERR;
237.2.126 by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes.
152
	  goto failure;
208 by Teddy Hogeborn
* Makefile (PLUGINS): Added "plugins.d/usplash".
153
	}
223 by Teddy Hogeborn
* .bzrignore (plugins.d/askpass-fifo): Added.
154
	
155
	/* Check that it refers to a symlink owned by root:root */
156
	struct stat exe_stat;
157
	ret = lstat(exe_link, &exe_stat);
158
	if(ret == -1){
237.2.25 by Teddy Hogeborn
* plugins.d/splashy.c (main): Do not abort if a process vanishes while
159
	  if(errno == ENOENT){
160
	    free(exe_link);
161
	    continue;
162
	  }
237.2.152 by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>.
163
	  int e = errno;
223 by Teddy Hogeborn
* .bzrignore (plugins.d/askpass-fifo): Added.
164
	  perror("lstat");
165
	  free(exe_link);
237.2.152 by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>.
166
	  switch(e){
167
	  case EACCES:
168
	  case ENOTDIR:
169
	  case ELOOP:
170
	  default:
171
	    exitstatus = EX_OSFILE;
172
	    break;
173
	  case ENAMETOOLONG:
174
	    exitstatus = EX_OSERR;
175
	    break;
176
	  }
237.2.126 by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes.
177
	  goto failure;
223 by Teddy Hogeborn
* .bzrignore (plugins.d/askpass-fifo): Added.
178
	}
179
	if(not S_ISLNK(exe_stat.st_mode)
180
	   or exe_stat.st_uid != 0
181
	   or exe_stat.st_gid != 0){
182
	  free(exe_link);
183
	  continue;
184
	}
185
	
208 by Teddy Hogeborn
* Makefile (PLUGINS): Added "plugins.d/usplash".
186
	sret = readlink(exe_link, exe_target, sizeof(exe_target));
187
	free(exe_link);
188
      }
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
189
      if((sret == ((ssize_t)sizeof(exe_target)-1))
190
	 and (memcmp(splashy_name, exe_target,
191
		     sizeof(exe_target)-1) == 0)){
192
	splashy_pid = pid;
193
	break;
194
      }
195
    }
196
    closedir(proc_dir);
237.2.126 by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes.
197
    proc_dir = NULL;
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
198
  }
199
  if(splashy_pid == 0){
237.2.152 by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>.
200
    exitstatus = EX_UNAVAILABLE;
237.2.126 by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes.
201
    goto failure;
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
202
  }
203
  
204
  /* Set up the signal handler */
205
  {
206
    struct sigaction old_action,
207
      new_action = { .sa_handler = termination_handler,
208
		     .sa_flags = 0 };
209
    sigemptyset(&new_action.sa_mask);
237.2.132 by Teddy Hogeborn
* init.d-mandos (Required-Start, Required-Stop): Bug fix: Added
210
    ret = sigaddset(&new_action.sa_mask, SIGINT);
211
    if(ret == -1){
212
      perror("sigaddset");
237.2.152 by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>.
213
      exitstatus = EX_OSERR;
237.2.132 by Teddy Hogeborn
* init.d-mandos (Required-Start, Required-Stop): Bug fix: Added
214
      goto failure;
215
    }
216
    ret = sigaddset(&new_action.sa_mask, SIGHUP);
217
    if(ret == -1){
218
      perror("sigaddset");
237.2.152 by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>.
219
      exitstatus = EX_OSERR;
237.2.132 by Teddy Hogeborn
* init.d-mandos (Required-Start, Required-Stop): Bug fix: Added
220
      goto failure;
221
    }
222
    ret = sigaddset(&new_action.sa_mask, SIGTERM);
237.2.125 by Teddy Hogeborn
* plugin-runner.c (getplugin, add_environment, main): Handle EINTR
223
    if(ret == -1){
224
      perror("sigaddset");
237.2.152 by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>.
225
      exitstatus = EX_OSERR;
237.2.126 by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes.
226
      goto failure;
237.2.125 by Teddy Hogeborn
* plugin-runner.c (getplugin, add_environment, main): Handle EINTR
227
    }
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
228
    ret = sigaction(SIGINT, NULL, &old_action);
229
    if(ret == -1){
230
      perror("sigaction");
237.2.152 by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>.
231
      exitstatus = EX_OSERR;
237.2.126 by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes.
232
      goto failure;
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
233
    }
223 by Teddy Hogeborn
* .bzrignore (plugins.d/askpass-fifo): Added.
234
    if(old_action.sa_handler != SIG_IGN){
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
235
      ret = sigaction(SIGINT, &new_action, NULL);
236
      if(ret == -1){
237
	perror("sigaction");
237.2.152 by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>.
238
	exitstatus = EX_OSERR;
237.2.126 by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes.
239
	goto failure;
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
240
      }
241
    }
242
    ret = sigaction(SIGHUP, NULL, &old_action);
243
    if(ret == -1){
244
      perror("sigaction");
237.2.152 by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>.
245
      exitstatus = EX_OSERR;
237.2.126 by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes.
246
      goto failure;
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
247
    }
223 by Teddy Hogeborn
* .bzrignore (plugins.d/askpass-fifo): Added.
248
    if(old_action.sa_handler != SIG_IGN){
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
249
      ret = sigaction(SIGHUP, &new_action, NULL);
250
      if(ret == -1){
251
	perror("sigaction");
237.2.152 by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>.
252
	exitstatus = EX_OSERR;
237.2.126 by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes.
253
	goto failure;
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
254
      }
255
    }
256
    ret = sigaction(SIGTERM, NULL, &old_action);
257
    if(ret == -1){
258
      perror("sigaction");
237.2.152 by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>.
259
      exitstatus = EX_OSERR;
237.2.126 by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes.
260
      goto failure;
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
261
    }
223 by Teddy Hogeborn
* .bzrignore (plugins.d/askpass-fifo): Added.
262
    if(old_action.sa_handler != SIG_IGN){
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
263
      ret = sigaction(SIGTERM, &new_action, NULL);
264
      if(ret == -1){
265
	perror("sigaction");
237.2.152 by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>.
266
	exitstatus = EX_OSERR;
237.2.126 by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes.
267
	goto failure;
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
268
      }
269
    }
270
  }
271
  
237.2.126 by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes.
272
  if(interrupted_by_signal){
273
    goto failure;
274
  }
275
  
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
276
  /* Fork off the splashy command to prompt for password */
237.2.126 by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes.
277
  splashy_command_pid = fork();
278
  if(splashy_command_pid != 0 and interrupted_by_signal){
279
    goto failure;
280
  }
281
  if(splashy_command_pid == -1){
282
    perror("fork");
237.2.152 by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>.
283
    exitstatus = EX_OSERR;
237.2.126 by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes.
284
    goto failure;
285
  }
286
  /* Child */
287
  if(splashy_command_pid == 0){
288
    if(not interrupted_by_signal){
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
289
      const char splashy_command[] = "/sbin/splashy_update";
237.2.126 by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes.
290
      execl(splashy_command, splashy_command, prompt, (char *)NULL);
291
      perror("execl");
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
292
    }
237.2.126 by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes.
293
    free(prompt);
294
    _exit(EXIT_FAILURE);
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
295
  }
296
  
297
  /* Parent */
298
  free(prompt);
237.2.126 by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes.
299
  prompt = NULL;
300
  
301
  if(interrupted_by_signal){
302
    goto failure;
303
  }
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
304
  
305
  /* Wait for command to complete */
237.2.126 by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes.
306
  {
223 by Teddy Hogeborn
* .bzrignore (plugins.d/askpass-fifo): Added.
307
    int status;
237.2.126 by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes.
308
    do {
309
      ret = waitpid(splashy_command_pid, &status, 0);
310
    } while(ret == -1 and errno == EINTR
311
	    and not interrupted_by_signal);
312
    if(interrupted_by_signal){
313
      goto failure;
314
    }
223 by Teddy Hogeborn
* .bzrignore (plugins.d/askpass-fifo): Added.
315
    if(ret == -1){
237.2.126 by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes.
316
      perror("waitpid");
223 by Teddy Hogeborn
* .bzrignore (plugins.d/askpass-fifo): Added.
317
      if(errno == ECHILD){
318
	splashy_command_pid = 0;
319
      }
320
    } else {
321
      /* The child process has exited */
322
      splashy_command_pid = 0;
237.2.126 by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes.
323
      if(WIFEXITED(status) and WEXITSTATUS(status) == 0){
223 by Teddy Hogeborn
* .bzrignore (plugins.d/askpass-fifo): Added.
324
	return EXIT_SUCCESS;
325
      }
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
326
    }
327
  }
237.2.126 by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes.
328
  
329
 failure:
330
  
331
  free(prompt);
332
  
333
  if(proc_dir != NULL){
334
    TEMP_FAILURE_RETRY(closedir(proc_dir));
335
  }
336
  
337
  if(splashy_command_pid != 0){
338
    TEMP_FAILURE_RETRY(kill(splashy_command_pid, SIGTERM));
223 by Teddy Hogeborn
* .bzrignore (plugins.d/askpass-fifo): Added.
339
    
237.2.126 by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes.
340
    TEMP_FAILURE_RETRY(kill(splashy_pid, SIGTERM));
341
    sleep(2);
342
    while(TEMP_FAILURE_RETRY(kill(splashy_pid, 0)) == 0){
343
      TEMP_FAILURE_RETRY(kill(splashy_pid, SIGKILL));
344
      sleep(1);
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
345
    }
237.2.132 by Teddy Hogeborn
* init.d-mandos (Required-Start, Required-Stop): Bug fix: Added
346
    pid_t new_splashy_pid = (pid_t)TEMP_FAILURE_RETRY(fork());
237.2.126 by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes.
347
    if(new_splashy_pid == 0){
348
      /* Child; will become new splashy process */
349
      
350
      /* Make the effective user ID (root) the only user ID instead of
351
	 the real user ID (_mandos) */
352
      ret = setuid(geteuid());
353
      if(ret == -1){
354
	perror("setuid");
355
      }
356
      
357
      setsid();
358
      ret = chdir("/");
359
      if(ret == -1){
360
	perror("chdir");
361
      }
362
/*       if(fork() != 0){ */
363
/* 	_exit(EXIT_SUCCESS); */
364
/*       } */
365
      ret = dup2(STDERR_FILENO, STDOUT_FILENO); /* replace stdout */
366
      if(ret == -1){
367
	perror("dup2");
237.2.152 by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>.
368
	_exit(EX_OSERR);
237.2.126 by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes.
369
      }
237.2.152 by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>.
370
      
237.2.126 by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes.
371
      execl("/sbin/splashy", "/sbin/splashy", "boot", (char *)NULL);
237.2.152 by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>.
372
      {
373
	int e = errno;
374
	perror("execl");
375
	switch(e){
376
	case EACCES:
377
	case ENOENT:
378
	case ENOEXEC:
379
	default:
380
	  _exit(EX_UNAVAILABLE);
381
	case ENAMETOOLONG:
382
	case E2BIG:
383
	case ENOMEM:
384
	  _exit(EX_OSERR);
385
	case ENOTDIR:
386
	case ELOOP:
387
	  _exit(EX_OSFILE);
388
	}
389
      }
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
390
    }
237.2.126 by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes.
391
  }
392
  
393
  if(interrupted_by_signal){
394
    struct sigaction signal_action;
395
    sigemptyset(&signal_action.sa_mask);
396
    signal_action.sa_handler = SIG_DFL;
237.2.132 by Teddy Hogeborn
* init.d-mandos (Required-Start, Required-Stop): Bug fix: Added
397
    ret = (int)TEMP_FAILURE_RETRY(sigaction(signal_received,
398
					    &signal_action, NULL));
237.2.126 by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes.
399
    if(ret == -1){
400
      perror("sigaction");
401
    }
402
    do {
403
      ret = raise(signal_received);
404
    } while(ret != 0 and errno == EINTR);
405
    if(ret != 0){
406
      perror("raise");
407
      abort();
408
    }
409
    TEMP_FAILURE_RETRY(pause());
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
410
  }
411
  
237.2.152 by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>.
412
  return exitstatus;
205 by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client,
413
}