File: polkitbackendactionlookup.c

package info (click to toggle)
policykit-1 0.105-15~deb8u2
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 8,644 kB
  • ctags: 4,294
  • sloc: ansic: 18,560; sh: 11,430; xml: 3,384; makefile: 767
file content (182 lines) | stat: -rw-r--r-- 6,902 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
 * Copyright (C) 2008 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 "config.h"
#include <errno.h>
#include <pwd.h>
#include <string.h>

#define _POLKIT_BACKEND_ACTION_LOOKUP_NO_DEPRECATED_WARNING

#include <polkit/polkit.h>
#include <polkit/polkitprivate.h>
#include "polkitbackendactionlookup.h"

#include "polkitbackendprivate.h"

/**
 * SECTION:polkitbackendactionlookup
 * @title: PolkitBackendActionLookup
 * @short_description: Interface used to provide data to authentication dialogs
 * @stability: Unstable
 *
 * An interface that is used by backends to provide localized data
 * shown in authentication dialogs.
 *
 * This inteface is intended for mechanisms to customize the message
 * to show - a mechanism can provide a #GIOModule that registers one
 * or more extensions that implement this interface. Every time an
 * authentication dialog is shown, the registered extensions are
 * consulted in priority order.
 *
 * This is useful if your mechanism wants to put up a message such as
 * "Authentication is required to install 'Totem Movie Player'",
 * e.g. messages that include more information than just the action
 * name.
 *
 * Code implementing this interface <emphasis>cannot</emphasis> block
 * or do any IO when methods are invoked. If information is needed to
 * format the message or details, prepare it in advance and pass it as
 * part of the @details object when doing the
 * polkit_authority_check_authorization() call. Then the code in this
 * interface can use that information to return localized data.
 *
 * Note that setlocale() and the <literal>LANG</literal> environment
 * variable will be set up to match the locale of the authentication
 * agent that is the receiver of the information. This means that code
 * implementing this interface can use dgettext() or similar machinery
 * to look up translations.
 */

static void
base_init (gpointer g_iface)
{
}

GType
polkit_backend_action_lookup_get_type (void)
{
  static volatile gsize g_define_type_id__volatile = 0;

  if (g_once_init_enter (&g_define_type_id__volatile))
    {
      static const GTypeInfo info =
      {
        sizeof (PolkitBackendActionLookupIface),
        base_init,              /* base_init      */
        NULL,                   /* base_finalize  */
        NULL,                   /* class_init     */
        NULL,                   /* class_finalize */
        NULL,                   /* class_data     */
        0,                      /* instance_size  */
        0,                      /* n_preallocs    */
        NULL,                   /* instance_init  */
        NULL                    /* value_table    */
      };

      GType iface_type =
        g_type_register_static (G_TYPE_INTERFACE, "PolkitBackendActionLookup", &info, 0);

      g_type_interface_add_prerequisite (iface_type, G_TYPE_OBJECT);
      g_once_init_leave (&g_define_type_id__volatile, iface_type);
    }

  return g_define_type_id__volatile;
}

/**
 * polkit_backend_action_lookup_get_message:
 * @lookup: A #PolkitBackendActionLookup.
 * @action_id: The action to get the message for.
 * @details: Details passed to polkit_authority_check_authorization().
 * @action_description: A #PolkitActionDescription object for @action_id.
 *
 * Computes a message to show in an authentication dialog for
 * @action_id and @details.
 *
 * Returns: A localized string to show in the authentication dialog or %NULL. Caller must free this string.
 **/
gchar *
polkit_backend_action_lookup_get_message (PolkitBackendActionLookup *lookup,
                                          const gchar               *action_id,
                                          PolkitDetails             *details,
                                          PolkitActionDescription   *action_description)
{
  PolkitBackendActionLookupIface *iface = POLKIT_BACKEND_ACTION_LOOKUP_GET_IFACE (lookup);

  if (iface->get_message == NULL)
    return NULL;
  else
    return iface->get_message (lookup, action_id, details, action_description);
}

/**
 * polkit_backend_action_lookup_get_icon_name:
 * @lookup: A #PolkitBackendActionLookup.
 * @action_id: The action to get the themed icon for.
 * @details: Details passed to polkit_authority_check_authorization().
 * @action_description: A #PolkitActionDescription object for @action_id.
 *
 * Computes a themed icon name to show in an authentication dialog for
 * @action_id and @details.
 *
 * Returns: A themed icon name or %NULL. Caller must free this string.
 **/
gchar *
polkit_backend_action_lookup_get_icon_name (PolkitBackendActionLookup *lookup,
                                            const gchar               *action_id,
                                            PolkitDetails             *details,
                                            PolkitActionDescription   *action_description)
{
  PolkitBackendActionLookupIface *iface = POLKIT_BACKEND_ACTION_LOOKUP_GET_IFACE (lookup);

  if (iface->get_icon_name == NULL)
    return NULL;
  else
    return iface->get_icon_name (lookup, action_id, details, action_description);
}

/**
 * polkit_backend_action_lookup_get_details:
 * @lookup: A #PolkitBackendActionLookup.
 * @action_id: The action to get the details for.
 * @details: Details passed to polkit_authority_check_authorization().
 * @action_description: A #PolkitActionDescription object for @action_id.
 *
 * Computes localized details to show in an authentication dialog for
 * @action_id and @details.
 *
 * Returns: A #PolkitDetails object with localized details or %NULL. Caller must free the result.
 **/
PolkitDetails *
polkit_backend_action_lookup_get_details (PolkitBackendActionLookup *lookup,
                                          const gchar               *action_id,
                                          PolkitDetails             *details,
                                          PolkitActionDescription   *action_description)
{
  PolkitBackendActionLookupIface *iface = POLKIT_BACKEND_ACTION_LOOKUP_GET_IFACE (lookup);

  if (iface->get_details == NULL)
    return NULL;
  else
    return iface->get_details (lookup, action_id, details, action_description);
}