summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Zeuthen <davidz@redhat.com>2009-01-11 17:06:25 -0500
committerDavid Zeuthen <davidz@redhat.com>2009-01-11 17:06:25 -0500
commit86ea33f920cf1000a5ab30f5e7f2c2fc7a85e89e (patch)
tree2c6e56948895e773f937b80721ae101526e4bf00
parentc1e0322e08460acd00ccdd2e6edb86416578a159 (diff)
downloadpolkit-86ea33f920cf1000a5ab30f5e7f2c2fc7a85e89e.tar.gz
add polkit-1 man page and rework cmd/options handling
-rw-r--r--data/org.freedesktop.PolicyKit1.Authority.xml1
-rw-r--r--docs/man/Makefile.am16
-rw-r--r--docs/man/PolicyKit.xml33
-rw-r--r--docs/man/polkit.xml328
-rw-r--r--src/polkit/Makefile.am4
-rw-r--r--src/polkit/polkit.h4
-rw-r--r--src/polkit/polkitactiondescription.c3
-rw-r--r--src/polkit/polkitauthority.c40
-rw-r--r--src/polkit/polkitauthority.h5
-rw-r--r--src/polkit/polkitprivate.h4
-rw-r--r--src/polkit/polkitsystembusname.c3
-rw-r--r--src/polkit/polkittypes.h3
-rw-r--r--src/programs/polkit.c206
13 files changed, 547 insertions, 103 deletions
diff --git a/data/org.freedesktop.PolicyKit1.Authority.xml b/data/org.freedesktop.PolicyKit1.Authority.xml
index 510d6a7..f99855e 100644
--- a/data/org.freedesktop.PolicyKit1.Authority.xml
+++ b/data/org.freedesktop.PolicyKit1.Authority.xml
@@ -108,6 +108,7 @@
<arg name="result" direction="out" type="i">
<annotation name="org.gtk.EggDBus.EnumType" value="AuthorizationResult"/>
</arg>
+ <arg name="attributes" direction="out" type="a{ss}"/>
</method>
</interface>
diff --git a/docs/man/Makefile.am b/docs/man/Makefile.am
index a61a882..51db971 100644
--- a/docs/man/Makefile.am
+++ b/docs/man/Makefile.am
@@ -3,16 +3,20 @@ NULL =
if MAN_PAGES_ENABLED
-man_MANS = PolicyKit-1.8 \
- $(NULL)
+man_MANS = \
+ PolicyKit-1.8 \
+ polkit-1.1 \
+ $(NULL)
-%-1.8 : %.xml
+%-1.8 %-1.1 : %.xml
$(XSLTPROC) -nonet http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl $<
endif # MAN_PAGES_ENABLED
-EXTRA_DIST= PolicyKit.xml \
- $(NULL)
+EXTRA_DIST = \
+ PolicyKit.xml \
+ polkit.xml \
+ $(NULL)
clean-local:
- rm -f *~ *.8
+ rm -f *~ *.1 *.8
diff --git a/docs/man/PolicyKit.xml b/docs/man/PolicyKit.xml
index 6cb9145..961bddd 100644
--- a/docs/man/PolicyKit.xml
+++ b/docs/man/PolicyKit.xml
@@ -1,60 +1,59 @@
<refentry id="PolicyKit-1.8">
<refentryinfo>
<title>PolicyKit-1</title>
- <date>August 2007</date>
+ <date>January 2009</date>
<productname>PolicyKit-1</productname>
</refentryinfo>
-
+
<refmeta>
<refentrytitle>PolicyKit-1</refentrytitle>
<manvolnum>8</manvolnum>
<refmiscinfo class="version"></refmiscinfo>
</refmeta>
-
+
<refnamediv>
<refname>PolicyKit-1</refname>
<refpurpose>Authorization API</refpurpose>
</refnamediv>
-
- <refsect1><title>DESCRIPTION</title>
+
+ <refsect1><title>DESCRIPTION</title>
<para>
For more information about the big picture refer to the
PolicyKit specification which can be normally be found
under <filename>/usr/share/doc</filename>.
</para>
-
+
<para>
<emphasis>TODO:</emphasis> This manual page should contain a
simple introduction to PolicyKit for a system administrator
audience. Remains to be written.
</para>
</refsect1>
-
-
- <refsect1><title>AUTHOR</title>
+
+
+ <refsect1><title>AUTHOR</title>
<para>
- Written by David Zeuthen <email>david@fubar.dk</email> with
+ Written by David Zeuthen <email>davidz@redhat.com</email> with
a lot of help from many others.
</para>
</refsect1>
-
+
<refsect1>
- <title>BUGS</title>
+ <title>BUGS</title>
<para>
Please send bug reports to either the distribution or the
polkit-devel mailing list,
- see <ulink url="http://lists.freedesktop.org/mailman/listinfo/polkit-devel"/>.
- to subscribe.
+ see the link <ulink url="http://lists.freedesktop.org/mailman/listinfo/polkit-devel"/>
+ on how to subscribe.
</para>
</refsect1>
-
+
<refsect1>
<title>SEE ALSO</title>
<para>
<citerefentry>
- <refentrytitle>polkit-adm-1</refentrytitle><manvolnum>1</manvolnum>
+ <refentrytitle>polkit-1</refentrytitle><manvolnum>1</manvolnum>
</citerefentry>
</para>
</refsect1>
</refentry>
-
diff --git a/docs/man/polkit.xml b/docs/man/polkit.xml
new file mode 100644
index 0000000..6b20b8f
--- /dev/null
+++ b/docs/man/polkit.xml
@@ -0,0 +1,328 @@
+<refentry id="PolicyKit-1.8">
+ <refentryinfo>
+ <title>polkit-1</title>
+ <date>January 2009</date>
+ <productname>PolicyKit-1</productname>
+ </refentryinfo>
+
+ <refmeta>
+ <refentrytitle>polkit-1</refentrytitle>
+ <manvolnum>1</manvolnum>
+ <refmiscinfo class="version"></refmiscinfo>
+ </refmeta>
+
+ <refnamediv>
+ <refname>polkit-1</refname>
+ <refpurpose>PolicyKit Authorization Tool</refpurpose>
+ </refnamediv>
+
+ <refsynopsisdiv>
+ <cmdsynopsis>
+ <command>polkit-1</command>
+ <arg><option>--version</option></arg>
+ <arg><option>--help</option></arg>
+ </cmdsynopsis>
+
+ <cmdsynopsis>
+ <command>polkit-1 list</command>
+ <group>
+ <arg choice="plain">
+ actions
+ <arg><option>--verbose</option></arg>
+ </arg>
+ <arg choice="plain">
+ <sbr/>
+ users
+ <arg><option>--verbose</option></arg>
+ </arg>
+ <arg choice="plain">
+ <sbr/>
+ groups
+ <arg><option>--verbose</option></arg>
+ </arg>
+ <arg choice="plain">
+ <sbr/>
+ authorizations
+ </arg>
+ <arg choice="plain">
+ <sbr/>
+ explicit-authorizations <replaceable>subject</replaceable>
+ <arg><option>--verbose</option></arg>
+ </arg>
+ </group>
+ </cmdsynopsis>
+
+ <cmdsynopsis>
+ <command>polkit-1 check</command>
+ <arg choice="plain"><replaceable>action-id</replaceable></arg>
+ </cmdsynopsis>
+
+ <cmdsynopsis>
+ <command>polkit-1 grant</command>
+ <arg choice="plain"><replaceable>subject</replaceable></arg>
+ <arg choice="plain"><replaceable>action-id</replaceable></arg>
+ </cmdsynopsis>
+
+ <cmdsynopsis>
+ <command>polkit-1 revoke</command>
+ <arg choice="plain"><replaceable>subject</replaceable></arg>
+ <arg choice="plain"><replaceable>action-id</replaceable></arg>
+ </cmdsynopsis>
+
+ <cmdsynopsis>
+ <command>polkit-1 action</command>
+ <arg choice="plain"><replaceable>action-id</replaceable></arg>
+ <sbr/>
+ <group>
+ <arg choice="plain">
+ set-implicit-any
+ <replaceable>value</replaceable>
+ </arg>
+ <arg choice="plain">
+ <sbr/>
+ set-implicit-inactive
+ <replaceable>value</replaceable>
+ </arg>
+ <arg choice="plain">
+ <sbr/>
+ set-implicit-active
+ <replaceable>value</replaceable>
+ </arg>
+ <arg choice="plain">
+ <sbr/>
+ reset-implicit
+ </arg>
+ </group>
+ </cmdsynopsis>
+
+ <cmdsynopsis>
+ <command>polkit-1 run</command>
+ <arg choice="plain"><replaceable>action-id</replaceable></arg>
+ <arg choice="plain"><replaceable>PROGRAM</replaceable></arg>
+ <group rep="repeat">
+ <arg choice="plain"><replaceable>ARGUMENTS</replaceable></arg>
+ </group>
+ </cmdsynopsis>
+
+ </refsynopsisdiv>
+
+ <refsect1><title>DESCRIPTION</title>
+ <para>
+ Manage PolicyKit authorizations.
+ </para>
+ </refsect1>
+
+ <refsect1>
+ <title>OPTIONS</title>
+ <variablelist>
+ <varlistentry>
+ <term><option>--version</option></term>
+ <listitem>
+ <para>
+ Show version and exit.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><option>--help</option></term>
+ <listitem>
+ <para>
+ Show this information.
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+
+ <refsect2>
+ <para>
+ <command>polkit-1 list actions</command>
+ <arg><option>--verbose</option></arg>
+ </para>
+ <para>
+ Lists all identifiers for registered PolicyKit actions. The returned identifiers can be
+ used as <replaceable>action-id</replaceable> parameters.
+ Prints detailed information about each action if <option>--verbose</option> is given.
+ </para>
+ </refsect2>
+
+ <refsect2>
+ <para>
+ <command>polkit-1 list users</command>
+ <arg><option>--verbose</option></arg>
+ </para>
+ <para>
+ Lists all users.
+ The returned identifiers can be used as <replaceable>subject</replaceable> parameters.
+ Prints detailed information about each user if <option>--verbose</option> is given.
+ </para>
+ </refsect2>
+
+ <refsect2>
+ <para>
+ <command>polkit-1 list groups</command>
+ <arg><option>--verbose</option></arg>
+ </para>
+ <para>
+ Lists all groups.
+ The returned identifiers can be used as <replaceable>subject</replaceable> parameters.
+ Prints detailed information about each group if <option>--verbose</option> is given.
+ </para>
+ </refsect2>
+
+ <refsect2>
+ <para>
+ <command>polkit-1 list authorizations</command>
+ </para>
+ <para>
+ Lists all <replaceable>action-id</replaceable>s that the calling process is authorized for.
+ </para>
+ </refsect2>
+
+ <refsect2>
+ <para>
+ <command>polkit-1 list explicit-authorizations <replaceable>subject</replaceable></command>
+ <arg><option>--verbose</option></arg>
+ </para>
+ <para>
+ Lists all explicit authorizations for <replaceable>subject</replaceable>.
+ Prints detailed information about each authorization if <option>--verbose</option> is given.
+ </para>
+ </refsect2>
+
+ <refsect2>
+ <para>
+ <command>polkit-1 check</command>
+ <arg choice="plain"><replaceable>action-id</replaceable></arg>
+ </para>
+ <para>
+ Checks if the calling process is authorized for <replaceable>action-id</replaceable>.
+ </para>
+ </refsect2>
+
+ <refsect2>
+ <para>
+ <command>polkit-1 grant</command>
+ <arg choice="plain"><replaceable>subject</replaceable></arg>
+ <arg choice="plain"><replaceable>action-id</replaceable></arg>
+ </para>
+ <para>
+ Grants an authorization to <replaceable>subject</replaceable> for <replaceable>action-id</replaceable>.
+ </para>
+ </refsect2>
+
+ <refsect2>
+ <para>
+ <command>polkit-1 revoke</command>
+ <arg choice="plain"><replaceable>subject</replaceable></arg>
+ <arg choice="plain"><replaceable>action-id</replaceable></arg>
+ </para>
+ <para>
+ Revokes an authorization from <replaceable>subject</replaceable> for <replaceable>action-id</replaceable>.
+ </para>
+ </refsect2>
+
+ <refsect2>
+ <para>
+ <command>polkit-1 action</command>
+ <arg choice="plain"><replaceable>action-id</replaceable></arg>
+ <arg choice="plain">
+ set-implicit-any
+ <replaceable>value</replaceable>
+ </arg>
+ </para>
+ <para>
+ Sets the implicit authorizations on
+ <replaceable>action-id</replaceable> to <replaceable>value</replaceable>.
+ </para>
+ </refsect2>
+
+ <refsect2>
+ <para>
+ <command>polkit-1 action</command>
+ <arg choice="plain"><replaceable>action-id</replaceable></arg>
+ <arg choice="plain">
+ set-implicit-inactive
+ <replaceable>value</replaceable>
+ </arg>
+ </para>
+ <para>
+ Sets the implicit authorizations for local inactive sessions on
+ <replaceable>action-id</replaceable> to <replaceable>value</replaceable>.
+ </para>
+ </refsect2>
+
+ <refsect2>
+ <para>
+ <command>polkit-1 action</command>
+ <arg choice="plain"><replaceable>action-id</replaceable></arg>
+ <arg choice="plain">
+ set-implicit-active
+ <replaceable>value</replaceable>
+ </arg>
+ </para>
+ <para>
+ Sets the implicit authorizations for local active sessions on
+ <replaceable>action-id</replaceable> to <replaceable>value</replaceable>.
+ </para>
+ </refsect2>
+
+ <refsect2>
+ <para>
+ <command>polkit-1 action</command>
+ <arg choice="plain"><replaceable>action-id</replaceable></arg>
+ <arg choice="plain">
+ reset-implicit
+ </arg>
+ </para>
+ <para>
+ Resets all implicit authorizations on <replaceable>action-id</replaceable> to factory defaults.
+ </para>
+ </refsect2>
+
+ <refsect2>
+ <para>
+ <command>polkit-1 run</command>
+ <arg choice="plain"><replaceable>action-id</replaceable></arg>
+ <arg choice="plain"><replaceable>PROGRAM</replaceable></arg>
+ <group rep="repeat">
+ <arg choice="plain"><replaceable>ARGUMENTS</replaceable></arg>
+ </group>
+ </para>
+ <para>
+ Attempts to ensure that a PolicyKit authorization for <replaceable>action-id</replaceable>
+ is available and runs the <replaceable>PROGRAM</replaceable> if an authorization is
+ in place. This may involve having to make the user obtain the authorization through
+ authentication. If an authorization cannot be obtained, <replaceable>PROGRAM</replaceable>
+ will not be runned.
+ </para>
+ </refsect2>
+
+ </refsect1>
+
+ <refsect1><title>AUTHOR</title>
+ <para>
+ Written by David Zeuthen <email>davidz@redhat.com</email> with
+ a lot of help from many others.
+ </para>
+ </refsect1>
+
+ <refsect1>
+ <title>BUGS</title>
+ <para>
+ Please send bug reports to either the distribution or the
+ polkit-devel mailing list,
+ see the link <ulink url="http://lists.freedesktop.org/mailman/listinfo/polkit-devel"/>
+ on how to subscribe.
+ </para>
+ </refsect1>
+
+ <refsect1>
+ <title>SEE ALSO</title>
+ <para>
+ <citerefentry>
+ <refentrytitle>PolicyKit-1</refentrytitle><manvolnum>8</manvolnum>
+ </citerefentry>
+ </para>
+ </refsect1>
+</refentry>
diff --git a/src/polkit/Makefile.am b/src/polkit/Makefile.am
index 1761076..8caf9d8 100644
--- a/src/polkit/Makefile.am
+++ b/src/polkit/Makefile.am
@@ -48,6 +48,8 @@ libpolkit_gobject_1include_HEADERS = \
polkitunixgroup.h \
polkitunixprocess.h \
polkitsystembusname.h \
+ polkitauthorizationclaim.h \
+ polkitauthorizationresult.h \
$(NULL)
libpolkit_gobject_1_la_SOURCES = \
@@ -61,6 +63,8 @@ libpolkit_gobject_1_la_SOURCES = \
polkitunixgroup.c polkitunixgroup.h \
polkitunixprocess.c polkitunixprocess.h \
polkitsystembusname.c polkitsystembusname.h \
+ polkitauthorizationclaim.c polkitauthorizationclaim.h \
+ polkitauthorizationresult.c polkitauthorizationresult.h \
$(NULL)
libpolkit_gobject_1_la_CFLAGS = \
diff --git a/src/polkit/polkit.h b/src/polkit/polkit.h
index 1520fed..c81d14e 100644
--- a/src/polkit/polkit.h
+++ b/src/polkit/polkit.h
@@ -25,13 +25,15 @@
#define _POLKIT_INSIDE_POLKIT_H 1
#include <polkit/polkitactiondescription.h>
-#include <polkit/polkitauthority.h>
#include <polkit/polkiterror.h>
#include <polkit/polkitsubject.h>
#include <polkit/polkitunixuser.h>
#include <polkit/polkitunixgroup.h>
#include <polkit/polkitunixprocess.h>
#include <polkit/polkitsystembusname.h>
+#include <polkit/polkitauthorizationclaim.h>
+#include <polkit/polkitauthorizationresult.h>
+#include <polkit/polkitauthority.h>
#undef _POLKIT_INSIDE_POLKIT_H
diff --git a/src/polkit/polkitactiondescription.c b/src/polkit/polkitactiondescription.c
index 83de4f9..2133024 100644
--- a/src/polkit/polkitactiondescription.c
+++ b/src/polkit/polkitactiondescription.c
@@ -73,6 +73,9 @@ polkit_action_description_finalize (GObject *object)
if (action_description->icon != NULL)
g_object_unref (action_description->icon);
+
+ if (G_OBJECT_CLASS (polkit_action_description_parent_class)->finalize != NULL)
+ G_OBJECT_CLASS (polkit_action_description_parent_class)->finalize (object);
}
static void
diff --git a/src/polkit/polkitauthority.c b/src/polkit/polkitauthority.c
index 6e74e5e..bb4d1c6 100644
--- a/src/polkit/polkitauthority.c
+++ b/src/polkit/polkitauthority.c
@@ -23,6 +23,7 @@
# include "config.h"
#endif
+#include "polkitauthorizationresult.h"
#include "polkitauthority.h"
#include "polkitprivate.h"
@@ -82,6 +83,9 @@ polkit_authority_finalize (GObject *object)
g_object_unref (authority->authority_object_proxy);
the_authority = NULL;
+
+ if (G_OBJECT_CLASS (polkit_authority_parent_class)->finalize != NULL)
+ G_OBJECT_CLASS (polkit_authority_parent_class)->finalize (object);
}
static void
@@ -210,3 +214,39 @@ polkit_authority_enumerate_groups_sync (PolkitAuthority *authority,
out:
return result;
}
+
+PolkitAuthorizationResult
+polkit_authority_check_claim_sync (PolkitAuthority *authority,
+ PolkitAuthorizationClaim *claim,
+ GCancellable *cancellable,
+ GError **error)
+{
+ _PolkitAuthorizationResult result;
+ _PolkitAuthorizationClaim *real_claim;
+ EggDBusHashMap *result_attributes;
+
+ result = _POLKIT_AUTHORIZATION_RESULT_NOT_AUTHORIZED;
+ real_claim = NULL;
+
+ real_claim = polkit_authorization_claim_get_real (claim);
+
+ if (!_polkit_authority_check_claim_sync (authority->real,
+ EGG_DBUS_CALL_FLAGS_NONE,
+ real_claim,
+ &result,
+ &result_attributes,
+ cancellable,
+ error))
+ goto out;
+
+ /* TODO: pass these back */
+ if (result_attributes != NULL)
+ g_object_unref (result_attributes);
+
+ out:
+ if (real_claim != NULL)
+ g_object_unref (real_claim);
+
+ return result;
+}
+
diff --git a/src/polkit/polkitauthority.h b/src/polkit/polkitauthority.h
index 1cb49f6..0e4a45e 100644
--- a/src/polkit/polkitauthority.h
+++ b/src/polkit/polkitauthority.h
@@ -57,6 +57,11 @@ GList *polkit_authority_enumerate_groups_sync (PolkitAuthorit
GCancellable *cancellable,
GError **error);
+PolkitAuthorizationResult polkit_authority_check_claim_sync (PolkitAuthority *authority,
+ PolkitAuthorizationClaim *claim,
+ GCancellable *cancellable,
+ GError **error);
+
G_END_DECLS
#endif /* __POLKIT_AUTHORITY_H */
diff --git a/src/polkit/polkitprivate.h b/src/polkit/polkitprivate.h
index 70662d1..9976fad 100644
--- a/src/polkit/polkitprivate.h
+++ b/src/polkit/polkitprivate.h
@@ -23,6 +23,8 @@
#define __POLKIT_PRIVATE_H
#include "polkitactiondescription.h"
+#include "polkitsubject.h"
+#include "polkitauthorizationclaim.h"
#include "_polkitbindings.h"
/* notes:
@@ -38,6 +40,8 @@ _PolkitActionDescription *polkit_action_description_get_real (PolkitActionDe
PolkitSubject *polkit_subject_new_for_real (_PolkitSubject *real);
_PolkitSubject *polkit_subject_get_real (PolkitSubject *subject);
+PolkitAuthorizationClaim *polkit_authorization_claim_new_for_real (_PolkitAuthorizationClaim *real);
+_PolkitAuthorizationClaim *polkit_authorization_claim_get_real (PolkitAuthorizationClaim *claim);
#endif /* __POLKIT_PRIVATE_H */
diff --git a/src/polkit/polkitsystembusname.c b/src/polkit/polkitsystembusname.c
index ec069e5..7045dbe 100644
--- a/src/polkit/polkitsystembusname.c
+++ b/src/polkit/polkitsystembusname.c
@@ -71,6 +71,9 @@ polkit_system_bus_name_finalize (GObject *object)
PolkitSystemBusName *system_bus_name = POLKIT_SYSTEM_BUS_NAME (object);
g_free (system_bus_name->name);
+
+ if (G_OBJECT_CLASS (polkit_system_bus_name_parent_class)->finalize != NULL)
+ G_OBJECT_CLASS (polkit_system_bus_name_parent_class)->finalize (object);
}
static void
diff --git a/src/polkit/polkittypes.h b/src/polkit/polkittypes.h
index 8e0c3f5..235f92d 100644
--- a/src/polkit/polkittypes.h
+++ b/src/polkit/polkittypes.h
@@ -44,5 +44,8 @@ typedef struct _PolkitUnixProcess PolkitUnixProcess;
struct _PolkitSystemBusName;
typedef struct _PolkitSystemBusName PolkitSystemBusName;
+struct _PolkitAuthorizationClaim;
+typedef struct _PolkitAuthorizationClaim PolkitAuthorizationClaim;
+
#endif /* __POLKIT_TYPES_H */
diff --git a/src/programs/polkit.c b/src/programs/polkit.c
index 7da08e5..126488b 100644
--- a/src/programs/polkit.c
+++ b/src/programs/polkit.c
@@ -31,17 +31,15 @@ static PolkitAuthority *authority;
static gboolean opt_list_actions = FALSE;
static gboolean opt_list_users = FALSE;
static gboolean opt_list_groups = FALSE;
-static gchar *opt_show_action = NULL;
+static gboolean opt_list_authorizations = FALSE;
+static gboolean opt_list_explicit_authorizations = FALSE;
+
+static gboolean opt_show_help = FALSE;
static gboolean opt_show_version = FALSE;
-static GOptionEntry option_entries[] = {
- {"list-actions", 'l', 0, G_OPTION_ARG_NONE, &opt_list_actions, "List registered actions", NULL},
- {"list-users", 0, 0, G_OPTION_ARG_NONE, &opt_list_users, "List known users", NULL},
- {"list-groups", 0, 0, G_OPTION_ARG_NONE, &opt_list_groups, "List known groups", NULL},
- {"show-action", 's', 0, G_OPTION_ARG_STRING, &opt_show_action, "Show details for an action", "action_id"},
- {"version", 'V', 0, G_OPTION_ARG_NONE, &opt_show_version, "Show version", NULL},
- {NULL, },
-};
+static gboolean opt_verbose = FALSE;
+
+static PolkitSubject *subject;
static gboolean list_actions (void);
static gboolean list_users (void);
@@ -49,31 +47,122 @@ static gboolean list_groups (void);
static gboolean show_action (const gchar *action_id);
+static void
+usage (int argc, char *argv[])
+{
+ GError *error;
+
+ error = NULL;
+ if (!g_spawn_command_line_sync ("man polkit-1",
+ NULL,
+ NULL,
+ NULL,
+ &error))
+ {
+ g_printerr ("Cannot show manual page: %s\n", error->message);
+ g_error_free (error);
+ }
+}
+
int
main (int argc, char *argv[])
{
gboolean ret;
- GError *error;
- GOptionContext *option_ctx;
+ gint n;
+ gboolean in_list;
ret = FALSE;
g_type_init ();
- option_ctx = g_option_context_new ("polkit-1");
- g_option_context_add_main_entries (option_ctx, option_entries, NULL);
- g_option_context_set_summary (option_ctx, "PolicyKit commandline tool");
- error = NULL;
- if (!g_option_context_parse (option_ctx, &argc, &argv, &error))
+ in_list = FALSE;
+ for (n = 1; n < argc; n++)
{
- g_printerr ("Error parsing options: %s\n", error->message);
- g_error_free (error);
- goto out;
+ if (in_list)
+ {
+ if (strcmp (argv[n], "actions") == 0)
+ {
+ opt_list_actions = TRUE;
+ }
+ else if (strcmp (argv[n], "users") == 0)
+ {
+ opt_list_users = TRUE;
+ }
+ else if (strcmp (argv[n], "groups") == 0)
+ {
+ opt_list_groups = TRUE;
+ }
+ else if (strcmp (argv[n], "authorizations") == 0)
+ {
+ opt_list_authorizations = TRUE;
+ }
+ else if (strcmp (argv[n], "explicit-authorizations") == 0)
+ {
+ opt_list_explicit_authorizations = TRUE;
+
+ n++;
+ if (n >= argc)
+ {
+ usage (argc, argv);
+ goto out;
+ }
+
+ subject = NULL; //polkit_subject_from_string (argv[n]);
+ if (subject == NULL)
+ {
+ g_printerr ("Malformed subject identifier '%s'", argv[n]);
+ goto out;
+ }
+
+ }
+ else
+ {
+ usage (argc, argv);
+ goto out;
+ }
+
+ in_list = FALSE;
+ }
+ else if (strcmp (argv[n], "list") == 0)
+ {
+ in_list = TRUE;
+ continue;
+ }
+ else if (strcmp (argv[n], "--help") == 0)
+ {
+ opt_show_help = TRUE;
+ }
+ else if (strcmp (argv[n], "--version") == 0)
+ {
+ opt_show_version = TRUE;
+ }
+ else if (strcmp (argv[n], "--verbose") == 0)
+ {
+ opt_verbose = TRUE;
+ }
+ else
+ {
+ usage (argc, argv);
+ goto out;
+ }
}
authority = polkit_authority_get ();
- if (opt_list_actions)
+ if (opt_show_help)
+ {
+ usage (argc, argv);
+ ret = TRUE;
+ goto out;
+ }
+ else if (opt_show_version)
+ {
+ g_print ("PolicyKit version %s\n", PACKAGE_VERSION);
+ /* TODO: print backend name / version */
+ ret = TRUE;
+ goto out;
+ }
+ else if (opt_list_actions)
{
ret = list_actions ();
}
@@ -85,33 +174,18 @@ main (int argc, char *argv[])
{
ret = list_groups ();
}
- else if (opt_show_action != NULL)
- {
- ret = show_action (opt_show_action);
- }
- else if (opt_show_version)
- {
- g_print ("polkit-1 %s\n", PACKAGE_VERSION);
- ret = TRUE;
- }
else
{
- gchar *s;
-
- /* print usage */
- s = g_option_context_get_help (option_ctx, TRUE, NULL);
- g_print ("%s", s);
- g_free (s);
- ret = 0;
- goto out;
+ usage (argc, argv);
}
- g_object_unref (authority);
-
- g_option_context_free (option_ctx);
out:
- g_free (opt_show_action);
+ if (authority != NULL)
+ g_object_unref (authority);
+
+ if (subject != NULL)
+ g_object_unref (subject);
return ret ? 0 : 1;
}
@@ -234,8 +308,19 @@ list_actions (void)
for (l = actions; l != NULL; l = l->next)
{
PolkitActionDescription *action = POLKIT_ACTION_DESCRIPTION (l->data);
+ const gchar *action_id;
- g_print ("%s\n", polkit_action_description_get_action_id (action));
+ action_id = polkit_action_description_get_action_id (action);
+
+ if (opt_verbose)
+ {
+ show_action (action_id);
+ g_print ("\n");
+ }
+ else
+ {
+ g_print ("%s\n", action_id);
+ }
}
g_list_foreach (actions, (GFunc) g_object_unref, NULL);
@@ -324,40 +409,3 @@ list_groups (void)
out:
return ret;
}
-
-
-#if 0
- PolkitSubject *subject1;
- PolkitSubject *subject2;
- PolkitSubject *subject3;
-
- subject1 = polkit_user_new ("moe");
- subject2 = polkit_user_new ("bernie");
- subject3 = polkit_process_new (42);
-
- GList *claims;
- claims = NULL;
- claims = g_list_prepend (claims, polkit_authorization_claim_new (subject1, "org.foo.1"));
- claims = g_list_prepend (claims, polkit_authorization_claim_new (subject2, "org.foo.2"));
- claims = g_list_prepend (claims, polkit_authorization_claim_new (subject3, "org.foo.3"));
-
- PolkitAuthorizationClaim *claim;
- claim = polkit_authorization_claim_new (subject3, "org.foo.4");
- polkit_authorization_claim_set_attribute (claim, "foo", "bar");
- polkit_authorization_claim_set_attribute (claim, "unix-device", "/dev/sda");
- claims = g_list_prepend (claims, claim);
-
-
- error = NULL;
- result = polkit_authority_check_claims_sync (authority,
- claims,
- NULL,
- &error);
- if (error != NULL) {
- g_print ("Got error: %s\n", error->message);
- g_error_free (error);
- } else {
- g_print ("Got result: %d\n", result);
- }
-
-#endif