unicode_{start,stop}: To run loadkeys is allowed only to root
authorAlexey Gladkov <legion@altlinux.org>
Thu, 21 Feb 2008 22:36:54 +0000 (01:36 +0300)
committerAlexey Gladkov <legion@altlinux.org>
Thu, 21 Feb 2008 22:41:51 +0000 (01:41 +0300)
Signed-off-by: Alexey Gladkov <legion@altlinux.org>
CHANGES
src/unicode_start
src/unicode_stop

diff --git a/CHANGES b/CHANGES
index eb9c301..3364e7c 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -4,6 +4,8 @@ o Build system:
   - Fix computing of the host-system type.
   - Fix options handling (thanks for the help to Mike Frysinger).
   - Fix DESTDIR handling.
+o Programs:
+  - unicode_{start,stop}: To run loadkeys is allowed only to root.
 o Keymaps:
   - Add Norwegian dvorak keymap.
   - Add turkish F (trf) keyboard map.
index 7eb98d9..82ef457 100755 (executable)
@@ -30,24 +30,33 @@ kbd_mode -u
 # produce UTF-8 encoded multibyte sequences, instead of single bytes
 # >= 0x80 in a legacy 8-bit encoding.
 
-# There is no way of reverting the effect of "dumpkeys | loadkeys --unicode",
-# the memory of the earlier keymap is lost. Therefore, try
-# to save a copy of the original keymap to be able to reload it in unicode_stop.
-# (see also http://mail.nl.linux.org/linux-utf8/2003-08/msg00053.html):
-
-[ -n "$HOME" -a "$HOME" != '/' ] ||
-       HOME='/root'
-
-if [ -d "$HOME" ]; then
-       [ -d "$HOME/.kbd" ] ||
-               mkdir -- "$HOME/.kbd"
-       dumpkeys > "$HOME/.kbd/.keymap_sv"
-fi
+# Non-root users are allowed to change the unicode mode of their console, but
+# not the global keymap. root will have to load the keymap in unicode mode
+# explicitly.
+
+uid="`id -u 2>/dev/null`" ||:
+if [ "$uid" = '0' ]; then
+       # There is no way of reverting the effect of "dumpkeys | loadkeys --unicode",
+       # the memory of the earlier keymap is lost. Therefore, try
+       # to save a copy of the original keymap to be able to reload it in unicode_stop.
+       # (see also http://mail.nl.linux.org/linux-utf8/2003-08/msg00053.html):
+
+       [ -n "$HOME" -a "$HOME" != '/' ] ||
+               HOME='/root'
 
-# redirect stderr and stdout of loadkeys to /dev/null to avoid the confusing
-# "plus before udiaeresis ignored" warnings.
+       if [ -d "$HOME" -a -w "$HOME" ]; then
+               [ -d "$HOME/.kbd" ] ||
+                       mkdir -- "$HOME/.kbd"
 
-dumpkeys | loadkeys --unicode > /dev/null 2>&1
+               [ ! -w "$HOME/.kbd" ] ||
+                       dumpkeys > "$HOME/.kbd/.keymap_sv"
+       fi
+
+       # redirect stderr and stdout of loadkeys to /dev/null to avoid the confusing
+       # "plus before udiaeresis ignored" warnings.
+
+       dumpkeys | loadkeys --unicode > /dev/null 2>&1
+fi
 
 # 2. The output side: the console screen.
 
index 05b0b8e..07a8e4b 100755 (executable)
@@ -17,9 +17,8 @@ if test -t ; then
 fi
 stty -iutf8
 
-# "dumpkeys | loadkeys --unicode" which is called in "unicode_start"
-# cannot be reverted, therefore we have to load the keyboard mapping again
-# if it could be sucessfully saved in "unicode_start":
-
-[ ! -r "$HOME/.kbd/.keymap_sv" ] ||
-       loadkeys "$HOME/.kbd/.keymap_sv"
+uid="`id -u 2>/dev/null`" ||:
+if [ "$uid" = '0' ]; then
+       [ ! -r "$HOME/.kbd/.keymap_sv" ] ||
+               loadkeys "$HOME/.kbd/.keymap_sv"
+fi