/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-13 04:35:19 UTC
  • Revision ID: teddy@fukt.bsnet.se-20090113043519-0yr39snphoegq8l1
* plugin-runner.c: Only space changes.
* plugins.d/mandos-client.c: - '' -
* plugins.d/password-prompt.c: - '' -

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
49
#include <sys/stat.h>           /* struct stat, lstat(), S_ISLNK */
50
50
 
51
51
sig_atomic_t interrupted_by_signal = 0;
63
63
   */
64
64
  int ret;
65
65
  int fifo_fd;
66
 
  do {
 
66
  do{
67
67
    fifo_fd = open("/dev/.initramfs/usplash_fifo", O_WRONLY);
68
 
    if((fifo_fd == -1) and (errno != EINTR or interrupted_by_signal)){
 
68
    if(fifo_fd == -1 and (errno != EINTR or interrupted_by_signal)){
69
69
      return false;
70
70
    }
71
 
  } while(fifo_fd == -1);
 
71
  }while(fifo_fd == -1);
72
72
  
73
73
  const char *cmd_line;
74
74
  size_t cmd_line_len;
76
76
  if(arg == NULL){
77
77
    cmd_line = cmd;
78
78
    cmd_line_len = strlen(cmd);
79
 
  } else {
80
 
    do {
 
79
  }else{
 
80
    do{
81
81
      ret = asprintf(&cmd_line_alloc, "%s %s", cmd, arg);
82
82
      if(ret == -1 and (errno != EINTR or interrupted_by_signal)){
83
83
        int e = errno;
85
85
        errno = e;
86
86
        return false;
87
87
      }
88
 
    } while(ret == -1);
 
88
    }while(ret == -1);
89
89
    cmd_line = cmd_line_alloc;
90
90
    cmd_line_len = (size_t)ret + 1;
91
91
  }
109
109
    written += (size_t)sret;
110
110
  }
111
111
  free(cmd_line_alloc);
112
 
  do {
 
112
  do{
113
113
    ret = close(fifo_fd);
114
114
    if(ret == -1 and (errno != EINTR or interrupted_by_signal)){
115
115
      return false;
116
116
    }
117
 
  } while(ret == -1);
 
117
  }while(ret == -1);
118
118
  if(interrupted_by_signal){
119
119
    return false;
120
120
  }
170
170
        proc_ent != NULL;
171
171
        proc_ent = readdir(proc_dir)){
172
172
      pid_t pid;
173
 
      {
174
 
        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){
180
 
          /* Not a process */
181
 
          continue;
182
 
        }
183
 
        pid = (pid_t)tmpmax;
 
173
      /* In the GNU C library, pid_t is always int */
 
174
      ret = sscanf(proc_ent->d_name, "%d", &pid);
 
175
      if(ret != 1){
 
176
        /* Not a process */
 
177
        continue;
184
178
      }
185
179
      /* Find the executable name by doing readlink() on the
186
180
         /proc/<pid>/exe link */
251
245
          size_t cmdline_allocated = 0;
252
246
          char *tmp;
253
247
          const size_t blocksize = 1024;
254
 
          do {
 
248
          do{
255
249
            if(cmdline_len + blocksize > cmdline_allocated){
256
250
              tmp = realloc(cmdline, cmdline_allocated + blocksize);
257
251
              if(tmp == NULL){
365
359
    
366
360
    /* Open FIFO */
367
361
    int fifo_fd;
368
 
    do {
 
362
    do{
369
363
      fifo_fd = open("/dev/.initramfs/usplash_outfifo", O_RDONLY);
370
364
      if(fifo_fd == -1){
371
365
        if(errno != EINTR){
377
371
          break;
378
372
        }
379
373
      }
380
 
    } while(fifo_fd == -1);
 
374
    }while(fifo_fd == -1);
381
375
    if(interrupted_by_signal or an_error_occured){
382
376
      break;                    /* Big */
383
377
    }
385
379
    /* Read from FIFO */
386
380
    size_t buf_allocated = 0;
387
381
    const size_t blocksize = 1024;
388
 
    do {
 
382
    do{
389
383
      if(buf_len + blocksize > buf_allocated){
390
384
        char *tmp = realloc(buf, buf_allocated + blocksize);
391
385
        if(tmp == NULL){
396
390
        buf = tmp;
397
391
        buf_allocated += blocksize;
398
392
      }
399
 
      do {
 
393
      do{
400
394
        sret = read(fifo_fd, buf + buf_len, buf_allocated - buf_len);
401
395
        if(sret == -1){
402
396
          if(errno != EINTR){
408
402
            break;
409
403
          }
410
404
        }
411
 
      } while(sret == -1);
 
405
      }while(sret == -1);
412
406
      if(interrupted_by_signal or an_error_occured){
413
407
        break;
414
408
      }
415
409
      
416
410
      buf_len += (size_t)sret;
417
 
    } while(sret != 0);
 
411
    }while(sret != 0);
418
412
    close(fifo_fd);
419
413
    if(interrupted_by_signal or an_error_occured){
420
414
      break;                    /* Big */
432
426
    /* Print password to stdout */
433
427
    size_t written = 0;
434
428
    while(written < buf_len){
435
 
      do {
 
429
      do{
436
430
        sret = write(STDOUT_FILENO, buf + written, buf_len - written);
437
431
        if(sret == -1){
438
432
          if(errno != EINTR){
444
438
            break;
445
439
          }
446
440
        }
447
 
      } while(sret == -1);
 
441
      }while(sret == -1);
448
442
      if(interrupted_by_signal or an_error_occured){
449
443
        break;
450
444
      }