/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-04-17 08:26:17 UTC
  • Revision ID: teddy@fukt.bsnet.se-20090417082617-eltetak5lzjyz55o
* initramfs-tools-hook: Bug fix: Add "--userid" and "--groupid" to
                        start of "plugin-runner.conf" file instead of
                        appending, to allow any preexisting options to
                        override.
* plugin-runner.conf: Improved wording.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*  -*- coding: utf-8 -*- */
2
2
/*
3
 
 * Passprompt - Read a password from usplash and output it
 
3
 * Usplash - Read a password from usplash and output it
4
4
 * 
5
 
 * Copyright © 2008 Teddy Hogeborn
6
 
 * Copyright © 2008 Björn Påhlsson
 
5
 * Copyright © 2008,2009 Teddy Hogeborn
 
6
 * Copyright © 2008,2009 Björn Påhlsson
7
7
 * 
8
8
 * This program is free software: you can redistribute it and/or
9
9
 * modify it under the terms of the GNU General Public License as
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, strtoimax() */
50
50
#include <sys/stat.h>           /* struct stat, lstat(), S_ISLNK */
51
51
 
52
52
sig_atomic_t interrupted_by_signal = 0;
92
92
  }
93
93
  
94
94
  size_t written = 0;
 
95
  ssize_t sret = 0;
95
96
  while(not interrupted_by_signal and written < cmd_line_len){
96
 
    ret = write(fifo_fd, cmd_line + written,
97
 
                cmd_line_len - written);
98
 
    if(ret == -1){
 
97
    sret = write(fifo_fd, cmd_line + written,
 
98
                 cmd_line_len - written);
 
99
    if(sret == -1){
99
100
      if(errno != EINTR or interrupted_by_signal){
100
101
        int e = errno;
101
102
        close(fifo_fd);
106
107
        continue;
107
108
      }
108
109
    }
109
 
    written += (size_t)ret;
 
110
    written += (size_t)sret;
110
111
  }
111
112
  free(cmd_line_alloc);
112
113
  do{
169
170
    for(struct dirent *proc_ent = readdir(proc_dir);
170
171
        proc_ent != NULL;
171
172
        proc_ent = readdir(proc_dir)){
172
 
      pid_t pid = (pid_t) strtoul(proc_ent->d_name, NULL, 10);
173
 
      if(pid == 0){
174
 
        /* Not a process */
175
 
        continue;
 
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;
176
185
      }
177
186
      /* Find the executable name by doing readlink() on the
178
187
         /proc/<pid>/exe link */
192
201
        struct stat exe_stat;
193
202
        ret = lstat(exe_link, &exe_stat);
194
203
        if(ret == -1){
 
204
          if(errno == ENOENT){
 
205
            free(exe_link);
 
206
            continue;
 
207
          }
195
208
          perror("lstat");
196
209
          free(exe_link);
197
210
          free(prompt);
207
220
        
208
221
        sret = readlink(exe_link, exe_target, sizeof(exe_target));
209
222
        free(exe_link);
210
 
        if(sret == -1){
211
 
          continue;
212
 
        }
213
223
      }
214
224
      if((sret == ((ssize_t)sizeof(exe_target)-1))
215
225
         and (memcmp(usplash_name, exe_target,
484
494
    /* Child; will become new usplash process */
485
495
    
486
496
    /* Make the effective user ID (root) the only user ID instead of
487
 
       the real user ID (mandos) */
 
497
       the real user ID (_mandos) */
488
498
    ret = setuid(geteuid());
489
499
    if(ret == -1){
490
500
      perror("setuid");