/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: 2009-01-18 06:41:57 UTC
  • Revision ID: teddy@fukt.bsnet.se-20090118064157-8o4oia1y0t8di0xj
* debian/mandos-client.lintian-overrides: Remove override for
                                          unbreakable line in
                                          plugin-runner manual page.
* plugin-runner.xml (EXAMPLES): Make long command line more breakable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
                                   dirent */
37
37
#include <stddef.h>             /* NULL */
38
38
#include <string.h>             /* strlen(), memcmp() */
39
 
#include <stdio.h>              /* asprintf(), perror() */
 
39
#include <stdio.h>              /* asprintf(), perror(), sscanf() */
40
40
#include <unistd.h>             /* close(), write(), readlink(),
41
41
                                   read(), STDOUT_FILENO, sleep(),
42
42
                                   fork(), setuid(), geteuid(),
43
43
                                   setsid(), chdir(), dup2(),
44
44
                                   STDERR_FILENO, execv() */
45
 
#include <stdlib.h>             /* free(), EXIT_FAILURE, strtoul(),
46
 
                                   realloc(), EXIT_SUCCESS, malloc(),
47
 
                                   _exit() */
 
45
#include <stdlib.h>             /* free(), EXIT_FAILURE, realloc(),
 
46
                                   EXIT_SUCCESS, malloc(), _exit() */
48
47
#include <stdlib.h>             /* getenv() */
49
48
#include <dirent.h>             /* opendir(), readdir(), closedir() */
 
49
#include <inttypes.h>           /* intmax_t, SCNdMAX */
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 = (pid_t) strtoul(proc_ent->d_name, NULL, 10);
174
 
      if(pid == 0){
175
 
        /* Not a process */
176
 
        continue;
 
173
      pid_t pid;
 
174
      {
 
175
        intmax_t tmpmax;
 
176
        int numchars;
 
177
        ret = sscanf(proc_ent->d_name, "%" SCNdMAX "%n", &tmpmax,
 
178
                     &numchars);
 
179
        if(ret < 1 or tmpmax != (pid_t)tmpmax
 
180
           or proc_ent->d_name[numchars] != '\0'){
 
181
          /* Not a process */
 
182
          continue;
 
183
        }
 
184
        pid = (pid_t)tmpmax;
177
185
      }
178
186
      /* Find the executable name by doing readlink() on the
179
187
         /proc/<pid>/exe link */
193
201
        struct stat exe_stat;
194
202
        ret = lstat(exe_link, &exe_stat);
195
203
        if(ret == -1){
 
204
          if(errno == ENOENT){
 
205
            free(exe_link);
 
206
            continue;
 
207
          }
196
208
          perror("lstat");
197
209
          free(exe_link);
198
210
          free(prompt);
208
220
        
209
221
        sret = readlink(exe_link, exe_target, sizeof(exe_target));
210
222
        free(exe_link);
211
 
        if(sret == -1){
212
 
          continue;
213
 
        }
214
223
      }
215
224
      if((sret == ((ssize_t)sizeof(exe_target)-1))
216
225
         and (memcmp(usplash_name, exe_target,
485
494
    /* Child; will become new usplash process */
486
495
    
487
496
    /* Make the effective user ID (root) the only user ID instead of
488
 
       the real user ID (mandos) */
 
497
       the real user ID (_mandos) */
489
498
    ret = setuid(geteuid());
490
499
    if(ret == -1){
491
500
      perror("setuid");