Wednesday, May 20, 2009

facing problem while using Policykit for user authentication

I am trying to use policykit in system-config-language for authentication, so thought lets try with some test application

while doing so i am following steps given in murrayc

everything is going well
****************************************************
def write_file():
fp = open('/etc/fonts/fonts.conf', 'a')
fp.write("i have wrote")
fp.close


if __name__ == "__main__":
print "calling wrtie file"


#Call the D-Bus method to request PolicyKit authorization:
session_bus = dbus.SessionBus()
policykit = session_bus.get_object('org.freedesktop.PolicyKit.AuthenticationAgent', '/')
if(policykit == None):
print("Error: Could not get PolicyKit D-Bus Interface\n")
granted = policykit.ObtainAuthorization("test.org.gnome.lirc-properties.mechanism.configure", (dbus.UInt32)(0), (dbus.UInt32)(os.getpid()))

print granted


if granted:
write_file()
else:
print "no access"
****************************************************

in my code after calling

granted = policykit.ObtainAuthorization("test.org.gnome.lirc-properties.mechanism.configure", (dbus.UInt32)(0), (dbus.UInt32)(os.getpid()))

it is asking me for root password as per i stated in .policy file, but after entering root password, in next line when i am trying to update /etc/fonts/conf.d, it is not allowing me to do that :(

i dont know even after entering root password from policykit why my code is not able to edit above file

my all file are here
policykit

still trying for this, thought lets share it

2 comments:

Colin Walters said...

You need a "mechanism" component which runs as root. See:

http://people.freedesktop.org/~david/polkit-spec.html

Basically you might have a "AppendFontConfig" method which takes an XML fragment, and then in your mechanism use policykit to determine whether the calling process has the privileges to do so.

Anonymous said...

Check out the python slip project, there is a useful example.
https://fedorahosted.org/python-slip/wiki

Example code:
https://fedorahosted.org/python-slip/browser/doc/dbus/example