chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
man: wording and grammar updates
[elogind.git]
/
src
/
locale
/
localed.c
diff --git
a/src/locale/localed.c
b/src/locale/localed.c
index 56fb339e19cd023f33d5dd76120ea88b8b6a288d..e160c046a47924b9ad89425a342c454f4a1b6933 100644
(file)
--- a/
src/locale/localed.c
+++ b/
src/locale/localed.c
@@
-31,6
+31,10
@@
#include "dbus-common.h"
#include "polkit.h"
#include "def.h"
#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" \
#define INTERFACE \
" <interface name=\"org.freedesktop.locale1\">\n" \
@@
-114,21
+118,7
@@
static const char * const names[_PROP_MAX] = {
[PROP_LC_IDENTIFICATION] = "LC_IDENTIFICATION"
};
[PROP_LC_IDENTIFICATION] = "LC_IDENTIFICATION"
};
-static char *data[_PROP_MAX] = {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL
-};
+static char *data[_PROP_MAX] = {};
typedef struct State {
char *x11_layout, *x11_model, *x11_variant, *x11_options;
typedef struct State {
char *x11_layout, *x11_model, *x11_variant, *x11_options;
@@
-271,24
+261,8
@@
static int read_data_x11(void) {
free_data_x11();
f = fopen("/etc/X11/xorg.conf.d/00-keyboard.conf", "re");
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;
while (fgets(line, sizeof(line), f)) {
char *l;
@@
-367,7
+341,7
@@
static int write_data_locale(void) {
int r, p;
char **l = NULL;
int r, p;
char **l = NULL;
- r = load_env_file("/etc/locale.conf", &l);
+ r = load_env_file("/etc/locale.conf",
NULL,
&l);
if (r < 0 && r != -ENOENT)
return r;
if (r < 0 && r != -ENOENT)
return r;
@@
-405,7
+379,7
@@
static int write_data_locale(void) {
return 0;
}
return 0;
}
- r = write_env_file("/etc/locale.conf", l);
+ r = write_env_file
_label
("/etc/locale.conf", l);
strv_free(l);
return r;
strv_free(l);
return r;
@@
-425,7
+399,7
@@
static void push_data(DBusConnection *bus) {
l_set = new0(char*, _PROP_MAX);
l_unset = new0(char*, _PROP_MAX);
if (!l_set || !l_unset) {
l_set = new0(char*, _PROP_MAX);
l_unset = new0(char*, _PROP_MAX);
if (!l_set || !l_unset) {
- log_
error("Out of memory"
);
+ log_
oom(
);
goto finish;
}
goto finish;
}
@@
-438,7
+412,7
@@
static void push_data(DBusConnection *bus) {
char *s;
if (asprintf(&s, "%s=%s", names[p], data[p]) < 0) {
char *s;
if (asprintf(&s, "%s=%s", names[p], data[p]) < 0) {
- log_
error("Out of memory"
);
+ log_
oom(
);
goto finish;
}
goto finish;
}
@@
-456,30
+430,30
@@
static void push_data(DBusConnection *bus) {
dbus_message_iter_init_append(m, &iter);
if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "s", &sub)) {
dbus_message_iter_init_append(m, &iter);
if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "s", &sub)) {
- log_
error("Out of memory."
);
+ log_
oom(
);
goto finish;
}
STRV_FOREACH(t, l_unset)
if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, t)) {
goto finish;
}
STRV_FOREACH(t, l_unset)
if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, t)) {
- log_
error("Out of memory."
);
+ log_
oom(
);
goto finish;
}
if (!dbus_message_iter_close_container(&iter, &sub) ||
!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "s", &sub)) {
goto finish;
}
if (!dbus_message_iter_close_container(&iter, &sub) ||
!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "s", &sub)) {
- log_
error("Out of memory."
);
+ log_
oom(
);
goto finish;
}
STRV_FOREACH(t, l_set)
if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, t)) {
goto finish;
}
STRV_FOREACH(t, l_set)
if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, t)) {
- log_
error("Out of memory."
);
+ log_
oom(
);
goto finish;
}
if (!dbus_message_iter_close_container(&iter, &sub)) {
goto finish;
}
if (!dbus_message_iter_close_container(&iter, &sub)) {
- log_
error("Out of memory."
);
+ log_
oom(
);
goto finish;
}
goto finish;
}
@@
-506,7
+480,7
@@
static int write_data_vconsole(void) {
int r;
char **l = NULL;
int r;
char **l = NULL;
- r = load_env_file("/etc/vconsole.conf", &l);
+ r = load_env_file("/etc/vconsole.conf",
NULL,
&l);
if (r < 0 && r != -ENOENT)
return r;
if (r < 0 && r != -ENOENT)
return r;
@@
-561,7
+535,7
@@
static int write_data_vconsole(void) {
return 0;
}
return 0;
}
- r = write_env_file("/etc/vconsole.conf", l);
+ r = write_env_file
_label
("/etc/vconsole.conf", l);
strv_free(l);
return r;
strv_free(l);
return r;
@@
-577,21
+551,13
@@
static int write_data_x11(void) {
isempty(state.x11_variant) &&
isempty(state.x11_options)) {
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;
}
if (unlink("/etc/X11/xorg.conf.d/00-keyboard.conf") < 0)
return errno == ENOENT ? 0 : -errno;
return 0;
}
- mkdir_p
arents
_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)
r = fopen_temporary("/etc/X11/xorg.conf.d/00-keyboard.conf", &f, &temp_path);
if (r < 0)
@@
-624,18
+590,8
@@
static int write_data_x11(void) {
r = -errno;
unlink("/etc/X11/xorg.conf.d/00-keyboard.conf");
unlink(temp_path);
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;
r = 0;
- }
fclose(f);
free(temp_path);
fclose(f);
free(temp_path);
@@
-887,7
+843,7
@@
static int convert_x11_to_vconsole(DBusConnection *connection) {
* layout stripped off. */
if (x > 0 &&
strlen(a[1]) == x &&
* layout stripped off. */
if (x > 0 &&
strlen(a[1]) == x &&
- strn
cmp(state.x11_layout, a[1], x) == 0
)
+ strn
eq(state.x11_layout, a[1], x)
)
matching = 5;
else {
size_t w;
matching = 5;
else {
size_t w;
@@
-1041,7
+997,7
@@
static DBusHandlerResult locale_message_handler(
dbus_bool_t interactive;
DBusMessageIter iter;
bool modified = false;
dbus_bool_t interactive;
DBusMessageIter iter;
bool modified = false;
- bool passed[_PROP_MAX];
+ bool passed[_PROP_MAX]
= {}
;
int p;
if (!dbus_message_iter_init(message, &iter))
int p;
if (!dbus_message_iter_init(message, &iter))
@@
-1063,8
+1019,6
@@
static DBusHandlerResult locale_message_handler(
dbus_message_iter_get_basic(&iter, &interactive);
dbus_message_iter_get_basic(&iter, &interactive);
- zero(passed);
-
/* Check whether a variable changed and if so valid */
STRV_FOREACH(i, l) {
bool valid = false;
/* Check whether a variable changed and if so valid */
STRV_FOREACH(i, l) {
bool valid = false;
@@
-1073,7
+1027,9
@@
static DBusHandlerResult locale_message_handler(
size_t k;
k = strlen(names[p]);
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;
valid = true;
passed[p] = true;
@@
-1157,7
+1113,9
@@
static DBusHandlerResult locale_message_handler(
"Locale\0");
if (!changed)
goto oom;
"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;
} else if (dbus_message_is_method_call(message, "org.freedesktop.locale1", "SetVConsoleKeyboard")) {
const char *keymap, *keymap_toggle;
@@
-1182,6
+1140,10
@@
static DBusHandlerResult locale_message_handler(
if (!streq_ptr(keymap, state.vc_keymap) ||
!streq_ptr(keymap_toggle, state.vc_keymap_toggle)) {
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);
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
+1214,12
@@
static DBusHandlerResult locale_message_handler(
!streq_ptr(variant, state.x11_variant) ||
!streq_ptr(options, state.x11_options)) {
!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);
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);
@@
-1293,7
+1261,7
@@
static DBusHandlerResult locale_message_handler(
if (!(reply = dbus_message_new_method_return(message)))
goto oom;
if (!(reply = dbus_message_new_method_return(message)))
goto oom;
- if (!
dbus_connection_send(connection, reply, NULL
))
+ if (!
bus_maybe_send_reply(connection, message, reply
))
goto oom;
dbus_message_unref(reply);
goto oom;
dbus_message_unref(reply);
@@
-1344,8
+1312,7
@@
static int connect_bus(DBusConnection **_bus) {
if (!dbus_connection_register_object_path(bus, "/org/freedesktop/locale1", &locale_vtable, NULL) ||
!dbus_connection_add_filter(bus, bus_exit_idle_filter, &remain_until, NULL)) {
if (!dbus_connection_register_object_path(bus, "/org/freedesktop/locale1", &locale_vtable, NULL) ||
!dbus_connection_add_filter(bus, bus_exit_idle_filter, &remain_until, NULL)) {
- log_error("Not enough memory");
- r = -ENOMEM;
+ r = log_oom();
goto fail;
}
goto fail;
}
@@
-1384,7
+1351,7
@@
int main(int argc, char *argv[]) {
log_set_target(LOG_TARGET_AUTO);
log_parse_environment();
log_open();
log_set_target(LOG_TARGET_AUTO);
log_parse_environment();
log_open();
-
+ label_init("/etc");
umask(0022);
if (argc == 2 && streq(argv[1], "--introspect")) {
umask(0022);
if (argc == 2 && streq(argv[1], "--introspect")) {