45 * An implementation of DnsResolverConfiguration for Solaris |
45 * An implementation of DnsResolverConfiguration for Solaris |
46 * and Linux. |
46 * and Linux. |
47 */ |
47 */ |
48 |
48 |
49 public class DnsResolverConfiguration { |
49 public class DnsResolverConfiguration { |
|
50 |
|
51 public static String getDefaultHostsFileLocation() { |
|
52 return "/etc/hosts"; |
|
53 } |
|
54 |
50 // Lock held whilst loading configuration or checking |
55 // Lock held whilst loading configuration or checking |
51 private static final ReadWriteLock LOCK = new ReentrantReadWriteLock(); |
56 private static final ReadWriteLock LOCK = new ReentrantReadWriteLock(); |
52 |
57 |
53 // |
58 // |
54 private static String RESOLV_CONF_LOCATION = java.security.AccessController.doPrivileged( |
59 private static String RESOLV_CONF_LOCATION = java.security.AccessController.doPrivileged( |
55 (PrivilegedAction<String>) () -> System.getProperty("jdk.dns.client.resolv.conf", "/etc/resolv.conf")); |
60 (PrivilegedAction<String>) () -> System.getProperty("jdk.dns.client.resolv.conf", "/etc/resolv.conf")); |
56 private static final ReloadTracker RESOLVE_CONF_TRACKER; |
61 private static final ReloadTracker RESOLVE_CONF_TRACKER; |
57 |
62 |
58 |
63 |
59 // Cache timeout (300 seconds) - should be converted into property |
64 // Cache timeout (300 seconds) in nano seconds - should be converted into property |
60 // or configured as preference in the future. |
65 // or configured as preference in the future. |
61 private static final int TIMEOUT = 300_000; |
66 private static final long TIMEOUT = 300_000_000_000L; |
62 |
67 |
63 // Parse /etc/resolv.conf to get the values for a particular |
68 // Parse /etc/resolv.conf to get the values for a particular |
64 // keyword. |
69 // keyword. |
65 // |
70 // |
66 private List<String> resolvconf(String keyword, |
71 private List<String> resolvconf(String keyword, |
67 int maxperkeyword, |
72 int maxperkeyword, |
68 int maxkeywords) { |
73 int maxkeywords) { |
69 LinkedList<String> ll = new LinkedList<>(); |
74 LinkedList<String> ll = new LinkedList<>(); |
70 |
75 |
71 try { |
76 try { |
72 BufferedReader in = |
77 BufferedReader in = |
73 new BufferedReader(new FileReader(RESOLV_CONF_LOCATION)); |
78 new BufferedReader(new FileReader(RESOLV_CONF_LOCATION)); |
264 static native String localDomain0(); |
269 static native String localDomain0(); |
265 |
270 |
266 static native String fallbackDomain0(); |
271 static native String fallbackDomain0(); |
267 |
272 |
268 static { |
273 static { |
269 var pa = (PrivilegedAction<Void>) () -> {System.loadLibrary("resolver"); return null;}; |
274 var pa = (PrivilegedAction<Void>) () -> { |
|
275 System.loadLibrary("resolver"); |
|
276 return null; |
|
277 }; |
270 if (System.getSecurityManager() == null) { |
278 if (System.getSecurityManager() == null) { |
271 pa.run(); |
279 pa.run(); |
272 } else { |
280 } else { |
273 AccessController.doPrivileged(pa); |
281 AccessController.doPrivileged(pa); |
274 } |
282 } |