2016-12-16 12 views
7

나는 루트 권한이 필요한 메소드를 가진 파이썬 애플리케이션을 만들고있다. https://www.freedesktop.org/software/polkit/docs/0.105/polkit-apps.html에서 예 2를 찾으십시오. 아래 코드의 파이썬 버전 인 D-Bus을 통해 권한에 액세스하면 암호가 입력 된 후 루트 권한을 얻을 수 있다고 생각했지만 실행했습니다. 여전히 내 앱에서 "허가가 거부되었습니다". This 함수는 난 당신이 인용 한 파이썬 코드에서dbus와 policykit을 파이썬에서 함수에 연결하려면 어떻게해야합니까?

import dbus 

bus = dbus.SystemBus() 
proxy = bus.get_object('org.freedesktop.PolicyKit1', '/org/freedesktop/PolicyKit1/Authority') 
authority = dbus.Interface(proxy, dbus_interface='org.freedesktop.PolicyKit1.Authority') 

system_bus_name = bus.get_unique_name() 

subject = ('system-bus-name', {'name' : system_bus_name}) 
action_id = 'org.freedesktop.policykit.exec' 
details = {} 
flags = 1   # AllowUserInteraction flag 
cancellation_id = '' # No cancellation id 

result = authority.CheckAuthorization(subject, action_id, details, flags, cancellation_id) 

print result 

답변

0

를 연결하는 것을 시도하고있다 result은 성공 또는 실패를 나타 냅니까? 실패 할 경우 먼저 bus, proxy, authoritysystem_bus_name의 반환 값이 무엇인지 알아 내서 오류 범위를 좁혀 야합니다. 성공하면 result을 어떻게 사용하고 있는지 확인해야합니다.

+0

글쎄, 올바른 암호를 입력하면 성공할 수 있다고 생각합니다. 그러나 결과를 어떻게 사용하는지 모르겠으므로 여전히 길을 잃고 있습니다. 나는 문서를 시도했지만 구체적인 것을 생각해 낼 수 없었다. – answerSeeker

+0

다음은 [aptdaemon docs] (https://pythonhosted.org/aptdaemon/dbus.html#policykit-privileges)의 예입니다. –