/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: 2009-11-05 19:16:46 UTC
  • Revision ID: teddy@fukt.bsnet.se-20091105191646-5l7bkq5h4wkh3huh
* mandos-monitor: New prototype version of interactive server
                  administraton tool using D-Bus.

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