tree-wide: generate SD_BUS_ERROR_INVALID_ARGS when we get invalid arguments on bus calls
Let's make sure that when we return a D-Bus error, we return a native one, if we generate it ourselves, and use errno-based error synthetization only if we received an errno ourselves. Yes, this makes things slightly longer, but is highly misleading as we propagate D-Bus errors, and not errnos to the client.
This commit is contained in:
+23
-23
@@ -381,7 +381,7 @@ static int bus_cgroup_set_transient_property(
|
||||
|
||||
cc = cgroup_controller_from_string(t);
|
||||
if (cc < 0)
|
||||
return sd_bus_error_set_errnof(error, EINVAL, "Unknown cgroup contoller '%s'", t);
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unknown cgroup contoller '%s'", t);
|
||||
|
||||
mask |= CGROUP_CONTROLLER_TO_MASK(cc);
|
||||
}
|
||||
@@ -453,7 +453,7 @@ int bus_cgroup_set_property(
|
||||
return r;
|
||||
|
||||
if (!CGROUP_WEIGHT_IS_OK(weight))
|
||||
return sd_bus_error_set_errnof(error, EINVAL, "CPUWeight= value out of range");
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "CPUWeight= value out of range");
|
||||
|
||||
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
||||
c->cpu_weight = weight;
|
||||
@@ -475,7 +475,7 @@ int bus_cgroup_set_property(
|
||||
return r;
|
||||
|
||||
if (!CGROUP_WEIGHT_IS_OK(weight))
|
||||
return sd_bus_error_set_errnof(error, EINVAL, "StartupCPUWeight= value out of range");
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "StartupCPUWeight= value out of range");
|
||||
|
||||
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
||||
c->startup_cpu_weight = weight;
|
||||
@@ -497,7 +497,7 @@ int bus_cgroup_set_property(
|
||||
return r;
|
||||
|
||||
if (!CGROUP_CPU_SHARES_IS_OK(shares))
|
||||
return sd_bus_error_set_errnof(error, EINVAL, "CPUShares= value out of range");
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "CPUShares= value out of range");
|
||||
|
||||
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
||||
c->cpu_shares = shares;
|
||||
@@ -519,7 +519,7 @@ int bus_cgroup_set_property(
|
||||
return r;
|
||||
|
||||
if (!CGROUP_CPU_SHARES_IS_OK(shares))
|
||||
return sd_bus_error_set_errnof(error, EINVAL, "StartupCPUShares= value out of range");
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "StartupCPUShares= value out of range");
|
||||
|
||||
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
||||
c->startup_cpu_shares = shares;
|
||||
@@ -541,7 +541,7 @@ int bus_cgroup_set_property(
|
||||
return r;
|
||||
|
||||
if (u64 <= 0)
|
||||
return sd_bus_error_set_errnof(error, EINVAL, "CPUQuotaPerSecUSec= value out of range");
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "CPUQuotaPerSecUSec= value out of range");
|
||||
|
||||
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
||||
c->cpu_quota_per_sec_usec = u64;
|
||||
@@ -582,7 +582,7 @@ int bus_cgroup_set_property(
|
||||
return r;
|
||||
|
||||
if (!CGROUP_WEIGHT_IS_OK(weight))
|
||||
return sd_bus_error_set_errnof(error, EINVAL, "IOWeight= value out of range");
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "IOWeight= value out of range");
|
||||
|
||||
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
||||
c->io_weight = weight;
|
||||
@@ -604,7 +604,7 @@ int bus_cgroup_set_property(
|
||||
return r;
|
||||
|
||||
if (CGROUP_WEIGHT_IS_OK(weight))
|
||||
return sd_bus_error_set_errnof(error, EINVAL, "StartupIOWeight= value out of range");
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "StartupIOWeight= value out of range");
|
||||
|
||||
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
||||
c->startup_io_weight = weight;
|
||||
@@ -712,7 +712,7 @@ int bus_cgroup_set_property(
|
||||
while ((r = sd_bus_message_read(message, "(st)", &path, &weight)) > 0) {
|
||||
|
||||
if (!CGROUP_WEIGHT_IS_OK(weight) || weight == CGROUP_WEIGHT_INVALID)
|
||||
return sd_bus_error_set_errnof(error, EINVAL, "IODeviceWeight= value out of range");
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "IODeviceWeight= value out of range");
|
||||
|
||||
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
||||
CGroupIODeviceWeight *a = NULL, *b;
|
||||
@@ -799,7 +799,7 @@ int bus_cgroup_set_property(
|
||||
return r;
|
||||
|
||||
if (!CGROUP_BLKIO_WEIGHT_IS_OK(weight))
|
||||
return sd_bus_error_set_errnof(error, EINVAL, "BlockIOWeight= value out of range");
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "BlockIOWeight= value out of range");
|
||||
|
||||
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
||||
c->blockio_weight = weight;
|
||||
@@ -821,7 +821,7 @@ int bus_cgroup_set_property(
|
||||
return r;
|
||||
|
||||
if (!CGROUP_BLKIO_WEIGHT_IS_OK(weight))
|
||||
return sd_bus_error_set_errnof(error, EINVAL, "StartupBlockIOWeight= value out of range");
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "StartupBlockIOWeight= value out of range");
|
||||
|
||||
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
||||
c->startup_blockio_weight = weight;
|
||||
@@ -945,7 +945,7 @@ int bus_cgroup_set_property(
|
||||
while ((r = sd_bus_message_read(message, "(st)", &path, &weight)) > 0) {
|
||||
|
||||
if (!CGROUP_BLKIO_WEIGHT_IS_OK(weight) || weight == CGROUP_BLKIO_WEIGHT_INVALID)
|
||||
return sd_bus_error_set_errnof(error, EINVAL, "BlockIODeviceWeight= out of range");
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "BlockIODeviceWeight= out of range");
|
||||
|
||||
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
||||
CGroupBlockIODeviceWeight *a = NULL, *b;
|
||||
@@ -1032,7 +1032,7 @@ int bus_cgroup_set_property(
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (v <= 0)
|
||||
return sd_bus_error_set_errnof(error, EINVAL, "%s= is too small", name);
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= is too small", name);
|
||||
|
||||
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
||||
if (streq(name, "MemoryLow"))
|
||||
@@ -1064,7 +1064,7 @@ int bus_cgroup_set_property(
|
||||
|
||||
v = physical_memory_scale(raw, UINT32_MAX);
|
||||
if (v <= 0 || v == UINT64_MAX)
|
||||
return sd_bus_error_set_errnof(error, EINVAL, "%s= is out of range", name);
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= is out of range", name);
|
||||
|
||||
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
||||
const char *e;
|
||||
@@ -1094,7 +1094,7 @@ int bus_cgroup_set_property(
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (limit <= 0)
|
||||
return sd_bus_error_set_errnof(error, EINVAL, "%s= is too small", name);
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= is too small", name);
|
||||
|
||||
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
||||
c->memory_limit = limit;
|
||||
@@ -1118,7 +1118,7 @@ int bus_cgroup_set_property(
|
||||
|
||||
limit = physical_memory_scale(raw, UINT32_MAX);
|
||||
if (limit <= 0 || limit == UINT64_MAX)
|
||||
return sd_bus_error_set_errnof(error, EINVAL, "%s= is out of range", name);
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= is out of range", name);
|
||||
|
||||
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
||||
c->memory_limit = limit;
|
||||
@@ -1164,13 +1164,13 @@ int bus_cgroup_set_property(
|
||||
!startswith(path, "block-") &&
|
||||
!startswith(path, "char-")) ||
|
||||
strpbrk(path, WHITESPACE))
|
||||
return sd_bus_error_set_errnof(error, EINVAL, "DeviceAllow= requires device node");
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "DeviceAllow= requires device node");
|
||||
|
||||
if (isempty(rwm))
|
||||
rwm = "rwm";
|
||||
|
||||
if (!in_charset(rwm, "rwm"))
|
||||
return sd_bus_error_set_errnof(error, EINVAL, "DeviceAllow= requires combination of rwm flags");
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "DeviceAllow= requires combination of rwm flags");
|
||||
|
||||
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
||||
CGroupDeviceAllow *a = NULL, *b;
|
||||
@@ -1261,7 +1261,7 @@ int bus_cgroup_set_property(
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (limit <= 0)
|
||||
return sd_bus_error_set_errnof(error, EINVAL, "%s= is too small", name);
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= is too small", name);
|
||||
|
||||
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
||||
c->tasks_max = limit;
|
||||
@@ -1285,7 +1285,7 @@ int bus_cgroup_set_property(
|
||||
|
||||
limit = system_tasks_max_scale(raw, UINT32_MAX);
|
||||
if (limit <= 0 || limit >= UINT64_MAX)
|
||||
return sd_bus_error_set_errnof(error, EINVAL, "%s= is out of range", name);
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= is out of range", name);
|
||||
|
||||
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
||||
c->tasks_max = limit;
|
||||
@@ -1339,14 +1339,14 @@ int bus_cgroup_set_property(
|
||||
return r;
|
||||
|
||||
if (!IN_SET(family, AF_INET, AF_INET6))
|
||||
return sd_bus_error_set_errnof(error, EINVAL, "%s= expects IPv4 or IPv6 addresses only.", name);
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= expects IPv4 or IPv6 addresses only.", name);
|
||||
|
||||
r = sd_bus_message_read_array(message, 'y', &ap, &an);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (an != FAMILY_ADDRESS_SIZE(family))
|
||||
return sd_bus_error_set_errnof(error, EINVAL, "IP address has wrong size for family (%s, expected %zu, got %zu)",
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "IP address has wrong size for family (%s, expected %zu, got %zu)",
|
||||
af_to_name(family), FAMILY_ADDRESS_SIZE(family), an);
|
||||
|
||||
r = sd_bus_message_read(message, "u", &prefixlen);
|
||||
@@ -1354,7 +1354,7 @@ int bus_cgroup_set_property(
|
||||
return r;
|
||||
|
||||
if (prefixlen > FAMILY_ADDRESS_SIZE(family)*8)
|
||||
return sd_bus_error_set_errnof(error, EINVAL, "Prefix length %" PRIu32 " too large for address family %s.", prefixlen, af_to_name(family));
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Prefix length %" PRIu32 " too large for address family %s.", prefixlen, af_to_name(family));
|
||||
|
||||
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
||||
IPAddressAccessItem *item;
|
||||
|
||||
@@ -253,7 +253,7 @@ static int bus_service_set_transient_property(
|
||||
return r;
|
||||
|
||||
if (!path_is_absolute(path))
|
||||
return sd_bus_error_set_errnof(error, EINVAL, "Path %s is not absolute.", path);
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not absolute.", path);
|
||||
|
||||
r = sd_bus_message_read_strv(message, &argv);
|
||||
if (r < 0)
|
||||
|
||||
@@ -381,7 +381,7 @@ static int method_set_vc_keyboard(sd_bus_message *m, void *userdata, sd_bus_erro
|
||||
|
||||
if ((keymap && (!filename_is_valid(keymap) || !string_is_safe(keymap))) ||
|
||||
(keymap_toggle && (!filename_is_valid(keymap_toggle) || !string_is_safe(keymap_toggle))))
|
||||
return sd_bus_error_set_errnof(error, -EINVAL, "Received invalid keymap data");
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Received invalid keymap data");
|
||||
|
||||
r = bus_verify_polkit_async(
|
||||
m,
|
||||
@@ -560,7 +560,7 @@ static int method_set_x11_keyboard(sd_bus_message *m, void *userdata, sd_bus_err
|
||||
(model && !string_is_safe(model)) ||
|
||||
(variant && !string_is_safe(variant)) ||
|
||||
(options && !string_is_safe(options)))
|
||||
return sd_bus_error_set_errnof(error, -EINVAL, "Received invalid keyboard data");
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Received invalid keyboard data");
|
||||
|
||||
r = bus_verify_polkit_async(
|
||||
m,
|
||||
|
||||
Reference in New Issue
Block a user