/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/passprompt.c

  • Committer: Björn Påhlsson
  • Date: 2008-07-20 23:34:51 UTC
  • mto: This revision was merged to the branch mainline in revision 17.
  • Revision ID: belorn@braxen-20080720233451-720put8qyxqvk2ld
Added debug options from passprompt as --debug and --debug=passprompt

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
#include <errno.h>              /* errno, EINVAL */
19
19
#include <iso646.h>             /* or, not */
20
20
#include <stdbool.h>            /* bool, false, true */
 
21
#include <string.h>             /* strlen, rindex, strncmp, strcmp */
21
22
 
22
23
volatile bool quit_now = false;
 
24
bool debug = false;
23
25
 
24
26
void termination_handler(int signum){
25
27
  quit_now = true;
34
36
  struct sigaction old_action,
35
37
    new_action = { .sa_handler = termination_handler,
36
38
                   .sa_flags = 0 };
 
39
  const char db[] = "--debug";
 
40
  char *basename = rindex(argv[0], '/');
 
41
  if(basename == NULL){
 
42
    basename = argv[0];
 
43
  } else {
 
44
    basename++;
 
45
  }
 
46
 
 
47
  char *program_name = malloc(strlen(basename) + sizeof(db));
 
48
  if (program_name == NULL){
 
49
    perror("argv[0]");
 
50
    return EXIT_FAILURE;
 
51
  }
 
52
    
 
53
  program_name[0] = '\0';
 
54
    
 
55
  for (int i = 1; i < argc; i++){
 
56
    if (not strncmp(argv[i], db, 5)){
 
57
      strcat(strcat(strcat(program_name, db ), "="), basename);
 
58
      if(not strcmp(argv[i], db) or not strcmp(argv[i], program_name)){
 
59
        debug = true;
 
60
      }
 
61
    }
 
62
  }
 
63
  free(program_name);
 
64
 
 
65
  if (debug){
 
66
    fprintf(stderr, "Starting %s\n", argv[0]);
 
67
  }
 
68
  if (debug){
 
69
    fprintf(stderr, "Storing current terminal attributes\n");
 
70
  }
37
71
  
38
72
  if (tcgetattr(STDIN_FILENO, &t_old) != 0){
39
73
    return EXIT_FAILURE;
56
90
  sigaction(SIGTERM, NULL, &old_action);
57
91
  if (old_action.sa_handler != SIG_IGN)
58
92
    sigaction(SIGTERM, &new_action, NULL);
 
93
 
 
94
  
 
95
  if (debug){
 
96
    fprintf(stderr, "Removing echo flag from terminal attributes\n");
 
97
  }
59
98
  
60
99
  t_new = t_old;
61
100
  t_new.c_lflag &= ~ECHO;
63
102
    perror("tcsetattr-echo");
64
103
    return EXIT_FAILURE;
65
104
  }
66
 
  
 
105
 
 
106
  if (debug){
 
107
    fprintf(stderr, "Waiting for input from stdin \n");
 
108
  }
67
109
  while(true){
68
110
    if (quit_now){
69
111
      status = EXIT_FAILURE;
87
129
    fputc('\n', stderr);
88
130
  }
89
131
 
 
132
  if (debug){
 
133
    fprintf(stderr, "Restoring terminal attributes\n");
 
134
  }
90
135
  if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &t_old) != 0){
91
136
    perror("tcsetattr+echo");
92
137
  }
 
138
 
 
139
  if (debug){
 
140
    fprintf(stderr, "%s is exiting\n", argv[0]);
 
141
  }
93
142
  
94
143
  return status;
95
144
}