/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: Teddy Hogeborn
  • Date: 2008-07-20 06:33:48 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080720063348-jscgy5p0itrgvlo8
* mandos-clients.conf ([foo]): Uncommented.
  ([foo]/secret): New.
  ([foo]/secfile): Commented out.
  ([foo]/checker): Changed to "fping -q -- %%(fqdn)s".
  ([foo]/timeout): New.

* server.py: New modeline for Python and Emacs.  Set a logging format.
  (Client.__init__): Bug fix: Choose either the value from the options
                     object or pass the argument through string_to_delta
                     for both "timeout" and "interval".
  (Client.checker_callback): Bug fix: Do not log spurious "Checker for
                             <foo> failed" messages.
  (Client.start_checker): Moved "Starting checker" log message down to
                          just before actually starting the subprocess.
                          Do not redirect the subprocesses' stdout to a
                          pipe.
  (peer_certificate, fingerprint): Added docstrings.
  (entry_group_state_changed): Call "killme()" instead of
                               "main_loop.quit()".
  (daemon, killme): New functions.
  (exitstatus, main_loop_started): New global variables.
  (__main__): Removed the "--cert", "--key", "--ca", and "--crl"
              options.  Removed the sleep command from the default
              checker.  Add a console logger in debug mode.  Call
              "killme()" instead of "main_loop.quit()" when there are no
              more clients.  Call "daemon()" if not in debug mode.
              Register "cleanup()" to run at exit.  Ignore some
              signals.  Catch DBusException to detect another running
              server and exit cleanly.  Exit with "exitstatus".
  (cleanup): New function.

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
}