diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-02-01 18:53:35 +0100 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-03-25 07:36:48 +0100 |
commit | 0327d5b20f9e845dc310cb9e87207ac982c8bbd0 (patch) | |
tree | ff0fbcd62adbdd0641564972ed2c7efdd2a45695 /src/locale | |
parent | locale: split out xkbcommon related functions to xkbcommon-util.c (diff) | |
download | systemd-0327d5b20f9e845dc310cb9e87207ac982c8bbd0.tar.xz systemd-0327d5b20f9e845dc310cb9e87207ac982c8bbd0.zip |
locale: introduce x11_context_verify()
No functional change, preparation for later commits.
Diffstat (limited to 'src/locale')
-rw-r--r-- | src/locale/localed-util.c | 30 | ||||
-rw-r--r-- | src/locale/localed-util.h | 4 | ||||
-rw-r--r-- | src/locale/localed.c | 16 |
3 files changed, 37 insertions, 13 deletions
diff --git a/src/locale/localed-util.c b/src/locale/localed-util.c index f955a74a8a..bb08c0b78a 100644 --- a/src/locale/localed-util.c +++ b/src/locale/localed-util.c @@ -24,6 +24,7 @@ #include "string-util.h" #include "strv.h" #include "tmpfile-util.h" +#include "xkbcommon-util.h" static bool startswith_comma(const char *s, const char *prefix) { assert(s); @@ -154,6 +155,35 @@ int x11_context_copy(X11Context *dest, const X11Context *src) { return modified; } +int x11_context_verify_and_warn(const X11Context *xc, int log_level, sd_bus_error *error) { + int r; + + assert(xc); + + if (!x11_context_is_safe(xc)) { + if (error) + sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid X11 keyboard layout."); + return log_full_errno(log_level, SYNTHETIC_ERRNO(EINVAL), "Invalid X11 keyboard layout."); + } + + r = verify_xkb_rmlvo(xc->model, xc->layout, xc->variant, xc->options); + if (r == -EOPNOTSUPP) { + log_full_errno(MAX(log_level, LOG_NOTICE), r, + "Cannot verify if new keymap is correct, libxkbcommon.so unavailable."); + return 0; + } + if (r < 0) { + if (error) + sd_bus_error_set_errnof(error, r, "Specified keymap cannot be compiled, refusing as invalid."); + return log_full_errno(log_level, r, + "Cannot compile XKB keymap for x11 keyboard layout " + "(model='%s' / layout='%s' / variant='%s' / options='%s'): %m", + strempty(xc->model), strempty(xc->layout), strempty(xc->variant), strempty(xc->options)); + } + + return 0; +} + void vc_context_clear(VCContext *vc) { assert(vc); diff --git a/src/locale/localed-util.h b/src/locale/localed-util.h index 4ddc560991..0c68f2942e 100644 --- a/src/locale/localed-util.h +++ b/src/locale/localed-util.h @@ -43,6 +43,10 @@ void x11_context_empty_to_null(X11Context *xc); bool x11_context_is_safe(const X11Context *xc); bool x11_context_equal(const X11Context *a, const X11Context *b); int x11_context_copy(X11Context *dest, const X11Context *src); +int x11_context_verify_and_warn(const X11Context *xc, int log_level, sd_bus_error *error); +static inline int x11_context_verify(const X11Context *xc) { + return x11_context_verify_and_warn(xc, LOG_DEBUG, NULL); +} X11Context *context_get_x11_context(Context *c); diff --git a/src/locale/localed.c b/src/locale/localed.c index 587e072c6b..e08f8ac6ef 100644 --- a/src/locale/localed.c +++ b/src/locale/localed.c @@ -26,7 +26,6 @@ #include "string-util.h" #include "strv.h" #include "user-util.h" -#include "xkbcommon-util.h" static int reload_system_manager(sd_bus *bus) { _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL; @@ -491,18 +490,9 @@ static int method_set_x11_keyboard(sd_bus_message *m, void *userdata, sd_bus_err x11_context_empty_to_null(&in); - if (!x11_context_is_safe(&in)) - return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Received invalid keyboard data"); - - r = verify_xkb_rmlvo(in.model, in.layout, in.variant, in.options); - if (r == -EOPNOTSUPP) - log_notice_errno(r, "Cannot verify if new keymap is correct, libxkbcommon.so unavailable."); - else if (r < 0) { - log_error_errno(r, "Cannot compile XKB keymap for new x11 keyboard layout ('%s' / '%s' / '%s' / '%s'): %m", - strempty(in.model), strempty(in.layout), strempty(in.variant), strempty(in.options)); - return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, - "Specified keymap cannot be compiled, refusing as invalid."); - } + r = x11_context_verify_and_warn(&in, LOG_ERR, error); + if (r < 0) + return r; r = vconsole_read_data(c, m); if (r < 0) { |