/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-19 18:43:24 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080719184324-iwhoa5in75xa0u2u
* mandos-clients.conf ([foo]/dn, [foo]/password, [braxen_client]/dn,
                       [braxen_client]/password): Removed.
  ([foo]/fingerprint, [braxen_client]/fingerprint): New.
  ([foo]/checker): New.
  ([foo]/secfile): New.
  ([braxen_client]/secret): New.

* server.py: New "--debug" option to set debug flag.  Removed "cert",
             "key", "ca", "crl", and "cred" variables.  Added default
             value for "checker" config file setting.  Do not pass
             credentials to IPv6_TCPServer constructor.
  (debug): New global debug flag.  Used by most debugging output code.
  (Client.__init__): Keyword argument "dn" replaced by "fingerprint",
                     "password" renamed to "secret", and "passfile"
                     renamed to "secfile".  New keyword argument
                     "checker". All callers changed.
  (Client.dn): Removed.
  (Client.fingerprint): New.
  (Client.password): Renamed to "secret"; all users changed.
  (Client.passfile): Renamed to "secfile"; all users changed.
  (Client.timeout, Client.interval): Changed to be properties; now
                                     automatically updates the
                                     "_timeout_milliseconds" and
                                     "_interval_milliseconds" values.
  (Client.timeout_milliseconds): Renamed to "_timeout_milliseconds".
  (Client.interval_milliseconds): Renamed to "_interval_milliseconds".
  (Client.check_command): New.
  (Client.start_checker): Use the new "check_command" attribute.
  (peer_certificate, fingerprint): New functions.

  (tcp_handler.handle): Use ClientSession with empty credentials
                        object instead of ServerSession.  Set gnutls
                        priority string.  Do not verify peer.  Use
                        fingerprint instead of DN when searching for
                        clients.  Bug fix: Loop sending data so even large
                        secret data strings are sent.
  (IPv6_TCPServer.credentials): Removed.
  (if_nametoindex): Do not import ctypes since that is now imported
                    globally.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#define _GNU_SOURCE             /* getline() */
2
 
#define _FORTIFY_SOURCE 2
3
 
#include <termios.h>            /* struct termios, tcsetattr(),
4
 
                                   TCSAFLUSH, tcgetattr(), ECHO */
5
 
#include <unistd.h>             /* struct termios, tcsetattr(),
6
 
                                   STDIN_FILENO, TCSAFLUSH,
7
 
                                   tcgetattr(), ECHO */
8
 
#include <signal.h>             /* sig_atomic_t, raise(), struct
9
 
                                   sigaction, sigemptyset(),
10
 
                                   sigaction(), sigaddset(), SIGINT,
11
 
                                   SIGQUIT, SIGHUP, SIGTERM */
12
 
#include <stddef.h>             /* NULL, size_t */
13
 
#include <sys/types.h>          /* ssize_t */
14
 
#include <stdlib.h>             /* EXIT_SUCCESS, EXIT_FAILURE */
15
 
#include <stdio.h>              /* fprintf(), stderr, getline(),
16
 
                                   stdin, feof(), perror(), fputc(),
17
 
                                   stdout */
18
 
#include <errno.h>              /* errno, EINVAL */
19
 
#include <iso646.h>             /* or, not */
20
 
#include <stdbool.h>            /* bool, false, true */
21
 
 
22
 
volatile bool quit_now = false;
23
 
 
24
 
void termination_handler(int signum){
25
 
  quit_now = true;
26
 
}
27
 
 
28
 
int main(int argc, char **argv){
29
 
  ssize_t ret = -1;
30
 
  size_t n;
31
 
  struct termios t_new, t_old;
32
 
  char *buffer = NULL;
33
 
  int status = EXIT_SUCCESS;
34
 
  struct sigaction old_action,
35
 
    new_action = { .sa_handler = termination_handler,
36
 
                   .sa_flags = 0 };
37
 
  
38
 
  if (tcgetattr(STDIN_FILENO, &t_old) != 0){
39
 
    return EXIT_FAILURE;
40
 
  }
41
 
  
42
 
  sigemptyset(&new_action.sa_mask);
43
 
  sigaddset(&new_action.sa_mask, SIGINT);
44
 
  sigaddset(&new_action.sa_mask, SIGQUIT);
45
 
  sigaddset(&new_action.sa_mask, SIGHUP);
46
 
  sigaddset(&new_action.sa_mask, SIGTERM);
47
 
  sigaction(SIGINT, NULL, &old_action);
48
 
  if (old_action.sa_handler != SIG_IGN)
49
 
    sigaction(SIGINT, &new_action, NULL);
50
 
  sigaction(SIGQUIT, NULL, &old_action);
51
 
  if (old_action.sa_handler != SIG_IGN)
52
 
    sigaction(SIGQUIT, &new_action, NULL);
53
 
  sigaction(SIGHUP, NULL, &old_action);
54
 
  if (old_action.sa_handler != SIG_IGN)
55
 
    sigaction(SIGHUP, &new_action, NULL);
56
 
  sigaction(SIGTERM, NULL, &old_action);
57
 
  if (old_action.sa_handler != SIG_IGN)
58
 
    sigaction(SIGTERM, &new_action, NULL);
59
 
  
60
 
  t_new = t_old;
61
 
  t_new.c_lflag &= ~ECHO;
62
 
  if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &t_new) != 0){
63
 
    perror("tcsetattr-echo");
64
 
    return EXIT_FAILURE;
65
 
  }
66
 
  
67
 
  while(true){
68
 
    if (quit_now){
69
 
      status = EXIT_FAILURE;
70
 
      break;
71
 
    }
72
 
    fprintf(stderr, "Password: ");
73
 
    ret = getline(&buffer, &n, stdin);
74
 
    if (ret > 0){
75
 
      fprintf(stdout, "%s", buffer);
76
 
      status = EXIT_SUCCESS;
77
 
      break;
78
 
    }
79
 
    // ret == 0 makes no other sence than to retry to read from stdin
80
 
    if (ret < 0){
81
 
      if (errno != EINTR and not feof(stdin)){
82
 
        perror("getline");
83
 
        status = EXIT_FAILURE;
84
 
        break;
85
 
      }
86
 
    }
87
 
    fputc('\n', stderr);
88
 
  }
89
 
 
90
 
  if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &t_old) != 0){
91
 
    perror("tcsetattr+echo");
92
 
  }
93
 
  
94
 
  return status;
95
 
}