Commit f510fde8 authored by Luca Weiss's avatar Luca Weiss Committed by Rasmus Thomsen
Browse files

community/openrc-settingsd: upgrade to 1.1.0

Upstream didn't have a release since 2012 and there doesn't seem to be
any interest in maintaining this in the original Gentoo repository.
parent 23c99382
Upstream: No, upstream is dead unfortunately
From c72e431ba98990c34cce0b87231bd0092586955c Mon Sep 17 00:00:00 2001
From: Rasmus Thomsen <oss@cogitri.dev>
Date: Sat, 6 Jun 2020 12:37:12 +0200
Subject: [PATCH] Make /etc/localtime a symlink if it doesn't exist yet or
already is a symlink
Previously we always tried to write the contents of the file in
/usr/share/zoneinfo to /etc/localtime, but that doesn't work if it
doesn't exist or if /etc/localtime is a symlink. As such, we should just
make it a symlink if it doesn't exist or already is one.
---
src/timedated.c | 34 +++++++++++++++++++++++++++-------
1 file changed, 27 insertions(+), 7 deletions(-)
diff --git a/src/timedated.c b/src/timedated.c
index 07c29da..a3402b1 100644
--- a/src/timedated.c
+++ b/src/timedated.c
@@ -139,13 +139,33 @@ set_timezone (const gchar *_timezone_name,
localtime_filename = g_file_get_path (localtime_file);
localtime2_filename = g_strdup_printf (DATADIR "/zoneinfo/%s", _timezone_name);
localtime2_file = g_file_new_for_path (localtime2_filename);
- if (!g_file_load_contents (localtime2_file, NULL, &filebuf, &length, NULL, error)) {
- g_prefix_error (error, "Unable to read '%s':", localtime2_filename);
- goto out;
- }
- if (!g_file_replace_contents (localtime_file, filebuf, length, NULL, FALSE, 0, NULL, NULL, error)) {
- g_prefix_error (error, "Unable to write '%s':", localtime_filename);
- goto out;
+
+ if (g_file_test(localtime_filename, G_FILE_TEST_IS_SYMLINK)) {
+ if (!g_file_delete (localtime_file, NULL, error)) {
+ g_prefix_error (error, "Unable to delete file to make new symlink %s:", localtime_filename);
+ goto out;
+ }
+ if (!g_file_make_symbolic_link (localtime_file, localtime2_filename, NULL, error)) {
+ g_error("Failed to make symlink %s", (*error)->message);
+ g_prefix_error (error, "Unable to create symlink %s -> %s:", localtime_filename, localtime2_filename);
+ goto out;
+ }
+ } else if (g_file_test(localtime_filename, G_FILE_TEST_IS_REGULAR)) {
+ if (!g_file_load_contents (localtime2_file, NULL, &filebuf, &length, NULL, error)) {
+ g_prefix_error (error, "Unable to read '%s':", localtime2_filename);
+ goto out;
+ }
+ if (!g_file_replace_contents (localtime_file, filebuf, length, NULL, FALSE, 0, NULL, NULL, error)) {
+ g_prefix_error (error, "Unable to write '%s':", localtime_filename);
+ goto out;
+ }
+ } else {
+ // File doesn't exist yet -> make a new symlink
+ if (!g_file_make_symbolic_link (localtime_file, localtime2_filename, NULL, error)) {
+ g_error("Failed to make symlink %s", (*error)->message);
+ g_prefix_error (error, "Unable to create symlink %s -> %s:", localtime_filename, localtime2_filename);
+ goto out;
+ }
}
ret = TRUE;
--
2.27.0
From fdeef40875bebf3970d1365dc92cb893a0298097 Mon Sep 17 00:00:00 2001
From: Rasmus Thomsen <oss@cogitri.dev>
Date: Fri, 3 Jul 2020 12:19:52 +0200
Subject: [PATCH 2/2] Ensure 0664 permissions on /etc/localtime
Otherwise the timezone couldn't be read by other users
---
src/timedated.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/src/timedated.c b/src/timedated.c
index a6779f9..77d12ee 100644
--- a/src/timedated.c
+++ b/src/timedated.c
@@ -26,6 +26,7 @@
#include <dbus/dbus-protocol.h>
#include <glib.h>
+#include <glib/gstdio.h>
#include <gio/gio.h>
#if HAVE_OPENRC
@@ -135,6 +136,9 @@ set_timezone (const gchar *_timezone_name,
g_prefix_error (error, "Unable to write '%s':", timezone_filename);
goto out;
}
+ if(g_chmod (timezone_filename, 0664) != 0) {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED, "Unable to set 0664 permissions on timezone file '%s'", timezone_filename);
+ }
localtime_filename = g_file_get_path (localtime_file);
localtime2_filename = g_strdup_printf (DATADIR "/zoneinfo/%s", _timezone_name);
@@ -158,6 +162,9 @@ set_timezone (const gchar *_timezone_name,
g_prefix_error (error, "Unable to write '%s':", localtime_filename);
goto out;
}
+ if(g_chmod (localtime_filename, 0664) != 0) {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED, "Unable to set 0664 permissions on localtime file '%s'", localtime_filename);
+ }
} else {
// File doesn't exist yet -> make a new symlink
if (!g_file_make_symbolic_link (localtime_file, localtime2_filename, NULL, error)) {
--
2.26.2
From 64debbaf5bdef93302f29c3f6cd395e3e22d65d8 Mon Sep 17 00:00:00 2001
From: Luca Weiss <luca@z3ntu.xyz>
Date: Wed, 28 Oct 2020 23:05:52 +0100
Subject: [PATCH] utils: fix missing newline on new shell entries
Previously if the existing file didn't end with a newline then two shell
entries would be written without any separator to the file leading to a
broken file.
---
src/utils.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/src/utils.c b/src/utils.c
index d61274a..041a087 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -488,6 +488,23 @@ shell_parser_set_variable (ShellParser *parser,
ret = TRUE;
} else {
if (add_if_unset) {
+ GList *previous;
+ struct ShellEntry *previous_entry = NULL;
+
+ /* We need to add a separator (\n) between two items if there isn't one already. */
+ if ((previous = g_list_last(parser->entry_list)) != NULL) {
+ previous_entry = previous->data;
+ }
+ if (previous_entry && previous_entry->type != SHELL_ENTRY_TYPE_SEPARATOR) {
+ struct ShellEntry *separator_entry;
+
+ g_debug ("Adding separator entry");
+ separator_entry = g_new0 (struct ShellEntry, 1);
+ separator_entry->type = SHELL_ENTRY_TYPE_SEPARATOR;
+ separator_entry->string = g_strdup ("\n");
+ parser->entry_list = g_list_append (parser->entry_list, separator_entry);
+ }
+
found_entry = g_new0 (struct ShellEntry, 1);
found_entry->type = SHELL_ENTRY_TYPE_ASSIGNMENT;
found_entry->variable = g_strdup (variable);
--
2.25.1
From 7c49162fb18ee886bb9138585e23694daa63a3f1 Mon Sep 17 00:00:00 2001
From: Luca Weiss <luca@z3ntu.xyz>
Date: Wed, 28 Oct 2020 22:01:55 +0100
Subject: [PATCH] hostnamed: add support for Chassis, Deployment & Location
properties
---
data/org.freedesktop.hostname1.xml | 15 ++
src/hostnamed.c | 219 ++++++++++++++++++++++++++++-
2 files changed, 233 insertions(+), 1 deletion(-)
diff --git a/data/org.freedesktop.hostname1.xml b/data/org.freedesktop.hostname1.xml
index e351096..1a4aa0d 100644
--- a/data/org.freedesktop.hostname1.xml
+++ b/data/org.freedesktop.hostname1.xml
@@ -19,9 +19,24 @@
<arg direction="in" type="s" name="name"/>
<arg direction="in" type="b" name="user_interaction"/>
</method>
+ <method name="SetChassis">
+ <arg direction="in" type="s" name="chassis"/>
+ <arg direction="in" type="b" name="interactive"/>
+ </method>
+ <method name="SetDeployment">
+ <arg direction="in" type="s" name="deployment"/>
+ <arg direction="in" type="b" name="interactive"/>
+ </method>
+ <method name="SetLocation">
+ <arg direction="in" type="s" name="location"/>
+ <arg direction="in" type="b" name="interactive"/>
+ </method>
<property name="Hostname" type="s" access="read"/>
<property name="StaticHostname" type="s" access="read"/>
<property name="PrettyHostname" type="s" access="read"/>
<property name="IconName" type="s" access="read"/>
+ <property name="Chassis" type="s" access="read"/>
+ <property name="Deployment" type="s" access="read"/>
+ <property name="Location" type="s" access="read"/>
</interface>
</node>
diff --git a/src/hostnamed.c b/src/hostnamed.c
index 92ca794..b837dc8 100644
--- a/src/hostnamed.c
+++ b/src/hostnamed.c
@@ -60,6 +60,9 @@ static GFile *static_hostname_file = NULL;
G_LOCK_DEFINE_STATIC (static_hostname);
static gchar *pretty_hostname = NULL;
static gchar *icon_name = NULL;
+static gchar *chassis = NULL;
+static gchar *deployment = NULL;
+static gchar *location = NULL;
static GFile *machine_info_file = NULL;
G_LOCK_DEFINE_STATIC (machine_info);
@@ -375,6 +378,183 @@ on_handle_set_icon_name (OpenrcSettingsdHostnamedHostname1 *hostname1,
return TRUE; /* Always return TRUE to indicate signal has been handled */
}
+static void
+on_handle_set_chassis_authorized_cb (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ GError *err = NULL;
+ struct invoked_name *data;
+
+ data = (struct invoked_name *) user_data;
+ if (!check_polkit_finish (res, &err)) {
+ g_dbus_method_invocation_return_gerror (data->invocation, err);
+ goto out;
+ }
+
+ G_LOCK (machine_info);
+ /* Don't allow a null chassis */
+ if (data->name == NULL)
+ data->name = g_strdup ("");
+
+ if (!shell_parser_set_and_save (machine_info_file, &err, "CHASSIS", NULL, data->name, NULL)) {
+ g_dbus_method_invocation_return_gerror (data->invocation, err);
+ G_UNLOCK (machine_info);
+ goto out;
+ }
+
+ g_free (chassis);
+ chassis = data->name; /* data->name is g_strdup-ed already */
+ openrc_settingsd_hostnamed_hostname1_complete_set_chassis (hostname1, data->invocation);
+ openrc_settingsd_hostnamed_hostname1_set_chassis (hostname1, chassis);
+ G_UNLOCK (machine_info);
+
+ out:
+ g_free (data);
+ if (err != NULL)
+ g_error_free (err);
+}
+
+static gboolean
+on_handle_set_chassis (OpenrcSettingsdHostnamedHostname1 *hostname1,
+ GDBusMethodInvocation *invocation,
+ const gchar *name,
+ const gboolean user_interaction,
+ gpointer user_data)
+{
+ if (read_only)
+ g_dbus_method_invocation_return_dbus_error (invocation,
+ DBUS_ERROR_NOT_SUPPORTED,
+ "openrc-settingsd hostnamed is in read-only mode");
+ else {
+ struct invoked_name *data;
+ data = g_new0 (struct invoked_name, 1);
+ data->invocation = invocation;
+ data->name = g_strdup (name);
+ check_polkit_async (g_dbus_method_invocation_get_sender (invocation), "org.freedesktop.hostname1.set-machine-info", user_interaction, on_handle_set_chassis_authorized_cb, data);
+ }
+
+ return TRUE; /* Always return TRUE to indicate signal has been handled */
+}
+
+static void
+on_handle_set_deployment_authorized_cb (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ GError *err = NULL;
+ struct invoked_name *data;
+
+ data = (struct invoked_name *) user_data;
+ if (!check_polkit_finish (res, &err)) {
+ g_dbus_method_invocation_return_gerror (data->invocation, err);
+ goto out;
+ }
+
+ G_LOCK (machine_info);
+ /* Don't allow a null deployment */
+ if (data->name == NULL)
+ data->name = g_strdup ("");
+
+ if (!shell_parser_set_and_save (machine_info_file, &err, "DEPLOYMENT", NULL, data->name, NULL)) {
+ g_dbus_method_invocation_return_gerror (data->invocation, err);
+ G_UNLOCK (machine_info);
+ goto out;
+ }
+
+ g_free (deployment);
+ deployment = data->name; /* data->name is g_strdup-ed already */
+ openrc_settingsd_hostnamed_hostname1_complete_set_deployment (hostname1, data->invocation);
+ openrc_settingsd_hostnamed_hostname1_set_deployment (hostname1, deployment);
+ G_UNLOCK (machine_info);
+
+ out:
+ g_free (data);
+ if (err != NULL)
+ g_error_free (err);
+}
+
+static gboolean
+on_handle_set_deployment (OpenrcSettingsdHostnamedHostname1 *hostname1,
+ GDBusMethodInvocation *invocation,
+ const gchar *name,
+ const gboolean user_interaction,
+ gpointer user_data)
+{
+ if (read_only)
+ g_dbus_method_invocation_return_dbus_error (invocation,
+ DBUS_ERROR_NOT_SUPPORTED,
+ "openrc-settingsd hostnamed is in read-only mode");
+ else {
+ struct invoked_name *data;
+ data = g_new0 (struct invoked_name, 1);
+ data->invocation = invocation;
+ data->name = g_strdup (name);
+ check_polkit_async (g_dbus_method_invocation_get_sender (invocation), "org.freedesktop.hostname1.set-machine-info", user_interaction, on_handle_set_deployment_authorized_cb, data);
+ }
+
+ return TRUE; /* Always return TRUE to indicate signal has been handled */
+}
+
+static void
+on_handle_set_location_authorized_cb (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ GError *err = NULL;
+ struct invoked_name *data;
+
+ data = (struct invoked_name *) user_data;
+ if (!check_polkit_finish (res, &err)) {
+ g_dbus_method_invocation_return_gerror (data->invocation, err);
+ goto out;
+ }
+
+ G_LOCK (machine_info);
+ /* Don't allow a null location */
+ if (data->name == NULL)
+ data->name = g_strdup ("");
+
+ if (!shell_parser_set_and_save (machine_info_file, &err, "LOCATION", NULL, data->name, NULL)) {
+ g_dbus_method_invocation_return_gerror (data->invocation, err);
+ G_UNLOCK (machine_info);
+ goto out;
+ }
+
+ g_free (location);
+ location = data->name; /* data->name is g_strdup-ed already */
+ openrc_settingsd_hostnamed_hostname1_complete_set_location (hostname1, data->invocation);
+ openrc_settingsd_hostnamed_hostname1_set_location (hostname1, location);
+ G_UNLOCK (machine_info);
+
+ out:
+ g_free (data);
+ if (err != NULL)
+ g_error_free (err);
+}
+
+static gboolean
+on_handle_set_location (OpenrcSettingsdHostnamedHostname1 *hostname1,
+ GDBusMethodInvocation *invocation,
+ const gchar *name,
+ const gboolean user_interaction,
+ gpointer user_data)
+{
+ if (read_only)
+ g_dbus_method_invocation_return_dbus_error (invocation,
+ DBUS_ERROR_NOT_SUPPORTED,
+ "openrc-settingsd hostnamed is in read-only mode");
+ else {
+ struct invoked_name *data;
+ data = g_new0 (struct invoked_name, 1);
+ data->invocation = invocation;
+ data->name = g_strdup (name);
+ check_polkit_async (g_dbus_method_invocation_get_sender (invocation), "org.freedesktop.hostname1.set-machine-info", user_interaction, on_handle_set_location_authorized_cb, data);
+ }
+
+ return TRUE; /* Always return TRUE to indicate signal has been handled */
+}
+
static void
on_bus_acquired (GDBusConnection *connection,
const gchar *bus_name,
@@ -391,11 +571,17 @@ on_bus_acquired (GDBusConnection *connection,
openrc_settingsd_hostnamed_hostname1_set_static_hostname (hostname1, static_hostname);
openrc_settingsd_hostnamed_hostname1_set_pretty_hostname (hostname1, pretty_hostname);
openrc_settingsd_hostnamed_hostname1_set_icon_name (hostname1, icon_name);
+ openrc_settingsd_hostnamed_hostname1_set_chassis (hostname1, chassis);
+ openrc_settingsd_hostnamed_hostname1_set_deployment (hostname1, deployment);
+ openrc_settingsd_hostnamed_hostname1_set_location (hostname1, location);
g_signal_connect (hostname1, "handle-set-hostname", G_CALLBACK (on_handle_set_hostname), NULL);
g_signal_connect (hostname1, "handle-set-static-hostname", G_CALLBACK (on_handle_set_static_hostname), NULL);
g_signal_connect (hostname1, "handle-set-pretty-hostname", G_CALLBACK (on_handle_set_pretty_hostname), NULL);
g_signal_connect (hostname1, "handle-set-icon-name", G_CALLBACK (on_handle_set_icon_name), NULL);
+ g_signal_connect (hostname1, "handle-set-chassis", G_CALLBACK (on_handle_set_chassis), NULL);
+ g_signal_connect (hostname1, "handle-set-deployment", G_CALLBACK (on_handle_set_deployment), NULL);
+ g_signal_connect (hostname1, "handle-set-location", G_CALLBACK (on_handle_set_location), NULL);
if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (hostname1),
connection,
@@ -451,6 +637,7 @@ hostnamed_init (gboolean _read_only)
g_error_free (err);
err = NULL;
}
+
pretty_hostname = shell_source_var (machine_info_file, "${PRETTY_HOSTNAME}", &err);
if (pretty_hostname == NULL)
pretty_hostname = g_strdup ("");
@@ -459,6 +646,7 @@ hostnamed_init (gboolean _read_only)
g_error_free (err);
err = NULL;
}
+
icon_name = shell_source_var (machine_info_file, "${ICON_NAME}", &err);
if (icon_name == NULL)
icon_name = g_strdup ("");
@@ -467,12 +655,38 @@ hostnamed_init (gboolean _read_only)
g_error_free (err);
err = NULL;
}
-
if (icon_name == NULL || *icon_name == 0) {
g_free (icon_name);
icon_name = guess_icon_name ();
}
+ chassis = shell_source_var (machine_info_file, "${CHASSIS}", &err);
+ if (chassis == NULL)
+ chassis = g_strdup ("");
+ if (err != NULL) {
+ g_debug ("%s", err->message);
+ g_error_free (err);
+ err = NULL;
+ }
+
+ deployment = shell_source_var (machine_info_file, "${DEPLOYMENT}", &err);
+ if (deployment == NULL)
+ deployment = g_strdup ("");
+ if (err != NULL) {
+ g_debug ("%s", err->message);
+ g_error_free (err);
+ err = NULL;
+ }
+
+ location = shell_source_var (machine_info_file, "${LOCATION}", &err);
+ if (location == NULL)
+ location = g_strdup ("");
+ if (err != NULL) {
+ g_debug ("%s", err->message);
+ g_error_free (err);
+ err = NULL;
+ }
+
read_only = _read_only;
bus_id = g_bus_own_name (G_BUS_TYPE_SYSTEM,
@@ -495,6 +709,9 @@ hostnamed_destroy (void)
g_free (static_hostname);
g_free (pretty_hostname);
g_free (icon_name);
+ g_free (chassis);
+ g_free (deployment);
+ g_free (location);
g_object_unref (static_hostname_file);
g_object_unref (machine_info_file);
--
2.25.1
From 2ca7608889909fb91e76e559419ca6aebf8b84a1 Mon Sep 17 00:00:00 2001
From: Luca Weiss <luca@z3ntu.xyz>
Date: Thu, 29 Oct 2020 22:08:13 +0100
Subject: [PATCH] hostnamed: add comments to smbios constants
---
src/hostnamed.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/src/hostnamed.c b/src/hostnamed.c
index b837dc8..706a85c 100644
--- a/src/hostnamed.c
+++ b/src/hostnamed.c
@@ -103,22 +103,22 @@ guess_icon_name ()
if (g_file_get_contents ("/sys/class/dmi/id/chassis_type", &filebuf, NULL, NULL)) {
switch (g_ascii_strtoull (filebuf, NULL, 10)) {
- case 0x3:
- case 0x4:
- case 0x5:
- case 0x6:
- case 0x7:
+ case 0x3: /* Desktop */
+ case 0x4: /* Low Profile Desktop */
+ case 0x5: /* Pizza Box */
+ case 0x6: /* Mini Tower */
+ case 0x7: /* Tower */
ret = g_strdup ("computer-desktop");
goto out;
- case 0x9:
- case 0xA:
- case 0xE:
+ case 0x9: /* Laptop */
+ case 0xA: /* Notebook */
+ case 0xE: /* Sub Notebook */
ret = g_strdup ("computer-laptop");
goto out;
- case 0x11:
- case 0x17:
- case 0x1C:
- case 0x1D:
+ case 0x11: /* Main Server Chassis */
+ case 0x17: /* Rack Mount Chassis */
+ case 0x1C: /* Blade */
+ case 0x1D: /* Blade Enclosure */
ret = g_strdup ("computer-server");
goto out;
}
--
2.25.1
From 13f8d940ba07e47b3865359913104ec8101dde26 Mon Sep 17 00:00:00 2001
From: Luca Weiss <luca@z3ntu.xyz>
Date: Thu, 29 Oct 2020 22:39:52 +0100
Subject: [PATCH] hostnamed: add detection for more smbios types
---
src/hostnamed.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/src/hostnamed.c b/src/hostnamed.c
index 706a85c..2608196 100644
--- a/src/hostnamed.c
+++ b/src/hostnamed.c
@@ -95,10 +95,10 @@ guess_icon_name ()
Taken with a few minor changes from systemd's hostnamed.c,
copyright 2011 Lennart Poettering.
- See the SMBIOS Specification 2.7.1 section 7.4.1 for
+ See the SMBIOS Specification 3.4.0 section 7.4.1 for
details about the values listed here:
- http://www.dmtf.org/sites/default/files/standards/documents/DSP0134_2.7.1.pdf
+ https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.4.0.pdf
*/
if (g_file_get_contents ("/sys/class/dmi/id/chassis_type", &filebuf, NULL, NULL)) {
@@ -108,19 +108,31 @@ guess_icon_name ()
case 0x5: /* Pizza Box */
case 0x6: /* Mini Tower */
case 0x7: /* Tower */
+ case 0xD: /* All in One */
ret = g_strdup ("computer-desktop");
goto out;
+ case 0x8: /* Portable */
case 0x9: /* Laptop */
case 0xA: /* Notebook */
case 0xE: /* Sub Notebook */
ret = g_strdup ("computer-laptop");
goto out;
+ case 0xB: /* Hand Held */
+ ret = g_strdup ("computer-handset");
+ goto out;
case 0x11: /* Main Server Chassis */
case 0x17: /* Rack Mount Chassis */
case 0x1C: /* Blade */
case 0x1D: /* Blade Enclosure */
ret = g_strdup ("computer-server");
goto out;
+ case 0x1E: /* Tablet */
+ ret = g_strdup ("computer-tablet");
+ goto out;
+ case 0x1F: /* Convertible */
+ case 0x20: /* Detachable */
+ ret = g_strdup ("computer-convertible");
+ goto out;
}
}
#endif
--
2.25.1