# HG changeset patch # User msheppar # Date 1460340050 -3600 # Node ID d041d2e80712a8f30aebb77393a0ddda0fa885f8 # Parent 4209c9e19c457a42e2e587f92a773d981697b95b 8134577: Eliminate or standardize a replacement for sun.net.spi.nameservice.NameServiceDescriptor Reviewed-by: chegar, alanb diff -r 4209c9e19c45 -r d041d2e80712 jdk/src/java.base/share/classes/java/net/InetAddress.java --- a/jdk/src/java.base/share/classes/java/net/InetAddress.java Sat Apr 09 20:12:13 2016 +0100 +++ b/jdk/src/java.base/share/classes/java/net/InetAddress.java Mon Apr 11 03:00:50 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2016, 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 @@ -30,8 +30,10 @@ import java.util.List; import java.util.ArrayList; import java.util.Objects; -import java.util.ServiceLoader; +import java.util.Scanner; import java.security.AccessController; +import java.io.File; +import java.io.FileNotFoundException; import java.io.ObjectStreamException; import java.io.ObjectStreamField; import java.io.IOException; @@ -49,7 +51,6 @@ import sun.security.action.*; import sun.net.InetAddressCachePolicy; import sun.net.util.IPAddressUtil; -import sun.net.spi.nameservice.*; /** * This class represents an Internet Protocol (IP) address. @@ -207,6 +208,7 @@ /* Specify address family preference */ static transient boolean preferIPv6Address = false; + static class InetAddressHolder { /** * Reserve the original application specified hostname. @@ -279,7 +281,7 @@ } /* Used to store the name service provider */ - private static List nameServices = null; + private static transient NameService nameService = null; /* Used to store the best available hostname */ private transient String canonicalHostName = null; @@ -623,7 +625,6 @@ */ private static String getHostFromNameService(InetAddress addr, boolean check) { String host = null; - for (NameService nameService : nameServices) { try { // first lookup the hostname host = nameService.getHostByAddr(addr.getAddress()); @@ -657,18 +658,12 @@ host = addr.getHostAddress(); return host; } - - break; - } catch (SecurityException e) { host = addr.getHostAddress(); - break; } catch (UnknownHostException e) { host = addr.getHostAddress(); // let next provider resolve the hostname } - } - return host; } @@ -860,88 +855,287 @@ } } - static InetAddressImpl impl; + /** + * NameService provides host and address lookup service + * + * @since 9 + */ + private interface NameService { + + /** + * Lookup a host mapping by name. Retrieve the IP addresses + * associated with a host + * + * @param host the specified hostname + * @return array of IP addresses for the requested host + * @throws UnknownHostException + * if no IP address for the {@code host} could be found + */ + InetAddress[] lookupAllHostAddr(String host) + throws UnknownHostException; - private static NameService createNSProvider(String provider) { - if (provider == null) - return null; + /** + * Lookup the host corresponding to the IP address provided + * + * @param addr byte array representing an IP address + * @return {@code String} representing the host name mapping + * @throws UnknownHostException + * if no host found for the specified IP address + */ + String getHostByAddr(byte[] addr) throws UnknownHostException; - NameService nameService = null; - if (provider.equals("default")) { - // initialize the default name service - nameService = new NameService() { + } + + /** + * The default NameService implementation, which delegates to the underlying + * OS network libraries to resolve host address mappings. + * + * @since 9 + */ + private static final class PlatformNameService implements NameService { + public InetAddress[] lookupAllHostAddr(String host) throws UnknownHostException { + return impl.lookupAllHostAddr(host); - } - public String getHostByAddr(byte[] addr) - throws UnknownHostException { - return impl.getHostByAddr(addr); + + } + + public String getHostByAddr(byte[] addr) throws UnknownHostException { + + return impl.getHostByAddr(addr); + + } + + } + + /** + * The HostsFileNameService provides host address mapping + * by reading the entries in a hosts file, which is specified by + * {@code jdk.net.hosts.file} system property + * + *

The file format is that which corresponds with the /etc/hosts file + * IP Address host alias list. + * + *

