]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
locale: always check input keyboard layout and friends earlier
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 26 Jan 2023 08:48:11 +0000 (17:48 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 28 Jan 2023 05:47:36 +0000 (14:47 +0900)
src/locale/localed.c

index dcd3b3e38dce9b881b2e6df8b45aecd995d35998..88f5604f1ed63a2abadb0e23cd464f9df5b6ffae 100644 (file)
@@ -378,12 +378,6 @@ static int method_set_vc_keyboard(sd_bus_message *m, void *userdata, sd_bus_erro
 
         vc_context_empty_to_null(&in);
 
-        r = vconsole_read_data(c, m);
-        if (r < 0) {
-                log_error_errno(r, "Failed to read virtual console keymap data: %m");
-                return sd_bus_error_set_errnof(error, r, "Failed to read virtual console keymap data: %m");
-        }
-
         FOREACH_STRING(name, in.keymap ?: in.toggle, in.keymap ? in.toggle : NULL) {
                 r = keymap_exists(name); /* This also verifies that the keymap name is kosher. */
                 if (r < 0) {
@@ -394,6 +388,12 @@ static int method_set_vc_keyboard(sd_bus_message *m, void *userdata, sd_bus_erro
                         return sd_bus_error_setf(error, SD_BUS_ERROR_FAILED, "Keymap %s is not installed.", name);
         }
 
+        r = vconsole_read_data(c, m);
+        if (r < 0) {
+                log_error_errno(r, "Failed to read virtual console keymap data: %m");
+                return sd_bus_error_set_errnof(error, r, "Failed to read virtual console keymap data: %m");
+        }
+
         if (vc_context_equal(&c->vc, &in))
                 return sd_bus_reply_method_return(m, NULL);
 
@@ -580,17 +580,6 @@ static int method_set_x11_keyboard(sd_bus_message *m, void *userdata, sd_bus_err
 
         x11_context_empty_to_null(&in);
 
-        r = x11_read_data(c, m);
-        if (r < 0) {
-                log_error_errno(r, "Failed to read x11 keyboard layout data: %m");
-                return sd_bus_error_set(error, SD_BUS_ERROR_FAILED, "Failed to read x11 keyboard layout data");
-        }
-
-        xc = context_get_x11_context(c);
-
-        if (x11_context_equal(xc, &in))
-                return sd_bus_reply_method_return(m, NULL);
-
         if (!x11_context_is_safe(&in))
                 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Received invalid keyboard data");
 
@@ -605,6 +594,17 @@ static int method_set_x11_keyboard(sd_bus_message *m, void *userdata, sd_bus_err
                 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Specified keymap cannot be compiled, refusing as invalid.");
         }
 
+        r = x11_read_data(c, m);
+        if (r < 0) {
+                log_error_errno(r, "Failed to read x11 keyboard layout data: %m");
+                return sd_bus_error_set(error, SD_BUS_ERROR_FAILED, "Failed to read x11 keyboard layout data");
+        }
+
+        xc = context_get_x11_context(c);
+
+        if (x11_context_equal(xc, &in))
+                return sd_bus_reply_method_return(m, NULL);
+
         r = bus_verify_polkit_async(
                         m,
                         CAP_SYS_ADMIN,