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

Added fallback to mandos-client

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;
654
666
          break;
655
667
        }
656
668
        /* This process exited nicely, so print its buffer */
657
 
        for(size_t written = 0; written < proc->buffer_length;
658
 
            written += (size_t)ret){
659
 
          ret = TEMP_FAILURE_RETRY(write(STDOUT_FILENO,
660
 
                                         proc->buffer + written,
661
 
                                         proc->buffer_length
662
 
                                         - written));
663
 
          if(ret < 0){
664
 
            perror("write");
665
 
            exitstatus = EXIT_FAILURE;
666
 
            goto end;
667
 
          }
 
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;
668
674
        }
669
675
        goto end;
670
676
      }
699
705
      }
700
706
    }
701
707
  }
 
708
  
702
709
  if(process_list == NULL){
703
 
    fprintf(stderr, "All plugin processes failed, exiting\n");
704
 
    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
    }
705
724
  }
706
 
  
 
725
 
707
726
 end:
 
727
  
708
728
  /* Restore old signal handler */
709
729
  sigaction(SIGCHLD, &old_sigchld_action, NULL);
710
730