Line |
Branch |
Exec |
Source |
1 |
|
|
/* |
2 |
|
|
* Copyright (C) 2013 Intel, Inc |
3 |
|
|
* |
4 |
|
|
* This program is free software; you can redistribute it and/or modify |
5 |
|
|
* it under the terms of the GNU General Public License as published by |
6 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
7 |
|
|
* (at your option) any later version. |
8 |
|
|
* |
9 |
|
|
* This program is distributed in the hope that it will be useful, |
10 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 |
|
|
* GNU General Public License for more details. |
13 |
|
|
* |
14 |
|
|
* You should have received a copy of the GNU General Public License |
15 |
|
|
* along with this program; if not, write to the Free Software |
16 |
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
17 |
|
|
* |
18 |
|
|
* Author: Thomas Wood <thomas.wood@intel.com> |
19 |
|
|
* |
20 |
|
|
*/ |
21 |
|
|
#include "cc-secure-shell.h" |
22 |
|
|
#include "cc-systemd-service.h" |
23 |
|
|
|
24 |
|
|
#include <gio/gio.h> |
25 |
|
|
#include <polkit/polkit.h> |
26 |
|
|
|
27 |
|
|
#ifndef SSHD_SERVICE |
28 |
|
|
#define SSHD_SERVICE "sshd.service" |
29 |
|
|
#endif |
30 |
|
|
|
31 |
|
|
typedef struct |
32 |
|
|
{ |
33 |
|
|
AdwSwitchRow *widget; |
34 |
|
|
GtkWidget *row; |
35 |
|
|
GCancellable *cancellable; |
36 |
|
|
} CallbackData; |
37 |
|
|
|
38 |
|
✗ |
G_DEFINE_AUTOPTR_CLEANUP_FUNC (CallbackData, g_free) |
39 |
|
|
|
40 |
|
|
void |
41 |
|
✗ |
cc_secure_shell_get_enabled (AdwSwitchRow *widget) |
42 |
|
|
{ |
43 |
|
|
/* disable the switch until the current state is known */ |
44 |
|
✗ |
gtk_widget_set_sensitive (GTK_WIDGET (widget), FALSE); |
45 |
|
|
|
46 |
|
✗ |
adw_switch_row_set_active (widget, cc_is_service_active (SSHD_SERVICE, G_BUS_TYPE_SYSTEM)); |
47 |
|
|
|
48 |
|
✗ |
gtk_widget_set_sensitive (GTK_WIDGET (widget), TRUE); |
49 |
|
✗ |
} |
50 |
|
|
|
51 |
|
|
static void |
52 |
|
✗ |
enable_ssh_service (GError** error) |
53 |
|
|
{ |
54 |
|
✗ |
cc_enable_service (SSHD_SERVICE, G_BUS_TYPE_SYSTEM, error); |
55 |
|
✗ |
} |
56 |
|
|
|
57 |
|
|
static void |
58 |
|
✗ |
disable_ssh_service (GError** error) |
59 |
|
|
{ |
60 |
|
✗ |
cc_disable_service (SSHD_SERVICE, G_BUS_TYPE_SYSTEM, error); |
61 |
|
✗ |
} |
62 |
|
|
|
63 |
|
|
static void |
64 |
|
✗ |
on_permission_acquired (GObject *source_object, |
65 |
|
|
GAsyncResult *res, |
66 |
|
|
gpointer user_data) |
67 |
|
|
{ |
68 |
|
✗ |
GPermission *permission = (GPermission*) source_object; |
69 |
|
✗ |
g_autoptr(CallbackData) callback_data = user_data; |
70 |
|
✗ |
g_autoptr(GError) error = NULL; |
71 |
|
|
|
72 |
|
✗ |
if (!g_permission_acquire_finish (permission, res, &error)) |
73 |
|
|
{ |
74 |
|
✗ |
g_warning ("Cannot acquire '%s' permission: %s", |
75 |
|
|
"org.gnome.controlcenter.remote-login-helper", |
76 |
|
|
error->message); |
77 |
|
|
} |
78 |
|
|
else |
79 |
|
|
{ |
80 |
|
✗ |
if (g_permission_get_allowed (permission)) |
81 |
|
|
{ |
82 |
|
✗ |
if (adw_switch_row_get_active (callback_data->widget)) |
83 |
|
✗ |
enable_ssh_service (&error); |
84 |
|
|
else |
85 |
|
✗ |
disable_ssh_service (&error); |
86 |
|
|
|
87 |
|
|
/* Switch state should match service state */ |
88 |
|
✗ |
return; |
89 |
|
|
} |
90 |
|
|
else |
91 |
|
|
{ |
92 |
|
✗ |
g_warning ("Permission: %s not granted", |
93 |
|
|
"org.gnome.controlcenter.remote-login-helper"); |
94 |
|
|
} |
95 |
|
|
} |
96 |
|
|
|
97 |
|
|
/* If permission could not be acquired, or permission was not granted, |
98 |
|
|
* switch might be out of sync, update switch state */ |
99 |
|
✗ |
cc_secure_shell_get_enabled (callback_data->widget); |
100 |
|
|
} |
101 |
|
|
|
102 |
|
|
void |
103 |
|
✗ |
cc_secure_shell_set_enabled (GCancellable *cancellable, |
104 |
|
|
AdwSwitchRow *widget) |
105 |
|
|
{ |
106 |
|
|
GPermission *permission; |
107 |
|
✗ |
g_autoptr(GError) error = NULL; |
108 |
|
|
|
109 |
|
|
CallbackData *callback_data; |
110 |
|
|
|
111 |
|
✗ |
if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget), "set-from-dbus")) == 1) |
112 |
|
|
{ |
113 |
|
✗ |
g_object_set_data (G_OBJECT (widget), "set-from-dbus", NULL); |
114 |
|
✗ |
return; |
115 |
|
|
} |
116 |
|
|
|
117 |
|
✗ |
callback_data = g_new0 (CallbackData, 1); |
118 |
|
✗ |
callback_data->widget = widget; |
119 |
|
✗ |
callback_data->cancellable = cancellable; |
120 |
|
|
|
121 |
|
✗ |
permission = polkit_permission_new_sync ("org.gnome.controlcenter.remote-login-helper", |
122 |
|
|
NULL, NULL, &error); |
123 |
|
|
|
124 |
|
✗ |
if (permission != NULL) |
125 |
|
|
{ |
126 |
|
✗ |
g_permission_acquire_async (permission, callback_data->cancellable, |
127 |
|
|
on_permission_acquired, callback_data); |
128 |
|
|
} |
129 |
|
|
else |
130 |
|
|
{ |
131 |
|
✗ |
g_warning ("Cannot create '%s' permission: %s", |
132 |
|
|
"org.gnome.controlcenter.remote-login-helper", |
133 |
|
|
error->message); |
134 |
|
|
} |
135 |
|
|
} |
136 |
|
|
|
137 |
|
|
|