mirror of
https://github.com/systemd/systemd.git
synced 2025-01-26 14:04:03 +03:00
locale: introduce x11_context_verify()
No functional change, preparation for later commits.
This commit is contained in:
parent
d45cbc0711
commit
0327d5b20f
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user