--- old/src/jdk.net/share/classes/jdk/net/ExtendedSocketOptions.java 2020-07-31 12:17:09.000000000 +0100 +++ new/src/jdk.net/share/classes/jdk/net/ExtendedSocketOptions.java 2020-07-31 12:17:09.000000000 +0100 @@ -180,6 +180,25 @@ public static final SocketOption SO_INCOMING_NAPI_ID = new ExtSocketOption("SO_INCOMING_NAPI_ID", Integer.class); + /** + * Unix Domain peer credentials. + * + *

The value of this socket option is a {@link UnixDomainPrincipal} that + * represents the credentials of a peer connected to a Unix Domain socket. + * The credentials are those that applied at the time the socket was first + * connected or accepted. + * + *

The socket option is read-only and an attempt to set the socket option + * will throw {@code SocketException}. {@code SocketException} is also thrown + * when attempting to get the value of the socket option on an unconnected Unix + * Domain socket. + * + * @since 16 + */ + public static final SocketOption SO_PEERCRED + = new ExtSocketOption + ("SO_PEERCRED", UnixDomainPrincipal.class); + private static final PlatformSocketOptions platformSocketOptions = PlatformSocketOptions.get(); @@ -187,6 +206,8 @@ platformSocketOptions.quickAckSupported(); private static final boolean keepAliveOptSupported = platformSocketOptions.keepAliveOptionsSupported(); + private static final boolean peerCredentialsSupported = + platformSocketOptions.peerCredentialsSupported(); private static final boolean incomingNapiIdOptSupported = platformSocketOptions.incomingNapiIdSupported(); private static final Set> extendedOptions = options(); @@ -202,6 +223,9 @@ if (keepAliveOptSupported) { options.addAll(Set.of(TCP_KEEPCOUNT, TCP_KEEPIDLE, TCP_KEEPINTERVAL)); } + if (peerCredentialsSupported) { + options.add(SO_PEERCRED); + } return Collections.unmodifiableSet(options); } @@ -233,6 +257,8 @@ throw new UnsupportedOperationException("Attempt to set unsupported option " + option); else throw new SocketException("Attempt to set read only option " + option); + } else if (option == SO_PEERCRED) { + throw new SocketException("SO_PEERCRED cannot be set "); } else { throw new InternalError("Unexpected option " + option); } @@ -255,6 +281,8 @@ return getTcpKeepAliveTime(fd); } else if (option == TCP_KEEPINTERVAL) { return getTcpKeepAliveIntvl(fd); + } else if (option == SO_PEERCRED) { + return getSoPeerCred(fd); } else if (option == SO_INCOMING_NAPI_ID) { return getIncomingNapiId(fd); } else { @@ -272,6 +300,11 @@ platformSocketOptions.setQuickAck(fdAccess.get(fd), enable); } + private static Object getSoPeerCred(FileDescriptor fd) + throws SocketException { + return platformSocketOptions.getSoPeerCred(fdAccess.get(fd)); + } + private static Object getQuickAckOption(FileDescriptor fd) throws SocketException { return platformSocketOptions.getQuickAck(fdAccess.get(fd)); @@ -345,6 +378,10 @@ return instance; } + boolean peerCredentialsSupported() { + return false; + } + void setQuickAck(int fd, boolean on) throws SocketException { throw new UnsupportedOperationException("unsupported TCP_QUICKACK option"); } @@ -369,6 +406,10 @@ throw new UnsupportedOperationException("unsupported TCP_KEEPIDLE option"); } + UnixDomainPrincipal getSoPeerCred(int fd) throws SocketException { + throw new UnsupportedOperationException("unsupported SO_PEERCRED option"); + } + void setTcpKeepAliveIntvl(int fd, final int value) throws SocketException { throw new UnsupportedOperationException("unsupported TCP_KEEPINTVL option"); }