/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

* mandos-ctl: Made work again after D-Bus API changes.
  (datetime_to_milliseconds): Renamed to "timedelta_to_milliseconds".
                              All callers changed.
  (milliseconds_to_string): Use clearer mapping string format.
  (string_to_delta): Add some comments.

Show diffs side-by-side

added added

removed removed

Lines of Context:
292
292
        elif u"secfile" in config:
293
293
            with closing(open(os.path.expanduser
294
294
                              (os.path.expandvars
295
 
                               (config[u"secfile"])),
296
 
                              "rb")) as secfile:
 
295
                               (config[u"secfile"])))) as secfile:
297
296
                self.secret = secfile.read()
298
297
        else:
299
298
            raise TypeError(u"No secret or secfile for client %s"
399
398
        # is as it should be.
400
399
        
401
400
        # If a checker exists, make sure it is not a zombie
402
 
        try:
 
401
        if self.checker is not None:
403
402
            pid, status = os.waitpid(self.checker.pid, os.WNOHANG)
404
 
        except (AttributeError, OSError), error:
405
 
            if (isinstance(error, OSError)
406
 
                and error.errno != errno.ECHILD):
407
 
                raise error
408
 
        else:
409
403
            if pid:
410
404
                logger.warning(u"Checker was a zombie")
411
405
                gobject.source_remove(self.checker_callback_tag)
626
620
        """Standard D-Bus method, overloaded to insert property tags.
627
621
        """
628
622
        xmlstring = dbus.service.Object.Introspect(self, object_path,
629
 
                                                   connection)
630
 
        try:
631
 
            document = xml.dom.minidom.parseString(xmlstring)
632
 
            def make_tag(document, name, prop):
633
 
                e = document.createElement(u"property")
634
 
                e.setAttribute(u"name", name)
635
 
                e.setAttribute(u"type", prop._dbus_signature)
636
 
                e.setAttribute(u"access", prop._dbus_access)
637
 
                return e
638
 
            for if_tag in document.getElementsByTagName(u"interface"):
639
 
                for tag in (make_tag(document, name, prop)
640
 
                            for name, prop
641
 
                            in self._get_all_dbus_properties()
642
 
                            if prop._dbus_interface
643
 
                            == if_tag.getAttribute(u"name")):
644
 
                    if_tag.appendChild(tag)
645
 
                # Add the names to the return values for the
646
 
                # "org.freedesktop.DBus.Properties" methods
647
 
                if (if_tag.getAttribute(u"name")
648
 
                    == u"org.freedesktop.DBus.Properties"):
649
 
                    for cn in if_tag.getElementsByTagName(u"method"):
650
 
                        if cn.getAttribute(u"name") == u"Get":
651
 
                            for arg in cn.getElementsByTagName(u"arg"):
652
 
                                if (arg.getAttribute(u"direction")
653
 
                                    == u"out"):
654
 
                                    arg.setAttribute(u"name", u"value")
655
 
                        elif cn.getAttribute(u"name") == u"GetAll":
656
 
                            for arg in cn.getElementsByTagName(u"arg"):
657
 
                                if (arg.getAttribute(u"direction")
658
 
                                    == u"out"):
659
 
                                    arg.setAttribute(u"name", u"props")
660
 
            xmlstring = document.toxml(u"utf-8")
661
 
            document.unlink()
662
 
        except (AttributeError, xml.dom.DOMException,
663
 
                xml.parsers.expat.ExpatError), error:
664
 
            logger.error(u"Failed to override Introspection method",
665
 
                         error)
 
623
                                           connection)
 
624
        document = xml.dom.minidom.parseString(xmlstring)
 
625
        del xmlstring
 
626
        def make_tag(document, name, prop):
 
627
            e = document.createElement(u"property")
 
628
            e.setAttribute(u"name", name)
 
629
            e.setAttribute(u"type", prop._dbus_signature)
 
630
            e.setAttribute(u"access", prop._dbus_access)
 
631
            return e
 
632
        for if_tag in document.getElementsByTagName(u"interface"):
 
633
            for tag in (make_tag(document, name, prop)
 
634
                        for name, prop
 
635
                        in self._get_all_dbus_properties()
 
636
                        if prop._dbus_interface
 
637
                        == if_tag.getAttribute(u"name")):
 
638
                if_tag.appendChild(tag)
 
639
        xmlstring = document.toxml(u"utf-8")
 
640
        document.unlink()
666
641
        return xmlstring
667
642
 
668
643
 
806
781
        "D-Bus signal"
807
782
        pass
808
783
    
809
 
    # GotSecret - signal
 
784
    # ReceivedSecret - signal
810
785
    @dbus.service.signal(_interface)
811
 
    def GotSecret(self):
 
786
    def ReceivedSecret(self):
812
787
        "D-Bus signal"
813
788
        pass
814
789
    
1301
1276
                    client.checked_ok()
1302
1277
                    if self.use_dbus:
1303
1278
                        # Emit D-Bus signal
1304
 
                        client.GotSecret()
 
1279
                        client.ReceivedSecret()
1305
1280
                    break
1306
1281
            else:
1307
1282
                logger.error(u"Sending secret to unknown client %s",
1392
1367
        null = os.open(os.path.devnull, os.O_NOCTTY | os.O_RDWR)
1393
1368
        if not stat.S_ISCHR(os.fstat(null).st_mode):
1394
1369
            raise OSError(errno.ENODEV,
1395
 
                          u"%s not a character device"
1396
 
                          % os.path.devnull)
 
1370
                          u"/dev/null not a character device")
1397
1371
        os.dup2(null, sys.stdin.fileno())
1398
1372
        os.dup2(null, sys.stdout.fileno())
1399
1373
        os.dup2(null, sys.stderr.fileno())