/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to plugins.d/splashy.c

  • Committer: Teddy Hogeborn
  • Date: 2010-09-11 18:34:55 UTC
  • mfrom: (24.1.162 mandos)
  • Revision ID: teddy@fukt.bsnet.se-20100911183455-kmzttvbywdbfbepm
Merge from Björn.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
                                   SIG_IGN, kill(), SIGKILL */
30
30
#include <stddef.h>             /* NULL */
31
31
#include <stdlib.h>             /* getenv() */
32
 
#include <stdio.h>              /* asprintf(), perror() */
 
32
#include <stdio.h>              /* asprintf() */
33
33
#include <stdlib.h>             /* EXIT_FAILURE, free(),
34
34
                                   EXIT_SUCCESS */
35
35
#include <sys/types.h>          /* pid_t, DIR, struct dirent,
49
49
                                   E2BIG, EFAULT, EIO, ETXTBSY,
50
50
                                   EISDIR, ELIBBAD, EPERM, EINTR,
51
51
                                   ECHILD */
 
52
#include <error.h>              /* error() */
52
53
#include <sys/wait.h>           /* waitpid(), WIFEXITED(),
53
54
                                   WEXITSTATUS() */
54
55
#include <sysexits.h>           /* EX_OSERR, EX_OSFILE,
109
110
    proc_dir = opendir("/proc");
