PolicyKit from Python

Murray Cumming murrayc at murrayc.com
Fri Feb 8 05:28:52 PST 2008


On Thu, 2008-02-07 at 22:43 +0800, David Zeuthen wrote:
> Hi,
> 
> Sorry for the lag, have been on vacation since Jan 19 and won't return
> back home until late next week.
> 
> On Mon, 2008-02-04 at 01:21 +0100, Murray Cumming wrote:
> > Hi. Sorry for the direct email, but I can't google up a PolicyKit
> > mailing list, or even a website. Feel free to CC any reply.
> 
> Yeah, the hal list. I've added it as Cc.
> 
> > Do you happen to know if there are already PolicyKit (and
> > policykit-gnome) python bindings?
> 
> Nope, not yet. Though with 0.7 the main functionality is expressed via a
> D-Bus system bus service too 
> 
> http://gitweb.freedesktop.org/?p=PolicyKit.git;a=blob;h=4539043c84c34df7745c9524af58b7fe60d24862;hb=4cfb96627a5afbe34c0bc583bdcf4caf306bf1a5;f=polkitd/org.freedesktop.PolicyKit.xml
> 
> Basically what you want is IsProcessAuthorized();

Thanks. The return type is a little odd. It's a string, but where are
the possible values documented?

For instance, with the attached test case:
- if my action ID does not really exist, I get "no"
- if I am not authorized, I get "auth_self_keep_always"
- if I am authorized, I get "yes"


Here is the introspected interface, for reference:

$ dbus-send --system --print-reply --dest=org.freedesktop.PolicyKit /
org.freedesktop.DBus.Introspectable.Introspect
method return sender=:1.235 -> dest=:1.234 reply_serial=2
   string "<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object
Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
  <interface name="org.freedesktop.DBus.Introspectable">
    <method name="Introspect">
      <arg name="data" direction="out" type="s"/>
    </method>
  </interface>
  <interface name="org.freedesktop.DBus.Properties">
    <method name="Get">
      <arg name="interface" direction="in" type="s"/>
      <arg name="propname" direction="in" type="s"/>
      <arg name="value" direction="out" type="v"/>
    </method>
    <method name="Set">
      <arg name="interface" direction="in" type="s"/>
      <arg name="propname" direction="in" type="s"/>
      <arg name="value" direction="in" type="v"/>
    </method>
  </interface>
  <interface name="org.freedesktop.PolicyKit">
    <method name="IsSystemBusNameAuthorized">
      <arg name="action_id" type="s" direction="in"/>
      <arg name="system_bus_name" type="s" direction="in"/>
      <arg name="revoke_if_one_shot" type="b" direction="in"/>
      <arg name="result" type="s" direction="out"/>
    </method>
    <method name="IsProcessAuthorized">
      <arg name="action_id" type="s" direction="in"/>
      <arg name="pid" type="u" direction="in"/>
      <arg name="revoke_if_one_shot" type="b" direction="in"/>
      <arg name="result" type="s" direction="out"/>
    </method>
  </interface>
</node>
"


-- 
murrayc at murrayc.com
www.murrayc.com
www.openismus.com
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_policy_kit_is_authorized.py
Type: text/x-python
Size: 993 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/hal/attachments/20080208/c212f20a/attachment.py 


More information about the hal mailing list