/mandos/release

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/release

« back to all changes in this revision

Viewing changes to plugins.d/usplash.c

  • Committer: Björn Påhlsson
  • Date: 2011-06-23 22:27:15 UTC
  • mto: (237.7.33 trunk)
  • mto: This revision was merged to the branch mainline in revision 284.
  • 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:
2
2
/*
3
3
 * Usplash - Read a password from usplash and output it
4
4
 * 
5
 
 * Copyright © 2008-2018, 2021 Teddy Hogeborn
6
 
 * Copyright © 2008-2018, 2021 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
 
5
 * Copyright © 2008-2011 Teddy Hogeborn
 
6
 * Copyright © 2008-2011 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
16
14
 * WITHOUT ANY WARRANTY; without even the implied warranty of
17
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18
16
 * General Public License for more details.
19
17
 * 
20
18
 * You should have received a copy of the GNU General Public License
21
 
 * along with Mandos.  If not, see <http://www.gnu.org/licenses/>.
 
19
 * along with this program.  If not, see
 
20
 * <http://www.gnu.org/licenses/>.
22
21
 * 
23
 
 * Contact the authors at <mandos@recompile.se>.
 
22
 * Contact the authors at <mandos@fukt.bsnet.se>.
24
23
 */
25
24
 
26
 
#define _GNU_SOURCE             /* vasprintf(),
27
 
                                   program_invocation_short_name,
28
 
                                   asprintf(), TEMP_FAILURE_RETRY() */
29
 
#include <sys/types.h>          /* sig_atomic_t, pid_t, setuid(),
30
 
                                   geteuid(), setsid() */
31
 
#include <stdarg.h>             /* va_list, va_start(), vfprintf() */
32
 
#include <stdio.h>              /* vasprintf(), fprintf(), stderr,
33
 
                                   vfprintf(), asprintf() */
34
 
#include <errno.h>              /* program_invocation_short_name,
35
 
                                   errno, ENOENT, EINTR */
36
 
#include <string.h>             /* strerror(), strlen(), memcmp() */
37
 
#include <error.h>              /* error() */
38
 
#include <stdlib.h>             /* free(), getenv(), realloc(),
39
 
                                   EXIT_FAILURE, EXIT_SUCCESS,
40
 
                                   malloc(), abort() */
 
25
#define _GNU_SOURCE             /* asprintf(), TEMP_FAILURE_RETRY() */
 
26
#include <signal.h>             /* sig_atomic_t, struct sigaction,
 
27
                                   sigemptyset(), sigaddset(), SIGINT,
 
28
                                   SIGHUP, SIGTERM, sigaction(),
 
29
                                   SIG_IGN, kill(), SIGKILL */
41
30
#include <stdbool.h>            /* bool, false, true */
42
31
#include <fcntl.h>              /* open(), O_WRONLY, O_RDONLY */
43
 
#include <stddef.h>             /* size_t, NULL */
44
 
#include <unistd.h>             /* close(), ssize_t, write(),
45
 
                                   readlink(), read(), STDOUT_FILENO,
46
 
                                   sleep(), fork(), setuid(),
47
 
                                   geteuid(), setsid(), chdir(),
48
 
                                   _exit(), dup2(), STDERR_FILENO,
49
 
                                   execv(), TEMP_FAILURE_RETRY(),
50
 
                                   pause() */
51
 
#include <dirent.h>             /* DIR, opendir(), struct dirent,
52
 
                                   readdir(), closedir() */
 
32
#include <iso646.h>             /* and, or, not*/
 
33
#include <errno.h>              /* errno, EINTR */
 
34
#include <error.h>
 
35
#include <sys/types.h>          /* size_t, ssize_t, pid_t, DIR, struct
 
36
                                   dirent */
 
37
#include <stddef.h>             /* NULL */
 
38
#include <string.h>             /* strlen(), memcmp(), strerror() */
 
39
#include <stdio.h>              /* asprintf(), vasprintf(), vprintf(), fprintf() */
 
40
#include <unistd.h>             /* close(), write(), readlink(),
 
41
                                   read(), STDOUT_FILENO, sleep(),
 
42
                                   fork(), setuid(), geteuid(),
 
43
                                   setsid(), chdir(), dup2(),
 
44
                                   STDERR_FILENO, execv() */
 
