Kaydet (Commit) 0fad819c authored tarafından Bahadır Kandemir's avatar Bahadır Kandemir

Use polkit-auth

üst 5d0d275d
2009-06-04 Bahadır Kandemir <bahadir@pardus.org.tr>
* api: Use polkit-auth
2009-05-11 Bahadır Kandemir <bahadir@pardus.org.tr> 2009-05-11 Bahadır Kandemir <bahadir@pardus.org.tr>
* network: callScrip(profile, state) for executing profile scripts under * network: callScrip(profile, state) for executing profile scripts under
/etc/network/netlink.d/profilename.state /etc/network/netlink.d/profilename.state
......
...@@ -31,6 +31,9 @@ Asynchronous calls: ...@@ -31,6 +31,9 @@ Asynchronous calls:
# Localize strings # Localize strings
link.setLocale() link.setLocale()
# Use authentication agent (GUI)
link.useAgent()
# Make an asynchronous call to get service information # Make an asynchronous call to get service information
def handler(package, exception, result): def handler(package, exception, result):
if exception: if exception:
...@@ -49,5 +52,7 @@ Connecting COMAR service on alternate destination: ...@@ -49,5 +52,7 @@ Connecting COMAR service on alternate destination:
This will simply try to connect tr.org.pardus.comar2 instead This will simply try to connect tr.org.pardus.comar2 instead
of tr.org.pardus.comar of tr.org.pardus.comar
COMAR 3.0's primary destination is tr.org.pardus.comar3 and Connecting to alternative DBus server:
alternate destination is tr.org.pardus.comar3.updated
import comar
link = comar.Link(socket="/mnt/target/var/run/dbus/system_bus_socket")
...@@ -14,6 +14,7 @@ __version__ = '2.4.1' ...@@ -14,6 +14,7 @@ __version__ = '2.4.1'
import dbus import dbus
import locale import locale
import os import os
import subprocess
class Call: class Call:
def __init__(self, link, group, class_=None, package=None, method=None): def __init__(self, link, group, class_=None, package=None, method=None):
...@@ -128,18 +129,12 @@ class Call: ...@@ -128,18 +129,12 @@ class Call:
raise AttributeError, "Package name required for non-async calls." raise AttributeError, "Package name required for non-async calls."
def queryPolicyKit(self, action): def queryPolicyKit(self, action):
if "DISPLAY" not in os.environ: if not self.link.useAgent:
raise Exception, "X session required to query PolKit" os.environ["POLKIT_AUTH_FORCE_TEXT"] = "1"
bus = dbus.SessionBus() ret = subprocess.call(["/usr/bin/polkit-auth", "--obtain", action])
try: if ret == 0:
obj = bus.get_object("org.freedesktop.PolicyKit.AuthenticationAgent", "/") return True
except dbus.DBusException, exception: return False
return False
iface = dbus.Interface(obj, "org.freedesktop.PolicyKit.AuthenticationAgent")
try:
return iface.ObtainAuthorization(action, 0, os.getpid(), timeout=2**16-1) == 1
except:
return False
class Link: class Link:
...@@ -148,6 +143,7 @@ class Link: ...@@ -148,6 +143,7 @@ class Link:
self.address = "tr.org.pardus.comar" self.address = "tr.org.pardus.comar"
self.interface = "tr.org.pardus.comar" self.interface = "tr.org.pardus.comar"
self.socket = socket self.socket = socket
self.useAgent = False
if not socket: if not socket:
self.bus = dbus.SystemBus() self.bus = dbus.SystemBus()
...@@ -157,6 +153,9 @@ class Link: ...@@ -157,6 +153,9 @@ class Link:
if alternate: if alternate:
self.address += "2" self.address += "2"
def useAgent(self, agent=True):
self.useAgent = agent
def setLocale(self): def setLocale(self):
try: try:
code, encoding = locale.getdefaultlocale() code, encoding = locale.getdefaultlocale()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment