Skip to content

Commit fe85083

Browse files
author
Federico Fissore
committed
Setting preferences.txt permissions to 600 on linux and mac
1 parent 4db6c73 commit fe85083

File tree

4 files changed

+34
-18
lines changed

4 files changed

+34
-18
lines changed

app/src/processing/app/Preferences.java

-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@
6464
*/
6565
public class Preferences {
6666

67-
static final String PREFS_FILE = PreferencesData.PREFS_FILE;
68-
6967
class Language {
7068
Language(String _name, String _originalName, String _isoCode) {
7169
name = _name;

arduino-core/src/processing/app/Platform.java

+11-9
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,6 @@
2121
*/
2222

2323
package processing.app;
24-
import static processing.app.I18n._;
25-
26-
import java.io.File;
27-
import java.util.HashMap;
28-
import java.util.LinkedList;
29-
import java.util.List;
30-
import java.util.Map;
31-
32-
import javax.swing.UIManager;
3324

3425
import cc.arduino.packages.BoardPort;
3526
import com.sun.jna.Library;
@@ -39,6 +30,12 @@
3930
import processing.app.debug.TargetPlatform;
4031
import processing.app.legacy.PConstants;
4132

33+
import javax.swing.*;
34+
import java.io.*;
35+
import java.util.*;
36+
37+
import static processing.app.I18n._;
38+
4239

4340
/**
4441
* Used by Base for platform-specific tweaking, for instance finding the
@@ -227,4 +224,9 @@ protected void showLauncherWarning() {
227224
public List<BoardPort> filterPorts(List<BoardPort> ports, boolean aBoolean) {
228225
return new LinkedList<BoardPort>(ports);
229226
}
227+
228+
public void fixPrefsFilePermissions(File prefsFile) throws IOException, InterruptedException {
229+
Process process = Runtime.getRuntime().exec(new String[]{"chmod", "600", prefsFile.getAbsolutePath()}, null, null);
230+
process.waitFor();
231+
}
230232
}

arduino-core/src/processing/app/PreferencesData.java

+18-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
public class PreferencesData {
2121

22-
static final String PREFS_FILE = "preferences.txt";
22+
private static final String PREFS_FILE = "preferences.txt";
2323

2424
// data model
2525

@@ -30,18 +30,25 @@ public class PreferencesData {
3030

3131

3232
static public void init(File file) {
33-
if (file != null)
33+
if (file != null) {
3434
preferencesFile = file;
35-
else
35+
} else {
3636
preferencesFile = BaseNoGui.getSettingsFile(PREFS_FILE);
37+
}
38+
39+
try {
40+
BaseNoGui.getPlatform().fixPrefsFilePermissions(preferencesFile);
41+
} catch (Exception e) {
42+
//ignore
43+
}
3744

3845
// start by loading the defaults, in case something
3946
// important was deleted from the user prefs
4047
try {
41-
prefs.load(BaseNoGui.getLibStream("preferences.txt"));
48+
prefs.load(BaseNoGui.getLibStream(PREFS_FILE));
4249
} catch (IOException e) {
4350
BaseNoGui.showError(null, _("Could not read default settings.\n" +
44-
"You'll need to reinstall Arduino."), e);
51+
"You'll need to reinstall Arduino."), e);
4552
}
4653

4754
// set some runtime constants (not saved on preferences file)
@@ -144,6 +151,12 @@ static protected void save() {
144151

145152
writer.flush();
146153
writer.close();
154+
155+
try {
156+
BaseNoGui.getPlatform().fixPrefsFilePermissions(preferencesFile);
157+
} catch (Exception e) {
158+
//ignore
159+
}
147160
}
148161

149162

arduino-core/src/processing/app/windows/Platform.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@
2424

2525
import com.sun.jna.Library;
2626
import com.sun.jna.Native;
27-
2827
import org.apache.commons.exec.CommandLine;
2928
import org.apache.commons.exec.Executor;
30-
3129
import processing.app.PreferencesData;
3230
import processing.app.debug.TargetPackage;
3331
import processing.app.legacy.PApplet;
@@ -351,4 +349,9 @@ public String preListAllCandidateDevices() {
351349
return super.preListAllCandidateDevices();
352350
}
353351
}
352+
353+
@Override
354+
public void fixPrefsFilePermissions(File prefsFile) throws IOException {
355+
//noop
356+
}
354357
}

0 commit comments

Comments
 (0)