45
#include <stdlib.h>             /* free(), EXIT_FAILURE, realloc(),
 
46
                                   EXIT_SUCCESS, malloc(), _exit(),
 
47
                                   getenv() */
 
48
#include <dirent.h>             /* opendir(), readdir(), closedir() */
53
49
#include <inttypes.h>           /* intmax_t, strtoimax() */
54
 
#include <iso646.h>             /* or, not, and */
55
 
#include <sys/stat.h>           /* struct stat, lstat(), S_ISLNK() */
 
50
#include <sys/stat.h>           /* struct stat, lstat(), S_ISLNK */
56
51
#include <sysexits.h>           /* EX_OSERR, EX_UNAVAILABLE */
57
 
#include <signal.h>             /* struct sigaction, sigemptyset(),
58
 
                                   sigaddset(), SIGINT, SIGHUP,
59
 
                                   SIGTERM, SIG_IGN, kill(), SIGKILL,
60
 
                                   SIG_DFL, raise() */
61
52
#include <argz.h>               /* argz_count(), argz_extract() */
 
53
#include <stdarg.h>             /* va_list, va_start(), ... */
62
54
 
63
55
sig_atomic_t interrupted_by_signal = 0;
64
56
int signal_received;
65
57
const char usplash_name[] = "/sbin/usplash";
66
58
 
67
59
/* Function to use when printing errors */
68
 
__attribute__((format (gnu_printf, 3, 4)))
69
 
void error_plus(int status, int errnum, const char *formatstring,
70
 
                ...){
 
60
void error_plus(int status, int errnum, const char *formatstring, ...){
71
61
  va_list ap;
72
62
  char *text;
73
63
  int ret;
74
64
  
75
65
  va_start(ap, formatstring);
76
66
  ret = vasprintf(&text, formatstring, ap);
77
 
  if(ret == -1){
78
 
    fprintf(stderr, "Mandos plugin %s: ",
79
 
            program_invocation_short_name);
 
67
  if (ret == -1){
 
68
    fprintf(stderr, "Mandos plugin %s: ", program_invocation_short_name);
80
69
    vfprintf(stderr, formatstring, ap);
81
70
    fprintf(stderr, ": ");
82
71
    fprintf(stderr, "%s\n", strerror(errnum));
124
113
      ret = asprintf(&cmd_line_alloc, "%s %s", cmd, arg);
125
114
      if(ret == -1){
126
115
        int e = errno;
127
 
        close(*fifo_fd_r);
 
116
        TEMP_FAILURE_RETRY(close(*fifo_fd_r));
128
117
        errno = e;
129
118
        return false;
130
119
      }
140
129
                 cmd_line_len - written);
141
130
    if(sret == -1){
142
131
      int e = errno;
143
 
      close(*fifo_fd_r);
 
132
      TEMP_FAILURE_RETRY(close(*fifo_fd_r));
144
133
      free(cmd_line_alloc);
145
134
      errno = e;
146
135
      return false;
498
487
        error_plus(0, errno, "read");
499
488
        status = EX_OSERR;
500
489
      }
501
 
      close(outfifo_fd);
 
490
      TEMP_FAILURE_RETRY(close(outfifo_fd));
502
491
      goto failure;
503
492
    }
504
493
    if(interrupted_by_signal){
585
574
  
586
575
  /* Close FIFO */
587
576
  if(fifo_fd != -1){
588
 
    ret = close(fifo_fd);
 
577
    ret = (int)TEMP_FAILURE_RETRY(close(fifo_fd));
589
578
    if(ret == -1 and errno != EINTR){
590
579
      error_plus(0, errno, "close");
591
580
    }
594
583
  
595
584
  /* Close output FIFO */
596
585
  if(outfifo_fd != -1){
597
 
    ret = close(outfifo_fd);
 
586
    ret = (int)TEMP_FAILURE_RETRY(close(outfifo_fd));
598
587
    if(ret == -1){
599
588
      error_plus(0, errno, "close");
600
589
    }
662
651
  
663
652
  /* Close FIFO (again) */
664
653
  if(fifo_fd != -1){
665
 
    ret = close(fifo_fd);
 
654
    ret = (int)TEMP_FAILURE_RETRY(close(fifo_fd));
666
655
    if(ret == -1 and errno != EINTR){
667
656
      error_plus(0, errno, "close");
668
657
    }