/mandos/release

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/release

« back to all changes in this revision

Viewing changes to plugins.d/usplash.c

merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
                                   fork(), setuid(), geteuid(),
43
43
                                   setsid(), chdir(), dup2(),
44
44
                                   STDERR_FILENO, execv() */
45
 
#include <stdlib.h>             /* free(), EXIT_FAILURE, realloc(),
46
 
                                   EXIT_SUCCESS, malloc(), _exit() */
 
45
#include <stdlib.h>             /* free(), EXIT_FAILURE, strtoul(),
 
46
                                   realloc(), EXIT_SUCCESS, malloc(),
 
47
                                   _exit() */
47
48
#include <stdlib.h>             /* getenv() */
48
49
#include <dirent.h>             /* opendir(), readdir(), closedir() */
49
 
#include <inttypes.h>           /* intmax_t, strtoimax() */
50
50
#include <sys/stat.h>           /* struct stat, lstat(), S_ISLNK */
51
51
 
52
52
sig_atomic_t interrupted_by_signal = 0;
170
170
    for(struct dirent *proc_ent = readdir(proc_dir);
171
171
        proc_ent != NULL;
172
172
        proc_ent = readdir(proc_dir)){
173
 
      pid_t pid;
174
 
      {
175
 
        intmax_t tmpmax;
176
 
        char *tmp;
177
 
        errno = 0;
178
 
        tmpmax = strtoimax(proc_ent->d_name, &tmp, 10);
179
 
        if(errno != 0 or tmp == proc_ent->d_name or *tmp != '\0'
180
 
           or tmpmax != (pid_t)tmpmax){
181
 
          /* Not a process */
182
 
          continue;
183
 
        }
184
 
        pid = (pid_t)tmpmax;
 
173
      pid_t pid = (pid_t) strtoul(proc_ent->d_name, NULL, 10);
 
174
      if(pid == 0){
 
175
        /* Not a process */
 
176
        continue;
185
177
      }
186
178
      /* Find the executable name by doing readlink() on the
187
179
         /proc/<pid>/exe link */
494
486
    /* Child; will become new usplash process */
495
487
    
496
488
    /* Make the effective user ID (root) the only user ID instead of
497
 
       the real user ID (_mandos) */
 
489
       the real user ID (mandos) */
498
490
    ret = setuid(geteuid());
499
491
    if(ret == -1){
500
492
      perror("setuid");