/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-08 12:03:16 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080908120316-rrt6r0a5yezc3q1d
* INSTALL: New file.

* mandos-keygen: Use "/etc/mandos/keys" if "/etc/keys/mandos" does not
                 exist.

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");
485
473
      debug = true;
486
474
      break;
487
475
    case ARGP_KEY_ARG:
488
 
      fprintf(stderr, "Ignoring unknown argument \"%s\"\n", 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
      }
489
482
      break;
490
483
    case ARGP_KEY_END:
491
484
      break;
510
503
    case 128:                   /* --plugin-dir */
511
504
      break;
512
505
    case 129:                   /* --config-file */
 
506
      free(argfile);
513
507
      argfile = strdup(arg);
514
508
      if(argfile == NULL){
515
509
        perror("strdup");
745
739
    }
746
740
 
747
741
    char *filename;
748
 
    ret = asprintf(&filename, "%s/%s", plugindir, dirst->d_name);
 
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
    }
749
747
    if(ret < 0){
750
748
      perror("asprintf");
751
749
      continue;
940
938
    }
941
939
    /* OK, now either a process completed, or something can be read
942
940
       from one of them */
943
 
    for(plugin *proc = plugin_list; proc != NULL; proc = proc->next){
 
941
    for(plugin *proc = plugin_list; proc != NULL;){
944
942
      /* Is this process completely done? */
945
943
      if(proc->eof and proc->completed){
946
944
        /* Only accept the plugin output if it exited cleanly */
973
971
            exitstatus = EXIT_FAILURE;
974
972
            goto fallback;
975
973
          }
976
 
          free_plugin(proc);
 
974
          
977
975
          /* We are done modifying process list, so unblock signal */
978
976
          ret = sigprocmask (SIG_UNBLOCK, &sigchld_action.sa_mask,
979
977
                             NULL);
986
984
          if(plugin_list == NULL){
987
985
            break;
988
986
          }
 
987
          
 
988
          plugin *next_plugin = proc->next;
 
989
          free_plugin(proc);
 
990
          proc = next_plugin;
989
991
          continue;
990
992
        }
991
993
        
1003
1005
      /* This process has not completed.  Does it have any output? */
1004
1006
      if(proc->eof or not FD_ISSET(proc->fd, &rfds)){
1005
1007
        /* This process had nothing to say at this time */
 
1008
        proc = proc->next;
1006
1009
        continue;
1007
1010
      }
1008
1011
      /* Before reading, make the process' data buffer large enough */
1021
1024
                 BUFFER_SIZE);
1022
1025
      if(ret < 0){
1023
1026
        /* Read error from this process; ignore the error */
 
1027
        proc = proc->next;
1024
1028
        continue;
1025
1029
      }
1026
1030
      if(ret == 0){
1041
1045
    bool bret;
1042
1046
    fprintf(stderr, "Going to fallback mode using getpass(3)\n");
1043
1047
    char *passwordbuffer = getpass("Password: ");
1044
 
    bret = print_out_password(passwordbuffer, strlen(passwordbuffer));
 
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);
1045
1055
    if(not bret){
1046
1056
      perror("print_out_password");
1047
1057
      exitstatus = EXIT_FAILURE;