/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-21 04:22:50 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080921042250-r0qqjsbz2ulfo5le
* Makefile: Bug fix: fix syntax error.

* debian/control: Depend on "po-debconf".
  (mandos, mandos-client): Add "${misc:Depends}", used by
                           dh_installdebconf.

* debian/mandos-client.config: New; show note.
* debian/mandos-client.template: New.

* debian/mandos.README.Debian: New.

* debian/mandos.config: New; show note.
* debian/mandos.prerm: New; stop daemon.
* debian/mandos.template: New.

* debian/po/POTFILES.in: New.
* debian/po/sv.po: New.

* debian/rules (clean): Added "debconf-updatepo" as suggested by
                        po-debconf(7).
  (binary-common): Added "dh_installdebconf" to use "debian/*.config"
                   and "debian/*.template" files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
72
72
const char *argp_program_version = "plugin-runner 1.0";
73
73
const char *argp_program_bug_address = "<mandos@fukt.bsnet.se>";
74
74
 
75
 
struct plugin;
76
 
 
77
75
typedef struct plugin{
78
76
  char *name;                   /* can be NULL or any plugin name */
79
77
  char **argv;
208
206
 * Descriptor Flags".
209
207
 * *Note File Descriptor Flags:(libc)Descriptor Flags.
210
208
 */
211
 
static int set_cloexec_flag(int fd)
212
 
{
 
209
static int set_cloexec_flag(int fd){
213
210
  int ret = fcntl(fd, F_GETFD, 0);
214
211
  /* If reading the flags failed, return error indication now. */
215
212
  if(ret < 0){
222
219
 
223
220
/* Mark processes as completed when they exit, and save their exit
224
221
   status. */
225
 
void handle_sigchld(__attribute__((unused)) int sig){
 
222
static void handle_sigchld(__attribute__((unused)) int sig){
226
223
  while(true){
227
224
    plugin *proc = plugin_list;
228
225
    int status;
253
250
}
254
251
 
255
252
/* Prints out a password to stdout */
256
 
bool print_out_password(const char *buffer, size_t length){
 
253
static bool print_out_password(const char *buffer, size_t length){
257
254
  ssize_t ret;
258
255
  for(size_t written = 0; written < length; written += (size_t)ret){
259
256
    ret = TEMP_FAILURE_RETRY(write(STDOUT_FILENO, buffer + written,
394
391
      if(arg == NULL){
395
392
        break;
396
393
      }
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
 
        }
 
394
      if(not add_environment(getplugin(NULL), arg, true)){
 
395
        perror("add_environment");
405
396
      }
406
397
      break;
407
398
    case 'o':                   /* --options-for */
435
426
        if(envdef == NULL){
436
427
          break;
437
428
        }
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)){
 
429
        *envdef = '\0';
 
430
        if(not add_environment(getplugin(arg), envdef+1, true)){
444
431
          perror("add_environment");
445
432
        }
446
433
      }
464
451
      }
465
452
      break;
466
453
    case 128:                   /* --plugin-dir */
 
454
      free(plugindir);
467
455
      plugindir = strdup(arg);
468
456
      if(plugindir == NULL){
469
457
        perror("strdup");
482
470
      debug = true;
483
471
      break;
484
472
    case ARGP_KEY_ARG:
485
 
      fprintf(stderr, "Ignoring unknown argument \"%s\"\n", arg);
 
473
      /* Cryptsetup always passes an argument, which is an empty
 
474
         string if "none" was specified in /etc/crypttab.  So if
 
475
         argument was empty, we ignore it silently. */
 
476
      if(arg[0] != '\0'){
 
477
        fprintf(stderr, "Ignoring unknown argument \"%s\"\n", arg);
 
478
      }
486
479
      break;
487
480
    case ARGP_KEY_END:
488
481
      break;
507
500
    case 128:                   /* --plugin-dir */
508
501
      break;
509
502
    case 129:                   /* --config-file */
 
503
      free(argfile);
510
504
      argfile = strdup(arg);
511
505
      if(argfile == NULL){
512
506
        perror("strdup");
941
935
    }
942
936
    /* OK, now either a process completed, or something can be read
943
937
       from one of them */
944
 
    for(plugin *proc = plugin_list; proc != NULL; proc = proc->next){
 
938
    for(plugin *proc = plugin_list; proc != NULL;){
945
939
      /* Is this process completely done? */
946
940
      if(proc->eof and proc->completed){
947
941
        /* Only accept the plugin output if it exited cleanly */
974
968
            exitstatus = EXIT_FAILURE;
975
969
            goto fallback;
976
970
          }
977
 
          free_plugin(proc);
 
971
          
978
972
          /* We are done modifying process list, so unblock signal */
979
973
          ret = sigprocmask (SIG_UNBLOCK, &sigchld_action.sa_mask,
980
974
                             NULL);
987
981
          if(plugin_list == NULL){
988
982
            break;
989
983
          }
 
984
          
 
985
          plugin *next_plugin = proc->next;
 
986
          free_plugin(proc);
 
987
          proc = next_plugin;
990
988
          continue;
991
989
        }
992
990
        
1004
1002
      /* This process has not completed.  Does it have any output? */
1005
1003
      if(proc->eof or not FD_ISSET(proc->fd, &rfds)){
1006
1004
        /* This process had nothing to say at this time */
 
1005
        proc = proc->next;
1007
1006
        continue;
1008
1007
      }
1009
1008
      /* Before reading, make the process' data buffer large enough */
1022
1021
                 BUFFER_SIZE);
1023
1022
      if(ret < 0){
1024
1023
        /* Read error from this process; ignore the error */
 
1024
        proc = proc->next;
1025
1025
        continue;
1026
1026
      }
1027
1027
      if(ret == 0){