/mandos/release

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/release

« back to all changes in this revision

Viewing changes to mandos-ctl

  • Committer: Teddy Hogeborn
  • Date: 2019-03-08 23:55:34 UTC
  • mto: (237.7.594 trunk)
  • mto: This revision was merged to the branch mainline in revision 382.
  • Revision ID: teddy@recompile.se-20190308235534-kkiwc3oeyp0vxw5h
mandos-ctl: Add new --debug option to show D-Bus calls

* mandos-ctl (PropertyCmd, RemoveCmd, ApproveCmd, DenyCmd): Add debug
  output
  (add_command_line_options): Also add "--debug" options.
  (main): If debug option is set, set logging level to DEBUG.  Also
          add debug output when connecting to Mandos server.
* mandos-ctl.xml (SYNOPSIS): Show --debug option where appropriate.
  (OPTIONS): Document new "--debug" option.

Show diffs side-by-side

added added

removed removed

Lines of Context:
300
300
    """Abstract class for Actions for setting one client property"""
301
301
    def run_on_one_client(self, client, properties):
302
302
        """Set the Client's D-Bus property"""
 
303
        log.debug("D-Bus: %s:%s:%s.Set(%r, %r, %r)", busname,
 
304
                  client.__dbus_object_path__,
 
305
                  dbus.PROPERTIES_IFACE, client_interface,
 
306
                  self.property, self.value_to_set
 
307
                  if not isinstance(self.value_to_set, dbus.Boolean)
 
308
                  else bool(self.value_to_set))
303
309
        client.Set(client_interface, self.property, self.value_to_set,
304
310
                   dbus_interface=dbus.PROPERTIES_IFACE)
305
311
 
431
437
 
432
438
class RemoveCmd(Command):
433
439
    def run_on_one_client(self, client, properties):
 
440
        log.debug("D-Bus: %s:%s:%s.RemoveClient(%r)", busname,
 
441
                  server_path, server_interface,
 
442
                  str(client.__dbus_object_path__))
434
443
        self.mandos.RemoveClient(client.__dbus_object_path__)
435
444
 
436
445
class ApproveCmd(Command):
437
446
    def run_on_one_client(self, client, properties):
 
447
        log.debug("D-Bus: %s:%s.Approve(True)",
 
448
                  client.__dbus_object_path__, client_interface)
438
449
        client.Approve(dbus.Boolean(True),
439
450
                       dbus_interface=client_interface)
440
451
 
441
452
class DenyCmd(Command):
442
453
    def run_on_one_client(self, client, properties):
 
454
        log.debug("D-Bus: %s:%s.Approve(False)",
 
455
                  client.__dbus_object_path__, client_interface)
443
456
        client.Approve(dbus.Boolean(False),
444
457
                       dbus_interface=client_interface)
445
458
 
566
579
        help="Approve any current client request")
567
580
    approve_deny.add_argument("-D", "--deny", action="store_true",
568
581
                              help="Deny any current client request")
 
582
    parser.add_argument("--debug", action="store_true",
 
583
                        help="Debug mode (show D-Bus commands)")
569
584
    parser.add_argument("--check", action="store_true",
570
585
                        help="Run self-test")
571
586
    parser.add_argument("client", nargs="*", help="Client name")
693
708
 
694
709
    clientnames = options.client
695
710
 
 
711
    if options.debug:
 
712
        log.setLevel(logging.DEBUG)
 
713
 
696
714
    try:
697
715
        bus = dbus.SystemBus()
 
716
        log.debug("D-Bus: Connect to: (name=%r, path=%r)", busname,
 
717
                  server_path)
698
718
        mandos_dbus_objc = bus.get_object(busname, server_path)
699
719
    except dbus.exceptions.DBusException:
700
720
        log.critical("Could not connect to Mandos server")
713
733
    dbus_filter = NullFilter()
714
734
    try:
715
735
        dbus_logger.addFilter(dbus_filter)
 
736
        log.debug("D-Bus: %s:%s:%s.GetManagedObjects()", busname,
 
737
                  server_path, dbus.OBJECT_MANAGER_IFACE)
716
738
        mandos_clients = {path: ifs_and_props[client_interface]
717
739
                          for path, ifs_and_props in
718
740
                          mandos_serv_object_manager