/mandos/release

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/release

« back to all changes in this revision

Viewing changes to plugin-runner.c

  • Committer: Teddy Hogeborn
  • Date: 2008-08-24 10:52:46 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080824105246-4gu1o1q6sdjvqcyb
* mandos (fingerprint): Bug fix: Remove some temporary debugging code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
#include <argp.h>               /* struct argp_option, struct
57
57
                                   argp_state, struct argp,
58
58
                                   argp_parse(), ARGP_ERR_UNKNOWN,
59
 
                                   ARGP_KEY_END, ARGP_KEY_ARG,
60
 
                                   error_t */
 
59
                                   ARGP_KEY_END, ARGP_KEY_ARG, error_t */
61
60
#include <signal.h>             /* struct sigaction, sigemptyset(),
62
61
                                   sigaddset(), sigaction(),
63
62
                                   sigprocmask(), SIG_BLOCK, SIGCHLD,
79
78
  size_t buffer_size;
80
79
  size_t buffer_length;
81
80
  bool eof;
82
 
  volatile bool completed;
83
 
  volatile int status;
 
81
  bool completed;
 
82
  int status;
84
83
  struct process *next;
85
84
} process;
86
85
 
200
199
 
201
200
process *process_list = NULL;
202
201
 
203
 
/* Mark processes as completed when they exit, and save their exit
 
202
/* Mark a process as completed when it exits, and save its exit
204
203
   status. */
205
204
void handle_sigchld(__attribute__((unused)) int sig){
206
 
  while(true){
207
 
    process *proc = process_list;
208
 
    int status;
209
 
    pid_t pid = waitpid(-1, &status, WNOHANG);
210
 
    if(pid == 0){
211
 
      /* Only still running child processes */
212
 
      break;
213
 
    }
214
 
    if(pid == -1){
215
 
      if (errno != ECHILD){
216
 
        perror("waitpid");
217
 
      }
218
 
      /* No child processes */
219
 
      break;
220
 
    }
221
 
 
222
 
    /* A child exited, find it in process_list */
223
 
    while(proc != NULL and proc->pid != pid){
224
 
      proc = proc->next;
225
 
    }
226
 
    if(proc == NULL){
227
 
      /* Process not found in process list */
228
 
      continue;
229
 
    }
230
 
    proc->status = status;
231
 
    proc->completed = true;
232
 
  }
 
205
  process *proc = process_list;
 
206
  int status;
 
207
  pid_t pid = wait(&status);
 
208
  if(pid == -1){
 
209
    perror("wait");
 
210
    return;
 
211
  }
 
212
  while(proc != NULL and proc->pid != pid){
 
213
    proc = proc->next;
 
214
  }
 
215
  if(proc == NULL){
 
216
    /* Process not found in process list */
 
217
    return;
 
218
  }
 
219
  proc->status = status;
 
220
  proc->completed = true;
233
221
}
234
222
 
235
223
bool print_out_password(const char *buffer, size_t length){
254
242
    if(argv == NULL){
255
243
      return NULL;
256
244
    }
257
 
    argv[0] = NULL;     /* Will be set to argv[0] in main before
258
 
                           parsing */
 
245
    argv[0] = NULL;     /* Will be set to argv[0] in main before parsing */
259
246
    argv[1] = NULL;
260
247
  }
261
248
  *argc += 1;
514
501
 
515
502
  if(custom_argv != NULL){
516
503
    custom_argv[0] = argv[0];
517
 
    ret = argp_parse (&argp, custom_argc, custom_argv, 0, 0,
518
 
                      &plugin_list);
 
504
    ret = argp_parse (&argp, custom_argc, custom_argv, 0, 0, &plugin_list);
519
505
    if (ret == ARGP_ERR_UNKNOWN){
520
506
      fprintf(stderr, "Unknown error while parsing arguments\n");
521
507
      exitstatus = EXIT_FAILURE;
849
835
          /* Remove the plugin */
850
836
          FD_CLR(proc->fd, &rfds_all);
851
837
          /* Block signal while modifying process_list */
852
 
          ret = sigprocmask(SIG_BLOCK, &sigchld_action.sa_mask, NULL);
 
838
          ret = sigprocmask (SIG_BLOCK, &sigchld_action.sa_mask, NULL);
853
839
          if(ret < 0){
854
840
            perror("sigprocmask");
855
841
            exitstatus = EXIT_FAILURE;
883
869
        }
884
870
        /* This process exited nicely, so print its buffer */
885
871
 
886
 
        bool bret = print_out_password(proc->buffer,
887
 
                                       proc->buffer_length);
 
872
        bool bret = print_out_password(proc->buffer, proc->buffer_length);
888
873
        if(not bret){
889
874
          perror("print_out_password");
890
875
          exitstatus = EXIT_FAILURE;
927
912
 fallback:
928
913
  
929
914
  if(process_list == NULL or exitstatus != EXIT_SUCCESS){
930
 
    /* Fallback if all plugins failed, none are found or an error
931
 
       occured */
 
915
    /* Fallback if all plugins failed, none are found or an error occured */
932
916
    bool bret;
933
917
    fprintf(stderr, "Going to fallback mode using getpass(3)\n");
934
918
    char *passwordbuffer = getpass("Password: ");