chiark / gitweb /
systemctl: try to reload daemon after enable/disable only when not running in a chroot
[elogind.git] / src / locale / localed.c
index 22950a60a988db33db185e1aa38cce5c7503d8ef..4f85b8b583ddab7fb2e5bfaad5441cf4aa6a715e 100644 (file)
 #include "dbus-common.h"
 #include "polkit.h"
 #include "def.h"
+#include "env-util.h"
+#include "fileio.h"
+#include "fileio-label.h"
+#include "label.h"
 
 #define INTERFACE                                                       \
         " <interface name=\"org.freedesktop.locale1\">\n"               \
@@ -271,24 +275,8 @@ static int read_data_x11(void) {
         free_data_x11();
 
         f = fopen("/etc/X11/xorg.conf.d/00-keyboard.conf", "re");
-        if (!f) {
-                if (errno == ENOENT) {
-
-#ifdef TARGET_FEDORA
-                        f = fopen("/etc/X11/xorg.conf.d/00-system-setup-keyboard.conf", "re");
-                        if (!f) {
-                                if (errno == ENOENT)
-                                        return 0;
-                                else
-                                        return -errno;
-                        }
-#else
-                        return 0;
-#endif
-
-                } else
-                          return -errno;
-        }
+        if (!f)
+                return errno == ENOENT ? 0 : -errno;
 
         while (fgets(line, sizeof(line), f)) {
                 char *l;
@@ -405,7 +393,7 @@ static int write_data_locale(void) {
                 return 0;
         }
 
-        r = write_env_file("/etc/locale.conf", l);
+        r = write_env_file_label("/etc/locale.conf", l);
         strv_free(l);
 
         return r;
@@ -561,7 +549,7 @@ static int write_data_vconsole(void) {
                 return 0;
         }
 
-        r = write_env_file("/etc/vconsole.conf", l);
+        r = write_env_file_label("/etc/vconsole.conf", l);
         strv_free(l);
 
         return r;
@@ -577,21 +565,13 @@ static int write_data_x11(void) {
             isempty(state.x11_variant) &&
             isempty(state.x11_options)) {
 
-#ifdef TARGET_FEDORA
-                unlink("/etc/X11/xorg.conf.d/00-system-setup-keyboard.conf");
-
-                /* Symlink this to /dev/null, so that s-s-k (if it is
-                 * still running) doesn't recreate this. */
-                symlink("/dev/null", "/etc/X11/xorg.conf.d/00-system-setup-keyboard.conf");
-#endif
-
                 if (unlink("/etc/X11/xorg.conf.d/00-keyboard.conf") < 0)
                         return errno == ENOENT ? 0 : -errno;
 
                 return 0;
         }
 
-        mkdir_parents_label("/etc/X11/xorg.conf.d", 0755);
+        mkdir_p_label("/etc/X11/xorg.conf.d", 0755);
 
         r = fopen_temporary("/etc/X11/xorg.conf.d/00-keyboard.conf", &f, &temp_path);
         if (r < 0)
@@ -624,18 +604,8 @@ static int write_data_x11(void) {
                 r = -errno;
                 unlink("/etc/X11/xorg.conf.d/00-keyboard.conf");
                 unlink(temp_path);
-        } else {
-
-#ifdef TARGET_FEDORA
-                unlink("/etc/X11/xorg.conf.d/00-system-setup-keyboard.conf");
-
-                /* Symlink this to /dev/null, so that s-s-k (if it is
-                 * still running) doesn't recreate this. */
-                symlink("/dev/null", "/etc/X11/xorg.conf.d/00-system-setup-keyboard.conf");
-#endif
-
+        } else
                 r = 0;
-        }
 
         fclose(f);
         free(temp_path);
@@ -887,7 +857,7 @@ static int convert_x11_to_vconsole(DBusConnection *connection) {
                                  * layout stripped off. */
                                 if (x > 0 &&
                                     strlen(a[1]) == x &&
-                                    strncmp(state.x11_layout, a[1], x) == 0)
+                                    strneq(state.x11_layout, a[1], x))
                                         matching = 5;
                                 else  {
                                         size_t w;
@@ -1073,7 +1043,9 @@ static DBusHandlerResult locale_message_handler(
                                 size_t k;
 
                                 k = strlen(names[p]);
-                                if (startswith(*i, names[p]) && (*i)[k] == '=') {
+                                if (startswith(*i, names[p]) &&
+                                    (*i)[k] == '=' &&
+                                    string_is_safe((*i) + k + 1)) {
                                         valid = true;
                                         passed[p] = true;
 
@@ -1157,7 +1129,9 @@ static DBusHandlerResult locale_message_handler(
                                         "Locale\0");
                         if (!changed)
                                 goto oom;
-                }
+                } else
+                        strv_free(l);
+
         } else if (dbus_message_is_method_call(message, "org.freedesktop.locale1", "SetVConsoleKeyboard")) {
 
                 const char *keymap, *keymap_toggle;
@@ -1182,6 +1156,10 @@ static DBusHandlerResult locale_message_handler(
                 if (!streq_ptr(keymap, state.vc_keymap) ||
                     !streq_ptr(keymap_toggle, state.vc_keymap_toggle)) {
 
+                        if ((keymap && (!filename_is_safe(keymap) || !string_is_safe(keymap))) ||
+                            (keymap_toggle && (!filename_is_safe(keymap_toggle) || !string_is_safe(keymap_toggle))))
+                                return bus_send_error_reply(connection, message, NULL, -EINVAL);
+
                         r = verify_polkit(connection, message, "org.freedesktop.locale1.set-keyboard", interactive, NULL, &error);
                         if (r < 0)
                                 return bus_send_error_reply(connection, message, &error, r);
@@ -1252,6 +1230,12 @@ static DBusHandlerResult locale_message_handler(
                     !streq_ptr(variant, state.x11_variant) ||
                     !streq_ptr(options, state.x11_options)) {
 
+                        if ((layout && !string_is_safe(layout)) ||
+                            (model && !string_is_safe(model)) ||
+                            (variant && !string_is_safe(variant)) ||
+                            (options && !string_is_safe(options)))
+                                return bus_send_error_reply(connection, message, NULL, -EINVAL);
+
                         r = verify_polkit(connection, message, "org.freedesktop.locale1.set-keyboard", interactive, NULL, &error);
                         if (r < 0)
                                 return bus_send_error_reply(connection, message, &error, r);
@@ -1383,7 +1367,7 @@ int main(int argc, char *argv[]) {
         log_set_target(LOG_TARGET_AUTO);
         log_parse_environment();
         log_open();
-
+        label_init("/etc");
         umask(0022);
 
         if (argc == 2 && streq(argv[1], "--introspect")) {