/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-09 02:01:13 UTC
  • Revision ID: teddy@fukt.bsnet.se-20090209020113-726hq380zvp8zt97
Four new interrelated features:

1. Support using a different network interface via both initramfs.conf
   (the DEVICE setting) and the kernel command line (sixth field of
   the "ip=" option as in Linux' Documentation/nfsroot.txt).

2. Support connecting to a specified Mandos server directly using a
   kernel command line option ("mandos=connect:<ADDRESS>:<PORT>").

3. Support connecting directly to an IPv4 address (and port) using the
   "--connect" option of mandos-client.

4. Support an empty string to the --interface option to mandos-client.

* Makefile (WARN): Increase strictness by changing to
                   "-Wstrict-aliasing=1".

* debian/mandos-client.README.Debian (Use the Correct Network
  Interface): Changed to refer to initramfs.conf and nfsroot.txt.
  (Test the Server): Improve wording.
  (Non-local Connection): New section.
* initramfs-tools-script: Obey DEVICE environment variable and setting
                          from "/conf/initramfs.conf".  Also let any
                          "ip=" kernel command line option override
                          it.  Support new "mandos=connect" option.
                          Call "configure_networking" to set up IP
                          address on interface if necessary.
* plugin-runner.conf: Change example.
* plugins.d/mandos-client.c: Some whitespace and comment changes.
  (start_mandos_communication): Take an additional argument for
                                address family, all callers changed.
                                Connect to an IPv4 address if address
                                family is AF_INET.  Only set IPv6
                                scope_id for link-local addresses.
  (main): Accept empty interface name; this will not bring up any
         interface and leave the interface as unspecified.  Also do
         not restore kernel log level if lowering it failed.
* plugins.d/mandos-client.xml (OPTIONS): Document that the
                                         "--interface" option accepts
                                         an empty string.
  (EXAMPLE): Change example IPv6 address to a link-local address.

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
 
82
81
  char **environ;
83
82
  int envc;
84
83
  bool disabled;
85
 
  
 
84
 
86
85
  /* Variables used for running processes*/
87
86
  pid_t pid;
88
87
  int fd;
280
279
  }
281
280
  free(plugin_node->environ);
282
281
  free(plugin_node->buffer);
283
 
  
 
282
 
284
283
  /* Removes the plugin from the singly-linked list */
285
284
  if(plugin_node == plugin_list){
286
285
    /* First one - simple */
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 {
569
572
    size_t size = 0;
570
573
    const char whitespace_delims[] = " \r\t\f\v\n";
571
574
    const char comment_delim[] = "#";
572
 
    
 
575
 
573
576
    custom_argc = 1;
574
577
    custom_argv = malloc(sizeof(char*) * 2);
575
578
    if(custom_argv == NULL){
579
582
    }
580
583
    custom_argv[0] = argv[0];
581
584
    custom_argv[1] = NULL;
582
 
    
 
585
 
583
586
    /* for each line in the config file, strip whitespace and ignore
584
587
       commented text */
585
588
    while(true){
587
590
      if(sret == -1){
588
591
        break;
589
592
      }
590
 
      
 
593
 
591
594
      line = org_line;
592
595
      arg = strsep(&line, comment_delim);
593
596
      while((p = strsep(&arg, whitespace_delims)) != NULL){
756
759
        continue;
757
760
      }
758
761
    }
759
 
    
 
762
 
760
763
    char *filename;
761
764
    if(plugindir == NULL){
762
765
      ret = asprintf(&filename, PDIR "/%s", dirst->d_name);
774
777
      free(filename);
775
778
      continue;
776
779
    }
777
 
    
 
780
 
778
781
    /* Ignore non-executable files */
779
782
    if(not S_ISREG(st.st_mode) or (access(filename, X_OK) != 0)){
780
783
      if(debug){
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){
964
966
        if(not WIFEXITED(proc->status)
965
967
           or WEXITSTATUS(proc->status) != 0){
966
968
          /* Bad exit by plugin */
967
 
          
 
969
 
968
970
          if(debug){
969
971
            if(WIFEXITED(proc->status)){
970
972
              fprintf(stderr, "Plugin %s [%" PRIdMAX "] exited with"
984
986
          
985
987
          /* Remove the plugin */
986
988
          FD_CLR(proc->fd, &rfds_all);
987
 
          
 
989
 
988
990
          /* Block signal while modifying process_list */
989
991
          ret = sigprocmask(SIG_BLOCK, &sigchld_action.sa_mask, NULL);
990
992
          if(ret < 0){
1057
1059
      }
1058
1060
    }
1059
1061
  }
1060
 
  
1061
 
  
 
1062
 
 
1063
 
1062
1064
 fallback:
1063
1065
  
1064
1066
  if(plugin_list == NULL or exitstatus != EXIT_SUCCESS){