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

  • Committer: Teddy Hogeborn
  • Date: 2011-03-08 19:09:03 UTC
  • Revision ID: teddy@fukt.bsnet.se-20110308190903-j499ebtb9bpk31ar
* INSTALL: Updated.

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@recompile.se>.
 
22
 * Contact the authors at <mandos@fukt.bsnet.se>.
23
23
 */
24
24
 
25
25
#define _GNU_SOURCE             /* TEMP_FAILURE_RETRY() */
32
32
                                   ENFILE, ENOMEM, EBADF, EINVAL, EIO,
33
33
                                   EISDIR, EFBIG */
34
34
#include <error.h>              /* error() */
35
 
#include <stdio.h>              /* fprintf(), vfprintf(),
36
 
                                   vasprintf() */
37
35
#include <stdlib.h>             /* EXIT_FAILURE, NULL, size_t, free(),
38
36
                                   realloc(), EXIT_SUCCESS */
39
37
#include <fcntl.h>              /* open(), O_RDONLY */
41
39
                                   STDOUT_FILENO */
42
40
#include <sysexits.h>           /* EX_OSERR, EX_OSFILE,
43
41
                                   EX_UNAVAILABLE, EX_IOERR */
44
 
#include <string.h>             /* strerror() */
45
 
#include <stdarg.h>             /* va_list, va_start(), ... */
46
 
 
47
 
 
48
 
/* Function to use when printing errors */
49
 
void error_plus(int status, int errnum, const char *formatstring,
50
 
                ...){
51
 
  va_list ap;
52
 
  char *text;
53
 
  int ret;
54
 
  
55
 
  va_start(ap, formatstring);
56
 
  ret = vasprintf(&text, formatstring, ap);
57
 
  if (ret == -1){
58
 
    fprintf(stderr, "Mandos plugin %s: ",
59
 
            program_invocation_short_name);
60
 
    vfprintf(stderr, formatstring, ap);
61
 
    fprintf(stderr, ": ");
62
 
    fprintf(stderr, "%s\n", strerror(errnum));
63
 
    error(status, errno, "vasprintf while printing error");
64
 
    return;
65
 
  }
66
 
  fprintf(stderr, "Mandos plugin ");
67
 
  error(status, errnum, "%s", text);
68
 
  free(text);
69
 
}
 
42
 
70
43
 
71
44
int main(__attribute__((unused))int argc,
72
45
         __attribute__((unused))char **argv){
78
51
  ret = mkfifo(passfifo, S_IRUSR | S_IWUSR);
79
52
  if(ret == -1){
80
53
    int e = errno;
 
54
    error(0, errno, "mkfifo");
81
55
    switch(e){
82
56
    case EACCES:
83
57
    case ENOTDIR:
84
58
    case ELOOP:
85
 
      error_plus(EX_OSFILE, errno, "mkfifo");
 
59
      return EX_OSFILE;
86
60
    case ENAMETOOLONG:
87
61
    case ENOSPC:
88
62
    case EROFS:
89
63
    default:
90
 
      error_plus(EX_OSERR, errno, "mkfifo");
 
64
      return EX_OSERR;
91
65
    case ENOENT:
92
 
      /* no "/lib/cryptsetup"? */
93
 
      error_plus(EX_UNAVAILABLE, errno, "mkfifo");
 
66
      return EX_UNAVAILABLE;    /* no "/lib/cryptsetup"? */
94
67
    case EEXIST:
95
68
      break;                    /* not an error */
96
69
    }
100
73
  int fifo_fd = open(passfifo, O_RDONLY);
101
74
  if(fifo_fd == -1){
102
75
    int e = errno;
103
 
    error_plus(0, errno, "open");
 
76
    error(0, errno, "open");
104
77
    switch(e){
105
78
    case EACCES:
106
79
    case ENOENT:
128
101
      if(buf_len + blocksize > buf_allocated){
129
102
        char *tmp = realloc(buf, buf_allocated + blocksize);
130
103
        if(tmp == NULL){
131
 
          error_plus(0, errno, "realloc");
 
104
          error(0, errno, "realloc");
132
105
          free(buf);
133
106
          return EX_OSERR;
134
107
        }
140
113
        int e = errno;
141
114
        free(buf);
142
115
        errno = e;
143
 
        error_plus(0, errno, "read");
 
116
        error(0, errno, "read");
144
117
        switch(e){
145
118
        case EBADF:
146
119
        case EFAULT:
168
141
      int e = errno;
169
142
      free(buf);
170
143
      errno = e;
171
 
      error_plus(0, errno, "write");
 
144
      error(0, errno, "write");
172
145
      switch(e){
173
146
      case EBADF:
174
147
      case EFAULT:
188
161
  ret = close(STDOUT_FILENO);
189
162
  if(ret == -1){
190
163
    int e = errno;
191
 
    error_plus(0, errno, "close");
 
164
    error(0, errno, "close");
192
165
    switch(e){
193
166
    case EBADF:
194
167
      return EX_OSFILE;