/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/plymouth.c

  • Committer: Teddy Hogeborn
  • Date: 2010-09-25 23:52:17 UTC
  • Revision ID: teddy@fukt.bsnet.se-20100925235217-4hhqfryz1ste6uw3
* mandos (ClientDBus.__init__): Bug fix: Translate "-" in client names
                                to "_" in D-Bus object paths.
  (MandosServer.handle_ipc): Bug fix: Send only address string to
                             D-Bus signal, not whole tuple.

* mandos-ctl: New options "--approve-by-default", "--deny-by-default",
              "--approval-delay", and "--approval-duration".
* mandos-ctl.xml (SYNOPSIS, OPTIONS): Document new options.

* mandos-monitor (MandosClientWidget.update): Fix spelling.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
#include <stdbool.h>            /* bool, false, true */
7
7
#include <fcntl.h>              /* open(), O_RDONLY */
8
8
#include <iso646.h>             /* and, or, not*/
9
 
#include <sys/types.h>          /* size_t, ssize_t, pid_t, struct dirent,
10
 
                                   waitpid() */
 
9
#include <sys/types.h>          /* size_t, ssize_t, pid_t, struct
 
10
                                   dirent, waitpid() */
11
11
#include <sys/wait.h>           /* waitpid() */
12
12
#include <stddef.h>             /* NULL */
13
13
#include <string.h>             /* strchr(), memcmp() */
14
 
#include <stdio.h>              /* asprintf(), perror(), fopen(), fscanf() */
15
 
#include <unistd.h>             /* close(), readlink(), read(), fork()
16
 
                                   setsid(), chdir(), dup2()
 
14
#include <stdio.h>              /* asprintf(), perror(), fopen(),
 
15
                                   fscanf() */
 
16
#include <unistd.h>             /* close(), readlink(), read(),
 
17
                                   fork(), setsid(), chdir(), dup2(),
17
18
                                   STDERR_FILENO, execv(), access() */
18
19
#include <stdlib.h>             /* free(), EXIT_FAILURE, realloc(),
19
20
                                   EXIT_SUCCESS, malloc(), _exit(),
21
22
#include <dirent.h>             /* scandir(), alphasort() */
22
23
#include <inttypes.h>           /* intmax_t, strtoumax(), SCNuMAX */
23
24
#include <sys/stat.h>           /* struct stat, lstat() */
24
 
#include <sysexits.h>           /* EX_OSERR */
 
25
#include <sysexits.h>           /* EX_OSERR, EX_UNAVAILABLE */
25
26
#include <error.h>              /* error() */
26
27
#include <errno.h>              /* TEMP_FAILURE_RETRY */
27
28
#include <argz.h>               /* argz_count(), argz_extract() */
30
31
const char plymouth_pid[] = "/dev/.initramfs/plymouth.pid";
31
32
const char plymouth_path[] = "/bin/plymouth";
32
33
const char plymouthd_path[] = "/sbin/plymouthd";
33
 
