From e7c217c72dea7beb23a2f40b83ba3f6417e1de58 Mon Sep 17 00:00:00 2001 From: Weijun Wang Date: Tue, 3 Feb 2009 09:38:13 +0800 Subject: [PATCH] 6552334: Enable DNS in Kerberos by default Reviewed-by: valeriep --- .../share/classes/sun/security/krb5/Config.java | 16 ++++++++-------- .../sun/security/krb5/KrbServiceLocator.java | 4 ++-- jdk/test/sun/security/krb5/DnsFallback.java | 10 ++++++++-- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/jdk/src/share/classes/sun/security/krb5/Config.java b/jdk/src/share/classes/sun/security/krb5/Config.java index ec3eb81767d..401f50206f9 100644 --- a/jdk/src/share/classes/sun/security/krb5/Config.java +++ b/jdk/src/share/classes/sun/security/krb5/Config.java @@ -39,7 +39,6 @@ import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; import java.util.Enumeration; -import java.util.List; import java.util.StringTokenizer; import java.net.InetAddress; import java.net.UnknownHostException; @@ -156,11 +155,7 @@ public class Config { configFile = loadConfigFile(); stanzaTable = parseStanzaTable(configFile); } catch (IOException ioe) { - KrbException ke = new KrbException("Could not load " + - "configuration file " + - ioe.getMessage()); - ke.initCause(ioe); - throw(ke); + // No krb5.conf, no problem. We'll use DNS etc. } } } @@ -1057,7 +1052,12 @@ public class Config { public boolean useDNS(String name) { String value = getDefault(name, "libdefaults"); if (value == null) { - return getDefaultBooleanValue("dns_fallback", "libdefaults"); + value = getDefault("dns_fallback", "libdefaults"); + if ("false".equalsIgnoreCase(value)) { + return false; + } else { + return true; + } } else { return value.equalsIgnoreCase("true"); } @@ -1117,7 +1117,7 @@ public class Config { String realm = null; String hostName = null; try { - hostName = InetAddress.getLocalHost().getHostName(); + hostName = InetAddress.getLocalHost().getCanonicalHostName(); } catch (UnknownHostException e) { KrbException ke = new KrbException(Krb5.KRB_ERR_GENERIC, "Unable to locate Kerberos realm: " + e.getMessage()); diff --git a/jdk/src/share/classes/sun/security/krb5/KrbServiceLocator.java b/jdk/src/share/classes/sun/security/krb5/KrbServiceLocator.java index 0efe37d1aa4..fefcdbde054 100644 --- a/jdk/src/share/classes/sun/security/krb5/KrbServiceLocator.java +++ b/jdk/src/share/classes/sun/security/krb5/KrbServiceLocator.java @@ -1,5 +1,5 @@ /* - * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2006-2009 Sun Microsystems, Inc. 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 @@ -133,7 +133,7 @@ class KrbServiceLocator { */ static String[] getKerberosService(String realmName, String protocol) { - String dnsUrl = "dns:///_kerberos." + protocol + realmName; + String dnsUrl = "dns:///_kerberos." + protocol + "." + realmName; String[] hostports = null; try { diff --git a/jdk/test/sun/security/krb5/DnsFallback.java b/jdk/test/sun/security/krb5/DnsFallback.java index 95fbf3b165b..54aa8301eff 100644 --- a/jdk/test/sun/security/krb5/DnsFallback.java +++ b/jdk/test/sun/security/krb5/DnsFallback.java @@ -1,5 +1,5 @@ /* - * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2008-2009 Sun Microsystems, Inc. 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 @@ -23,7 +23,8 @@ /* * @test * @bug 6673164 - * @summary dns_fallback parse error + * @bug 6552334 + * @summary fix dns_fallback parse error, and use dns by default */ import sun.security.krb5.*; @@ -31,6 +32,8 @@ import java.io.*; public class DnsFallback { public static void main(String[] args) throws Exception { + + // for 6673164 check("true", "true", true); check("false", "true", false); check("true", "false", true); @@ -39,6 +42,9 @@ public class DnsFallback { check("false", null, false); check(null, "true", true); check(null, "false", false); + + // for 6552334 + check(null, null, true); } static void check(String realm, String fallback, boolean output) throws Exception {