# HG changeset patch # User michaelm # Date 1572376989 0 # Node ID 692de65ab293cf9ded2167383b8be0704648c590 # Parent 203fceb089fc37dadd981ef350b3912cc9beee06 partial cleanup diff -r 203fceb089fc -r 692de65ab293 src/java.base/share/classes/java/nio/channels/ServerSocketChannel.java --- a/src/java.base/share/classes/java/nio/channels/ServerSocketChannel.java Tue Oct 29 08:26:48 2019 +0000 +++ b/src/java.base/share/classes/java/nio/channels/ServerSocketChannel.java Tue Oct 29 19:23:09 2019 +0000 @@ -186,9 +186,9 @@ * @throws SecurityException * If a security manager has been installed and its * {@link SecurityManager#checkListen checkListen} method denies - * the operation for IP channels or for unix domain + * the operation for IP channels. Or with unix domain * channels, if the security manager denies "read" or "write" - * {@link FilePermission} for the local path. + * {@link java.io.FilePermission} for the local path. * * @since 1.7 */ @@ -214,9 +214,9 @@ * default is used. * *
Note, for Unix domain channels, a file is created in the file-system - * with the same name as this channel's bound address. This file persists after - * the channel is closed, and must be removed before another channel can bind - * to the same name. + * with the same path name as this channel's bound {@link UnixDomainSocketAddress}. + * This file persists after the channel is closed, and must be removed before + * another channel can bind to the same name. * * @param local * The address to bind the socket, or {@code null} to bind to an @@ -237,9 +237,9 @@ * @throws SecurityException * If a security manager has been installed and its * {@link SecurityManager#checkListen checkListen} method denies - * the operation for IP channels or for unix domain + * the operation for IP channels. Or with unix domain * channels, if the security manager denies "read" or "write" - * {@link FilePermission} for the local path. + * {@link java.io.FilePermission} for the local path. * * @since 1.7 */ @@ -265,7 +265,7 @@ * declared in the {@link java.net.ServerSocket} class.
* * @return A server socket associated with this channel - * @throws UnsupportedOperationException is this is a Unix domain channel + * @throws UnsupportedOperationException if this is a Unix domain channel */ public abstract ServerSocket socket(); @@ -280,8 +280,8 @@ *The socket channel returned by this method, if any, will be in * blocking mode regardless of the blocking mode of this channel. * - *
For IP channels, this method performs exactly the same security checks as the {@link - * java.net.ServerSocket#accept accept} method of the {@link + *
For IP channels, this method performs exactly the same security checks + * as the {@link java.net.ServerSocket#accept accept} method of the {@link * java.net.ServerSocket} class. That is, if a security manager has been * installed then for each new connection this method verifies that the * address and port number of the connection's remote endpoint are @@ -325,6 +325,8 @@ /** * {@inheritDoc} + * Where the channel is bound to a Unix domain address, the return + * value from this this method is of type {@link UnixDomainSocketAddress}. *
* If there is a security manager set and this is an IP channel, * {@code checkConnect} method is @@ -334,9 +336,12 @@ * {@link java.net.InetAddress#getLoopbackAddress loopback} address and the * local port of the channel's socket is returned. *
- * If there is a security manager set and this is an unix domain channel, - * then this returns a {@link UnixDomainSocketAddress} corresponding to the - * bound address. + * If there is a security manager set and this is a unix domain channel, + * then {@link SecurityManager#checkPermission(Permission)} is called using + * a {@link java.io.FilePermission} constructed with the path from the + * local address and "read" as the action. If this check fails + * then an unnamed {@link UnixDomainSocketAddress} (with empty pathname) + * is returned. * * @return The {@code SocketAddress} that the socket is bound to, or the * {@code SocketAddress} representing the loopback address if diff -r 203fceb089fc -r 692de65ab293 src/java.base/share/classes/java/nio/channels/SocketChannel.java --- a/src/java.base/share/classes/java/nio/channels/SocketChannel.java Tue Oct 29 08:26:48 2019 +0000 +++ b/src/java.base/share/classes/java/nio/channels/SocketChannel.java Tue Oct 29 19:23:09 2019 +0000 @@ -116,7 +116,6 @@ * * * - * * Additional (implementation specific) options may also be supported. * *
Socket channels are safe for use by multiple concurrent threads. They @@ -290,7 +289,7 @@ * {@link SecurityManager#checkListen checkListen} method denies * the operation for IP channels or for unix domain * channels, if the security manager denies "read" or "write" - * {@link FilePermission} for the local path. + * {@link java.io.FilePermission} for the local path. * * @since 1.7 */ diff -r 203fceb089fc -r 692de65ab293 src/java.base/share/classes/java/nio/channels/UnixDomainSocketAddress.java --- a/src/java.base/share/classes/java/nio/channels/UnixDomainSocketAddress.java Tue Oct 29 08:26:48 2019 +0000 +++ b/src/java.base/share/classes/java/nio/channels/UnixDomainSocketAddress.java Tue Oct 29 19:23:09 2019 +0000 @@ -36,8 +36,8 @@ * addresses contain a String path name, which when bound to a channel, * have an associated file in the file-system with the same name. *
- * If a channel is automatically bound to Unix domain address then its address - * is unnamed, has an empty path field, and therefore has no associated + * If a channel is automatically bound to a Unix domain address then its address + * is unnamed; it has an empty path field, and therefore has no associated * file in the file-system. *
* Note, not all channel types support Unix domain addresses.
diff -r 203fceb089fc -r 692de65ab293 src/java.base/share/classes/sun/net/util/SocketExceptions.java
--- a/src/java.base/share/classes/sun/net/util/SocketExceptions.java Tue Oct 29 08:26:48 2019 +0000
+++ b/src/java.base/share/classes/sun/net/util/SocketExceptions.java Tue Oct 29 19:23:09 2019 +0000
@@ -28,6 +28,7 @@
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.net.InetSocketAddress;
+import java.nio.channels.UnixDomainSocketAddress;
import java.net.SocketAddress;
import java.security.AccessController;
import java.security.PrivilegedAction;
@@ -53,8 +54,11 @@
* Only specific IOException subtypes are supported.
*/
public static IOException of(IOException e, SocketAddress addr) {
+ if (addr instanceof UnixDomainSocketAddress)
+ return ofUnixDomain(e, (UnixDomainSocketAddress)addr);
if (!(addr instanceof InetSocketAddress))
return e;
+
InetSocketAddress address = (InetSocketAddress)addr;
if (!enhancedExceptionText || address == null)
return e;
@@ -70,6 +74,18 @@
return create(e, enhancedMsg);
}
+ private static IOException ofUnixDomain(IOException e, UnixDomainSocketAddress addr) {
+ if (!enhancedExceptionText || addr == null)
+ return e;
+ String path = addr.getPath();
+ StringBuilder sb = new StringBuilder();
+ sb.append(e.getMessage());
+ sb.append(": ");
+ sb.append(path);
+ String enhancedMsg = sb.toString();
+ return create(e, enhancedMsg);
+ }
+
// return a new instance of the same type with the given detail
// msg, or if the type doesn't support detail msgs, return given
// instance.
diff -r 203fceb089fc -r 692de65ab293 src/java.base/share/classes/sun/nio/ch/Net.java
--- a/src/java.base/share/classes/sun/nio/ch/Net.java Tue Oct 29 08:26:48 2019 +0000
+++ b/src/java.base/share/classes/sun/nio/ch/Net.java Tue Oct 29 19:23:09 2019 +0000
@@ -26,6 +26,7 @@
package sun.nio.ch;
import java.io.FileDescriptor;
+import java.io.FilePermission;
import java.io.IOException;
import java.net.Inet4Address;
import java.net.Inet6Address;
@@ -57,28 +58,18 @@
public class Net {
- public Net() { }
+ private Net() { }
- private static final boolean unixDomainSupported;
- //private static final boolean abstractNamesSupported;
+ private static final boolean unixDomainSupported =
+ unixDomainSocketSupported();
// unspecified protocol family
- public static final ProtocolFamily UNSPEC = new ProtocolFamily() {
+ static final ProtocolFamily UNSPEC = new ProtocolFamily() {
public String name() {
return "UNSPEC";
}
};
- static {
- unixDomainSupported = unixDomainSocketSupported();
- String name = GetPropertyAction.privilegedGetProperty("os.name")
- .toLowerCase();
-
- // Windows claims to support it but doesn't. Disable for now
- //abstractNamesSupported = name.startsWith("linux");
- // || name.startsWith("windows");
- }
-
// set to true if exclusive binding is on for Windows
private static final boolean exclusiveBind;
@@ -117,7 +108,7 @@
/**
* Returns true if exclusive binding is on
*/
- public static boolean useExclusiveBind() {
+ static boolean useExclusiveBind() {
return exclusiveBind;
}
@@ -326,13 +317,13 @@
static final ExtendedSocketOptions extendedOptions =
ExtendedSocketOptions.getInstance();
- public static void setSocketOption(FileDescriptor fd, SocketOption> name, Object value)
+ static void setSocketOption(FileDescriptor fd, SocketOption> name, Object value)
throws IOException
{
setSocketOption(fd, Net.UNSPEC, name, value);
}
- public static void setSocketOption(FileDescriptor fd, ProtocolFamily family,
+ static void setSocketOption(FileDescriptor fd, ProtocolFamily family,
SocketOption> name, Object value)
throws IOException
{
@@ -394,13 +385,13 @@
setIntOption0(fd, mayNeedConversion, key.level(), key.name(), arg, isIPv6);
}
- public static Object getSocketOption(FileDescriptor fd, SocketOption> name)
+ static Object getSocketOption(FileDescriptor fd, SocketOption> name)
throws IOException
{
return getSocketOption(fd, Net.UNSPEC, name);
}
- public static Object getSocketOption(FileDescriptor fd, ProtocolFamily family, SocketOption> name)
+ static Object getSocketOption(FileDescriptor fd, ProtocolFamily family, SocketOption> name)
throws IOException
{
Class> type = name.type();
@@ -459,7 +450,7 @@
return IOUtil.newFD(socket0(preferIPv6, stream, false, fastLoopback));
}
- public static FileDescriptor serverSocket(boolean stream) {
+ static FileDescriptor serverSocket(boolean stream) {
return IOUtil.newFD(socket0(isIPv6Available(), stream, true, fastLoopback));
}
@@ -489,7 +480,7 @@
int port)
throws IOException;
- public static native void listen(FileDescriptor fd, int backlog) throws IOException;
+ static native void listen(FileDescriptor fd, int backlog) throws IOException;
static int connect(FileDescriptor fd, InetAddress remote, int remotePort)
throws IOException
@@ -523,7 +514,7 @@
public static final int SHUT_WR = 1;
public static final int SHUT_RDWR = 2;
- public static native void shutdown(FileDescriptor fd, int how) throws IOException;
+ static native void shutdown(FileDescriptor fd, int how) throws IOException;
private static native int localPort(FileDescriptor fd)
throws IOException;
@@ -590,14 +581,14 @@
*
* @return true if connected
*/
- public static boolean pollConnectNow(FileDescriptor fd) throws IOException {
+ static boolean pollConnectNow(FileDescriptor fd) throws IOException {
return pollConnect(fd, 0);
}
/**
* Return the number of bytes in the socket input buffer.
*/
- public static native int available(FileDescriptor fd) throws IOException;
+ static native int available(FileDescriptor fd) throws IOException;
/**
* Send one byte of urgent data (MSG_OOB) on the socket.
@@ -709,30 +700,40 @@
public static final short POLLIN;
public static final short POLLOUT;
- public static boolean isUnixDomainSupported() {
- return unixDomainSupported;
- }
-
public static UnixDomainSocketAddress checkUnixAddress(SocketAddress sa) {
if (sa == null)
throw new NullPointerException();
if (!(sa instanceof UnixDomainSocketAddress))
throw new UnsupportedAddressTypeException();
UnixDomainSocketAddress usa = (UnixDomainSocketAddress)sa;
- //if (usa.isAbstract() && !abstractNamesSupported())
- //throw new UnsupportedAddressTypeException();
return usa;
}
- /**
- * 2 methods to be implemented if fine-grained security to be used
- */
+ public static boolean isUnixDomainSupported() {
+ return unixDomainSupported;
+ }
+
+ private static UnixDomainSocketAddress UNNAMED = new UnixDomainSocketAddress("");
+
static UnixDomainSocketAddress getRevealedLocalAddress(UnixDomainSocketAddress addr) {
+ SecurityManager sm = System.getSecurityManager();
+ if (addr == null || sm == null)
+ return addr;
+
+ try{
+ FilePermission p = new FilePermission(addr.getPath(), "read");
+ sm.checkPermission(p);
+ // Security check passed
+ } catch (SecurityException e) {
+ // Return unnamed address only if security check fails
+ addr = UNNAMED;
+ }
return addr;
}
static String getRevealedLocalAddressAsString(UnixDomainSocketAddress addr) {
- return addr.toString();
+ return System.getSecurityManager() == null ? addr.toString() :
+ UNNAMED.toString();
}
// -- Socket operations --
@@ -741,9 +742,9 @@
return IOUtil.newFD(unixDomainSocket0());
}
- public static native boolean unixDomainSocketSupported();
+ private static native int unixDomainSocket0();
- private static native int unixDomainSocket0();
+ private static native boolean unixDomainSocketSupported();
static native void unixDomainBind(FileDescriptor fd, UnixDomainSocketAddress addr)
throws IOException;
@@ -801,6 +802,4 @@
fastLoopback = isFastTcpLoopbackRequested();
}
-
-
}
diff -r 203fceb089fc -r 692de65ab293 src/java.base/share/classes/sun/nio/ch/SelectorProviderImpl.java
--- a/src/java.base/share/classes/sun/nio/ch/SelectorProviderImpl.java Tue Oct 29 08:26:48 2019 +0000
+++ b/src/java.base/share/classes/sun/nio/ch/SelectorProviderImpl.java Tue Oct 29 19:23:09 2019 +0000
@@ -66,7 +66,7 @@
if (family == StandardProtocolFamily.INET || family == StandardProtocolFamily.INET6) {
throw new UnsupportedOperationException("This will be supported, but is not implemented yet");
//return new InetSocketChannelImpl(this);
- } else if (family == StandardProtocolFamily.UNIX) {
+ } else if (family == StandardProtocolFamily.UNIX && Net.isUnixDomainSupported()) {
return new UnixDomainSocketChannelImpl(this, Net.unixDomainSocket(), false);
} else
throw new UnsupportedAddressTypeException();
@@ -77,7 +77,7 @@
if (family == StandardProtocolFamily.INET || family == StandardProtocolFamily.INET6) {
throw new UnsupportedOperationException("This will be supported, but is not implemented yet");
//return new InetServerSocketChannelImpl(this);
- } else if (family == StandardProtocolFamily.UNIX) {
+ } else if (family == StandardProtocolFamily.UNIX && Net.isUnixDomainSupported()) {
return new UnixDomainServerSocketChannelImpl(this);
} else
throw new UnsupportedAddressTypeException();
diff -r 203fceb089fc -r 692de65ab293 src/java.base/share/classes/sun/nio/ch/ServerSocketChannelImpl.java
--- a/src/java.base/share/classes/sun/nio/ch/ServerSocketChannelImpl.java Tue Oct 29 08:26:48 2019 +0000
+++ b/src/java.base/share/classes/sun/nio/ch/ServerSocketChannelImpl.java Tue Oct 29 19:23:09 2019 +0000
@@ -55,7 +55,7 @@
* An implementation of ServerSocketChannels
*/
-public abstract class ServerSocketChannelImpl
+abstract class ServerSocketChannelImpl
extends ServerSocketChannel
implements SelChImpl
{
diff -r 203fceb089fc -r 692de65ab293 src/java.base/share/classes/sun/nio/ch/SocketChannelImpl.java
--- a/src/java.base/share/classes/sun/nio/ch/SocketChannelImpl.java Tue Oct 29 08:26:48 2019 +0000
+++ b/src/java.base/share/classes/sun/nio/ch/SocketChannelImpl.java Tue Oct 29 19:23:09 2019 +0000
@@ -64,7 +64,7 @@
* An implementation of SocketChannels
*/
-public abstract class SocketChannelImpl
+abstract class SocketChannelImpl
extends SocketChannel
implements SelChImpl
{
@@ -118,13 +118,13 @@
// Constructor for normal connecting sockets
//
- public SocketChannelImpl(SelectorProvider sp) throws IOException {
+ SocketChannelImpl(SelectorProvider sp) throws IOException {
super(sp);
this.fd = Net.socket(true);
this.fdVal = IOUtil.fdVal(fd);
}
- public SocketChannelImpl(SelectorProvider sp, FileDescriptor fd)
+ SocketChannelImpl(SelectorProvider sp, FileDescriptor fd)
throws IOException
{
super(sp);
@@ -765,13 +765,6 @@
}
}
- /**
- * Package private version called from InheritedChannel
- */
- void localImplCloseSelectableChannel() throws IOException {
- implCloseSelectableChannel();
- }
-
@Override
public SocketChannel shutdownInput() throws IOException {
synchronized (stateLock) {
diff -r 203fceb089fc -r 692de65ab293 src/java.base/share/classes/sun/nio/ch/UnixDomainSocketChannelImpl.java
--- a/src/java.base/share/classes/sun/nio/ch/UnixDomainSocketChannelImpl.java Tue Oct 29 08:26:48 2019 +0000
+++ b/src/java.base/share/classes/sun/nio/ch/UnixDomainSocketChannelImpl.java Tue Oct 29 19:23:09 2019 +0000
@@ -78,16 +78,6 @@
}
}
-/*
- public static AbstractSocketChannelImpl create(SelectorProvider sp, FileDescriptor fd) {
- try {
- return new UnixDomainSocketChannelImpl(sp, fd, false);
- } catch (IOException e) {
- throw new UncheckedIOException(e);
- }
- }
-*/
-
// Constructor for sockets obtained from server sockets
//
UnixDomainSocketChannelImpl(SelectorProvider sp, FileDescriptor fd, SocketAddress isa)
diff -r 203fceb089fc -r 692de65ab293 src/java.base/share/native/libnet/net_util.h
--- a/src/java.base/share/native/libnet/net_util.h Tue Oct 29 08:26:48 2019 +0000
+++ b/src/java.base/share/native/libnet/net_util.h Tue Oct 29 19:23:09 2019 +0000
@@ -118,7 +118,6 @@
extern jclass udsa_class;
extern jmethodID udsa_ctorID;
extern jfieldID udsa_pathID;
-extern jfieldID udsa_isAbstractID;
/************************************************************************
* Utilities
diff -r 203fceb089fc -r 692de65ab293 src/java.base/share/native/libnio/ch/UnixDomainSocketAddress.c
--- a/src/java.base/share/native/libnio/ch/UnixDomainSocketAddress.c Tue Oct 29 08:26:48 2019 +0000
+++ b/src/java.base/share/native/libnio/ch/UnixDomainSocketAddress.c Tue Oct 29 19:23:09 2019 +0000
@@ -35,7 +35,6 @@
jclass udsa_class;
jmethodID udsa_ctorID;
jfieldID udsa_pathID;
-//jfieldID udsa_isAbstractID;
static int udsa_initialized = 0;
@@ -55,9 +54,6 @@
udsa_pathID = (*env)->GetFieldID(env, udsa_class, "path", "Ljava/lang/String;");
CHECK_NULL(udsa_pathID);
- //udsa_isAbstractID = (*env)->GetFieldID(env, udsa_class, "isAbstract", "Z");
- //CHECK_NULL(udsa_isAbstractID);
-
udsa_ctorID = (*env)->GetMethodID(env, udsa_class, "