/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-06 16:31:49 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080906163149-1ddq2klhdwwiw1ry
Renamed "password-request" to "mandos-client".

* Makefile: - '' -
* mandos-keygen.xml: - '' -
* mandos-options.xml: - '' -
* mandos.xml: - '' -
* plugin-runner.conf: - '' -
* plugin-runner.xml: - '' -
* plugins.d/password-prompt.xml: - '' -
* plugins.d/password-request.c: Renamed to "mandos-client.c".
* plugins.d/password-request.xml: Renamed to "mandos-client.xml".

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