110
111
    if(proc_dir == NULL){
111
112
      int e = errno;
112
 
      perror("opendir");
 
113
      error(0, errno, "opendir");
113
114
      switch(e){
114
115
      case EACCES:
115
116
      case ENOTDIR:
151
152
        char *exe_link;
152
153
        ret = asprintf(&exe_link, "/proc/%s/exe", proc_ent->d_name);
153
154
        if(ret == -1){
154
 
          perror("asprintf");
 
155
          error(0, errno, "asprintf");
155
156
          exitstatus = EX_OSERR;
156
157
          goto failure;
157
158
        }
165
166
            continue;
166
167
          }
167
168
          int e = errno;
168
 
          perror("lstat");
 
169
          error(0, errno, "lstat");
169
170
          free(exe_link);
170
171
          switch(e){
171
172
          case EACCES:
213
214
    sigemptyset(&new_action.sa_mask);
214
215
    ret = sigaddset(&new_action.sa_mask, SIGINT);
215
216
    if(ret == -1){
216
 
      perror("sigaddset");
 
217
      error(0, errno, "sigaddset");
217
218
      exitstatus = EX_OSERR;
218
219
      goto failure;
219
220
    }
220
221
    ret = sigaddset(&new_action.sa_mask, SIGHUP);
221
222
    if(ret == -1){
222
 
      perror("sigaddset");
 
223
      error(0, errno, "sigaddset");
223
224
      exitstatus = EX_OSERR;
224
225
      goto failure;
225
226
    }
226
227
    ret = sigaddset(&new_action.sa_mask, SIGTERM);
227
228
    if(ret == -1){
228
 
      perror("sigaddset");
 
229
      error(0, errno, "sigaddset");
229
230
      exitstatus = EX_OSERR;
230
231
      goto failure;
231
232
    }
232
233
    ret = sigaction(SIGINT, NULL, &old_action);
233
234
    if(ret == -1){
234
 
      perror("sigaction");
 
235
      error(0, errno, "sigaction");
235
236
      exitstatus = EX_OSERR;
236
237
      goto failure;
237
238
    }
238
239
    if(old_action.sa_handler != SIG_IGN){
239
240
      ret = sigaction(SIGINT, &new_action, NULL);
240
241
      if(ret == -1){
241
 
        perror("sigaction");
 
242
        error(0, errno, "sigaction");
242
243
        exitstatus = EX_OSERR;
243
244
        goto failure;
244
245
      }
245
246
    }
246
247
    ret = sigaction(SIGHUP, NULL, &old_action);
247
248
    if(ret == -1){
248
 
      perror("sigaction");
 
249
      error(0, errno, "sigaction");
249
250
      exitstatus = EX_OSERR;
250
251
      goto failure;
251
252
    }
252
253
    if(old_action.sa_handler != SIG_IGN){
253
254
      ret = sigaction(SIGHUP, &new_action, NULL);
254
255
      if(ret == -1){
255
 
        perror("sigaction");
 
256
        error(0, errno, "sigaction");
256
257
        exitstatus = EX_OSERR;
257
258
        goto failure;
258
259
      }
259
260
    }
260
261
    ret = sigaction(SIGTERM, NULL, &old_action);
261
262
    if(ret == -1){
262
 
      perror("sigaction");
 
263
      error(0, errno, "sigaction");
263
264
      exitstatus = EX_OSERR;
264
265
      goto failure;
265
266
    }
266
267
    if(old_action.sa_handler != SIG_IGN){
267
268
      ret = sigaction(SIGTERM, &new_action, NULL);
268
269
      if(ret == -1){
269
 
        perror("sigaction");
 
270
        error(0, errno, "sigaction");
270
271
        exitstatus = EX_OSERR;
271
272
        goto failure;
272
273
      }
283
284
    goto failure;
284
285
  }
285
286
  if(splashy_command_pid == -1){
286
 
    perror("fork");
 
287
    error(0, errno, "fork");
287
288
    exitstatus = EX_OSERR;
288
289
    goto failure;
289
290
  }
293
294
      const char splashy_command[] = "/sbin/splashy_update";
294
295
      execl(splashy_command, splashy_command, prompt, (char *)NULL);
295
296
      int e = errno;
296
 
      perror("execl");
 
297
      error(0, errno, "execl");
297
298
      switch(e){
298
299
      case EACCES:
299
300
      case ENOENT:
341
342
      goto failure;
342
343
    }
343
344
    if(ret == -1){
344
 
      perror("waitpid");
 
345
      error(0, errno, "waitpid");
345
346
      if(errno == ECHILD){
346
347
        splashy_command_pid = 0;
347
348
      }
379
380
         the real user ID (_mandos) */
380
381
      ret = setuid(geteuid());
381
382
      if(ret == -1){
382
 
        perror("setuid");
 
383
        error(0, errno, "setuid");
383
384
      }
384
385
      
385
386
      setsid();
386
387
      ret = chdir("/");
387
388
      if(ret == -1){
388
 
        perror("chdir");
 
389
        error(0, errno, "chdir");
389
390
      }
390
391
/*       if(fork() != 0){ */
391
392
/*      _exit(EXIT_SUCCESS); */
392
393
/*       } */
393
394
      ret = dup2(STDERR_FILENO, STDOUT_FILENO); /* replace stdout */
394
395
      if(ret == -1){
395
 
        perror("dup2");
 
396
        error(0, errno, "dup2");
396
397
        _exit(EX_OSERR);
397
398
      }
398
399
      
399
400
      execl("/sbin/splashy", "/sbin/splashy", "boot", (char *)NULL);
400
401
      {
401
402
        int e = errno;
402
 
        perror("execl");
 
403
        error(0, errno, "execl");
403
404
        switch(e){
404
405
        case EACCES:
405
406
        case ENOENT:
425
426
    ret = (int)TEMP_FAILURE_RETRY(sigaction(signal_received,
426
427
                                            &signal_action, NULL));
427
428
    if(ret == -1){
428
 
      perror("sigaction");
 
429
      error(0, errno, "sigaction");
429
430
    }
430
431
    do {
431
432
      ret = raise(signal_received);
432
433
    } while(ret != 0 and errno == EINTR);
433
434
    if(ret != 0){
434
 
      perror("raise");
 
435
      error(0, errno, "raise");
435
436
      abort();
436
437
    }
437
438
    TEMP_FAILURE_RETRY(pause());