const char *plymouthd_default_argv[] = {"/sbin/plymouthd", "--mode=boot",
 
34
const char *plymouthd_default_argv[] = {"/sbin/plymouthd",
 
35
                                        "--mode=boot",
34
36
                                        "--attach-to-session",
35
 
                                        "--pid-file=/dev/.initramfs/plymouth.pid",
 
37
                                        "--pid-file="
 
38
                                        "/dev/.initramfs/"
 
39
                                        "plymouth.pid",
36
40
                                        NULL };
37
41
 
38
42
static void termination_handler(__attribute__((unused))int signum){
123
127
      if (tmp == NULL){
124
128
        error(0, errno, "realloc");
125
129
        free(new_argv);
126
 
        _exit(EXIT_FAILURE);
 
130
        _exit(EX_OSERR);
127
131
      }
128
132
      new_argv = (char **)tmp;
129
133
      new_argv[i] = strdup(argv[i]);
149
153
    error(0, errno, "waitpid");
150
154
    return false;
151
155
  }
152
 
  if(WIFEXITED(status) and WEXITSTATUS(status) == 0){
 
156
  if(WIFEXITED(status) and (WEXITSTATUS(status) == 0)){
153
157
    return true;
154
158
  }
155
159
  return false;
163
167
    errno = 0;
164
168
    maxvalue = strtoumax(proc_entry->d_name, &tmp, 10);
165
169
 
166
 
    if(errno != 0 or *tmp != '\0' or maxvalue != (uintmax_t)((pid_t)maxvalue)){
 
170
    if(errno != 0 or *tmp != '\0'
 
171
       or maxvalue != (uintmax_t)((pid_t)maxvalue)){
167
172
      return 0;
168
173
    }
169
174
  }
174
179
    error(0, errno, "asprintf");
175
180
    return 0;
176
181
  }
177
 
 
 
182
  
178
183
  struct stat exe_stat;
179
184
  ret = lstat(exe_link, &exe_stat);
180
185
  if(ret == -1){
191
196
    free(exe_link);
192
197
    return 0;
193
198
  }
194
 
 
 
199
  
195
200
  ssize_t sret = readlink(exe_link, exe_target, sizeof(exe_target));
196
201
  free(exe_link);
197
202
  if((sret != (ssize_t)sizeof(plymouth_path)-1) or
308
313
  /* test -x /bin/plymouth */
309
314
  ret = access(plymouth_path, X_OK);
310
315
  if(ret == -1){
311
 
    exit(EXIT_FAILURE);
 
316
    /* Plymouth is probably not installed.  Don't print an error
 
317
       message, just exit. */
 
318
    exit(EX_UNAVAILABLE);
312
319
  }
313
 
 
 
320
  
314
321
  { /* Add signal handlers */
315
322
    struct sigaction old_action,
316
323
      new_action = { .sa_handler = termination_handler,
317
324
                     .sa_flags = 0 };
318
325
    sigemptyset(&new_action.sa_mask);
319
 
    for(int *sig = (int[]){ SIGINT, SIGHUP, SIGTERM, 0 }; *sig != 0; sig++){
 
326
    for(int *sig = (int[]){ SIGINT, SIGHUP, SIGTERM, 0 };
 
327
        *sig != 0; sig++){
320
328
      ret = sigaddset(&new_action.sa_mask, *sig);
321
329
      if(ret == -1){
322
 
        error(0, errno, "sigaddset");
323
 
        exit(EX_OSERR);
 
330
        error(EX_OSERR, errno, "sigaddset");
324
331
      }
325
332
      ret = sigaction(*sig, NULL, &old_action);
326
333
      if(ret == -1){
327
 
        error(0, errno, "sigaction");
328
 
        exit(EX_OSERR);
 
334
        error(EX_OSERR, errno, "sigaction");
329
335
      }
330
336
      if(old_action.sa_handler != SIG_IGN){
331
337
        ret = sigaction(*sig, &new_action, NULL);
332
338
        if(ret == -1){
333
 
          error(0, errno, "sigaction");
334
 
          exit(EX_OSERR);
 
339
          error(EX_OSERR, errno, "sigaction");
335
340
        }
336
341
      }
337
342
    }
338
343
  }
339
 
    
 
344
  
340
345
  /* plymouth --ping */
341
346
  bret = exec_and_wait(&plymouth_command_pid, plymouth_path,
342
 
                       (const char *[]){ (const char *)plymouth_path, (const char *)"--ping", (const char *)NULL},
 
347
                       (const char *[])
 
348
                       { plymouth_path, "--ping", NULL },
343
349
                       true, false);
344
350
  if(not bret){
345
351
    if(interrupted_by_signal){
346
352
      kill_and_wait(plymouth_command_pid);
 
353
      exit(EXIT_FAILURE);
347
354
    }
348
 
    exit(EXIT_FAILURE);
 
355
    /* Plymouth is probably not running.  Don't print an error
 
356
       message, just exit. */
 
357
    exit(EX_UNAVAILABLE);
349
358
  }
350
359
  
351
360
  prompt = makeprompt();
352
361
  ret = asprintf(&prompt_arg, "--prompt=%s", prompt);
353
362
  free(prompt);
354
363
  if(ret == -1){
355
 
    error(0, errno, "asprintf");
356
 
    exit(EXIT_FAILURE);
 
364
    error(EX_OSERR, errno, "asprintf");
357
365
  }
358
366
  
359
367
  /* plymouth ask-for-password --prompt="$prompt" */
360
 
  bret = exec_and_wait(&plymouth_command_pid, plymouth_path,
361
 
                       (const char *[]){plymouth_path, "ask-for-password", prompt_arg, NULL},
 
368
  bret = exec_and_wait(&plymouth_command_pid,
 
369
                       plymouth_path, (const char *[])
 
370
                       { plymouth_path, "ask-for-password",
 
371
                           prompt_arg, NULL },
362
372
                       true, false);
363
373
  free(prompt_arg);
364
 
  if(not bret){
365
 
    if(interrupted_by_signal){
366
 
      kill_and_wait(plymouth_command_pid);
367
 
    } else {
368
 
      exit(EXIT_FAILURE);
369
 
    }
370
 
  }
371
 
  
372
374
  if(bret){
373
375
    exit(EXIT_SUCCESS);
374
376
  }
 
377
  if(not interrupted_by_signal){
 
378
    /* exec_and_wait failed for some other reason */
 
379
    exit(EXIT_FAILURE);
 
380
  }
 
381
  kill_and_wait(plymouth_command_pid);
375
382
  
376
 
  const char **plymouthd_argv = NULL;
 
383
  const char **plymouthd_argv;
377
384
  pid_t pid = get_pid();
378
385
  if(pid == 0){
379
386
    error(0, 0, "plymouthd pid not found");
 
387
    plymouthd_argv = plymouthd_default_argv;
380
388
  } else {
381
389
    plymouthd_argv = getargv(pid);
382
390
  }
383
 
  if(plymouthd_argv == NULL){
384
 
    plymouthd_argv = plymouthd_default_argv;
385
 
  }
386
391
  
387
 
  bret = exec_and_wait(NULL, plymouth_path,
388
 
                       (const char *[]){plymouth_path, "quit", NULL}, false, false);
389
 
  if(not bret){
390
 
    exit(EXIT_FAILURE);
391
 
  }
392
 
  bret = exec_and_wait(NULL, plymouthd_path, plymouthd_argv, false, true);
393
 
  if(not bret){
394
 
    exit(EXIT_FAILURE);
395
 
  }
396
 
  exec_and_wait(NULL, plymouth_path,
397
 
                (const char *[]){ plymouth_path, "show-splash", NULL }, false, false);
 
392
  bret = exec_and_wait(NULL, plymouth_path, (const char *[])
 
393
                       { plymouth_path, "quit", NULL },
 
394
                       false, false);
 
395
  if(not bret){
 
396
    exit(EXIT_FAILURE);
 
397
  }
 
398
  bret = exec_and_wait(NULL, plymouthd_path, plymouthd_argv,
 
399
                       false, true);
 
400
  if(not bret){
 
401
    exit(EXIT_FAILURE);
 
402
  }
 
403
  exec_and_wait(NULL, plymouth_path, (const char *[])
 
404
                { plymouth_path, "show-splash", NULL },
 
405
                false, false);
398
406
  exit(EXIT_FAILURE);
399
407
}