/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: 2008-10-03 09:32:30 UTC
  • Revision ID: teddy@fukt.bsnet.se-20081003093230-rshn19e0c19zz12i
* .bzrignore (plugins.d/askpass-fifo): Added.

* Makefile (FORTIFY): Added "-fstack-protector-all".
  (mandos, mandos-keygen): Use more strict regexps when updating the
                           version number.

* mandos (Client.__init__): Use os.path.expandvars() and
                            os.path.expanduser() on the "secfile"
                            config value.

* plugins.d/splashy.c: Update comments and order of #include's.
  (main): Check user and group when looking for running splashy
          process.  Do not ignore ENOENT from execl().  Use _exit()
          instead of "return" when an error happens in child
          processes.  Bug fix: Only wait for splashy_update
          completion if it was started.  Bug fix: detect failing
          waitpid().  Only kill splashy_update if it is running.  Do
          the killing of the old splashy process before the fork().
          Do setsid() and setuid(geteuid()) before starting the new
          splashy.  Report failing execl().

* plugins.d/usplash.c: Update comments and order of #include's.
  (main): Check user and group when looking for running usplash
          process.  Do not report execv() error if interrupted by a
          signal.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*  -*- coding: utf-8 -*- */
2
 
/*
3
 
 * Splashy - Read a password from splashy 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,
31
6
#include <stddef.h>             /* NULL */
32
7
#include <stdlib.h>             /* getenv() */
33
8
#include <stdio.h>              /* asprintf(), perror() */
34
 
#include <stdlib.h>             /* EXIT_FAILURE, free(),
 
9
#include <stdlib.h>             /* EXIT_FAILURE, free(), strtoul(),
35
10
                                   EXIT_SUCCESS */
36
11
#include <sys/types.h>          /* pid_t, DIR, struct dirent,
37
12
                                   ssize_t */
38
13
#include <dirent.h>             /* opendir(), readdir(), closedir() */
39
 
#include <inttypes.h>           /* intmax_t, strtoimax() */
40
14
#include <sys/stat.h>           /* struct stat, lstat(), S_ISLNK */
41
15
#include <iso646.h>             /* not, or, and */
42
16
#include <unistd.h>             /* readlink(), fork(), execl(),
98
72
    for(struct dirent *proc_ent = readdir(proc_dir);
99
73
        proc_ent != NULL;
100
74
        proc_ent = readdir(proc_dir)){
101
 
      pid_t pid;
102
 
      {
103
 
        intmax_t tmpmax;
104
 
        char *tmp;
105
 
        errno = 0;
106
 
        tmpmax = strtoimax(proc_ent->d_name, &tmp, 10);
107
 
        if(errno != 0 or tmp == proc_ent->d_name or *tmp != '\0'
108
 
           or tmpmax != (pid_t)tmpmax){
109
 
          /* Not a process */
110
 
          continue;
111
 
        }
112
 
        pid = (pid_t)tmpmax;
 
75
      pid_t pid = (pid_t) strtoul(proc_ent->d_name, NULL, 10);
 
76
      if(pid == 0){
 
77
        /* Not a process */
 
78
        continue;
113
79
      }
114
80
      /* Find the executable name by doing readlink() on the
115
81
         /proc/<pid>/exe link */
129
95
        struct stat exe_stat;
130
96
        ret = lstat(exe_link, &exe_stat);
131
97
        if(ret == -1){
132
 
          if(errno == ENOENT){
133
 
            free(exe_link);
134
 
            continue;
135
 
          }
136
98
          perror("lstat");
137
99
          free(exe_link);
138
100
          free(prompt);
276
238
    /* Child; will become new splashy process */
277
239
    
278
240
    /* Make the effective user ID (root) the only user ID instead of
279
 
       the real user ID (_mandos) */
 
241
       the real user ID (mandos) */
280
242
    ret = setuid(geteuid());
281
243
    if(ret == -1){
282
244
      perror("setuid");