Не удается перехватить некоторые базы данных Python, за исключением ошибок

На самом деле это очень просто. Войдите в командный режим, нажав prefix key, затем :. Затем выполните capture-pane -S -<line number you want to dump>Тогдаsave-buffer <filepath>

Этот файл содержит весь вывод прокрутки. После этого вы должны удалить буфер из соображений безопасности.

0
11.02.2020, 03:16
1 ответ

Оказывается, я не первый, кто столкнулся с этой проблемой из-за «ошибки дизайна» dbus по сравнению с systemd. Решением была эта процедура:

    def BuildNoPermissions(self, bus):
        ''' Errors add 5 seconds:

        ERROR:dbus.proxies:Introspect error on :1.4:/org/freedesktop/thermald:
        dbus.exceptions.DBusException: org.freedesktop.DBus.Error.AccessDenied:

        Trap this error by first:
        Build list of objects with no introspection.

        Add to list if entry:
            <policy context="default">
                <deny own="fi.epitest.hostap.WPASupplicant"/>
                <deny own="fi.w1.wpa_supplicant1"/>
            </policy>
       ...exists. Add each deny entry to list to trap error:
        ERROR:dbus.proxies:Introspect error on :1.19:/fi/w1/wpa_supplicant1...

        Then before introspecting dbus make sure item isn't on list. If it is
        on list then create necessary "No permissions" entry instead.

        Now all that is left is:

        ERROR:dbus.proxies:Introspect error on :1.1450:/org/freedesktop/
        NetworkManager/dnsmasq:

        Found in:
        /etc/dbus-1/system.d/org.freedesktop.NetworkManager.conf:
                        <deny own="org.freedesktop.NetworkManager.dnsmasq"/>

        Problem is NetworkManager has Introspect but denies dnsmasq so check
        deny for all *.conf files even ones with introspect.

        NOTE: when running with sudo things get worse:

        ERROR:dbus.proxies:Introspect error on :1.19:/fi/epitest/hostap/
        WPASupplicant/Interfaces/62: dbus.exceptions.DBusException:
        org.freedesktop.DBus.Error.NoReply: Message recipient disconnected 
        from message bus without replying

       ... and then Ubuntu prints system crash message with option to report.
        '''
#        print ('\n=============   BuildNoPermissions   =================\n')
#        print (bus, '\n')
        result = os.popen("grep -Li introspect /etc/dbus-1/system.d/*"). \
                          read().splitlines()

        for line in result:
            base=os.path.basename(line)     # remove path prefix
            base=os.path.splitext(base)[0]  # remove extension suffix
            ''' Must open up file to see if <deny> is used and add them
            '''
#            print (base)
            self.NoPermissions.append(base)

        result = os.popen("grep 'deny own' /etc/dbus-1/system.d/*"). \
                          read().splitlines()
        for deny in result:
            # [1::2] is a slicing which extracts odd values
            d = deny.split('"')[1::2]
            self.NoPermissions.append(d[0])
            # Only 1 per line, so take index 0
            # print (d[0])

Извините за все комментарии, но лучше оставить их на месте, чем удалять (или, что еще хуже, переписывать их ).

Для вызова подпрограммы исходная функция была изменена:

        bus = dbus.SystemBus()
        self.BuildNoPermissions(bus)
#        print ('\n=============   System services   =================\n')
#        print (self.NoPermissions, '\n')
        for service in bus.list_names():
            # Skip over ":1.20", ":1.65", etc.
            if not service.startswith(":") :
                denied = False
                for deny in self.NoPermissions:
                    if deny == service:
                        denied = True
                        break
                if denied: continue

                # print(service)
                object_path=service.replace(".", "/")
                object_path = "/" + object_path
                dictionary = self.rec_intro(bus, service, object_path)
                # print(dictionary)
                if dictionary != False :
                    listdata.append(dictionary)

Дополнительный ответ... удалить -из путей к объектам:

    if "-" in object_path :
        # Bug: https://bugs.launchpad.net/snappy/+bug/1449722
        object_path = object_path.replace("-", "")
0
28.04.2021, 23:23

Теги

Похожие вопросы