/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 04:42:08 UTC
  • mfrom: (15.1.3 mandos)
  • Revision ID: teddy@fukt.bsnet.se-20080721044208-y8v1sjmvalfiehrv
Merge.

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 */
 
14
#include <stdlib.h>             /* EXIT_SUCCESS, EXIT_FAILURE,
 
15
                                   getopt_long */
15
16
#include <stdio.h>              /* fprintf(), stderr, getline(),
16
17
                                   stdin, feof(), perror(), fputc(),
17
 
                                   stdout */
 
18
                                   stdout, getopt_long */
18
19
#include <errno.h>              /* errno, EINVAL */
19
20
#include <iso646.h>             /* or, not */
20
21
#include <stdbool.h>            /* bool, false, true */
21
22
#include <string.h>             /* strlen, rindex, strncmp, strcmp */
 
23
#include <getopt.h>             /* getopt_long */
22
24
 
23
25
volatile bool quit_now = false;
24
26
bool debug = false;
28
30
}
29
31
 
30
32
int main(int argc, char **argv){
31
 
  ssize_t ret = -1;
 
33
  ssize_t ret;
32
34
  size_t n;
33
35
  struct termios t_new, t_old;
34
36
  char *buffer = NULL;
 
37
  char *prefix = NULL;
35
38
  int status = EXIT_SUCCESS;
36
39
  struct sigaction old_action,
37
40
    new_action = { .sa_handler = termination_handler,
38
41
                   .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
 
 
 
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
      
65
68
  if (debug){
66
69
    fprintf(stderr, "Starting %s\n", argv[0]);
67
70
  }
111
114
      status = EXIT_FAILURE;
112
115
      break;
113
116
    }
114
 
    fprintf(stderr, "Password: ");
 
117
 
 
118
    if(prefix){
 
119
      fprintf(stderr, "%s Password: ", prefix);
 
120
    } else {
 
121
      fprintf(stderr, "Password: ");
 
122
    }      
115
123
    ret = getline(&buffer, &n, stdin);
116
124
    if (ret > 0){
117
125
      fprintf(stdout, "%s", buffer);