/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 mandos-ctl

  • Committer: Teddy Hogeborn
  • Date: 2019-04-08 21:53:22 UTC
  • Revision ID: teddy@recompile.se-20190408215322-y3hmfxzdgs9t84l1
plugin-runner: Fix minor memory leak

* plugin-runner.c (free_plugin): Even if argv[0] is NULL, as for the
                                 pseudo-plugin for global options,
                                 free all other arguments by simply
                                 starting at argv[1] and freeing
                                 plugin_node->name (which is always
                                 argv[0]) separately.

Show diffs side-by-side

added added

removed removed

Lines of Context:
571
571
                        for key, subval in value.items()}
572
572
            return value
573
573
 
574
 
        def set_client_property(self, objectpath, key, value):
575
 
            if key == "Secret":
576
 
                if not isinstance(value, bytes):
577
 
                    value = value.encode("utf-8")
578
 
                value = self.dbus_python.ByteArray(value)
579
 
            return self.set_property(self.busname, objectpath,
580
 
                                     self.client_interface, key,
581
 
                                     value)
582
574
 
583
575
    class SilenceLogger(object):
584
576
        "Simple context manager to silence a particular logger"
1320
1312
                @staticmethod
1321
1313
                def get_object(busname, objectpath):
1322
1314
                    DBusObject = collections.namedtuple(
1323
 
                        "DBusObject", ("methodname", "Set"))
 
1315
                        "DBusObject", ("methodname",))
1324
1316
                    def method(*args, **kwargs):
1325
1317
                        self.assertEqual({"dbus_interface":
1326
1318
                                          "interface"},
1327
1319
                                         kwargs)
1328
1320
                        return func(*args)
1329
 
                    def set_property(interface, key, value,
1330
 
                                     dbus_interface=None):
1331
 
                        self.assertEqual(
1332
 
                            "org.freedesktop.DBus.Properties",
1333
 
                            dbus_interface)
1334
 
                        self.assertEqual("Secret", key)
1335
 
                        return func(interface, key, value,
1336
 
                                    dbus_interface=dbus_interface)
1337
 
                    return DBusObject(methodname=method,
1338
 
                                      Set=set_property)
 
1321
                    return DBusObject(methodname=method)
1339
1322
            class Boolean(object):
1340
1323
                def __init__(self, value):
1341
1324
                    self.value = bool(value)
1347
1330
                pass
1348
1331
            class Dictionary(dict):
1349
1332
                pass
1350
 
            class ByteArray(bytes):
1351
 
                pass
1352
1333
        return mock_dbus_python
1353
1334
 
1354
1335
    def call_method(self, bus, methodname, busname, objectpath,
1531
1512
        # Make sure the dbus logger was suppressed
1532
1513
        self.assertEqual(0, counting_handler.count)
1533
1514
 
1534
 
    def test_Set_Secret_sends_bytearray(self):
1535
 
        ret = [None]
1536
 
        def func(*args, **kwargs):
1537
 
            ret[0] = (args, kwargs)
1538
 
        mock_dbus_python = self.MockDBusPython_func(func)
1539
 
        bus = dbus_python_adapter.SystemBus(mock_dbus_python)
1540
 
        bus.set_client_property("objectpath", "Secret", "value")
1541
 
        expected_call = (("se.recompile.Mandos.Client", "Secret",
1542
 
                          mock_dbus_python.ByteArray(b"value")),
1543
 
                         {"dbus_interface":
1544
 
                          "org.freedesktop.DBus.Properties"})
1545
 
        self.assertEqual(expected_call, ret[0])
1546
 
        if sys.version_info.major == 2:
1547
 
            self.assertIsInstance(ret[0][0][-1],
1548
 
                                  mock_dbus_python.ByteArray)
1549
 
 
1550
1515
    def test_get_object_converts_to_correct_exception(self):
1551
1516
        bus = dbus_python_adapter.SystemBus(
1552
1517
            self.fake_dbus_python_raises_exception_on_connect)