/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: 2014-07-25 22:44:20 UTC
  • mto: This revision was merged to the branch mainline in revision 724.
  • Revision ID: teddy@recompile.se-20140725224420-4a5ct2ptt0hsc92z
Require Python 2.7.

This is in preparation for the eventual move to Python 3, which will
happen as soon as all Python modules required by Mandos are available.
The mandos-ctl and mandos-monitor programs are already portable
between Python 2.6 and Python 3 without changes; this change will
bring the requirement up to Python 2.7.

* INSTALL (Prerequisites/Libraries/Mandos Server): Document
                                                   requirement of
                                                   Python 2.7; remove
                                                   Python-argparse
                                                   which is in the
                                                   Python 2.7 standard
                                                   library.
* debian/control (Source: mandos/Build-Depends-Indep): Depend on
                                                       exactly the
                                                       python2.7
                                                       package and all
                                                       the Python 2.7
                                                       versions of the
                                                       python modules.
  (Package: mandos/Depends): - '' - but still depend on python (<=2.7)
                            and the generic versions of the Python
                            modules; this is for mandos-ctl and
                            mandos-monitor, both of which are
                            compatible with Python 3, and use
                            #!/usr/bin/python.
* mandos: Use #!/usr/bin/python2.7 instead of #!/usr/bin/python.

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