/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 plugin-runner.c

  • Committer: Teddy Hogeborn
  • Date: 2008-09-05 18:19:52 UTC
  • mfrom: (24.1.91 mandos)
  • Revision ID: teddy@fukt.bsnet.se-20080905181952-qfuwtyvefanh9v3v
* mandos: Open the PID file before daemonizing, but write to it
          afterwards.

* plugin-runner.xml (SECURITY): Improved grammar.

Also merge.

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
 
      if(not add_environment(getplugin(NULL), arg, true)){
398
 
        perror("add_environment");
 
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
        }
399
408
      }
400
409
      break;
401
410
    case 'o':                   /* --options-for */
429
438
        if(envdef == NULL){
430
439
          break;
431
440
        }
432
 
        *envdef = '\0';
433
 
        if(not add_environment(getplugin(arg), envdef+1, true)){
 
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)){
434
447
          perror("add_environment");
435
448
        }
436
449
      }
454
467
      }
455
468
      break;
456
469
    case 128:                   /* --plugin-dir */
457
 
      free(plugindir);
458
470
      plugindir = strdup(arg);
459
471
      if(plugindir == NULL){
460
472
        perror("strdup");
473
485
      debug = true;
474
486
      break;
475
487
    case ARGP_KEY_ARG:
476
 
      /* Cryptsetup always passes an argument, which is an empty
477
 
         string if "none" was specified in /etc/crypttab.  So if
478
 
         argument was empty, we ignore it silently. */
479
 
      if(arg[0] != '\0'){
480
 
        fprintf(stderr, "Ignoring unknown argument \"%s\"\n", arg);
481
 
      }
 
488
      fprintf(stderr, "Ignoring unknown argument \"%s\"\n", arg);
482
489
      break;
483
490
    case ARGP_KEY_END:
484
491
      break;
503
510
    case 128:                   /* --plugin-dir */
504
511
      break;
505
512
    case 129:                   /* --config-file */
506
 
      free(argfile);
507
513
      argfile = strdup(arg);
508
514
      if(argfile == NULL){
509
515
        perror("strdup");
739
745
    }
740
746
 
741
747
    char *filename;
742
 
    if(plugindir == NULL){
743
 
      ret = asprintf(&filename, PDIR "/%s", dirst->d_name);
744
 
    } else {
745
 
      ret = asprintf(&filename, "%s/%s", plugindir, dirst->d_name);
746
 
    }
 
748
    ret = asprintf(&filename, "%s/%s", plugindir, dirst->d_name);
747
749
    if(ret < 0){
748
750
      perror("asprintf");
749
751
      continue;
938
940
    }
939
941
    /* OK, now either a process completed, or something can be read
940
942
       from one of them */
941
 
    for(plugin *proc = plugin_list; proc != NULL;){
 
943
    for(plugin *proc = plugin_list; proc != NULL; proc = proc->next){
942
944
      /* Is this process completely done? */
943
945
      if(proc->eof and proc->completed){
944
946
        /* Only accept the plugin output if it exited cleanly */
971
973
            exitstatus = EXIT_FAILURE;
972
974
            goto fallback;
973
975
          }
974
 
          
 
976
          free_plugin(proc);
975
977
          /* We are done modifying process list, so unblock signal */
976
978
          ret = sigprocmask (SIG_UNBLOCK, &sigchld_action.sa_mask,
977
979
                             NULL);
984
986
          if(plugin_list == NULL){
985
987
            break;
986
988
          }
987
 
          
988
 
          plugin *next_plugin = proc->next;
989
 
          free_plugin(proc);
990
 
          proc = next_plugin;
991
989
          continue;
992
990
        }
993
991
        
1005
1003
      /* This process has not completed.  Does it have any output? */
1006
1004
      if(proc->eof or not FD_ISSET(proc->fd, &rfds)){
1007
1005
        /* This process had nothing to say at this time */
1008
 
        proc = proc->next;
1009
1006
        continue;
1010
1007
      }
1011
1008
      /* Before reading, make the process' data buffer large enough */
1024
1021
                 BUFFER_SIZE);
1025
1022
      if(ret < 0){
1026
1023
        /* Read error from this process; ignore the error */
1027
 
        proc = proc->next;
1028
1024
        continue;
1029
1025
      }
1030
1026
      if(ret == 0){
1045
1041
    bool bret;
1046
1042
    fprintf(stderr, "Going to fallback mode using getpass(3)\n");
1047
1043
    char *passwordbuffer = getpass("Password: ");
1048
 
    size_t len = strlen(passwordbuffer);
1049
 
    /* Strip trailing newline */
1050
 
    if(len > 0 and passwordbuffer[len-1] == '\n'){
1051
 
      passwordbuffer[len-1] = '\0'; /* not strictly necessary */
1052
 
      len--;
1053
 
    }
1054
 
    bret = print_out_password(passwordbuffer, len);
 
1044
    bret = print_out_password(passwordbuffer, strlen(passwordbuffer));
1055
1045
    if(not bret){
1056
1046
      perror("print_out_password");
1057
1047
      exitstatus = EXIT_FAILURE;