diff -r f9b973ecc909 -r 24ca414edbff open-src/xserver/xorg/xorgconfig.patch --- a/open-src/xserver/xorg/xorgconfig.patch Thu May 14 20:00:54 2009 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,290 +0,0 @@ -diff -urp -x '*~' -x '*.orig' hw/xfree86/utils/xorgconfig/xorgconfig.c hw/xfree86/utils/xorgconfig/xorgconfig.c ---- hw/xfree86/utils/xorgconfig/xorgconfig.c 2008-09-23 11:24:59.000000000 -0700 -+++ hw/xfree86/utils/xorgconfig/xorgconfig.c 2008-09-23 16:32:21.769251000 -0700 -@@ -1,3 +1,30 @@ -+/* Copyright 2005 Sun Microsystems, Inc. All rights reserved. -+ * -+ * Permission is hereby granted, free of charge, to any person obtaining a -+ * copy of this software and associated documentation files (the -+ * "Software"), to deal in the Software without restriction, including -+ * without limitation the rights to use, copy, modify, merge, publish, -+ * distribute, and/or sell copies of the Software, and to permit persons -+ * to whom the Software is furnished to do so, provided that the above -+ * copyright notice(s) and this permission notice appear in all copies of -+ * the Software and that both the above copyright notice(s) and this -+ * permission notice appear in supporting documentation. -+ * -+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT -+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL -+ * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING -+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, -+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION -+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -+ * -+ * Except as contained in this notice, the name of a copyright holder -+ * shall not be used in advertising or otherwise to promote the sale, use -+ * or other dealings in this Software without prior written authorization -+ * of the copyright holder. -+ */ - /* - * This is a configuration program that will create a base XF86Config - * file based on menu choices. Its main feature is that clueless users -@@ -112,6 +139,15 @@ - - #include "cards.h" - -+#ifdef SUNSOFT /* setuid support for running under RBAC */ -+#include -+#include -+#include -+#include -+static int euid_changed = 0; -+static uid_t saved_id = -1; -+static void configdir_check(void); -+#endif - - /* - * Define the following to 310 to remove references to XFree86 features that -@@ -249,7 +285,11 @@ static char *intro_text = - "This program will create a basic " CONFIGNAME " file, based on menu selections\n" - "you make. It will ask for a pathname when it is ready to write the file.\n" - "\n" -+#ifdef SUNSOFT -+"The " CONFIGNAME " file usually resides in /etc/X11. If\n" -+#else - "The " CONFIGNAME " file usually resides in /etc/X11 or " TREEROOTCFG ". If\n" -+#endif - "no " CONFIGNAME " file is present there, " __XSERVERNAME__" will probe the system to\n" - "autoconfigure itself. You can run " __XSERVERNAME__ " -configure to generate a " CONFIGNAME "\n" - "file based on the results of autoconfiguration, or let this program\n" -@@ -1702,6 +1742,7 @@ skipclockprobing: - config_virtual = 0; - for (;;) { - char modes[128]; -+ int modes_space_left; - - emptylines(); - -@@ -1735,24 +1776,29 @@ skipclockprobing: - printf("\n"); - - modes[0] = '\0'; -+ modes_space_left = sizeof(modes) - 1; - for (i = 0; i < strlen(s); i++) { -- if ( NU_MODESTRINGS > 9 ) { -- if ((s[i] < '1' || s[i] > '9') && -- (s[i] < 'a' || s[i] > 'a' + NU_MODESTRINGS - 10)) { -- printf("Invalid mode skipped.\n"); -+ int choice = -1; -+ -+ if ((s[i] >= '1') && (s[i] <= '9')) { -+ choice = s[i] - '1'; -+ } else if ((s[i] >= 'a') && -+ (s[i] <= ('a' + NU_MODESTRINGS - 10))) { -+ choice = s[i] - 'a' + 9; -+ } -+ -+ if ( (choice < 0) || (choice > NU_MODESTRINGS) ) { -+ printf("Invalid mode %c skipped.\n", s[i]); - continue; -- } -- } -- else { -- if (s[i] < '1' || s[i] > '0' + NU_MODESTRINGS) { -- printf("Invalid mode skipped.\n"); -- continue; -- } - } -- if (i > 0) -+ if ((i > 0) && (modes_space_left > 1)) { - strcat(modes, " "); -- strcat(modes, modestring[s[i] <= '9' ? s[i] - '1' : -- s[i] - 'a' + 9]); -+ modes_space_left--; -+ } -+ if (modes_space_left > strlen(modestring[choice])) { -+ modes_space_left -= strlen(modestring[choice]); -+ strcat(modes, modestring[choice]); -+ } - } - switch (c) { - case 0 : -@@ -1883,10 +1929,21 @@ static char *XF86Config_firstchunk_text - "# Load \"type1\"\n" - #endif - " Load \"freetype\"\n" -+#ifndef SUNSOFT - "# Load \"xtt\"\n" -+#endif - "\n" -+#ifdef SUNSOFT -+"# This loads the SolarisIA module\n" -+" Load \"IA\"\n" -+"# This loads the GLX module\n" -+" Load \"glx\"\n" -+"# This loads the Solaris Trusted Extensions module if it is installed\n" -+" Load \"xtsol\"\n" -+#else - "# This loads the GLX module\n" - "# Load \"glx\"\n" -+#endif - "# This loads the DRI module\n" - "# Load \"dri\"\n" - "\n" -@@ -2463,20 +2520,71 @@ write_fontpath_section(FILE *f) - static int - write_XF86Config(char *filename) - { -- FILE *f; -+ FILE *f = NULL; -+ int fd; -+ - - /* - * Write the file. - */ - -- f = fopen(filename, "w"); -- if (f == NULL) { -+#ifdef SUNSOFT -+ int need_uid_reset = 0; -+ if (euid_changed && (strcmp(filename, "/etc/X11/"XCONFIGFILE) == 0)) { -+ if (seteuid(saved_id) == 0) { -+ need_uid_reset = 1; -+ } -+ } -+ configdir_check(); -+#endif -+ -+#if defined(O_NOFOLLOW) && defined(O_NOLINKS) -+# define EXTRA_OPEN_FLAGS O_NOFOLLOW | O_NOLINKS -+#endif -+ fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC | EXTRA_OPEN_FLAGS, 0644); -+ -+#ifdef SUNSOFT -+ if (need_uid_reset) { -+ if (seteuid(getuid()) != 0) { -+ perror("xorgconfig: could not reset euid"); -+ exit(-1); -+ } -+ } -+#endif -+ if (fd >= 0) { -+ f = fdopen(fd, "w"); -+ } -+ -+ if ((fd < 0) || (f == NULL)) { - printf("Failed to open filename for writing.\n"); - if (getuid() != 0) - printf("Maybe you need to be root to write to the specified directory?\n"); - return(1); - } - -+#ifdef SUNSOFT -+ { -+ char hostname[MAXHOSTNAMELEN] = ""; -+ struct passwd *pwd = getpwuid(getuid()); -+ char *username, *timestamp; -+ time_t now; -+ -+ if (pwd == NULL) { -+ username = Malloc(32); -+ snprintf(username, 32, "uid %l", (long) getuid()); -+ } else { -+ username = pwd->pw_name; -+ } -+ -+ gethostname(hostname, sizeof(hostname)); -+ -+ time(&now); -+ timestamp = ctime(&now); -+ -+ fprintf(f, "# Generated by %s on %s at %s\n", -+ username, hostname, timestamp); -+ } -+#endif - fprintf(f, "%s", XF86Config_firstchunk_text); - write_fontpath_section(f); - fprintf(f, "%s", XF86Config_fontpathchunk_text); -@@ -2702,7 +2810,11 @@ ask_XF86Config_location(void) { - "I am going to write the " CONFIGNAME " file now. Make sure you don't accidently\n" - "overwrite a previously configured one.\n\n"); - -+#ifdef SUNSOFT -+ if ((geteuid() == 0) || euid_changed) { -+#else - if (getuid() == 0) { -+#endif - #ifdef PREFER_XF86CONFIG_IN_ETC - filename = Strdup("/etc/X11/" XCONFIGFILE); - filename = append_version(filename); -@@ -2713,6 +2825,7 @@ ask_XF86Config_location(void) { - return filename; - #endif - -+#ifndef SUNSOFT - if (filename) - free(filename); - filename = Strdup(TREEROOTCFG "/" XCONFIGFILE); -@@ -2723,6 +2836,7 @@ ask_XF86Config_location(void) { - printf("\n"); - if (answerisyes(s)) - return filename; -+#endif - - #ifndef PREFER_XF86CONFIG_IN_ETC - if (filename) -@@ -2824,12 +2938,18 @@ static void - configdir_check(void) - { - /* /etc/X11 may not exist on some systems */ -+#ifdef SUNSOFT -+ if (geteuid() == 0) { -+#else - if (getuid() == 0) { -+#endif - struct stat buf; - if (stat("/etc/X11", &buf) == -1 && errno == ENOENT) - mkdir("/etc/X11", 0777); -+#ifndef SUNSOFT - if (stat(TREEROOTCFG, &buf) == -1 && errno == ENOENT) - mkdir(TREEROOTCFG, 0777); -+#endif - } - } - -@@ -2840,6 +2960,19 @@ configdir_check(void) - - int - main(int argc, char *argv[]) { -+ -+#ifdef SUNSOFT -+ /* Try to run more securely when being run seteuid via RBAC */ -+ if (issetugid() || (geteuid() != getuid())) { -+ saved_id = geteuid(); -+ if (seteuid(getuid()) == 0) { -+ euid_changed = 1; -+ } else { -+ perror("xorgconfig: could not reset euid"); -+ exit(-1); -+ } -+ } -+#endif - - createtmpdir(); - -@@ -2854,9 +2987,11 @@ main(int argc, char *argv[]) { - - emptylines(); - -+#ifndef SUNSOFT /* Moved into write_XF86Config */ - configdir_check(); - - emptylines(); -+#endif - - mouse_configuration(); -