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

  • Committer: Björn Påhlsson
  • Date: 2011-06-18 20:21:33 UTC
  • mfrom: (237.7.31 trunk)
  • mto: (237.7.33 trunk)
  • mto: This revision was merged to the branch mainline in revision 284.
  • Revision ID: belorn@fukt.bsnet.se-20110618202133-j9f1ibmcplwjkbce
merge

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,
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 */
55
55
#include <argp.h>               /* struct argp_option, struct
56
56
                                   argp_state, struct argp,
57
57
                                   argp_parse(), error_t,
67
67
const char *argp_program_version = "password-prompt " VERSION;
68
68
const char *argp_program_bug_address = "<mandos@fukt.bsnet.se>";
69
69
 
70
 
/* Needed for conflic resolution */
71
 
const char plymouthd_name[] = "plymouthd";
72
 
 
 
70
/* Needed for conflict resolution */
 
71
const char plymouth_name[] = "plymouthd";
73
72
 
74
73
static void termination_handler(int signum){
75
74
  if(quit_now){
101
100
    }
102
101
    
103
102
    char *cmdline_filename;
104
 
    ret = asprintf(&cmdline_filename, "/proc/%s/cmdline", proc_entry->d_name);
 
103
    ret = asprintf(&cmdline_filename, "/proc/%s/cmdline",
 
104
                   proc_entry->d_name);
105
105
    if(ret == -1){
106
106
      error(0, errno, "asprintf");
107
107
      return 0;
108
108
    }
109
109
    
110
 
    /* Open /proc/<pid>/cmdline  */
 
110
    /* Open /proc/<pid>/cmdline */
111
111
    cl_fd = open(cmdline_filename, O_RDONLY);
112
112
    free(cmdline_filename);
113
113
    if(cl_fd == -1){
114
 
      error(0, errno, "open");
 
114
      if(errno != ENOENT){
 
115
        error(0, errno, "open");
 
116
      }
115
117
      return 0;
116
118
    }
117
119
    
165
167
      cmdline_base = cmdline;
166
168
    }
167
169
    
168
 
    if(strcmp(cmdline_base, plymouthd_name) != 0){
 
170
    if(strcmp(cmdline_base, plymouth_name) != 0){
 
171
      if(debug){
 
172
        fprintf(stderr, "\"%s\" is not \"%s\"\n", cmdline_base,
 
173
                plymouth_name);
 
174
      }
169
175
      free(cmdline);
170
176
      return 0;
171
177
    }
 
178
    if(debug){
 
179
      fprintf(stderr, "\"%s\" equals \"%s\"\n", cmdline_base,
 
180
              plymouth_name);
 
181
    }
172
182
    free(cmdline);
173
183
    return 1;
174
184
  }
175
 
 
 
185
  
176
186
  struct dirent **direntries;
177
187
  int ret;
178
188
  ret = scandir("/proc", &direntries, is_plymouth, alphasort);
267
277
 
268
278
  if (conflict_detection()){
269
279
    if(debug){
270
 
      fprintf(stderr, "Stopping %s because of conflict", argv[0]);
 
280
      fprintf(stderr, "Stopping %s because of conflict\n", argv[0]);
271
281
    }
272
282
    return EXIT_FAILURE;
273
283
  }
475
485
        break;
476
486
      }
477
487
    }
478
 
    /* if(sret == 0), then the only sensible thing to do is to retry to
479
 
       read from stdin */
 
488
    /* if(sret == 0), then the only sensible thing to do is to retry
 
489
       to read from stdin */
480
490
    fputc('\n', stderr);
481
491
    if(debug and not quit_now){
482
492
      /* If quit_now is nonzero, we were interrupted by a signal, and