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

  • Committer: Teddy Hogeborn
  • Date: 2008-10-04 20:09:53 UTC
  • Revision ID: teddy@fukt.bsnet.se-20081004200953-7j0fjlq6fqsxs9t2
* Makefile (DOCS): Added "plugins.d/askpass-fifo.8mandos".
  (install-client-nokey): Also install
                          "plugins.d/askpass-fifo.8mandos".
  (uninstall-client): Also uninstall "plugins.d/askpass-fifo.8mandos".

* plugins.d/askpass-fifo.xml: New.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
                                   SIG_IGN, kill(), SIGKILL */
6
6
#include <stdbool.h>            /* bool, false, true */
7
7
#include <fcntl.h>              /* open(), O_WRONLY, O_RDONLY */
 
8
#include <iso646.h>             /* and, or, not*/
8
9
#include <errno.h>              /* errno, EINTR */
9
 
#include <sys/types.h>          /* size_t, ssize_t, pid_t, DIR,
10
 
                                   struct dirent */
 
10
#include <sys/types.h>          /* size_t, ssize_t, pid_t, DIR, struct
 
11
                                   dirent */
11
12
#include <stddef.h>             /* NULL */
12
13
#include <string.h>             /* strlen(), memcmp() */
13
14
#include <stdio.h>              /* asprintf(), perror() */
21
22
                                   _exit() */
22
23
#include <stdlib.h>             /* getenv() */
23
24
#include <dirent.h>             /* opendir(), readdir(), closedir() */
24
 
 
25
 
 
26
 
 
27
 
#include <iso646.h>             /* and */
28
 
#include <sys/wait.h>           /* waitpid(), WIFEXITED(),
29
 
                                   WEXITSTATUS() */
 
25
#include <sys/stat.h>           /* struct stat, lstat(), S_ISLNK */
30
26
 
31
27
sig_atomic_t interrupted_by_signal = 0;
32
28
 
36
32
 
37
33
static bool usplash_write(const char *cmd, const char *arg){
38
34
  /* 
39
 
   * usplash_write("TIMEOUT", "15"); -> "TIMEOUT 15\0"
40
 
   * usplash_write("PULSATE", NULL); -> "PULSATE\0"
 
35
   * usplash_write("TIMEOUT", "15") will write "TIMEOUT 15\0"
 
36
   * usplash_write("PULSATE", NULL) will write "PULSATE\0"
41
37
   * SEE ALSO
42
38
   *         usplash_write(8)
43
39
   */
157
153
         /proc/<pid>/exe link */
158
154
      char exe_target[sizeof(usplash_name)];
159
155
      {
 
156
        /* create file name string */
160
157
        char *exe_link;
161
158
        ret = asprintf(&exe_link, "/proc/%s/exe", proc_ent->d_name);
162
159
        if(ret == -1){
165
162
          closedir(proc_dir);
166
163
          return EXIT_FAILURE;
167
164
        }
 
165
        
 
166
        /* Check that it refers to a symlink owned by root:root */
 
167
        struct stat exe_stat;
 
168
        ret = lstat(exe_link, &exe_stat);
 
169
        if(ret == -1){
 
170
          perror("lstat");
 
171
          free(exe_link);
 
172
          free(prompt);
 
173
          closedir(proc_dir);
 
174
          return EXIT_FAILURE;
 
175
        }
 
176
        if(not S_ISLNK(exe_stat.st_mode)
 
177
           or exe_stat.st_uid != 0
 
178
           or exe_stat.st_gid != 0){
 
179
          free(exe_link);
 
180
          continue;
 
181
        }
 
182
        
168
183
        sret = readlink(exe_link, exe_target, sizeof(exe_target));
169
184
        free(exe_link);
170
185
        if(sret == -1){
253
268
      free(prompt);
254
269
      return EXIT_FAILURE;
255
270
    }
256
 
    if (old_action.sa_handler != SIG_IGN){
 
271
    if(old_action.sa_handler != SIG_IGN){
257
272
      ret = sigaction(SIGINT, &new_action, NULL);
258
273
      if(ret == -1){
259
274
        perror("sigaction");
267
282
      free(prompt);
268
283
      return EXIT_FAILURE;
269
284
    }
270
 
    if (old_action.sa_handler != SIG_IGN){
 
285
    if(old_action.sa_handler != SIG_IGN){
271
286
      ret = sigaction(SIGHUP, &new_action, NULL);
272
287
      if(ret == -1){
273
288
        perror("sigaction");
281
296
      free(prompt);
282
297
      return EXIT_FAILURE;
283
298
    }
284
 
    if (old_action.sa_handler != SIG_IGN){
 
299
    if(old_action.sa_handler != SIG_IGN){
285
300
      ret = sigaction(SIGTERM, &new_action, NULL);
286
301
      if(ret == -1){
287
302
        perror("sigaction");
407
422
      return EXIT_SUCCESS;
408
423
    }
409
424
    break;                      /* Big */
410
 
  }
 
425
  }                             /* end of non-loop while() */
411
426
  
412
427
  /* If we got here, an error or interrupt must have happened */
413
428
  
 
429
  /* Create argc and argv for new usplash*/
414
430
  int cmdline_argc = 0;
415
431
  char **cmdline_argv = malloc(sizeof(char *));
416
 
  /* Create argv and argc for new usplash*/
417
432
  {
418
433
    size_t position = 0;
419
434
    while(position < cmdline_len){
433
448
    cmdline_argv[cmdline_argc] = NULL;
434
449
  }
435
450
  /* Kill old usplash */
436
 
    kill(usplash_pid, SIGTERM);
437
 
    sleep(2);
 
451
  kill(usplash_pid, SIGTERM);
 
452
  sleep(2);
438
453
  while(kill(usplash_pid, 0) == 0){
439
454
    kill(usplash_pid, SIGKILL);
440
455
    sleep(1);
446
461
    /* Make the effective user ID (root) the only user ID instead of
447
462
       the real user ID (mandos) */
448
463
    ret = setuid(geteuid());
449
 
    if (ret == -1){
 
464
    if(ret == -1){
450
465
      perror("setuid");
451
466
    }
452
467
    
462
477
    }
463
478
    
464
479
    execv(usplash_name, cmdline_argv);
465
 
    perror("execv");
 
480
    if(not interrupted_by_signal){
 
481
      perror("execv");
 
482
    }
466
483
    free(cmdline);
467
484
    free(cmdline_argv);
468
485
    _exit(EXIT_FAILURE);