/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/password-prompt.c

  • Committer: Teddy Hogeborn
  • Date: 2011-07-13 02:24:39 UTC
  • mfrom: (24.1.174 mandos)
  • Revision ID: teddy@fukt.bsnet.se-20110713022439-wbv6kghshdsc2x24
Merge from Björn.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
#define _GNU_SOURCE             /* getline(), asprintf() */
26
26
 
27
 
#include <termios.h>            /* struct termios, tcsetattr(),
 
27
#include <termios.h>            /* struct termios, tcsetattr(),
28
28
                                   TCSAFLUSH, tcgetattr(), ECHO */
29
29
#include <unistd.h>             /* struct termios, tcsetattr(),
30
30
                                   STDIN_FILENO, TCSAFLUSH,
41
41
                                   getenv(), free() */
42
42
#include <dirent.h>             /* scandir(), alphasort() */
43
43
#include <stdio.h>              /* fprintf(), stderr, getline(),
44
 
                                   stdin, feof(), fputc()
45
 
                                */
 
44
                                   stdin, feof(), fputc(), vfprintf(),
 
45
                                   vasprintf() */
46
46
#include <errno.h>              /* errno, EBADF, ENOTTY, EINVAL,
47
47
                                   EFAULT, EFBIG, EIO, ENOSPC, EINTR
48
48
                                */
50
50
#include <iso646.h>             /* or, not */
51
51
#include <stdbool.h>            /* bool, false, true */
52
52
#include <inttypes.h>           /* strtoumax() */
53
 
#include <sys/stat.h>           /* struct stat, lstat(), open() */
54
 
#include <string.h>             /* strlen, rindex, memcmp */
 
53
#include <sys/stat.h>           /* struct stat, lstat(), open() */
 
54
#include <string.h>             /* strlen, rindex, memcmp, strerror()
 
55
                                 */
55
56
#include <argp.h>               /* struct argp_option, struct
56
57
                                   argp_state, struct argp,
57
58
                                   argp_parse(), error_t,
60
61
#include <sysexits.h>           /* EX_SOFTWARE, EX_OSERR,
61
62
                                   EX_UNAVAILABLE, EX_IOERR, EX_OK */
62
63
#include <fcntl.h>              /* open() */
 
64
#include <stdarg.h>             /* va_list, va_start(), ... */
63
65
 
64
66
volatile sig_atomic_t quit_now = 0;
65
67
int signal_received;
69
71
 
70
72
/* Needed for conflict resolution */
71
73
const char plymouth_name[] = "plymouthd";
72
 
const char plymouth_alt_name[] = "plymouthd";
73
74
 
 
75
/* Function to use when printing errors */
 
76
void error_plus(int status, int errnum, const char *formatstring,
 
77
                ...){
 
78
  va_list ap;
 
79
  char *text;
 
80
  int ret;
 
81
  
 
82
  va_start(ap, formatstring);
 
83
  ret = vasprintf(&text, formatstring, ap);
 
84
  if (ret == -1){
 
85
    fprintf(stderr, "Mandos plugin %s: ",
 
86
            program_invocation_short_name);
 
87
    vfprintf(stderr, formatstring, ap);
 
88
    fprintf(stderr, ": ");
 
89
    fprintf(stderr, "%s\n", strerror(errnum));
 
90
    error(status, errno, "vasprintf while printing error");
 
91
    return;
 
92
  }
 
93
  fprintf(stderr, "Mandos plugin ");
 
94
  error(status, errnum, "%s", text);
 
95
  free(text);
 
96
}
74
97
 
75
98
static void termination_handler(int signum){
76
99
  if(quit_now){
102
125
    }
103
126
    
104
127
    char *cmdline_filename;
105
 
    ret = asprintf(&cmdline_filename, "/proc/%s/cmdline", proc_entry->d_name);
 
128
    ret = asprintf(&cmdline_filename, "/proc/%s/cmdline",
 
129
                   proc_entry->d_name);
106
130
    if(ret == -1){
107
131
      error(0, errno, "asprintf");
108
132
      return 0;
109
133
    }
110
134
    
111
 
    /* Open /proc/<pid>/cmdline  */
 
135
    /* Open /proc/<pid>/cmdline */
112
136
    cl_fd = open(cmdline_filename, O_RDONLY);
113
137
    free(cmdline_filename);
114
138
    if(cl_fd == -1){
115
 
      error(0, errno, "open");
 
139
      if(errno != ENOENT){
 
140
        error(0, errno, "open");
 
141
      }
116
142
      return 0;
117
143
    }
118
144
    
166
192
      cmdline_base = cmdline;
167
193
    }
168
194
    
169
 
    if((strcmp(cmdline_base, plymouth_name) != 0)
170
 
       and (strcmp(cmdline_base, plymouth_alt_name) != 0)){
 
195
    if(strcmp(cmdline_base, plymouth_name) != 0){
 
196
      if(debug){
 
197
        fprintf(stderr, "\"%s\" is not \"%s\"\n", cmdline_base,
 
198
                plymouth_name);
 
199
      }
171
200
      free(cmdline);
172
201
      return 0;
173
202
    }
 
203
    if(debug){
 
204
      fprintf(stderr, "\"%s\" equals \"%s\"\n", cmdline_base,
 
205
              plymouth_name);
 
206
    }
174
207
    free(cmdline);
175
208
    return 1;
176
209
  }
177
 
 
 
210
  
178
211
  struct dirent **direntries;
179
212
  int ret;
180
213
  ret = scandir("/proc", &direntries, is_plymouth, alphasort);
269
302
 
270
303
  if (conflict_detection()){
271
304
    if(debug){
272
 
      fprintf(stderr, "Stopping %s because of conflict", argv[0]);
 
305
      fprintf(stderr, "Stopping %s because of conflict\n", argv[0]);
273
306
    }
274
307
    return EXIT_FAILURE;
275
308
  }
477
510
        break;
478
511
      }
479
512
    }
480
 
    /* if(sret == 0), then the only sensible thing to do is to retry to
481
 
       read from stdin */
 
513
    /* if(sret == 0), then the only sensible thing to do is to retry
 
514
       to read from stdin */
482
515
    fputc('\n', stderr);
483
516
    if(debug and not quit_now){
484
517
      /* If quit_now is nonzero, we were interrupted by a signal, and