/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: 2019-02-10 03:50:20 UTC
  • Revision ID: teddy@recompile.se-20190210035020-nttr1tybgwwixueu
Show debconf note about new TLS key IDs

If mandos-client did not see TLS keys and had to create them, or if
mandos sees GnuTLS version 3.6.6 or later, show an important notice on
package installation about the importance of adding the new key_id
options to clients.conf on the Mandos server.

* debian/control (Package: mandos, Package: mandos-client): Depend on
                                                            debconf.
* debian/mandos-client.lintian-overrides: Override warnings.
* debian/mandos-client.postinst (create_keys): Show notice if new TLS
                                               key files were created.
* debian/mandos-client.templates: New.
* debian/mandos.lintian-overrides: Override warnings.
* debian/mandos.postinst (configure): If GnuTLS 3.6.6 or later is
                                      detected, show an important
                                      notice (once) about the new
                                      key_id option required in
                                      clients.conf.
* debian/mandos.templates: New.

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
7
 
 * 
8
 
 * This program is free software: you can redistribute it and/or
9
 
 * modify it under the terms of the GNU General Public License as
10
 
 * published by the Free Software Foundation, either version 3 of the
11
 
 * License, or (at your option) any later version.
12
 
 * 
13
 
 * This program is distributed in the hope that it will be useful, but
 
5
 * Copyright © 2008-2018 Teddy Hogeborn
 
6
 * Copyright © 2008-2018 Björn Påhlsson
 
7
 * 
 
8
 * This file is part of Mandos.
 
9
 * 
 
10
 * Mandos is free software: you can redistribute it and/or modify it
 
11
 * under the terms of the GNU General Public License as published by
 
12
 * the Free Software Foundation, either version 3 of the License, or
 
13
 * (at your option) any later version.
 
14
 * 
 
15
 * Mandos is distributed in the hope that it will be useful, but
14
16
 * WITHOUT ANY WARRANTY; without even the implied warranty of
15
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
18
 * General Public License for more details.
17
19
 * 
18
20
 * You should have received a copy of the GNU General Public License
19
 
 * along with this program.  If not, see
20
 
 * <http://www.gnu.org/licenses/>.
 
21
 * along with Mandos.  If not, see <http://www.gnu.org/licenses/>.
21
22
 * 
22
 
 * Contact the authors at <mandos@fukt.bsnet.se>.
 
23
 * Contact the authors at <mandos@recompile.se>.
23
24
 */
24
25
 
25
26
#define _GNU_SOURCE             /* TEMP_FAILURE_RETRY() */
26
 
#include <sys/types.h>          /* ssize_t */
 
27
#include <sys/types.h>          /* uid_t, gid_t, ssize_t */
27
28
#include <sys/stat.h>           /* mkfifo(), S_IRUSR, S_IWUSR */
28
29
#include <iso646.h>             /* and */
29
30
#include <errno.h>              /* errno, EACCES, ENOTDIR, ELOOP,
32
33
                                   ENFILE, ENOMEM, EBADF, EINVAL, EIO,
33
34
                                   EISDIR, EFBIG */
34
35
#include <error.h>              /* error() */
 
36
#include <stdio.h>              /* fprintf(), vfprintf(),
 
37
                                   vasprintf() */
35
38
#include <stdlib.h>             /* EXIT_FAILURE, NULL, size_t, free(),
36
39
                                   realloc(), EXIT_SUCCESS */
37
40
#include <fcntl.h>              /* open(), O_RDONLY */
39
42
                                   STDOUT_FILENO */
40
43
#include <sysexits.h>           /* EX_OSERR, EX_OSFILE,
41
44
                                   EX_UNAVAILABLE, EX_IOERR */
42
 
 
 
45
#include <string.h>             /* strerror() */
 
46
#include <stdarg.h>             /* va_list, va_start(), ... */
 
47
 
 
48
uid_t uid = 65534;
 
49
gid_t gid = 65534;
 
50
 
 
51
/* Function to use when printing errors */
 
52
__attribute__((format (gnu_printf, 3, 4)))
 
