1185N/ABased on Xorg upstream git commit b07602014061cb41540f6a7e74e4132e67aa1117
606N/AFrom: Alan Coopersmith <Alan.Coopersmith@sun.com>
606N/ADate: Mon, 22 Aug 2005 21:47:59 +0000
606N/A
606N/AIf MAKE_XKM_OUTPUT_DIR is defined, call trans_mkdir to create directory if
606N/Ait doesn't already exist. (ported from Solaris Xsun bug #5039004)
606N/A
606N/A[Xorg has since dropped upstream, but we still use.]
606N/A
880N/AUpdated to include changes to ensure xkb directory & files are writable
880N/Aby gid 0, to fix bug:
880N/A6916317 Changing xkb settings after login not working on snv130
880N/A
1124N/Adiff --git a/xkb/Makefile.am b/xkb/Makefile.am
1124N/Aindex fb3ccbf..5a82e09 100644
1124N/A--- a/xkb/Makefile.am
1124N/A+++ b/xkb/Makefile.am
606N/A@@ -1,6 +1,7 @@
606N/A noinst_LTLIBRARIES = libxkb.la libxkbstubs.la
606N/A
1088N/A AM_CFLAGS = $(DIX_CFLAGS)
1088N/A+AM_CFLAGS += -DMAKE_XKM_OUTPUT_DIR
606N/A
606N/A DDX_SRCS = \
1088N/A ddxBeep.c \
1124N/Adiff --git a/xkb/ddxLoad.c b/xkb/ddxLoad.c
1340N/Aindex d462957..9338a1c 100644
1124N/A--- a/xkb/ddxLoad.c
1124N/A+++ b/xkb/ddxLoad.c
1340N/A@@ -68,14 +68,30 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
1340N/A #define PATHSEPARATOR "/"
606N/A #endif
606N/A
606N/A+#ifdef MAKE_XKM_OUTPUT_DIR
606N/A+/* Borrow trans_mkdir from Xtransutil.c to more safely make directories */
606N/A+# undef X11_t
606N/A+# define TRANS_SERVER
1276N/A+# define prmsg(lvl,...) \
1276N/A+ if (lvl <= 1) { LogMessage(X_ERROR, __VA_ARGS__); } else ((void)0)
606N/A+# include <X11/Xtrans/Xtransutil.c>
606N/A+# ifndef XKM_OUTPUT_DIR_MODE
880N/A+# define XKM_OUTPUT_DIR_MODE 0775
606N/A+# endif
606N/A+#endif
606N/A+
606N/A static void
1276N/A OutputDirectory(char *outdir, size_t size)
606N/A {
606N/A #ifndef WIN32
1185N/A+#ifdef MAKE_XKM_OUTPUT_DIR
1286N/A+ if (geteuid() == 0 && trans_mkdir(XKM_OUTPUT_DIR, XKM_OUTPUT_DIR_MODE) == 0 && (strlen(XKM_OUTPUT_DIR) < size)) {
1286N/A+#else
1276N/A /* Can we write an xkm and then open it too? */
1276N/A if (access(XKM_OUTPUT_DIR, W_OK | X_OK) == 0 &&
1276N/A (strlen(XKM_OUTPUT_DIR) < size)) {
1286N/A- (void) strcpy(outdir, XKM_OUTPUT_DIR);
1286N/A+#endif
1286N/A+ (void) strcpy (outdir, XKM_OUTPUT_DIR);
1286N/A }
1286N/A else
1286N/A #else
1340N/A@@ -113,6 +129,15 @@ XkbDDXCompileKeymapByNames(XkbDescPtr xkb,
880N/A const char *xkmfile = "-";
880N/A #endif
880N/A
880N/A+ /* save gid and reset to gid 0 before making xkm_output_dir or
880N/A+ running xkbcomp to create the xkm file in it. */
1276N/A+ gid_t usr_gid = getgid();
880N/A+
880N/A+ if (setregid(0, usr_gid) < 0)
1265N/A+ ErrorF("Error in setting regid to 0: %s\n", strerror(errno));
880N/A+ if (setegid(0) < 0)
1265N/A+ ErrorF("Error in setting egid to 0: %s\n", strerror(errno));
880N/A+
880N/A snprintf(keymap, sizeof(keymap), "server-%s", display);
880N/A
880N/A OutputDirectory(xkm_output_dir, sizeof(xkm_output_dir));
1340N/A@@ -164,6 +189,11 @@ XkbDDXCompileKeymapByNames(XkbDescPtr xkb,
1276N/A out = fopen(tmpname, "w");
880N/A #endif
1276N/A
880N/A+ if (setregid(usr_gid, 0) < 0)
1265N/A+ ErrorF("Error in resetting regid: %s\n", strerror(errno));
880N/A+ if (setegid(usr_gid) < 0)
1265N/A+ ErrorF("Error in resetting egid: %s\n", strerror(errno));
1276N/A+
1276N/A if (out != NULL) {
880N/A #ifdef DEBUG
1276N/A if (xkbDebugFlags) {