/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-09-07 01:44:44 UTC
  • mfrom: (24.1.93 mandos)
  • Revision ID: teddy@fukt.bsnet.se-20080907014444-cf4ilzndc0tbn8va
Merge & resolve.

Show diffs side-by-side

added added

removed removed

Lines of Context:
255
255
/* Prints out a password to stdout */
256
256
bool print_out_password(const char *buffer, size_t length){
257
257
  ssize_t ret;
258
 
  if(length>0 and buffer[length-1] == '\n'){
259
 
    length--;
260
 
  }
261
258
  for(size_t written = 0; written < length; written += (size_t)ret){
262
259
    ret = TEMP_FAILURE_RETRY(write(STDOUT_FILENO, buffer + written,
263
260
                                   length - written));
397
394
      if(arg == NULL){
398
395
        break;
399
396
      }
400
 
      {
401
 
        char *envdef = strdup(arg);
402
 
        if(envdef == NULL){
403
 
          break;
404
 
        }
405
 
        if(not add_environment(getplugin(NULL), envdef, true)){
406
 
          perror("add_environment");
407
 
        }
 
397
      if(not add_environment(getplugin(NULL), arg, true)){
 
398
        perror("add_environment");
408
399
      }
409
400
      break;
410
401
    case 'o':                   /* --options-for */
438
429
        if(envdef == NULL){
439
430
          break;
440
431
        }
441
 
        char *p_name = strndup(arg, (size_t) (envdef-arg));
442
 
        if(p_name == NULL){
443
 
          break;
444
 
        }
445
 
        envdef++;
446
 
        if(not add_environment(getplugin(p_name), envdef, true)){
 
432
        *envdef = '\0';
 
433
        if(not add_environment(getplugin(arg), envdef+1, true)){
447
434
          perror("add_environment");
448
435
        }
449
436
      }
467
454
      }
468
455
      break;
469
456
    case 128:                   /* --plugin-dir */
 
457
      free(plugindir);
470
458
      plugindir = strdup(arg);
471
459
      if(plugindir == NULL){
472
460
        perror("strdup");
510
498
    case 128:                   /* --plugin-dir */
511
499
      break;
512
500
    case 129:                   /* --config-file */
 
501
      free(argfile);
513
502
      argfile = strdup(arg);
514
503
      if(argfile == NULL){
515
504
        perror("strdup");
745
734
    }
746
735
 
747
736
    char *filename;
748
 
    ret = asprintf(&filename, "%s/%s", plugindir, dirst->d_name);
 
737
    if(plugindir == NULL){
 
738
      ret = asprintf(&filename, PDIR "/%s", dirst->d_name);
 
739
    } else {
 
740
      ret = asprintf(&filename, "%s/%s", plugindir, dirst->d_name);
 
741
    }
749
742
    if(ret < 0){
750
743
      perror("asprintf");
751
744
      continue;
940
933
    }
941
934
    /* OK, now either a process completed, or something can be read
942
935
       from one of them */
943
 
    for(plugin *proc = plugin_list; proc != NULL; proc = proc->next){
 
936
    for(plugin *proc = plugin_list; proc != NULL;){
944
937
      /* Is this process completely done? */
945
938
      if(proc->eof and proc->completed){
946
939
        /* Only accept the plugin output if it exited cleanly */
973
966
            exitstatus = EXIT_FAILURE;
974
967
            goto fallback;
975
968
          }
976
 
          free_plugin(proc);
 
969
          
977
970
          /* We are done modifying process list, so unblock signal */
978
971
          ret = sigprocmask (SIG_UNBLOCK, &sigchld_action.sa_mask,
979
972
                             NULL);
986
979
          if(plugin_list == NULL){
987
980
            break;
988
981
          }
 
982
          
 
983
          plugin *next_plugin = proc->next;
 
984
          free_plugin(proc);
 
985
          proc = next_plugin;
989
986
          continue;
990
987
        }
991
988
        
1003
1000
      /* This process has not completed.  Does it have any output? */
1004
1001
      if(proc->eof or not FD_ISSET(proc->fd, &rfds)){
1005
1002
        /* This process had nothing to say at this time */
 
1003
        proc = proc->next;
1006
1004
        continue;
1007
1005
      }
1008
1006
      /* Before reading, make the process' data buffer large enough */
1021
1019
                 BUFFER_SIZE);
1022
1020
      if(ret < 0){
1023
1021
        /* Read error from this process; ignore the error */
 
1022
        proc = proc->next;
1024
1023
        continue;
1025
1024
      }
1026
1025
      if(ret == 0){
1041
1040
    bool bret;
1042
1041
    fprintf(stderr, "Going to fallback mode using getpass(3)\n");
1043
1042
    char *passwordbuffer = getpass("Password: ");
1044
 
    bret = print_out_password(passwordbuffer, strlen(passwordbuffer));
 
1043
    size_t len = strlen(passwordbuffer);
 
1044
    /* Strip trailing newline */
 
1045
    if(len > 0 and passwordbuffer[len-1] == '\n'){
 
1046
      passwordbuffer[len-1] = '\0'; /* not strictly necessary */
 
1047
      len--;
 
1048
    }
 
1049
    bret = print_out_password(passwordbuffer, len);
1045
1050
    if(not bret){
1046
1051
      perror("print_out_password");
1047
1052
      exitstatus = EXIT_FAILURE;