/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 02:52:20 UTC
  • Revision ID: belorn@braxen-20080720025220-r5u0388uy9iu23h6
Added following support:
Pluginbased client handler
rewritten Mandos client
       Avahi instead of udp server discovery
       openpgp encrypted key support
Passprompt stand alone application for direct console input
Added logging for Mandos server

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 */
22
21
 
23
22
volatile bool quit_now = false;
24
 
bool debug = false;
25
23
 
26
24
void termination_handler(int signum){
27
25
  quit_now = true;
36
34
  struct sigaction old_action,
37
35
    new_action = { .sa_handler = termination_handler,
38
36
                   .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
 
  }
71
37
  
72
38
  if (tcgetattr(STDIN_FILENO, &t_old) != 0){
73
39
    return EXIT_FAILURE;
90
56
  sigaction(SIGTERM, NULL, &old_action);
91
57
  if (old_action.sa_handler != SIG_IGN)
92
58
    sigaction(SIGTERM, &new_action, NULL);
93
 
 
94
 
  
95
 
  if (debug){
96
 
    fprintf(stderr, "Removing echo flag from terminal attributes\n");
97
 
  }
98
59
  
99
60
  t_new = t_old;
100
61
  t_new.c_lflag &= ~ECHO;
102
63
    perror("tcsetattr-echo");
103
64
    return EXIT_FAILURE;
104
65
  }
105
 
 
106
 
  if (debug){
107
 
    fprintf(stderr, "Waiting for input from stdin \n");
108
 
  }
 
66
  
109
67
  while(true){
110
68
    if (quit_now){
111
69
      status = EXIT_FAILURE;
129
87
    fputc('\n', stderr);
130
88
  }
131
89
 
132
 
  if (debug){
133
 
    fprintf(stderr, "Restoring terminal attributes\n");
134
 
  }
135
90
  if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &t_old) != 0){
136
91
    perror("tcsetattr+echo");
137
92
  }
138
 
 
139
 
  if (debug){
140
 
    fprintf(stderr, "%s is exiting\n", argv[0]);
141
 
  }
142
93
  
143
94
  return status;
144
95
}