Your IP : 3.144.252.170


Current Path : /tmp/
Upload File :
Current File : //tmp/check.py

# -*- coding: utf-8 -*-
import dbus

# Connect to the system bus
bus = dbus.SystemBus()

# Get the PolicyKit Authority interface
proxy = bus.get_object("org.freedesktop.PolicyKit1", "/org/freedesktop/PolicyKit1/Authority")
interface = dbus.Interface(proxy, "org.freedesktop.PolicyKit1.Authority")

# ✅ First argument: Properly structured `sa{sv}`
action_name = dbus.String("org.freedesktop.policykit.exec")  # Explicit dbus.String()
action_details = dbus.Dictionary({}, signature="sv")  # Empty dictionary

# Pack as a dbus.Struct to match `(sa{sv})`
action_struct = dbus.Struct((action_name, action_details), signature="sa{sv}")

# ✅ Second argument: Empty dictionary for details `(sa{ss})`
details_struct = dbus.Struct(("", dbus.Dictionary({}, signature="ss")), signature="sa{ss}")

# ✅ Third & Fourth arguments (flags & one_shot)
flags = dbus.UInt32(1)  # Interaction flags
one_shot = dbus.Boolean(True)  # One-shot authentication check

# Call CheckAuthorization with explicitly packed arguments
try:
    result = interface.CheckAuthorization(
        action_struct,  # ✅ Now a proper `dbus.Struct`
        details_struct, # ✅ Empty details dictionary properly formatted
        flags,          # ✅ Correct UInt32 format
        one_shot        # ✅ Correct Boolean format
    )
    print("Authorization Result:", result)
except dbus.DBusException as e:
    print("D-Bus Error:", e)
except TypeError as te:
    print("Type Error:", te)