/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 mandos-client.c

  • Committer: Teddy Hogeborn
  • Date: 2008-08-10 20:35:01 UTC
  • mfrom: (24.1.42 mandos)
  • Revision ID: teddy@fukt.bsnet.se-20080810203501-euh3qcf1nopilksm
Merge.

Show diffs side-by-side

added added

removed removed

Lines of Context:
170
170
  proc->completed = true;
171
171
}
172
172
 
 
173
bool print_out_password(const char *buffer, size_t length){
 
174
  size_t ret;
 
175
  for(size_t written = 0; written < length; written += ret){
 
176
    ret = TEMP_FAILURE_RETRY(write(STDOUT_FILENO, buffer + written,
 
177
                                   length - written));
 
178
    if(ret < 0){
 
179
      return false;
 
180
    }
 
181
  }
 
182
  return true;
 
183
}
 
184
 
173
185
int main(int argc, char *argv[]){
174
186
  const char *plugindir = "/conf/conf.d/mandos/plugins.d";
175
187
  size_t d_name_len;
583
595
  dir = NULL;
584
596
    
585
597
  if (process_list == NULL){
586
 
    fprintf(stderr, "No plugin processes started, exiting\n");
587
 
    exitstatus = EXIT_FAILURE;
588
 
    goto end;
 
598
    fprintf(stderr, "No plugin processes started. Incorrect plugin"
 
599
            " directory?\n");
 
600
    process_list = NULL;
589
601
  }
590
602
  while(process_list){
591
603
    fd_set rfds = rfds_all;
606
618
          /* Bad exit by plugin */
607
619
          if(debug){
608
620
            if(WIFEXITED(proc->status)){
609
 
              fprintf(stderr, "Plugin %d exited with status %d\n",
610
 
                      proc->pid, WEXITSTATUS(proc->status));
 
621
              fprintf(stderr, "Plugin %u exited with status %d\n",
 
622
                      (unsigned int) (proc->pid),
 
623
                      WEXITSTATUS(proc->status));
611
624
            } else if(WIFSIGNALED(proc->status)) {
612
 
              fprintf(stderr, "Plugin %d killed by signal %d\n",
613
 
                      proc->pid, WTERMSIG(proc->status));
 
625
              fprintf(stderr, "Plugin %u killed by signal %d\n",
 
626
                      (unsigned int) (proc->pid),
 
627
                      WTERMSIG(proc->status));
614
628
            } else if(WCOREDUMP(proc->status)){
615
 
              fprintf(stderr, "Plugin %d dumped core\n", proc->pid);
 
629
              fprintf(stderr, "Plugin %d dumped core\n",
 
630
                      (unsigned int) (proc->pid));
616
631
            }
617
632
          }
618
633
          /* Remove the plugin */
651
666
          break;
652
667
        }
653
668
        /* This process exited nicely, so print its buffer */
654
 
        for(size_t written = 0; written < proc->buffer_length;
655
 
            written += (size_t)ret){
656
 
          ret = TEMP_FAILURE_RETRY(write(STDOUT_FILENO,
657
 
                                         proc->buffer + written,
658
 
                                         proc->buffer_length
659
 
                                         - written));
660
 
          if(ret < 0){
661
 
            perror("write");
662
 
            exitstatus = EXIT_FAILURE;
663
 
            goto end;
664
 
          }
 
669
 
 
670
        bool bret = print_out_password(proc->buffer, proc->buffer_length);
 
671
        if(not bret){
 
672
          perror("print_out_password");
 
673
          exitstatus = EXIT_FAILURE;
665
674
        }
666
675
        goto end;
667
676
      }
696
705
      }
697
706
    }
698
707
  }
 
708
  
699
709
  if(process_list == NULL){
700
 
    fprintf(stderr, "All plugin processes failed, exiting\n");
701
 
    exitstatus = EXIT_FAILURE;
 
710
    bool bret;
 
711
    fprintf(stderr, "Going to fallback mode using getpass(3)\n");
 
712
    char *passwordbuffer = getpass("Password: ");
 
713
    bret = print_out_password(passwordbuffer, strlen(passwordbuffer));
 
714
    if(not bret){
 
715
      perror("print_out_password");
 
716
      exitstatus = EXIT_FAILURE;
 
717
      goto end;
 
718
    }
 
719
    bret = print_out_password("\n", 1);
 
720
    if(not bret){
 
721
      perror("print_out_password");
 
722
      exitstatus = EXIT_FAILURE;
 
723
    }
702
724
  }
703
 
  
 
725
 
704
726
 end:
 
727
  
705
728
  /* Restore old signal handler */
706
729
  sigaction(SIGCHLD, &old_sigchld_action, NULL);
707
730