1 Based on Xorg upstream git commit b07602014061cb41540f6a7e74e4132e67aa1117
2 From: Alan Coopersmith <Alan.Coopersmith@sun.com>
3 Date: Mon, 22 Aug 2005 21:47:59 +0000
5 If MAKE_XKM_OUTPUT_DIR is defined, call trans_mkdir to create directory if
6 it doesn't already exist. (ported from Solaris Xsun bug #5039004)
8 [Xorg has since dropped upstream, but we still use.]
10 Updated to include changes to ensure xkb directory & files are writable
12 6916317 Changing xkb settings after login not working on snv130
14 diff --git a/xkb/Makefile.am b/xkb/Makefile.am
15 index fb3ccbf..5a82e09 100644
19 noinst_LTLIBRARIES = libxkb.la libxkbstubs.la
21 AM_CFLAGS = $(DIX_CFLAGS)
22 +AM_CFLAGS += -DMAKE_XKM_OUTPUT_DIR
26 diff --git a/xkb/ddxLoad.c b/xkb/ddxLoad.c
27 index d462957..9338a1c 100644
30 @@ -68,14 +68,30 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
31 #define PATHSEPARATOR "/"
34 +#ifdef MAKE_XKM_OUTPUT_DIR
35 +/* Borrow trans_mkdir from Xtransutil.c to more safely make directories */
37 +# define TRANS_SERVER
38 +# define prmsg(lvl,...) \
39 + if (lvl <= 1) { LogMessage(X_ERROR, __VA_ARGS__); } else ((void)0)
40 +# include <X11/Xtrans/Xtransutil.c>
41 +# ifndef XKM_OUTPUT_DIR_MODE
42 +# define XKM_OUTPUT_DIR_MODE 0775
47 OutputDirectory(char *outdir, size_t size)
50 +#ifdef MAKE_XKM_OUTPUT_DIR
51 + if (geteuid() == 0 && trans_mkdir(XKM_OUTPUT_DIR, XKM_OUTPUT_DIR_MODE) == 0 && (strlen(XKM_OUTPUT_DIR) < size)) {
53 /* Can we write an xkm and then open it too? */
54 if (access(XKM_OUTPUT_DIR, W_OK | X_OK) == 0 &&
55 (strlen(XKM_OUTPUT_DIR) < size)) {
56 - (void) strcpy(outdir, XKM_OUTPUT_DIR);
58 + (void) strcpy (outdir, XKM_OUTPUT_DIR);
62 @@ -113,6 +129,15 @@ XkbDDXCompileKeymapByNames(XkbDescPtr xkb,
63 const char *xkmfile = "-";
66 + /* save gid and reset to gid 0 before making xkm_output_dir or
67 + running xkbcomp to create the xkm file in it. */
68 + gid_t usr_gid = getgid();
70 + if (setregid(0, usr_gid) < 0)
71 + ErrorF("Error in setting regid to 0: %s\n", strerror(errno));
73 + ErrorF("Error in setting egid to 0: %s\n", strerror(errno));
75 snprintf(keymap, sizeof(keymap), "server-%s", display);
77 OutputDirectory(xkm_output_dir, sizeof(xkm_output_dir));
78 @@ -164,6 +189,11 @@ XkbDDXCompileKeymapByNames(XkbDescPtr xkb,
79 out = fopen(tmpname, "w");
82 + if (setregid(usr_gid, 0) < 0)
83 + ErrorF("Error in resetting regid: %s\n", strerror(errno));
84 + if (setegid(usr_gid) < 0)
85 + ErrorF("Error in resetting egid: %s\n", strerror(errno));