When the file lookup is enabled it replaces the default NameService + * implementation + * + * @since 9 + */ + private static final class HostsFileNameService implements NameService { + + private final String hostsFile; + + public HostsFileNameService (String hostsFileName) { + this.hostsFile = hostsFileName; + } + + private String addrToString(byte addr[]) { + String stringifiedAddress = null; + + if (addr.length == Inet4Address.INADDRSZ) { + stringifiedAddress = Inet4Address.numericToTextFormat(addr); + } else { // treat as an IPV6 jobby + byte[] newAddr + = IPAddressUtil.convertFromIPv4MappedAddress(addr); + if (newAddr != null) { + stringifiedAddress = Inet4Address.numericToTextFormat(addr); + } else { + stringifiedAddress = Inet6Address.numericToTextFormat(addr); } - }; - } else { - final String providerName = provider; - try { - nameService = java.security.AccessController.doPrivileged( - new java.security.PrivilegedExceptionAction<>() { - public NameService run() { - Iterator itr = - ServiceLoader.load(NameServiceDescriptor.class) - .iterator(); - while (itr.hasNext()) { - NameServiceDescriptor nsd = itr.next(); - if (providerName. - equalsIgnoreCase(nsd.getType()+"," - +nsd.getProviderName())) { - try { - return nsd.createNameService(); - } catch (Exception e) { - e.printStackTrace(); - System.err.println( - "Cannot create name service:" - +providerName+": " + e); - } + } + return stringifiedAddress; + } + + /** + * Lookup the host name corresponding to the IP address provided. + * Search the configured host file a host name corresponding to + * the specified IP address. + * + * @param addr byte array representing an IP address + * @return {@code String} representing the host name mapping + * @throws UnknownHostException + * if no host found for the specified IP address + */ + @Override + public String getHostByAddr(byte[] addr) throws UnknownHostException { + String hostEntry; + String host = null; + + String addrString = addrToString(addr); + try (Scanner hostsFileScanner = new Scanner(new File(hostsFile), "UTF-8")) { + while (hostsFileScanner.hasNextLine()) { + hostEntry = hostsFileScanner.nextLine(); + if (!hostEntry.startsWith("#")) { + hostEntry = removeComments(hostEntry); + if (hostEntry.contains(addrString)) { + host = extractHost(hostEntry, addrString); + if (host != null) { + break; + } + } + } + } + } catch (FileNotFoundException e) { + throw new UnknownHostException("Unable to resolve address " + + addrString + " as hosts file " + hostsFile + + " not found "); + } + + if ((host == null) || (host.equals("")) || (host.equals(" "))) { + throw new UnknownHostException("Requested address " + + addrString + + " resolves to an invalid entry in hosts file " + + hostsFile); + } + return host; + } + + + /** + *

Lookup a host mapping by name. Retrieve the IP addresses + * associated with a host. + * + *

Search the configured hosts file for the addresses assocaited with + * with the specified host name. + * + * @param host the specified hostname + * @return array of IP addresses for the requested host + * @throws UnknownHostException + * if no IP address for the {@code host} could be found + */ + + public InetAddress[] lookupAllHostAddr(String host) + throws UnknownHostException { + String hostEntry; + String addrStr = null; + InetAddress[] res = null; + byte addr[] = new byte[4]; + ArrayList inetAddresses = null; + + // lookup the file and create a list InetAddress for the specfied host + try (Scanner hostsFileScanner = new Scanner(new File(hostsFile), "UTF-8")) { + while (hostsFileScanner.hasNextLine()) { + hostEntry = hostsFileScanner.nextLine(); + if (!hostEntry.startsWith("#")) { + hostEntry = removeComments(hostEntry); + if (hostEntry.contains(host)) { + addrStr = extractHostAddr(hostEntry, host); + if ((addrStr != null) && (!addrStr.equals(""))) { + addr = createAddressByteArray(addrStr); + if (inetAddresses == null) { + inetAddresses = new ArrayList<>(1); + } + if (addr != null) { + inetAddresses.add(InetAddress.getByAddress(host, addr)); } } - - return null; } } - ); - } catch (java.security.PrivilegedActionException e) { + } + } catch (FileNotFoundException e) { + throw new UnknownHostException("Unable to resolve host " + host + + " as hosts file " + hostsFile + " not found "); + } + + if (inetAddresses != null) { + res = inetAddresses.toArray(new InetAddress[inetAddresses.size()]); + } else { + throw new UnknownHostException("Unable to resolve host " + host + + " in hosts file " + hostsFile); } + return res; + } + + private String removeComments(String hostsEntry) { + String filteredEntry = hostsEntry; + int hashIndex; + + if ((hashIndex = hostsEntry.indexOf("#")) != -1) { + filteredEntry = hostsEntry.substring(0, hashIndex); + } + return filteredEntry; + } + + private byte [] createAddressByteArray(String addrStr) { + byte[] addrArray; + // check if IPV4 address - most likely + addrArray = IPAddressUtil.textToNumericFormatV4(addrStr); + if (addrArray == null) { + addrArray = IPAddressUtil.textToNumericFormatV6(addrStr); + } + return addrArray; } - return nameService; + /** host to ip address mapping */ + private String extractHostAddr(String hostEntry, String host) { + String[] mapping = hostEntry.split("\\s+"); + String hostAddr = null; + + if (mapping.length >= 2) { + // look at the host aliases + for (int i = 1; i < mapping.length; i++) { + if (mapping[i].equalsIgnoreCase(host)) { + hostAddr = mapping[0]; + } + } + } + return hostAddr; + } + + /** + * IP Address to host mapping + * use first host alias in list + */ + private String extractHost(String hostEntry, String addrString) { + String[] mapping = hostEntry.split("\\s+"); + String host = null; + + if (mapping.length >= 2) { + if (mapping[0].equalsIgnoreCase(addrString)) { + host = mapping[1]; + } + } + return host; + } } + static final InetAddressImpl impl; + static { // create the impl impl = InetAddressImplFactory.create(); - // get name service if provided and requested - String provider = null;; - String propPrefix = "sun.net.spi.nameservice.provider."; - int n = 1; - nameServices = new ArrayList<>(); - provider = AccessController.doPrivileged( - new GetPropertyAction(propPrefix + n)); - while (provider != null) { - NameService ns = createNSProvider(provider); - if (ns != null) - nameServices.add(ns); - - n++; - provider = AccessController.doPrivileged( - new GetPropertyAction(propPrefix + n)); + // create name service + nameService = createNameService(); } - // if not designate any name services provider, - // create a default one - if (nameServices.size() == 0) { - NameService ns = createNSProvider("default"); - nameServices.add(ns); + /** + * Create an instance of the NameService interface based on + * the setting of the {@codejdk.net.hosts.file} system property. + * + *

The default NameService is the PlatformNameService, which typically + * delegates name and address resolution calls to the underlying + * OS network libraries. + * + *

A HostsFileNameService is created if the {@code jdk.net.hosts.file} + * system property is set. If the specified file doesn't exist, the name or + * address lookup will result in an UnknownHostException. Thus, non existent + * hosts file is handled as if the file is empty. + * + * @return a NameService + */ + private static NameService createNameService() { + + String hostsFileName = AccessController + .doPrivileged(new GetPropertyAction("jdk.net.hosts.file")); + NameService theNameService; + if (hostsFileName != null) { + theNameService = new HostsFileNameService(hostsFileName); + } else { + theNameService = new PlatformNameService(); } + return theNameService; } /** @@ -1286,20 +1480,16 @@ InetAddress[] addresses = null; UnknownHostException ex = null; - for (NameService nameService : nameServices) { try { addresses = nameService.lookupAllHostAddr(host); - break; } catch (UnknownHostException uhe) { if (host.equalsIgnoreCase("localhost")) { addresses = new InetAddress[] { impl.loopbackAddress() }; - break; } else { ex = uhe; } } - } if (addresses == null) { throw ex == null ? new UnknownHostException(host) : ex; diff -r 4209c9e19c45 -r d041d2e80712 jdk/src/java.base/share/classes/module-info.java --- a/jdk/src/java.base/share/classes/module-info.java Sat Apr 09 20:12:13 2016 +0100 +++ b/jdk/src/java.base/share/classes/module-info.java Mon Apr 11 03:00:50 2016 +0100 @@ -192,8 +192,6 @@ exports sun.net.dns to java.security.jgss, jdk.naming.dns; - exports sun.net.spi.nameservice to - jdk.naming.dns; exports sun.net.util to java.desktop, jdk.jconsole, @@ -286,7 +284,6 @@ // JDK-internal service types uses jdk.internal.logger.DefaultLoggerFinder; - uses sun.net.spi.nameservice.NameServiceDescriptor; uses sun.security.ssl.ClientKeyExchangeService; uses sun.util.spi.CalendarProvider; uses sun.util.locale.provider.LocaleDataMetaInfo; diff -r 4209c9e19c45 -r d041d2e80712 jdk/src/java.base/share/classes/sun/net/spi/nameservice/NameService.java --- a/jdk/src/java.base/share/classes/sun/net/spi/nameservice/NameService.java Sat Apr 09 20:12:13 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2000, 2005, 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 sun.net.spi.nameservice; - -import java.net.UnknownHostException; - -public interface NameService { - public java.net.InetAddress[] lookupAllHostAddr(String host) throws UnknownHostException; - public String getHostByAddr(byte[] addr) throws UnknownHostException; -} diff -r 4209c9e19c45 -r d041d2e80712 jdk/src/java.base/share/classes/sun/net/spi/nameservice/NameServiceDescriptor.java --- a/jdk/src/java.base/share/classes/sun/net/spi/nameservice/NameServiceDescriptor.java Sat Apr 09 20:12:13 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2000, 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 sun.net.spi.nameservice; - -public interface NameServiceDescriptor { - /** - * Create a new instance of the corresponding name service. - */ - public NameService createNameService () throws Exception ; - - /** - * Returns this service provider's name - * - */ - public String getProviderName(); - - /** - * Returns this name service type - * "dns" "nis" etc - */ - public String getType(); -} diff -r 4209c9e19c45 -r d041d2e80712 jdk/src/jdk.naming.dns/share/classes/module-info.java --- a/jdk/src/jdk.naming.dns/share/classes/module-info.java Sat Apr 09 20:12:13 2016 +0100 +++ b/jdk/src/jdk.naming.dns/share/classes/module-info.java Mon Apr 11 03:00:50 2016 +0100 @@ -31,7 +31,5 @@ provides javax.naming.spi.InitialContextFactory with com.sun.jndi.dns.DnsContextFactory; - provides sun.net.spi.nameservice.NameServiceDescriptor - with sun.net.spi.nameservice.dns.DNSNameServiceDescriptor; } diff -r 4209c9e19c45 -r d041d2e80712 jdk/src/jdk.naming.dns/share/classes/sun/net/spi/nameservice/dns/DNSNameService.java --- a/jdk/src/jdk.naming.dns/share/classes/sun/net/spi/nameservice/dns/DNSNameService.java Sat Apr 09 20:12:13 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,501 +0,0 @@ -/* - * Copyright (c) 2000, 2011, 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 sun.net.spi.nameservice.dns; - -import java.lang.ref.SoftReference; -import java.net.InetAddress; -import java.net.UnknownHostException; -import javax.naming.*; -import javax.naming.directory.*; -import javax.naming.spi.NamingManager; -import java.util.*; -import sun.net.util.IPAddressUtil; -import sun.net.dns.ResolverConfiguration; -import sun.net.spi.nameservice.*; -import java.security.AccessController; -import java.security.PrivilegedAction; - -/* - * A name service provider based on JNDI-DNS. - */ - -public final class DNSNameService implements NameService { - - // List of domains specified by property - private LinkedList domainList = null; - - // JNDI-DNS URL for name servers specified via property - private String nameProviderUrl = null; - - // Per-thread soft cache of the last temporary context - private static ThreadLocal> contextRef = - new ThreadLocal<>(); - - // Simple class to encapsulate the temporary context - private static class ThreadContext { - private DirContext dirCtxt; - private List nsList; - - public ThreadContext(DirContext dirCtxt, List nsList) { - this.dirCtxt = dirCtxt; - this.nsList = nsList; - } - - public DirContext dirContext() { - return dirCtxt; - } - - public List nameservers() { - return nsList; - } - } - - // Returns a per-thread DirContext - private DirContext getTemporaryContext() throws NamingException { - SoftReference ref = contextRef.get(); - ThreadContext thrCtxt = null; - List nsList = null; - - // if no property specified we need to obtain the list of servers - // - if (nameProviderUrl == null) - nsList = ResolverConfiguration.open().nameservers(); - - // if soft reference hasn't been gc'ed no property has been - // specified then we need to check if the DNS configuration - // has changed. - // - if ((ref != null) && ((thrCtxt = ref.get()) != null)) { - if (nameProviderUrl == null) { - if (!thrCtxt.nameservers().equals(nsList)) { - // DNS configuration has changed - thrCtxt = null; - } - } - } - - // new thread context needs to be created - if (thrCtxt == null) { - final Hashtable env = new Hashtable<>(); - env.put("java.naming.factory.initial", - "com.sun.jndi.dns.DnsContextFactory"); - - // If no nameservers property specified we create provider URL - // based on system configured name servers - // - String provUrl = nameProviderUrl; - if (provUrl == null) { - provUrl = createProviderURL(nsList); - if (provUrl.length() == 0) { - throw new RuntimeException("bad nameserver configuration"); - } - } - env.put("java.naming.provider.url", provUrl); - - // Need to create directory context in privileged block - // as JNDI-DNS needs to resolve the name servers. - // - DirContext dirCtxt; - try { - dirCtxt = java.security.AccessController.doPrivileged( - new java.security.PrivilegedExceptionAction() { - public DirContext run() throws NamingException { - // Create the DNS context using NamingManager rather than using - // the initial context constructor. This avoids having the initial - // context constructor call itself. - Context ctx = NamingManager.getInitialContext(env); - if (!(ctx instanceof DirContext)) { - return null; // cannot create a DNS context - } - return (DirContext)ctx; - } - }); - } catch (java.security.PrivilegedActionException pae) { - throw (NamingException)pae.getException(); - } - - // create new soft reference to our thread context - // - thrCtxt = new ThreadContext(dirCtxt, nsList); - contextRef.set(new SoftReference(thrCtxt)); - } - - return thrCtxt.dirContext(); - } - - /** - * Resolves the specified entry in DNS. - * - * Canonical name records are recursively resolved (to a maximum - * of 5 to avoid performance hit and potential CNAME loops). - * - * @param ctx JNDI directory context - * @param name name to resolve - * @param ids record types to search - * @param depth call depth - pass as 0. - * - * @return array list with results (will have at least on entry) - * - * @throws UnknownHostException if lookup fails or other error. - */ - private ArrayList resolve(final DirContext ctx, final String name, - final String[] ids, int depth) - throws UnknownHostException - { - ArrayList results = new ArrayList<>(); - Attributes attrs; - - // do the query - try { - attrs = java.security.AccessController.doPrivileged( - new java.security.PrivilegedExceptionAction() { - public Attributes run() throws NamingException { - return ctx.getAttributes(name, ids); - } - }); - } catch (java.security.PrivilegedActionException pae) { - throw new UnknownHostException(pae.getException().getMessage()); - } - - // non-requested type returned so enumeration is empty - NamingEnumeration ne = attrs.getAll(); - if (!ne.hasMoreElements()) { - throw new UnknownHostException("DNS record not found"); - } - - // iterate through the returned attributes - UnknownHostException uhe = null; - try { - while (ne.hasMoreElements()) { - Attribute attr = ne.next(); - String attrID = attr.getID(); - - for (NamingEnumeration e = attr.getAll(); e.hasMoreElements();) { - String addr = (String)e.next(); - - // for canoncical name records do recursive lookup - // - also check for CNAME loops to avoid stack overflow - - if (attrID.equals("CNAME")) { - if (depth > 4) { - throw new UnknownHostException(name + ": possible CNAME loop"); - } - try { - results.addAll(resolve(ctx, addr, ids, depth+1)); - } catch (UnknownHostException x) { - // canonical name can't be resolved. - if (uhe == null) - uhe = x; - } - } else { - results.add(addr); - } - } - } - } catch (NamingException nx) { - throw new UnknownHostException(nx.getMessage()); - } - - // pending exception as canonical name could not be resolved. - if (results.isEmpty() && uhe != null) { - throw uhe; - } - - return results; - } - - public DNSNameService() throws Exception { - - // default domain - String domain = AccessController.doPrivileged( - (PrivilegedAction) () -> System.getProperty("sun.net.spi.nameservice.domain")); - if (domain != null && domain.length() > 0) { - domainList = new LinkedList(); - domainList.add(domain); - } - - // name servers - String nameservers = AccessController.doPrivileged( - (PrivilegedAction) () -> System.getProperty("sun.net.spi.nameservice.nameservers")); - if (nameservers != null && nameservers.length() > 0) { - nameProviderUrl = createProviderURL(nameservers); - if (nameProviderUrl.length() == 0) { - throw new RuntimeException("malformed nameservers property"); - } - - } else { - - // no property specified so check host DNS resolver configured - // with at least one nameserver in dotted notation. - // - List nsList = ResolverConfiguration.open().nameservers(); - if (nsList.isEmpty()) { - throw new RuntimeException("no nameservers provided"); - } - boolean found = false; - for (String addr: nsList) { - if (IPAddressUtil.isIPv4LiteralAddress(addr) || - IPAddressUtil.isIPv6LiteralAddress(addr)) { - found = true; - break; - } - } - if (!found) { - throw new RuntimeException("bad nameserver configuration"); - } - } - } - - public InetAddress[] lookupAllHostAddr(String host) throws UnknownHostException { - - // DNS records that we search for - String[] ids = {"A", "AAAA", "CNAME"}; - - // first get directory context - DirContext ctx; - try { - ctx = getTemporaryContext(); - } catch (NamingException nx) { - throw new Error(nx); - } - - ArrayList results = null; - UnknownHostException uhe = null; - - // If host already contains a domain name then just look it up - if (host.indexOf('.') >= 0) { - try { - results = resolve(ctx, host, ids, 0); - } catch (UnknownHostException x) { - uhe = x; - } - } - - // Here we try to resolve the host using the domain suffix or - // the domain suffix search list. If the host cannot be resolved - // using the domain suffix then we attempt devolution of - // the suffix - eg: if we are searching for "foo" and our - // domain suffix is "eng.sun.com" we will try to resolve - // "foo.eng.sun.com" and "foo.sun.com". - // It's not normal to attempt devolation with domains on the - // domain suffix search list - however as ResolverConfiguration - // doesn't distinguish domain or search list in the list it - // returns we approximate by doing devolution on the domain - // suffix if the list has one entry. - - if (results == null) { - List searchList = null; - Iterator i; - boolean usingSearchList = false; - - if (domainList != null) { - i = domainList.iterator(); - } else { - searchList = ResolverConfiguration.open().searchlist(); - if (searchList.size() > 1) { - usingSearchList = true; - } - i = searchList.iterator(); - } - - // iterator through each domain suffix - while (i.hasNext()) { - String parentDomain = i.next(); - int start = 0; - while ((start = parentDomain.indexOf('.')) != -1 - && start < parentDomain.length() -1) { - try { - results = resolve(ctx, host+"."+parentDomain, ids, 0); - break; - } catch (UnknownHostException x) { - uhe = x; - if (usingSearchList) { - break; - } - - // devolve - parentDomain = parentDomain.substring(start+1); - } - } - if (results != null) { - break; - } - } - } - - // finally try the host if it doesn't have a domain name - if (results == null && (host.indexOf('.') < 0)) { - results = resolve(ctx, host, ids, 0); - } - - // if not found then throw the (last) exception thrown. - if (results == null) { - assert uhe != null; - throw uhe; - } - - /** - * Convert the array list into a byte aray list - this - * filters out any invalid IPv4/IPv6 addresses. - */ - assert results.size() > 0; - InetAddress[] addrs = new InetAddress[results.size()]; - int count = 0; - for (int i=0; i results = null; - try { - ctx = getTemporaryContext(); - } catch (NamingException nx) { - throw new Error(nx); - } - if (addr.length == 4) { // IPv4 Address - for (int i = addr.length-1; i >= 0; i--) { - literalip += (addr[i] & 0xff) +"."; - } - literalip += "IN-ADDR.ARPA."; - - results = resolve(ctx, literalip, ids, 0); - host = results.get(0); - } else if (addr.length == 16) { // IPv6 Address - /** - * Because RFC 3152 changed the root domain name for reverse - * lookups from IP6.INT. to IP6.ARPA., we need to check - * both. I.E. first the new one, IP6.ARPA, then if it fails - * the older one, IP6.INT - */ - - for (int i = addr.length-1; i >= 0; i--) { - literalip += Integer.toHexString((addr[i] & 0x0f)) +"." - +Integer.toHexString((addr[i] & 0xf0) >> 4) +"."; - } - String ip6lit = literalip + "IP6.ARPA."; - - try { - results = resolve(ctx, ip6lit, ids, 0); - host = results.get(0); - } catch (UnknownHostException e) { - host = null; - } - if (host == null) { - // IP6.ARPA lookup failed, let's try the older IP6.INT - ip6lit = literalip + "IP6.INT."; - results = resolve(ctx, ip6lit, ids, 0); - host = results.get(0); - } - } - } catch (Exception e) { - throw new UnknownHostException(e.getMessage()); - } - // Either we couldn't find it or the address was neither IPv4 or IPv6 - if (host == null) - throw new UnknownHostException(); - // remove trailing dot - if (host.endsWith(".")) { - host = host.substring(0, host.length() - 1); - } - return host; - } - - - // --------- - - private static void appendIfLiteralAddress(String addr, StringBuilder sb) { - if (IPAddressUtil.isIPv4LiteralAddress(addr)) { - sb.append("dns://").append(addr).append(' '); - } else { - if (IPAddressUtil.isIPv6LiteralAddress(addr)) { - sb.append("dns://[").append(addr).append("] "); - } - } - } - - /* - * @return String containing the JNDI-DNS provider URL - * corresponding to the supplied List of nameservers. - */ - private static String createProviderURL(List nsList) { - StringBuilder sb = new StringBuilder(); - for (String s: nsList) { - appendIfLiteralAddress(s, sb); - } - return sb.toString(); - } - - /* - * @return String containing the JNDI-DNS provider URL - * corresponding to the list of nameservers - * contained in the provided str. - */ - private static String createProviderURL(String str) { - StringBuilder sb = new StringBuilder(); - StringTokenizer st = new StringTokenizer(str, ","); - while (st.hasMoreTokens()) { - appendIfLiteralAddress(st.nextToken(), sb); - } - return sb.toString(); - } -} diff -r 4209c9e19c45 -r d041d2e80712 jdk/src/jdk.naming.dns/share/classes/sun/net/spi/nameservice/dns/DNSNameServiceDescriptor.java --- a/jdk/src/jdk.naming.dns/share/classes/sun/net/spi/nameservice/dns/DNSNameServiceDescriptor.java Sat Apr 09 20:12:13 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2000, 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 sun.net.spi.nameservice.dns; - -import sun.net.spi.nameservice.*; - -public final class DNSNameServiceDescriptor implements NameServiceDescriptor { - /** - * Create a new instance of the corresponding name service. - */ - public NameService createNameService() throws Exception { - return new DNSNameService(); - } - - /** - * Returns this service provider's name - * - */ - public String getProviderName() { - return "sun"; - } - - /** - * Returns this name service type - * "dns" "nis" etc - */ - public String getType() { - return "dns"; - } -} diff -r 4209c9e19c45 -r d041d2e80712 jdk/test/ProblemList.txt --- a/jdk/test/ProblemList.txt Sat Apr 09 20:12:13 2016 +0100 +++ b/jdk/test/ProblemList.txt Mon Apr 11 03:00:50 2016 +0100 @@ -159,8 +159,6 @@ # jdk_net -sun/net/InetAddress/nameservice/simple/CacheTest.java 7148829 generic-all -sun/net/InetAddress/nameservice/simple/DefaultCaching.java 7148829 generic-all java/net/MulticastSocket/NoLoopbackPackets.java 7122846 macosx-all java/net/MulticastSocket/SetLoopbackMode.java 7122846 macosx-all @@ -284,6 +282,8 @@ sun/security/provider/NSASuiteB/TestDSAGenParameterSpec.java 8137255 generic-all +sun/security/x509/URICertStore/ExtensionsWithLDAP.java 8134577 generic-all + ############################################################################ # jdk_sound @@ -310,6 +310,7 @@ # jdk_time + ############################################################################ # jdk_tools diff -r 4209c9e19c45 -r d041d2e80712 jdk/test/java/net/Inet4Address/DummyNameService.java --- a/jdk/test/java/net/Inet4Address/DummyNameService.java Sat Apr 09 20:12:13 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2014, 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. - * - * 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. - */ - -/* - * A simple name service which throws an exception when invoked - */ - -import java.net.UnknownHostException; -import java.net.InetAddress; -import sun.net.spi.nameservice.*; -import java.util.*; - -public final class DummyNameService implements NameService { - - public DummyNameService() throws Exception { - } - - public InetAddress[] lookupAllHostAddr(String host) throws UnknownHostException { - throw new UnknownHostException("Dummy name service"); - } - - public String getHostByAddr(byte[] addr) throws UnknownHostException { - throw new UnknownHostException("Dummy name service"); - } -} diff -r 4209c9e19c45 -r d041d2e80712 jdk/test/java/net/Inet4Address/DummyNameServiceDescriptor.java --- a/jdk/test/java/net/Inet4Address/DummyNameServiceDescriptor.java Sat Apr 09 20:12:13 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2014, 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. - * - * 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. - */ - -/* - * Descriptor for the dummy name service - */ - -import sun.net.spi.nameservice.*; - -public final class DummyNameServiceDescriptor implements NameServiceDescriptor { - - /** - * Create a new instance of the corresponding name service. - */ - public NameService createNameService() throws Exception { - return new DummyNameService(); - } - - /** - * Returns this service provider's name - * - */ - public String getProviderName() { - return "oracle"; - } - - /** - * Returns this name service type - * "dns" "nis" etc - */ - public String getType() { - return "dummy"; - } -} diff -r 4209c9e19c45 -r d041d2e80712 jdk/test/java/net/Inet4Address/META-INF/services/sun.net.spi.nameservice.NameServiceDescriptor --- a/jdk/test/java/net/Inet4Address/META-INF/services/sun.net.spi.nameservice.NameServiceDescriptor Sat Apr 09 20:12:13 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ -# Copyright (c) 2014, 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. -# -# 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. - -DummyNameServiceDescriptor # name service provider descriptor diff -r 4209c9e19c45 -r d041d2e80712 jdk/test/java/net/Inet4Address/TestToNumericFormatHosts --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/net/Inet4Address/TestToNumericFormatHosts Mon Apr 11 03:00:50 2016 +0100 @@ -0,0 +1,1 @@ + diff -r 4209c9e19c45 -r d041d2e80712 jdk/test/java/net/Inet4Address/textToNumericFormat.java --- a/jdk/test/java/net/Inet4Address/textToNumericFormat.java Sat Apr 09 20:12:13 2016 +0100 +++ b/jdk/test/java/net/Inet4Address/textToNumericFormat.java Mon Apr 11 03:00:50 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2016 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 @@ -25,9 +25,7 @@ * @test * @bug 4749938 8087190 * @summary Bug in the parsing IPv4 literal addresses - * @modules java.base/sun.net.spi.nameservice - * @compile -XDignore.symbol.file=true DummyNameService.java DummyNameServiceDescriptor.java - * @run main/othervm -Dsun.net.spi.nameservice.provider.1=dummy,oracle textToNumericFormat + * @run main/othervm textToNumericFormat */ /** @@ -68,6 +66,8 @@ "1..1.1", "1.1.1.", "..." }; + String hostsFileName = System.getProperty("test.src", ".") + "/TestToNumericFormatHosts"; + System.setProperty("jdk.net.hosts.file", hostsFileName); for (int i=0; i host addr mapping - private HashMap hosts = new LinkedHashMap(); - - public void put(String host, String addr) { - hosts.put(host, addr); - } - - private static String addrToString(byte addr[]) { - return Byte.toString(addr[0]) + "." + - Byte.toString(addr[1]) + "." + - Byte.toString(addr[2]) + "." + - Byte.toString(addr[3]); - } - - public SimpleNameService() { - } - - public InetAddress[] lookupAllHostAddr(String host) throws UnknownHostException { - String addr = hosts.get(host); - if (addr == null) { - throw new UnknownHostException(host); - } - - StringTokenizer tokenizer = new StringTokenizer(addr, "."); - byte addrs[] = new byte[4]; - for (int i = 0; i < 4; i++) { - addrs[i] = (byte)Integer.parseInt(tokenizer.nextToken()); - } - InetAddress[] ret = new InetAddress[1]; - ret[0] = InetAddress.getByAddress(host, addrs); - return ret; - } - - public String getHostByAddr(byte[] addr) throws UnknownHostException { - String addrString = addrToString(addr); - Iterator i = hosts.keySet().iterator(); - while (i.hasNext()) { - String host = (String)i.next(); - String value = (String)hosts.get(host); - if (value.equals(addrString)) { - return host; - } - } - throw new UnknownHostException(); - } -} diff -r 4209c9e19c45 -r d041d2e80712 jdk/test/sun/net/InetAddress/nameservice/deadlock/Hang.java --- a/jdk/test/sun/net/InetAddress/nameservice/deadlock/Hang.java Sat Apr 09 20:12:13 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2011, 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. - * - * 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. - */ - -/** - * @test - * @bug 7012768 - * @modules java.base/sun.net.spi.nameservice - * @compile -XDignore.symbol.file=true ThrowingNameService.java - * ThrowingNameServiceDescriptor.java - * @run main/othervm/timeout=30 -Dsun.net.spi.nameservice.provider.1=throwing,sun Hang - * @summary InetAddress lookupTable leaks/deadlocks when using unsupported - * name service spi - */ - -import java.net.InetAddress; - -public class Hang { - public static void main(String[] args) throws Exception { - try { - // 1st attempt - IllegalStateException caught below - InetAddress.getByName("host.company.com"); - } catch (IllegalStateException e) { } - - // 2nd attempt - Stuck here forever if bug exists - InetAddress.getByName("host.company.com"); - } -} diff -r 4209c9e19c45 -r d041d2e80712 jdk/test/sun/net/InetAddress/nameservice/deadlock/META-INF/services/sun.net.spi.nameservice.NameServiceDescriptor --- a/jdk/test/sun/net/InetAddress/nameservice/deadlock/META-INF/services/sun.net.spi.nameservice.NameServiceDescriptor Sat Apr 09 20:12:13 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ -# Copyright (c) 2011, 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. -# -# 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. - -ThrowingNameServiceDescriptor diff -r 4209c9e19c45 -r d041d2e80712 jdk/test/sun/net/InetAddress/nameservice/deadlock/ThrowingNameService.java --- a/jdk/test/sun/net/InetAddress/nameservice/deadlock/ThrowingNameService.java Sat Apr 09 20:12:13 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2011, 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. - * - * 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. - */ - -import java.net.InetAddress; -import java.net.UnknownHostException; -import sun.net.spi.nameservice.NameService; - -public class ThrowingNameService implements NameService { - static boolean firstCall = true; - - @Override - public InetAddress[] lookupAllHostAddr(String host) throws UnknownHostException { - if (firstCall) { - firstCall = false; - // throw unchecked exception first time round - throw new IllegalStateException(); - } - - // return any valid address - return new InetAddress[] { InetAddress.getLoopbackAddress() }; - } - - @Override - public String getHostByAddr(byte[] addr) throws UnknownHostException { - throw new IllegalStateException(); - } -} diff -r 4209c9e19c45 -r d041d2e80712 jdk/test/sun/net/InetAddress/nameservice/deadlock/ThrowingNameServiceDescriptor.java --- a/jdk/test/sun/net/InetAddress/nameservice/deadlock/ThrowingNameServiceDescriptor.java Sat Apr 09 20:12:13 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2011, 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. - * - * 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. - */ - -import sun.net.spi.nameservice.*; - -public class ThrowingNameServiceDescriptor implements NameServiceDescriptor { - public NameService createNameService() { - return new ThrowingNameService(); - } - - @Override - public String getProviderName() { - return "sun"; - } - - @Override - public String getType() { - return "throwing"; - } -} diff -r 4209c9e19c45 -r d041d2e80712 jdk/test/sun/net/InetAddress/nameservice/dns/cname.sh --- a/jdk/test/sun/net/InetAddress/nameservice/dns/cname.sh Sat Apr 09 20:12:13 2016 +0100 +++ b/jdk/test/sun/net/InetAddress/nameservice/dns/cname.sh Mon Apr 11 03:00:50 2016 +0100 @@ -66,8 +66,8 @@ np="-Dsun.net.spi.nameservice.provider.1=dns,sun" sm="-Djava.security.manager -Djava.security.policy=${POLICY}" -go "$np" "$HOST" -go "$np $sm" "$HOST" +go "" "$HOST" +go "$sm" "$HOST" # diff -r 4209c9e19c45 -r d041d2e80712 jdk/test/sun/net/InetAddress/nameservice/simple/CacheTest.java --- a/jdk/test/sun/net/InetAddress/nameservice/simple/CacheTest.java Sat Apr 09 20:12:13 2016 +0100 +++ b/jdk/test/sun/net/InetAddress/nameservice/simple/CacheTest.java Mon Apr 11 03:00:50 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2016, 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 @@ -26,14 +26,14 @@ * @summary Check that InetAddress doesn't continue to throw UHE * after the name service has recovered and the negative ttl * on the initial lookup has expired. - * @modules java.base/sun.net.spi.nameservice - * @compile -XDignore.symbol.file=true SimpleNameService.java - * SimpleNameServiceDescriptor.java - * @run main/othervm/timeout=200 -Dsun.net.spi.nameservice.provider.1=simple,sun CacheTest + * @run main/othervm/timeout=200 CacheTest */ import java.net.InetAddress; import java.net.UnknownHostException; import java.security.Security; +import java.io.PrintWriter; +import java.io.FileWriter; +import java.io.BufferedWriter; public class CacheTest { @@ -59,6 +59,8 @@ return; } + String hostsFileName = System.getProperty("test.src", ".") + "/CacheTestHosts"; + System.setProperty("jdk.net.hosts.file", hostsFileName); /* * The following outlines how the test works :- @@ -78,7 +80,7 @@ */ // name service needs to resolve this. - SimpleNameService.put("theclub", "129.156.220.219"); + addMappingToHostsFile("theclub", "129.156.220.219", hostsFileName, false); // this lookup will succeed InetAddress.getByName("theclub"); @@ -89,12 +91,12 @@ try { InetAddress.getByName("luster"); throw new RuntimeException("Test internal error " + - " - luster is bring resolved by name service"); + " - luster is being resolved by name service"); } catch (UnknownHostException x) { } // name service now needs to know about luster - SimpleNameService.put("luster", "10.5.18.21"); + addMappingToHostsFile("luster", "10.5.18.21", hostsFileName, true); // wait for the cache entry to expire and lookup should // succeed. @@ -102,4 +104,16 @@ InetAddress.getByName("luster"); } + private static void addMappingToHostsFile ( String host, + String addr, + String hostsFileName, + boolean append) + throws Exception { + String mapping = addr + " " + host; + try (PrintWriter hfPWriter = new PrintWriter(new BufferedWriter( + new FileWriter(hostsFileName, append)))) { + hfPWriter.println(mapping); } + } + +} diff -r 4209c9e19c45 -r d041d2e80712 jdk/test/sun/net/InetAddress/nameservice/simple/CacheTestHosts --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/sun/net/InetAddress/nameservice/simple/CacheTestHosts Mon Apr 11 03:00:50 2016 +0100 @@ -0,0 +1,2 @@ +129.156.220.219 theclub +10.5.18.21 luster diff -r 4209c9e19c45 -r d041d2e80712 jdk/test/sun/net/InetAddress/nameservice/simple/DefaultCaching.java --- a/jdk/test/sun/net/InetAddress/nameservice/simple/DefaultCaching.java Sat Apr 09 20:12:13 2016 +0100 +++ b/jdk/test/sun/net/InetAddress/nameservice/simple/DefaultCaching.java Mon Apr 11 03:00:50 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2016, 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 @@ -25,35 +25,40 @@ * @bug 6442088 * @summary Change default DNS caching behavior for code not running under * security manager. - * @modules java.base/sun.net.spi.nameservice - * @compile -XDignore.symbol.file=true SimpleNameService.java - * SimpleNameServiceDescriptor.java - * @run main/othervm/timeout=200 -Dsun.net.inetaddr.ttl=20 -Dsun.net.spi.nameservice.provider.1=simple,sun DefaultCaching + * @run main/othervm/timeout=200 -Dsun.net.inetaddr.ttl=20 DefaultCaching */ import java.net.InetAddress; import java.net.UnknownHostException; import java.security.Security; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.io.BufferedWriter; public class DefaultCaching { public static void main(String args[]) throws Exception { + String hostsFileName = System.getProperty("test.src", ".") + "/DefaultCachingHosts"; + System.setProperty("jdk.net.hosts.file", hostsFileName); + // initial mapping // name service needs to resolve this. - SimpleNameService.put("theclub", "129.156.220.219"); + addMappingToHostsFile("theclub", "129.156.220.219", hostsFileName, false); test ("theclub", "129.156.220.219", true); // lk: 1 test ("luster", "1.16.20.2", false); // lk: 2 // name service now needs to know about luster - SimpleNameService.put("luster", "10.5.18.21"); + addMappingToHostsFile("luster", "10.5.18.21", hostsFileName, true); test ("luster", "1.16.20.2", false); // lk: 2 sleep (10+1); test("luster", "10.5.18.21", true, 3); // lk: 3 sleep (5); - SimpleNameService.put("foo", "10.5.18.22"); - SimpleNameService.put("theclub", "129.156.220.1"); + // new mapping for theclub and rewrite existing foo and luster mappings + addMappingToHostsFile("theclub", "129.156.220.1", hostsFileName, false); + addMappingToHostsFile("foo", "10.5.18.22", hostsFileName, true); + addMappingToHostsFile("luster", "10.5.18.21", hostsFileName, true); test ("theclub", "129.156.220.219", true, 3); test ("luster", "10.5.18.21", true, 3); @@ -84,10 +89,6 @@ static void test (String host, String address, boolean shouldSucceed, int count) { test (host, address, shouldSucceed); - int got = SimpleNameService.lookupCalls(); - if (got != count) { - throw new RuntimeException ("lookups exp/got: " + count+"/"+got); - } } static void sleep (int seconds) { @@ -114,4 +115,16 @@ } } + + private static void addMappingToHostsFile (String host, + String addr, + String hostsFileName, + boolean append) + throws Exception { + String mapping = addr + " " + host; + try (PrintWriter hfPWriter = new PrintWriter(new BufferedWriter( + new FileWriter(hostsFileName, append)))) { + hfPWriter.println(mapping); } + } +} diff -r 4209c9e19c45 -r d041d2e80712 jdk/test/sun/net/InetAddress/nameservice/simple/DefaultCachingHosts --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/sun/net/InetAddress/nameservice/simple/DefaultCachingHosts Mon Apr 11 03:00:50 2016 +0100 @@ -0,0 +1,3 @@ +129.156.220.1 theclub +10.5.18.22 foo +10.5.18.21 luster diff -r 4209c9e19c45 -r d041d2e80712 jdk/test/sun/net/InetAddress/nameservice/simple/META-INF/services/sun.net.spi.nameservice.NameServiceDescriptor --- a/jdk/test/sun/net/InetAddress/nameservice/simple/META-INF/services/sun.net.spi.nameservice.NameServiceDescriptor Sat Apr 09 20:12:13 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ -# Copyright (c) 2011, 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. -# -# 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. - -SimpleNameServiceDescriptor # name service provider descriptor diff -r 4209c9e19c45 -r d041d2e80712 jdk/test/sun/net/InetAddress/nameservice/simple/SimpleNameService.java --- a/jdk/test/sun/net/InetAddress/nameservice/simple/SimpleNameService.java Sat Apr 09 20:12:13 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2002, 2011, 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. - * - * 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. - */ - -/* - * A simple name service based on an in-memory HashMap. - */ -import java.net.UnknownHostException; -import java.net.InetAddress; -import sun.net.spi.nameservice.*; -import java.util.*; - -public final class SimpleNameService implements NameService { - - private static LinkedHashMap hosts = new LinkedHashMap(); - - private static String addrToString(byte addr[]) { - return Byte.toString(addr[0]) + "." + - Byte.toString(addr[1]) + "." + - Byte.toString(addr[2]) + "." + - Byte.toString(addr[3]); - } - - // ------------ - - public static void put(String host, String addr) { - hosts.put(host, addr); - } - - public static void put(String host, byte addr[]) { - hosts.put(host, addrToString(addr)); - } - - public static void remove(String host) { - hosts.remove(host); - } - - public static int entries () { - return hosts.size(); - } - - public static int lookupCalls() { - return lookupCalls; - } - - static int lookupCalls = 0; - - // ------------ - - public SimpleNameService() throws Exception { - } - - public InetAddress[] lookupAllHostAddr(String host) throws UnknownHostException { - - lookupCalls ++; - - String value = (String)hosts.get(host); - if (value == null) { - throw new UnknownHostException(host); - } - StringTokenizer st = new StringTokenizer(value, "."); - byte addr[] = new byte[4]; - for (int i=0; i<4; i++) { - addr[i] = (byte)Integer.parseInt(st.nextToken()); - } - InetAddress[] res = new InetAddress[1]; - res[0] = InetAddress.getByAddress(host, addr); - return res; - } - - public String getHostByAddr(byte[] addr) throws UnknownHostException { - String addrString = addrToString(addr); - Iterator i = hosts.keySet().iterator(); - while (i.hasNext()) { - String host = (String)i.next(); - String value = (String)hosts.get(host); - if (value.equals(addrString)) { - return host; - } - } - throw new UnknownHostException(); - } -} diff -r 4209c9e19c45 -r d041d2e80712 jdk/test/sun/net/InetAddress/nameservice/simple/SimpleNameServiceDescriptor.java --- a/jdk/test/sun/net/InetAddress/nameservice/simple/SimpleNameServiceDescriptor.java Sat Apr 09 20:12:13 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2002, 2011, 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. - * - * 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. - */ - -/* - * Descriptor for the simple name service - */ -import sun.net.spi.nameservice.*; - -public final class SimpleNameServiceDescriptor implements NameServiceDescriptor { - /** - * Create a new instance of the corresponding name service. - */ - public NameService createNameService() throws Exception { - return new SimpleNameService(); - } - - /** - * Returns this service provider's name - * - */ - public String getProviderName() { - return "sun"; - } - - /** - * Returns this name service type - * "dns" "nis" etc - */ - public String getType() { - return "simple"; - } -} diff -r 4209c9e19c45 -r d041d2e80712 jdk/test/sun/security/krb5/auto/BogusKDC.java --- a/jdk/test/sun/security/krb5/auto/BogusKDC.java Sat Apr 09 20:12:13 2016 +0100 +++ b/jdk/test/sun/security/krb5/auto/BogusKDC.java Mon Apr 11 03:00:50 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2016 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 @@ -82,7 +82,7 @@ // and wrong port for slave KDC try (PrintWriter w = new PrintWriter(new FileWriter(KRB5_CONF))) { w.write(String.format(KRB5_CONF_TEMPLATE, - KDC.KDCNameService.NOT_EXISTING_HOST, WRONG_KDC_PORT)); + KDC.NOT_EXISTING_HOST, WRONG_KDC_PORT)); w.flush(); } @@ -98,7 +98,7 @@ // but correct port for slave KDC try (PrintWriter w = new PrintWriter(new FileWriter(KRB5_CONF))) { w.write(String.format(KRB5_CONF_TEMPLATE, - KDC.KDCNameService.NOT_EXISTING_HOST, kdc.getPort())); + KDC.NOT_EXISTING_HOST, kdc.getPort())); w.flush(); } diff -r 4209c9e19c45 -r d041d2e80712 jdk/test/sun/security/krb5/auto/HttpNegotiateServer.java --- a/jdk/test/sun/security/krb5/auto/HttpNegotiateServer.java Sat Apr 09 20:12:13 2016 +0100 +++ b/jdk/test/sun/security/krb5/auto/HttpNegotiateServer.java Mon Apr 11 03:00:50 2016 +0100 @@ -24,8 +24,7 @@ /* * @test * @bug 6578647 6829283 - * @modules java.base/sun.net.spi.nameservice - * java.base/sun.security.util + * @modules java.base/sun.security.util * java.security.jgss/sun.security.jgss * java.security.jgss/sun.security.krb5 * java.security.jgss/sun.security.krb5.internal diff -r 4209c9e19c45 -r d041d2e80712 jdk/test/sun/security/krb5/auto/KDC.java --- a/jdk/test/sun/security/krb5/auto/KDC.java Sat Apr 09 20:12:13 2016 +0100 +++ b/jdk/test/sun/security/krb5/auto/KDC.java Mon Apr 11 03:00:50 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2016, 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 @@ -35,8 +35,6 @@ import java.util.*; import java.util.concurrent.*; -import sun.net.spi.nameservice.NameService; -import sun.net.spi.nameservice.NameServiceDescriptor; import sun.security.krb5.*; import sun.security.krb5.internal.*; import sun.security.krb5.internal.ccache.CredentialsCache; @@ -129,6 +127,8 @@ public static final int DEFAULT_LIFETIME = 39600; public static final int DEFAULT_RENEWTIME = 86400; + public static String NOT_EXISTING_HOST = "not.existing.host"; + // Under the hood. // The random generator to generate random keys (including session keys) @@ -219,7 +219,8 @@ }; static { - System.setProperty("sun.net.spi.nameservice.provider.1", "ns,mock"); + String hostsFileName = System.getProperty("test.src", ".") + "/TestHosts"; + System.setProperty("jdk.net.hosts.file", hostsFileName); } /** @@ -1448,45 +1449,6 @@ } } - public static class KDCNameService implements NameServiceDescriptor { - - public static String NOT_EXISTING_HOST = "not.existing.host"; - - @Override - public NameService createNameService() throws Exception { - NameService ns = new NameService() { - @Override - public InetAddress[] lookupAllHostAddr(String host) - throws UnknownHostException { - // Everything is localhost except NOT_EXISTING_HOST - if (NOT_EXISTING_HOST.equals(host)) { - throw new UnknownHostException("Unknown host name: " - + NOT_EXISTING_HOST); - } - return new InetAddress[]{ - InetAddress.getByAddress(host, new byte[]{127,0,0,1}) - }; - } - @Override - public String getHostByAddr(byte[] addr) - throws UnknownHostException { - // No reverse lookup, PrincipalName use original string - throw new UnknownHostException(); - } - }; - return ns; - } - - @Override - public String getProviderName() { - return "mock"; - } - - @Override - public String getType() { - return "ns"; - } - } // Calling private methods thru reflections private static final Field getPADataField; diff -r 4209c9e19c45 -r d041d2e80712 jdk/test/sun/security/krb5/auto/META-INF/services/sun.net.spi.nameservice.NameServiceDescriptor --- a/jdk/test/sun/security/krb5/auto/META-INF/services/sun.net.spi.nameservice.NameServiceDescriptor Sat Apr 09 20:12:13 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -KDC$KDCNameService diff -r 4209c9e19c45 -r d041d2e80712 jdk/test/sun/security/krb5/auto/NoAddresses.java --- a/jdk/test/sun/security/krb5/auto/NoAddresses.java Sat Apr 09 20:12:13 2016 +0100 +++ b/jdk/test/sun/security/krb5/auto/NoAddresses.java Mon Apr 11 03:00:50 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2016 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 @@ -24,6 +24,7 @@ /* * @test * @bug 7032354 + * @run main/othervm NoAddresses setup * @run main/othervm NoAddresses 1 * @run main/othervm NoAddresses 2 * @run main/othervm/fail NoAddresses 3 @@ -34,12 +35,24 @@ import org.ietf.jgss.ChannelBinding; import sun.security.jgss.GSSUtil; import sun.security.krb5.Config; +import java.io.PrintWriter; +import java.io.FileWriter; +import java.io.BufferedWriter; public class NoAddresses { public static void main(String[] args) throws Exception { + if (args[0].equalsIgnoreCase("setup")) { + // add a mapping of test host name to 127.0.0.1 to test's hosts file + InetAddress localHost = InetAddress.getLocalHost(); + String localHostName = localHost.getHostName(); + String hostsFileName = System.getProperty("test.src", ".") + "/TestHosts"; + String loopBackAddress = "127.0.0.1"; + System.setProperty("jdk.net.hosts.file", hostsFileName); + addMappingToHostsFile(localHostName, loopBackAddress, hostsFileName, true); + } else { OneKDC kdc = new OneKDC(null); kdc.writeJAASConf(); KDC.saveConfig(OneKDC.KRB5_CONF, kdc, @@ -79,3 +92,16 @@ Context.handshake(c, s); } } + + private static void addMappingToHostsFile (String host, + String addr, + String hostsFileName, + boolean append) + throws Exception { + String mapping = addr + " " + host; + try (PrintWriter hfPWriter = new PrintWriter(new BufferedWriter( + new FileWriter(hostsFileName, append)))) { + hfPWriter.println(mapping); + } + } +} diff -r 4209c9e19c45 -r d041d2e80712 jdk/test/sun/security/krb5/auto/Renew.java --- a/jdk/test/sun/security/krb5/auto/Renew.java Sat Apr 09 20:12:13 2016 +0100 +++ b/jdk/test/sun/security/krb5/auto/Renew.java Mon Apr 11 03:00:50 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2016 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 @@ -26,8 +26,7 @@ * @bug 8058290 * @summary JAAS Krb5LoginModule has suspect ticket-renewal logic, * relies on clockskew grace - * @modules java.base/sun.net.spi.nameservice - * java.base/sun.security.util + * @modules java.base/sun.security.util * java.security.jgss/sun.security.krb5 * java.security.jgss/sun.security.krb5.internal * java.security.jgss/sun.security.krb5.internal.ccache diff -r 4209c9e19c45 -r d041d2e80712 jdk/test/sun/security/krb5/auto/Renewal.java --- a/jdk/test/sun/security/krb5/auto/Renewal.java Sat Apr 09 20:12:13 2016 +0100 +++ b/jdk/test/sun/security/krb5/auto/Renewal.java Mon Apr 11 03:00:50 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2016 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 @@ -45,8 +45,11 @@ static OneKDC kdc; static String clazz = "sun.security.krb5.internal.tools.Kinit"; + static String hostsFileName = null; public static void main(String[] args) throws Exception { + hostsFileName = System.getProperty("test.src", ".") + "/TestHosts"; + System.setProperty("jdk.net.hosts.file", hostsFileName); kdc = new OneKDC(null); kdc.writeJAASConf(); @@ -95,7 +98,7 @@ count++; p.args(OneKDC.USER, new String(OneKDC.PASS)) .inheritIO() - .prop("sun.net.spi.nameservice.provider.1", "ns,mock") + .prop("jdk.net.hosts.file", hostsFileName) .prop("java.security.krb5.conf", OneKDC.KRB5_CONF) .env("KRB5CCNAME", "ccache" + count) .start(); @@ -114,10 +117,11 @@ } static void checkKinitRenew() throws Exception { + Proc p = Proc.create(clazz) .args("-R") .inheritIO() - .prop("sun.net.spi.nameservice.provider.1", "ns,mock") + .prop("jdk.net.hosts.file", hostsFileName) .prop("java.security.krb5.conf", OneKDC.KRB5_CONF) .env("KRB5CCNAME", "ccache" + count) .start(); diff -r 4209c9e19c45 -r d041d2e80712 jdk/test/sun/security/krb5/auto/SSLwithPerms.java --- a/jdk/test/sun/security/krb5/auto/SSLwithPerms.java Sat Apr 09 20:12:13 2016 +0100 +++ b/jdk/test/sun/security/krb5/auto/SSLwithPerms.java Mon Apr 11 03:00:50 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2016 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 @@ -84,19 +84,21 @@ ).getBytes()); fos.close(); + String hostsFileName = System.getProperty("test.src", ".") + "/TestHosts"; + Proc pc = Proc.create("SSLwithPerms") .args("client") .inheritIO() .prop("java.security.manager", "") .prop("java.security.krb5.conf", KRB5_CONF) - .prop("sun.net.spi.nameservice.provider.1", "ns,mock") + .prop("jdk.net.hosts.file", hostsFileName) .prop("javax.net.ssl", "handshake") .prop("sun.security.krb5.debug", "true") .perm(new SecurityPermission("setProperty.jdk.tls.disabledAlgorithms")) .perm(new PropertyPermission("sun.security.krb5.principal", "read")) .perm(new FilePermission("port", "read")) + .perm(new FilePermission(hostsFileName, "read")) .perm(new FilePermission(KTAB, "read")) - .perm(new RuntimePermission("accessClassInPackage.sun.net.spi.nameservice")) .perm(new AuthPermission("modifyPrincipals")) .perm(new AuthPermission("modifyPrivateCredentials")) .perm(new AuthPermission("doAs")) @@ -110,11 +112,13 @@ .prop("java.security.manager", "") .prop("java.security.krb5.conf", KRB5_CONF) .prop("java.security.auth.login.config", JAAS_CONF) + .prop("jdk.net.hosts.file", hostsFileName) .prop("javax.net.ssl", "handshake") .prop("sun.security.krb5.debug", "true") .perm(new SecurityPermission("setProperty.jdk.tls.disabledAlgorithms")) .perm(new AuthPermission("createLoginContext.ssl")) .perm(new AuthPermission("doAs")) + .perm(new FilePermission(hostsFileName, "read")) .perm(new FilePermission("port", "write")) .perm(new SocketPermission("127.0.0.1", "accept")) .perm(new ServicePermission("host/host.realm@REALM", "accept")) diff -r 4209c9e19c45 -r d041d2e80712 jdk/test/sun/security/krb5/auto/TEST.properties --- a/jdk/test/sun/security/krb5/auto/TEST.properties Sat Apr 09 20:12:13 2016 +0100 +++ b/jdk/test/sun/security/krb5/auto/TEST.properties Mon Apr 11 03:00:50 2016 +0100 @@ -1,5 +1,4 @@ modules java.base/jdk.internal.misc \ - java.base/sun.net.spi.nameservice \ java.base/sun.security.util \ java.security.jgss/sun.security.jgss \ java.security.jgss/sun.security.krb5 \ diff -r 4209c9e19c45 -r d041d2e80712 jdk/test/sun/security/krb5/auto/TestHosts --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/sun/security/krb5/auto/TestHosts Mon Apr 11 03:00:50 2016 +0100 @@ -0,0 +1,16 @@ +127.0.0.1 host.rabbit.hole +127.0.0.1 kdc.rabbit.hole +127.0.0.1 kdc.snake.hole +127.0.0.1 kdc.web.domain +127.0.0.1 host.web.domain +127.0.0.1 host.proxy.domain +127.0.0.1 kdc.proxy.domain +127.0.0.1 client.rabbit.hole +127.0.0.1 localhost +127.0.0.1 host.r3.local +127.0.0.1 kdc.r1 +127.0.0.1 kdc.r2 +127.0.0.1 kdc.r3 +127.0.0.1 host.realm +127.0.0.1 realm +127.0.0.1 irlga09 diff -r 4209c9e19c45 -r d041d2e80712 jdk/test/sun/security/krb5/auto/principalProperty/TestHosts --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/sun/security/krb5/auto/principalProperty/TestHosts Mon Apr 11 03:00:50 2016 +0100 @@ -0,0 +1,1 @@ +127.0.0.1 localhost diff -r 4209c9e19c45 -r d041d2e80712 jdk/test/sun/security/krb5/auto/principalProperty/principalSystemPropTest.policy --- a/jdk/test/sun/security/krb5/auto/principalProperty/principalSystemPropTest.policy Sat Apr 09 20:12:13 2016 +0100 +++ b/jdk/test/sun/security/krb5/auto/principalProperty/principalSystemPropTest.policy Mon Apr 11 03:00:50 2016 +0100 @@ -11,6 +11,7 @@ permission javax.security.auth.AuthPermission "modifyPrincipals"; permission javax.security.auth.AuthPermission "getSubject"; permission java.util.PropertyPermission "*", "read,write"; + permission java.io.FilePermission "/-", "read,write,delete"; permission java.io.FilePermission "*", "read,write,delete"; permission java.lang.RuntimePermission "accessDeclaredMembers"; permission java.lang.reflect.ReflectPermission "suppressAccessChecks"; diff -r 4209c9e19c45 -r d041d2e80712 jdk/test/sun/security/krb5/auto/unbound.ssl.policy --- a/jdk/test/sun/security/krb5/auto/unbound.ssl.policy Sat Apr 09 20:12:13 2016 +0100 +++ b/jdk/test/sun/security/krb5/auto/unbound.ssl.policy Mon Apr 11 03:00:50 2016 +0100 @@ -1,6 +1,7 @@ grant { permission java.util.PropertyPermission "*", "read,write"; permission java.net.SocketPermission "*:*", "listen,resolve,accept,connect"; + permission java.io.FilePermission "/-", "read"; permission java.io.FilePermission "*", "read,write,delete"; permission java.lang.RuntimePermission "accessDeclaredMembers"; permission java.lang.reflect.ReflectPermission "suppressAccessChecks"; diff -r 4209c9e19c45 -r d041d2e80712 jdk/test/sun/security/krb5/canonicalize/META-INF/services/sun.net.spi.nameservice.NameServiceDescriptor --- a/jdk/test/sun/security/krb5/canonicalize/META-INF/services/sun.net.spi.nameservice.NameServiceDescriptor Sat Apr 09 20:12:13 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -Test diff -r 4209c9e19c45 -r d041d2e80712 jdk/test/sun/security/krb5/canonicalize/Test.java --- a/jdk/test/sun/security/krb5/canonicalize/Test.java Sat Apr 09 20:12:13 2016 +0100 +++ b/jdk/test/sun/security/krb5/canonicalize/Test.java Mon Apr 11 03:00:50 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2016 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 @@ -24,20 +24,19 @@ * @test * @bug 6682516 * @summary SPNEGO_HTTP_AUTH/WWW_KRB and SPNEGO_HTTP_AUTH/WWW_SPNEGO failed on all non-windows platforms - * @modules java.base/sun.net.spi.nameservice - * java.security.jgss/sun.security.krb5 - * @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock -Djava.security.krb5.conf=krb5.conf Test + * @modules java.security.jgss/sun.security.krb5 + * @run main/othervm -Djava.security.krb5.conf=krb5.conf Test */ import java.net.InetAddress; import java.net.UnknownHostException; -import sun.net.spi.nameservice.NameService; -import sun.net.spi.nameservice.NameServiceDescriptor; import sun.security.krb5.PrincipalName; -public class Test implements NameServiceDescriptor { +public class Test { public static void main(String[] args) throws Exception { // This config file is generated using Kerberos.app on a Mac + String hostsFileName = System.getProperty("test.src", ".") + "/TestHosts"; + System.setProperty("jdk.net.hosts.file", hostsFileName); System.setProperty("java.security.krb5.realm", "THIS.REALM"); System.setProperty("java.security.krb5.kdc", "localhost"); @@ -64,42 +63,4 @@ throw new Exception("Output is " + pn); } } - - @Override - public NameService createNameService() throws Exception { - NameService ns = new NameService() { - @Override - public InetAddress[] lookupAllHostAddr(String host) - throws UnknownHostException { - // All c.* goes to 127.0.0.n - int i = Integer.valueOf(host.split("\\.")[0].substring(1)); - return new InetAddress[]{ - InetAddress.getByAddress(host, new byte[]{127,0,0,(byte)i}) - }; } - @Override - public String getHostByAddr(byte[] addr) - throws UnknownHostException { - int i = addr[3]; - switch (i) { - case 1: return "c1.this.domain"; // Good - case 2: return "127.0.0.2"; // Only IP - case 3: return "d3.this.domain"; // name change - default: - throw new UnknownHostException(); - } - } - }; - return ns; - } - - @Override - public String getProviderName() { - return "mock"; - } - - @Override - public String getType() { - return "ns"; - } -} diff -r 4209c9e19c45 -r d041d2e80712 jdk/test/sun/security/krb5/canonicalize/TestHosts --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/sun/security/krb5/canonicalize/TestHosts Mon Apr 11 03:00:50 2016 +0100 @@ -0,0 +1,6 @@ +127.0.0.1 c1.this.domain +127.0.0.1 c1 +127.0.0.2 127.0.0.2 +127.0.0.2 c2 +127.0.0.3 c3 +127.0.0.1 c1.this diff -r 4209c9e19c45 -r d041d2e80712 jdk/test/sun/security/x509/URICertStore/ExtensionsWithLDAP.java --- a/jdk/test/sun/security/x509/URICertStore/ExtensionsWithLDAP.java Sat Apr 09 20:12:13 2016 +0100 +++ b/jdk/test/sun/security/x509/URICertStore/ExtensionsWithLDAP.java Mon Apr 11 03:00:50 2016 +0100 @@ -44,14 +44,11 @@ import java.util.List; import java.util.Locale; import java.util.Set; -import sun.net.spi.nameservice.NameService; -import sun.net.spi.nameservice.NameServiceDescriptor; /* * @test * @bug 8134708 * @summary Check if LDAP resources from CRLDP and AIA extensions can be loaded - * @modules java.base/sun.net.spi.nameservice * @run main/othervm ExtensionsWithLDAP */ public class ExtensionsWithLDAP { @@ -149,7 +146,8 @@ System.setProperty("com.sun.security.enableAIAcaIssuers", "true"); // register a local name service - System.setProperty("sun.net.spi.nameservice.provider.1", "ns,localdns"); + String hostsFileName = System.getProperty("test.src", ".") + "/ExtensionsWithLDAPHosts"; + System.setProperty("jdk.net.hosts.file", hostsFileName); X509Certificate trustedCert = loadCertificate(CA_CERT); X509Certificate eeCert = loadCertificate(EE_CERT); @@ -201,48 +199,8 @@ } // a local name service which log requested host names - public static class LocalNameService implements NameServiceDescriptor { + public static class LocalNameService { static final List requestedHosts = new ArrayList<>(); - - @Override - public NameService createNameService() throws Exception { - System.out.println("LocalNameService: createNameService() called"); - NameService ns = new NameService() { - - @Override - public InetAddress[] lookupAllHostAddr(String host) - throws UnknownHostException { - - System.out.println("LocalNameService: " - + "NameService.lookupAllHostAddr(): " + host); - - requestedHosts.add(host); - - throw new UnknownHostException(); } - - @Override - public String getHostByAddr(byte[] addr) - throws UnknownHostException { - System.out.println("LocalNameService: " - + "NameService.getHostByAddr(): " - + Arrays.toString(addr)); - throw new UnknownHostException("No reverse lookup"); } - }; - return ns; - } - - @Override - public String getProviderName() { - return "localdns"; - } - - @Override - public String getType() { - return "ns"; - } - } - -} diff -r 4209c9e19c45 -r d041d2e80712 jdk/test/sun/security/x509/URICertStore/META-INF/services/sun.net.spi.nameservice.NameServiceDescriptor --- a/jdk/test/sun/security/x509/URICertStore/META-INF/services/sun.net.spi.nameservice.NameServiceDescriptor Sat Apr 09 20:12:13 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -ExtensionsWithLDAP$LocalNameService