/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-12-10 01:26:02 UTC
  • mfrom: (237.1.2 mandos)
  • Revision ID: teddy@fukt.bsnet.se-20081210012602-vhz3h75xkj24t340
First version of a somewhat complete D-Bus server interface.  Also
change user/group name to "_mandos".

* debian/mandos.postinst: Rename old "mandos" user and group to
                          "_mandos"; create "_mandos" user and group
                          if none exist.
* debian/mandos-client.postinst: - '' -

* initramfs-tools-hook: Try "_mandos" before "mandos" as user and
                        group name.

* mandos (_datetime_to_dbus_struct): New; was previously local.
  (Client.started): Renamed to "last_started".  All users changed.
  (Client.started): New; boolean.
  (Client.dbus_object_path): New.
  (Client.check_command): Renamed to "checker_command".  All users
                          changed.
  (Client.__init__): Set and use "self.dbus_object_path".  Set
                     "self.started".
  (Client.start): Update "self.started".  Emit "self.PropertyChanged"
                  signals for both "started" and "last_started".
  (Client.stop): Update "self.started".  Emit "self.PropertyChanged"
                 signal for "started".
  (Client.checker_callback): Take additional "command" argument.  All
                             callers changed. Emit
                             "self.PropertyChanged" signal.
  (Client.bump_timeout): Emit "self.PropertyChanged" signal for
                         "last_checked_ok".
  (Client.start_checker): Emit "self.PropertyChanged" signal for
                          "checker_running".
  (Client.stop_checker): Emit "self.PropertyChanged" signal for
                         "checker_running".
  (Client.still_valid): Bug fix: use "getattr(self, started, False)"
                        instead of "self.started" in case this client
                        object is so new that the "started" attribute
                        has not been created yet.
  (Client.IntervalChanged, Client.CheckerIsRunning, Client.GetChecker,
  Client.GetCreated, Client.GetFingerprint, Client.GetHost,
  Client.GetInterval, Client.GetName, Client.GetStarted,
  Client.GetTimeout, Client.StateChanged, Client.TimeoutChanged):
  Removed; all callers changed.
  (Client.CheckerCompleted): Add "condition" and "command" arguments.
                             All callers changed.
  (Client.GetAllProperties, Client.PropertyChanged): New.
  (Client.StillValid): Renamed to "IsStillValid".
  (Client.StartChecker): Changed to its own function to avoid the
                         return value from "Client.start_checker()".
  (Client.Stop): Changed to its own function to avoid the return value
                 from "Client.stop()".
  (main): Try "_mandos" before "mandos" as user and group name.
          Removed inner function "remove_from_clients".  New inner
          class "MandosServer".

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
/*
3
3
 * Mandos plugin runner - Run Mandos plugins
4
4
 *
5
 
 * Copyright © 2008,2009 Teddy Hogeborn
6
 
 * Copyright © 2008,2009 Björn Påhlsson
 
5
 * Copyright © 2008 Teddy Hogeborn
 
6
 * Copyright © 2008 Björn Påhlsson
7
7
 * 
8
8
 * This program is free software: you can redistribute it and/or
9
9
 * modify it under the terms of the GNU General Public License as
309
309
  struct stat st;
310
310
  fd_set rfds_all;
311
311
  int ret, maxfd = 0;
312
 
  ssize_t sret;
313
312
  uid_t uid = 65534;
314
313
  gid_t gid = 65534;
315
314
  bool debug = false;
463
462
      /* This is already done by parse_opt_config_file() */
464
463
      break;
465
464
    case 130:                   /* --userid */
466
 
      /* In the GNU C library, uid_t is always unsigned int */
467
 
      ret = sscanf(arg, "%u", &uid);
468
 
      if(ret != 1){
469
 
        fprintf(stderr, "Bad user ID number: \"%s\", using %u\n", arg,
470
 
                uid);
471
 
      }
 
465
      uid = (uid_t)strtol(arg, NULL, 10);
472
466
      break;
473
467
    case 131:                   /* --groupid */
474
 
      /* In the GNU C library, gid_t is always unsigned int */
475
 
      ret = sscanf(arg, "%u", &gid);
476
 
      if(ret != 1){
477
 
        fprintf(stderr, "Bad group ID number: \"%s\", using %u\n",
478
 
                arg, gid);
479
 
      }
 
468
      gid = (gid_t)strtol(arg, NULL, 10);
480
469
      break;
481
470
    case 132:                   /* --debug */
482
471
      debug = true;
483
472
      break;
484
 
/*
485
 
 * When adding more options before this line, remember to also add a
486
 
 * "case" to the "parse_opt_config_file" function below.
487
 
 */
488
473
    case ARGP_KEY_ARG:
489
474
      /* Cryptsetup always passes an argument, which is an empty
490
475
         string if "none" was specified in /etc/crypttab.  So if
539
524
                       .args_doc = "",
540
525
                       .doc = "Mandos plugin runner -- Run plugins" };
541
526
  
542
 
  /* Parse using parse_opt_config_file() in order to get the custom
 
527
  /* Parse using the parse_opt_config_file in order to get the custom
543
528
     config file location, if any. */
544
529
  ret = argp_parse (&argp, argc, argv, ARGP_IN_ORDER, 0, NULL);
545
530
  if (ret == ARGP_ERR_UNKNOWN){
561
546
    char *org_line = NULL;
562
547
    char *p, *arg, *new_arg, *line;
563
548
    size_t size = 0;
 
549
    ssize_t sret;
564
550
    const char whitespace_delims[] = " \r\t\f\v\n";
565
551
    const char comment_delim[] = "#";
566
552
 
968
954
                      (unsigned int) (proc->pid),
969
955
                      WTERMSIG(proc->status));
970
956
            } else if(WCOREDUMP(proc->status)){
971
 
              fprintf(stderr, "Plugin %u dumped core\n",
 
957
              fprintf(stderr, "Plugin %d dumped core\n",
972
958
                      (unsigned int) (proc->pid));
973
959
            }
974
960
          }
1033
1019
        proc->buffer_size += BUFFER_SIZE;
1034
1020
      }
1035
1021
      /* Read from the process */
1036
 
      sret = read(proc->fd, proc->buffer + proc->buffer_length,
1037
 
                  BUFFER_SIZE);
1038
 
      if(sret < 0){
 
1022
      ret = read(proc->fd, proc->buffer + proc->buffer_length,
 
1023
                 BUFFER_SIZE);
 
1024
      if(ret < 0){
1039
1025
        /* Read error from this process; ignore the error */
1040
1026
        proc = proc->next;
1041
1027
        continue;
1042
1028
      }
1043
 
      if(sret == 0){
 
1029
      if(ret == 0){
1044
1030
        /* got EOF */
1045
1031
        proc->eof = true;
1046
1032
      } else {
1047
 
        proc->buffer_length += (size_t) sret;
 
1033
        proc->buffer_length += (size_t) ret;
1048
1034
      }
1049
1035
    }
1050
1036
  }