Merge branch 'bug3179'
* bug3179: Drop log.DBusHandler vm: fix handling policy deny on admin.vm.List
This commit is contained in:
		
						commit
						61ddccb6d6
					
				@ -27,8 +27,6 @@ See also: :py:attr:`qubes.vm.qubesvm.QubesVM.log`
 | 
				
			|||||||
import logging
 | 
					import logging
 | 
				
			||||||
import sys
 | 
					import sys
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import dbus
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
FORMAT_CONSOLE = '%(name)s: %(message)s'
 | 
					FORMAT_CONSOLE = '%(name)s: %(message)s'
 | 
				
			||||||
FORMAT_LOG = '%(asctime)s %(message)s'
 | 
					FORMAT_LOG = '%(asctime)s %(message)s'
 | 
				
			||||||
FORMAT_DEBUG = '%(asctime)s ' \
 | 
					FORMAT_DEBUG = '%(asctime)s ' \
 | 
				
			||||||
@ -39,43 +37,6 @@ formatter_log = logging.Formatter(FORMAT_LOG)
 | 
				
			|||||||
formatter_debug = logging.Formatter(FORMAT_DEBUG)
 | 
					formatter_debug = logging.Formatter(FORMAT_DEBUG)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class DBusHandler(logging.Handler):
 | 
					 | 
				
			||||||
    '''Handler which displays records as DBus notifications'''
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    #: mapping of loglevels to icons
 | 
					 | 
				
			||||||
    app_icons = {
 | 
					 | 
				
			||||||
        logging.ERROR:      'dialog-error',
 | 
					 | 
				
			||||||
        logging.WARNING:    'dialog-warning',
 | 
					 | 
				
			||||||
        logging.NOTSET:     'dialog-information',
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def __init__(self, *args, **kwargs):
 | 
					 | 
				
			||||||
        super(DBusHandler, self).__init__(*args, **kwargs)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        self._notify_object = dbus.SessionBus().get_object(
 | 
					 | 
				
			||||||
            'org.freedesktop.Notifications', '/org/freedesktop/Notifications')
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def emit(self, record):
 | 
					 | 
				
			||||||
        app_icon = self.app_icons[
 | 
					 | 
				
			||||||
            max(level for level in self.app_icons if level <= record.levelno)]
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        try:
 | 
					 | 
				
			||||||
            # https://developer.gnome.org/notification-spec/#command-notify
 | 
					 | 
				
			||||||
            self._notify_object.Notify(
 | 
					 | 
				
			||||||
                'Qubes',    # STRING app_name
 | 
					 | 
				
			||||||
                0,          # UINT32 replaces_id
 | 
					 | 
				
			||||||
                app_icon,   # STRING app_icon
 | 
					 | 
				
			||||||
                record.msg, # STRING summary
 | 
					 | 
				
			||||||
                '',         # STRING body
 | 
					 | 
				
			||||||
                (),         # ARRAY actions
 | 
					 | 
				
			||||||
                {},         # DICT hints
 | 
					 | 
				
			||||||
                0,          # INT32 timeout
 | 
					 | 
				
			||||||
                dbus_interface='org.freedesktop.Notifications')
 | 
					 | 
				
			||||||
        except dbus.DBusException:
 | 
					 | 
				
			||||||
            pass
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def enable():
 | 
					def enable():
 | 
				
			||||||
    '''Enable global logging
 | 
					    '''Enable global logging
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -168,11 +168,14 @@ class QubesVM(qubesadmin.base.PropertyHolder):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        '''
 | 
					        '''
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        vm_list_info = [line
 | 
					        try:
 | 
				
			||||||
            for line in self.qubesd_call(
 | 
					            vm_list_info = [line
 | 
				
			||||||
                self._method_dest, 'admin.vm.List', None, None
 | 
					                for line in self.qubesd_call(
 | 
				
			||||||
            ).decode('ascii').split('\n')
 | 
					                    self._method_dest, 'admin.vm.List', None, None
 | 
				
			||||||
            if line.startswith(self._method_dest+' ')]
 | 
					                ).decode('ascii').split('\n')
 | 
				
			||||||
 | 
					                if line.startswith(self._method_dest+' ')]
 | 
				
			||||||
 | 
					        except qubesadmin.exc.QubesDaemonNoResponseError:
 | 
				
			||||||
 | 
					            return 'NA'
 | 
				
			||||||
        assert len(vm_list_info) == 1
 | 
					        assert len(vm_list_info) == 1
 | 
				
			||||||
        #  name class=... state=... other=...
 | 
					        #  name class=... state=... other=...
 | 
				
			||||||
        # NOTE: when querying dom0, we get whole list
 | 
					        # NOTE: when querying dom0, we get whole list
 | 
				
			||||||
@ -206,7 +209,7 @@ class QubesVM(qubesadmin.base.PropertyHolder):
 | 
				
			|||||||
        :rtype: bool
 | 
					        :rtype: bool
 | 
				
			||||||
        '''
 | 
					        '''
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return self.get_power_state() != 'Halted'
 | 
					        return self.get_power_state() not in ('Halted', 'NA')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def is_networked(self):
 | 
					    def is_networked(self):
 | 
				
			||||||
        '''Check whether this VM can reach network (firewall notwithstanding).
 | 
					        '''Check whether this VM can reach network (firewall notwithstanding).
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user