/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: 2009-02-07 05:05:03 UTC
  • Revision ID: teddy@fukt.bsnet.se-20090207050503-wi4qno0t5ua46vvx
* initramfs-tools-hook: Add extra newline to plugin-runner.conf to
                        guard against a possible comment character
                        without a newline.

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
#include <signal.h>             /* struct sigaction, sigemptyset(),
63
63
                                   sigaddset(), sigaction(),
64
64
                                   sigprocmask(), SIG_BLOCK, SIGCHLD,
65
 
                                   SIG_UNBLOCK, kill(), sig_atomic_t
66
 
                                */
 
65
                                   SIG_UNBLOCK, kill() */
67
66
#include <errno.h>              /* errno, EBADF */
68
 
#include <inttypes.h>           /* intmax_t, PRIdMAX, strtoimax() */
 
67
#include <inttypes.h>           /* intmax_t, SCNdMAX, PRIdMAX,  */
69
68
 
70
69
#define BUFFER_SIZE 256
71
70
 
313
312
  struct dirent *dirst;
314
313
  struct stat st;
315
314
  fd_set rfds_all;
316
 
  int ret, maxfd = 0;
 
315
  int ret, numchars, maxfd = 0;
317
316
  ssize_t sret;
318
317
  intmax_t tmpmax;
319
318
  uid_t uid = 65534;
380
379
  
381
380
  error_t parse_opt(int key, char *arg, __attribute__((unused))
382
381
                    struct argp_state *state){
383
 
    char *tmp;
384
382
    switch(key){
385
383
    case 'g':                   /* --global-options */
386
384
      if(arg != NULL){
387
 
        char *plugin_option;
388
 
        while((plugin_option = strsep(&arg, ",")) != NULL){
389
 
          if(plugin_option[0] == '\0'){
 
385
        char *p;
 
386
        while((p = strsep(&arg, ",")) != NULL){
 
387
          if(p[0] == '\0'){
390
388
            continue;
391
389
          }
392
 
          if(not add_argument(getplugin(NULL), plugin_option)){
 
390
          if(not add_argument(getplugin(NULL), p)){
393
391
            perror("add_argument");
394
392
            return ARGP_ERR_UNKNOWN;
395
393
          }
406
404
      break;
407
405
    case 'o':                   /* --options-for */
408
406
      if(arg != NULL){
409
 
        char *plugin_name = strsep(&arg, ":");
410
 
        if(plugin_name[0] == '\0'){
411
 
          break;
412
 
        }
413
 
        char *plugin_option;
414
 
        while((plugin_option = strsep(&arg, ",")) != NULL){
415
 
          if(not add_argument(getplugin(plugin_name), plugin_option)){
 
407
        char *p_name = strsep(&arg, ":");
 
408
        if(p_name[0] == '\0' or arg == NULL){
 
409
          break;
 
410
        }
 
411
        char *opt = strsep(&arg, ":");
 
412
        if(opt[0] == '\0' or opt == NULL){
 
413
          break;
 
414
        }
 
415
        char *p;
 
416
        while((p = strsep(&opt, ",")) != NULL){
 
417
          if(p[0] == '\0'){
 
418
            continue;
 
419
          }
 
420
          if(not add_argument(getplugin(p_name), p)){
416
421
            perror("add_argument");
417
422
            return ARGP_ERR_UNKNOWN;
418
423
          }
463
468
      /* This is already done by parse_opt_config_file() */
464
469
      break;
465
470
    case 130:                   /* --userid */
466
 
      errno = 0;
467
 
      tmpmax = strtoimax(arg, &tmp, 10);
468
 
      if(errno != 0 or tmp == arg or *tmp != '\0'
469
 
         or tmpmax != (uid_t)tmpmax){
 
471
      ret = sscanf(arg, "%" SCNdMAX "%n", &tmpmax, &numchars);
 
472
      if(ret < 1 or tmpmax != (uid_t)tmpmax
 
473
         or arg[numchars] != '\0'){
470
474
        fprintf(stderr, "Bad user ID number: \"%s\", using %"
471
475
                PRIdMAX "\n", arg, (intmax_t)uid);
472
476
      } else {
474
478
      }
475
479
      break;
476
480
    case 131:                   /* --groupid */
477
 
      errno = 0;
478
 
      tmpmax = strtoimax(arg, &tmp, 10);
479
 
      if(errno != 0 or tmp == arg or *tmp != '\0'
480
 
         or tmpmax != (gid_t)tmpmax){
 
481
      ret = sscanf(arg, "%" SCNdMAX "%n", &tmpmax, &numchars);
 
482
      if(ret < 1 or tmpmax != (gid_t)tmpmax
 
483
         or arg[numchars] != '\0'){
481
484
        fprintf(stderr, "Bad group ID number: \"%s\", using %"
482
485
                PRIdMAX "\n", arg, (intmax_t)gid);
483
486
      } else {
933
936
  
934
937
  closedir(dir);
935
938
  dir = NULL;
936
 
  free_plugin(getplugin(NULL));
937
939
  
938
940
  for(plugin *p = plugin_list; p != NULL; p = p->next){
939
941
    if(p->pid != 0){