53
void error_plus(int status, int errnum, const char *formatstring,
 
54
                ...){
 
55
  va_list ap;
 
56
  char *text;
 
57
  int ret;
 
58
  
 
59
  va_start(ap, formatstring);
 
60
  ret = vasprintf(&text, formatstring, ap);
 
61
  if(ret == -1){
 
62
    fprintf(stderr, "Mandos plugin %s: ",
 
63
            program_invocation_short_name);
 
64
    vfprintf(stderr, formatstring, ap);
 
65
    fprintf(stderr, ": ");
 
66
    fprintf(stderr, "%s\n", strerror(errnum));
 
67
    error(status, errno, "vasprintf while printing error");
 
68
    return;
 
69
  }
 
70
  fprintf(stderr, "Mandos plugin ");
 
71
  error(status, errnum, "%s", text);
 
72
  free(text);
 
73
}
43
74
 
44
75
int main(__attribute__((unused))int argc,
45
76
         __attribute__((unused))char **argv){
46
77
  int ret = 0;
47
78
  ssize_t sret;
48
79
  
 
80
  uid = getuid();
 
81
  gid = getgid();
 
82
  
49
83
  /* Create FIFO */
50
84
  const char passfifo[] = "/lib/cryptsetup/passfifo";
51
85
  ret = mkfifo(passfifo, S_IRUSR | S_IWUSR);
52
86
  if(ret == -1){
53
87
    int e = errno;
54
 
    error(0, errno, "mkfifo");
55
88
    switch(e){
56
89
    case EACCES:
57
90
    case ENOTDIR:
58
91
    case ELOOP:
59
 
      return EX_OSFILE;
 
92
      error_plus(EX_OSFILE, errno, "mkfifo");
60
93
    case ENAMETOOLONG:
61
94
    case ENOSPC:
62
95
    case EROFS:
63
96
    default:
64
 
      return EX_OSERR;
 
97
      error_plus(EX_OSERR, errno, "mkfifo");
65
98
    case ENOENT:
66
 
      return EX_UNAVAILABLE;    /* no "/lib/cryptsetup"? */
 
99
      /* no "/lib/cryptsetup"? */
 
100
      error_plus(EX_UNAVAILABLE, errno, "mkfifo");
67
101
    case EEXIST:
68
102
      break;                    /* not an error */
69
103
    }
73
107
  int fifo_fd = open(passfifo, O_RDONLY);
74
108
  if(fifo_fd == -1){
75
109
    int e = errno;
76
 
    error(0, errno, "open");
 
110
    error_plus(0, errno, "open");
77
111
    switch(e){
78
112
    case EACCES:
79
113
    case ENOENT:
91
125
    }
92
126
  }
93
127
  
 
128
  /* Lower group privileges  */
 
129
  if(setgid(gid) == -1){
 
130
    error_plus(0, errno, "setgid");
 
131
  }
 
132
  
 
133
  /* Lower user privileges */
 
134
  if(setuid(uid) == -1){
 
135
    error_plus(0, errno, "setuid");
 
136
  }
 
137
  
94
138
  /* Read from FIFO */
95
139
  char *buf = NULL;
96
140
  size_t buf_len = 0;
101
145
      if(buf_len + blocksize > buf_allocated){
102
146
        char *tmp = realloc(buf, buf_allocated + blocksize);
103
147
        if(tmp == NULL){
104
 
          error(0, errno, "realloc");
 
148
          error_plus(0, errno, "realloc");
105
149
          free(buf);
106
150
          return EX_OSERR;
107
151
        }
113
157
        int e = errno;
114
158
        free(buf);
115
159
        errno = e;
116
 
        error(0, errno, "read");
 
160
        error_plus(0, errno, "read");
117
161
        switch(e){
118
162
        case EBADF:
119
163
        case EFAULT:
141
185
      int e = errno;
142
186
      free(buf);
143
187
      errno = e;
144
 
      error(0, errno, "write");
 
188
      error_plus(0, errno, "write");
145
189
      switch(e){
146
190
      case EBADF:
147
191
      case EFAULT:
161
205
  ret = close(STDOUT_FILENO);
162
206
  if(ret == -1){
163
207
    int e = errno;
164
 
    error(0, errno, "close");
 
208
    error_plus(0, errno, "close");
165
209
    switch(e){
166
210
    case EBADF:
167
211
      return EX_OSFILE;