/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: 2021-02-03 08:41:01 UTC
  • mfrom: (1235 trunk)
  • mto: This revision was merged to the branch mainline in revision 1236.
  • Revision ID: teddy@recompile.se-20210203084101-411siabek78fx6bi
Merge from trunk

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-2018 Teddy Hogeborn
6
 
 * Copyright © 2008-2018 Björn Påhlsson
 
5
 * Copyright © 2008-2019, 2021 Teddy Hogeborn
 
6
 * Copyright © 2008-2019, 2021 Björn Påhlsson
7
7
 * 
8
8
 * This file is part of Mandos.
9
9
 * 
23
23
 * Contact the authors at <mandos@recompile.se>.
24
24
 */
25
25
 
26
 
#define _GNU_SOURCE             /* TEMP_FAILURE_RETRY() */
27
 
#include <sys/types.h>          /* uid_t, gid_t, ssize_t */
28
 
#include <sys/stat.h>           /* mkfifo(), S_IRUSR, S_IWUSR */
29
 
#include <iso646.h>             /* and */
30
 
#include <errno.h>              /* errno, EACCES, ENOTDIR, ELOOP,
 
26
#define _GNU_SOURCE             /* vasprintf(),
 
27
                                   program_invocation_short_name */
 
28
#include <sys/types.h>          /* uid_t, gid_t, getuid(), getgid(),
 
29
                                   setgid(), setuid() */
 
30
#include <unistd.h>             /* uid_t, gid_t, ssize_t, getuid(),
 
31
                                   getgid(), setgid(), setuid(),
 
32
                                   read(), close(), write(),
 
33
                                   STDOUT_FILENO */
 
34
#include <stdarg.h>             /* va_list, va_start(), vfprintf() */
 
35
#include <stdio.h>              /* vasprintf(), fprintf(), stderr,
 
36
                                   vfprintf() */
 
37
#include <errno.h>              /* program_invocation_short_name,
 
38
                                   errno, EACCES, ENOTDIR, ELOOP,
31
39
                                   ENAMETOOLONG, ENOSPC, EROFS,
32
40
                                   ENOENT, EEXIST, EFAULT, EMFILE,
33
41
                                   ENFILE, ENOMEM, EBADF, EINVAL, EIO,
34
42
                                   EISDIR, EFBIG */
 
43
#include <string.h>             /* strerror() */
35
44
#include <error.h>              /* error() */
36
 
#include <stdio.h>              /* fprintf(), vfprintf(),
37
 
                                   vasprintf() */
38
 
#include <stdlib.h>             /* EXIT_FAILURE, NULL, size_t, free(),
39
 
                                   realloc(), EXIT_SUCCESS */
 
45
#include <stdlib.h>             /* free(), realloc(), EXIT_SUCCESS */
 
46
#include <sys/stat.h>           /* mkfifo(), S_IRUSR, S_IWUSR */
 
47
#include <sysexits.h>           /* EX_OSFILE, EX_OSERR,
 
48
                                   EX_UNAVAILABLE, EX_IOERR */
40
49
#include <fcntl.h>              /* open(), O_RDONLY */
41
 
#include <unistd.h>             /* read(), close(), write(),
42
 
                                   STDOUT_FILENO */
43
 
#include <sysexits.h>           /* EX_OSERR, EX_OSFILE,
44
 
                                   EX_UNAVAILABLE, EX_IOERR */
45
 
#include <string.h>             /* strerror() */
46
 
#include <stdarg.h>             /* va_list, va_start(), ... */
 
50
#include <stddef.h>             /* NULL, size_t */
47
51
 
48
52
uid_t uid = 65534;
49
53
gid_t gid = 65534;
65
69
    fprintf(stderr, ": ");
66
70
    fprintf(stderr, "%s\n", strerror(errnum));
67
71
    error(status, errno, "vasprintf while printing error");
 
72
    if(status){
 
73
      __builtin_unreachable();
 
74
    }
68
75
    return;
69
76
  }
70
77
  fprintf(stderr, "Mandos plugin ");
71
78
  error(status, errnum, "%s", text);
 
79
  if(status){
 
80
    __builtin_unreachable();
 
81
  }
72
82
  free(text);
73
83
}
74
84
 
90
100
    case ENOTDIR:
91
101
    case ELOOP:
92
102
      error_plus(EX_OSFILE, errno, "mkfifo");
 
103
      __builtin_unreachable();
93
104
    case ENAMETOOLONG:
94
105
    case ENOSPC:
95
106
    case EROFS:
96
107
    default:
97
108
      error_plus(EX_OSERR, errno, "mkfifo");
 
109
      __builtin_unreachable();
98
110
    case ENOENT:
99
111
      /* no "/lib/cryptsetup"? */
100
112
      error_plus(EX_UNAVAILABLE, errno, "mkfifo");
 
113
      __builtin_unreachable();
101
114
    case EEXIST:
102
115
      break;                    /* not an error */
103
116
    }