/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/askpass-fifo.c

* debian/control (Standards-Version): Updated to "3.9.1".
* mandos-keygen: Use "set -e" as per Debian Policy section 10.4.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
/*
3
3
 * Askpass-FIFO - Read a password from a FIFO and output it
4
4
 * 
5
 
 * Copyright © 2008-2011 Teddy Hogeborn
6
 
 * Copyright © 2008-2011 Björn Påhlsson
 
5
 * Copyright © 2008-2010 Teddy Hogeborn
 
6
 * Copyright © 2008-2010 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
32
32
                                   ENFILE, ENOMEM, EBADF, EINVAL, EIO,
33
33
                                   EISDIR, EFBIG */
34
34
#include <error.h>              /* error() */
35
 
#include <stdio.h>              /* fprintf(), vfprintf(), vasprintf() */
36
35
#include <stdlib.h>             /* EXIT_FAILURE, NULL, size_t, free(),
37
36
                                   realloc(), EXIT_SUCCESS */
38
37
#include <fcntl.h>              /* open(), O_RDONLY */
40
39
                                   STDOUT_FILENO */
41
40
#include <sysexits.h>           /* EX_OSERR, EX_OSFILE,
42
41
                                   EX_UNAVAILABLE, EX_IOERR */
43
 
#include <string.h>             /* strerror() */
44
 
#include <stdarg.h>             /* va_list, va_start(), ... */
45
 
 
46
 
 
47
 
/* Function to use when printing errors */
48
 
void error_plus(int status, int errnum, const char *formatstring, ...){
49
 
  va_list ap;
50
 
  char *text;
51
 
  int ret;
52
 
  
53
 
  va_start(ap, formatstring);
54
 
  ret = vasprintf(&text, formatstring, ap);
55
 
  if (ret == -1){
56
 
    fprintf(stderr, "Mandos plugin %s: ", program_invocation_short_name);
57
 
    vfprintf(stderr, formatstring, ap);
58
 
    fprintf(stderr, ": ");
59
 
    fprintf(stderr, "%s\n", strerror(errnum));
60
 
    error(status, errno, "vasprintf while printing error");
61
 
    return;
62
 
  }
63
 
  fprintf(stderr, "Mandos plugin ");
64
 
  error(status, errnum, "%s", text);
65
 
  free(text);
66
 
}
 
42
 
67
43
 
68
44
int main(__attribute__((unused))int argc,
69
45
         __attribute__((unused))char **argv){
75
51
  ret = mkfifo(passfifo, S_IRUSR | S_IWUSR);
76
52
  if(ret == -1){
77
53
    int e = errno;
 
54
    error(0, errno, "mkfifo");
78
55
    switch(e){
79
56
    case EACCES:
80
57
    case ENOTDIR:
81
58
    case ELOOP:
82
 
      error_plus(EX_OSFILE, errno, "mkfifo");
 
59
      return EX_OSFILE;
83
60
    case ENAMETOOLONG:
84
61
    case ENOSPC:
85
62
    case EROFS:
86
63
    default:
87
 
      error_plus(EX_OSERR, errno, "mkfifo");
 
64
      return EX_OSERR;
88
65
    case ENOENT:
89
 
      /* no "/lib/cryptsetup"? */
90
 
      error_plus(EX_UNAVAILABLE, errno, "mkfifo");
 
66
      return EX_UNAVAILABLE;    /* no "/lib/cryptsetup"? */
91
67
    case EEXIST:
92
68
      break;                    /* not an error */
93
69
    }
97
73
  int fifo_fd = open(passfifo, O_RDONLY);
98
74
  if(fifo_fd == -1){
99
75
    int e = errno;
100
 
    error_plus(0, errno, "open");
 
76
    error(0, errno, "open");
101
77
    switch(e){
102
78
    case EACCES:
103
79
    case ENOENT:
125
101
      if(buf_len + blocksize > buf_allocated){
126
102
        char *tmp = realloc(buf, buf_allocated + blocksize);
127
103
        if(tmp == NULL){
128
 
          error_plus(0, errno, "realloc");
 
104
          error(0, errno, "realloc");
129
105
          free(buf);
130
106
          return EX_OSERR;
131
107
        }
137
113
        int e = errno;
138
114
        free(buf);
139
115
        errno = e;
140
 
        error_plus(0, errno, "read");
 
116
        error(0, errno, "read");
141
117
        switch(e){
142
118
        case EBADF:
143
119
        case EFAULT:
165
141
      int e = errno;
166
142
      free(buf);
167
143
      errno = e;
168
 
      error_plus(0, errno, "write");
 
144
      error(0, errno, "write");
169
145
      switch(e){
170
146
      case EBADF:
171
147
      case EFAULT:
185
161
  ret = close(STDOUT_FILENO);
186
162
  if(ret == -1){
187
163
    int e = errno;
188
 
    error_plus(0, errno, "close");
 
164
    error(0, errno, "close");
189
165
    switch(e){
190
166
    case EBADF:
191
167
      return EX_OSFILE;