~ubuntu-branches/ubuntu/lucid/network-manager-applet/lucid-updates

« back to all changes in this revision

Viewing changes to src/polkit-helpers/polkit-gnome-auth.c

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Sack, Alexander Sack, Tony Espy
  • Date: 2009-09-14 11:32:57 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20090914113257-47x5o2kfwwm95w3l
Tags: 0.8~a~git.20090913t161448.cc2f6be-0ubuntu1
* upstream snapshot 2009-09-13 16:14:48 (GMT)
  + cc2f6bea12daec5f0caf535a3534f07ade5b5cf2

[ Alexander Sack <asac@ubuntu.com> ]
* build depend on libpolkit-gobject-1-dev instead of libpolkit-dbus-dev
  - update debian/control

[ Tony Espy <espy@ubuntu.com> ]
* adjust patches for upstream code base
  - update debian/patches/20_use_full_vpn_dialog_service_name_path.patch
  - update debian/patches/lp328572_dxteam_connect_text.patch
  - update debian/patches/lp337960_dxteam_notification_icon_names.diff
  - update debian/patches/lp341684_device_sensitive_disconnect_notify.patch
* adjust build and runtime depends due to ABI changes in latest NM
  - update debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
2
 
/***************************************************************************
3
 
 *
4
 
 * polkit-gnome-auth.c : Show authentication dialogs to gain privileges
5
 
 *
6
 
 * Copyright (C) 2007 David Zeuthen, <david@fubar.dk>
7
 
 *
8
 
 * This library is free software; you can redistribute it and/or
9
 
 * modify it under the terms of the GNU Lesser General Public License
10
 
 * as published by the Free Software Foundation; either version 2 of
11
 
 * the License, or (at your option) any later version.
12
 
 *
13
 
 * This library is distributed in the hope that it will be useful, but
14
 
 * WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 
 * Lesser General Public License for more details.
17
 
 *
18
 
 * You should have received a copy of the GNU Lesser General Public
19
 
 * License along with this library; if not, write to the Free Software
20
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21
 
 * 02110-1301 USA.
22
 
 *
23
 
 **************************************************************************/
24
 
 
25
 
#ifdef HAVE_CONFIG_H
26
 
#  include "config.h"
27
 
#endif
28
 
 
29
 
#include <stdlib.h>
30
 
#include <stdio.h>
31
 
#include <unistd.h>
32
 
#include <signal.h>
33
 
#include <errno.h>
34
 
#include <string.h>
35
 
#include <sys/types.h>
36
 
#include <sys/stat.h>
37
 
#include <sys/wait.h>
38
 
#include <fcntl.h>
39
 
 
40
 
#include <glib.h>
41
 
#include <glib/gi18n-lib.h>
42
 
#include <glib-object.h>
43
 
 
44
 
#include <gtk/gtk.h>
45
 
#include <gdk/gdkx.h>
46
 
 
47
 
#include <dbus/dbus-glib.h>
48
 
#include <dbus/dbus-glib-lowlevel.h>
49
 
 
50
 
#include "polkit-gnome-auth.h"
51
 
 
52
 
/**
53
 
 * SECTION:polkit-gnome-auth
54
 
 * @title: Authentication Dialogs
55
 
 * @short_description: Show authentication dialogs to gain privileges
56
 
 *
57
 
 * Show authentication dialogs to gain privileges.
58
 
 *
59
 
 **/
60
 
 
61
 
 
62
 
typedef struct {
63
 
        PolKitAction *action;
64
 
        PolKitGnomeAuthCB callback;
65
 
        gpointer user_data;
66
 
} CallClosure;
67
 
 
68
 
static void
69
 
_notify_callback (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data)
70
 
{
71
 
        GError *error;
72
 
        CallClosure *c = (CallClosure *) user_data;
73
 
        gboolean gained_privilege;
74
 
 
75
 
        error = NULL;
76
 
        if (!dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_BOOLEAN, &gained_privilege, G_TYPE_INVALID)) {
77
 
                gained_privilege = FALSE;
78
 
        }
79
 
 
80
 
        /* perform the callback */
