2
* Copyright (C) 2013 Intel, Inc
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.
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.
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.
18
* Author: Thomas Wood <thomas.wood@intel.com>
25
#define SSHD_SERVICE "sshd.service"
28
static const gchar *service_list[] = { SSHD_SERVICE, NULL };
33
GDBusConnection *connection;
35
GVariant *temp_variant;
37
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
40
g_critical ("Error connecting to D-Bus system bus: %s", error->message);
41
g_clear_error (&error);
45
temp_variant = g_dbus_connection_call_sync (connection,
46
"org.freedesktop.systemd1",
47
"/org/freedesktop/systemd1",
48
"org.freedesktop.systemd1.Manager",
50
g_variant_new ("(ss)",
53
(GVariantType *) "(o)",
54
G_DBUS_CALL_FLAGS_NONE,
61
g_critical ("Error starting " SSHD_SERVICE ": %s", error->message);
62
g_clear_error (&error);
66
g_variant_unref (temp_variant);
68
temp_variant = g_dbus_connection_call_sync (connection,
69
"org.freedesktop.systemd1",
70
"/org/freedesktop/systemd1",
71
"org.freedesktop.systemd1.Manager",
73
g_variant_new ("(^asbb)",
76
(GVariantType *) "(ba(sss))",
77
G_DBUS_CALL_FLAGS_NONE,
84
g_critical ("Error enabling " SSHD_SERVICE ": %s", error->message);
85
g_clear_error (&error);
89
g_variant_unref (temp_variant);
95
disable_ssh_service ()
97
GDBusConnection *connection;
99
GVariant *temp_variant;
101
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
104
g_critical ("Error connecting to D-Bus system bus: %s", error->message);
105
g_clear_error (&error);
109
temp_variant = g_dbus_connection_call_sync (connection,
110
"org.freedesktop.systemd1",
111
"/org/freedesktop/systemd1",
112
"org.freedesktop.systemd1.Manager",
114
g_variant_new ("(ss)", SSHD_SERVICE, "replace"),
115
(GVariantType *) "(o)",
116
G_DBUS_CALL_FLAGS_NONE,
122
g_critical ("Error stopping " SSHD_SERVICE ": %s", error->message);
123
g_clear_error (&error);
127
g_variant_unref (temp_variant);
129
temp_variant = g_dbus_connection_call_sync (connection,
130
"org.freedesktop.systemd1",
131
"/org/freedesktop/systemd1",
132
"org.freedesktop.systemd1.Manager",
134
g_variant_new ("(^asb)", service_list, FALSE,
136
(GVariantType *) "(a(sss))",
137
G_DBUS_CALL_FLAGS_NONE,
144
g_critical ("Error disabling " SSHD_SERVICE ": %s", error->message);
145
g_clear_error (&error);
149
g_variant_unref (temp_variant);
164
if (g_str_equal (argv[1], "enable"))
165
return enable_ssh_service ();
166
else if (g_str_equal (argv[1], "disable"))
167
return disable_ssh_service ();