/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

  • Committer: Teddy Hogeborn
  • Date: 2008-08-10 16:13:23 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080810161323-wrh1rbpdrq0otuhf
* mandos (console): Define handler globally.
  (main): If in debug mode, also reduce consol log level.  Remove
          console log handler before daemonizing.

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
 
  ssize_t ret;
175
 
  if(length>0 and buffer[length-1] == '\n'){
176
 
    length--;
177
 
  }
178
 
  for(size_t written = 0; written < length; written += (size_t)ret){
179
 
    ret = TEMP_FAILURE_RETRY(write(STDOUT_FILENO, buffer + written,
180
 
                                   length - written));
181
 
    if(ret < 0){
182
 
      return false;
183
 
    }
184
 
  }
185
 
  return true;
186
 
}
187
 
 
188
173
int main(int argc, char *argv[]){
189
174
  const char *plugindir = "/conf/conf.d/mandos/plugins.d";
190
175
  size_t d_name_len;
307
292
  
308
293
  ret = argp_parse (&argp, argc, argv, 0, 0, &plugin_list);
309
294
  if (ret == ARGP_ERR_UNKNOWN){
310
 
    fprintf(stderr, "Unknown error while parsing arguments\n");
 
295
    fprintf(stderr, "Unkown error while parsing arguments\n");
311
296
    exitstatus = EXIT_FAILURE;
312
297
    goto end;
313
298
  }
344
329
    }
345
330
    ret = argp_parse (&argp, new_argc, plus_argv, 0, 0, &plugin_list);
346
331
    if (ret == ARGP_ERR_UNKNOWN){
347
 
      fprintf(stderr, "Unknown error while parsing arguments\n");
 
332
      fprintf(stderr, "Unkown error while parsing arguments\n");
348
333
      exitstatus = EXIT_FAILURE;
349
334
      goto end;
350
335
    }
598
583
  dir = NULL;
599
584
    
600
585
  if (process_list == NULL){
601
 
    fprintf(stderr, "No plugin processes started. Incorrect plugin"
602
 
            " directory?\n");
603
 
    process_list = NULL;
 
586
    fprintf(stderr, "No plugin processes started, exiting\n");
 
587
    exitstatus = EXIT_FAILURE;
 
588
    goto end;
604
589
  }
605
590
  while(process_list){
606
591
    fd_set rfds = rfds_all;
669
654
          break;
670
655
        }
671
656
        /* This process exited nicely, so print its buffer */
672
 
 
673
 
        bool bret = print_out_password(proc->buffer, proc->buffer_length);
674
 
        if(not bret){
675
 
          perror("print_out_password");
676
 
          exitstatus = EXIT_FAILURE;
 
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
          }
677
668
        }
678
669
        goto end;
679
670
      }
708
699
      }
709
700
    }
710
701
  }
711
 
  
712
702
  if(process_list == NULL){
713
 
    bool bret;
714
 
    fprintf(stderr, "Going to fallback mode using getpass(3)\n");
715
 
    char *passwordbuffer = getpass("Password: ");
716
 
    bret = print_out_password(passwordbuffer, strlen(passwordbuffer));
717
 
    if(not bret){
718
 
      perror("print_out_password");
719
 
      exitstatus = EXIT_FAILURE;
720
 
      goto end;
721
 
    }
 
703
    fprintf(stderr, "All plugin processes failed, exiting\n");
 
704
    exitstatus = EXIT_FAILURE;
722
705
  }
723
 
 
 
706
  
724
707
 end:
725
 
  
726
708
  /* Restore old signal handler */
727
709
  sigaction(SIGCHLD, &old_sigchld_action, NULL);
728
710