From fe85083f0bebe5735c33af5aea28f2cf32d778b5 Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Tue, 17 Mar 2015 15:48:25 +0100 Subject: [PATCH] Setting preferences.txt permissions to 600 on linux and mac --- app/src/processing/app/Preferences.java | 2 -- arduino-core/src/processing/app/Platform.java | 20 ++++++++-------- .../src/processing/app/PreferencesData.java | 23 +++++++++++++++---- .../src/processing/app/windows/Platform.java | 7 ++++-- 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/app/src/processing/app/Preferences.java b/app/src/processing/app/Preferences.java index 7f13a4270..62ddbce9e 100644 --- a/app/src/processing/app/Preferences.java +++ b/app/src/processing/app/Preferences.java @@ -64,8 +64,6 @@ import static processing.app.I18n._; */ public class Preferences { - static final String PREFS_FILE = PreferencesData.PREFS_FILE; - class Language { Language(String _name, String _originalName, String _isoCode) { name = _name; diff --git a/arduino-core/src/processing/app/Platform.java b/arduino-core/src/processing/app/Platform.java index 3c46c095d..d873bb12c 100644 --- a/arduino-core/src/processing/app/Platform.java +++ b/arduino-core/src/processing/app/Platform.java @@ -21,15 +21,6 @@ */ package processing.app; -import static processing.app.I18n._; - -import java.io.File; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -import javax.swing.UIManager; import cc.arduino.packages.BoardPort; import com.sun.jna.Library; @@ -39,6 +30,12 @@ import processing.app.debug.TargetPackage; import processing.app.debug.TargetPlatform; import processing.app.legacy.PConstants; +import javax.swing.*; +import java.io.*; +import java.util.*; + +import static processing.app.I18n._; + /** * Used by Base for platform-specific tweaking, for instance finding the @@ -227,4 +224,9 @@ public class Platform { public List filterPorts(List ports, boolean aBoolean) { return new LinkedList(ports); } + + public void fixPrefsFilePermissions(File prefsFile) throws IOException, InterruptedException { + Process process = Runtime.getRuntime().exec(new String[]{"chmod", "600", prefsFile.getAbsolutePath()}, null, null); + process.waitFor(); + } } diff --git a/arduino-core/src/processing/app/PreferencesData.java b/arduino-core/src/processing/app/PreferencesData.java index 1052b380a..b34629983 100644 --- a/arduino-core/src/processing/app/PreferencesData.java +++ b/arduino-core/src/processing/app/PreferencesData.java @@ -19,7 +19,7 @@ import processing.app.legacy.PConstants; public class PreferencesData { - static final String PREFS_FILE = "preferences.txt"; + private static final String PREFS_FILE = "preferences.txt"; // data model @@ -30,18 +30,25 @@ public class PreferencesData { static public void init(File file) { - if (file != null) + if (file != null) { preferencesFile = file; - else + } else { preferencesFile = BaseNoGui.getSettingsFile(PREFS_FILE); + } + + try { + BaseNoGui.getPlatform().fixPrefsFilePermissions(preferencesFile); + } catch (Exception e) { + //ignore + } // start by loading the defaults, in case something // important was deleted from the user prefs try { - prefs.load(BaseNoGui.getLibStream("preferences.txt")); + prefs.load(BaseNoGui.getLibStream(PREFS_FILE)); } catch (IOException e) { BaseNoGui.showError(null, _("Could not read default settings.\n" + - "You'll need to reinstall Arduino."), e); + "You'll need to reinstall Arduino."), e); } // set some runtime constants (not saved on preferences file) @@ -144,6 +151,12 @@ public class PreferencesData { writer.flush(); writer.close(); + + try { + BaseNoGui.getPlatform().fixPrefsFilePermissions(preferencesFile); + } catch (Exception e) { + //ignore + } } diff --git a/arduino-core/src/processing/app/windows/Platform.java b/arduino-core/src/processing/app/windows/Platform.java index d74b51209..d612a9959 100644 --- a/arduino-core/src/processing/app/windows/Platform.java +++ b/arduino-core/src/processing/app/windows/Platform.java @@ -24,10 +24,8 @@ package processing.app.windows; import com.sun.jna.Library; import com.sun.jna.Native; - import org.apache.commons.exec.CommandLine; import org.apache.commons.exec.Executor; - import processing.app.PreferencesData; import processing.app.debug.TargetPackage; import processing.app.legacy.PApplet; @@ -351,4 +349,9 @@ public class Platform extends processing.app.Platform { return super.preListAllCandidateDevices(); } } + + @Override + public void fixPrefsFilePermissions(File prefsFile) throws IOException { + //noop + } }