/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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.
*/
/*
*
* (C) Copyright IBM Corp. 1999 All Rights Reserved.
* Copyright 1997 The Open Group Research Institute. All rights reserved.
*/
/**
* This class maintains key-value pairs of Kerberos configurable constants
* from configuration file or from user specified system properties.
*/
public class Config {
/*
* Only allow a single instance of Config.
*/
/*
* Hashtable used to store configuration infomation.
*/
// these are used for hexdecimal calculation.
/**
* Specified by system properties. Must be both null or non-null.
*/
// used for native interface
/**
* Gets an instance of Config class. One and only one instance (the
* singleton) is returned.
*
* @exception KrbException if error occurs when constructing a Config
* instance. Possible causes would be either of java.security.krb5.realm or
* java.security.krb5.kdc not specified, error reading configuration file.
*/
}
return singleton;
}
/**
* Refresh and reload the Configuration. This could involve,
* for example reading the Configuration file again or getting
* the java.security.krb5.* system properties again.
*
* @exception KrbException if error occurs when constructing a Config
* instance. Possible causes would be either of java.security.krb5.realm or
* java.security.krb5.kdc not specified, error reading configuration file.
*/
}
private static boolean isMacosLionOrBetter() {
// split the "10.x.y" version number
return false;
}
// sanity check the "10." part of the version
// check if Mac OS X 10.7(.y)
try {
if (minorVers >= 7) return true;
} catch (NumberFormatException e) {
// was not an integer
}
return false;
}
/**
* Private constructor - can not be instantiated externally.
*/
/*
* If either one system property is specified, we throw exception.
*/
// The user can specify a list of kdc hosts separated by ":"
} else {
defaultKDC = null;
}
throw new KrbException
("System property java.security.krb5.kdc and " +
"java.security.krb5.realm both must be set or " +
"neither must be set.");
}
// Always read the Kerberos configuration file
try {
if (DEBUG) {
}
} else {
boolean found = false;
if (isMacosLionOrBetter()) {
try {
if (DEBUG) {
}
found = true;
} catch (IOException ioe) {
// OK. Will go on with file
}
}
if (!found) {
if (DEBUG) {
}
}
}
} catch (IOException ioe) {
// No krb5.conf, no problem. We'll use DNS or system property etc.
}
}
/**
* Gets the default int value for the specified name.
* @param name the name.
* @return the default Integer, null is returned if no such name and
* value are found in configuration file, or error occurs when parsing
* string to integer.
*/
try {
} catch (NumberFormatException e) {
if (DEBUG) {
name + " " +
e.getMessage());
" to minimum value");
}
}
}
return value;
}
/**
* Gets the default int value for the specified name in the specified
* section. <br>This method is quicker by using section name as the
* search key.
* @param name the name.
* @param sectio the name string of the section.
* @return the default Integer, null is returned if no such name and
* value are found in configuration file, or error occurs when parsing
* string to integer.
*/
try {
} catch (NumberFormatException e) {
if (DEBUG) {
name +" in section " +
" to minimum value");
}
}
}
return value;
}
/**
* Gets the default string value for the specified name.
* @param name the name.
* @return the default value, null is returned if it cannot be found.
*/
if (stanzaTable == null) {
return null;
} else {
}
}
/**
* This method does the real job to recursively search through the
* stanzaTable.
* @param k the key string.
* @param t stanzaTable or sub hashtable within it.
* @return the value found in config file, returns null if no value
* matched with the key is found.
*/
if (stanzaTable != null) {
return result;
}
} else if (key.equalsIgnoreCase(k)) {
result = "";
for (int i = 0; i < length; i++) {
if (i == length -1) {
result +=
} else {
result +=
}
}
return result;
}
}
}
}
return result;
}
/**
* Gets the default string value for the specified name in the
* specified section.
* <br>This method is quicker by using the section name as the search key.
* @param name the name.
* @param section the name of the section.
* @return the default value, null is returned if it cannot be found.
*/
if (stanzaTable != null) {
}
result = "";
for (int i = 0; i < length; i++) {
if (i == length - 1) {
result +=
} else {
result +=
+ " ";
}
}
} else {
}
}
}
}
}
}
return result;
}
/**
* Gets the default boolean value for the specified name.
* @param name the name.
* @return the default boolean value, false is returned if it cannot be
* found.
*/
if (stanzaTable == null) {
} else {
}
return true;
} else {
return false;
}
}
/**
* Gets the default boolean value for the specified name in the
* specified section.
* <br>This method is quicker by using the section name as the search key.
* @param name the name.
* @param section the name of the section.
* @return the default boolean value, false is returned if it cannot be
* found.
*/
return true;
} else {
return false;
}
}
/**
* Parses a string to an integer. The convertible strings include the
* string representations of positive integers, negative integers, and
* hex decimal integers. Valid inputs are, e.g., -1234, +1234,
* 0x40000.
*
* @param input the String to be converted to an Integer.
* @return an numeric value represented by the string
* @exception NumberFormationException if the String does not contain a
* parsable integer.
*/
int value = 0;
throw new NumberFormatException();
} else {
switch (chars[i]) {
case '0':
value += 0;
break;
case '1':
break;
case '2':
break;
case '3':
break;
case '4':
break;
case '5':
break;
case '6':
break;
case '7':
break;
case '8':
break;
case '9':
break;
case 'a':
case 'A':
break;
case 'b':
case 'B':
break;
case 'c':
case 'C':
break;
case 'd':
case 'D':
break;
case 'e':
case 'E':
break;
case 'f':
case 'F':
break;
default:
throw new NumberFormatException("Invalid numerical format");
}
}
}
if (value < 0) {
throw new NumberFormatException("Data overflow.");
}
} else {
}
return value;
}
private int getBase(int i) {
int result = 16;
switch (i) {
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
default:
for (int j = 1; j < i; j++) {
result *= 16;
}
}
return result;
}
/**
* Finds the matching value in the hashtable.
*/
if ((stanzaTable != null) &&
return result;
} else {
return "";
}
}
/**
* file. The default location of the configuration file is in java home
* directory.
*
* Configuration file contains information about the default realm,
* ticket parameters, location of the KDC and the admin server for
* known realms, etc. The file is divided into sections. Each section
* typical file would be:
* [libdefaults]
* default_realm = EXAMPLE.COM
* default_tgs_enctypes = des-cbc-md5
* default_tkt_enctypes = des-cbc-md5
* [realms]
* EXAMPLE.COM = {
* kdc = kerberos.example.com
* kdc = kerberos-1.example.com
* admin_server = kerberos.example.com
* }
* SAMPLE_COM = {
* kdc = orange.sample.com
* admin_server = orange.sample.com
* }
* [domain_realm]
* blue.sample.com = TEST.SAMPLE.COM
* .backup.com = EXAMPLE.COM
*
* @params fileName the conf file, cannot be null
* @return the content, null if fileName is empty
* @throws IOException if there is an I/O or format error
*/
try {
return new FileInputStream(fileName);
}
})));
// ignore comments and blank line in the configuration file.
// Comments start with #.
// In practice, a subsection might look like:
// EXAMPLE.COM =
// {
// kdc = kerberos.example.com
// ...
// }
// Before parsed into stanza table, it needs to be
// converted into formal style:
// EXAMPLE.COM = {
// kdc = kerberos.example.com
// ...
// }
//
// So, if a line is "{", adhere to the previous line.
throw new IOException(
"Config file should not start with \"{\"");
}
} else {
v.addElement(previous);
}
}
}
}
v.addElement(previous);
}
return v;
}
return null;
}
}
/**
* Parses stanza names and values from configuration file to
* stanzaTable (Hashtable). Hashtable key would be stanza names,
* (libdefaults, realms, domain_realms, etc), and the hashtable value
* would be another hashtable which contains the key-value pairs under
* a stanza name.
*/
if (v == null) {
throw new KrbException("I/O error while reading" +
" configuration file.");
}
for (int i = 0; i < v.size(); i++) {
// find the next stanza name
new Hashtable<>();
i = count - 1;
break;
}
}
// find the next stanza name
new Hashtable<>();
i = count - 1;
break;
}
}
// find the next stanza name
i = count - 1;
break;
}
}
}
}
return table;
}
/**
* Gets the default Java configuration file name.
*
* If the system property "java.security.krb5.conf" is defined, we'll
* use its value, no matter if the file exists or not. Otherwise, we
* and return it if the file exists.
*
* The method returns null if it cannot find a Java config file.
*/
if (!fileExists(name)) {
}
}
if (DEBUG) {
}
return name;
}
/**
* Gets the default native configuration file name.
*
* Depending on the OS type, the method returns the default native
* kerberos config file name, which is at windows directory with
*
* Note: When the Terminal Service is started in Windows (from 2003),
* there are two kinds of Windows directories: A system one (say,
* C:\Windows), and a user-private one (say, C:\Users\Me\Windows).
* We will first look for krb5.ini in the user-private one. If not
* found, try the system one instead.
*
* This method will always return a non-null non-empty file name,
* even if that file does not exist.
*/
try {
} catch (Exception e) {
// ignore exceptions
}
if (Credentials.alreadyLoaded) {
} else {
}
if (fileExists(path)) {
}
}
path = getWindowsDirectory(true);
} else {
}
}
}
}
}
name = findMacosConfigFile();
} else {
}
if (DEBUG) {
}
return name;
}
}
if (fileExists(userPrefs)) {
return userPrefs;
}
if (fileExists(PREF_FILE)) {
return PREF_FILE;
}
}
s = s.trim();
}
return s;
}
/**
* Parses key-value pairs under a stanza name.
*/
break;
}
}
}
return table;
}
/**
* Parses key-value pairs under [realms]. The key would be the realm
* name, the value would be another hashtable which contains
* information for the realm given within a pair of braces.
*/
private Hashtable<String,Hashtable<String,Vector<String>>> parseRealmField(Vector<String> v, int start, int end) {
// get the key
break;
}
}
for (int k = i + 1; k < end; k++) {
boolean found = false;
found = true;
break;
}
}
if (found == true) {
i = k;
found = false;
break;
}
}
}
}
return table;
}
/**
* Parses key-value pairs within each braces under [realms].
*/
int index;
} else {
}
break;
}
}
}
return table;
}
/**
* Compares the key with the known keys to see if it exists.
*/
boolean exists = false;
for (int i = 0; i < v.size(); i++) {
exists = true;
}
}
return exists;
}
/**
* For testing purpose. This method lists all information being parsed from
* the configuration file to the hashtable.
*/
public void listTable() {
}
if (stanzaTable != null) {
if (table == stanzaTable) {
}
if (table != stanzaTable)
if (table != stanzaTable)
for (int i = 0; i < v.size(); i++) {
}
}
}
} else {
}
}
/**
* Returns the default encryption types.
*
*/
int[] etype;
if (default_enctypes == null) {
if (DEBUG) {
enctypes);
}
} else {
// only two delimiters are allowed to use
// according to Kerberos DCE doc.
delim = ",";
break;
}
}
int type;
for (int i = 0; i < len; i++) {
if ((type != -1) &&
}
}
if (DEBUG) {
"no supported default etypes for " + enctypes);
}
return null;
} else {
}
}
}
if (DEBUG) {
}
}
return etype;
}
/**
* Get the etype and checksum value for the specified encryption and
* checksum type.
*
*/
/*
* This method converts the string representation of encryption type and
* checksum type to int value that can be later used by EType and
* Checksum classes.
*/
int result = -1;
return result;
}
}
// AES
// ARCFOUR-HMAC
}
// RC4-HMAC
}
}
return result;
}
/**
* Resets the default kdc realm.
* We do not need to synchronize these methods since assignments are atomic
*
* This method was useless. Kept here in case some class still calls it.
*/
if (DEBUG) {
}
}
/**
* Check to use addresses in tickets
* use addresses if "no_addresses" or "noaddresses" is set to false
*/
public boolean useAddresses() {
boolean useAddr = false;
// use addresses if "no_addresses" is set to false
if (useAddr == false) {
// use addresses if "noaddresses" is set to false
}
return useAddr;
}
/**
* Check if need to use DNS to locate Kerberos services
*/
return false;
} else {
return true;
}
} else {
}
}
/**
* Check if need to use DNS to locate the KDC
*/
public boolean useDNS_KDC() {
return useDNS("dns_lookup_kdc");
}
/*
* Check if need to use DNS to locate the Realm
*/
public boolean useDNS_Realm() {
return useDNS("dns_lookup_realm");
}
/**
* Gets default realm.
* @throws KrbException where no realm can be located
* @return the default realm, always non null
*/
if (defaultRealm != null) {
return defaultRealm;
}
// use DNS to locate Kerberos realm
try {
realm = getRealmFromDNS();
} catch (KrbException ke) {
}
}
}
return null;
}
});
}
}
throw ke;
}
return realm;
}
/**
* Returns a list of KDC's with each KDC separated by a space
*
* @param realm the realm for which the KDC list is desired
* @throws KrbException if there's no way to find KDC for the realm
* @return the list of KDCs separated by a space, always non null
*/
realm = getDefaultRealm();
}
return defaultKDC;
}
// use DNS to locate KDC
try {
} catch (KrbException ke) {
}
}
if (logonServer != null
}
return logonServer;
}
return null;
}
});
}
if (defaultKDC != null) {
return defaultKDC;
}
}
throw ke;
}
return kdcs;
}
/**
* Locate Kerberos realm using DNS
*
* @return the Kerberos realm
*/
// use DNS to locate Kerberos realm
try {
} catch (UnknownHostException e) {
"Unable to locate Kerberos realm: " + e.getMessage());
throw (ke);
}
// get the domain realm mapping from the configuration
// No match. Try search and/or domain in /etc/resolv.conf
break;
}
}
} else {
}
"Unable to locate Kerberos realm");
}
return realm;
}
/**
* Check if the provided realm is the correct realm
* @return the realm if correct, or null otherwise
*/
if (DEBUG) {
}
// locate DNS TXT record
// if no DNS TXT records found, try again using sub-realm
}
return records[i];
}
}
}
return null;
}
/**
* Locate KDC using DNS
*
* @param realm the realm for which the master KDC is desired
* @return the KDC
*/
// use DNS to locate KDC
// locate DNS SRV record using UDP
if (DEBUG) {
}
// locate DNS SRV record using TCP
if (DEBUG) {
}
}
// no DNS SRV records
"Unable to locate KDC for realm " + realm);
}
return null;
}
}
return null;
}
return kdcs;
}
new FileExistsAction(name));
}
static class FileExistsAction
}
}
}
// Shows the content of the Config object for debug purpose.
//
// {
// libdefaults = {
// default_realm = R
// }
// realms = {
// R = {
// kdc = [k1,k2]
// }
// }
// }
}
StringBuffer sb) {
// A string value, just print it
// A table, start a new sub-section...
// ...indent, print "key = ", and
// ...go recursively into value
}
// A vector of strings, print them inside [ and ]
boolean first = true;
first = false;
}
}
}
}