diff --git a/bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/Main.java b/bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/Main.java
index c47de5717a7..8c51b9eb231 100644
--- a/bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/Main.java
+++ b/bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/Main.java
@@ -18,17 +18,47 @@
*******************************************************************************/
package org.eclipse.equinox.launcher;
-import java.io.*;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.net.*;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.net.URLConnection;
+import java.net.URLDecoder;
+import java.net.URLStreamHandlerFactory;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
-import java.security.*;
-import java.util.*;
+import java.security.AllPermission;
+import java.security.CodeSource;
+import java.security.Permission;
+import java.security.PermissionCollection;
+import java.security.Policy;
+import java.security.ProtectionDomain;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Locale;
+import java.util.Properties;
+import java.util.StringJoiner;
+import java.util.StringTokenizer;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
+
import org.eclipse.equinox.internal.launcher.Constants;
/**
@@ -715,7 +745,7 @@ private boolean checkConfigurationLocation(URL locationUrl) {
return false;
}
}
- if (!canWrite(configDir)) {
+ if (!canWrite(configDir, getOS())) {
System.setProperty(PROP_EXITCODE, "15"); //$NON-NLS-1$
System.setProperty(PROP_EXITDATA, "
Invalid Configuration LocationThe configuration area at '" + configDir + //$NON-NLS-1$
"' is not writable. Please choose a writable location using the '-configuration' command line option."); //$NON-NLS-1$
@@ -1273,19 +1303,24 @@ private String computeDefaultConfigurationLocation() {
// TODO a little dangerous here. Basically we have to assume that it is a file URL.
if (install.getProtocol().equals("file")) { //$NON-NLS-1$
File installDir = new File(install.getFile());
- if (canWrite(installDir))
+ if (canWrite(installDir, getOS()))
return installDir.getAbsolutePath() + File.separator + CONFIG_DIR;
}
// We can't write in the eclipse install dir so try for some place in the user's home dir
return computeDefaultUserAreaLocation(CONFIG_DIR);
}
- private static boolean canWrite(File installDir) {
+ private static boolean canWrite(File installDir, String os) {
if (!installDir.isDirectory())
return false;
- if (Files.isWritable(installDir.toPath()))
+ if (Files.isWritable(installDir.toPath())) {
return true;
+ } else if (Constants.OS_ZOS.equals(os)) {
+ // For z/OS avoid doing the windows specific .dll check below.
+ // This causes additional alarms on z/OS for unauthorized attempts to write.
+ return false;
+ }
File fileTest = null;
try {
@@ -1320,7 +1355,7 @@ private String computeDefaultUserAreaLocation(String pathAppendage) {
File installDir = new File(installURL.getFile());
String installDirHash = getInstallDirHash();
- if (protectBase && Constants.OS_MACOSX.equals(os)) {
+ if (protectBase && Constants.OS_MACOSX.equals(getOS())) {
initializeBridgeEarly();
String macConfiguration = computeConfigurationLocationForMacOS();
if (macConfiguration != null) {
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/location/EquinoxLocations.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/location/EquinoxLocations.java
index eb14cac4c2e..b972928c076 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/location/EquinoxLocations.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/location/EquinoxLocations.java
@@ -23,6 +23,7 @@
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicBoolean;
+
import org.eclipse.osgi.framework.log.FrameworkLogEntry;
import org.eclipse.osgi.internal.framework.EquinoxConfiguration;
import org.eclipse.osgi.internal.framework.EquinoxConfiguration.ConfigValues;
@@ -205,7 +206,8 @@ private BasicLocation buildLocation(String property, URL defaultLocation, String
// put the instance area inside the workspace meta area.
if (location == null)
return new BasicLocation(property, defaultLocation,
- userReadOnlySetting != null || !computeReadOnly ? readOnly : !canWrite(defaultLocation),
+ userReadOnlySetting != null || !computeReadOnly ? readOnly
+ : !canWrite(defaultLocation, getOS()),
dataAreaPrefix, equinoxConfig, container, debugLocations);
String trimmedLocation = location.trim();
if (trimmedLocation.equalsIgnoreCase(NONE))
@@ -232,7 +234,9 @@ private BasicLocation buildLocation(String property, URL defaultLocation, String
BasicLocation result = null;
if (url != null) {
result = new BasicLocation(property, null,
- userReadOnlySetting != null || !computeReadOnly ? readOnly : !canWrite(url), dataAreaPrefix,
+ userReadOnlySetting != null || !computeReadOnly ? readOnly
+ : !canWrite(url, getOS()),
+ dataAreaPrefix,
equinoxConfig, container, debugLocations);
result.setURL(url, false);
}
@@ -289,7 +293,7 @@ private String computeDefaultConfigurationLocation() {
File defaultConfigDir = new File(installDir, CONFIG_DIR);
if (!defaultConfigDir.exists())
defaultConfigDir.mkdirs();
- if (defaultConfigDir.exists() && StorageUtil.canWrite(defaultConfigDir))
+ if (defaultConfigDir.exists() && StorageUtil.canWrite(defaultConfigDir, getOS()))
return defaultConfigDir.getAbsolutePath();
}
// We can't write in the eclipse install dir so try for some place in the user's
@@ -297,12 +301,16 @@ private String computeDefaultConfigurationLocation() {
return computeDefaultUserAreaLocation(CONFIG_DIR);
}
- private static boolean canWrite(URL location) {
+ private String getOS() {
+ return equinoxConfig.getConfiguration(EquinoxConfiguration.PROP_OSGI_OS);
+ }
+
+ private static boolean canWrite(URL location, String os) {
if (location != null && "file".equals(location.getProtocol())) { //$NON-NLS-1$
File locationDir = new File(location.getPath());
if (!locationDir.exists())
locationDir.mkdirs();
- if (locationDir.exists() && StorageUtil.canWrite(locationDir))
+ if (locationDir.exists() && StorageUtil.canWrite(locationDir, os))
return true;
}
return false;
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/StorageUtil.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/StorageUtil.java
index d6d23834d37..791c69844da 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/StorageUtil.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/StorageUtil.java
@@ -15,6 +15,8 @@
package org.eclipse.osgi.storage;
+import static org.eclipse.osgi.service.environment.Constants.OS_ZOS;
+
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@@ -32,6 +34,7 @@
import java.util.Hashtable;
import java.util.Set;
import java.util.stream.Stream;
+
import org.eclipse.osgi.framework.internal.reliablefile.ReliableFile;
import org.eclipse.osgi.internal.debug.Debug;
import org.osgi.framework.BundleContext;
@@ -139,12 +142,18 @@ public static ServiceRegistration> register(String name, Object service, Bundl
return context.registerService(name, service, properties);
}
- public static boolean canWrite(File installDir) {
- if (!installDir.isDirectory())
+ public static boolean canWrite(File installDir, String os) {
+ if (!installDir.isDirectory()) {
return false;
+ }
- if (Files.isWritable(installDir.toPath()))
+ if (Files.isWritable(installDir.toPath())) {
return true;
+ } else if (OS_ZOS.equals(os)) {
+ // For z/OS avoid doing the windows specific .dll check below.
+ // This causes additional alarms on z/OS for unauthorized attempts to write.
+ return false;
+ }
File fileTest = null;
try {
@@ -153,8 +162,8 @@ public static boolean canWrite(File installDir) {
// like "Program Files"
fileTest = ReliableFile.createTempFile("writableArea", ".dll", installDir); //$NON-NLS-1$ //$NON-NLS-2$
} catch (IOException e) {
- // If an exception occured while trying to create the file, it means that it is
- // not writtable
+ // If an exception occurred while trying to create the file, it means that it is
+ // not writable
return false;
} finally {
if (fileTest != null)