81
 
        c->callback (c->action, gained_privilege, error, c->user_data);
82
 
 
83
 
        g_object_unref (proxy);
84
 
        polkit_action_unref (c->action);
85
 
}
86
 
 
87
 
/**
88
 
 * polkit_gnome_auth_obtain:
89
 
 * @action: The #PolKitAction to make the user authenticate for
90
 
 * @xid: X11 window ID for the window that the dialog will be transient for. If there is no window, pass 0.
91
 
 * @pid: Process ID of process to grant authorization to. Normally one wants to pass result of getpid().
92
 
 * @callback: Function to call when authentication is done
93
 
 * @user_data: Data to pass to the callback function
94
 
 * @error: Return location for error
95
 
 *
96
 
 * Applications can use this function to show a dialog for the user
97
 
 * asking her to authenticate in order to gain privileges to do the
98
 
 * given action. The authentication, for security reasons, happens in
99
 
 * a separate process; this function is merely a wrapper around a
100
 
 * D-Bus call across the session message bus to the
101
 
 * <literal>org.freedesktop.PolicyKit.AuthenticationAgent</literal>
102
 
 * service. Depending on the setup, this may be the Authentication
103
 
 * Agent shipped with PolicyKit-gnome or it may be another
104
 
 * implementation. For example, if the user is in KDE it may be an
105
 
 * Authentication Agent using the Qt toolkit.
106
 
 *
107
 
 * The Authentication Agent shipped with PolicyKit-gnome is described
108
 
 * in <link linkend="ref-auth-daemon">this section</link>.
109
 
 *
110
 
 * This function is similar to the polkit_auth_obtain() function
111
 
 * supplied in <literal>libpolkit-dbus</literal> except that this
112
 
 * function is asynchronous.
113
 
 *
114
 
 * Returns: #TRUE if the authentication session was scheduled to
115
 
 * start. #FALSE if error is set (and no callback will be made).
116
 
 */
117
 
gboolean 
118
 
polkit_gnome_auth_obtain (PolKitAction *action, 
119
 
                          guint xid,
120
 
                          pid_t pid,
121
 
                          PolKitGnomeAuthCB callback, 
122
 
                          gpointer user_data, 
123
 
                          GError **error)
124
 
{
125
 
        char *polkit_action_id;
126
 
        gboolean ret;
127
 
        CallClosure *c;
128
 
        DBusGConnection *session_bus;
129
 
        DBusGProxy *polkit_gnome_proxy;
130
 
 
131
 
        ret = FALSE;
132
 
 
133
 
        if ((session_bus = dbus_g_bus_get (DBUS_BUS_SESSION, error)) == NULL) {
134
 
                goto error;
135
 
        }
136
 
 
137
 
        /* TODO: this can fail.. */
138
 
        polkit_action_get_action_id (action, &polkit_action_id);
139
 
 
140
 
        polkit_gnome_proxy = dbus_g_proxy_new_for_name (session_bus,
141
 
                                                        "org.freedesktop.PolicyKit.AuthenticationAgent", /* bus name */
142
 
                                                        "/",                                             /* object */
143
 
                                                        "org.freedesktop.PolicyKit.AuthenticationAgent");/* interface */
144
 
 
145
 
        c = g_new0 (CallClosure, 1);
146
 
        c->action = polkit_action_ref (action);
147
 
        c->callback = callback;
148
 
        c->user_data = user_data;
149
 
 
150
 
        dbus_g_proxy_begin_call_with_timeout (polkit_gnome_proxy,
151
 
                                              "ShowDialog",
152
 
                                              _notify_callback,
153
 
                                              c,
154
 
                                              g_free,
155
 
                                              INT_MAX,
156
 
                                              /* parameters: */
157
 
                                              G_TYPE_STRING, polkit_action_id,  /* action_id */
158
 
                                              G_TYPE_UINT, xid,                 /* X11 window ID */
159
 
                                              G_TYPE_INVALID);
160
 
 
161
 
        ret = TRUE;
162
 
error:
163
 
        return ret;
164
 
}
165