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")

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("", (dbus.UInt32)(0), (dbus.UInt32)(os.getpid()))

print granted

if granted:
print "no access"

in my code after calling

granted = policykit.ObtainAuthorization("", (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

still trying for this, thought lets share it


Colin Walters said...

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

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.

Example code: