Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8245194: Unix domain socket channel implementation #52

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
e2eb987
unixdomainchannels: initial commit from hg sandbox with changes from …
Michael-Mc-Mahon Sep 7, 2020
6d164c9
unixdomainchannels: fixing compile error on Windows and Alan's review…
Michael-Mc-Mahon Sep 7, 2020
4d08c15
Made some changes relating to selection of the local directory where …
Michael-Mc-Mahon Sep 11, 2020
110b45c
Merge branch 'master' into unixdomainchannels
Michael-Mc-Mahon Sep 14, 2020
22f37a8
unixdomainchannels: updates from review of Sept 11 2020
Michael-Mc-Mahon Sep 14, 2020
3669509
unixdomainchannels: updates after comments sent by Alan 14 Sept
Michael-Mc-Mahon Sep 21, 2020
d29e8cc
unixdomainchannels: some tests were failing on Windows version prior …
Michael-Mc-Mahon Sep 24, 2020
a08186d
Merge branch 'master' into unixdomainchannels
Michael-Mc-Mahon Sep 24, 2020
c669e2d
unixdomainchannels: Update after Alan's review of Sept 29
Michael-Mc-Mahon Sep 29, 2020
4dc90c7
unixdomainchannels: typo in WindowsFileSystemProvider.java
Michael-Mc-Mahon Sep 29, 2020
3fe6baa
unixdomainchannels: change to Net.c was missed after all
Michael-Mc-Mahon Sep 29, 2020
e78228b
unixdomainchannels: remove more cruft from Windows Net.c
Michael-Mc-Mahon Sep 30, 2020
c40d205
Merge branch 'master' into unixdomainchannels
Michael-Mc-Mahon Sep 30, 2020
275e092
unixdomainchannels:
Michael-Mc-Mahon Oct 2, 2020
dc70cd6
unixdomainchannels: error in the last commit in make/modules/java.bas…
Michael-Mc-Mahon Oct 2, 2020
0096645
- simplified Copy.gmk to CAT source files directly
Michael-Mc-Mahon Oct 4, 2020
17acf10
- update after Alan's review on Oct 4
Michael-Mc-Mahon Oct 6, 2020
36efb46
Merge branch 'master' into unixdomainchannels
Michael-Mc-Mahon Oct 6, 2020
0e8e527
unixdomainchannels:
Michael-Mc-Mahon Oct 6, 2020
cb28f3c
unixdomainchannels: updates from Chris's review 9 Oct 2020
Michael-Mc-Mahon Oct 9, 2020
36a0e30
- reorganised the channel impls back into SocketChannelImpl and Serve…
Michael-Mc-Mahon Oct 13, 2020
7f677d5
Merge branch 'master' into unixdomainchannels
Michael-Mc-Mahon Oct 13, 2020
4bbbde3
src changes from Daniel's review. Tests will come later
Michael-Mc-Mahon Oct 14, 2020
3859e61
- test updates from Daniel's review 14 Oct 2020
Michael-Mc-Mahon Oct 14, 2020
8a545a7
fix white space error
Michael-Mc-Mahon Oct 14, 2020
15dc94b
- use String.isEmpty where appropriate
Michael-Mc-Mahon Oct 15, 2020
2d59542
- added NullTest and fix in SocketChannel.open
Michael-Mc-Mahon Oct 16, 2020
d0ae134
- Alan's review patch from Oct 18
Michael-Mc-Mahon Oct 19, 2020
eca95d8
Merge branch 'master' into unixdomainchannels
Michael-Mc-Mahon Oct 19, 2020
36623a4
final feedback from Alan
Michael-Mc-Mahon Oct 19, 2020
053bffe
Merge branch 'master' into unixdomainchannels
Michael-Mc-Mahon Oct 20, 2020
cc106a7
update from Daniel's test comments
Michael-Mc-Mahon Oct 20, 2020
3594e4b
forgot to stage updated test files in last commit
Michael-Mc-Mahon Oct 20, 2020
e07522b
further test update from Daniel
Michael-Mc-Mahon Oct 20, 2020
368fa8b
updated one error in review
Michael-Mc-Mahon Oct 21, 2020
01d7cf5
Merge branch 'master' into unixdomainchannels
Michael-Mc-Mahon Oct 21, 2020
c01c3c9
- fixed 32 bit Linux build error
Michael-Mc-Mahon Oct 22, 2020
bb6c729
tidy up WindowsSelectorImpl
Michael-Mc-Mahon Oct 27, 2020
1a8b304
Merge branch 'master' into unixdomainchannels
Michael-Mc-Mahon Oct 27, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 9 additions & 5 deletions make/modules/java.base/Copy.gmk
Expand Up @@ -182,12 +182,16 @@ endif

################################################################################

$(eval $(call SetupCopyFiles, COPY_NET_PROPERTIES, \
FILES := $(TOPDIR)/src/java.base/share/conf/net.properties, \
DEST := $(CONF_DST_DIR), \
))
NET_PROPERTIES_SRCS := $(TOPDIR)/src/java.base/share/conf/net.properties \
$(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_TYPE)/conf/net.properties

NET_PROPERTIES_DST := $(CONF_DST_DIR)/net.properties

$(NET_PROPERTIES_DST): $(NET_PROPERTIES_SRCS)
$(call MakeTargetDir)
$(CAT) $(NET_PROPERTIES_SRCS) > $@

TARGETS += $(COPY_NET_PROPERTIES)
TARGETS += $(NET_PROPERTIES_DST)

ifeq ($(call isTargetOs, linux), true)
$(eval $(call SetupCopyFiles, COPY_SDP_CONF, \
Expand Down
10 changes: 10 additions & 0 deletions src/java.base/share/classes/java/net/NetPermission.java
Expand Up @@ -66,6 +66,16 @@
* </tr>
*
* <tr>
* <th scope="row">accessUnixDomainSocket</th>
* <td>The ability to accept, bind, connect or get the local address
* of a <i>Unix Domain</i> socket.
* </td>
* <td>Malicious code could connect to local processes using Unix domain sockets
* or impersonate local processes, by binding to the same pathnames (assuming they
* have the required Operating System permissions.</td>
* </tr>
*
* <tr>
* <th scope="row">getCookieHandler</th>
* <td>The ability to get the cookie handler that processes highly
* security sensitive cookie information for an Http session.</td>
Expand Down
10 changes: 8 additions & 2 deletions src/java.base/share/classes/java/net/StandardProtocolFamily.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -41,5 +41,11 @@ public enum StandardProtocolFamily implements ProtocolFamily {
/**
* Internet Protocol Version 6 (IPv6)
*/
INET6
INET6,

/**
* Unix domain (Local) interprocess communication.
* @since 16
*/
UNIX
}
211 changes: 211 additions & 0 deletions src/java.base/share/classes/java/net/UnixDomainSocketAddress.java
@@ -0,0 +1,211 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package java.net;

import java.io.ObjectStreamException;
import java.io.Serializable;
import java.net.SocketAddress;
import java.nio.channels.SocketChannel;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;

/**
* A <a href="package-summary.html#unixdomain">Unix domain</a> socket address.
* A Unix domain socket address encapsulates a file-system path that Unix domain sockets
* bind or connect to.
*
* <p> An <a id="unnamed"></a><i>unnamed</i> {@code UnixDomainSocketAddress} has
* an empty path. The local address of a {@link SocketChannel} to a Unix domain socket
* that is <i>automatically</i> or <i>implicitly</i> bound will be unnamed.
*
* <p> {@link Path} objects used to create instances of this class must be obtained
* from the {@linkplain FileSystems#getDefault system-default} file system.
*
* @see java.nio.channels.SocketChannel
* @see java.nio.channels.ServerSocketChannel
* @since 16
*/
public final class UnixDomainSocketAddress extends SocketAddress {
@java.io.Serial
static final long serialVersionUID = 92902496589351288L;

private final transient Path path;

/**
* A serial proxy for all {@link UnixDomainSocketAddress} instances.
* It captures the file path name and reconstructs using the public static
* {@link #of(String) factory}.
*
* @serial include
*/
private static final class Ser implements Serializable {
@java.io.Serial
static final long serialVersionUID = -7955684448513979814L;

/**
* The path name.
* @serial
*/
private final String pathname;

Ser(String pathname) {
this.pathname = pathname;
}

/**
* Creates a {@link UnixDomainSocketAddress} instance, by an invocation
* of the {@link #of(String) factory} method passing the path name.
* @return a UnixDomainSocketAddress
*/
@java.io.Serial
private Object readResolve() {
return UnixDomainSocketAddress.of(pathname);
}
}

/**
* Returns a
* <a href="{@docRoot}/serialized-form.html#java.net.UnixDomainSocketAddress.Ser">
* Ser</a> containing the path name of this instance.
*
* @return a {@link Ser}
* representing the path name of this instance
*/
@java.io.Serial
private Object writeReplace() throws ObjectStreamException {
return new Ser(path.toString());
}

/**
* Throws InvalidObjectException, always.
* @param s the stream
* @throws java.io.InvalidObjectException always
*/
@java.io.Serial
private void readObject(java.io.ObjectInputStream s)
throws java.io.InvalidObjectException
{
throw new java.io.InvalidObjectException("Proxy required");
}

/**
* Throws InvalidObjectException, always.
* @throws java.io.InvalidObjectException always
*/
@java.io.Serial
private void readObjectNoData()
throws java.io.InvalidObjectException
{
throw new java.io.InvalidObjectException("Proxy required");
}

private UnixDomainSocketAddress(Path path) {
this.path = path;
}

/**
* Creates a UnixDomainSocketAddress from the given path string.
*
* @param pathname
* The path string, which can be empty
*
* @return A UnixDomainSocketAddress
*
* @throws InvalidPathException
* If the path cannot be converted to a Path
*
* @throws NullPointerException if pathname is {@code null}
*/
public static UnixDomainSocketAddress of(String pathname) {
return of(Path.of(pathname));
}

/**
* Creates a UnixDomainSocketAddress for the given path.
*
* @param path
* The path to the socket, which can be empty
*
* @return A UnixDomainSocketAddress
*
* @throws IllegalArgumentException
* If the path is not associated with the default file system
*
* @throws NullPointerException if path is {@code null}
*/
public static UnixDomainSocketAddress of(Path path) {
FileSystem fs = path.getFileSystem();
if (fs != FileSystems.getDefault()) {
throw new IllegalArgumentException();
}
if (fs.getClass().getModule() != Object.class.getModule()) {
throw new IllegalArgumentException();
}
return new UnixDomainSocketAddress(path);
}

/**
* Returns this address's path.
*
* @return this address's path
*/
public Path getPath() {
return path;
}

/**
* Returns the hash code of this {@code UnixDomainSocketAddress}
*/
@Override
public int hashCode() {
return path.hashCode();
}

/**
* Compares this address with another object.
*
* @return true if the path fields are equal
*/
@Override
public boolean equals(Object o) {
if (!(o instanceof UnixDomainSocketAddress))
return false;
UnixDomainSocketAddress that = (UnixDomainSocketAddress)o;
return this.path.equals(that.path);
}

/**
* Returns a string representation of this {@code UnixDomainSocketAddress}.
*
* @return this address's path which may be empty for an unnamed address
*/
@Override
public String toString() {
return path.toString();
}
}
Expand Up @@ -150,6 +150,9 @@ protected DatagramChannel(SelectorProvider provider) {
*
* @throws IOException
* If an I/O error occurs
*
* @see <a href="../../net/doc-files/net-properties.html#Ipv4IPv6">
* java.net.preferIPv4Stack</a> system property
*/
public static DatagramChannel open() throws IOException {
return SelectorProvider.provider().openDatagramChannel();
Expand All @@ -169,6 +172,9 @@ public static DatagramChannel open() throws IOException {
* java.nio.channels.spi.SelectorProvider} object. The channel will not be
* connected.
*
* @apiNote <a href="package-summary.html#unixdomain">Unix domain</a> sockets
* are not supported by DatagramChannel.
*
* @param family
* The protocol family
*
Expand All @@ -182,6 +188,9 @@ public static DatagramChannel open() throws IOException {
* @throws IOException
* If an I/O error occurs
*
* @see <a href="../../net/doc-files/net-properties.html#Ipv4IPv6">
* java.net.preferIPv4Stack</a> system property
*
* @since 1.7
*/
public static DatagramChannel open(ProtocolFamily family) throws IOException {
Expand Down Expand Up @@ -629,5 +638,4 @@ public final long write(ByteBuffer[] srcs) throws IOException {
*/
@Override
public abstract SocketAddress getLocalAddress() throws IOException;

}