/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-21 01:50:31 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080721015031-ivjiclli2j06hwgs
* Makefile: Include targets for all binaries.

* plugins.d/Makefile: Do nothing but call the parent Makefile.

* server.py: Added copyright statement and information.
  (Client.__init__): Added doc string.
  (Client.stop): Bug fix: Only log message if stopping for the first
                 time.  Check if the "stop_initiator_tag" and
                 "checker_initiator_tag" attributes exist before using
                 them.
  (Client.__del__): Call self.stop() instead of doing things here.
  (Client.checker_callback): Set self.checker_callback_tag and
                             self.checker to None unconditionally and
                             immediately.
  (Client.stop_checker): Added some checks to handle multiple calls.
  (tcp_handler.handle): Use "self.server.clients" instead of "clients".
  (__main__): Moved all code to the "main" function.
  (main): New.  New option "--address".  Instantiate IPv6_TCPServer
          with "options.address".  Log before starting main loop.
  (main.cleanup) Use "clients.pop()" to remove clients from the set as
                 they are stopped.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
                                   SIGQUIT, SIGHUP, SIGTERM */
12
12
#include <stddef.h>             /* NULL, size_t */
13
13
#include <sys/types.h>          /* ssize_t */
14
 
#include <stdlib.h>             /* EXIT_SUCCESS, EXIT_FAILURE,
15
 
                                   getopt_long */
 
14
#include <stdlib.h>             /* EXIT_SUCCESS, EXIT_FAILURE */
16
15
#include <stdio.h>              /* fprintf(), stderr, getline(),
17
16
                                   stdin, feof(), perror(), fputc(),
18
 
                                   stdout, getopt_long */
 
17
                                   stdout */
19
18
#include <errno.h>              /* errno, EINVAL */
20
19
#include <iso646.h>             /* or, not */
21
20
#include <stdbool.h>            /* bool, false, true */
22
 
#include <string.h>             /* strlen, rindex, strncmp, strcmp */
23
 
#include <getopt.h>             /* getopt_long */
24
21
 
25
22
volatile bool quit_now = false;
26
 
bool debug = false;
27
23
 
28
24
void termination_handler(int signum){
29
25
  quit_now = true;
30
26
}
31
27
 
32
28
int main(int argc, char **argv){
33
 
  ssize_t ret;
 
29
  ssize_t ret = -1;
34
30
  size_t n;
35
31
  struct termios t_new, t_old;
36
32
  char *buffer = NULL;
37
 
  char *prefix = NULL;
38
33
  int status = EXIT_SUCCESS;
39
34
  struct sigaction old_action,
40
35
    new_action = { .sa_handler = termination_handler,
41
36
                   .sa_flags = 0 };
42
 
 
43
 
  while (true){
44
 
    static struct option long_options[] = {
45
 
      {"debug", no_argument, (int *)&debug, 1},
46
 
      {"prefix", required_argument, 0, 'p'},
47
 
      {0, 0, 0, 0} };
48
 
 
49
 
    int option_index = 0;
50
 
    ret = getopt_long (argc, argv, "p:", long_options, &option_index);
51
 
 
52
 
    if (ret == -1){
53
 
      break;
54
 
    }
55
 
      
56
 
    switch(ret){
57
 
    case 0:
58
 
      break;
59
 
    case 'p':
60
 
      prefix = optarg;
61
 
      break;
62
 
    default:
63
 
      fprintf(stderr, "bad arguments\n");
64
 
      exit(EXIT_FAILURE);
65
 
    }
66
 
  }
67
 
      
68
 
  if (debug){
69
 
    fprintf(stderr, "Starting %s\n", argv[0]);
70
 
  }
71
 
  if (debug){
72
 
    fprintf(stderr, "Storing current terminal attributes\n");
73
 
  }
74
37
  
75
38
  if (tcgetattr(STDIN_FILENO, &t_old) != 0){
76
39
    return EXIT_FAILURE;
93
56
  sigaction(SIGTERM, NULL, &old_action);
94
57
  if (old_action.sa_handler != SIG_IGN)
95
58
    sigaction(SIGTERM, &new_action, NULL);
96
 
 
97
 
  
98
 
  if (debug){
99
 
    fprintf(stderr, "Removing echo flag from terminal attributes\n");
100
 
  }
101
59
  
102
60
  t_new = t_old;
103
61
  t_new.c_lflag &= ~ECHO;
105
63
    perror("tcsetattr-echo");
106
64
    return EXIT_FAILURE;
107
65
  }
108
 
 
109
 
  if (debug){
110
 
    fprintf(stderr, "Waiting for input from stdin \n");
111
 
  }
 
66
  
112
67
  while(true){
113
68
    if (quit_now){
114
69
      status = EXIT_FAILURE;
115
70
      break;
116
71
    }
117
 
 
118
 
    if(prefix){
119
 
      fprintf(stderr, "%s Password: ", prefix);
120
 
    } else {
121
 
      fprintf(stderr, "Password: ");
122
 
    }      
 
72
    fprintf(stderr, "Password: ");
123
73
    ret = getline(&buffer, &n, stdin);
124
74
    if (ret > 0){
125
75
      fprintf(stdout, "%s", buffer);
137
87
    fputc('\n', stderr);
138
88
  }
139
89
 
140
 
  if (debug){
141
 
    fprintf(stderr, "Restoring terminal attributes\n");
142
 
  }
143
90
  if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &t_old) != 0){
144
91
    perror("tcsetattr+echo");
145
92
  }
146
 
 
147
 
  if (debug){
148
 
    fprintf(stderr, "%s is exiting\n", argv[0]);
149
 
  }
150
93
  
151
94
  return status;
152
95
}