/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-03 05:04:40 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080903050440-7cwzxestx6pvdy1i
* Makefile (mandos.8): Add dependency on "overview.xml" and
                       "legalnotice.xml".
  (mandos-keygen.8): New target.
  (mandos-conf.5): Added dependency on "legalnotice.xml".
  (plugin-runner.8mandos): New target
  (plugins.d/password-request.8mandos): - '' -

* mandos-options.xml (priority): Make wording server/client neutral.

* plugins.d/password-request.c (main): Changed .arg fields of the argp
                                       options struct to be more
                                       consistent with the manual.

* plugins.d/password-request.xml (OVERVIEW): Moved to after "OPTIONS".
  (OPTIONS): Improved wording and names of replaceables.

Show diffs side-by-side

added added

removed removed

Lines of Context:
96
96
 
97
97
static plugin *plugin_list = NULL;
98
98
 
99
 
/* Gets an existing plugin based on name,
 
99
/* Gets a existing plugin based on name,
100
100
   or if none is found, creates a new one */
101
101
static plugin *getplugin(char *name){
102
102
  /* Check for exiting plugin with that name */
118
118
      return NULL;
119
119
    }
120
120
  }
121
 
  
 
121
 
122
122
  *new_plugin = (plugin) { .name = copy_name,
123
123
                           .argc = 1,
124
124
                           .disabled = false,
187
187
  size_t namelen = (size_t)(strchrnul(def, '=') - def);
188
188
  /* Search for this environment variable */
189
189
  for(char **e = p->environ; *e != NULL; e++){
190
 
    if(strncmp(*e, def, namelen + 1) == 0){
 
190
    if(strncmp(*e, def, namelen+1) == 0){
191
191
      /* It already exists */
192
192
      if(replace){
193
 
        char *new = realloc(*e, strlen(def) + 1);
 
193
        char *new = realloc(*e, strlen(def));
194
194
        if(new == NULL){
195
195
          return false;
196
196
        }
238
238
      /* No child processes */
239
239
      break;
240
240
    }
241
 
    
 
241
 
242
242
    /* A child exited, find it in process_list */
243
243
    while(proc != NULL and proc->pid != pid){
244
244
      proc = proc->next;
397
397
      if(arg == NULL){
398
398
        break;
399
399
      }
400
 
      if(not add_environment(getplugin(NULL), arg, true)){
401
 
        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
        }
402
408
      }
403
409
      break;
404
410
    case 'o':                   /* --options-for */
405
411
      if (arg != NULL){
406
412
        char *p_name = strsep(&arg, ":");
407
 
        if(p_name[0] == '\0' or arg == NULL){
 
413
        if(p_name[0] == '\0'){
408
414
          break;
409
415
        }
410
416
        char *opt = strsep(&arg, ":");
411
 
        if(opt[0] == '\0' or opt == NULL){
 
417
        if(opt[0] == '\0'){
412
418
          break;
413
419
        }
414
 
        char *p;
415
 
        while((p = strsep(&opt, ",")) != NULL){
416
 
          if(p[0] == '\0'){
417
 
            continue;
418
 
          }
419
 
          if(not add_argument(getplugin(p_name), p)){
420
 
            perror("add_argument");
421
 
            return ARGP_ERR_UNKNOWN;
 
420
        if(opt != NULL){
 
421
          char *p;
 
422
          while((p = strsep(&opt, ",")) != NULL){
 
423
            if(p[0] == '\0'){
 
424
              continue;
 
425
            }
 
426
            if(not add_argument(getplugin(p_name), p)){
 
427
              perror("add_argument");
 
428
              return ARGP_ERR_UNKNOWN;
 
429
            }
422
430
          }
423
431
        }
424
432
      }
432
440
        if(envdef == NULL){
433
441
          break;
434
442
        }
435
 
        *envdef = '\0';
436
 
        if(not add_environment(getplugin(arg), envdef+1, true)){
 
443
        char *p_name = strndup(arg, (size_t) (envdef-arg));
 
444
        if(p_name == NULL){
 
445
          break;
 
446
        }
 
447
        envdef++;
 
448
        if(not add_environment(getplugin(p_name), envdef, true)){
437
449
          perror("add_environment");
438
450
        }
439
451
      }
457
469
      }
458
470
      break;
459
471
    case 128:                   /* --plugin-dir */
460
 
      free(plugindir);
461
472
      plugindir = strdup(arg);
462
473
      if(plugindir == NULL){
463
474
        perror("strdup");
501
512
    case 128:                   /* --plugin-dir */
502
513
      break;
503
514
    case 129:                   /* --config-file */
504
 
      free(argfile);
505
515
      argfile = strdup(arg);
506
516
      if(argfile == NULL){
507
517
        perror("strdup");
932
942
    }
933
943
    /* OK, now either a process completed, or something can be read
934
944
       from one of them */
935
 
    for(plugin *proc = plugin_list; proc != NULL;){
 
945
    for(plugin *proc = plugin_list; proc != NULL; proc = proc->next){
936
946
      /* Is this process completely done? */
937
947
      if(proc->eof and proc->completed){
938
948
        /* Only accept the plugin output if it exited cleanly */
965
975
            exitstatus = EXIT_FAILURE;
966
976
            goto fallback;
967
977
          }
968
 
          
 
978
          free_plugin(proc);
969
979
          /* We are done modifying process list, so unblock signal */
970
980
          ret = sigprocmask (SIG_UNBLOCK, &sigchld_action.sa_mask,
971
981
                             NULL);
978
988
          if(plugin_list == NULL){
979
989
            break;
980
990
          }
981
 
          
982
 
          plugin *next_plugin = proc->next;
983
 
          free_plugin(proc);
984
 
          proc = next_plugin;
985
991
          continue;
986
992
        }
987
993
        
999
1005
      /* This process has not completed.  Does it have any output? */
1000
1006
      if(proc->eof or not FD_ISSET(proc->fd, &rfds)){
1001
1007
        /* This process had nothing to say at this time */
1002
 
        proc = proc->next;
1003
1008
        continue;
1004
1009
      }
1005
1010
      /* Before reading, make the process' data buffer large enough */
1018
1023
                 BUFFER_SIZE);
1019
1024
      if(ret < 0){
1020
1025
        /* Read error from this process; ignore the error */
1021
 
        proc = proc->next;
1022
1026
        continue;
1023
1027
      }
1024
1028
      if(ret == 0){