/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-02-27 17:33:28 UTC
  • mfrom: (237.5.2 mandos-release)
  • Revision ID: teddy@fukt.bsnet.se-20110227173328-iobho8fi50761460
Merge fix for password-prompt/plymouth conflict 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,
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 conflict resolution */
71
 
const char plymouth_name[] = "plymouthd";
 
70
/* Needed for conflic resolution */
 
71
const char plymouthd_name[] = "plymouthd";
 
72
 
72
73
 
73
74
static void termination_handler(int signum){
74
75
  if(quit_now){
100
101
    }
101
102
    
102
103
    char *cmdline_filename;
103
 
    ret = asprintf(&cmdline_filename, "/proc/%s/cmdline",
104
 
                   proc_entry->d_name);
 
104
    ret = asprintf(&cmdline_filename, "/proc/%s/cmdline", 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
 
      if(errno != ENOENT){
115
 
        error(0, errno, "open");
116
 
      }
 
114
      error(0, errno, "open");
117
115
      return 0;
118
116
    }
119
117
    
167
165
      cmdline_base = cmdline;
168
166
    }
169
167
    
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
 
      }
 
168
    if(strcmp(cmdline_base, plymouthd_name) != 0){
175
169
      free(cmdline);
176
170
      return 0;
177
171
    }
178
 
    if(debug){
179
 
      fprintf(stderr, "\"%s\" equals \"%s\"\n", cmdline_base,
180
 
              plymouth_name);
181
 
    }
182
172
    free(cmdline);
183
173
    return 1;
184
174
  }
185
 
  
 
175
 
186
176
  struct dirent **direntries;
187
177
  int ret;
188
178
  ret = scandir("/proc", &direntries, is_plymouth, alphasort);
277
267
 
278
268
  if (conflict_detection()){
279
269
    if(debug){
280
 
      fprintf(stderr, "Stopping %s because of conflict\n", argv[0]);
 
270
      fprintf(stderr, "Stopping %s because of conflict", argv[0]);
281
271
    }
282
272
    return EXIT_FAILURE;
283
273
  }
485
475
        break;
486
476
      }
487
477
    }
488
 
    /* if(sret == 0), then the only sensible thing to do is to retry
489
 
       to read from stdin */
 
478
    /* if(sret == 0), then the only sensible thing to do is to retry to
 
479
       read from stdin */
490
480
    fputc('\n', stderr);
491
481
    if(debug and not quit_now){
492
482
      /* If quit_now is nonzero, we were interrupted by a signal, and