/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-15 05:27:55 UTC
  • mfrom: (237.2.9 mandos-release)
  • Revision ID: teddy@fukt.bsnet.se-20090115052755-luw0gjx8727p24o3
Merge from release branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 * along with this program.  If not, see
20
20
 * <http://www.gnu.org/licenses/>.
21
21
 * 
22
 
 * Contact the authors at <mandos@fukt.bsnet.se>.
 
22
 * Contact the authors at <https://www.fukt.bsnet.se/~belorn/> and
 
23
 * <https://www.fukt.bsnet.se/~teddy/>.
23
24
 */
24
25
 
25
26
#define _GNU_SOURCE             /* asprintf() */
35
36
                                   dirent */
36
37
#include <stddef.h>             /* NULL */
37
38
#include <string.h>             /* strlen(), memcmp() */
38
 
#include <stdio.h>              /* asprintf(), perror() */
 
39
#include <stdio.h>              /* asprintf(), perror(), sscanf() */
39
40
#include <unistd.h>             /* close(), write(), readlink(),
40
41
                                   read(), STDOUT_FILENO, sleep(),
41
42
                                   fork(), setuid(), geteuid(),
45
46
                                   EXIT_SUCCESS, malloc(), _exit() */
46
47
#include <stdlib.h>             /* getenv() */
47
48
#include <dirent.h>             /* opendir(), readdir(), closedir() */
48
 
#include <inttypes.h>           /* intmax_t, strtoimax() */
 
49
#include <inttypes.h>           /* intmax_t, SCNdMAX */
49
50
#include <sys/stat.h>           /* struct stat, lstat(), S_ISLNK */
50
51
 
51
52
sig_atomic_t interrupted_by_signal = 0;
63
64
   */
64
65
  int ret;
65
66
  int fifo_fd;
66
 
  do {
 
67
  do{
67
68
    fifo_fd = open("/dev/.initramfs/usplash_fifo", O_WRONLY);
68
69
    if(fifo_fd == -1 and (errno != EINTR or interrupted_by_signal)){
69
70
      return false;
70
71
    }
71
 
  } while(fifo_fd == -1);
 
72
  }while(fifo_fd == -1);
72
73
  
73
74
  const char *cmd_line;
74
75
  size_t cmd_line_len;
76
77
  if(arg == NULL){
77
78
    cmd_line = cmd;
78
79
    cmd_line_len = strlen(cmd);
79
 
  } else {
80
 
    do {
 
80
  }else{
 
81
    do{
81
82
      ret = asprintf(&cmd_line_alloc, "%s %s", cmd, arg);
82
83
      if(ret == -1 and (errno != EINTR or interrupted_by_signal)){
83
84
        int e = errno;
85
86
        errno = e;
86
87
        return false;
87
88
      }
88
 
    } while(ret == -1);
 
89
    }while(ret == -1);
89
90
    cmd_line = cmd_line_alloc;
90
91
    cmd_line_len = (size_t)ret + 1;
91
92
  }
109
110
    written += (size_t)sret;
110
111
  }
111
112
  free(cmd_line_alloc);
112
 
  do {
 
113
  do{
113
114
    ret = close(fifo_fd);
114
115
    if(ret == -1 and (errno != EINTR or interrupted_by_signal)){
115
116
      return false;
116
117
    }
117
 
  } while(ret == -1);
 
118
  }while(ret == -1);
118
119
  if(interrupted_by_signal){
119
120
    return false;
120
121
  }
172
173
      pid_t pid;
173
174
      {
174
175
        intmax_t tmpmax;
175
 
        char *tmp;
176
 
        errno = 0;
177
 
        tmpmax = strtoimax(proc_ent->d_name, &tmp, 10);
178
 
        if(errno != 0 or tmp == proc_ent->d_name or *tmp != '\0'
179
 
           or tmpmax != (pid_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'){
180
181
          /* Not a process */
181
182
          continue;
182
183
        }
251
252
          size_t cmdline_allocated = 0;
252
253
          char *tmp;
253
254
          const size_t blocksize = 1024;
254
 
          do {
 
255
          do{
255
256
            if(cmdline_len + blocksize > cmdline_allocated){
256
257
              tmp = realloc(cmdline, cmdline_allocated + blocksize);
257
258
              if(tmp == NULL){
365
366
    
366
367
    /* Open FIFO */
367
368
    int fifo_fd;
368
 
    do {
 
369
    do{
369
370
      fifo_fd = open("/dev/.initramfs/usplash_outfifo", O_RDONLY);
370
371
      if(fifo_fd == -1){
371
372
        if(errno != EINTR){
377
378
          break;
378
379
        }
379
380
      }
380
 
    } while(fifo_fd == -1);
 
381
    }while(fifo_fd == -1);
381
382
    if(interrupted_by_signal or an_error_occured){
382
383
      break;                    /* Big */
383
384
    }
385
386
    /* Read from FIFO */
386
387
    size_t buf_allocated = 0;
387
388
    const size_t blocksize = 1024;
388
 
    do {
 
389
    do{
389
390
      if(buf_len + blocksize > buf_allocated){
390
391
        char *tmp = realloc(buf, buf_allocated + blocksize);
391
392
        if(tmp == NULL){
396
397
        buf = tmp;
397
398
        buf_allocated += blocksize;
398
399
      }
399
 
      do {
 
400
      do{
400
401
        sret = read(fifo_fd, buf + buf_len, buf_allocated - buf_len);
401
402
        if(sret == -1){
402
403
          if(errno != EINTR){
408
409
            break;
409
410
          }
410
411
        }
411
 
      } while(sret == -1);
 
412
      }while(sret == -1);
412
413
      if(interrupted_by_signal or an_error_occured){
413
414
        break;
414
415
      }
415
416
      
416
417
      buf_len += (size_t)sret;
417
 
    } while(sret != 0);
 
418
    }while(sret != 0);
418
419
    close(fifo_fd);
419
420
    if(interrupted_by_signal or an_error_occured){
420
421
      break;                    /* Big */
432
433
    /* Print password to stdout */
433
434
    size_t written = 0;
434
435
    while(written < buf_len){
435
 
      do {
 
436
      do{
436
437
        sret = write(STDOUT_FILENO, buf + written, buf_len - written);
437
438
        if(sret == -1){
438
439
          if(errno != EINTR){
444
445
            break;
445
446
          }
446
447
        }
447
 
      } while(sret == -1);
 
448
      }while(sret == -1);
448
449
      if(interrupted_by_signal or an_error_occured){
449
450
        break;
450
451
      }