summaryrefslogtreecommitdiff
path: root/src/examples
diff options
context:
space:
mode:
authorDavid Zeuthen <davidz@redhat.com>2009-05-15 15:30:25 -0400
committerDavid Zeuthen <davidz@redhat.com>2009-05-15 15:30:25 -0400
commitc8c3d835d24fc4ce5a9c596c7d55d85a0311e8d1 (patch)
treea752d649a78ae1ad961aa337621b0154040ffa97 /src/examples
parentccf8f97948205eed26dc2003ec0984b90034e8af (diff)
downloadpolkit-c8c3d835d24fc4ce5a9c596c7d55d85a0311e8d1.tar.gz
Add a pkexec(1) command
Diffstat (limited to 'src/examples')
-rw-r--r--src/examples/Makefile.am39
-rw-r--r--src/examples/frobnicate.c68
-rw-r--r--src/examples/org.freedesktop.policykit.examples.pkexec.policy.in22
3 files changed, 127 insertions, 2 deletions
diff --git a/src/examples/Makefile.am b/src/examples/Makefile.am
index 1c40863..b30155b 100644
--- a/src/examples/Makefile.am
+++ b/src/examples/Makefile.am
@@ -15,7 +15,12 @@ INCLUDES = \
-D_REENTRANT \
$(NULL)
-noinst_PROGRAMS = cancel
+bin_PROGRAMS =
+noinst_PROGRAMS =
+
+# ----------------------------------------------------------------------------------------------------
+
+noinst_PROGRAMS += cancel
cancel_SOURCES = cancel.c
@@ -24,9 +29,39 @@ cancel_CFLAGS = \
$(NULL)
cancel_LDADD = \
- $(GLIB_LDADD) \
+ $(GLIB_LIBS) \
$(top_builddir)/src/polkit/libpolkit-gobject-1.la \
$(NULL)
+
+# ----------------------------------------------------------------------------------------------------
+
+bin_PROGRAMS += pk-example-frobnicate
+
+pk_example_frobnicate_SOURCES = frobnicate.c
+
+pk_example_frobnicate_CFLAGS = \
+ $(GLIB_CFLAGS) \
+ $(NULL)
+
+pk_example_frobnicate_LDADD = \
+ $(GLIB_LIBS) \
+ $(NULL)
+
+polkit_actiondir = $(datadir)/polkit-1/actions
+
+dist_polkit_action_DATA = org.freedesktop.policykit.examples.pkexec.policy
+
+@INTLTOOL_POLICY_RULE@
+
+#check:
+# $(top_builddir)/tools/polkit-policy-file-validate-1 $(top_srcdir)/policy/$(dist_polkit_action_DATA)
+
+DISTCLEANFILES = org.freedesktop.policykit.examples.pkexec.policy
+
+EXTRA_DIST = org.freedesktop.policykit.examples.pkexec.policy.in
+
+# ----------------------------------------------------------------------------------------------------
+
clean-local :
rm -f *~
diff --git a/src/examples/frobnicate.c b/src/examples/frobnicate.c
new file mode 100644
index 0000000..6b6b8ff
--- /dev/null
+++ b/src/examples/frobnicate.c
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2009 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: David Zeuthen <davidz@redhat.com>
+ */
+
+#include <glib.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+int
+main (int argc, char *argv[])
+{
+ gchar *args;
+ gchar **env;
+ guint n;
+ int ret;
+ gchar cwd[PATH_MAX];
+
+ ret = 1;
+ args = NULL;
+ env = NULL;
+
+ if (getcwd (cwd, sizeof cwd) == NULL)
+ {
+ g_printerr ("Error getting cwd: %m");
+ goto out;
+ }
+
+ args = g_strjoinv (" ", argv);
+
+ g_print ("In pk-example-frobnicate\n");
+ g_print ("uid: %d\n", getuid ());
+ g_print ("euid: %d\n", geteuid ());
+ g_print ("args: `%s'\n", args);
+ g_print ("cwd: %s\n", cwd);
+ g_print ("environment:\n");
+
+ env = g_listenv ();
+ for (n = 0; env[n] != NULL; n++)
+ {
+ g_print (" %s=%s\n", env[n], g_getenv (env[n]));
+ }
+
+ ret = 0;
+
+ out:
+
+ g_free (args);
+ g_strfreev (env);
+
+ return ret;
+}
diff --git a/src/examples/org.freedesktop.policykit.examples.pkexec.policy.in b/src/examples/org.freedesktop.policykit.examples.pkexec.policy.in
new file mode 100644
index 0000000..b2139cf
--- /dev/null
+++ b/src/examples/org.freedesktop.policykit.examples.pkexec.policy.in
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE policyconfig PUBLIC
+ "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">
+<policyconfig>
+
+ <vendor>Examples for the PolicyKit Project</vendor>
+ <vendor_url>http://hal.freedesktop.org/docs/PolicyKit/</vendor_url>
+
+ <action id="org.freedesktop.policykit.example.pkexec.run-frobnicate">
+ <_description>Run the PolicyKit example program Frobnicate</_description>
+ <_message>Authentication is required to run the PolicyKit example program Frobnicate</_message>
+ <icon_name>audio-x-generic</icon_name> <!-- just an example -->
+ <defaults>
+ <allow_any>no</allow_any>
+ <allow_inactive>no</allow_inactive>
+ <allow_active>auth_admin_keep</allow_active>
+ </defaults>
+ <annotate key="org.freedesktop.policykit.exec.path">/usr/bin/pk-example-frobnicate</annotate>
+ </action>
+
+</policyconfig>