/src/glib/gio/gdbusauthmechanism.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* GDBus - GLib D-Bus Library |
2 | | * |
3 | | * Copyright (C) 2008-2010 Red Hat, Inc. |
4 | | * |
5 | | * SPDX-License-Identifier: LGPL-2.1-or-later |
6 | | * |
7 | | * This library is free software; you can redistribute it and/or |
8 | | * modify it under the terms of the GNU Lesser General Public |
9 | | * License as published by the Free Software Foundation; either |
10 | | * version 2.1 of the License, or (at your option) any later version. |
11 | | * |
12 | | * This library is distributed in the hope that it will be useful, |
13 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | | * Lesser General Public License for more details. |
16 | | * |
17 | | * You should have received a copy of the GNU Lesser General |
18 | | * Public License along with this library; if not, see <http://www.gnu.org/licenses/>. |
19 | | * |
20 | | * Author: David Zeuthen <davidz@redhat.com> |
21 | | */ |
22 | | |
23 | | #include "config.h" |
24 | | |
25 | | #include "gdbusauthmechanism.h" |
26 | | #include "gcredentials.h" |
27 | | #include "gdbuserror.h" |
28 | | #include "gioenumtypes.h" |
29 | | #include "giostream.h" |
30 | | |
31 | | #include "glibintl.h" |
32 | | |
33 | | /* ---------------------------------------------------------------------------------------------------- */ |
34 | | |
35 | | struct _GDBusAuthMechanismPrivate |
36 | | { |
37 | | GIOStream *stream; |
38 | | GCredentials *credentials; |
39 | | }; |
40 | | |
41 | | enum |
42 | | { |
43 | | PROP_0, |
44 | | PROP_STREAM, |
45 | | PROP_CREDENTIALS |
46 | | }; |
47 | | |
48 | | G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GDBusAuthMechanism, _g_dbus_auth_mechanism, G_TYPE_OBJECT) |
49 | | |
50 | | /* ---------------------------------------------------------------------------------------------------- */ |
51 | | |
52 | | static void |
53 | | _g_dbus_auth_mechanism_finalize (GObject *object) |
54 | 0 | { |
55 | 0 | GDBusAuthMechanism *mechanism = G_DBUS_AUTH_MECHANISM (object); |
56 | |
|
57 | 0 | if (mechanism->priv->stream != NULL) |
58 | 0 | g_object_unref (mechanism->priv->stream); |
59 | 0 | if (mechanism->priv->credentials != NULL) |
60 | 0 | g_object_unref (mechanism->priv->credentials); |
61 | |
|
62 | 0 | G_OBJECT_CLASS (_g_dbus_auth_mechanism_parent_class)->finalize (object); |
63 | 0 | } |
64 | | |
65 | | static void |
66 | | _g_dbus_auth_mechanism_get_property (GObject *object, |
67 | | guint prop_id, |
68 | | GValue *value, |
69 | | GParamSpec *pspec) |
70 | 0 | { |
71 | 0 | GDBusAuthMechanism *mechanism = G_DBUS_AUTH_MECHANISM (object); |
72 | |
|
73 | 0 | switch (prop_id) |
74 | 0 | { |
75 | 0 | case PROP_STREAM: |
76 | 0 | g_value_set_object (value, mechanism->priv->stream); |
77 | 0 | break; |
78 | | |
79 | 0 | case PROP_CREDENTIALS: |
80 | 0 | g_value_set_object (value, mechanism->priv->credentials); |
81 | 0 | break; |
82 | | |
83 | 0 | default: |
84 | 0 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
85 | 0 | break; |
86 | 0 | } |
87 | 0 | } |
88 | | |
89 | | static void |
90 | | _g_dbus_auth_mechanism_set_property (GObject *object, |
91 | | guint prop_id, |
92 | | const GValue *value, |
93 | | GParamSpec *pspec) |
94 | 0 | { |
95 | 0 | GDBusAuthMechanism *mechanism = G_DBUS_AUTH_MECHANISM (object); |
96 | |
|
97 | 0 | switch (prop_id) |
98 | 0 | { |
99 | 0 | case PROP_STREAM: |
100 | 0 | mechanism->priv->stream = g_value_dup_object (value); |
101 | 0 | break; |
102 | | |
103 | 0 | case PROP_CREDENTIALS: |
104 | 0 | mechanism->priv->credentials = g_value_dup_object (value); |
105 | 0 | break; |
106 | | |
107 | 0 | default: |
108 | 0 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
109 | 0 | break; |
110 | 0 | } |
111 | 0 | } |
112 | | |
113 | | static void |
114 | | _g_dbus_auth_mechanism_class_init (GDBusAuthMechanismClass *klass) |
115 | 0 | { |
116 | 0 | GObjectClass *gobject_class; |
117 | |
|
118 | 0 | gobject_class = G_OBJECT_CLASS (klass); |
119 | 0 | gobject_class->get_property = _g_dbus_auth_mechanism_get_property; |
120 | 0 | gobject_class->set_property = _g_dbus_auth_mechanism_set_property; |
121 | 0 | gobject_class->finalize = _g_dbus_auth_mechanism_finalize; |
122 | |
|
123 | 0 | g_object_class_install_property (gobject_class, |
124 | 0 | PROP_STREAM, |
125 | 0 | g_param_spec_object ("stream", |
126 | 0 | P_("IO Stream"), |
127 | 0 | P_("The underlying GIOStream used for I/O"), |
128 | 0 | G_TYPE_IO_STREAM, |
129 | 0 | G_PARAM_READABLE | |
130 | 0 | G_PARAM_WRITABLE | |
131 | 0 | G_PARAM_CONSTRUCT_ONLY | |
132 | 0 | G_PARAM_STATIC_NAME | |
133 | 0 | G_PARAM_STATIC_BLURB | |
134 | 0 | G_PARAM_STATIC_NICK)); |
135 | | |
136 | | /** |
137 | | * GDBusAuthMechanism:credentials: |
138 | | * |
139 | | * If authenticating as a server, this property contains the |
140 | | * received credentials, if any. |
141 | | * |
142 | | * If authenticating as a client, the property contains the |
143 | | * credentials that were sent, if any. |
144 | | */ |
145 | 0 | g_object_class_install_property (gobject_class, |
146 | 0 | PROP_CREDENTIALS, |
147 | 0 | g_param_spec_object ("credentials", |
148 | 0 | P_("Credentials"), |
149 | 0 | P_("The credentials of the remote peer"), |
150 | 0 | G_TYPE_CREDENTIALS, |
151 | 0 | G_PARAM_READABLE | |
152 | 0 | G_PARAM_WRITABLE | |
153 | 0 | G_PARAM_CONSTRUCT_ONLY | |
154 | 0 | G_PARAM_STATIC_NAME | |
155 | 0 | G_PARAM_STATIC_BLURB | |
156 | 0 | G_PARAM_STATIC_NICK)); |
157 | 0 | } |
158 | | |
159 | | static void |
160 | | _g_dbus_auth_mechanism_init (GDBusAuthMechanism *mechanism) |
161 | 0 | { |
162 | 0 | mechanism->priv = _g_dbus_auth_mechanism_get_instance_private (mechanism); |
163 | 0 | } |
164 | | |
165 | | /* ---------------------------------------------------------------------------------------------------- */ |
166 | | |
167 | | GIOStream * |
168 | | _g_dbus_auth_mechanism_get_stream (GDBusAuthMechanism *mechanism) |
169 | 0 | { |
170 | 0 | g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL); |
171 | 0 | return mechanism->priv->stream; |
172 | 0 | } |
173 | | |
174 | | GCredentials * |
175 | | _g_dbus_auth_mechanism_get_credentials (GDBusAuthMechanism *mechanism) |
176 | 0 | { |
177 | 0 | g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL); |
178 | 0 | return mechanism->priv->credentials; |
179 | 0 | } |
180 | | |
181 | | /* ---------------------------------------------------------------------------------------------------- */ |
182 | | |
183 | | const gchar * |
184 | | _g_dbus_auth_mechanism_get_name (GType mechanism_type) |
185 | 0 | { |
186 | 0 | const gchar *name; |
187 | 0 | GDBusAuthMechanismClass *klass; |
188 | |
|
189 | 0 | g_return_val_if_fail (g_type_is_a (mechanism_type, G_TYPE_DBUS_AUTH_MECHANISM), NULL); |
190 | | |
191 | 0 | klass = g_type_class_ref (mechanism_type); |
192 | 0 | g_assert (klass != NULL); |
193 | 0 | name = klass->get_name (); |
194 | | //g_type_class_unref (klass); |
195 | |
|
196 | 0 | return name; |
197 | 0 | } |
198 | | |
199 | | gint |
200 | | _g_dbus_auth_mechanism_get_priority (GType mechanism_type) |
201 | 0 | { |
202 | 0 | gint priority; |
203 | 0 | GDBusAuthMechanismClass *klass; |
204 | |
|
205 | 0 | g_return_val_if_fail (g_type_is_a (mechanism_type, G_TYPE_DBUS_AUTH_MECHANISM), 0); |
206 | | |
207 | 0 | klass = g_type_class_ref (mechanism_type); |
208 | 0 | g_assert (klass != NULL); |
209 | 0 | priority = klass->get_priority (); |
210 | | //g_type_class_unref (klass); |
211 | |
|
212 | 0 | return priority; |
213 | 0 | } |
214 | | |
215 | | /* ---------------------------------------------------------------------------------------------------- */ |
216 | | |
217 | | gboolean |
218 | | _g_dbus_auth_mechanism_is_supported (GDBusAuthMechanism *mechanism) |
219 | 0 | { |
220 | 0 | g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), FALSE); |
221 | 0 | return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->is_supported (mechanism); |
222 | 0 | } |
223 | | |
224 | | gchar * |
225 | | _g_dbus_auth_mechanism_encode_data (GDBusAuthMechanism *mechanism, |
226 | | const gchar *data, |
227 | | gsize data_len, |
228 | | gsize *out_data_len) |
229 | 0 | { |
230 | 0 | g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL); |
231 | 0 | return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->encode_data (mechanism, data, data_len, out_data_len); |
232 | 0 | } |
233 | | |
234 | | |
235 | | gchar * |
236 | | _g_dbus_auth_mechanism_decode_data (GDBusAuthMechanism *mechanism, |
237 | | const gchar *data, |
238 | | gsize data_len, |
239 | | gsize *out_data_len) |
240 | 0 | { |
241 | 0 | g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL); |
242 | 0 | return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->decode_data (mechanism, data, data_len, out_data_len); |
243 | 0 | } |
244 | | |
245 | | /* ---------------------------------------------------------------------------------------------------- */ |
246 | | |
247 | | GDBusAuthMechanismState |
248 | | _g_dbus_auth_mechanism_server_get_state (GDBusAuthMechanism *mechanism) |
249 | 0 | { |
250 | 0 | g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), G_DBUS_AUTH_MECHANISM_STATE_INVALID); |
251 | 0 | return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_get_state (mechanism); |
252 | 0 | } |
253 | | |
254 | | void |
255 | | _g_dbus_auth_mechanism_server_initiate (GDBusAuthMechanism *mechanism, |
256 | | const gchar *initial_response, |
257 | | gsize initial_response_len) |
258 | 0 | { |
259 | 0 | g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism)); |
260 | 0 | G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_initiate (mechanism, initial_response, initial_response_len); |
261 | 0 | } |
262 | | |
263 | | void |
264 | | _g_dbus_auth_mechanism_server_data_receive (GDBusAuthMechanism *mechanism, |
265 | | const gchar *data, |
266 | | gsize data_len) |
267 | 0 | { |
268 | 0 | g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism)); |
269 | 0 | G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_data_receive (mechanism, data, data_len); |
270 | 0 | } |
271 | | |
272 | | gchar * |
273 | | _g_dbus_auth_mechanism_server_data_send (GDBusAuthMechanism *mechanism, |
274 | | gsize *out_data_len) |
275 | 0 | { |
276 | 0 | g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL); |
277 | 0 | return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_data_send (mechanism, out_data_len); |
278 | 0 | } |
279 | | |
280 | | gchar * |
281 | | _g_dbus_auth_mechanism_server_get_reject_reason (GDBusAuthMechanism *mechanism) |
282 | 0 | { |
283 | 0 | g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL); |
284 | 0 | return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_get_reject_reason (mechanism); |
285 | 0 | } |
286 | | |
287 | | void |
288 | | _g_dbus_auth_mechanism_server_shutdown (GDBusAuthMechanism *mechanism) |
289 | 0 | { |
290 | 0 | g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism)); |
291 | 0 | G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_shutdown (mechanism); |
292 | 0 | } |
293 | | |
294 | | /* ---------------------------------------------------------------------------------------------------- */ |
295 | | |
296 | | GDBusAuthMechanismState |
297 | | _g_dbus_auth_mechanism_client_get_state (GDBusAuthMechanism *mechanism) |
298 | 0 | { |
299 | 0 | g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), G_DBUS_AUTH_MECHANISM_STATE_INVALID); |
300 | 0 | return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->client_get_state (mechanism); |
301 | 0 | } |
302 | | |
303 | | gchar * |
304 | | _g_dbus_auth_mechanism_client_initiate (GDBusAuthMechanism *mechanism, |
305 | | GDBusConnectionFlags conn_flags, |
306 | | gsize *out_initial_response_len) |
307 | 0 | { |
308 | 0 | g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL); |
309 | 0 | return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->client_initiate (mechanism, |
310 | 0 | conn_flags, |
311 | 0 | out_initial_response_len); |
312 | 0 | } |
313 | | |
314 | | void |
315 | | _g_dbus_auth_mechanism_client_data_receive (GDBusAuthMechanism *mechanism, |
316 | | const gchar *data, |
317 | | gsize data_len) |
318 | 0 | { |
319 | 0 | g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism)); |
320 | 0 | G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->client_data_receive (mechanism, data, data_len); |
321 | 0 | } |
322 | | |
323 | | gchar * |
324 | | _g_dbus_auth_mechanism_client_data_send (GDBusAuthMechanism *mechanism, |
325 | | gsize *out_data_len) |
326 | 0 | { |
327 | 0 | g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL); |
328 | 0 | return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->client_data_send (mechanism, out_data_len); |
329 | 0 | } |
330 | | |
331 | | void |
332 | | _g_dbus_auth_mechanism_client_shutdown (GDBusAuthMechanism *mechanism) |
333 | 0 | { |
334 | 0 | g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism)); |
335 | 0 | G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->client_shutdown (mechanism); |
336 | 0 | } |
337 | | |
338 | | /* ---------------------------------------------------------------------------------------------------- */ |