/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/password-prompt.c

  • Committer: Teddy Hogeborn
  • Date: 2009-01-13 04:35:19 UTC
  • Revision ID: teddy@fukt.bsnet.se-20090113043519-0yr39snphoegq8l1
* plugin-runner.c: Only space changes.
* plugins.d/mandos-client.c: - '' -
* plugins.d/password-prompt.c: - '' -

Show diffs side-by-side

added added

removed removed

Lines of Context:
89
89
        debug = true;
90
90
        break;
91
91
      case ARGP_KEY_ARG:
92
 
        argp_usage (state);
 
92
        argp_usage(state);
93
93
        break;
94
94
      case ARGP_KEY_END:
95
95
        break;
103
103
                         .args_doc = "",
104
104
                         .doc = "Mandos password-prompt -- Read and"
105
105
                         " output a password" };
106
 
    ret = argp_parse (&argp, argc, argv, 0, 0, NULL);
107
 
    if (ret == ARGP_ERR_UNKNOWN){
 
106
    ret = argp_parse(&argp, argc, argv, 0, 0, NULL);
 
107
    if(ret == ARGP_ERR_UNKNOWN){
108
108
      fprintf(stderr, "Unknown error while parsing arguments\n");
109
109
      return EXIT_FAILURE;
110
110
    }
111
111
  }
112
112
  
113
 
  if (debug){
 
113
  if(debug){
114
114
    fprintf(stderr, "Starting %s\n", argv[0]);
115
115
  }
116
 
  if (debug){
 
116
  if(debug){
117
117
    fprintf(stderr, "Storing current terminal attributes\n");
118
118
  }
119
119
  
120
 
  if (tcgetattr(STDIN_FILENO, &t_old) != 0){
 
120
  if(tcgetattr(STDIN_FILENO, &t_old) != 0){
121
121
    perror("tcgetattr");
122
122
    return EXIT_FAILURE;
123
123
  }
131
131
    perror("sigaction");
132
132
    return EXIT_FAILURE;
133
133
  }
134
 
  if (old_action.sa_handler != SIG_IGN){
 
134
  if(old_action.sa_handler != SIG_IGN){
135
135
    ret = sigaction(SIGINT, &new_action, NULL);
136
136
    if(ret == -1){
137
137
      perror("sigaction");
143
143
    perror("sigaction");
144
144
    return EXIT_FAILURE;
145
145
  }
146
 
  if (old_action.sa_handler != SIG_IGN){
 
146
  if(old_action.sa_handler != SIG_IGN){
147
147
    ret = sigaction(SIGHUP, &new_action, NULL);
148
148
    if(ret == -1){
149
149
      perror("sigaction");
155
155
    perror("sigaction");
156
156
    return EXIT_FAILURE;
157
157
  }
158
 
  if (old_action.sa_handler != SIG_IGN){
 
158
  if(old_action.sa_handler != SIG_IGN){
159
159
    ret = sigaction(SIGTERM, &new_action, NULL);
160
160
    if(ret == -1){
161
161
      perror("sigaction");
164
164
  }
165
165
  
166
166
  
167
 
  if (debug){
 
167
  if(debug){
168
168
    fprintf(stderr, "Removing echo flag from terminal attributes\n");
169
169
  }
170
170
  
171
171
  t_new = t_old;
172
172
  t_new.c_lflag &= ~ECHO;
173
 
  if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &t_new) != 0){
 
173
  if(tcsetattr(STDIN_FILENO, TCSAFLUSH, &t_new) != 0){
174
174
    perror("tcsetattr-echo");
175
175
    return EXIT_FAILURE;
176
176
  }
177
177
 
178
 
  if (debug){
 
178
  if(debug){
179
179
    fprintf(stderr, "Waiting for input from stdin \n");
180
180
  }
181
181
  while(true){
182
 
    if (quit_now){
 
182
    if(quit_now){
183
183
      if(debug){
184
184
        fprintf(stderr, "Interrupted by signal, exiting.\n");
185
185
      }
211
211
      }
212
212
    }
213
213
    ret = getline(&buffer, &n, stdin);
214
 
    if (ret > 0){
 
214
    if(ret > 0){
215
215
      status = EXIT_SUCCESS;
216
216
      /* Make n = data size instead of allocated buffer size */
217
217
      n = (size_t)ret;
232
232
      }
233
233
      break;
234
234
    }
235
 
    if (ret < 0){
236
 
      if (errno != EINTR and not feof(stdin)){
 
235
    if(ret < 0){
 
236
      if(errno != EINTR and not feof(stdin)){
237
237
        perror("getline");
238
238
        status = EXIT_FAILURE;
239
239
        break;
251
251
  
252
252
  free(buffer);
253
253
  
254
 
  if (debug){
 
254
  if(debug){
255
255
    fprintf(stderr, "Restoring terminal attributes\n");
256
256
  }
257
 
  if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &t_old) != 0){
 
257
  if(tcsetattr(STDIN_FILENO, TCSAFLUSH, &t_old) != 0){
258
258
    perror("tcsetattr+echo");
259
259
  }
260
260
  
261
 
  if (debug){
 
261
  if(debug){
262
262
    fprintf(stderr, "%s is exiting with status %d\n", argv[0],
263
263
            status);
264
264
  }