From 6bbd5189e967e8ddc36100bf22cd12bcb152ab5f Mon Sep 17 00:00:00 2001 From: David Zeuthen Date: Tue, 20 Sep 2011 14:13:12 -0400 Subject: Add support for the org.freedesktop.policykit.imply annotation For example, GNOME control center can now defined e.g. Meta Action Example of a meta action, blabla no no auth_admin_keep org.freedesktop.udisks2.ata-smart-selftest org.freedesktop.udisks2.encrypted-lock-others org.freedesktop.udisks2.filesystem-unmount-others and set up a single GtkLockButton for a PolkitPermission for action id "org.zee.example.meta". When unlocked the given subject will now be authorized for the actions mentioned in the annotation. Example test program: int main (int argc, char *argv[]) { PolkitSubject *subject; GtkWidget *window; GtkWidget *table; GMainLoop *loop; guint n; gtk_init (&argc, &argv); subject = polkit_unix_process_new (getpid ()); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); table = gtk_table_new (1, 2, FALSE); for (n = 1; n < argc; n++) { const gchar *action_id = argv[n]; GPermission *permission; GtkWidget *label; GtkWidget *lock_button; GError *error = NULL; label = gtk_label_new (action_id); permission = polkit_permission_new_sync (action_id, subject, NULL, &error); if (permission == NULL) { g_error ("Error constructing permission for action_id %s: %s (%s, %d)", action_id, error->message, g_quark_to_string (error->domain), error->code); goto out; } lock_button = gtk_lock_button_new (permission); g_object_unref (permission); gtk_table_attach (GTK_TABLE (table), label, 0, 1, n - 1, n, GTK_FILL, GTK_FILL, 0, 0); gtk_table_attach (GTK_TABLE (table), lock_button, 1, 2, n - 1, n, GTK_FILL, GTK_FILL, 0, 0); } gtk_container_add (GTK_CONTAINER (window), table); gtk_widget_show_all (window); loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (loop); out: ; } Compile with: gcc -o showpolkit showpolkit.c `pkg-config --cflags --libs polkit-gobject-1 gtk+-3.0` -g -O0 Run with: ./showpolkit org.freedesktop.udisks2.ata-smart-selftest org.freedesktop.udisks2.encrypted-lock-others org.freedesktop.udisks2.filesystem-unmount-others org.zee.example.meta Signed-off-by: David Zeuthen --- docs/man/polkit.xml | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'docs') diff --git a/docs/man/polkit.xml b/docs/man/polkit.xml index bcb276b..bfa5ccd 100644 --- a/docs/man/polkit.xml +++ b/docs/man/polkit.xml @@ -369,8 +369,7 @@ System Context | | the key attribute and the value is specified using the value attribute. This element may appear zero or more times. See - pkexec1 - for an example of how this can be used. + below for known annotations. vendor @@ -398,6 +397,28 @@ System Context | | pkaction1 command. + + Known annotations + + The org.freedesktop.policykit.exec.path + annotation is used by the pkexec program + shipped with PolicyKit - see the + pkexec1 + man page for details. + + + The org.freedesktop.policykit.imply + annotation (its value is a string containing a space separated + list of action identifiers) can be used to define meta + actions. The way it works is that if a subject is + authorized for an action with this annotation, then it is also + authorized for any action specified by the annotation. A typical + use of this annotation is when defining an UI shell with a + single lock button that should unlock multiple actions from + distinct mechanisms. + + + AUTHOR -- cgit v1.2.1