From 965e398053c37c346d485f2a6c429a0cff59a6b2 Mon Sep 17 00:00:00 2001 From: kappa1 Date: Thu, 22 Apr 2010 18:32:46 +0000 Subject: [PATCH] Remove extra permissions from XRandR and just allow minimal permissions needed by the LinuxDisplay. --- src/java/org/lwjgl/opengl/LinuxDisplay.java | 23 ++++++++++-- src/java/org/lwjgl/opengl/XRandR.java | 41 ++++----------------- 2 files changed, 27 insertions(+), 37 deletions(-) diff --git a/src/java/org/lwjgl/opengl/LinuxDisplay.java b/src/java/org/lwjgl/opengl/LinuxDisplay.java index 61332e88..7f36ee52 100644 --- a/src/java/org/lwjgl/opengl/LinuxDisplay.java +++ b/src/java/org/lwjgl/opengl/LinuxDisplay.java @@ -48,6 +48,9 @@ import org.lwjgl.LWJGLException; import org.lwjgl.LWJGLUtil; import org.lwjgl.opengl.XRandR.Screen; +import java.security.AccessController; +import java.security.PrivilegedAction; + final class LinuxDisplay implements DisplayImplementation { /* X11 constants */ public final static int CurrentTime = 0; @@ -524,7 +527,12 @@ final class LinuxDisplay implements DisplayImplementation { try { if( current_displaymode_extension == XRANDR && savedXrandrConfig.length > 0 ) { - XRandR.setConfiguration( savedXrandrConfig ); + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + XRandR.setConfiguration( savedXrandrConfig ); + return null; + } + }); } else { @@ -615,7 +623,11 @@ final class LinuxDisplay implements DisplayImplementation { throw new LWJGLException("No modes available"); switch (current_displaymode_extension) { case XRANDR: - savedXrandrConfig = XRandR.getConfiguration(); + savedXrandrConfig = (Screen[])AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + return XRandR.getConfiguration(); + } + }); saved_mode = getCurrentXRandrMode(); break; case XF86VIDMODE: @@ -890,7 +902,12 @@ final class LinuxDisplay implements DisplayImplementation { try { if( current_displaymode_extension == XRANDR && savedXrandrConfig.length > 0 ) { - XRandR.setConfiguration( savedXrandrConfig ); + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + XRandR.setConfiguration( savedXrandrConfig ); + return null; + } + }); } else { diff --git a/src/java/org/lwjgl/opengl/XRandR.java b/src/java/org/lwjgl/opengl/XRandR.java index 825b99ed..bc60e660 100644 --- a/src/java/org/lwjgl/opengl/XRandR.java +++ b/src/java/org/lwjgl/opengl/XRandR.java @@ -40,8 +40,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.regex.Pattern; -import java.security.AccessController; -import java.security.PrivilegedAction; /** * Utility for working with the xrandr commmand-line utility. Assumes @@ -105,12 +103,7 @@ public class XRandR { * xrandr is not supported */ public static Screen[] getConfiguration() { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - populate(); - return null; - } - }); + populate(); return (Screen[]) current.clone(); } @@ -119,20 +112,11 @@ public class XRandR { * @param screens * The desired screen set, may not be null */ - public static void setConfiguration(final Screen[]/* ... */screens) { + public static void setConfiguration(Screen[]/* ... */screens) { if (screens.length == 0) { throw new IllegalArgumentException("Must specify at least one screen"); } - - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - setScreen(screens); - return null; - } - }); - } - - private static void setScreen(Screen[] screens) { + List/* */cmd = new ArrayList/* */(); cmd.add("xrandr"); @@ -173,6 +157,7 @@ public class XRandR { } catch (IOException e) { e.printStackTrace(); } + } /** @@ -180,13 +165,7 @@ public class XRandR { * xrandr is not supported */ public static String[] getScreenNames() { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - populate(); - return null; - } - }); - + populate(); return (String[]) screens.keySet().toArray(new String[screens.size()]); } @@ -196,13 +175,7 @@ public class XRandR { * null if there is no such screen */ public static Screen[] getResolutions(String name) { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - populate(); - return null; - } - }); - + populate(); // clone the array to prevent held copies being altered return (Screen[]) ((Screen[]) screens.get(name)).clone(); } @@ -274,4 +247,4 @@ public class XRandR { return name + " " + width + "x" + height + " @ " + xPos + "x" + yPos; } } -} +} \ No newline at end of file