/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: Björn Påhlsson
  • Date: 2008-09-05 19:30:21 UTC
  • mto: (237.7.1 mandos) (24.1.154 mandos)
  • mto: This revision was merged to the branch mainline in revision 176.
  • Revision ID: belorn@braxen-20080905193021-vie7b22ootg6r2t8
Several memory leaks detected by valgrind fixed
A bugg fixed that could cause seg fault.

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