/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

* debian/mandos-client.postinst: Converted to Bourne shell.  Also
                                 minor message change.
* debian/mandos-client.postrm: Minor message change.
* debian/mandos.postinst: Converted to Bourne shell.  Also minor
                          message change.
* debian/mandos.prerm: Minor message change.

Show diffs side-by-side

added added

removed removed

Lines of Context:
89
89
  size_t buffer_size;
90
90
  size_t buffer_length;
91
91
  bool eof;
92
 
  volatile sig_atomic_t completed;
93
 
  int status;
 
92
  volatile bool completed;
 
93
  volatile int status;
94
94
  struct plugin *next;
95
95
} plugin;
96
96
 
120
120
    }
121
121
  }
122
122
  
123
 
  *new_plugin = (plugin){ .name = copy_name,
124
 
                          .argc = 1,
125
 
                          .disabled = false,
126
 
                          .next = plugin_list };
 
123
  *new_plugin = (plugin) { .name = copy_name,
 
124
                           .argc = 1,
 
125
                           .disabled = false,
 
126
                           .next = plugin_list };
127
127
  
128
128
  new_plugin->argv = malloc(sizeof(char *) * 2);
129
129
  if(new_plugin->argv == NULL){
223
223
/* Mark processes as completed when they exit, and save their exit
224
224
   status. */
225
225
static void handle_sigchld(__attribute__((unused)) int sig){
226
 
  int old_errno = errno;
227
226
  while(true){
228
227
    plugin *proc = plugin_list;
229
228
    int status;
233
232
      break;
234
233
    }
235
234
    if(pid == -1){
236
 
      if(errno == ECHILD){
237
 
        /* No child processes */
238
 
        break;
 
235
      if(errno != ECHILD){
 
236
        perror("waitpid");
239
237
      }
240
 
      perror("waitpid");
 
238
      /* No child processes */
 
239
      break;
241
240
    }
242
241
    
243
242
    /* A child exited, find it in process_list */
249
248
      continue;
250
249
    }
251
250
    proc->status = status;
252
 
    proc->completed = 1;
 
251
    proc->completed = true;
253
252
  }
254
 
  errno = old_errno;
255
253
}
256
254
 
257
255
/* Prints out a password to stdout */
378
376
  };
379
377
  
380
378
  error_t parse_opt(int key, char *arg, __attribute__((unused))
381
 
                    struct argp_state *state){
382
 
    switch(key){
 
379
                    struct argp_state *state) {
 
380
    switch(key) {
383
381
    case 'g':                   /* --global-options */
384
382
      if(arg != NULL){
385
 
        char *plugin_option;
386
 
        while((plugin_option = strsep(&arg, ",")) != NULL){
387
 
          if(plugin_option[0] == '\0'){
 
383
        char *p;
 
384
        while((p = strsep(&arg, ",")) != NULL){
 
385
          if(p[0] == '\0'){
388
386
            continue;
389
387
          }
390
 
          if(not add_argument(getplugin(NULL), plugin_option)){
 
388
          if(not add_argument(getplugin(NULL), p)){
391
389
            perror("add_argument");
392
390
            return ARGP_ERR_UNKNOWN;
393
391
          }
404
402
      break;
405
403
    case 'o':                   /* --options-for */
406
404
      if(arg != NULL){
407
 
        char *plugin_name = strsep(&arg, ":");
408
 
        if(plugin_name[0] == '\0'){
409
 
          break;
410
 
        }
411
 
        char *plugin_option;
412
 
        while((plugin_option = strsep(&arg, ",")) != NULL){
413
 
          if(not add_argument(getplugin(plugin_name), plugin_option)){
 
405
        char *p_name = strsep(&arg, ":");
 
406
        if(p_name[0] == '\0' or arg == NULL){
 
407
          break;
 
408
        }
 
409
        char *opt = strsep(&arg, ":");
 
410
        if(opt[0] == '\0' or opt == NULL){
 
411
          break;
 
412
        }
 
413
        char *p;
 
414
        while((p = strsep(&opt, ",")) != NULL){
 
415
          if(p[0] == '\0'){
 
416
            continue;
 
417
          }
 
418
          if(not add_argument(getplugin(p_name), p)){
414
419
            perror("add_argument");
415
420
            return ARGP_ERR_UNKNOWN;
416
421
          }
507
512
     ignores everything but the --config-file option. */
508
513
  error_t parse_opt_config_file(int key, char *arg,
509
514
                                __attribute__((unused))
510
 
                                struct argp_state *state){
511
 
    switch(key){
 
515
                                struct argp_state *state) {
 
516
    switch(key) {
512
517
    case 'g':                   /* --global-options */
513
518
    case 'G':                   /* --global-env */
514
519
    case 'o':                   /* --options-for */
657
662
  }
658
663
  
659
664
  /* Strip permissions down to nobody */
 
665
  ret = setuid(uid);
 
666
  if(ret == -1){
 
667
    perror("setuid");
 
668
  }  
660
669
  setgid(gid);
661
670
  if(ret == -1){
662
671
    perror("setgid");
663
672
  }
664
 
  ret = setuid(uid);
665
 
  if(ret == -1){
666
 
    perror("setuid");
667
 
  }
668
673
  
669
674
  if(plugindir == NULL){
670
675
    dir = opendir(PDIR);
929
934
  
930
935
  closedir(dir);
931
936
  dir = NULL;
932
 
  free_plugin(getplugin(NULL));
933
937
  
934
938
  for(plugin *p = plugin_list; p != NULL; p = p->next){
935
939
    if(p->pid != 0){
955
959
       from one of them */
956
960
    for(plugin *proc = plugin_list; proc != NULL;){
957
961
      /* Is this process completely done? */
958
 
      if(proc->completed and proc->eof){
 
962
      if(proc->eof and proc->completed){
959
963
        /* Only accept the plugin output if it exited cleanly */
960
964
        if(not WIFEXITED(proc->status)
961
965
           or WEXITSTATUS(proc->status) != 0){
963
967
 
964
968
          if(debug){
965
969
            if(WIFEXITED(proc->status)){
966
 
              fprintf(stderr, "Plugin %s [%" PRIdMAX "] exited with"
967
 
                      " status %d\n", proc->name,
968
 
                      (intmax_t) (proc->pid),
 
970
              fprintf(stderr, "Plugin %" PRIdMAX " exited with status"
 
971
                      " %d\n", (intmax_t) (proc->pid),
969
972
                      WEXITSTATUS(proc->status));
970
 
            } else if(WIFSIGNALED(proc->status)){
971
 
              fprintf(stderr, "Plugin %s [%" PRIdMAX "] killed by"
972
 
                      " signal %d\n", proc->name,
973
 
                      (intmax_t) (proc->pid),
 
973
            } else if(WIFSIGNALED(proc->status)) {
 
974
              fprintf(stderr, "Plugin %" PRIdMAX " killed by signal"
 
975
                      " %d\n", (intmax_t) (proc->pid),
974
976
                      WTERMSIG(proc->status));
975
977
            } else if(WCOREDUMP(proc->status)){
976
 
              fprintf(stderr, "Plugin %s [%" PRIdMAX "] dumped"
977
 
                      " core\n", proc->name, (intmax_t) (proc->pid));
 
978
              fprintf(stderr, "Plugin %" PRIdMAX " dumped core\n",
 
979
                      (intmax_t) (proc->pid));
978
980
            }
979
981
          }
980
982