summaryrefslogtreecommitdiff
path: root/src/hostname
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2021-01-25 13:16:20 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-02-09 13:37:27 +0900
commit957991b7acec20ccf2c21f0162e9da54ea22d2dd (patch)
tree3aaa0e417e7f5f8b14aeee997f32013ac197fc8c /src/hostname
parent0ce2a086da8cfc89f4ed49ed965e4e8f17b5ccac (diff)
downloadsystemd-957991b7acec20ccf2c21f0162e9da54ea22d2dd.tar.gz
hostname: introduce two bus errors for updating file
Diffstat (limited to 'src/hostname')
-rw-r--r--src/hostname/hostnamed.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c
index 0e4dd02b49..cc5c21cd1f 100644
--- a/src/hostname/hostnamed.c
+++ b/src/hostname/hostnamed.c
@@ -767,6 +767,10 @@ static int method_set_static_hostname(sd_bus_message *m, void *userdata, sd_bus_
r = context_write_data_static_hostname(c);
if (r < 0) {
log_error_errno(r, "Failed to write static hostname: %m");
+ if (ERRNO_IS_PRIVILEGE(r))
+ return sd_bus_error_set(error, BUS_ERROR_FILE_IS_PROTECTED, "Not allowed to update /etc/hostname.");
+ if (r == -EROFS)
+ return sd_bus_error_set(error, BUS_ERROR_READ_ONLY_FILESYSTEM, "/etc/hostname is in a read-only filesystem.");
return sd_bus_error_set_errnof(error, r, "Failed to set static hostname: %m");
}
@@ -843,6 +847,10 @@ static int set_machine_info(Context *c, sd_bus_message *m, int prop, sd_bus_mess
r = context_write_data_machine_info(c);
if (r < 0) {
log_error_errno(r, "Failed to write machine info: %m");
+ if (ERRNO_IS_PRIVILEGE(r))
+ return sd_bus_error_set(error, BUS_ERROR_FILE_IS_PROTECTED, "Not allowed to update /etc/machine-info.");
+ if (r == -EROFS)
+ return sd_bus_error_set(error, BUS_ERROR_READ_ONLY_FILESYSTEM, "/etc/machine-info is in a read-only filesystem.");
return sd_bus_error_set_errnof(error, r, "Failed to write machine info: %m");
}