summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2011-10-11 22:36:19 -0500
committerDan Williams <dcbw@redhat.com>2011-10-11 22:37:50 -0500
commit784e6cb684d786cb1c1415c4d1d2f0e231b18d04 (patch)
tree16f392e6ae6b939054dec40792a69dd52ade0017
parentd591c284aa4dc737098a312071b122a2fa14f551 (diff)
downloadNetworkManager-784e6cb684d786cb1c1415c4d1d2f0e231b18d04.tar.gz
polkit: remove unused code and tighten up polkit stubs
-rw-r--r--src/nm-polkit.c75
-rw-r--r--src/nm-polkit.h163
2 files changed, 83 insertions, 155 deletions
diff --git a/src/nm-polkit.c b/src/nm-polkit.c
index 6e092bb4bb..fd9a258621 100644
--- a/src/nm-polkit.c
+++ b/src/nm-polkit.c
@@ -14,88 +14,21 @@
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * (C) Copyright 2008 Novell, Inc.
- * (C) Copyright 2008 - 2010 Red Hat, Inc.
*/
-#include "nm-polkit.h"
+#include <config.h>
#if !HAVE_POLKIT
-G_DEFINE_TYPE (PolkitSubject, polkit_subject, G_TYPE_OBJECT);
+#include "nm-polkit.h"
+
G_DEFINE_TYPE (PolkitAuthority, polkit_authority, G_TYPE_OBJECT);
G_DEFINE_TYPE (PolkitAuthorizationResult, polkit_authorization_result, G_TYPE_OBJECT);
-static void polkit_subject_init (PolkitSubject *self) { }
+
static void polkit_authority_init (PolkitAuthority *self) { }
static void polkit_authorization_result_init (PolkitAuthorizationResult *self) { }
-static void polkit_subject_class_init (PolkitSubjectClass *klass) { }
static void polkit_authority_class_init (PolkitAuthorityClass *klass) { }
static void polkit_authorization_result_class_init (PolkitAuthorizationResultClass *klass) { }
-PolkitAuthority *polkit_authority_get (void)
-{
- return POLKIT_AUTHORITY (g_object_new (POLKIT_TYPE_AUTHORITY, NULL));
-}
-
-void polkit_authority_check_authorization (PolkitAuthority *authority,
- PolkitSubject *subject,
- const gchar *action_id,
- gpointer details,
- PolkitCheckAuthorizationFlags flags,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
-{
- GSimpleAsyncResult *dummy_result = g_simple_async_result_new(G_OBJECT (authority),
- callback,
- user_data,
- NULL);
- /* This will invoke the callback from the idle loop. The callback won't
- look at the contents of dummy_result, it will merely pass it into
- ..._finish() */
- g_simple_async_result_complete_in_idle (dummy_result);
-}
-
-PolkitAuthorizationResult *polkit_authority_check_authorization_finish (PolkitAuthority *authority,
- GAsyncResult *res,
- GError **error)
-{
- /* Again, the contents of the returned object don't matter, as the caller
- will only use it via ..._get_is_authorized and ..._get_is_challenge,
- below. */
- return POLKIT_AUTHORIZATION_RESULT (g_object_new (POLKIT_TYPE_AUTHORIZATION_RESULT, NULL));
-}
-gboolean polkit_authorization_result_get_is_authorized (PolkitAuthorizationResult *result)
-{
- return TRUE;
-}
-gboolean polkit_authorization_result_get_is_challenge (PolkitAuthorizationResult *result)
-{
- return FALSE;
-}
-
-PolkitSubject *polkit_system_bus_name_new (const gchar *name)
-{
- /* The contents of the returned object don't matter, as the caller will
- merely pass it as a parameter to polkit_authority_check_authorization. */
- return POLKIT_SUBJECT (g_object_new (POLKIT_TYPE_SUBJECT, NULL));
-}
-
#endif /* !HAVE_POLKIT */
-
-#if !HAVE_POLKIT || !HAVE_POLKIT_AUTHORITY_GET_SYNC
-
-PolkitAuthority *
-polkit_authority_get_sync (GCancellable *cancellable, GError **error)
-{
- PolkitAuthority *authority;
-
- authority = polkit_authority_get ();
- if (!authority)
- g_set_error (error, 0, 0, "failed to get the PolicyKit authority");
- return authority;
-}
-
-#endif /* !HAVE_POLKIT || !HAVE_POLKIT_AUTHORITY_GET_SYNC */
diff --git a/src/nm-polkit.h b/src/nm-polkit.h
index b7c4027af8..7565fdc64a 100644
--- a/src/nm-polkit.h
+++ b/src/nm-polkit.h
@@ -30,117 +30,112 @@
#define NM_SYSCONFIG_POLICY_ACTION_HOSTNAME_MODIFY "org.freedesktop.network-manager-settings.system.hostname.modify"
#if HAVE_POLKIT
-
#include <polkit/polkit.h>
+#else
-/* Fix for polkit 0.97 and later */
-#if !HAVE_POLKIT_AUTHORITY_GET_SYNC
-PolkitAuthority *
-polkit_authority_get_sync (GCancellable *cancellable, GError **error);
-#endif /* !HAVE_POLKIT_AUTHORITY_GET_SYNC */
-
-
-#else /* ! HAVE_POLKIT */
-/* Stubs for the polkit api, that always allow the requested operation. */
-
+/* Stub out PolicyKit's internal data structures: */
#include <glib-object.h>
#include <gio/gio.h>
-/* Stub out PolicyKit's internal data structures: */
+typedef enum {
+ POLKIT_CHECK_AUTHORIZATION_FLAGS_NONE = 0,
+ POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION = (1 << 0),
+} PolkitCheckAuthorizationFlags;
-/* ... PolkitSubject
- In Polkit this is an interface, not a class, but to make it easier for
- me to create instances of it, here it is just a class. */
-#define POLKIT_TYPE_SUBJECT (polkit_subject_get_type())
-#define POLKIT_SUBJECT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), POLKIT_TYPE_SUBJECT, PolkitSubject))
-#define POLKIT_SUBJECT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), POLKIT_TYPE_SUBJECT, PolkitSubjectClass))
-#define POLKIT_SUBJECT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), POLKIT_TYPE_SUBJECT, PolkitSubjectClass))
-#define POLKIT_IS_SUBJECT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), POLKIT_TYPE_SUBJECT))
-#define POLKIT_IS_SUBJECT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), POLKIT_TYPE_SUBJECT))
-typedef struct _PolkitSubject PolkitSubject;
-typedef struct _PolkitSubjectClass PolkitSubjectClass;
-struct _PolkitSubject
-{
- GObject parent_instance;
-};
-struct _PolkitSubjectClass
+typedef void PolkitSubject;
+
+static inline PolkitSubject *
+polkit_system_bus_name_new (const gchar *name)
{
- GObjectClass parent_class;
-};
-GType polkit_subject_get_type (void);
+ return (PolkitSubject *) 0x1;
+}
-/* ... PolkitAuthority */
+/* PolkitAuthority */
#define POLKIT_TYPE_AUTHORITY (polkit_authority_get_type())
#define POLKIT_AUTHORITY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), POLKIT_TYPE_AUTHORITY, PolkitAuthority))
-#define POLKIT_AUTHORITY_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), POLKIT_TYPE_AUTHORITY, PolkitAuthorityClass))
-#define POLKIT_AUTHORITY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), POLKIT_TYPE_AUTHORITY, PolkitAuthorityClass))
-#define POLKIT_IS_AUTHORITY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), POLKIT_TYPE_AUTHORITY))
-#define POLKIT_IS_AUTHORITY_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), POLKIT_TYPE_AUTHORITY))
-typedef struct _PolkitAuthority PolkitAuthority;
-typedef struct _PolkitAuthorityClass PolkitAuthorityClass;
-struct _PolkitAuthority
-{
+
+typedef struct {
GObject parent_instance;
-};
-struct _PolkitAuthorityClass
-{
+} PolkitAuthority;
+
+typedef struct {
GObjectClass parent_class;
-};
+} PolkitAuthorityClass;
+
GType polkit_authority_get_type (void);
-/* ... PolkitAuthorizationResult */
+/* PolkitAuthorizationResult */
#define POLKIT_TYPE_AUTHORIZATION_RESULT (polkit_authorization_result_get_type())
#define POLKIT_AUTHORIZATION_RESULT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), POLKIT_TYPE_AUTHORIZATION_RESULT, PolkitAuthorizationResult))
-#define POLKIT_AUTHORIZATION_RESULT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), POLKIT_TYPE_AUTHORIZATION_RESULT, PolkitAuthorizationResultClass))
-#define POLKIT_AUTHORIZATION_RESULT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), POLKIT_TYPE_AUTHORIZATION_RESULT, PolkitAuthorizationResultClass))
-#define POLKIT_IS_AUTHORIZATION_RESULT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), POLKIT_TYPE_AUTHORIZATION_RESULT))
-#define POLKIT_IS_AUTHORIZATION_RESULT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), POLKIT_TYPE_AUTHORIZATION_RESULT))
-typedef struct _PolkitAuthorizationResult PolkitAuthorizationResult;
-typedef struct _PolkitAuthorizationResultClass PolkitAuthorizationResultClass;
-struct _PolkitAuthorizationResult
-{
+
+typedef struct {
GObject parent_instance;
-};
-struct _PolkitAuthorizationResultClass
-{
+} PolkitAuthorizationResult;
+
+typedef struct {
GObjectClass parent_class;
-};
-GType polkit_authorization_result_get_type (void);
+} PolkitAuthorizationResultClass;
+GType polkit_authorization_result_get_type (void);
-/* From polkitcheckauthorizationflags.h */
-typedef enum
+static inline PolkitAuthority *
+polkit_authority_get (void)
{
- POLKIT_CHECK_AUTHORIZATION_FLAGS_NONE = 0,
- POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION = (1<<0),
-} PolkitCheckAuthorizationFlags;
+ return (PolkitAuthority *) g_object_new (POLKIT_TYPE_AUTHORITY, NULL);
+}
+
+static inline void
+polkit_authority_check_authorization (PolkitAuthority *authority,
+ PolkitSubject *subject,
+ const gchar *action_id,
+ gpointer details,
+ PolkitCheckAuthorizationFlags flags,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *dummy_result;
-/* From polkitauthority.h */
-PolkitAuthority *polkit_authority_get (void);
+ dummy_result = g_simple_async_result_new(G_OBJECT (authority), callback, user_data, NULL);
+ g_simple_async_result_complete_in_idle (dummy_result);
+}
-PolkitAuthority *
-polkit_authority_get_sync (GCancellable *cancellable, GError **error);
+static inline PolkitAuthorizationResult *
+polkit_authority_check_authorization_finish (PolkitAuthority *authority,
+ GAsyncResult *res,
+ GError **error)
+{
+ return (PolkitAuthorizationResult *) g_object_new (POLKIT_TYPE_AUTHORIZATION_RESULT, NULL);
+}
-void polkit_authority_check_authorization (PolkitAuthority *authority,
- PolkitSubject *subject,
- const gchar *action_id,
- gpointer details,
- PolkitCheckAuthorizationFlags flags,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
+/* From polkitauthority.h */
+static inline gboolean
+polkit_authorization_result_get_is_authorized (PolkitAuthorizationResult *result)
+{
+ return TRUE;
+}
-PolkitAuthorizationResult *polkit_authority_check_authorization_finish (PolkitAuthority *authority,
- GAsyncResult *res,
- GError **error);
+static inline gboolean
+polkit_authorization_result_get_is_challenge (PolkitAuthorizationResult *result)
+{
+ return FALSE;
+}
-/* From polkitauthorizationresult.h */
-gboolean polkit_authorization_result_get_is_authorized (PolkitAuthorizationResult *result);
-gboolean polkit_authorization_result_get_is_challenge (PolkitAuthorizationResult *result);
+#endif /* HAVE_POLKIT */
-/* From polkitsystembusname.h */
-PolkitSubject *polkit_system_bus_name_new (const gchar *name);
-#endif /* HAVE_POLKIT */
+#if !HAVE_POLKIT || !HAVE_POLKIT_AUTHORITY_GET_SYNC
+/* Fix for polkit 0.97 and later and when polkit is disabled */
+static inline PolkitAuthority *
+polkit_authority_get_sync (GCancellable *cancellable, GError **error)
+{
+ PolkitAuthority *authority;
+
+ authority = polkit_authority_get ();
+ if (!authority)
+ g_set_error (error, 0, 0, "failed to get the PolicyKit authority");
+ return authority;
+}
+#endif /* !HAVE_POLKIT || !HAVE_POLKIT_AUTHORITY_GET_SYNC */
#endif /* NM_POLKIT_H */