/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: Björn Påhlsson
  • Date: 2011-06-23 22:27:15 UTC
  • mto: This revision was merged to the branch mainline in revision 485.
  • Revision ID: belorn@fukt.bsnet.se-20110623222715-q5wro9ma9iyjl367
* Makefile (CFLAGS): Added "-lrt" to include real time library.
* plugins.d/mandos-client.c: use scandir(3) instead of readdir(3)
                             Prefix all debug output with "Mandos plugin " + program_invocation_short_name
                             Retry servers that failed to provide password.
                             New option --retry SECONDS that sets the interval between rechecking.
                             --retry also controls how often it retries a server when using --connect.
* plugins.d/splashy.c:  Prefix all debug output with "Mandos plugin " + program_invocation_short_name
* plugins.d/usplash.c: --||--
* plugins.d/askpass-fifo.c: --||--
* plugins.d/password-prompt.c: --||--
* plugins.d/plymouth.c: --||--
* mandos: Lower logger level from warning to info on failed client requests because client was disabled or unknown fingerprint.
* plugins.d/plymouth.c (get_pid): bug fix. Was not calling free on direntries. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
                                   ENFILE, ENOMEM, EBADF, EINVAL, EIO,
33
33
                                   EISDIR, EFBIG */
34
34
#include <error.h>              /* error() */
 
35
#include <stdio.h>              /* fprintf(), vfprintf(), vasprintf() */
35
36
#include <stdlib.h>             /* EXIT_FAILURE, NULL, size_t, free(),
36
37
                                   realloc(), EXIT_SUCCESS */
37
38
#include <fcntl.h>              /* open(), O_RDONLY */
39
40
                                   STDOUT_FILENO */
40
41
#include <sysexits.h>           /* EX_OSERR, EX_OSFILE,
41
42
                                   EX_UNAVAILABLE, EX_IOERR */
42
 
 
 
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
}
43
67
 
44
68
int main(__attribute__((unused))int argc,
45
69
         __attribute__((unused))char **argv){
55
79
    case EACCES:
56
80
    case ENOTDIR:
57
81
    case ELOOP:
58
 
      error(EX_OSFILE, errno, "mkfifo");
 
82
      error_plus(EX_OSFILE, errno, "mkfifo");
59
83
    case ENAMETOOLONG:
60
84
    case ENOSPC:
61
85
    case EROFS:
62
86
    default:
63
 
      error(EX_OSERR, errno, "mkfifo");
 
87
      error_plus(EX_OSERR, errno, "mkfifo");
64
88
    case ENOENT:
65
89
      /* no "/lib/cryptsetup"? */
66
 
      error(EX_UNAVAILABLE, errno, "mkfifo");
 
90
      error_plus(EX_UNAVAILABLE, errno, "mkfifo");
67
91
    case EEXIST:
68
92
      break;                    /* not an error */
69
93
    }
73
97
  int fifo_fd = open(passfifo, O_RDONLY);
74
98
  if(fifo_fd == -1){
75
99
    int e = errno;
76
 
    error(0, errno, "open");
 
100
    error_plus(0, errno, "open");
77
101
    switch(e){
78
102
    case EACCES:
79
103
    case ENOENT:
101
125
      if(buf_len + blocksize > buf_allocated){
102
126
        char *tmp = realloc(buf, buf_allocated + blocksize);
103
127
        if(tmp == NULL){
104
 
          error(0, errno, "realloc");
 
128
          error_plus(0, errno, "realloc");
105
129
          free(buf);
106
130
          return EX_OSERR;
107
131
        }
113
137
        int e = errno;
114
138
        free(buf);
115
139
        errno = e;
116
 
        error(0, errno, "read");
 
140
        error_plus(0, errno, "read");
117
141
        switch(e){
118
142
        case EBADF:
119
143
        case EFAULT:
141
165
      int e = errno;
142
166
      free(buf);
143
167
      errno = e;
144
 
      error(0, errno, "write");
 
168
      error_plus(0, errno, "write");
145
169
      switch(e){
146
170
      case EBADF:
147
171
      case EFAULT:
161
185
  ret = close(STDOUT_FILENO);
162
186
  if(ret == -1){
163
187
    int e = errno;
164
 
    error(0, errno, "close");
 
188
    error_plus(0, errno, "close");
165
189
    switch(e){
166
190
    case EBADF:
167
191
      return EX_OSFILE;