示例#1
0
 def save(self, o):
     q = qubesdb.QubesDB()
     try:
         o = json.dumps(o)
         q.write(self.PATH, o)
     finally:
         q.close()
示例#2
0
 def load(self):
     q = qubesdb.QubesDB()
     try:
         d = q.read(self.PATH) or "{}"
         try:
             if isinstance(d, bytes):
                 d = d.decode("utf-8")
             d = json.loads(d)
         except (FileNotFoundError, json.decoder.JSONDecodeError):
             d = {}
         return ConjoinTracker.from_dict(d)
     finally:
         q.close()
def main():
    args = parse_args()
    logger = get_logger("notification-forwarder", verbose=args.v)

    qdb = qubesdb.QubesDB()
    set_env(qdb)

    if args.target:
        notification_vm = args.target
    else:
        notification_vm = (qdb.read("/desktop-notification-target")
                           or b"").decode()

    vm = qdb.read("/name").decode()

    local_mode = args.L
    force_mode = args.F
    if local_mode:
        if force_mode:
            logger.warning(
                "Cannot use local mode and force mode at the same time. Exiting..."
            )
            sys.exit(3)
    elif not notification_vm or (vm == notification_vm):
        logger.info(
            "No notification target specified or we are the target. Handling notifications locally..."
        )
        local_mode = True
        force_mode = False

    forwarder = NotificationForwarder(notification_vm,
                                      verbose=args.v,
                                      local_mode=local_mode,
                                      force_mode=force_mode,
                                      exit_idle=args.x,
                                      private_bus_address=args.dbus_address)
    sys.excepthook = lambda e, v, t: glib_error_handler(
        logger, forwarder, e, v, t
    )  #for some reason GLib otherwise ignores Exceptions / hangs
    forwarder.run()

    sys.exit(0)
示例#4
0
    def start_qdb_watch(self, loop=None):
        '''Start watching QubesDB

        Calling this method in appropriate time is responsibility of child
        class.
        '''
        # cleanup old watch connection first, if any
        if self._qdb_connection_watch is not None:
            asyncio.get_event_loop().remove_reader(
                self._qdb_connection_watch.watch_fd())
            self._qdb_connection_watch.close()

        import qubesdb  # pylint: disable=import-error
        self._qdb_connection_watch = qubesdb.QubesDB(self.name)
        if loop is None:
            loop = asyncio.get_event_loop()
        loop.add_reader(self._qdb_connection_watch.watch_fd(),
                        self._qdb_watch_reader, loop)
        for path in self._qdb_watch_paths:
            self._qdb_connection_watch.watch(path)
示例#5
0
    def main(cls, self) -> NoReturn:
        """Program entry point"""

        import argparse, qubesdb, os
        argparse.ArgumentParser().parse_args()

        try:
            target_domain = qubesdb.QubesDB().read('/name').decode(
                'ascii', 'strict')
        except:
            # dom0 doesn't have a /name value in its QubesDB
            target_domain = 'dom0'
        remote_domain = os.getenv('QREXEC_REMOTE_DOMAIN')

        self.validate_qube_names(target_domain, remote_domain)

        self.start_service(target_domain, remote_domain)
        self.start_transmission()

        Gtk.main()
示例#6
0
 def __init__(self):
     self.terminate_requested = False
     self.qdb = qubesdb.QubesDB()
     self.log = logging.getLogger('qubes.firewall')
     self.log.addHandler(logging.StreamHandler(sys.stderr))
示例#7
0
 def untrusted_qdb(self):
     '''QubesDB handle for this domain.'''
     if self._qdb_connection is None:
         import qubesdb  # pylint: disable=import-error
         self._qdb_connection = qubesdb.QubesDB(self.name)
     return self._qdb_connection