/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-09-26 19:47:21 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080926194721-r8pm2p876hcf9xay
* Makefile (PLUGINS): Added "plugins.d/askpass-fifo".
  (install-client-nokey): - '' -

* debian/mandos-client.lintian-overrides: Added "plugins.d/askpass-fifo".

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

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*  -*- coding: utf-8 -*- */
2
 
/*
3
 
 * Passprompt - Read a password from usplash and output it
4
 
 * 
5
 
 * Copyright © 2008,2009 Teddy Hogeborn
6
 
 * Copyright © 2008,2009 Björn Påhlsson
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
 
 * 
22
 
 * Contact the authors at <https://www.fukt.bsnet.se/~belorn/> and
23
 
 * <https://www.fukt.bsnet.se/~teddy/>.
24
 
 */
25
 
 
26
1
#define _GNU_SOURCE             /* asprintf() */
27
2
#include <signal.h>             /* sig_atomic_t, struct sigaction,
28
3
                                   sigemptyset(), sigaddset(), SIGINT,
30
5
                                   SIG_IGN, kill(), SIGKILL */
31
6
#include <stdbool.h>            /* bool, false, true */
32
7
#include <fcntl.h>              /* open(), O_WRONLY, O_RDONLY */
33
 
#include <iso646.h>             /* and, or, not*/
34
8
#include <errno.h>              /* errno, EINTR */
35
 
#include <sys/types.h>          /* size_t, ssize_t, pid_t, DIR, struct
36
 
                                   dirent */
 
9
#include <sys/types.h>          /* size_t, ssize_t, pid_t, DIR,
 
10
                                   struct dirent */
37
11
#include <stddef.h>             /* NULL */
38
12
#include <string.h>             /* strlen(), memcmp() */
39
13
#include <stdio.h>              /* asprintf(), perror() */
47
21
                                   _exit() */
48
22
#include <stdlib.h>             /* getenv() */
49
23
#include <dirent.h>             /* opendir(), readdir(), closedir() */
50
 
#include <sys/stat.h>           /* struct stat, lstat(), S_ISLNK */
 
24
 
 
25
 
 
26
 
 
27
#include <iso646.h>             /* and */
 
28
#include <sys/wait.h>           /* waitpid(), WIFEXITED(),
 
29
                                   WEXITSTATUS() */
51
30
 
52
31
sig_atomic_t interrupted_by_signal = 0;
53
32
 
57
36
 
58
37
static bool usplash_write(const char *cmd, const char *arg){
59
38
  /* 
60
 
   * usplash_write("TIMEOUT", "15") will write "TIMEOUT 15\0"
61
 
   * usplash_write("PULSATE", NULL) will write "PULSATE\0"
 
39
   * usplash_write("TIMEOUT", "15"); -> "TIMEOUT 15\0"
 
40
   * usplash_write("PULSATE", NULL); -> "PULSATE\0"
62
41
   * SEE ALSO
63
42
   *         usplash_write(8)
64
43
   */
178
157
         /proc/<pid>/exe link */
179
158
      char exe_target[sizeof(usplash_name)];
180
159
      {
181
 
        /* create file name string */
182
160
        char *exe_link;
183
161
        ret = asprintf(&exe_link, "/proc/%s/exe", proc_ent->d_name);
184
162
        if(ret == -1){
187
165
          closedir(proc_dir);
188
166
          return EXIT_FAILURE;
189
167
        }
190
 
        
191
 
        /* Check that it refers to a symlink owned by root:root */
192
 
        struct stat exe_stat;
193
 
        ret = lstat(exe_link, &exe_stat);
194
 
        if(ret == -1){
195
 
          perror("lstat");
196
 
          free(exe_link);
197
 
          free(prompt);
198
 
          closedir(proc_dir);
199
 
          return EXIT_FAILURE;
200
 
        }
201
 
        if(not S_ISLNK(exe_stat.st_mode)
202
 
           or exe_stat.st_uid != 0
203
 
           or exe_stat.st_gid != 0){
204
 
          free(exe_link);
205
 
          continue;
206
 
        }
207
 
        
208
168
        sret = readlink(exe_link, exe_target, sizeof(exe_target));
209
169
        free(exe_link);
210
170
        if(sret == -1){
293
253
      free(prompt);
294
254
      return EXIT_FAILURE;
295
255
    }
296
 
    if(old_action.sa_handler != SIG_IGN){
 
256
    if (old_action.sa_handler != SIG_IGN){
297
257
      ret = sigaction(SIGINT, &new_action, NULL);
298
258
      if(ret == -1){
299
259
        perror("sigaction");
307
267
      free(prompt);
308
268
      return EXIT_FAILURE;
309
269
    }
310
 
    if(old_action.sa_handler != SIG_IGN){
 
270
    if (old_action.sa_handler != SIG_IGN){
311
271
      ret = sigaction(SIGHUP, &new_action, NULL);
312
272
      if(ret == -1){
313
273
        perror("sigaction");
321
281
      free(prompt);
322
282
      return EXIT_FAILURE;
323
283
    }
324
 
    if(old_action.sa_handler != SIG_IGN){
 
284
    if (old_action.sa_handler != SIG_IGN){
325
285
      ret = sigaction(SIGTERM, &new_action, NULL);
326
286
      if(ret == -1){
327
287
        perror("sigaction");
447
407
      return EXIT_SUCCESS;
448
408
    }
449
409
    break;                      /* Big */
450
 
  }                             /* end of non-loop while() */
 
410
  }
451
411
  
452
412
  /* If we got here, an error or interrupt must have happened */
453
413
  
454
 
  /* Create argc and argv for new usplash*/
455
414
  int cmdline_argc = 0;
456
415
  char **cmdline_argv = malloc(sizeof(char *));
 
416
  /* Create argv and argc for new usplash*/
457
417
  {
458
418
    size_t position = 0;
459
419
    while(position < cmdline_len){
473
433
    cmdline_argv[cmdline_argc] = NULL;
474
434
  }
475
435
  /* Kill old usplash */
476
 
  kill(usplash_pid, SIGTERM);
477
 
  sleep(2);
 
436
    kill(usplash_pid, SIGTERM);
 
437
    sleep(2);
478
438
  while(kill(usplash_pid, 0) == 0){
479
439
    kill(usplash_pid, SIGKILL);
480
440
    sleep(1);
486
446
    /* Make the effective user ID (root) the only user ID instead of
487
447
       the real user ID (mandos) */
488
448
    ret = setuid(geteuid());
489
 
    if(ret == -1){
 
449
    if (ret == -1){
490
450
      perror("setuid");
491
451
    }
492
452
    
502
462
    }
503
463
    
504
464
    execv(usplash_name, cmdline_argv);
505
 
    if(not interrupted_by_signal){
506
 
      perror("execv");
507
 
    }
 
465
    perror("execv");
508
466
    free(cmdline);
509
467
    free(cmdline_argv);
510
468
    _exit(EXIT_FAILURE);